Skip to content

Commit

Permalink
fix(yearn): Fix Yearn token prices (Zapper-fi#1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich committed Aug 16, 2022
1 parent 91b06cc commit 569aa53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/apps/yearn/ethereum/yearn.v1-vault.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export class EthereumYearnV1VaultTokenFetcher extends YearnVaultTokenFetcher<Yea
return this.contractFactory.yearnVault({ network: this.network, address });
}

async getPricePerShare({ contract, appToken }: PricePerShareStageParams<YearnVault>) {
async getPricePerShare({ contract }: PricePerShareStageParams<YearnVault>) {
const pricePerShareRaw = await contract.getPricePerFullShare().catch(err => {
if (isMulticallUnderlyingError(err)) return 0;
throw err;
});
return Number(pricePerShareRaw) / 10 ** appToken.decimals;
return Number(pricePerShareRaw) / 10 ** 18;
}

async getDataProps(
Expand Down
3 changes: 1 addition & 2 deletions src/apps/yearn/ethereum/yearn.yield.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ export class EthereumYearnYieldTokenFetcher extends AppTokenTemplatePositionFetc

async getPricePerShare({
contract,
appToken,
}: PricePerShareStageParams<YearnVault, YearnYieldTokenDataProps>): Promise<number> {
return contract
.getPricePerFullShare()
.catch(err => {
if (isMulticallUnderlyingError(err)) return 0;
throw err;
})
.then(pps => Number(pps) / 10 ** appToken.decimals);
.then(pps => Number(pps) / 10 ** 18);
}

async getDataProps(
Expand Down
16 changes: 9 additions & 7 deletions src/position/template/app-token.template.position-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
buildPercentageDisplayItem,
} from '~app-toolkit/helpers/presentation/display-item.present';
import { getImagesFromToken } from '~app-toolkit/helpers/presentation/image.present';
import { Erc20 } from '~contract/contracts';
import { IMulticallWrapper } from '~multicall';
import { ContractType } from '~position/contract.interface';
import { DefaultDataProps, DisplayProps, StatsItem } from '~position/display.interface';
Expand Down Expand Up @@ -73,16 +72,19 @@ export abstract class AppTokenTemplatePositionFetcher<T extends Contract, V exte
abstract getAddresses(): Promise<string[]>;

// Token Props
async getSymbol({ contract }: TokenPropsStageParams<T>): Promise<string> {
return (contract as unknown as Erc20).symbol();
async getSymbol({ address, multicall }: TokenPropsStageParams<T>): Promise<string> {
const erc20 = this.appToolkit.globalContracts.erc20({ address, network: this.network });
return multicall.wrap(erc20).symbol();
}

async getDecimals({ contract }: TokenPropsStageParams<T>): Promise<number> {
return (contract as unknown as Erc20).decimals();
async getDecimals({ address, multicall }: TokenPropsStageParams<T>): Promise<number> {
const erc20 = this.appToolkit.globalContracts.erc20({ address, network: this.network });
return multicall.wrap(erc20).decimals();
}

async getSupply({ contract }: TokenPropsStageParams<T>): Promise<BigNumberish> {
return (contract as unknown as Erc20).totalSupply();
async getSupply({ address, multicall }: TokenPropsStageParams<T>): Promise<BigNumberish> {
const erc20 = this.appToolkit.globalContracts.erc20({ address, network: this.network });
return multicall.wrap(erc20).totalSupply();
}

// Price Properties
Expand Down

0 comments on commit 569aa53

Please sign in to comment.