diff --git a/src/interfaces/vault.ts b/src/interfaces/vault.ts index 6c4bc4ce..827f9abe 100644 --- a/src/interfaces/vault.ts +++ b/src/interfaces/vault.ts @@ -5,7 +5,7 @@ import { JsonRpcSigner } from "@ethersproject/providers"; import { ChainId } from "../chain"; import { ServiceInterface } from "../common"; -import { EthAddress } from "../helpers"; +import { EthAddress, WethAddress } from "../helpers"; import { PickleJars } from "../services/partners/pickle"; import { Address, @@ -35,26 +35,18 @@ export class VaultInterface extends ServiceInterface { * @returns */ async get(addresses?: Address[], overrides?: CallOverrides): Promise { - const adapters = Object.values(this.yearn.services.lens.adapters.vaults); - return await Promise.all( - adapters.map(async adapter => { - const assetsStatic = await adapter.assetsStatic(addresses, overrides); - const assetsDynamic = await adapter.assetsDynamic(addresses, overrides); - const assetsApy = await this.yearn.services.vision.apy(addresses); - const assets = new Array(); - for (const asset of assetsStatic) { - const dynamic = assetsDynamic.find(({ address }) => asset.address === address); - if (!dynamic) { - throw new SdkError(`Dynamic asset does not exist for ${asset.address}`); - } - dynamic.metadata.apy = assetsApy[asset.address]; - const alias = this.yearn.services.asset.alias(asset.token); - dynamic.metadata.displayName = alias ? alias.symbol : asset.name; - assets.push({ ...asset, ...dynamic }); - } - return assets; - }) - ).then(arr => arr.flat()); + const assetsStatic = await this.getStatic(addresses, overrides); + const assetsDynamic = await this.getDynamic(addresses, overrides); + const assets = new Array(); + for (const asset of assetsStatic) { + const dynamic = assetsDynamic.find(({ address }) => asset.address === address); + if (!dynamic) { + throw new SdkError(`Dynamic asset does not exist for ${asset.address}`); + } + dynamic.metadata.displayName = dynamic.metadata.displayName || asset.name; + assets.push({ ...asset, ...dynamic }); + } + return assets; } /** @@ -82,7 +74,24 @@ export class VaultInterface extends ServiceInterface { const adapters = Object.values(this.yearn.services.lens.adapters.vaults); return await Promise.all( adapters.map(async adapter => { - return await adapter.assetsDynamic(addresses, overrides); + const data = await adapter.assetsDynamic(addresses, overrides); + const assetsApy = await this.yearn.services.vision.apy(data.map(dynamic => dynamic.address)); + return data.map(dynamic => { + dynamic.metadata.apy = assetsApy[dynamic.address]; + if (dynamic.tokenId === WethAddress) { + const icon = this.yearn.services.asset.icon(EthAddress) ?? ""; + dynamic.metadata.displayIcon = icon; + dynamic.metadata.displayName = "ETH"; + dynamic.metadata.defaultDisplayToken = EthAddress; + } else { + const icon = this.yearn.services.asset.icon(dynamic.tokenId) ?? ""; + dynamic.metadata.displayIcon = icon; + const alias = this.yearn.services.asset.alias(dynamic.tokenId); + dynamic.metadata.displayName = alias ? alias.symbol : ""; + dynamic.metadata.defaultDisplayToken = dynamic.tokenId; + } + return dynamic; + }); }) ).then(arr => arr.flat()); } diff --git a/src/types/metadata.ts b/src/types/metadata.ts index 933bd26b..4609d29e 100644 --- a/src/types/metadata.ts +++ b/src/types/metadata.ts @@ -18,6 +18,8 @@ export interface VaultMetadata { apy?: Apy; displayName: string; + displayIcon: string; + defaultDisplayToken: Address; } /**