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

feat: balancer v2 buy support for specific pools #836

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
57 changes: 56 additions & 1 deletion src/dex/balancer-v2/balancer-v2-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { ContractMethod, Network, SwapSide } from '../../constants';
import { StaticJsonRpcProvider } from '@ethersproject/providers';

import { generateConfig } from '../../config';
import { DirectMethodsV6 } from './constants';

jest.setTimeout(50 * 1000);

Expand Down Expand Up @@ -543,6 +542,62 @@ describe('BalancerV2 E2E', () => {
);
});

describe('GHO -> USDT buy', () => {
const sideToContractMethods = new Map([
[
SwapSide.BUY,
[
ContractMethod.swapExactAmountOutOnBalancerV2,
ContractMethod.swapExactAmountOut,
],
],
]);

const pairs: { name: string; amount: string }[][] = [
[
{ name: 'GHO', amount: '81530002926' },
{ name: 'USDT', amount: '82245407358961750602330' },
],
];

sideToContractMethods.forEach((contractMethods, side) =>
describe(`${side}`, () => {
contractMethods.forEach((contractMethod: ContractMethod) => {
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],
pair[0].amount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
it(`${pair[1].name} -> ${pair[0].name}`, async () => {
await testE2E(
tokens[pair[1].name],
tokens[pair[0].name],
holders[pair[1].name],
pair[1].amount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
});
});
});
}),
);
});

//daniel: BPT swaps are currently not supported, we've refactored to focus on mainToken paths
/*it('MAIN TOKEN -> BPT, LinearPool', async () => {
// Linear Pools allow swaps between main token (i.e. USDT) and pools BPT
Expand Down
13 changes: 12 additions & 1 deletion src/dex/balancer-v2/balancer-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ export class BalancerV2EventPool extends StatefulEventSubscriber<PoolStateMap> {
BalancerPoolTypes.GyroE,
]);

buySupportedPoolAddresses: Partial<Record<number, Set<Address>>> = {
[Network.MAINNET]: new Set([
'0x8353157092ed8be69a9df8f95af097bbf33cb2af', // ComposableStable USDC - USDT - GHO
]),
};

eventSupportedPoolTypes: BalancerPoolTypes[] = [
BalancerPoolTypes.Stable,
BalancerPoolTypes.Weighted,
Expand Down Expand Up @@ -511,7 +517,12 @@ export class BalancerV2EventPool extends StatefulEventSubscriber<PoolStateMap> {

if (
side === SwapSide.BUY &&
!this.buySupportedPoolTypes.has(subgraphPool.poolType)
!(
this.buySupportedPoolTypes.has(subgraphPool.poolType) ||
this.buySupportedPoolAddresses[this.network]?.has(
subgraphPool.address.toLowerCase(),
)
)
) {
return null;
}
Expand Down
Loading