From 86e103a1c624425b932a710eeb806672c153441d Mon Sep 17 00:00:00 2001 From: William Poulin Date: Mon, 21 Aug 2023 16:39:49 -0400 Subject: [PATCH] fix(position): Update tokenId's type to String (#2903) --- ...nance.farm-v1.contract-position-fetcher.ts | 33 +++++++++++++------ ...nance.mint-v1.contract-position-fetcher.ts | 9 ++--- ...nance.mint-v2.contract-position-fetcher.ts | 9 ++--- .../selectors/app-token-selector.interface.ts | 2 +- .../token-dependency-selector.interface.ts | 2 +- .../app-token.template.position-fetcher.ts | 3 +- .../template/app-token.template.types.ts | 2 +- .../contract-position.template.types.ts | 2 +- 8 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/apps/y2k-finance/arbitrum/y2k-finance.farm-v1.contract-position-fetcher.ts b/src/apps/y2k-finance/arbitrum/y2k-finance.farm-v1.contract-position-fetcher.ts index 6b7afdeed..fad6a7eb3 100644 --- a/src/apps/y2k-finance/arbitrum/y2k-finance.farm-v1.contract-position-fetcher.ts +++ b/src/apps/y2k-finance/arbitrum/y2k-finance.farm-v1.contract-position-fetcher.ts @@ -43,29 +43,42 @@ export class ArbitrumY2KFinanceFarmV1ContractPositionFetcher extends ContractPos return farms.map(farm => ({ address: farm })); } - async getTokenDefinitions( - params: GetTokenDefinitionsParams, - ): Promise { + async getTokenDefinitions({ + contract, + }: GetTokenDefinitionsParams): Promise< + UnderlyingTokenDefinition[] | null + > { + const [stakingToken, tokenIdRaw, rewardsToken] = await Promise.all([ + contract.stakingToken(), + contract.id(), + contract.rewardsToken(), + ]); + return [ { metaType: MetaType.SUPPLIED, - address: await params.contract.stakingToken(), + address: stakingToken, network: this.network, - tokenId: (await params.contract.id()).toNumber(), + tokenId: tokenIdRaw.toString(), }, { metaType: MetaType.CLAIMABLE, - address: await params.contract.rewardsToken(), + address: rewardsToken, network: this.network, }, ]; } - async getLabel( - params: GetDisplayPropsParams, - ): Promise { + async getLabel({ + contractPosition, + }: GetDisplayPropsParams< + Y2KFinanceStakingRewards, + DefaultDataProps, + DefaultContractPositionDefinition + >): Promise { + const stakingTokenAddress = contractPosition.tokens[0]; const vault = this.contractFactory.y2KFinanceVaultV1({ - address: await params.contract.stakingToken(), + address: stakingTokenAddress.address, network: this.network, }); const name = await vault.name(); diff --git a/src/apps/y2k-finance/arbitrum/y2k-finance.mint-v1.contract-position-fetcher.ts b/src/apps/y2k-finance/arbitrum/y2k-finance.mint-v1.contract-position-fetcher.ts index 5802506fc..421f06cb5 100644 --- a/src/apps/y2k-finance/arbitrum/y2k-finance.mint-v1.contract-position-fetcher.ts +++ b/src/apps/y2k-finance/arbitrum/y2k-finance.mint-v1.contract-position-fetcher.ts @@ -58,21 +58,22 @@ export class ArbitrumY2KFinanceMintV1ContractPositionFetcher extends ContractPos async getTokenDefinitions( params: GetTokenDefinitionsParams, ): Promise { - const epochIds = await this.getEpochIds(params.multicall, params.contract); + const epochIdsRaw = await this.getEpochIds(params.multicall, params.contract); const claimableAsset = await params.contract.asset(); + const epochIds = epochIdsRaw.map(x => x.toString()); return epochIds - .map(id => [ + .map(tokenId => [ { metaType: MetaType.SUPPLIED, address: params.contract.address, network: this.network, - tokenId: id.toNumber(), + tokenId, }, { metaType: MetaType.CLAIMABLE, address: claimableAsset, network: this.network, - tokenId: id.toNumber(), + tokenId, }, ]) .flat(); diff --git a/src/apps/y2k-finance/arbitrum/y2k-finance.mint-v2.contract-position-fetcher.ts b/src/apps/y2k-finance/arbitrum/y2k-finance.mint-v2.contract-position-fetcher.ts index 668c3c091..6bcefe507 100644 --- a/src/apps/y2k-finance/arbitrum/y2k-finance.mint-v2.contract-position-fetcher.ts +++ b/src/apps/y2k-finance/arbitrum/y2k-finance.mint-v2.contract-position-fetcher.ts @@ -46,22 +46,23 @@ export class ArbitrumY2KFinanceMintV2ContractPositionFetcher extends ContractPos async getTokenDefinitions( params: GetTokenDefinitionsParams, ): Promise { - const epochIds = await params.contract.getAllEpochs(); + const epochIdsRaw = await params.contract.getAllEpochs(); const claimableAsset = await params.contract.asset(); const emission = await params.contract.emissionsToken(); + const epochIds = epochIdsRaw.map(x => x.toString()); return epochIds - .map(id => [ + .map(tokenId => [ { metaType: MetaType.SUPPLIED, address: params.contract.address, network: this.network, - tokenId: id.toNumber(), + tokenId, }, { metaType: MetaType.CLAIMABLE, address: claimableAsset, network: this.network, - tokenId: id.toNumber(), + tokenId, }, { metaType: MetaType.CLAIMABLE, diff --git a/src/position/selectors/app-token-selector.interface.ts b/src/position/selectors/app-token-selector.interface.ts index ef645861b..ddaae1cb8 100644 --- a/src/position/selectors/app-token-selector.interface.ts +++ b/src/position/selectors/app-token-selector.interface.ts @@ -10,7 +10,7 @@ export type LoggingTags = { export type AppTokenSelectorKey = { address: string; network: Network; - tokenId?: number; + tokenId?: string; }; export type GetOne = (opts: AppTokenSelectorKey) => Promise; diff --git a/src/position/selectors/token-dependency-selector.interface.ts b/src/position/selectors/token-dependency-selector.interface.ts index 623c6d28f..d24e2c839 100644 --- a/src/position/selectors/token-dependency-selector.interface.ts +++ b/src/position/selectors/token-dependency-selector.interface.ts @@ -10,7 +10,7 @@ export type LoggingTags = { export type TokenDependencySelectorKey = { address: string; network: Network; - tokenId?: number; + tokenId?: string; }; export type TokenDependency = BaseToken | AppTokenPosition | NonFungibleToken; diff --git a/src/position/template/app-token.template.position-fetcher.ts b/src/position/template/app-token.template.position-fetcher.ts index ec3506166..3868b3042 100644 --- a/src/position/template/app-token.template.position-fetcher.ts +++ b/src/position/template/app-token.template.position-fetcher.ts @@ -208,8 +208,7 @@ export abstract class AppTokenTemplatePositionFetcher< const isMaybeTokenIdMatch = isUndefined(definition.tokenId) || (token.type === ContractType.APP_TOKEN && token.dataProps.tokenId === definition.tokenId) || - (token.type === ContractType.NON_FUNGIBLE_TOKEN && - Number(token.assets?.[0].tokenId) === definition.tokenId); + (token.type === ContractType.NON_FUNGIBLE_TOKEN && token.assets?.[0].tokenId === definition.tokenId); return isAddressMatch && isNetworkMatch && isMaybeTokenIdMatch; }); diff --git a/src/position/template/app-token.template.types.ts b/src/position/template/app-token.template.types.ts index 4687869c4..f93d0c82b 100644 --- a/src/position/template/app-token.template.types.ts +++ b/src/position/template/app-token.template.types.ts @@ -17,7 +17,7 @@ export type DefaultAppTokenDataProps = { export type UnderlyingTokenDefinition = { address: string; network: Network; - tokenId?: number; + tokenId?: string; }; // PHASE 1: List addresses and definitions diff --git a/src/position/template/contract-position.template.types.ts b/src/position/template/contract-position.template.types.ts index 14052b5c1..e8bf9117e 100644 --- a/src/position/template/contract-position.template.types.ts +++ b/src/position/template/contract-position.template.types.ts @@ -14,7 +14,7 @@ export type UnderlyingTokenDefinition = { metaType: MetaType; address: string; network: Network; - tokenId?: number; + tokenId?: string; }; // PHASE 1: List definitions