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

Commit

Permalink
fix(balancer-v2): Fix Gauge and Reward for Polygon and Arbitrum (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwele authored May 10, 2022
1 parent 1d85e46 commit 206e7b6
Show file tree
Hide file tree
Showing 13 changed files with 750 additions and 21 deletions.
7 changes: 6 additions & 1 deletion src/apps/balancer-v2/arbitrum/balancer-v2.balance-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SingleStakingContractPositionBalanceHelper, TokenBalanceHelper } from '
import { Register } from '~app-toolkit/decorators';
import { presentBalanceFetcherResponse } from '~app-toolkit/helpers/presentation/balance-fetcher-response.present';
import { BalanceFetcher } from '~balance/balance-fetcher.interface';
import { isClaimable } from '~position/position.utils';
import { Network } from '~types/network.interface';

import { BALANCER_V2_DEFINITION } from '../balancer-v2.definition';
Expand Down Expand Up @@ -33,7 +34,11 @@ export class ArbitrumBalancerV2BalanceFetcher implements BalanceFetcher {
groupId: BALANCER_V2_DEFINITION.groups.farm.id,
resolveContract: ({ address, network }) => this.balancerV2ContractFactory.balancerGauge({ address, network }),
resolveStakedTokenBalance: ({ contract, address, multicall }) => multicall.wrap(contract).balanceOf(address),
resolveRewardTokenBalances: () => [],
resolveRewardTokenBalances: ({ contract, address, multicall, contractPosition }) => {
const rewardTokens = contractPosition.tokens.filter(isClaimable);
const wrappedContract = multicall.wrap(contract);
return Promise.all(rewardTokens.map(v => wrappedContract.claimable_reward(address, v.address)));
},
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Inject } from '@nestjs/common';
import { compact } from 'lodash';

import { SingleStakingFarmContractPositionHelper } from '~app-toolkit';
import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { ZERO_ADDRESS } from '~app-toolkit/constants/address';
import { Register } from '~app-toolkit/decorators';
import { PositionFetcher } from '~position/position-fetcher.interface';
import { ContractPosition } from '~position/position.interface';
import { Network } from '~types/network.interface';

import { BALANCER_V2_DEFINITION } from '../balancer-v2.definition';
import { BalancerGauge, BalancerV2ContractFactory } from '../contracts';
import { BalancerV2GaugeAddressesGetter } from '../helpers/balancer-v2.gauge-addresses-getter';
import { BalancerV2GaugeRewardTokenStrategy } from '../helpers/balancer-v2.reward-token-strategy';

const appId = BALANCER_V2_DEFINITION.id;
const groupId = BALANCER_V2_DEFINITION.groups.farm.id;
Expand All @@ -17,32 +20,56 @@ const network = Network.ARBITRUM_MAINNET;
@Register.ContractPositionFetcher({ appId, groupId, network })
export class ArbitrumBalancerV2StakedfContractPositionFetcher implements PositionFetcher<ContractPosition> {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@Inject(BalancerV2ContractFactory)
private readonly balancerV2ContractFactory: BalancerV2ContractFactory,
@Inject(BalancerV2GaugeAddressesGetter)
private readonly balancerV2GaugeAddressesGetter: BalancerV2GaugeAddressesGetter,
@Inject(SingleStakingFarmContractPositionHelper)
private readonly curveStakingHelper: SingleStakingFarmContractPositionHelper,
@Inject(BalancerV2GaugeRewardTokenStrategy)
private readonly gaugeRewardTokenStrategy: BalancerV2GaugeRewardTokenStrategy,
) {}

