@tonappchain/sdk 0.7.3-rc1 → 0.7.3-rc3
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/index.d.ts +2 -2
- package/dist/artifacts/dev/index.js +2 -1
- package/dist/artifacts/dev/ton/endpoints.d.ts +1 -0
- package/dist/artifacts/dev/ton/endpoints.js +2 -1
- package/dist/artifacts/mainnet/index.d.ts +2 -2
- package/dist/artifacts/mainnet/index.js +2 -1
- package/dist/artifacts/mainnet/ton/endpoints.d.ts +1 -0
- package/dist/artifacts/mainnet/ton/endpoints.js +2 -1
- package/dist/artifacts/testnet/index.d.ts +2 -2
- package/dist/artifacts/testnet/index.js +2 -1
- package/dist/artifacts/testnet/ton/endpoints.d.ts +1 -0
- package/dist/artifacts/testnet/ton/endpoints.js +2 -1
- package/dist/src/adapters/RetryableContractOpener.d.ts +6 -1
- package/dist/src/adapters/RetryableContractOpener.js +35 -8
- package/dist/src/adapters/ToncenterV3Indexer.d.ts +34 -0
- package/dist/src/adapters/ToncenterV3Indexer.js +123 -0
- package/dist/src/adapters/index.d.ts +1 -0
- package/dist/src/adapters/index.js +1 -0
- package/dist/src/assets/FT.d.ts +3 -2
- package/dist/src/assets/FT.js +30 -14
- package/dist/src/assets/NFT.d.ts +4 -2
- package/dist/src/assets/NFT.js +6 -2
- package/dist/src/assets/TAC.d.ts +2 -1
- package/dist/src/assets/TAC.js +1 -0
- package/dist/src/assets/TON.d.ts +2 -1
- package/dist/src/assets/TON.js +1 -0
- package/dist/src/errors/index.d.ts +1 -1
- package/dist/src/errors/index.js +3 -1
- package/dist/src/errors/instances.d.ts +2 -0
- package/dist/src/errors/instances.js +5 -1
- package/dist/src/interfaces/Asset.d.ts +2 -1
- package/dist/src/interfaces/ContractOpener.d.ts +1 -1
- package/dist/src/interfaces/ILiteSequencerClient.d.ts +8 -2
- package/dist/src/interfaces/IOperationTracker.d.ts +13 -1
- package/dist/src/interfaces/ITACTransactionManager.d.ts +4 -3
- package/dist/src/interfaces/ITacSDK.d.ts +26 -5
- package/dist/src/interfaces/IToncenterV3Indexer.d.ts +35 -0
- package/dist/src/interfaces/IToncenterV3Indexer.js +2 -0
- package/dist/src/interfaces/index.d.ts +1 -0
- package/dist/src/interfaces/index.js +1 -0
- package/dist/src/sdk/Consts.d.ts +13 -0
- package/dist/src/sdk/Consts.js +15 -1
- package/dist/src/sdk/LiteSequencerClient.d.ts +4 -2
- package/dist/src/sdk/LiteSequencerClient.js +29 -13
- package/dist/src/sdk/OperationTracker.d.ts +3 -1
- package/dist/src/sdk/OperationTracker.js +36 -0
- package/dist/src/sdk/Simulator.d.ts +3 -0
- package/dist/src/sdk/Simulator.js +27 -0
- package/dist/src/sdk/TACTransactionManager.d.ts +3 -2
- package/dist/src/sdk/TACTransactionManager.js +45 -35
- package/dist/src/sdk/TacSdk.d.ts +6 -2
- package/dist/src/sdk/TacSdk.js +36 -2
- package/dist/src/sdk/Utils.js +2 -2
- package/dist/src/structs/InternalStruct.d.ts +8 -7
- package/dist/src/structs/Struct.d.ts +64 -2
- package/dist/src/structs/Struct.js +7 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Wallet } from 'ethers';
|
|
2
2
|
import { Asset, IConfiguration, ILogger, IOperationTracker, ITACTransactionManager } from '../interfaces';
|
|
3
|
-
import {
|
|
3
|
+
import { CrossChainTransactionToTONOptions, TACCrossChainTransactionResult } from '../structs/Struct';
|
|
4
4
|
export declare class TACTransactionManager implements ITACTransactionManager {
|
|
5
5
|
private readonly config;
|
|
6
6
|
private readonly operationTracker;
|
|
@@ -8,6 +8,7 @@ export declare class TACTransactionManager implements ITACTransactionManager {
|
|
|
8
8
|
constructor(config: IConfiguration, operationTracker: IOperationTracker, logger?: ILogger);
|
|
9
9
|
private prepareBridgeTokensToTON;
|
|
10
10
|
private approveAsset;
|
|
11
|
-
|
|
11
|
+
private estimateApprovalGas;
|
|
12
|
+
sendCrossChainTransactionToTON(signer: Wallet, tonTarget: string, assets?: Asset[], options?: CrossChainTransactionToTONOptions): Promise<TACCrossChainTransactionResult>;
|
|
12
13
|
bridgeTokensToTON(signer: Wallet, value: bigint, tonTarget: string, assets?: Asset[], tvmExecutorFee?: bigint, tvmValidExecutors?: string[]): Promise<string>;
|
|
13
14
|
}
|
|
@@ -36,7 +36,6 @@ class TACTransactionManager {
|
|
|
36
36
|
this.logger.debug(`Suggested TON executor fee: ${(0, Utils_1.formatObjectForLogging)(suggestedFee)}`);
|
|
37
37
|
tvmExecutorFee = BigInt(suggestedFee.inTAC);
|
|
38
38
|
}
|
|
39
|
-
const crossChainLayerAddress = await this.config.TACParams.crossChainLayer.getAddress();
|
|
40
39
|
const protocolFee = await this.config.TACParams.crossChainLayer.getProtocolFee();
|
|
41
40
|
const shardsKey = BigInt(Math.round(Math.random() * Consts_1.SHARDS_KEY_RANDOM_RANGE));
|
|
42
41
|
this.logger.debug(`Shards key: ${shardsKey}, Protocol fee: ${protocolFee}`);
|
|
@@ -66,29 +65,44 @@ class TACTransactionManager {
|
|
|
66
65
|
toBridgeNFT,
|
|
67
66
|
};
|
|
68
67
|
return {
|
|
69
|
-
crossChainLayerAddress,
|
|
70
68
|
outMessagePayload: this.config.artifacts.tac.utils.encodeOutMessageV1(outMessage),
|
|
71
69
|
totalValue: value + BigInt(outMessage.tvmProtocolFee) + BigInt(outMessage.tvmExecutorFee),
|
|
72
70
|
};
|
|
73
71
|
}
|
|
74
72
|
async approveAsset(asset, signer, spenderAddress, transactionParams = {}) {
|
|
75
73
|
const evmAddress = await asset.getEVMAddress();
|
|
74
|
+
const hasTransactionParams = Object.keys(transactionParams).length > 0;
|
|
76
75
|
if (asset.type === Struct_1.AssetType.FT) {
|
|
77
76
|
this.logger.debug(`Approving FT ${evmAddress} for ${spenderAddress}`);
|
|
78
77
|
const contract = new ethers_1.ethers.Contract(evmAddress, this.config.artifacts.tac.compilationArtifacts.IERC20WithDecimals.abi, this.config.TACParams.provider);
|
|
79
|
-
const tx =
|
|
78
|
+
const tx = hasTransactionParams
|
|
79
|
+
? await contract.connect(signer).approve(spenderAddress, asset.rawAmount, transactionParams)
|
|
80
|
+
: await contract.connect(signer).approve(spenderAddress, asset.rawAmount);
|
|
80
81
|
await tx.wait();
|
|
81
82
|
}
|
|
82
83
|
else {
|
|
83
84
|
this.logger.debug(`Approving NFT ${evmAddress} for ${spenderAddress}`);
|
|
84
85
|
const contract = new ethers_1.ethers.Contract(evmAddress, this.config.artifacts.tac.compilationArtifacts.IERC721.abi, this.config.TACParams.provider);
|
|
85
|
-
const tx =
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
const tx = hasTransactionParams
|
|
87
|
+
? await contract
|
|
88
|
+
.connect(signer)
|
|
89
|
+
.approve(spenderAddress, asset.addresses.index, transactionParams)
|
|
90
|
+
: await contract.connect(signer).approve(spenderAddress, asset.addresses.index);
|
|
88
91
|
await tx.wait();
|
|
89
92
|
}
|
|
90
93
|
this.logger.debug(`Approved ${evmAddress} for ${spenderAddress}`);
|
|
91
94
|
}
|
|
95
|
+
async estimateApprovalGas(asset, signer, spenderAddress, transactionParams = {}) {
|
|
96
|
+
const evmAddress = await asset.getEVMAddress();
|
|
97
|
+
if (asset.type === Struct_1.AssetType.FT) {
|
|
98
|
+
const contract = new ethers_1.ethers.Contract(evmAddress, this.config.artifacts.tac.compilationArtifacts.IERC20WithDecimals.abi, this.config.TACParams.provider);
|
|
99
|
+
return contract.connect(signer).approve.estimateGas(spenderAddress, asset.rawAmount, transactionParams);
|
|
100
|
+
}
|
|
101
|
+
const contract = new ethers_1.ethers.Contract(evmAddress, this.config.artifacts.tac.compilationArtifacts.IERC721.abi, this.config.TACParams.provider);
|
|
102
|
+
return contract
|
|
103
|
+
.connect(signer)
|
|
104
|
+
.approve.estimateGas(spenderAddress, asset.addresses.index, transactionParams);
|
|
105
|
+
}
|
|
92
106
|
async sendCrossChainTransactionToTON(signer, tonTarget, assets = [], options) {
|
|
93
107
|
const signerAddress = signer.address;
|
|
94
108
|
const nativeTACAsset = await assets_1.AssetFactory.from(this.config, {
|
|
@@ -98,21 +112,22 @@ class TACTransactionManager {
|
|
|
98
112
|
let value = 0n;
|
|
99
113
|
const bridgeAssets = [];
|
|
100
114
|
for (const asset of assets) {
|
|
101
|
-
if (asset.origin === Struct_1.Origin.TAC &&
|
|
115
|
+
if (asset.origin === Struct_1.Origin.TAC &&
|
|
116
|
+
asset.type === Struct_1.AssetType.FT &&
|
|
117
|
+
asset.address === nativeTACAsset.address) {
|
|
102
118
|
value += asset.rawAmount;
|
|
103
119
|
continue;
|
|
104
120
|
}
|
|
105
121
|
bridgeAssets.push(asset);
|
|
106
122
|
}
|
|
123
|
+
const crossChainLayerAddress = await this.config.TACParams.crossChainLayer.getAddress();
|
|
107
124
|
const preparedBridge = await this.prepareBridgeTokensToTON(value, tonTarget, bridgeAssets, options?.tvmExecutorFee, options?.tvmValidExecutors);
|
|
108
125
|
const feeData = await this.config.TACParams.provider.getFeeData();
|
|
109
126
|
const maxFeePerGas = feeData.maxFeePerGas;
|
|
110
127
|
if (maxFeePerGas === null) {
|
|
111
128
|
throw (0, errors_1.gasPriceFetchError)('TAC provider did not return maxFeePerGas');
|
|
112
129
|
}
|
|
113
|
-
const latestBlock = await this.config.TACParams.provider
|
|
114
|
-
.getBlock('latest')
|
|
115
|
-
.catch((error) => {
|
|
130
|
+
const latestBlock = await this.config.TACParams.provider.getBlock('latest').catch((error) => {
|
|
116
131
|
throw (0, errors_1.blockGasLimitFetchError)('provider failed to return latest block', error);
|
|
117
132
|
});
|
|
118
133
|
const blockGasLimit = latestBlock?.gasLimit;
|
|
@@ -127,28 +142,26 @@ class TACTransactionManager {
|
|
|
127
142
|
if (shouldValidateAssetsBalance) {
|
|
128
143
|
await Promise.all(bridgeAssets.map((asset) => asset.checkCanBeTransferredBy(signerAddress, Struct_1.BlockchainType.TAC)));
|
|
129
144
|
}
|
|
130
|
-
let
|
|
145
|
+
let requiredApprovalBalance = 0n;
|
|
131
146
|
const approvalPlans = [];
|
|
132
147
|
for (const asset of bridgeAssets) {
|
|
133
|
-
|
|
134
|
-
if (asset.type === Struct_1.AssetType.FT) {
|
|
135
|
-
const contract = new ethers_1.ethers.Contract(await asset.getEVMAddress(), this.config.artifacts.tac.compilationArtifacts.IERC20WithDecimals.abi, this.config.TACParams.provider);
|
|
136
|
-
estimatedGas = await contract
|
|
137
|
-
.connect(signer)
|
|
138
|
-
.approve.estimateGas(preparedBridge.crossChainLayerAddress, asset.rawAmount, transactionParams);
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
const contract = new ethers_1.ethers.Contract(await asset.getEVMAddress(), this.config.artifacts.tac.compilationArtifacts.IERC721.abi, this.config.TACParams.provider);
|
|
142
|
-
estimatedGas = await contract
|
|
143
|
-
.connect(signer)
|
|
144
|
-
.approve.estimateGas(preparedBridge.crossChainLayerAddress, asset.addresses.index, transactionParams);
|
|
145
|
-
}
|
|
148
|
+
const estimatedGas = await this.estimateApprovalGas(asset, signer, crossChainLayerAddress, transactionParams);
|
|
146
149
|
if (estimatedGas > blockGasLimit) {
|
|
147
150
|
throw (0, errors_1.estimatedGasExceedsBlockGasLimitError)('approve', estimatedGas, blockGasLimit);
|
|
148
151
|
}
|
|
149
|
-
|
|
152
|
+
requiredApprovalBalance += estimatedGas * maxFeePerGas;
|
|
150
153
|
approvalPlans.push({ asset, gasLimit: estimatedGas });
|
|
151
154
|
}
|
|
155
|
+
const approvalBalance = await this.config.TACParams.provider.getBalance(signer.address);
|
|
156
|
+
if (approvalBalance < requiredApprovalBalance) {
|
|
157
|
+
throw (0, errors_1.insufficientBalanceError)(Consts_1.TAC_SYMBOL);
|
|
158
|
+
}
|
|
159
|
+
for (const approval of approvalPlans) {
|
|
160
|
+
await this.approveAsset(approval.asset, signer, crossChainLayerAddress, {
|
|
161
|
+
...transactionParams,
|
|
162
|
+
gasLimit: approval.gasLimit,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
152
165
|
const sendMessageGas = await this.config.TACParams.crossChainLayer
|
|
153
166
|
.connect(signer)
|
|
154
167
|
.sendMessage.estimateGas(Consts_1.CROSS_CHAIN_MESSAGE_VERSION_V1, preparedBridge.outMessagePayload, {
|
|
@@ -158,17 +171,11 @@ class TACTransactionManager {
|
|
|
158
171
|
if (sendMessageGas > blockGasLimit) {
|
|
159
172
|
throw (0, errors_1.estimatedGasExceedsBlockGasLimitError)('sendMessage', sendMessageGas, blockGasLimit);
|
|
160
173
|
}
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
if (
|
|
174
|
+
const requiredSendMessageBalance = preparedBridge.totalValue + sendMessageGas * maxFeePerGas;
|
|
175
|
+
const sendMessageBalance = await this.config.TACParams.provider.getBalance(signer.address);
|
|
176
|
+
if (sendMessageBalance < requiredSendMessageBalance) {
|
|
164
177
|
throw (0, errors_1.insufficientBalanceError)(Consts_1.TAC_SYMBOL);
|
|
165
178
|
}
|
|
166
|
-
for (const approval of approvalPlans) {
|
|
167
|
-
await this.approveAsset(approval.asset, signer, preparedBridge.crossChainLayerAddress, {
|
|
168
|
-
...transactionParams,
|
|
169
|
-
gasLimit: approval.gasLimit,
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
179
|
const tx = await this.config.TACParams.crossChainLayer
|
|
173
180
|
.connect(signer)
|
|
174
181
|
.sendMessage(Consts_1.CROSS_CHAIN_MESSAGE_VERSION_V1, preparedBridge.outMessagePayload, {
|
|
@@ -219,7 +226,10 @@ class TACTransactionManager {
|
|
|
219
226
|
}
|
|
220
227
|
async bridgeTokensToTON(signer, value, tonTarget, assets = [], tvmExecutorFee, tvmValidExecutors) {
|
|
221
228
|
this.logger.debug('Bridging tokens to TON');
|
|
222
|
-
|
|
229
|
+
Validator_1.Validator.validateTVMAddress(tonTarget);
|
|
230
|
+
Validator_1.Validator.validateTVMAddresses(tvmValidExecutors);
|
|
231
|
+
const crossChainLayerAddress = await this.config.TACParams.crossChainLayer.getAddress();
|
|
232
|
+
const { outMessagePayload, totalValue } = await this.prepareBridgeTokensToTON(value, tonTarget, assets, tvmExecutorFee, tvmValidExecutors);
|
|
223
233
|
this.logger.debug(`Total value: ${totalValue}`);
|
|
224
234
|
for (const asset of assets) {
|
|
225
235
|
await this.approveAsset(asset, signer, crossChainLayerAddress);
|
package/dist/src/sdk/TacSdk.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { JettonMinterData, NFTItemData } from '../../artifacts/tonTypes';
|
|
|
3
3
|
import { FT, NFT, TAC, TON } from '../assets';
|
|
4
4
|
import { ContractOpener, IConfiguration, ILogger, IOperationTracker, ITacExplorerClient, ITacSDK } from '../interfaces';
|
|
5
5
|
import type { SenderAbstraction } from '../sender';
|
|
6
|
-
import { AssetFromFTArg, AssetFromNFTCollectionArg, AssetFromNFTItemArg, AssetLike, BatchCrossChainTxWithAssetLike,
|
|
6
|
+
import { AssetFromFTArg, AssetFromNFTCollectionArg, AssetFromNFTItemArg, AssetLike, BatchCrossChainTxWithAssetLike, CrossChainPayloadResult, CrossChainTransactionOptions, CrossChainTransactionsOptions, CrossChainTransactionToTONOptions, CrosschainTx, EVMAddress, EvmProxyMsg, ExecutionFeeEstimationResult, NFTAddressType, SDKParams, SuggestedTVMExecutorFee, TACCrossChainTransactionResult, TacGasPrice, TACSimulationParams, TACSimulationResult, TransactionLinkerWithOperationId, TVMAddress, UserWalletBalanceExtended, WaitOptions } from '../structs/Struct';
|
|
7
7
|
export declare class TacSdk implements ITacSDK {
|
|
8
8
|
readonly config: IConfiguration;
|
|
9
9
|
readonly contactOpener: ContractOpener;
|
|
@@ -12,6 +12,7 @@ export declare class TacSdk implements ITacSDK {
|
|
|
12
12
|
private readonly simulator;
|
|
13
13
|
private readonly tonTransactionManager;
|
|
14
14
|
private readonly tacTransactionManager;
|
|
15
|
+
private readonly tonIndexer;
|
|
15
16
|
private constructor();
|
|
16
17
|
static create(sdkParams: SDKParams, logger?: ILogger): Promise<TacSdk>;
|
|
17
18
|
closeConnections(): unknown;
|
|
@@ -23,8 +24,10 @@ export declare class TacSdk implements ITacSDK {
|
|
|
23
24
|
getSimulationInfo(evmProxyMsg: EvmProxyMsg, sender: SenderAbstraction, assets?: AssetLike[], options?: CrossChainTransactionOptions): Promise<ExecutionFeeEstimationResult>;
|
|
24
25
|
getTVMExecutorFeeInfo(assets: AssetLike[], feeSymbol: string, tvmValidExecutors?: string[]): Promise<SuggestedTVMExecutorFee>;
|
|
25
26
|
sendCrossChainTransaction(evmProxyMsg: EvmProxyMsg, sender: SenderAbstraction, assets?: AssetLike[], options?: CrossChainTransactionOptions): Promise<TransactionLinkerWithOperationId>;
|
|
26
|
-
sendCrossChainTransactionToTON(signer: Wallet, tonTarget: string, assets?: AssetLike[], options?:
|
|
27
|
+
sendCrossChainTransactionToTON(signer: Wallet, tonTarget: string, assets?: AssetLike[], options?: CrossChainTransactionToTONOptions): Promise<TACCrossChainTransactionResult>;
|
|
27
28
|
sendCrossChainTransactions(sender: SenderAbstraction, txs: BatchCrossChainTxWithAssetLike[], options?: CrossChainTransactionsOptions): Promise<TransactionLinkerWithOperationId[]>;
|
|
29
|
+
getOperationIdByTonTransactionHash(transactionHash: string, waitOptions?: WaitOptions<string> | null): Promise<string>;
|
|
30
|
+
getOperationIdByTonTransactionBoc(boc: string, waitOptions?: WaitOptions<string> | null): Promise<string>;
|
|
28
31
|
bridgeTokensToTON(signer: Wallet, value: bigint, tonTarget: string, assets?: AssetLike[], tvmExecutorFee?: bigint, tvmValidExecutors?: string[]): Promise<string>;
|
|
29
32
|
isContractDeployedOnTVM(address: string): Promise<boolean>;
|
|
30
33
|
simulateTACMessage(req: TACSimulationParams): Promise<TACSimulationResult>;
|
|
@@ -48,4 +51,5 @@ export declare class TacSdk implements ITacSDK {
|
|
|
48
51
|
prepareCrossChainTransactionPayload(evmProxyMsg: EvmProxyMsg, senderAddress: string, assets?: AssetLike[], options?: CrossChainTransactionOptions): Promise<CrossChainPayloadResult[]>;
|
|
49
52
|
getTACGasPrice(): Promise<TacGasPrice>;
|
|
50
53
|
getTonContractOpener(): ContractOpener;
|
|
54
|
+
private toSequencerTonTransactionHash;
|
|
51
55
|
}
|
package/dist/src/sdk/TacSdk.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TacSdk = void 0;
|
|
4
|
+
const ton_1 = require("@ton/ton");
|
|
4
5
|
const artifacts_1 = require("../../artifacts");
|
|
6
|
+
const adapters_1 = require("../adapters");
|
|
5
7
|
const assets_1 = require("../assets");
|
|
8
|
+
const errors_1 = require("../errors");
|
|
6
9
|
const Struct_1 = require("../structs/Struct");
|
|
7
10
|
const Configuration_1 = require("./Configuration");
|
|
8
11
|
const Consts_1 = require("./Consts");
|
|
@@ -14,7 +17,7 @@ const TACTransactionManager_1 = require("./TACTransactionManager");
|
|
|
14
17
|
const TONTransactionManager_1 = require("./TONTransactionManager");
|
|
15
18
|
const Utils_1 = require("./Utils");
|
|
16
19
|
class TacSdk {
|
|
17
|
-
constructor(config, simulator, tonTransactionManager, tacTransactionManager, operationTracker, explorerClient) {
|
|
20
|
+
constructor(config, simulator, tonTransactionManager, tacTransactionManager, operationTracker, explorerClient, tonIndexer) {
|
|
18
21
|
this.config = config;
|
|
19
22
|
this.contactOpener = config.TONParams.contractOpener;
|
|
20
23
|
this.simulator = simulator;
|
|
@@ -22,6 +25,7 @@ class TacSdk {
|
|
|
22
25
|
this.tacTransactionManager = tacTransactionManager;
|
|
23
26
|
this.operationTracker = operationTracker;
|
|
24
27
|
this.explorerClient = explorerClient;
|
|
28
|
+
this.tonIndexer = tonIndexer;
|
|
25
29
|
}
|
|
26
30
|
static async create(sdkParams, logger = new Logger_1.NoopLogger()) {
|
|
27
31
|
const network = sdkParams.network;
|
|
@@ -47,7 +51,8 @@ class TacSdk {
|
|
|
47
51
|
const simulator = new Simulator_1.Simulator(config, operationTracker, logger);
|
|
48
52
|
const tonTransactionManager = new TONTransactionManager_1.TONTransactionManager(config, simulator, operationTracker, logger);
|
|
49
53
|
const tacTransactionManager = new TACTransactionManager_1.TACTransactionManager(config, operationTracker, logger);
|
|
50
|
-
|
|
54
|
+
const tonIndexer = sdkParams.TONParams?.tonIndexer ?? new adapters_1.ToncenterV3Indexer(artifacts.TONCENTER_V3_INDEXER_ENDPOINT);
|
|
55
|
+
return new TacSdk(config, simulator, tonTransactionManager, tacTransactionManager, operationTracker, explorerClient, tonIndexer);
|
|
51
56
|
}
|
|
52
57
|
closeConnections() {
|
|
53
58
|
return this.config.closeConnections();
|
|
@@ -99,6 +104,32 @@ class TacSdk {
|
|
|
99
104
|
})));
|
|
100
105
|
return this.tonTransactionManager.sendCrossChainTransactions(sender, normalizedTxs, options);
|
|
101
106
|
}
|
|
107
|
+
async getOperationIdByTonTransactionHash(transactionHash, waitOptions) {
|
|
108
|
+
const cclTransaction = await this.tonIndexer.findCollectibleCrossChainLayerTransaction(transactionHash, this.config.TONParams.crossChainLayerAddress);
|
|
109
|
+
if (!cclTransaction) {
|
|
110
|
+
return '';
|
|
111
|
+
}
|
|
112
|
+
return this.operationTracker.getOperationIdByTonTransactionHash(this.toSequencerTonTransactionHash(cclTransaction), waitOptions);
|
|
113
|
+
}
|
|
114
|
+
async getOperationIdByTonTransactionBoc(boc, waitOptions) {
|
|
115
|
+
let message;
|
|
116
|
+
try {
|
|
117
|
+
message = (0, ton_1.loadMessage)(ton_1.Cell.fromBase64(boc).beginParse());
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
const reason = error instanceof Error ? error.message : undefined;
|
|
121
|
+
throw (0, errors_1.invalidTonExternalMessageBocError)(reason);
|
|
122
|
+
}
|
|
123
|
+
if (message.info.type !== 'external-in') {
|
|
124
|
+
throw (0, errors_1.externalInMessageRequiredError)(message.info.type);
|
|
125
|
+
}
|
|
126
|
+
const destination = message.info.dest;
|
|
127
|
+
const transaction = await this.contactOpener.getTransactionByHash(ton_1.Address.parse(destination.toString()), (0, Utils_1.getNormalizedExtMessageHash)(message));
|
|
128
|
+
if (!transaction) {
|
|
129
|
+
return '';
|
|
130
|
+
}
|
|
131
|
+
return this.getOperationIdByTonTransactionHash(transaction.hash().toString('base64'), waitOptions);
|
|
132
|
+
}
|
|
102
133
|
async bridgeTokensToTON(signer, value, tonTarget, assets, tvmExecutorFee, tvmValidExecutors) {
|
|
103
134
|
const normalizedAssets = await (0, Utils_1.normalizeAssets)(this.config, assets);
|
|
104
135
|
return this.tacTransactionManager.bridgeTokensToTON(signer, value, tonTarget, normalizedAssets, tvmExecutorFee, tvmValidExecutors);
|
|
@@ -204,5 +235,8 @@ class TacSdk {
|
|
|
204
235
|
getTonContractOpener() {
|
|
205
236
|
return this.contactOpener;
|
|
206
237
|
}
|
|
238
|
+
toSequencerTonTransactionHash(transaction) {
|
|
239
|
+
return `0x${(0, Utils_1.normalizeHashToHex)(transaction.hash)}`;
|
|
240
|
+
}
|
|
207
241
|
}
|
|
208
242
|
exports.TacSdk = TacSdk;
|
package/dist/src/sdk/Utils.js
CHANGED
|
@@ -416,7 +416,7 @@ function decodeBase64Like(input) {
|
|
|
416
416
|
}
|
|
417
417
|
function getNormalizedExtMessageHash(message) {
|
|
418
418
|
if (message.info.type !== 'external-in') {
|
|
419
|
-
throw
|
|
419
|
+
throw (0, errors_1.externalInMessageRequiredError)(message.info.type);
|
|
420
420
|
}
|
|
421
421
|
const info = {
|
|
422
422
|
...message.info,
|
|
@@ -460,5 +460,5 @@ function recurisivelyCollectCellStats(cell) {
|
|
|
460
460
|
return { bits, cells };
|
|
461
461
|
}
|
|
462
462
|
function isFinalProfiling(profilingData) {
|
|
463
|
-
return profilingData.operationType !== Struct_1.OperationType.PENDING && profilingData.operationType !== Struct_1.OperationType.UNKNOWN;
|
|
463
|
+
return (profilingData.operationType !== Struct_1.OperationType.PENDING && profilingData.operationType !== Struct_1.OperationType.UNKNOWN);
|
|
464
464
|
}
|
|
@@ -2,7 +2,7 @@ import { Address, Cell } from '@ton/ton';
|
|
|
2
2
|
import { AbstractProvider, ethers } from 'ethers';
|
|
3
3
|
import { ICrossChainLayer, ISAFactory, ISettings, ITokenUtils } from '../../artifacts/tacTypes';
|
|
4
4
|
import { ContractOpener } from '../interfaces';
|
|
5
|
-
import { CurrencyType, ExecutionStagesByOperationId, ExecutionStagesV2ByOperationId, Network, OperationIdsByShardsKey, OperationType, OperationTypeV2Info, StatusInfosByOperationId, SuggestedTVMExecutorFee, TACSimulationResult, TransactionLinker } from './Struct';
|
|
5
|
+
import { CurrencyType, ExecutionStagesByOperationId, ExecutionStagesV2ByOperationId, Network, OperationIdsByShardsKey, OperationIdWithLogIndex, OperationType, OperationTypeV2Info, StatusInfosByOperationId, SuggestedTVMExecutorFee, TACSimulationResult, ToncenterV3IndexedTransaction, TransactionLinker } from './Struct';
|
|
6
6
|
export type ShardMessage = {
|
|
7
7
|
address: string;
|
|
8
8
|
value: bigint;
|
|
@@ -22,7 +22,6 @@ export type PreparedCrossChainTransaction = {
|
|
|
22
22
|
transactionLinker: TransactionLinker;
|
|
23
23
|
};
|
|
24
24
|
export type PreparedBridgeTokensToTON = {
|
|
25
|
-
crossChainLayerAddress: string;
|
|
26
25
|
outMessagePayload: ethers.BytesLike;
|
|
27
26
|
totalValue: bigint;
|
|
28
27
|
};
|
|
@@ -71,11 +70,7 @@ export type StageProfilingV2Response = ResponseBase<ExecutionStagesV2ByOperation
|
|
|
71
70
|
export type TACSimulationResponse = ResponseBase<TACSimulationResult>;
|
|
72
71
|
export type SuggestedTVMExecutorFeeResponse = ResponseBase<SuggestedTVMExecutorFee>;
|
|
73
72
|
export type ConvertCurrencyResponse = ResponseBase<ConvertedCurrencyRawResult>;
|
|
74
|
-
export type
|
|
75
|
-
operationId: string;
|
|
76
|
-
logIndex: number;
|
|
77
|
-
};
|
|
78
|
-
export type OperationIdWithLogIndexResponse = ResponseBase<OperationIdWithLogIndex>;
|
|
73
|
+
export type OperationIdWithLogIndexResponse = ResponseBase<OperationIdWithLogIndex[]>;
|
|
79
74
|
export interface SendResult {
|
|
80
75
|
success: boolean;
|
|
81
76
|
boc: string;
|
|
@@ -138,6 +133,12 @@ export type TransactionDepth = {
|
|
|
138
133
|
export type AdjacentTransactionsResponse = {
|
|
139
134
|
transactions: ToncenterTransaction[];
|
|
140
135
|
};
|
|
136
|
+
export type TonAdjacentTransactionsResponse = {
|
|
137
|
+
transactions: ToncenterV3IndexedTransaction[];
|
|
138
|
+
};
|
|
139
|
+
export type ToncenterV3TransactionsResponse = {
|
|
140
|
+
transactions: ToncenterV3IndexedTransaction[];
|
|
141
|
+
};
|
|
141
142
|
export type TxFinalizerConfig = {
|
|
142
143
|
urlBuilder: (hash: string) => string;
|
|
143
144
|
authorization?: {
|
|
@@ -3,7 +3,7 @@ import { Cell, OpenedContract } from '@ton/ton';
|
|
|
3
3
|
import { AbstractProvider } from 'ethers';
|
|
4
4
|
import { JettonMinter, JettonMinterData } from '../../artifacts/tonTypes';
|
|
5
5
|
import type { FT, NFT } from '../assets';
|
|
6
|
-
import type { Asset, ContractOpener, ILogger } from '../interfaces';
|
|
6
|
+
import type { Asset, ContractOpener, ILogger, IToncenterV3Indexer } from '../interfaces';
|
|
7
7
|
import { SendResult } from './InternalStruct';
|
|
8
8
|
export type ContractState = {
|
|
9
9
|
balance: bigint;
|
|
@@ -61,6 +61,11 @@ export type TONParams = {
|
|
|
61
61
|
* Provider for TON side. Use your own provider for tests or to increase ratelimit
|
|
62
62
|
*/
|
|
63
63
|
contractOpener?: ContractOpener;
|
|
64
|
+
/**
|
|
65
|
+
* Indexed Toncenter v3 client used to resolve TON transaction context by hash.
|
|
66
|
+
* Use your own implementation for tests or custom indexed backends.
|
|
67
|
+
*/
|
|
68
|
+
tonIndexer?: IToncenterV3Indexer;
|
|
64
69
|
/**
|
|
65
70
|
* Address of TON settings contract. Use only for tests.
|
|
66
71
|
*/
|
|
@@ -182,6 +187,54 @@ export type StageData = {
|
|
|
182
187
|
export type StatusInfo = StageData & {
|
|
183
188
|
stage: StageName;
|
|
184
189
|
};
|
|
190
|
+
/**
|
|
191
|
+
* Indexed transaction returned by Toncenter v3 `/transactions` and `/adjacentTransactions` endpoints.
|
|
192
|
+
*/
|
|
193
|
+
export type ToncenterV3IndexedTransaction = {
|
|
194
|
+
/** Account address that owns the transaction. */
|
|
195
|
+
account: string;
|
|
196
|
+
/** Indexed TON transaction hash. */
|
|
197
|
+
hash: string;
|
|
198
|
+
/** Optional trace identifier returned by Toncenter v3. */
|
|
199
|
+
traceId?: string;
|
|
200
|
+
/** Incoming message of the indexed transaction, when present in the response. */
|
|
201
|
+
inMsg?: {
|
|
202
|
+
/** Message source address. */
|
|
203
|
+
source?: string | null;
|
|
204
|
+
/** Message destination address. */
|
|
205
|
+
destination?: string | null;
|
|
206
|
+
/** Opcode reported by Toncenter v3 for the incoming message. */
|
|
207
|
+
opcode?: string | null;
|
|
208
|
+
/** Raw message content returned by Toncenter v3. */
|
|
209
|
+
messageContent?: {
|
|
210
|
+
/** BOC-encoded message body in base64 form. */
|
|
211
|
+
body?: string | null;
|
|
212
|
+
} | null;
|
|
213
|
+
} | null;
|
|
214
|
+
/** Outgoing messages of the indexed transaction. */
|
|
215
|
+
outMsgs: Array<{
|
|
216
|
+
/** Message destination address. `null` means external outbound log message. */
|
|
217
|
+
destination?: string | null;
|
|
218
|
+
/** Raw message content returned by Toncenter v3. */
|
|
219
|
+
messageContent?: {
|
|
220
|
+
/** BOC-encoded message body in base64 form. */
|
|
221
|
+
body?: string | null;
|
|
222
|
+
} | null;
|
|
223
|
+
}>;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Traversal settings for indexed search through a linked TON transaction chain in Toncenter v3.
|
|
227
|
+
*/
|
|
228
|
+
export type ToncenterV3TraversalParams = {
|
|
229
|
+
/**
|
|
230
|
+
* Maximum traversal depth from the starting transaction in the linked TON transaction chain.
|
|
231
|
+
*/
|
|
232
|
+
maxDepth?: number;
|
|
233
|
+
/**
|
|
234
|
+
* Maximum number of unique indexed transactions to inspect.
|
|
235
|
+
*/
|
|
236
|
+
maxScannedTransactions?: number;
|
|
237
|
+
};
|
|
185
238
|
export type ProfilingStageData = {
|
|
186
239
|
exists: boolean;
|
|
187
240
|
stageData: StageData | null;
|
|
@@ -257,6 +310,10 @@ export type StatusInfosByOperationId = Record<string, StatusInfo>;
|
|
|
257
310
|
export type OperationIds = {
|
|
258
311
|
operationIds: string[];
|
|
259
312
|
};
|
|
313
|
+
export type OperationIdWithLogIndex = {
|
|
314
|
+
operationId: string;
|
|
315
|
+
logIndex: number;
|
|
316
|
+
};
|
|
260
317
|
export type OperationIdsByShardsKey = Record<string, OperationIds>;
|
|
261
318
|
export type TACSimulationResult = {
|
|
262
319
|
estimatedGas: bigint;
|
|
@@ -419,7 +476,7 @@ export type CrossChainTransactionsOptions = {
|
|
|
419
476
|
waitOperationIds?: boolean;
|
|
420
477
|
waitOptions?: WaitOptions<OperationIdsByShardsKey>;
|
|
421
478
|
};
|
|
422
|
-
export type
|
|
479
|
+
export type CrossChainTransactionToTONOptions = {
|
|
423
480
|
/**
|
|
424
481
|
* Optional explicit TON-side executor fee.
|
|
425
482
|
* When omitted, the SDK calls OperationTracker.getTVMExecutorFee().
|
|
@@ -541,6 +598,11 @@ export declare enum Origin {
|
|
|
541
598
|
TON = "TON",
|
|
542
599
|
TAC = "TAC"
|
|
543
600
|
}
|
|
601
|
+
export declare enum AssetFeeMode {
|
|
602
|
+
TAC_ORIGINAL = "TAC_ORIGINAL",
|
|
603
|
+
LEGACY = "LEGACY",
|
|
604
|
+
DYNAMIC = "DYNAMIC"
|
|
605
|
+
}
|
|
544
606
|
export type TVMAddress = string;
|
|
545
607
|
export type EVMAddress = string;
|
|
546
608
|
export type AssetFromFTArg = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TransactionTreeDirection = exports.Origin = exports.defaultWaitOptions = exports.TokenSymbol = exports.StageName = exports.NFTAddressType = exports.AssetType = exports.OperationExecutionStatus = exports.OperationType = exports.CurrencyType = exports.BlockchainType = exports.Network = exports.SimplifiedStatuses = void 0;
|
|
3
|
+
exports.TransactionTreeDirection = exports.AssetFeeMode = exports.Origin = exports.defaultWaitOptions = exports.TokenSymbol = exports.StageName = exports.NFTAddressType = exports.AssetType = exports.OperationExecutionStatus = exports.OperationType = exports.CurrencyType = exports.BlockchainType = exports.Network = exports.SimplifiedStatuses = void 0;
|
|
4
4
|
const Consts_1 = require("../sdk/Consts");
|
|
5
5
|
var SimplifiedStatuses;
|
|
6
6
|
(function (SimplifiedStatuses) {
|
|
@@ -73,6 +73,12 @@ var Origin;
|
|
|
73
73
|
Origin["TON"] = "TON";
|
|
74
74
|
Origin["TAC"] = "TAC";
|
|
75
75
|
})(Origin || (exports.Origin = Origin = {}));
|
|
76
|
+
var AssetFeeMode;
|
|
77
|
+
(function (AssetFeeMode) {
|
|
78
|
+
AssetFeeMode["TAC_ORIGINAL"] = "TAC_ORIGINAL";
|
|
79
|
+
AssetFeeMode["LEGACY"] = "LEGACY";
|
|
80
|
+
AssetFeeMode["DYNAMIC"] = "DYNAMIC";
|
|
81
|
+
})(AssetFeeMode || (exports.AssetFeeMode = AssetFeeMode = {}));
|
|
76
82
|
var TransactionTreeDirection;
|
|
77
83
|
(function (TransactionTreeDirection) {
|
|
78
84
|
TransactionTreeDirection["FORWARD"] = "forward";
|