Skip to content

Commit

Permalink
Add FX custom swap fees to multicall onChainData fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoguerios committed Jul 26, 2023
1 parent 512b460 commit 2ea57f5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
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

0 comments on commit 2ea57f5

Please sign in to comment.