Skip to content

Commit bea4011

Browse files
committed
fix: change input from number to bigint
1 parent d85983d commit bea4011

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

src/services/router/router.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class Router extends Services {
66
public async findBestRoute(
77
inputAssetAddress: string,
88
outputAssetAddress: string,
9-
payAmount: number,
9+
payAmount: bigint,
1010
slippage?: number,
1111
forceDex?: Dex,
1212
) {
@@ -16,7 +16,7 @@ export class Router extends Services {
1616
const body = {
1717
token0: inputAssetAddress,
1818
token1: outputAssetAddress,
19-
amount: toNano(payAmount).toString(),
19+
amount: payAmount.toString(),
2020
slippage: slippage ?? 'auto',
2121
token0_symbol: 'SDK',
2222
token1_symbol: 'SDK',

src/services/router/router.test.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { beforeAll, beforeEach, expect, test } from 'bun:test';
22
import { MyTonSwapClient } from '../../core/client';
3+
import { toNano } from '../../utils';
34
let client: MyTonSwapClient;
45

56
beforeEach(() => {
@@ -12,7 +13,11 @@ test('it should find a route for a pair', async () => {
1213
expect(asset0).not.toBeNull();
1314
expect(asset1).not.toBeNull();
1415

15-
const bestRoute = await client.router.findBestRoute(asset0!.address, asset1!.address, 1000);
16+
const bestRoute = await client.router.findBestRoute(
17+
asset0!.address,
18+
asset1!.address,
19+
toNano(1000),
20+
);
1621
expect(bestRoute.selected_pool.dex).toBe('stonfi');
1722
});
1823

@@ -22,7 +27,11 @@ test('it should select dedust for scale', async () => {
2227
expect(asset0).not.toBeNull();
2328
expect(asset1).not.toBeNull();
2429

25-
const bestRoute = await client.router.findBestRoute(asset0!.address, asset1!.address, 1000);
30+
const bestRoute = await client.router.findBestRoute(
31+
asset0!.address,
32+
asset1!.address,
33+
toNano(1000),
34+
);
2635
expect(bestRoute.selected_pool.dex).toBe('dedust');
2736
});
2837

@@ -32,7 +41,11 @@ test('it should select ston for ston', async () => {
3241
expect(asset0).not.toBeNull();
3342
expect(asset1).not.toBeNull();
3443

35-
const bestRoute = await client.router.findBestRoute(asset0!.address, asset1!.address, 1000);
44+
const bestRoute = await client.router.findBestRoute(
45+
asset0!.address,
46+
asset1!.address,
47+
toNano(1000),
48+
);
3649
expect(bestRoute.selected_pool.dex).toBe('stonfi');
3750
});
3851

@@ -42,6 +55,10 @@ test('it should impact price on large amount input', async () => {
4255
expect(asset0).not.toBeNull();
4356
expect(asset1).not.toBeNull();
4457

45-
const bestRoute = await client.router.findBestRoute(asset0!.address, asset1!.address, 100000);
58+
const bestRoute = await client.router.findBestRoute(
59+
asset0!.address,
60+
asset1!.address,
61+
toNano(100000),
62+
);
4663
expect(bestRoute.pool_data.priceImpact).toBeGreaterThan(90);
4764
});

src/services/swap/swap.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from '../../constants';
1919
import { Services } from '../../core/services';
2020
import { BestRoute } from '../../types/router';
21-
import { Balance, CustomPayload } from '../../types/swap';
21+
import { Balance } from '../../types/swap';
2222
import { DEX, pTON } from '@ston-fi/sdk';
2323
import {
2424
Asset,

src/services/swap/swap.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test(
1818
const bestRoute = await client.router.findBestRoute(
1919
TON!.address,
2020
NOT!.address,
21-
1,
21+
toNano(1),
2222
1,
2323
'stonfi',
2424
);
@@ -39,7 +39,7 @@ test(
3939
const bestRoute = await client.router.findBestRoute(
4040
TON!.address,
4141
NOT!.address,
42-
1,
42+
toNano(1),
4343
1,
4444
'dedust',
4545
);
@@ -50,3 +50,9 @@ test(
5050
},
5151
{ timeout: 10000 },
5252
);
53+
54+
test('it should successfully swap tokens', async () => {
55+
const TON = await client.assets.getExactAsset('TON');
56+
const NOT = await client.assets.getExactAsset('NOT');
57+
const bestRoute = client.router.findBestRoute(TON!.address, NOT!.address, toNano(1));
58+
});

0 commit comments

Comments
 (0)