@tonappchain/sdk 0.6.5-mainnet-alpha → 0.7.0-rc6

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 (66) hide show
  1. package/dist/adapters/contractOpener.d.ts +1 -1
  2. package/dist/adapters/contractOpener.js +7 -8
  3. package/dist/adapters/retryableContractOpener.d.ts +21 -0
  4. package/dist/adapters/retryableContractOpener.js +101 -0
  5. package/dist/assets/AssetFactory.d.ts +13 -0
  6. package/dist/assets/AssetFactory.js +73 -0
  7. package/dist/assets/FT.d.ts +58 -0
  8. package/dist/assets/FT.js +199 -0
  9. package/dist/assets/NFT.d.ts +60 -0
  10. package/dist/assets/NFT.js +170 -0
  11. package/dist/assets/TON.d.ts +38 -0
  12. package/dist/assets/TON.js +91 -0
  13. package/dist/assets/index.d.ts +4 -0
  14. package/dist/assets/index.js +11 -0
  15. package/dist/errors/errors.d.ts +6 -0
  16. package/dist/errors/errors.js +15 -1
  17. package/dist/errors/index.d.ts +2 -2
  18. package/dist/errors/index.js +26 -21
  19. package/dist/errors/instances.d.ts +9 -4
  20. package/dist/errors/instances.js +19 -5
  21. package/dist/index.d.ts +12 -6
  22. package/dist/index.js +24 -13
  23. package/dist/sdk/Configuration.d.ts +21 -0
  24. package/dist/sdk/Configuration.js +90 -0
  25. package/dist/sdk/LiteSequencerClient.d.ts +1 -1
  26. package/dist/sdk/LiteSequencerClient.js +5 -11
  27. package/dist/sdk/Logger.d.ts +13 -0
  28. package/dist/sdk/Logger.js +25 -0
  29. package/dist/sdk/OperationTracker.d.ts +21 -6
  30. package/dist/sdk/OperationTracker.js +155 -75
  31. package/dist/sdk/Simulator.d.ts +23 -0
  32. package/dist/sdk/Simulator.js +169 -0
  33. package/dist/sdk/StartTracking.d.ts +6 -0
  34. package/dist/sdk/StartTracking.js +66 -29
  35. package/dist/sdk/TacSdk.d.ts +12 -41
  36. package/dist/sdk/TacSdk.js +69 -712
  37. package/dist/sdk/TransactionManager.d.ts +22 -0
  38. package/dist/sdk/TransactionManager.js +257 -0
  39. package/dist/sdk/TxFinalizer.d.ts +10 -0
  40. package/dist/sdk/TxFinalizer.js +104 -0
  41. package/dist/sdk/Utils.d.ts +12 -4
  42. package/dist/sdk/Utils.js +80 -16
  43. package/dist/sdk/Validator.d.ts +9 -0
  44. package/dist/sdk/Validator.js +43 -0
  45. package/dist/sender/BatchSender.d.ts +7 -4
  46. package/dist/sender/BatchSender.js +18 -6
  47. package/dist/sender/RawSender.d.ts +9 -4
  48. package/dist/sender/RawSender.js +46 -18
  49. package/dist/sender/SenderAbstraction.d.ts +5 -3
  50. package/dist/sender/SenderFactory.d.ts +1 -1
  51. package/dist/sender/SenderFactory.js +5 -4
  52. package/dist/sender/TonConnectSender.d.ts +5 -3
  53. package/dist/sender/TonConnectSender.js +12 -8
  54. package/dist/sender/index.d.ts +1 -1
  55. package/dist/sender/index.js +1 -1
  56. package/dist/structs/InternalStruct.d.ts +36 -33
  57. package/dist/structs/Services.d.ts +40 -0
  58. package/dist/structs/Services.js +2 -0
  59. package/dist/structs/Struct.d.ts +98 -79
  60. package/dist/structs/Struct.js +11 -1
  61. package/dist/wrappers/HighloadQueryId.js +0 -1
  62. package/dist/wrappers/HighloadWalletV3.d.ts +3 -2
  63. package/dist/wrappers/HighloadWalletV3.js +5 -2
  64. package/dist/wrappers/JettonWallet.d.ts +11 -2
  65. package/dist/wrappers/JettonWallet.js +33 -16
  66. package/package.json +2 -2
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Configuration = void 0;
4
+ const ton_1 = require("@ton/ton");
5
+ const artifacts_1 = require("@tonappchain/artifacts");
6
+ const ethers_1 = require("ethers");
7
+ const retryableContractOpener_1 = require("../adapters/retryableContractOpener");
8
+ const Struct_1 = require("../structs/Struct");
9
+ const Settings_1 = require("../wrappers/Settings");
10
+ const Validator_1 = require("./Validator");
11
+ class Configuration {
12
+ constructor(network, artifacts, TONParams, TACParams, liteSequencerEndpoints) {
13
+ this.network = network;
14
+ this.artifacts = artifacts;
15
+ this.TONParams = TONParams;
16
+ this.TACParams = TACParams;
17
+ this.liteSequencerEndpoints = liteSequencerEndpoints;
18
+ }
19
+ static async create(network, artifacts, TONParams, TACParams, customLiteSequencerEndpoints, delay) {
20
+ const internalTONParams = await this.prepareTONParams(artifacts, TONParams, delay);
21
+ const internalTACParams = await this.prepareTACParams(artifacts, TACParams);
22
+ const liteSequencerEndpoints = customLiteSequencerEndpoints ??
23
+ (network === Struct_1.Network.TESTNET
24
+ ? artifacts_1.testnet.PUBLIC_LITE_SEQUENCER_ENDPOINTS
25
+ : artifacts_1.mainnet.PUBLIC_LITE_SEQUENCER_ENDPOINTS);
26
+ return new Configuration(network, artifacts, internalTONParams, internalTACParams, liteSequencerEndpoints);
27
+ }
28
+ static async prepareTONParams(artifacts, TONParams, delay) {
29
+ const contractOpener = TONParams?.contractOpener ?? (await (0, retryableContractOpener_1.createDefaultRetryableOpener)(artifacts, 3, delay));
30
+ const settingsAddress = TONParams?.settingsAddress ?? artifacts.TON_SETTINGS_ADDRESS;
31
+ const settings = contractOpener.open(new Settings_1.Settings(ton_1.Address.parse(settingsAddress)));
32
+ const jettonProxyAddress = await settings.getAddressSetting('JettonProxyAddress');
33
+ const crossChainLayerAddress = await settings.getAddressSetting('CrossChainLayerAddress');
34
+ const jettonMinterCode = await settings.getCellSetting('JettonMinterCode');
35
+ const jettonWalletCode = await settings.getCellSetting('JettonWalletCode');
36
+ const nftProxyAddress = await settings.getAddressSetting('NFTProxyAddress');
37
+ const nftItemCode = await settings.getCellSetting('NFTItemCode');
38
+ const nftCollectionCode = await settings.getCellSetting('NFTCollectionCode');
39
+ return {
40
+ contractOpener,
41
+ jettonProxyAddress,
42
+ crossChainLayerAddress,
43
+ jettonMinterCode,
44
+ jettonWalletCode,
45
+ nftProxyAddress,
46
+ nftItemCode,
47
+ nftCollectionCode,
48
+ };
49
+ }
50
+ static async prepareTACParams(artifacts, TACParams) {
51
+ const provider = TACParams?.provider ?? ethers_1.ethers.getDefaultProvider(artifacts.TAC_RPC_ENDPOINT);
52
+ const settingsAddress = TACParams?.settingsAddress?.toString() ?? artifacts.TAC_SETTINGS_ADDRESS;
53
+ Validator_1.Validator.validateEVMAddress(settingsAddress);
54
+ const settings = artifacts.tac.wrappers.SettingsFactoryTAC.connect(settingsAddress, provider);
55
+ const crossChainLayerAddress = await settings.getAddressSetting((0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)('CrossChainLayerAddress')));
56
+ const crossChainLayer = artifacts.tac.wrappers.CrossChainLayerFactoryTAC.connect(crossChainLayerAddress, provider);
57
+ const tokenUtilsAddress = await settings.getAddressSetting((0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)('TokenUtilsAddress')));
58
+ const tokenUtils = artifacts.tac.wrappers.TokenUtilsFactoryTAC.connect(tokenUtilsAddress, provider);
59
+ const trustedTACExecutors = await settings.getTrustedEVMExecutors();
60
+ const trustedTONExecutors = await settings.getTrustedTVMExecutors();
61
+ return {
62
+ provider,
63
+ settings,
64
+ tokenUtils,
65
+ crossChainLayer,
66
+ trustedTACExecutors,
67
+ trustedTONExecutors,
68
+ abiCoder: new ethers_1.ethers.AbiCoder(),
69
+ };
70
+ }
71
+ get nativeTONAddress() {
72
+ return 'NONE';
73
+ }
74
+ async nativeTACAddress() {
75
+ return this.TACParams.crossChainLayer.NATIVE_TOKEN_ADDRESS.staticCall();
76
+ }
77
+ get getTrustedTACExecutors() {
78
+ return this.TACParams.trustedTACExecutors;
79
+ }
80
+ get getTrustedTONExecutors() {
81
+ return this.TACParams.trustedTONExecutors;
82
+ }
83
+ closeConnections() {
84
+ return this.TONParams.contractOpener.closeConnections?.();
85
+ }
86
+ async isContractDeployedOnTVM(address) {
87
+ return (await this.TONParams.contractOpener.getContractState(ton_1.Address.parse(address))).state === 'active';
88
+ }
89
+ }
90
+ exports.Configuration = Configuration;
@@ -1,4 +1,4 @@
1
- import { TransactionLinker, StatusInfosByOperationId, OperationIdsByShardsKey, ExecutionStagesByOperationId, OperationType } from '../structs/Struct';
1
+ import { ExecutionStagesByOperationId, OperationIdsByShardsKey, OperationType, StatusInfosByOperationId, TransactionLinker } from '../structs/Struct';
2
2
  export declare class LiteSequencerClient {
3
3
  private readonly endpoint;
4
4
  private readonly maxChunkSize;
@@ -22,8 +22,7 @@ class LiteSequencerClient {
22
22
  return response.data.response || '';
23
23
  }
24
24
  catch (error) {
25
- console.error(`Failed to get operationType with ${this.endpoint}:`, error);
26
- throw errors_1.operationFetchError;
25
+ throw (0, errors_1.operationFetchError)(`endpoint ${this.endpoint} failed to complete request`, error);
27
26
  }
28
27
  }
