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 FX custom swap fees to multicall onChainData fetch #499

Merged
merged 1 commit into from
Aug 7, 2023
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
42 changes: 33 additions & 9 deletions balancer-js/src/modules/sor/pool-data/onChainData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,52 @@ import dotenv from 'dotenv';
dotenv.config();
import { expect } from 'chai';
import { cloneDeep } from 'lodash';
import { BALANCER_NETWORK_CONFIG, Network, PoolsSubgraphRepository } from '@/.';
import { getOnChainPools } from './onChainData';
import { JsonRpcProvider } from '@ethersproject/providers';

import {
BALANCER_NETWORK_CONFIG,
Network,
Pool,
PoolsSubgraphRepository,
} from '@/.';

import { getOnChainBalances, getOnChainPools } from './onChainData';

// yarn test:only ./src/modules/sor/pool-data/onChainData.spec.ts
describe('getOnChainPools', async function () {
it('should fetch onchain pools', async function () {
const network = Network.POLYGON;
const rpcUrl = `https://polygon-mainnet.infura.io/v3/${process.env.INFURA}`;
const provider = new JsonRpcProvider(rpcUrl);
const url = BALANCER_NETWORK_CONFIG[network].urls.subgraph;
this.timeout(40000);
let pools: Pool[];
let provider: JsonRpcProvider;
const network = Network.POLYGON;
const url = BALANCER_NETWORK_CONFIG[network].urls.subgraph;
const rpcUrl = `https://polygon-mainnet.infura.io/v3/${process.env.INFURA}`;

before(async function () {
provider = new JsonRpcProvider(rpcUrl);
const poolsRepo = new PoolsSubgraphRepository({
url,
chainId: network,
});
const pools = await poolsRepo.all();
pools = await poolsRepo.all();
});

it('should fetch onchain pools using queries helper contract', async function () {
const onChainPools = await getOnChainPools(
cloneDeep(pools),
BALANCER_NETWORK_CONFIG[network].addresses.contracts.poolDataQueries,
BALANCER_NETWORK_CONFIG[network].addresses.contracts.multicall,
provider
);
expect(onChainPools.length).to.be.gt(0);
}).timeout(40000);
});

it('should fetch onchain pools using multicall', async function () {
const onChainBalances = await getOnChainBalances(
cloneDeep(pools),
BALANCER_NETWORK_CONFIG[network].addresses.contracts.multicall,
BALANCER_NETWORK_CONFIG[network].addresses.contracts.vault,
provider
);
expect(onChainBalances.length).to.be.gt(0);
});
});
12 changes: 10 additions & 2 deletions balancer-js/src/modules/sor/pool-data/onChainData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { formatFixed } from '@ethersproject/bignumber';
import {
ComposableStablePool__factory,
ConvergentCurvePool__factory,
FXPool__factory,
GyroEV2__factory,
LinearPool__factory,
Multicall__factory,
Expand Down Expand Up @@ -79,6 +80,7 @@ export async function getOnChainBalances<
...(LinearPool__factory.abi as readonly JsonFragment[]),
...(ComposableStablePool__factory.abi as readonly JsonFragment[]),
...(GyroEV2__factory.abi as readonly JsonFragment[]),
...(FXPool__factory.abi as readonly JsonFragment[]),
].map((row) => [row.name, row])
)
);
Expand Down Expand Up @@ -183,6 +185,13 @@ export async function getOnChainBalances<
case 'Element':
multiPool.call(`${pool.id}.swapFee`, pool.address, 'percentFee');
break;
case 'FX':
multiPool.call(
`${pool.id}.swapFee`,
pool.address,
'protocolPercentFee'
);
break;
case 'Gyro2':
case 'Gyro3':
multiPool.call(`${pool.id}.poolTokens`, vaultAddress, 'getPoolTokens', [
Expand Down Expand Up @@ -333,8 +342,7 @@ export async function getOnChainBalances<
);
}

if (subgraphPools[index].poolType !== 'FX')
subgraphPools[index].swapFee = formatFixed(swapFee, 18);
subgraphPools[index].swapFee = formatFixed(swapFee, 18);

poolTokens.tokens.forEach((token, i) => {
const tokens = subgraphPools[index].tokens;
Expand Down
Loading