@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
|
@@ -1 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a JavaScript value to a JSON string with support for BigInt values
|
|
3
|
+
*
|
|
4
|
+
* This function extends the standard JSON.stringify to handle BigInt values,
|
|
5
|
+
* which are commonly used in blockchain applications for handling large numbers
|
|
6
|
+
* like token amounts, gas prices, and transaction values.
|
|
7
|
+
*
|
|
8
|
+
* @param value - The value to convert to JSON string
|
|
9
|
+
* @param space - Optional. A String or Number object used to insert white space into the output JSON string for readability purposes
|
|
10
|
+
* @returns JSON string representation of the value with BigInt values converted to strings
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Basic usage with primitive values
|
|
15
|
+
* stringify({ name: 'Alice', age: 25 });
|
|
16
|
+
* // Returns: '{"name":"Alice","age":25}'
|
|
17
|
+
*
|
|
18
|
+
* // Handling BigInt values (common in blockchain)
|
|
19
|
+
* const tokenAmount = BigInt('1000000000000000000'); // 1 ETH in wei
|
|
20
|
+
* stringify({ amount: tokenAmount, symbol: 'ETH' });
|
|
21
|
+
* // Returns: '{"amount":"1000000000000000000","symbol":"ETH"}'
|
|
22
|
+
*
|
|
23
|
+
* // Pretty printing with indentation
|
|
24
|
+
* const transactionData = {
|
|
25
|
+
* hash: '0x1234567890abcdef',
|
|
26
|
+
* value: BigInt('500000000000000000'), // 0.5 ETH
|
|
27
|
+
* gasPrice: BigInt('20000000000'), // 20 Gwei
|
|
28
|
+
* gasLimit: BigInt('21000')
|
|
29
|
+
* };
|
|
30
|
+
*
|
|
31
|
+
* stringify(transactionData, 2);
|
|
32
|
+
* // Returns:
|
|
33
|
+
* // {
|
|
34
|
+
* // "hash": "0x1234567890abcdef",
|
|
35
|
+
* // "value": "500000000000000000",
|
|
36
|
+
* // "gasPrice": "20000000000",
|
|
37
|
+
* // "gasLimit": "21000"
|
|
38
|
+
* // }
|
|
39
|
+
*
|
|
40
|
+
* // EVM transaction parameters
|
|
41
|
+
* const evmTx = {
|
|
42
|
+
* to: '0x742d35cc6798c532c9c75e2c7ad3e6b9b11b38c1',
|
|
43
|
+
* value: BigInt('1000000000000000000'), // 1 ETH
|
|
44
|
+
* gasLimit: BigInt('21000'),
|
|
45
|
+
* gasPrice: BigInt('30000000000'), // 30 Gwei
|
|
46
|
+
* nonce: 42,
|
|
47
|
+
* data: '0x'
|
|
48
|
+
* };
|
|
49
|
+
*
|
|
50
|
+
* const txJson = stringify(evmTx);
|
|
51
|
+
* console.log('Transaction JSON:', txJson);
|
|
52
|
+
* // Outputs: {"to":"0x742d35cc6798c532c9c75e2c7ad3e6b9b11b38c1","value":"1000000000000000000","gasLimit":"21000","gasPrice":"30000000000","nonce":42,"data":"0x"}
|
|
53
|
+
*
|
|
54
|
+
* // Token balance information
|
|
55
|
+
* const tokenBalance = {
|
|
56
|
+
* address: '0xa0b86a33e6885b3ae5372f1c6c8e0e2e3e3b8c4d',
|
|
57
|
+
* symbol: 'USDC',
|
|
58
|
+
* decimals: 6,
|
|
59
|
+
* balance: BigInt('1500000000'), // 1,500 USDC (6 decimals)
|
|
60
|
+
* valueInWei: BigInt('1500000000000000000000') // equivalent ETH value
|
|
61
|
+
* };
|
|
62
|
+
*
|
|
63
|
+
* stringify(tokenBalance, ' '); // Using string indentation
|
|
64
|
+
* // Returns formatted JSON with BigInt values as strings
|
|
65
|
+
*
|
|
66
|
+
* // Array of transactions with BigInt values
|
|
67
|
+
* const transactions = [
|
|
68
|
+
* {
|
|
69
|
+
* hash: '0xabc123',
|
|
70
|
+
* value: BigInt('100000000000000000'), // 0.1 ETH
|
|
71
|
+
* timestamp: 1697184000
|
|
72
|
+
* },
|
|
73
|
+
* {
|
|
74
|
+
* hash: '0xdef456',
|
|
75
|
+
* value: BigInt('250000000000000000'), // 0.25 ETH
|
|
76
|
+
* timestamp: 1697184060
|
|
77
|
+
* }
|
|
78
|
+
* ];
|
|
79
|
+
*
|
|
80
|
+
* stringify(transactions);
|
|
81
|
+
* // Returns: [{"hash":"0xabc123","value":"100000000000000000","timestamp":1697184000},{"hash":"0xdef456","value":"250000000000000000","timestamp":1697184060}]
|
|
82
|
+
*
|
|
83
|
+
* // Solana transaction data
|
|
84
|
+
* const solanaData = {
|
|
85
|
+
* signature: '5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW',
|
|
86
|
+
* slot: BigInt('123456789'),
|
|
87
|
+
* lamports: BigInt('1000000000'), // 1 SOL in lamports
|
|
88
|
+
* fee: BigInt('5000') // transaction fee
|
|
89
|
+
* };
|
|
90
|
+
*
|
|
91
|
+
* stringify(solanaData, 4);
|
|
92
|
+
* // Returns formatted JSON with BigInt slot and lamport values as strings
|
|
93
|
+
*
|
|
94
|
+
* // TON transaction information
|
|
95
|
+
* const tonTx = {
|
|
96
|
+
* hash: 'abc123def456',
|
|
97
|
+
* lt: BigInt('25123456000001'), // logical time
|
|
98
|
+
* value: BigInt('1000000000'), // 1 TON in nanotons
|
|
99
|
+
* fees: {
|
|
100
|
+
* inFwdFee: BigInt('1000000'),
|
|
101
|
+
* storageFee: BigInt('500000'),
|
|
102
|
+
* gasFee: BigInt('2000000')
|
|
103
|
+
* }
|
|
104
|
+
* };
|
|
105
|
+
*
|
|
106
|
+
* stringify(tonTx);
|
|
107
|
+
* // All BigInt values converted to strings for JSON compatibility
|
|
108
|
+
*
|
|
109
|
+
* // DeFi protocol data with large numbers
|
|
110
|
+
* const defiData = {
|
|
111
|
+
* protocol: 'Uniswap V3',
|
|
112
|
+
* poolAddress: '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8',
|
|
113
|
+
* liquidity: BigInt('12345678901234567890123'),
|
|
114
|
+
* sqrtPriceX96: BigInt('1234567890123456789012345'),
|
|
115
|
+
* tick: -276324,
|
|
116
|
+
* feeGrowthGlobal0X128: BigInt('98765432109876543210'),
|
|
117
|
+
* feeGrowthGlobal1X128: BigInt('13579246801357924680')
|
|
118
|
+
* };
|
|
119
|
+
*
|
|
120
|
+
* const defiJson = stringify(defiData, 2);
|
|
121
|
+
* console.log('DeFi Pool Data:', defiJson);
|
|
122
|
+
*
|
|
123
|
+
* // NFT metadata with BigInt token IDs
|
|
124
|
+
* const nftData = {
|
|
125
|
+
* contractAddress: '0x60e4d786628fea6478f785a6d7e704777c86a7c6',
|
|
126
|
+
* tokenId: BigInt('1234567890123456789'),
|
|
127
|
+
* owner: '0x123456789abcdef123456789abcdef123456789a',
|
|
128
|
+
* metadata: {
|
|
129
|
+
* name: 'Cool NFT #1234567890123456789',
|
|
130
|
+
* description: 'A unique digital asset',
|
|
131
|
+
* image: 'ipfs://QmHash123456789'
|
|
132
|
+
* },
|
|
133
|
+
* lastSalePrice: BigInt('5000000000000000000') // 5 ETH
|
|
134
|
+
* };
|
|
135
|
+
*
|
|
136
|
+
* stringify(nftData);
|
|
137
|
+
* // BigInt tokenId and lastSalePrice converted to strings
|
|
138
|
+
*
|
|
139
|
+
* // Multi-chain portfolio data
|
|
140
|
+
* const portfolio = {
|
|
141
|
+
* ethereum: {
|
|
142
|
+
* nativeBalance: BigInt('2500000000000000000'), // 2.5 ETH
|
|
143
|
+
* tokens: [
|
|
144
|
+
* {
|
|
145
|
+
* symbol: 'USDC',
|
|
146
|
+
* balance: BigInt('1000000000'), // 1,000 USDC (6 decimals)
|
|
147
|
+
* address: '0xa0b86a33e6885b3ae5372f1c6c8e0e2e3e3b8c4d'
|
|
148
|
+
* }
|
|
149
|
+
* ]
|
|
150
|
+
* },
|
|
151
|
+
* polygon: {
|
|
152
|
+
* nativeBalance: BigInt('100000000000000000000'), // 100 MATIC
|
|
153
|
+
* tokens: []
|
|
154
|
+
* },
|
|
155
|
+
* solana: {
|
|
156
|
+
* nativeBalance: BigInt('5000000000'), // 5 SOL
|
|
157
|
+
* tokens: []
|
|
158
|
+
* }
|
|
159
|
+
* };
|
|
160
|
+
*
|
|
161
|
+
* const portfolioJson = stringify(portfolio, 2);
|
|
162
|
+
* // All BigInt balances converted to strings for cross-chain compatibility
|
|
163
|
+
*
|
|
164
|
+
* // Error handling with BigInt
|
|
165
|
+
* try {
|
|
166
|
+
* const problematicData = {
|
|
167
|
+
* regularNumber: 123,
|
|
168
|
+
* bigIntValue: BigInt('999999999999999999999'),
|
|
169
|
+
* circularRef: null as any
|
|
170
|
+
* };
|
|
171
|
+
* problematicData.circularRef = problematicData; // Creates circular reference
|
|
172
|
+
*
|
|
173
|
+
* // This will throw due to circular reference, not BigInt
|
|
174
|
+
* stringify(problematicData);
|
|
175
|
+
* } catch (error) {
|
|
176
|
+
* console.error('Stringify error:', error.message);
|
|
177
|
+
* }
|
|
178
|
+
*
|
|
179
|
+
* // Comparison with standard JSON.stringify (would fail with BigInt)
|
|
180
|
+
* const bigIntData = { amount: BigInt('123456789012345678901234567890') };
|
|
181
|
+
*
|
|
182
|
+
* // ❌ This would throw: JSON.stringify(bigIntData)
|
|
183
|
+
* // TypeError: Do not know how to serialize a BigInt
|
|
184
|
+
*
|
|
185
|
+
* // ✅ This works: stringify(bigIntData)
|
|
186
|
+
* stringify(bigIntData);
|
|
187
|
+
* // Returns: '{"amount":"123456789012345678901234567890"}'
|
|
188
|
+
*
|
|
189
|
+
* // Logging blockchain events with BigInt block numbers
|
|
190
|
+
* const blockchainEvents = [
|
|
191
|
+
* {
|
|
192
|
+
* event: 'Transfer',
|
|
193
|
+
* blockNumber: BigInt('18500000'),
|
|
194
|
+
* transactionIndex: 25,
|
|
195
|
+
* logIndex: 3,
|
|
196
|
+
* args: {
|
|
197
|
+
* from: '0x123...',
|
|
198
|
+
* to: '0x456...',
|
|
199
|
+
* value: BigInt('1000000000000000000')
|
|
200
|
+
* }
|
|
201
|
+
* }
|
|
202
|
+
* ];
|
|
203
|
+
*
|
|
204
|
+
* const eventsLog = stringify(blockchainEvents, 2);
|
|
205
|
+
* console.log('Blockchain Events:', eventsLog);
|
|
206
|
+
*
|
|
207
|
+
* // Configuration objects with BigInt limits
|
|
208
|
+
* const sdkConfig = {
|
|
209
|
+
* maxGasPrice: BigInt('100000000000'), // 100 Gwei
|
|
210
|
+
* minBalance: BigInt('100000000000000000'), // 0.1 ETH
|
|
211
|
+
* retryDelayMs: 1000,
|
|
212
|
+
* maxRetries: 3,
|
|
213
|
+
* networkTimeouts: {
|
|
214
|
+
* ethereum: BigInt('15000'), // 15 seconds in ms
|
|
215
|
+
* polygon: BigInt('5000'), // 5 seconds in ms
|
|
216
|
+
* solana: BigInt('10000') // 10 seconds in ms
|
|
217
|
+
* }
|
|
218
|
+
* };
|
|
219
|
+
*
|
|
220
|
+
* const configJson = stringify(sdkConfig);
|
|
221
|
+
* // Safely serialize configuration with BigInt values
|
|
222
|
+
*
|
|
223
|
+
* // Utility for pretty-printing blockchain data
|
|
224
|
+
* function logBlockchainData(data: any, label: string = 'Data') {
|
|
225
|
+
* console.log(`${label}:`, stringify(data, 2));
|
|
226
|
+
* }
|
|
227
|
+
*
|
|
228
|
+
* // Usage in debugging
|
|
229
|
+
* logBlockchainData({
|
|
230
|
+
* txHash: '0xabc123',
|
|
231
|
+
* blockNumber: BigInt('18500001'),
|
|
232
|
+
* gasUsed: BigInt('21000')
|
|
233
|
+
* }, 'Transaction Receipt');
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
1
236
|
export declare function stringify(value: any, space?: string | number): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heyanon/sdk",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@ton-api/client": "0.3.1",
|
|
47
47
|
"@ton-api/ton-adapter": "0.3.0",
|
|
48
48
|
"@ton/core": "0.60.0",
|
|
49
|
+
"@ton/crypto": "^3.3.0",
|
|
49
50
|
"@ton/ton": "15.2.0",
|
|
50
51
|
"ccxt": "4.4.78",
|
|
51
52
|
"openai": "5.12.1",
|