Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
fix(aura): Fix LP Farms underlying tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
wpoulin committed Sep 27, 2023
1 parent c5a3983 commit a5ee5b4
Show file tree
Hide file tree
Showing 11 changed files with 2,512 additions and 821 deletions.
2 changes: 1 addition & 1 deletion src/apps/aura/aura.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import { OptimismAuraDepositTokenFetcher } from './optimism/aura.deposit.token-f
ArbitrumAuraDepositTokenFetcher,
// Ethereum
EthereumAuraAuraBalTokenFetcher,
EthereumAuraDepositTokenFetcher,
EthereumAuraChefContractPositionFetcher,
EthereumAuraDepositTokenFetcher,
EthereumAuraLpFarmContractPositionFetcher,
EthereumAuraLockerContractPositionFetcher,
EthereumAuraAuraBalStakingContractPositionFetcher,
Expand Down
63 changes: 55 additions & 8 deletions src/apps/aura/common/aura.farm.contract-position-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Inject } from '@nestjs/common';
import { BigNumber, BigNumberish } from 'ethers';
import { range } from 'lodash';
import { compact, range } from 'lodash';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { isClaimable } from '~position/position.utils';
Expand Down Expand Up @@ -97,11 +97,33 @@ export abstract class AuraFarmContractPositionFetcher extends SingleStakingFarmD
range(0, Number(await contract.extraRewardsLength())).map(async v => {
const vbpAddress = await contract.extraRewards(v);
const vbp = this.contractFactory.auraVirtualBalanceRewardPool({ address: vbpAddress, network: this.network });
return multicall.wrap(vbp).rewardToken();
const stashTokenAddressRaw = await multicall.wrap(vbp).rewardToken();
let rewardTokenAddress = stashTokenAddressRaw.toLowerCase();

const stashTokenContract = this.contractFactory.auraStashToken({
address: rewardTokenAddress,
network: this.network,
});

const isStash = await multicall
.wrap(stashTokenContract)
.stash()
.then(() => true)
.catch(() => false);

if (isStash) {
const rewardTokenAddressRaw = await multicall.wrap(stashTokenContract).baseToken();
rewardTokenAddress = rewardTokenAddressRaw.toLowerCase();
}

// We will combine AURA extra rewards with the amount minted
if (rewardTokenAddress === primaryRewardTokenAddresses[1]) return null;

return rewardTokenAddress;
}),
);

return [...primaryRewardTokenAddresses, ...extraRewardTokenAddresses];
return [...primaryRewardTokenAddresses, ...compact(extraRewardTokenAddresses)];
}

async getRewardRates({
Expand Down Expand Up @@ -139,28 +161,53 @@ export abstract class AuraFarmContractPositionFetcher extends SingleStakingFarmD
multicall,
}: GetTokenBalancesParams<AuraBaseRewardPool>) {
const rewardTokens = contractPosition.tokens.filter(isClaimable);
const [, auraRewardToken, ...extraRewards] = rewardTokens;
const [, auraRewardToken] = rewardTokens;

const auraTokenContract = multicall.wrap(this.contractFactory.erc20(auraRewardToken));
const currentAuraSupply = await auraTokenContract.totalSupply();

const balBalanceBN = await contract.earned(address);
const balBalanceRaw = balBalanceBN.toString();
const auraBalanceRaw = claimedBalToMintedAura(balBalanceRaw, currentAuraSupply.toString());
let auraBalanceRaw = claimedBalToMintedAura(balBalanceRaw, currentAuraSupply.toString());

const numExtraRewards = await multicall.wrap(contract).extraRewardsLength();
const extraRewardBalances = await Promise.all(
extraRewards.map(async (_, i) => {
range(0, Number(numExtraRewards)).map(async (_, i) => {
const extraRewardAddress = await contract.extraRewards(i);
const extraRewardContract = this.contractFactory.auraVirtualBalanceRewardPool({
address: extraRewardAddress,
network: this.network,
});

const earnedBN = await multicall.wrap(extraRewardContract).earned(address);
return earnedBN.toString();
const extraRewardStashTokenAddressRaw = await multicall.wrap(extraRewardContract).rewardToken();
let extraRewardStashTokenAddress = extraRewardStashTokenAddressRaw.toLowerCase();
const stashTokenContract = this.contractFactory.auraStashToken({
address: extraRewardStashTokenAddress,
network: this.network,
});

const isStash = await multicall
.wrap(stashTokenContract)
.stash()
.then(() => true)
.catch(() => false);

if (isStash) {
const extraRewardTokenAddressRaw = await multicall.wrap(stashTokenContract).baseToken();
extraRewardStashTokenAddress = extraRewardTokenAddressRaw.toLowerCase();
}

// We will combine AURA extra rewards with the amount minted
if (extraRewardStashTokenAddress === auraRewardToken.address) {
auraBalanceRaw = auraBalanceRaw.add(earnedBN);
return null;
}

return earnedBN;
}),
);

return [balBalanceRaw, auraBalanceRaw, ...extraRewardBalances];
return [balBalanceRaw, auraBalanceRaw, ...compact(extraRewardBalances)];
}
}
Loading

0 comments on commit a5ee5b4

Please sign in to comment.