@coinlist-co/react 0.12.2-rc.0ff2d03 → 0.12.2-rc.3de3751

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.
@@ -291,6 +291,75 @@ function isExpired({
291
291
  return now >= expiresAt - buffer;
292
292
  }
293
293
 
294
+ // src/universal/types/blockchain/ui.ts
295
+ var FormattedAmountUi = (value) => value;
296
+ var FormattedPercentUi = (value) => value;
297
+ var TxExplorerUrl = (value) => value;
298
+ var ShortenedWalletAddress = (value) => value;
299
+ var FormattedAmountAssetUi = (value) => value;
300
+ var AssetIconUrl = (value) => value;
301
+
302
+ // src/universal/core/shared/blockchain/chain.ts
303
+ import { base, baseSepolia, mainnet, sepolia } from "viem/chains";
304
+ var VIEM_CHAINS = {
305
+ ethereum_mainnet: mainnet,
306
+ ethereum_sepolia: sepolia,
307
+ base_mainnet: base,
308
+ base_sepolia: baseSepolia
309
+ };
310
+ function viemChain(chain) {
311
+ return VIEM_CHAINS[chain];
312
+ }
313
+ function getChainId(chain) {
314
+ return VIEM_CHAINS[chain].id;
315
+ }
316
+ function chainFromId(chainId) {
317
+ const chains = Object.keys(VIEM_CHAINS);
318
+ const chain = chains.find((c) => String(VIEM_CHAINS[c].id) === chainId);
319
+ if (!chain) {
320
+ throw new ValidationError(`Unsupported EIP-155 chain id: "${chainId}"`);
321
+ }
322
+ return chain;
323
+ }
324
+ function contractOn(contracts, chain) {
325
+ return contracts.find((contract) => contract.chain === chain)?.address ?? null;
326
+ }
327
+ function getNetworkName(chain) {
328
+ switch (chain) {
329
+ case "ethereum_mainnet":
330
+ return "Ethereum";
331
+ case "ethereum_sepolia":
332
+ return "Ethereum Sepolia";
333
+ case "base_mainnet":
334
+ return "Base";
335
+ case "base_sepolia":
336
+ return "Base Sepolia";
337
+ default: {
338
+ const _exhaustive = chain;
339
+ return _exhaustive;
340
+ }
341
+ }
342
+ }
343
+ function txExplorerUrl(chain, txHash) {
344
+ return TxExplorerUrl(`${explorerBaseUrl(chain)}/tx/${txHash}`);
345
+ }
346
+ function explorerBaseUrl(chain) {
347
+ switch (chain) {
348
+ case "ethereum_mainnet":
349
+ return "https://etherscan.io";
350
+ case "ethereum_sepolia":
351
+ return "https://sepolia.etherscan.io";
352
+ case "base_mainnet":
353
+ return "https://basescan.org";
354
+ case "base_sepolia":
355
+ return "https://sepolia-explorer.base.org";
356
+ default: {
357
+ const _exhaustive = chain;
358
+ return _exhaustive;
359
+ }
360
+ }
361
+ }
362
+
294
363
  // src/universal/types/blockchain/core.ts
295
364
  var ETHEREUM_CHAINS = {
296
365
  ethereum_mainnet: true,
@@ -421,6 +490,36 @@ function blockchainAmountFromRawOrThrow({
421
490
  throw new ValidationError(`${label}: out of uint256 bounds (${value})`);
422
491
  }
423
492
  }
493
+ function positiveAmountFromRawOrThrow({
494
+ label,
495
+ raw,
496
+ decimals,
497
+ reason
498
+ }) {
499
+ const amount = blockchainAmountFromRawOrThrow({ label, raw, decimals });
500
+ if (amount.raw === 0n) {
501
+ throw new ValidationError(
502
+ `${label}: must be greater than zero ("${raw}") - ${reason}`
503
+ );
504
+ }
505
+ return amount;
506
+ }
507
+ function pricePerShare({
508
+ usd,
509
+ shares
510
+ }) {
511
+ const price = BlockchainAmount.div(usd, shares);
512
+ return BlockchainAmount({
513
+ raw: assertPriceFits(price.raw),
514
+ decimals: price.decimals
515
+ });
516
+ }
517
+ function assertPriceFits(raw) {
518
+ if (raw > MAX_UINT_256) {
519
+ throw new MathError(`Price per share: out of uint256 bounds (${raw})`);
520
+ }
521
+ return raw;
522
+ }
424
523
  function parseBlockchainAmount(amount, decimals) {
425
524
  const trimmed = amount.trim();
426
525
  if (trimmed === "") return { valid: false, reason: { type: "empty" } };
@@ -547,6 +646,12 @@ function requiredArray(value, field) {
547
646
  }
548
647
  return value;
549
648
  }
649
+ function txFromWire(wire) {
650
+ return {
651
+ to: EvmContractAddress(wire.to),
652
+ data: HexEncodedTransactionData(wire.data)
653
+ };
654
+ }
550
655
 
551
656
  // src/universal/types/providers/centrifuge/centrifuge.ts
552
657
  var CentrifugeVaultStatus = {
@@ -575,19 +680,16 @@ var CentrifugeVaultStatus = {
575
680
  };
576
681
  var CentrifugeVaultBuyTransaction = {
577
682
  fromDto: (dto) => {
578
- const spendInputAmount = blockchainAmountFromRawOrThrow({
579
- label: "spend_input_amount",
580
- raw: dto.spend_input_amount,
581
- decimals: AssetDecimals(dto.spend_input_decimals)
582
- });
583
- if (spendInputAmount.raw <= 0n) {
584
- throw new ValidationError(
585
- `spend_input_amount: must be greater than zero ("${dto.spend_input_amount}") - a deposit of nothing is not a request`
586
- );
587
- }
588
683
  return {
589
684
  ...parseTransactionCore(dto, "CentrifugeVaultBuyTransaction"),
590
- spendInputAmount
685
+ spendInputAmount: positiveAmountFromRawOrThrow({
686
+ label: "spend_input_amount",
687
+ raw: dto.spend_input_amount,
688
+ decimals: AssetDecimals(dto.spend_input_decimals),
689
+ // Frontline refuses an `amount` of zero, so a zero here is a changed
690
+ // encoding, not a small deposit - and not calldata worth signing.
691
+ reason: "a deposit of nothing is not a request"
692
+ })
591
693
  };
592
694
  }
593
695
  };
@@ -671,14 +773,25 @@ function parseOrderability(canOrder, reasons, model) {
671
773
  }
672
774
  function parseTransactionCore(dto, model) {
673
775
  return {
674
- tx: {
675
- to: EvmContractAddress(dto.to),
676
- data: HexEncodedTransactionData(dto.data)
677
- },
776
+ tx: txFromWire(dto),
678
777
  expiresAt: dateOrNull(dto.expires_at, `${model}.expires_at`)
679
778
  };
680
779
  }
681
780
 
781
+ // src/universal/api/frontline/providers/shared/spend-scale.ts
782
+ function assertSpendScaleAgrees({
783
+ published,
784
+ sized,
785
+ trade,
786
+ note
787
+ }) {
788
+ if (published === sized.decimals) return;
789
+ const because = note === void 0 ? "" : ` - ${note}`;
790
+ throw new ValidationError(
791
+ `spend_input_decimals: the ${trade} was priced in ${published} decimals but the order was sized in ${sized.decimals}${because}`
792
+ );
793
+ }
794
+
682
795
  // src/universal/api/frontline/providers/centrifuge/centrifuge.ts
683
796
  async function getCentrifugeVaultStatus(api, params) {
684
797
  const dto = await api.send({
@@ -702,11 +815,11 @@ async function buildCentrifugeVaultBuy(api, params) {
702
815
  },
703
816
  attributes: Attributes.protected()
704
817
  });
705
- if (dto.spend_input_decimals !== params.amount.decimals) {
706
- throw new ValidationError(
707
- `spend_input_decimals: the request was priced in ${dto.spend_input_decimals} decimals but the deposit was sized in ${params.amount.decimals}`
708
- );
709
- }
818
+ assertSpendScaleAgrees({
819
+ published: dto.spend_input_decimals,
820
+ sized: params.amount,
821
+ trade: "deposit"
822
+ });
710
823
  return CentrifugeVaultBuyTransaction.fromDto(dto);
711
824
  }
712
825
  async function createCentrifugeVaultClaim(api, params) {
@@ -1044,14 +1157,6 @@ var CentrifugeNamespaceImpl = class {
1044
1157
  }
1045
1158
  };
1046
1159
 
1047
- // src/universal/types/blockchain/ui.ts
1048
- var FormattedAmountUi = (value) => value;
1049
- var FormattedPercentUi = (value) => value;
1050
- var TxExplorerUrl = (value) => value;
1051
- var ShortenedWalletAddress = (value) => value;
1052
- var FormattedAmountAssetUi = (value) => value;
1053
- var AssetIconUrl = (value) => value;
1054
-
1055
1160
  // src/universal/core/shared/blockchain/formatters.ts
1056
1161
  import { formatUnits } from "viem";
1057
1162
  function shortenAddress(address) {
@@ -1160,6 +1265,38 @@ function formattedUsdPrice(amount, locale) {
1160
1265
  );
1161
1266
  }
1162
1267
 
1268
+ // src/universal/types/pagination.ts
1269
+ var Cursor = (value) => value;
1270
+ var PaginatedResponse = {
1271
+ fromDto: (dto, itemMapper) => PaginatedResponse.fromDtoPage(dto, (items) => items.map(itemMapper)),
1272
+ /**
1273
+ * For a mapper that decides the page as a whole - one that drops items it
1274
+ * cannot map, such as `Offer.listFromDto` - rather than item by item. The
1275
+ * cursors are the wire's either way: dropping an item changes what the
1276
+ * page holds, not where the next page starts.
1277
+ */
1278
+ fromDtoPage: (dto, pageMapper) => ({
1279
+ data: pageMapper(dto.data),
1280
+ startingAfter: dto.starting_after ? Cursor(dto.starting_after) : null,
1281
+ startingBefore: dto.starting_before ? Cursor(dto.starting_before) : null
1282
+ })
1283
+ };
1284
+ var PaginationParams = {
1285
+ toQueryParams: (params) => {
1286
+ const queryParams = {};
1287
+ if (params.after) {
1288
+ queryParams.starting_after = params.after;
1289
+ }
1290
+ if (params.before) {
1291
+ queryParams.starting_before = params.before;
1292
+ }
1293
+ if (params.limit) {
1294
+ queryParams.limit = params.limit;
1295
+ }
1296
+ return queryParams;
1297
+ }
1298
+ };
1299
+
1163
1300
  // src/universal/types/asset.ts
1164
1301
  var AssetId = (value) => value;
1165
1302
  var AssetCode = (value) => value;
@@ -1428,42 +1565,8 @@ var Milestone = {
1428
1565
  })
1429
1566
  };
1430
1567
 
1431
- // src/universal/types/pagination.ts
1432
- var Cursor = (value) => value;
1433
- var PaginatedResponse = {
1434
- fromDto: (dto, itemMapper) => PaginatedResponse.fromDtoPage(dto, (items) => items.map(itemMapper)),
1435
- /**
1436
- * For a mapper that decides the page as a whole - one that drops items it
1437
- * cannot map, such as `Offer.listFromDto` - rather than item by item. The
1438
- * cursors are the wire's either way: dropping an item changes what the
1439
- * page holds, not where the next page starts.
1440
- */
1441
- fromDtoPage: (dto, pageMapper) => ({
1442
- data: pageMapper(dto.data),
1443
- startingAfter: dto.starting_after ? Cursor(dto.starting_after) : null,
1444
- startingBefore: dto.starting_before ? Cursor(dto.starting_before) : null
1445
- })
1446
- };
1447
- var PaginationParams = {
1448
- toQueryParams: (params) => {
1449
- const queryParams = {};
1450
- if (params.after) {
1451
- queryParams.starting_after = params.after;
1452
- }
1453
- if (params.before) {
1454
- queryParams.starting_before = params.before;
1455
- }
1456
- if (params.limit) {
1457
- queryParams.limit = params.limit;
1458
- }
1459
- return queryParams;
1460
- }
1461
- };
1462
-
1463
1568
  // src/universal/types/providers/coin-list/token-sale.ts
1464
1569
  var ParticipationId = (value) => value;
1465
- var Blockchain = (value) => value;
1466
- var WalletAddress = (value) => value;
1467
1570
  var ParticipationsPaginationParams = {
1468
1571
  toQueryParams: (params) => {
1469
1572
  const queryParams = PaginationParams.toQueryParams(params);
@@ -1487,10 +1590,10 @@ var Participation = {
1487
1590
  amount: dto.amount,
1488
1591
  displayAmount: dto.amount_string,
1489
1592
  asset: Asset.fromDto(dto.asset),
1490
- chain: Blockchain(dto.chain),
1593
+ chain: isChain(dto.chain) ? dto.chain : null,
1491
1594
  insertedAt: dto.inserted_at ? new Date(dto.inserted_at) : null,
1492
1595
  updatedAt: dto.updated_at ? new Date(dto.updated_at) : null,
1493
- walletAddress: walletAddress ? WalletAddress(walletAddress) : null
1596
+ walletAddress: walletAddress ? EvmWalletAddress(walletAddress) : null
1494
1597
  };
1495
1598
  }
1496
1599
  };
@@ -1589,64 +1692,6 @@ var CoinListTokenSaleNamespaceImpl = class {
1589
1692
  }
1590
1693
  };
