Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buy support for BalancerV2 ComposableStable pools #837

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading