rainbow-swap-sdk 1.0.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/dist/dexes/abstract/calculated-swap-route.interface.d.ts +5 -0
- package/dist/dexes/abstract/calculated-swap-route.interface.js +2 -0
- package/dist/dexes/dedust/calculated-swap-route.interface.d.ts +6 -0
- package/dist/dexes/dedust/calculated-swap-route.interface.js +2 -0
- package/dist/dexes/dedust/sdk.d.ts +14 -0
- package/dist/dexes/dedust/sdk.js +4 -0
- package/dist/dexes/dedust/transfer-params-pack.utils.d.ts +16 -0
- package/dist/dexes/dedust/transfer-params-pack.utils.js +48 -0
- package/dist/dexes/dedust/transfer-params.utils.d.ts +7 -0
- package/dist/dexes/dedust/transfer-params.utils.js +70 -0
- package/dist/dexes/dedust/vault.utils.d.ts +2 -0
- package/dist/dexes/dedust/vault.utils.js +28 -0
- package/dist/dexes/rainbow/calculated-swap-route.interface.d.ts +7 -0
- package/dist/dexes/rainbow/calculated-swap-route.interface.js +2 -0
- package/dist/dexes/rainbow/rainbow-wallet.contract.d.ts +21 -0
- package/dist/dexes/rainbow/rainbow-wallet.contract.js +32 -0
- package/dist/dexes/rainbow/transfer-params-pack.utils.d.ts +29 -0
- package/dist/dexes/rainbow/transfer-params-pack.utils.js +55 -0
- package/dist/dexes/rainbow/transfer-params.utils.d.ts +4 -0
- package/dist/dexes/rainbow/transfer-params.utils.js +73 -0
- package/dist/dexes/shared/slippage-tolerance.utils.d.ts +1 -0
- package/dist/dexes/shared/slippage-tolerance.utils.js +11 -0
- package/dist/dexes/shared/transfer-params.utils.d.ts +9 -0
- package/dist/dexes/shared/transfer-params.utils.js +34 -0
- package/dist/dexes/ston/calculated-swap-route.interface.d.ts +6 -0
- package/dist/dexes/ston/calculated-swap-route.interface.js +2 -0
- package/dist/dexes/ston/sdk.d.ts +3 -0
- package/dist/dexes/ston/sdk.js +6 -0
- package/dist/dexes/ston/transfer-params-pack.utils.d.ts +8 -0
- package/dist/dexes/ston/transfer-params-pack.utils.js +16 -0
- package/dist/dexes/ston/transfer-params.utils.d.ts +7 -0
- package/dist/dexes/ston/transfer-params.utils.js +56 -0
- package/dist/enums/dex-type.enum.d.ts +5 -0
- package/dist/enums/dex-type.enum.js +9 -0
- package/dist/enums/route-direction.enum.d.ts +4 -0
- package/dist/enums/route-direction.enum.js +8 -0
- package/dist/enums/swap-route-type.enum.d.ts +5 -0
- package/dist/enums/swap-route-type.enum.js +9 -0
- package/dist/globals.d.ts +7 -0
- package/dist/globals.js +19 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +12 -0
- package/dist/interfaces/message.interface.d.ts +6 -0
- package/dist/interfaces/message.interface.js +2 -0
- package/dist/interfaces/route-step-with-calculation.interface.d.ts +5 -0
- package/dist/interfaces/route-step-with-calculation.interface.js +2 -0
- package/dist/interfaces/route-step.interface.d.ts +9 -0
- package/dist/interfaces/route-step.interface.js +2 -0
- package/dist/interfaces/transfer-params.interface.d.ts +7 -0
- package/dist/interfaces/transfer-params.interface.js +2 -0
- package/dist/types/asset.type.d.ts +8 -0
- package/dist/types/asset.type.js +2 -0
- package/dist/types/assets-record-response.type.d.ts +2 -0
- package/dist/types/assets-record-response.type.js +2 -0
- package/dist/types/best-route-response.type.d.ts +5 -0
- package/dist/types/best-route-response.type.js +2 -0
- package/dist/types/calculated-swap-route.type.d.ts +4 -0
- package/dist/types/calculated-swap-route.type.js +2 -0
- package/dist/utils/api.utils.d.ts +8 -0
- package/dist/utils/api.utils.js +8 -0
- package/dist/utils/boc.utils.d.ts +2 -0
- package/dist/utils/boc.utils.js +7 -0
- package/dist/utils/jetton.utils.d.ts +11 -0
- package/dist/utils/jetton.utils.js +30 -0
- package/dist/utils/math.utils.d.ts +1 -0
- package/dist/utils/math.utils.js +5 -0
- package/dist/utils/message.utils.d.ts +4 -0
- package/dist/utils/message.utils.js +32 -0
- package/dist/utils/rainbow-wallet.utils.d.ts +3 -0
- package/dist/utils/rainbow-wallet.utils.js +28 -0
- package/dist/utils/transfer-params.utils.d.ts +1 -0
- package/dist/utils/transfer-params.utils.js +6 -0
- package/package.json +35 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SwapRouteType } from '../../enums/swap-route-type.enum';
|
|
2
|
+
import { RouteStepWithCalculation } from '../../interfaces/route-step-with-calculation.interface';
|
|
3
|
+
import { AbstractCalculatedSwapRoute } from '../abstract/calculated-swap-route.interface';
|
|
4
|
+
export interface DeDustCalculatedSwapRoute extends AbstractCalculatedSwapRoute<SwapRouteType.DeDust> {
|
|
5
|
+
route: RouteStepWithCalculation[];
|
|
6
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
|
@@ -0,0 +1,48 @@
|
|
|
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();
|
|
@@ -0,0 +1,7 @@
|
|
|
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: string) => Promise<{
|
|
4
|
+
to: Address;
|
|
5
|
+
value: bigint;
|
|
6
|
+
body: import("@ton/core").Cell;
|
|
7
|
+
}>;
|
|
@@ -0,0 +1,70 @@
|
|
|
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.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.dexPairAddress);
|
|
31
|
+
const minOutputAmount = (0, slippage_tolerance_utils_1.applySlippageTolerance)(firstRouteStep.outputAssetAmount, slippageTolerance);
|
|
32
|
+
const nextSwapStep = createNextSwapStepPayload(route.slice(1), slippageTolerance);
|
|
33
|
+
const swapParams = { recipientAddress: receiverAddress };
|
|
34
|
+
if (firstRouteStep.inputAssetAddress === globals_1.TON) {
|
|
35
|
+
return {
|
|
36
|
+
to: vaultAddress,
|
|
37
|
+
value: gasAmount + BigInt(firstRouteStep.inputAssetAmount),
|
|
38
|
+
body: (0, transfer_params_pack_utils_1.packTonSwap)({
|
|
39
|
+
queryId,
|
|
40
|
+
inputAmount: BigInt(firstRouteStep.inputAssetAmount),
|
|
41
|
+
poolAddress,
|
|
42
|
+
minOutputAmount,
|
|
43
|
+
nextSwapStep,
|
|
44
|
+
swapParams
|
|
45
|
+
})
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const inputJettonWalletAddress = await (0, jetton_utils_1.getJettonWalletAddress)(firstRouteStep.inputAssetAddress, senderAddress);
|
|
50
|
+
const jettonSwapPayload = (0, transfer_params_pack_utils_1.packJettonSwap)({
|
|
51
|
+
poolAddress,
|
|
52
|
+
minOutputAmount,
|
|
53
|
+
nextSwapStep,
|
|
54
|
+
swapParams
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
to: inputJettonWalletAddress,
|
|
58
|
+
value: gasAmount + globals_1.JETTON_TRANSFER_GAS_AMOUNT,
|
|
59
|
+
body: (0, jetton_utils_1.getJettonTransferBody)({
|
|
60
|
+
queryId,
|
|
61
|
+
amount: BigInt(firstRouteStep.inputAssetAmount),
|
|
62
|
+
destination: vaultAddress,
|
|
63
|
+
responseDestination: responseDestination,
|
|
64
|
+
forwardTonAmount: gasAmount,
|
|
65
|
+
forwardPayload: jettonSwapPayload
|
|
66
|
+
})
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.dedust_getTransferParams = dedust_getTransferParams;
|
|
@@ -0,0 +1,28 @@
|
|
|
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;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SwapRouteType } from '../../enums/swap-route-type.enum';
|
|
2
|
+
import { RouteStepWithCalculation } from '../../interfaces/route-step-with-calculation.interface';
|
|
3
|
+
import { AbstractCalculatedSwapRoute } from '../abstract/calculated-swap-route.interface';
|
|
4
|
+
export interface RainbowCalculatedSwapRoute extends AbstractCalculatedSwapRoute<SwapRouteType.Rainbow> {
|
|
5
|
+
firstChunk: RouteStepWithCalculation[];
|
|
6
|
+
secondChunk: RouteStepWithCalculation[];
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
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: string) => Promise<{
|
|
26
|
+
to: Address;
|
|
27
|
+
value: bigint;
|
|
28
|
+
body: Cell;
|
|
29
|
+
}>;
|
|
@@ -0,0 +1,55 @@
|
|
|
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].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;
|
|
@@ -0,0 +1,4 @@
|
|
|
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: string) => Promise<TransferParams>;
|
|
@@ -0,0 +1,73 @@
|
|
|
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].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].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].dexType === dex_type_enum_1.DexTypeEnum.Ston &&
|
|
34
|
+
firstChunk[0].inputAssetAmount !== 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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const applySlippageTolerance: (amount: string, slippageTolerance: string) => bigint;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applySlippageTolerance = void 0;
|
|
4
|
+
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));
|
|
10
|
+
};
|
|
11
|
+
exports.applySlippageTolerance = applySlippageTolerance;
|
|
@@ -0,0 +1,9 @@
|
|
|
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: string) => Promise<{
|
|
5
|
+
to: Address;
|
|
6
|
+
value: bigint;
|
|
7
|
+
body: import("@ton/core").Cell;
|
|
8
|
+
}> | Promise<TransferParams>;
|
|
9
|
+
export declare const getRainbowWalletActivationTransferParams: (senderAddress: Address) => TransferParams;
|
|
@@ -0,0 +1,34 @@
|
|
|
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 getSwapRouteTransferParams = (swapRoute, senderAddress, slippageTolerance) => {
|
|
13
|
+
const queryId = (0, transfer_params_utils_1.getQueryId)();
|
|
14
|
+
if (swapRoute.type === swap_route_type_enum_1.SwapRouteType.DeDust) {
|
|
15
|
+
return (0, transfer_params_utils_2.dedust_getTransferParams)(swapRoute.route, queryId, globals_1.GAS_AMOUNT, senderAddress, senderAddress, senderAddress, slippageTolerance);
|
|
16
|
+
}
|
|
17
|
+
if (swapRoute.type === swap_route_type_enum_1.SwapRouteType.Ston) {
|
|
18
|
+
return (0, transfer_params_utils_4.ston_getTransferParams)(swapRoute.routeStep, queryId, globals_1.GAS_AMOUNT, senderAddress, senderAddress, senderAddress, slippageTolerance);
|
|
19
|
+
}
|
|
20
|
+
return (0, transfer_params_utils_3.rainbow_getTransferParams)(swapRoute.firstChunk, swapRoute.secondChunk, queryId, globals_1.GAS_AMOUNT, senderAddress, slippageTolerance);
|
|
21
|
+
};
|
|
22
|
+
exports.getSwapRouteTransferParams = getSwapRouteTransferParams;
|
|
23
|
+
const getRainbowWalletActivationTransferParams = (senderAddress) => {
|
|
24
|
+
const rainbowWallet = rainbow_wallet_contract_1.RainbowWalletContract.create({
|
|
25
|
+
workchain: globals_1.WORKCHAIN,
|
|
26
|
+
ownerAddress: senderAddress
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
to: rainbowWallet.address,
|
|
30
|
+
value: (0, core_1.toNano)('0.01'),
|
|
31
|
+
init: rainbowWallet.init
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.getRainbowWalletActivationTransferParams = getRainbowWalletActivationTransferParams;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SwapRouteType } from '../../enums/swap-route-type.enum';
|
|
2
|
+
import { RouteStepWithCalculation } from '../../interfaces/route-step-with-calculation.interface';
|
|
3
|
+
import { AbstractCalculatedSwapRoute } from '../abstract/calculated-swap-route.interface';
|
|
4
|
+
export interface StonCalculatedSwapRoute extends AbstractCalculatedSwapRoute<SwapRouteType.Ston> {
|
|
5
|
+
routeStep: RouteStepWithCalculation;
|
|
6
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
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';
|
|
@@ -0,0 +1,8 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
|
@@ -0,0 +1,7 @@
|
|
|
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: string) => Promise<{
|
|
4
|
+
to: Address;
|
|
5
|
+
value: bigint;
|
|
6
|
+
body: import("@ton/core").Cell;
|
|
7
|
+
}>;
|
|
@@ -0,0 +1,56 @@
|
|
|
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;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DexTypeEnum = void 0;
|
|
4
|
+
var DexTypeEnum;
|
|
5
|
+
(function (DexTypeEnum) {
|
|
6
|
+
DexTypeEnum["DeDust"] = "DeDust";
|
|
7
|
+
DexTypeEnum["Ston"] = "Ston";
|
|
8
|
+
DexTypeEnum["DeDustStable"] = "DeDustStable";
|
|
9
|
+
})(DexTypeEnum || (exports.DexTypeEnum = DexTypeEnum = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouteDirectionEnum = void 0;
|
|
4
|
+
var RouteDirectionEnum;
|
|
5
|
+
(function (RouteDirectionEnum) {
|
|
6
|
+
RouteDirectionEnum["Direct"] = "Direct";
|
|
7
|
+
RouteDirectionEnum["Inverted"] = "Inverted";
|
|
8
|
+
})(RouteDirectionEnum || (exports.RouteDirectionEnum = RouteDirectionEnum = {}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwapRouteType = void 0;
|
|
4
|
+
var SwapRouteType;
|
|
5
|
+
(function (SwapRouteType) {
|
|
6
|
+
SwapRouteType["DeDust"] = "DeDust";
|
|
7
|
+
SwapRouteType["Ston"] = "Ston";
|
|
8
|
+
SwapRouteType["Rainbow"] = "Rainbow";
|
|
9
|
+
})(SwapRouteType || (exports.SwapRouteType = SwapRouteType = {}));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TonClient } from '@ton/ton';
|
|
2
|
+
export declare const TON = "ton";
|
|
3
|
+
export declare const WORKCHAIN = 0;
|
|
4
|
+
export declare const API: import("axios").AxiosInstance;
|
|
5
|
+
export declare const TON_CLIENT: TonClient;
|
|
6
|
+
export declare const GAS_AMOUNT: bigint;
|
|
7
|
+
export declare const JETTON_TRANSFER_GAS_AMOUNT: bigint;
|
package/dist/globals.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
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");
|
|
9
|
+
const axios_1 = __importDefault(require("axios"));
|
|
10
|
+
exports.TON = 'ton';
|
|
11
|
+
exports.WORKCHAIN = 0;
|
|
12
|
+
exports.API = axios_1.default.create({
|
|
13
|
+
baseURL: 'https://api.blackbot.technology/rainbow/api'
|
|
14
|
+
});
|
|
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');
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getIsActivationRequired = exports.getIsRainbowWalletActive = exports.getRainbowWalletActivationMessages = exports.getSwapMessages = exports.getBestRoute = exports.getAssetsRecord = void 0;
|
|
4
|
+
var api_utils_1 = require("./utils/api.utils");
|
|
5
|
+
Object.defineProperty(exports, "getAssetsRecord", { enumerable: true, get: function () { return api_utils_1.getAssetsRecord; } });
|
|
6
|
+
Object.defineProperty(exports, "getBestRoute", { enumerable: true, get: function () { return api_utils_1.getBestRoute; } });
|
|
7
|
+
var message_utils_1 = require("./utils/message.utils");
|
|
8
|
+
Object.defineProperty(exports, "getSwapMessages", { enumerable: true, get: function () { return message_utils_1.getSwapMessages; } });
|
|
9
|
+
Object.defineProperty(exports, "getRainbowWalletActivationMessages", { enumerable: true, get: function () { return message_utils_1.getRainbowWalletActivationMessages; } });
|
|
10
|
+
var rainbow_wallet_utils_1 = require("./utils/rainbow-wallet.utils");
|
|
11
|
+
Object.defineProperty(exports, "getIsRainbowWalletActive", { enumerable: true, get: function () { return rainbow_wallet_utils_1.getIsRainbowWalletActive; } });
|
|
12
|
+
Object.defineProperty(exports, "getIsActivationRequired", { enumerable: true, get: function () { return rainbow_wallet_utils_1.getIsActivationRequired; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DexTypeEnum } from '../enums/dex-type.enum';
|
|
2
|
+
import { RouteDirectionEnum } from '../enums/route-direction.enum';
|
|
3
|
+
export interface RouteStep {
|
|
4
|
+
dexType: DexTypeEnum;
|
|
5
|
+
dexPairAddress: string;
|
|
6
|
+
inputAssetAddress: string;
|
|
7
|
+
outputAssetAddress: string;
|
|
8
|
+
routeDirection: RouteDirectionEnum;
|
|
9
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DeDustCalculatedSwapRoute } from '../dexes/dedust/calculated-swap-route.interface';
|
|
2
|
+
import { RainbowCalculatedSwapRoute } from '../dexes/rainbow/calculated-swap-route.interface';
|
|
3
|
+
import { StonCalculatedSwapRoute } from '../dexes/ston/calculated-swap-route.interface';
|
|
4
|
+
export type CalculatedSwapRoute = DeDustCalculatedSwapRoute | StonCalculatedSwapRoute | RainbowCalculatedSwapRoute;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AssetsRecordResponse } from '../types/assets-record-response.type';
|
|
2
|
+
import { BestRouteResponse } from '../types/best-route-response.type';
|
|
3
|
+
export declare const getAssetsRecord: () => Promise<import("axios").AxiosResponse<AssetsRecordResponse, any>>;
|
|
4
|
+
export declare const getBestRoute: (params: {
|
|
5
|
+
inputAssetAmount: string;
|
|
6
|
+
inputAssetAddress: string;
|
|
7
|
+
outputAssetAddress: string;
|
|
8
|
+
}) => Promise<import("axios").AxiosResponse<BestRouteResponse, any>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBestRoute = exports.getAssetsRecord = void 0;
|
|
4
|
+
const globals_1 = require("../globals");
|
|
5
|
+
const getAssetsRecord = () => globals_1.API.get('/assets-record');
|
|
6
|
+
exports.getAssetsRecord = getAssetsRecord;
|
|
7
|
+
const getBestRoute = (params) => globals_1.API.get('/best-route', { params });
|
|
8
|
+
exports.getBestRoute = getBestRoute;
|
|
@@ -0,0 +1,7 @@
|
|
|
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;
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
@@ -0,0 +1,30 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const randomIntFromInterval: (min: number, max: number) => number;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomIntFromInterval = void 0;
|
|
4
|
+
const randomIntFromInterval = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
|
|
5
|
+
exports.randomIntFromInterval = randomIntFromInterval;
|
|
@@ -0,0 +1,4 @@
|
|
|
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: string) => Promise<Message[]>;
|
|
4
|
+
export declare const getRainbowWalletActivationMessages: (senderAddress: string) => Message[];
|
|
@@ -0,0 +1,32 @@
|
|
|
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;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CalculatedSwapRoute } from '../types/calculated-swap-route.type';
|
|
2
|
+
export declare const getIsRainbowWalletActive: (ownerAddress: string) => Promise<boolean>;
|
|
3
|
+
export declare const getIsActivationRequired: (senderAddress: string, bestRoute: CalculatedSwapRoute[]) => Promise<boolean>;
|
|
@@ -0,0 +1,28 @@
|
|
|
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 = async (senderAddress, bestRoute) => {
|
|
19
|
+
const isRainbowContractCalled = bestRoute.some(swapRoute => swapRoute.type === swap_route_type_enum_1.SwapRouteType.Rainbow);
|
|
20
|
+
if (isRainbowContractCalled) {
|
|
21
|
+
const isRainbowWalletActive = await (0, exports.getIsRainbowWalletActive)(senderAddress);
|
|
22
|
+
return !isRainbowWalletActive;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.getIsActivationRequired = getIsActivationRequired;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getQueryId: () => number;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getQueryId = void 0;
|
|
4
|
+
const math_utils_1 = require("./math.utils");
|
|
5
|
+
const getQueryId = () => (0, math_utils_1.randomIntFromInterval)(1, 10 ** 6);
|
|
6
|
+
exports.getQueryId = getQueryId;
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rainbow-swap-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "An SDK for building applications on top of Rainbow Swap",
|
|
5
|
+
"repository": "https://github.com/0xblackbot/rainbow-swap-sdk.git",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"ts": "tsc --pretty",
|
|
14
|
+
"lint": "eslint . --ext ts --report-unused-disable-directives --max-warnings 0",
|
|
15
|
+
"build": "tsc"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@rnw-community/shared": "^0.73.0",
|
|
19
|
+
"@ton/core": "^0.56.3",
|
|
20
|
+
"@ton/ton": "^13.11.2",
|
|
21
|
+
"axios": "^1.7.2",
|
|
22
|
+
"buffer": "^6.0.3"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^7.16.0",
|
|
26
|
+
"@typescript-eslint/parser": "^7.16.0",
|
|
27
|
+
"eslint": "^8.57.0",
|
|
28
|
+
"eslint-config-prettier": "^9.1.0",
|
|
29
|
+
"eslint-plugin-import": "^2.29.1",
|
|
30
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
31
|
+
"prettier": "^3.2.5",
|
|
32
|
+
"ts-node": "^10.9.2",
|
|
33
|
+
"typescript": "^5.5.3"
|
|
34
|
+
}
|
|
35
|
+
}
|