@tonappchain/sdk 0.7.0-rc24-test-8 → 0.7.0-rc24-test-10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/artifacts/dev/tac/artifacts.js +2 -2
- package/dist/artifacts/dev/tac/wrappers.d.ts +4 -4
- package/dist/artifacts/mainnet/tac/artifacts.js +2 -2
- package/dist/artifacts/mainnet/tac/wrappers.d.ts +4 -4
- package/dist/artifacts/tacTypes.d.ts +1 -1
- package/dist/artifacts/testnet/tac/artifacts.js +2 -2
- package/dist/artifacts/testnet/tac/wrappers.d.ts +4 -4
- package/dist/artifacts/tonTypes.d.ts +1 -1
- package/dist/src/adapters/contractOpener.js +3 -1
- package/dist/src/agnosticSdk/AbiHandler.d.ts +23 -0
- package/dist/src/agnosticSdk/AbiHandler.js +105 -0
- package/dist/src/agnosticSdk/AgnosticSdk.d.ts +47 -217
- package/dist/src/agnosticSdk/AgnosticSdk.js +60 -595
- package/dist/src/agnosticSdk/AgnosticStructs.d.ts +108 -0
- package/dist/src/agnosticSdk/AgnosticStructs.js +23 -0
- package/dist/src/agnosticSdk/DebugHelpers.d.ts +88 -0
- package/dist/src/agnosticSdk/DebugHelpers.js +274 -0
- package/dist/src/agnosticSdk/HooksHandler.d.ts +43 -0
- package/dist/src/agnosticSdk/HooksHandler.js +102 -0
- package/dist/src/agnosticSdk/ReplacementHelper.d.ts +95 -0
- package/dist/src/agnosticSdk/ReplacementHelper.js +233 -0
- package/dist/src/assets/NFT.js +3 -3
- package/dist/src/errors/index.d.ts +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +26 -2
- package/dist/src/sdk/Configuration.js +5 -5
- package/dist/src/sdk/OperationTracker.js +37 -14
- package/dist/src/sdk/TONTransactionManager.js +3 -2
- package/dist/src/sdk/TacSdk.js +4 -37
- package/dist/src/structs/InternalStruct.d.ts +1 -1
- package/dist/src/wrappers/ContentUtils.js +0 -1
- package/package.json +1 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Interface } from 'ethers';
|
|
2
|
+
import { AmountChange } from './AgnosticStructs';
|
|
3
|
+
export declare class ReplacementHelper {
|
|
4
|
+
/**
|
|
5
|
+
* Helper to create dynamic amount replacement for a specific parameter
|
|
6
|
+
* @param paramIndex - The index of the parameter to replace
|
|
7
|
+
* @param token - The token to replace
|
|
8
|
+
* @param balanceAddress - The address to replace the parameter with
|
|
9
|
+
* @returns The amount replacement
|
|
10
|
+
*/
|
|
11
|
+
createAmountReplacement(paramIndex: number, token: string, balanceAddress: string): AmountChange;
|
|
12
|
+
/**
|
|
13
|
+
* Advanced replacement calculator - calculates position and length for any parameter type
|
|
14
|
+
* Required that you have added the contract interface first using addContractInterface().
|
|
15
|
+
* If human readable abi is used, need to provide function and params names also
|
|
16
|
+
* @param contractAddress - The address of the contract to call
|
|
17
|
+
* @param functionName - The name of the function to call
|
|
18
|
+
* @param parameterName - The name of the parameter to replace
|
|
19
|
+
* @param token - The token to replace
|
|
20
|
+
* @param balanceAddress - The address to replace the parameter with
|
|
21
|
+
* @returns The replacement data
|
|
22
|
+
*/
|
|
23
|
+
calculateReplacementData(contractAddress: string, functionName: string, parameterName: string, token: string, balanceAddress: string, contractInterfaces: Map<string, Interface>): AmountChange;
|
|
24
|
+
/**
|
|
25
|
+
* Get replacement helper - shows available functions and parameters for a contract
|
|
26
|
+
* Required that you have added the contract interface first using addContractInterface().
|
|
27
|
+
* If human readable abi is used, need to provide function and params names also
|
|
28
|
+
* @param contractAddress - The address of the contract to call
|
|
29
|
+
* @returns The replacement helper
|
|
30
|
+
*/
|
|
31
|
+
getReplacementHelper(contractAddress: string, contractInterfaces: Map<string, Interface>): {
|
|
32
|
+
contractAddress: string;
|
|
33
|
+
functions: {
|
|
34
|
+
name: string;
|
|
35
|
+
signature: string;
|
|
36
|
+
parameters: {
|
|
37
|
+
name: string;
|
|
38
|
+
type: string;
|
|
39
|
+
index: number;
|
|
40
|
+
canReplace: boolean;
|
|
41
|
+
reason?: string;
|
|
42
|
+
}[];
|
|
43
|
+
}[];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Interactive replacement builder - helps build replacement step by step
|
|
47
|
+
* @param contractAddress - The address of the contract to call
|
|
48
|
+
* @param functionName - The name of the function to call
|
|
49
|
+
* @param parameterName - The name of the parameter to replace
|
|
50
|
+
* @param token - The token to replace
|
|
51
|
+
* @param balanceAddress - The address to replace the parameter with
|
|
52
|
+
* @param options - The options of the interactive replacement builder
|
|
53
|
+
* @returns The interactive replacement builder
|
|
54
|
+
*/
|
|
55
|
+
buildReplacementInteractive(contractAddress: string, functionName: string, parameterName: string, token: string, balanceAddress: string, contractInterfaces: Map<string, Interface>, options?: {
|
|
56
|
+
validate?: boolean;
|
|
57
|
+
}): {
|
|
58
|
+
replacement: AmountChange;
|
|
59
|
+
calculation: {
|
|
60
|
+
functionSignature: string;
|
|
61
|
+
parameterInfo: {
|
|
62
|
+
name: string;
|
|
63
|
+
type: string;
|
|
64
|
+
index: number;
|
|
65
|
+
position: number;
|
|
66
|
+
length: number;
|
|
67
|
+
};
|
|
68
|
+
positionCalculation: string;
|
|
69
|
+
};
|
|
70
|
+
validation: {
|
|
71
|
+
isValid: boolean;
|
|
72
|
+
warnings: string[];
|
|
73
|
+
suggestions: string[];
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Private helper to calculate position and length for complex parameter types
|
|
78
|
+
* @param inputs - The inputs of the function
|
|
79
|
+
* @param targetIndex - The index of the parameter to calculate the position and length for
|
|
80
|
+
* @returns The position and length of the parameter
|
|
81
|
+
*/
|
|
82
|
+
private _calculateParamPositionAndLength;
|
|
83
|
+
/**
|
|
84
|
+
* Get the size in bytes for a parameter type
|
|
85
|
+
* @param type - The type of the parameter
|
|
86
|
+
* @returns The size in bytes of the parameter
|
|
87
|
+
*/
|
|
88
|
+
private _getTypeSize;
|
|
89
|
+
/**
|
|
90
|
+
* Check if a parameter type can be replaced with a balance
|
|
91
|
+
* @param type - The type of the parameter
|
|
92
|
+
* @returns The can replace and reason of the parameter
|
|
93
|
+
*/
|
|
94
|
+
private _canParameterBeReplaced;
|
|
95
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReplacementHelper = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
class ReplacementHelper {
|
|
6
|
+
/**
|
|
7
|
+
* Helper to create dynamic amount replacement for a specific parameter
|
|
8
|
+
* @param paramIndex - The index of the parameter to replace
|
|
9
|
+
* @param token - The token to replace
|
|
10
|
+
* @param balanceAddress - The address to replace the parameter with
|
|
11
|
+
* @returns The amount replacement
|
|
12
|
+
*/
|
|
13
|
+
createAmountReplacement(paramIndex, token, balanceAddress) {
|
|
14
|
+
// Calculate position in calldata (4 bytes selector + 32 bytes per param)
|
|
15
|
+
const position = 4 + paramIndex * 32;
|
|
16
|
+
return {
|
|
17
|
+
position,
|
|
18
|
+
len: 32, // uint256 is 32 bytes
|
|
19
|
+
token,
|
|
20
|
+
balanceAddress,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Advanced replacement calculator - calculates position and length for any parameter type
|
|
25
|
+
* Required that you have added the contract interface first using addContractInterface().
|
|
26
|
+
* If human readable abi is used, need to provide function and params names also
|
|
27
|
+
* @param contractAddress - The address of the contract to call
|
|
28
|
+
* @param functionName - The name of the function to call
|
|
29
|
+
* @param parameterName - The name of the parameter to replace
|
|
30
|
+
* @param token - The token to replace
|
|
31
|
+
* @param balanceAddress - The address to replace the parameter with
|
|
32
|
+
* @returns The replacement data
|
|
33
|
+
*/
|
|
34
|
+
calculateReplacementData(contractAddress, functionName, parameterName, token, balanceAddress, contractInterfaces) {
|
|
35
|
+
const contractInterface = contractInterfaces.get(contractAddress.toLowerCase());
|
|
36
|
+
if (!contractInterface) {
|
|
37
|
+
throw new Error(`Contract interface not found for address: ${contractAddress}. Please add it first using addContractInterface().`);
|
|
38
|
+
}
|
|
39
|
+
let functionFragment;
|
|
40
|
+
try {
|
|
41
|
+
functionFragment = contractInterface.getFunction(functionName);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
throw new Error(`Function '${functionName}' not found in contract interface for ${contractAddress}`);
|
|
45
|
+
}
|
|
46
|
+
if (!functionFragment) {
|
|
47
|
+
throw new Error(`Function '${functionName}' not found in contract interface for ${contractAddress}`);
|
|
48
|
+
}
|
|
49
|
+
// Find the parameter by name
|
|
50
|
+
const paramIndex = functionFragment.inputs.findIndex((input) => input.name === parameterName);
|
|
51
|
+
if (paramIndex === -1) {
|
|
52
|
+
const availableParams = functionFragment.inputs.map((input) => `${input.name} (${input.type})`).join(', ');
|
|
53
|
+
throw new Error(`Parameter '${parameterName}' not found in function '${functionName}'. Available parameters: ${availableParams}`);
|
|
54
|
+
}
|
|
55
|
+
// Calculate position and length based on parameter type
|
|
56
|
+
const { position, len } = this._calculateParamPositionAndLength(functionFragment.inputs, paramIndex);
|
|
57
|
+
return {
|
|
58
|
+
position,
|
|
59
|
+
len,
|
|
60
|
+
token,
|
|
61
|
+
balanceAddress,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get replacement helper - shows available functions and parameters for a contract
|
|
66
|
+
* Required that you have added the contract interface first using addContractInterface().
|
|
67
|
+
* If human readable abi is used, need to provide function and params names also
|
|
68
|
+
* @param contractAddress - The address of the contract to call
|
|
69
|
+
* @returns The replacement helper
|
|
70
|
+
*/
|
|
71
|
+
getReplacementHelper(contractAddress, contractInterfaces) {
|
|
72
|
+
const contractInterface = contractInterfaces.get(contractAddress.toLowerCase());
|
|
73
|
+
if (!contractInterface) {
|
|
74
|
+
throw new Error(`Contract interface not found for address: ${contractAddress}. Please add it first using addContractInterface().`);
|
|
75
|
+
}
|
|
76
|
+
const functions = contractInterface.fragments
|
|
77
|
+
.filter((fragment) => fragment.type === 'function')
|
|
78
|
+
.map((fragment) => {
|
|
79
|
+
const func = fragment;
|
|
80
|
+
return {
|
|
81
|
+
name: func.name,
|
|
82
|
+
signature: func.format('full'),
|
|
83
|
+
parameters: func.inputs.map((input, index) => {
|
|
84
|
+
const canReplace = this._canParameterBeReplaced(input.type);
|
|
85
|
+
return {
|
|
86
|
+
name: input.name || `param${index}`,
|
|
87
|
+
type: input.type,
|
|
88
|
+
index,
|
|
89
|
+
canReplace: canReplace.canReplace,
|
|
90
|
+
reason: canReplace.reason,
|
|
91
|
+
};
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
contractAddress,
|
|
97
|
+
functions,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Interactive replacement builder - helps build replacement step by step
|
|
102
|
+
* @param contractAddress - The address of the contract to call
|
|
103
|
+
* @param functionName - The name of the function to call
|
|
104
|
+
* @param parameterName - The name of the parameter to replace
|
|
105
|
+
* @param token - The token to replace
|
|
106
|
+
* @param balanceAddress - The address to replace the parameter with
|
|
107
|
+
* @param options - The options of the interactive replacement builder
|
|
108
|
+
* @returns The interactive replacement builder
|
|
109
|
+
*/
|
|
110
|
+
buildReplacementInteractive(contractAddress, functionName, parameterName, token, balanceAddress, contractInterfaces, options = {}) {
|
|
111
|
+
const { validate = true } = options;
|
|
112
|
+
// Get the replacement data
|
|
113
|
+
const replacement = this.calculateReplacementData(contractAddress, functionName, parameterName, token, balanceAddress, contractInterfaces);
|
|
114
|
+
// Get function info for calculation details
|
|
115
|
+
const contractInterface = contractInterfaces.get(contractAddress.toLowerCase());
|
|
116
|
+
if (!contractInterface) {
|
|
117
|
+
throw new Error(`Contract interface not found for address: ${contractAddress}`);
|
|
118
|
+
}
|
|
119
|
+
const functionFragment = contractInterface.getFunction(functionName);
|
|
120
|
+
if (!functionFragment) {
|
|
121
|
+
throw new Error(`Function '${functionName}' not found in contract interface for ${contractAddress}`);
|
|
122
|
+
}
|
|
123
|
+
const paramIndex = functionFragment.inputs.findIndex((input) => input.name === parameterName);
|
|
124
|
+
const param = functionFragment.inputs[paramIndex];
|
|
125
|
+
const calculation = {
|
|
126
|
+
functionSignature: functionFragment.format('full'),
|
|
127
|
+
parameterInfo: {
|
|
128
|
+
name: parameterName,
|
|
129
|
+
type: param.type,
|
|
130
|
+
index: paramIndex,
|
|
131
|
+
position: replacement.position,
|
|
132
|
+
length: replacement.len,
|
|
133
|
+
},
|
|
134
|
+
positionCalculation: `Position = 4 bytes (selector) + ${paramIndex} * 32 bytes = ${replacement.position} bytes`,
|
|
135
|
+
};
|
|
136
|
+
// Validation
|
|
137
|
+
const validation = {
|
|
138
|
+
isValid: true,
|
|
139
|
+
warnings: [],
|
|
140
|
+
suggestions: [],
|
|
141
|
+
};
|
|
142
|
+
if (validate) {
|
|
143
|
+
// Check if parameter type is suitable for replacement
|
|
144
|
+
const typeCheck = this._canParameterBeReplaced(param.type);
|
|
145
|
+
if (!typeCheck.canReplace) {
|
|
146
|
+
validation.isValid = false;
|
|
147
|
+
validation.warnings.push(`Parameter type '${param.type}' ${typeCheck.reason}`);
|
|
148
|
+
}
|
|
149
|
+
// Check if it's a reasonable parameter to replace
|
|
150
|
+
if (param.name.toLowerCase().includes('amount') || param.name.toLowerCase().includes('value')) {
|
|
151
|
+
validation.suggestions.push(`✅ Parameter '${param.name}' looks suitable for dynamic replacement`);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
validation.warnings.push(`⚠️ Parameter '${param.name}' might not be intended for amount replacement`);
|
|
155
|
+
}
|
|
156
|
+
// Check token address
|
|
157
|
+
if (!ethers_1.ethers.isAddress(token)) {
|
|
158
|
+
validation.isValid = false;
|
|
159
|
+
validation.warnings.push(`Invalid token address: ${token}`);
|
|
160
|
+
}
|
|
161
|
+
if (!ethers_1.ethers.isAddress(balanceAddress)) {
|
|
162
|
+
validation.isValid = false;
|
|
163
|
+
validation.warnings.push(`Invalid balance address: ${balanceAddress}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
replacement,
|
|
168
|
+
calculation,
|
|
169
|
+
validation,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Private helper to calculate position and length for complex parameter types
|
|
174
|
+
* @param inputs - The inputs of the function
|
|
175
|
+
* @param targetIndex - The index of the parameter to calculate the position and length for
|
|
176
|
+
* @returns The position and length of the parameter
|
|
177
|
+
*/
|
|
178
|
+
_calculateParamPositionAndLength(inputs, targetIndex) {
|
|
179
|
+
// For now, we support simple types. Complex types (arrays, structs) would need more sophisticated calculation
|
|
180
|
+
// This is a simplified version that works for basic types like uint256, address, etc.
|
|
181
|
+
let position = 4; // Start after function selector
|
|
182
|
+
for (let i = 0; i < targetIndex; i++) {
|
|
183
|
+
const paramType = inputs[i].type;
|
|
184
|
+
position += this._getTypeSize(paramType);
|
|
185
|
+
}
|
|
186
|
+
const targetType = inputs[targetIndex].type;
|
|
187
|
+
const len = this._getTypeSize(targetType);
|
|
188
|
+
return { position, len };
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Get the size in bytes for a parameter type
|
|
192
|
+
* @param type - The type of the parameter
|
|
193
|
+
* @returns The size in bytes of the parameter
|
|
194
|
+
*/
|
|
195
|
+
_getTypeSize(type) {
|
|
196
|
+
// Basic types are all 32 bytes in calldata (due to ABI encoding)
|
|
197
|
+
if (type.startsWith('uint') ||
|
|
198
|
+
type.startsWith('int') ||
|
|
199
|
+
type === 'address' ||
|
|
200
|
+
type === 'bool' ||
|
|
201
|
+
type.startsWith('bytes32')) {
|
|
202
|
+
return 32;
|
|
203
|
+
}
|
|
204
|
+
// Dynamic types (bytes, string) are also 32 bytes for the offset
|
|
205
|
+
if (type === 'bytes' || type === 'string') {
|
|
206
|
+
return 32;
|
|
207
|
+
}
|
|
208
|
+
// Arrays are 32 bytes for the offset
|
|
209
|
+
if (type.includes('[]')) {
|
|
210
|
+
return 32;
|
|
211
|
+
}
|
|
212
|
+
// Default to 32 bytes for unknown types
|
|
213
|
+
return 32;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Check if a parameter type can be replaced with a balance
|
|
217
|
+
* @param type - The type of the parameter
|
|
218
|
+
* @returns The can replace and reason of the parameter
|
|
219
|
+
*/
|
|
220
|
+
_canParameterBeReplaced(type) {
|
|
221
|
+
if (type.startsWith('uint') && !type.includes('[]')) {
|
|
222
|
+
return { canReplace: true };
|
|
223
|
+
}
|
|
224
|
+
if (type.startsWith('int') && !type.includes('[]')) {
|
|
225
|
+
return { canReplace: true, reason: 'but be careful with signed integers' };
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
canReplace: false,
|
|
229
|
+
reason: `is not suitable for balance replacement. Only uint/int types are supported.`,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
exports.ReplacementHelper = ReplacementHelper;
|
package/dist/src/assets/NFT.js
CHANGED
|
@@ -119,9 +119,9 @@ class NFT {
|
|
|
119
119
|
originalAddress: collectionAddress,
|
|
120
120
|
}, configuration.TONParams.nftCollectionCode));
|
|
121
121
|
const NFTItemC = configuration.artifacts.ton.wrappers.NFTItem;
|
|
122
|
-
return tokenId == undefined
|
|
123
|
-
nftCollection.address.toString()
|
|
124
|
-
NFTItemC.createFromConfig({
|
|
122
|
+
return tokenId == undefined
|
|
123
|
+
? nftCollection.address.toString()
|
|
124
|
+
: NFTItemC.createFromConfig({
|
|
125
125
|
collectionAddress: nftCollection.address,
|
|
126
126
|
cclAddress: ton_1.Address.parse(configuration.TONParams.crossChainLayerAddress),
|
|
127
127
|
index: tokenId,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { AddressError, BitError, ContractError, EVMCallError, FetchError, FormatError, KeyError, MetadataError, SettingError, TokenError, WalletError, } from './errors';
|
|
2
|
-
export { allEndpointsFailedError, emptyArrayError, emptyContractError, emptySettingError, evmAddressError, indexRequiredError, insufficientBalanceError, invalidMethodNameError, missingDecimals, missingFeeParamsError, missingGasLimitError, missingJettonDataError, missingTvmExecutorFeeError, notMultiplyOf8Error, operationFetchError, prefixError, profilingFetchError, simulationFetchError, statusFetchError, tvmAddressError, unknownTokenTypeError, unknownWalletError, unsupportedFormatError, unsupportedKeyError } from './instances';
|
|
2
|
+
export { allEndpointsFailedError, emptyArrayError, emptyContractError, emptySettingError, evmAddressError, indexRequiredError, insufficientBalanceError, invalidMethodNameError, missingDecimals, missingFeeParamsError, missingGasLimitError, missingJettonDataError, missingTvmExecutorFeeError, notMultiplyOf8Error, operationFetchError, prefixError, profilingFetchError, simulationFetchError, statusFetchError, tvmAddressError, unknownTokenTypeError, unknownWalletError, unsupportedFormatError, unsupportedKeyError, } from './instances';
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './adapters';
|
|
2
|
-
export
|
|
2
|
+
export { AgnosticProxySDK } from './agnosticSdk/AgnosticSdk';
|
|
3
|
+
export * as AgnosticStructs from './agnosticSdk/AgnosticStructs';
|
|
3
4
|
export * from './assets';
|
|
4
5
|
export * from './errors';
|
|
5
6
|
export * from './interfaces';
|
package/dist/src/index.js
CHANGED
|
@@ -10,13 +10,37 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
16
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.TONTransactionManager = exports.TACTransactionManager = exports.TacSdk = exports.startTrackingMultiple = exports.startTracking = exports.Simulator = exports.OperationTracker = exports.NoopLogger = exports.ConsoleLogger = exports.LiteSequencerClient = exports.Configuration = exports.AxiosHttpClient = void 0;
|
|
39
|
+
exports.TONTransactionManager = exports.TACTransactionManager = exports.TacSdk = exports.startTrackingMultiple = exports.startTracking = exports.Simulator = exports.OperationTracker = exports.NoopLogger = exports.ConsoleLogger = exports.LiteSequencerClient = exports.Configuration = exports.AxiosHttpClient = exports.AgnosticStructs = exports.AgnosticProxySDK = void 0;
|
|
18
40
|
__exportStar(require("./adapters"), exports);
|
|
19
|
-
|
|
41
|
+
var AgnosticSdk_1 = require("./agnosticSdk/AgnosticSdk");
|
|
42
|
+
Object.defineProperty(exports, "AgnosticProxySDK", { enumerable: true, get: function () { return AgnosticSdk_1.AgnosticProxySDK; } });
|
|
43
|
+
exports.AgnosticStructs = __importStar(require("./agnosticSdk/AgnosticStructs"));
|
|
20
44
|
__exportStar(require("./assets"), exports);
|
|
21
45
|
__exportStar(require("./errors"), exports);
|
|
22
46
|
__exportStar(require("./interfaces"), exports);
|
|
@@ -4,7 +4,7 @@ exports.Configuration = void 0;
|
|
|
4
4
|
const ton_1 = require("@ton/ton");
|
|
5
5
|
const ethers_1 = require("ethers");
|
|
6
6
|
const artifacts_1 = require("../../artifacts");
|
|
7
|
-
const
|
|
7
|
+
const adapters_1 = require("../adapters");
|
|
8
8
|
const Struct_1 = require("../structs/Struct");
|
|
9
9
|
const Utils_1 = require("./Utils");
|
|
10
10
|
const Validator_1 = require("./Validator");
|
|
@@ -29,9 +29,7 @@ class Configuration {
|
|
|
29
29
|
liteSequencerEndpoints = customLiteSequencerEndpoints;
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
|
-
liteSequencerEndpoints =
|
|
33
|
-
customLiteSequencerEndpoints ??
|
|
34
|
-
artifacts.PUBLIC_LITE_SEQUENCER_ENDPOINTS;
|
|
32
|
+
liteSequencerEndpoints = customLiteSequencerEndpoints ?? artifacts.PUBLIC_LITE_SEQUENCER_ENDPOINTS;
|
|
35
33
|
}
|
|
36
34
|
return new Configuration(network, artifacts, internalTONParams, internalTACParams, liteSequencerEndpoints);
|
|
37
35
|
}
|
|
@@ -50,7 +48,9 @@ class Configuration {
|
|
|
50
48
|
settingsAddress = TONParams.settingsAddress;
|
|
51
49
|
}
|
|
52
50
|
else {
|
|
53
|
-
contractOpener =
|
|
51
|
+
contractOpener =
|
|
52
|
+
TONParams?.contractOpener ??
|
|
53
|
+
(await (0, adapters_1.createDefaultRetryableOpener)(artifacts.TON_RPC_ENDPOINT_BY_TAC, network, 5, delay));
|
|
54
54
|
settingsAddress = TONParams?.settingsAddress ?? artifacts.TON_SETTINGS_ADDRESS;
|
|
55
55
|
}
|
|
56
56
|
const settings = contractOpener.open(artifacts.ton.wrappers.Settings.createFromAddress(ton_1.Address.parse(settingsAddress)));
|
|
@@ -25,9 +25,10 @@ class OperationTracker {
|
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
27
|
const artifacts = network === Struct_1.Network.MAINNET ? artifacts_1.mainnet : artifacts_1.testnet;
|
|
28
|
-
endpoints =
|
|
29
|
-
customLiteSequencerEndpoints
|
|
30
|
-
|
|
28
|
+
endpoints =
|
|
29
|
+
customLiteSequencerEndpoints && customLiteSequencerEndpoints.length !== 0
|
|
30
|
+
? customLiteSequencerEndpoints
|
|
31
|
+
: artifacts.PUBLIC_LITE_SEQUENCER_ENDPOINTS;
|
|
31
32
|
}
|
|
32
33
|
this.clients = clientFactory.createClients(endpoints);
|
|
33
34
|
this.logger = logger;
|
|
@@ -50,7 +51,9 @@ class OperationTracker {
|
|
|
50
51
|
this.logger.error('All endpoints failed to get operation id by transactionHash');
|
|
51
52
|
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
52
53
|
};
|
|
53
|
-
return waitOptions
|
|
54
|
+
return waitOptions
|
|
55
|
+
? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn, 'OperationTracker: Getting operation ID by transaction hash')
|
|
56
|
+
: await requestFn();
|
|
54
57
|
}
|
|
55
58
|
async getOperationType(operationId, waitOptions) {
|
|
56
59
|
this.logger.debug(`Getting operation type for ${(0, Utils_1.formatObjectForLogging)(operationId)}`);
|
|
@@ -70,7 +73,9 @@ class OperationTracker {
|
|
|
70
73
|
this.logger.error('All endpoints failed to get operation type');
|
|
71
74
|
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
72
75
|
};
|
|
73
|
-
return waitOptions
|
|
76
|
+
return waitOptions
|
|
77
|
+
? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn, 'OperationTracker: Getting operation type')
|
|
78
|
+
: await requestFn();
|
|
74
79
|
}
|
|
75
80
|
async getOperationId(transactionLinker, waitOptions) {
|
|
76
81
|
this.logger.debug(`Getting operation ID for transaction linker: ${(0, Utils_1.formatObjectForLogging)(transactionLinker)}`);
|
|
@@ -90,7 +95,9 @@ class OperationTracker {
|
|
|
90
95
|
this.logger.error('All endpoints failed to get operation id');
|
|
91
96
|
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
92
97
|
};
|
|
93
|
-
return waitOptions
|
|
98
|
+
return waitOptions
|
|
99
|
+
? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn, 'OperationTracker: Getting operation ID by transaction linker')
|
|
100
|
+
: await requestFn();
|
|
94
101
|
}
|
|
95
102
|
async getOperationIdsByShardsKeys(shardsKeys, caller, waitOptions, chunkSize = 100) {
|
|
96
103
|
this.logger.debug(`Getting operation IDs for shards keys: ${(0, Utils_1.formatObjectForLogging)(shardsKeys)}`);
|
|
@@ -111,7 +118,9 @@ class OperationTracker {
|
|
|
111
118
|
this.logger.error('All endpoints failed to get operation ids by shards keys');
|
|
112
119
|
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
113
120
|
};
|
|
114
|
-
return waitOptions
|
|
121
|
+
return waitOptions
|
|
122
|
+
? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn, 'OperationTracker: Getting operation IDs by shards keys')
|
|
123
|
+
: await requestFn();
|
|
115
124
|
}
|
|
116
125
|
async getStageProfiling(operationId, waitOptions) {
|
|
117
126
|
this.logger.debug(`Getting stage profiling for operation ${operationId}`);
|
|
@@ -136,7 +145,9 @@ class OperationTracker {
|
|
|
136
145
|
this.logger.error('All endpoints failed to get stage profiling');
|
|
137
146
|
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
138
147
|
};
|
|
139
|
-
return waitOptions
|
|
148
|
+
return waitOptions
|
|
149
|
+
? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn, 'OperationTracker: Getting stage profiling')
|
|
150
|
+
: await requestFn();
|
|
140
151
|
}
|
|
141
152
|
async getStageProfilings(operationIds, waitOptions, chunkSize = 100) {
|
|
142
153
|
this.logger.debug(`Getting stage profilings for operations: ${operationIds.join(', ')}`);
|
|
@@ -157,7 +168,9 @@ class OperationTracker {
|
|
|
157
168
|
this.logger.error('All endpoints failed to get stage profilings');
|
|
158
169
|
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
159
170
|
};
|
|
160
|
-
return waitOptions
|
|
171
|
+
return waitOptions
|
|
172
|
+
? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn, 'OperationTracker: Getting stage profilings')
|
|
173
|
+
: await requestFn();
|
|
161
174
|
}
|
|
162
175
|
async getOperationStatuses(operationIds, waitOptions, chunkSize = 100) {
|
|
163
176
|
this.logger.debug(`Getting operation statuses for operations: ${(0, Utils_1.formatObjectForLogging)(operationIds)}`);
|
|
@@ -178,7 +191,9 @@ class OperationTracker {
|
|
|
178
191
|
this.logger.error('All endpoints failed to get operation statuses');
|
|
179
192
|
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
180
193
|
};
|
|
181
|
-
return waitOptions
|
|
194
|
+
return waitOptions
|
|
195
|
+
? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn, 'OperationTracker: Getting operation statuses')
|
|
196
|
+
: await requestFn();
|
|
182
197
|
}
|
|
183
198
|
async getOperationStatus(operationId, waitOptions) {
|
|
184
199
|
this.logger.debug(`Getting operation status for ${(0, Utils_1.formatObjectForLogging)(operationId)}`);
|
|
@@ -203,7 +218,9 @@ class OperationTracker {
|
|
|
203
218
|
this.logger.error('All endpoints failed to get operation status');
|
|
204
219
|
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
205
220
|
};
|
|
206
|
-
return waitOptions
|
|
221
|
+
return waitOptions
|
|
222
|
+
? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn, 'OperationTracker: Getting operation status')
|
|
223
|
+
: await requestFn();
|
|
207
224
|
}
|
|
208
225
|
async getSimplifiedOperationStatus(transactionLinker) {
|
|
209
226
|
this.logger.debug(`Getting simplified operation status for transaction linker: ${(0, Utils_1.formatObjectForLogging)(transactionLinker)}`);
|
|
@@ -239,7 +256,9 @@ class OperationTracker {
|
|
|
239
256
|
this.logger.error('All endpoints failed to convert currency');
|
|
240
257
|
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
241
258
|
};
|
|
242
|
-
return waitOptions
|
|
259
|
+
return waitOptions
|
|
260
|
+
? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn, 'OperationTracker: Converting currency')
|
|
261
|
+
: await requestFn();
|
|
243
262
|
}
|
|
244
263
|
async simulateTACMessage(params, waitOptions) {
|
|
245
264
|
Validator_1.Validator.validateTACSimulationParams(params);
|
|
@@ -260,7 +279,9 @@ class OperationTracker {
|
|
|
260
279
|
this.logger.error('All endpoints failed to simulate TAC message');
|
|
261
280
|
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
262
281
|
};
|
|
263
|
-
return waitOptions
|
|
282
|
+
return waitOptions
|
|
283
|
+
? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn, 'OperationTracker: Simulating TAC message')
|
|
284
|
+
: await requestFn();
|
|
264
285
|
}
|
|
265
286
|
async getTVMExecutorFee(params, waitOptions) {
|
|
266
287
|
this.logger.debug(`get TVM executor fee: ${(0, Utils_1.formatObjectForLogging)(params)}`);
|
|
@@ -280,7 +301,9 @@ class OperationTracker {
|
|
|
280
301
|
this.logger.error('All endpoints failed to get TVM executor fee');
|
|
281
302
|
throw (0, errors_1.allEndpointsFailedError)(lastError);
|
|
282
303
|
};
|
|
283
|
-
return waitOptions
|
|
304
|
+
return waitOptions
|
|
305
|
+
? await (0, Utils_1.waitUntilSuccess)(waitOptions, requestFn, 'OperationTracker: Getting TVM executor fee')
|
|
306
|
+
: await requestFn();
|
|
284
307
|
}
|
|
285
308
|
}
|
|
286
309
|
exports.OperationTracker = OperationTracker;
|
|
@@ -50,7 +50,7 @@ class TONTransactionManager {
|
|
|
50
50
|
async prepareCrossChainTransaction(evmProxyMsg, sender, assets, options, skipAssetsBalanceValidation = false) {
|
|
51
51
|
this.logger.debug('Preparing cross-chain transaction');
|
|
52
52
|
const caller = sender.getSenderAddress();
|
|
53
|
-
const { allowSimulationError = false, isRoundTrip = undefined, calculateRollbackFee = true, validateAssetsBalance = true } = options || {};
|
|
53
|
+
const { allowSimulationError = false, isRoundTrip = undefined, calculateRollbackFee = true, validateAssetsBalance = true, } = options || {};
|
|
54
54
|
const { evmValidExecutors = [], tvmValidExecutors = [] } = options || {};
|
|
55
55
|
Validator_1.Validator.validateEVMAddress(evmProxyMsg.evmTargetAddress);
|
|
56
56
|
const aggregatedData = await (0, Utils_1.aggregateTokens)(assets);
|
|
@@ -144,7 +144,8 @@ class TONTransactionManager {
|
|
|
144
144
|
if (!waitOptions) {
|
|
145
145
|
return { sendTransactionResult, ...transactionLinker };
|
|
146
146
|
}
|
|
147
|
-
const operationId = await this.operationTracker
|
|
147
|
+
const operationId = await this.operationTracker
|
|
148
|
+
.getOperationId(transactionLinker, {
|
|
148
149
|
...waitOptions,
|
|
149
150
|
successCheck: (id) => !!id,
|
|
150
151
|
logger: this.logger,
|
package/dist/src/sdk/TacSdk.js
CHANGED
|
@@ -1,39 +1,7 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.TacSdk = void 0;
|
|
4
|
+
const artifacts_1 = require("../../artifacts");
|
|
37
5
|
const assets_1 = require("../assets");
|
|
38
6
|
const Struct_1 = require("../structs/Struct");
|
|
39
7
|
const Configuration_1 = require("./Configuration");
|
|
@@ -55,17 +23,16 @@ class TacSdk {
|
|
|
55
23
|
static async create(sdkParams, logger = new Logger_1.NoopLogger()) {
|
|
56
24
|
const network = sdkParams.network;
|
|
57
25
|
const delay = sdkParams.delay ?? Consts_1.DEFAULT_DELAY;
|
|
58
|
-
const { dev, testnet, mainnet } = await Promise.resolve().then(() => __importStar(require('../../artifacts')));
|
|
59
26
|
let artifacts;
|
|
60
27
|
switch (network) {
|
|
61
28
|
case Struct_1.Network.MAINNET:
|
|
62
|
-
artifacts = mainnet;
|
|
29
|
+
artifacts = artifacts_1.mainnet;
|
|
63
30
|
break;
|
|
64
31
|
case Struct_1.Network.TESTNET:
|
|
65
|
-
artifacts = testnet;
|
|
32
|
+
artifacts = artifacts_1.testnet;
|
|
66
33
|
break;
|
|
67
34
|
case Struct_1.Network.DEV:
|
|
68
|
-
artifacts = dev;
|
|
35
|
+
artifacts = artifacts_1.dev;
|
|
69
36
|
break;
|
|
70
37
|
default:
|
|
71
38
|
throw new Error(`Unsupported network: ${network}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cell } from '@ton/ton';
|
|
2
2
|
import { AbstractProvider, ethers } from 'ethers';
|
|
3
|
-
import { ICrossChainLayer,
|
|
3
|
+
import { ICrossChainLayer, ISAFactory, ISettings, ITokenUtils } from '../../artifacts/tacTypes';
|
|
4
4
|
import { ContractOpener } from '../interfaces';
|
|
5
5
|
import { CurrencyType, ExecutionStagesByOperationId, Network, OperationIdsByShardsKey, OperationType, StatusInfosByOperationId, SuggestedTVMExecutorFee, TACSimulationResult } from './Struct';
|
|
6
6
|
export type ShardMessage = {
|