@heyanon/sdk 2.3.1 → 2.3.3

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.
Files changed (30) hide show
  1. package/dist/adapter/misc.d.ts +35 -0
  2. package/dist/adapter/transformers/toResult.d.ts +24 -0
  3. package/dist/adapter/types.d.ts +123 -7
  4. package/dist/blockchain/constants/chains.d.ts +96 -2
  5. package/dist/blockchain/constants/types.d.ts +33 -0
  6. package/dist/blockchain/evm/constants/chains.d.ts +57 -0
  7. package/dist/blockchain/evm/constants/misc.d.ts +69 -0
  8. package/dist/blockchain/evm/constants/weth9.d.ts +77 -1
  9. package/dist/blockchain/evm/types.d.ts +273 -0
  10. package/dist/blockchain/evm/utils/checkToApprove.d.ts +86 -0
  11. package/dist/blockchain/evm/utils/getChainFromName.d.ts +81 -0
  12. package/dist/blockchain/evm/utils/getChainName.d.ts +114 -0
  13. package/dist/blockchain/evm/utils/getUnwrapData.d.ts +114 -0
  14. package/dist/blockchain/evm/utils/getWrapAddress.d.ts +147 -0
  15. package/dist/blockchain/evm/utils/getWrapData.d.ts +189 -0
  16. package/dist/blockchain/evm/utils/getWrappedNative.d.ts +198 -0
  17. package/dist/blockchain/evm/utils/isEvmChain.d.ts +183 -0
  18. package/dist/blockchain/evm/utils/isNativeAddress.d.ts +221 -0
  19. package/dist/blockchain/evm/utils/isNativeAddress.test.d.ts +1 -0
  20. package/dist/blockchain/solana/types.d.ts +291 -0
  21. package/dist/blockchain/solana/utils/buildV0Transaction.d.ts +184 -0
  22. package/dist/blockchain/solana/utils/toPublicKey.d.ts +194 -0
  23. package/dist/blockchain/ton/types.d.ts +410 -0
  24. package/dist/index.js +37 -2
  25. package/dist/index.mjs +37 -2
  26. package/dist/utils/retry.d.ts +218 -0
  27. package/dist/utils/sleep.d.ts +239 -0
  28. package/dist/utils/stringify.d.ts +235 -0
  29. package/dist/utils/stringify.spec.d.ts +1 -0
  30. package/package.json +1 -1
@@ -1,6 +1,224 @@
1
+ /**
2
+ * Options for configuring retry behavior
3
+ * @interface Options
4
+ */
1
5
  interface Options {
6
+ /** Number of retry attempts (default: 0) */
2
7
  readonly retries?: number;
8
+ /** Delay between retry attempts in milliseconds (optional) */
3
9
  readonly delayMs?: number;
4
10
  }
