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

Using gaugeControllerCheckpointer for mainnet network; #517

Merged
merged 2 commits into from
Aug 15, 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
2 changes: 2 additions & 0 deletions balancer-js/src/lib/constants/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const BALANCER_NETWORK_CONFIG: Record<Network, BalancerNetworkConfig> = {
poolDataQueries: '0xf5CDdF6feD9C589f1Be04899F48f9738531daD59',
lidoRelayer: '0xdcdbf71A870cc60C6F9B621E28a7D3Ffd6Dd4965',
veBal: '0xC128a9954e6c874eA3d62ce62B468bA073093F25',
gaugeControllerCheckpointer:
'0x8e5698dc4897dc12243c8642e77b4f21349db97c',
veBalProxy: '0x6f5a2eE11E7a772AeB5114A20d0D7c0ff61EB8A0',
gyroConfigProxy: '0xac89cc9d78bbad7eb3a02601b4d65daa1f908aa6',
...addressesByNetwork[Network.MAINNET].contracts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
33 changes: 25 additions & 8 deletions balancer-js/src/modules/data/gauge-controller/multicall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion balancer-js/src/modules/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
6 changes: 4 additions & 2 deletions balancer-js/src/modules/data/liquidity-gauges/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading