rainbow-swap-sdk 1.4.4 → 1.4.6

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
@@ -1,73 +1,88 @@
1
1
  # Rainbow Swap 🌈 SDK
2
2
 
3
- This SDK is designed for building applications on top of [Rainbow Swap 🌈](https://github.com/0xblackbot/rainbow-swap) - The Next Gen DEX Aggregator on the TON blockchain 💎.
3
+ This SDK is designed for building applications on top of [Rainbow.ag](https://github.com/0xblackbot/rainbow-swap) - Swap Aggregator on TON blockchain 💎.
4
4
 
5
- ---
5
+ ---
6
6
 
7
- **We have plans to integrate commissions and share them with those who have integrated this SDK into their DApps.**
7
+ **To receive your `partnerId`, set custom fees, and enjoy a 50% revenue share, contact us in our [Community Chat](https://t.me/rainbow_swap_chat).**
8
8
 
9
9
  ---
10
10
 
11
11
  [![npm version](https://badge.fury.io/js/rainbow-swap-sdk.svg)](https://badge.fury.io/js/rainbow-swap-sdk)
12
12
  ![NPM License](https://img.shields.io/npm/l/rainbow-swap-sdk)
13
13
 
14
- ### Installation
14
+ ## Installation
15
+
16
+ You can install the Rainbow Swap SDK using either npm or Yarn:
15
17
 
16
- To install the rainbow-swap-sdk, use the following npm command:
18
+ **Using npm:**
17
19
  ```shell
18
20
  npm install rainbow-swap-sdk
19
21
  ```
20
22
 
21
- ### Integrate your dApp
22
-
23
- ```typescript
24
- import {
25
- getAssetsRecord,
26
- getBestRoute
27
- } from 'rainbow-swap-sdk';
28
-
29
- // 1. Load the list of available tokens
30
- const assetsRecord = await getAssetsRecord();
23
+ **Using Yarn:**
24
+ ```shell
25
+ yarn add rainbow-swap-sdk
26
+ ```
31
27
 
32
- ...
28
+ ## Integrate Your dApp
33
29
 
34
- // 2. Load the best swap route & swap messages
35
- const params = {
36
- inputAssetAmount: '1000000000', // 1 TON in nano
37
- inputAssetAddress: 'ton', // TON
38
- outputAssetAddress: 'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs', // USDT jetton master address
39
- maxDepth: 2, // optional number of maximum route length (should be in range from 1 to 3)
40
- userAddress: 'UQDGGjjuwhikx8ZPJsrLbKXGq7mx26D8pK_l8GqBejzB52Pa', // optional user wallet address, if set - swapMessages will return
41
- slippageTolerance: 5 // optional max slippage value (should be in range )
42
- };
30
+ ### Example: Swapping 1.35 TON to USDT
43
31
 
44
- const bestRouteResponse = await getBestRoute(params);
32
+ ```typescript
33
+ import {getAssetsList, getBestRoute, toNano} from 'rainbow-swap-sdk';
45
34
 
46
- const bestRoute = bestRouteResponse.bestRoute; // Route of the best possible swap route
47
- const swapMessages = bestRouteResponse.swapMessages; // Array of messages that should be sent to @tonconnect
35
+ // 1. Load the list of available tokens
36
+ const assetsList = await getAssetsList({
37
+ userAssets: [] // Array of asset addresses the user holds; see AssetsListParams for more details.
38
+ });
39
+
40
+ // Retrieve specific assets by their address
41
+ const inputAsset = assetsList.find(asset => asset.address === 'ton');
42
+ const outputAsset = assetsList.find(asset => asset.address === 'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs');
43
+
44
+ // 2. Load the best swap route and swap messages
45
+ const bestRouteResponse = await getBestRoute({
46
+ inputAssetAmount: toNano('1.35', inputAsset.decimals).toString(), // Convert 1.35 TON to nano format
47
+ inputAssetAddress: inputAsset.address,
48
+ outputAssetAddress: outputAsset.address,
49
+ senderAddress: 'UQDGGjjuwhikx8ZPJsrLbKXGq7mx26D8pK_l8GqBejzB52Pa', // Optional user wallet address; if set, swap messages will be returned
50
+ partnerId: 'demo-partner' // Optional unique identifier in our App Developer Partnership program
51
+ });
52
+
53
+ // 3. Sign and send messages to the blockchain to execute the swap.
54
+ // This example uses the React UI client. For other frameworks, refer to https://docs.ton.org/develop/dapps/ton-connect/overview
55
+ import {useTonConnectUI} from '@tonconnect/ui-react';
56
+
57
+ const [tonConnectUI] = useTonConnectUI();
58
+
59
+ const result = await tonConnectUI.sendTransaction({
60
+ validUntil: Math.floor(Date.now() / 1000) + 60, // 60 seconds from now
61
+ messages: bestRouteResponse.swapMessages
62
+ });
48
63
  ```
49
64
 
50
- ### Application status check
65
+ ## Application Status Check
51
66
 
52
- Additionally, you might want to check if everything is functioning correctly. For instance, you could temporarily disable swaps if block production on TON is disrupted due to the DOGS listing.
67
+ You may want to check the status of your application to ensure everything is functioning correctly. For example, temporarily disable swaps if block production on TON is disrupted due to an external event like the DOGS listing.
53
68
 
54
69
  ```typescript
55
- import { getAppStatus } from 'rainbow-swap-sdk';
70
+ import {getAppStatus} from 'rainbow-swap-sdk';
56
71
 
57
72
  const {
58
- isSwapsEnabled, // true - if everything works fine
59
- message // explanations why swaps are disabled
73
+ isSwapsEnabled, // true if everything is working fine
74
+ message // Explanation of why swaps are disabled, if applicable
60
75
  } = await getAppStatus();
61
76
  ```
62
77
 
63
- ### Live example
78
+ ## Live Example
64
79
 
65
- For a live example of using the SDK, visit [Rainbow Swap 🌈 repository](https://github.com/0xblackbot/rainbow-swap).
80
+ For a live example of using the SDK, visit the [Rainbow Swap 🌈 Repository](https://github.com/0xblackbot/rainbow-swap).
66
81
 
67
- ### Contact
82
+ ## Contact
68
83
 
69
- For questions and suggestions, contact us at [Blackbot](https://blackbot.technology/).
84
+ For questions and suggestions, visit [Community Chat](https://t.me/rainbow_swap_chat).
70
85
 
71
- ### License
86
+ ## License
72
87
 
73
88
  This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
package/dist/index.d.ts CHANGED
@@ -7,9 +7,11 @@ export type { RouteStep } from './interfaces/route-step.interface';
7
7
  export type { RouteStepWithCalculation } from './interfaces/route-step-with-calculation.interface';
8
8
  export type { AppStatus } from './types/app-status.type';
9
9
  export type { Asset } from './types/asset.type';
10
+ export type { AssetsListParams } from './types/assets-list-patams.type';
10
11
  export type { AssetsRecord } from './types/assets-record.type';
11
12
  export type { BestRouteParams } from './types/best-route-params.type';
12
13
  export type { BestRouteResponse } from './types/best-route-response.type';
13
14
  export type { CalculatedSwapRoute } from './types/calculated-swap-route.type';
14
- export { getAssetsRecord, getBestRoute, getAppStatus } from './utils/api.utils';
15
+ export { getAssetsRecord, getAssetsList, getBestRoute, getAppStatus } from './utils/api.utils';
16
+ export { toNano, fromNano } from './utils/big-int.utils';
15
17
  export { getQueryId } from './utils/transfer-params.utils';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getQueryId = exports.getAppStatus = exports.getBestRoute = exports.getAssetsRecord = exports.SwapRouteType = exports.RouteDirectionEnum = exports.DexTypeEnum = exports.mapSwapRouteToRoute = void 0;
3
+ exports.getQueryId = exports.fromNano = exports.toNano = exports.getAppStatus = exports.getBestRoute = exports.getAssetsList = exports.getAssetsRecord = exports.SwapRouteType = exports.RouteDirectionEnum = exports.DexTypeEnum = exports.mapSwapRouteToRoute = void 0;
4
4
  var calculated_swap_route_utils_1 = require("./dexes/shared/calculated-swap-route.utils");
5
5
  Object.defineProperty(exports, "mapSwapRouteToRoute", { enumerable: true, get: function () { return calculated_swap_route_utils_1.mapSwapRouteToRoute; } });
6
6
  var dex_type_enum_1 = require("./enums/dex-type.enum");
@@ -11,7 +11,11 @@ var swap_route_type_enum_1 = require("./enums/swap-route-type.enum");
11
11
  Object.defineProperty(exports, "SwapRouteType", { enumerable: true, get: function () { return swap_route_type_enum_1.SwapRouteType; } });
12
12
  var api_utils_1 = require("./utils/api.utils");
13
13
  Object.defineProperty(exports, "getAssetsRecord", { enumerable: true, get: function () { return api_utils_1.getAssetsRecord; } });
14
+ Object.defineProperty(exports, "getAssetsList", { enumerable: true, get: function () { return api_utils_1.getAssetsList; } });
14
15
  Object.defineProperty(exports, "getBestRoute", { enumerable: true, get: function () { return api_utils_1.getBestRoute; } });
15
16
  Object.defineProperty(exports, "getAppStatus", { enumerable: true, get: function () { return api_utils_1.getAppStatus; } });
17
+ var big_int_utils_1 = require("./utils/big-int.utils");
18
+ Object.defineProperty(exports, "toNano", { enumerable: true, get: function () { return big_int_utils_1.toNano; } });
19
+ Object.defineProperty(exports, "fromNano", { enumerable: true, get: function () { return big_int_utils_1.fromNano; } });
16
20
  var transfer_params_utils_1 = require("./utils/transfer-params.utils");
17
21
  Object.defineProperty(exports, "getQueryId", { enumerable: true, get: function () { return transfer_params_utils_1.getQueryId; } });
@@ -0,0 +1,25 @@
1
+ export type AssetsListParams = {
2
+ /**
3
+ * A list of asset addresses that the user holds balances in.
4
+ *
5
+ * **Example values:**
6
+ * - `'ton'` for TON.
7
+ * - `'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs'` for USDT.
8
+ *
9
+ * **Default:** An empty array (`[]`), indicating no specified user assets.
10
+ */
11
+ userAssets?: string[];
12
+ /**
13
+ * A text string used to filter assets by symbol, name, or address.
14
+ *
15
+ * **Default:** An empty string (`''`), indicating no specific filter applied.
16
+ */
17
+ searchValue?: string;
18
+ /**
19
+ * The maximum number of assets (excluding user-owned) to return in the response.
20
+ * Acceptable values range from 10 to 200.
21
+ *
22
+ * **Default:** `100`
23
+ */
24
+ limit?: number;
25
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ export type BestRouteDisplayData = {
2
+ inputAssetAmount: number;
3
+ inputAssetUsdAmount: number;
4
+ outputAssetAmount: number;
5
+ outputAssetUsdAmount: number;
6
+ minOutputAssetAmount: number;
7
+ exchangeRate: number;
8
+ maxSlippage: number;
9
+ routingFeePercent: number;
10
+ priceImprovementPercent: number;
11
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +1,60 @@
1
1
  export type BestRouteParams = {
2
+ /**
3
+ * The amount of the input asset that the user wants to send, specified in nano units.
4
+ * This should be a string representation of a bigint value.
5
+ *
6
+ * **Example:** `'1350000000'` (represents 1.35 TON in nano).
7
+ */
2
8
  inputAssetAmount: string;
9
+ /**
10
+ * The address or identifier of the asset that the user wants to send.
11
+ *
12
+ * **Example:**
13
+ * - `'ton'` for TON.
14
+ * - `'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs'` for USDT.
15
+ */
3
16
  inputAssetAddress: string;
17
+ /**
18
+ * The address or identifier of the asset that the user wants to receive.
19
+ *
20
+ * **Example:**
21
+ * - `'ton'` for TON.
22
+ * - `'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs'` for USDT.
23
+ */
4
24
  outputAssetAddress: string;
25
+ /**
26
+ * (Optional) The maximum length of the route.
27
+ * Should be a number between **1 and 3** (inclusive).
28
+ *
29
+ * **Default:** `2`
30
+ */
5
31
  maxDepth?: number;
32
+ /**
33
+ * (Optional) The wallet address of the user.
34
+ * If not provided, the `swapMessages` will return an empty array (`[]`).
35
+ */
6
36
  senderAddress?: string;
37
+ /**
38
+ * (Optional) The percentage setting for slippage tolerance.
39
+ * Should be a number between **0 and 100** (inclusive).
40
+ *
41
+ * **Example:** `1.5` for 1.5% slippage tolerance.
42
+ *
43
+ * **Default:** `5`
44
+ */
7
45
  maxSlippage?: number;
46
+ /**
47
+ * (Optional) The referral address of a user.
48
+ * Refer a new user and earn a share of their trading fees.
49
+ *
50
+ * For more details, visit the **Rewards Center** at [rainbow.ag](https://rainbow.ag).
51
+ */
52
+ referralAddress?: string;
53
+ /**
54
+ * (Optional) A unique identifier in our App Developer Partnership program.
55
+ * Integrate our SDK to enable in-app swaps, set custom fees, and enjoy a 50% revenue share.
56
+ *
57
+ * For more details, contact us at **Community Chat**: [https://t.me/rainbow_swap_chat](https://t.me/rainbow_swap_chat).
58
+ */
59
+ partnerId?: string;
8
60
  };
@@ -1,17 +1,22 @@
1
+ import { BestRouteDisplayData } from './best-route-display-data.type';
1
2
  import { CalculatedSwapRoute } from './calculated-swap-route.type';
2
3
  import { Message } from '../interfaces/message.interface';
3
4
  export type BestRouteResponse = {
4
- bestRoute: CalculatedSwapRoute[];
5
- displayData: {
6
- inputAssetAmount: number;
7
- inputAssetUsdAmount: number;
8
- outputAssetAmount: number;
9
- outputAssetUsdAmount: number;
10
- minOutputAssetAmount: number;
11
- exchangeRate: number;
12
- maxSlippage: number;
13
- routingFeePercent: number;
14
- priceImprovementPercent: number;
15
- };
5
+ /**
6
+ * A user-friendly representation of the best route details.
7
+ */
8
+ displayData: BestRouteDisplayData;
9
+ /**
10
+ * An array of messages that should be signed and sent to the blockchain to execute the swap.
11
+ *
12
+ * - For TON dApps, it is recommended to use `@tonconnect/sdk`.
13
+ * - If the `senderAddress` parameter in the request was not set, an empty array (`[]`) will be returned.
14
+ * - An empty array in other cases indicates that no route was found between the input asset and the output asset.
15
+ */
16
16
  swapMessages: Message[];
17
+ /**
18
+ * Detailed information about the most efficient routes for swapping the user's input asset,
19
+ * taking into account swap distribution and gas costs.
20
+ */
21
+ bestRoute: CalculatedSwapRoute[];
17
22
  };
@@ -1,7 +1,10 @@
1
1
  import { AppStatus } from '../types/app-status.type';
2
+ import { Asset } from '../types/asset.type';
3
+ import { AssetsListParams } from '../types/assets-list-patams.type';
2
4
  import { AssetsRecord } from '../types/assets-record.type';
3
5
  import { BestRouteParams } from '../types/best-route-params.type';
4
6
  import { BestRouteResponse } from '../types/best-route-response.type';
5
7
  export declare const getAssetsRecord: () => Promise<AssetsRecord>;
8
+ export declare const getAssetsList: (params: AssetsListParams) => Promise<Asset[]>;
6
9
  export declare const getBestRoute: (params: BestRouteParams) => Promise<BestRouteResponse>;
7
10
  export declare const getAppStatus: () => Promise<AppStatus>;
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAppStatus = exports.getBestRoute = exports.getAssetsRecord = void 0;
3
+ exports.getAppStatus = exports.getBestRoute = exports.getAssetsList = exports.getAssetsRecord = void 0;
4
4
  const globals_1 = require("../globals");
5
5
  const getAssetsRecord = () => globals_1.API.get('/assets-record').then(response => response.data);
6
6
  exports.getAssetsRecord = getAssetsRecord;
7
+ const getAssetsList = (params) => globals_1.API.post('/assets-list', params).then(response => response.data);
8
+ exports.getAssetsList = getAssetsList;
7
9
  const getBestRoute = (params) => globals_1.API.get('/best-route', { params }).then(response => response.data);
8
10
  exports.getBestRoute = getBestRoute;
9
11
  const getAppStatus = () => globals_1.API.get('/app-status').then(response => response.data);
@@ -0,0 +1,2 @@
1
+ export declare const toNano: (src: string, decimals: number) => bigint;
2
+ export declare const fromNano: (value: bigint, decimals: number) => string;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fromNano = exports.toNano = void 0;
4
+ const toNano = (src, decimals) => {
5
+ const precision = 10n ** BigInt(decimals);
6
+ // Check sign
7
+ let neg = false;
8
+ while (src.startsWith('-')) {
9
+ neg = !neg;
10
+ src = src.slice(1);
11
+ }
12
+ // Split string
13
+ if (src === '.') {
14
+ throw Error('Invalid number');
15
+ }
16
+ const parts = src.split('.');
17
+ if (parts.length > 2) {
18
+ throw Error('Invalid number');
19
+ }
20
+ // Prepare parts
21
+ let whole = parts[0];
22
+ let frac = parts[1];
23
+ if (!whole) {
24
+ whole = '0';
25
+ }
26
+ if (!frac) {
27
+ frac = '';
28
+ }
29
+ if (frac.length > decimals) {
30
+ throw Error('Invalid number');
31
+ }
32
+ while (frac.length < decimals) {
33
+ frac += '0';
34
+ }
35
+ // Convert
36
+ let r = BigInt(whole) * precision + BigInt(frac);
37
+ if (neg) {
38
+ r = -r;
39
+ }
40
+ return r;
41
+ };
42
+ exports.toNano = toNano;
43
+ const fromNano = (value, decimals) => String(Number(value) / 10 ** decimals);
44
+ exports.fromNano = fromNano;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rainbow-swap-sdk",
3
- "version": "1.4.4",
4
- "description": "SDK for building applications on top of Rainbow Swap - Swap Aggregator on TON 💎.",
3
+ "version": "1.4.6",
4
+ "description": "SDK for building applications on top of Rainbow.ag - Swap Aggregator on TON 💎.",
5
5
  "repository": "https://github.com/0xblackbot/rainbow-swap-sdk.git",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/index.js",