11
+ /**
12
+ * Executes an async function with automatic retry logic on failure
13
+ * @template T - The return type of the function
14
+ * @param fn - The async function to execute with retry logic
15
+ * @param options - Configuration options for retry behavior
16
+ * @returns Promise that resolves with the function result or rejects after all retries are exhausted
17
+ * @example
18
+ * ```typescript
19
+ * // Basic retry without delay
20
+ * const result = await retry(
21
+ * async () => {
22
+ * const response = await fetch('https://api.example.com/data');
23
+ * if (!response.ok) throw new Error('Network error');
24
+ * return response.json();
25
+ * },
26
+ * { retries: 3 }
27
+ * );
28
+ *
29
+ * // Retry with delay between attempts
30
+ * const dataWithDelay = await retry(
31
+ * async () => {
32
+ * const connection = await database.connect();
33
+ * return await connection.query('SELECT * FROM users');
34
+ * },
35
+ * { retries: 5, delayMs: 1000 } // Wait 1 second between retries
36
+ * );
37
+ *
38
+ * // Blockchain transaction with exponential backoff simulation
39
+ * async function sendTransactionWithRetry(transaction: TransactionParams) {
40
+ * let attempt = 0;
41
+ *
42
+ * return await retry(
43
+ * async () => {
44
+ * attempt++;
45
+ * console.log(`Attempt ${attempt}: Sending transaction...`);
46
+ *
47
+ * const result = await options.evm.sendTransactions({
48
+ * transactions: [transaction]
49
+ * });
50
+ *
51
+ * if (!result.data[0].message.includes('confirmed')) {
52
+ * throw new Error('Transaction not confirmed');
53
+ * }
54
+ *
55
+ * return result;
56
+ * },
57
+ * { retries: 3, delayMs: 2000 }
58
+ * );
59
+ * }
60
+ *
61
+ * // API call with retry for rate limiting
62
+ * async function fetchTokenPrice(tokenAddress: string) {
63
+ * return await retry(
64
+ * async () => {
65
+ * const response = await fetch(`https://api.coingecko.com/api/v3/tokens/${tokenAddress}`);
66
+ *
67
+ * if (response.status === 429) {
68
+ * throw new Error('Rate limited');
69
+ * }
70
+ *
71
+ * if (!response.ok) {
72
+ * throw new Error(`HTTP ${response.status}: ${response.statusText}`);
73
+ * }
74
+ *
75
+ * return await response.json();
76
+ * },
77
+ * { retries: 5, delayMs: 3000 } // 3 second delay for rate limits
78
+ * );
79
+ * }
80
+ *
81
+ * // RPC provider failover
82
+ * async function getBlockNumberWithFailover(providers: PublicClient[]) {
83
+ * let providerIndex = 0;
84
+ *
85
+ * return await retry(
86
+ * async () => {
87
+ * if (providerIndex >= providers.length) {
88
+ * throw new Error('All providers failed');
89
+ * }
90
+ *
91
+ * const provider = providers[providerIndex];
92
+ *
93
+ * try {
94
+ * return await provider.getBlockNumber();
95
+ * } catch (error) {
96
+ * providerIndex++;
97
+ * throw error;
98
+ * }
99
+ * },
100
+ * { retries: providers.length - 1, delayMs: 500 }
101
+ * );
102
+ * }
103
+ *
104
+ * // Solana transaction confirmation
105
+ * async function confirmSolanaTransaction(signature: string, connection: Connection) {
106
+ * return await retry(
107
+ * async () => {
108
+ * const status = await connection.getSignatureStatus(signature);
109
+ *
110
+ * if (!status.value) {
111
+ * throw new Error('Transaction not found');
112
+ * }
113
+ *
114
+ * if (status.value.err) {
115
+ * throw new Error(`Transaction failed: ${JSON.stringify(status.value.err)}`);
116
+ * }
117
+ *
118
+ * if (!status.value.confirmationStatus) {
119
+ * throw new Error('Transaction not confirmed yet');
120
+ * }
121
+ *
122
+ * return status.value;
123
+ * },
124
+ * { retries: 30, delayMs: 1000 } // Check every second for 30 seconds
125
+ * );
126
+ * }
127
+ *
128
+ * // TON client operations with retry
129
+ * async function getTonAccountWithRetry(address: Address, client: Client) {
130
+ * return await retry(
131
+ * async () => {
132
+ * try {
133
+ * return await client.api.accounts.getAccount(address.toString());
134
+ * } catch (error) {
135
+ * if (error.message.includes('429')) {
136
+ * throw new Error('Rate limited - will retry');
137
+ * }
138
+ * if (error.message.includes('timeout')) {
139
+ * throw new Error('Timeout - will retry');
140
+ * }
141
+ * // Don't retry for other errors
142
+ * throw error;
143
+ * }
144
+ * },
145
+ * { retries: 3, delayMs: 2000 }
146
+ * );
147
+ * }
148
+ *
149
+ * // File operations with retry
150
+ * async function readFileWithRetry(filePath: string) {
151
+ * return await retry(
152
+ * async () => {
153
+ * const fs = await import('fs/promises');
154
+ * return await fs.readFile(filePath, 'utf-8');
155
+ * },
156
+ * { retries: 3, delayMs: 100 }
157
+ * );
158
+ * }
159
+ *
160
+ * // Complex retry with custom logic
161
+ * async function smartContractCallWithRetry(
162
+ * contractAddress: Address,
163
+ * methodName: string,
164
+ * args: any[],
165
+ * provider: PublicClient
166
+ * ) {
167
+ * let gasPrice = await provider.getGasPrice();
168
+ *
169
+ * return await retry(
170
+ * async () => {
171
+ * try {
172
+ * return await provider.readContract({
173
+ * address: contractAddress,
174
+ * abi: contractAbi,
175
+ * functionName: methodName,
176
+ * args
177
+ * });
178
+ * } catch (error) {
179
+ * if (error.message.includes('gas')) {
180
+ * // Increase gas price for next attempt
181
+ * gasPrice = gasPrice * 110n / 100n; // +10%
182
+ * console.log(`Increasing gas price to ${gasPrice}`);
183
+ * }
184
+ * throw error;
185
+ * }
186
+ * },
187
+ * { retries: 3, delayMs: 1000 }
188
+ * );
189
+ * }
190
+ *
191
+ * // Error handling patterns
192
+ * async function handleOperationWithRetry<T>(
193
+ * operation: () => Promise<T>,
194
+ * operationName: string
195
+ * ): Promise<T> {
196
+ * try {
197
+ * return await retry(operation, { retries: 3, delayMs: 1000 });
198
+ * } catch (error) {
199
+ * console.error(`${operationName} failed after all retries:`, error);
200
+ *
201
+ * // Log for monitoring
202
+ * if (typeof error === 'object' && error !== null) {
203
+ * console.error('Final error details:', {
204
+ * message: error.message,
205
+ * stack: error.stack,
206
+ * operation: operationName
207
+ * });
208
+ * }
209
+ *
210
+ * throw new Error(`${operationName} failed: ${error.message}`);
211
+ * }
212
+ * }
213
+ *
214
+ * // Usage in adapter functions
215
+ * async function executeWithRetry<T>(
216
+ * operation: () => Promise<T>,
217
+ * retryConfig: Options = { retries: 3, delayMs: 1000 }
218
+ * ): Promise<T> {
219
+ * return await retry(operation, retryConfig);
220
+ * }
221
+ * ```
222
+ */
5
223
  export declare function retry<T>(fn: () => Promise<T>, options?: Options): Promise<T>;