async getPositions() {
const farms = await this.balancerV2GaugeAddressesGetter.getGauges({ network });
return await this.curveStakingHelper.getContractPositions<BalancerGauge>({
const multicall = this.appToolkit.getMulticall(network);
const gaugeFactoryContract = this.balancerV2ContractFactory.balancerChildChainGaugeFactory({
address: '0xb08e16cfc07c684daa2f93c70323badb2a6cbfd2',
network,
});

const balancerPoolTokens = await this.appToolkit.getAppTokenPositions({
appId,
groupIds: [BALANCER_V2_DEFINITION.groups.pool.id],
network,
});

const farms = await Promise.all(
balancerPoolTokens.map(async pool => {
return await multicall
.wrap(gaugeFactoryContract)
.getPoolGauge(pool.address)
.then(r => r.toLowerCase())
.catch(() => ZERO_ADDRESS);
}),
).then(r => r.filter(v => v !== ZERO_ADDRESS));

const positions = await this.curveStakingHelper.getContractPositions<BalancerGauge>({
network,
appId,
groupId,
dependencies: [
{
appId: BALANCER_V2_DEFINITION.id,
appId,
groupIds: [BALANCER_V2_DEFINITION.groups.pool.id],
network,
},
],
resolveFarmAddresses: () => farms.map(farm => farm.address),
resolveFarmAddresses: () => farms,
resolveFarmContract: ({ address, network }) => this.balancerV2ContractFactory.balancerGauge({ address, network }),
resolveStakedTokenAddress: ({ contract, multicall }) => multicall.wrap(contract).lp_token(),
resolveRewardTokenAddresses: async () => [],
resolveRewardTokenAddresses: this.gaugeRewardTokenStrategy.build(),
resolveRois: async () => ({ dailyROI: 0, weeklyROI: 0, yearlyROI: 0 }),
});

return compact(positions);
}
}
2 changes: 2 additions & 0 deletions src/apps/balancer-v2/balancer-v2.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { BalancerV2ClaimableContractPositionBalanceHelper } from './helpers/bala
import { BalancerV2EventsPoolTokenDataStrategy } from './helpers/balancer-v2.events.pool-token-address-strategy';
import { BalancerV2GaugeAddressesGetter } from './helpers/balancer-v2.gauge-addresses-getter';
import { BalancerV2PoolTokensHelper } from './helpers/balancer-v2.pool.token-helper';
import { BalancerV2GaugeRewardTokenStrategy } from './helpers/balancer-v2.reward-token-strategy';
import { BalancerV2SpotPriceHelper } from './helpers/balancer-v2.spot-price.helper';
import { BalancerV2TheGraphPoolTokenDataStrategy } from './helpers/balancer-v2.the-graph.pool-token-address-strategy';
import { PolygonBalancerV2BalanceFetcher } from './polygon/balancer-v2.balance-fetcher';
Expand Down Expand Up @@ -49,6 +50,7 @@ import { PolygonBalancerV2StakedfContractPositionFetcher } from './polygon/balan
BalancerV2ClaimableContractPositionBalanceHelper,
BalancerV2EventsPoolTokenDataStrategy,
BalancerV2GaugeAddressesGetter,
BalancerV2GaugeRewardTokenStrategy,
],
exports: [BalancerV2SpotPriceHelper, BalancerV2PoolTokensHelper, BalancerV2ContractFactory],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
[
{
"inputs": [
{
"internalType": "contract ILiquidityGauge",
"name": "gauge",
"type": "address"
},
{
"internalType": "contract IChildChainStreamer",
"name": "childChainStreamer",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "gauge",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "pool",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "streamer",
"type": "address"
}
],
"name": "RewardsOnlyGaugeCreated",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "pool",
"type": "address"
}
],
"name": "create",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "getChildChainStreamerImplementation",
"outputs": [
{
"internalType": "contract IChildChainStreamer",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getGaugeImplementation",
"outputs": [
{
"internalType": "contract ILiquidityGauge",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "gauge",
"type": "address"
}
],
"name": "getGaugePool",
"outputs": [
{
"internalType": "contract IERC20",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "gauge",
"type": "address"
}
],
"name": "getGaugeStreamer",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "pool",
"type": "address"
}
],
"name": "getPoolGauge",
"outputs": [
{
"internalType": "contract ILiquidityGauge",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "pool",
"type": "address"
}
],
"name": "getPoolStreamer",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "gauge",
"type": "address"
}
],
"name": "isGaugeFromFactory",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "streamer",
"type": "address"
}
],
"name": "isStreamerFromFactory",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
}
]
Loading

0 comments on commit 206e7b6

Please sign in to comment.