@silentswap/react 0.0.52 → 0.0.55
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/BalancesContext.d.ts +2 -0
- package/dist/contexts/BalancesContext.js +106 -6
- package/dist/contexts/SilentSwapContext.d.ts +6 -1
- package/dist/contexts/SilentSwapContext.js +40 -14
- package/dist/hooks/silent/useBridgeExecution.d.ts +5 -1
- package/dist/hooks/silent/useBridgeExecution.js +203 -23
- package/dist/hooks/silent/useQuoteCalculation.js +135 -33
- package/dist/hooks/silent/useSilentQuote.d.ts +10 -1
- package/dist/hooks/silent/useSilentQuote.js +134 -8
- package/dist/hooks/useOrderEstimates.js +14 -6
- package/dist/hooks/useQuote.js +5 -1
- package/dist/hooks/useSwap.js +7 -1
- package/dist/hooks/useTransaction.d.ts +6 -1
- package/dist/hooks/useTransaction.js +105 -2
- package/dist/hooks/useTransactionAddress.d.ts +3 -2
- package/dist/hooks/useTransactionAddress.js +8 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +4 -3
|
@@ -2,6 +2,8 @@ import { useCallback, useState } from 'react';
|
|
|
2
2
|
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
|
+
import { createBitcoinTransactionExecutor, convertRelayBitcoinStepToTransaction } from './silent/bitcoin-transaction.js';
|
|
6
|
+
import { N_RELAY_CHAIN_ID_BITCOIN } from '@silentswap/sdk';
|
|
5
7
|
/**
|
|
6
8
|
* React hook for executing transactions
|
|
7
9
|
*
|
|
@@ -76,7 +78,7 @@ import { createSolanaTransactionExecutor } from './silent/solana-transaction.js'
|
|
|
76
78
|
* }
|
|
77
79
|
* ```
|
|
78
80
|
*/
|
|
79
|
-
export function useTransaction({ walletClient, connector, solanaConnector, solanaConnection, solanaRpcUrl, setCurrentStep: externalSetCurrentStep, onStatus: externalOnStatus, }) {
|
|
81
|
+
export function useTransaction({ walletClient, connector, solanaConnector, solanaConnection, solanaRpcUrl, bitcoinConnector, bitcoinConnection, setCurrentStep: externalSetCurrentStep, onStatus: externalOnStatus, }) {
|
|
80
82
|
const [isLoading, setIsLoading] = useState(false);
|
|
81
83
|
const [internalCurrentStep, setInternalCurrentStep] = useState('');
|
|
82
84
|
const [error, setError] = useState(null);
|
|
@@ -89,9 +91,108 @@ export function useTransaction({ walletClient, connector, solanaConnector, solan
|
|
|
89
91
|
* Supports both EVM and Solana transactions
|
|
90
92
|
*/
|
|
91
93
|
const executeTransaction = useCallback(async (quote) => {
|
|
94
|
+
// Check if quote contains Bitcoin transactions
|
|
95
|
+
// First check txs array for Bitcoin transactions
|
|
96
|
+
const hasBitcoinInTxs = quote.txs.some((tx) => tx.chainId === N_RELAY_CHAIN_ID_BITCOIN || tx.psbt !== undefined);
|
|
97
|
+
// Also check route.steps for Bitcoin PSBT data (for Relay quotes that haven't been fully converted)
|
|
98
|
+
const hasBitcoinInRoute = quote.route?.steps?.some?.((step) => {
|
|
99
|
+
if (step.kind === 'transaction' && step.items) {
|
|
100
|
+
return step.items.some((item) => {
|
|
101
|
+
const itemData = item.data || {};
|
|
102
|
+
return 'psbt' in itemData || 'hex' in itemData;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
});
|
|
107
|
+
const hasBitcoinTransactions = hasBitcoinInTxs || hasBitcoinInRoute;
|
|
92
108
|
// Check if quote contains Solana transactions
|
|
93
109
|
const hasSolanaTransactions = quote.txs.some((tx) => tx.instructions !== undefined);
|
|
94
|
-
if (
|
|
110
|
+
if (hasBitcoinTransactions) {
|
|
111
|
+
// Bitcoin transactions require Bitcoin connector
|
|
112
|
+
if (!bitcoinConnector) {
|
|
113
|
+
throw new Error('Bitcoin connector is required for Bitcoin bridge transactions. ' +
|
|
114
|
+
'Please provide bitcoinConnector option.');
|
|
115
|
+
}
|
|
116
|
+
// Create Bitcoin transaction executor
|
|
117
|
+
const bitcoinExecutor = createBitcoinTransactionExecutor(bitcoinConnector, bitcoinConnection);
|
|
118
|
+
setIsLoading(true);
|
|
119
|
+
setError(null);
|
|
120
|
+
try {
|
|
121
|
+
// Execute based on provider
|
|
122
|
+
switch (quote.provider) {
|
|
123
|
+
case 'relay':
|
|
124
|
+
// For Bitcoin transactions, if txs array doesn't have Bitcoin transactions,
|
|
125
|
+
// execute directly from route.steps (similar to useBridgeExecution)
|
|
126
|
+
if (hasBitcoinInRoute && !hasBitcoinInTxs) {
|
|
127
|
+
// Execute Bitcoin transactions directly from route steps
|
|
128
|
+
const steps = quote.route?.steps || [];
|
|
129
|
+
for (const step of steps) {
|
|
130
|
+
if (step.kind === 'transaction' && step.items) {
|
|
131
|
+
for (const item of step.items) {
|
|
132
|
+
const itemData = item.data || {};
|
|
133
|
+
if ('psbt' in itemData || 'hex' in itemData || 'data' in itemData) {
|
|
134
|
+
setCurrentStep(step.id === 'approve'
|
|
135
|
+
? 'Requesting approval...'
|
|
136
|
+
: step.id === 'deposit'
|
|
137
|
+
? 'Requesting deposit...'
|
|
138
|
+
: 'Requesting bridge...');
|
|
139
|
+
onStatus?.(step.id === 'approve'
|
|
140
|
+
? 'Requesting approval...'
|
|
141
|
+
: step.id === 'deposit'
|
|
142
|
+
? 'Requesting deposit...'
|
|
143
|
+
: 'Requesting bridge...');
|
|
144
|
+
// Convert relay step to BridgeTransaction
|
|
145
|
+
const bitcoinTx = convertRelayBitcoinStepToTransaction(itemData, N_RELAY_CHAIN_ID_BITCOIN);
|
|
146
|
+
// Execute Bitcoin transaction
|
|
147
|
+
await bitcoinExecutor(bitcoinTx);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Find request ID for status monitoring
|
|
153
|
+
const requestId = steps.find((s) => s.requestId)?.requestId;
|
|
154
|
+
if (!requestId) {
|
|
155
|
+
throw new Error('Missing relay.link request ID');
|
|
156
|
+
}
|
|
157
|
+
// Return pending status (status monitoring would be handled separately)
|
|
158
|
+
return {
|
|
159
|
+
status: 'pending',
|
|
160
|
+
txHashes: [],
|
|
161
|
+
requestId,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
// Use standard execution path if txs array has Bitcoin transactions
|
|
166
|
+
const executeTx = createTransactionExecutor(walletClient, connector, undefined, // solanaExecutor
|
|
167
|
+
bitcoinExecutor);
|
|
168
|
+
// Create a no-op chain switcher for Bitcoin (chain switching is handled by connector)
|
|
169
|
+
const switchChain = async (_chainId) => {
|
|
170
|
+
// Bitcoin doesn't require chain switching
|
|
171
|
+
};
|
|
172
|
+
return await executeRelayBridge(quote, executeTx, switchChain, (step) => {
|
|
173
|
+
setCurrentStep(step);
|
|
174
|
+
onStatus?.(step);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
case 'debridge':
|
|
178
|
+
// DeBridge doesn't support Bitcoin
|
|
179
|
+
throw new Error('DeBridge does not support Bitcoin transactions');
|
|
180
|
+
default:
|
|
181
|
+
throw new Error(`Unsupported bridge provider: ${quote.provider}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
const error = err instanceof Error ? err : new Error('Bridge execution failed');
|
|
186
|
+
console.error('Bridge execution failed:', error);
|
|
187
|
+
setError(error);
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
setIsLoading(false);
|
|
192
|
+
setCurrentStep('');
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else if (hasSolanaTransactions) {
|
|
95
196
|
// Solana transactions require Solana connector and connection
|
|
96
197
|
if (!solanaConnector || !solanaConnection) {
|
|
97
198
|
throw new Error('Solana connector and connection are required for Solana bridge transactions. ' +
|
|
@@ -99,6 +200,7 @@ export function useTransaction({ walletClient, connector, solanaConnector, solan
|
|
|
99
200
|
}
|
|
100
201
|
// Create Solana transaction executor
|
|
101
202
|
const solanaExecutor = createSolanaTransactionExecutor(solanaConnector, solanaConnection);
|
|
203
|
+
debugger;
|
|
102
204
|
// For Solana, we still need EVM wallet client for chain switching (if needed)
|
|
103
205
|
// But the actual transaction execution will use Solana executor
|
|
104
206
|
const executeTx = createTransactionExecutor(walletClient, connector, solanaExecutor);
|
|
@@ -145,6 +247,7 @@ export function useTransaction({ walletClient, connector, solanaConnector, solan
|
|
|
145
247
|
setIsLoading(true);
|
|
146
248
|
setError(null);
|
|
147
249
|
try {
|
|
250
|
+
debugger;
|
|
148
251
|
// Create wrapper functions using shared utilities
|
|
149
252
|
const executeTx = createTransactionExecutor(walletClient, connector);
|
|
150
253
|
const switchChain = createChainSwitcher(walletClient, connector);
|
|
@@ -1,11 +1,12 @@
|
|
|
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 address for Solana tokens.
|
|
4
|
+
* Returns EVM address for EVM tokens, Solana address for Solana tokens, Bitcoin address for Bitcoin tokens.
|
|
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
|
+
* @param bitcoinAddress - The user's Bitcoin address or null
|
|
9
10
|
* @returns The appropriate address for the token's chain, or undefined if no token/address
|
|
10
11
|
*/
|
|
11
|
-
export declare function useTransactionAddress(tokenIn: AssetInfo | null | undefined, evmAddress: string | null | undefined, solAddress: string | null | undefined): `0x${string}` | string | undefined;
|
|
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;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
import { isEvmAsset, isSolanaAsset } from '@silentswap/sdk';
|
|
2
|
+
import { isEvmAsset, isSolanaAsset, isBitcoinAsset } 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 address for Solana tokens.
|
|
5
|
+
* Returns EVM address for EVM tokens, Solana address for Solana tokens, Bitcoin address for Bitcoin tokens.
|
|
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
|
+
* @param bitcoinAddress - The user's Bitcoin address or null
|
|
10
11
|
* @returns The appropriate address for the token's chain, or undefined if no token/address
|
|
11
12
|
*/
|
|
12
|
-
export function useTransactionAddress(tokenIn, evmAddress, solAddress) {
|
|
13
|
+
export function useTransactionAddress(tokenIn, evmAddress, solAddress, bitcoinAddress) {
|
|
13
14
|
return useMemo(() => {
|
|
14
15
|
if (!tokenIn) {
|
|
15
16
|
return (evmAddress ?? undefined);
|
|
@@ -20,7 +21,10 @@ export function useTransactionAddress(tokenIn, evmAddress, solAddress) {
|
|
|
20
21
|
if (isSolanaAsset(tokenIn.caip19)) {
|
|
21
22
|
return solAddress ?? undefined; // Return Solana address as string (not cast to 0x)
|
|
22
23
|
}
|
|
24
|
+
if (isBitcoinAsset(tokenIn.caip19)) {
|
|
25
|
+
return bitcoinAddress ?? undefined; // Return Bitcoin address as string
|
|
26
|
+
}
|
|
23
27
|
// Default to EVM address
|
|
24
28
|
return (evmAddress ?? undefined);
|
|
25
|
-
}, [tokenIn?.caip19, evmAddress, solAddress]);
|
|
29
|
+
}, [tokenIn?.caip19, evmAddress, solAddress, bitcoinAddress]);
|
|
26
30
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -56,3 +56,5 @@ export type { UseOrderTrackingOptions, UseOrderTrackingReturn, OrderDeposit, Out
|
|
|
56
56
|
export type { UseRefundOptions, UseRefundReturn } from './hooks/silent/useRefund.js';
|
|
57
57
|
export { createSolanaTransactionExecutor, convertRelaySolanaStepToTransaction, } from './hooks/silent/solana-transaction.js';
|
|
58
58
|
export type { SolanaWalletConnector, SolanaConnection } from './hooks/silent/solana-transaction.js';
|
|
59
|
+
export { createBitcoinTransactionExecutor, convertRelayBitcoinStepToTransaction, } from './hooks/silent/bitcoin-transaction.js';
|
|
60
|
+
export type { BitcoinWalletConnector, BitcoinConnection } from './hooks/silent/bitcoin-transaction.js';
|
package/dist/index.js
CHANGED
|
@@ -41,3 +41,5 @@ DepositStatus, queryOrderStatus, checkRefundEligibility, executeRefund, checkRec
|
|
|
41
41
|
NI_CHAIN_ID_AVALANCHE, XT_TTL_SESSION_CACHE, X_MINIMUM_INPUT_USD, X_MAX_IMPACT_PERCENT, S0X_ADDR_USDC_AVALANCHE, S_CAIP19_USDC_AVALANCHE, } from '@silentswap/sdk';
|
|
42
42
|
// Solana transaction utilities
|
|
43
43
|
export { createSolanaTransactionExecutor, convertRelaySolanaStepToTransaction, } from './hooks/silent/solana-transaction.js';
|
|
44
|
+
// Bitcoin transaction utilities
|
|
45
|
+
export { createBitcoinTransactionExecutor, convertRelayBitcoinStepToTransaction, } from './hooks/silent/bitcoin-transaction.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@silentswap/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.55",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -22,9 +22,10 @@
|
|
|
22
22
|
"react": ">=16.8.0"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@bigmi/core": "^0.6.5",
|
|
25
26
|
"@ensdomains/ensjs": "^4.2.0",
|
|
26
|
-
"@silentswap/sdk": "0.0.
|
|
27
|
-
"@silentswap/ui-kit": "0.0.
|
|
27
|
+
"@silentswap/sdk": "0.0.55",
|
|
28
|
+
"@silentswap/ui-kit": "0.0.55",
|
|
28
29
|
"@solana/codecs-strings": "^5.1.0",
|
|
29
30
|
"@solana/kit": "^5.1.0",
|
|
30
31
|
"@solana/rpc": "^5.1.0",
|