Skip to content

Commit 794df86

Browse files
committed
feat: add fetchTokenInfo to alexSDK
1 parent cf4d5e4 commit 794df86

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/alexSDK.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ export class AlexSDK {
5555
return this.getTokenInfos();
5656
}
5757

58+
/**
59+
* Fetch the token info for a given token address.
60+
* @param tokenAddress - The address of the token to fetch info for. e.g SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex
61+
* @returns A promise that resolves to a `TokenInfo` object or `null` if the token is not found.
62+
*/
63+
async fetchTokenInfo(tokenAddress: string): Promise<TokenInfo | null> {
64+
return (
65+
(await this.getTokenInfos()).find(
66+
(x) => x.underlyingToken.split('::')[0] === tokenAddress.split('::')[0]
67+
) ?? null
68+
);
69+
}
70+
5871
private async getPrices(): Promise<PriceData[]> {
5972
return getPrices(await this.getTokenInfos());
6073
}

0 commit comments

Comments
 (0)