Skip to content

Commit

Permalink
fix: staking boost on L2s
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco committed Oct 5, 2023
1 parent 5c3a117 commit af29efc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions balancer-js/src/modules/data/liquidity-gauges/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ export class LiquidityGaugeSubgraphRPCProvider
childGaugeAddresses
);
console.timeEnd('Fetching multicall.inflationRates');
console.time('Fetching multicall.getWorkingSupplies');
this.workingSupplies = await this.multicall.getWorkingSupplies(
childGaugeAddresses
);
console.timeEnd('Fetching multicall.getWorkingSupplies');
}
}
if (this.gaugeController) {
Expand Down
9 changes: 4 additions & 5 deletions balancer-js/src/modules/pools/apr/apr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,15 @@ export class PoolApr {
throw 'Missing BAL price';
}

const gaugeSupply = (gauge.workingSupply + 0.4) / 0.4; // Only 40% of LP token staked accrue emissions, totalSupply = workingSupply * 2.5
const gaugeSupplyUsd = gaugeSupply * bptPriceUsd;

// Handle child chain gauges with inflation_rate
// balInflationRate - amount of BAL tokens per second as a float
if (gauge.balInflationRate) {
const reward =
gauge.balInflationRate * 86400 * 365 * parseFloat(balPrice.usd);
const totalSupplyUsd = gauge.totalSupply * bptPriceUsd;
const rewardValue = reward / totalSupplyUsd;
return Math.round(boost * 10000 * rewardValue);
return Math.round((boost * 10000 * reward) / gaugeSupplyUsd);
} else if (pool.chainId > 1) {
// TODO: remove after all gauges are migrated (around 01-07-2023), Subgraph is returning BAL staking rewards as reward tokens for L2 gauges.
if (!gauge.rewardTokens) {
Expand All @@ -307,8 +308,6 @@ export class PoolApr {
const totalBalEmissions = (emissions.weekly(now) / 7) * 365;
const gaugeBalEmissions = totalBalEmissions * gauge.relativeWeight;
const gaugeBalEmissionsUsd = gaugeBalEmissions * balPriceUsd;
const gaugeSupply = (gauge.workingSupply + 0.4) / 0.4; // Only 40% of LP token staked accrue emissions, totalSupply = workingSupply * 2.5
const gaugeSupplyUsd = gaugeSupply * bptPriceUsd;
const gaugeBalAprBps = Math.round(
(boost * 10000 * gaugeBalEmissionsUsd) / gaugeSupplyUsd
);
Expand Down

0 comments on commit af29efc

Please sign in to comment.