uniport-sdk 0.0.1 → 0.0.2
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/LICENSE +21 -0
- package/README.md +128 -73
- package/dist/components/index.cjs +1140 -975
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +2 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +1118 -953
- package/dist/components/index.js.map +1 -1
- package/dist/core/index.cjs +216 -130
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +55 -45
- package/dist/core/index.d.ts +55 -45
- package/dist/core/index.js +212 -116
- package/dist/core/index.js.map +1 -1
- package/dist/{index-uzI1Zngp.d.cts → index-Dg_m2bK3.d.cts} +19 -10
- package/dist/{index-uzI1Zngp.d.ts → index-Dg_m2bK3.d.ts} +19 -10
- package/dist/index.cjs +1178 -1018
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -6
- package/dist/index.d.ts +8 -6
- package/dist/index.js +1145 -975
- package/dist/index.js.map +1 -1
- package/package.json +18 -12
package/dist/core/index.cjs
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var oneClickSdkTypescript = require('@defuse-protocol/one-click-sdk-typescript');
|
|
4
|
-
|
|
5
3
|
// src/core/tokens.ts
|
|
6
4
|
var TOKEN_ICONS = {
|
|
7
5
|
// Stablecoins
|
|
8
6
|
USDC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
9
7
|
USDT: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png",
|
|
10
|
-
DAI: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/
|
|
8
|
+
DAI: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6B175474E89094C44Da98b954EedeEC495271d0F/logo.png",
|
|
11
9
|
// Major tokens
|
|
12
10
|
ETH: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png",
|
|
13
11
|
WETH: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
|
|
@@ -40,16 +38,16 @@ var TOKEN_ICONS = {
|
|
|
40
38
|
SHIB: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE/logo.png",
|
|
41
39
|
PEPE: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6982508145454Ce325dDbE47a25d4ec3d2311933/logo.png",
|
|
42
40
|
// Ecosystem tokens
|
|
43
|
-
STRK: "https://
|
|
44
|
-
BERA: "https://
|
|
41
|
+
STRK: "https://coin-images.coingecko.com/coins/images/26433/large/starknet.png",
|
|
42
|
+
BERA: "https://s2.coinmarketcap.com/static/img/coins/64x64/31645.png",
|
|
45
43
|
GNO: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6810e776880C02933D47DB1b9fc05908e5386b96/logo.png",
|
|
46
|
-
MON: "https://
|
|
44
|
+
MON: "https://s2.coinmarketcap.com/static/img/coins/64x64/33868.png",
|
|
47
45
|
ZEC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zcash/info/logo.png",
|
|
48
46
|
// Meme coins
|
|
49
|
-
TRUMP: "https://
|
|
50
|
-
WIF: "https://
|
|
51
|
-
BRETT: "https://
|
|
52
|
-
TURBO: "https://
|
|
47
|
+
TRUMP: "https://s2.coinmarketcap.com/static/img/coins/64x64/35336.png",
|
|
48
|
+
WIF: "https://s2.coinmarketcap.com/static/img/coins/64x64/28752.png",
|
|
49
|
+
BRETT: "https://s2.coinmarketcap.com/static/img/coins/64x64/29743.png",
|
|
50
|
+
TURBO: "https://s2.coinmarketcap.com/static/img/coins/64x64/24911.png",
|
|
53
51
|
// Default fallback
|
|
54
52
|
DEFAULT: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png"
|
|
55
53
|
};
|
|
@@ -71,21 +69,29 @@ var CHAIN_ICONS = {
|
|
|
71
69
|
cardano: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/cardano/info/logo.png",
|
|
72
70
|
aptos: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/aptos/info/logo.png",
|
|
73
71
|
gnosis: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/xdai/info/logo.png",
|
|
74
|
-
starknet: "https://
|
|
75
|
-
bera: "https://
|
|
76
|
-
monad: "https://
|
|
72
|
+
starknet: "https://coin-images.coingecko.com/coins/images/26433/large/starknet.png",
|
|
73
|
+
bera: "https://s2.coinmarketcap.com/static/img/coins/64x64/31645.png",
|
|
74
|
+
monad: "https://s2.coinmarketcap.com/static/img/coins/64x64/33868.png",
|
|
77
75
|
doge: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/doge/info/logo.png",
|
|
78
76
|
ltc: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/litecoin/info/logo.png",
|
|
79
77
|
bch: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/bitcoincash/info/logo.png",
|
|
80
78
|
xrp: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ripple/info/logo.png",
|
|
81
79
|
zec: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zcash/info/logo.png"
|
|
82
80
|
};
|
|
83
|
-
function createToken(chain, symbol, assetId, decimals, contractAddress) {
|
|
84
|
-
const
|
|
81
|
+
function createToken(chain, symbol, assetId, decimals, contractAddress, options) {
|
|
82
|
+
const normalizedSymbol = symbol.replace("$", "").replace(" ", "");
|
|
83
|
+
const canonicalPrefix = TOKEN_NAME_PREFIXES[chain] || chain;
|
|
84
|
+
const legacyName = `${chain}${normalizedSymbol}`;
|
|
85
|
+
const name = options?.name || `${canonicalPrefix}${normalizedSymbol}`;
|
|
85
86
|
const icon = TOKEN_ICONS[symbol] || TOKEN_ICONS.DEFAULT;
|
|
86
87
|
const chainIcon = CHAIN_ICONS[chain];
|
|
88
|
+
const aliases = new Set(options?.aliases || []);
|
|
89
|
+
if (legacyName !== name) {
|
|
90
|
+
aliases.add(legacyName);
|
|
91
|
+
}
|
|
87
92
|
return {
|
|
88
93
|
name,
|
|
94
|
+
aliases: aliases.size > 0 ? Array.from(aliases) : void 0,
|
|
89
95
|
symbol,
|
|
90
96
|
assetId,
|
|
91
97
|
chain,
|
|
@@ -95,6 +101,19 @@ function createToken(chain, symbol, assetId, decimals, contractAddress) {
|
|
|
95
101
|
contractAddress
|
|
96
102
|
};
|
|
97
103
|
}
|
|
104
|
+
var TOKEN_NAME_PREFIXES = {
|
|
105
|
+
eth: "ethereum",
|
|
106
|
+
arb: "arbitrum",
|
|
107
|
+
op: "optimism",
|
|
108
|
+
sol: "solana",
|
|
109
|
+
btc: "bitcoin",
|
|
110
|
+
avax: "avalanche",
|
|
111
|
+
doge: "dogecoin",
|
|
112
|
+
ltc: "litecoin",
|
|
113
|
+
bch: "bitcoinCash",
|
|
114
|
+
bera: "berachain",
|
|
115
|
+
zec: "zcash"
|
|
116
|
+
};
|
|
98
117
|
var suiSUI = createToken("sui", "SUI", "nep141:sui.omft.near", 9);
|
|
99
118
|
var suiUSDC = createToken("sui", "USDC", "nep141:sui-c1b81ecaf27933252d31a963bc5e9458f13c18ce.omft.near", 6, "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC");
|
|
100
119
|
var ethereumETH = createToken("eth", "ETH", "nep141:eth.omft.near", 18);
|
|
@@ -116,7 +135,7 @@ var arbitrumARB = createToken("arb", "ARB", "nep141:arb-0x912ce59144191c1204e645
|
|
|
116
135
|
var arbitrumGMX = createToken("arb", "GMX", "nep141:arb-0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a.omft.near", 18, "0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a");
|
|
117
136
|
var baseETH = createToken("base", "ETH", "nep141:base.omft.near", 18);
|
|
118
137
|
var baseUSDC = createToken("base", "USDC", "nep141:base-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913.omft.near", 6, "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913");
|
|
119
|
-
var baseCbBTC = createToken("base", "cbBTC", "nep141:base-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near", 8, "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf");
|
|
138
|
+
var baseCbBTC = createToken("base", "cbBTC", "nep141:base-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near", 8, "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf", { name: "baseCbBTC" });
|
|
120
139
|
var baseBRETT = createToken("base", "BRETT", "nep141:base-0x532f27101965dd16442e59d40670faf5ebb142e4.omft.near", 18, "0x532f27101965dd16442e59d40670faf5ebb142e4");
|
|
121
140
|
var optimismETH = createToken("op", "ETH", "nep245:v2_1.omni.hot.tg:10_11111111111111111111", 18);
|
|
122
141
|
var optimismUSDC = createToken("op", "USDC", "nep245:v2_1.omni.hot.tg:10_A2ewyUyDp6qsue1jqZsGypkCxRJ", 6, "0x0b2c639c533813f4aa9d7837caf62653d097ff85");
|
|
@@ -151,7 +170,10 @@ var aptosAPT = createToken("aptos", "APT", "nep141:aptos.omft.near", 8);
|
|
|
151
170
|
var starknetSTRK = createToken("starknet", "STRK", "nep141:starknet.omft.near", 18);
|
|
152
171
|
var berachainBERA = createToken("bera", "BERA", "nep141:bera.omft.near", 18);
|
|
153
172
|
var zcashZEC = createToken("zec", "ZEC", "nep141:zec.omft.near", 8);
|
|
154
|
-
var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near"
|
|
173
|
+
var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near", {
|
|
174
|
+
name: "nearNEAR",
|
|
175
|
+
aliases: ["nearwNEAR"]
|
|
176
|
+
});
|
|
155
177
|
var nearUSDC = createToken("near", "USDC", "nep141:17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1", 6, "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1");
|
|
156
178
|
var nearUSDT = createToken("near", "USDT", "nep141:usdt.tether-token.near", 6, "usdt.tether-token.near");
|
|
157
179
|
var CHAINS = {
|
|
@@ -308,7 +330,9 @@ var CHAINS = {
|
|
|
308
330
|
};
|
|
309
331
|
var ALL_TOKENS = Object.values(CHAINS).flatMap((chain) => chain.tokens);
|
|
310
332
|
function getToken(name) {
|
|
311
|
-
return ALL_TOKENS.find(
|
|
333
|
+
return ALL_TOKENS.find(
|
|
334
|
+
(token) => token.name === name || token.aliases?.includes(name)
|
|
335
|
+
);
|
|
312
336
|
}
|
|
313
337
|
function getTokensByChain(chainId) {
|
|
314
338
|
return CHAINS[chainId]?.tokens || [];
|
|
@@ -319,31 +343,77 @@ function getTokenByAssetId(assetId) {
|
|
|
319
343
|
function getSupportedChains() {
|
|
320
344
|
return Object.values(CHAINS).filter((c) => c.tokens.length > 0);
|
|
321
345
|
}
|
|
322
|
-
|
|
323
|
-
|
|
346
|
+
|
|
347
|
+
// src/core/config.ts
|
|
348
|
+
var DEFAULT_HOSTED_BACKEND_URL = "https://uniport-backend-production.up.railway.app";
|
|
349
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 2e4;
|
|
350
|
+
var configuredBackendUrl;
|
|
351
|
+
var configuredRequestTimeoutMs;
|
|
352
|
+
function normalizeBackendUrl(url) {
|
|
353
|
+
return url.replace(/\/+$/, "");
|
|
324
354
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
throw new Error("Uniport SDK Error: apiKey is required. Pass your NEAR API key to initUniport().");
|
|
330
|
-
}
|
|
331
|
-
oneClickSdkTypescript.OpenAPI.BASE = config.baseUrl || "https://1click.chaindefuser.com";
|
|
332
|
-
oneClickSdkTypescript.OpenAPI.TOKEN = config.apiKey;
|
|
355
|
+
function getLegacyBackendOverride() {
|
|
356
|
+
const envBackendUrl = typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_UNIPORT_BACKEND_URL : void 0;
|
|
357
|
+
const windowBackendUrl = typeof window !== "undefined" ? window.__UNIPORT_BACKEND_URL__ : void 0;
|
|
358
|
+
return envBackendUrl || windowBackendUrl;
|
|
333
359
|
}
|
|
334
|
-
function
|
|
335
|
-
if (
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
360
|
+
function configureUniport(config) {
|
|
361
|
+
if (config.backendUrl !== void 0) {
|
|
362
|
+
configuredBackendUrl = config.backendUrl ? normalizeBackendUrl(config.backendUrl) : void 0;
|
|
363
|
+
}
|
|
364
|
+
if (config.requestTimeoutMs !== void 0) {
|
|
365
|
+
configuredRequestTimeoutMs = config.requestTimeoutMs > 0 ? config.requestTimeoutMs : DEFAULT_REQUEST_TIMEOUT_MS;
|
|
339
366
|
}
|
|
340
|
-
return _config;
|
|
341
367
|
}
|
|
342
|
-
function
|
|
343
|
-
|
|
368
|
+
function getUniportConfig() {
|
|
369
|
+
const backendUrl = configuredBackendUrl || getLegacyBackendOverride() || DEFAULT_HOSTED_BACKEND_URL;
|
|
370
|
+
return {
|
|
371
|
+
backendUrl: normalizeBackendUrl(backendUrl),
|
|
372
|
+
requestTimeoutMs: configuredRequestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS
|
|
373
|
+
};
|
|
344
374
|
}
|
|
345
375
|
|
|
346
376
|
// src/core/intents.ts
|
|
377
|
+
var UniportError = class extends Error {
|
|
378
|
+
constructor(params) {
|
|
379
|
+
super(params.message);
|
|
380
|
+
this.name = "UniportError";
|
|
381
|
+
this.code = params.code;
|
|
382
|
+
this.details = params.details;
|
|
383
|
+
this.status = params.status;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
function isAbortError(error) {
|
|
387
|
+
return error instanceof Error && error.name === "AbortError";
|
|
388
|
+
}
|
|
389
|
+
function toUniportError(body, fallback) {
|
|
390
|
+
return new UniportError({
|
|
391
|
+
code: body.code || fallback.code,
|
|
392
|
+
message: body.message || fallback.message,
|
|
393
|
+
details: body.details,
|
|
394
|
+
status: fallback.status
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
function createTimeoutSignal(timeoutMs, externalSignal) {
|
|
398
|
+
const controller = new AbortController();
|
|
399
|
+
let timedOut = false;
|
|
400
|
+
const timeoutId = setTimeout(() => {
|
|
401
|
+
timedOut = true;
|
|
402
|
+
controller.abort();
|
|
403
|
+
}, timeoutMs);
|
|
404
|
+
const abortFromExternal = () => controller.abort();
|
|
405
|
+
externalSignal?.addEventListener("abort", abortFromExternal, {
|
|
406
|
+
once: true
|
|
407
|
+
});
|
|
408
|
+
return {
|
|
409
|
+
signal: controller.signal,
|
|
410
|
+
didTimeout: () => timedOut,
|
|
411
|
+
cleanup: () => {
|
|
412
|
+
clearTimeout(timeoutId);
|
|
413
|
+
externalSignal?.removeEventListener("abort", abortFromExternal);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
}
|
|
347
417
|
function toSmallestUnits(amount, decimals) {
|
|
348
418
|
const [whole, fraction = ""] = amount.split(".");
|
|
349
419
|
const paddedFraction = fraction.padEnd(decimals, "0").slice(0, decimals);
|
|
@@ -359,16 +429,7 @@ function generateDeadline(hoursFromNow = 1) {
|
|
|
359
429
|
const deadline = new Date(Date.now() + hoursFromNow * 60 * 60 * 1e3);
|
|
360
430
|
return deadline.toISOString();
|
|
361
431
|
}
|
|
362
|
-
function ensureInitialized() {
|
|
363
|
-
if (!isInitialized()) {
|
|
364
|
-
throw new Error(
|
|
365
|
-
"Uniport SDK not initialized. Call initUniport() first."
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
432
|
async function getQuote(options) {
|
|
370
|
-
ensureInitialized();
|
|
371
|
-
const config = getConfig();
|
|
372
433
|
const {
|
|
373
434
|
originToken,
|
|
374
435
|
destinationToken,
|
|
@@ -380,97 +441,133 @@ async function getQuote(options) {
|
|
|
380
441
|
swapType = "EXACT_INPUT",
|
|
381
442
|
deadline,
|
|
382
443
|
dry = false,
|
|
383
|
-
referral =
|
|
444
|
+
referral = "uniport",
|
|
445
|
+
signal
|
|
384
446
|
} = options;
|
|
385
447
|
const amountInSmallestUnits = toSmallestUnits(amount, originToken.decimals);
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
destinationAsset: destinationToken.assetId,
|
|
393
|
-
amount: amountInSmallestUnits,
|
|
394
|
-
refundTo,
|
|
395
|
-
refundType: oneClickSdkTypescript.QuoteRequest.refundType.ORIGIN_CHAIN,
|
|
396
|
-
recipient,
|
|
397
|
-
recipientType: oneClickSdkTypescript.QuoteRequest.recipientType.DESTINATION_CHAIN,
|
|
398
|
-
deadline: deadline?.toISOString() || generateDeadline(1),
|
|
399
|
-
referral
|
|
400
|
-
};
|
|
448
|
+
const { backendUrl, requestTimeoutMs } = getUniportConfig();
|
|
449
|
+
const { signal: requestSignal, cleanup, didTimeout } = createTimeoutSignal(
|
|
450
|
+
requestTimeoutMs,
|
|
451
|
+
signal
|
|
452
|
+
);
|
|
453
|
+
let response;
|
|
401
454
|
try {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
455
|
+
response = await fetch(`${backendUrl}/api/quote`, {
|
|
456
|
+
method: "POST",
|
|
457
|
+
headers: { "Content-Type": "application/json" },
|
|
458
|
+
signal: requestSignal,
|
|
459
|
+
body: JSON.stringify({
|
|
460
|
+
dry,
|
|
461
|
+
swapType,
|
|
462
|
+
slippageTolerance,
|
|
463
|
+
originAsset: originToken.assetId,
|
|
464
|
+
destinationAsset: destinationToken.assetId,
|
|
465
|
+
amount: amountInSmallestUnits,
|
|
466
|
+
refundTo,
|
|
467
|
+
recipient,
|
|
468
|
+
deadline: deadline?.toISOString() || generateDeadline(1),
|
|
469
|
+
referral
|
|
470
|
+
})
|
|
471
|
+
});
|
|
415
472
|
} catch (error) {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
473
|
+
cleanup();
|
|
474
|
+
if (isAbortError(error)) {
|
|
475
|
+
if (signal?.aborted && !didTimeout()) {
|
|
476
|
+
throw error;
|
|
477
|
+
}
|
|
478
|
+
throw new UniportError({
|
|
479
|
+
code: "REQUEST_TIMEOUT",
|
|
480
|
+
message: "Quote request timed out"
|
|
481
|
+
});
|
|
420
482
|
}
|
|
421
483
|
throw error;
|
|
422
484
|
}
|
|
485
|
+
cleanup();
|
|
486
|
+
if (!response.ok) {
|
|
487
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
488
|
+
throw toUniportError(errorBody, {
|
|
489
|
+
code: "QUOTE_FAILED",
|
|
490
|
+
message: "Quote failed.",
|
|
491
|
+
status: response.status
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
const data = await response.json();
|
|
495
|
+
const quote = data.quote;
|
|
496
|
+
return {
|
|
497
|
+
depositAddress: quote.depositAddress || "",
|
|
498
|
+
memo: quote.depositMemo,
|
|
499
|
+
amountIn: quote.amountIn,
|
|
500
|
+
amountOut: quote.amountOut,
|
|
501
|
+
amountOutFormatted: quote.amountOutFormatted,
|
|
502
|
+
amountOutUsd: quote.amountOutUsd,
|
|
503
|
+
deadline: quote.deadline,
|
|
504
|
+
timeWhenInactive: quote.timeWhenInactive,
|
|
505
|
+
correlationId: data.correlationId
|
|
506
|
+
};
|
|
423
507
|
}
|
|
424
508
|
async function submitDepositTx(params) {
|
|
425
|
-
|
|
426
|
-
const {
|
|
509
|
+
const { backendUrl, requestTimeoutMs } = getUniportConfig();
|
|
510
|
+
const { signal, cleanup } = createTimeoutSignal(requestTimeoutMs);
|
|
511
|
+
let response;
|
|
427
512
|
try {
|
|
428
|
-
await
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
513
|
+
response = await fetch(`${backendUrl}/api/deposit`, {
|
|
514
|
+
method: "POST",
|
|
515
|
+
headers: { "Content-Type": "application/json" },
|
|
516
|
+
signal,
|
|
517
|
+
body: JSON.stringify(params)
|
|
433
518
|
});
|
|
434
519
|
} catch (error) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
520
|
+
cleanup();
|
|
521
|
+
if (isAbortError(error)) {
|
|
522
|
+
throw new UniportError({
|
|
523
|
+
code: "REQUEST_TIMEOUT",
|
|
524
|
+
message: "Deposit submission timed out"
|
|
525
|
+
});
|
|
439
526
|
}
|
|
440
527
|
throw error;
|
|
441
528
|
}
|
|
529
|
+
cleanup();
|
|
530
|
+
if (!response.ok) {
|
|
531
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
532
|
+
throw toUniportError(errorBody, {
|
|
533
|
+
code: "DEPOSIT_SUBMISSION_FAILED",
|
|
534
|
+
message: "Submit deposit failed.",
|
|
535
|
+
status: response.status
|
|
536
|
+
});
|
|
537
|
+
}
|
|
442
538
|
}
|
|
443
539
|
async function getExecutionStatus(depositAddress, memo) {
|
|
444
|
-
|
|
540
|
+
const { backendUrl, requestTimeoutMs } = getUniportConfig();
|
|
541
|
+
const url = new URL(
|
|
542
|
+
`${backendUrl}/api/status/${encodeURIComponent(depositAddress)}`
|
|
543
|
+
);
|
|
544
|
+
if (memo) {
|
|
545
|
+
url.searchParams.set("memo", memo);
|
|
546
|
+
}
|
|
547
|
+
const { signal, cleanup } = createTimeoutSignal(requestTimeoutMs);
|
|
548
|
+
let response;
|
|
445
549
|
try {
|
|
446
|
-
|
|
447
|
-
depositAddress,
|
|
448
|
-
memo
|
|
449
|
-
);
|
|
450
|
-
const status = response.status;
|
|
451
|
-
const isComplete = ["SUCCESS", "REFUNDED", "FAILED"].includes(status);
|
|
452
|
-
const isSuccess = status === "SUCCESS";
|
|
453
|
-
const swapDetails = response.swapDetails;
|
|
454
|
-
const destinationTxHashes = swapDetails?.destinationChainTxHashes?.map((tx) => tx.hash);
|
|
455
|
-
const originTxHashes = swapDetails?.originChainTxHashes?.map(
|
|
456
|
-
(tx) => tx.hash
|
|
457
|
-
);
|
|
458
|
-
return {
|
|
459
|
-
status,
|
|
460
|
-
isComplete,
|
|
461
|
-
isSuccess,
|
|
462
|
-
correlationId: response.correlationId,
|
|
463
|
-
destinationTxHashes,
|
|
464
|
-
originTxHashes
|
|
465
|
-
};
|
|
550
|
+
response = await fetch(url.toString(), { signal });
|
|
466
551
|
} catch (error) {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
552
|
+
cleanup();
|
|
553
|
+
if (isAbortError(error)) {
|
|
554
|
+
throw new UniportError({
|
|
555
|
+
code: "REQUEST_TIMEOUT",
|
|
556
|
+
message: "Status check timed out"
|
|
557
|
+
});
|
|
471
558
|
}
|
|
472
559
|
throw error;
|
|
473
560
|
}
|
|
561
|
+
cleanup();
|
|
562
|
+
if (!response.ok) {
|
|
563
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
564
|
+
throw toUniportError(errorBody, {
|
|
565
|
+
code: "STATUS_CHECK_FAILED",
|
|
566
|
+
message: "Status check failed.",
|
|
567
|
+
status: response.status
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
return await response.json();
|
|
474
571
|
}
|
|
475
572
|
async function pollExecutionStatus(depositAddress, options) {
|
|
476
573
|
const {
|
|
@@ -495,22 +592,13 @@ async function pollExecutionStatus(depositAddress, options) {
|
|
|
495
592
|
throw new Error(`Timeout waiting for swap completion after ${timeout}ms`);
|
|
496
593
|
}
|
|
497
594
|
|
|
498
|
-
Object.defineProperty(exports, "ApiError", {
|
|
499
|
-
enumerable: true,
|
|
500
|
-
get: function () { return oneClickSdkTypescript.ApiError; }
|
|
501
|
-
});
|
|
502
|
-
Object.defineProperty(exports, "OneClickService", {
|
|
503
|
-
enumerable: true,
|
|
504
|
-
get: function () { return oneClickSdkTypescript.OneClickService; }
|
|
505
|
-
});
|
|
506
|
-
Object.defineProperty(exports, "OpenAPI", {
|
|
507
|
-
enumerable: true,
|
|
508
|
-
get: function () { return oneClickSdkTypescript.OpenAPI; }
|
|
509
|
-
});
|
|
510
595
|
exports.ALL_TOKENS = ALL_TOKENS;
|
|
511
596
|
exports.CHAINS = CHAINS;
|
|
512
597
|
exports.CHAIN_ICONS = CHAIN_ICONS;
|
|
598
|
+
exports.DEFAULT_HOSTED_BACKEND_URL = DEFAULT_HOSTED_BACKEND_URL;
|
|
599
|
+
exports.DEFAULT_REQUEST_TIMEOUT_MS = DEFAULT_REQUEST_TIMEOUT_MS;
|
|
513
600
|
exports.TOKEN_ICONS = TOKEN_ICONS;
|
|
601
|
+
exports.UniportError = UniportError;
|
|
514
602
|
exports.aptosAPT = aptosAPT;
|
|
515
603
|
exports.arbitrumARB = arbitrumARB;
|
|
516
604
|
exports.arbitrumETH = arbitrumETH;
|
|
@@ -531,6 +619,7 @@ exports.bscBNB = bscBNB;
|
|
|
531
619
|
exports.bscUSDC = bscUSDC;
|
|
532
620
|
exports.bscUSDT = bscUSDT;
|
|
533
621
|
exports.cardanoADA = cardanoADA;
|
|
622
|
+
exports.configureUniport = configureUniport;
|
|
534
623
|
exports.dogecoinDOGE = dogecoinDOGE;
|
|
535
624
|
exports.ethereumAAVE = ethereumAAVE;
|
|
536
625
|
exports.ethereumDAI = ethereumDAI;
|
|
@@ -546,16 +635,13 @@ exports.ethereumUSDT = ethereumUSDT;
|
|
|
546
635
|
exports.ethereumWBTC = ethereumWBTC;
|
|
547
636
|
exports.fromSmallestUnits = fromSmallestUnits;
|
|
548
637
|
exports.generateDeadline = generateDeadline;
|
|
549
|
-
exports.getConfig = getConfig;
|
|
550
638
|
exports.getExecutionStatus = getExecutionStatus;
|
|
551
639
|
exports.getQuote = getQuote;
|
|
552
|
-
exports.getSuiDestinationTokens = getSuiDestinationTokens;
|
|
553
640
|
exports.getSupportedChains = getSupportedChains;
|
|
554
641
|
exports.getToken = getToken;
|
|
555
642
|
exports.getTokenByAssetId = getTokenByAssetId;
|
|
556
643
|
exports.getTokensByChain = getTokensByChain;
|
|
557
|
-
exports.
|
|
558
|
-
exports.isInitialized = isInitialized;
|
|
644
|
+
exports.getUniportConfig = getUniportConfig;
|
|
559
645
|
exports.litecoinLTC = litecoinLTC;
|
|
560
646
|
exports.nearNEAR = nearNEAR;
|
|
561
647
|
exports.nearUSDC = nearUSDC;
|