29
28
  async getOperationId(transactionLinker) {
@@ -40,12 +39,10 @@ class LiteSequencerClient {
40
39
  catch (error) {
41
40
  if (axios_1.default.isAxiosError(error)) {
42
41
  if (error.response?.status === 404) {
43
- console.warn(`404 Not Found: ${new URL('ton/operation-id', this.endpoint).toString()}`);
44
42
  return '';
45
43
  }
46
44
  }
47
- console.error(`Failed to get OperationId with ${this.endpoint}:`, error);
48
- throw errors_1.operationFetchError;
45
+ throw (0, errors_1.operationFetchError)(`endpoint ${this.endpoint} failed to complete request`, error);
49
46
  }
50
47
  }
51
48
  async getOperationIdsByShardsKeys(shardsKeys, caller, chunkSize = this.maxChunkSize) {
@@ -63,8 +60,7 @@ class LiteSequencerClient {
63
60
  return response.response;
64
61
  }
65
62
  catch (error) {
66
- console.error(`Failed to get OperationIds with ${this.endpoint}:`, error);
67
- throw errors_1.operationFetchError;
63
+ throw (0, errors_1.operationFetchError)(`endpoint ${this.endpoint} failed to complete request`, error);
68
64
  }
69
65
  }
70
66
  async getStageProfilings(operationIds, chunkSize = this.maxChunkSize) {
@@ -83,8 +79,7 @@ class LiteSequencerClient {
83
79
  return response.response;
84
80
  }
85
81
  catch (error) {
86
- console.error(`Error fetching stage profiling with ${this.endpoint}:`, error);
87
- throw (0, errors_1.profilingFetchError)('endpoint failed to complete request');
82
+ throw (0, errors_1.profilingFetchError)(`endpoint ${this.endpoint} failed to complete request`, error);
88
83
  }
89
84
  }
90
85
  async getOperationStatuses(operationIds, chunkSize = this.maxChunkSize) {
@@ -103,8 +98,7 @@ class LiteSequencerClient {
103
98
  return response.response;
104
99
  }
105
100
  catch (error) {
106
- console.error(`Error fetching status transaction with ${this.endpoint}:`, error);
107
- throw (0, errors_1.statusFetchError)('endpoint failed to complete request');
101
+ throw (0, errors_1.statusFetchError)(`endpoint ${this.endpoint} failed to complete request`, error);
108
102
  }
109
103
  }
110
104
  async processChunkedRequest(identificators, requestFn, chunkSize = this.maxChunkSize) {
@@ -0,0 +1,13 @@
1
+ import { ILogger } from '../structs/Services';
2
+ export declare class ConsoleLogger implements ILogger {
3
+ debug(...arg: unknown[]): void;
4
+ info(...arg: unknown[]): void;
5
+ warn(...arg: unknown[]): void;
6
+ error(...arg: unknown[]): void;
7
+ }
8
+ export declare class NoopLogger implements ILogger {
9
+ debug(): void;
10
+ info(): void;
11
+ warn(): void;
12
+ error(): void;
13
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoopLogger = exports.ConsoleLogger = void 0;
4
+ class ConsoleLogger {
5
+ debug(...arg) {
6
+ console.debug(`[DEBUG]`, ...arg);
7
+ }
8
+ info(...arg) {
9
+ console.info(`[INFO]`, ...arg);
10
+ }
11
+ warn(...arg) {
12
+ console.warn(`[WARN]`, ...arg);
13
+ }
14
+ error(...arg) {
15
+ console.error(`[ERROR]`, ...arg);
16
+ }
17
+ }
18
+ exports.ConsoleLogger = ConsoleLogger;
19
+ class NoopLogger {
20
+ debug() { }
21
+ info() { }
22
+ warn() { }
23
+ error() { }
24
+ }
25
+ exports.NoopLogger = NoopLogger;
@@ -1,13 +1,28 @@
1
- import { Network, TransactionLinker, SimplifiedStatuses, OperationType, OperationIdsByShardsKey, ExecutionStages, ExecutionStagesByOperationId, StatusInfosByOperationId, StatusInfo } from '../structs/Struct';
2
- export declare class OperationTracker {
3
- private readonly clients;
4
- constructor(network: Network, customLiteSequencerEndpoints?: string[]);
1
+ import { ILogger, IOperationTracker } from '../structs/Services';
2
+ import { ExecutionStages, ExecutionStagesByOperationId, Network, OperationIdsByShardsKey, OperationType, SimplifiedStatuses, StatusInfo, StatusInfosByOperationId, TransactionLinker, WaitOptions } from '../structs/Struct';
3
+ export interface ILiteSequencerClientFactory {
4
+ createClients(endpoints: string[]): ILiteSequencerClient[];
5
+ }
6
+ export interface ILiteSequencerClient {
5
7
  getOperationType(operationId: string): Promise<OperationType>;
6
8
  getOperationId(transactionLinker: TransactionLinker): Promise<string>;
7
9
  getOperationIdsByShardsKeys(shardsKeys: string[], caller: string, chunkSize?: number): Promise<OperationIdsByShardsKey>;
8
- getStageProfiling(operationId: string): Promise<ExecutionStages>;
9
10
  getStageProfilings(operationIds: string[], chunkSize?: number): Promise<ExecutionStagesByOperationId>;
10
11
  getOperationStatuses(operationIds: string[], chunkSize?: number): Promise<StatusInfosByOperationId>;
11
- getOperationStatus(operationId: string): Promise<StatusInfo>;
12
+ }
13
+ export declare class DefaultLiteSequencerClientFactory implements ILiteSequencerClientFactory {
14
+ createClients(endpoints: string[]): ILiteSequencerClient[];
15
+ }
16
+ export declare class OperationTracker implements IOperationTracker {
17
+ private readonly clients;
18
+ private readonly logger;
19
+ constructor(network: Network, customLiteSequencerEndpoints?: string[], logger?: ILogger, clientFactory?: ILiteSequencerClientFactory);
20
+ getOperationType(operationId: string, waitOptions?: WaitOptions<OperationType>): Promise<OperationType>;
21
+ getOperationId(transactionLinker: TransactionLinker, waitOptions?: WaitOptions<string>): Promise<string>;
22
+ getOperationIdsByShardsKeys(shardsKeys: string[], caller: string, waitOptions?: WaitOptions<OperationIdsByShardsKey>, chunkSize?: number): Promise<OperationIdsByShardsKey>;
23
+ getStageProfiling(operationId: string, waitOptions?: WaitOptions<ExecutionStages>): Promise<ExecutionStages>;
24
+ getStageProfilings(operationIds: string[], waitOptions?: WaitOptions<ExecutionStagesByOperationId>, chunkSize?: number): Promise<ExecutionStagesByOperationId>;
25
+ getOperationStatuses(operationIds: string[], waitOptions?: WaitOptions<StatusInfosByOperationId>, chunkSize?: number): Promise<StatusInfosByOperationId>;
26
+ getOperationStatus(operationId: string, waitOptions?: WaitOptions<StatusInfo>): Promise<StatusInfo>;
12
27
  getSimplifiedOperationStatus(transactionLinker: TransactionLinker): Promise<SimplifiedStatuses>;
13
28
  }
@@ -1,110 +1,190 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OperationTracker = void 0;
4
- const Struct_1 = require("../structs/Struct");
3
+ exports.OperationTracker = exports.DefaultLiteSequencerClientFactory = void 0;
5
4
  const artifacts_1 = require("@tonappchain/artifacts");
5
+ const errors_1 = require("../errors");
6
+ const Struct_1 = require("../structs/Struct");
6
7
  const LiteSequencerClient_1 = require("./LiteSequencerClient");
8
+ const Logger_1 = require("./Logger");
9
+ const Utils_1 = require("./Utils");
10
+ class DefaultLiteSequencerClientFactory {
11
+ createClients(endpoints) {
12
+ return endpoints.map(endpoint => new LiteSequencerClient_1.LiteSequencerClient(endpoint));
13
+ }
14
+ }
15
+ exports.DefaultLiteSequencerClientFactory = DefaultLiteSequencerClientFactory;
7
16
  class OperationTracker {
8
- constructor(network, customLiteSequencerEndpoints) {
17
+ constructor(network, customLiteSequencerEndpoints, logger = new Logger_1.NoopLogger(), clientFactory = new DefaultLiteSequencerClientFactory()) {
9
18
  const endpoints = customLiteSequencerEndpoints ??
10
19
  (network === Struct_1.Network.TESTNET
11
20
  ? artifacts_1.testnet.PUBLIC_LITE_SEQUENCER_ENDPOINTS
12
21
  : artifacts_1.mainnet.PUBLIC_LITE_SEQUENCER_ENDPOINTS);
13
- this.clients = endpoints.map((endpoint) => new LiteSequencerClient_1.LiteSequencerClient(endpoint));
22
+ this.clients = clientFactory.createClients(endpoints);
23
+ this.logger = logger;
14
24
  }
15
- async getOperationType(operationId) {
16
- for (const client of this.clients) {
17
- try {
18
- return await client.getOperationType(operationId);
19
- }
20
- catch (error) {
21
- console.error('Failed to get operationType:', error);
25
+ async getOperationType(operationId, waitOptions) {
26
+ this.logger.debug(`Getting operation type for ${(0, Utils_1.formatObjectForLogging)(operationId)}`);
27
+ const requestFn = async () => {
28
+ let lastError;
29
+ for (const client of this.clients) {
30
+ try {
31
+ const type = await client.getOperationType(operationId);
32
+ this.logger.debug(`Operation retrieved successfully`);
33
+ return type;
34
+ }
35
+ catch (error) {
36
+ this.logger.warn(`Failed to get operationType using one of the endpoints`);
37
+ lastError = error;
38
+ }
22
39
  }
23
- }
24
- throw new Error('All endpoints failed to get operation type');
40
+ this.logger.error('All endpoints failed to get operation type');
41
+ throw (0, errors_1.allEndpointsFailedError)(lastError);
42
+ };
43
+ return waitOptions ? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn) : await requestFn();
25
44
  }
26
- async getOperationId(transactionLinker) {
27
- for (const client of this.clients) {
28
- try {
29
- return await client.getOperationId(transactionLinker);
30
- }
31
- catch (error) {
32
- console.error('Failed to get OperationId:', error);
45
+ async getOperationId(transactionLinker, waitOptions) {
46
+ this.logger.debug(`Getting operation ID for transaction linker: ${(0, Utils_1.formatObjectForLogging)(transactionLinker)}`);
47
+ const requestFn = async () => {
48
+ let lastError;
49
+ for (const client of this.clients) {
50
+ try {
51
+ const id = await client.getOperationId(transactionLinker);
52
+ this.logger.debug(`Operation ID ${id == '' ? 'does not exist' : 'retrieved successfully'}`);
53
+ return id;
54
+ }
55
+ catch (error) {
56
+ this.logger.warn(`Failed to get OperationId using one of the endpoints`);
57
+ lastError = error;
58
+ }
33
59
  }
34
- }
35
- throw new Error('All endpoints failed to get operation id');
60
+ this.logger.error('All endpoints failed to get operation id');
61
+ throw (0, errors_1.allEndpointsFailedError)(lastError);
62
+ };
63
+ return waitOptions ? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn) : await requestFn();
36
64
  }
37
- async getOperationIdsByShardsKeys(shardsKeys, caller, chunkSize = 100) {
38
- for (const client of this.clients) {
39
- try {
40
- return await client.getOperationIdsByShardsKeys(shardsKeys, caller, chunkSize);
41
- }
42
- catch (error) {
43
- console.error('Failed to get OperationIds:', error);
65
+ async getOperationIdsByShardsKeys(shardsKeys, caller, waitOptions, chunkSize = 100) {
66
+ this.logger.debug(`Getting operation IDs for shards keys: ${(0, Utils_1.formatObjectForLogging)(shardsKeys)}`);
67
+ this.logger.debug(`Caller: ${caller}, Chunk size: ${chunkSize}`);
68
+ const requestFn = async () => {
69
+ let lastError;
70
+ for (const client of this.clients) {
71
+ try {
72
+ const result = await client.getOperationIdsByShardsKeys(shardsKeys, caller, chunkSize);
73
+ this.logger.debug(`Operation IDs by shards keys retrieved successfully`);
74
+ return result;
75
+ }
76
+ catch (error) {
77
+ this.logger.warn(`Failed to get OperationIds using one of the endpoints`);
78
+ lastError = error;
79
+ }
44
80
  }
45
- }
46
- throw new Error('All endpoints failed to get operation ids by shards keys');
81
+ this.logger.error('All endpoints failed to get operation ids by shards keys');
82
+ throw (0, errors_1.allEndpointsFailedError)(lastError);
83
+ };
84
+ return waitOptions ? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn) : await requestFn();
47
85
  }
48
- async getStageProfiling(operationId) {
49
- for (const client of this.clients) {
50
- try {
51
- const map = await client.getStageProfilings([operationId]);
52
- const result = map[operationId];
53
- if (!result) {
54
- throw new Error(`No stageProfiling data for operationId=${operationId}`);
86
+ async getStageProfiling(operationId, waitOptions) {
87
+ this.logger.debug(`Getting stage profiling for operation ${operationId}`);
88
+ const requestFn = async () => {
89
+ let lastError;
90
+ for (const client of this.clients) {
91
+ try {
92
+ const map = await client.getStageProfilings([operationId]);
93
+ const result = map[operationId];
94
+ if (!result) {
95
+ this.logger.warn(`No stageProfiling data for operationId=${operationId}`);
96
+ throw new Error(`No stageProfiling data for operationId=${operationId}`);
97
+ }
98
+ this.logger.debug(`Stage profiling retrieved successfully`);
99
+ return result;
100
+ }
101
+ catch (error) {
102
+ this.logger.warn(`Failed to get stage profiling using one of the endpoints`);
103
+ lastError = error;
55
104
  }
56
- return result;
57
- }
58
- catch (error) {
59
- console.error('Failed to get stage profiling:', error);
60
105
  }
61
- }
62
- throw new Error('All endpoints failed to get stage profiling');
106
+ this.logger.error('All endpoints failed to get stage profiling');
107
+ throw (0, errors_1.allEndpointsFailedError)(lastError);
108
+ };
109
+ return waitOptions ? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn) : await requestFn();
63
110
  }
64
- async getStageProfilings(operationIds, chunkSize = 100) {
65
- for (const client of this.clients) {
66
- try {
67
- return await client.getStageProfilings(operationIds, chunkSize);
68
- }
69
- catch (error) {
70
- console.error('Failed to get stage profilings:', error);
111
+ async getStageProfilings(operationIds, waitOptions, chunkSize = 100) {
112
+ this.logger.debug(`Getting stage profilings for operations: ${operationIds.join(', ')}`);
113
+ this.logger.debug(`Chunk size: ${chunkSize}`);
114
+ const requestFn = async () => {
115
+ let lastError;
116
+ for (const client of this.clients) {
117
+ try {
118
+ const result = await client.getStageProfilings(operationIds, chunkSize);
119
+ this.logger.debug(`Stage profilings retrieved successfully`);
120
+ return result;
121
+ }
122
+ catch (error) {
123
+ this.logger.warn(`Failed to get stage profilings using one of the endpoints`);
124
+ lastError = error;
125
+ }
71
126
  }
72
- }
73
- throw new Error('All endpoints failed to get stage profilings');
127
+ this.logger.error('All endpoints failed to get stage profilings');
128
+ throw (0, errors_1.allEndpointsFailedError)(lastError);
129
+ };
130
+ return waitOptions ? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn) : await requestFn();
74
131
  }
75
- async getOperationStatuses(operationIds, chunkSize = 100) {
76
- for (const client of this.clients) {
77
- try {
78
- return await client.getOperationStatuses(operationIds, chunkSize);
79
- }
80
- catch (error) {
81
- console.error('Failed to get operation statuses:', error);
132
+ async getOperationStatuses(operationIds, waitOptions, chunkSize = 100) {
133
+ this.logger.debug(`Getting operation statuses for operations: ${(0, Utils_1.formatObjectForLogging)(operationIds)}`);
134
+ this.logger.debug(`Chunk size: ${chunkSize}`);
135
+ const requestFn = async () => {
136
+ let lastError;
137
+ for (const client of this.clients) {
138
+ try {
139
+ const result = await client.getOperationStatuses(operationIds, chunkSize);
140
+ this.logger.debug(`Operation statuses retrieved successfully`);
141
+ return result;
142
+ }
143
+ catch (error) {
144
+ this.logger.warn(`Failed to get operation statuses using one of the endpoints`);
145
+ lastError = error;
146
+ }
82
147
  }
83
- }
84
- throw new Error('All endpoints failed to get operation statuses');
148
+ this.logger.error('All endpoints failed to get operation statuses');
149
+ throw (0, errors_1.allEndpointsFailedError)(lastError);
150
+ };
151
+ return waitOptions ? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn) : await requestFn();
85
152
  }
86
- async getOperationStatus(operationId) {
87
- for (const client of this.clients) {
88
- try {
89
- const map = await client.getOperationStatuses([operationId]);
90
- const result = map[operationId];
91
- if (!result) {
92
- throw new Error(`No operation status for operationId=${operationId}`);
153
+ async getOperationStatus(operationId, waitOptions) {
154
+ this.logger.debug(`Getting operation status for ${(0, Utils_1.formatObjectForLogging)(operationId)}`);
155
+ const requestFn = async () => {
156
+ let lastError;
157
+ for (const client of this.clients) {
158
+ try {
159
+ const map = await client.getOperationStatuses([operationId]);
160
+ const result = map[operationId];
161
+ if (!result) {
162
+ this.logger.warn(`No operation status for operationId=${operationId}`);
163
+ throw new Error(`No operation status for operationId=${operationId}`);
164
+ }
165
+ this.logger.debug(`Operation status retrieved successfully`);
166
+ return result;
167
+ }
168
+ catch (error) {
169
+ this.logger.warn(`Failed to get operation status using one of the endpoints`);
170
+ lastError = error;
93
171
  }
94
- return result;
95
- }
96
- catch (error) {
97
- console.error('Failed to get operation status:', error);
98
172
  }
99
- }
100
- throw new Error('All endpoints failed to get operation status');
173
+ this.logger.error('All endpoints failed to get operation status');
174
+ throw (0, errors_1.allEndpointsFailedError)(lastError);
175
+ };
176
+ return waitOptions ? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn) : await requestFn();
101
177
  }
102
178
  async getSimplifiedOperationStatus(transactionLinker) {
179
+ this.logger.debug(`Getting simplified operation status for transaction linker: ${(0, Utils_1.formatObjectForLogging)(transactionLinker)}`);
103
180
  const operationId = await this.getOperationId(transactionLinker);
104
181
  if (operationId == '') {
182
+ this.logger.warn('Operation ID not found');
105
183
  return Struct_1.SimplifiedStatuses.OPERATION_ID_NOT_FOUND;
106
184
  }
185
+ this.logger.debug(`Operation ID: ${operationId}`);
107
186
  const operationType = await this.getOperationType(operationId);
187
+ this.logger.debug(`Operation type: ${operationType}`);
108
188
  if (operationType == Struct_1.OperationType.PENDING || operationType == Struct_1.OperationType.UNKNOWN) {
109
189
  return Struct_1.SimplifiedStatuses.PENDING;
110
190
  }
@@ -0,0 +1,23 @@
1
+ import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
+ import type { SenderAbstraction } from '../sender';
3
+ import { IConfiguration, ILogger, ISimulator } from '../structs/Services';
4
+ import { Asset, CrosschainTx, EvmProxyMsg, ExecutionFeeEstimationResult, SuggestedTONExecutorFee, TACSimulationRequest, TACSimulationResult, TransactionLinker } from '../structs/Struct';
5
+ export interface IHttpClient {
6
+ post<T>(url: string, data: unknown, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
7
+ }
8
+ export declare class AxiosHttpClient implements IHttpClient {
9
+ post<T>(url: string, data: unknown, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
10
+ }
11
+ export declare class Simulator implements ISimulator {
12
+ private readonly config;
13
+ private readonly logger;
14
+ private readonly httpClient;
15
+ constructor(config: IConfiguration, logger?: ILogger, httpClient?: IHttpClient);
16
+ simulateTACMessage(req: TACSimulationRequest): Promise<TACSimulationResult>;
17
+ simulateTransactions(sender: SenderAbstraction, txs: CrosschainTx[]): Promise<TACSimulationResult[]>;
18
+ private buildTACSimulationRequest;
19
+ getTVMExecutorFeeInfo(assets: Asset[], feeSymbol: string): Promise<SuggestedTONExecutorFee>;
20
+ private getFeeInfo;
21
+ getTransactionSimulationInfo(evmProxyMsg: EvmProxyMsg, sender: SenderAbstraction, assets?: Asset[]): Promise<ExecutionFeeEstimationResult>;
22
+ getSimulationInfoForTransaction(evmProxyMsg: EvmProxyMsg, transactionLinker: TransactionLinker, assets: Asset[], allowSimulationError?: boolean, isRoundTrip?: boolean, evmValidExecutors?: string[], tvmValidExecutors?: string[]): Promise<ExecutionFeeEstimationResult>;
23
+ }