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

fix(vvs-finance): add labels and xVVS token balance #687

Merged
merged 2 commits into from
Jun 21, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class CronosVvsFinanceAutoVvsMineContractPositionFetcher implements Posit
resolveTotalAllocPoints: ({ multicall }) => multicall.wrap(chefContract).totalAllocPoint(),
resolveTotalRewardRate: ({ multicall }) => multicall.wrap(chefContract).vvsPerBlock(),
}),
resolveLabel: () => 'Auto VVS mine (compounding)',
});
}
}
41 changes: 31 additions & 10 deletions src/apps/vvs-finance/cronos/vvs-finance.balance-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ export class CronosVvsFinanceBalanceFetcher implements BalanceFetcher {
});
}

private async getXvvsBalances(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
address,
appId,
network,
groupId: VVS_FINANCE_DEFINITION.groups.xvvs.id,
});
}

private async getXvvsVaultBalances(address: string) {
const multicall = this.appToolkit.getMulticall(network);
const contractPositions = await this.appToolkit.getAppContractPositions<XvvsVaultContractPositionDataProps>({
Expand Down Expand Up @@ -176,15 +185,23 @@ export class CronosVvsFinanceBalanceFetcher implements BalanceFetcher {
}

async getBalances(address: string) {
const [poolBalances, farmBalances, farmV2Balances, autoVvsMineBalances, mineBalances, xvvsVaultBalances] =
await Promise.all([
this.getPoolBalances(address),
this.getFarmBalances(address),
this.getFarmV2Balances(address),
this.getAutoVvsMineBalances(address),
this.getMineBalances(address),
this.getXvvsVaultBalances(address),
]);
const [
poolBalances,
farmBalances,
farmV2Balances,
autoVvsMineBalances,
mineBalances,
xvvsBalances,
xvvsVaultBalances,
] = await Promise.all([
this.getPoolBalances(address),
this.getFarmBalances(address),
this.getFarmV2Balances(address),
this.getAutoVvsMineBalances(address),
this.getMineBalances(address),
this.getXvvsBalances(address),
this.getXvvsVaultBalances(address),
]);

return presentBalanceFetcherResponse([
{
Expand All @@ -208,7 +225,11 @@ export class CronosVvsFinanceBalanceFetcher implements BalanceFetcher {
assets: mineBalances,
},
{
label: 'xVVS Vault',
label: 'xVVS',
assets: xvvsBalances,
},
{
label: 'xVVS Vaults',
assets: xvvsVaultBalances,
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { compact } from 'lodash';
import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper';
import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';
Expand Down Expand Up @@ -113,6 +114,8 @@ export class CronosVvsFinanceFarmV2ContractPositionFetcher implements PositionFe
resolveTotalRewardRate: async ({ poolIndex }) =>
poolRecords[poolIndex].rewards.map(r => r.rewardPerSecond).reduce((p, c) => p.add(c), BigNumber.from(0)),
}),
resolveLabel: ({ stakedToken, rewardTokens }) =>
`Staked ${getLabelFromToken(stakedToken)} for ${rewardTokens.map(getLabelFromToken).join(', ')} farm`,
});

return positions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Inject } from '@nestjs/common';
import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper';
import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';
Expand Down Expand Up @@ -51,9 +52,22 @@ export class CronosVvsFinanceFarmContractPositionFetcher implements PositionFetc
return multicall.wrap(contract).vvsPerBlock();
},
}),
resolveLabel: ({ stakedToken, rewardTokens }) =>
`Staked ${getLabelFromToken(stakedToken)} for ${rewardTokens.map(getLabelFromToken).join(', ')} farm`,
},
);

return positions;
return positions.map(position => {
if (position.dataProps.poolIndex === 0) {
return {
...position,
displayProps: {
...position.displayProps,
label: 'Manual VVS mine',
},
};
}
return position;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import request, { gql } from 'graphql-request';
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { Register } from '~app-toolkit/decorators';
import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper';
import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';
Expand Down Expand Up @@ -93,6 +94,8 @@ export class CronosVvsFinanceMinesContractPositionFetcher implements PositionFet
return multicall.wrap(contract).rewardPerBlock();
},
}),
resolveLabel: ({ stakedToken, rewardTokens }) =>
`Staked ${getLabelFromToken(stakedToken)} for ${rewardTokens.map(getLabelFromToken).join(', ')} mine`,
});
}
}