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.
@@ -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/tokens'
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/0x6B175474E89094C44Da98b954EesdfdsfdC495271d0F/logo.png";
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://assets.coingecko.com/coins/images/26433/standard/starknet.png";
44
- readonly BERA: "https://assets.coingecko.com/coins/images/34286/standard/bera.png";
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://assets.coingecko.com/coins/images/35887/standard/monad.png";
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://assets.coingecko.com/coins/images/53746/standard/trump.jpg";
49
- readonly WIF: "https://assets.coingecko.com/coins/images/33566/standard/dogwifhat.jpg";
50
- readonly BRETT: "https://assets.coingecko.com/coins/images/35529/standard/brett.png";
51
- readonly TURBO: "https://assets.coingecko.com/coins/images/30116/standard/turbo.png";
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://assets.coingecko.com/coins/images/26433/standard/starknet.png";
73
- readonly bera: "https://assets.coingecko.com/coins/images/34286/standard/bera.png";
74
- readonly monad: "https://assets.coingecko.com/coins/images/35887/standard/monad.png";
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 1Click SDK
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,26 @@ 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. Advanced consumers can
309
+ * explicitly override the backend URL or request timeout for self-hosting,
310
+ * staging, or local development.
288
311
  */
289
312
  interface UniportConfig {
290
- /** NEAR API key for 1Click service */
291
- apiKey: string;
292
- /** API base URL (default: production) */
293
- baseUrl?: string;
294
- /** Default referral ID */
295
- referral?: string;
313
+ /** Optional backend override. If omitted, Uniport's hosted backend is used. */
314
+ backendUrl?: string;
315
+ /** Request timeout in milliseconds for backend calls. */
316
+ requestTimeoutMs?: number;
296
317
  }
297
- /**
298
- * Initialize the Uniport SDK
299
- *
300
- * @example
301
- * ```ts
302
- * import { initUniport } from 'uniport'
303
- *
304
- * initUniport({
305
- * apiKey: 'your-near-api-key',
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;
318
+ interface ResolvedUniportConfig {
319
+ backendUrl: string;
320
+ requestTimeoutMs: number;
321
+ }
322
+ /** Default hosted backend URL */
323
+ declare const DEFAULT_HOSTED_BACKEND_URL = "https://uniport-backend-production.up.railway.app";
324
+ /** Default timeout for backend requests */
325
+ declare const DEFAULT_REQUEST_TIMEOUT_MS = 20000;
326
+ declare function configureUniport(config: UniportConfig): void;
327
+ declare function getUniportConfig(): ResolvedUniportConfig;
318
328
 
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, getConfig, getExecutionStatus, getQuote, getSuiDestinationTokens, getSupportedChains, getToken, getTokenByAssetId, getTokensByChain, initUniport, isInitialized, 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 };
329
+ 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 };
@@ -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/0x6B175474E89094C44Da98b954EesdfdsfdC495271d0F/logo.png",
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://assets.coingecko.com/coins/images/26433/standard/starknet.png",
43
- BERA: "https://assets.coingecko.com/coins/images/34286/standard/bera.png",
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://assets.coingecko.com/coins/images/35887/standard/monad.png",
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://assets.coingecko.com/coins/images/53746/standard/trump.jpg",
49
- WIF: "https://assets.coingecko.com/coins/images/33566/standard/dogwifhat.jpg",
50
- BRETT: "https://assets.coingecko.com/coins/images/35529/standard/brett.png",
51
- TURBO: "https://assets.coingecko.com/coins/images/30116/standard/turbo.png",
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://assets.coingecko.com/coins/images/26433/standard/starknet.png",
74
- bera: "https://assets.coingecko.com/coins/images/34286/standard/bera.png",
75
- monad: "https://assets.coingecko.com/coins/images/35887/standard/monad.png",
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 name = `${chain}${symbol.replace("$", "").replace(" ", "")}`;
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,19 @@ 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
+ avax: "avalanche",
109
+ doge: "dogecoin",
110
+ ltc: "litecoin",
111
+ bch: "bitcoinCash",
112
+ bera: "berachain",
113
+ zec: "zcash"
114
+ };
97
115
  var suiSUI = createToken("sui", "SUI", "nep141:sui.omft.near", 9);
