rainbow-swap-sdk 1.3.6 → 1.4.1

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.
Files changed (46) hide show
  1. package/dist/globals.d.ts +0 -9
  2. package/dist/globals.js +1 -12
  3. package/dist/index.d.ts +0 -2
  4. package/dist/index.js +1 -7
  5. package/dist/types/best-route-response.type.d.ts +1 -0
  6. package/package.json +3 -7
  7. package/dist/dexes/dedust/sdk.d.ts +0 -14
  8. package/dist/dexes/dedust/sdk.js +0 -4
  9. package/dist/dexes/dedust/transfer-params-pack.utils.d.ts +0 -16
  10. package/dist/dexes/dedust/transfer-params-pack.utils.js +0 -48
  11. package/dist/dexes/dedust/transfer-params.utils.d.ts +0 -7
  12. package/dist/dexes/dedust/transfer-params.utils.js +0 -73
  13. package/dist/dexes/dedust/vault.utils.d.ts +0 -2
  14. package/dist/dexes/dedust/vault.utils.js +0 -28
  15. package/dist/dexes/rainbow/rainbow-wallet.contract.d.ts +0 -21
  16. package/dist/dexes/rainbow/rainbow-wallet.contract.js +0 -32
  17. package/dist/dexes/rainbow/transfer-params-pack.utils.d.ts +0 -29
  18. package/dist/dexes/rainbow/transfer-params-pack.utils.js +0 -55
  19. package/dist/dexes/rainbow/transfer-params.utils.d.ts +0 -4
  20. package/dist/dexes/rainbow/transfer-params.utils.js +0 -73
  21. package/dist/dexes/shared/slippage-tolerance.utils.d.ts +0 -1
  22. package/dist/dexes/shared/slippage-tolerance.utils.js +0 -11
  23. package/dist/dexes/shared/transfer-params.utils.d.ts +0 -9
  24. package/dist/dexes/shared/transfer-params.utils.js +0 -38
  25. package/dist/dexes/ston/sdk.d.ts +0 -3
  26. package/dist/dexes/ston/sdk.js +0 -6
  27. package/dist/dexes/ston/transfer-params-pack.utils.d.ts +0 -8
  28. package/dist/dexes/ston/transfer-params-pack.utils.js +0 -16
  29. package/dist/dexes/ston/transfer-params.utils.d.ts +0 -7
  30. package/dist/dexes/ston/transfer-params.utils.js +0 -56
  31. package/dist/dexes/ston-v2/sdk.d.ts +0 -10
  32. package/dist/dexes/ston-v2/sdk.js +0 -22
  33. package/dist/dexes/ston-v2/transfer-params-pack.utils.d.ts +0 -4
  34. package/dist/dexes/ston-v2/transfer-params-pack.utils.js +0 -86
  35. package/dist/dexes/ston-v2/transfer-params.utils.d.ts +0 -7
  36. package/dist/dexes/ston-v2/transfer-params.utils.js +0 -53
  37. package/dist/interfaces/transfer-params.interface.d.ts +0 -7
  38. package/dist/interfaces/transfer-params.interface.js +0 -2
  39. package/dist/utils/boc.utils.d.ts +0 -2
  40. package/dist/utils/boc.utils.js +0 -7
  41. package/dist/utils/jetton.utils.d.ts +0 -11
  42. package/dist/utils/jetton.utils.js +0 -30
  43. package/dist/utils/message.utils.d.ts +0 -4
  44. package/dist/utils/message.utils.js +0 -32
  45. package/dist/utils/rainbow-wallet.utils.d.ts +0 -3
  46. package/dist/utils/rainbow-wallet.utils.js +0 -22
package/dist/globals.d.ts CHANGED
@@ -1,10 +1 @@
1
- import { Address } from '@ton/core';
2
- import { TonClient } from '@ton/ton';
3
- export declare const TON = "ton";
4
- export declare const WORKCHAIN = 0;
5
1
  export declare const API: import("axios").AxiosInstance;
6
- export declare const TON_CLIENT: TonClient;
7
- export declare const GAS_AMOUNT: bigint;
8
- export declare const JETTON_TRANSFER_GAS_AMOUNT: bigint;
9
- export declare const REFERRAL_ADDRESS: Address;
10
- export declare const REFERRAL_VALUE = 0n;
package/dist/globals.js CHANGED
@@ -3,19 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.REFERRAL_VALUE = exports.REFERRAL_ADDRESS = exports.JETTON_TRANSFER_GAS_AMOUNT = exports.GAS_AMOUNT = exports.TON_CLIENT = exports.API = exports.WORKCHAIN = exports.TON = void 0;
7
- const core_1 = require("@ton/core");
8
- const ton_1 = require("@ton/ton");
6
+ exports.API = void 0;
9
7
  const axios_1 = __importDefault(require("axios"));
10
- exports.TON = 'ton';
11
- exports.WORKCHAIN = 0;
12
8
  exports.API = axios_1.default.create({
13
9
  baseURL: 'https://api.blackbot.technology/rainbow/api'
14
10
  });
15
- exports.TON_CLIENT = new ton_1.TonClient({
16
- endpoint: `https://api.blackbot.technology/ton-http-api/jsonRPC`
17
- });
18
- exports.GAS_AMOUNT = (0, core_1.toNano)('0.255');
19
- exports.JETTON_TRANSFER_GAS_AMOUNT = (0, core_1.toNano)('0.065');
20
- exports.REFERRAL_ADDRESS = core_1.Address.parse('UQBBPVrn4Y6F0Fci4j0mXuSAXmRDeE-nZCRIInQsNC9__8vG');
21
- exports.REFERRAL_VALUE = 0n;
package/dist/index.d.ts CHANGED
@@ -12,6 +12,4 @@ export type { BestRouteParams } from './types/best-route-params.type';
12
12
  export type { BestRouteResponse } from './types/best-route-response.type';
13
13
  export type { CalculatedSwapRoute } from './types/calculated-swap-route.type';
14
14
  export { getAssetsRecord, getBestRoute, getAppStatus } from './utils/api.utils';
15
- export { getSwapMessages, getRainbowWalletActivationMessages } from './utils/message.utils';
16
- export { getIsRainbowWalletActive, getIsActivationRequired } from './utils/rainbow-wallet.utils';
17
15
  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.getIsActivationRequired = exports.getIsRainbowWalletActive = exports.getRainbowWalletActivationMessages = exports.getSwapMessages = exports.getAppStatus = exports.getBestRoute = exports.getAssetsRecord = exports.SwapRouteType = exports.RouteDirectionEnum = exports.DexTypeEnum = exports.mapSwapRouteToRoute = void 0;
3
+ exports.getQueryId = exports.getAppStatus = exports.getBestRoute = 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");
@@ -13,11 +13,5 @@ var api_utils_1 = require("./utils/api.utils");
13
13
  Object.defineProperty(exports, "getAssetsRecord", { enumerable: true, get: function () { return api_utils_1.getAssetsRecord; } });
14
14
  Object.defineProperty(exports, "getBestRoute", { enumerable: true, get: function () { return api_utils_1.getBestRoute; } });
15
15
  Object.defineProperty(exports, "getAppStatus", { enumerable: true, get: function () { return api_utils_1.getAppStatus; } });
