@tonappchain/sdk 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1197 -0
- package/dist/adapters/contractOpener.d.ts +19 -0
- package/dist/adapters/contractOpener.js +94 -0
- package/dist/errors/errors.d.ts +34 -0
- package/dist/errors/errors.js +80 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +30 -0
- package/dist/errors/instances.d.ts +16 -0
- package/dist/errors/instances.js +28 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +35 -0
- package/dist/sdk/Consts.d.ts +6 -0
- package/dist/sdk/Consts.js +10 -0
- package/dist/sdk/OperationTracker.d.ts +15 -0
- package/dist/sdk/OperationTracker.js +128 -0
- package/dist/sdk/StartTracking.d.ts +2 -0
- package/dist/sdk/StartTracking.js +91 -0
- package/dist/sdk/TacSdk.d.ts +36 -0
- package/dist/sdk/TacSdk.js +361 -0
- package/dist/sdk/Utils.d.ts +18 -0
- package/dist/sdk/Utils.js +126 -0
- package/dist/sender/RawSender.d.ts +13 -0
- package/dist/sender/RawSender.js +37 -0
- package/dist/sender/SenderAbstraction.d.ts +19 -0
- package/dist/sender/SenderAbstraction.js +5 -0
- package/dist/sender/SenderFactory.d.ts +33 -0
- package/dist/sender/SenderFactory.js +51 -0
- package/dist/sender/TonConnectSender.d.ts +10 -0
- package/dist/sender/TonConnectSender.js +33 -0
- package/dist/sender/index.d.ts +2 -0
- package/dist/sender/index.js +18 -0
- package/dist/structs/InternalStruct.d.ts +52 -0
- package/dist/structs/InternalStruct.js +8 -0
- package/dist/structs/Struct.d.ts +210 -0
- package/dist/structs/Struct.js +15 -0
- package/dist/wrappers/ContentUtils.d.ts +25 -0
- package/dist/wrappers/ContentUtils.js +160 -0
- package/dist/wrappers/HighloadQueryId.d.ts +17 -0
- package/dist/wrappers/HighloadQueryId.js +72 -0
- package/dist/wrappers/HighloadWalletV3.d.ts +61 -0
- package/dist/wrappers/HighloadWalletV3.js +161 -0
- package/dist/wrappers/JettonMaster.d.ts +24 -0
- package/dist/wrappers/JettonMaster.js +52 -0
- package/dist/wrappers/JettonWallet.d.ts +46 -0
- package/dist/wrappers/JettonWallet.js +103 -0
- package/dist/wrappers/Settings.d.ts +10 -0
- package/dist/wrappers/Settings.js +38 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,1197 @@
|
|
|
1
|
+
# TAC-SDK
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@tonappchain/sdk)
|
|
4
|
+
|
|
5
|
+
**TAC-SDK** is an SDK for facilitating crosschain operations from TVM (TON Virtual Machine) to EVM-compatible blockchains. It is designed to simplify crosschain interactions for EVM developers by enabling transactions from TVM to EVM with minimal configuration.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
This SDK allows EVM developers to perform crosschain operations without needing an in-depth understanding of TON. By specifying the following details, the SDK will generate the necessary transactions:
|
|
10
|
+
|
|
11
|
+
**For EVM:**
|
|
12
|
+
1. The ProxyDapp address to interact with.
|
|
13
|
+
2. The method to call on the contract.
|
|
14
|
+
3. Any encoded parameters required for the contract method.
|
|
15
|
+
|
|
16
|
+
**For TVM:**
|
|
17
|
+
1. Addresses of TVM Jettons corresponding to EVM tokens.
|
|
18
|
+
|
|
19
|
+
Using these inputs, the SDK builds a TON transaction payload and enables further signature processing through TON-Connect or directly via mnemonic.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
**TON:**
|
|
26
|
+
- Get user jetton balance
|
|
27
|
+
- Generate TON transaction payloads for crosschain operations and transfer jettons
|
|
28
|
+
- Get `operationId` with `transactionLinker` struct
|
|
29
|
+
- Track operation status using `operationId`
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Sharded Messages
|
|
34
|
+
|
|
35
|
+
Due to the specific architecture of TVM, it’s not possible to send multiple tokens in a single transaction. Therefore, transactions are handled using a sharded messaging system, where each message is linked on the validator side using a unique triplet: `(caller, ShardsKey, ShardCount)`. This system is particularly useful for complex operations like liquidity providing, where multiple tokens need to be transferred on the TON side.
|
|
36
|
+
|
|
37
|
+
**Example:**
|
|
38
|
+
- **Liquidity Providing:** To add liquidity, two tokens need to be transferred on the TON side. Each token transfer is sent as an individual sharded message, which validators process and link together.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## How to Track the Status of an Operation
|
|
43
|
+
|
|
44
|
+
To track an operation, you first need to obtain its `operationId`. The `operationId` can be retrieved using the `transactionLinker` structure, which is generated within the SDK and returned by the `sendCrossChainTransaction` function. Once you have the `transactionLinker`, call `OperationTracker.getOperationId(transactionLinker: TransactionLinker)`.
|
|
45
|
+
|
|
46
|
+
> **Note:** An empty response string indicates that validators have not yet received your messages. Continue making requests until you receive a non-empty `operationId`.
|
|
47
|
+
|
|
48
|
+
After obtaining the `operationId`, you can check the operation’s status by using `OperationTracker.getOperationStatus(operationId: string)`. The following statuses may be returned:
|
|
49
|
+
|
|
50
|
+
1. **EVMMerkleMessageCollected:** The validator has collected all events for a single sharded message. For simple transfers (e.g., a token swap), this status indicates that the message is fully gathered.
|
|
51
|
+
2. **EVMMerkleRootSet:** The EVM message has been added to the Merkle tree, and subsequent roots will reflect this addition.
|
|
52
|
+
3. **EVMMerkleMessageExecuted:** The collected message has been executed on the EVM side.
|
|
53
|
+
4. **TVMMerkleMessageCollected:** After execution on EVM, a return message event is generated, which will then be executed on the TVM side.
|
|
54
|
+
5. **TVMMerkleRootSet:** The TVM message has been added to the Merkle tree, updating future roots accordingly.
|
|
55
|
+
6. **TVMMerkleMessageExecuted:** The TVM Merkle message has been successfully executed on the TVM CrossChainLayer.
|
|
56
|
+
|
|
57
|
+
If an issue occurs, the error message will also be included in response.
|
|
58
|
+
|
|
59
|
+
### Terminal State
|
|
60
|
+
- **TVMMerkleMessageExecuted**: Indicates that the operation has completed its full cycle from TVM to EVM and back.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Install
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npm install @tonappchain/sdk
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Functionality description
|
|
73
|
+
The `TacSdk` class is designed for performing crosschain operations, particularly bridging Jetton tokens for interaction with the TAC.
|
|
74
|
+
|
|
75
|
+
### Creating an Instance of `TacSdk`
|
|
76
|
+
|
|
77
|
+
To use the `TacSdk` class, create it with the required parameters encapsulated in the `SDKParams` object (you can also specify custom params for TAC and TON by `TACParams` and `TONParams`):
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { TacSdk } from '@tonappchain/sdk';
|
|
81
|
+
import { Network } from '@tonappchain/sdk';
|
|
82
|
+
|
|
83
|
+
const sdkParams: SDKParams = {
|
|
84
|
+
network: Network.Testnet
|
|
85
|
+
// you can also customize TAC and TON params here
|
|
86
|
+
};
|
|
87
|
+
const tacSdk = await TacSdk.create(sdkParams);
|
|
88
|
+
```
|
|
89
|
+
> **Note:** By default Orbs Network is used as TON provider
|
|
90
|
+
|
|
91
|
+
Optionally, only in NodeJS you can provide custom liteservers client for TON blockchain in `contractOpener` argument:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { TacSdk, Network, liteClientOpener } from '@tonappchain/sdk';
|
|
95
|
+
|
|
96
|
+
// Ex.: your own lite clients for TON
|
|
97
|
+
const liteClientServers = [<liteClientServer1>, <liteClientServer1>, ...];
|
|
98
|
+
|
|
99
|
+
const sdkParams: SDKParams = {
|
|
100
|
+
network: Network.Testnet,
|
|
101
|
+
TONParams: {
|
|
102
|
+
contractOpener: await liteClientOpener({ liteservers : liteClientServers }),
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const tacSdk = await TacSdk.create(sdkParams);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
*ATTENTION:* don't forget to close the connections after all the work is done, otherwise the script will hang:
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
tacSdk.closeConnections();
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Optionally, you can provide @ton/ton TonClient (public endpoints will be used by default):
|
|
116
|
+
|
|
117
|
+
- **Mainnet**: https://toncenter.com/api/v2/jsonRPC
|
|
118
|
+
- **Testnet**: https://testnet.toncenter.com/api/v2/jsonRPC
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { TacSdk, Network } from '@tonappchain/sdk';
|
|
122
|
+
import { TonClient } from '@ton/ton';
|
|
123
|
+
|
|
124
|
+
const sdk = await TacSdk.create({
|
|
125
|
+
network: Network.Testnet,
|
|
126
|
+
delay: 1,
|
|
127
|
+
TONParams: {
|
|
128
|
+
contractOpener: new TonClient({
|
|
129
|
+
endpoint: "https://testnet.toncenter.com/api/v2/jsonRPC",
|
|
130
|
+
// apiKey: "your_api_key"
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const tacSdk = await TacSdk.create(sdkParams);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### Possible exceptions
|
|
139
|
+
|
|
140
|
+
- **`SettingError`**: settings contract at provided address does not contain required setting key.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
### Function: `closeConnections`
|
|
145
|
+
|
|
146
|
+
This function stops all connections to the network, such as Ton Liteservers, and should be called after all operations are completed. Can be used if you use custom contract opener and need to close connections manually.
|
|
147
|
+
|
|
148
|
+
### Function: `sendCrossChainTransaction`
|
|
149
|
+
|
|
150
|
+
This function facilitates crosschain operations by bridging data and assets from TON for interaction with TAC. Creates a transaction on the TON side that is sent to the TAC protocol address. This starts the crosschain operation. Works with TON native coin transfer and/or it handles the required logic for burning or transferring jettons based on the Jetton type(wrapped by our s-c CrossChainLayer or not).
|
|
151
|
+
|
|
152
|
+
#### **Purpose**
|
|
153
|
+
|
|
154
|
+
The `sendCrossChainTransaction` method is the core functionality of the `TacSdk` class, enabling the bridging of assets (or just data) to execute crosschain operations seamlessly.
|
|
155
|
+
|
|
156
|
+
#### **Parameters**
|
|
157
|
+
|
|
158
|
+
- **`evmProxyMsg`**: An `EvmProxyMsg` object defining the EVM-specific logic:
|
|
159
|
+
- **`evmTargetAddress`**: Target address on the EVM network.
|
|
160
|
+
- **`methodName`** *(optional)*: Method name to execute on the target contract. Either method name `MethodName` or signature `MethodName(bytes,bytes)` must be specified (strictly (bytes,bytes)).
|
|
161
|
+
- **`encodedParameters`** *(optional)*: Encoded parameters for the EVM method. You need to specify all arguments except the first one (TACHeader bytes). The TACHeader logic will be specified below
|
|
162
|
+
|
|
163
|
+
- **`sender`**: A `SenderAbstraction` object, such as:
|
|
164
|
+
- **`TonConnectSender`**: For TonConnect integration.
|
|
165
|
+
- **`RawSender`**: For raw wallet transactions using a mnemonic.
|
|
166
|
+
|
|
167
|
+
- **`assets`** *(optional)*: An array of `AssetBridgingData` objects, each specifying the Assets details:
|
|
168
|
+
- **`address`** *(optional)*: Address of the Asset.
|
|
169
|
+
- **`rawAmount`** *(required if `amount` is not specified): Amount of Assets to be transferred taking into account the number of decimals.
|
|
170
|
+
- **`amount`** *(required if `rawAmount` is not specified): Amount of Assets to be transferred.
|
|
171
|
+
- **`decimals`** *(optional)*: Number of decimals for the asset. If not specified, the SDK will attempt to extract the decimals from the chain.
|
|
172
|
+
|
|
173
|
+
> **Note:** If you specify methodName and encodedParameters and don't specify assets this will mean sending any data (contract call) to evmTargetAddress.
|
|
174
|
+
|
|
175
|
+
> **Note:** If you don't specify methodName and encodedParameters and specify assets this will mean bridge any assets to evmTargetAddress (be sure to specify assets when doing this).
|
|
176
|
+
|
|
177
|
+
#### **Returns**
|
|
178
|
+
|
|
179
|
+
- **`Promise<TransactionLinker>`**:
|
|
180
|
+
- A `TransactionLinker` object for linking TON transaction and crosschain operation as well as for tracking crosschain operation status
|
|
181
|
+
|
|
182
|
+
#### **Possible exceptions**
|
|
183
|
+
|
|
184
|
+
- **`ContractError`**: contract for given jetton is not deployed on TVM side.
|
|
185
|
+
- **`AddressError`**: invalid token address provided.
|
|
186
|
+
|
|
187
|
+
#### **Functionality**
|
|
188
|
+
|
|
189
|
+
1. Determines whether each Jetton requires a **burn** or **transfer** operation based on its type.
|
|
190
|
+
2. Prepares shard messages and encodes the necessary payloads.
|
|
191
|
+
3. Bridges Jettons by sending shard transactions to the appropriate smart contracts.
|
|
192
|
+
4. Incorporates EVM logic into the payload for interaction with the TAC.
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
### TACHeader
|
|
196
|
+
> **Note:** The TAC protocol only knows how to send data to contracts that inherit from a TacProxy (TacProxyV1) contract. Such a contract must have a strictly defined signature of its methods. It is specified below:
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
function myProxyFunction(bytes calldata tacHeader, bytes calldata arguments) external onlyTacCCL {
|
|
200
|
+
// Function implementation
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
> **Note:** methodName in `evmProxyMsg` must be either a simple method name or a signature of the form MethodName(bytes,bytes)
|
|
205
|
+
|
|
206
|
+
The first argument of methods must always be TACHeader. It is sent by protocol, augmented with data from executor.
|
|
207
|
+
- **`bytes tacHeader`**: Encoded structure TacHeaderV1, containing:
|
|
208
|
+
- **`uint64 shardsKey`**: ID you can specify for yourself an inside message to the TVM contract on the TON network.
|
|
209
|
+
- **`uint256 timestamp`**: The block timestamp on TON where the user's message was created.
|
|
210
|
+
- **`bytes32 operationId`**: Unique identifier for the message created by the TAC infrastructure.
|
|
211
|
+
- **`string tvmCaller`**: The TON user's wallet address that sent the message.
|
|
212
|
+
- **`bytes extraData`**: Untrusted extra data, provided by executor with the current message if needed. Otherwise, it's an empty bytes array.
|
|
213
|
+
|
|
214
|
+
You need to specify all the remaining data you need in tuple (bytes) in arguments. For example this is how arguments for addLiquidity method in UniswapV2 (a special proxy contract for it) will look like:
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
const abi = new ethers.AbiCoder();
|
|
218
|
+
const encodedParameters = abi.encode(
|
|
219
|
+
['tuple(address,address,uint256,uint256,uint256,uint256,address,uint256)'],
|
|
220
|
+
[
|
|
221
|
+
[
|
|
222
|
+
EVM_TOKEN_A_ADDRESS,
|
|
223
|
+
EVM_TOKEN_B_ADDRESS,
|
|
224
|
+
amountA,
|
|
225
|
+
amountB,
|
|
226
|
+
amountAMin,
|
|
227
|
+
amountBMin,
|
|
228
|
+
UNISWAPV2_PROXY_ADDRESS,
|
|
229
|
+
deadline
|
|
230
|
+
]
|
|
231
|
+
]
|
|
232
|
+
);
|
|
233
|
+
```
|
|
234
|
+
More details in [sendAddLiquidity.ts](tests/uniswap_v2/sendAddLiquidity.ts) and in other tests.
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
### Getter: `nativeTONAddress`
|
|
239
|
+
|
|
240
|
+
This getter returns address(better to say "indicator") of native TON Coin.
|
|
241
|
+
|
|
242
|
+
#### **Purpose**
|
|
243
|
+
|
|
244
|
+
The indicator should only be used in *getEVMTokenAddress* to calculate address of TON wrapper on TAC Chain.
|
|
245
|
+
|
|
246
|
+
#### **Returns**
|
|
247
|
+
|
|
248
|
+
- **`string`**:
|
|
249
|
+
- A string that indicates the native TON Coin.
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
### Getter: `nativeTACAddress`
|
|
253
|
+
|
|
254
|
+
This getter returns address of TAC Coin on TAC Chain.
|
|
255
|
+
|
|
256
|
+
#### **Purpose**
|
|
257
|
+
|
|
258
|
+
The address could be used in *getTVMTokenAddress* to calculate address of TAC wrapper on TON Chain.
|
|
259
|
+
|
|
260
|
+
#### **Returns**
|
|
261
|
+
|
|
262
|
+
- **`Promise<string>`**:
|
|
263
|
+
- A promise that resolves to the computed EVM token address as a string.
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
### Function: `getEVMTokenAddress`
|
|
267
|
+
|
|
268
|
+
This function will get the EVM paired address for a TVM token.
|
|
269
|
+
|
|
270
|
+
#### **Purpose**
|
|
271
|
+
|
|
272
|
+
The ability to compute the EVM address is crucial, in evmProxyMsg you almost always requires the token addresses on the EVM network as parameters. By precomputing the corresponding EVM addresses for TVM tokens, users can ensure that the transaction parameters are correctly configured before executing crosschain operations.
|
|
273
|
+
|
|
274
|
+
For example, when adding liquidity, you need to specify the addresses of the tokens on the EVM network that you intend to add. Without the ability to compute these addresses in advance, configuring the transaction would be error-prone and could lead to failures. This function will bridge this gap, making the process seamless and reliable.
|
|
275
|
+
|
|
276
|
+
#### **Parameters**
|
|
277
|
+
|
|
278
|
+
- **`tvmTokenAddress(string)`**: The address of the token on the TON blockchain (TVM format), including support for native TON. Address of native TON can be retreieved using *nativeTONAddress* getter in TacSDK.
|
|
279
|
+
|
|
280
|
+
#### **Returns**
|
|
281
|
+
|
|
282
|
+
- **`Promise<string>`**:
|
|
283
|
+
- A promise that resolves to the computed EVM token address as a string.
|
|
284
|
+
|
|
285
|
+
#### **Possible exceptions**
|
|
286
|
+
|
|
287
|
+
- **`AddressError`**: invalid token address provided.
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
### Function: `getTVMTokenAddress`
|
|
291
|
+
|
|
292
|
+
This function gets the TVM paired address for a EVM token.
|
|
293
|
+
|
|
294
|
+
#### **Purpose**
|
|
295
|
+
|
|
296
|
+
This function provides the address of the wrapper for any EVM token at a specific address.
|
|
297
|
+
|
|
298
|
+
#### **Parameters**
|
|
299
|
+
|
|
300
|
+
- **`evmTokenAddress(string)`**: The address of the token on the TAC blockchain (EVM format), including support for native TAC. Address of native TAC can be retreieved using *nativeTACAddress* getter in TacSDK.
|
|
301
|
+
|
|
302
|
+
#### **Returns**
|
|
303
|
+
|
|
304
|
+
- **`Promise<string>`**:
|
|
305
|
+
- A promise that resolves to the computed TVM token address as a string.
|
|
306
|
+
|
|
307
|
+
#### **Possible exceptions**
|
|
308
|
+
|
|
309
|
+
- **`AddressError`**: invalid token address provided.
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
### Function: `getUserJettonWalletAddress`
|
|
313
|
+
|
|
314
|
+
This function retrieves the address of a user's Jetton wallet for a specific token.
|
|
315
|
+
|
|
316
|
+
#### **Purpose**
|
|
317
|
+
|
|
318
|
+
This function is useful for obtaining the address of a user's Jetton wallet, which is necessary for interacting with Jetton tokens on the TON blockchain.
|
|
319
|
+
|
|
320
|
+
#### **Parameters**
|
|
321
|
+
|
|
322
|
+
- **`userAddress(string)`**: The address of the user's wallet on the TON blockchain.
|
|
323
|
+
- **`tokenAddress(string)`**: The address of the Jetton token.
|
|
324
|
+
|
|
325
|
+
#### **Returns**
|
|
326
|
+
|
|
327
|
+
- **`Promise<string>`**:
|
|
328
|
+
- A promise that resolves to the address of the user's Jetton wallet as a string.
|
|
329
|
+
|
|
330
|
+
#### **Possible exceptions**
|
|
331
|
+
|
|
332
|
+
- **`AddressError`**: invalid token address provided.
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
### Function: `getUserJettonBalance`
|
|
336
|
+
|
|
337
|
+
This function retrieves the balance of a specific Jetton token in a user's wallet.
|
|
338
|
+
|
|
339
|
+
#### **Purpose**
|
|
340
|
+
|
|
341
|
+
This function allows users to check their balance of a specific Jetton token, which is essential for managing assets on the TON blockchain.
|
|
342
|
+
|
|
343
|
+
#### **Parameters**
|
|
344
|
+
|
|
345
|
+
- **`userAddress(string)`**: The address of the user's wallet on the TON blockchain.
|
|
346
|
+
- **`tokenAddress(string)`**: The address of the Jetton token.
|
|
347
|
+
|
|
348
|
+
#### **Returns**
|
|
349
|
+
|
|
350
|
+
- **`Promise<bigint>`**:
|
|
351
|
+
- A promise that resolves to the balance of the Jetton token in the user's wallet as a `bigint`.
|
|
352
|
+
|
|
353
|
+
#### **Possible exceptions**
|
|
354
|
+
|
|
355
|
+
- **`AddressError`**: invalid token address provided.
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
### Function: `getUserJettonBalanceExtended`
|
|
359
|
+
|
|
360
|
+
This function retrieves detailed information about a user's Jetton balance, including the raw amount, decimals, and formatted amount.
|
|
361
|
+
|
|
362
|
+
#### **Purpose**
|
|
363
|
+
|
|
364
|
+
This function provides a more detailed view of a user's Jetton balance, including the raw amount, the number of decimals, and the formatted amount, which is useful for displaying balances in a user-friendly format.
|
|
365
|
+
|
|
366
|
+
#### **Parameters**
|
|
367
|
+
|
|
368
|
+
- **`userAddress(string)`**: The address of the user's wallet on the TON blockchain.
|
|
369
|
+
- **`tokenAddress(string)`**: The address of the Jetton token.
|
|
370
|
+
|
|
371
|
+
#### **Returns**
|
|
372
|
+
|
|
373
|
+
- **`Promise<UserWalletBalanceExtended>`**:
|
|
374
|
+
- A promise that resolves to an object with one of the following structures:
|
|
375
|
+
- If the Jetton wallet exists:
|
|
376
|
+
- **`exists`**: A boolean indicating whether the Jetton wallet exists (`true`).
|
|
377
|
+
- **`rawAmount`**: The raw balance of the Jetton token as a `bigint`.
|
|
378
|
+
- **`decimals`**: The number of decimals for the Jetton token.
|
|
379
|
+
- **`amount`**: The formatted balance of the Jetton token as a number.
|
|
380
|
+
- If the Jetton wallet does not exist:
|
|
381
|
+
- **`exists`**: A boolean indicating whether the Jetton wallet exists (`false`).
|
|
382
|
+
#### **Possible exceptions**
|
|
383
|
+
|
|
384
|
+
- **`AddressError`**: invalid token address provided.
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
### Function: `simulateEVMMessage`
|
|
388
|
+
|
|
389
|
+
This function will simulate the EVM message on the TAC side.
|
|
390
|
+
|
|
391
|
+
#### **Purpose**
|
|
392
|
+
|
|
393
|
+
The ability to simulate the EVM message is crucial for testing and debugging crosschain operations. By simulating the message, developers can verify that the transaction parameters are correctly configured and that the operation will execute.
|
|
394
|
+
|
|
395
|
+
#### **Parameters**
|
|
396
|
+
|
|
397
|
+
- **`evmCallParams`**: An object defining the EVM-specific logic:
|
|
398
|
+
- **`target`**: Target address on the EVM network.
|
|
399
|
+
- **`methodName`**: Method name to execute on the target contract. Either method name `MethodName` or signature `MethodName(bytes,bytes)` must be specified (strictly (bytes,bytes)).
|
|
400
|
+
- **`arguments`**: Encoded parameters for the EVM method.
|
|
401
|
+
- **`extraData`**: Unstrusted Extra Data provided by executor.
|
|
402
|
+
- **`feeAssetAddress`**: TVM Fee Asset Address, empty string for native TON.
|
|
403
|
+
- **`shardedId`**: Sharded ID.
|
|
404
|
+
- **`tvmAssets`**: An array of objects, each specifying the Assets details:
|
|
405
|
+
- **`tokenAddress`**: Address of the Asset.
|
|
406
|
+
- **`amount`**: Amount of Assets to be transferred.
|
|
407
|
+
- **`tvmCaller`**: TVM Caller wallet address.
|
|
408
|
+
|
|
409
|
+
#### **Returns**
|
|
410
|
+
|
|
411
|
+
- **`Promise<EVMSimulationResults>`**:
|
|
412
|
+
- A promise that resolves to detailed information about the execution of the given message, including:
|
|
413
|
+
- **`estimatedGas`**: The estimated gas required for the message.
|
|
414
|
+
- **`estimatedJettonFeeAmount`**: The estimated fee amount in Jettons.
|
|
415
|
+
- **`feeParams`**: The parameters related to the fee.
|
|
416
|
+
- **`currentBaseFee`**: The current base fee.
|
|
417
|
+
- **`isEip1559`**: Indicates if EIP-1559 is applied.
|
|
418
|
+
- **`suggestedGasPrice`**: The suggested gas price.
|
|
419
|
+
- **`suggestedGasTip`**: The suggested gas tip.
|
|
420
|
+
- **`message`**: The message details.
|
|
421
|
+
- **`outMessages`**: The outgoing messages.
|
|
422
|
+
- **`callerAddress`**: The address of the caller.
|
|
423
|
+
- **`operationId`**: The operation ID.
|
|
424
|
+
- **`payload`**: The payload.
|
|
425
|
+
- **`queryId`**: The query ID.
|
|
426
|
+
- **`targetAddress`**: The target address.
|
|
427
|
+
- **`tokensBurned`**: The tokens burned.
|
|
428
|
+
- **`amount`**: The amount of tokens burned.
|
|
429
|
+
- **`tokenAddress`**: The address of the token.
|
|
430
|
+
- **`tokensLocked`**: The tokens locked.
|
|
431
|
+
- **`simulationError`**: Any error encountered during the simulation.
|
|
432
|
+
- **`simulationStatus`**: The status of the simulation.
|
|
433
|
+
- **`debugInfo`**: Debugging information.
|
|
434
|
+
- **`from`**: The sender address.
|
|
435
|
+
- **`to`**: The recipient address.
|
|
436
|
+
- **`callData`**: The call data.
|
|
437
|
+
- **`blockNumber`**: The block number.
|
|
438
|
+
|
|
439
|
+
---
|
|
440
|
+
|
|
441
|
+
## Sending TON Transactions: Two Approaches
|
|
442
|
+
|
|
443
|
+
The SDK provides two approaches for sending TON transactions: using **TonConnect** or a **raw wallet via mnemonic**. Below is an explanation of both options.
|
|
444
|
+
|
|
445
|
+
Look at example below or in tests folder(better in tests folder)
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
### 1. Using TonConnect
|
|
449
|
+
|
|
450
|
+
The `TonConnectSender` class enables sending transactions via the TonConnect.
|
|
451
|
+
- **Example dirty, better look at uniswap example**:
|
|
452
|
+
```typescript
|
|
453
|
+
tonConnect: TonConnectUI
|
|
454
|
+
const sender = await SenderFactory.getSender({
|
|
455
|
+
tonConnect,
|
|
456
|
+
});
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
### 2. Using a Raw Wallet via Mnemonic
|
|
460
|
+
|
|
461
|
+
The `RawSender` class allows direct interaction with the blockchain using a raw wallet created from a mnemonic phrase.
|
|
462
|
+
|
|
463
|
+
- **Example**:
|
|
464
|
+
```typescript
|
|
465
|
+
const walletVersion = 'v4';
|
|
466
|
+
const mnemonic = process.env.TVM_MNEMONICS || ''; // 24 words mnemonic
|
|
467
|
+
const network = Network.Testnet; // or Network.Mainnet
|
|
468
|
+
const sender = await SenderFactory.getSender({
|
|
469
|
+
version: walletVersion,
|
|
470
|
+
mnemonic,
|
|
471
|
+
network,
|
|
472
|
+
});
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
- **Supported wallet versions**:
|
|
476
|
+
```
|
|
477
|
+
export type WalletVersion =
|
|
478
|
+
| "v2r1"
|
|
479
|
+
| "v2r2"
|
|
480
|
+
| "v3r1"
|
|
481
|
+
| "v3r2"
|
|
482
|
+
| "v4"
|
|
483
|
+
| "v5r1"
|
|
484
|
+
| "highloadV3";
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
- **Possible exceptions**:
|
|
488
|
+
- **`WalletError`**: invalid wallet version provided.
|
|
489
|
+
|
|
490
|
+
---
|
|
491
|
+
|
|
492
|
+
## Tracking operation
|
|
493
|
+
The `OperationTracker` class is designed to track the status of crosschain operations by interacting with public or custom Lite Sequencer endpoints. It provides methods to fetch and interpret transaction statuses, enabling smooth monitoring of transaction lifecycles.
|
|
494
|
+
|
|
495
|
+
### Purpose
|
|
496
|
+
|
|
497
|
+
This class facilitates tracking crosschain operation statuses by:
|
|
498
|
+
1. Fetching the `operationId` for a TON transaction using the `transactionLinker` returned from `sendCrossChainTransaction` function in `TacSDK`.
|
|
499
|
+
2. Retrieving the current status of an operation using the `operationId`.
|
|
500
|
+
3. Returning a simplified status for easier operation monitoring.
|
|
501
|
+
|
|
502
|
+
To track an operation, follow these steps:
|
|
503
|
+
|
|
504
|
+
### 0. Create an Instance of OperationTracker
|
|
505
|
+
|
|
506
|
+
To use the `OperationTracker` class, initialize it with the required parameters (you can specify `customLiteSequencerEndpoints` for sending requests there):
|
|
507
|
+
|
|
508
|
+
```typescript
|
|
509
|
+
import { OperationTracker, Network } from '@tonappchain/sdk';
|
|
510
|
+
|
|
511
|
+
const tracker = new OperationTracker(
|
|
512
|
+
network: Network.Testnet,
|
|
513
|
+
// customLiteSequencerEndpoints: ["custom.com"]
|
|
514
|
+
);
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
### 1. Get the `operationId`
|
|
518
|
+
|
|
519
|
+
Use the `getOperationId(transactionLinker)` method with the `transactionLinker` structure returned from `sendCrossChainTransaction` after sending TON transaction.
|
|
520
|
+
|
|
521
|
+
> **Note:** An empty response string indicates that validators have not yet received your messages. Continue retrying until you receive a non-empty `operationId`.
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
#### **Method: `getOperationId(transactionLinker: TransactionLinker): Promise<string>`**
|
|
525
|
+
|
|
526
|
+
#### **Parameters**:
|
|
527
|
+
- `transactionLinker`: A `TransactionLinker` object containing TON transaction linkers.
|
|
528
|
+
|
|
529
|
+
#### **Returns**:
|
|
530
|
+
- **`Promise<string>`**:
|
|
531
|
+
- A string representing the `operationId`.
|
|
532
|
+
|
|
533
|
+
#### **Usage**:
|
|
534
|
+
```typescript
|
|
535
|
+
const tracker = new OperationTracker(
|
|
536
|
+
network: Network.Testnet
|
|
537
|
+
);
|
|
538
|
+
const operationId = await tracker.getOperationId(transactionLinker);
|
|
539
|
+
console.log('Operation ID:', operationId);
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
### 2. Check the Operation Status
|
|
543
|
+
|
|
544
|
+
Use the `getOperationStatus(operationId)` method to fetch the operation status.
|
|
545
|
+
|
|
546
|
+
#### **Method: `getOperationStatus(operationId: string): Promise<StatusInfo>`**
|
|
547
|
+
|
|
548
|
+
Retrieves the current status of an operation using its `operationId`.
|
|
549
|
+
|
|
550
|
+
#### **Parameters**:
|
|
551
|
+
- `operationId`: The identifier obtained from `getOperationId`.
|
|
552
|
+
|
|
553
|
+
#### **Returns**:
|
|
554
|
+
- **`Promise<StatusInfo>`**:
|
|
555
|
+
- A structure representing the operation's status, including:
|
|
556
|
+
- `status`:
|
|
557
|
+
- `EVMMerkleMessageCollected`: Validator has collected all events for a single sharded message.
|
|
558
|
+
- `EVMMerkleRootSet`: The EVM message has been added to the Merkle tree.
|
|
559
|
+
- `EVMMerkleMessageExecuted`: The collected message has been executed on the EVM side.
|
|
560
|
+
- `TVMMerkleMessageCollected`: After EVM execution, a return message event is generated for TVM execution.
|
|
561
|
+
- `TVMMerkleRootSet`: The TVM message has been added to the Merkle tree.
|
|
562
|
+
- `TVMMerkleMessageExecuted`: The operation is fully executed across TVM and EVM.
|
|
563
|
+
- `errorMessage`: The error message if the operation failed.
|
|
564
|
+
- `operationId`: The identifier of the operation.
|
|
565
|
+
(error requests will be processed in future version)
|
|
566
|
+
#### **Usage**:
|
|
567
|
+
```typescript
|
|
568
|
+
const tracker = new OperationTracker(
|
|
569
|
+
network: Network.Testnet
|
|
570
|
+
);
|
|
571
|
+
const { status, errorMessage } = await tracker.getOperationStatus(operationId);
|
|
572
|
+
if (errorMessage) {
|
|
573
|
+
console.log('Error:', status);
|
|
574
|
+
}
|
|
575
|
+
console.log('Operation Status:', status);
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
---
|
|
579
|
+
|
|
580
|
+
### * Use Simplified Status (instead of 1 and 2 steps)
|
|
581
|
+
|
|
582
|
+
Use the `getSimplifiedOperationStatus(transactionLinker)` method for an easy-to-interpret status.
|
|
583
|
+
|
|
584
|
+
#### Method: `getSimplifiedOperationStatus(transactionLinker: TransactionLinker, isBridgeOperation: boolean = false): Promise<SimplifiedStatuses>`
|
|
585
|
+
|
|
586
|
+
Fetches a simplified operation status using the `transactionLinker`.
|
|
587
|
+
|
|
588
|
+
#### **Parameters**:
|
|
589
|
+
- `transactionLinker`: A `TransactionLinker` object returned from `sendCrossChainTransaction` function.
|
|
590
|
+
- `isBridgeOperation` *(optional)*: If your operation should only execute on EVM side without returning to TVM set `isBridgeOperation` to **true**. TAC protocol can just bridge the assets.
|
|
591
|
+
|
|
592
|
+
#### **Returns**:
|
|
593
|
+
- **`Promise<SimplifiedStatuses>`**:
|
|
594
|
+
- A simplified status from the `SimplifiedStatuses` enum:
|
|
595
|
+
- **`Pending`**: The operation is still in progress.
|
|
596
|
+
- **`Successful`**: The operation has successfully completed.
|
|
597
|
+
- **`OperationIdNotFound`**: The operation ID could not be found.
|
|
598
|
+
- **`Failed`**: The operation failed.
|
|
599
|
+
|
|
600
|
+
#### **Usage**
|
|
601
|
+
Here operationId will be always requested(not optimal).
|
|
602
|
+
```typescript
|
|
603
|
+
const tracker = new OperationTracker();
|
|
604
|
+
const simplifiedStatus = await tracker.getSimpifiedOperationStatus(transactionLinker);
|
|
605
|
+
console.log('Simplified Status:', simplifiedStatus);
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
---
|
|
609
|
+
### Other functions
|
|
610
|
+
|
|
611
|
+
#### Method: `getOperationIdsByShardsKeys(shardsKeys: string[], caller: string): Promise<OperationIdsByShardsKey>`
|
|
612
|
+
|
|
613
|
+
Retrieves operation IDs associated with specific shard keys for a given caller. Shard keys uniquely identify shards within the TON network, and this method maps them to their corresponding operation IDs.
|
|
614
|
+
|
|
615
|
+
##### **Parameters**
|
|
616
|
+
|
|
617
|
+
- **`shardsKeys`**: An array of shard keys for which operation IDs are to be fetched.
|
|
618
|
+
- **`caller`**: The address of the caller initiating the request.
|
|
619
|
+
|
|
620
|
+
##### **Returns**
|
|
621
|
+
|
|
622
|
+
- **`Promise<OperationIdsByShardsKey>`**: A promise that resolves to a mapping of shard keys to their corresponding operation IDs.
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
#### Method: `getStageProfiling(operationId: string): Promise<ExecutionStages>`
|
|
626
|
+
|
|
627
|
+
Fetches profiling information for all execution stages of operation identified by its operation ID.
|
|
628
|
+
|
|
629
|
+
##### **Parameters**
|
|
630
|
+
|
|
631
|
+
- **`operationId`**: The unique identifier of the operation whose profiling data is to be retrieved.
|
|
632
|
+
|
|
633
|
+
##### **Returns**
|
|
634
|
+
|
|
635
|
+
- **`Promise<ExecutionStages>`**: A promise that resolves to the profiling data of the operation's execution stages.
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
#### Method: `getStageProfilings(operationIds: string[]): Promise<ExecutionStagesByOperationId>`
|
|
639
|
+
|
|
640
|
+
Retrieves profiling information for multiple operations at once.
|
|
641
|
+
|
|
642
|
+
##### **Parameters**
|
|
643
|
+
|
|
644
|
+
- **`operationIds`**: An array of operation IDs for which profiling data is to be fetched.
|
|
645
|
+
|
|
646
|
+
##### **Returns**
|
|
647
|
+
|
|
648
|
+
- **`Promise<ExecutionStagesByOperationId>`**: A promise that resolves to a mapping of operation IDs to their corresponding execution stages profiling data.
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
#### Method: `getOperationStatuses(operationIds: string[]): Promise<StatusInfosByOperationId>`
|
|
652
|
+
|
|
653
|
+
Fetches the current status information for multiple operations based on their operation IDs.
|
|
654
|
+
|
|
655
|
+
##### **Parameters**
|
|
656
|
+
|
|
657
|
+
- **`operationIds: string[]`**: An array of operation IDs whose statuses need to be retrieved.
|
|
658
|
+
|
|
659
|
+
##### **Returns**
|
|
660
|
+
|
|
661
|
+
- **`Promise<StatusInfosByOperationId>`**: A promise that resolves to a mapping of operation IDs to their respective status information.
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
---
|
|
665
|
+
### startTracking
|
|
666
|
+
|
|
667
|
+
Track the execution of crosschain operation with `startTracking` method
|
|
668
|
+
|
|
669
|
+
#### Method: `async startTracking(transactionLinker: TransactionLinker, network: network, isBridgeOperation: boolean = false, customLiteSequencerEndpoints?: string[]): Promise<void>`
|
|
670
|
+
|
|
671
|
+
#### **Parameters**:
|
|
672
|
+
- `transactionLinker`: A `TransactionLinker` object returned from `sendCrossChainTransaction` function.
|
|
673
|
+
- `network`: TON network (`Network` type).
|
|
674
|
+
- `isBridgeOperation` *(optional)*: If your operation should only execute on EVM side without returning to TVM set `isBridgeOperation` to **true**. TAC protocol can just bridge the assets.
|
|
675
|
+
- `customLiteSequencerEndpoints` *(optional)*: specify custom lite sequencer API URL for sending requests there.
|
|
676
|
+
|
|
677
|
+
#### **Returns**:
|
|
678
|
+
- void:
|
|
679
|
+
- Will stop requesting status once the final status of crosschain operation has been reached.
|
|
680
|
+
|
|
681
|
+
#### **Possible exceptions**
|
|
682
|
+
|
|
683
|
+
- **`FetchError`**: failed to fetch operation id or status of operation from lite sequencer.
|
|
684
|
+
|
|
685
|
+
#### **Usage**
|
|
686
|
+
Here operationId will be always requested(not optimal).
|
|
687
|
+
```typescript
|
|
688
|
+
await startTracking(transactionLinker, network.Testnet);
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
---
|
|
692
|
+
|
|
693
|
+
## Structures Description
|
|
694
|
+
|
|
695
|
+
### `Network (Enum)`
|
|
696
|
+
Represents TON network type you want to use.
|
|
697
|
+
```typescript
|
|
698
|
+
export enum Network {
|
|
699
|
+
Testnet = 'testnet',
|
|
700
|
+
Mainnet = 'mainnet'
|
|
701
|
+
}
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
- **`Testnet`**: Represents the testnet TON network.
|
|
705
|
+
- **`Mainnet`**: Represents the mainnet TON network.
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
### `SDKParams (Type)`
|
|
709
|
+
```typescript
|
|
710
|
+
export type SDKParams = {
|
|
711
|
+
network: Network;
|
|
712
|
+
delay?: number;
|
|
713
|
+
TACParams?: TACParams;
|
|
714
|
+
TONParams?: TONParams;
|
|
715
|
+
customLiteSequencerEndpoints?: string[];
|
|
716
|
+
}
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
Parameters for SDK:
|
|
720
|
+
- **`network`**: Specifies TON network (`Network` type).
|
|
721
|
+
- **`delay`** *(optional)*: Delay (in seconds) for requests to the TON client. Default is *0*.
|
|
722
|
+
- **`TACParams`** *(optional)*: Custom parameters for TAC side
|
|
723
|
+
- **`TONParams`** *(optional)*: Custom parameters for TON side
|
|
724
|
+
- **`customLiteSequencerEndpoints`** *(optional)*: Custom lite sequencer endpoints for API access.
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
### `TONParams (Type)`
|
|
728
|
+
```typescript
|
|
729
|
+
export type TONParams = {
|
|
730
|
+
contractOpener?: ContractOpener;
|
|
731
|
+
settingsAddress?: string;
|
|
732
|
+
}
|
|
733
|
+
```
|
|
734
|
+
TON Parameters for SDK:
|
|
735
|
+
- **`contractOpener`** *(optional)*: Client used for TON smart contract interaction. Default is `orbsOpener4`. Set for tests only
|
|
736
|
+
- **`settingsAddress`** *(optional)*: TON settings contract address. Needed to retrieve protocol data. Set for tests only
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
### `TACParams (Type)`
|
|
740
|
+
```typescript
|
|
741
|
+
export type TACParams = {
|
|
742
|
+
provider?: AbstractProvider;
|
|
743
|
+
settingsAddress?: string | Addressable;
|
|
744
|
+
settingsABI?: Interface | InterfaceAbi;
|
|
745
|
+
crossChainLayerABI?: Interface | InterfaceAbi;
|
|
746
|
+
crossChainLayerTokenABI?: Interface | InterfaceAbi;
|
|
747
|
+
crossChainLayerTokenBytecode?: string;
|
|
748
|
+
}
|
|
749
|
+
```
|
|
750
|
+
|
|
751
|
+
TAC Parameters for SDK:
|
|
752
|
+
- **`provider`** *(optional)*: Provider used for TAC smart contract interaction. Set for increasing rate limit or tests only
|
|
753
|
+
- **`settingsAddress`** *(optional)*: TAC settings contract address. Needed to retrieve protocol data. Set for tests only
|
|
754
|
+
- **`settingsABI`** *(optional)*: TAC settings contract ABI. Set for tests only
|
|
755
|
+
- **`crossChainLayerABI`** *(optional)*: TAC CCL contract ABI. Set for tests only
|
|
756
|
+
- **`crossChainLayerTokenABI`** *(optional)*: TAC CCL Token contract ABI. Set for tests only
|
|
757
|
+
- **`crossChainLayerTokenBytecode`** *(optional)*: TAC CCL Token contract bytecode. Set for tests only
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
### `EvmProxyMsg (Type)`
|
|
761
|
+
```typescript
|
|
762
|
+
export type EvmProxyMsg = {
|
|
763
|
+
evmTargetAddress: string,
|
|
764
|
+
methodName?: string,
|
|
765
|
+
encodedParameters?: string,
|
|
766
|
+
gasLimit?: bigint,
|
|
767
|
+
}
|
|
768
|
+
```
|
|
769
|
+
Represents a proxy message to a TAC.
|
|
770
|
+
- **`evmTargetAddress`**: Target address on the EVM network.
|
|
771
|
+
- **`methodName`** *(optional)*: Method name to be called on the target contract. Either method name `MethodName` or signature `MethodName(bytes,bytes)` must be specified (strictly (bytes,bytes)).
|
|
772
|
+
- **`encodedParameters`** *(optional)*: Parameters for the method, encoded as a string.
|
|
773
|
+
- **`gasLimit`** *(optional)*: `gasLimit` is a parameter that will be passed on the TAC side. The executor must allocate at least gasLimit gas for executing the transaction on the TAC side. If this parameter is not specified, it will be calculated using the `simulateEVMMessage` method(prefered).
|
|
774
|
+
|
|
775
|
+
This structure defines the logic you want to execute on the TAC side. This message is sent along with all the sharded messages related to the jetton bridging, enabling the TAC to process the intended logic on the TAC side during the crosschain transaction.
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
### `AssetBridgingData (Type)`
|
|
779
|
+
|
|
780
|
+
This structure is used to specify the details of the Assets you want to bridge for your operation. This allows you to precisely control the tokens and amounts involved in your crosschain transaction.
|
|
781
|
+
|
|
782
|
+
```typescript
|
|
783
|
+
export type WithAddress = {
|
|
784
|
+
/**
|
|
785
|
+
* Address of TAC or TON token.
|
|
786
|
+
* Empty if sending native TON coin.
|
|
787
|
+
*/
|
|
788
|
+
address?: string;
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
export type RawAssetBridgingData = {
|
|
792
|
+
/** Raw format, e.g. 12340000000 (=12.34 tokens if decimals is 9) */
|
|
793
|
+
rawAmount: bigint;
|
|
794
|
+
} & WithAddress;
|
|
795
|
+
|
|
796
|
+
export type UserFriendlyAssetBridgingData = {
|
|
797
|
+
/**
|
|
798
|
+
* User friendly format, e.g. 12.34 tokens
|
|
799
|
+
* Specified value will be converted automatically to raw format: 12.34 * (10^decimals).
|
|
800
|
+
* No decimals should be specified.
|
|
801
|
+
*/
|
|
802
|
+
amount: number;
|
|
803
|
+
/**
|
|
804
|
+
* Decimals may be specified manually.
|
|
805
|
+
* Otherwise, SDK tries to extract them from chain.
|
|
806
|
+
*/
|
|
807
|
+
decimals?: number;
|
|
808
|
+
} & WithAddress;
|
|
809
|
+
|
|
810
|
+
export type AssetBridgingData = RawAssetBridgingData | UserFriendlyAssetBridgingData;
|
|
811
|
+
```
|
|
812
|
+
|
|
813
|
+
Represents general data for Asset operations.
|
|
814
|
+
- **`rawAmount`** *(required if `amount` is not specified): Amount of Assets to be transferred taking into account the number of decimals.
|
|
815
|
+
- **`amount`** *(required if `rawAmount` is not specified): Amount of Assets to be transferred.
|
|
816
|
+
- **`decimals`** *(optional)*: Number of decimals for the asset. If not specified, the SDK will attempt to extract the decimals from the chain.
|
|
817
|
+
- **`address`** *(optional)*: TVM or EVM asset's address.
|
|
818
|
+
|
|
819
|
+
> **Note:** If you need to transfer a native TON coin, do not specify address.
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
### `TransactionLinker (Type)`
|
|
823
|
+
```typescript
|
|
824
|
+
export type TransactionLinker = {
|
|
825
|
+
caller: string,
|
|
826
|
+
shardCount: number,
|
|
827
|
+
shardsKey: string,
|
|
828
|
+
timestamp: number,
|
|
829
|
+
sendTransactionResult?: unknown,
|
|
830
|
+
}
|
|
831
|
+
```
|
|
832
|
+
Linker to track TON transaction for crosschain operation.
|
|
833
|
+
- **`caller`**: Address of the transaction initiator.
|
|
834
|
+
- **`shardCount`**: Number of shards involved.
|
|
835
|
+
- **`shardsKey`**: Identifier for the shard.
|
|
836
|
+
- **`timestamp`**: Timestamp of the transaction.
|
|
837
|
+
- **`sendTransactionResult`** *(optional)*: Result of sending transaction. May be used to check result of sending transaction. Default TonClient does NOT fill this field. However, in unit tests @ton/sandbox set transaction result object to this field.
|
|
838
|
+
|
|
839
|
+
This structure is designed to help track the entire execution path of a operation across all levels. By using it, you can identify the `operationId` and subsequently monitor the operation status through a public API. This is particularly useful for ensuring visibility and transparency in the operation lifecycle, allowing you to verify its progress and outcome.
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
### `SimplifiedStatuses (Enum)`
|
|
843
|
+
```typescript
|
|
844
|
+
export enum SimplifiedStatuses {
|
|
845
|
+
Pending,
|
|
846
|
+
Failed,
|
|
847
|
+
Successful,
|
|
848
|
+
OperationIdNotFound,
|
|
849
|
+
}
|
|
850
|
+
```
|
|
851
|
+
Represents the simplified operation statuses.
|
|
852
|
+
- **`Pending`**: The operation in progress.
|
|
853
|
+
- **`Failed`**: The operation has failed.
|
|
854
|
+
- **`Successful`**: The operation was executed successfully.
|
|
855
|
+
- **`OperationIdNotFound`**: The operation ID was not found.
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
### `ContractOpener (Interface)`
|
|
859
|
+
|
|
860
|
+
The ContractOpener interface provides methods to interact with smart contracts on the TON network. It allows opening contracts for interaction and retrieving contract states.
|
|
861
|
+
```typescript
|
|
862
|
+
export interface ContractOpener {
|
|
863
|
+
open<T extends Contract>(src: T): OpenedContract<T> | SandboxContract<T>;
|
|
864
|
+
|
|
865
|
+
getContractState(address: Address): Promise<{
|
|
866
|
+
balance: bigint;
|
|
867
|
+
state: 'active' | 'uninitialized' | 'frozen';
|
|
868
|
+
code: Buffer | null;
|
|
869
|
+
}>;
|
|
870
|
+
}
|
|
871
|
+
```
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
### `EVMSimulationRequest`
|
|
875
|
+
|
|
876
|
+
```typescript
|
|
877
|
+
export type EVMSimulationRequest = {
|
|
878
|
+
evmCallParams: {
|
|
879
|
+
arguments: string;
|
|
880
|
+
methodName: string;
|
|
881
|
+
target: string;
|
|
882
|
+
};
|
|
883
|
+
extraData: string;
|
|
884
|
+
feeAssetAddress: string;
|
|
885
|
+
shardsKey: number;
|
|
886
|
+
tvmAssets: {
|
|
887
|
+
amount: string;
|
|
888
|
+
tokenAddress: string;
|
|
889
|
+
}[];
|
|
890
|
+
tvmCaller: string;
|
|
891
|
+
};
|
|
892
|
+
```
|
|
893
|
+
|
|
894
|
+
Represents a request to simulate an EVM message.
|
|
895
|
+
|
|
896
|
+
- **`evmCallParams`**: An object containing parameters for the EVM call.
|
|
897
|
+
- **`arguments`**: Encoded arguments for the EVM method.
|
|
898
|
+
- **`methodName`**: Name of the method to be called on the target EVM contract.
|
|
899
|
+
- **`target`**: The target address on the EVM network.
|
|
900
|
+
- **`extraData`**: Additional non-root data to be included in EVM call.
|
|
901
|
+
- **`feeAssetAddress`**: Address of the asset used to cover fees; empty string if using native TON.
|
|
902
|
+
- **`shardsKey`**: Key identifying shards for the operation.
|
|
903
|
+
- **`tvmAssets`**: An array of assets involved in the transaction.
|
|
904
|
+
- **`amount`**: Amount of the asset to be transferred.
|
|
905
|
+
- **`tokenAddress`**: Address of the token.
|
|
906
|
+
- **`tvmCaller`**: Address of the caller in the TVM.
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
### `TransactionData`
|
|
910
|
+
|
|
911
|
+
```typescript
|
|
912
|
+
export type TransactionData = {
|
|
913
|
+
hash: string;
|
|
914
|
+
};
|
|
915
|
+
```
|
|
916
|
+
|
|
917
|
+
Represents transaction details.
|
|
918
|
+
- **`hash`**: The hash of the transaction.
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
### `NoteInfo`
|
|
922
|
+
|
|
923
|
+
```typescript
|
|
924
|
+
export type NoteInfo = {
|
|
925
|
+
content: string;
|
|
926
|
+
errorName: string;
|
|
927
|
+
internalMsg: string;
|
|
928
|
+
internalBytesError: string;
|
|
929
|
+
};
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
Provides detailed information about any notes or errors encountered during operation processing.
|
|
933
|
+
|
|
934
|
+
- **`content`**: Content of the note.
|
|
935
|
+
- **`errorName`**: Name of the error.
|
|
936
|
+
- **`internalMsg`**: Internal message related to the note or error.
|
|
937
|
+
- **`internalBytesError`**: Detailed bytes error information.
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
### `StageData`
|
|
941
|
+
|
|
942
|
+
```typescript
|
|
943
|
+
export type StageData = {
|
|
944
|
+
success: boolean;
|
|
945
|
+
timestamp: number;
|
|
946
|
+
transactions: TransactionData[] | null;
|
|
947
|
+
note: NoteInfo | null;
|
|
948
|
+
};
|
|
949
|
+
```
|
|
950
|
+
|
|
951
|
+
Represents data for a specific stage of operation execution.
|
|
952
|
+
|
|
953
|
+
#### **Properties**
|
|
954
|
+
|
|
955
|
+
- **`success`**: Indicates whether the stage was successful.
|
|
956
|
+
- **`timestamp`**: Timestamp of when the stage was executed.
|
|
957
|
+
- **`transactions`** *(optional)*: Array of transaction data related to the stage. `null` if none.
|
|
958
|
+
- **`note`** *(optional)*: Additional notes or errors related to the stage. `null` if none.
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
### `StatusInfo`
|
|
962
|
+
|
|
963
|
+
```typescript
|
|
964
|
+
export type StatusInfo = StageData & {
|
|
965
|
+
stage: string;
|
|
966
|
+
};
|
|
967
|
+
```
|
|
968
|
+
|
|
969
|
+
Combines `StageData` with an additional stage identifier.
|
|
970
|
+
|
|
971
|
+
- **`stage`**: Name of the current stage.
|
|
972
|
+
|
|
973
|
+
- **Other Properties from `StageData`**
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
### `ProfilingStageData`
|
|
977
|
+
|
|
978
|
+
```typescript
|
|
979
|
+
export type ProfilingStageData = {
|
|
980
|
+
exists: boolean;
|
|
981
|
+
stageData: StageData | null;
|
|
982
|
+
};
|
|
983
|
+
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
Provides profiling information for a specific stage.
|
|
987
|
+
|
|
988
|
+
- **`exists`**: Indicates whether profiling data exists for the stage.
|
|
989
|
+
|
|
990
|
+
- **`stageData`** *(optional)*: Detailed data of the stage. `null` if none.
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
### `ExecutionStages`
|
|
994
|
+
|
|
995
|
+
```typescript
|
|
996
|
+
export type ExecutionStages = {
|
|
997
|
+
evmMerkleMsgCollected: ProfilingStageData;
|
|
998
|
+
evmMerkleRootSet: ProfilingStageData;
|
|
999
|
+
evmMerkleMsgExecuted: ProfilingStageData;
|
|
1000
|
+
tvmMerkleMsgCollected: ProfilingStageData;
|
|
1001
|
+
tvmMerkleMsgExecuted: ProfilingStageData;
|
|
1002
|
+
};
|
|
1003
|
+
```
|
|
1004
|
+
|
|
1005
|
+
Represents the profiling data for all execution stages within an operation.
|
|
1006
|
+
|
|
1007
|
+
- **`evmMerkleMsgCollected`**: Profiling data for the EVM Merkle message collection stage.
|
|
1008
|
+
- **`evmMerkleRootSet`**: Profiling data for setting the EVM Merkle root.
|
|
1009
|
+
- **`evmMerkleMsgExecuted`**: Profiling data for executing the EVM Merkle message.
|
|
1010
|
+
- **`tvmMerkleMsgCollected`**: Profiling data for the TVM Merkle message collection stage.
|
|
1011
|
+
- **`tvmMerkleMsgExecuted`**: Profiling data for executing the TVM Merkle message.
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
### `ExecutionStagesByOperationId`
|
|
1015
|
+
|
|
1016
|
+
```typescript
|
|
1017
|
+
export type ExecutionStagesByOperationId = Record<string, ExecutionStages>;
|
|
1018
|
+
```
|
|
1019
|
+
|
|
1020
|
+
Maps each `operationId` to its respective `executionStages`.
|
|
1021
|
+
|
|
1022
|
+
|
|
1023
|
+
### `StatusInfosByOperationId`
|
|
1024
|
+
|
|
1025
|
+
```typescript
|
|
1026
|
+
export type StatusInfosByOperationId = Record<string, StatusInfo>;
|
|
1027
|
+
```
|
|
1028
|
+
|
|
1029
|
+
Maps each `operationId` to its respective `statusInfo`.
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
### `OperationIdsByShardsKeyResponse`
|
|
1033
|
+
|
|
1034
|
+
Maps each `operationId[]` to its respective `shardsKey`.
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
### `UserWalletBalanceExtended`
|
|
1038
|
+
|
|
1039
|
+
Provides extended information about a user's Jetton balance.
|
|
1040
|
+
|
|
1041
|
+
#### **Union Types**
|
|
1042
|
+
|
|
1043
|
+
- **If the Jetton wallet exists:**
|
|
1044
|
+
```typescript
|
|
1045
|
+
{
|
|
1046
|
+
exists: true;
|
|
1047
|
+
amount: number; // The formatted balance of the Jetton token.
|
|
1048
|
+
rawAmount: bigint; // The raw balance of the Jetton token.
|
|
1049
|
+
decimals: number; // The number of decimals for the Jetton token.
|
|
1050
|
+
}
|
|
1051
|
+
```
|
|
1052
|
+
|
|
1053
|
+
- **If the Jetton wallet does not exist:**
|
|
1054
|
+
```typescript
|
|
1055
|
+
{
|
|
1056
|
+
exists: false;
|
|
1057
|
+
}
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
- **`exists`**: Indicates whether the Jetton wallet exists.
|
|
1062
|
+
- **`amount`** *(optional)*: The formatted balance of the Jetton token. Present only if `exists` is `true`.
|
|
1063
|
+
- **`rawAmount`** *(optional)*: The raw balance of the Jetton token. Present only if `exists` is `true`.
|
|
1064
|
+
- **`decimals`** *(optional)*: The number of decimals for the Jetton token. Present only if `exists` is `true`.
|
|
1065
|
+
|
|
1066
|
+
|
|
1067
|
+
### `EVMSimulationResults`
|
|
1068
|
+
|
|
1069
|
+
```typescript
|
|
1070
|
+
export type EVMSimulationResults = {
|
|
1071
|
+
estimatedGas: bigint;
|
|
1072
|
+
estimatedJettonFeeAmount: string;
|
|
1073
|
+
feeParams: {
|
|
1074
|
+
currentBaseFee: string;
|
|
1075
|
+
isEip1559: boolean;
|
|
1076
|
+
suggestedGasPrice: string;
|
|
1077
|
+
suggestedGasTip: string;
|
|
1078
|
+
};
|
|
1079
|
+
message: string;
|
|
1080
|
+
outMessages:
|
|
1081
|
+
| {
|
|
1082
|
+
callerAddress: string;
|
|
1083
|
+
operationId: string;
|
|
1084
|
+
payload: string;
|
|
1085
|
+
queryId: number;
|
|
1086
|
+
targetAddress: string;
|
|
1087
|
+
tokensBurned: {
|
|
1088
|
+
amount: string;
|
|
1089
|
+
tokenAddress: string;
|
|
1090
|
+
}[];
|
|
1091
|
+
tokensLocked: {
|
|
1092
|
+
amount: string;
|
|
1093
|
+
tokenAddress: string;
|
|
1094
|
+
}[];
|
|
1095
|
+
}[]
|
|
1096
|
+
| null;
|
|
1097
|
+
simulationError: string;
|
|
1098
|
+
simulationStatus: boolean;
|
|
1099
|
+
debugInfo: {
|
|
1100
|
+
from: string;
|
|
1101
|
+
to: string;
|
|
1102
|
+
callData: string;
|
|
1103
|
+
blockNumber: number;
|
|
1104
|
+
};
|
|
1105
|
+
};
|
|
1106
|
+
```
|
|
1107
|
+
Provides EVM simulation results.
|
|
1108
|
+
|
|
1109
|
+
- **`estimatedGas`**: The estimated gas required for the message.
|
|
1110
|
+
- **`estimatedJettonFeeAmount`**: The estimated fee amount in Jettons.
|
|
1111
|
+
- **`feeParams`**: The parameters related to the fee.
|
|
1112
|
+
- **`currentBaseFee`**: The current base fee.
|
|
1113
|
+
- **`isEip1559`**: Indicates if EIP-1559 is applied.
|
|
1114
|
+
- **`suggestedGasPrice`**: The suggested gas price.
|
|
1115
|
+
- **`suggestedGasTip`**: The suggested gas tip.
|
|
1116
|
+
- **`message`**: The message details.
|
|
1117
|
+
- **`outMessages`** *(optional)*: The outgoing messages. Maybe `null` if there is a bridge operation.
|
|
1118
|
+
- **`callerAddress`**: The address of the caller.
|
|
1119
|
+
- **`operationId`**: The operation ID.
|
|
1120
|
+
- **`payload`**: The payload.
|
|
1121
|
+
- **`queryId`**: The query ID.
|
|
1122
|
+
- **`targetAddress`**: The target address.
|
|
1123
|
+
- **`tokensBurned`**: The tokens burned.
|
|
1124
|
+
- **`amount`**: The amount of tokens burned.
|
|
1125
|
+
- **`tokenAddress`**: The address of the token.
|
|
1126
|
+
- **`tokensLocked`**: The tokens locked.
|
|
1127
|
+
- **`simulationError`**: Any error encountered during the simulation.
|
|
1128
|
+
- **`simulationStatus`**: The status of the simulation.
|
|
1129
|
+
- **`debugInfo`**: Debugging information.
|
|
1130
|
+
- **`from`**: The sender address.
|
|
1131
|
+
- **`to`**: The recipient address.
|
|
1132
|
+
- **`callData`**: The call data.
|
|
1133
|
+
- **`blockNumber`**: The block number.
|
|
1134
|
+
---
|
|
1135
|
+
|
|
1136
|
+
## Usage
|
|
1137
|
+
|
|
1138
|
+
```typescript
|
|
1139
|
+
import { TacSdk } from '@tonappchain/sdk';
|
|
1140
|
+
import { TonConnectUI } from '@tonconnect/ui';
|
|
1141
|
+
import { ethers } from 'ethers';
|
|
1142
|
+
|
|
1143
|
+
// Create EVM payload for DappProxy
|
|
1144
|
+
const abi = new ethers.AbiCoder();
|
|
1145
|
+
const encodedParameters = abi.encode(
|
|
1146
|
+
['tuple(uint256,uint256,address[],address)'],
|
|
1147
|
+
[
|
|
1148
|
+
[
|
|
1149
|
+
tokenAAmount,
|
|
1150
|
+
tokenBAmount,
|
|
1151
|
+
[EVMtokenAAddress, EVMtokenBAddress],
|
|
1152
|
+
proxyDapp
|
|
1153
|
+
]
|
|
1154
|
+
]
|
|
1155
|
+
);
|
|
1156
|
+
const evmProxyMsg: EvmProxyMsg = {
|
|
1157
|
+
evmTargetAddress: DappProxyAddress,
|
|
1158
|
+
methodName: 'addLiquidity',
|
|
1159
|
+
encodedParameters
|
|
1160
|
+
};
|
|
1161
|
+
|
|
1162
|
+
// Create jetton transfer messages corresponding to EVM tokens, e.g., two tokens for adding liquidity to a pool
|
|
1163
|
+
const assets: AssetBridgingData[] = [
|
|
1164
|
+
{
|
|
1165
|
+
address: TVMtokenAAddress,
|
|
1166
|
+
amount: tokenAAmount
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
address: TVMtokenBAddress,
|
|
1170
|
+
amount: tokenBAmount
|
|
1171
|
+
}
|
|
1172
|
+
];
|
|
1173
|
+
|
|
1174
|
+
const sdkParams: SDKParams = {
|
|
1175
|
+
network: Network.Testnet
|
|
1176
|
+
};
|
|
1177
|
+
const tacSdk = await TacSdk.create(sdkParams);
|
|
1178
|
+
|
|
1179
|
+
//Send transaction via tonConnect or mnemonic
|
|
1180
|
+
const tonConnectUI = new TonConnectUI({
|
|
1181
|
+
manifestUrl: config.tonconnectManifestUrl as string
|
|
1182
|
+
});
|
|
1183
|
+
const sender = await SenderFactory.getSender({
|
|
1184
|
+
tonConnect: tonConnectUI
|
|
1185
|
+
});
|
|
1186
|
+
|
|
1187
|
+
await tacSdk.sendCrossChainTransaction(evmProxyMsg, sender, assets);
|
|
1188
|
+
|
|
1189
|
+
tacSdk.closeConnections();
|
|
1190
|
+
```
|
|
1191
|
+
For a detailed example, see `test/sendSwap.ts` or `test/sendRemoveLiquidity.ts`, which demonstrates swapping tokens and removing liquidity on Uniswap and tracking the transaction status.
|
|
1192
|
+
|
|
1193
|
+
---
|
|
1194
|
+
|
|
1195
|
+
## License
|
|
1196
|
+
|
|
1197
|
+
MIT
|