98
116
  var suiUSDC = createToken("sui", "USDC", "nep141:sui-c1b81ecaf27933252d31a963bc5e9458f13c18ce.omft.near", 6, "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC");
99
117
  var ethereumETH = createToken("eth", "ETH", "nep141:eth.omft.near", 18);
@@ -115,7 +133,7 @@ var arbitrumARB = createToken("arb", "ARB", "nep141:arb-0x912ce59144191c1204e645
115
133
  var arbitrumGMX = createToken("arb", "GMX", "nep141:arb-0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a.omft.near", 18, "0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a");
116
134
  var baseETH = createToken("base", "ETH", "nep141:base.omft.near", 18);
117
135
  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");
136
+ var baseCbBTC = createToken("base", "cbBTC", "nep141:base-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near", 8, "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf", { name: "baseCbBTC" });
119
137
  var baseBRETT = createToken("base", "BRETT", "nep141:base-0x532f27101965dd16442e59d40670faf5ebb142e4.omft.near", 18, "0x532f27101965dd16442e59d40670faf5ebb142e4");
120
138
  var optimismETH = createToken("op", "ETH", "nep245:v2_1.omni.hot.tg:10_11111111111111111111", 18);
121
139
  var optimismUSDC = createToken("op", "USDC", "nep245:v2_1.omni.hot.tg:10_A2ewyUyDp6qsue1jqZsGypkCxRJ", 6, "0x0b2c639c533813f4aa9d7837caf62653d097ff85");
@@ -150,7 +168,10 @@ var aptosAPT = createToken("aptos", "APT", "nep141:aptos.omft.near", 8);
150
168
  var starknetSTRK = createToken("starknet", "STRK", "nep141:starknet.omft.near", 18);
151
169
  var berachainBERA = createToken("bera", "BERA", "nep141:bera.omft.near", 18);
152
170
  var zcashZEC = createToken("zec", "ZEC", "nep141:zec.omft.near", 8);
153
- var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near");
171
+ var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near", {
172
+ name: "nearNEAR",
173
+ aliases: ["nearwNEAR"]
174
+ });
154
175
  var nearUSDC = createToken("near", "USDC", "nep141:17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1", 6, "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1");
155
176
  var nearUSDT = createToken("near", "USDT", "nep141:usdt.tether-token.near", 6, "usdt.tether-token.near");