6
224
  export {};
@@ -1 +1,240 @@
1
+ /**
2
+ * Creates a promise that resolves after the specified number of milliseconds
3
+ * @param ms - Number of milliseconds to sleep/wait
4
+ * @returns Promise that resolves after the specified delay
5
+ * @example
6
+ * ```typescript
7
+ * // Basic usage - wait for 1 second
8
+ * await sleep(1000);
9
+ * console.log('Executed after 1 second');
10
+ *
11
+ * // Wait between operations
12
+ * console.log('Starting operation...');
13
+ * await sleep(2000);
14
+ * console.log('Continuing after 2 seconds...');
15
+ *
16
+ * // Use in blockchain operations for rate limiting
17
+ * async function batchProcessTransactions(transactions: TransactionParams[]) {
18
+ * const results = [];
19
+ *
20
+ * for (const tx of transactions) {
21
+ * const result = await options.evm.sendTransactions({
22
+ * transactions: [tx]
23
+ * });
24
+ * results.push(result);
25
+ *
26
+ * // Wait 3 seconds between transactions to avoid rate limits
27
+ * await sleep(3000);
28
+ * }
29
+ *
30
+ * return results;
31
+ * }
32
+ *
33
+ * // Polling with delays
34
+ * async function pollTransactionStatus(hash: string, maxAttempts: number = 30) {
35
+ * for (let attempt = 1; attempt <= maxAttempts; attempt++) {
36
+ * const receipt = await provider.getTransactionReceipt(hash);
37
+ *
38
+ * if (receipt) {
39
+ * return receipt;
40
+ * }
41
+ *
42
+ * console.log(`Attempt ${attempt}: Transaction not confirmed yet, waiting...`);
43
+ * await sleep(2000); // Wait 2 seconds before next check
44
+ * }
45
+ *
46
+ * throw new Error('Transaction confirmation timeout');
47
+ * }
48
+ *
49
+ * // Gradual data loading with delays
50
+ * async function loadUserPortfolio(userAddress: string, chains: EvmChain[]) {
51
+ * const portfolio = [];
52
+ *
53
+ * for (const chain of chains) {
54
+ * console.log(`Loading ${chain} data...`);
55
+ *
56
+ * const chainData = await getUserBalances(userAddress, chain);
57
+ * portfolio.push({ chain, data: chainData });
58
+ *
59
+ * // Small delay to prevent overwhelming APIs
60
+ * await sleep(500);
61
+ * }
62
+ *
63
+ * return portfolio;
64
+ * }
65
+ *
66
+ * // Retry with increasing delays (exponential backoff)
67
+ * async function exponentialBackoffOperation<T>(
68
+ * operation: () => Promise<T>,
69
+ * maxRetries: number = 5
70
+ * ): Promise<T> {
71
+ * let lastError: Error;
72
+ *
73
+ * for (let attempt = 1; attempt <= maxRetries; attempt++) {
74
+ * try {
75
+ * return await operation();
76
+ * } catch (error) {
77
+ * lastError = error as Error;
78
+ *
79
+ * if (attempt === maxRetries) {
80
+ * throw lastError;
81
+ * }
82
+ *
83
+ * const delayMs = Math.pow(2, attempt) * 1000; // 2s, 4s, 8s, 16s, 32s
84
+ * console.log(`Attempt ${attempt} failed, retrying in ${delayMs}ms...`);
85
+ * await sleep(delayMs);
86
+ * }
87
+ * }
88
+ *
89
+ * throw lastError!;
90
+ * }
91
+ *
92
+ * // Animation delays in UI
93
+ * async function animatedTokenTransfer(fromAddress: string, toAddress: string, amount: bigint) {
94
+ * console.log('🚀 Initiating transfer...');
95
+ * await sleep(500);
96
+ *
97
+ * console.log('⏳ Preparing transaction...');
98
+ * const tx = await buildTransferTransaction(fromAddress, toAddress, amount);
99
+ * await sleep(800);
100
+ *
101
+ * console.log('📝 Signing transaction...');
102
+ * await sleep(1000);
103
+ *
104
+ * console.log('📡 Broadcasting to network...');
105
+ * const result = await options.evm.sendTransactions({ transactions: [tx] });
106
+ * await sleep(500);
107
+ *
108
+ * console.log('✅ Transfer complete!');
109
+ * return result;
110
+ * }
111
+ *
112
+ * // Throttled API calls
113
+ * async function throttledApiCalls<T>(
114
+ * apiCalls: (() => Promise<T>)[],
115
+ * delayBetweenCalls: number = 1000
116
+ * ): Promise<T[]> {
117
+ * const results: T[] = [];
118
+ *
119
+ * for (let i = 0; i < apiCalls.length; i++) {
120
+ * const result = await apiCalls[i]();
121
+ * results.push(result);
122
+ *
123
+ * // Don't wait after the last call
124
+ * if (i < apiCalls.length - 1) {
125
+ * await sleep(delayBetweenCalls);
126
+ * }
127
+ * }
128
+ *
129
+ * return results;
130
+ * }
131
+ *
132
+ * // Blockchain confirmation waiting
133
+ * async function waitForConfirmations(
134
+ * transactionHash: string,
135
+ * requiredConfirmations: number = 6,
136
+ * checkInterval: number = 15000 // 15 seconds
137
+ * ) {
138
+ * let confirmations = 0;
139
+ *
140
+ * while (confirmations < requiredConfirmations) {
141
+ * const receipt = await provider.getTransactionReceipt(transactionHash);
142
+ *
143
+ * if (!receipt) {
144
+ * console.log('Transaction not found, waiting...');
145
+ * await sleep(checkInterval);
146
+ * continue;
147
+ * }
148
+ *
149
+ * const currentBlock = await provider.getBlockNumber();
150
+ * confirmations = currentBlock - receipt.blockNumber + 1;
151
+ *
152
+ * console.log(`Confirmations: ${confirmations}/${requiredConfirmations}`);
153
+ *
154
+ * if (confirmations < requiredConfirmations) {
155
+ * await sleep(checkInterval);
156
+ * }
157
+ * }
158
+ *
159
+ * console.log('✅ Transaction fully confirmed!');
160
+ * }
161
+ *
162
+ * // Solana transaction confirmation with sleep
163
+ * async function confirmSolanaTransactionWithSleep(
164
+ * signature: string,
165
+ * connection: Connection,
166
+ * timeout: number = 60000
167
+ * ) {
168
+ * const startTime = Date.now();
169
+ *
170
+ * while (Date.now() - startTime < timeout) {
171
+ * const status = await connection.getSignatureStatus(signature);
172
+ *
173
+ * if (status.value?.confirmationStatus === 'confirmed' ||
174
+ * status.value?.confirmationStatus === 'finalized') {
175
+ * return status.value;
176
+ * }
177
+ *
178
+ * await sleep(1000); // Check every second
179
+ * }
180
+ *
181
+ * throw new Error('Transaction confirmation timeout');
182
+ * }
183
+ *
184
+ * // TON transaction monitoring
185
+ * async function monitorTonTransaction(hash: string, client: Client) {
186
+ * const maxAttempts = 30;
187
+ *
188
+ * for (let attempt = 1; attempt <= maxAttempts; attempt++) {
189
+ * try {
190
+ * const tx = await client.api.blockchain.getBlockchainTransaction(hash);
191
+ *
192
+ * if (tx.success) {
193
+ * return tx;
194
+ * } else {
195
+ * throw new Error('Transaction failed');
196
+ * }
197
+ * } catch (error) {
198
+ * if (attempt === maxAttempts) {
199
+ * throw error;
200
+ * }
201
+ *
202
+ * console.log(`Attempt ${attempt}: Transaction not ready, waiting 2 seconds...`);
203
+ * await sleep(2000);
204
+ * }
205
+ * }
206
+ * }
207
+ *
208
+ * // Progressive loading with sleep
209
+ * async function progressiveDataLoad(addresses: string[], progressCallback?: (progress: number) => void) {
210
+ * const results = [];
211
+ * const total = addresses.length;
212
+ *
213
+ * for (let i = 0; i < addresses.length; i++) {
214
+ * const address = addresses[i];
215
+ * const data = await getAddressData(address);
216
+ * results.push(data);
217
+ *
218
+ * // Update progress
219
+ * const progress = ((i + 1) / total) * 100;
220
+ * progressCallback?.(progress);
221
+ *
222
+ * // Brief pause between loads
223
+ * if (i < addresses.length - 1) {
224
+ * await sleep(200);
225
+ * }
226
+ * }
227
+ *
228
+ * return results;
229
+ * }
230
+ *
231
+ * // Utility functions with sleep
232
+ * const sleepSeconds = (seconds: number) => sleep(seconds * 1000);
233
+ * const sleepMinutes = (minutes: number) => sleep(minutes * 60 * 1000);
234
+ *
235
+ * // Usage examples
236
+ * // await sleepSeconds(5); // Sleep for 5 seconds
237
+ * // await sleepMinutes(1); // Sleep for 1 minute
238
+ * ```
239
+ */
1
240
  export declare const sleep: (ms: number) => Promise<unknown>;
@@ -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.1",
3
+ "version": "2.3.3",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",