1591
1694
 
1592
- // src/universal/core/shared/blockchain/chain.ts
1593
- import { base, baseSepolia, mainnet, sepolia } from "viem/chains";
1594
- var VIEM_CHAINS = {
1595
- ethereum_mainnet: mainnet,
1596
- ethereum_sepolia: sepolia,
1597
- base_mainnet: base,
1598
- base_sepolia: baseSepolia
1599
- };
1600
- function viemChain(chain) {
1601
- return VIEM_CHAINS[chain];
1602
- }
1603
- function getChainId(chain) {
1604
- return VIEM_CHAINS[chain].id;
1605
- }
1606
- function chainFromId(chainId) {
1607
- const chains = Object.keys(VIEM_CHAINS);
1608
- const chain = chains.find((c) => String(VIEM_CHAINS[c].id) === chainId);
1609
- if (!chain) {
1610
- throw new ValidationError(`Unsupported EIP-155 chain id: "${chainId}"`);
1611
- }
1612
- return chain;
1613
- }
1614
- function getNetworkName(chain) {
1615
- switch (chain) {
1616
- case "ethereum_mainnet":
1617
- return "Ethereum";
1618
- case "ethereum_sepolia":
1619
- return "Ethereum Sepolia";
1620
- case "base_mainnet":
1621
- return "Base";
1622
- case "base_sepolia":
1623
- return "Base Sepolia";
1624
- default: {
1625
- const _exhaustive = chain;
1626
- return _exhaustive;
1627
- }
1628
- }
1629
- }
1630
- function txExplorerUrl(chain, txHash) {
1631
- return TxExplorerUrl(`${explorerBaseUrl(chain)}/tx/${txHash}`);
1632
- }
1633
- function explorerBaseUrl(chain) {
1634
- switch (chain) {
1635
- case "ethereum_mainnet":
1636
- return "https://etherscan.io";
1637
- case "ethereum_sepolia":
1638
- return "https://sepolia.etherscan.io";
1639
- case "base_mainnet":
1640
- return "https://basescan.org";
1641
- case "base_sepolia":
1642
- return "https://sepolia-explorer.base.org";
1643
- default: {
1644
- const _exhaustive = chain;
1645
- return _exhaustive;
1646
- }
1647
- }
1648
- }
1649
-
1650
1695
  // src/universal/types/providers/ondo/ondo.ts
