@silentswap/sdk 0.0.21 → 0.0.22
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/assets.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Caip19, Caip2 } from './types/core.js';
|
|
2
|
+
export interface AssetInfo {
|
|
3
|
+
caip19: Caip19;
|
|
4
|
+
coingeckoId: string;
|
|
5
|
+
name: string;
|
|
6
|
+
symbol: string;
|
|
7
|
+
decimals: number;
|
|
8
|
+
gradient: [string, string];
|
|
9
|
+
style?: string;
|
|
10
|
+
ext?: string;
|
|
11
|
+
precision?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ChainInfo {
|
|
14
|
+
coingeckoPlatformId?: string;
|
|
15
|
+
coingeckoId?: string;
|
|
16
|
+
shortName?: string;
|
|
17
|
+
native?: {
|
|
18
|
+
slip44: number;
|
|
19
|
+
decimals: number;
|
|
20
|
+
symbol: string;
|
|
21
|
+
};
|
|
22
|
+
caip2: Caip2;
|
|
23
|
+
nativeCoinId?: string;
|
|
24
|
+
name: string;
|
|
25
|
+
}
|
|
26
|
+
export interface AssetsData {
|
|
27
|
+
chains: Record<Caip2, ChainInfo>;
|
|
28
|
+
assets: Record<Caip19, AssetInfo>;
|
|
29
|
+
}
|
|
30
|
+
export declare function loadAssetsData(): AssetsData;
|
|
31
|
+
export declare function getAllAssets(): Record<Caip19, AssetInfo>;
|
|
32
|
+
export declare function getAllChains(): Record<Caip2, ChainInfo>;
|
|
33
|
+
export declare function getAllAssetsArray(): AssetInfo[];
|
|
34
|
+
export declare const COMMON_ASSETS: AssetInfo[];
|
|
35
|
+
export declare const CHAIN_NAMES: Record<string, string>;
|
|
36
|
+
/**
|
|
37
|
+
* Get asset by CAIP-19 identifier from the full dataset
|
|
38
|
+
*/
|
|
39
|
+
export declare function getAssetByCaip19(caip19: Caip19): AssetInfo | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Get chain info by CAIP-2 identifier
|
|
42
|
+
*/
|
|
43
|
+
export declare function getChainByCaip2(caip2: Caip2): ChainInfo | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Get all assets filtered by chain ID (for ingress/egress)
|
|
46
|
+
*/
|
|
47
|
+
export declare function getAssetsByChain(chainId: string, ingress?: boolean): AssetInfo[];
|
|
48
|
+
/**
|
|
49
|
+
* Get chain name from chain ID
|
|
50
|
+
*/
|
|
51
|
+
export declare function getChainName(chainId: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Search assets by symbol, name, or CAIP-19
|
|
54
|
+
*/
|
|
55
|
+
export declare function searchAssets(query: string): AssetInfo[];
|
package/dist/assets.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import filteredData from './data/filtered.json' with { type: 'json' };
|
|
2
|
+
// Load assets data from filtered.json
|
|
3
|
+
export function loadAssetsData() {
|
|
4
|
+
return filteredData;
|
|
5
|
+
}
|
|
6
|
+
// Get all assets from the filtered data
|
|
7
|
+
export function getAllAssets() {
|
|
8
|
+
return filteredData.assets;
|
|
9
|
+
}
|
|
10
|
+
// Get all chains from the filtered data
|
|
11
|
+
export function getAllChains() {
|
|
12
|
+
return filteredData.chains;
|
|
13
|
+
}
|
|
14
|
+
// Get all assets as an array for easy iteration
|
|
15
|
+
export function getAllAssetsArray() {
|
|
16
|
+
const assets = filteredData.assets;
|
|
17
|
+
return Object.values(assets).map(asset => ({
|
|
18
|
+
...asset,
|
|
19
|
+
gradient: asset.gradient.length >= 2
|
|
20
|
+
? [asset.gradient[0], asset.gradient[1]]
|
|
21
|
+
: ['000000', '000000'],
|
|
22
|
+
caip19: asset.caip19,
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
// Common tokens list - frequently used assets for quick access
|
|
26
|
+
// This is a subset extracted from filtered.json for convenience
|
|
27
|
+
export const COMMON_ASSETS = getAllAssetsArray().filter(asset => {
|
|
28
|
+
// Filter to commonly used tokens
|
|
29
|
+
const commonCaip19s = [
|
|
30
|
+
'eip155:43114/erc20:0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E', // USDC Avalanche
|
|
31
|
+
'eip155:1/erc20:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC Ethereum
|
|
32
|
+
'eip155:1/erc20:0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT Ethereum
|
|
33
|
+
'eip155:43114/erc20:0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7', // USDT Avalanche
|
|
34
|
+
'eip155:1/slip44:60', // ETH
|
|
35
|
+
'eip155:43114/slip44:9005', // AVAX
|
|
36
|
+
'eip155:10/erc20:0x7F5c764cBc14f9669B88837ca1490cCa17c31607', // USDC Optimism
|
|
37
|
+
'eip155:56/erc20:0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d', // USDC BSC
|
|
38
|
+
'eip155:137/erc20:0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359', // USDC Polygon
|
|
39
|
+
'eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC Base
|
|
40
|
+
'eip155:42161/erc20:0xaf88d065e77c8cC2239327C5EDb3A432268e5831', // USDC Arbitrum
|
|
41
|
+
];
|
|
42
|
+
return commonCaip19s.includes(asset.caip19);
|
|
43
|
+
});
|
|
44
|
+
// Build chain names map from filtered data
|
|
45
|
+
export const CHAIN_NAMES = Object.fromEntries(Object.entries(filteredData.chains).map(([caip2, chain]) => {
|
|
46
|
+
const match = caip2.match(/^eip155:(\d+)$/);
|
|
47
|
+
if (match) {
|
|
48
|
+
return [match[1], chain.name];
|
|
49
|
+
}
|
|
50
|
+
return [];
|
|
51
|
+
}).filter((entry) => entry.length > 0));
|
|
52
|
+
/**
|
|
53
|
+
* Get asset by CAIP-19 identifier from the full dataset
|
|
54
|
+
*/
|
|
55
|
+
export function getAssetByCaip19(caip19) {
|
|
56
|
+
const assets = filteredData.assets;
|
|
57
|
+
const asset = assets[caip19];
|
|
58
|
+
if (!asset)
|
|
59
|
+
return undefined;
|
|
60
|
+
return {
|
|
61
|
+
...asset,
|
|
62
|
+
gradient: asset.gradient.length >= 2
|
|
63
|
+
? [asset.gradient[0], asset.gradient[1]]
|
|
64
|
+
: ['000000', '000000'],
|
|
65
|
+
caip19: asset.caip19,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get chain info by CAIP-2 identifier
|
|
70
|
+
*/
|
|
71
|
+
export function getChainByCaip2(caip2) {
|
|
72
|
+
const chains = filteredData.chains;
|
|
73
|
+
return chains[caip2];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get all assets filtered by chain ID (for ingress/egress)
|
|
77
|
+
*/
|
|
78
|
+
export function getAssetsByChain(chainId, ingress = true) {
|
|
79
|
+
return getAllAssetsArray().filter(asset => {
|
|
80
|
+
const match = asset.caip19.match(/^eip155:(\d+)\//);
|
|
81
|
+
if (!match)
|
|
82
|
+
return false;
|
|
83
|
+
return match[1] === chainId;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get chain name from chain ID
|
|
88
|
+
*/
|
|
89
|
+
export function getChainName(chainId) {
|
|
90
|
+
const chainInfo = getChainByCaip2(`eip155:${chainId}`);
|
|
91
|
+
return chainInfo?.name || CHAIN_NAMES[chainId] || `Chain ${chainId}`;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Search assets by symbol, name, or CAIP-19
|
|
95
|
+
*/
|
|
96
|
+
export function searchAssets(query) {
|
|
97
|
+
const lowerQuery = query.toLowerCase();
|
|
98
|
+
return getAllAssetsArray().filter(asset => asset.symbol.toLowerCase().includes(lowerQuery) ||
|
|
99
|
+
asset.name.toLowerCase().includes(lowerQuery) ||
|
|
100
|
+
asset.caip19.toLowerCase().includes(lowerQuery));
|
|
101
|
+
}
|
package/dist/bridge.d.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import type { Hex } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Bridge provider types
|
|
4
|
+
*/
|
|
5
|
+
export type BridgeProvider = 'relay' | 'debridge';
|
|
6
|
+
/**
|
|
7
|
+
* Bridge quote interface
|
|
8
|
+
*/
|
|
9
|
+
export interface BridgeQuote {
|
|
10
|
+
provider: BridgeProvider;
|
|
11
|
+
estimatedTime: number;
|
|
12
|
+
fee: {
|
|
13
|
+
amount: string;
|
|
14
|
+
token: string;
|
|
15
|
+
usdValue?: number;
|
|
16
|
+
};
|
|
17
|
+
slippage: number;
|
|
18
|
+
route: any;
|
|
19
|
+
txs: BridgeTransaction[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Bridge transaction interface
|
|
23
|
+
*/
|
|
24
|
+
export interface BridgeTransaction {
|
|
25
|
+
to: `0x${string}`;
|
|
26
|
+
value: string;
|
|
27
|
+
data: `0x${string}`;
|
|
28
|
+
gasLimit?: string;
|
|
29
|
+
chainId: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Bridge status interface
|
|
33
|
+
*/
|
|
34
|
+
export interface BridgeStatus {
|
|
35
|
+
status: 'pending' | 'success' | 'failed' | 'refund' | 'fallback';
|
|
36
|
+
txHashes?: Hex[];
|
|
37
|
+
details?: string;
|
|
38
|
+
requestId?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Bridge quote parameters
|
|
42
|
+
*/
|
|
43
|
+
export interface BridgeQuoteParams {
|
|
44
|
+
/** Source chain ID */
|
|
45
|
+
srcChainId: number;
|
|
46
|
+
/** Destination chain ID */
|
|
47
|
+
dstChainId: number;
|
|
48
|
+
/** Source token address (0x0 for native) */
|
|
49
|
+
srcToken: `0x${string}`;
|
|
50
|
+
/** Destination token address */
|
|
51
|
+
dstToken: `0x${string}`;
|
|
52
|
+
/** Amount to bridge (in source token units) */
|
|
53
|
+
amount: string;
|
|
54
|
+
/** Recipient address on destination chain */
|
|
55
|
+
recipient: `0x${string}`;
|
|
56
|
+
/** User/sender address for the bridge operation */
|
|
57
|
+
user: `0x${string}`;
|
|
58
|
+
/** Additional transactions to execute after bridging */
|
|
59
|
+
additionalTxs?: BridgeTransaction[];
|
|
60
|
+
/** Trade type for the bridge operation */
|
|
61
|
+
tradeType: 'EXACT_INPUT' | 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT';
|
|
62
|
+
/** Whether to prepend operating expenses (deBridge only) */
|
|
63
|
+
prependOperatingExpenses?: boolean;
|
|
64
|
+
/** Whether to enable estimation (deBridge only) */
|
|
65
|
+
enableEstimate?: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get a quote from relay.link
|
|
69
|
+
*/
|
|
70
|
+
export declare function getRelayQuote(params: BridgeQuoteParams, apiKey?: string): Promise<BridgeQuote>;
|
|
71
|
+
/**
|
|
72
|
+
* Get a quote from debridge (handles both cross-chain and same-chain swaps)
|
|
73
|
+
*/
|
|
74
|
+
export declare function getDebridgeQuote(params: BridgeQuoteParams, apiKey?: string): Promise<BridgeQuote>;
|
|
75
|
+
/**
|
|
76
|
+
* Execute a relay.link bridge transaction
|
|
77
|
+
*/
|
|
78
|
+
export declare function executeRelayBridge(quote: BridgeQuote, executeTransaction: (tx: BridgeTransaction) => Promise<Hex>, switchChain: (chainId: number) => Promise<void>, setStep: (step: string) => void): Promise<BridgeStatus>;
|
|
79
|
+
/**
|
|
80
|
+
* Execute a debridge bridge transaction
|
|
81
|
+
*/
|
|
82
|
+
export declare function executeDebridgeBridge(quote: BridgeQuote, executeTransaction: (tx: BridgeTransaction) => Promise<Hex>, switchChain: (chainId: number) => Promise<void>, setStep: (step: string) => void): Promise<BridgeStatus>;
|
|
83
|
+
/**
|
|
84
|
+
* Get relay.link bridge status
|
|
85
|
+
*/
|
|
86
|
+
export declare function getRelayStatus(requestId: string): Promise<BridgeStatus>;
|
|
87
|
+
/**
|
|
88
|
+
* Get debridge bridge status
|
|
89
|
+
*/
|
|
90
|
+
export declare function getDebridgeStatus(requestId: string): Promise<BridgeStatus>;
|
|
91
|
+
/**
|
|
92
|
+
* Advanced bridge API types for optimal solving
|
|
93
|
+
*/
|
|
94
|
+
export interface RelayQuoteParams {
|
|
95
|
+
user: string;
|
|
96
|
+
originChainId: number;
|
|
97
|
+
destinationChainId: number;
|
|
98
|
+
originCurrency: string;
|
|
99
|
+
destinationCurrency: string;
|
|
100
|
+
amount: string;
|
|
101
|
+
tradeType: 'EXACT_INPUT' | 'EXACT_OUTPUT';
|
|
102
|
+
recipient?: string;
|
|
103
|
+
referrer?: string;
|
|
104
|
+
txs?: Array<{
|
|
105
|
+
to: string;
|
|
106
|
+
value: string;
|
|
107
|
+
data: string;
|
|
108
|
+
}>;
|
|
109
|
+
txsGasLimit?: number;
|
|
110
|
+
}
|
|
111
|
+
export interface RelayQuoteResponse {
|
|
112
|
+
details: {
|
|
113
|
+
currencyIn: {
|
|
114
|
+
amount: string;
|
|
115
|
+
amountUsd: number;
|
|
116
|
+
};
|
|
117
|
+
currencyOut: {
|
|
118
|
+
amount: string;
|
|
119
|
+
amountUsd: number;
|
|
120
|
+
};
|
|
121
|
+
totalImpact: {
|
|
122
|
+
percent: string;
|
|
123
|
+
};
|
|
124
|
+
timeEstimate: number;
|
|
125
|
+
};
|
|
126
|
+
fees: {
|
|
127
|
+
gas: {
|
|
128
|
+
amount?: string;
|
|
129
|
+
amountUsd?: string;
|
|
130
|
+
};
|
|
131
|
+
relayer: {
|
|
132
|
+
amountUsd?: string;
|
|
133
|
+
};
|
|
134
|
+
relayerGas: {
|
|
135
|
+
amountUsd?: string;
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export interface DeBridgeOrderParams {
|
|
140
|
+
srcChainId: number;
|
|
141
|
+
dstChainId: number;
|
|
142
|
+
srcChainTokenIn: string;
|
|
143
|
+
dstChainTokenOut: string;
|
|
144
|
+
srcChainTokenInAmount: string;
|
|
145
|
+
dstChainTokenOutAmount: string;
|
|
146
|
+
dstChainTokenOutRecipient?: string;
|
|
147
|
+
account?: string;
|
|
148
|
+
prependOperatingExpenses?: boolean;
|
|
149
|
+
enableEstimate?: boolean;
|
|
150
|
+
dlnHook?: string;
|
|
151
|
+
}
|
|
152
|
+
export interface DeBridgeOrderResponse {
|
|
153
|
+
tx: {
|
|
154
|
+
allowanceTarget?: string;
|
|
155
|
+
};
|
|
156
|
+
estimation: {
|
|
157
|
+
srcChainTokenIn: {
|
|
158
|
+
amount: string;
|
|
159
|
+
approximateUsdValue: number;
|
|
160
|
+
};
|
|
161
|
+
dstChainTokenOut: {
|
|
162
|
+
amount: string;
|
|
163
|
+
approximateUsdValue: number;
|
|
164
|
+
};
|
|
165
|
+
costDetails?: Array<{
|
|
166
|
+
payload?: {
|
|
167
|
+
feeApproximateUsdValue?: string;
|
|
168
|
+
};
|
|
169
|
+
}>;
|
|
170
|
+
};
|
|
171
|
+
estimatedTransactionFee?: {
|
|
172
|
+
total?: string;
|
|
173
|
+
};
|
|
174
|
+
order?: {
|
|
175
|
+
approximateFulfillmentDelay?: number;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Fetch a relay.link quote with detailed response
|
|
180
|
+
*/
|
|
181
|
+
export declare function fetchRelayQuote(params: RelayQuoteParams, signal?: AbortSignal): Promise<RelayQuoteResponse>;
|
|
182
|
+
/**
|
|
183
|
+
* Fetch a deBridge order with detailed response (handles both cross-chain and same-chain swaps)
|
|
184
|
+
*/
|
|
185
|
+
export declare function fetchDebridgeOrder(params: DeBridgeOrderParams, signal?: AbortSignal): Promise<DeBridgeOrderResponse>;
|
|
186
|
+
/**
|
|
187
|
+
* Result from solving optimal USDC amount
|
|
188
|
+
*/
|
|
189
|
+
export interface SolveUsdcResult {
|
|
190
|
+
/** Optimal USDC amount out (in microUSDC) */
|
|
191
|
+
usdcAmountOut: bigint;
|
|
192
|
+
/** Actual input amount required */
|
|
193
|
+
actualAmountIn: bigint;
|
|
194
|
+
/** Bridge provider used */
|
|
195
|
+
provider: BridgeProvider;
|
|
196
|
+
/** Allowance target address (for deBridge) */
|
|
197
|
+
allowanceTarget: string;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Solve for optimal USDC amount using both relay and debridge providers
|
|
201
|
+
* Compares rates and returns the best option
|
|
202
|
+
*
|
|
203
|
+
* @param srcChainId - Source chain ID
|
|
204
|
+
* @param srcToken - Source token address (use 0x0 for native)
|
|
205
|
+
* @param srcAmount - Source amount in token units (as string)
|
|
206
|
+
* @param userAddress - User's EVM address
|
|
207
|
+
* @param depositCalldata - Optional deposit calldata (will use phony if not provided)
|
|
208
|
+
* @param maxImpactPercent - Maximum price impact percentage allowed (default from constants)
|
|
209
|
+
* @returns Promise resolving to solve result with optimal amounts
|
|
210
|
+
*/
|
|
211
|
+
export declare function solveOptimalUsdcAmount(srcChainId: number, srcToken: string, srcAmount: string, userAddress: string, depositCalldata?: string, maxImpactPercent?: number): Promise<SolveUsdcResult>;
|