uniport-sdk 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -85,7 +85,8 @@ var CHAIN_ICONS = {
85
85
  ltc: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/litecoin/info/logo.png",
86
86
  bch: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/bitcoincash/info/logo.png",
87
87
  xrp: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ripple/info/logo.png",
88
- zec: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zcash/info/logo.png"
88
+ zec: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zcash/info/logo.png",
89
+ scroll: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/scroll/info/logo.png"
89
90
  };
90
91
  var EVM_CHAINS = [
91
92
  "eth",
@@ -97,11 +98,16 @@ var EVM_CHAINS = [
97
98
  "bsc",
98
99
  "gnosis",
99
100
  "bera",
100
- "monad"
101
+ "monad",
102
+ "scroll"
101
103
  ];
102
104
  function isEvmChain(chain) {
103
105
  return EVM_CHAINS.includes(chain);
104
106
  }
107
+ var CHAINS_REQUIRING_MEMO = ["stellar"];
108
+ function needsMemoDeposit(chain) {
109
+ return CHAINS_REQUIRING_MEMO.includes(chain);
110
+ }
105
111
  var EXPLORER_TX_URLS = {
106
112
  eth: (h) => `https://etherscan.io/tx/${h}`,
107
113
  arb: (h) => `https://arbiscan.io/tx/${h}`,
@@ -127,7 +133,8 @@ var EXPLORER_TX_URLS = {
127
133
  ltc: (h) => `https://litecoinspace.org/tx/${h}`,
128
134
  bch: (h) => `https://blockchair.com/bitcoin-cash/transaction/${h}`,
129
135
  xrp: (h) => `https://xrpscan.com/tx/${h}`,
130
- zec: (h) => `https://blockchair.com/zcash/transaction/${h}`
136
+ zec: (h) => `https://blockchair.com/zcash/transaction/${h}`,
137
+ scroll: (h) => `https://scrollscan.com/tx/${h}`
131
138
  };
132
139
  function getExplorerTxUrl(chain, hash) {
133
140
  return EXPLORER_TX_URLS[chain]?.(hash);
@@ -192,6 +199,8 @@ var baseETH = createToken("base", "ETH", "nep141:base.omft.near", 18);
192
199
  var baseUSDC = createToken("base", "USDC", "nep141:base-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913.omft.near", 6, "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913");
193
200
  var baseCbBTC = createToken("base", "cbBTC", "nep141:base-0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf.omft.near", 8, "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf", { name: "baseCbBTC" });
194
201
  var baseBRETT = createToken("base", "BRETT", "nep141:base-0x532f27101965dd16442e59d40670faf5ebb142e4.omft.near", 18, "0x532f27101965dd16442e59d40670faf5ebb142e4");
202
+ var scrollETH = createToken("scroll", "ETH", "nep245:v2_1.omni.hot.tg:534352_11111111111111111111", 18);
203
+ var scrollUSDT = createToken("scroll", "USDT", "nep245:v2_1.omni.hot.tg:534352_4RG3Q2wFsMQmd45m5m89RjsLfupA", 6, "0xf55bec9cafdbe8730f096aa55dad6d22d44099df");
195
204
  var optimismETH = createToken("op", "ETH", "nep245:v2_1.omni.hot.tg:10_11111111111111111111", 18);
196
205
  var optimismUSDC = createToken("op", "USDC", "nep245:v2_1.omni.hot.tg:10_A2ewyUyDp6qsue1jqZsGypkCxRJ", 6, "0x0b2c639c533813f4aa9d7837caf62653d097ff85");
197
206
  var optimismUSDT = createToken("op", "USDT", "nep245:v2_1.omni.hot.tg:10_359RPSJVdTxwTJT9TyGssr2rFoWo", 6, "0x94b008aa00579c1307b0ef2c499ad98a8ce58e58");
@@ -225,6 +234,8 @@ var aptosAPT = createToken("aptos", "APT", "nep141:aptos.omft.near", 8);
225
234
  var starknetSTRK = createToken("starknet", "STRK", "nep141:starknet.omft.near", 18);
226
235
  var berachainBERA = createToken("bera", "BERA", "nep141:bera.omft.near", 18);
227
236
  var zcashZEC = createToken("zec", "ZEC", "nep141:zec.omft.near", 8);
237
+ var stellarXLM = createToken("stellar", "XLM", "nep245:v2_1.omni.hot.tg:1100_111bzQBB5v7AhLyPMDwS8uJgQV24KaAPXtwyVWu2KXbbfQU6NXRCz", 7);
238
+ var stellarUSDC = createToken("stellar", "USDC", "nep245:v2_1.omni.hot.tg:1100_111bzQBB65GxAPAVoxqmMcgYo5oS3txhqs1Uh1cgahKQUeTUq1TJu", 7, "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN");
228
239
  var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near", {
229
240
  name: "nearNEAR",
230
241
  aliases: ["nearwNEAR"]
@@ -232,11 +243,11 @@ var nearNEAR = createToken("near", "wNEAR", "nep141:wrap.near", 24, "wrap.near",
232
243
  var nearUSDC = createToken("near", "USDC", "nep141:17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1", 6, "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1");
233
244
  var nearUSDT = createToken("near", "USDT", "nep141:usdt.tether-token.near", 6, "usdt.tether-token.near");
234
245
  var CHAINS = {
235
- sui: {
236
- id: "sui",
237
- name: "Sui",
238
- icon: CHAIN_ICONS.sui,
239
- tokens: [suiSUI, suiUSDC]
246
+ stellar: {
247
+ id: "stellar",
248
+ name: "Stellar",
249
+ icon: CHAIN_ICONS.stellar,
250
+ tokens: [stellarXLM, stellarUSDC]
240
251
  },
241
252
  eth: {
242
253
  id: "eth",
@@ -256,6 +267,12 @@ var CHAINS = {
256
267
  icon: CHAIN_ICONS.base,
257
268
  tokens: [baseETH, baseUSDC, baseCbBTC, baseBRETT]
258
269
  },
270
+ sui: {
271
+ id: "sui",
272
+ name: "Sui",
273
+ icon: CHAIN_ICONS.sui,
274
+ tokens: [suiSUI, suiUSDC]
275
+ },
259
276
  op: {
260
277
  id: "op",
261
278
  name: "Optimism",
@@ -376,11 +393,11 @@ var CHAINS = {
376
393
  icon: CHAIN_ICONS.monad,
377
394
  tokens: []
378
395
  },
379
- stellar: {
380
- id: "stellar",
381
- name: "Stellar",
382
- icon: CHAIN_ICONS.stellar,
383
- tokens: []
396
+ scroll: {
397
+ id: "scroll",
398
+ name: "Scroll",
399
+ icon: CHAIN_ICONS.scroll,
400
+ tokens: [scrollETH, scrollUSDT]
384
401
  }
385
402
  };
386
403
  var ALL_TOKENS = Object.values(CHAINS).flatMap((chain) => chain.tokens);
@@ -496,6 +513,17 @@ function generateDeadline(hoursFromNow = 1) {
496
513
  const deadline = new Date(Date.now() + hoursFromNow * 60 * 60 * 1e3);
497
514
  return deadline.toISOString();
498
515
  }
516
+ function formatDisplayAmount(amount, significantDigits = 6) {
517
+ if (!amount) return amount ?? "";
518
+ const num = Number(amount);
519
+ if (!Number.isFinite(num) || num === 0) return amount;
520
+ const abs = Math.abs(num);
521
+ if (abs < 1e-6 || abs >= 1e21) return amount;
522
+ return new Intl.NumberFormat("en-US", {
523
+ maximumSignificantDigits: significantDigits,
524
+ useGrouping: false
525
+ }).format(num);
526
+ }
499
527
  async function getQuote(options) {
500
528
  const {
501
529
  originToken,
@@ -527,6 +555,7 @@ async function getQuote(options) {
527
555
  dry,
528
556
  swapType,
529
557
  slippageTolerance,
558
+ depositMode: needsMemoDeposit(originToken.chain) ? "MEMO" : void 0,
530
559
  originAsset: originToken.assetId,
531
560
  destinationAsset: destinationToken.assetId,
532
561
  amount: amountInSmallestUnits,
@@ -1231,7 +1260,7 @@ function UniportModal({
1231
1260
  onError
1232
1261
  });
1233
1262
  const [modalStep, setModalStep] = react.useState("chain");
1234
- const [copied, setCopied] = react.useState(false);
1263
+ const [copiedField, setCopiedField] = react.useState(null);
1235
1264
  const [showReceipt, setShowReceipt] = react.useState(false);
1236
1265
  const [portalRoot, setPortalRoot] = react.useState(null);
1237
1266
  react.useEffect(() => {
@@ -1263,13 +1292,11 @@ function UniportModal({
1263
1292
  };
1264
1293
  }
1265
1294
  }, [open, handleClose]);
1266
- const handleCopy = react.useCallback(async () => {
1267
- if (payment.quote?.depositAddress) {
1268
- const ok = await payment.copyToClipboard(payment.quote.depositAddress);
1269
- if (ok) {
1270
- setCopied(true);
1271
- setTimeout(() => setCopied(false), 2e3);
1272
- }
1295
+ const handleCopy = react.useCallback(async (field, text) => {
1296
+ const ok = await payment.copyToClipboard(text);
1297
+ if (ok) {
1298
+ setCopiedField(field);
1299
+ setTimeout(() => setCopiedField(null), 2e3);
1273
1300
  }
1274
1301
  }, [payment]);
1275
1302
  if (!open || !portalRoot) return null;
@@ -1554,6 +1581,22 @@ function UniportModal({
1554
1581
  },
1555
1582
  children: payment.isUsingDefaultRefundAddress ? `Used only if the swap fails. You can enter your own address, or leave blank to use Uniport's default (${UNIPORT_ENS_NAME}).` : "Used only if the swap fails. This address must live on the chain the payer is sending from."
1556
1583
  }
1584
+ ),
1585
+ ch?.id === "stellar" && tok?.symbol !== "XLM" && /* @__PURE__ */ jsxRuntime.jsxs(
1586
+ "p",
1587
+ {
1588
+ style: {
1589
+ margin: "6px 0 0",
1590
+ fontSize: "12px",
1591
+ color: t.warning,
1592
+ lineHeight: 1.5
1593
+ },
1594
+ children: [
1595
+ "This refund address must already have a trustline for ",
1596
+ tok?.symbol,
1597
+ " on Stellar, or a refund cannot be delivered to it."
1598
+ ]
1599
+ }
1557
1600
  )
1558
1601
  ] }),
1559
1602
  /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
@@ -1576,7 +1619,7 @@ function UniportModal({
1576
1619
  "You will receive",
1577
1620
  " ",
1578
1621
  /* @__PURE__ */ jsxRuntime.jsxs("strong", { style: { color: t.text }, children: [
1579
- payment.previewQuote.amountOutFormatted,
1622
+ formatDisplayAmount(payment.previewQuote.amountOutFormatted),
1580
1623
  " ",
1581
1624
  payment.destinationToken.symbol
1582
1625
  ] }),
@@ -1657,7 +1700,7 @@ function UniportModal({
1657
1700
  padding: "11px 13px",
1658
1701
  background: t.inputBg,
1659
1702
  borderRadius: "10px",
1660
- marginBottom: "14px",
1703
+ marginBottom: quote.memo ? "10px" : "14px",
1661
1704
  border: `1px solid ${t.border}`
1662
1705
  }, children: [
1663
1706
  /* @__PURE__ */ jsxRuntime.jsx("span", { style: {
@@ -1671,22 +1714,64 @@ function UniportModal({
1671
1714
  /* @__PURE__ */ jsxRuntime.jsx(
1672
1715
  "button",
1673
1716
  {
1674
- onClick: handleCopy,
1717
+ onClick: () => handleCopy("address", quote.depositAddress),
1675
1718
  title: "Copy address",
1676
1719
  style: {
1677
1720
  flexShrink: 0,
1678
1721
  width: 34,
1679
1722
  height: 34,
1680
1723
  borderRadius: "8px",
1681
- background: copied ? `${t.success}18` : t.iconBtnBg,
1682
- border: `1px solid ${copied ? t.success + "44" : t.border}`,
1724
+ background: copiedField === "address" ? `${t.success}18` : t.iconBtnBg,
1725
+ border: `1px solid ${copiedField === "address" ? t.success + "44" : t.border}`,
1683
1726
  cursor: "pointer",
1684
1727
  display: "flex",
1685
1728
  alignItems: "center",
1686
1729
  justifyContent: "center",
1687
1730
  transition: "all 0.2s"
1688
1731
  },
1689
- children: copied ? /* @__PURE__ */ jsxRuntime.jsx(CheckMark, { color: t.success }) : /* @__PURE__ */ jsxRuntime.jsx(CopyIcon, { color: t.textMuted })
1732
+ children: copiedField === "address" ? /* @__PURE__ */ jsxRuntime.jsx(CheckMark, { color: t.success }) : /* @__PURE__ */ jsxRuntime.jsx(CopyIcon, { color: t.textMuted })
1733
+ }
1734
+ )
1735
+ ] }),
1736
+ quote.memo && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
1737
+ display: "flex",
1738
+ alignItems: "center",
1739
+ gap: "10px",
1740
+ padding: "11px 13px",
1741
+ background: `${t.warning}0f`,
1742
+ borderRadius: "10px",
1743
+ marginBottom: "14px",
1744
+ border: `1px solid ${t.warning}44`
1745
+ }, children: [
1746
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { flex: 1 }, children: [
1747
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: "0 0 3px", fontSize: "11px", color: t.warning, fontWeight: 600, textTransform: "uppercase", letterSpacing: "0.05em" }, children: "Memo required" }),
1748
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: {
1749
+ fontSize: "13px",
1750
+ color: t.text,
1751
+ fontFamily: "monospace",
1752
+ wordBreak: "break-all",
1753
+ lineHeight: 1.4
1754
+ }, children: quote.memo })
1755
+ ] }),
1756
+ /* @__PURE__ */ jsxRuntime.jsx(
1757
+ "button",
1758
+ {
1759
+ onClick: () => handleCopy("memo", quote.memo),
1760
+ title: "Copy memo",
1761
+ style: {
1762
+ flexShrink: 0,
1763
+ width: 34,
1764
+ height: 34,
1765
+ borderRadius: "8px",
1766
+ background: copiedField === "memo" ? `${t.success}18` : t.iconBtnBg,
1767
+ border: `1px solid ${copiedField === "memo" ? t.success + "44" : t.border}`,
1768
+ cursor: "pointer",
1769
+ display: "flex",
1770
+ alignItems: "center",
1771
+ justifyContent: "center",
1772
+ transition: "all 0.2s"
1773
+ },
1774
+ children: copiedField === "memo" ? /* @__PURE__ */ jsxRuntime.jsx(CheckMark, { color: t.success }) : /* @__PURE__ */ jsxRuntime.jsx(CopyIcon, { color: t.textMuted })
1690
1775
  }
1691
1776
  )
1692
1777
  ] }),
@@ -1703,7 +1788,14 @@ function UniportModal({
1703
1788
  " ",
1704
1789
  "on ",
1705
1790
  /* @__PURE__ */ jsxRuntime.jsx("strong", { children: payment.selectedChain?.name }),
1706
- " to this address. Other assets may be permanently lost."
1791
+ " to this address",
1792
+ quote.memo && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1793
+ " ",
1794
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "with the memo above" })
1795
+ ] }),
1796
+ ". Other assets may be permanently lost",
1797
+ quote.memo && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: ", and omitting the memo may make your deposit unrecoverable" }),
1798
+ "."
1707
1799
  ] })