1651
1696
  var OndoTradingStatus = {
1652
1697
  fromDto: (dto) => {
@@ -1701,7 +1746,7 @@ var OndoBuyTransaction = {
1701
1746
  raw: dto.notional_value,
1702
1747
  decimals: spendDecimals
1703
1748
  }),
1704
- receiveOutputAmount: parsePositiveAmount({
1749
+ receiveOutputAmount: positiveAmountFromRawOrThrow({
1705
1750
  label: "receive_output_amount",
1706
1751
  raw: dto.receive_output_amount,
1707
1752
  decimals: outputDecimals,
@@ -1720,7 +1765,7 @@ var OndoSellTransaction = {
1720
1765
  fromDto: (dto) => {
1721
1766
  const spendDecimals = AssetDecimals(dto.spend_input_decimals);
1722
1767
  const outputDecimals = AssetDecimals(dto.receive_output_decimals);
1723
- const expectedQuantity = parsePositiveAmount({
1768
+ const expectedQuantity = positiveAmountFromRawOrThrow({
1724
1769
  label: "expected_quantity",
1725
1770
  raw: dto.expected_quantity,
1726
1771
  decimals: outputDecimals,
@@ -1754,12 +1799,12 @@ var OndoSellTransaction = {
1754
1799
  };
1755
1800
  function parseSwapCore(dto, spendDecimals) {
1756
1801
  return {
1757
- tx: {
1758
- to: EvmContractAddress(dto.to),
1759
- data: HexEncodedTransactionData(dto.data)
1760
- },
1761
- expiresAt: parseExpiresAt(dto.expires_at),
1762
- spendInputAmount: parsePositiveAmount({
1802
+ tx: txFromWire(dto),
1803
+ // A transaction whose expiry cannot be read is not safely fillable - the
1804
+ // deadline is encoded in the calldata either way, so broadcasting against
1805
+ // an unknown one only spends gas on a revert.
1806
+ expiresAt: requiredDate(dto.expires_at, "expires_at"),
1807
+ spendInputAmount: positiveAmountFromRawOrThrow({
1763
1808
  label: "spend_input_amount",
1764
1809
  raw: dto.spend_input_amount,
1765
1810
  decimals: spendDecimals,
@@ -1777,7 +1822,7 @@ function parseSwapCore(dto, spendDecimals) {
1777
1822
  };
1778
1823
  }
1779
1824
  function parseMinimumQuantity(raw, decimals, expectedQuantity) {
1780
- const amount = parsePositiveAmount({
1825
+ const amount = positiveAmountFromRawOrThrow({
1781
1826
  label: "minimum_quantity",
1782
1827
  raw,
1783
1828
  decimals,
@@ -1790,27 +1835,6 @@ function parseMinimumQuantity(raw, decimals, expectedQuantity) {
1790
1835
  }
1791
1836
  return amount;
1792
1837
  }
1793
- function parsePositiveAmount({
1794
- label,
1795
- raw,
1796
- decimals,
1797
- reason
1798
- }) {
1799
- const amount = blockchainAmountFromRawOrThrow({ label, raw, decimals });
1800
- if (amount.raw <= 0n) {
1801
- throw new ValidationError(
1802
- `${label}: must be greater than zero ("${raw}") - ${reason}`
1803
- );
1804
- }
1805
- return amount;
1806
- }
1807
- function parseExpiresAt(value) {
1808
- const date = new Date(value);
1809
- if (Number.isNaN(date.getTime())) {
1810
- throw new ValidationError(`expires_at: not a date ("${value}")`);
1811
- }
1812
- return date;
1813
- }
1814
1838
 
1815
1839
  // src/universal/api/frontline/providers/ondo/ondo.ts
1816
1840
  async function getOndoTradingStatus(api, params) {
@@ -1876,18 +1900,6 @@ function swapBody(params) {
1876
1900
  amount: params.amount.raw.toString()
1877
1901
  };
1878
1902
  }
1879
- function assertSpendScaleAgrees({
1880
- published,
1881
- sized,
1882
- trade,
1883
- note
1884
- }) {
1885
- if (published === sized.decimals) return;
1886
- const because = note === void 0 ? "" : ` - ${note}`;
1887
- throw new ValidationError(
1888
- `spend_input_decimals: the ${trade} was priced in ${published} decimals but the order was sized in ${sized.decimals}${because}`
1889
- );
1890
- }
1891
1903
  function sizeParam(params) {
1892
1904
  const tokenAmount = "tokenAmount" in params ? params.tokenAmount : void 0;
1893
1905
  const notionalValue = "notionalValue" in params ? params.notionalValue : void 0;
@@ -1983,8 +1995,7 @@ var AllowWalletResponse = {
1983
1995
  case "broadcast_transaction":
1984
1996
  return {
1985
1997
  action: "broadcast_transaction",
1986
- to: EvmContractAddress(dto.to),
1987
- data: HexEncodedTransactionData(dto.data)
1998
+ tx: txFromWire(dto)
1988
1999
  };
1989
2000
  case "none":
1990
2001
  return {
@@ -3914,6 +3925,18 @@ export {
3914
3925
  Seconds,
3915
3926
  isExpired,
3916
3927
  ERC20_ABI,
3928
+ FormattedAmountUi,
3929
+ FormattedPercentUi,
3930
+ TxExplorerUrl,
3931
+ ShortenedWalletAddress,
3932
+ FormattedAmountAssetUi,
3933
+ AssetIconUrl,
3934
+ viemChain,
3935
+ getChainId,
3936
+ chainFromId,
3937
+ contractOn,
3938
+ getNetworkName,
3939
+ txExplorerUrl,
3917
3940
  ETHEREUM_CHAINS,
3918
3941
  EthereumChain,
3919
3942
  SOLANA_CHAINS,
@@ -3936,6 +3959,8 @@ export {
3936
3959
  KnownAssetSymbol,
3937
3960
  Bps,
3938
3961
  blockchainAmountFromRawOrThrow,
3962
+ positiveAmountFromRawOrThrow,
3963
+ pricePerShare,
3939
3964
  parseBlockchainAmount,
3940
3965
  CentrifugeVaultStatus,
3941
3966
  CentrifugeVaultBuyTransaction,
@@ -3948,12 +3973,6 @@ export {
3948
3973
  CentrifugeVaultLegId,
3949
3974
  CentrifugeVaultClaimProceedsTransaction,
3950
3975
  CentrifugeNamespaceImpl,
3951
- FormattedAmountUi,
3952
- FormattedPercentUi,
3953
- TxExplorerUrl,
3954
- ShortenedWalletAddress,
3955
- FormattedAmountAssetUi,
3956
- AssetIconUrl,
3957
3976
  shortenAddress,
3958
3977
  formatAmount,
3959
3978
  formatRawAmount,
@@ -3964,6 +3983,9 @@ export {
3964
3983
  NA_AMOUNT_ASSET_UI,
3965
3984
  formatShareAmount,
3966
3985
  formattedUsdPrice,
3986
+ Cursor,
3987
+ PaginatedResponse,
3988
+ PaginationParams,
3967
3989
  AssetId,
3968
3990
  AssetCode,
3969
3991
  Asset,
@@ -3986,21 +4008,11 @@ export {
3986
4008
  Link,
3987
4009
  TermItem,
3988
4010
  Milestone,
3989
- Cursor,
3990
- PaginatedResponse,
3991
- PaginationParams,
3992
4011
  ParticipationId,
3993
- Blockchain,
3994
- WalletAddress,
3995
4012
  ParticipationsPaginationParams,
3996
4013
  Participation,
3997
4014
  CreateParticipationParams,
3998
4015
  CoinListTokenSaleNamespaceImpl,
3999
- viemChain,
4000
- getChainId,
4001
- chainFromId,
4002
- getNetworkName,
4003
- txExplorerUrl,
4004
4016
  OndoTradingStatus,
4005
4017
  OndoQuote,
4006
4018
  OndoBuyTransaction,
@@ -4039,4 +4051,4 @@ export {
4039
4051
  TokenMetadata,
4040
4052
  TokensNamespaceImpl
4041
4053
  };
4042
- //# sourceMappingURL=chunk-SVPFFLIT.js.map
4054
+ //# sourceMappingURL=chunk-HMLWCXAP.js.map