@silentswap/sdk 0.0.21 → 0.0.23
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/assets.d.ts +55 -0
- package/dist/assets.js +101 -0
- package/dist/bridge.d.ts +211 -0
- package/dist/bridge.js +615 -0
- package/dist/chain.d.ts +35 -0
- package/dist/chain.js +81 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.js +16 -0
- package/dist/data/filtered.json +2179 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +8 -0
- package/dist/quote-utils.d.ts +75 -0
- package/dist/quote-utils.js +185 -0
- package/dist/storage.d.ts +74 -0
- package/dist/storage.js +161 -0
- package/dist/transaction-utils.d.ts +19 -0
- package/dist/transaction-utils.js +85 -0
- package/dist/wallet.d.ts +18 -0
- package/dist/wallet.js +107 -0
- package/package.json +10 -4
- package/src/data/filtered.json +2179 -0
package/dist/chain.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ensure the correct chain is active
|
|
3
|
+
*
|
|
4
|
+
* @param chainId - The target chain ID
|
|
5
|
+
* @param walletClient - The wallet client
|
|
6
|
+
* @param connector - The wagmi connector for chain switching
|
|
7
|
+
* @returns The wallet client (after ensuring correct chain)
|
|
8
|
+
*/
|
|
9
|
+
export async function ensureChain(chainId, walletClient, connector) {
|
|
10
|
+
// Check current chain
|
|
11
|
+
let currentChainId;
|
|
12
|
+
try {
|
|
13
|
+
currentChainId = await walletClient.getChainId();
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
// If we can't get chain ID, assume we need to switch
|
|
17
|
+
currentChainId = -1;
|
|
18
|
+
}
|
|
19
|
+
if (currentChainId !== chainId) {
|
|
20
|
+
try {
|
|
21
|
+
// Try to switch chain
|
|
22
|
+
await connector.switchChain?.({ chainId });
|
|
23
|
+
}
|
|
24
|
+
catch (switchError) {
|
|
25
|
+
// If switch fails, try to add the chain
|
|
26
|
+
try {
|
|
27
|
+
// This would need viem chain definitions
|
|
28
|
+
// For now, we'll throw the original error
|
|
29
|
+
throw switchError;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
throw new Error(`Failed to switch to chain ${chainId}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return walletClient;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Wait for transaction confirmation using viem's waitForTransactionReceipt
|
|
40
|
+
*
|
|
41
|
+
* @param hash - The transaction hash to wait for
|
|
42
|
+
* @param publicClient - The public client to use for waiting
|
|
43
|
+
* @param timeoutMs - Timeout in milliseconds (default: 30000)
|
|
44
|
+
* @returns Promise resolving when transaction is confirmed
|
|
45
|
+
*/
|
|
46
|
+
export async function waitForTransactionConfirmation(hash, publicClient, timeoutMs = 30000) {
|
|
47
|
+
try {
|
|
48
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
49
|
+
hash,
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
status: receipt.status === 'success' ? 'success' : 'failed',
|
|
53
|
+
transactionHash: hash,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.warn('Transaction confirmation failed:', error);
|
|
58
|
+
return {
|
|
59
|
+
status: 'failed',
|
|
60
|
+
transactionHash: hash,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Execute a transaction with confirmation waiting
|
|
66
|
+
*
|
|
67
|
+
* @param params - Transaction parameters
|
|
68
|
+
* @param walletClient - The wallet client
|
|
69
|
+
* @param publicClient - The public client to use for waiting
|
|
70
|
+
* @returns Promise resolving to transaction result
|
|
71
|
+
*/
|
|
72
|
+
export async function executeTransaction(params, walletClient, publicClient) {
|
|
73
|
+
// Send transaction
|
|
74
|
+
const hash = await walletClient.sendTransaction(params);
|
|
75
|
+
// Wait for confirmation
|
|
76
|
+
const result = await waitForTransactionConfirmation(hash, publicClient);
|
|
77
|
+
return {
|
|
78
|
+
hash,
|
|
79
|
+
status: result.status,
|
|
80
|
+
};
|
|
81
|
+
}
|
package/dist/constants.d.ts
CHANGED
|
@@ -4,6 +4,14 @@ export declare const EVM_NATIVE_ADDRESS: Hex;
|
|
|
4
4
|
export declare const MAINNET_SILENTSWAP_API = "https://api.silentswap.com/v2";
|
|
5
5
|
export declare const MAINNET_GATEWAY_ADDRESS = "0xA798d4D04faad17C309127C2B9B99Cc459635eDC";
|
|
6
6
|
export declare const MAINNET_GATEWAY_PUBLIC_KEY = "0x0494913354a94d40604cd453d2a654489aa78472daf953c63cae4ceaaa40740d682905847e99618c34b360d8ef4645a954cc9686619995465dfdba6da34f35642f";
|
|
7
|
+
export declare const S0X_ADDR_GATEWAY = "0xAAef732E8B327917BF44A7892102A5ED3Bd27842";
|
|
8
|
+
export declare const S0X_ADDR_DEPOSITOR = "0x02AcB3A073eF5625Ec0e30481df1cf8c4bD7a98E";
|
|
9
|
+
export declare const S0X_ADDR_USDC_AVALANCHE = "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E";
|
|
10
|
+
export declare const S_CAIP19_USDC_AVALANCHE = "eip155:43114/erc20:0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E";
|
|
11
|
+
export declare const NI_CHAIN_ID_AVALANCHE = 43114;
|
|
12
|
+
export declare const XT_TTL_SESSION_CACHE: number;
|
|
13
|
+
export declare const X_MINIMUM_INPUT_USD = 9.95;
|
|
14
|
+
export declare const X_MAX_IMPACT_PERCENT = 1.5;
|
|
7
15
|
export declare const COIN_TYPES: {
|
|
8
16
|
readonly ETH: "60";
|
|
9
17
|
readonly ATOM: "118";
|
package/dist/constants.js
CHANGED
|
@@ -5,6 +5,22 @@ export const EVM_NATIVE_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
|
|
|
5
5
|
export const MAINNET_SILENTSWAP_API = 'https://api.silentswap.com/v2';
|
|
6
6
|
export const MAINNET_GATEWAY_ADDRESS = '0xA798d4D04faad17C309127C2B9B99Cc459635eDC';
|
|
7
7
|
export const MAINNET_GATEWAY_PUBLIC_KEY = '0x0494913354a94d40604cd453d2a654489aa78472daf953c63cae4ceaaa40740d682905847e99618c34b360d8ef4645a954cc9686619995465dfdba6da34f35642f';
|
|
8
|
+
// Gateway contract address on Avalanche (Testnet)
|
|
9
|
+
export const S0X_ADDR_GATEWAY = "0xAAef732E8B327917BF44A7892102A5ED3Bd27842";
|
|
10
|
+
// Depositor contract address on Avalanche
|
|
11
|
+
export const S0X_ADDR_DEPOSITOR = "0x02AcB3A073eF5625Ec0e30481df1cf8c4bD7a98E";
|
|
12
|
+
// USDC contract address on Avalanche
|
|
13
|
+
export const S0X_ADDR_USDC_AVALANCHE = "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E";
|
|
14
|
+
// CAIP-19 identifier for USDC on Avalanche
|
|
15
|
+
export const S_CAIP19_USDC_AVALANCHE = `eip155:43114/erc20:${S0X_ADDR_USDC_AVALANCHE}`;
|
|
16
|
+
// Avalanche chain ID
|
|
17
|
+
export const NI_CHAIN_ID_AVALANCHE = 43114;
|
|
18
|
+
// Session cache TTL
|
|
19
|
+
export const XT_TTL_SESSION_CACHE = 24 * 60 * 60 * 1000; // 24 hours
|
|
20
|
+
// Minimum input USD amount
|
|
21
|
+
export const X_MINIMUM_INPUT_USD = 9.95;
|
|
22
|
+
// Maximum impact percentage for bridge operations
|
|
23
|
+
export const X_MAX_IMPACT_PERCENT = 1.5;
|
|
8
24
|
// Coin types
|
|
9
25
|
export const COIN_TYPES = {
|
|
10
26
|
ETH: '60',
|