@tonappchain/sdk 0.6.5-mainnet-alpha → 0.6.6-mainnet-alpha

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.
@@ -1,7 +1,7 @@
1
1
  import { Address, Cell } from '@ton/ton';
2
2
  import { AbiCoder } from 'ethers';
3
- import { EvmProxyMsg, FeeParams, TransactionLinker, ValidExecutors } from '../structs/Struct';
4
3
  import { RandomNumberByTimestamp } from '../structs/InternalStruct';
4
+ import { EvmProxyMsg, FeeParams, TransactionLinker, ValidExecutors, WaitOptions } from '../structs/Struct';
5
5
  export declare const sleep: (ms: number) => Promise<unknown>;
6
6
  export declare function generateRandomNumber(interval: number): number;
7
7
  export declare function generateRandomNumberByTimestamp(): RandomNumberByTimestamp;
@@ -15,5 +15,7 @@ export declare function calculateEVMTokenAddress(abiCoder: AbiCoder, tokenUtilsA
15
15
  export declare const convertKeysToCamelCase: <T>(data: T) => T;
16
16
  export declare const calculateRawAmount: (amount: number, decimals: number) => bigint;
17
17
  export declare const calculateAmount: (rawAmount: bigint, decimals: number) => number;
18
- export declare const toCamelCaseTransformer: (data: any) => any;
18
+ export declare const toCamelCaseTransformer: (data: string) => any;
19
19
  export declare const generateFeeData: (feeParams?: FeeParams) => Cell | undefined;
20
+ export declare function waitUntilSuccess<T, A extends unknown[]>(options: WaitOptions<T> | undefined, operation: (...args: A) => Promise<T>, ...args: A): Promise<T>;
21
+ export declare function formatObjectForLogging(obj: unknown): string;
package/dist/sdk/Utils.js CHANGED
@@ -10,6 +10,8 @@ exports.generateTransactionLinker = generateTransactionLinker;
10
10
  exports.validateTVMAddress = validateTVMAddress;
11
11
  exports.validateEVMAddress = validateEVMAddress;
12
12
  exports.calculateEVMTokenAddress = calculateEVMTokenAddress;
13
+ exports.waitUntilSuccess = waitUntilSuccess;
14
+ exports.formatObjectForLogging = formatObjectForLogging;
13
15
  const ton_1 = require("@ton/ton");
14
16
  const ethers_1 = require("ethers");
15
17
  const errors_1 = require("../errors");
@@ -128,7 +130,7 @@ const toCamelCaseTransformer = (data) => {
128
130
  exports.toCamelCaseTransformer = toCamelCaseTransformer;
129
131
  const generateFeeData = (feeParams) => {
130
132
  if (feeParams) {
131
- let feeDataBuilder = (0, ton_1.beginCell)()
133
+ const feeDataBuilder = (0, ton_1.beginCell)()
132
134
  .storeBit(feeParams.isRoundTrip)
133
135
  .storeCoins(feeParams.protocolFee)
134
136
  .storeCoins(feeParams.evmExecutorFee);
@@ -142,3 +144,46 @@ const generateFeeData = (feeParams) => {
142
144
  }
143
145
  };
144
146
  exports.generateFeeData = generateFeeData;
147
+ async function waitUntilSuccess(options = {}, operation, ...args) {
148
+ const timeout = options.timeout ?? 300000;
149
+ const maxAttempts = options.maxAttempts ?? 30;
150
+ const delay = options.delay ?? 10000;
151
+ const successCheck = options.successCheck;
152
+ const log = options.log ?? (() => { });
153
+ log(`Starting wait for success with timeout=${timeout}ms, maxAttempts=${maxAttempts}, delay=${delay}ms`);
154
+ const startTime = Date.now();
155
+ let attempt = 1;
156
+ while (true) {
157
+ const currentTime = Date.now();
158
+ const elapsedTime = currentTime - startTime;
159
+ try {
160
+ const result = await operation(...args);
161
+ if (!result) {
162
+ throw new Error(`Empty result`);
163
+ }
164
+ log(`Result: ${formatObjectForLogging(result)}`);
165
+ if (successCheck && !successCheck(result)) {
166
+ throw new Error(`Result is not successful`);
167
+ }
168
+ log(`Attempt ${attempt} successful`);
169
+ return result;
170
+ }
171
+ catch (error) {
172
+ if (elapsedTime >= timeout) {
173
+ log(`Timeout after ${elapsedTime}ms`);
174
+ throw error;
175
+ }
176
+ if (attempt >= maxAttempts) {
177
+ log(`Max attempts (${maxAttempts}) reached`);
178
+ throw error;
179
+ }
180
+ log(`Error on attempt ${attempt}: ${error}`);
181
+ log(`Waiting ${delay}ms before next attempt`);
182
+ await (0, exports.sleep)(delay);
183
+ attempt++;
184
+ }
185
+ }
186
+ }
187
+ function formatObjectForLogging(obj) {
188
+ return JSON.stringify(obj, (key, value) => typeof value === 'bigint' ? value.toString() : value);
189
+ }
@@ -60,7 +60,7 @@ export type InternalTONParams = {
60
60
  export type InternalTACParams = {
61
61
  provider: AbstractProvider;
62
62
  crossChainLayer: testnet.tac.wrappers.CrossChainLayerTAC | mainnet.tac.wrappers.CrossChainLayerTAC;
63
- settings: testnet.tac.wrappers.SettingsTAC | testnet.tac.wrappers.SettingsTAC;
63
+ settings: testnet.tac.wrappers.SettingsTAC | mainnet.tac.wrappers.SettingsTAC;
64
64
  tokenUtils: testnet.tac.wrappers.TokenUtilsTAC | mainnet.tac.wrappers.TokenUtilsTAC;
65
65
  trustedTACExecutors: string[];
66
66
  trustedTONExecutors: string[];
@@ -1,13 +1,14 @@
1
1
  import { SandboxContract } from '@ton/sandbox';
2
2
  import type { Address, Cell, Contract, OpenedContract } from '@ton/ton';
3
3
  import { AbstractProvider, Addressable, Interface, InterfaceAbi } from 'ethers';
4
+ export type ContractState = {
5
+ balance: bigint;
6
+ state: 'active' | 'uninitialized' | 'frozen';
7
+ code: Buffer | null;
8
+ };
4
9
  export interface ContractOpener {
5
10
  open<T extends Contract>(src: T): OpenedContract<T> | SandboxContract<T>;
6
- getContractState(address: Address): Promise<{
7
- balance: bigint;
8
- state: 'active' | 'uninitialized' | 'frozen';
9
- code: Buffer | null;
10
- }>;
11
+ getContractState(address: Address): Promise<ContractState>;
11
12
  closeConnections?: () => unknown;
12
13
  }
13
14
  export declare enum SimplifiedStatuses {
@@ -97,6 +98,10 @@ export type SDKParams = {
97
98
  * URLs of lite sequencers
98
99
  */
99
100
  customLiteSequencerEndpoints?: string[];
101
+ /**
102
+ * Debug flag
103
+ */
104
+ debug?: boolean;
100
105
  };
101
106
  export declare enum AssetType {
102
107
  NFT = "NFT",
@@ -173,6 +178,9 @@ export type TransactionLinker = {
173
178
  timestamp: number;
174
179
  sendTransactionResult?: unknown;
175
180
  };
181
+ export type TransactionLinkerWithOperationId = TransactionLinker & {
182
+ operationId?: string;
183
+ };
176
184
  export type TACSimulationRequest = {
177
185
  tacCallParams: {
178
186
  arguments: string;
@@ -180,6 +188,7 @@ export type TACSimulationRequest = {
180
188
  target: string;
181
189
  };
182
190
  evmValidExecutors: string[];
191
+ tvmValidExecutors: string[];
183
192
  extraData: string;
184
193
  shardsKey: string;
185
194
  tonAssets: {
@@ -335,3 +344,30 @@ export type NFTItemData = {
335
344
  ownerAddress: Address | null;
336
345
  content: Cell | null;
337
346
  };
347
+ export interface WaitOptions<T = unknown> {
348
+ /**
349
+ * Timeout in milliseconds
350
+ * @default 300000 (5 minutes)
351
+ */
352
+ timeout?: number;
353
+ /**
354
+ * Maximum number of attempts
355
+ * @default 30
356
+ */
357
+ maxAttempts?: number;
358
+ /**
359
+ * Delay between attempts in milliseconds
360
+ * @default 10000 (10 seconds)
361
+ */
362
+ delay?: number;
363
+ /**
364
+ * Function to log debug messages
365
+ */
366
+ log?: (message: string) => void;
367
+ /**
368
+ * Function to check if the result is successful
369
+ * If not provided, any non-error result is considered successful
370
+ */
371
+ successCheck?: (result: T) => boolean;
372
+ }
373
+ export declare const defaultWaitOptions: WaitOptions;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TokenSymbol = exports.StageName = exports.NFTAddressType = exports.AssetType = exports.OperationType = exports.BlockchainType = exports.Network = exports.SimplifiedStatuses = void 0;
3
+ exports.defaultWaitOptions = exports.TokenSymbol = exports.StageName = exports.NFTAddressType = exports.AssetType = exports.OperationType = exports.BlockchainType = exports.Network = exports.SimplifiedStatuses = void 0;
4
4
  var SimplifiedStatuses;
5
5
  (function (SimplifiedStatuses) {
6
6
  SimplifiedStatuses["PENDING"] = "PENDING";
@@ -51,3 +51,8 @@ var TokenSymbol;
51
51
  TokenSymbol["TAC_SYMBOL"] = "TAC";
52
52
  TokenSymbol["TON_SYMBOL"] = "TON";
53
53
  })(TokenSymbol || (exports.TokenSymbol = TokenSymbol = {}));
54
+ exports.defaultWaitOptions = {
55
+ timeout: 300000,
56
+ maxAttempts: 30,
57
+ delay: 10000,
58
+ };
@@ -1,4 +1,4 @@
1
- import type { Contract, ContractProvider, Sender } from '@ton/ton';
1
+ import { Contract, ContractProvider, Sender } from '@ton/ton';
2
2
  import { Address, Cell } from '@ton/ton';
3
3
  export type JettonWalletData = {
4
4
  balance: bigint;
@@ -8,7 +8,8 @@ export type JettonWalletData = {
8
8
  };
9
9
  export declare enum JettonWalletOpCodes {
10
10
  burn = 1499400124,
11
- transfer = 260734629
11
+ transfer = 260734629,
12
+ internalTransfer = 395134233
12
13
  }
13
14
  export declare function jettonWalletConfigToCell(config: JettonWalletData): Cell;
14
15
  export declare class JettonWallet implements Contract {
@@ -42,6 +43,14 @@ export declare class JettonWallet implements Contract {
42
43
  forwardTonAmount?: bigint;
43
44
  forwardPayload?: Cell | null;
44
45
  }): Promise<void>;
46
+ sendReceive(provider: ContractProvider, via: Sender, value: bigint, opts: {
47
+ queryId?: number;
48
+ jettonAmount: number;
49
+ fromOwnerAddress?: string;
50
+ responseAddress?: string;
51
+ forwardTonAmount?: number;
52
+ forwardPayload?: Cell;
53
+ }): Promise<void>;
45
54
  getWalletData(provider: ContractProvider): Promise<JettonWalletData>;
46
55
  getJettonBalance(provider: ContractProvider): Promise<bigint>;
47
56
  }
@@ -3,16 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JettonWallet = exports.JettonWalletOpCodes = void 0;
4
4
  exports.jettonWalletConfigToCell = jettonWalletConfigToCell;
5
5
  const ton_1 = require("@ton/ton");
6
+ const ton_2 = require("@ton/ton");
6
7
  var JettonWalletOpCodes;
7
8
  (function (JettonWalletOpCodes) {
8
9
  JettonWalletOpCodes[JettonWalletOpCodes["burn"] = 1499400124] = "burn";
9
10
  JettonWalletOpCodes[JettonWalletOpCodes["transfer"] = 260734629] = "transfer";
11
+ JettonWalletOpCodes[JettonWalletOpCodes["internalTransfer"] = 395134233] = "internalTransfer";
10
12
  })(JettonWalletOpCodes || (exports.JettonWalletOpCodes = JettonWalletOpCodes = {}));
11
13
  function jettonWalletConfigToCell(config) {
12
- return (0, ton_1.beginCell)()
14
+ return (0, ton_2.beginCell)()
13
15
  .storeCoins(config.balance)
14
- .storeAddress(ton_1.Address.parse(config.ownerAddress))
15
- .storeAddress(ton_1.Address.parse(config.jettonMasterAddress))
16
+ .storeAddress(ton_2.Address.parse(config.ownerAddress))
17
+ .storeAddress(ton_2.Address.parse(config.jettonMasterAddress))
16
18
  .endCell();
17
19
  }
18
20
  class JettonWallet {
@@ -26,16 +28,16 @@ class JettonWallet {
26
28
  static createFromConfig(config, code, workchain = 0) {
27
29
  const data = jettonWalletConfigToCell(config);
28
30
  const init = { code, data };
29
- return new JettonWallet((0, ton_1.contractAddress)(workchain, init), init);
31
+ return new JettonWallet((0, ton_2.contractAddress)(workchain, init), init);
30
32
  }
31
33
  static burnMessage(jettonAmount, receiverAddress, crossChainTonAmount, feeData, crossChainPayload, queryId) {
32
- const body = (0, ton_1.beginCell)()
34
+ const body = (0, ton_2.beginCell)()
33
35
  .storeUint(JettonWalletOpCodes.burn, 32)
34
36
  .storeUint(queryId || 0, 64)
35
37
  .storeCoins(jettonAmount)
36
- .storeAddress(receiverAddress ? ton_1.Address.parse(receiverAddress) : null);
38
+ .storeAddress(receiverAddress ? ton_2.Address.parse(receiverAddress) : null);
37
39
  if (crossChainTonAmount || crossChainPayload) {
38
- body.storeMaybeRef((0, ton_1.beginCell)()
40
+ body.storeMaybeRef((0, ton_2.beginCell)()
39
41
  .storeCoins(crossChainTonAmount ?? 0n)
40
42
  .storeMaybeRef(feeData)
41
43
  .storeMaybeRef(crossChainPayload)
@@ -50,20 +52,20 @@ class JettonWallet {
50
52
  const body = JettonWallet.burnMessage(opts.jettonAmount, opts.receiverAddress, opts.crossChainTonAmount, opts.feeData, opts.crossChainPayload, opts.queryId);
51
53
  await provider.internal(via, {
52
54
  value,
53
- sendMode: ton_1.SendMode.PAY_GAS_SEPARATELY,
55
+ sendMode: ton_2.SendMode.PAY_GAS_SEPARATELY,
54
56
  body: body,
55
57
  });
56
58
  }
57
59
  static transferMessage(jettonAmount, to, responseAddress, forwardTonAmount, crossChainTonAmount, feeData, crossChainPayload, queryId) {
58
- return (0, ton_1.beginCell)()
60
+ return (0, ton_2.beginCell)()
59
61
  .storeUint(JettonWalletOpCodes.transfer, 32)
60
62
  .storeUint(queryId ?? 0, 64)
61
63
  .storeCoins(jettonAmount)
62
- .storeAddress(ton_1.Address.parse(to))
63
- .storeAddress(responseAddress ? ton_1.Address.parse(responseAddress) : null)
64
+ .storeAddress(ton_2.Address.parse(to))
65
+ .storeAddress(responseAddress ? ton_2.Address.parse(responseAddress) : null)
64
66
  .storeMaybeRef(null)
65
67
  .storeCoins(forwardTonAmount || 0n)
66
- .storeMaybeRef((0, ton_1.beginCell)()
68
+ .storeMaybeRef((0, ton_2.beginCell)()
67
69
  .storeCoins(crossChainTonAmount ?? 0n)
68
70
  .storeMaybeRef(feeData)
69
71
  .storeMaybeRef(crossChainPayload)
@@ -73,19 +75,34 @@ class JettonWallet {
73
75
  async sendTransfer(provider, via, value, opts) {
74
76
  await provider.internal(via, {
75
77
  value,
76
- sendMode: ton_1.SendMode.PAY_GAS_SEPARATELY,
77
- body: (0, ton_1.beginCell)()
78
+ sendMode: ton_2.SendMode.PAY_GAS_SEPARATELY,
79
+ body: (0, ton_2.beginCell)()
78
80
  .storeUint(JettonWalletOpCodes.transfer, 32)
79
81
  .storeUint(opts.queryId || 0, 64)
80
82
  .storeCoins(opts.jettonAmount)
81
- .storeAddress(ton_1.Address.parse(opts.toOwnerAddress))
82
- .storeAddress(opts.responseAddress ? ton_1.Address.parse(opts.responseAddress) : null)
83
+ .storeAddress(ton_2.Address.parse(opts.toOwnerAddress))
84
+ .storeAddress(opts.responseAddress ? ton_2.Address.parse(opts.responseAddress) : null)
83
85
  .storeMaybeRef(opts.customPayload)
84
86
  .storeCoins(opts.forwardTonAmount ?? 0n)
85
87
  .storeMaybeRef(opts.forwardPayload)
86
88
  .endCell(),
87
89
  });
88
90
  }
91
+ async sendReceive(provider, via, value, opts) {
92
+ await provider.internal(via, {
93
+ value,
94
+ sendMode: ton_2.SendMode.PAY_GAS_SEPARATELY,
95
+ body: (0, ton_2.beginCell)()
96
+ .storeUint(JettonWalletOpCodes.internalTransfer, 32)
97
+ .storeUint(opts.queryId || 0, 64)
98
+ .storeCoins((0, ton_1.toNano)(opts.jettonAmount.toFixed(9)))
99
+ .storeAddress(opts.fromOwnerAddress ? ton_2.Address.parse(opts.fromOwnerAddress) : null)
100
+ .storeAddress(opts.responseAddress ? ton_2.Address.parse(opts.responseAddress) : null)
101
+ .storeCoins(opts.forwardTonAmount || 0)
102
+ .storeMaybeRef(opts.forwardPayload)
103
+ .endCell(),
104
+ });
105
+ }
89
106
  async getWalletData(provider) {
90
107
  const result = await provider.get('get_wallet_data', []);
91
108
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonappchain/sdk",
3
- "version": "0.6.5-mainnet-alpha",
3
+ "version": "0.6.6-mainnet-alpha",
4
4
  "repository": "https://github.com/TacBuild/tac-sdk.git",
5
5
  "author": "TAC. <developers@tac>",
6
6
  "license": "MIT",
@@ -20,7 +20,7 @@
20
20
  "@aws-crypto/sha256-js": "^5.2.0",
21
21
  "@orbs-network/ton-access": "^2.3.3",
22
22
  "@ton/ton": "15.1.0",
23
- "@tonappchain/artifacts": "0.0.19-mainnet-rc2",
23
+ "@tonappchain/artifacts": "0.0.19-smart-accounts-4",
24
24
  "@tonappchain/ton-lite-client": "3.0.6",
25
25
  "@tonconnect/ui": "^2.0.11",
26
26
  "bn.js": "^5.2.1",