uniport-sdk 0.0.1 → 0.0.3
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 +112 -73
- package/dist/components/index.cjs +1222 -982
- 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 +1191 -951
- package/dist/components/index.js.map +1 -1
- package/dist/core/index.cjs +229 -130
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +54 -45
- package/dist/core/index.d.ts +54 -45
- package/dist/core/index.js +225 -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 +1250 -1015
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -6
- package/dist/index.d.ts +9 -6
- package/dist/index.js +1214 -969
- 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,20 @@ 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
|
+
pol: "polygon",
|
|
111
|
+
avax: "avalanche",
|
|
112
|
+
doge: "dogecoin",
|
|
113
|
+
ltc: "litecoin",
|
|
114
|
+
bch: "bitcoinCash",
|
|
115
|
+
bera: "berachain",
|
|
116
|
+
zec: "zcash"
|
|
117
|
+
};
|
|
98
118
|
var suiSUI = createToken("sui", "SUI", "nep141:sui.omft.near", 9);
|
|
99
119
|
var suiUSDC = createToken("sui", "USDC", "nep141:sui-c1b81ecaf27933252d31a963bc5e9458f13c18ce.omft.near", 6, "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC");
|
|
100
120
|
var ethereumETH = createToken("eth", "ETH", "nep141:eth.omft.near", 18);
|
|
@@ -116,7 +136,7 @@ var arbitrumARB = createToken("arb", "ARB", "nep141:arb-0x912ce59144191c1204e645
|
|
|
116
136
|
var arbitrumGMX = createToken("arb", "GMX", "nep141:arb-0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a.omft.near", 18, "0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a");
|
|
117
137
|
var baseETH = createToken("base", "ETH", "nep141:base.omft.near", 18);
|
|
118
138
|
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");
|
|
139
|
+
var baseCbBTC = createToken("base", "cbBTC", "nep141:base-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near", 8, "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf", { name: "baseCbBTC" });
|
|
120
140
|
var baseBRETT = createToken("base", "BRETT", "nep141:base-0x532f27101965dd16442e59d40670faf5ebb142e4.omft.near", 18, "0x532f27101965dd16442e59d40670faf5ebb142e4");
|
|
121
141
|
var optimismETH = createToken("op", "ETH", "nep245:v2_1.omni.hot.tg:10_11111111111111111111", 18);
|
|
122
142
|
var optimismUSDC = createToken("op", "USDC", "nep245:v2_1.omni.hot.tg:10_A2ewyUyDp6qsue1jqZsGypkCxRJ", 6, "0x0b2c639c533813f4aa9d7837caf62653d097ff85");
|
|
@@ -151,7 +171,10 @@ var aptosAPT = createToken("aptos", "APT", "nep141:aptos.omft.near", 8);
|
|
|
151
171
|
var starknetSTRK = createToken("starknet", "STRK", "nep141:starknet.omft.near", 18);
|
|
152
172
|
var berachainBERA = createToken("bera", "BERA", "nep141:bera.omft.near", 18);
|
|
153
173
|
var zcashZEC = createToken("zec", "ZEC", "nep141:zec.omft.near", 8);
|
|
154
|
-
var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near"
|
|
174
|
+
var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near", {
|
|
175
|
+
name: "nearNEAR",
|
|
176
|
+
aliases: ["nearwNEAR"]
|
|
177
|
+
});
|
|
155
178
|
var nearUSDC = createToken("near", "USDC", "nep141:17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1", 6, "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1");
|
|
156
179
|
var nearUSDT = createToken("near", "USDT", "nep141:usdt.tether-token.near", 6, "usdt.tether-token.near");
|
|
157
180
|
var CHAINS = {
|
|
@@ -308,7 +331,9 @@ var CHAINS = {
|
|
|
308
331
|
};
|
|
309
332
|
var ALL_TOKENS = Object.values(CHAINS).flatMap((chain) => chain.tokens);
|
|
310
333
|
function getToken(name) {
|
|
311
|
-
return ALL_TOKENS.find(
|
|
334
|
+
return ALL_TOKENS.find(
|
|
335
|
+
(token) => token.name === name || token.aliases?.includes(name)
|
|
336
|
+
);
|
|
312
337
|
}
|
|
313
338
|
function getTokensByChain(chainId) {
|
|
314
339
|
return CHAINS[chainId]?.tokens || [];
|
|
@@ -319,31 +344,89 @@ function getTokenByAssetId(assetId) {
|
|
|
319
344
|
function getSupportedChains() {
|
|
320
345
|
return Object.values(CHAINS).filter((c) => c.tokens.length > 0);
|
|
321
346
|
}
|
|
322
|
-
|
|
323
|
-
|
|
347
|
+
|
|
348
|
+
// src/core/config.ts
|
|
349
|
+
var DEFAULT_HOSTED_BACKEND_URL = "https://uniport-backend-production.up.railway.app";
|
|
350
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 2e4;
|
|
351
|
+
var configuredBackendUrl;
|
|
352
|
+
var configuredRequestTimeoutMs;
|
|
353
|
+
function normalizeBackendUrl(url) {
|
|
354
|
+
return url.replace(/\/+$/, "");
|
|
324
355
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
if (!config.apiKey) {
|
|
329
|
-
throw new Error("Uniport SDK Error: apiKey is required. Pass your NEAR API key to initUniport().");
|
|
356
|
+
function configureUniport(config) {
|
|
357
|
+
if (config.backendUrl !== void 0) {
|
|
358
|
+
configuredBackendUrl = config.backendUrl ? normalizeBackendUrl(config.backendUrl) : void 0;
|
|
330
359
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
function getConfig() {
|
|
335
|
-
if (!_config) {
|
|
336
|
-
throw new Error(
|
|
337
|
-
"Uniport SDK not initialized. Call initUniport() first."
|
|
338
|
-
);
|
|
360
|
+
if (config.requestTimeoutMs !== void 0) {
|
|
361
|
+
configuredRequestTimeoutMs = config.requestTimeoutMs > 0 ? config.requestTimeoutMs : DEFAULT_REQUEST_TIMEOUT_MS;
|
|
339
362
|
}
|
|
340
|
-
return _config;
|
|
341
363
|
}
|
|
342
|
-
function
|
|
343
|
-
|
|
364
|
+
function getUniportConfig() {
|
|
365
|
+
const backendUrl = configuredBackendUrl || DEFAULT_HOSTED_BACKEND_URL;
|
|
366
|
+
return {
|
|
367
|
+
backendUrl: normalizeBackendUrl(backendUrl),
|
|
368
|
+
requestTimeoutMs: configuredRequestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS
|
|
369
|
+
};
|
|
344
370
|
}
|
|
345
371
|
|
|
346
372
|
// src/core/intents.ts
|
|
373
|
+
var UniportError = class extends Error {
|
|
374
|
+
constructor(params) {
|
|
375
|
+
super(params.message);
|
|
376
|
+
this.name = "UniportError";
|
|
377
|
+
this.code = params.code;
|
|
378
|
+
this.details = params.details;
|
|
379
|
+
this.status = params.status;
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
function isAbortError(error) {
|
|
383
|
+
return error instanceof Error && error.name === "AbortError";
|
|
384
|
+
}
|
|
385
|
+
function extractDetailMessage(details) {
|
|
386
|
+
if (typeof details === "string" && details.trim()) {
|
|
387
|
+
return details;
|
|
388
|
+
}
|
|
389
|
+
if (Array.isArray(details)) {
|
|
390
|
+
const firstString = details.find(
|
|
391
|
+
(detail) => typeof detail === "string" && detail.trim().length > 0
|
|
392
|
+
);
|
|
393
|
+
return firstString;
|
|
394
|
+
}
|
|
395
|
+
if (typeof details === "object" && details !== null && "message" in details && typeof details.message === "string") {
|
|
396
|
+
const message = details.message.trim();
|
|
397
|
+
return message || void 0;
|
|
398
|
+
}
|
|
399
|
+
return void 0;
|
|
400
|
+
}
|
|
401
|
+
function toUniportError(body, fallback) {
|
|
402
|
+
const detailMessage = extractDetailMessage(body.details);
|
|
403
|
+
return new UniportError({
|
|
404
|
+
code: body.code || fallback.code,
|
|
405
|
+
message: detailMessage || body.message || fallback.message,
|
|
406
|
+
details: body.details,
|
|
407
|
+
status: fallback.status
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
function createTimeoutSignal(timeoutMs, externalSignal) {
|
|
411
|
+
const controller = new AbortController();
|
|
412
|
+
let timedOut = false;
|
|
413
|
+
const timeoutId = setTimeout(() => {
|
|
414
|
+
timedOut = true;
|
|
415
|
+
controller.abort();
|
|
416
|
+
}, timeoutMs);
|
|
417
|
+
const abortFromExternal = () => controller.abort();
|
|
418
|
+
externalSignal?.addEventListener("abort", abortFromExternal, {
|
|
419
|
+
once: true
|
|
420
|
+
});
|
|
421
|
+
return {
|
|
422
|
+
signal: controller.signal,
|
|
423
|
+
didTimeout: () => timedOut,
|
|
424
|
+
cleanup: () => {
|
|
425
|
+
clearTimeout(timeoutId);
|
|
426
|
+
externalSignal?.removeEventListener("abort", abortFromExternal);
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
}
|
|
347
430
|
function toSmallestUnits(amount, decimals) {
|
|
348
431
|
const [whole, fraction = ""] = amount.split(".");
|
|
349
432
|
const paddedFraction = fraction.padEnd(decimals, "0").slice(0, decimals);
|
|
@@ -359,16 +442,7 @@ function generateDeadline(hoursFromNow = 1) {
|
|
|
359
442
|
const deadline = new Date(Date.now() + hoursFromNow * 60 * 60 * 1e3);
|
|
360
443
|
return deadline.toISOString();
|
|
361
444
|
}
|
|
362
|
-
function ensureInitialized() {
|
|
363
|
-
if (!isInitialized()) {
|
|
364
|
-
throw new Error(
|
|
365
|
-
"Uniport SDK not initialized. Call initUniport() first."
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
445
|
async function getQuote(options) {
|
|
370
|
-
ensureInitialized();
|
|
371
|
-
const config = getConfig();
|
|
372
446
|
const {
|
|
373
447
|
originToken,
|
|
374
448
|
destinationToken,
|
|
@@ -380,97 +454,133 @@ async function getQuote(options) {
|
|
|
380
454
|
swapType = "EXACT_INPUT",
|
|
381
455
|
deadline,
|
|
382
456
|
dry = false,
|
|
383
|
-
referral =
|
|
457
|
+
referral = "uniport",
|
|
458
|
+
signal
|
|
384
459
|
} = options;
|
|
385
460
|
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
|
-
};
|
|
461
|
+
const { backendUrl, requestTimeoutMs } = getUniportConfig();
|
|
462
|
+
const { signal: requestSignal, cleanup, didTimeout } = createTimeoutSignal(
|
|
463
|
+
requestTimeoutMs,
|
|
464
|
+
signal
|
|
465
|
+
);
|
|
466
|
+
let response;
|
|
401
467
|
try {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
468
|
+
response = await fetch(`${backendUrl}/api/quote`, {
|
|
469
|
+
method: "POST",
|
|
470
|
+
headers: { "Content-Type": "application/json" },
|
|
471
|
+
signal: requestSignal,
|
|
472
|
+
body: JSON.stringify({
|
|
473
|
+
dry,
|
|
474
|
+
swapType,
|
|
475
|
+
slippageTolerance,
|
|
476
|
+
originAsset: originToken.assetId,
|
|
477
|
+
destinationAsset: destinationToken.assetId,
|
|
478
|
+
amount: amountInSmallestUnits,
|
|
479
|
+
refundTo,
|
|
480
|
+
recipient,
|
|
481
|
+
deadline: deadline?.toISOString() || generateDeadline(1),
|
|
482
|
+
referral
|
|
483
|
+
})
|
|
484
|
+
});
|
|
415
485
|
} catch (error) {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
486
|
+
cleanup();
|
|
487
|
+
if (isAbortError(error)) {
|
|
488
|
+
if (signal?.aborted && !didTimeout()) {
|
|
489
|
+
throw error;
|
|
490
|
+
}
|
|
491
|
+
throw new UniportError({
|
|
492
|
+
code: "REQUEST_TIMEOUT",
|
|
493
|
+
message: "Quote request timed out"
|
|
494
|
+
});
|
|
420
495
|
}
|
|
421
496
|
throw error;
|
|
422
497
|
}
|
|
498
|
+
cleanup();
|
|
499
|
+
if (!response.ok) {
|
|
500
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
501
|
+
throw toUniportError(errorBody, {
|
|
502
|
+
code: "QUOTE_FAILED",
|
|
503
|
+
message: "Quote failed.",
|
|
504
|
+
status: response.status
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
const data = await response.json();
|
|
508
|
+
const quote = data.quote;
|
|
509
|
+
return {
|
|
510
|
+
depositAddress: quote.depositAddress || "",
|
|
511
|
+
memo: quote.depositMemo,
|
|
512
|
+
amountIn: quote.amountIn,
|
|
513
|
+
amountOut: quote.amountOut,
|
|
514
|
+
amountOutFormatted: quote.amountOutFormatted,
|
|
515
|
+
amountOutUsd: quote.amountOutUsd,
|
|
516
|
+
deadline: quote.deadline,
|
|
517
|
+
timeWhenInactive: quote.timeWhenInactive,
|
|
518
|
+
correlationId: data.correlationId
|
|
519
|
+
};
|
|
423
520
|
}
|
|
424
521
|
async function submitDepositTx(params) {
|
|
425
|
-
|
|
426
|
-
const {
|
|
522
|
+
const { backendUrl, requestTimeoutMs } = getUniportConfig();
|
|
523
|
+
const { signal, cleanup } = createTimeoutSignal(requestTimeoutMs);
|
|
524
|
+
let response;
|
|
427
525
|
try {
|
|
428
|
-
await
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
526
|
+
response = await fetch(`${backendUrl}/api/deposit`, {
|
|
527
|
+
method: "POST",
|
|
528
|
+
headers: { "Content-Type": "application/json" },
|
|
529
|
+
signal,
|
|
530
|
+
body: JSON.stringify(params)
|
|
433
531
|
});
|
|
434
532
|
} catch (error) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
533
|
+
cleanup();
|
|
534
|
+
if (isAbortError(error)) {
|
|
535
|
+
throw new UniportError({
|
|
536
|
+
code: "REQUEST_TIMEOUT",
|
|
537
|
+
message: "Deposit submission timed out"
|
|
538
|
+
});
|
|
439
539
|
}
|
|
440
540
|
throw error;
|
|
441
541
|
}
|
|
542
|
+
cleanup();
|
|
543
|
+
if (!response.ok) {
|
|
544
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
545
|
+
throw toUniportError(errorBody, {
|
|
546
|
+
code: "DEPOSIT_SUBMISSION_FAILED",
|
|
547
|
+
message: "Submit deposit failed.",
|
|
548
|
+
status: response.status
|
|
549
|
+
});
|
|
550
|
+
}
|
|
442
551
|
}
|
|
443
552
|
async function getExecutionStatus(depositAddress, memo) {
|
|
444
|
-
|
|
553
|
+
const { backendUrl, requestTimeoutMs } = getUniportConfig();
|
|
554
|
+
const url = new URL(
|
|
555
|
+
`${backendUrl}/api/status/${encodeURIComponent(depositAddress)}`
|
|
556
|
+
);
|
|
557
|
+
if (memo) {
|
|
558
|
+
url.searchParams.set("memo", memo);
|
|
559
|
+
}
|
|
560
|
+
const { signal, cleanup } = createTimeoutSignal(requestTimeoutMs);
|
|
561
|
+
let response;
|
|
445
562
|
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
|
-
};
|
|
563
|
+
response = await fetch(url.toString(), { signal });
|
|
466
564
|
} catch (error) {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
565
|
+
cleanup();
|
|
566
|
+
if (isAbortError(error)) {
|
|
567
|
+
throw new UniportError({
|
|
568
|
+
code: "REQUEST_TIMEOUT",
|
|
569
|
+
message: "Status check timed out"
|
|
570
|
+
});
|
|
471
571
|
}
|
|
472
572
|
throw error;
|
|
473
573
|
}
|
|
574
|
+
cleanup();
|
|
575
|
+
if (!response.ok) {
|
|
576
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
577
|
+
throw toUniportError(errorBody, {
|
|
578
|
+
code: "STATUS_CHECK_FAILED",
|
|
579
|
+
message: "Status check failed.",
|
|
580
|
+
status: response.status
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
return await response.json();
|
|
474
584
|
}
|
|
475
585
|
async function pollExecutionStatus(depositAddress, options) {
|
|
476
586
|
const {
|
|
@@ -495,22 +605,13 @@ async function pollExecutionStatus(depositAddress, options) {
|
|
|
495
605
|
throw new Error(`Timeout waiting for swap completion after ${timeout}ms`);
|
|
496
606
|
}
|
|
497
607
|
|
|
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
608
|
exports.ALL_TOKENS = ALL_TOKENS;
|
|
511
609
|
exports.CHAINS = CHAINS;
|
|
512
610
|
exports.CHAIN_ICONS = CHAIN_ICONS;
|
|
611
|
+
exports.DEFAULT_HOSTED_BACKEND_URL = DEFAULT_HOSTED_BACKEND_URL;
|
|
612
|
+
exports.DEFAULT_REQUEST_TIMEOUT_MS = DEFAULT_REQUEST_TIMEOUT_MS;
|
|
513
613
|
exports.TOKEN_ICONS = TOKEN_ICONS;
|
|
614
|
+
exports.UniportError = UniportError;
|
|
514
615
|
exports.aptosAPT = aptosAPT;
|
|
515
616
|
exports.arbitrumARB = arbitrumARB;
|
|
516
617
|
exports.arbitrumETH = arbitrumETH;
|
|
@@ -531,6 +632,7 @@ exports.bscBNB = bscBNB;
|
|
|
531
632
|
exports.bscUSDC = bscUSDC;
|
|
532
633
|
exports.bscUSDT = bscUSDT;
|
|
533
634
|
exports.cardanoADA = cardanoADA;
|
|
635
|
+
exports.configureUniport = configureUniport;
|
|
534
636
|
exports.dogecoinDOGE = dogecoinDOGE;
|
|
535
637
|
exports.ethereumAAVE = ethereumAAVE;
|
|
536
638
|
exports.ethereumDAI = ethereumDAI;
|
|
@@ -546,16 +648,13 @@ exports.ethereumUSDT = ethereumUSDT;
|
|
|
546
648
|
exports.ethereumWBTC = ethereumWBTC;
|
|
547
649
|
exports.fromSmallestUnits = fromSmallestUnits;
|
|
548
650
|
exports.generateDeadline = generateDeadline;
|
|
549
|
-
exports.getConfig = getConfig;
|
|
550
651
|
exports.getExecutionStatus = getExecutionStatus;
|
|
551
652
|
exports.getQuote = getQuote;
|
|
552
|
-
exports.getSuiDestinationTokens = getSuiDestinationTokens;
|
|
553
653
|
exports.getSupportedChains = getSupportedChains;
|
|
554
654
|
exports.getToken = getToken;
|
|
555
655
|
exports.getTokenByAssetId = getTokenByAssetId;
|
|
556
656
|
exports.getTokensByChain = getTokensByChain;
|
|
557
|
-
exports.
|
|
558
|
-
exports.isInitialized = isInitialized;
|
|
657
|
+
exports.getUniportConfig = getUniportConfig;
|
|
559
658
|
exports.litecoinLTC = litecoinLTC;
|
|
560
659
|
exports.nearNEAR = nearNEAR;
|
|
561
660
|
exports.nearUSDC = nearUSDC;
|