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

Commit

Permalink
fix(position): Update tokenId's type to String (#2903)
Browse files Browse the repository at this point in the history
  • Loading branch information
wpoulin authored Aug 21, 2023
1 parent 3a0c48f commit 86e103a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,42 @@ export class ArbitrumY2KFinanceFarmV1ContractPositionFetcher extends ContractPos
return farms.map(farm => ({ address: farm }));
}

async getTokenDefinitions(
params: GetTokenDefinitionsParams<Y2KFinanceStakingRewards, DefaultContractPositionDefinition>,
): Promise<UnderlyingTokenDefinition[] | null> {
async getTokenDefinitions({
contract,
}: GetTokenDefinitionsParams<Y2KFinanceStakingRewards, DefaultContractPositionDefinition>): 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<Y2KFinanceStakingRewards, DefaultDataProps, DefaultContractPositionDefinition>,
): Promise<string> {
async getLabel({
contractPosition,
}: GetDisplayPropsParams<
Y2KFinanceStakingRewards,
DefaultDataProps,
DefaultContractPositionDefinition
>): Promise<string> {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,22 @@ export class ArbitrumY2KFinanceMintV1ContractPositionFetcher extends ContractPos
async getTokenDefinitions(
params: GetTokenDefinitionsParams<Y2KFinanceVaultV1, DefaultContractPositionDefinition>,
): Promise<UnderlyingTokenDefinition[] | null> {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,23 @@ export class ArbitrumY2KFinanceMintV2ContractPositionFetcher extends ContractPos
async getTokenDefinitions(
params: GetTokenDefinitionsParams<Y2KFinanceCarousel, DefaultContractPositionDefinition>,
): Promise<UnderlyingTokenDefinition[] | null> {
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,
Expand Down
2 changes: 1 addition & 1 deletion src/position/selectors/app-token-selector.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type LoggingTags = {
export type AppTokenSelectorKey = {
address: string;
network: Network;
tokenId?: number;
tokenId?: string;
};

export type GetOne = (opts: AppTokenSelectorKey) => Promise<AppTokenPosition | null>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type LoggingTags = {
export type TokenDependencySelectorKey = {
address: string;
network: Network;
tokenId?: number;
tokenId?: string;
};

export type TokenDependency = BaseToken | AppTokenPosition | NonFungibleToken;
Expand Down
3 changes: 1 addition & 2 deletions src/position/template/app-token.template.position-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
2 changes: 1 addition & 1 deletion src/position/template/app-token.template.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type DefaultAppTokenDataProps = {
export type UnderlyingTokenDefinition = {
address: string;
network: Network;
tokenId?: number;
tokenId?: string;
};

// PHASE 1: List addresses and definitions
Expand Down
2 changes: 1 addition & 1 deletion src/position/template/contract-position.template.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type UnderlyingTokenDefinition = {
metaType: MetaType;
address: string;
network: Network;
tokenId?: number;
tokenId?: string;
};

// PHASE 1: List definitions
Expand Down

0 comments on commit 86e103a

Please sign in to comment.