16
- var message_utils_1 = require("./utils/message.utils");
17
- Object.defineProperty(exports, "getSwapMessages", { enumerable: true, get: function () { return message_utils_1.getSwapMessages; } });
18
- Object.defineProperty(exports, "getRainbowWalletActivationMessages", { enumerable: true, get: function () { return message_utils_1.getRainbowWalletActivationMessages; } });
19
- var rainbow_wallet_utils_1 = require("./utils/rainbow-wallet.utils");
20
- Object.defineProperty(exports, "getIsRainbowWalletActive", { enumerable: true, get: function () { return rainbow_wallet_utils_1.getIsRainbowWalletActive; } });
21
- Object.defineProperty(exports, "getIsActivationRequired", { enumerable: true, get: function () { return rainbow_wallet_utils_1.getIsActivationRequired; } });
22
16
  var transfer_params_utils_1 = require("./utils/transfer-params.utils");
23
17
  Object.defineProperty(exports, "getQueryId", { enumerable: true, get: function () { return transfer_params_utils_1.getQueryId; } });
@@ -3,5 +3,6 @@ import { Message } from '../interfaces/message.interface';
3
3
  export type BestRouteResponse = {
4
4
  bestRoute: CalculatedSwapRoute[];
5
5
  priceImprovement: number;
6
+ routingFee: number;
6
7
  swapMessages: Message[];
7
8
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rainbow-swap-sdk",
3
- "version": "1.3.6",
4
- "description": "SDK for building applications on top of Rainbow Swap 🌈 - The Next Gen DEX Aggregator on TON 💎.",
3
+ "version": "1.4.1",
4
+ "description": "SDK for building applications on top of Rainbow Swap - 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",
@@ -17,11 +17,7 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@rnw-community/shared": "^0.74.0",
20
- "@ton/core": "^0.58.1",
21
- "@ton/crypto": "^3.3.0",
22
- "@ton/ton": "^15.0.0",
23
- "axios": "^1.7.7",
24
- "buffer": "^6.0.3"
20
+ "axios": "^1.7.7"
25
21
  },
