@silentswap/react 0.0.42 → 0.0.44
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/hooks/silent/useBridgeExecution.js +4 -10
- package/dist/hooks/silent/useOrderSigning.d.ts +1 -0
- package/dist/hooks/silent/useSilentQuote.d.ts +2 -0
- package/dist/hooks/silent/useSilentQuote.js +10 -5
- package/dist/hooks/useSwap.d.ts +1 -1
- package/dist/hooks/useSwap.js +1 -1
- package/dist/hooks/useTransaction.js +6 -18
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { ensureChain, waitForTransactionConfirmation, NI_CHAIN_ID_AVALANCHE, S0X_ADDR_USDC_AVALANCHE, X_MAX_IMPACT_PERCENT, getRelayStatus, getDebridgeStatus, fetchDebridgeOrder, fetchRelayQuote, createPhonyDepositCalldata, isSolanaAsset, parseSolanaCaip19, isSolanaNativeToken, isSplToken, N_RELAY_CHAIN_ID_SOLANA, SB58_ADDR_SOL_PROGRAM_SYSTEM, getChainById, } from '@silentswap/sdk';
|
|
2
|
+
import { encodeFunctionData, erc20Abi, getAddress } from 'viem';
|
|
3
|
+
import { ensureChain, waitForTransactionConfirmation, createPublicClientWithRpc, NI_CHAIN_ID_AVALANCHE, S0X_ADDR_USDC_AVALANCHE, X_MAX_IMPACT_PERCENT, getRelayStatus, getDebridgeStatus, fetchDebridgeOrder, fetchRelayQuote, createPhonyDepositCalldata, isSolanaAsset, parseSolanaCaip19, isSolanaNativeToken, isSplToken, N_RELAY_CHAIN_ID_SOLANA, SB58_ADDR_SOL_PROGRAM_SYSTEM, getChainById, } from '@silentswap/sdk';
|
|
4
4
|
import { createSolanaTransactionExecutor, convertRelaySolanaStepToTransaction } from './solana-transaction.js';
|
|
5
5
|
const S0X_ADDR_EVM_ZERO = '0x0000000000000000000000000000000000000000';
|
|
6
6
|
const XG_UINT256_MAX = (1n << 256n) - 1n;
|
|
@@ -28,14 +28,8 @@ async function ensureChainAndCreateClient(chainId, walletClient, connector) {
|
|
|
28
28
|
const wallet = await ensureChain(chainId, walletClient, connector);
|
|
29
29
|
// Use wallet's chain if available, otherwise look up chain by ID
|
|
30
30
|
const chain = wallet.chain || getChainById(chainId);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
// Create public client - viem has complex union types that TypeScript struggles with
|
|
35
|
-
const publicClient = createPublicClient({
|
|
36
|
-
chain,
|
|
37
|
-
transport: http(),
|
|
38
|
-
});
|
|
31
|
+
// Create public client with RPC fallback configuration
|
|
32
|
+
const publicClient = createPublicClientWithRpc(chainId, chain);
|
|
39
33
|
return { wallet, publicClient };
|
|
40
34
|
}
|
|
41
35
|
/**
|
|
@@ -84,5 +84,7 @@ export interface ExecuteSwapParams {
|
|
|
84
84
|
splits: number[];
|
|
85
85
|
/** Contact ID of the sender (e.g., "caip10:eip155:*:0x...") */
|
|
86
86
|
senderContactId: string;
|
|
87
|
+
/** Optional integrator ID for tracking */
|
|
88
|
+
integratorId?: string;
|
|
87
89
|
}
|
|
88
90
|
export declare function useSilentQuote({ client, address, evmAddress, solAddress, walletClient, connector, wallet, walletLoading, onStatus, solanaConnector, solanaConnection, solanaRpcUrl, getPrice, setDestinations, }: useSilentQuoteOptions): useSilentQuoteReturn;
|
|
@@ -86,7 +86,7 @@ export function useSilentQuote({ client, address, evmAddress, solAddress, wallet
|
|
|
86
86
|
* 5. Executes deposit transaction
|
|
87
87
|
* 6. Returns swap result with order ID and transaction hashes
|
|
88
88
|
*/
|
|
89
|
-
const executeSwap = useCallback(async ({ sourceAsset, sourceAmount, destinations, splits, senderContactId, }) => {
|
|
89
|
+
const executeSwap = useCallback(async ({ sourceAsset, sourceAmount, destinations, splits, senderContactId, integratorId, }) => {
|
|
90
90
|
if (!rawAddress) {
|
|
91
91
|
throw new Error('Address required for swap execution');
|
|
92
92
|
}
|
|
@@ -157,7 +157,8 @@ export function useSilentQuote({ client, address, evmAddress, solAddress, wallet
|
|
|
157
157
|
// Handle Solana swaps
|
|
158
158
|
if (isSourceSolana) {
|
|
159
159
|
const result = await executeSolanaSwap(quoteResponse, sourceAsset, sourceAmountInUnits, effectiveUsdcAmount, senderContactId, solanaConnector, evmSignerAddress, // Use EVM signer address, not normalizedAddress
|
|
160
|
-
viewingAuth, createOrder, executeSolanaBridge, resolvedGroup
|
|
160
|
+
viewingAuth, createOrder, executeSolanaBridge, resolvedGroup, // Pass resolved group for order creation
|
|
161
|
+
integratorId);
|
|
161
162
|
setOrderId(result.orderId);
|
|
162
163
|
setViewingAuth(result.viewingAuth);
|
|
163
164
|
return result;
|
|
@@ -175,6 +176,7 @@ export function useSilentQuote({ client, address, evmAddress, solAddress, wallet
|
|
|
175
176
|
sourceSender: {
|
|
176
177
|
contactId: senderContactId,
|
|
177
178
|
},
|
|
179
|
+
...(integratorId && { integratorId }),
|
|
178
180
|
}, resolvedGroup);
|
|
179
181
|
// Handle ERC-20 approvals if needed
|
|
180
182
|
if (effectiveAllowanceTarget && !isDepositingDirectly && evmSignerAddress) {
|
|
@@ -191,7 +193,8 @@ export function useSilentQuote({ client, address, evmAddress, solAddress, wallet
|
|
|
191
193
|
// In Svelte: zg_amount_src_usdc is passed directly to bridge execution (line 1028)
|
|
192
194
|
const result = await executeEvmSwap(sourceAsset, sourceAmountInUnits, effectiveUsdcAmount, // Use amount from solveOptimalUsdcAmount (matches Svelte)
|
|
193
195
|
providerForSwap, orderResponse, evmSignerAddress, // Use EVM signer address, not normalizedAddress
|
|
194
|
-
viewingAuth, executeEvmBridge, senderContactId
|
|
196
|
+
viewingAuth, executeEvmBridge, senderContactId, // Pass sender contact ID to extract sender address
|
|
197
|
+
integratorId);
|
|
195
198
|
setOrderId(result.orderId);
|
|
196
199
|
setViewingAuth(result.viewingAuth);
|
|
197
200
|
return result;
|
|
@@ -275,7 +278,7 @@ export function useSilentQuote({ client, address, evmAddress, solAddress, wallet
|
|
|
275
278
|
* 4. Returns swap result
|
|
276
279
|
*/
|
|
277
280
|
async function executeSolanaSwap(quoteResponse, sourceAsset, sourceAmount, usdcAmount, senderContactId, solanaConnector, evmSignerAddress, // EVM signer address (matches Svelte's s0x_signer)
|
|
278
|
-
viewingAuth, createOrder, executeSolanaBridge, facilitatorGroup) {
|
|
281
|
+
viewingAuth, createOrder, executeSolanaBridge, facilitatorGroup, integratorId) {
|
|
279
282
|
if (!solanaConnector) {
|
|
280
283
|
throw new Error('Solana connector required for Solana swaps');
|
|
281
284
|
}
|
|
@@ -300,6 +303,7 @@ viewingAuth, createOrder, executeSolanaBridge, facilitatorGroup) {
|
|
|
300
303
|
sourceSender: {
|
|
301
304
|
contactId: senderContactId,
|
|
302
305
|
},
|
|
306
|
+
...(integratorId && { integratorId }),
|
|
303
307
|
}, facilitatorGroup);
|
|
304
308
|
// Get deposit parameters from order
|
|
305
309
|
const depositParams = orderResponse.transaction.metadata?.params;
|
|
@@ -337,7 +341,8 @@ viewingAuth, createOrder, executeSolanaBridge, facilitatorGroup) {
|
|
|
337
341
|
* 4. Returns swap result
|
|
338
342
|
*/
|
|
339
343
|
async function executeEvmSwap(sourceAsset, sourceAmount, usdcAmount, provider, orderResponse, evmSignerAddress, // EVM signer address (matches Svelte's s0x_signer)
|
|
340
|
-
viewingAuth, executeEvmBridge, senderContactId
|
|
344
|
+
viewingAuth, executeEvmBridge, senderContactId, // Sender contact ID to extract sender address
|
|
345
|
+
integratorId) {
|
|
341
346
|
// Parse source asset to get chain ID and token address
|
|
342
347
|
const sourceEvmParsed = parseEvmCaip19(sourceAsset);
|
|
343
348
|
if (!sourceEvmParsed) {
|
package/dist/hooks/useSwap.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AssetInfo } from '@silentswap/sdk';
|
|
2
2
|
export declare const X_RANGE_SLIDER_MIN_GAP = 0.01;
|
|
3
|
-
export declare const OUTPUT_LIMIT =
|
|
3
|
+
export declare const OUTPUT_LIMIT = 10;
|
|
4
4
|
export declare const DEFAULT_SOURCE_ASSET = "eip155:1/slip44:60";
|
|
5
5
|
export declare const DEFAULT_DEST_ASSET = "eip155:1/erc20:0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599";
|
|
6
6
|
export declare const DEFAULT_OUTPUT_ASSET = "eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
package/dist/hooks/useSwap.js
CHANGED
|
@@ -4,7 +4,7 @@ import { getAssetByCaip19 } from '@silentswap/sdk';
|
|
|
4
4
|
const DEFAULT_SLIPPAGE = 1;
|
|
5
5
|
// Constants matching Svelte app
|
|
6
6
|
export const X_RANGE_SLIDER_MIN_GAP = 0.01;
|
|
7
|
-
export const OUTPUT_LIMIT =
|
|
7
|
+
export const OUTPUT_LIMIT = 10;
|
|
8
8
|
// Default assets
|
|
9
9
|
export const DEFAULT_SOURCE_ASSET = 'eip155:1/slip44:60'; // ETH on Ethereum
|
|
10
10
|
export const DEFAULT_DEST_ASSET = 'eip155:1/erc20:0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599'; // WBTC on Ethereum
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { executeRelayBridge, executeDebridgeBridge, getBridgeStatus, createTransactionExecutor, createChainSwitcher, ensureChain, waitForTransactionConfirmation, parseTransactionRequestForViem, getChainById, } from '@silentswap/sdk';
|
|
2
|
+
import { erc20Abi } from 'viem';
|
|
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
|
/**
|
|
6
6
|
* React hook for executing transactions
|
|
@@ -204,16 +204,10 @@ export function useTransaction({ walletClient, connector, solanaConnector, solan
|
|
|
204
204
|
const chainId = transactionParams.chainId ?? 1;
|
|
205
205
|
// Ensure correct chain
|
|
206
206
|
const wallet = await ensureChain(chainId, walletClient, connector);
|
|
207
|
-
// Create public client
|
|
207
|
+
// Create public client with RPC fallback configuration
|
|
208
208
|
// Use wallet's chain if available, otherwise look up chain by ID
|
|
209
209
|
const chain = wallet.chain || getChainById(chainId);
|
|
210
|
-
|
|
211
|
-
throw new Error(`Unsupported chain ID: ${chainId}. Please ensure the chain is supported.`);
|
|
212
|
-
}
|
|
213
|
-
const publicClient = createPublicClient({
|
|
214
|
-
chain,
|
|
215
|
-
transport: http(),
|
|
216
|
-
});
|
|
210
|
+
const publicClient = createPublicClientWithRpc(chainId, chain);
|
|
217
211
|
setCurrentStep('Sending transaction');
|
|
218
212
|
onStatus?.('Sending transaction');
|
|
219
213
|
// Execute transaction
|
|
@@ -269,16 +263,10 @@ export function useTransaction({ walletClient, connector, solanaConnector, solan
|
|
|
269
263
|
try {
|
|
270
264
|
// Switch to source chain for approval
|
|
271
265
|
const wallet = await ensureChain(chainId, walletClient, connector);
|
|
272
|
-
//
|
|
266
|
+
// Create public client with RPC fallback configuration
|
|
273
267
|
// Use wallet's chain if available, otherwise look up chain by ID
|
|
274
268
|
const chain = wallet.chain || getChainById(chainId);
|
|
275
|
-
|
|
276
|
-
throw new Error(`Unsupported chain ID: ${chainId}. Please ensure the chain is supported.`);
|
|
277
|
-
}
|
|
278
|
-
const publicClient = createPublicClient({
|
|
279
|
-
chain,
|
|
280
|
-
transport: http(),
|
|
281
|
-
});
|
|
269
|
+
const publicClient = createPublicClientWithRpc(chainId, chain);
|
|
282
270
|
const currentAllowance = (await publicClient.readContract({
|
|
283
271
|
address: tokenAddress,
|
|
284
272
|
abi: erc20Abi,
|
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.44",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@ensdomains/ensjs": "^4.2.0",
|
|
26
|
-
"@silentswap/sdk": "0.0.
|
|
27
|
-
"@silentswap/ui-kit": "0.0.
|
|
26
|
+
"@silentswap/sdk": "0.0.44",
|
|
27
|
+
"@silentswap/ui-kit": "0.0.44",
|
|
28
28
|
"@solana/codecs-strings": "^5.1.0",
|
|
29
29
|
"@solana/kit": "^5.1.0",
|
|
30
30
|
"@solana/rpc": "^5.1.0",
|