@tonappchain/sdk 0.5.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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1197 -0
  3. package/dist/adapters/contractOpener.d.ts +19 -0
  4. package/dist/adapters/contractOpener.js +94 -0
  5. package/dist/errors/errors.d.ts +34 -0
  6. package/dist/errors/errors.js +80 -0
  7. package/dist/errors/index.d.ts +2 -0
  8. package/dist/errors/index.js +30 -0
  9. package/dist/errors/instances.d.ts +16 -0
  10. package/dist/errors/instances.js +28 -0
  11. package/dist/index.d.ts +10 -0
  12. package/dist/index.js +35 -0
  13. package/dist/sdk/Consts.d.ts +6 -0
  14. package/dist/sdk/Consts.js +10 -0
  15. package/dist/sdk/OperationTracker.d.ts +15 -0
  16. package/dist/sdk/OperationTracker.js +128 -0
  17. package/dist/sdk/StartTracking.d.ts +2 -0
  18. package/dist/sdk/StartTracking.js +91 -0
  19. package/dist/sdk/TacSdk.d.ts +36 -0
  20. package/dist/sdk/TacSdk.js +361 -0
  21. package/dist/sdk/Utils.d.ts +18 -0
  22. package/dist/sdk/Utils.js +126 -0
  23. package/dist/sender/RawSender.d.ts +13 -0
  24. package/dist/sender/RawSender.js +37 -0
  25. package/dist/sender/SenderAbstraction.d.ts +19 -0
  26. package/dist/sender/SenderAbstraction.js +5 -0
  27. package/dist/sender/SenderFactory.d.ts +33 -0
  28. package/dist/sender/SenderFactory.js +51 -0
  29. package/dist/sender/TonConnectSender.d.ts +10 -0
  30. package/dist/sender/TonConnectSender.js +33 -0
  31. package/dist/sender/index.d.ts +2 -0
  32. package/dist/sender/index.js +18 -0
  33. package/dist/structs/InternalStruct.d.ts +52 -0
  34. package/dist/structs/InternalStruct.js +8 -0
  35. package/dist/structs/Struct.d.ts +210 -0
  36. package/dist/structs/Struct.js +15 -0
  37. package/dist/wrappers/ContentUtils.d.ts +25 -0
  38. package/dist/wrappers/ContentUtils.js +160 -0
  39. package/dist/wrappers/HighloadQueryId.d.ts +17 -0
  40. package/dist/wrappers/HighloadQueryId.js +72 -0
  41. package/dist/wrappers/HighloadWalletV3.d.ts +61 -0
  42. package/dist/wrappers/HighloadWalletV3.js +161 -0
  43. package/dist/wrappers/JettonMaster.d.ts +24 -0
  44. package/dist/wrappers/JettonMaster.js +52 -0
  45. package/dist/wrappers/JettonWallet.d.ts +46 -0
  46. package/dist/wrappers/JettonWallet.js +103 -0
  47. package/dist/wrappers/Settings.d.ts +10 -0
  48. package/dist/wrappers/Settings.js +38 -0
  49. package/package.json +66 -0