26
22
  "devDependencies": {
27
23
  "@types/node": "^20.14.10",
@@ -1,14 +0,0 @@
1
- import { Address, Cell } from '@ton/core';
2
- export declare const DEDUST_FACTORY_ADDRESS = "EQBfBWT7X2BHg9tXAxzhz2aKiNTU1tpt5NsiK0uSDW_YAJ67";
3
- export interface SwapStep {
4
- poolAddress: Address;
5
- limit?: bigint;
6
- next?: SwapStep;
7
- }
8
- export interface SwapParams {
9
- deadline?: number;
10
- recipientAddress?: Address | null;
11
- referralAddress?: Address | null;
12
- fulfillPayload?: Cell | null;
13
- rejectPayload?: Cell | null;
14
- }
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEDUST_FACTORY_ADDRESS = void 0;
4
- exports.DEDUST_FACTORY_ADDRESS = 'EQBfBWT7X2BHg9tXAxzhz2aKiNTU1tpt5NsiK0uSDW_YAJ67';
@@ -1,16 +0,0 @@
1
- import { Address, Cell } from '@ton/core';
2
- import { SwapParams, SwapStep } from './sdk';
3
- export declare const packTonSwap: (params: {
4
- queryId: number;
5
- inputAmount: bigint;
6
- poolAddress: Address;
7
- minOutputAmount: bigint;
8
- nextSwapStep?: SwapStep;
9
- swapParams?: SwapParams;
10
- }) => Cell;
11
- export declare const packJettonSwap: (params: {
12
- poolAddress: Address;
13
- minOutputAmount: bigint;
14
- nextSwapStep?: SwapStep;
15
- swapParams?: SwapParams;
16
- }) => Cell;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.packJettonSwap = exports.packTonSwap = void 0;
4
- const shared_1 = require("@rnw-community/shared");
5
- const core_1 = require("@ton/core");
6
- var Operation;
7
- (function (Operation) {
8
- Operation[Operation["TON_SWAP"] = 3926267997] = "TON_SWAP";
9
- Operation[Operation["JETTON_SWAP"] = 3818968194] = "JETTON_SWAP";
10
- })(Operation || (Operation = {}));
11
- const packTonSwap = (params) => (0, core_1.beginCell)()
12
- .storeUint(Operation.TON_SWAP, 32)
13
- .storeUint(params.queryId, 64)
14
- .storeCoins(params.inputAmount)
15
- .storeAddress(params.poolAddress)
16
- .storeUint(0, 1)
17
- .storeCoins(params.minOutputAmount)
18
- .storeMaybeRef(packNextSwapStep(params.nextSwapStep))
19
- .storeRef(packSwapParams(params.swapParams))
20
- .endCell();
21
- exports.packTonSwap = packTonSwap;
22
- const packJettonSwap = (params) => (0, core_1.beginCell)()
23
- .storeUint(Operation.JETTON_SWAP, 32)
24
- .storeAddress(params.poolAddress)
25
- .storeUint(0, 1) // reserved
26
- .storeCoins(params.minOutputAmount)
27
- .storeMaybeRef(packNextSwapStep(params.nextSwapStep))
28
- .storeRef(packSwapParams(params.swapParams))
29
- .endCell();
30
- exports.packJettonSwap = packJettonSwap;
31
- const packNextSwapStep = (step) => {
32
- if (!(0, shared_1.isDefined)(step)) {
33
- return null;
34
- }
35
- return (0, core_1.beginCell)()
36
- .storeAddress(step.poolAddress)
37
- .storeUint(0, 1) // reserved
38
- .storeCoins(step.limit ?? 0n)
39
- .storeMaybeRef(packNextSwapStep(step.next))
40
- .endCell();
41
- };
42
- const packSwapParams = (params = {}) => (0, core_1.beginCell)()
43
- .storeUint(params.deadline ?? 0, 32)
44
- .storeAddress(params.recipientAddress ?? null)
45
- .storeAddress(params.referralAddress ?? null)
46
- .storeMaybeRef(params.fulfillPayload)
47
- .storeMaybeRef(params.rejectPayload)
48
- .endCell();
@@ -1,7 +0,0 @@
1
- import { Address } from '@ton/core';
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: number) => Promise<{
4
- to: Address;
5
- value: bigint;
6
- body: import("@ton/core").Cell;
7
- }>;
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dedust_getTransferParams = void 0;
4
- const core_1 = require("@ton/core");
5
- const transfer_params_pack_utils_1 = require("./transfer-params-pack.utils");
6
- const vault_utils_1 = require("./vault.utils");
7
- const globals_1 = require("../../globals");
8
- const jetton_utils_1 = require("../../utils/jetton.utils");
9
- const slippage_tolerance_utils_1 = require("../shared/slippage-tolerance.utils");
10
- const createNextSwapStepPayload = (remainingRoute, slippageTolerance) => {
11
- if (remainingRoute.length === 0) {
12
- return undefined;
13
- }
14
- const routeStep = remainingRoute[0];
15
- const poolAddress = core_1.Address.parse(routeStep.dexPair.dexPairAddress);
16
- const limit = (0, slippage_tolerance_utils_1.applySlippageTolerance)(routeStep.outputAssetAmount, slippageTolerance);
17
- const next = createNextSwapStepPayload(remainingRoute.slice(1), slippageTolerance);
18
- return {
19
- poolAddress,
20
- limit,
21
- next
22
- };
23
- };
24
- const dedust_getTransferParams = async (route, queryId, gasAmount, senderAddress, receiverAddress, responseDestination, slippageTolerance) => {
25
- if (route.length === 0) {
26
- throw new Error('Empty route');
27
- }
28
- const firstRouteStep = route[0];
29
- const vaultAddress = await (0, vault_utils_1.dedust_getVaultAddress)(firstRouteStep.inputAssetAddress);
30
- const poolAddress = core_1.Address.parse(firstRouteStep.dexPair.dexPairAddress);
31
- const minOutputAmount = (0, slippage_tolerance_utils_1.applySlippageTolerance)(firstRouteStep.outputAssetAmount, slippageTolerance);
32
- const nextSwapStep = createNextSwapStepPayload(route.slice(1), slippageTolerance);
33
- const swapParams = {
34
- recipientAddress: receiverAddress,
35
- referralAddress: globals_1.REFERRAL_ADDRESS
36
- };
37
- if (firstRouteStep.inputAssetAddress === globals_1.TON) {
38
- return {
39
- to: vaultAddress,
40
- value: gasAmount + BigInt(firstRouteStep.inputAssetAmount),
41
- body: (0, transfer_params_pack_utils_1.packTonSwap)({
42
- queryId,
43
- inputAmount: BigInt(firstRouteStep.inputAssetAmount),
44
- poolAddress,
45
- minOutputAmount,
46
- nextSwapStep,
47
- swapParams
48
- })
49
- };
50
- }
51
- else {
52
- const inputJettonWalletAddress = await (0, jetton_utils_1.getJettonWalletAddress)(firstRouteStep.inputAssetAddress, senderAddress);
53
- const jettonSwapPayload = (0, transfer_params_pack_utils_1.packJettonSwap)({
54
- poolAddress,
55
- minOutputAmount,
56
- nextSwapStep,
57
- swapParams
58
- });
59
- return {
60
- to: inputJettonWalletAddress,
61
- value: gasAmount + globals_1.JETTON_TRANSFER_GAS_AMOUNT,
62
- body: (0, jetton_utils_1.getJettonTransferBody)({
63
- queryId,
64
- amount: BigInt(firstRouteStep.inputAssetAmount),
65
- destination: vaultAddress,
66
- responseDestination: responseDestination,
67
- forwardTonAmount: gasAmount,
68
- forwardPayload: jettonSwapPayload
69
- })
70
- };
71
- }
72
- };
73
- exports.dedust_getTransferParams = dedust_getTransferParams;
@@ -1,2 +0,0 @@
1
- import { Address } from '@ton/core';
2
- export declare const dedust_getVaultAddress: (inputAssetAddress: string) => Promise<Address>;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dedust_getVaultAddress = void 0;
4
- const core_1 = require("@ton/core");
5
- const sdk_1 = require("./sdk");
6
- const globals_1 = require("../../globals");
7
- var AssetType;
8
- (function (AssetType) {
9
- AssetType[AssetType["TON"] = 0] = "TON";
10
- AssetType[AssetType["JETTON"] = 1] = "JETTON";
11
- })(AssetType || (AssetType = {}));
12
- const getAssetCell = (assetAddress) => {
13
- if (assetAddress === globals_1.TON) {
14
- return (0, core_1.beginCell)().storeUint(AssetType.TON, 4).endCell();
15
- }
16
- const jettonAddress = core_1.Address.parse(assetAddress);
17
- return (0, core_1.beginCell)()
18
- .storeUint(AssetType.JETTON, 4)
19
- .storeInt(jettonAddress.workChain, 8)
20
- .storeBuffer(jettonAddress.hash)
21
- .endCell();
22
- };
23
- const dedust_getVaultAddress = async (inputAssetAddress) => {
24
- const assetCell = getAssetCell(inputAssetAddress);
25
- const vaultAddressResponse = await globals_1.TON_CLIENT.runMethod(core_1.Address.parse(sdk_1.DEDUST_FACTORY_ADDRESS), 'get_vault_address', [{ type: 'slice', cell: assetCell }]);
26
- return vaultAddressResponse.stack.readAddress();
27
- };
28
- exports.dedust_getVaultAddress = dedust_getVaultAddress;
@@ -1,21 +0,0 @@
1
- import { Address, Cell, Contract } from '@ton/core';
2
- export declare enum RainbowWalletOperation {
3
- MAKE_A_SWAP = 430800,
4
- WITHDRAW_TON = 430801,
5
- WITHDRAW_JETTON = 430802
6
- }
7
- export declare class RainbowWalletContract implements Contract {
8
- readonly address: Address;
9
- readonly init?: {
10
- code: Cell;
11
- data: Cell;
12
- } | undefined;
13
- constructor(address: Address, init?: {
14
- code: Cell;
15
- data: Cell;
16
- } | undefined);
17
- static create: (args: {
18
- workchain: number;
19
- ownerAddress: Address;
20
- }) => RainbowWalletContract;
21
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RainbowWalletContract = exports.RainbowWalletOperation = void 0;
4
- const core_1 = require("@ton/core");
5
- const boc_utils_1 = require("../../utils/boc.utils");
6
- const CODE_BOC = 'te6ccgECEAEAAvsAART/APSkE/S88sgLAQIBYgIDAgLOBAUCAVgODwIBIAYHABlPhCyPhBzxb0AMntVIAu07aLt+zIhxwCRW+DwAQHTH9M/IoIQ1TJ227qOHzBsEgHIyx/LP8lxgBjIywX4Qc8WcPoCy2rMyYBA+wDgIoQfuo4fMGwSAcjLH8s/yXGAGMjLBfhBzxZw+gLLaszJgED7AOAD0NMDMfpAMPhBIccF4w+BImDy8IAgJAB07UTQ+kAB+GH0BAH4YtGAB/jAhgggGktC6jjkxAfpA1PpA1DCBAUvIUAPPFhXLP8nQBND4QkUDBfQS+GLwAnGAGMjLBVjPFnD6AstqzMmAQPsA2zHgIYIIBpLRuo4rMQH6ADCCENUydtvIyx8Syz/JcYAYyMsF+EHPFlAD+gISy2rMyYBA+wDbMeABgggGktIKAsgighBzYtCcuo7MMgL6APpA+EEixwWOPWwx9AQw0PpA1PpA1DCBAUvIUAPPFhXLP8nQBND4QkUDBfQS+GLwAnGAGMjLBVjPFnD6AstqzMmAQPsA2zHgMOAwMiCCEEdPhs+64wJbCwwAjLqOQQH6QPoAMG1tghAPin6lyMsfFcs/WPoC+EHPFvhBzxYT9ABw+gIS9ADJcYAYyMsFUAPPFnD6AhLLaszJgED7ANsx4FsBroEBS8hYzxZSQMs/ydD4QlRhMfQKb6GOO18DbW2CEA+KfqXIyx8Vyz9Y+gL4Qc8W+EHPFhP0AHD6AhL0AMlxgBjIywVQA88WcPoCEstqzMmAQPsA4w3bMQ0APgEByMsfyz/JcYAYyMsF+EHPFnD6AstqzMmAQPsA2zEA1jQD+kBAUwLTANQw0CHAAI4UMYIQD4p+pcjLHxLLP1j6AgHPFsmOIgHAAY4TghDqBhhdyMsfEss/WPoCAc8WyeBfA4EiYfLwyMnicYAYyMsFUAXPFnD6AhTLahPMyYBA+wD4Qlj0WTD4YvACABG6Xk8AH4QfhCgAL7tBPwAYEBS8hQA88Wyz/J0PhCWPQKb6GA==';
7
- var RainbowWalletOperation;
8
- (function (RainbowWalletOperation) {
9
- RainbowWalletOperation[RainbowWalletOperation["MAKE_A_SWAP"] = 430800] = "MAKE_A_SWAP";
10
- RainbowWalletOperation[RainbowWalletOperation["WITHDRAW_TON"] = 430801] = "WITHDRAW_TON";
11
- RainbowWalletOperation[RainbowWalletOperation["WITHDRAW_JETTON"] = 430802] = "WITHDRAW_JETTON";
12
- })(RainbowWalletOperation || (exports.RainbowWalletOperation = RainbowWalletOperation = {}));
13
- const storageToCell = (storage) => (0, core_1.beginCell)()
14
- .storeAddress(storage.ownerAddress)
15
- .storeDict(storage.effectsDict)
16
- .endCell();
17
- class RainbowWalletContract {
18
- constructor(address, init) {
19
- this.address = address;
20
- this.init = init;
21
- }
22
- }
23
- exports.RainbowWalletContract = RainbowWalletContract;
24
- RainbowWalletContract.create = (args) => {
25
- const code = (0, boc_utils_1.bocToCell)(CODE_BOC);
26
- const data = storageToCell({
27
- ownerAddress: args.ownerAddress,
28
- effectsDict: core_1.Dictionary.empty()
29
- });
30
- const init = { code, data };
31
- return new RainbowWalletContract((0, core_1.contractAddress)(args.workchain, init), init);
32
- };
@@ -1,29 +0,0 @@
1
- import { Address, Cell } from '@ton/core';
2
- import { RouteStepWithCalculation } from '../../interfaces/route-step-with-calculation.interface';
3
- export declare const packTonSwap: (params: {
4
- queryId: number;
5
- destination: Address;
6
- body: Cell;
7
- jettonSenderAddressToListen: Address;
8
- jettonReceiveEffect: Cell;
9
- }) => Cell;
10
- export declare const packJettonSwap: (params: {
11
- destination: Address;
12
- body: Cell;
13
- jettonSenderAddressToListen: Address;
14
- jettonReceiveEffect: Cell;
15
- }) => Cell;
16
- export declare enum EffectType {
17
- JettonTransfer = 0,
18
- DedustTonSwap = 1
19
- }
20
- export declare const packJettonReceiveEffect: (params: {
21
- destination: Address;
22
- effectType: EffectType;
23
- fullBody: Cell;
24
- }) => Cell;
25
- export declare const getDexTransferParams: (route: RouteStepWithCalculation[], queryId: number, gasAmount: bigint, senderAddress: Address, receiverAddress: Address, responseDestination: Address, slippageTolerance: number) => Promise<{
26
- to: Address;
27
- value: bigint;
28
- body: Cell;
29
- }>;
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDexTransferParams = exports.packJettonReceiveEffect = exports.EffectType = exports.packJettonSwap = exports.packTonSwap = void 0;
4
- const core_1 = require("@ton/core");
5
- const rainbow_wallet_contract_1 = require("./rainbow-wallet.contract");
6
- const dex_type_enum_1 = require("../../enums/dex-type.enum");
7
- const transfer_params_utils_1 = require("../dedust/transfer-params.utils");
8
- const transfer_params_utils_2 = require("../ston/transfer-params.utils");
9
- const packTonSwap = (params) => (0, core_1.beginCell)()
10
- .storeUint(rainbow_wallet_contract_1.RainbowWalletOperation.MAKE_A_SWAP, 32)
11
- .storeUint(params.queryId, 64)
12
- .storeAddress(params.destination)
13
- .storeRef(params.body)
14
- .storeAddress(params.jettonSenderAddressToListen)
15
- .storeRef(params.jettonReceiveEffect)
16
- .endCell();
17
- exports.packTonSwap = packTonSwap;
18
- const packJettonSwap = (params) => (0, core_1.beginCell)()
19
- .storeAddress(params.destination)
20
- .storeRef(params.body)
21
- .storeAddress(params.jettonSenderAddressToListen)
22
- .storeRef(params.jettonReceiveEffect)
23
- .endCell();
24
- exports.packJettonSwap = packJettonSwap;
25
- var EffectType;
26
- (function (EffectType) {
27
- EffectType[EffectType["JettonTransfer"] = 0] = "JettonTransfer";
28
- EffectType[EffectType["DedustTonSwap"] = 1] = "DedustTonSwap";
29
- })(EffectType || (exports.EffectType = EffectType = {}));
30
- const packJettonReceiveEffect = (params) => {
31
- const slice = params.fullBody.beginParse();
32
- slice.loadUint(32); // op
33
- slice.loadUint(64); // queryId
34
- slice.loadCoins(); // amount
35
- return (0, core_1.beginCell)()
36
- .storeAddress(params.destination)
37
- .storeUint(params.effectType, 1)
38
- .storeRef(slice.asCell())
39
- .endCell();
40
- };
41
- exports.packJettonReceiveEffect = packJettonReceiveEffect;
42
- const getDexTransferParams = (route, queryId, gasAmount, senderAddress, receiverAddress, responseDestination, slippageTolerance) => {
43
- const dexType = route[0].dexPair.dexType;
44
- if (dexType === dex_type_enum_1.DexTypeEnum.DeDust) {
45
- return (0, transfer_params_utils_1.dedust_getTransferParams)(route, queryId, gasAmount, senderAddress, receiverAddress, responseDestination, slippageTolerance);
46
- }
47
- if (dexType === dex_type_enum_1.DexTypeEnum.Ston) {
48
- if (route.length !== 1) {
49
- throw new Error(`Not supported Ston route.length ${route.length}`);
50
- }
51
- return (0, transfer_params_utils_2.ston_getTransferParams)(route[0], queryId, gasAmount, senderAddress, receiverAddress, responseDestination, slippageTolerance);
52
- }
53
- throw new Error(`Not supported dexType ${dexType}`);
54
- };
55
- exports.getDexTransferParams = getDexTransferParams;
@@ -1,4 +0,0 @@
1
- import { Address } from '@ton/core';
2
- import { RouteStepWithCalculation } from '../../interfaces/route-step-with-calculation.interface';
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: number) => Promise<TransferParams>;
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rainbow_getTransferParams = void 0;
4
- const rainbow_wallet_contract_1 = require("./rainbow-wallet.contract");
5
- const transfer_params_pack_utils_1 = require("./transfer-params-pack.utils");
6
- const dex_type_enum_1 = require("../../enums/dex-type.enum");
7
- const globals_1 = require("../../globals");
8
- const jetton_utils_1 = require("../../utils/jetton.utils");
9
- const vault_utils_1 = require("../dedust/vault.utils");
10
- const sdk_1 = require("../ston/sdk");
11
- const rainbow_getTransferParams = async (firstChunk, secondChunk, queryId, gasAmount, senderAddress, slippageTolerance) => {
12
- const rainbowWallet = rainbow_wallet_contract_1.RainbowWalletContract.create({
13
- workchain: globals_1.WORKCHAIN,
14
- ownerAddress: senderAddress
15
- });
16
- const inputAssetAddress = firstChunk[0].inputAssetAddress;
17
- const secondChunk_transferParams = await (0, transfer_params_pack_utils_1.getDexTransferParams)(secondChunk, queryId, gasAmount, rainbowWallet.address, senderAddress, senderAddress, slippageTolerance);
18
- const jettonSenderAddressToListen = firstChunk[0].dexPair.dexType === dex_type_enum_1.DexTypeEnum.Ston
19
- ? sdk_1.STON_ROUTER_ADDRESS
20
- : await (0, vault_utils_1.dedust_getVaultAddress)(firstChunk[firstChunk.length - 1].outputAssetAddress);
21
- const jettonReceiveEffectType = secondChunk[0].dexPair.dexType === dex_type_enum_1.DexTypeEnum.DeDust &&
22
- secondChunk[0].inputAssetAddress === globals_1.TON
23
- ? transfer_params_pack_utils_1.EffectType.DedustTonSwap
24
- : transfer_params_pack_utils_1.EffectType.JettonTransfer;
25
- const jettonReceiveEffectGasAmount = jettonReceiveEffectType === transfer_params_pack_utils_1.EffectType.DedustTonSwap
26
- ? 2n * globals_1.JETTON_TRANSFER_GAS_AMOUNT
27
- : 3n * globals_1.JETTON_TRANSFER_GAS_AMOUNT;
28
- const jettonReceiveEffect = (0, transfer_params_pack_utils_1.packJettonReceiveEffect)({
29
- effectType: jettonReceiveEffectType,
30
- destination: secondChunk_transferParams.to,
31
- fullBody: secondChunk_transferParams.body
32
- });
33
- const tweakedSlippageTolerance = firstChunk[0].dexPair.dexType === dex_type_enum_1.DexTypeEnum.Ston &&
34
- firstChunk[0].inputAssetAddress !== globals_1.TON
35
- ? 100 // We could not handle Ston.fi returned jettons
36
- : slippageTolerance;
37
- const firstChunk_transferParams = await (0, transfer_params_pack_utils_1.getDexTransferParams)(firstChunk, queryId, gasAmount + jettonReceiveEffectGasAmount, rainbowWallet.address, rainbowWallet.address, senderAddress, tweakedSlippageTolerance);
38
- if (inputAssetAddress === globals_1.TON) {
39
- return {
40
- to: rainbowWallet.address,
41
- value: firstChunk_transferParams.value,
42
- body: (0, transfer_params_pack_utils_1.packTonSwap)({
43
- queryId,
44
- destination: firstChunk_transferParams.to,
45
- body: firstChunk_transferParams.body,
46
- jettonSenderAddressToListen,
47
- jettonReceiveEffect
48
- })
49
- };
50
- }
51
- else {
52
- const inputJettonWalletAddress = await (0, jetton_utils_1.getJettonWalletAddress)(inputAssetAddress, senderAddress);
53
- const jettonSwapPayload = (0, transfer_params_pack_utils_1.packJettonSwap)({
54
- destination: firstChunk_transferParams.to,
55
- body: firstChunk_transferParams.body,
56
- jettonSenderAddressToListen,
57
- jettonReceiveEffect
58
- });
59
- return {
60
- to: inputJettonWalletAddress,
61
- value: firstChunk_transferParams.value + globals_1.JETTON_TRANSFER_GAS_AMOUNT,
62
- body: (0, jetton_utils_1.getJettonTransferBody)({
63
- queryId,
64
- amount: BigInt(firstChunk[0].inputAssetAmount),
65
- destination: rainbowWallet.address,
66
- responseDestination: senderAddress,
67
- forwardTonAmount: firstChunk_transferParams.value,
68
- forwardPayload: jettonSwapPayload
69
- })
70
- };
71
- }
72
- };
73
- exports.rainbow_getTransferParams = rainbow_getTransferParams;
@@ -1 +0,0 @@
1
- export declare const applySlippageTolerance: (amount: string, slippageTolerance: number) => bigint;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applySlippageTolerance = void 0;
4
- const PRECISION = 10 ** 6;
5
- const applySlippageTolerance = (amount, slippageTolerance) => {
6
- const amountBigInt = BigInt(amount);
7
- const slippageAmount = (amountBigInt * BigInt(Math.ceil(slippageTolerance * PRECISION))) /
8
- BigInt(100 * PRECISION);
9
- return amountBigInt - slippageAmount;
10
- };
11
- exports.applySlippageTolerance = applySlippageTolerance;
@@ -1,9 +0,0 @@
1
- import { Address } from '@ton/core';
2
- import { TransferParams } from '../../interfaces/transfer-params.interface';
3
- import { CalculatedSwapRoute } from '../../types/calculated-swap-route.type';
4
- export declare const getSwapRouteTransferParams: (swapRoute: CalculatedSwapRoute, senderAddress: Address, slippageTolerance: number) => Promise<{
5
- to: Address;
6
- value: bigint;
7
- body: import("@ton/core").Cell;
8
- }> | Promise<TransferParams>;
9
- export declare const getRainbowWalletActivationTransferParams: (senderAddress: Address) => TransferParams;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRainbowWalletActivationTransferParams = exports.getSwapRouteTransferParams = void 0;
4
- const core_1 = require("@ton/core");
5
- const swap_route_type_enum_1 = require("../../enums/swap-route-type.enum");
6
- const globals_1 = require("../../globals");
7
- const transfer_params_utils_1 = require("../../utils/transfer-params.utils");
8
- const transfer_params_utils_2 = require("../dedust/transfer-params.utils");
9
- const rainbow_wallet_contract_1 = require("../rainbow/rainbow-wallet.contract");
10
- const transfer_params_utils_3 = require("../rainbow/transfer-params.utils");
11
- const transfer_params_utils_4 = require("../ston/transfer-params.utils");
12
- const transfer_params_utils_5 = require("../ston-v2/transfer-params.utils");
13
- const getSwapRouteTransferParams = (swapRoute, senderAddress, slippageTolerance) => {
14
- const queryId = (0, transfer_params_utils_1.getQueryId)();
15
- if (swapRoute.type === swap_route_type_enum_1.SwapRouteType.DeDust) {
16
- return (0, transfer_params_utils_2.dedust_getTransferParams)(swapRoute.route, queryId, globals_1.GAS_AMOUNT, senderAddress, senderAddress, senderAddress, slippageTolerance);
17
- }
18
- if (swapRoute.type === swap_route_type_enum_1.SwapRouteType.Ston) {
19
- return (0, transfer_params_utils_4.ston_getTransferParams)(swapRoute.routeStep, queryId, globals_1.GAS_AMOUNT, senderAddress, senderAddress, senderAddress, slippageTolerance);
20
- }
21
- if (swapRoute.type === swap_route_type_enum_1.SwapRouteType.Ston_v2) {
22
- return (0, transfer_params_utils_5.stonV2_getTransferParams)(swapRoute.route, queryId, globals_1.GAS_AMOUNT, senderAddress, senderAddress, senderAddress, slippageTolerance);
23
- }
24
- return (0, transfer_params_utils_3.rainbow_getTransferParams)(swapRoute.firstChunk, swapRoute.secondChunk, queryId, globals_1.GAS_AMOUNT, senderAddress, slippageTolerance);
25
- };
26
- exports.getSwapRouteTransferParams = getSwapRouteTransferParams;
27
- const getRainbowWalletActivationTransferParams = (senderAddress) => {
28
- const rainbowWallet = rainbow_wallet_contract_1.RainbowWalletContract.create({
29
- workchain: globals_1.WORKCHAIN,
30
- ownerAddress: senderAddress
31
- });
32
- return {
33
- to: rainbowWallet.address,
34
- value: (0, core_1.toNano)('0.01'),
35
- init: rainbowWallet.init
36
- };
37
- };
38
- exports.getRainbowWalletActivationTransferParams = getRainbowWalletActivationTransferParams;
@@ -1,3 +0,0 @@
1
- import { Address } from '@ton/core';
2
- export declare const STON_ROUTER_ADDRESS: Address;
3
- export declare const PROXY_TON_MASTER_ADDRESS = "EQCM3B12QK1e4yZSf8GtBRT0aLMNyEsBc_DhVfRRtOEffLez";
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PROXY_TON_MASTER_ADDRESS = exports.STON_ROUTER_ADDRESS = void 0;
4
- const core_1 = require("@ton/core");
5
- exports.STON_ROUTER_ADDRESS = core_1.Address.parse('EQB3ncyBUTjZUA5EnFKR5_EnOMI9V1tTEAAPaiU71gc4TiUt');
6
- exports.PROXY_TON_MASTER_ADDRESS = 'EQCM3B12QK1e4yZSf8GtBRT0aLMNyEsBc_DhVfRRtOEffLez';
@@ -1,8 +0,0 @@
1
- import { Address } from '@ton/core';
2
- interface SwapParams {
3
- outputJettonWalletAddress: Address;
4
- minOutputAmount: bigint;
5
- receiverAddress: Address;
6
- }
7
- export declare const packSwapParams: ({ outputJettonWalletAddress, minOutputAmount, receiverAddress }: SwapParams) => import("@ton/core").Cell;
8
- export {};
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.packSwapParams = void 0;
4
- const core_1 = require("@ton/core");
5
- var Operation;
6
- (function (Operation) {
7
- Operation[Operation["SWAP"] = 630424929] = "SWAP";
8
- })(Operation || (Operation = {}));
9
- const packSwapParams = ({ outputJettonWalletAddress, minOutputAmount, receiverAddress }) => (0, core_1.beginCell)()
10
- .storeUint(Operation.SWAP, 32)
11
- .storeAddress(outputJettonWalletAddress)
12
- .storeCoins(minOutputAmount)
13
- .storeAddress(receiverAddress)
14
- .storeUint(0, 1) // no referralAddress
15
- .endCell();
16
- exports.packSwapParams = packSwapParams;
@@ -1,7 +0,0 @@
1
- import { Address } from '@ton/core';
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: number) => Promise<{
4
- to: Address;
5
- value: bigint;
6
- body: import("@ton/core").Cell;
7
- }>;
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ston_getTransferParams = void 0;
4
- const sdk_1 = require("./sdk");
5
- const transfer_params_pack_utils_1 = require("./transfer-params-pack.utils");
6
- const globals_1 = require("../../globals");
7
- const jetton_utils_1 = require("../../utils/jetton.utils");
8
- const slippage_tolerance_utils_1 = require("../shared/slippage-tolerance.utils");
9
- const ston_getTransferParams = async (routeStep, queryId, gasAmount, senderAddress, receiverAddress, responseDestination, slippageTolerance) => {
10
- const minOutputAmount = (0, slippage_tolerance_utils_1.applySlippageTolerance)(routeStep.outputAssetAmount, slippageTolerance);
11
- if (routeStep.inputAssetAddress === globals_1.TON) {
12
- const stonRouterProxyTonWalletAddress = await (0, jetton_utils_1.getJettonWalletAddress)(sdk_1.PROXY_TON_MASTER_ADDRESS, sdk_1.STON_ROUTER_ADDRESS);
13
- const stonRouterOutputJettonWalletAddress = await (0, jetton_utils_1.getJettonWalletAddress)(routeStep.outputAssetAddress, sdk_1.STON_ROUTER_ADDRESS);
14
- const tonSwapPayload = (0, transfer_params_pack_utils_1.packSwapParams)({
15
- outputJettonWalletAddress: stonRouterOutputJettonWalletAddress,
16
- minOutputAmount,
17
- receiverAddress
18
- });
19
- return {
20
- to: stonRouterProxyTonWalletAddress,
21
- value: gasAmount + BigInt(routeStep.inputAssetAmount),
22
- body: (0, jetton_utils_1.getJettonTransferBody)({
23
- queryId,
24
- amount: BigInt(routeStep.inputAssetAmount),
25
- destination: sdk_1.STON_ROUTER_ADDRESS,
26
- responseDestination: responseDestination,
27
- forwardTonAmount: gasAmount,
28
- forwardPayload: tonSwapPayload
29
- })
30
- };
31
- }
32
- else {
33
- const inputJettonWalletAddress = await (0, jetton_utils_1.getJettonWalletAddress)(routeStep.inputAssetAddress, senderAddress);
34
- const outputJettonWalletAddress = await (0, jetton_utils_1.getJettonWalletAddress)(routeStep.outputAssetAddress === globals_1.TON
35
- ? sdk_1.PROXY_TON_MASTER_ADDRESS
36
- : routeStep.outputAssetAddress, sdk_1.STON_ROUTER_ADDRESS);
37
- const jettonSwapPayload = (0, transfer_params_pack_utils_1.packSwapParams)({
38
- outputJettonWalletAddress,
39
- minOutputAmount,
40
- receiverAddress
41
- });
42
- return {
43
- to: inputJettonWalletAddress,
44
- value: gasAmount + globals_1.JETTON_TRANSFER_GAS_AMOUNT,
45
- body: (0, jetton_utils_1.getJettonTransferBody)({
46
- queryId,
47
- amount: BigInt(routeStep.inputAssetAmount),
48
- destination: sdk_1.STON_ROUTER_ADDRESS,
49
- responseDestination: responseDestination,
50
- forwardTonAmount: gasAmount,
51
- forwardPayload: jettonSwapPayload
52
- })
53
- };
54
- }
55
- };
56
- exports.ston_getTransferParams = ston_getTransferParams;
@@ -1,10 +0,0 @@
1
- import { Address, Cell } from '@ton/core';
2
- export declare const PROXY_TON_V2_MASTER_ADDRESS = "EQBnGWMCf3-FZZq1W4IWcWiGAc3PHuZ0_H-7sad2oY00o83S";
3
- interface pTonV2_TonTransferParams {
4
- queryId?: number;
5
- amount: bigint;
6
- refundAddress: Address;
7
- forwardPayload?: Cell;
8
- }
9
- export declare const pTonV2_createTonTransferBody: (params: pTonV2_TonTransferParams) => Cell;
10
- export {};
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pTonV2_createTonTransferBody = exports.PROXY_TON_V2_MASTER_ADDRESS = void 0;
4
- const core_1 = require("@ton/core");
5
- exports.PROXY_TON_V2_MASTER_ADDRESS = 'EQBnGWMCf3-FZZq1W4IWcWiGAc3PHuZ0_H-7sad2oY00o83S';
6
- var Operation;
7
- (function (Operation) {
8
- Operation[Operation["TON_TRANSFER"] = 32736093] = "TON_TRANSFER";
9
- })(Operation || (Operation = {}));
10
- const pTonV2_createTonTransferBody = (params) => {
11
- const builder = (0, core_1.beginCell)();
12
- builder.storeUint(Operation.TON_TRANSFER, 32);
13
- builder.storeUint(params.queryId ?? 0, 64);
14
- builder.storeCoins(params.amount);
15
- builder.storeAddress(params.refundAddress);
16
- if (params.forwardPayload) {
17
- builder.storeBit(true);
18
- builder.storeRef(params.forwardPayload);
19
- }
20
- return builder.endCell();
21
- };
22
- exports.pTonV2_createTonTransferBody = pTonV2_createTonTransferBody;
@@ -1,4 +0,0 @@
1
- import { Address, Cell } from '@ton/core';
2
- import { RouteStepWithCalculation } from '../../interfaces/route-step-with-calculation.interface';
3
- export declare const getRouterAddress: (routeStep: RouteStepWithCalculation) => Address;
4
- export declare const packSwapParams: (remainingRoute: RouteStepWithCalculation[], routeStepGasAmount: bigint, receiverAddress: Address, responseDestination: Address, referralAddress: Address, referralValue: bigint, slippageTolerance: number) => Promise<Cell | undefined>;
@@ -1,86 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.packSwapParams = exports.getRouterAddress = void 0;
4
- const shared_1 = require("@rnw-community/shared");
5
- const core_1 = require("@ton/core");
6
- const sdk_1 = require("./sdk");
7
- const dex_type_enum_1 = require("../../enums/dex-type.enum");
8
- const globals_1 = require("../../globals");
9
- const jetton_utils_1 = require("../../utils/jetton.utils");
10
- const slippage_tolerance_utils_1 = require("../shared/slippage-tolerance.utils");
11
- const TX_DEADLINE = 15 * 60; // 15 minutes
12
- const getDefaultDeadline = () => Math.floor(Date.now() / 1000) + TX_DEADLINE;
13
- var Operation;
14
- (function (Operation) {
15
- Operation[Operation["SWAP"] = 1717886506] = "SWAP";
16
- })(Operation || (Operation = {}));
17
- const routeStep_packSwapParams = (params) => {
18
- if (params.referralValue < 0 || params.referralValue > 100) {
19
- throw Error(`'referralValue' should be in range [0, 100] BPS`);
20
- }
21
- return (0, core_1.beginCell)()
22
- .storeUint(Operation.SWAP, 32)
23
- .storeAddress(params.outputJettonWalletAddress)
24
- .storeAddress(params.refundAddress)
25
- .storeAddress(params.excessesAddress ?? params.refundAddress)
26
- .storeUint(params.deadline ?? getDefaultDeadline(), 64)
27
- .storeRef((0, core_1.beginCell)()
28
- .storeCoins(params.minOutputAmount)
29
- .storeAddress(params.receiverAddress)
30
- .storeCoins(params.dexCustomPayloadForwardGasAmount ?? 0)
31
- .storeMaybeRef(params.dexCustomPayload)
32
- .storeCoins(params.refundForwardGasAmount ?? 0)
33
- .storeMaybeRef(params.refundPayload)
34
- .storeUint(params.referralValue, 16)
35
- .storeAddress(params.referralAddress)
36
- .endCell())
37
- .endCell();
38
- };
39
- const getRouterAddress = (routeStep) => {
40
- if (routeStep.dexPair.dexType !== dex_type_enum_1.DexTypeEnum.Ston_v2) {
41
- throw new Error(`Unsupported dexType ${routeStep.dexPair.dexType}, ${dex_type_enum_1.DexTypeEnum.Ston_v2} expected`);
42
- }
43
- return core_1.Address.parse(routeStep.dexPair.routerAddress);
44
- };
45
- exports.getRouterAddress = getRouterAddress;
46
- const getOutputJettonWalletAddress = (routeStep) => {
47
- const routerAddress = (0, exports.getRouterAddress)(routeStep);
48
- const jettonMasterAddress = routeStep.outputAssetAddress === globals_1.TON
49
- ? sdk_1.PROXY_TON_V2_MASTER_ADDRESS
50
- : routeStep.outputAssetAddress;
51
- return (0, jetton_utils_1.getJettonWalletAddress)(jettonMasterAddress, routerAddress);
52
- };
53
- const getNextReceiverAddress = async (receiverAddress, nextStep) => {
54
- if ((0, shared_1.isDefined)(nextStep)) {
55
- const routerAddress = (0, exports.getRouterAddress)(nextStep);
56
- if (nextStep.inputAssetAddress === globals_1.TON) {
57
- return (0, jetton_utils_1.getJettonWalletAddress)(sdk_1.PROXY_TON_V2_MASTER_ADDRESS, routerAddress);
58
- }
59
- else {
60
- return routerAddress;
61
- }
62
- }
63
- return receiverAddress;
64
- };
65
- const packSwapParams = async (remainingRoute, routeStepGasAmount, receiverAddress, responseDestination, referralAddress, referralValue, slippageTolerance) => {
66
- if (remainingRoute.length === 0) {
67
- return undefined;
68
- }
69
- const routeStep = remainingRoute[0];
70
- const outputJettonWalletAddress = await getOutputJettonWalletAddress(routeStep);
71
- const nextReceiverAddress = await getNextReceiverAddress(receiverAddress, remainingRoute[1]);
72
- const minOutputAmount = (0, slippage_tolerance_utils_1.applySlippageTolerance)(routeStep.outputAssetAmount, slippageTolerance);
73
- const dexCustomPayload = await (0, exports.packSwapParams)(remainingRoute.slice(1), routeStepGasAmount, receiverAddress, responseDestination, referralAddress, referralValue, slippageTolerance);
74
- const dexCustomPayloadForwardGasAmount = routeStepGasAmount * BigInt(remainingRoute.length - 1);
75
- return routeStep_packSwapParams({
76
- outputJettonWalletAddress,
77
- receiverAddress: nextReceiverAddress,
78
- minOutputAmount,
79
- refundAddress: responseDestination,
80
- dexCustomPayload,
81
- dexCustomPayloadForwardGasAmount,
82
- referralAddress,
83
- referralValue
84
- });
85
- };
86
- exports.packSwapParams = packSwapParams;
@@ -1,7 +0,0 @@
1
- import { Address } from '@ton/core';
2
- import { RouteStepWithCalculation } from '../../interfaces/route-step-with-calculation.interface';
3
- export declare const stonV2_getTransferParams: (route: RouteStepWithCalculation[], queryId: number, gasAmount: bigint, senderAddress: Address, receiverAddress: Address, responseDestination: Address, slippageTolerance: number) => Promise<{
4
- to: Address;
5
- value: bigint;
6
- body: import("@ton/core").Cell;
7
- }>;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stonV2_getTransferParams = void 0;
4
- const shared_1 = require("@rnw-community/shared");
5
- const core_1 = require("@ton/core");
6
- const sdk_1 = require("./sdk");
7
- const transfer_params_pack_utils_1 = require("./transfer-params-pack.utils");
8
- const globals_1 = require("../../globals");
9
- const jetton_utils_1 = require("../../utils/jetton.utils");
10
- const ROUTE_STEP_GAS_AMOUNT = (0, core_1.toNano)('0.30');
11
- const stonV2_getTransferParams = async (route, queryId, gasAmount, senderAddress, receiverAddress, responseDestination, slippageTolerance) => {
12
- if (route.length === 0) {
13
- throw new Error('Empty route');
14
- }
15
- const firstRouteStep = route[0];
16
- const routerAddress = (0, transfer_params_pack_utils_1.getRouterAddress)(firstRouteStep);
17
- const additionalGasAmount = ROUTE_STEP_GAS_AMOUNT * BigInt(route.length - 1);
18
- const swapPayload = await (0, transfer_params_pack_utils_1.packSwapParams)(route, ROUTE_STEP_GAS_AMOUNT, receiverAddress, responseDestination, globals_1.REFERRAL_ADDRESS, globals_1.REFERRAL_VALUE, slippageTolerance);
19
- if (!(0, shared_1.isDefined)(swapPayload)) {
20
- throw new Error('swapPayload not defined');
21
- }
22
- if (firstRouteStep.inputAssetAddress === globals_1.TON) {
23
- const stonRouterProxyTonWalletAddress = await (0, jetton_utils_1.getJettonWalletAddress)(sdk_1.PROXY_TON_V2_MASTER_ADDRESS, routerAddress);
24
- return {
25
- to: stonRouterProxyTonWalletAddress,
26
- value: gasAmount +
27
- additionalGasAmount +
28
- BigInt(firstRouteStep.inputAssetAmount),
29
- body: (0, sdk_1.pTonV2_createTonTransferBody)({
30
- queryId,
31
- amount: BigInt(firstRouteStep.inputAssetAmount),
32
- refundAddress: responseDestination,
33
- forwardPayload: swapPayload
34
- })
35
- };
36
- }
37
- else {
38
- const inputJettonWalletAddress = await (0, jetton_utils_1.getJettonWalletAddress)(firstRouteStep.inputAssetAddress, senderAddress);
39
- return {
40
- to: inputJettonWalletAddress,
41
- value: gasAmount + globals_1.JETTON_TRANSFER_GAS_AMOUNT + additionalGasAmount,
42
- body: (0, jetton_utils_1.getJettonTransferBody)({
43
- queryId,
44
- amount: BigInt(firstRouteStep.inputAssetAmount),
45
- destination: routerAddress,
46
- responseDestination: responseDestination,
47
- forwardTonAmount: gasAmount + additionalGasAmount,
48
- forwardPayload: swapPayload
49
- })
50
- };
51
- }
52
- };
53
- exports.stonV2_getTransferParams = stonV2_getTransferParams;
@@ -1,7 +0,0 @@
1
- import { Address, Cell, StateInit } from '@ton/core';
2
- export interface TransferParams {
3
- to: Address;
4
- value: bigint;
5
- init?: StateInit;
6
- body?: Cell;
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- import { Cell } from '@ton/core';
2
- export declare const bocToCell: (boc: string) => Cell;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bocToCell = void 0;
4
- const core_1 = require("@ton/core");
5
- const buffer_1 = require("buffer");
6
- const bocToCell = (boc) => core_1.Cell.fromBoc(buffer_1.Buffer.from(boc, 'base64'))[0];
7
- exports.bocToCell = bocToCell;
@@ -1,11 +0,0 @@
1
- import { Address, Cell } from '@ton/core';
2
- export declare const getJettonWalletAddress: (jettonMasterAddress: string, ownerAddress: Address) => Promise<Address>;
3
- export declare const getJettonTransferBody: (params: {
4
- queryId?: number;
5
- amount: bigint;
6
- destination: Address;
7
- responseDestination: Address;
8
- customPayload?: Cell;
9
- forwardTonAmount: bigint;
10
- forwardPayload: Cell;
11
- }) => Cell;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getJettonTransferBody = exports.getJettonWalletAddress = void 0;
4
- const core_1 = require("@ton/core");
5
- const globals_1 = require("../globals");
6
- const getJettonWalletAddress = async (jettonMasterAddress, ownerAddress) => {
7
- const walletAddressResponse = await globals_1.TON_CLIENT.runMethod(core_1.Address.parse(jettonMasterAddress), 'get_wallet_address', [
8
- {
9
- type: 'slice',
10
- cell: (0, core_1.beginCell)().storeAddress(ownerAddress).endCell()
11
- }
12
- ]);
13
- return walletAddressResponse.stack.readAddress();
14
- };
15
- exports.getJettonWalletAddress = getJettonWalletAddress;
16
- var Operation;
17
- (function (Operation) {
18
- Operation[Operation["TRANSFER"] = 260734629] = "TRANSFER";
19
- })(Operation || (Operation = {}));
20
- const getJettonTransferBody = (params) => (0, core_1.beginCell)()
21
- .storeUint(Operation.TRANSFER, 32)
22
- .storeUint(params.queryId ?? 0, 64)
23
- .storeCoins(params.amount)
24
- .storeAddress(params.destination)
25
- .storeAddress(params.responseDestination) // address where to return fee (diff between input fee and forwardAmount)
26
- .storeMaybeRef(params.customPayload ?? null)
27
- .storeCoins(params.forwardTonAmount)
28
- .storeMaybeRef(params.forwardPayload)
29
- .endCell();
30
- exports.getJettonTransferBody = getJettonTransferBody;
@@ -1,4 +0,0 @@
1
- import { Message } from '../interfaces/message.interface';
2
- import { CalculatedSwapRoute } from '../types/calculated-swap-route.type';
3
- export declare const getSwapMessages: (senderAddress: string, bestRoute: CalculatedSwapRoute[], slippageTolerance: number) => Promise<Message[]>;
4
- export declare const getRainbowWalletActivationMessages: (senderAddress: string) => Message[];
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRainbowWalletActivationMessages = exports.getSwapMessages = void 0;
4
- const shared_1 = require("@rnw-community/shared");
5
- const core_1 = require("@ton/core");
6
- const transfer_params_utils_1 = require("../dexes/shared/transfer-params.utils");
7
- const transferParamsToMessages = (transferParamsArray) => transferParamsArray.map(transferParams => ({
8
- address: transferParams.to.toRawString(),
9
- amount: transferParams.value.toString(),
10
- payload: (0, shared_1.isDefined)(transferParams.body)
11
- ? transferParams.body.toBoc().toString('base64')
12
- : undefined,
13
- stateInit: (0, shared_1.isDefined)(transferParams.init)
14
- ? (0, core_1.beginCell)()
15
- .store((0, core_1.storeStateInit)(transferParams.init))
16
- .endCell()
17
- .toBoc()
18
- .toString('base64')
19
- : undefined
20
- }));
21
- const getSwapMessages = async (senderAddress, bestRoute, slippageTolerance) => {
22
- const swapTransferParams = await Promise.all(bestRoute.map(swapRoute => (0, transfer_params_utils_1.getSwapRouteTransferParams)(swapRoute, core_1.Address.parse(senderAddress), slippageTolerance)));
23
- return transferParamsToMessages(swapTransferParams);
24
- };
25
- exports.getSwapMessages = getSwapMessages;
26
- const getRainbowWalletActivationMessages = (senderAddress) => {
27
- const activationTransferParams = [
28
- (0, transfer_params_utils_1.getRainbowWalletActivationTransferParams)(core_1.Address.parse(senderAddress))
29
- ];
30
- return transferParamsToMessages(activationTransferParams);
31
- };
32
- exports.getRainbowWalletActivationMessages = getRainbowWalletActivationMessages;
@@ -1,3 +0,0 @@
1
- import { CalculatedSwapRoute } from '../types/calculated-swap-route.type';
2
- export declare const getIsRainbowWalletActive: (ownerAddress: string) => Promise<boolean>;
3
- export declare const getIsActivationRequired: (bestRoute: CalculatedSwapRoute[], isRainbowWalletActive: boolean) => boolean;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIsActivationRequired = exports.getIsRainbowWalletActive = void 0;
4
- const core_1 = require("@ton/core");
5
- const rainbow_wallet_contract_1 = require("../dexes/rainbow/rainbow-wallet.contract");
6
- const swap_route_type_enum_1 = require("../enums/swap-route-type.enum");
7
- const globals_1 = require("../globals");
8
- const getIsRainbowWalletActive = async (ownerAddress) => {
9
- const rainbowWallet = rainbow_wallet_contract_1.RainbowWalletContract.create({
10
- workchain: globals_1.WORKCHAIN,
11
- ownerAddress: core_1.Address.parse(ownerAddress)
12
- });
13
- const contractProvider = globals_1.TON_CLIENT.provider(rainbowWallet.address);
14
- const state = await contractProvider.getState();
15
- return state.state.type === 'active';
16
- };
17
- exports.getIsRainbowWalletActive = getIsRainbowWalletActive;
18
- const getIsActivationRequired = (bestRoute, isRainbowWalletActive) => {
19
- const isRainbowContractCalled = bestRoute.some(swapRoute => swapRoute.type === swap_route_type_enum_1.SwapRouteType.Rainbow);
20
- return isRainbowContractCalled && !isRainbowWalletActive;
21
- };
22
- exports.getIsActivationRequired = getIsActivationRequired;