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 boosted pool lp token supply (#2749)
Browse files Browse the repository at this point in the history
  • Loading branch information
wpoulin authored Jun 15, 2023
1 parent 2287a39 commit 0b41c78
Show file tree
Hide file tree
Showing 8 changed files with 3,298 additions and 23 deletions.
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 @@ -11,6 +11,7 @@ import { EthereumBalancerV2FarmContractPositionFetcher } from './ethereum/balanc
import { EthereumBalancerV2PoolTokenFetcher } from './ethereum/balancer-v2.pool.token-fetcher';
import { EthereumBalancerV2VotingEscrowContractPositionFetcher } from './ethereum/balancer-v2.voting-escrow.contract-position-fetcher';
import { EthereumBalancerV2WrappedAaveTokenFetcher } from './ethereum/balancer-v2.wrapped-aave.token-fetcher';
import { PolygonBalancerV2BoostedTokenFetcher } from './polygon/balancer-v2.boosted.token-fetcher';
import { PolygonBalancerV2FarmContractPositionFetcher } from './polygon/balancer-v2.farm.contract-position-fetcher';
import { PolygonBalancerV2PoolTokenFetcher } from './polygon/balancer-v2.pool.token-fetcher';
import { PolygonBalancerV2StaticYieldTokenFetcher } from './polygon/balancer-v2.static-yield.token-fetcher';
Expand All @@ -28,6 +29,7 @@ import { PolygonBalancerV2StaticYieldTokenFetcher } from './polygon/balancer-v2.
EthereumBalancerV2FarmContractPositionFetcher,
EthereumBalancerV2WrappedAaveTokenFetcher,
// Polygon
PolygonBalancerV2BoostedTokenFetcher,
PolygonBalancerV2PoolTokenFetcher,
PolygonBalancerV2FarmContractPositionFetcher,
PolygonBalancerV2StaticYieldTokenFetcher,
Expand Down
51 changes: 28 additions & 23 deletions src/apps/balancer-v2/common/balancer-v2.boosted.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ import { Inject } from '@nestjs/common';
import { gql } from 'graphql-request';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present';
import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper';
import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher';
import {
DefaultAppTokenDataProps,
DefaultAppTokenDefinition,
GetAddressesParams,
GetDisplayPropsParams,
GetPricePerShareParams,
GetTokenPropsParams,
GetUnderlyingTokensParams,
} from '~position/template/app-token.template.types';

import { BalancerPool, BalancerV2ContractFactory } from '../contracts';

import { BalancerV2ContractFactory } from '../contracts';
import { BalancerBoostedPool } from '../contracts/ethers/BalancerBoostedPool';

type GetBoostedResponse = {
pools: {
Expand All @@ -21,16 +25,14 @@ type GetBoostedResponse = {
};

const GET_BOOSTED_QUERY = gql`
query getBoosted {
pools(where: { poolType: "ERC4626Linear" }) {
address
query getBoosted {
pools(where: { poolType: "ERC4626Linear" }) {
address
}
}
}
`;

export abstract class BalancerV2PoolTokenFetcher extends AppTokenTemplatePositionFetcher<
BalancerPool
> {
export abstract class BalancerV2PoolTokenFetcher extends AppTokenTemplatePositionFetcher<BalancerBoostedPool> {
constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
@Inject(BalancerV2ContractFactory) protected readonly contractFactory: BalancerV2ContractFactory,
Expand All @@ -41,8 +43,8 @@ export abstract class BalancerV2PoolTokenFetcher extends AppTokenTemplatePositio
abstract subgraphUrl: string;
abstract vaultAddress: string;

getContract(address: string) {
return this.contractFactory.balancerPool({ address, network: this.network });
getContract(address: string): BalancerBoostedPool {
return this.contractFactory.balancerBoostedPool({ address, network: this.network });
}

async getDefinitions(): Promise<{ address: string }[]> {
Expand All @@ -51,38 +53,41 @@ export abstract class BalancerV2PoolTokenFetcher extends AppTokenTemplatePositio
query: GET_BOOSTED_QUERY,
});

return poolsResponse.pools
return poolsResponse.pools;
}

async getAddresses({ definitions }: GetAddressesParams<{ address: string }>) {
async getAddresses({ definitions }: GetAddressesParams) {
return definitions.map(v => v.address);
}

async getSupply({
contract,
}) {
return contract.totalSupply();
}: GetTokenPropsParams<BalancerBoostedPool, DefaultAppTokenDataProps, DefaultAppTokenDefinition>) {
return contract.getVirtualSupply();
}

async getUnderlyingTokenDefinitions({ contract, multicall }: GetUnderlyingTokensParams<BalancerPool>) {
async getUnderlyingTokenDefinitions({ contract, multicall }: GetUnderlyingTokensParams<BalancerBoostedPool>) {
const _vault = this.contractFactory.balancerVault({ address: this.vaultAddress, network: this.network });
const vault = multicall.wrap(_vault);

const poolId = await contract.getPoolId();
const { tokens } = await vault.getPoolTokens(poolId);
return [{ address: tokens[tokens.length - 1], network: this.network }]
return [{ address: tokens[tokens.length - 1], network: this.network }];
}

async getPricePerShare({ appToken, multicall }: GetPricePerShareParams<BalancerPool>) {
const _boosted = this.contractFactory.balancerErc4626LinearPool({ address: appToken.address, network: this.network });
async getPricePerShare({ appToken, multicall }: GetPricePerShareParams<BalancerBoostedPool>) {
const _boosted = this.contractFactory.balancerErc4626LinearPool({
address: appToken.address,
network: this.network,
});
const boosted = multicall.wrap(_boosted);

const decimals = await boosted.decimals()
const decimals = await boosted.decimals();
const ratio = await boosted.getWrappedTokenRate();
return [Number(ratio) / 10 ** Number(decimals)]
return [Number(ratio) / 10 ** Number(decimals)];
}

async getLabel({ appToken }: GetDisplayPropsParams<BalancerPool>): Promise<string> {
return appToken.symbol
async getLabel({ appToken }: GetDisplayPropsParams<BalancerBoostedPool>): Promise<string> {
return getLabelFromToken(appToken.tokens[0]);
}
}
Loading

0 comments on commit 0b41c78

Please sign in to comment.