diff --git a/src/types.ts b/src/types.ts index 95aa893..1e4eba2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -51,6 +51,7 @@ export type PoolData = { tokenX: Currency; tokenY: Currency; factor: bigint; + poolId: bigint }; export type PriceData = { diff --git a/src/utils/fetchData.ts b/src/utils/fetchData.ts index 8dfc241..b62c0b0 100644 --- a/src/utils/fetchData.ts +++ b/src/utils/fetchData.ts @@ -18,11 +18,17 @@ import { } from 'clarity-codegen'; export async function getAlexSDKData(): Promise { - return fetch(configs.SDK_API_HOST).then((r) => { + return fetch(configs.SDK_API_HOST).then((r): Promise => { if (r.ok) { return r.json(); } throw new Error('Failed to fetch token mappings'); + }).then(x => { + for (const a of x.pools) { + a.poolId = BigInt(a.poolId) + a.factor = BigInt(a.factor) + } + return x }); } @@ -99,7 +105,7 @@ export async function fetchBalanceForAccount( return [ a.id, (BigInt(amount) * BigInt(1e8)) / - BigInt(10 ** a.underlyingTokenDecimals), + BigInt(10 ** a.underlyingTokenDecimals), ]; } if (a.id === Currency.STX) { @@ -113,7 +119,7 @@ export async function fetchBalanceForAccount( return [ a.id, (BigInt(fungibleToken) * BigInt(1e8)) / - BigInt(10 ** a.underlyingTokenDecimals), + BigInt(10 ** a.underlyingTokenDecimals), ]; }) ) diff --git a/test/ammRouteResolver.test.ts b/test/ammRouteResolver.test.ts index fe0c6f0..2f20441 100644 --- a/test/ammRouteResolver.test.ts +++ b/test/ammRouteResolver.test.ts @@ -108,5 +108,6 @@ function toPoolData(pool: string): PoolData { tokenX: tokenX as Currency, tokenY: tokenY as Currency, factor: BigInt(Number(factor) * 1e8), + poolId: BigInt(0), }; } diff --git a/test/mock-data/alexSDKMockResponses.ts b/test/mock-data/alexSDKMockResponses.ts index 175b7ed..da530b9 100644 --- a/test/mock-data/alexSDKMockResponses.ts +++ b/test/mock-data/alexSDKMockResponses.ts @@ -23,6 +23,7 @@ export const dummyAmmRoute: AMMRouteSegment[] = [ tokenX: dummyTokenA, tokenY: dummyTokenC, factor: dummyFactorA, + poolId: BigInt(1), }, }, { @@ -32,6 +33,7 @@ export const dummyAmmRoute: AMMRouteSegment[] = [ tokenX: dummyTokenC, tokenY: dummyTokenB, factor: dummyFactorB, + poolId: BigInt(2), }, }, ];