@dynamic-labs/ton 4.52.5 → 4.53.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.
- package/CHANGELOG.md +18 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +11 -5
- package/src/TonWalletConnector.cjs +87 -0
- package/src/TonWalletConnector.d.ts +38 -0
- package/src/TonWalletConnector.js +83 -0
- package/src/index.cjs +40 -0
- package/src/index.d.ts +9 -1
- package/src/index.js +20 -0
- package/src/types.cjs +13 -0
- package/src/types.d.ts +80 -4
- package/src/types.js +11 -0
- package/src/utils/convertSendTransactionRequest/convertSendTransactionRequest.cjs +117 -0
- package/src/utils/convertSendTransactionRequest/convertSendTransactionRequest.d.ts +9 -0
- package/src/utils/convertSendTransactionRequest/convertSendTransactionRequest.js +113 -0
- package/src/utils/convertSendTransactionRequest/index.d.ts +1 -0
- package/src/utils/createWalletStateInit/createWalletStateInit.cjs +23 -0
- package/src/utils/createWalletStateInit/createWalletStateInit.d.ts +15 -0
- package/src/utils/createWalletStateInit/createWalletStateInit.js +19 -0
- package/src/utils/createWalletStateInit/index.d.ts +1 -0
- package/src/utils/executeTransaction/executeTransaction.cjs +51 -0
- package/src/utils/executeTransaction/executeTransaction.d.ts +28 -0
- package/src/utils/executeTransaction/executeTransaction.js +47 -0
- package/src/utils/executeTransaction/index.d.ts +1 -0
- package/src/utils/extractDisplayInfoFromRequest/extractDisplayInfoFromRequest.cjs +51 -0
- package/src/utils/extractDisplayInfoFromRequest/extractDisplayInfoFromRequest.d.ts +18 -0
- package/src/utils/extractDisplayInfoFromRequest/extractDisplayInfoFromRequest.js +47 -0
- package/src/utils/extractDisplayInfoFromRequest/index.d.ts +1 -0
- package/src/utils/generateTonConnectProofHash/generateTonConnectProofHash.cjs +89 -0
- package/src/utils/generateTonConnectProofHash/generateTonConnectProofHash.d.ts +24 -0
- package/src/utils/generateTonConnectProofHash/generateTonConnectProofHash.js +85 -0
- package/src/utils/generateTonConnectProofHash/index.d.ts +1 -0
- package/src/utils/getJettonWalletAddress/getJettonWalletAddress.cjs +32 -0
- package/src/utils/getJettonWalletAddress/getJettonWalletAddress.d.ts +17 -0
- package/src/utils/getJettonWalletAddress/getJettonWalletAddress.js +28 -0
- package/src/utils/getJettonWalletAddress/index.d.ts +1 -0
- package/src/utils/getWalletSeqno/getWalletSeqno.cjs +22 -0
- package/src/utils/getWalletSeqno/getWalletSeqno.d.ts +9 -0
- package/src/utils/getWalletSeqno/getWalletSeqno.js +18 -0
- package/src/utils/getWalletSeqno/index.d.ts +1 -0
- package/src/utils/index.d.ts +13 -1
- package/src/utils/isWalletDeployed/index.d.ts +1 -0
- package/src/utils/isWalletDeployed/isWalletDeployed.cjs +22 -0
- package/src/utils/isWalletDeployed/isWalletDeployed.d.ts +14 -0
- package/src/utils/isWalletDeployed/isWalletDeployed.js +18 -0
- package/src/utils/logger/logger.cjs +14 -0
- package/src/utils/logger/logger.d.ts +3 -0
- package/src/utils/logger/logger.js +7 -0
- package/src/utils/prepareJettonTransfer/index.d.ts +1 -0
- package/src/utils/prepareJettonTransfer/prepareJettonTransfer.cjs +78 -0
- package/src/utils/prepareJettonTransfer/prepareJettonTransfer.d.ts +31 -0
- package/src/utils/prepareJettonTransfer/prepareJettonTransfer.js +74 -0
- package/src/utils/prepareTonTransfer/index.d.ts +1 -0
- package/src/utils/prepareTonTransfer/prepareTonTransfer.cjs +45 -0
- package/src/utils/prepareTonTransfer/prepareTonTransfer.d.ts +23 -0
- package/src/utils/prepareTonTransfer/prepareTonTransfer.js +41 -0
- package/src/utils/prepareTransaction/index.d.ts +1 -0
- package/src/utils/prepareTransaction/prepareTransaction.cjs +74 -0
- package/src/utils/prepareTransaction/prepareTransaction.d.ts +32 -0
- package/src/utils/prepareTransaction/prepareTransaction.js +70 -0
- package/src/waas/DynamicWaasTonConnectors.cjs +12 -0
- package/src/waas/DynamicWaasTonConnectors.d.ts +2 -0
- package/src/waas/DynamicWaasTonConnectors.js +8 -0
- package/src/waas/connector/DynamicWaasTonConnector.cjs +293 -0
- package/src/waas/connector/DynamicWaasTonConnector.d.ts +160 -0
- package/src/waas/connector/DynamicWaasTonConnector.js +289 -0
- package/src/waas/signer/DynamicWaasTonSigner.cjs +56 -0
- package/src/waas/signer/DynamicWaasTonSigner.d.ts +20 -0
- package/src/waas/signer/DynamicWaasTonSigner.js +52 -0
- package/src/wallet/TonWallet.cjs +26 -0
- package/src/wallet/TonWallet.d.ts +16 -0
- package/src/wallet/TonWallet.js +22 -0
- package/src/wallet/WaasTonWallet.cjs +34 -0
- package/src/wallet/WaasTonWallet.d.ts +12 -0
- package/src/wallet/WaasTonWallet.js +30 -0
- package/src/wallet/index.d.ts +3 -0
- package/src/wallet/isTonWallet/index.d.ts +1 -0
- package/src/wallet/isTonWallet/isTonWallet.cjs +8 -0
- package/src/wallet/isTonWallet/isTonWallet.d.ts +3 -0
- package/src/wallet/isTonWallet/isTonWallet.js +4 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TonClient } from '@ton/ton';
|
|
2
|
+
export interface GetJettonWalletAddressParams {
|
|
3
|
+
/** Jetton master contract address */
|
|
4
|
+
jettonMasterAddress: string;
|
|
5
|
+
/** Owner's wallet address */
|
|
6
|
+
ownerAddress: string;
|
|
7
|
+
/** TonClient instance */
|
|
8
|
+
client: TonClient;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Derives a jetton wallet address for a given owner by calling
|
|
12
|
+
* the get_wallet_address method on the jetton master contract
|
|
13
|
+
*
|
|
14
|
+
* @param params - Parameters for getting jetton wallet address
|
|
15
|
+
* @returns Jetton wallet address for the owner
|
|
16
|
+
*/
|
|
17
|
+
export declare const getJettonWalletAddress: (params: GetJettonWalletAddressParams) => Promise<string>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { Address, beginCell } from '@ton/ton';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Derives a jetton wallet address for a given owner by calling
|
|
7
|
+
* the get_wallet_address method on the jetton master contract
|
|
8
|
+
*
|
|
9
|
+
* @param params - Parameters for getting jetton wallet address
|
|
10
|
+
* @returns Jetton wallet address for the owner
|
|
11
|
+
*/
|
|
12
|
+
const getJettonWalletAddress = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
const { jettonMasterAddress, ownerAddress, client } = params;
|
|
14
|
+
const masterAddress = Address.parse(jettonMasterAddress);
|
|
15
|
+
const owner = Address.parse(ownerAddress);
|
|
16
|
+
const ownerCell = beginCell().storeAddress(owner).endCell();
|
|
17
|
+
const result = yield client.runMethod(masterAddress, 'get_wallet_address', [
|
|
18
|
+
{ cell: ownerCell, type: 'slice' },
|
|
19
|
+
]);
|
|
20
|
+
const jettonWalletAddress = result.stack.readAddress();
|
|
21
|
+
return jettonWalletAddress.toString({
|
|
22
|
+
bounceable: true,
|
|
23
|
+
testOnly: false,
|
|
24
|
+
urlSafe: true,
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export { getJettonWalletAddress };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getJettonWalletAddress, type GetJettonWalletAddressParams, } from './getJettonWalletAddress';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var ton = require('@ton/ton');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Fetches the current seqno using TonClient
|
|
11
|
+
*
|
|
12
|
+
* @param walletAddress - Wallet address string
|
|
13
|
+
* @param client - TonClient instance
|
|
14
|
+
* @returns Current seqno
|
|
15
|
+
*/
|
|
16
|
+
const getWalletSeqno = (walletAddress, client) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const address = ton.Address.parse(walletAddress);
|
|
18
|
+
const result = yield client.runMethod(address, 'seqno');
|
|
19
|
+
return result.stack.readNumber();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
exports.getWalletSeqno = getWalletSeqno;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TonClient } from '@ton/ton';
|
|
2
|
+
/**
|
|
3
|
+
* Fetches the current seqno using TonClient
|
|
4
|
+
*
|
|
5
|
+
* @param walletAddress - Wallet address string
|
|
6
|
+
* @param client - TonClient instance
|
|
7
|
+
* @returns Current seqno
|
|
8
|
+
*/
|
|
9
|
+
export declare const getWalletSeqno: (walletAddress: string, client: TonClient) => Promise<number>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { Address } from '@ton/ton';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Fetches the current seqno using TonClient
|
|
7
|
+
*
|
|
8
|
+
* @param walletAddress - Wallet address string
|
|
9
|
+
* @param client - TonClient instance
|
|
10
|
+
* @returns Current seqno
|
|
11
|
+
*/
|
|
12
|
+
const getWalletSeqno = (walletAddress, client) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
const address = Address.parse(walletAddress);
|
|
14
|
+
const result = yield client.runMethod(address, 'seqno');
|
|
15
|
+
return result.stack.readNumber();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export { getWalletSeqno };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getWalletSeqno } from './getWalletSeqno';
|
package/src/utils/index.d.ts
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './TonUiTransaction';
|
|
2
|
+
export * from './prepareTransaction';
|
|
3
|
+
export * from './prepareTonTransfer';
|
|
4
|
+
export * from './prepareJettonTransfer';
|
|
5
|
+
export * from './getJettonWalletAddress';
|
|
6
|
+
export * from './getWalletSeqno';
|
|
7
|
+
export * from './executeTransaction';
|
|
8
|
+
export * from './extractDisplayInfoFromRequest';
|
|
9
|
+
export * from './convertSendTransactionRequest';
|
|
10
|
+
export * from './generateTonConnectProofHash';
|
|
11
|
+
export * from './logger/logger';
|
|
12
|
+
export * from './isWalletDeployed/isWalletDeployed';
|
|
13
|
+
export * from './createWalletStateInit/createWalletStateInit';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './isWalletDeployed';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var ton = require('@ton/ton');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a wallet contract is deployed on-chain by verifying if it has code.
|
|
11
|
+
*
|
|
12
|
+
* @param params - Parameters for checking wallet deployment
|
|
13
|
+
* @returns true if wallet contract is deployed (has code), false otherwise
|
|
14
|
+
*/
|
|
15
|
+
const isWalletDeployed = (params) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const { walletAddress, client } = params;
|
|
17
|
+
const address = ton.Address.parse(walletAddress);
|
|
18
|
+
const state = yield client.getContractState(address);
|
|
19
|
+
return state.state === 'active';
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
exports.isWalletDeployed = isWalletDeployed;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TonClient } from '@ton/ton';
|
|
2
|
+
export interface IsWalletDeployedParams {
|
|
3
|
+
/** Wallet address string */
|
|
4
|
+
walletAddress: string;
|
|
5
|
+
/** TonClient instance */
|
|
6
|
+
client: TonClient;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Checks if a wallet contract is deployed on-chain by verifying if it has code.
|
|
10
|
+
*
|
|
11
|
+
* @param params - Parameters for checking wallet deployment
|
|
12
|
+
* @returns true if wallet contract is deployed (has code), false otherwise
|
|
13
|
+
*/
|
|
14
|
+
export declare const isWalletDeployed: (params: IsWalletDeployedParams) => Promise<boolean>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { Address } from '@ton/ton';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a wallet contract is deployed on-chain by verifying if it has code.
|
|
7
|
+
*
|
|
8
|
+
* @param params - Parameters for checking wallet deployment
|
|
9
|
+
* @returns true if wallet contract is deployed (has code), false otherwise
|
|
10
|
+
*/
|
|
11
|
+
const isWalletDeployed = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
const { walletAddress, client } = params;
|
|
13
|
+
const address = Address.parse(walletAddress);
|
|
14
|
+
const state = yield client.getContractState(address);
|
|
15
|
+
return state.state === 'active';
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export { isWalletDeployed };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var logger$1 = require('@dynamic-labs/logger');
|
|
7
|
+
|
|
8
|
+
const logger = new logger$1.Logger('@dynamic-labs/ton');
|
|
9
|
+
|
|
10
|
+
Object.defineProperty(exports, 'Logger', {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () { return logger$1.Logger; }
|
|
13
|
+
});
|
|
14
|
+
exports.logger = logger;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { prepareJettonTransfer, type PrepareJettonTransferParams, } from './prepareJettonTransfer';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var ton = require('@ton/ton');
|
|
8
|
+
var types = require('../../types.cjs');
|
|
9
|
+
var getJettonWalletAddress = require('../getJettonWalletAddress/getJettonWalletAddress.cjs');
|
|
10
|
+
|
|
11
|
+
const DEFAULT_JETTON_GAS = BigInt(50000000);
|
|
12
|
+
/**
|
|
13
|
+
* Prepares a jetton (non-native token) transfer transaction
|
|
14
|
+
*
|
|
15
|
+
* @param params - Jetton transfer parameters
|
|
16
|
+
* @returns TON Connect SendTransactionRequest
|
|
17
|
+
*/
|
|
18
|
+
const prepareJettonTransfer = (params) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const { walletAddress, jettonMasterAddress, recipientAddress, jettonAmount, forwardTonAmount, client, forwardPayload = '', timeout = 60, gasAmount = DEFAULT_JETTON_GAS, network = types.CHAIN.MAINNET, } = params;
|
|
20
|
+
const validUntil = Math.floor(Date.now() / 1000) + timeout;
|
|
21
|
+
const jettonWalletAddress = yield getJettonWalletAddress.getJettonWalletAddress({
|
|
22
|
+
client,
|
|
23
|
+
jettonMasterAddress,
|
|
24
|
+
ownerAddress: walletAddress,
|
|
25
|
+
});
|
|
26
|
+
const jettonWalletAddr = ton.Address.parse(jettonWalletAddress);
|
|
27
|
+
const recipientAddr = ton.Address.parse(recipientAddress);
|
|
28
|
+
const walletAddr = ton.Address.parse(walletAddress);
|
|
29
|
+
const isTestnet = network === types.CHAIN.TESTNET;
|
|
30
|
+
// Build jetton transfer payload
|
|
31
|
+
// Jetton transfer message format (TEP-74):
|
|
32
|
+
// transfer#0f8a7ea5 query_id:uint64 amount:(VarUInteger 16)
|
|
33
|
+
// destination:MsgAddress response_destination:MsgAddress
|
|
34
|
+
// custom_payload:(Maybe ^Cell) forward_ton_amount:(VarUInteger 16)
|
|
35
|
+
// forward_payload:(Either Cell ^Cell) = InternalMsgBody;
|
|
36
|
+
const forwardPayloadCell = forwardPayload
|
|
37
|
+
? ton.beginCell()
|
|
38
|
+
.storeUint(0, 32) // text comment opcode
|
|
39
|
+
.storeStringTail(forwardPayload)
|
|
40
|
+
.endCell()
|
|
41
|
+
: ton.beginCell().endCell(); // empty cell
|
|
42
|
+
const jettonTransferBody = ton.beginCell()
|
|
43
|
+
.storeUint(0xf8a7ea5, 32) // jetton transfer op code
|
|
44
|
+
.storeUint(0, 64) // query_id (use 0 or timestamp)
|
|
45
|
+
.storeCoins(jettonAmount) // amount of jettons to transfer
|
|
46
|
+
.storeAddress(recipientAddr) // destination address
|
|
47
|
+
.storeAddress(walletAddr) // response_destination (excess TON goes here)
|
|
48
|
+
.storeBit(0) // custom_payload (null)
|
|
49
|
+
.storeCoins(forwardTonAmount) // forward_ton_amount
|
|
50
|
+
.storeBit(0) // forward_payload in this slice (not separate cell)
|
|
51
|
+
.storeSlice(forwardPayloadCell.beginParse()) // forward_payload content
|
|
52
|
+
.endCell();
|
|
53
|
+
// Total TON = forwardTonAmount + gas for the jetton transfer operation
|
|
54
|
+
const totalAmount = forwardTonAmount + gasAmount;
|
|
55
|
+
// Create TON Connect compatible message
|
|
56
|
+
const message = {
|
|
57
|
+
address: jettonWalletAddr.toString({
|
|
58
|
+
bounceable: true,
|
|
59
|
+
testOnly: isTestnet,
|
|
60
|
+
urlSafe: true,
|
|
61
|
+
}),
|
|
62
|
+
amount: totalAmount.toString(),
|
|
63
|
+
payload: jettonTransferBody.toBoc().toString('base64'),
|
|
64
|
+
};
|
|
65
|
+
const request = {
|
|
66
|
+
from: walletAddr.toString({
|
|
67
|
+
bounceable: false,
|
|
68
|
+
testOnly: isTestnet,
|
|
69
|
+
urlSafe: true,
|
|
70
|
+
}),
|
|
71
|
+
messages: [message],
|
|
72
|
+
network,
|
|
73
|
+
validUntil,
|
|
74
|
+
};
|
|
75
|
+
return request;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
exports.prepareJettonTransfer = prepareJettonTransfer;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TonClient } from '@ton/ton';
|
|
2
|
+
import { CHAIN, SendTransactionRequest } from '../../types';
|
|
3
|
+
export interface PrepareJettonTransferParams {
|
|
4
|
+
/** Sender wallet address */
|
|
5
|
+
walletAddress: string;
|
|
6
|
+
/** Jetton master contract address */
|
|
7
|
+
jettonMasterAddress: string;
|
|
8
|
+
/** Recipient's main wallet address */
|
|
9
|
+
recipientAddress: string;
|
|
10
|
+
/** Amount of jettons in base units (bigint) */
|
|
11
|
+
jettonAmount: bigint;
|
|
12
|
+
/** TON amount to forward with notification */
|
|
13
|
+
forwardTonAmount: bigint;
|
|
14
|
+
/** TonClient instance */
|
|
15
|
+
client: TonClient;
|
|
16
|
+
/** Optional comment/memo */
|
|
17
|
+
forwardPayload?: string;
|
|
18
|
+
/** Network (MAINNET or TESTNET) */
|
|
19
|
+
network?: CHAIN;
|
|
20
|
+
/** Message timeout in seconds (default: 60) */
|
|
21
|
+
timeout?: number;
|
|
22
|
+
/** Gas amount in nanotons for the jetton transfer */
|
|
23
|
+
gasAmount?: bigint;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Prepares a jetton (non-native token) transfer transaction
|
|
27
|
+
*
|
|
28
|
+
* @param params - Jetton transfer parameters
|
|
29
|
+
* @returns TON Connect SendTransactionRequest
|
|
30
|
+
*/
|
|
31
|
+
export declare const prepareJettonTransfer: (params: PrepareJettonTransferParams) => Promise<SendTransactionRequest>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { Address, beginCell } from '@ton/ton';
|
|
4
|
+
import { CHAIN } from '../../types.js';
|
|
5
|
+
import { getJettonWalletAddress } from '../getJettonWalletAddress/getJettonWalletAddress.js';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_JETTON_GAS = BigInt(50000000);
|
|
8
|
+
/**
|
|
9
|
+
* Prepares a jetton (non-native token) transfer transaction
|
|
10
|
+
*
|
|
11
|
+
* @param params - Jetton transfer parameters
|
|
12
|
+
* @returns TON Connect SendTransactionRequest
|
|
13
|
+
*/
|
|
14
|
+
const prepareJettonTransfer = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const { walletAddress, jettonMasterAddress, recipientAddress, jettonAmount, forwardTonAmount, client, forwardPayload = '', timeout = 60, gasAmount = DEFAULT_JETTON_GAS, network = CHAIN.MAINNET, } = params;
|
|
16
|
+
const validUntil = Math.floor(Date.now() / 1000) + timeout;
|
|
17
|
+
const jettonWalletAddress = yield getJettonWalletAddress({
|
|
18
|
+
client,
|
|
19
|
+
jettonMasterAddress,
|
|
20
|
+
ownerAddress: walletAddress,
|
|
21
|
+
});
|
|
22
|
+
const jettonWalletAddr = Address.parse(jettonWalletAddress);
|
|
23
|
+
const recipientAddr = Address.parse(recipientAddress);
|
|
24
|
+
const walletAddr = Address.parse(walletAddress);
|
|
25
|
+
const isTestnet = network === CHAIN.TESTNET;
|
|
26
|
+
// Build jetton transfer payload
|
|
27
|
+
// Jetton transfer message format (TEP-74):
|
|
28
|
+
// transfer#0f8a7ea5 query_id:uint64 amount:(VarUInteger 16)
|
|
29
|
+
// destination:MsgAddress response_destination:MsgAddress
|
|
30
|
+
// custom_payload:(Maybe ^Cell) forward_ton_amount:(VarUInteger 16)
|
|
31
|
+
// forward_payload:(Either Cell ^Cell) = InternalMsgBody;
|
|
32
|
+
const forwardPayloadCell = forwardPayload
|
|
33
|
+
? beginCell()
|
|
34
|
+
.storeUint(0, 32) // text comment opcode
|
|
35
|
+
.storeStringTail(forwardPayload)
|
|
36
|
+
.endCell()
|
|
37
|
+
: beginCell().endCell(); // empty cell
|
|
38
|
+
const jettonTransferBody = beginCell()
|
|
39
|
+
.storeUint(0xf8a7ea5, 32) // jetton transfer op code
|
|
40
|
+
.storeUint(0, 64) // query_id (use 0 or timestamp)
|
|
41
|
+
.storeCoins(jettonAmount) // amount of jettons to transfer
|
|
42
|
+
.storeAddress(recipientAddr) // destination address
|
|
43
|
+
.storeAddress(walletAddr) // response_destination (excess TON goes here)
|
|
44
|
+
.storeBit(0) // custom_payload (null)
|
|
45
|
+
.storeCoins(forwardTonAmount) // forward_ton_amount
|
|
46
|
+
.storeBit(0) // forward_payload in this slice (not separate cell)
|
|
47
|
+
.storeSlice(forwardPayloadCell.beginParse()) // forward_payload content
|
|
48
|
+
.endCell();
|
|
49
|
+
// Total TON = forwardTonAmount + gas for the jetton transfer operation
|
|
50
|
+
const totalAmount = forwardTonAmount + gasAmount;
|
|
51
|
+
// Create TON Connect compatible message
|
|
52
|
+
const message = {
|
|
53
|
+
address: jettonWalletAddr.toString({
|
|
54
|
+
bounceable: true,
|
|
55
|
+
testOnly: isTestnet,
|
|
56
|
+
urlSafe: true,
|
|
57
|
+
}),
|
|
58
|
+
amount: totalAmount.toString(),
|
|
59
|
+
payload: jettonTransferBody.toBoc().toString('base64'),
|
|
60
|
+
};
|
|
61
|
+
const request = {
|
|
62
|
+
from: walletAddr.toString({
|
|
63
|
+
bounceable: false,
|
|
64
|
+
testOnly: isTestnet,
|
|
65
|
+
urlSafe: true,
|
|
66
|
+
}),
|
|
67
|
+
messages: [message],
|
|
68
|
+
network,
|
|
69
|
+
validUntil,
|
|
70
|
+
};
|
|
71
|
+
return request;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export { prepareJettonTransfer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { prepareTonTransfer, type PrepareTonTransferParams, } from './prepareTonTransfer';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var ton = require('@ton/ton');
|
|
8
|
+
var types = require('../../types.cjs');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Prepares a native TON transfer transaction
|
|
12
|
+
*
|
|
13
|
+
* @param params - Transfer parameters
|
|
14
|
+
* @returns TON Connect SendTransactionRequest
|
|
15
|
+
*/
|
|
16
|
+
const prepareTonTransfer = (params) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const { walletAddress, recipient, amount, timeout = 60, network = types.CHAIN.MAINNET, } = params;
|
|
18
|
+
const validUntil = Math.floor(Date.now() / 1000) + timeout;
|
|
19
|
+
const recipientAddress = ton.Address.parse(recipient);
|
|
20
|
+
const amountNano = ton.toNano(amount.toString());
|
|
21
|
+
const walletAddr = ton.Address.parse(walletAddress);
|
|
22
|
+
const isTestnet = network === types.CHAIN.TESTNET;
|
|
23
|
+
// Create TON Connect compatible message
|
|
24
|
+
const message = {
|
|
25
|
+
address: recipientAddress.toString({
|
|
26
|
+
bounceable: false,
|
|
27
|
+
testOnly: isTestnet,
|
|
28
|
+
urlSafe: true,
|
|
29
|
+
}),
|
|
30
|
+
amount: amountNano.toString(),
|
|
31
|
+
};
|
|
32
|
+
const request = {
|
|
33
|
+
from: walletAddr.toString({
|
|
34
|
+
bounceable: false,
|
|
35
|
+
testOnly: isTestnet,
|
|
36
|
+
urlSafe: true,
|
|
37
|
+
}),
|
|
38
|
+
messages: [message],
|
|
39
|
+
network,
|
|
40
|
+
validUntil,
|
|
41
|
+
};
|
|
42
|
+
return request;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
exports.prepareTonTransfer = prepareTonTransfer;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TonClient } from '@ton/ton';
|
|
2
|
+
import { CHAIN, SendTransactionRequest } from '../../types';
|
|
3
|
+
export interface PrepareTonTransferParams {
|
|
4
|
+
/** Sender wallet address */
|
|
5
|
+
walletAddress: string;
|
|
6
|
+
/** Recipient address */
|
|
7
|
+
recipient: string;
|
|
8
|
+
/** Amount in TON (will be converted to nanotons) */
|
|
9
|
+
amount: string | number;
|
|
10
|
+
/** TonClient instance */
|
|
11
|
+
client: TonClient;
|
|
12
|
+
/** Network (MAINNET or TESTNET, default: MAINNET) */
|
|
13
|
+
network?: CHAIN;
|
|
14
|
+
/** Message timeout in seconds (default: 60) */
|
|
15
|
+
timeout?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Prepares a native TON transfer transaction
|
|
19
|
+
*
|
|
20
|
+
* @param params - Transfer parameters
|
|
21
|
+
* @returns TON Connect SendTransactionRequest
|
|
22
|
+
*/
|
|
23
|
+
export declare const prepareTonTransfer: (params: PrepareTonTransferParams) => Promise<SendTransactionRequest>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { Address, toNano } from '@ton/ton';
|
|
4
|
+
import { CHAIN } from '../../types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Prepares a native TON transfer transaction
|
|
8
|
+
*
|
|
9
|
+
* @param params - Transfer parameters
|
|
10
|
+
* @returns TON Connect SendTransactionRequest
|
|
11
|
+
*/
|
|
12
|
+
const prepareTonTransfer = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
const { walletAddress, recipient, amount, timeout = 60, network = CHAIN.MAINNET, } = params;
|
|
14
|
+
const validUntil = Math.floor(Date.now() / 1000) + timeout;
|
|
15
|
+
const recipientAddress = Address.parse(recipient);
|
|
16
|
+
const amountNano = toNano(amount.toString());
|
|
17
|
+
const walletAddr = Address.parse(walletAddress);
|
|
18
|
+
const isTestnet = network === CHAIN.TESTNET;
|
|
19
|
+
// Create TON Connect compatible message
|
|
20
|
+
const message = {
|
|
21
|
+
address: recipientAddress.toString({
|
|
22
|
+
bounceable: false,
|
|
23
|
+
testOnly: isTestnet,
|
|
24
|
+
urlSafe: true,
|
|
25
|
+
}),
|
|
26
|
+
amount: amountNano.toString(),
|
|
27
|
+
};
|
|
28
|
+
const request = {
|
|
29
|
+
from: walletAddr.toString({
|
|
30
|
+
bounceable: false,
|
|
31
|
+
testOnly: isTestnet,
|
|
32
|
+
urlSafe: true,
|
|
33
|
+
}),
|
|
34
|
+
messages: [message],
|
|
35
|
+
network,
|
|
36
|
+
validUntil,
|
|
37
|
+
};
|
|
38
|
+
return request;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export { prepareTonTransfer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { prepareTransaction, type PrepareTransactionParams, type PrepareTransactionResult, } from './prepareTransaction';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var ton = require('@ton/ton');
|
|
7
|
+
var core = require('@ton/core');
|
|
8
|
+
var types = require('../../types.cjs');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Prepares a v5r1 wallet transaction from an array of actions
|
|
12
|
+
*
|
|
13
|
+
* @param params - Parameters for preparing the transaction
|
|
14
|
+
* @returns The hash to sign and transaction data
|
|
15
|
+
*/
|
|
16
|
+
const prepareTransaction = (params) => {
|
|
17
|
+
const { actionsArray, walletAddress, seqno, validUntil, timeout, networkGlobalId = types.CHAIN.MAINNET, } = params;
|
|
18
|
+
const walletAddr = ton.Address.parse(walletAddress);
|
|
19
|
+
// Build actions cell from actions array
|
|
20
|
+
const actionsCell = ton.beginCell().store(core.storeOutList(actionsArray)).endCell();
|
|
21
|
+
const actions = ton.beginCell()
|
|
22
|
+
.storeBit(1) // storeMaybeRef - we have basic actions
|
|
23
|
+
.storeRef(actionsCell) // ref to basic actions
|
|
24
|
+
.storeBit(0) // no extended actions
|
|
25
|
+
.endCell();
|
|
26
|
+
// Calculate walletId following v5r1 spec:
|
|
27
|
+
// walletId = networkGlobalId XOR context
|
|
28
|
+
// context = (1 bit: isClient=1) + (8 bits: workchain) + (8 bits: version=0) + (15 bits: subwallet=0)
|
|
29
|
+
const context = ton.beginCell()
|
|
30
|
+
.storeUint(1, 1) // isClientContext
|
|
31
|
+
.storeInt(walletAddr.workChain, 8) // workchain
|
|
32
|
+
.storeUint(0, 8) // wallet_version (v5r1 = 0)
|
|
33
|
+
.storeUint(0, 15) // subwalletNumber
|
|
34
|
+
.endCell()
|
|
35
|
+
.beginParse()
|
|
36
|
+
.loadInt(32);
|
|
37
|
+
const walletIdValue = BigInt(networkGlobalId) ^ BigInt(context);
|
|
38
|
+
// Build the signing message according to v5r1 spec
|
|
39
|
+
// opcode | walletId | valid_until/timeout | seqno | actions
|
|
40
|
+
const signingMessage = ton.beginCell()
|
|
41
|
+
.storeUint(ton.WalletContractV5R1.OpCodes.auth_signed_external, 32)
|
|
42
|
+
.storeInt(walletIdValue, 32);
|
|
43
|
+
// For seqno 0 (first transaction/deployment), store 32 bits of 1s instead of validUntil
|
|
44
|
+
// This is a special case in v5r1 spec for the first transaction of a wallet
|
|
45
|
+
// It doesn't matter if the contract is already deployed or not.
|
|
46
|
+
if (seqno === 0) {
|
|
47
|
+
for (let i = 0; i < 32; i++) {
|
|
48
|
+
signingMessage.storeBit(1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
signingMessage.storeUint(validUntil, 32);
|
|
53
|
+
}
|
|
54
|
+
signingMessage.storeUint(seqno, 32).storeSlice(actions.beginParse());
|
|
55
|
+
// Calculate hash to sign
|
|
56
|
+
const dataToSign = signingMessage.endCell();
|
|
57
|
+
const hashToSign = dataToSign.hash();
|
|
58
|
+
const hashToSignHex = hashToSign.toString('hex');
|
|
59
|
+
// Store the signing message
|
|
60
|
+
const messageBody = dataToSign.toBoc().toString('base64');
|
|
61
|
+
const transactionData = {
|
|
62
|
+
address: walletAddress,
|
|
63
|
+
messageBody,
|
|
64
|
+
seqno,
|
|
65
|
+
timeout,
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
hashToSign,
|
|
69
|
+
hashToSignHex,
|
|
70
|
+
transactionData,
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
exports.prepareTransaction = prepareTransaction;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { OutActionSendMsg } from '@ton/core';
|
|
3
|
+
import { CHAIN, type TonTransactionData } from '../../types';
|
|
4
|
+
export interface PrepareTransactionParams {
|
|
5
|
+
/** Array of actions to include in the transaction */
|
|
6
|
+
actionsArray: OutActionSendMsg[];
|
|
7
|
+
/** Sender wallet address */
|
|
8
|
+
walletAddress: string;
|
|
9
|
+
/** Current wallet seqno */
|
|
10
|
+
seqno: number;
|
|
11
|
+
/** Unix timestamp when transaction expires */
|
|
12
|
+
validUntil: number;
|
|
13
|
+
/** Transaction timeout in seconds (for transactionData) */
|
|
14
|
+
timeout: number;
|
|
15
|
+
/** Network global ID (-239 for mainnet, -3 for testnet) */
|
|
16
|
+
networkGlobalId?: CHAIN;
|
|
17
|
+
}
|
|
18
|
+
export interface PrepareTransactionResult {
|
|
19
|
+
/** Hash to sign as Buffer */
|
|
20
|
+
hashToSign: Buffer;
|
|
21
|
+
/** Hash to sign as hex string */
|
|
22
|
+
hashToSignHex: string;
|
|
23
|
+
/** Transaction data for executeTransaction */
|
|
24
|
+
transactionData: TonTransactionData;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Prepares a v5r1 wallet transaction from an array of actions
|
|
28
|
+
*
|
|
29
|
+
* @param params - Parameters for preparing the transaction
|
|
30
|
+
* @returns The hash to sign and transaction data
|
|
31
|
+
*/
|
|
32
|
+
export declare const prepareTransaction: (params: PrepareTransactionParams) => PrepareTransactionResult;
|