diff --git a/balancer-js/src/lib/constants/config.ts b/balancer-js/src/lib/constants/config.ts index cf04b5eda..062681c59 100644 --- a/balancer-js/src/lib/constants/config.ts +++ b/balancer-js/src/lib/constants/config.ts @@ -18,6 +18,8 @@ export const BALANCER_NETWORK_CONFIG: Record = { poolDataQueries: '0xf5CDdF6feD9C589f1Be04899F48f9738531daD59', lidoRelayer: '0xdcdbf71A870cc60C6F9B621E28a7D3Ffd6Dd4965', veBal: '0xC128a9954e6c874eA3d62ce62B468bA073093F25', + gaugeControllerCheckpointer: + '0x8e5698dc4897dc12243c8642e77b4f21349db97c', veBalProxy: '0x6f5a2eE11E7a772AeB5114A20d0D7c0ff61EB8A0', gyroConfigProxy: '0xac89cc9d78bbad7eb3a02601b4d65daa1f908aa6', ...addressesByNetwork[Network.MAINNET].contracts, diff --git a/balancer-js/src/modules/data/gauge-controller/multicall.spec.ts b/balancer-js/src/modules/data/gauge-controller/multicall.spec.ts index 62e5043c4..71510ab09 100644 --- a/balancer-js/src/modules/data/gauge-controller/multicall.spec.ts +++ b/balancer-js/src/modules/data/gauge-controller/multicall.spec.ts @@ -8,7 +8,8 @@ describe('Gauge controller', () => { const { contracts } = new Contracts(1, provider); const fetcher = new GaugeControllerMulticallRepository( contracts.multicall, - '0xc128468b7ce63ea702c1f104d55a2566b13d3abd' + '0xc128468b7ce63ea702c1f104d55a2566b13d3abd', + '0x8e5698dc4897dc12243c8642e77b4f21349db97c' ); it('is fetching relative weights for current period', async () => { diff --git a/balancer-js/src/modules/data/gauge-controller/multicall.ts b/balancer-js/src/modules/data/gauge-controller/multicall.ts index 4eee738c1..77295cddb 100644 --- a/balancer-js/src/modules/data/gauge-controller/multicall.ts +++ b/balancer-js/src/modules/data/gauge-controller/multicall.ts @@ -7,23 +7,40 @@ const gaugeControllerInterface = new Interface([ 'function gauge_relative_weight(address gauge, uint timestamp) view returns (uint)', ]); +const gaugeControllerCheckpointerInterface = new Interface([ + 'function gauge_relative_weight(address gauge) view returns (uint)', +]); + export class GaugeControllerMulticallRepository { constructor( private multicall: Multicall, - private gaugeControllerAddress: string + private gaugeControllerAddress: string, + private gaugeControllerCheckpointerAddress?: string ) {} async getRelativeWeights( gaugeAddresses: string[], timestamp?: number ): Promise<{ [gaugeAddress: string]: number }> { - const payload = gaugeAddresses.map((gaugeAddress) => ({ - target: this.gaugeControllerAddress, - callData: gaugeControllerInterface.encodeFunctionData( - 'gauge_relative_weight', - [getAddress(gaugeAddress), timestamp || Math.floor(Date.now() / 1000)] - ), - })); + const payload = gaugeAddresses.map((gaugeAddress) => { + // The checkpointer only exists for mainnet, if the network is a testnet, it'll use the regular gauge controller + if (this.gaugeControllerCheckpointerAddress && !timestamp) { + return { + target: this.gaugeControllerCheckpointerAddress, + callData: gaugeControllerCheckpointerInterface.encodeFunctionData( + 'gauge_relative_weight', + [getAddress(gaugeAddress)] + ), + }; + } + return { + target: this.gaugeControllerAddress, + callData: gaugeControllerInterface.encodeFunctionData( + 'gauge_relative_weight', + [getAddress(gaugeAddress), timestamp || Math.floor(Date.now() / 1000)] + ), + }; + }); const [, res] = await this.multicall.callStatic.aggregate(payload); const weights = gaugeAddresses.reduce( diff --git a/balancer-js/src/modules/data/index.ts b/balancer-js/src/modules/data/index.ts index 34702db35..c7b83dae0 100644 --- a/balancer-js/src/modules/data/index.ts +++ b/balancer-js/src/modules/data/index.ts @@ -199,7 +199,8 @@ export class Data implements BalancerDataRepositories { networkConfig.urls.gaugesSubgraph, contracts.contracts.multicall, networkConfig.addresses.contracts.gaugeController || '', - networkConfig.chainId + networkConfig.chainId, + networkConfig.addresses.contracts.gaugeControllerCheckpointer ); } diff --git a/balancer-js/src/modules/data/liquidity-gauges/provider.ts b/balancer-js/src/modules/data/liquidity-gauges/provider.ts index e30fd438d..126b01559 100644 --- a/balancer-js/src/modules/data/liquidity-gauges/provider.ts +++ b/balancer-js/src/modules/data/liquidity-gauges/provider.ts @@ -43,12 +43,14 @@ export class LiquidityGaugeSubgraphRPCProvider subgraphUrl: string, multicall: Multicall, gaugeControllerAddress: string, - private chainId: Network + private chainId: Network, + gaugeControllerCheckpointerAddress?: string ) { if (gaugeControllerAddress) { this.gaugeController = new GaugeControllerMulticallRepository( multicall, - gaugeControllerAddress + gaugeControllerAddress, + gaugeControllerCheckpointerAddress ); } this.multicall = new LiquidityGaugesMulticallRepository(multicall, chainId);