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

Commit

Permalink
feat(curve): Added liquidity data prop and enabled TVL (#603)
Browse files Browse the repository at this point in the history
Co-authored-by: immasandwich <karan.shahani91@gmail.com>
  • Loading branch information
wpoulin and immasandwich committed Jun 14, 2022
1 parent 055fd62 commit 548055f
Show file tree
Hide file tree
Showing 20 changed files with 87 additions and 52 deletions.
8 changes: 5 additions & 3 deletions src/apps/curve/arbitrum/curve.balance-fetcher.ts
Expand Up @@ -10,6 +10,8 @@ import { Network } from '~types/network.interface';
import { CurveChildLiquidityGauge, CurveContractFactory, CurveRewardsOnlyGauge } from '../contracts';
import { CURVE_DEFINITION } from '../curve.definition';

const network = Network.ARBITRUM_MAINNET;

@Register.BalanceFetcher(CURVE_DEFINITION.id, Network.ARBITRUM_MAINNET)
export class ArbitrumCurveBalanceFetcher implements BalanceFetcher {
constructor(
Expand All @@ -19,7 +21,7 @@ export class ArbitrumCurveBalanceFetcher implements BalanceFetcher {

private async getPoolTokenBalances(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
network: Network.ARBITRUM_MAINNET,
network,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.pool.id,
address,
Expand All @@ -31,7 +33,7 @@ export class ArbitrumCurveBalanceFetcher implements BalanceFetcher {
address,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.farm.id,
network: Network.ARBITRUM_MAINNET,
network,
farmFilter: v => v.dataProps.implementation === 'rewards-only-gauge',
resolveContract: ({ address, network }) => this.curveContractFactory.curveRewardsOnlyGauge({ address, network }),
resolveStakedTokenBalance: ({ contract, address, multicall }) => multicall.wrap(contract).balanceOf(address),
Expand All @@ -48,7 +50,7 @@ export class ArbitrumCurveBalanceFetcher implements BalanceFetcher {
address,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.farm.id,
network: Network.ARBITRUM_MAINNET,
network,
farmFilter: v => v.dataProps.implementation === 'child-liquidity-gauge',
resolveContract: ({ address, network }) =>
this.curveContractFactory.curveChildLiquidityGauge({ address, network }),
Expand Down
2 changes: 1 addition & 1 deletion src/apps/curve/arbitrum/curve.pool.token-fetcher.ts
Expand Up @@ -16,7 +16,7 @@ const appId = CURVE_DEFINITION.id;
const groupId = CURVE_DEFINITION.groups.pool.id;
const network = Network.ARBITRUM_MAINNET;

@Register.TokenPositionFetcher({ appId, groupId, network })
@Register.TokenPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } })
export class ArbitrumCurvePoolTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(CurveV1PoolTokenHelper)
Expand Down
8 changes: 5 additions & 3 deletions src/apps/curve/avalanche/curve.balance-fetcher.ts
Expand Up @@ -10,6 +10,8 @@ import { Network } from '~types/network.interface';
import { CurveChildLiquidityGauge, CurveContractFactory, CurveRewardsOnlyGauge } from '../contracts';
import { CURVE_DEFINITION } from '../curve.definition';

const network = Network.AVALANCHE_MAINNET;

@Register.BalanceFetcher(CURVE_DEFINITION.id, Network.AVALANCHE_MAINNET)
export class AvalancheCurveBalanceFetcher implements BalanceFetcher {
constructor(
Expand All @@ -19,7 +21,7 @@ export class AvalancheCurveBalanceFetcher implements BalanceFetcher {

private async getPoolTokenBalances(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
network: Network.AVALANCHE_MAINNET,
network,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.pool.id,
address,
Expand All @@ -31,7 +33,7 @@ export class AvalancheCurveBalanceFetcher implements BalanceFetcher {
address,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.farm.id,
network: Network.AVALANCHE_MAINNET,
network,
farmFilter: v => v.dataProps.implementation === 'rewards-only-gauge',
resolveContract: ({ address, network }) => this.curveContractFactory.curveRewardsOnlyGauge({ address, network }),
resolveStakedTokenBalance: ({ contract, address, multicall }) => multicall.wrap(contract).balanceOf(address),
Expand All @@ -48,7 +50,7 @@ export class AvalancheCurveBalanceFetcher implements BalanceFetcher {
address,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.farm.id,
network: Network.AVALANCHE_MAINNET,
network,
farmFilter: v => v.dataProps.implementation === 'child-liquidity-gauge',
resolveContract: ({ address, network }) =>
this.curveContractFactory.curveChildLiquidityGauge({ address, network }),
Expand Down
2 changes: 1 addition & 1 deletion src/apps/curve/avalanche/curve.pool.token-fetcher.ts
Expand Up @@ -16,7 +16,7 @@ const appId = CURVE_DEFINITION.id;
const groupId = CURVE_DEFINITION.groups.pool.id;
const network = Network.AVALANCHE_MAINNET;

@Register.TokenPositionFetcher({ appId, groupId, network })
@Register.TokenPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } })
export class AvalancheCurvePoolTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(CurveV1PoolTokenHelper)
Expand Down
4 changes: 2 additions & 2 deletions src/apps/curve/curve.definition.ts
Expand Up @@ -17,8 +17,8 @@ export const CURVE_DEFINITION = appDefinition({
groups: {
farm: { id: 'farm', type: GroupType.POSITION, label: 'Staking', groupLabel: 'Farms' },
pool: { id: 'pool', type: GroupType.TOKEN, label: 'Pools' },
votingEscrow: { id: 'votingEscrow', type: GroupType.POSITION, label: 'Voting Escrow' },
vestingEscrow: { id: 'vestingEscrow', type: GroupType.POSITION, label: 'Vesting' },
votingEscrow: { id: 'voting-escrow', type: GroupType.POSITION, label: 'Voting Escrow' },
vestingEscrow: { id: 'vesting-escrow', type: GroupType.POSITION, label: 'Vesting' },
},
tags: [AppTag.LIQUIDITY_POOL],
supportedNetworks: {
Expand Down
10 changes: 5 additions & 5 deletions src/apps/curve/ethereum/curve.pool.token-fetcher.ts
Expand Up @@ -25,7 +25,7 @@ const appId = CURVE_DEFINITION.id;
const groupId = CURVE_DEFINITION.groups.pool.id;
const network = Network.ETHEREUM_MAINNET;

@Register.TokenPositionFetcher({ appId, groupId, network })
@Register.TokenPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } })
export class EthereumCurvePoolTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(CurveV1PoolTokenHelper)
Expand Down Expand Up @@ -67,7 +67,7 @@ export class EthereumCurvePoolTokenFetcher implements PositionFetcher<AppTokenPo
statsUrl: 'https://stats.curve.fi/raw-stats/apys.json',
}),
this.curveV2PoolTokenHelper.getTokens({
network: Network.ETHEREUM_MAINNET,
network,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.pool.id,
baseCurveTokens: v1Pools,
Expand All @@ -76,14 +76,14 @@ export class EthereumCurvePoolTokenFetcher implements PositionFetcher<AppTokenPo
}),
this.curveFactoryPoolTokenHelper.getTokens({
factoryAddress: '0x0959158b6040d32d04c301a72cbfd6b39e21c9ae',
network: Network.ETHEREUM_MAINNET,
network,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.pool.id,
baseCurveTokens: v1Pools,
}),
this.curveFactoryPoolTokenHelper.getTokens({
factoryAddress: '0xb9fc157394af804a3578134a6585c0dc9cc990d4',
network: Network.ETHEREUM_MAINNET,
network,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.pool.id,
baseCurveTokens: v1Pools,
Expand All @@ -104,7 +104,7 @@ export class EthereumCurvePoolTokenFetcher implements PositionFetcher<AppTokenPo
}),
this.curveCryptoFactoryPoolTokenHelper.getTokens({
factoryAddress: '0xf18056bbd320e96a48e3fbf8bc061322531aac99',
network: Network.ETHEREUM_MAINNET,
network,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.pool.id,
baseCurveTokens: v1Pools,
Expand Down
Expand Up @@ -9,19 +9,18 @@ import { CurveVestingEscrow } from '../contracts';
import { CURVE_DEFINITION } from '../curve.definition';
import { CurveVestingEscrowContractPositionHelper } from '../helpers/curve.vesting-escrow.contract-position-helper';

@Register.ContractPositionFetcher({
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.vestingEscrow.id,
network: Network.ETHEREUM_MAINNET,
})
const appId = CURVE_DEFINITION.id;
const groupId = CURVE_DEFINITION.groups.vestingEscrow.id;
const network = Network.ETHEREUM_MAINNET;

@Register.ContractPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } })
export class EthereumCurveVestingEscrowContractPositionFetcher implements PositionFetcher<ContractPosition> {
constructor(
@Inject(CurveVestingEscrowContractPositionHelper)
private readonly curveVestingEscrowContractPositionHelper: CurveVestingEscrowContractPositionHelper,
) {}

async getPositions() {
const network = Network.ETHEREUM_MAINNET;
return this.curveVestingEscrowContractPositionHelper.getContractPositions<CurveVestingEscrow>({
vestingEscrowAddress: '0x575ccd8e2d300e2377b43478339e364000318e2c',
appId: CURVE_DEFINITION.id,
Expand Down
Expand Up @@ -9,19 +9,18 @@ import { CurveVotingEscrow, CurveVotingEscrowReward } from '../contracts';
import { CURVE_DEFINITION } from '../curve.definition';
import { CurveVotingEscrowContractPositionHelper } from '../helpers/curve.voting-escrow.contract-position-helper';

@Register.ContractPositionFetcher({
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.votingEscrow.id,
network: Network.ETHEREUM_MAINNET,
})
const appId = CURVE_DEFINITION.id;
const groupId = CURVE_DEFINITION.groups.votingEscrow.id;
const network = Network.ETHEREUM_MAINNET;

@Register.ContractPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } })
export class EthereumCurveVotingEscrowContractPositionFetcher implements PositionFetcher<ContractPosition> {
constructor(
@Inject(CurveVotingEscrowContractPositionHelper)
private readonly curveVotingEscrowContractPositionHelper: CurveVotingEscrowContractPositionHelper,
) {}

async getPositions() {
const network = Network.ETHEREUM_MAINNET;
return this.curveVotingEscrowContractPositionHelper.getContractPositions<
CurveVotingEscrow,
CurveVotingEscrowReward
Expand Down
8 changes: 5 additions & 3 deletions src/apps/curve/fantom/curve.balance-fetcher.ts
Expand Up @@ -10,6 +10,8 @@ import { Network } from '~types/network.interface';
import { CurveChildLiquidityGauge, CurveContractFactory, CurveRewardsOnlyGauge } from '../contracts';
import { CURVE_DEFINITION } from '../curve.definition';

const network = Network.FANTOM_OPERA_MAINNET;

@Register.BalanceFetcher(CURVE_DEFINITION.id, Network.FANTOM_OPERA_MAINNET)
export class FantomCurveBalanceFetcher implements BalanceFetcher {
constructor(
Expand All @@ -19,7 +21,7 @@ export class FantomCurveBalanceFetcher implements BalanceFetcher {

private async getPoolTokenBalances(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
network: Network.FANTOM_OPERA_MAINNET,
network,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.pool.id,
address,
Expand All @@ -31,7 +33,7 @@ export class FantomCurveBalanceFetcher implements BalanceFetcher {
address,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.farm.id,
network: Network.FANTOM_OPERA_MAINNET,
network,
farmFilter: v => v.dataProps.implementation === 'rewards-only-gauge',
resolveContract: ({ address, network }) => this.curveContractFactory.curveRewardsOnlyGauge({ address, network }),
resolveStakedTokenBalance: ({ contract, address, multicall }) => multicall.wrap(contract).balanceOf(address),
Expand All @@ -48,7 +50,7 @@ export class FantomCurveBalanceFetcher implements BalanceFetcher {
address,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.farm.id,
network: Network.FANTOM_OPERA_MAINNET,
network,
farmFilter: v => v.dataProps.implementation === 'child-liquidity-gauge',
resolveContract: ({ address, network }) =>
this.curveContractFactory.curveChildLiquidityGauge({ address, network }),
Expand Down
2 changes: 1 addition & 1 deletion src/apps/curve/fantom/curve.pool.token-fetcher.ts
Expand Up @@ -20,7 +20,7 @@ const appId = CURVE_DEFINITION.id;
const groupId = CURVE_DEFINITION.groups.pool.id;
const network = Network.FANTOM_OPERA_MAINNET;

@Register.TokenPositionFetcher({ appId, groupId, network })
@Register.TokenPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } })
export class FantomCurvePoolTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(CurveV1PoolTokenHelper)
Expand Down
8 changes: 5 additions & 3 deletions src/apps/curve/gnosis/curve.balance-fetcher.ts
Expand Up @@ -10,6 +10,8 @@ import { Network } from '~types/network.interface';
import { CurveChildLiquidityGauge, CurveContractFactory, CurveRewardsOnlyGauge } from '../contracts';
import { CURVE_DEFINITION } from '../curve.definition';

const network = Network.GNOSIS_MAINNET;

@Register.BalanceFetcher(CURVE_DEFINITION.id, Network.GNOSIS_MAINNET)
export class GnosisCurveBalanceFetcher implements BalanceFetcher {
constructor(
Expand All @@ -19,7 +21,7 @@ export class GnosisCurveBalanceFetcher implements BalanceFetcher {

private async getPoolTokenBalances(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
network: Network.GNOSIS_MAINNET,
network,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.pool.id,
address,
Expand All @@ -31,7 +33,7 @@ export class GnosisCurveBalanceFetcher implements BalanceFetcher {
address,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.farm.id,
network: Network.GNOSIS_MAINNET,
network,
farmFilter: v => v.dataProps.implementation === 'rewards-only-gauge',
resolveContract: ({ address, network }) => this.curveContractFactory.curveRewardsOnlyGauge({ address, network }),
resolveStakedTokenBalance: ({ contract, address, multicall }) => multicall.wrap(contract).balanceOf(address),
Expand All @@ -48,7 +50,7 @@ export class GnosisCurveBalanceFetcher implements BalanceFetcher {
address,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.farm.id,
network: Network.GNOSIS_MAINNET,
network,
farmFilter: v => v.dataProps.implementation === 'child-liquidity-gauge',
resolveContract: ({ address, network }) =>
this.curveContractFactory.curveChildLiquidityGauge({ address, network }),
Expand Down
2 changes: 1 addition & 1 deletion src/apps/curve/gnosis/curve.pool.token-fetcher.ts
Expand Up @@ -14,7 +14,7 @@ const appId = CURVE_DEFINITION.id;
const groupId = CURVE_DEFINITION.groups.pool.id;
const network = Network.GNOSIS_MAINNET;

@Register.TokenPositionFetcher({ appId, groupId, network })
@Register.TokenPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } })
export class GnosisCurvePoolTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(CurveV1PoolTokenHelper)
Expand Down
8 changes: 5 additions & 3 deletions src/apps/curve/harmony/curve.balance-fetcher.ts
Expand Up @@ -10,6 +10,8 @@ import { Network } from '~types/network.interface';
import { CurveChildLiquidityGauge, CurveContractFactory, CurveRewardsOnlyGauge } from '../contracts';
import { CURVE_DEFINITION } from '../curve.definition';

const network = Network.HARMONY_MAINNET;

@Register.BalanceFetcher(CURVE_DEFINITION.id, Network.HARMONY_MAINNET)
export class HarmonyCurveBalanceFetcher implements BalanceFetcher {
constructor(
Expand All @@ -19,7 +21,7 @@ export class HarmonyCurveBalanceFetcher implements BalanceFetcher {

private async getPoolTokenBalances(address: string) {
return this.appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
network: Network.HARMONY_MAINNET,
network,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.pool.id,
address,
Expand All @@ -31,7 +33,7 @@ export class HarmonyCurveBalanceFetcher implements BalanceFetcher {
address,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.farm.id,
network: Network.HARMONY_MAINNET,
network,
farmFilter: v => v.dataProps.implementation === 'rewards-only-gauge',
resolveContract: ({ address, network }) => this.curveContractFactory.curveRewardsOnlyGauge({ address, network }),
resolveStakedTokenBalance: ({ contract, address, multicall }) => multicall.wrap(contract).balanceOf(address),
Expand All @@ -48,7 +50,7 @@ export class HarmonyCurveBalanceFetcher implements BalanceFetcher {
address,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.farm.id,
network: Network.HARMONY_MAINNET,
network,
farmFilter: v => v.dataProps.implementation === 'child-liquidity-gauge',
resolveContract: ({ address, network }) =>
this.curveContractFactory.curveChildLiquidityGauge({ address, network }),
Expand Down
2 changes: 1 addition & 1 deletion src/apps/curve/harmony/curve.pool.token-fetcher.ts
Expand Up @@ -15,7 +15,7 @@ const appId = CURVE_DEFINITION.id;
const groupId = CURVE_DEFINITION.groups.pool.id;
const network = Network.HARMONY_MAINNET;

@Register.TokenPositionFetcher({ appId, groupId, network })
@Register.TokenPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } })
export class HarmonyCurvePoolTokenFetcher implements PositionFetcher<AppTokenPosition> {
constructor(
@Inject(CurveV1PoolTokenHelper)
Expand Down
Expand Up @@ -45,13 +45,25 @@ export class CurveVestingEscrowContractPositionHelper {
const escrowedToken = baseTokens.find(v => v.address === escrowedTokenAddress)!;
const tokens = [claimable(escrowedToken), vesting(escrowedToken)];

const escrowedTokenContract = this.contractFactory.erc20({ address: escrowedToken.address, network });
const balanceOfRaw = await multicall.wrap(escrowedTokenContract).balanceOf(vestingEscrowAddress);
const balanceOf = Number(balanceOfRaw) / 10 ** escrowedToken.decimals;
const liquidity = balanceOf * escrowedToken.price;

// Display Props
const label = `Vesting Escrow ${escrowedToken.symbol}`;
const secondaryLabel = buildDollarDisplayItem(escrowedToken.price);
const images = [getTokenImg(escrowedToken.address, network)];
const statsItems = [];
const statsItems = [
{
label: 'Liquidity',
value: buildDollarDisplayItem(liquidity),
},
];

const dataProps = {};
const dataProps = {
liquidity,
};
const displayProps = { label, secondaryLabel, images, statsItems };

const contractPosition: ContractPosition = {
Expand All @@ -60,9 +72,9 @@ export class CurveVestingEscrowContractPositionHelper {
appId,
groupId,
network,
tokens,
dataProps,
displayProps,
tokens,
};

return [contractPosition];
Expand Down

0 comments on commit 548055f

Please sign in to comment.