rainbow-swap-sdk 1.1.18 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,10 +23,7 @@ npm install rainbow-swap-sdk
23
23
  ```typescript
24
24
  import {
25
25
  getAssetsRecord,
26
- getIsRainbowWalletActive,
27
26
  getBestRoute,
28
- getIsActivationRequired,
29
- getRainbowWalletActivationMessages,
30
27
  getSwapMessages
31
28
  } from 'rainbow-swap-sdk';
32
29
 
@@ -35,13 +32,7 @@ const assetsRecord = await getAssetsRecord();
35
32
 
36
33
  ...
37
34
 
38
- // 2. On wallet connection: check if `Rainbow Wallet` smart contract is active
39
- const userAddress = 'UQDGGjjuwhikx8ZPJsrLbKXGq7mx26D8pK_l8GqBejzB52Pa'; // user wallet address
40
- const isRainbowWalletActive = await getIsRainbowWalletActive(userAddress);
41
-
42
- ...
43
-
44
- // 3. On input asset amount, input asset, or output asset change: fetch a new swap route
35
+ // 2. On input asset amount, input asset, or output asset change: fetch a new swap route
45
36
  const params = {
46
37
  inputAssetAmount: '1000000000', // 1 TON in nano
47
38
  inputAssetAddress: 'ton', // TON
@@ -51,23 +42,15 @@ const bestRouteResponse = await getBestRoute(params);
51
42
 
52
43
  ...
53
44
 
54
- // 4. Generate sign request messages
55
-
56
- // Check if `Rainbow Wallet` Smart Contract Activation is Required
57
- const isActivationRequired = getIsActivationRequired(bestRouteResponse.bestRoute, isRainbowWalletActive);
58
-
59
- if (isActivationRequired) {
60
- // If activation is required, the user needs to sign rainbowWalletActivationMessages first
61
- const activationMessages = getRainbowWalletActivationMessages(userAddress);
62
- } else {
63
- // After the transaction is confirmed, or if activation is not required, the user can proceed with the swap transaction
64
- const slippageTolerance = '2.5'; // 2.5%
65
- const swapMessages = await getSwapMessages(
66
- userAddress,
67
- bestRouteResponse.bestRoute,
68
- slippageTolerance
69
- );
70
- }
45
+ // 3. Generate sign request messages & send it via @tonconnect
46
+ const userAddress = 'UQDGGjjuwhikx8ZPJsrLbKXGq7mx26D8pK_l8GqBejzB52Pa'; // user wallet address
47
+ const slippageTolerance = 2.5; // 2.5%
48
+
49
+ const swapMessages = await getSwapMessages(
50
+ userAddress,
51
+ bestRouteResponse.bestRoute,
52
+ slippageTolerance
53
+ );
71
54
  ```
72
55
 
73
56
  ### Live example
@@ -1,6 +1,6 @@
1
1
  import { Address } from '@ton/core';
2
2
  import { RouteStepWithCalculation } from '../../interfaces/route-step-with-calculation.interface';