@@ -0,0 +1,19 @@
1
+ import { ContractOpener, Network } from '../structs/Struct';
2
+ import { Blockchain } from '@ton/sandbox';
3
+ type LiteServer = {
4
+ ip: number;
5
+ port: number;
6
+ id: {
7
+ '@type': string;
8
+ key: string;
9
+ };
10
+ };
11
+ export declare function liteClientOpener(options: {
12
+ liteservers: LiteServer[];
13
+ } | {
14
+ network: Network;
15
+ }): Promise<ContractOpener>;
16
+ export declare function sandboxOpener(blockchain: Blockchain): ContractOpener;
17
+ export declare function orbsOpener(network: Network): Promise<ContractOpener>;
18
+ export declare function orbsOpener4(network: Network, timeout?: number): Promise<ContractOpener>;
19
+ export {};
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.liteClientOpener = liteClientOpener;
4
+ exports.sandboxOpener = sandboxOpener;
5
+ exports.orbsOpener = orbsOpener;
6
+ exports.orbsOpener4 = orbsOpener4;
7
+ const ton_lite_client_1 = require("@tonappchain/ton-lite-client");
8
+ const Struct_1 = require("../structs/Struct");
9
+ const ton_access_1 = require("@orbs-network/ton-access");
10
+ const ton_1 = require("@ton/ton");
11
+ const artifacts_1 = require("@tonappchain/artifacts");
12
+ function intToIP(int) {
13
+ var part1 = int & 255;
14
+ var part2 = (int >> 8) & 255;
15
+ var part3 = (int >> 16) & 255;
16
+ var part4 = (int >> 24) & 255;
17
+ return part4 + '.' + part3 + '.' + part2 + '.' + part1;
18
+ }
19
+ async function getDefaultLiteServers(network) {
20
+ const url = network === Struct_1.Network.Testnet ? artifacts_1.testnet.DEFAULT_LITESERVERS : artifacts_1.mainnet.DEFAULT_LITESERVERS;
21
+ const resp = await fetch(url);
22
+ const liteClients = await resp.json();
23
+ return liteClients.liteservers;
24
+ }
25
+ async function liteClientOpener(options) {
26
+ const liteservers = 'liteservers' in options ? options.liteservers : await getDefaultLiteServers(options.network);
27
+ const engines = [];
28
+ for (const server of liteservers) {
29
+ const engine = await ton_lite_client_1.LiteSingleEngine.create({
30
+ host: `tcp://${intToIP(server.ip)}:${server.port}`,
31
+ publicKey: Buffer.from(server.id.key, 'base64'),
32
+ });
33
+ engines.push(engine);
34
+ }
35
+ const engine = new ton_lite_client_1.LiteRoundRobinEngine(engines);
36
+ const client = new ton_lite_client_1.LiteClient({ engine });
37
+ const closeConnections = () => {
38
+ engine.close();
39
+ };
40
+ return {
41
+ getContractState: async (addr) => {
42
+ const block = await client.getMasterchainInfo();
43
+ const state = await client.getAccountState(addr, block.last);
44
+ const accountState = state.state?.storage?.state;
45
+ const code = accountState?.type === 'active' ? accountState?.state?.code?.toBoc() : null;
46
+ return {
47
+ balance: state.balance.coins,
48
+ state: state.state.storage.state.type === 'uninit' ? 'uninitialized' : state.state.storage.state.type,
49
+ code: code ?? null,
50
+ };
51
+ },
52
+ open: (contract) => client.open(contract),
53
+ closeConnections,
54
+ };
55
+ }
56
+ function sandboxOpener(blockchain) {
57
+ return {
58
+ open: (contract) => blockchain.openContract(contract),
59
+ getContractState: async (address) => {
60
+ const state = await blockchain.provider(address).getState();
61
+ return {
62
+ balance: state.balance,
63
+ code: 'code' in state.state ? (state.state.code ?? null) : null,
64
+ state: state.state.type === 'uninit' ? 'uninitialized' : state.state.type,
65
+ };
66
+ },
67
+ };
68
+ }
69
+ async function orbsOpener(network) {
70
+ const endpoint = await (0, ton_access_1.getHttpEndpoint)({
71
+ network,
72
+ });
73
+ const client = new ton_1.TonClient({ endpoint });
74
+ return client;
75
+ }
76
+ async function orbsOpener4(network, timeout = 10000) {
77
+ const endpoint = await (0, ton_access_1.getHttpV4Endpoint)({ network });
78
+ const client4 = new ton_1.TonClient4({ endpoint, timeout });
79
+ return {
80
+ open: (contract) => client4.open(contract),
81
+ getContractState: async (address) => {
82
+ const latestBlock = await client4.getLastBlock();
83
+ const latestBlockNumber = latestBlock.last.seqno;
84
+ const state = await client4.getAccount(latestBlockNumber, address);
85
+ return {
86
+ balance: BigInt(state.account.balance.coins),
87
+ code: 'code' in state.account.state && state.account.state.code !== null
88
+ ? Buffer.from(state.account.state.code, 'base64')
89
+ : null,
90
+ state: state.account.state.type === 'uninit' ? 'uninitialized' : state.account.state.type,
91
+ };
92
+ },
93
+ };
94
+ }
@@ -0,0 +1,34 @@
1
+ export declare class ErrorWithStatusCode extends Error {
2
+ readonly errorCode: number;
3
+ constructor(message: string, errorCode: number);
4
+ }
5
+ export declare class ContractError extends ErrorWithStatusCode {
6
+ constructor(message: string, errorCode: number);
7
+ }
8
+ export declare class FetchError extends ErrorWithStatusCode {
9
+ constructor(message: string, errorCode: number);
10
+ }
11
+ export declare class AddressError extends ErrorWithStatusCode {
12
+ constructor(message: string, errorCode: number);
13
+ }
14
+ export declare class WalletError extends ErrorWithStatusCode {
15
+ constructor(message: string, errorCode: number);
16
+ }
17
+ export declare class KeyError extends ErrorWithStatusCode {
18
+ constructor(message: string, errorCode: number);
19
+ }
20
+ export declare class FormatError extends ErrorWithStatusCode {
21
+ constructor(message: string, errorCode: number);
22
+ }
23
+ export declare class BitError extends ErrorWithStatusCode {
24
+ constructor(message: string, errorCode: number);
25
+ }
26
+ export declare class MetadataError extends ErrorWithStatusCode {
27
+ constructor(message: string, errorCode: number);
28
+ }
29
+ export declare class SettingError extends ErrorWithStatusCode {
30
+ constructor(message: string, errorCode: number);
31
+ }
32
+ export declare class EVMCallError extends ErrorWithStatusCode {
33
+ constructor(message: string, errorCode: number);
34
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EVMCallError = exports.SettingError = exports.MetadataError = exports.BitError = exports.FormatError = exports.KeyError = exports.WalletError = exports.AddressError = exports.FetchError = exports.ContractError = exports.ErrorWithStatusCode = void 0;
4
+ class ErrorWithStatusCode extends Error {
5
+ constructor(message, errorCode) {
6
+ super(message);
7
+ this.errorCode = errorCode;
8
+ }
9
+ }
10
+ exports.ErrorWithStatusCode = ErrorWithStatusCode;
11
+ class ContractError extends ErrorWithStatusCode {
12
+ constructor(message, errorCode) {
13
+ super(message, errorCode);
14
+ this.name = 'ContractError';
15
+ }
16
+ }
17
+ exports.ContractError = ContractError;
18
+ class FetchError extends ErrorWithStatusCode {
19
+ constructor(message, errorCode) {
20
+ super(message, errorCode);
21
+ this.name = 'FetchError';
22
+ }
23
+ }
24
+ exports.FetchError = FetchError;
25
+ class AddressError extends ErrorWithStatusCode {
26
+ constructor(message, errorCode) {
27
+ super(message, errorCode);
28
+ this.name = 'AddressError';
29
+ }
30
+ }
31
+ exports.AddressError = AddressError;
32
+ class WalletError extends ErrorWithStatusCode {
33
+ constructor(message, errorCode) {
34
+ super(message, errorCode);
35
+ this.name = 'WalletError';
36
+ }
37
+ }
38
+ exports.WalletError = WalletError;
39
+ class KeyError extends ErrorWithStatusCode {
40
+ constructor(message, errorCode) {
41
+ super(message, errorCode);
42
+ this.name = 'KeyError';
43
+ }
44
+ }
45
+ exports.KeyError = KeyError;
46
+ class FormatError extends ErrorWithStatusCode {
47
+ constructor(message, errorCode) {
48
+ super(message, errorCode);
49
+ this.name = 'FormatError';
50
+ }
51
+ }
52
+ exports.FormatError = FormatError;
53
+ class BitError extends ErrorWithStatusCode {
54
+ constructor(message, errorCode) {
55
+ super(message, errorCode);
56
+ this.name = 'BitError';
57
+ }
58
+ }
59
+ exports.BitError = BitError;
60
+ class MetadataError extends ErrorWithStatusCode {
61
+ constructor(message, errorCode) {
62
+ super(message, errorCode);
63
+ this.name = 'MetadataError';
64
+ }
65
+ }
66
+ exports.MetadataError = MetadataError;
67
+ class SettingError extends ErrorWithStatusCode {
68
+ constructor(message, errorCode) {
69
+ super(message, errorCode);
70
+ this.name = 'SettingError';
71
+ }
72
+ }
73
+ exports.SettingError = SettingError;
74
+ class EVMCallError extends ErrorWithStatusCode {
75
+ constructor(message, errorCode) {
76
+ super(message, errorCode);
77
+ this.name = 'EVMCallError';
78
+ }
79
+ }
80
+ exports.EVMCallError = EVMCallError;
@@ -0,0 +1,2 @@
1
+ export { emptyContractError, operationFetchError, statusFetchError, tvmAddressError, evmAddressError, unknownWalletError, unsupportedKeyError, unsupportedFormatError, notMultiplyOf8Error, prefixError, emptySettingError, invalidMethodNameError, simulationError, emptyArrayError, profilingFetchError, } from './instances';
2
+ export { ContractError, FetchError, AddressError, WalletError, KeyError, FormatError, BitError, MetadataError, SettingError, EVMCallError, } from './errors';
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EVMCallError = exports.SettingError = exports.MetadataError = exports.BitError = exports.FormatError = exports.KeyError = exports.WalletError = exports.AddressError = exports.FetchError = exports.ContractError = exports.profilingFetchError = exports.emptyArrayError = exports.simulationError = exports.invalidMethodNameError = exports.emptySettingError = exports.prefixError = exports.notMultiplyOf8Error = exports.unsupportedFormatError = exports.unsupportedKeyError = exports.unknownWalletError = exports.evmAddressError = exports.tvmAddressError = exports.statusFetchError = exports.operationFetchError = exports.emptyContractError = void 0;
4
+ var instances_1 = require("./instances");
5
+ Object.defineProperty(exports, "emptyContractError", { enumerable: true, get: function () { return instances_1.emptyContractError; } });
6
+ Object.defineProperty(exports, "operationFetchError", { enumerable: true, get: function () { return instances_1.operationFetchError; } });
7
+ Object.defineProperty(exports, "statusFetchError", { enumerable: true, get: function () { return instances_1.statusFetchError; } });
8
+ Object.defineProperty(exports, "tvmAddressError", { enumerable: true, get: function () { return instances_1.tvmAddressError; } });
9
+ Object.defineProperty(exports, "evmAddressError", { enumerable: true, get: function () { return instances_1.evmAddressError; } });
10
+ Object.defineProperty(exports, "unknownWalletError", { enumerable: true, get: function () { return instances_1.unknownWalletError; } });
11
+ Object.defineProperty(exports, "unsupportedKeyError", { enumerable: true, get: function () { return instances_1.unsupportedKeyError; } });
12
+ Object.defineProperty(exports, "unsupportedFormatError", { enumerable: true, get: function () { return instances_1.unsupportedFormatError; } });
13
+ Object.defineProperty(exports, "notMultiplyOf8Error", { enumerable: true, get: function () { return instances_1.notMultiplyOf8Error; } });
14
+ Object.defineProperty(exports, "prefixError", { enumerable: true, get: function () { return instances_1.prefixError; } });
15
+ Object.defineProperty(exports, "emptySettingError", { enumerable: true, get: function () { return instances_1.emptySettingError; } });
16
+ Object.defineProperty(exports, "invalidMethodNameError", { enumerable: true, get: function () { return instances_1.invalidMethodNameError; } });
17
+ Object.defineProperty(exports, "simulationError", { enumerable: true, get: function () { return instances_1.simulationError; } });
18
+ Object.defineProperty(exports, "emptyArrayError", { enumerable: true, get: function () { return instances_1.emptyArrayError; } });
19
+ Object.defineProperty(exports, "profilingFetchError", { enumerable: true, get: function () { return instances_1.profilingFetchError; } });
20
+ var errors_1 = require("./errors");
21
+ Object.defineProperty(exports, "ContractError", { enumerable: true, get: function () { return errors_1.ContractError; } });
22
+ Object.defineProperty(exports, "FetchError", { enumerable: true, get: function () { return errors_1.FetchError; } });
23
+ Object.defineProperty(exports, "AddressError", { enumerable: true, get: function () { return errors_1.AddressError; } });
24
+ Object.defineProperty(exports, "WalletError", { enumerable: true, get: function () { return errors_1.WalletError; } });
25
+ Object.defineProperty(exports, "KeyError", { enumerable: true, get: function () { return errors_1.KeyError; } });
26
+ Object.defineProperty(exports, "FormatError", { enumerable: true, get: function () { return errors_1.FormatError; } });
27
+ Object.defineProperty(exports, "BitError", { enumerable: true, get: function () { return errors_1.BitError; } });
28
+ Object.defineProperty(exports, "MetadataError", { enumerable: true, get: function () { return errors_1.MetadataError; } });
29
+ Object.defineProperty(exports, "SettingError", { enumerable: true, get: function () { return errors_1.SettingError; } });
30
+ Object.defineProperty(exports, "EVMCallError", { enumerable: true, get: function () { return errors_1.EVMCallError; } });
@@ -0,0 +1,16 @@
1
+ import { ContractError, FetchError, AddressError, WalletError, KeyError, FormatError, BitError, MetadataError, SettingError, EVMCallError } from './errors';
2
+ export declare const emptyContractError: ContractError;
3
+ export declare const operationFetchError: FetchError;
4
+ export declare const statusFetchError: (msg: string) => FetchError;
5
+ export declare const tvmAddressError: (addr: string) => AddressError;
6
+ export declare const evmAddressError: (addr: string) => AddressError;
7
+ export declare const unknownWalletError: (version: string) => WalletError;
8
+ export declare const unsupportedKeyError: (key: string) => KeyError;
9
+ export declare const unsupportedFormatError: FormatError;
10
+ export declare const notMultiplyOf8Error: BitError;
11
+ export declare const prefixError: MetadataError;
12
+ export declare const emptySettingError: (setting: string) => SettingError;
13
+ export declare const invalidMethodNameError: (methodName: string) => EVMCallError;
14
+ export declare const simulationError: FetchError;
15
+ export declare const profilingFetchError: (msg: string) => FetchError;
16
+ export declare const emptyArrayError: (msg: string) => FetchError;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emptyArrayError = exports.profilingFetchError = exports.simulationError = exports.invalidMethodNameError = exports.emptySettingError = exports.prefixError = exports.notMultiplyOf8Error = exports.unsupportedFormatError = exports.unsupportedKeyError = exports.unknownWalletError = exports.evmAddressError = exports.tvmAddressError = exports.statusFetchError = exports.operationFetchError = exports.emptyContractError = void 0;
4
+ const errors_1 = require("./errors");
5
+ exports.emptyContractError = new errors_1.ContractError('unexpected empty contract code of given jetton.', 100);
6
+ exports.operationFetchError = new errors_1.FetchError('failed to fetch OperationId', 101);
7
+ const statusFetchError = (msg) => new errors_1.FetchError(`failed to fetch status transaction: ${msg}`, 102);
8
+ exports.statusFetchError = statusFetchError;
9
+ const tvmAddressError = (addr) => new errors_1.AddressError(`invalid tvm address ${addr}`, 103);
10
+ exports.tvmAddressError = tvmAddressError;
11
+ const evmAddressError = (addr) => new errors_1.AddressError(`invalid evm address ${addr}`, 104);
12
+ exports.evmAddressError = evmAddressError;
13
+ const unknownWalletError = (version) => new errors_1.WalletError(`Unknown wallet version ${version}`, 105);
14
+ exports.unknownWalletError = unknownWalletError;
15
+ const unsupportedKeyError = (key) => new errors_1.KeyError(`Unsupported onchain key: ${key}`, 106);
16
+ exports.unsupportedKeyError = unsupportedKeyError;
17
+ exports.unsupportedFormatError = new errors_1.FormatError('Only snake format is supported', 107);
18
+ exports.notMultiplyOf8Error = new errors_1.BitError('Number remaining of bits is not multiply of 8', 108);
19
+ exports.prefixError = new errors_1.MetadataError('Unexpected wrappers metadata content prefix', 109);
20
+ const emptySettingError = (setting) => new errors_1.SettingError(`unexpected empty ${setting}. Make sure the settings contract is valid.`, 110);
21
+ exports.emptySettingError = emptySettingError;
22
+ const invalidMethodNameError = (methodName) => new errors_1.EVMCallError(`Invalid Solidity method name: "${methodName}". Method must be either a valid identifier or have parameters (bytes,bytes).`, 111);
23
+ exports.invalidMethodNameError = invalidMethodNameError;
24
+ exports.simulationError = new errors_1.FetchError('Failed to simulate EVM call', 112);
25
+ const profilingFetchError = (msg) => new errors_1.FetchError(`failed to fetch stage profiling: ${msg}`, 113);
26
+ exports.profilingFetchError = profilingFetchError;
27
+ const emptyArrayError = (msg) => new errors_1.FetchError(`empty array: ${msg}`, 114);
28
+ exports.emptyArrayError = emptyArrayError;
@@ -0,0 +1,10 @@
1
+ export { TacSdk } from './sdk/TacSdk';
2
+ export { OperationTracker } from './sdk/OperationTracker';
3
+ export { startTracking } from './sdk/StartTracking';
4
+ export * from './sender';
5
+ export * from './structs/Struct';
6
+ export { Network, SimplifiedStatuses } from './structs/Struct';
7
+ export type { JettonWalletData } from './wrappers/JettonWallet';
8
+ export { JettonWallet, JettonWalletOpCodes } from './wrappers/JettonWallet';
9
+ export { orbsOpener, liteClientOpener } from './adapters/contractOpener';
10
+ export * from './errors';
package/dist/index.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.liteClientOpener = exports.orbsOpener = exports.JettonWalletOpCodes = exports.JettonWallet = exports.SimplifiedStatuses = exports.Network = exports.startTracking = exports.OperationTracker = exports.TacSdk = void 0;
18
+ var TacSdk_1 = require("./sdk/TacSdk");
19
+ Object.defineProperty(exports, "TacSdk", { enumerable: true, get: function () { return TacSdk_1.TacSdk; } });
20
+ var OperationTracker_1 = require("./sdk/OperationTracker");
21
+ Object.defineProperty(exports, "OperationTracker", { enumerable: true, get: function () { return OperationTracker_1.OperationTracker; } });
22
+ var StartTracking_1 = require("./sdk/StartTracking");
23
+ Object.defineProperty(exports, "startTracking", { enumerable: true, get: function () { return StartTracking_1.startTracking; } });
24
+ __exportStar(require("./sender"), exports);
25
+ __exportStar(require("./structs/Struct"), exports);
26
+ var Struct_1 = require("./structs/Struct");
27
+ Object.defineProperty(exports, "Network", { enumerable: true, get: function () { return Struct_1.Network; } });
28
+ Object.defineProperty(exports, "SimplifiedStatuses", { enumerable: true, get: function () { return Struct_1.SimplifiedStatuses; } });
29
+ var JettonWallet_1 = require("./wrappers/JettonWallet");
30
+ Object.defineProperty(exports, "JettonWallet", { enumerable: true, get: function () { return JettonWallet_1.JettonWallet; } });
31
+ Object.defineProperty(exports, "JettonWalletOpCodes", { enumerable: true, get: function () { return JettonWallet_1.JettonWalletOpCodes; } });
32
+ var contractOpener_1 = require("./adapters/contractOpener");
33
+ Object.defineProperty(exports, "orbsOpener", { enumerable: true, get: function () { return contractOpener_1.orbsOpener; } });
34
+ Object.defineProperty(exports, "liteClientOpener", { enumerable: true, get: function () { return contractOpener_1.liteClientOpener; } });
35
+ __exportStar(require("./errors"), exports);
@@ -0,0 +1,6 @@
1
+ export declare const TRANSACTION_TON_AMOUNT: bigint;
2
+ export declare const JETTON_TRANSFER_FORWARD_TON_AMOUNT: bigint;
3
+ export declare const MAX_ITERATION_COUNT = 120;
4
+ export declare const DEFAULT_DELAY = 0;
5
+ export declare const SOLIDITY_SIGNATURE_REGEX: RegExp;
6
+ export declare const SOLIDITY_METHOD_NAME_REGEX: RegExp;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SOLIDITY_METHOD_NAME_REGEX = exports.SOLIDITY_SIGNATURE_REGEX = exports.DEFAULT_DELAY = exports.MAX_ITERATION_COUNT = exports.JETTON_TRANSFER_FORWARD_TON_AMOUNT = exports.TRANSACTION_TON_AMOUNT = void 0;
4
+ const ton_1 = require("@ton/ton");
5
+ exports.TRANSACTION_TON_AMOUNT = (0, ton_1.toNano)(0.35);
6
+ exports.JETTON_TRANSFER_FORWARD_TON_AMOUNT = (0, ton_1.toNano)(0.2);
7
+ exports.MAX_ITERATION_COUNT = 120;
8
+ exports.DEFAULT_DELAY = 0;
9
+ exports.SOLIDITY_SIGNATURE_REGEX = /^[a-zA-Z_][a-zA-Z0-9_]*(\((bytes,bytes)\))?$/;
10
+ exports.SOLIDITY_METHOD_NAME_REGEX = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
@@ -0,0 +1,15 @@
1
+ import { Network, TransactionLinker, SimplifiedStatuses, StatusInfosByOperationId, StatusInfo, OperationIdsByShardsKey, ExecutionStages, ExecutionStagesByOperationId } from '../structs/Struct';
2
+ export declare class OperationTracker {
3
+ readonly TERMINATED_STATUS = "TVMMerkleMessageExecuted";
4
+ readonly BRIDGE_TERMINATED_STATUS = "EVMMerkleMessageExecuted";
5
+ readonly network: Network;
6
+ readonly customLiteSequencerEndpoints: string[];
7
+ constructor(network: Network, customLiteSequencerEndpoints?: string[]);
8
+ getOperationId(transactionLinker: TransactionLinker): Promise<string>;
9
+ getOperationIdsByShardsKeys(shardsKeys: string[], caller: string): Promise<OperationIdsByShardsKey>;
10
+ getStageProfiling(operationId: string): Promise<ExecutionStages>;
11
+ getStageProfilings(operationIds: string[]): Promise<ExecutionStagesByOperationId>;
12
+ getOperationStatuses(operationIds: string[]): Promise<StatusInfosByOperationId>;
13
+ getOperationStatus(operationId: string): Promise<StatusInfo>;
14
+ getSimplifiedOperationStatus(transactionLinker: TransactionLinker, isBridgeOperation?: boolean): Promise<SimplifiedStatuses>;
15
+ }
@@ -0,0 +1,128 @@
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.OperationTracker = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const Struct_1 = require("../structs/Struct");
9
+ const errors_1 = require("../errors");
10
+ const Utils_1 = require("./Utils");
11
+ const artifacts_1 = require("@tonappchain/artifacts");
12
+ class OperationTracker {
13
+ constructor(network, customLiteSequencerEndpoints) {
14
+ this.TERMINATED_STATUS = 'TVMMerkleMessageExecuted';
15
+ this.BRIDGE_TERMINATED_STATUS = 'EVMMerkleMessageExecuted';
16
+ this.network = network;
17
+ this.customLiteSequencerEndpoints =
18
+ customLiteSequencerEndpoints ??
19
+ (this.network === Struct_1.Network.Testnet
20
+ ? artifacts_1.testnet.PUBLIC_LITE_SEQUENCER_ENDPOINTS
21
+ : artifacts_1.mainnet.PUBLIC_LITE_SEQUENCER_ENDPOINTS);
22
+ }
23
+ async getOperationId(transactionLinker) {
24
+ for (const endpoint of this.customLiteSequencerEndpoints) {
25
+ try {
26
+ const response = await axios_1.default.get(`${endpoint}/operation-id`, {
27
+ params: {
28
+ shardsKey: transactionLinker.shardsKey,
29
+ caller: transactionLinker.caller,
30
+ shardCount: transactionLinker.shardCount,
31
+ timestamp: transactionLinker.timestamp,
32
+ },
33
+ });
34
+ return response.data.response || '';
35
+ }
36
+ catch (error) {
37
+ console.error(`Failed to get OperationId with ${endpoint}:`, error);
38
+ }
39
+ }
40
+ throw errors_1.operationFetchError;
41
+ }
42
+ async getOperationIdsByShardsKeys(shardsKeys, caller) {
43
+ const requestBody = {
44
+ shardsKeys: shardsKeys,
45
+ caller: caller,
46
+ };
47
+ for (const endpoint of this.customLiteSequencerEndpoints) {
48
+ try {
49
+ const response = await axios_1.default.post(`${endpoint}/operation-ids-by-shards-keys`, requestBody);
50
+ return response.data.response;
51
+ }
52
+ catch (error) {
53
+ console.error(`Failed to get OperationIds with ${endpoint}:`, error);
54
+ }
55
+ }
56
+ throw errors_1.operationFetchError;
57
+ }
58
+ async getStageProfiling(operationId) {
59
+ const map = await this.getStageProfilings([operationId]);
60
+ const result = map[operationId];
61
+ if (!result) {
62
+ throw new Error(`No stageProfiling data for operationId=${operationId}`);
63
+ }
64
+ return result;
65
+ }
66
+ async getStageProfilings(operationIds) {
67
+ if (!operationIds || operationIds.length === 0) {
68
+ throw (0, errors_1.emptyArrayError)('operationIds');
69
+ }
70
+ for (const endpoint of this.customLiteSequencerEndpoints) {
71
+ try {
72
+ const response = await axios_1.default.post(`${endpoint}/stage-profiling`, {
73
+ operationIds,
74
+ }, {
75
+ transformResponse: [Utils_1.toCamelCaseTransformer],
76
+ });
77
+ return response.data.response;
78
+ }
79
+ catch (error) {
80
+ console.error(`Error fetching status transaction with ${endpoint}:`, error);
81
+ }
82
+ }
83
+ throw (0, errors_1.profilingFetchError)('all endpoints failed to complete request');
84
+ }
85
+ async getOperationStatuses(operationIds) {
86
+ if (!operationIds || operationIds.length === 0) {
87
+ throw (0, errors_1.emptyArrayError)('operationIds');
88
+ }
89
+ for (const endpoint of this.customLiteSequencerEndpoints) {
90
+ try {
91
+ const response = await axios_1.default.post(`${endpoint}/status`, {
92
+ operationIds,
93
+ }, {
94
+ transformResponse: [Utils_1.toCamelCaseTransformer],
95
+ });
96
+ return response.data.response;
97
+ }
98
+ catch (error) {
99
+ console.error(`Error fetching status transaction with ${endpoint}:`, error);
100
+ }
101
+ }
102
+ throw (0, errors_1.statusFetchError)('all endpoints failed to complete request');
103
+ }
104
+ async getOperationStatus(operationId) {
105
+ const result = await this.getOperationStatuses([operationId]);
106
+ const currentStatus = result[operationId];
107
+ if (!currentStatus) {
108
+ throw (0, errors_1.statusFetchError)('operation is not found in response');
109
+ }
110
+ return currentStatus;
111
+ }
112
+ async getSimplifiedOperationStatus(transactionLinker, isBridgeOperation = false) {
113
+ const operationId = await this.getOperationId(transactionLinker);
114
+ if (operationId == '') {
115
+ return Struct_1.SimplifiedStatuses.OperationIdNotFound;
116
+ }
117
+ const status = await this.getOperationStatus(operationId);
118
+ if (!status.success) {
119
+ return Struct_1.SimplifiedStatuses.Failed;
120
+ }
121
+ const finalStatus = isBridgeOperation ? this.BRIDGE_TERMINATED_STATUS : this.TERMINATED_STATUS;
122
+ if (status.stage == finalStatus) {
123
+ return Struct_1.SimplifiedStatuses.Successful;
124
+ }
125
+ return Struct_1.SimplifiedStatuses.Pending;
126
+ }
127
+ }
128
+ exports.OperationTracker = OperationTracker;
@@ -0,0 +1,2 @@
1
+ import { Network, TransactionLinker } from '../structs/Struct';
2
+ export declare function startTracking(transactionLinker: TransactionLinker, network: Network, isBridgeOperation?: boolean, customLiteSequencerEndpoints?: string[]): Promise<void>;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startTracking = startTracking;
4
+ const Consts_1 = require("./Consts");
5
+ const OperationTracker_1 = require("./OperationTracker");
6
+ const Utils_1 = require("./Utils");
7
+ async function startTracking(transactionLinker, network, isBridgeOperation = false, customLiteSequencerEndpoints) {
8
+ const tracker = new OperationTracker_1.OperationTracker(network, customLiteSequencerEndpoints);
9
+ console.log('Start tracking operation');
10
+ console.log('caller: ', transactionLinker.caller);
11
+ console.log('shardsKey: ', transactionLinker.shardsKey);
12
+ console.log('shardCount: ', transactionLinker.shardCount);
13
+ console.log('timestamp: ', transactionLinker.timestamp);
14
+ let operationId = '';
15
+ let currentStatus = '';
16
+ let iteration = 0; // number of iterations
17
+ let ok = true; // finished successfully
18
+ let errorMessage;
19
+ while (true) {
20
+ ++iteration;
21
+ if (iteration >= Consts_1.MAX_ITERATION_COUNT) {
22
+ ok = false;
23
+ errorMessage = 'maximum number of iterations has been exceeded';
24
+ break;
25
+ }
26
+ console.log();
27
+ const finalStatus = isBridgeOperation ? tracker.BRIDGE_TERMINATED_STATUS : tracker.TERMINATED_STATUS;
28
+ if (currentStatus == finalStatus) {
29
+ break;
30
+ }
31
+ if (operationId == '') {
32
+ console.log('request operationId');
33
+ try {
34
+ operationId = await tracker.getOperationId(transactionLinker);
35
+ }
36
+ catch {
37
+ console.log('get operationId error');
38
+ }
39
+ }
40
+ else {
41
+ console.log('request operationStatus');
42
+ try {
43
+ const status = await tracker.getOperationStatuses([operationId]);
44
+ currentStatus = status[operationId].stage;
45
+ if (!status[operationId].success) {
46
+ if (status[operationId].transactions != null && status[operationId].transactions.length > 0) {
47
+ console.log('transactionHash: ', status[operationId].transactions[0]);
48
+ }
49
+ console.log(status[operationId]);
50
+ ok = false;
51
+ errorMessage = status[operationId].note != null ? status[operationId].note.errorName : '';
52
+ break;
53
+ }
54
+ }
55
+ catch (err) {
56
+ console.log('get status error:', err);
57
+ }
58
+ console.log('operationId:', operationId);
59
+ console.log('status: ', currentStatus);
60
+ console.log('time: ', Math.floor(+new Date() / 1000));
61
+ }
62
+ await (0, Utils_1.sleep)(10 * 1000);
63
+ }
64
+ if (!ok) {
65
+ console.log(`Finished with error: ${errorMessage}`);
66
+ }
67
+ else {
68
+ console.log('Tracking successfully finished');
69
+ }
70
+ const stages = await tracker.getStageProfiling(operationId);
71
+ formatExecutionStages(stages);
72
+ }
73
+ const formatExecutionStages = (stages) => {
74
+ const tableData = Object.entries(stages).map(([stage, data]) => ({
75
+ Stage: stage,
76
+ Exists: data.exists ? 'Yes' : 'No',
77
+ Success: data.exists && data.stageData ? (data.stageData.success ? 'Yes' : 'No') : '-',
78
+ Timestamp: data.exists && data.stageData ? new Date(data.stageData.timestamp * 1000).toLocaleString() : '-',
79
+ Transactions: data.exists &&
80
+ data.stageData &&
81
+ data.stageData.transactions != null &&
82
+ data.stageData.transactions.length > 0
83
+ ? data.stageData.transactions.map((t) => t.hash).join(', ')
84
+ : '-',
85
+ 'Note Content': data.exists && data.stageData && data.stageData.note != null ? data.stageData.note.content : '-',
86
+ 'Error Name': data.exists && data.stageData && data.stageData.note != null ? data.stageData.note.errorName : '-',
87
+ 'Internal Msg': data.exists && data.stageData && data.stageData.note != null ? data.stageData.note.internalMsg : '-',
88
+ 'Bytes Error': data.exists && data.stageData && data.stageData.note != null ? data.stageData.note.internalBytesError : '-',
89
+ }));
90
+ console.table(tableData);
91
+ };