Skip to content

Commit

Permalink
take tokens decimals into account for gauge reward rate
Browse files Browse the repository at this point in the history
  • Loading branch information
franzns committed Sep 8, 2023
1 parent 8634adc commit e9a9791
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions modules/pool/lib/staking/gauge-staking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,22 @@ export class GaugeStakingService implements PoolStakingService {
}
}
if (gauge.tokens) {
const rewardTokens = await prisma.prismaToken.findMany({
where: {
address: { in: gauge.tokens.map((token) => token.id.split('-')[0].toLowerCase()) },
chain: networkContext.chain,
},
});
for (let rewardToken of gauge.tokens) {
const tokenAddress = rewardToken.id.split('-')[0].toLowerCase();
const token = rewardTokens.find((token) => token.address === tokenAddress);
if (!token) {
console.error(
`Could not find reward token (${tokenAddress}) in DB for gauge ${gauge.id} of pool ${pool.id}`,
);
continue;
}

const id = `${gauge.id}-${tokenAddress}`;

let rewardRate = '0.0';
Expand All @@ -124,7 +138,7 @@ export class GaugeStakingService implements PoolStakingService {
periodFinish = rewardData[2];
if (periodFinish > moment().unix()) {
// period still running
rewardRate = formatFixed(rewardData[3], 18);
rewardRate = formatFixed(rewardData[3], token.decimals);
}
} else {
// we can't get BAL rate from the reward data but got it from the inflation_rate call which set the rewardToken.rate
Expand All @@ -137,7 +151,7 @@ export class GaugeStakingService implements PoolStakingService {
periodFinish = parseFloat(formatUnits(rewardData[1], 0));
if (periodFinish > moment().unix()) {
// period still running
rewardRate = formatFixed(rewardData[2], 18);
rewardRate = formatFixed(rewardData[2], token.decimals);
}
}
}
Expand Down

0 comments on commit e9a9791

Please sign in to comment.