From 1b71e02e515e779fde4dc3e12f330dac9e04ca75 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 19 Nov 2024 22:55:07 +0300 Subject: [PATCH 1/3] Add buy support for BalancerV2 ComposableStable pools --- src/dex/balancer-v2/balancer-v2-e2e.test.ts | 78 +++++++++++++++++++++ src/dex/balancer-v2/balancer-v2.ts | 2 + 2 files changed, 80 insertions(+) diff --git a/src/dex/balancer-v2/balancer-v2-e2e.test.ts b/src/dex/balancer-v2/balancer-v2-e2e.test.ts index c8f1ff3c0..491b06c0e 100644 --- a/src/dex/balancer-v2/balancer-v2-e2e.test.ts +++ b/src/dex/balancer-v2/balancer-v2-e2e.test.ts @@ -41,6 +41,7 @@ function testForNetwork( // ContractMethod.multiSwap, // ContractMethod.megaSwap, ContractMethod.swapExactAmountIn, + ContractMethod.swapExactAmountInOnBalancerV2, ], ], [ @@ -50,6 +51,7 @@ function testForNetwork( // ContractMethod.buy, // DirectMethodsV6.directBuy, ContractMethod.swapExactAmountOut, + ContractMethod.swapExactAmountOutOnBalancerV2, ], ], ]); @@ -128,6 +130,82 @@ describe('BalancerV2 E2E', () => { network, ); + describe.only('GHO -> USDT', () => { + const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = + [ + [ + { + name: 'GHO', + sellAmount: '1000000000000000000000', + buyAmount: '1000000000', + }, + { + name: 'USDT', + sellAmount: '1000000000', + buyAmount: '1000000000000000000000', + }, + ], + ]; + + const sideToContractMethods = new Map([ + [ + SwapSide.SELL, + [ + ContractMethod.swapExactAmountIn, + ContractMethod.swapExactAmountInOnBalancerV2, + ], + ], + [ + SwapSide.BUY, + [ + ContractMethod.swapExactAmountOut, + ContractMethod.swapExactAmountOutOnBalancerV2, + ], + ], + ]); + + sideToContractMethods.forEach((contractMethods, side) => + describe(`${side}`, () => { + contractMethods.forEach((contractMethod: string) => { + pairs.forEach(pair => { + describe(`${contractMethod}`, () => { + it(`${pair[0].name} -> ${pair[1].name}`, async () => { + await testE2E( + tokens[pair[0].name], + tokens[pair[1].name], + holders[pair[0].name], + side === SwapSide.SELL + ? pair[0].sellAmount + : pair[0].buyAmount, + side, + dexKey, + contractMethod as any, + network, + provider, + ); + }); + it(`${pair[1].name} -> ${pair[0].name}`, async () => { + await testE2E( + tokens[pair[1].name], + tokens[pair[0].name], + holders[pair[1].name], + side === SwapSide.SELL + ? pair[1].sellAmount + : pair[1].buyAmount, + side, + dexKey, + contractMethod as any, + network, + provider, + ); + }); + }); + }); + }); + }), + ); + }); + describe('Weighted Pool', () => { const sideToContractMethods = new Map([ [ diff --git a/src/dex/balancer-v2/balancer-v2.ts b/src/dex/balancer-v2/balancer-v2.ts index 97f60f1aa..19aedc760 100644 --- a/src/dex/balancer-v2/balancer-v2.ts +++ b/src/dex/balancer-v2/balancer-v2.ts @@ -266,6 +266,7 @@ export class BalancerV2EventPool extends StatefulEventSubscriber { buySupportedPoolTypes: Set = new Set([ BalancerPoolTypes.Weighted, BalancerPoolTypes.GyroE, + BalancerPoolTypes.ComposableStable, ]); eventSupportedPoolTypes: BalancerPoolTypes[] = [ @@ -868,6 +869,7 @@ export class BalancerV2 this.logger.error(`getState returned null`); } const eventPoolStates = { ...(eventPoolStatesRO || {}) }; + for (const addr of this.eventDisabledPools) delete eventPoolStates[addr]; // Fetch previously cached non-event pool states From c13a8cacfa0df40a59b3d9d5496d08099d8cb77c Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 19 Nov 2024 22:56:15 +0300 Subject: [PATCH 2/3] 3.11.4-balv2-compose-stable-buy-support.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a653af81d..38d63be4a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "3.11.3", + "version": "3.11.4-balv2-compose-stable-buy-support.0", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib", From 0088fd790334a4fa3048971d4175d098f5a984da Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Wed, 20 Nov 2024 13:35:29 +0300 Subject: [PATCH 3/3] 3.11.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 38d63be4a..63b88ca1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "3.11.4-balv2-compose-stable-buy-support.0", + "version": "3.11.4", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib",