@silentswap/react 0.1.50 → 0.1.52
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/contexts/AssetsContext.js +1 -0
- package/dist/contexts/BalancesContext.d.ts +3 -1
- package/dist/contexts/BalancesContext.js +235 -7
- package/dist/contexts/SilentSwapContext.d.ts +6 -1
- package/dist/contexts/SilentSwapContext.js +7 -4
- package/dist/hooks/silent/tron-transaction.d.ts +34 -4
- package/dist/hooks/silent/tron-transaction.js +45 -1
- package/dist/hooks/silent/useAuth.js +14 -0
- package/dist/hooks/silent/useBridgeExecution.d.ts +12 -2
- package/dist/hooks/silent/useBridgeExecution.js +341 -114
- package/dist/hooks/silent/useQuoteCalculation.d.ts +3 -1
- package/dist/hooks/silent/useQuoteCalculation.js +72 -5
- package/dist/hooks/silent/useSilentQuote.d.ts +8 -1
- package/dist/hooks/silent/useSilentQuote.js +77 -7
- package/dist/hooks/useContacts.d.ts +2 -2
- package/dist/hooks/useOrderEstimates.d.ts +3 -1
- package/dist/hooks/useOrderEstimates.js +23 -11
- package/dist/hooks/useQuote.js +53 -15
- package/dist/hooks/useTransaction.d.ts +6 -1
- package/dist/hooks/useTransaction.js +89 -8
- package/dist/hooks/useTransactionAddress.d.ts +3 -2
- package/dist/hooks/useTransactionAddress.js +10 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +3 -3
|
@@ -3,6 +3,7 @@ import type { Connector } from 'wagmi';
|
|
|
3
3
|
import type { BridgeProvider, BridgeQuote, BridgeStatus, OrderResponse } from '@silentswap/sdk';
|
|
4
4
|
import type { SolanaWalletConnector, SolanaConnection } from './silent/solana-transaction.js';
|
|
5
5
|
import type { BitcoinWalletConnector, BitcoinConnection } from './silent/bitcoin-transaction.js';
|
|
6
|
+
import type { TronWalletConnector, TronConnection } from './silent/tron-transaction.js';
|
|
6
7
|
export interface useTransactionOptions {
|
|
7
8
|
/** User's EVM address */
|
|
8
9
|
address: `0x${string}`;
|
|
@@ -20,6 +21,10 @@ export interface useTransactionOptions {
|
|
|
20
21
|
bitcoinConnector?: BitcoinWalletConnector;
|
|
21
22
|
/** Bitcoin connection (optional, for consistency with Solana pattern) */
|
|
22
23
|
bitcoinConnection?: BitcoinConnection;
|
|
24
|
+
/** Tron wallet connector (required for Tron transactions) */
|
|
25
|
+
tronConnector?: TronWalletConnector;
|
|
26
|
+
/** Tron connection (optional, for consistency with other adapters) */
|
|
27
|
+
tronConnection?: TronConnection;
|
|
23
28
|
/** Optional callback to set current step (for external state management) */
|
|
24
29
|
setCurrentStep?: (step: string) => void;
|
|
25
30
|
/** Optional status update callback */
|
|
@@ -121,4 +126,4 @@ export interface useTransactionReturn {
|
|
|
121
126
|
* }
|
|
122
127
|
* ```
|
|
123
128
|
*/
|
|
124
|
-
export declare function useTransaction({ walletClient, connector, solanaConnector, solanaConnection, solanaRpcUrl, bitcoinConnector, bitcoinConnection, setCurrentStep: externalSetCurrentStep, onStatus: externalOnStatus, }: useTransactionOptions): useTransactionReturn;
|
|
129
|
+
export declare function useTransaction({ walletClient, connector, solanaConnector, solanaConnection, solanaRpcUrl, bitcoinConnector, bitcoinConnection, tronConnector, tronConnection, setCurrentStep: externalSetCurrentStep, onStatus: externalOnStatus, }: useTransactionOptions): useTransactionReturn;
|
|
@@ -3,8 +3,9 @@ import { erc20Abi } from 'viem';
|
|
|
3
3
|
import { executeRelayBridge, executeDebridgeBridge, getBridgeStatus, createTransactionExecutor, createChainSwitcher, ensureChain, waitForTransactionConfirmation, parseTransactionRequestForViem, createPublicClientWithRpc, getChainById, } from '@silentswap/sdk';
|
|
4
4
|
import { createSolanaTransactionExecutor } from './silent/solana-transaction.js';
|
|
5
5
|
import { createBitcoinTransactionExecutor, convertRelayBitcoinStepToTransaction } from './silent/bitcoin-transaction.js';
|
|
6
|
+
import { createTronTransactionExecutor, convertRelayTronStepToTransaction, isRelayTronStepData } from './silent/tron-transaction.js';
|
|
7
|
+
import { N_RELAY_CHAIN_ID_BITCOIN, N_RELAY_CHAIN_ID_TRON, N_DEBRIDGE_CHAIN_ID_TRON } from '@silentswap/sdk';
|
|
6
8
|
import { N_DEBRIDGE_CHAIN_ID_SOLANA } from '@silentswap/sdk';
|
|
7
|
-
import { N_RELAY_CHAIN_ID_BITCOIN } from '@silentswap/sdk';
|
|
8
9
|
/**
|
|
9
10
|
* React hook for executing transactions
|
|
10
11
|
*
|
|
@@ -79,7 +80,7 @@ import { N_RELAY_CHAIN_ID_BITCOIN } from '@silentswap/sdk';
|
|
|
79
80
|
* }
|
|
80
81
|
* ```
|
|
81
82
|
*/
|
|
82
|
-
export function useTransaction({ walletClient, connector, solanaConnector, solanaConnection, solanaRpcUrl, bitcoinConnector, bitcoinConnection, setCurrentStep: externalSetCurrentStep, onStatus: externalOnStatus, }) {
|
|
83
|
+
export function useTransaction({ walletClient, connector, solanaConnector, solanaConnection, solanaRpcUrl, bitcoinConnector, bitcoinConnection, tronConnector, tronConnection, setCurrentStep: externalSetCurrentStep, onStatus: externalOnStatus, }) {
|
|
83
84
|
const [isLoading, setIsLoading] = useState(false);
|
|
84
85
|
const [internalCurrentStep, setInternalCurrentStep] = useState('');
|
|
85
86
|
const [error, setError] = useState(null);
|
|
@@ -106,6 +107,8 @@ export function useTransaction({ walletClient, connector, solanaConnector, solan
|
|
|
106
107
|
return false;
|
|
107
108
|
});
|
|
108
109
|
const hasBitcoinTransactions = hasBitcoinInTxs || hasBitcoinInRoute;
|
|
110
|
+
// Check if quote contains Tron transactions (relay or deBridge)
|
|
111
|
+
const hasTronTransactions = quote.txs.some((tx) => tx.chainId === N_RELAY_CHAIN_ID_TRON || tx.chainId === N_DEBRIDGE_CHAIN_ID_TRON);
|
|
109
112
|
// Check if quote contains Solana transactions (relay instructions or deBridge serialized tx)
|
|
110
113
|
const hasSolanaTransactions = quote.txs.some((tx) => tx.instructions !== undefined || tx.chainId === N_DEBRIDGE_CHAIN_ID_SOLANA);
|
|
111
114
|
if (hasBitcoinTransactions) {
|
|
@@ -166,7 +169,7 @@ export function useTransaction({ walletClient, connector, solanaConnector, solan
|
|
|
166
169
|
else {
|
|
167
170
|
// Use standard execution path if txs array has Bitcoin transactions
|
|
168
171
|
const executeTx = createTransactionExecutor(walletClient, connector, undefined, // solanaExecutor
|
|
169
|
-
bitcoinExecutor);
|
|
172
|
+
bitcoinExecutor, undefined);
|
|
170
173
|
// Create a no-op chain switcher for Bitcoin (chain switching is handled by connector)
|
|
171
174
|
const switchChain = async (_chainId) => {
|
|
172
175
|
// Bitcoin doesn't require chain switching
|
|
@@ -194,6 +197,84 @@ export function useTransaction({ walletClient, connector, solanaConnector, solan
|
|
|
194
197
|
setCurrentStep('');
|
|
195
198
|
}
|
|
196
199
|
}
|
|
200
|
+
else if (hasTronTransactions) {
|
|
201
|
+
if (!tronConnector) {
|
|
202
|
+
throw new Error('Tron connector is required for Tron bridge transactions. ' +
|
|
203
|
+
'Please provide tronConnector option.');
|
|
204
|
+
}
|
|
205
|
+
const tronExecutor = createTronTransactionExecutor(tronConnector, tronConnection);
|
|
206
|
+
setIsLoading(true);
|
|
207
|
+
setError(null);
|
|
208
|
+
try {
|
|
209
|
+
switch (quote.provider) {
|
|
210
|
+
case 'relay': {
|
|
211
|
+
const steps = quote.route?.steps || [];
|
|
212
|
+
const txHashes = [];
|
|
213
|
+
for (const step of steps) {
|
|
214
|
+
if (step.kind === 'transaction' && step.items) {
|
|
215
|
+
for (const item of step.items) {
|
|
216
|
+
const itemData = item.data || {};
|
|
217
|
+
// Relay returns Tron steps as nested TriggerSmartContract
|
|
218
|
+
// payloads (no top-level chainId), so discriminate by shape.
|
|
219
|
+
if (!isRelayTronStepData(itemData)) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
const label = step.id === 'approve'
|
|
223
|
+
? 'Requesting approval...'
|
|
224
|
+
: step.id === 'deposit'
|
|
225
|
+
? 'Requesting deposit...'
|
|
226
|
+
: 'Requesting bridge...';
|
|
227
|
+
setCurrentStep(label);
|
|
228
|
+
onStatus?.(label);
|
|
229
|
+
const tronTx = convertRelayTronStepToTransaction(itemData, N_RELAY_CHAIN_ID_TRON);
|
|
230
|
+
const hash = await tronExecutor(tronTx);
|
|
231
|
+
if (hash)
|
|
232
|
+
txHashes.push(hash);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const requestId = steps.find((s) => s.requestId)?.requestId;
|
|
237
|
+
if (!requestId) {
|
|
238
|
+
throw new Error('Missing relay.link request ID');
|
|
239
|
+
}
|
|
240
|
+
if (txHashes.length === 0) {
|
|
241
|
+
throw new Error('No Tron transactions were executed for relay quote. ' +
|
|
242
|
+
'The quote may not contain any Tron steps.');
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
status: 'pending',
|
|
246
|
+
txHashes: txHashes,
|
|
247
|
+
requestId,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
case 'debridge': {
|
|
251
|
+
// For deBridge Tron transactions, route through the universal executor.
|
|
252
|
+
// The TronLink connector handles chain context — walletClient/connector
|
|
253
|
+
// are not required for the Tron path.
|
|
254
|
+
const executeTx = createTransactionExecutor(walletClient, connector, undefined, undefined, tronExecutor);
|
|
255
|
+
const switchChain = async (_chainId) => {
|
|
256
|
+
// Tron doesn't require EVM chain switching
|
|
257
|
+
};
|
|
258
|
+
return await executeDebridgeBridge(quote, executeTx, switchChain, (step) => {
|
|
259
|
+
setCurrentStep(step);
|
|
260
|
+
onStatus?.(step);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
default:
|
|
264
|
+
throw new Error(`Unsupported bridge provider: ${quote.provider}`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
catch (err) {
|
|
268
|
+
const error = err instanceof Error ? err : new Error('Bridge execution failed');
|
|
269
|
+
console.error('Bridge execution failed:', error);
|
|
270
|
+
setError(error);
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
finally {
|
|
274
|
+
setIsLoading(false);
|
|
275
|
+
setCurrentStep('');
|
|
276
|
+
}
|
|
277
|
+
}
|
|
197
278
|
else if (hasSolanaTransactions) {
|
|
198
279
|
// Solana transactions require Solana connector and connection
|
|
199
280
|
if (!solanaConnector || !solanaConnection) {
|
|
@@ -204,7 +285,7 @@ export function useTransaction({ walletClient, connector, solanaConnector, solan
|
|
|
204
285
|
const solanaExecutor = createSolanaTransactionExecutor(solanaConnector, solanaConnection);
|
|
205
286
|
// For Solana, we still need EVM wallet client for chain switching (if needed)
|
|
206
287
|
// But the actual transaction execution will use Solana executor
|
|
207
|
-
const executeTx = createTransactionExecutor(walletClient, connector, solanaExecutor);
|
|
288
|
+
const executeTx = createTransactionExecutor(walletClient, connector, solanaExecutor, undefined, undefined);
|
|
208
289
|
// Create a no-op chain switcher for Solana (chain switching is handled by connector)
|
|
209
290
|
const switchChain = async (_chainId) => {
|
|
210
291
|
// Solana doesn't require chain switching
|
|
@@ -251,7 +332,7 @@ export function useTransaction({ walletClient, connector, solanaConnector, solan
|
|
|
251
332
|
setError(null);
|
|
252
333
|
try {
|
|
253
334
|
// Create wrapper functions using shared utilities
|
|
254
|
-
const executeTx = createTransactionExecutor(walletClient, connector);
|
|
335
|
+
const executeTx = createTransactionExecutor(walletClient, connector, undefined, undefined, undefined);
|
|
255
336
|
const switchChain = createChainSwitcher(walletClient, connector);
|
|
256
337
|
// Execute based on provider
|
|
257
338
|
switch (quote.provider) {
|
|
@@ -280,7 +361,7 @@ export function useTransaction({ walletClient, connector, solanaConnector, solan
|
|
|
280
361
|
setCurrentStep('');
|
|
281
362
|
}
|
|
282
363
|
}
|
|
283
|
-
}, [walletClient, connector, solanaConnector, solanaConnection, solanaRpcUrl]);
|
|
364
|
+
}, [walletClient, connector, solanaConnector, solanaConnection, solanaRpcUrl, bitcoinConnector, bitcoinConnection, tronConnector, tronConnection]);
|
|
284
365
|
/**
|
|
285
366
|
* Execute a deposit transaction from an OrderResponse
|
|
286
367
|
*
|
|
@@ -417,14 +498,14 @@ export function useTransaction({ walletClient, connector, solanaConnector, solan
|
|
|
417
498
|
const getStatus = useCallback(async (requestId, provider) => {
|
|
418
499
|
setIsLoading(true);
|
|
419
500
|
setCurrentStep('Checking bridge status');
|
|
420
|
-
setError(null);
|
|
421
501
|
try {
|
|
422
502
|
// Use shared status function
|
|
423
503
|
return await getBridgeStatus(requestId, provider);
|
|
424
504
|
}
|
|
425
505
|
catch (err) {
|
|
506
|
+
// Status checks are polled by the caller and can fail transiently (e.g. deBridge indexing lag).
|
|
507
|
+
// Do not surface this as a global transaction error in hook state.
|
|
426
508
|
const error = err instanceof Error ? err : new Error('Failed to get bridge status');
|
|
427
|
-
setError(error);
|
|
428
509
|
throw error;
|
|
429
510
|
}
|
|
430
511
|
finally {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { type AssetInfo } from '@silentswap/sdk';
|
|
2
2
|
/**
|
|
3
3
|
* Hook to select the correct transaction/quote address based on the input token.
|
|
4
|
-
* Returns EVM address for EVM tokens, Solana
|
|
4
|
+
* Returns EVM address for EVM tokens, Solana for Solana, Bitcoin for Bitcoin, Tron for Tron.
|
|
5
5
|
*
|
|
6
6
|
* @param tokenIn - The input token asset info
|
|
7
7
|
* @param evmAddress - The user's EVM address (0x...) or null
|
|
8
8
|
* @param solAddress - The user's Solana address (base58) or null
|
|
9
9
|
* @param bitcoinAddress - The user's Bitcoin address or null
|
|
10
|
+
* @param tronAddress - The user's Tron address or null
|
|
10
11
|
* @returns The appropriate address for the token's chain, or undefined if no token/address
|
|
11
12
|
*/
|
|
12
|
-
export declare function useTransactionAddress(tokenIn: AssetInfo | null | undefined, evmAddress: string | null | undefined, solAddress: string | null | undefined, bitcoinAddress?: string | null | undefined): `0x${string}` | string | undefined;
|
|
13
|
+
export declare function useTransactionAddress(tokenIn: AssetInfo | null | undefined, evmAddress: string | null | undefined, solAddress: string | null | undefined, bitcoinAddress?: string | null | undefined, tronAddress?: string | null | undefined): `0x${string}` | string | undefined;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
import { isEvmAsset, isSolanaAsset, isBitcoinAsset } from '@silentswap/sdk';
|
|
2
|
+
import { isEvmAsset, isSolanaAsset, isBitcoinAsset, isTronAsset } from '@silentswap/sdk';
|
|
3
3
|
/**
|
|
4
4
|
* Hook to select the correct transaction/quote address based on the input token.
|
|
5
|
-
* Returns EVM address for EVM tokens, Solana
|
|
5
|
+
* Returns EVM address for EVM tokens, Solana for Solana, Bitcoin for Bitcoin, Tron for Tron.
|
|
6
6
|
*
|
|
7
7
|
* @param tokenIn - The input token asset info
|
|
8
8
|
* @param evmAddress - The user's EVM address (0x...) or null
|
|
9
9
|
* @param solAddress - The user's Solana address (base58) or null
|
|
10
10
|
* @param bitcoinAddress - The user's Bitcoin address or null
|
|
11
|
+
* @param tronAddress - The user's Tron address or null
|
|
11
12
|
* @returns The appropriate address for the token's chain, or undefined if no token/address
|
|
12
13
|
*/
|
|
13
|
-
export function useTransactionAddress(tokenIn, evmAddress, solAddress, bitcoinAddress) {
|
|
14
|
+
export function useTransactionAddress(tokenIn, evmAddress, solAddress, bitcoinAddress, tronAddress) {
|
|
14
15
|
return useMemo(() => {
|
|
15
16
|
if (!tokenIn) {
|
|
16
17
|
return (evmAddress ?? undefined);
|
|
@@ -19,12 +20,15 @@ export function useTransactionAddress(tokenIn, evmAddress, solAddress, bitcoinAd
|
|
|
19
20
|
return (evmAddress ?? undefined);
|
|
20
21
|
}
|
|
21
22
|
if (isSolanaAsset(tokenIn.caip19)) {
|
|
22
|
-
return solAddress ?? undefined;
|
|
23
|
+
return solAddress ?? undefined;
|
|
23
24
|
}
|
|
24
25
|
if (isBitcoinAsset(tokenIn.caip19)) {
|
|
25
|
-
return bitcoinAddress ?? undefined;
|
|
26
|
+
return bitcoinAddress ?? undefined;
|
|
27
|
+
}
|
|
28
|
+
if (isTronAsset(tokenIn.caip19)) {
|
|
29
|
+
return tronAddress ?? undefined;
|
|
26
30
|
}
|
|
27
31
|
// Default to EVM address
|
|
28
32
|
return (evmAddress ?? undefined);
|
|
29
|
-
}, [tokenIn?.caip19, evmAddress, solAddress, bitcoinAddress]);
|
|
33
|
+
}, [tokenIn?.caip19, evmAddress, solAddress, bitcoinAddress, tronAddress]);
|
|
30
34
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -60,4 +60,6 @@ export { createSolanaTransactionExecutor, convertRelaySolanaStepToTransaction, }
|
|
|
60
60
|
export type { SolanaWalletConnector, SolanaConnection } from './hooks/silent/solana-transaction.js';
|
|
61
61
|
export { createBitcoinTransactionExecutor, convertRelayBitcoinStepToTransaction, } from './hooks/silent/bitcoin-transaction.js';
|
|
62
62
|
export type { BitcoinWalletConnector, BitcoinConnection } from './hooks/silent/bitcoin-transaction.js';
|
|
63
|
+
export { createTronTransactionExecutor, convertRelayTronStepToTransaction, } from './hooks/silent/tron-transaction.js';
|
|
64
|
+
export type { TronWalletConnector, TronConnection } from './hooks/silent/tron-transaction.js';
|
|
63
65
|
export type { Outputs, IOutput } from './contexts/orderTrackingTypes.js';
|
package/dist/index.js
CHANGED
|
@@ -44,3 +44,5 @@ NI_CHAIN_ID_AVALANCHE, XT_TTL_SESSION_CACHE, X_MINIMUM_INPUT_USD, X_MAX_IMPACT_P
|
|
|
44
44
|
export { createSolanaTransactionExecutor, convertRelaySolanaStepToTransaction, } from './hooks/silent/solana-transaction.js';
|
|
45
45
|
// Bitcoin transaction utilities
|
|
46
46
|
export { createBitcoinTransactionExecutor, convertRelayBitcoinStepToTransaction, } from './hooks/silent/bitcoin-transaction.js';
|
|
47
|
+
// Tron transaction utilities
|
|
48
|
+
export { createTronTransactionExecutor, convertRelayTronStepToTransaction, } from './hooks/silent/tron-transaction.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@silentswap/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.52",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@bigmi/core": "^0.6.5",
|
|
26
26
|
"@ensdomains/ensjs": "^4.2.0",
|
|
27
|
-
"@silentswap/sdk": "0.1.
|
|
28
|
-
"@silentswap/ui-kit": "0.1.
|
|
27
|
+
"@silentswap/sdk": "0.1.52",
|
|
28
|
+
"@silentswap/ui-kit": "0.1.52",
|
|
29
29
|
"@solana/codecs-strings": "^5.1.0",
|
|
30
30
|
"@solana/kit": "^5.1.0",
|
|
31
31
|
"@solana/rpc": "^5.1.0",
|