Skip to content

Commit

Permalink
Merge pull request #837 from paraswap/aburkut/back-1768-balv2-compose…
Browse files Browse the repository at this point in the history
…-stable-buy-support

Add buy support for BalancerV2 ComposableStable pools
  • Loading branch information
aburkut authored Nov 20, 2024
2 parents 96d4a07 + 0088fd7 commit c834699
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@paraswap/dex-lib",
"version": "3.11.3",
"version": "3.11.4",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": "https://github.com/paraswap/paraswap-dex-lib",
Expand Down
78 changes: 78 additions & 0 deletions src/dex/balancer-v2/balancer-v2-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function testForNetwork(
// ContractMethod.multiSwap,
// ContractMethod.megaSwap,
ContractMethod.swapExactAmountIn,
ContractMethod.swapExactAmountInOnBalancerV2,
],
],
[
Expand All @@ -50,6 +51,7 @@ function testForNetwork(
// ContractMethod.buy,
// DirectMethodsV6.directBuy,
ContractMethod.swapExactAmountOut,
ContractMethod.swapExactAmountOutOnBalancerV2,
],
],
]);
Expand Down Expand Up @@ -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([
[
Expand Down
2 changes: 2 additions & 0 deletions src/dex/balancer-v2/balancer-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export class BalancerV2EventPool extends StatefulEventSubscriber<PoolStateMap> {
buySupportedPoolTypes: Set<BalancerPoolTypes> = new Set([
BalancerPoolTypes.Weighted,
BalancerPoolTypes.GyroE,
BalancerPoolTypes.ComposableStable,
]);

eventSupportedPoolTypes: BalancerPoolTypes[] = [
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c834699

Please sign in to comment.