156
177
  var CHAINS = {
@@ -307,7 +328,9 @@ var CHAINS = {
307
328
  };
308
329
  var ALL_TOKENS = Object.values(CHAINS).flatMap((chain) => chain.tokens);
309
330
  function getToken(name) {
310
- return ALL_TOKENS.find((t) => t.name === name);
331
+ return ALL_TOKENS.find(
332
+ (token) => token.name === name || token.aliases?.includes(name)
333
+ );
311
334
  }
312
335
  function getTokensByChain(chainId) {
313
336
  return CHAINS[chainId]?.tokens || [];
@@ -318,31 +341,77 @@ function getTokenByAssetId(assetId) {
318
341
  function getSupportedChains() {
319
342
  return Object.values(CHAINS).filter((c) => c.tokens.length > 0);
320
343
  }
321
- function getSuiDestinationTokens() {
322
- return CHAINS.sui.tokens;
344
+
345
+ // src/core/config.ts
346
+ var DEFAULT_HOSTED_BACKEND_URL = "https://uniport-backend-production.up.railway.app";
347
+ var DEFAULT_REQUEST_TIMEOUT_MS = 2e4;
348
+ var configuredBackendUrl;
349
+ var configuredRequestTimeoutMs;
350
+ function normalizeBackendUrl(url) {
351
+ return url.replace(/\/+$/, "");
352
+ }
353
+ function getLegacyBackendOverride() {
354
+ const envBackendUrl = typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_UNIPORT_BACKEND_URL : void 0;
355
+ const windowBackendUrl = typeof window !== "undefined" ? window.__UNIPORT_BACKEND_URL__ : void 0;
356
+ return envBackendUrl || windowBackendUrl;
323
357
  }
324
- var _config = null;
325
- function initUniport(config) {
326
- _config = config;
327
- if (!config.apiKey) {
328
- throw new Error("Uniport SDK Error: apiKey is required. Pass your NEAR API key to initUniport().");
358
+ function configureUniport(config) {
359
+ if (config.backendUrl !== void 0) {
360
+ configuredBackendUrl = config.backendUrl ? normalizeBackendUrl(config.backendUrl) : void 0;
329
361
  }
330
- OpenAPI.BASE = config.baseUrl || "https://1click.chaindefuser.com";
331
- OpenAPI.TOKEN = config.apiKey;
332
- }
333
- function getConfig() {
334
- if (!_config) {
335
- throw new Error(
336
- "Uniport SDK not initialized. Call initUniport() first."
337
- );
362
+ if (config.requestTimeoutMs !== void 0) {
363
+ configuredRequestTimeoutMs = config.requestTimeoutMs > 0 ? config.requestTimeoutMs : DEFAULT_REQUEST_TIMEOUT_MS;
338
364
  }
339
- return _config;
340
365
  }
341
- function isInitialized() {
342
- return _config !== null;
366
+ function getUniportConfig() {
367
+ const backendUrl = configuredBackendUrl || getLegacyBackendOverride() || DEFAULT_HOSTED_BACKEND_URL;
368
+ return {
369
+ backendUrl: normalizeBackendUrl(backendUrl),
370
+ requestTimeoutMs: configuredRequestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS
371
+ };
343
372
  }
344
373
 
345
374
  // src/core/intents.ts
375
+ var UniportError = class extends Error {
376
+ constructor(params) {
377
+ super(params.message);
378
+ this.name = "UniportError";
379
+ this.code = params.code;
380
+ this.details = params.details;
381
+ this.status = params.status;
382
+ }
383
+ };
384
+ function isAbortError(error) {
385
+ return error instanceof Error && error.name === "AbortError";
386
+ }
387
+ function toUniportError(body, fallback) {
388
+ return new UniportError({
389
+ code: body.code || fallback.code,
390
+ message: body.message || fallback.message,
391
+ details: body.details,
392
+ status: fallback.status
393
+ });
394
+ }
395
+ function createTimeoutSignal(timeoutMs, externalSignal) {
396
+ const controller = new AbortController();
397
+ let timedOut = false;
398
+ const timeoutId = setTimeout(() => {
399
+ timedOut = true;
400
+ controller.abort();
401
+ }, timeoutMs);
402
+ const abortFromExternal = () => controller.abort();
403
+ externalSignal?.addEventListener("abort", abortFromExternal, {
404
+ once: true
405
+ });
406
+ return {
407
+ signal: controller.signal,
408
+ didTimeout: () => timedOut,
409
+ cleanup: () => {
410
+ clearTimeout(timeoutId);
411
+ externalSignal?.removeEventListener("abort", abortFromExternal);
412
+ }
413
+ };
414
+ }
346
415
  function toSmallestUnits(amount, decimals) {
347
416
  const [whole, fraction = ""] = amount.split(".");
348
417
  const paddedFraction = fraction.padEnd(decimals, "0").slice(0, decimals);
@@ -358,16 +427,7 @@ function generateDeadline(hoursFromNow = 1) {
358
427
  const deadline = new Date(Date.now() + hoursFromNow * 60 * 60 * 1e3);
359
428
  return deadline.toISOString();
360
429
  }
361
- function ensureInitialized() {
362
- if (!isInitialized()) {
363
- throw new Error(
364
- "Uniport SDK not initialized. Call initUniport() first."
365
- );
366
- }
367
- }
368
430
  async function getQuote(options) {
369
- ensureInitialized();
370
- const config = getConfig();
371
431
  const {
372
432
  originToken,
373
433
  destinationToken,
@@ -379,97 +439,133 @@ async function getQuote(options) {
379
439
  swapType = "EXACT_INPUT",
380
440
  deadline,
381
441
  dry = false,
382
- referral = config.referral || "uniport"
442
+ referral = "uniport",
443
+ signal
383
444
  } = options;
384
445
  const amountInSmallestUnits = toSmallestUnits(amount, originToken.decimals);
385
- const quoteRequest = {
386
- dry,
387
- swapType: QuoteRequest.swapType[swapType],
388
- slippageTolerance,
389
- originAsset: originToken.assetId,
390
- depositType: QuoteRequest.depositType.ORIGIN_CHAIN,
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
- };
446
+ const { backendUrl, requestTimeoutMs } = getUniportConfig();
447
+ const { signal: requestSignal, cleanup, didTimeout } = createTimeoutSignal(
448
+ requestTimeoutMs,
449
+ signal
450
+ );
451
+ let response;
400
452
  try {
401
- const response = await OneClickService.getQuote(quoteRequest);
402
- const quote = response.quote;
403
- return {
404
- depositAddress: quote.depositAddress || "",
405
- memo: quote.depositMemo,
406
- amountIn: quote.amountIn,
407
- amountOut: quote.amountOut,
408
- amountOutFormatted: quote.amountOutFormatted,
409
- amountOutUsd: quote.amountOutUsd,
410
- deadline: quote.deadline,
411
- timeWhenInactive: quote.timeWhenInactive,
412
- correlationId: response.correlationId
413
- };
453
+ response = await fetch(`${backendUrl}/api/quote`, {
454
+ method: "POST",
455
+ headers: { "Content-Type": "application/json" },
456
+ signal: requestSignal,
457
+ body: JSON.stringify({
458
+ dry,
459
+ swapType,
460
+ slippageTolerance,
461
+ originAsset: originToken.assetId,
462
+ destinationAsset: destinationToken.assetId,
463
+ amount: amountInSmallestUnits,
464
+ refundTo,
465
+ recipient,
466
+ deadline: deadline?.toISOString() || generateDeadline(1),
467
+ referral
468
+ })
469
+ });
414
470
  } catch (error) {
415
- if (error instanceof ApiError) {
416
- throw new Error(
417
- `Quote failed (${error.status}): ${JSON.stringify(error.body)}`
418
- );
471
+ cleanup();
472
+ if (isAbortError(error)) {
473
+ if (signal?.aborted && !didTimeout()) {
474
+ throw error;
475
+ }
476
+ throw new UniportError({
477
+ code: "REQUEST_TIMEOUT",
478
+ message: "Quote request timed out"
479
+ });
419
480
  }
420
481
  throw error;
421
482
  }
483
+ cleanup();
484
+ if (!response.ok) {
485
+ const errorBody = await response.json().catch(() => ({}));
486
+ throw toUniportError(errorBody, {
487
+ code: "QUOTE_FAILED",
488
+ message: "Quote failed.",
489
+ status: response.status
490
+ });
491
+ }
492
+ const data = await response.json();
493
+ const quote = data.quote;
494
+ return {
495
+ depositAddress: quote.depositAddress || "",
496
+ memo: quote.depositMemo,
497
+ amountIn: quote.amountIn,
498
+ amountOut: quote.amountOut,
499
+ amountOutFormatted: quote.amountOutFormatted,
500
+ amountOutUsd: quote.amountOutUsd,
501
+ deadline: quote.deadline,
502
+ timeWhenInactive: quote.timeWhenInactive,
503
+ correlationId: data.correlationId
504
+ };
422
505
  }
423
506
  async function submitDepositTx(params) {
424
- ensureInitialized();
425
- const { txHash, depositAddress, memo, nearSenderAccount } = params;
507
+ const { backendUrl, requestTimeoutMs } = getUniportConfig();
508
+ const { signal, cleanup } = createTimeoutSignal(requestTimeoutMs);
509
+ let response;
426
510
  try {
427
- await OneClickService.submitDepositTx({
428
- txHash,
429
- depositAddress,
430
- memo,
431
- nearSenderAccount
511
+ response = await fetch(`${backendUrl}/api/deposit`, {
512
+ method: "POST",
513
+ headers: { "Content-Type": "application/json" },
514
+ signal,
515
+ body: JSON.stringify(params)
432
516
  });
433
517
  } catch (error) {
434
- if (error instanceof ApiError) {
435
- throw new Error(
436
- `Submit deposit failed (${error.status}): ${JSON.stringify(error.body)}`
437
- );
518
+ cleanup();
519
+ if (isAbortError(error)) {
520
+ throw new UniportError({
521
+ code: "REQUEST_TIMEOUT",
522
+ message: "Deposit submission timed out"
523
+ });
438
524
  }
439
525
  throw error;
440
526
  }
527
+ cleanup();
528
+ if (!response.ok) {
529
+ const errorBody = await response.json().catch(() => ({}));
530
+ throw toUniportError(errorBody, {
531
+ code: "DEPOSIT_SUBMISSION_FAILED",
532
+ message: "Submit deposit failed.",
533
+ status: response.status
534
+ });
535
+ }
441
536
  }
442
537
  async function getExecutionStatus(depositAddress, memo) {
443
- ensureInitialized();
538
+ const { backendUrl, requestTimeoutMs } = getUniportConfig();
539
+ const url = new URL(
540
+ `${backendUrl}/api/status/${encodeURIComponent(depositAddress)}`
541
+ );
542
+ if (memo) {
543
+ url.searchParams.set("memo", memo);
544
+ }
545
+ const { signal, cleanup } = createTimeoutSignal(requestTimeoutMs);
546
+ let response;
444
547
  try {
445
- const response = await OneClickService.getExecutionStatus(
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
- };
548
+ response = await fetch(url.toString(), { signal });
465
549
  } catch (error) {
466
- if (error instanceof ApiError) {
467
- throw new Error(
468
- `Status check failed (${error.status}): ${JSON.stringify(error.body)}`
469
- );
550
+ cleanup();
551
+ if (isAbortError(error)) {
552
+ throw new UniportError({
553
+ code: "REQUEST_TIMEOUT",
554
+ message: "Status check timed out"
555
+ });
470
556
  }
471
557
  throw error;
472
558
  }
559
+ cleanup();
560
+ if (!response.ok) {
561
+ const errorBody = await response.json().catch(() => ({}));
562
+ throw toUniportError(errorBody, {
563
+ code: "STATUS_CHECK_FAILED",
564
+ message: "Status check failed.",
565
+ status: response.status
566
+ });
567
+ }
568
+ return await response.json();
473
569
  }
474
570
  async function pollExecutionStatus(depositAddress, options) {
475
571
  const {
@@ -494,6 +590,6 @@ async function pollExecutionStatus(depositAddress, options) {
494
590
  throw new Error(`Timeout waiting for swap completion after ${timeout}ms`);
495
591
  }
496
592
 
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, getConfig, getExecutionStatus, getQuote, getSuiDestinationTokens, getSupportedChains, getToken, getTokenByAssetId, getTokensByChain, initUniport, isInitialized, 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 };
593
+ 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
594
  //# sourceMappingURL=index.js.map
499
595
  //# sourceMappingURL=index.js.map