@heyanon/sdk 2.3.2 → 2.3.4
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/adapter/misc.d.ts +35 -0
- package/dist/adapter/transformers/toResult.d.ts +24 -0
- package/dist/adapter/types.d.ts +123 -7
- package/dist/blockchain/constants/chains.d.ts +93 -0
- package/dist/blockchain/constants/types.d.ts +33 -0
- package/dist/blockchain/evm/constants/chains.d.ts +56 -0
- package/dist/blockchain/evm/constants/misc.d.ts +69 -0
- package/dist/blockchain/evm/constants/weth9.d.ts +76 -1
- package/dist/blockchain/evm/types.d.ts +273 -0
- package/dist/blockchain/evm/utils/checkToApprove.d.ts +86 -0
- package/dist/blockchain/evm/utils/getChainFromName.d.ts +81 -0
- package/dist/blockchain/evm/utils/getChainName.d.ts +114 -0
- package/dist/blockchain/evm/utils/getUnwrapData.d.ts +114 -0
- package/dist/blockchain/evm/utils/getWrapAddress.d.ts +147 -0
- package/dist/blockchain/evm/utils/getWrapData.d.ts +189 -0
- package/dist/blockchain/evm/utils/getWrappedNative.d.ts +198 -0
- package/dist/blockchain/evm/utils/isEvmChain.d.ts +183 -0
- package/dist/blockchain/evm/utils/isNativeAddress.d.ts +221 -0
- package/dist/blockchain/evm/utils/isNativeAddress.test.d.ts +1 -0
- package/dist/blockchain/solana/types.d.ts +291 -0
- package/dist/blockchain/solana/utils/buildV0Transaction.d.ts +184 -0
- package/dist/blockchain/solana/utils/toPublicKey.d.ts +194 -0
- package/dist/blockchain/ton/types.d.ts +410 -0
- package/dist/index.js +83 -26
- package/dist/index.mjs +84 -28
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/is-address.d.ts +7 -0
- package/dist/utils/is-address.spec.d.ts +1 -0
- package/dist/utils/retry.d.ts +218 -0
- package/dist/utils/sleep.d.ts +239 -0
- package/dist/utils/stringify.d.ts +235 -0
- package/dist/utils/stringify.spec.d.ts +1 -0
- package/package.json +2 -1
|
@@ -2,20 +2,430 @@ import { SenderArguments } from '@ton/core';
|
|
|
2
2
|
import { TonApiClient } from '@ton-api/client';
|
|
3
3
|
import { ContractAdapter } from '@ton-api/ton-adapter';
|
|
4
4
|
import { Address, TonClient, TonClient4 } from '@ton/ton';
|
|
5
|
+
/**
|
|
6
|
+
* Data returned for each executed TON transaction
|
|
7
|
+
* @interface TransactionReturnData
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Successful transaction result
|
|
11
|
+
* const successData: TransactionReturnData = {
|
|
12
|
+
* message: "Transaction confirmed",
|
|
13
|
+
* hash: "a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456"
|
|
14
|
+
* };
|
|
15
|
+
*
|
|
16
|
+
* // Failed transaction result
|
|
17
|
+
* const failedData: TransactionReturnData = {
|
|
18
|
+
* message: "Transaction failed: Insufficient balance",
|
|
19
|
+
* hash: "b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef1234567a"
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* // Process transaction result
|
|
23
|
+
* function handleTonTransactionResult(result: TransactionReturnData) {
|
|
24
|
+
* console.log(`Status: ${result.message}`);
|
|
25
|
+
* console.log(`Transaction: https://tonscan.org/tx/${result.hash}`);
|
|
26
|
+
*
|
|
27
|
+
* if (result.message.includes('confirmed')) {
|
|
28
|
+
* // Handle success
|
|
29
|
+
* showSuccessNotification(`Transaction confirmed: ${result.hash}`);
|
|
30
|
+
* } else {
|
|
31
|
+
* // Handle error
|
|
32
|
+
* showErrorNotification(result.message);
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* // Extract transaction details
|
|
37
|
+
* function parseTransactionResult(result: TransactionReturnData) {
|
|
38
|
+
* return {
|
|
39
|
+
* isSuccess: result.message.includes('confirmed') || result.message.includes('successful'),
|
|
40
|
+
* transactionId: result.hash,
|
|
41
|
+
* explorerUrl: `https://tonscan.org/tx/${result.hash}`,
|
|
42
|
+
* statusMessage: result.message
|
|
43
|
+
* };
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
5
47
|
export interface TransactionReturnData {
|
|
48
|
+
/** Status message or error description */
|
|
6
49
|
readonly message: string;
|
|
50
|
+
/** Transaction hash on TON blockchain */
|
|
7
51
|
readonly hash: string;
|
|
8
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Complete result of TON transaction execution containing all transaction results
|
|
55
|
+
* @interface TransactionReturn
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // Batch transaction result
|
|
59
|
+
* const batchResult: TransactionReturn = {
|
|
60
|
+
* data: [
|
|
61
|
+
* {
|
|
62
|
+
* message: "TON transfer confirmed",
|
|
63
|
+
* hash: "a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456"
|
|
64
|
+
* },
|
|
65
|
+
* {
|
|
66
|
+
* message: "Jetton transfer completed",
|
|
67
|
+
* hash: "b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef1234567a"
|
|
68
|
+
* }
|
|
69
|
+
* ]
|
|
70
|
+
* };
|
|
71
|
+
*
|
|
72
|
+
* // Single transaction result
|
|
73
|
+
* const singleResult: TransactionReturn = {
|
|
74
|
+
* data: [{
|
|
75
|
+
* message: "Smart contract deployment successful",
|
|
76
|
+
* hash: "c3d4e5f6789012345678901234567890abcdef1234567890abcdef1234567ab2"
|
|
77
|
+
* }]
|
|
78
|
+
* };
|
|
79
|
+
*
|
|
80
|
+
* // Process all results
|
|
81
|
+
* function processTonBatchResults(result: TransactionReturn) {
|
|
82
|
+
* const successful = result.data.filter(tx =>
|
|
83
|
+
* tx.message.includes('confirmed') ||
|
|
84
|
+
* tx.message.includes('successful') ||
|
|
85
|
+
* tx.message.includes('completed')
|
|
86
|
+
* );
|
|
87
|
+
*
|
|
88
|
+
* const failed = result.data.filter(tx =>
|
|
89
|
+
* tx.message.includes('failed') ||
|
|
90
|
+
* tx.message.includes('error') ||
|
|
91
|
+
* tx.message.includes('rejected')
|
|
92
|
+
* );
|
|
93
|
+
*
|
|
94
|
+
* console.log(`TON Transactions - Successful: ${successful.length}, Failed: ${failed.length}`);
|
|
95
|
+
*
|
|
96
|
+
* // Create comprehensive summary
|
|
97
|
+
* return {
|
|
98
|
+
* totalTransactions: result.data.length,
|
|
99
|
+
* successCount: successful.length,
|
|
100
|
+
* failureCount: failed.length,
|
|
101
|
+
* successfulHashes: successful.map(tx => tx.hash),
|
|
102
|
+
* failedHashes: failed.map(tx => tx.hash),
|
|
103
|
+
* explorerLinks: result.data.map(tx => `https://tonscan.org/tx/${tx.hash}`)
|
|
104
|
+
* };
|
|
105
|
+
* }
|
|
106
|
+
*
|
|
107
|
+
* // Calculate transaction fees
|
|
108
|
+
* async function calculateTransactionCosts(result: TransactionReturn, client: Client) {
|
|
109
|
+
* const costs = await Promise.all(
|
|
110
|
+
* result.data.map(async (tx) => {
|
|
111
|
+
* try {
|
|
112
|
+
* const txData = await client.api.blockchain.getBlockchainTransaction(tx.hash);
|
|
113
|
+
* return {
|
|
114
|
+
* hash: tx.hash,
|
|
115
|
+
* fee: txData.fee.total,
|
|
116
|
+
* success: tx.message.includes('confirmed')
|
|
117
|
+
* };
|
|
118
|
+
* } catch (error) {
|
|
119
|
+
* return {
|
|
120
|
+
* hash: tx.hash,
|
|
121
|
+
* fee: 0,
|
|
122
|
+
* success: false,
|
|
123
|
+
* error: error.message
|
|
124
|
+
* };
|
|
125
|
+
* }
|
|
126
|
+
* })
|
|
127
|
+
* );
|
|
128
|
+
*
|
|
129
|
+
* return costs;
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
9
133
|
export interface TransactionReturn {
|
|
134
|
+
/** Array of transaction results */
|
|
10
135
|
readonly data: TransactionReturnData[];
|
|
11
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Properties for sending one or multiple TON transactions
|
|
139
|
+
* @interface SendTransactionProps
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* // Simple TON transfer
|
|
143
|
+
* const transferProps: SendTransactionProps = {
|
|
144
|
+
* account: Address.parse('EQD4FPq-PRDieyQKkizFTRtSDyucUIqrj0v_zXJmqaDp6_0t'),
|
|
145
|
+
* transactions: [{
|
|
146
|
+
* to: Address.parse('EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N'),
|
|
147
|
+
* value: toNano('1'), // 1 TON
|
|
148
|
+
* body: beginCell().endCell(), // Empty body for simple transfer
|
|
149
|
+
* bounce: false
|
|
150
|
+
* }]
|
|
151
|
+
* };
|
|
152
|
+
*
|
|
153
|
+
* // Jetton (TON token) transfer
|
|
154
|
+
* const jettonTransferProps: SendTransactionProps = {
|
|
155
|
+
* account: senderAddress,
|
|
156
|
+
* transactions: [{
|
|
157
|
+
* to: jettonWalletAddress,
|
|
158
|
+
* value: toNano('0.1'), // Gas fee
|
|
159
|
+
* body: beginCell()
|
|
160
|
+
* .storeUint(0xf8a7ea5, 32) // Jetton transfer opcode
|
|
161
|
+
* .storeUint(0, 64) // Query ID
|
|
162
|
+
* .storeCoins(toNano('100')) // Jetton amount
|
|
163
|
+
* .storeAddress(recipientAddress)
|
|
164
|
+
* .storeAddress(senderAddress) // Response address
|
|
165
|
+
* .storeBit(0) // Custom payload
|
|
166
|
+
* .storeCoins(toNano('0.01')) // Forward amount
|
|
167
|
+
* .storeBit(0) // Forward payload
|
|
168
|
+
* .endCell(),
|
|
169
|
+
* bounce: false
|
|
170
|
+
* }]
|
|
171
|
+
* };
|
|
172
|
+
*
|
|
173
|
+
* // Smart contract deployment
|
|
174
|
+
* const deployProps: SendTransactionProps = {
|
|
175
|
+
* account: deployerAddress,
|
|
176
|
+
* transactions: [{
|
|
177
|
+
* to: contractAddress,
|
|
178
|
+
* value: toNano('0.5'), // Initial contract balance
|
|
179
|
+
* body: beginCell()
|
|
180
|
+
* .storeRef(contractCode) // Contract code
|
|
181
|
+
* .storeRef(contractData) // Initial data
|
|
182
|
+
* .endCell(),
|
|
183
|
+
* bounce: false,
|
|
184
|
+
* init: {
|
|
185
|
+
* code: contractCode,
|
|
186
|
+
* data: contractData
|
|
187
|
+
* }
|
|
188
|
+
* }]
|
|
189
|
+
* };
|
|
190
|
+
*
|
|
191
|
+
* // Batch operations (multiple transactions)
|
|
192
|
+
* const batchProps: SendTransactionProps = {
|
|
193
|
+
* account: userAddress,
|
|
194
|
+
* transactions: [
|
|
195
|
+
* {
|
|
196
|
+
* to: Address.parse('EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N'),
|
|
197
|
+
* value: toNano('0.5'),
|
|
198
|
+
* body: beginCell().endCell(),
|
|
199
|
+
* bounce: false
|
|
200
|
+
* },
|
|
201
|
+
* {
|
|
202
|
+
* to: jettonMasterAddress,
|
|
203
|
+
* value: toNano('0.1'),
|
|
204
|
+
* body: buildJettonMintBody({
|
|
205
|
+
* recipient: userAddress,
|
|
206
|
+
* amount: toNano('1000'),
|
|
207
|
+
* queryId: Date.now()
|
|
208
|
+
* }),
|
|
209
|
+
* bounce: true
|
|
210
|
+
* }
|
|
211
|
+
* ]
|
|
212
|
+
* };
|
|
213
|
+
*
|
|
214
|
+
* // DEX operations (DeDust swap)
|
|
215
|
+
* const swapProps: SendTransactionProps = {
|
|
216
|
+
* account: await options.ton.getAddress(),
|
|
217
|
+
* transactions: [{
|
|
218
|
+
* to: poolAddress,
|
|
219
|
+
* value: toNano('1.5'), // TON amount + gas
|
|
220
|
+
* body: beginCell()
|
|
221
|
+
* .storeUint(0xea06185d, 32) // Swap opcode
|
|
222
|
+
* .storeUint(0, 64) // Query ID
|
|
223
|
+
* .storeCoins(toNano('1')) // Amount in
|
|
224
|
+
* .storeAddress(jettonAddressOut)
|
|
225
|
+
* .storeCoins(minAmountOut)
|
|
226
|
+
* .storeAddress(userAddress) // Recipient
|
|
227
|
+
* .endCell(),
|
|
228
|
+
* bounce: true
|
|
229
|
+
* }]
|
|
230
|
+
* };
|
|
231
|
+
*
|
|
232
|
+
* // NFT operations
|
|
233
|
+
* const nftTransferProps: SendTransactionProps = {
|
|
234
|
+
* account: nftOwnerAddress,
|
|
235
|
+
* transactions: [{
|
|
236
|
+
* to: nftItemAddress,
|
|
237
|
+
* value: toNano('0.1'),
|
|
238
|
+
* body: beginCell()
|
|
239
|
+
* .storeUint(0x5fcc3d14, 32) // NFT transfer opcode
|
|
240
|
+
* .storeUint(0, 64) // Query ID
|
|
241
|
+
* .storeAddress(newOwnerAddress)
|
|
242
|
+
* .storeAddress(nftOwnerAddress) // Response address
|
|
243
|
+
* .storeBit(0) // Custom payload
|
|
244
|
+
* .storeCoins(toNano('0.01')) // Forward amount
|
|
245
|
+
* .endCell(),
|
|
246
|
+
* bounce: false
|
|
247
|
+
* }]
|
|
248
|
+
* };
|
|
249
|
+
*
|
|
250
|
+
* // Usage in adapter function
|
|
251
|
+
* async function executeTonTransactions(props: SendTransactionProps) {
|
|
252
|
+
* const result = await options.ton.sendTransactions(props);
|
|
253
|
+
*
|
|
254
|
+
* // Log all transaction hashes
|
|
255
|
+
* result.data.forEach((tx, index) => {
|
|
256
|
+
* console.log(`TON Transaction ${index + 1}: ${tx.hash}`);
|
|
257
|
+
* console.log(`Status: ${tx.message}`);
|
|
258
|
+
* });
|
|
259
|
+
*
|
|
260
|
+
* return result;
|
|
261
|
+
* }
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
12
264
|
export interface SendTransactionProps {
|
|
265
|
+
/** Account that will execute the transactions */
|
|
13
266
|
readonly account: Address;
|
|
267
|
+
/** Array of TON transaction arguments */
|
|
14
268
|
readonly transactions: SenderArguments[];
|
|
15
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* TON blockchain client configuration with multiple client types and adapters
|
|
272
|
+
* @interface Client
|
|
273
|
+
* @example
|
|
274
|
+
* ```typescript
|
|
275
|
+
* // Create TON client configuration
|
|
276
|
+
* const tonClient: Client = {
|
|
277
|
+
* api: new TonApiClient({
|
|
278
|
+
* baseUrl: 'https://tonapi.io',
|
|
279
|
+
* apiKey: 'your-api-key'
|
|
280
|
+
* }),
|
|
281
|
+
* client: new TonClient({
|
|
282
|
+
* endpoint: 'https://toncenter.com/api/v2/jsonRPC'
|
|
283
|
+
* }),
|
|
284
|
+
* client4: new TonClient4({
|
|
285
|
+
* endpoint: 'https://mainnet-v4.tonhubapi.com'
|
|
286
|
+
* }),
|
|
287
|
+
* adapter: new ContractAdapter()
|
|
288
|
+
* };
|
|
289
|
+
*
|
|
290
|
+
* // Use different clients for different operations
|
|
291
|
+
* async function getTonAccountInfo(address: Address, client: Client) {
|
|
292
|
+
* // Use TonApiClient for rich API data
|
|
293
|
+
* const accountInfo = await client.api.accounts.getAccount(address.toString());
|
|
294
|
+
*
|
|
295
|
+
* // Use TonClient for basic operations
|
|
296
|
+
* const balance = await client.client.getBalance(address);
|
|
297
|
+
*
|
|
298
|
+
* // Use TonClient4 for v4 API features
|
|
299
|
+
* const accountState = await client.client4.getAccount(
|
|
300
|
+
* client.client4.provider.block.lastSeqno,
|
|
301
|
+
* address
|
|
302
|
+
* );
|
|
303
|
+
*
|
|
304
|
+
* return {
|
|
305
|
+
* address: address.toString(),
|
|
306
|
+
* balance: balance.toString(),
|
|
307
|
+
* status: accountInfo.status,
|
|
308
|
+
* lastActivity: accountInfo.lastActivity,
|
|
309
|
+
* interfaces: accountInfo.interfaces
|
|
310
|
+
* };
|
|
311
|
+
* }
|
|
312
|
+
*
|
|
313
|
+
* // Smart contract interaction
|
|
314
|
+
* async function interactWithContract(
|
|
315
|
+
* contractAddress: Address,
|
|
316
|
+
* method: string,
|
|
317
|
+
* params: any[],
|
|
318
|
+
* client: Client
|
|
319
|
+
* ) {
|
|
320
|
+
* // Use adapter for contract interactions
|
|
321
|
+
* const contract = client.adapter.open(
|
|
322
|
+
* Contract.create({
|
|
323
|
+
* workchain: contractAddress.workChain,
|
|
324
|
+
* address: contractAddress.hash
|
|
325
|
+
* }, contractCode)
|
|
326
|
+
* );
|
|
327
|
+
*
|
|
328
|
+
* // Call contract method
|
|
329
|
+
* const result = await contract.get(method, params);
|
|
330
|
+
* return result;
|
|
331
|
+
* }
|
|
332
|
+
*
|
|
333
|
+
* // Jetton operations using different clients
|
|
334
|
+
* async function getJettonInfo(jettonMaster: Address, client: Client) {
|
|
335
|
+
* // Get jetton data using API client
|
|
336
|
+
* const jettonInfo = await client.api.jettons.getJetton(jettonMaster.toString());
|
|
337
|
+
*
|
|
338
|
+
* // Get on-chain data using TonClient
|
|
339
|
+
* const jettonData = await client.client.runMethod(jettonMaster, 'get_jetton_data');
|
|
340
|
+
*
|
|
341
|
+
* return {
|
|
342
|
+
* name: jettonInfo.metadata?.name,
|
|
343
|
+
* symbol: jettonInfo.metadata?.symbol,
|
|
344
|
+
* decimals: jettonInfo.metadata?.decimals,
|
|
345
|
+
* totalSupply: jettonData.stack.readBigNumber(),
|
|
346
|
+
* mintable: jettonData.stack.readBoolean(),
|
|
347
|
+
* adminAddress: jettonData.stack.readAddress()
|
|
348
|
+
* };
|
|
349
|
+
* }
|
|
350
|
+
*
|
|
351
|
+
* // Transaction tracking
|
|
352
|
+
* async function trackTransaction(hash: string, client: Client) {
|
|
353
|
+
* try {
|
|
354
|
+
* // Use API client for detailed transaction info
|
|
355
|
+
* const txInfo = await client.api.blockchain.getBlockchainTransaction(hash);
|
|
356
|
+
*
|
|
357
|
+
* return {
|
|
358
|
+
* hash: txInfo.hash,
|
|
359
|
+
* success: txInfo.success,
|
|
360
|
+
* fee: txInfo.fee.total,
|
|
361
|
+
* timestamp: txInfo.utime,
|
|
362
|
+
* inMsg: txInfo.inMsg,
|
|
363
|
+
* outMsgs: txInfo.outMsgs
|
|
364
|
+
* };
|
|
365
|
+
* } catch (error) {
|
|
366
|
+
* console.error('Failed to track transaction:', error);
|
|
367
|
+
* return null;
|
|
368
|
+
* }
|
|
369
|
+
* }
|
|
370
|
+
*
|
|
371
|
+
* // Multi-client balance checking
|
|
372
|
+
* async function getComprehensiveBalance(address: Address, client: Client) {
|
|
373
|
+
* const [apiBalance, clientBalance, client4Balance] = await Promise.allSettled([
|
|
374
|
+
* client.api.accounts.getAccount(address.toString())
|
|
375
|
+
* .then(acc => acc.balance),
|
|
376
|
+
* client.client.getBalance(address),
|
|
377
|
+
* client.client4.getAccount(
|
|
378
|
+
* await client.client4.provider.block.lastSeqno,
|
|
379
|
+
* address
|
|
380
|
+
* ).then(acc => acc.account.balance?.coins || 0n)
|
|
381
|
+
* ]);
|
|
382
|
+
*
|
|
383
|
+
* return {
|
|
384
|
+
* api: apiBalance.status === 'fulfilled' ? apiBalance.value : null,
|
|
385
|
+
* client: clientBalance.status === 'fulfilled' ? clientBalance.value : null,
|
|
386
|
+
* client4: client4Balance.status === 'fulfilled' ? client4Balance.value : null
|
|
387
|
+
* };
|
|
388
|
+
* }
|
|
389
|
+
*
|
|
390
|
+
* // Initialize client with configuration
|
|
391
|
+
* function createTonClient(config: {
|
|
392
|
+
* apiKey?: string;
|
|
393
|
+
* network?: 'mainnet' | 'testnet';
|
|
394
|
+
* endpoints?: {
|
|
395
|
+
* api?: string;
|
|
396
|
+
* client?: string;
|
|
397
|
+
* client4?: string;
|
|
398
|
+
* };
|
|
399
|
+
* }): Client {
|
|
400
|
+
* const isTestnet = config.network === 'testnet';
|
|
401
|
+
*
|
|
402
|
+
* return {
|
|
403
|
+
* api: new TonApiClient({
|
|
404
|
+
* baseUrl: config.endpoints?.api || (isTestnet ? 'https://testnet.tonapi.io' : 'https://tonapi.io'),
|
|
405
|
+
* apiKey: config.apiKey
|
|
406
|
+
* }),
|
|
407
|
+
* client: new TonClient({
|
|
408
|
+
* endpoint: config.endpoints?.client || (isTestnet
|
|
409
|
+
* ? 'https://testnet.toncenter.com/api/v2/jsonRPC'
|
|
410
|
+
* : 'https://toncenter.com/api/v2/jsonRPC')
|
|
411
|
+
* }),
|
|
412
|
+
* client4: new TonClient4({
|
|
413
|
+
* endpoint: config.endpoints?.client4 || (isTestnet
|
|
414
|
+
* ? 'https://testnet-v4.tonhubapi.com'
|
|
415
|
+
* : 'https://mainnet-v4.tonhubapi.com')
|
|
416
|
+
* }),
|
|
417
|
+
* adapter: new ContractAdapter()
|
|
418
|
+
* };
|
|
419
|
+
* }
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
16
422
|
export interface Client {
|
|
423
|
+
/** TON API client for rich blockchain data and operations */
|
|
17
424
|
readonly api: TonApiClient;
|
|
425
|
+
/** Standard TON client for basic blockchain operations */
|
|
18
426
|
readonly client: TonClient;
|
|
427
|
+
/** TON v4 client for advanced features and better performance */
|
|
19
428
|
readonly client4: TonClient4;
|
|
429
|
+
/** Contract adapter for smart contract interactions */
|
|
20
430
|
readonly adapter: ContractAdapter;
|
|
21
431
|
}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var viem = require('viem');
|
|
4
4
|
var sdk = require('@real-wagmi/sdk');
|
|
5
5
|
var web3_js = require('@solana/web3.js');
|
|
6
|
+
var ton = require('@ton/ton');
|
|
6
7
|
|
|
7
8
|
var __defProp = Object.defineProperty;
|
|
8
9
|
var __export = (target, all) => {
|
|
@@ -38,32 +39,6 @@ function stringify(value, space) {
|
|
|
38
39
|
return JSON.stringify(value, (_key, value2) => typeof value2 === "bigint" ? value2.toString() : value2, space);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
// src/adapter/transformers/toResult.ts
|
|
42
|
-
function toResult(data, error = false) {
|
|
43
|
-
const formatedData = typeof data === "string" ? data : stringify(data);
|
|
44
|
-
return {
|
|
45
|
-
success: !error,
|
|
46
|
-
data: error ? `ERROR: ${formatedData}` : formatedData
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// src/adapter/misc.ts
|
|
51
|
-
var AdapterTag = /* @__PURE__ */ ((AdapterTag2) => {
|
|
52
|
-
AdapterTag2["ALM"] = "ALM";
|
|
53
|
-
AdapterTag2["STAKE"] = "Stake";
|
|
54
|
-
AdapterTag2["LENDING"] = "Lending";
|
|
55
|
-
AdapterTag2["FARM"] = "Farm";
|
|
56
|
-
AdapterTag2["PERPETUALS"] = "Perpetuals";
|
|
57
|
-
AdapterTag2["BRIDGE"] = "Bridge";
|
|
58
|
-
AdapterTag2["LIMIT_ORDER"] = "Limit orders";
|
|
59
|
-
AdapterTag2["DEX"] = "DEX";
|
|
60
|
-
AdapterTag2["LP"] = "LP";
|
|
61
|
-
AdapterTag2["GAMES"] = "Games";
|
|
62
|
-
AdapterTag2["CEX"] = "CEX";
|
|
63
|
-
AdapterTag2["LAUNCHPAD"] = "Launchpad";
|
|
64
|
-
return AdapterTag2;
|
|
65
|
-
})(AdapterTag || {});
|
|
66
|
-
|
|
67
42
|
// src/blockchain/evm/index.ts
|
|
68
43
|
var evm_exports = {};
|
|
69
44
|
__export(evm_exports, {
|
|
@@ -89,7 +64,9 @@ __export(utils_exports, {
|
|
|
89
64
|
isEvmChain: () => isEvmChain
|
|
90
65
|
});
|
|
91
66
|
var ZERO_ALLOWANCE = {
|
|
67
|
+
/** Ethereum mainnet tokens requiring zero allowance reset */
|
|
92
68
|
1: ["0xdAC17F958D2ee523a2206206994597C13D831ec7"]
|
|
69
|
+
// USDT
|
|
93
70
|
};
|
|
94
71
|
async function checkToApprove({ args, transactions, provider }) {
|
|
95
72
|
const { account, target, spender, amount } = args;
|
|
@@ -174,39 +151,69 @@ var WalletType = /* @__PURE__ */ ((WalletType2) => {
|
|
|
174
151
|
|
|
175
152
|
// src/blockchain/evm/constants/chains.ts
|
|
176
153
|
var ChainIds = {
|
|
154
|
+
/** Ethereum Mainnet - Chain ID: 1 */
|
|
177
155
|
["ethereum" /* ETHEREUM */]: 1,
|
|
156
|
+
/** Optimism - Chain ID: 10 */
|
|
178
157
|
["optimism" /* OPTIMISM */]: 10,
|
|
158
|
+
/** Binance Smart Chain - Chain ID: 56 */
|
|
179
159
|
["bsc" /* BSC */]: 56,
|
|
160
|
+
/** Gnosis Chain - Chain ID: 100 */
|
|
180
161
|
["gnosis" /* GNOSIS */]: 100,
|
|
162
|
+
/** Polygon - Chain ID: 137 */
|
|
181
163
|
["polygon" /* POLYGON */]: 137,
|
|
164
|
+
/** Sonic - Chain ID: 146 */
|
|
182
165
|
["sonic" /* SONIC */]: 146,
|
|
166
|
+
/** zkSync Era - Chain ID: 324 */
|
|
183
167
|
["zksync" /* ZKSYNC */]: 324,
|
|
168
|
+
/** Metis Andromeda - Chain ID: 1088 */
|
|
184
169
|
["metis" /* METIS */]: 1088,
|
|
170
|
+
/** Kava EVM - Chain ID: 2222 */
|
|
185
171
|
["kava_evm" /* KAVA_EVM */]: 2222,
|
|
172
|
+
/** Base - Chain ID: 8453 */
|
|
186
173
|
["base" /* BASE */]: 8453,
|
|
174
|
+
/** Avalanche C-Chain - Chain ID: 43114 */
|
|
187
175
|
["avalanche" /* AVALANCHE */]: 43114,
|
|
176
|
+
/** Arbitrum One - Chain ID: 42161 */
|
|
188
177
|
["arbitrum" /* ARBITRUM */]: 42161,
|
|
178
|
+
/** Scroll - Chain ID: 534352 */
|
|
189
179
|
["scroll" /* SCROLL */]: 534352,
|
|
180
|
+
/** HyperEVM - Chain ID: 999 */
|
|
190
181
|
["hyperevm" /* HYPEREVM */]: 999,
|
|
182
|
+
/** Plasma - Chain ID: 9745 */
|
|
191
183
|
["plasma" /* PLASMA */]: 9745
|
|
192
184
|
};
|
|
193
185
|
|
|
194
186
|
// src/blockchain/evm/constants/weth9.ts
|
|
195
187
|
var WETH9 = {
|
|
188
|
+
/** Wrapped Ether (WETH) on Ethereum */
|
|
196
189
|
["ethereum" /* ETHEREUM */]: sdk.ethereumTokens.weth,
|
|
190
|
+
/** Wrapped Ether (WETH) on Optimism */
|
|
197
191
|
["optimism" /* OPTIMISM */]: sdk.optimismTokens.weth,
|
|
192
|
+
/** Wrapped BNB (WBNB) on Binance Smart Chain */
|
|
198
193
|
["bsc" /* BSC */]: sdk.bscTokens.wbnb,
|
|
194
|
+
/** Wrapped POL (WPOL) on Polygon */
|
|
199
195
|
["polygon" /* POLYGON */]: sdk.polygonTokens.wpol,
|
|
196
|
+
/** Wrapped Ether (WETH) on zkSync Era */
|
|
200
197
|
["zksync" /* ZKSYNC */]: sdk.zkSyncTokens.weth,
|
|
198
|
+
/** Wrapped KAVA (WKAVA) on Kava EVM */
|
|
201
199
|
["kava_evm" /* KAVA_EVM */]: sdk.kavaTokens.wkava,
|
|
200
|
+
/** Wrapped AVAX (WAVAX) on Avalanche */
|
|
202
201
|
["avalanche" /* AVALANCHE */]: sdk.avalancheTokens.wavax,
|
|
202
|
+
/** Wrapped Ether (WETH) on Arbitrum */
|
|
203
203
|
["arbitrum" /* ARBITRUM */]: sdk.arbitrumTokens.weth,
|
|
204
|
+
/** Wrapped METIS (WMETIS) on Metis */
|
|
204
205
|
["metis" /* METIS */]: sdk.metisTokens.wmetis,
|
|
206
|
+
/** Wrapped Ether (WETH) on Base */
|
|
205
207
|
["base" /* BASE */]: sdk.baseTokens.weth,
|
|
208
|
+
/** Wrapped S (WS) on Sonic */
|
|
206
209
|
["sonic" /* SONIC */]: sdk.sonicTokens.ws,
|
|
210
|
+
/** Wrapped Ether (WETH) on Scroll */
|
|
207
211
|
["scroll" /* SCROLL */]: new sdk.Token(ChainIds["scroll" /* SCROLL */], "0x5300000000000000000000000000000000000004", 18, "WETH", "Wrapped Ether"),
|
|
212
|
+
/** Wrapped xDAI (WXDAI) on Gnosis Chain */
|
|
208
213
|
["gnosis" /* GNOSIS */]: new sdk.Token(ChainIds["gnosis" /* GNOSIS */], "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d", 18, "WXDAI", "Wrapped XDAI"),
|
|
214
|
+
/** Wrapped HYPE (WHYPE) on HyperEVM */
|
|
209
215
|
["hyperevm" /* HYPEREVM */]: new sdk.Token(ChainIds["hyperevm" /* HYPEREVM */], "0x5555555555555555555555555555555555555555", 18, "WHYPE", "Wrapped HYPE"),
|
|
216
|
+
/** Wrapped XPL (WXPL) on Plasma */
|
|
210
217
|
["plasma" /* PLASMA */]: new sdk.Token(ChainIds["plasma" /* PLASMA */], "0x6100E367285b01F48D07953803A2d8dCA5D19873", 18, "WXPL", "Wrapped XPL")
|
|
211
218
|
};
|
|
212
219
|
|
|
@@ -568,6 +575,55 @@ __export(ton_exports, {
|
|
|
568
575
|
|
|
569
576
|
// src/blockchain/ton/types.ts
|
|
570
577
|
var types_exports3 = {};
|
|
578
|
+
function isAddress(value) {
|
|
579
|
+
let result = { valid: false };
|
|
580
|
+
try {
|
|
581
|
+
result.valid = viem.isAddress(value);
|
|
582
|
+
if (result.valid) {
|
|
583
|
+
result.walletType = "evm" /* EVM */;
|
|
584
|
+
}
|
|
585
|
+
} catch (_error) {
|
|
586
|
+
}
|
|
587
|
+
try {
|
|
588
|
+
solana_exports.utils.toPublicKey(value);
|
|
589
|
+
result.valid = true;
|
|
590
|
+
result.walletType = "solana" /* SOLANA */;
|
|
591
|
+
} catch (_error) {
|
|
592
|
+
}
|
|
593
|
+
try {
|
|
594
|
+
ton.Address.parse(value);
|
|
595
|
+
result.valid = true;
|
|
596
|
+
result.walletType = "ton" /* TON */;
|
|
597
|
+
} catch (_error) {
|
|
598
|
+
}
|
|
599
|
+
return result;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// src/adapter/transformers/toResult.ts
|
|
603
|
+
function toResult(data, error = false) {
|
|
604
|
+
const formatedData = typeof data === "string" ? data : stringify(data);
|
|
605
|
+
return {
|
|
606
|
+
success: !error,
|
|
607
|
+
data: error ? `ERROR: ${formatedData}` : formatedData
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// src/adapter/misc.ts
|
|
612
|
+
var AdapterTag = /* @__PURE__ */ ((AdapterTag2) => {
|
|
613
|
+
AdapterTag2["ALM"] = "ALM";
|
|
614
|
+
AdapterTag2["STAKE"] = "Stake";
|
|
615
|
+
AdapterTag2["LENDING"] = "Lending";
|
|
616
|
+
AdapterTag2["FARM"] = "Farm";
|
|
617
|
+
AdapterTag2["PERPETUALS"] = "Perpetuals";
|
|
618
|
+
AdapterTag2["BRIDGE"] = "Bridge";
|
|
619
|
+
AdapterTag2["LIMIT_ORDER"] = "Limit orders";
|
|
620
|
+
AdapterTag2["DEX"] = "DEX";
|
|
621
|
+
AdapterTag2["LP"] = "LP";
|
|
622
|
+
AdapterTag2["GAMES"] = "Games";
|
|
623
|
+
AdapterTag2["CEX"] = "CEX";
|
|
624
|
+
AdapterTag2["LAUNCHPAD"] = "Launchpad";
|
|
625
|
+
return AdapterTag2;
|
|
626
|
+
})(AdapterTag || {});
|
|
571
627
|
|
|
572
628
|
exports.AdapterTag = AdapterTag;
|
|
573
629
|
exports.Chain = Chain;
|
|
@@ -577,6 +633,7 @@ exports.TON = ton_exports;
|
|
|
577
633
|
exports.WalletType = WalletType;
|
|
578
634
|
exports.allChains = allChains;
|
|
579
635
|
exports.allEvmChains = allEvmChains;
|
|
636
|
+
exports.isAddress = isAddress;
|
|
580
637
|
exports.retry = retry;
|
|
581
638
|
exports.sleep = sleep;
|
|
582
639
|
exports.stringify = stringify;
|