1708
1800
  ] }),
1709
1801
  /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { borderTop: `1px solid ${t.border}`, paddingTop: "12px" }, children: [
@@ -1711,7 +1803,7 @@ function UniportModal({
1711
1803
  /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: "13px", color: t.textMuted }, children: "You'll receive" }),
1712
1804
  /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { fontSize: "13px", fontWeight: 600, color: t.text }, children: [
1713
1805
  "\u2248",
1714
- quote.amountOutFormatted,
1806
+ formatDisplayAmount(quote.amountOutFormatted),
1715
1807
  " ",
1716
1808
  payment.destinationToken.symbol
1717
1809
  ] })
@@ -1805,7 +1897,7 @@ function UniportModal({
1805
1897
  payment.selectedToken?.symbol,
1806
1898
  " \u2192 ",
1807
1899
  "\u2248",
1808
- payment.quote?.amountOutFormatted,
1900
+ formatDisplayAmount(payment.quote?.amountOutFormatted),
1809
1901
  " ",
1810
1902
  payment.destinationToken.symbol
1811
1903
  ] }),
@@ -2154,6 +2246,7 @@ function UniportIcon() {
2154
2246
 
2155
2247
  exports.ALL_TOKENS = ALL_TOKENS;
2156
2248
  exports.CHAINS = CHAINS;
2249
+ exports.CHAINS_REQUIRING_MEMO = CHAINS_REQUIRING_MEMO;
2157
2250
  exports.CHAIN_ICONS = CHAIN_ICONS;
2158
2251
  exports.DEFAULT_HOSTED_BACKEND_URL = DEFAULT_HOSTED_BACKEND_URL;
2159
2252
  exports.DEFAULT_REQUEST_TIMEOUT_MS = DEFAULT_REQUEST_TIMEOUT_MS;
@@ -2198,6 +2291,7 @@ exports.ethereumUNI = ethereumUNI;
2198
2291
  exports.ethereumUSDC = ethereumUSDC;
2199
2292
  exports.ethereumUSDT = ethereumUSDT;
2200
2293
  exports.ethereumWBTC = ethereumWBTC;
2294
+ exports.formatDisplayAmount = formatDisplayAmount;
2201
2295
  exports.fromSmallestUnits = fromSmallestUnits;
2202
2296
  exports.generateDeadline = generateDeadline;
2203
2297
  exports.getExecutionStatus = getExecutionStatus;
@@ -2214,6 +2308,7 @@ exports.litecoinLTC = litecoinLTC;
2214
2308
  exports.nearNEAR = nearNEAR;
2215
2309
  exports.nearUSDC = nearUSDC;
2216
2310
  exports.nearUSDT = nearUSDT;
2311
+ exports.needsMemoDeposit = needsMemoDeposit;
2217
2312
  exports.optimismETH = optimismETH;
2218
2313
  exports.optimismOP = optimismOP;
2219
2314
  exports.optimismUSDC = optimismUSDC;
@@ -2224,6 +2319,8 @@ exports.polygonUSDC = polygonUSDC;
2224
2319
  exports.polygonUSDT = polygonUSDT;
2225
2320
  exports.resolveEnsName = resolveEnsName;
2226
2321
  exports.rippleXRP = rippleXRP;
2322
+ exports.scrollETH = scrollETH;
2323
+ exports.scrollUSDT = scrollUSDT;
2227
2324
  exports.solanaMELANIA = solanaMELANIA;
2228
2325
  exports.solanaSOL = solanaSOL;
2229
2326
  exports.solanaTRUMP = solanaTRUMP;
@@ -2231,6 +2328,8 @@ exports.solanaUSDC = solanaUSDC;
2231
2328
  exports.solanaUSDT = solanaUSDT;
2232
2329
  exports.solanaWIF = solanaWIF;
2233
2330
  exports.starknetSTRK = starknetSTRK;
2331
+ exports.stellarUSDC = stellarUSDC;
2332
+ exports.stellarXLM = stellarXLM;
2234
2333
  exports.submitDepositTx = submitDepositTx;
2235
2334
  exports.suiSUI = suiSUI;
2236
2335
  exports.suiUSDC = suiUSDC;