@silentswap/sdk 0.1.76 → 0.1.77
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/chains.d.ts +2853 -0
- package/dist/chains.js +16 -1
- package/dist/data/filtered.json +0 -11
- package/dist/rpc.js +3 -1
- package/dist/simpleswap.d.ts +60 -0
- package/dist/simpleswap.js +152 -0
- package/package.json +1 -1
- package/src/data/filtered.json +0 -11
package/dist/chains.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mainnet, avalanche, base, polygon, arbitrum, bsc, optimism, berachain, kava, taiko, filecoin, gnosis, coreDao, soneium, hedera, immutableZkEvm, hemi, unichain, rootstock, cronos, sei, linea, mantle, pulsechain, evmos, } from 'viem/chains';
|
|
1
|
+
import { mainnet, avalanche, base, polygon, arbitrum, bsc, optimism, berachain, kava, taiko, filecoin, gnosis, coreDao, soneium, hedera, immutableZkEvm, hemi, unichain, rootstock, cronos, sei, linea, mantle, pulsechain, evmos, celo, abstract as abstractChain, blast, etherlink, flowMainnet, hyperEvm, ink, katana, monad, near, plasma, scroll, sonic, xrplevm, zksync, } from 'viem/chains';
|
|
2
2
|
export const SOLANA_CHAIN_ID = 7565164;
|
|
3
3
|
export const BITCOIN_CHAIN_ID = 8253038; // Relay chain ID for Bitcoin
|
|
4
4
|
export const TRON_CHAIN_ID = 728126428; // Relay chain ID for Tron
|
|
@@ -34,6 +34,21 @@ export const A_VIEM_CHAINS = [
|
|
|
34
34
|
mantle,
|
|
35
35
|
pulsechain,
|
|
36
36
|
evmos,
|
|
37
|
+
celo,
|
|
38
|
+
abstractChain,
|
|
39
|
+
blast,
|
|
40
|
+
etherlink,
|
|
41
|
+
flowMainnet,
|
|
42
|
+
hyperEvm,
|
|
43
|
+
ink,
|
|
44
|
+
katana,
|
|
45
|
+
monad,
|
|
46
|
+
near,
|
|
47
|
+
plasma,
|
|
48
|
+
scroll,
|
|
49
|
+
sonic,
|
|
50
|
+
xrplevm,
|
|
51
|
+
zksync,
|
|
37
52
|
];
|
|
38
53
|
/**
|
|
39
54
|
* Get viem chain by chain ID
|
package/dist/data/filtered.json
CHANGED
|
@@ -3481,17 +3481,6 @@
|
|
|
3481
3481
|
"FFFFFF"
|
|
3482
3482
|
]
|
|
3483
3483
|
},
|
|
3484
|
-
"eip155:42220/erc20:0x471EcE3750Da237f93B8E339c536989b8978a438": {
|
|
3485
|
-
"caip19": "eip155:42220/erc20:0x471EcE3750Da237f93B8E339c536989b8978a438",
|
|
3486
|
-
"coingeckoId": "celo",
|
|
3487
|
-
"name": "Celo",
|
|
3488
|
-
"symbol": "celo",
|
|
3489
|
-
"decimals": 18,
|
|
3490
|
-
"gradient": [
|
|
3491
|
-
"E3E364",
|
|
3492
|
-
"FFFF70"
|
|
3493
|
-
]
|
|
3494
|
-
},
|
|
3495
3484
|
"eip155:42220/slip44:52752": {
|
|
3496
3485
|
"caip19": "eip155:42220/slip44:52752",
|
|
3497
3486
|
"coingeckoId": "celo",
|
package/dist/rpc.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { arbitrum, avalanche, base, berachain, bsc, mainnet, optimism, polygon } from 'viem/chains';
|
|
1
|
+
import { arbitrum, avalanche, base, berachain, bsc, celo, mainnet, optimism, polygon } from 'viem/chains';
|
|
2
2
|
import { SOLANA_CHAIN_ID, BITCOIN_CHAIN_ID, TRON_CHAIN_ID } from './chains.js';
|
|
3
3
|
/**
|
|
4
4
|
* Custom RPC endpoint configuration for EVM chains, Solana, and Bitcoin
|
|
@@ -36,6 +36,8 @@ export const H_RPCS = {
|
|
|
36
36
|
[bsc.id]: 'https://yolo-wandering-fire.bsc.quiknode.pro/07aae5c8f9c95c4d596a6997e6a28a786dc3d4a0/',
|
|
37
37
|
// Berachain
|
|
38
38
|
[berachain.id]: 'https://capable-purple-dream.bera-mainnet.quiknode.pro/11502780a6ec104db00d7940f6a61c90868a4402/',
|
|
39
|
+
// Celo
|
|
40
|
+
[celo.id]: 'https://forno.celo.org',
|
|
39
41
|
// Tron
|
|
40
42
|
[TRON_CHAIN_ID]: 'https://multi-icy-borough.tron-mainnet.quiknode.pro/58b72b5b6563a1122911fb254444777c9214d96c/jsonrpc',
|
|
41
43
|
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export interface SimpleSwapRangesResponse {
|
|
2
|
+
min: string;
|
|
3
|
+
max: string | null;
|
|
4
|
+
}
|
|
5
|
+
export interface SimpleSwapExchangeRequest {
|
|
6
|
+
currency_from: string;
|
|
7
|
+
network_from: string;
|
|
8
|
+
currency_to: string;
|
|
9
|
+
network_to: string;
|
|
10
|
+
amount: string;
|
|
11
|
+
address_to: string;
|
|
12
|
+
extra_id_to?: string;
|
|
13
|
+
user_refund_address?: string;
|
|
14
|
+
user_refund_extra_id?: string;
|
|
15
|
+
fixed: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface SimpleSwapExchangeResponse {
|
|
18
|
+
id: string;
|
|
19
|
+
type: string;
|
|
20
|
+
timestamp: string;
|
|
21
|
+
updated_at: string;
|
|
22
|
+
currency_from: string;
|
|
23
|
+
currency_to: string;
|
|
24
|
+
network_from: string;
|
|
25
|
+
network_to: string;
|
|
26
|
+
amount_from: string;
|
|
27
|
+
expected_amount: string;
|
|
28
|
+
amount_to: string | null;
|
|
29
|
+
address_from: string;
|
|
30
|
+
address_to: string;
|
|
31
|
+
extra_id_from: string | null;
|
|
32
|
+
extra_id_to: string | null;
|
|
33
|
+
user_refund_address: string | null;
|
|
34
|
+
user_refund_extra_id: string | null;
|
|
35
|
+
tx_from: string | null;
|
|
36
|
+
tx_to: string | null;
|
|
37
|
+
status: SimpleSwapExchangeStatus;
|
|
38
|
+
redirect_url: string | null;
|
|
39
|
+
}
|
|
40
|
+
export type SimpleSwapExchangeStatus = 'waiting' | 'confirming' | 'exchanging' | 'sending' | 'finished' | 'failed' | 'refunded' | 'expired';
|
|
41
|
+
export interface SimpleSwapEstimateResult {
|
|
42
|
+
estimatedAmount: string;
|
|
43
|
+
ranges: SimpleSwapRangesResponse;
|
|
44
|
+
currencyFrom: string;
|
|
45
|
+
networkFrom: string;
|
|
46
|
+
currencyTo: string;
|
|
47
|
+
networkTo: string;
|
|
48
|
+
}
|
|
49
|
+
export declare function fetchSimpleSwapEstimate(baseUrl: string, currencyFrom: string, networkFrom: string, currencyTo: string, networkTo: string, amount: string, fixed?: boolean, reverse?: boolean, signal?: AbortSignal): Promise<string>;
|
|
50
|
+
export declare function fetchSimpleSwapRanges(baseUrl: string, currencyFrom: string, networkFrom: string, currencyTo: string, networkTo: string, fixed?: boolean, signal?: AbortSignal): Promise<SimpleSwapRangesResponse>;
|
|
51
|
+
export declare function createSimpleSwapExchange(baseUrl: string, request: SimpleSwapExchangeRequest, signal?: AbortSignal): Promise<SimpleSwapExchangeResponse>;
|
|
52
|
+
export declare function getSimpleSwapExchangeStatus(baseUrl: string, exchangeId: string, signal?: AbortSignal): Promise<SimpleSwapExchangeResponse>;
|
|
53
|
+
interface SimpleSwapTicker {
|
|
54
|
+
ticker: string;
|
|
55
|
+
network: string;
|
|
56
|
+
}
|
|
57
|
+
export declare function caip19ToSimpleSwapTicker(caip19: string): SimpleSwapTicker | null;
|
|
58
|
+
export declare function simpleSwapTickerToCaip19(ticker: string, network: string): string | null;
|
|
59
|
+
export declare function isSimpleSwapSupported(caip19: string): boolean;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Types
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// API Functions
|
|
6
|
+
// ============================================================================
|
|
7
|
+
const FETCH_TIMEOUT = 30_000;
|
|
8
|
+
function withTimeout(signal) {
|
|
9
|
+
const controller = new AbortController();
|
|
10
|
+
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT);
|
|
11
|
+
if (signal) {
|
|
12
|
+
signal.addEventListener('abort', () => {
|
|
13
|
+
clearTimeout(timeout);
|
|
14
|
+
controller.abort();
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
controller.signal.addEventListener('abort', () => clearTimeout(timeout));
|
|
18
|
+
return controller.signal;
|
|
19
|
+
}
|
|
20
|
+
export async function fetchSimpleSwapEstimate(baseUrl, currencyFrom, networkFrom, currencyTo, networkTo, amount, fixed = false, reverse = false, signal) {
|
|
21
|
+
const params = new URLSearchParams({
|
|
22
|
+
fixed: String(fixed),
|
|
23
|
+
currency_from: currencyFrom,
|
|
24
|
+
network_from: networkFrom,
|
|
25
|
+
currency_to: currencyTo,
|
|
26
|
+
network_to: networkTo,
|
|
27
|
+
amount,
|
|
28
|
+
...(reverse ? { reverse: 'true' } : {}),
|
|
29
|
+
});
|
|
30
|
+
const response = await fetch(`${baseUrl}/get_estimated?${params}`, {
|
|
31
|
+
signal: withTimeout(signal),
|
|
32
|
+
});
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
const text = await response.text();
|
|
35
|
+
throw new Error(`SimpleSwap estimate failed: HTTP ${response.status}: ${text}`);
|
|
36
|
+
}
|
|
37
|
+
const data = await response.text();
|
|
38
|
+
const parsed = JSON.parse(data);
|
|
39
|
+
if (typeof parsed === 'string')
|
|
40
|
+
return parsed;
|
|
41
|
+
if (typeof parsed === 'number')
|
|
42
|
+
return String(parsed);
|
|
43
|
+
throw new Error(`SimpleSwap estimate: unexpected response: ${data}`);
|
|
44
|
+
}
|
|
45
|
+
export async function fetchSimpleSwapRanges(baseUrl, currencyFrom, networkFrom, currencyTo, networkTo, fixed = false, signal) {
|
|
46
|
+
const params = new URLSearchParams({
|
|
47
|
+
fixed: String(fixed),
|
|
48
|
+
currency_from: currencyFrom,
|
|
49
|
+
network_from: networkFrom,
|
|
50
|
+
currency_to: currencyTo,
|
|
51
|
+
network_to: networkTo,
|
|
52
|
+
});
|
|
53
|
+
const response = await fetch(`${baseUrl}/get_ranges?${params}`, {
|
|
54
|
+
signal: withTimeout(signal),
|
|
55
|
+
});
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
const text = await response.text();
|
|
58
|
+
throw new Error(`SimpleSwap ranges failed: HTTP ${response.status}: ${text}`);
|
|
59
|
+
}
|
|
60
|
+
return response.json();
|
|
61
|
+
}
|
|
62
|
+
export async function createSimpleSwapExchange(baseUrl, request, signal) {
|
|
63
|
+
const response = await fetch(`${baseUrl}/create_exchange`, {
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers: { 'Content-Type': 'application/json' },
|
|
66
|
+
body: JSON.stringify(request),
|
|
67
|
+
signal: withTimeout(signal),
|
|
68
|
+
});
|
|
69
|
+
if (!response.ok) {
|
|
70
|
+
const text = await response.text();
|
|
71
|
+
throw new Error(`SimpleSwap create exchange failed: HTTP ${response.status}: ${text}`);
|
|
72
|
+
}
|
|
73
|
+
return response.json();
|
|
74
|
+
}
|
|
75
|
+
export async function getSimpleSwapExchangeStatus(baseUrl, exchangeId, signal) {
|
|
76
|
+
const response = await fetch(`${baseUrl}/get_exchange?id=${encodeURIComponent(exchangeId)}`, {
|
|
77
|
+
signal: withTimeout(signal),
|
|
78
|
+
});
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
const text = await response.text();
|
|
81
|
+
throw new Error(`SimpleSwap get exchange failed: HTTP ${response.status}: ${text}`);
|
|
82
|
+
}
|
|
83
|
+
return response.json();
|
|
84
|
+
}
|
|
85
|
+
const CAIP19_TO_SIMPLESWAP = {
|
|
86
|
+
// Monero
|
|
87
|
+
'monero:mainnet/slip44:128': { ticker: 'xmr', network: 'xmr' },
|
|
88
|
+
// Bitcoin
|
|
89
|
+
'bip122:000000000019d6689c085ae165831e93/slip44:0': { ticker: 'btc', network: 'btc' },
|
|
90
|
+
// Ethereum native
|
|
91
|
+
'eip155:1/slip44:60': { ticker: 'eth', network: 'eth' },
|
|
92
|
+
// USDT on Ethereum
|
|
93
|
+
'eip155:1/erc20:0xdac17f958d2ee523a2206206994597c13d831ec7': { ticker: 'usdt', network: 'eth' },
|
|
94
|
+
// USDC on Ethereum
|
|
95
|
+
'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': { ticker: 'usdc', network: 'eth' },
|
|
96
|
+
// BNB native (BSC)
|
|
97
|
+
'eip155:56/slip44:60': { ticker: 'bnb', network: 'bsc' },
|
|
98
|
+
// USDT on BSC
|
|
99
|
+
'eip155:56/erc20:0x55d398326f99059ff775485246999027b3197955': { ticker: 'usdt', network: 'bsc' },
|
|
100
|
+
// USDC on BSC
|
|
101
|
+
'eip155:56/erc20:0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d': { ticker: 'usdc', network: 'bsc' },
|
|
102
|
+
// Solana native
|
|
103
|
+
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501': { ticker: 'sol', network: 'sol' },
|
|
104
|
+
// USDT on Solana
|
|
105
|
+
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB': { ticker: 'usdt', network: 'sol' },
|
|
106
|
+
// USDC on Solana
|
|
107
|
+
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v': { ticker: 'usdc', network: 'sol' },
|
|
108
|
+
// AVAX native (Avalanche C-Chain)
|
|
109
|
+
'eip155:43114/slip44:60': { ticker: 'avax', network: 'avax' },
|
|
110
|
+
// USDT on Avalanche
|
|
111
|
+
'eip155:43114/erc20:0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7': { ticker: 'usdt', network: 'avax' },
|
|
112
|
+
// USDC on Avalanche
|
|
113
|
+
'eip155:43114/erc20:0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e': { ticker: 'usdc', network: 'avax' },
|
|
114
|
+
// Polygon native (MATIC/POL)
|
|
115
|
+
'eip155:137/slip44:60': { ticker: 'matic', network: 'matic' },
|
|
116
|
+
// USDT on Polygon
|
|
117
|
+
'eip155:137/erc20:0xc2132d05d31c914a87c6611c10748aeb04b58e8f': { ticker: 'usdt', network: 'matic' },
|
|
118
|
+
// USDC on Polygon
|
|
119
|
+
'eip155:137/erc20:0x3c499c542cef5e3811e1192ce70d8cc03d5c3359': { ticker: 'usdc', network: 'matic' },
|
|
120
|
+
// Arbitrum native
|
|
121
|
+
'eip155:42161/slip44:60': { ticker: 'eth', network: 'arbitrum' },
|
|
122
|
+
// USDT on Arbitrum
|
|
123
|
+
'eip155:42161/erc20:0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9': { ticker: 'usdt', network: 'arbitrum' },
|
|
124
|
+
// USDC on Arbitrum
|
|
125
|
+
'eip155:42161/erc20:0xaf88d065e77c8cc2239327c5edb3a432268e5831': { ticker: 'usdc', network: 'arbitrum' },
|
|
126
|
+
// Optimism native
|
|
127
|
+
'eip155:10/slip44:60': { ticker: 'eth', network: 'op' },
|
|
128
|
+
// Base native
|
|
129
|
+
'eip155:8453/slip44:60': { ticker: 'eth', network: 'base' },
|
|
130
|
+
// TRX native (Tron)
|
|
131
|
+
'tron:0x2b6653dc/slip44:195': { ticker: 'trx', network: 'trx' },
|
|
132
|
+
// USDT on Tron
|
|
133
|
+
'tron:0x2b6653dc/trc20:TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t': { ticker: 'usdt', network: 'trx' },
|
|
134
|
+
};
|
|
135
|
+
const SIMPLESWAP_TO_CAIP19 = {};
|
|
136
|
+
for (const [caip19, ticker] of Object.entries(CAIP19_TO_SIMPLESWAP)) {
|
|
137
|
+
SIMPLESWAP_TO_CAIP19[`${ticker.ticker}:${ticker.network}`] = caip19;
|
|
138
|
+
}
|
|
139
|
+
export function caip19ToSimpleSwapTicker(caip19) {
|
|
140
|
+
const normalized = caip19.toLowerCase();
|
|
141
|
+
for (const [key, value] of Object.entries(CAIP19_TO_SIMPLESWAP)) {
|
|
142
|
+
if (key.toLowerCase() === normalized)
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
export function simpleSwapTickerToCaip19(ticker, network) {
|
|
148
|
+
return SIMPLESWAP_TO_CAIP19[`${ticker}:${network}`] || null;
|
|
149
|
+
}
|
|
150
|
+
export function isSimpleSwapSupported(caip19) {
|
|
151
|
+
return caip19ToSimpleSwapTicker(caip19) !== null;
|
|
152
|
+
}
|
package/package.json
CHANGED
package/src/data/filtered.json
CHANGED
|
@@ -3481,17 +3481,6 @@
|
|
|
3481
3481
|
"FFFFFF"
|
|
3482
3482
|
]
|
|
3483
3483
|
},
|
|
3484
|
-
"eip155:42220/erc20:0x471EcE3750Da237f93B8E339c536989b8978a438": {
|
|
3485
|
-
"caip19": "eip155:42220/erc20:0x471EcE3750Da237f93B8E339c536989b8978a438",
|
|
3486
|
-
"coingeckoId": "celo",
|
|
3487
|
-
"name": "Celo",
|
|
3488
|
-
"symbol": "celo",
|
|
3489
|
-
"decimals": 18,
|
|
3490
|
-
"gradient": [
|
|
3491
|
-
"E3E364",
|
|
3492
|
-
"FFFF70"
|
|
3493
|
-
]
|
|
3494
|
-
},
|
|
3495
3484
|
"eip155:42220/slip44:52752": {
|
|
3496
3485
|
"caip19": "eip155:42220/slip44:52752",
|
|
3497
3486
|
"coingeckoId": "celo",
|