feat: add fetchTokenInfo to alexSDK

This commit is contained in:
Kyle Fang
2024-11-19 09:44:58 +00:00
parent cf4d5e4ace
commit 794df86dc6

View File

@@ -55,6 +55,19 @@ export class AlexSDK {
return this.getTokenInfos();
}
/**
* Fetch the token info for a given token address.
* @param tokenAddress - The address of the token to fetch info for. e.g SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex
* @returns A promise that resolves to a `TokenInfo` object or `null` if the token is not found.
*/
async fetchTokenInfo(tokenAddress: string): Promise<TokenInfo | null> {
return (
(await this.getTokenInfos()).find(
(x) => x.underlyingToken.split('::')[0] === tokenAddress.split('::')[0]
) ?? null
);
}
private async getPrices(): Promise<PriceData[]> {
return getPrices(await this.getTokenInfos());
}