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

fix: decimals in gauge rewards #468

Merged
merged 1 commit into from
Oct 6, 2023
Merged
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
8 changes: 6 additions & 2 deletions modules/pool/lib/staking/gauge-staking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class GaugeStakingService implements PoolStakingService {
await prismaBulkExecuteOperations(operations, true, undefined);
}

private async getOnchainRewardTokensData(gauges: { id: string; version: 1 | 2; tokens: { id: string }[] }[]) {
private async getOnchainRewardTokensData(gauges: { id: string; version: 1 | 2; tokens: { id: string, decimals: number }[] }[]) {
// Get onchain data for BAL rewards
const currentWeek = Math.floor(Date.now() / 1000 / 604800);
for (const gauge of gauges) {
Expand All @@ -227,9 +227,11 @@ export class GaugeStakingService implements PoolStakingService {
const balData = (await this.balMulticaller.execute()) as GaugeBalDistributionData;

// Get onchain data for reward tokens
const decimals: { [address: string]: number } = {};
for (const gauge of gauges) {
for (const token of gauge.tokens ?? []) {
const [address] = token.id.toLowerCase().split('-');
decimals[address] = token.decimals;
if (gauge.version === 1) {
this.rewardsMulticallerV1.call(
`${gauge.id}.rewardData.${address}`,
Expand Down Expand Up @@ -281,7 +283,7 @@ export class GaugeStakingService implements PoolStakingService {
const id = `${gaugeAddress}-${tokenAddress}`.toLowerCase();
const { rate, period_finish } = rewardsData[gaugeAddress].rewardData[tokenAddress];
const rewardPerSecond =
period_finish && period_finish.toNumber() > now ? formatUnits(rate!) : '0.0';
period_finish && period_finish.toNumber() > now ? formatUnits(rate!, decimals[tokenAddress]) : '0.0';
const { totalSupply } = balData[gaugeAddress];

return {
Expand All @@ -300,6 +302,8 @@ export class GaugeStakingService implements PoolStakingService {
totalSupply: string;
}[];

console.log(onchainRates)

return onchainRates;
}

Expand Down