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.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
export { ApiError, OneClickService, OpenAPI } from '@defuse-protocol/one-click-sdk-typescript';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Uniport Token Definitions
|
|
5
3
|
*
|
|
6
4
|
* Importable token constants for the Uniport SDK.
|
|
7
|
-
* Usage: import { arbitrumUSDC, suiSUI, CHAINS } from 'uniport
|
|
5
|
+
* Usage: import { arbitrumUSDC, solanaSOL, suiSUI, CHAINS } from 'uniport-sdk'
|
|
8
6
|
*
|
|
9
7
|
* Token naming convention: {chain}{Symbol}
|
|
10
8
|
* Example: arbitrumUSDC, ethereumETH, suiSUI
|
|
@@ -12,7 +10,7 @@ export { ApiError, OneClickService, OpenAPI } from '@defuse-protocol/one-click-s
|
|
|
12
10
|
declare const TOKEN_ICONS: {
|
|
13
11
|
readonly USDC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png";
|
|
14
12
|
readonly USDT: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png";
|
|
15
|
-
readonly DAI: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/
|
|
13
|
+
readonly DAI: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6B175474E89094C44Da98b954EedeEC495271d0F/logo.png";
|
|
16
14
|
readonly ETH: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png";
|
|
17
15
|
readonly WETH: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png";
|
|
18
16
|
readonly BTC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/bitcoin/info/logo.png";
|
|
@@ -40,15 +38,15 @@ declare const TOKEN_ICONS: {
|
|
|
40
38
|
readonly LINK: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x514910771AF9Ca656af840dff83E8264EcF986CA/logo.png";
|
|
41
39
|
readonly SHIB: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE/logo.png";
|
|
42
40
|
readonly PEPE: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6982508145454Ce325dDbE47a25d4ec3d2311933/logo.png";
|
|
43
|
-
readonly STRK: "https://
|
|
44
|
-
readonly BERA: "https://
|
|
41
|
+
readonly STRK: "https://coin-images.coingecko.com/coins/images/26433/large/starknet.png";
|
|
42
|
+
readonly BERA: "https://s2.coinmarketcap.com/static/img/coins/64x64/31645.png";
|
|
45
43
|
readonly GNO: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6810e776880C02933D47DB1b9fc05908e5386b96/logo.png";
|
|
46
|
-
readonly MON: "https://
|
|
44
|
+
readonly MON: "https://s2.coinmarketcap.com/static/img/coins/64x64/33868.png";
|
|
47
45
|
readonly ZEC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zcash/info/logo.png";
|
|
48
|
-
readonly TRUMP: "https://
|
|
49
|
-
readonly WIF: "https://
|
|
50
|
-
readonly BRETT: "https://
|
|
51
|
-
readonly TURBO: "https://
|
|
46
|
+
readonly TRUMP: "https://s2.coinmarketcap.com/static/img/coins/64x64/35336.png";
|
|
47
|
+
readonly WIF: "https://s2.coinmarketcap.com/static/img/coins/64x64/28752.png";
|
|
48
|
+
readonly BRETT: "https://s2.coinmarketcap.com/static/img/coins/64x64/29743.png";
|
|
49
|
+
readonly TURBO: "https://s2.coinmarketcap.com/static/img/coins/64x64/24911.png";
|
|
52
50
|
readonly DEFAULT: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png";
|
|
53
51
|
};
|
|
54
52
|
declare const CHAIN_ICONS: {
|
|
@@ -69,9 +67,9 @@ declare const CHAIN_ICONS: {
|
|
|
69
67
|
readonly cardano: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/cardano/info/logo.png";
|
|
70
68
|
readonly aptos: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/aptos/info/logo.png";
|
|
71
69
|
readonly gnosis: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/xdai/info/logo.png";
|
|
72
|
-
readonly starknet: "https://
|
|
73
|
-
readonly bera: "https://
|
|
74
|
-
readonly monad: "https://
|
|
70
|
+
readonly starknet: "https://coin-images.coingecko.com/coins/images/26433/large/starknet.png";
|
|
71
|
+
readonly bera: "https://s2.coinmarketcap.com/static/img/coins/64x64/31645.png";
|
|
72
|
+
readonly monad: "https://s2.coinmarketcap.com/static/img/coins/64x64/33868.png";
|
|
75
73
|
readonly doge: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/doge/info/logo.png";
|
|
76
74
|
readonly ltc: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/litecoin/info/logo.png";
|
|
77
75
|
readonly bch: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/bitcoincash/info/logo.png";
|
|
@@ -82,6 +80,8 @@ type ChainId = keyof typeof CHAIN_ICONS;
|
|
|
82
80
|
interface Token {
|
|
83
81
|
/** Readable name: arbitrumUSDC, suiSUI */
|
|
84
82
|
name: string;
|
|
83
|
+
/** Backward-compatible identifiers accepted by the SDK */
|
|
84
|
+
aliases?: string[];
|
|
85
85
|
/** Display symbol: USDC, SUI, ETH */
|
|
86
86
|
symbol: string;
|
|
87
87
|
/** 1Click API asset ID */
|
|
@@ -172,17 +172,34 @@ declare function getTokensByChain(chainId: ChainId): Token[];
|
|
|
172
172
|
declare function getTokenByAssetId(assetId: string): Token | undefined;
|
|
173
173
|
/** Get all supported chains */
|
|
174
174
|
declare function getSupportedChains(): Chain[];
|
|
175
|
-
/** Get SUI destination tokens (for Uniport) */
|
|
176
|
-
declare function getSuiDestinationTokens(): Token[];
|
|
177
175
|
|
|
178
176
|
/**
|
|
179
177
|
* Uniport Intents Service
|
|
180
178
|
*
|
|
181
|
-
* Core functions for cross-chain swaps via
|
|
179
|
+
* Core functions for cross-chain swaps via the Uniport backend.
|
|
180
|
+
* All 1Click SDK logic lives server-side — the SDK just fetches.
|
|
182
181
|
*/
|
|
183
182
|
|
|
184
183
|
/** Swap type options */
|
|
185
184
|
type SwapType = 'EXACT_INPUT' | 'EXACT_OUTPUT' | 'FLEX_INPUT' | 'ANY_INPUT';
|
|
185
|
+
/** Stable backend error codes returned by Uniport */
|
|
186
|
+
type UniportErrorCode = 'VALIDATION_ERROR' | 'QUOTE_FAILED' | 'DEPOSIT_SUBMISSION_FAILED' | 'STATUS_CHECK_FAILED' | 'INTERNAL_ERROR' | 'REQUEST_TIMEOUT' | 'NETWORK_ERROR' | 'UNKNOWN_ERROR';
|
|
187
|
+
interface UniportApiErrorBody {
|
|
188
|
+
code?: UniportErrorCode;
|
|
189
|
+
message?: string;
|
|
190
|
+
details?: unknown;
|
|
191
|
+
}
|
|
192
|
+
declare class UniportError extends Error {
|
|
193
|
+
code: UniportErrorCode;
|
|
194
|
+
details?: unknown;
|
|
195
|
+
status?: number;
|
|
196
|
+
constructor(params: {
|
|
197
|
+
code: UniportErrorCode;
|
|
198
|
+
message: string;
|
|
199
|
+
details?: unknown;
|
|
200
|
+
status?: number;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
186
203
|
/** Quote request options */
|
|
187
204
|
interface QuoteOptions {
|
|
188
205
|
/** Origin token (source chain) */
|
|
@@ -205,6 +222,8 @@ interface QuoteOptions {
|
|
|
205
222
|
dry?: boolean;
|
|
206
223
|
/** Referral identifier for tracking */
|
|
207
224
|
referral?: string;
|
|
225
|
+
/** Abort signal for cancellation */
|
|
226
|
+
signal?: AbortSignal;
|
|
208
227
|
}
|
|
209
228
|
/** Quote result with deposit info */
|
|
210
229
|
interface QuoteResult {
|
|
@@ -285,35 +304,25 @@ declare function pollExecutionStatus(depositAddress: string, options?: {
|
|
|
285
304
|
|
|
286
305
|
/**
|
|
287
306
|
* Uniport SDK Configuration
|
|
307
|
+
*
|
|
308
|
+
* The SDK uses Uniport's hosted backend by default. No frontend API key or
|
|
309
|
+
* application-provided backend URL is required.
|
|
288
310
|
*/
|
|
289
311
|
interface UniportConfig {
|
|
290
|
-
/**
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
|
|
294
|
-
/** Default referral ID */
|
|
295
|
-
referral?: string;
|
|
312
|
+
/** Internal backend override. Standard integrations should not set this. */
|
|
313
|
+
backendUrl?: string;
|
|
314
|
+
/** Request timeout in milliseconds for backend calls. */
|
|
315
|
+
requestTimeoutMs?: number;
|
|
296
316
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
* ```
|
|
308
|
-
*/
|
|
309
|
-
declare function initUniport(config: UniportConfig): void;
|
|
310
|
-
/**
|
|
311
|
-
* Get the current SDK configuration
|
|
312
|
-
*/
|
|
313
|
-
declare function getConfig(): UniportConfig;
|
|
314
|
-
/**
|
|
315
|
-
* Check if SDK is initialized
|
|
316
|
-
*/
|
|
317
|
-
declare function isInitialized(): boolean;
|
|
317
|
+
interface ResolvedUniportConfig {
|
|
318
|
+
backendUrl: string;
|
|
319
|
+
requestTimeoutMs: number;
|
|
320
|
+
}
|
|
321
|
+
/** Default hosted backend URL */
|
|
322
|
+
declare const DEFAULT_HOSTED_BACKEND_URL = "https://uniport-backend-production.up.railway.app";
|
|
323
|
+
/** Default timeout for backend requests */
|
|
324
|
+
declare const DEFAULT_REQUEST_TIMEOUT_MS = 20000;
|
|
325
|
+
declare function configureUniport(config: UniportConfig): void;
|
|
326
|
+
declare function getUniportConfig(): ResolvedUniportConfig;
|
|
318
327
|
|
|
319
|
-
export { ALL_TOKENS, CHAINS, CHAIN_ICONS, type Chain, type ChainId, type ExecutionStatus, type QuoteOptions, type QuoteResult, type StatusResult, type SwapType, TOKEN_ICONS, type Token, type UniportConfig, aptosAPT, arbitrumARB, arbitrumETH, arbitrumGMX, arbitrumUSDC, arbitrumUSDT, avalancheAVAX, avalancheUSDC, avalancheUSDT, baseBRETT, baseCbBTC, baseETH, baseUSDC, berachainBERA, bitcoinBTC, bitcoinCashBCH, bscBNB, bscUSDC, bscUSDT, cardanoADA, dogecoinDOGE, ethereumAAVE, ethereumDAI, ethereumETH, ethereumLINK, ethereumPEPE, ethereumSAFE, ethereumSHIB, ethereumTURBO, ethereumUNI, ethereumUSDC, ethereumUSDT, ethereumWBTC, fromSmallestUnits, generateDeadline,
|
|
328
|
+
export { ALL_TOKENS, CHAINS, CHAIN_ICONS, type Chain, type ChainId, DEFAULT_HOSTED_BACKEND_URL, DEFAULT_REQUEST_TIMEOUT_MS, type ExecutionStatus, type QuoteOptions, type QuoteResult, type ResolvedUniportConfig, type StatusResult, type SwapType, TOKEN_ICONS, type Token, type UniportApiErrorBody, type UniportConfig, UniportError, type UniportErrorCode, aptosAPT, arbitrumARB, arbitrumETH, arbitrumGMX, arbitrumUSDC, arbitrumUSDT, avalancheAVAX, avalancheUSDC, avalancheUSDT, baseBRETT, baseCbBTC, baseETH, baseUSDC, berachainBERA, bitcoinBTC, bitcoinCashBCH, bscBNB, bscUSDC, bscUSDT, cardanoADA, configureUniport, dogecoinDOGE, ethereumAAVE, ethereumDAI, ethereumETH, ethereumLINK, ethereumPEPE, ethereumSAFE, ethereumSHIB, ethereumTURBO, ethereumUNI, ethereumUSDC, ethereumUSDT, ethereumWBTC, fromSmallestUnits, generateDeadline, getExecutionStatus, getQuote, getSupportedChains, getToken, getTokenByAssetId, getTokensByChain, getUniportConfig, litecoinLTC, nearNEAR, nearUSDC, nearUSDT, optimismETH, optimismOP, optimismUSDC, optimismUSDT, pollExecutionStatus, polygonPOL, polygonUSDC, polygonUSDT, rippleXRP, solanaMELANIA, solanaSOL, solanaTRUMP, solanaUSDC, solanaUSDT, solanaWIF, starknetSTRK, submitDepositTx, suiSUI, suiUSDC, toSmallestUnits, tonTON, tonUSDT, tronTRX, tronUSDT, zcashZEC };
|
package/dist/core/index.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { OpenAPI, QuoteRequest, OneClickService, ApiError } from '@defuse-protocol/one-click-sdk-typescript';
|
|
2
|
-
export { ApiError, OneClickService, OpenAPI } from '@defuse-protocol/one-click-sdk-typescript';
|
|
3
|
-
|
|
4
1
|
// src/core/tokens.ts
|
|
5
2
|
var TOKEN_ICONS = {
|
|
6
3
|
// Stablecoins
|
|
7
4
|
USDC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
8
5
|
USDT: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png",
|
|
9
|
-
DAI: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/
|
|
6
|
+
DAI: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6B175474E89094C44Da98b954EedeEC495271d0F/logo.png",
|
|
10
7
|
// Major tokens
|
|
11
8
|
ETH: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png",
|
|
12
9
|
WETH: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png",
|
|
@@ -39,16 +36,16 @@ var TOKEN_ICONS = {
|
|
|
39
36
|
SHIB: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE/logo.png",
|
|
40
37
|
PEPE: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6982508145454Ce325dDbE47a25d4ec3d2311933/logo.png",
|
|
41
38
|
// Ecosystem tokens
|
|
42
|
-
STRK: "https://
|
|
43
|
-
BERA: "https://
|
|
39
|
+
STRK: "https://coin-images.coingecko.com/coins/images/26433/large/starknet.png",
|
|
40
|
+
BERA: "https://s2.coinmarketcap.com/static/img/coins/64x64/31645.png",
|
|
44
41
|
GNO: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6810e776880C02933D47DB1b9fc05908e5386b96/logo.png",
|
|
45
|
-
MON: "https://
|
|
42
|
+
MON: "https://s2.coinmarketcap.com/static/img/coins/64x64/33868.png",
|
|
46
43
|
ZEC: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zcash/info/logo.png",
|
|
47
44
|
// Meme coins
|
|
48
|
-
TRUMP: "https://
|
|
49
|
-
WIF: "https://
|
|
50
|
-
BRETT: "https://
|
|
51
|
-
TURBO: "https://
|
|
45
|
+
TRUMP: "https://s2.coinmarketcap.com/static/img/coins/64x64/35336.png",
|
|
46
|
+
WIF: "https://s2.coinmarketcap.com/static/img/coins/64x64/28752.png",
|
|
47
|
+
BRETT: "https://s2.coinmarketcap.com/static/img/coins/64x64/29743.png",
|
|
48
|
+
TURBO: "https://s2.coinmarketcap.com/static/img/coins/64x64/24911.png",
|
|
52
49
|
// Default fallback
|
|
53
50
|
DEFAULT: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/info/logo.png"
|
|
54
51
|
};
|
|
@@ -70,21 +67,29 @@ var CHAIN_ICONS = {
|
|
|
70
67
|
cardano: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/cardano/info/logo.png",
|
|
71
68
|
aptos: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/aptos/info/logo.png",
|
|
72
69
|
gnosis: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/xdai/info/logo.png",
|
|
73
|
-
starknet: "https://
|
|
74
|
-
bera: "https://
|
|
75
|
-
monad: "https://
|
|
70
|
+
starknet: "https://coin-images.coingecko.com/coins/images/26433/large/starknet.png",
|
|
71
|
+
bera: "https://s2.coinmarketcap.com/static/img/coins/64x64/31645.png",
|
|
72
|
+
monad: "https://s2.coinmarketcap.com/static/img/coins/64x64/33868.png",
|
|
76
73
|
doge: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/doge/info/logo.png",
|
|
77
74
|
ltc: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/litecoin/info/logo.png",
|
|
78
75
|
bch: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/bitcoincash/info/logo.png",
|
|
79
76
|
xrp: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ripple/info/logo.png",
|
|
80
77
|
zec: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zcash/info/logo.png"
|
|
81
78
|
};
|
|
82
|
-
function createToken(chain, symbol, assetId, decimals, contractAddress) {
|
|
83
|
-
const
|
|
79
|
+
function createToken(chain, symbol, assetId, decimals, contractAddress, options) {
|
|
80
|
+
const normalizedSymbol = symbol.replace("$", "").replace(" ", "");
|
|
81
|
+
const canonicalPrefix = TOKEN_NAME_PREFIXES[chain] || chain;
|
|
82
|
+
const legacyName = `${chain}${normalizedSymbol}`;
|
|
83
|
+
const name = options?.name || `${canonicalPrefix}${normalizedSymbol}`;
|
|
84
84
|
const icon = TOKEN_ICONS[symbol] || TOKEN_ICONS.DEFAULT;
|
|
85
85
|
const chainIcon = CHAIN_ICONS[chain];
|
|
86
|
+
const aliases = new Set(options?.aliases || []);
|
|
87
|
+
if (legacyName !== name) {
|
|
88
|
+
aliases.add(legacyName);
|
|
89
|
+
}
|
|
86
90
|
return {
|
|
87
91
|
name,
|
|
92
|
+
aliases: aliases.size > 0 ? Array.from(aliases) : void 0,
|
|
88
93
|
symbol,
|
|
89
94
|
assetId,
|
|
90
95
|
chain,
|
|
@@ -94,6 +99,20 @@ function createToken(chain, symbol, assetId, decimals, contractAddress) {
|
|
|
94
99
|
contractAddress
|
|
95
100
|
};
|
|
96
101
|
}
|
|
102
|
+
var TOKEN_NAME_PREFIXES = {
|
|
103
|
+
eth: "ethereum",
|
|
104
|
+
arb: "arbitrum",
|
|
105
|
+
op: "optimism",
|
|
106
|
+
sol: "solana",
|
|
107
|
+
btc: "bitcoin",
|
|
108
|
+
pol: "polygon",
|
|
109
|
+
avax: "avalanche",
|
|
110
|
+
doge: "dogecoin",
|
|
111
|
+
ltc: "litecoin",
|
|
112
|
+
bch: "bitcoinCash",
|
|
113
|
+
bera: "berachain",
|
|
114
|
+
zec: "zcash"
|
|
115
|
+
};
|
|
97
116
|
var suiSUI = createToken("sui", "SUI", "nep141:sui.omft.near", 9);
|
|
98
117
|
var suiUSDC = createToken("sui", "USDC", "nep141:sui-c1b81ecaf27933252d31a963bc5e9458f13c18ce.omft.near", 6, "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC");
|
|
99
118
|
var ethereumETH = createToken("eth", "ETH", "nep141:eth.omft.near", 18);
|
|
@@ -115,7 +134,7 @@ var arbitrumARB = createToken("arb", "ARB", "nep141:arb-0x912ce59144191c1204e645
|
|
|
115
134
|
var arbitrumGMX = createToken("arb", "GMX", "nep141:arb-0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a.omft.near", 18, "0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a");
|
|
116
135
|
var baseETH = createToken("base", "ETH", "nep141:base.omft.near", 18);
|
|
117
136
|
var baseUSDC = createToken("base", "USDC", "nep141:base-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913.omft.near", 6, "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913");
|
|
118
|
-
var baseCbBTC = createToken("base", "cbBTC", "nep141:base-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near", 8, "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf");
|
|
137
|
+
var baseCbBTC = createToken("base", "cbBTC", "nep141:base-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near", 8, "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf", { name: "baseCbBTC" });
|
|
119
138
|
var baseBRETT = createToken("base", "BRETT", "nep141:base-0x532f27101965dd16442e59d40670faf5ebb142e4.omft.near", 18, "0x532f27101965dd16442e59d40670faf5ebb142e4");
|
|
120
139
|
var optimismETH = createToken("op", "ETH", "nep245:v2_1.omni.hot.tg:10_11111111111111111111", 18);
|
|
121
140
|
var optimismUSDC = createToken("op", "USDC", "nep245:v2_1.omni.hot.tg:10_A2ewyUyDp6qsue1jqZsGypkCxRJ", 6, "0x0b2c639c533813f4aa9d7837caf62653d097ff85");
|
|
@@ -150,7 +169,10 @@ var aptosAPT = createToken("aptos", "APT", "nep141:aptos.omft.near", 8);
|
|
|
150
169
|
var starknetSTRK = createToken("starknet", "STRK", "nep141:starknet.omft.near", 18);
|
|
151
170
|
var berachainBERA = createToken("bera", "BERA", "nep141:bera.omft.near", 18);
|
|
152
171
|
var zcashZEC = createToken("zec", "ZEC", "nep141:zec.omft.near", 8);
|
|
153
|
-
var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near"
|
|
172
|
+
var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near", {
|
|
173
|
+
name: "nearNEAR",
|
|
174
|
+
aliases: ["nearwNEAR"]
|
|
175
|
+
});
|
|
154
176
|
var nearUSDC = createToken("near", "USDC", "nep141:17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1", 6, "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1");
|
|
155
177
|
var nearUSDT = createToken("near", "USDT", "nep141:usdt.tether-token.near", 6, "usdt.tether-token.near");
|
|
156
178
|
var CHAINS = {
|
|
@@ -307,7 +329,9 @@ var CHAINS = {
|
|
|
307
329
|
};
|
|
308
330
|
var ALL_TOKENS = Object.values(CHAINS).flatMap((chain) => chain.tokens);
|
|
309
331
|
function getToken(name) {
|
|
310
|
-
return ALL_TOKENS.find(
|
|
332
|
+
return ALL_TOKENS.find(
|
|
333
|
+
(token) => token.name === name || token.aliases?.includes(name)
|
|
334
|
+
);
|
|
311
335
|
}
|
|
312
336
|
function getTokensByChain(chainId) {
|
|
313
337
|
return CHAINS[chainId]?.tokens || [];
|
|
@@ -318,31 +342,89 @@ function getTokenByAssetId(assetId) {
|
|
|
318
342
|
function getSupportedChains() {
|
|
319
343
|
return Object.values(CHAINS).filter((c) => c.tokens.length > 0);
|
|
320
344
|
}
|
|
321
|
-
|
|
322
|
-
|
|
345
|
+
|
|
346
|
+
// src/core/config.ts
|
|
347
|
+
var DEFAULT_HOSTED_BACKEND_URL = "https://uniport-backend-production.up.railway.app";
|
|
348
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 2e4;
|
|
349
|
+
var configuredBackendUrl;
|
|
350
|
+
var configuredRequestTimeoutMs;
|
|
351
|
+
function normalizeBackendUrl(url) {
|
|
352
|
+
return url.replace(/\/+$/, "");
|
|
323
353
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (!config.apiKey) {
|
|
328
|
-
throw new Error("Uniport SDK Error: apiKey is required. Pass your NEAR API key to initUniport().");
|
|
354
|
+
function configureUniport(config) {
|
|
355
|
+
if (config.backendUrl !== void 0) {
|
|
356
|
+
configuredBackendUrl = config.backendUrl ? normalizeBackendUrl(config.backendUrl) : void 0;
|
|
329
357
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}
|
|
333
|
-
function getConfig() {
|
|
334
|
-
if (!_config) {
|
|
335
|
-
throw new Error(
|
|
336
|
-
"Uniport SDK not initialized. Call initUniport() first."
|
|
337
|
-
);
|
|
358
|
+
if (config.requestTimeoutMs !== void 0) {
|
|
359
|
+
configuredRequestTimeoutMs = config.requestTimeoutMs > 0 ? config.requestTimeoutMs : DEFAULT_REQUEST_TIMEOUT_MS;
|
|
338
360
|
}
|
|
339
|
-
return _config;
|
|
340
361
|
}
|
|
341
|
-
function
|
|
342
|
-
|
|
362
|
+
function getUniportConfig() {
|
|
363
|
+
const backendUrl = configuredBackendUrl || DEFAULT_HOSTED_BACKEND_URL;
|
|
364
|
+
return {
|
|
365
|
+
backendUrl: normalizeBackendUrl(backendUrl),
|
|
366
|
+
requestTimeoutMs: configuredRequestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS
|
|
367
|
+
};
|
|
343
368
|
}
|
|
344
369
|
|
|
345
370
|
// src/core/intents.ts
|
|
371
|
+
var UniportError = class extends Error {
|
|
372
|
+
constructor(params) {
|
|
373
|
+
super(params.message);
|
|
374
|
+
this.name = "UniportError";
|
|
375
|
+
this.code = params.code;
|
|
376
|
+
this.details = params.details;
|
|
377
|
+
this.status = params.status;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
function isAbortError(error) {
|
|
381
|
+
return error instanceof Error && error.name === "AbortError";
|
|
382
|
+
}
|
|
383
|
+
function extractDetailMessage(details) {
|
|
384
|
+
if (typeof details === "string" && details.trim()) {
|
|
385
|
+
return details;
|
|
386
|
+
}
|
|
387
|
+
if (Array.isArray(details)) {
|
|
388
|
+
const firstString = details.find(
|
|
389
|
+
(detail) => typeof detail === "string" && detail.trim().length > 0
|
|
390
|
+
);
|
|
391
|
+
return firstString;
|
|
392
|
+
}
|
|
393
|
+
if (typeof details === "object" && details !== null && "message" in details && typeof details.message === "string") {
|
|
394
|
+
const message = details.message.trim();
|
|
395
|
+
return message || void 0;
|
|
396
|
+
}
|
|
397
|
+
return void 0;
|
|
398
|
+
}
|
|
399
|
+
function toUniportError(body, fallback) {
|
|
400
|
+
const detailMessage = extractDetailMessage(body.details);
|
|
401
|
+
return new UniportError({
|
|
402
|
+
code: body.code || fallback.code,
|
|
403
|
+
message: detailMessage || body.message || fallback.message,
|
|
404
|
+
details: body.details,
|
|
405
|
+
status: fallback.status
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
function createTimeoutSignal(timeoutMs, externalSignal) {
|
|
409
|
+
const controller = new AbortController();
|
|
410
|
+
let timedOut = false;
|
|
411
|
+
const timeoutId = setTimeout(() => {
|
|
412
|
+
timedOut = true;
|
|
413
|
+
controller.abort();
|
|
414
|
+
}, timeoutMs);
|
|
415
|
+
const abortFromExternal = () => controller.abort();
|
|
416
|
+
externalSignal?.addEventListener("abort", abortFromExternal, {
|
|
417
|
+
once: true
|
|
418
|
+
});
|
|
419
|
+
return {
|
|
420
|
+
signal: controller.signal,
|
|
421
|
+
didTimeout: () => timedOut,
|
|
422
|
+
cleanup: () => {
|
|
423
|
+
clearTimeout(timeoutId);
|
|
424
|
+
externalSignal?.removeEventListener("abort", abortFromExternal);
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
}
|
|
346
428
|
function toSmallestUnits(amount, decimals) {
|
|
347
429
|
const [whole, fraction = ""] = amount.split(".");
|
|
348
430
|
const paddedFraction = fraction.padEnd(decimals, "0").slice(0, decimals);
|
|
@@ -358,16 +440,7 @@ function generateDeadline(hoursFromNow = 1) {
|
|
|
358
440
|
const deadline = new Date(Date.now() + hoursFromNow * 60 * 60 * 1e3);
|
|
359
441
|
return deadline.toISOString();
|
|
360
442
|
}
|
|
361
|
-
function ensureInitialized() {
|
|
362
|
-
if (!isInitialized()) {
|
|
363
|
-
throw new Error(
|
|
364
|
-
"Uniport SDK not initialized. Call initUniport() first."
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
443
|
async function getQuote(options) {
|
|
369
|
-
ensureInitialized();
|
|
370
|
-
const config = getConfig();
|
|
371
444
|
const {
|
|
372
445
|
originToken,
|
|
373
446
|
destinationToken,
|
|
@@ -379,97 +452,133 @@ async function getQuote(options) {
|
|
|
379
452
|
swapType = "EXACT_INPUT",
|
|
380
453
|
deadline,
|
|
381
454
|
dry = false,
|
|
382
|
-
referral =
|
|
455
|
+
referral = "uniport",
|
|
456
|
+
signal
|
|
383
457
|
} = options;
|
|
384
458
|
const amountInSmallestUnits = toSmallestUnits(amount, originToken.decimals);
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
destinationAsset: destinationToken.assetId,
|
|
392
|
-
amount: amountInSmallestUnits,
|
|
393
|
-
refundTo,
|
|
394
|
-
refundType: QuoteRequest.refundType.ORIGIN_CHAIN,
|
|
395
|
-
recipient,
|
|
396
|
-
recipientType: QuoteRequest.recipientType.DESTINATION_CHAIN,
|
|
397
|
-
deadline: deadline?.toISOString() || generateDeadline(1),
|
|
398
|
-
referral
|
|
399
|
-
};
|
|
459
|
+
const { backendUrl, requestTimeoutMs } = getUniportConfig();
|
|
460
|
+
const { signal: requestSignal, cleanup, didTimeout } = createTimeoutSignal(
|
|
461
|
+
requestTimeoutMs,
|
|
462
|
+
signal
|
|
463
|
+
);
|
|
464
|
+
let response;
|
|
400
465
|
try {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
466
|
+
response = await fetch(`${backendUrl}/api/quote`, {
|
|
467
|
+
method: "POST",
|
|
468
|
+
headers: { "Content-Type": "application/json" },
|
|
469
|
+
signal: requestSignal,
|
|
470
|
+
body: JSON.stringify({
|
|
471
|
+
dry,
|
|
472
|
+
swapType,
|
|
473
|
+
slippageTolerance,
|
|
474
|
+
originAsset: originToken.assetId,
|
|
475
|
+
destinationAsset: destinationToken.assetId,
|
|
476
|
+
amount: amountInSmallestUnits,
|
|
477
|
+
refundTo,
|
|
478
|
+
recipient,
|
|
479
|
+
deadline: deadline?.toISOString() || generateDeadline(1),
|
|
480
|
+
referral
|
|
481
|
+
})
|
|
482
|
+
});
|
|
414
483
|
} catch (error) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
484
|
+
cleanup();
|
|
485
|
+
if (isAbortError(error)) {
|
|
486
|
+
if (signal?.aborted && !didTimeout()) {
|
|
487
|
+
throw error;
|
|
488
|
+
}
|
|
489
|
+
throw new UniportError({
|
|
490
|
+
code: "REQUEST_TIMEOUT",
|
|
491
|
+
message: "Quote request timed out"
|
|
492
|
+
});
|
|
419
493
|
}
|
|
420
494
|
throw error;
|
|
421
495
|
}
|
|
496
|
+
cleanup();
|
|
497
|
+
if (!response.ok) {
|
|
498
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
499
|
+
throw toUniportError(errorBody, {
|
|
500
|
+
code: "QUOTE_FAILED",
|
|
501
|
+
message: "Quote failed.",
|
|
502
|
+
status: response.status
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
const data = await response.json();
|
|
506
|
+
const quote = data.quote;
|
|
507
|
+
return {
|
|
508
|
+
depositAddress: quote.depositAddress || "",
|
|
509
|
+
memo: quote.depositMemo,
|
|
510
|
+
amountIn: quote.amountIn,
|
|
511
|
+
amountOut: quote.amountOut,
|
|
512
|
+
amountOutFormatted: quote.amountOutFormatted,
|
|
513
|
+
amountOutUsd: quote.amountOutUsd,
|
|
514
|
+
deadline: quote.deadline,
|
|
515
|
+
timeWhenInactive: quote.timeWhenInactive,
|
|
516
|
+
correlationId: data.correlationId
|
|
517
|
+
};
|
|
422
518
|
}
|
|
423
519
|
async function submitDepositTx(params) {
|
|
424
|
-
|
|
425
|
-
const {
|
|
520
|
+
const { backendUrl, requestTimeoutMs } = getUniportConfig();
|
|
521
|
+
const { signal, cleanup } = createTimeoutSignal(requestTimeoutMs);
|
|
522
|
+
let response;
|
|
426
523
|
try {
|
|
427
|
-
await
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
524
|
+
response = await fetch(`${backendUrl}/api/deposit`, {
|
|
525
|
+
method: "POST",
|
|
526
|
+
headers: { "Content-Type": "application/json" },
|
|
527
|
+
signal,
|
|
528
|
+
body: JSON.stringify(params)
|
|
432
529
|
});
|
|
433
530
|
} catch (error) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
531
|
+
cleanup();
|
|
532
|
+
if (isAbortError(error)) {
|
|
533
|
+
throw new UniportError({
|
|
534
|
+
code: "REQUEST_TIMEOUT",
|
|
535
|
+
message: "Deposit submission timed out"
|
|
536
|
+
});
|
|
438
537
|
}
|
|
439
538
|
throw error;
|
|
440
539
|
}
|
|
540
|
+
cleanup();
|
|
541
|
+
if (!response.ok) {
|
|
542
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
543
|
+
throw toUniportError(errorBody, {
|
|
544
|
+
code: "DEPOSIT_SUBMISSION_FAILED",
|
|
545
|
+
message: "Submit deposit failed.",
|
|
546
|
+
status: response.status
|
|
547
|
+
});
|
|
548
|
+
}
|
|
441
549
|
}
|
|
442
550
|
async function getExecutionStatus(depositAddress, memo) {
|
|
443
|
-
|
|
551
|
+
const { backendUrl, requestTimeoutMs } = getUniportConfig();
|
|
552
|
+
const url = new URL(
|
|
553
|
+
`${backendUrl}/api/status/${encodeURIComponent(depositAddress)}`
|
|
554
|
+
);
|
|
555
|
+
if (memo) {
|
|
556
|
+
url.searchParams.set("memo", memo);
|
|
557
|
+
}
|
|
558
|
+
const { signal, cleanup } = createTimeoutSignal(requestTimeoutMs);
|
|
559
|
+
let response;
|
|
444
560
|
try {
|
|
445
|
-
|
|
446
|
-
depositAddress,
|
|
447
|
-
memo
|
|
448
|
-
);
|
|
449
|
-
const status = response.status;
|
|
450
|
-
const isComplete = ["SUCCESS", "REFUNDED", "FAILED"].includes(status);
|
|
451
|
-
const isSuccess = status === "SUCCESS";
|
|
452
|
-
const swapDetails = response.swapDetails;
|
|
453
|
-
const destinationTxHashes = swapDetails?.destinationChainTxHashes?.map((tx) => tx.hash);
|
|
454
|
-
const originTxHashes = swapDetails?.originChainTxHashes?.map(
|
|
455
|
-
(tx) => tx.hash
|
|
456
|
-
);
|
|
457
|
-
return {
|
|
458
|
-
status,
|
|
459
|
-
isComplete,
|
|
460
|
-
isSuccess,
|
|
461
|
-
correlationId: response.correlationId,
|
|
462
|
-
destinationTxHashes,
|
|
463
|
-
originTxHashes
|
|
464
|
-
};
|
|
561
|
+
response = await fetch(url.toString(), { signal });
|
|
465
562
|
} catch (error) {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
563
|
+
cleanup();
|
|
564
|
+
if (isAbortError(error)) {
|
|
565
|
+
throw new UniportError({
|
|
566
|
+
code: "REQUEST_TIMEOUT",
|
|
567
|
+
message: "Status check timed out"
|
|
568
|
+
});
|
|
470
569
|
}
|
|
471
570
|
throw error;
|
|
472
571
|
}
|
|
572
|
+
cleanup();
|
|
573
|
+
if (!response.ok) {
|
|
574
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
575
|
+
throw toUniportError(errorBody, {
|
|
576
|
+
code: "STATUS_CHECK_FAILED",
|
|
577
|
+
message: "Status check failed.",
|
|
578
|
+
status: response.status
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
return await response.json();
|
|
473
582
|
}
|
|
474
583
|
async function pollExecutionStatus(depositAddress, options) {
|
|
475
584
|
const {
|
|
@@ -494,6 +603,6 @@ async function pollExecutionStatus(depositAddress, options) {
|
|
|
494
603
|
throw new Error(`Timeout waiting for swap completion after ${timeout}ms`);
|
|
495
604
|
}
|
|
496
605
|
|
|
497
|
-
export { ALL_TOKENS, CHAINS, CHAIN_ICONS, TOKEN_ICONS, aptosAPT, arbitrumARB, arbitrumETH, arbitrumGMX, arbitrumUSDC, arbitrumUSDT, avalancheAVAX, avalancheUSDC, avalancheUSDT, baseBRETT, baseCbBTC, baseETH, baseUSDC, berachainBERA, bitcoinBTC, bitcoinCashBCH, bscBNB, bscUSDC, bscUSDT, cardanoADA, dogecoinDOGE, ethereumAAVE, ethereumDAI, ethereumETH, ethereumLINK, ethereumPEPE, ethereumSAFE, ethereumSHIB, ethereumTURBO, ethereumUNI, ethereumUSDC, ethereumUSDT, ethereumWBTC, fromSmallestUnits, generateDeadline,
|
|
606
|
+
export { ALL_TOKENS, CHAINS, CHAIN_ICONS, DEFAULT_HOSTED_BACKEND_URL, DEFAULT_REQUEST_TIMEOUT_MS, TOKEN_ICONS, UniportError, aptosAPT, arbitrumARB, arbitrumETH, arbitrumGMX, arbitrumUSDC, arbitrumUSDT, avalancheAVAX, avalancheUSDC, avalancheUSDT, baseBRETT, baseCbBTC, baseETH, baseUSDC, berachainBERA, bitcoinBTC, bitcoinCashBCH, bscBNB, bscUSDC, bscUSDT, cardanoADA, configureUniport, dogecoinDOGE, ethereumAAVE, ethereumDAI, ethereumETH, ethereumLINK, ethereumPEPE, ethereumSAFE, ethereumSHIB, ethereumTURBO, ethereumUNI, ethereumUSDC, ethereumUSDT, ethereumWBTC, fromSmallestUnits, generateDeadline, getExecutionStatus, getQuote, getSupportedChains, getToken, getTokenByAssetId, getTokensByChain, getUniportConfig, litecoinLTC, nearNEAR, nearUSDC, nearUSDT, optimismETH, optimismOP, optimismUSDC, optimismUSDT, pollExecutionStatus, polygonPOL, polygonUSDC, polygonUSDT, rippleXRP, solanaMELANIA, solanaSOL, solanaTRUMP, solanaUSDC, solanaUSDT, solanaWIF, starknetSTRK, submitDepositTx, suiSUI, suiUSDC, toSmallestUnits, tonTON, tonUSDT, tronTRX, tronUSDT, zcashZEC };
|
|
498
607
|
//# sourceMappingURL=index.js.map
|
|
499
608
|
//# sourceMappingURL=index.js.map
|