3
- export declare const dedust_getTransferParams: (route: RouteStepWithCalculation[], queryId: number, gasAmount: bigint, senderAddress: Address, receiverAddress: Address, responseDestination: Address, slippageTolerance: string) => Promise<{
3
+ export declare const dedust_getTransferParams: (route: RouteStepWithCalculation[], queryId: number, gasAmount: bigint, senderAddress: Address, receiverAddress: Address, responseDestination: Address, slippageTolerance: number) => Promise<{
4
4
  to: Address;
5
5
  value: bigint;
6
6
  body: import("@ton/core").Cell;
@@ -22,7 +22,7 @@ export declare const packJettonReceiveEffect: (params: {
22
22
  effectType: EffectType;
23
23
  fullBody: Cell;
24
24
  }) => Cell;
25
- export declare const getDexTransferParams: (route: RouteStepWithCalculation[], queryId: number, gasAmount: bigint, senderAddress: Address, receiverAddress: Address, responseDestination: Address, slippageTolerance: string) => Promise<{
25
+ export declare const getDexTransferParams: (route: RouteStepWithCalculation[], queryId: number, gasAmount: bigint, senderAddress: Address, receiverAddress: Address, responseDestination: Address, slippageTolerance: number) => Promise<{
26
26
  to: Address;
27
27
  value: bigint;
28
28
  body: Cell;
@@ -1,4 +1,4 @@
1
1
  import { Address } from '@ton/core';
2
2
  import { RouteStepWithCalculation } from '../../interfaces/route-step-with-calculation.interface';
3
3
  import { TransferParams } from '../../interfaces/transfer-params.interface';
4
- export declare const rainbow_getTransferParams: (firstChunk: RouteStepWithCalculation[], secondChunk: RouteStepWithCalculation[], queryId: number, gasAmount: bigint, senderAddress: Address, slippageTolerance: string) => Promise<TransferParams>;
4
+ export declare const rainbow_getTransferParams: (firstChunk: RouteStepWithCalculation[], secondChunk: RouteStepWithCalculation[], queryId: number, gasAmount: bigint, senderAddress: Address, slippageTolerance: number) => Promise<TransferParams>;
@@ -32,7 +32,7 @@ const rainbow_getTransferParams = async (firstChunk, secondChunk, queryId, gasAm
32
32
  });
33
33
  const tweakedSlippageTolerance = firstChunk[0].dexType === dex_type_enum_1.DexTypeEnum.Ston &&
34
34
  firstChunk[0].inputAssetAmount !== globals_1.TON
35
- ? '100' // We could not handle Ston.fi returned jettons
35
+ ? 100 // We could not handle Ston.fi returned jettons
36
36
  : slippageTolerance;
37
37
  const firstChunk_transferParams = await (0, transfer_params_pack_utils_1.getDexTransferParams)(firstChunk, queryId, gasAmount + jettonReceiveEffectGasAmount, rainbowWallet.address, rainbowWallet.address, senderAddress, tweakedSlippageTolerance);
38
38
  if (inputAssetAddress === globals_1.TON) {
@@ -1 +1 @@
1
- export declare const applySlippageTolerance: (amount: string, slippageTolerance: string) => bigint;
1
+ export declare const applySlippageTolerance: (amount: string, slippageTolerance: number) => bigint;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applySlippageTolerance = void 0;
4
+ const PRECISION = 10 ** 6;
4
5
  const applySlippageTolerance = (amount, slippageTolerance) => {
5
- const decimals = slippageTolerance.split('.')[1]?.length || 0;
6
- const multiplier = BigInt(10 ** decimals);
7
- return ((BigInt(amount) *
8
- BigInt(Math.floor((100 - parseFloat(slippageTolerance)) * Number(multiplier)))) /
9
- (BigInt(100) * multiplier));
6
+ const amountBigInt = BigInt(amount);
7
+ const slippageAmount = (amountBigInt * BigInt(Math.ceil(slippageTolerance * PRECISION))) /
8
+ BigInt(100 * PRECISION);
9
+ return amountBigInt - slippageAmount;
10
10
  };
11
11
  exports.applySlippageTolerance = applySlippageTolerance;
@@ -1,7 +1,7 @@
1
1
  import { Address } from '@ton/core';
2
2
  import { TransferParams } from '../../interfaces/transfer-params.interface';
3
3
  import { CalculatedSwapRoute } from '../../types/calculated-swap-route.type';
4
- export declare const getSwapRouteTransferParams: (swapRoute: CalculatedSwapRoute, senderAddress: Address, slippageTolerance: string) => Promise<{
4
+ export declare const getSwapRouteTransferParams: (swapRoute: CalculatedSwapRoute, senderAddress: Address, slippageTolerance: number) => Promise<{
5
5
  to: Address;
6
6
  value: bigint;
7
7
  body: import("@ton/core").Cell;
@@ -1,6 +1,6 @@
1
1
  import { Address } from '@ton/core';
2
2
  import { RouteStepWithCalculation } from '../../interfaces/route-step-with-calculation.interface';
3
- export declare const ston_getTransferParams: (routeStep: RouteStepWithCalculation, queryId: number, gasAmount: bigint, senderAddress: Address, receiverAddress: Address, responseDestination: Address, slippageTolerance: string) => Promise<{
3
+ export declare const ston_getTransferParams: (routeStep: RouteStepWithCalculation, queryId: number, gasAmount: bigint, senderAddress: Address, receiverAddress: Address, responseDestination: Address, slippageTolerance: number) => Promise<{
4
4
  to: Address;
5
5
  value: bigint;
6
6
  body: import("@ton/core").Cell;
@@ -1,4 +1,4 @@
1
1
  import { Message } from '../interfaces/message.interface';
2
2
  import { CalculatedSwapRoute } from '../types/calculated-swap-route.type';
3
- export declare const getSwapMessages: (senderAddress: string, bestRoute: CalculatedSwapRoute[], slippageTolerance: string) => Promise<Message[]>;
3
+ export declare const getSwapMessages: (senderAddress: string, bestRoute: CalculatedSwapRoute[], slippageTolerance: number) => Promise<Message[]>;
4
4
  export declare const getRainbowWalletActivationMessages: (senderAddress: string) => Message[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rainbow-swap-sdk",
3
- "version": "1.1.18",
3
+ "version": "1.2.0",
4
4
  "description": "SDK for building applications on top of Rainbow Swap 🌈 - The Next Gen DEX Aggregator on TON 💎.",
5
5
  "repository": "https://github.com/0xblackbot/rainbow-swap-sdk.git",
6
6
  "license": "Apache-2.0",
@@ -16,11 +16,11 @@
16
16
  "release": "release-it patch --release-version"
17
17
  },
18
18
  "dependencies": {
19
- "@rnw-community/shared": "^0.73.0",
20
- "@ton/core": "^0.56.3",
21
- "@ton/crypto": "^3.2.0",
22
- "@ton/ton": "^14.0.0",
23
- "axios": "^1.7.2",
19
+ "@rnw-community/shared": "^0.74.0",
20
+ "@ton/core": "^0.57.0",
21
+ "@ton/crypto": "^3.3.0",
22
+ "@ton/ton": "^15.0.0",
23
+ "axios": "^1.7.3",
24
24
  "buffer": "^6.0.3"
25
25
  },
26
26
  "devDependencies": {