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

Commit

Permalink
feat(curve): Update Curve Fantom liquidity gauges (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich committed May 17, 2022
1 parent b4698e6 commit 2beb324
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 11 deletions.
34 changes: 29 additions & 5 deletions src/apps/curve/fantom/curve.balance-fetcher.ts
Expand Up @@ -7,7 +7,7 @@ import { BalanceFetcher } from '~balance/balance-fetcher.interface';
import { isClaimable } from '~position/position.utils';
import { Network } from '~types/network.interface';

import { CurveContractFactory, CurveRewardsOnlyGauge } from '../contracts';
import { CurveChildLiquidityGauge, CurveContractFactory, CurveRewardsOnlyGauge } from '../contracts';
import { CURVE_DEFINITION } from '../curve.definition';

@Register.BalanceFetcher(CURVE_DEFINITION.id, Network.FANTOM_OPERA_MAINNET)
Expand All @@ -26,12 +26,13 @@ export class FantomCurveBalanceFetcher implements BalanceFetcher {
});
}

private async getStakedBalances(address: string) {
private async getRewardsOnlyGaugeStakedBalances(address: string) {
return this.appToolkit.helpers.singleStakingContractPositionBalanceHelper.getBalances<CurveRewardsOnlyGauge>({
address,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.farm.id,
network: Network.FANTOM_OPERA_MAINNET,
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),
resolveRewardTokenBalances: ({ contract, address, multicall, contractPosition }) => {
Expand All @@ -42,10 +43,33 @@ export class FantomCurveBalanceFetcher implements BalanceFetcher {
});
}

private async getChildLiquidityGaugeStakedBalances(address: string) {
return this.appToolkit.helpers.singleStakingContractPositionBalanceHelper.getBalances<CurveChildLiquidityGauge>({
address,
appId: CURVE_DEFINITION.id,
groupId: CURVE_DEFINITION.groups.farm.id,
network: Network.FANTOM_OPERA_MAINNET,
farmFilter: v => v.dataProps.implementation === 'child-liquidity-gauge',
resolveContract: ({ address, network }) =>
this.curveContractFactory.curveChildLiquidityGauge({ address, network }),
resolveStakedTokenBalance: ({ contract, address, multicall }) => multicall.wrap(contract).balanceOf(address),
resolveRewardTokenBalances: async ({ contract, address, multicall, contractPosition }) => {
const rewardTokens = contractPosition.tokens.filter(isClaimable);
const otherRewardTokens = rewardTokens.filter(v => v.symbol !== 'CRV');

return Promise.all([
multicall.wrap(contract).callStatic.claimable_tokens(address),
...otherRewardTokens.map(v => multicall.wrap(contract).claimable_reward(address, v.address)),
]);
},
});
}

async getBalances(address: string) {
const [poolTokenBalances, stakedBalances] = await Promise.all([
const [poolTokenBalances, rewardOnlyGaugeStakedBalances, childLiquidityGaugeStakedBalances] = await Promise.all([
this.getPoolTokenBalances(address),
this.getStakedBalances(address),
this.getRewardsOnlyGaugeStakedBalances(address),
this.getChildLiquidityGaugeStakedBalances(address),
]);

return presentBalanceFetcherResponse([
Expand All @@ -55,7 +79,7 @@ export class FantomCurveBalanceFetcher implements BalanceFetcher {
},
{
label: 'Staked',
assets: stakedBalances,
assets: [...rewardOnlyGaugeStakedBalances, ...childLiquidityGaugeStakedBalances],
},
]);
}
Expand Down
55 changes: 49 additions & 6 deletions src/apps/curve/fantom/curve.farm.contract-position-fetcher.ts
Expand Up @@ -6,8 +6,11 @@ import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';

import { CurveContractFactory, CurveRewardsOnlyGauge } from '../contracts';
import { CurveChildLiquidityGauge, CurveContractFactory, CurveRewardsOnlyGauge } from '../contracts';
import { CURVE_DEFINITION } from '../curve.definition';
import { CurveChildLiquidityGaugeFactoryAddressHelper } from '../helpers/curve.child-liquidity-gauge-factory.address-helper';
import { CurveChildLiquidityGaugeRewardTokenStrategy } from '../helpers/curve.child-liquidity-gauge.reward-token-strategy';
import { CurveChildLiquidityGaugeRoiStrategy } from '../helpers/curve.child-liquidity-gauge.roi-strategy';
import { CurveGaugeV2RewardTokenStrategy } from '../helpers/curve.gauge-v2.reward-token-strategy';
import { CurveGaugeV2RoiStrategy } from '../helpers/curve.gauge-v2.roi-strategy';

Expand All @@ -31,26 +34,66 @@ export class FantomCurveFarmContractPositionFetcher implements PositionFetcher<C
private readonly curveGaugeV2RoiStrategy: CurveGaugeV2RoiStrategy,
@Inject(CurveGaugeV2RewardTokenStrategy)
private readonly curveGaugeV2RewardTokenStrategy: CurveGaugeV2RewardTokenStrategy,
@Inject(CurveChildLiquidityGaugeFactoryAddressHelper)
private readonly childGaugeAddressHelper: CurveChildLiquidityGaugeFactoryAddressHelper,
@Inject(CurveChildLiquidityGaugeRoiStrategy)
private readonly childGaugeRoiStrategy: CurveChildLiquidityGaugeRoiStrategy,
@Inject(CurveChildLiquidityGaugeRewardTokenStrategy)
private readonly childGaugeRewardTokenStrategy: CurveChildLiquidityGaugeRewardTokenStrategy,
) {}

async getPositions() {
async getRewardOnlyGaugePositions() {
const definitions = [CURVE_V1_POOL_DEFINITIONS, CURVE_V1_METAPOOL_DEFINITIONS, CURVE_V2_POOL_DEFINITIONS]
.flat()
.filter(v => !!v.gaugeAddress);

return this.appToolkit.helpers.singleStakingFarmContractPositionHelper.getContractPositions<CurveRewardsOnlyGauge>({
network,
appId,
groupId,
dependencies: [{ appId: CURVE_DEFINITION.id, groupIds: [CURVE_DEFINITION.groups.pool.id], network }],
resolveFarmAddresses: () => definitions.map(v => v.gaugeAddress ?? null),
resolveImplementation: () => 'rewards-only-gauge',
resolveFarmAddresses: () => definitions.map(v => v.gaugeAddress!),
resolveFarmContract: ({ address, network }) =>
this.curveContractFactory.curveRewardsOnlyGauge({ address, network }),
resolveStakedTokenAddress: ({ contract, multicall }) => multicall.wrap(contract).lp_token(),
resolveRewardTokenAddresses: this.curveGaugeV2RewardTokenStrategy.build(),
resolveRois: this.curveGaugeV2RoiStrategy.build({ tokenDefinitions: definitions }),
resolveIsActive: () => true,
resolveRois: this.curveGaugeV2RoiStrategy.build({
tokenDefinitions: definitions,
}),
});
}

async getChildLiquidityGaugePositions() {
return this.appToolkit.helpers.singleStakingFarmContractPositionHelper.getContractPositions<CurveChildLiquidityGauge>(
{
network,
appId,
groupId,
dependencies: [{ appId: CURVE_DEFINITION.id, groupIds: [CURVE_DEFINITION.groups.pool.id], network }],
resolveImplementation: () => 'child-liquidity-gauge',
resolveFarmAddresses: () =>
this.childGaugeAddressHelper.getGaugeAddresses({
factoryAddress: '0xabc000d88f23bb45525e447528dbf656a9d55bf5',
network,
}),
resolveFarmContract: ({ address, network }) =>
this.curveContractFactory.curveChildLiquidityGauge({ address, network }),
resolveStakedTokenAddress: ({ contract, multicall }) => multicall.wrap(contract).lp_token(),
resolveRewardTokenAddresses: this.childGaugeRewardTokenStrategy.build({
crvTokenAddress: '0x1e4f97b9f9f913c46f1632781732927b9019c68b',
}),
resolveRois: this.childGaugeRoiStrategy.build(),
resolveIsActive: () => true,
},
);
}

async getPositions() {
const [rewardOnlyGaugePositions, childLiquidityGaugePositions] = await Promise.all([
this.getRewardOnlyGaugePositions(),
this.getChildLiquidityGaugePositions(),
]);

return [...rewardOnlyGaugePositions, ...childLiquidityGaugePositions];
}
}

0 comments on commit 2beb324

Please sign in to comment.