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

Replace Multicall with Balancer pool data queries #476

Merged
merged 12 commits into from
Jul 7, 2023
447 changes: 447 additions & 0 deletions balancer-js/src/lib/abi/BalancerPoolDataQueries.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions balancer-js/src/lib/constants/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
//Mainnet deployment addresses: https://docs.balancer.fi/reference/contracts/deployment-addresses/mainnet.html
contracts: {
multicall: '0xeefba1e63905ef1d7acba5a8513c70307c1ce441',
poolDataQueries: '0xf5CDdF6feD9C589f1Be04899F48f9738531daD59',
lidoRelayer: '0xdcdbf71A870cc60C6F9B621E28a7D3Ffd6Dd4965',
veBal: '0xC128a9954e6c874eA3d62ce62B468bA073093F25',
veBalProxy: '0x6f5a2eE11E7a772AeB5114A20d0D7c0ff61EB8A0',
Expand Down Expand Up @@ -82,6 +83,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
//Polygon deployment addresses: https://docs.balancer.fi/reference/contracts/deployment-addresses/polygon.html
contracts: {
multicall: '0xa1B2b503959aedD81512C37e9dce48164ec6a94d',
poolDataQueries: '0x84813aA3e079A665C0B80F944427eE83cBA63617',
gaugeClaimHelper: '0xaeb406b0e430bf5ea2dc0b9fe62e4e53f74b3a33',
...addressesByNetwork[Network.POLYGON].contracts,
},
Expand Down Expand Up @@ -132,6 +134,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
addresses: {
contracts: {
multicall: '0x269ff446d9892c9e19082564df3f5e8741e190a1',
poolDataQueries: '0x7Ba29fE8E83dd6097A7298075C4AFfdBda3121cC',
gaugeClaimHelper: '0xa0dabebaad1b243bbb243f933013d560819eb66f',
...addressesByNetwork[Network.ARBITRUM].contracts,
},
Expand Down Expand Up @@ -174,6 +177,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
addresses: {
contracts: {
multicall: '0x77dCa2C955b15e9dE4dbBCf1246B4B85b651e50e',
poolDataQueries: '',
veBal: '0x33A99Dcc4C85C014cf12626959111D5898bbCAbF',
veBalProxy: '0xA1F107D1cD709514AE8A914eCB757E95f9cedB31',
erc4626LinearPoolFactory: '0xba240c856498e2d7a70af4911aafae0d6b565a5b',
Expand Down Expand Up @@ -213,6 +217,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
addresses: {
contracts: {
multicall: '0x2dc0e2aa608532da689e89e237df582b783e552c',
poolDataQueries: '0x6B5dA774890Db7B7b96C6f44e6a4b0F657399E2e',
...addressesByNetwork[Network.OPTIMISM].contracts,
},
tokens: {
Expand Down Expand Up @@ -251,6 +256,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
addresses: {
contracts: {
multicall: '0xbb6fab6b627947dae0a75808250d8b2652952cb5',
poolDataQueries: '0x3f170631ed9821Ca51A59D996aB095162438DC10',
...addressesByNetwork[Network.GNOSIS].contracts,
},
tokens: {
Expand Down Expand Up @@ -291,6 +297,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
contracts: {
vault: '0x20dd72Ed959b6147912C2e529F0a0C651c33c9ce',
multicall: '0x66335d7ad8011f6aa3f48aadcb523b62b38ed961',
poolDataQueries: '0xb132F1E145DcC085980C531e2dA81f2b84efc14F',
gaugeClaimHelper: '0x0000000000000000000000000000000000000000', // no guages on fantom
balancerRelayer: '0x419f7925b8c9e409b6ee8792242556fa210a7a09',
balancerHelpers: '0xfE18C7C70b0a2c6541bEde0367124278BC345Dc8',
Expand Down Expand Up @@ -336,6 +343,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
addresses: {
contracts: {
multicall: '0x25eef291876194aefad0d60dff89e268b90754bb',
poolDataQueries: '0x9805dcfD25e6De36bad8fe9D3Fe2c9b44B764102',
...addressesByNetwork[Network.SEPOLIA].contracts,
},
tokens: {
Expand Down Expand Up @@ -364,6 +372,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
contracts: {
balancerMinter: '0x475D18169BE8a89357A9ee3Ab00ca386d20fA229',
multicall: '0xcA11bde05977b3631167028862bE2a173976CA11',
poolDataQueries: '0xF24917fB88261a37Cc57F686eBC831a5c0B9fD39',
...addressesByNetwork[Network.ZKEVM].contracts,
},
tokens: {
Expand Down Expand Up @@ -404,6 +413,7 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
contracts: {
balancerMinter: '0xEa924b45a3fcDAAdf4E5cFB1665823B8F8F2039B',
multicall: '0xcA11bde05977b3631167028862bE2a173976CA11',
poolDataQueries: '0x67af5D428d38C5176a286a2371Df691cDD914Fb8',
...addressesByNetwork[Network.AVALANCHE].contracts,
},
tokens: {
Expand Down
2 changes: 1 addition & 1 deletion balancer-js/src/modules/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class Data implements BalancerDataRepositories {
{
provider: provider,
multicall: networkConfig.addresses.contracts.multicall,
vault: networkConfig.addresses.contracts.vault,
poolDataQueries: networkConfig.addresses.contracts.poolDataQueries,
},
networkConfig.poolsToIgnore
);
Expand Down
22 changes: 11 additions & 11 deletions balancer-js/src/modules/data/pool/subgraphOnChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Cacheable, Findable, Searchable } from '../types';
import { Provider } from '@ethersproject/providers';
import { PoolAttribute, PoolsRepositoryFetchOptions } from './types';
import { Pool } from '@/types';
import { getOnChainBalances } from '../../../modules/sor/pool-data/onChainData';
import { getOnChainPools } from '../../../modules/sor/pool-data/onChainData';
import { PoolsSubgraphRepository } from './subgraph';
import { isSameAddress } from '@/lib/utils';

interface PoolsSubgraphOnChainRepositoryOptions {
provider: Provider;
multicall: string;
vault: string;
poolDataQueries: string;
}

/**
Expand All @@ -21,14 +21,14 @@ export class PoolsSubgraphOnChainRepository
private provider: Provider;
private pools?: Promise<Pool[]>;
private multicall: string;
private vault: string;
private poolDataQueries: string;
public skip = 0;

/**
* Repository using multicall to get onchain data.
*
* @param poolsSubgraph subgraph repository
* @param options options containing provider, multicall and vault addresses
* @param options options containing provider, multicall and poolDataQueries address
*/
constructor(
private poolsSubgraph: PoolsSubgraphRepository,
Expand All @@ -37,7 +37,7 @@ export class PoolsSubgraphOnChainRepository
) {
this.provider = options.provider;
this.multicall = options.multicall;
this.vault = options.vault;
this.poolDataQueries = options.poolDataQueries;
}

private filterPools(pools: Pool[]): Pool[] {
Expand All @@ -64,10 +64,10 @@ export class PoolsSubgraphOnChainRepository
console.timeEnd('fetching pools SG');
const filteredPools = this.filterPools(pools);
console.time(`fetching onchain ${filteredPools.length} pools`);
const onchainPools = await getOnChainBalances(
const onchainPools = await getOnChainPools(
filteredPools,
this.poolDataQueries,
this.multicall,
this.vault,
this.provider
);
console.timeEnd(`fetching onchain ${filteredPools.length} pools`);
Expand All @@ -81,10 +81,10 @@ export class PoolsSubgraphOnChainRepository
console.timeEnd('fetching pools SG');
const filteredPools = this.filterPools(pools);
console.time(`fetching onchain ${filteredPools.length} pools`);
const onchainPools = await getOnChainBalances(
const onchainPools = await getOnChainPools(
filteredPools,
this.poolDataQueries,
this.multicall,
this.vault,
this.provider
);
console.timeEnd(`fetching onchain ${filteredPools.length} pools`);
Expand Down Expand Up @@ -123,10 +123,10 @@ export class PoolsSubgraphOnChainRepository
}

async refresh(pool: Pool): Promise<Pool> {
const onchainPool = await getOnChainBalances(
const onchainPool = await getOnChainPools(
[pool],
this.poolDataQueries,
this.multicall,
this.vault,
this.provider
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ import { expect } from 'chai';
import { Network } from '@/.';
import { BigNumber, parseFixed } from '@ethersproject/bignumber';
import { accuracy } from '@/test/lib/utils';
import { ADDRESSES } from '@/test/lib/constants';
import { ADDRESSES, TEST_BLOCK } from '@/test/lib/constants';
import { testFlow } from './testHelper';

dotenv.config();

const TEST_BBAUSD3 = true;

const blockNo = TEST_BLOCK[Network.MAINNET];

describe('generalised exit execution', async function () {
this.timeout(120000); // Sets timeout for all tests within this scope to 2 minutes

context('ERC4626 - bbausd3', async () => {
if (!TEST_BBAUSD3) return true;
const network = Network.MAINNET;
const blockNo = 17223300;
const pool = ADDRESSES[network].bbausd3;
const slippage = '10'; // 10 bps = 0.1%
let unwrappingTokensAmountsOut: string[];
Expand All @@ -30,7 +31,7 @@ describe('generalised exit execution', async function () {

const amountRatio = 10;
// Amount greater than the underlying main token balance, which will cause the exit to be unwrapped
const unwrapExitAmount = parseFixed('6000000', pool.decimals);
const unwrapExitAmount = parseFixed('10000000', pool.decimals);
// Amount smaller than the underlying main token balance, which will cause the exit to be done directly
const mainExitAmount = unwrapExitAmount.div(amountRatio);

Expand All @@ -40,7 +41,7 @@ describe('generalised exit execution', async function () {
pool,
slippage,
unwrapExitAmount.toString(),
[ADDRESSES[network].USDC.address],
[ADDRESSES[network].DAI.address],
network,
blockNo,
poolAddresses
Expand Down Expand Up @@ -85,7 +86,6 @@ describe('generalised exit execution', async function () {

context('GearboxLinear - bbgusd', async () => {
const network = Network.MAINNET;
const blockNo = 17263241;
const pool = ADDRESSES[network].bbgusd;
const slippage = '10'; // 10 bps = 0.1%
let unwrappingTokensAmountsOut: string[];
Expand All @@ -108,7 +108,7 @@ describe('generalised exit execution', async function () {
pool,
slippage,
unwrapExitAmount.toString(),
[ADDRESSES[network].DAI.address, ADDRESSES[network].USDC.address],
[ADDRESSES[network].USDC.address],
network,
blockNo,
poolAddresses
Expand Down Expand Up @@ -153,7 +153,6 @@ describe('generalised exit execution', async function () {

context('AaveLinear - bbausd', async () => {
const network = Network.MAINNET;
const blockNo = 17263241;
const pool = ADDRESSES[network].bbausd2;
const slippage = '10'; // 10 bps = 0.1%
let unwrappingTokensAmountsOut: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const poolAddresses = Object.values(ADDRESSES[network]).map(
);
const addresses = ADDRESSES[network];

describe('generalised exit execution', async function () {
describe.skip('generalised exit execution', async function () {
this.timeout(120000); // Sets timeout for all tests within this scope to 2 minutes

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import dotenv from 'dotenv';
import { parseFixed } from '@ethersproject/bignumber';
import { Network } from '@/.';
import { ADDRESSES } from '@/test/lib/constants';
import { ADDRESSES, TEST_BLOCK } from '@/test/lib/constants';
import { testFlow, Pool } from './testHelper';

dotenv.config();

const network = Network.MAINNET;
const blockNumber = 17116836;
const blockNumber = TEST_BLOCK[network];
const slippage = '10'; // 10 bps = 0.1%
const addresses = ADDRESSES[network];
const poolAddresses = Object.values(addresses).map(
Expand Down
13 changes: 9 additions & 4 deletions balancer-js/src/modules/joins/joins.module.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { BalancerSDK, GraphQLQuery, Network, SimulationType } from '@/.';
import { parseFixed } from '@ethersproject/bignumber';
import { JsonRpcProvider } from '@ethersproject/providers';
import { FORK_NODES, createSubgraphQuery, forkSetup } from '@/test/lib/utils';
import { ADDRESSES, TestAddress, TestAddresses } from '@/test/lib/constants';
import {
ADDRESSES,
TEST_BLOCK,
TestAddress,
TestAddresses,
} from '@/test/lib/constants';
import { JsonRpcSigner } from '@ethersproject/providers';
import { RPC_URLS } from '@/test/lib/utils';
import { AddressZero } from '@ethersproject/constants';
Expand Down Expand Up @@ -71,7 +76,7 @@ describe('generalised join execution', async function () {
context('mainnet', async () => {
before(async () => {
network = Network.MAINNET;
blockNumber = 17316477;
blockNumber = TEST_BLOCK[network];
jsonRpcUrl = FORK_NODES[network];
rpcUrl = RPC_URLS[network];
const provider = new JsonRpcProvider(rpcUrl, network);
Expand Down Expand Up @@ -195,7 +200,7 @@ describe('generalised join execution', async function () {
});
});

context('goerli', async () => {
context.skip('goerli', async () => {
before(async () => {
network = Network.GOERLI;
blockNumber = 8744170;
Expand Down Expand Up @@ -1080,7 +1085,7 @@ describe('generalised join execution', async function () {
context.skip('arbitrum', async () => {
before(async () => {
network = Network.ARBITRUM;
blockNumber = 79069597;
blockNumber = TEST_BLOCK[network];
jsonRpcUrl = FORK_NODES[network];
rpcUrl = RPC_URLS[network];
const provider = new JsonRpcProvider(rpcUrl, network);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
testExactTokensOut,
testRecoveryExit,
} from '@/test/lib/exitHelper';
import { TEST_BLOCK } from '@/test/lib/constants';

dotenv.config();

Expand All @@ -24,7 +25,7 @@ const { ALCHEMY_URL: jsonRpcUrl } = process.env;
const rpcUrl = 'http://127.0.0.1:8545';
const provider = new ethers.providers.JsonRpcProvider(rpcUrl, network);
const signer = provider.getSigner();
const blockNumber = 16350000;
const blockNumber = TEST_BLOCK[network];
const testPoolId =
'0xa13a9247ea42d743238089903570127dda72fe4400000000000000000000035d';
let pool: PoolWithMethods;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
testExactTokensOut,
testRecoveryExit,
} from '@/test/lib/exitHelper';
import { TEST_BLOCK } from '@/test/lib/constants';

dotenv.config();

Expand All @@ -26,7 +27,7 @@ const provider = new ethers.providers.JsonRpcProvider(rpcUrl, network);
const signer = provider.getSigner();
const testPoolId =
'0x373b347bc87998b151a5e9b6bb6ca692b766648a000000000000000000000923';
const blockNumber = 40818844;
const blockNumber = TEST_BLOCK[network];
let pool: PoolWithMethods;

describe('ComposableStableV2 Exits', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@/.';
import { forkSetup, getPoolFromFile, updateFromChain } from '@/test/lib/utils';
import { testExactBptIn, testExactTokensOut } from '@/test/lib/exitHelper';
import { TEST_BLOCK } from '@/test/lib/constants';

dotenv.config();

Expand All @@ -20,7 +21,7 @@ const { ALCHEMY_URL: jsonRpcUrl } = process.env;
const rpcUrl = 'http://127.0.0.1:8545';
const provider = new JsonRpcProvider(rpcUrl, network);
const signer = provider.getSigner();
const blockNumber = 16649181;
const blockNumber = TEST_BLOCK[network];

// wstETH-rETH-sfrxETH-BPT
const testPoolId =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@/.';
import { forkSetup, getPoolFromFile, updateFromChain } from '@/test/lib/utils';
import { testExactBptIn, testExactTokensOut } from '@/test/lib/exitHelper';
import { TEST_BLOCK } from '@/test/lib/constants';

dotenv.config();

Expand All @@ -20,7 +21,7 @@ const { ALCHEMY_URL: jsonRpcUrl } = process.env;
const rpcUrl = 'http://127.0.0.1:8545';
const provider = new JsonRpcProvider(rpcUrl, network);
const signer = provider.getSigner();
const blockNumber = 17280000;
const blockNumber = TEST_BLOCK[network];

// wstETH-rETH-sfrxETH-BPT
const testPoolId =
Expand Down
Loading