@coinlist-co/react 0.12.1-rc.73e7e17 → 0.12.1-rc.9aec85a

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.
Files changed (31) hide show
  1. package/dist/{chunk-3ZZCK4IT.js → chunk-DCW7NQXH.js} +129 -3
  2. package/dist/chunk-DCW7NQXH.js.map +1 -0
  3. package/dist/{chunk-D42IQHQZ.js → chunk-MOE5S6CE.js} +1345 -257
  4. package/dist/chunk-MOE5S6CE.js.map +1 -0
  5. package/dist/{chunk-ZUVVNZJJ.js → chunk-VH34YC3Q.js} +72 -330
  6. package/dist/chunk-VH34YC3Q.js.map +1 -0
  7. package/dist/client/index.cjs +9477 -8125
  8. package/dist/client/index.cjs.map +1 -1
  9. package/dist/client/index.d.cts +398 -166
  10. package/dist/client/index.d.ts +398 -166
  11. package/dist/client/index.js +4959 -4544
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/server/index.cjs +1458 -263
  14. package/dist/server/index.cjs.map +1 -1
  15. package/dist/server/index.d.cts +1 -1
  16. package/dist/server/index.d.ts +1 -1
  17. package/dist/server/index.js +5 -3
  18. package/dist/server/index.js.map +1 -1
  19. package/dist/{collections-CMoojQ9M.d.ts → token-registry-snapshot-BNBNuDu1.d.ts} +65 -2
  20. package/dist/{collections-koI4cjYa.d.cts → token-registry-snapshot-CqI6dXM_.d.cts} +65 -2
  21. package/dist/{config-BmK0t-XO.d.cts → tokens-namespace-CIWBtgt2.d.cts} +463 -229
  22. package/dist/{config-BmK0t-XO.d.ts → tokens-namespace-CIWBtgt2.d.ts} +463 -229
  23. package/dist/universal/index.cjs +1275 -450
  24. package/dist/universal/index.cjs.map +1 -1
  25. package/dist/universal/index.d.cts +431 -54
  26. package/dist/universal/index.d.ts +431 -54
  27. package/dist/universal/index.js +26 -16
  28. package/package.json +1 -1
  29. package/dist/chunk-3ZZCK4IT.js.map +0 -1
  30. package/dist/chunk-D42IQHQZ.js.map +0 -1
  31. package/dist/chunk-ZUVVNZJJ.js.map +0 -1
@@ -215,6 +215,9 @@ var HEADER_API_VERSION = "X-API-Version";
215
215
  var HEADER_IDEMPOTENCY_KEY = "Idempotency-Key";
216
216
  var API_VERSION = "2025-10-17";
217
217
 
218
+ // src/universal/core/shared/observability/log-cause.ts
219
+ var import_viem = require("viem");
220
+
218
221
  // src/universal/types/errors.ts
219
222
  var NotImplementedError = class extends Error {
220
223
  constructor(message = "Not implemented yet") {
@@ -267,8 +270,32 @@ function classifyLogCause(error) {
267
270
  if (error instanceof NotImplementedError) {
268
271
  return { type: "not-implemented" };
269
272
  }
273
+ if (error instanceof import_viem.BaseError) {
274
+ const http2 = error.walk((e) => e instanceof HttpError);
275
+ if (http2 instanceof HttpError) {
276
+ return httpCause(http2);
277
+ }
278
+ return { type: "rpc", reason: rpcFailureReason(error) };
279
+ }
270
280
  return { type: "generic-error", name: errorName(error) };
271
281
  }
282
+ function rpcFailureReason(error) {
283
+ if (error.walk((e) => e instanceof import_viem.ContractFunctionRevertedError)) {
284
+ return "reverted";
285
+ }
286
+ if (error.walk((e) => e instanceof import_viem.RpcError)) {
287
+ return "node-rejected";
288
+ }
289
+ if (error.walk(
290
+ (e) => e instanceof import_viem.HttpRequestError || e instanceof import_viem.WebSocketRequestError || e instanceof import_viem.SocketClosedError || e instanceof import_viem.TimeoutError
291
+ )) {
292
+ return "transport";
293
+ }
294
+ if (error instanceof import_viem.ContractFunctionExecutionError) {
295
+ return "malformed-response";
296
+ }
297
+ return "unknown";
298
+ }
272
299
  function describeErrorUnredacted(error) {
273
300
  if (error instanceof HttpError) {
274
301
  return describeHttpErrorRedacted(error);
@@ -457,9 +484,9 @@ var HttpClient = class {
457
484
  if (url.startsWith("http://") || url.startsWith("https://")) {
458
485
  return url;
459
486
  }
460
- const base = this.config.baseUrl.replace(/\/$/, "");
487
+ const base2 = this.config.baseUrl.replace(/\/$/, "");
461
488
  const path = url.startsWith("/") ? url : `/${url}`;
462
- return base + path;
489
+ return base2 + path;
463
490
  }
464
491
  async runBeforeRequestMiddleware(initialRequest) {
465
492
  let request = initialRequest;
@@ -908,6 +935,40 @@ async function fetchAllPages(fetchPage, baseParams) {
908
935
  return items;
909
936
  }
910
937
 
938
+ // src/universal/core/shared/utils/wire.ts
939
+ function unknownTypeError(dto, model) {
940
+ const type = dto.type;
941
+ throw new ValidationError(
942
+ `${model}.type: unknown type ${JSON.stringify(type)}`
943
+ );
944
+ }
945
+ function requiredString(value, field) {
946
+ const text = notBlankStringOrNull(value);
947
+ if (text === null) {
948
+ throw new ValidationError(
949
+ `${field}: expected a non-blank string, got ${typeof value === "string" ? "a blank string" : String(value)}`
950
+ );
951
+ }
952
+ return text;
953
+ }
954
+ function requiredDate(value, field) {
955
+ const date = typeof value === "string" ? new Date(value) : null;
956
+ if (date === null || Number.isNaN(date.getTime())) {
957
+ throw new ValidationError(
958
+ `${field}: expected a date, got ${JSON.stringify(value)}`
959
+ );
960
+ }
961
+ return date;
962
+ }
963
+ function requiredArray(value, field) {
964
+ if (!Array.isArray(value)) {
965
+ throw new ValidationError(
966
+ `${field}: expected an array, got ${typeof value}`
967
+ );
968
+ }
969
+ return value;
970
+ }
971
+
911
972
  // src/universal/types/blockchain/core.ts
912
973
  var ETHEREUM_CHAINS = {
913
974
  ethereum_mainnet: true,
@@ -999,25 +1060,69 @@ var AssetSymbol = (value) => value;
999
1060
  // src/universal/types/offer.ts
1000
1061
  var OfferId = (value) => value;
1001
1062
  var OfferSlug = (value) => value;
1063
+ var OFFER_TYPES = {
1064
+ "coinlist::token_sale": true,
1065
+ "superstate::swap": true,
1066
+ "ondo::swap": true
1067
+ };
1068
+ var isOfferType = (value) => Object.keys(OFFER_TYPES).includes(value);
1069
+ var OfferEditorial = {
1070
+ /**
1071
+ * `model` prefixes the field in the error (`'Offer'`, `'OfferDetail'`), so
1072
+ * the same three checks name the payload that failed them.
1073
+ */
1074
+ fromDto: (dto, model) => ({
1075
+ tagline: requiredString(dto.tagline, `${model}.tagline`),
1076
+ bannerUrl: requiredString(dto.banner_url, `${model}.banner_url`),
1077
+ startsAt: requiredDate(dto.starts_at, `${model}.starts_at`)
1078
+ })
1079
+ };
1002
1080
  var Offer = {
1003
1081
  fromDto: (dto) => {
1004
- if (!Array.isArray(dto.tokens)) {
1005
- throw new ValidationError(
1006
- `Offer.tokens: expected an array, got ${typeof dto.tokens}`
1007
- );
1008
- }
1009
- return {
1082
+ const tokens = requiredArray(dto.tokens, "Offer.tokens");
1083
+ const base2 = {
1010
1084
  id: OfferId(dto.id),
1011
1085
  slug: OfferSlug(dto.slug),
1012
- type: dto.type,
1013
- tagline: dto.tagline,
1014
- bannerUrl: dto.banner_url,
1015
- logoUrl: dto.logo_url,
1016
- startsAt: new Date(dto.starts_at),
1017
1086
  endsAt: dto.ends_at ? new Date(dto.ends_at) : null,
1018
- tokens: OfferToken.listFromDto(dto.tokens)
1087
+ tokens: OfferToken.listFromDto(tokens)
1019
1088
  };
1020
- }
1089
+ switch (dto.type) {
1090
+ case "coinlist::token_sale":
1091
+ return {
1092
+ ...base2,
1093
+ ...OfferEditorial.fromDto(dto, "Offer"),
1094
+ type: dto.type,
1095
+ logoUrl: requiredString(dto.logo_url, "Offer.logo_url")
1096
+ };
1097
+ case "superstate::swap":
1098
+ return {
1099
+ ...base2,
1100
+ ...OfferEditorial.fromDto(dto, "Offer"),
1101
+ type: dto.type,
1102
+ logoUrl: notBlankStringOrNull(dto.logo_url)
1103
+ };
1104
+ // `tagline`, `banner_url` and `starts_at` arrive as `null` and are left
1105
+ // on the wire: copying them would hand every consumer a `startsAt` that
1106
+ // is 1970 for one variant and a date for the others.
1107
+ case "ondo::swap":
1108
+ return {
1109
+ ...base2,
1110
+ type: dto.type,
1111
+ logoUrl: notBlankStringOrNull(dto.logo_url)
1112
+ };
1113
+ default:
1114
+ return unknownTypeError(dto, "Offer");
1115
+ }
1116
+ },
1117
+ /**
1118
+ * Maps a page of offers, dropping every offer whose `type` this SDK does not
1119
+ * name. The same reasoning as {@link OfferToken.listFromDto}: a plain `.map`
1120
+ * would throw out of `fromDto` and, through `PaginatedResponse.fromDto`,
1121
+ * reject the whole page, so one offer of an unknown type would blank the
1122
+ * grid for every offer beside it. A single offer fetched by id still
1123
+ * throws, because there is nothing beside it to keep.
1124
+ */
1125
+ listFromDto: (dtos) => dtos.filter((dto) => isOfferType(dto.type)).map(Offer.fromDto)
1021
1126
  };
1022
1127
  var OfferToken = {
1023
1128
  fromDto: (dto) => ({
@@ -1066,76 +1171,69 @@ var OfferSwapContract = {
1066
1171
  };
1067
1172
  var OfferDetail = {
1068
1173
  fromDto: (dto) => {
1069
- if (!Array.isArray(dto.funding_assets)) {
1070
- throw new ValidationError(
1071
- `OfferDetail.funding_assets: expected an array, got ${typeof dto.funding_assets}`
1072
- );
1073
- }
1074
- if (!Array.isArray(dto.options)) {
1075
- throw new ValidationError(
1076
- `OfferDetail.options: expected an array, got ${typeof dto.options}`
1077
- );
1078
- }
1079
- if (!Array.isArray(dto.terms)) {
1080
- throw new ValidationError(
1081
- `OfferDetail.terms: expected an array, got ${typeof dto.terms}`
1082
- );
1083
- }
1084
- if (!Array.isArray(dto.links)) {
1085
- throw new ValidationError(
1086
- `OfferDetail.links: expected an array, got ${typeof dto.links}`
1087
- );
1088
- }
1089
- if (!Array.isArray(dto.faqs)) {
1090
- throw new ValidationError(
1091
- `OfferDetail.faqs: expected an array, got ${typeof dto.faqs}`
1092
- );
1093
- }
1094
- if (!Array.isArray(dto.milestones)) {
1095
- throw new ValidationError(
1096
- `OfferDetail.milestones: expected an array, got ${typeof dto.milestones}`
1097
- );
1098
- }
1099
- if (!Array.isArray(dto.tokens)) {
1100
- throw new ValidationError(
1101
- `OfferDetail.tokens: expected an array, got ${typeof dto.tokens}`
1102
- );
1103
- }
1104
- const swapContracts = dto.swap_contracts === void 0 ? [] : dto.swap_contracts;
1105
- if (!Array.isArray(swapContracts)) {
1106
- throw new ValidationError(
1107
- `OfferDetail.swap_contracts: expected an array, got ${typeof swapContracts}`
1108
- );
1109
- }
1174
+ const fundingAssets = requiredArray(
1175
+ dto.funding_assets,
1176
+ "OfferDetail.funding_assets"
1177
+ );
1178
+ const options = requiredArray(dto.options, "OfferDetail.options");
1179
+ const terms = requiredArray(dto.terms, "OfferDetail.terms");
1180
+ const links = requiredArray(dto.links, "OfferDetail.links");
1181
+ const faqs = requiredArray(dto.faqs, "OfferDetail.faqs");
1182
+ const milestones = requiredArray(dto.milestones, "OfferDetail.milestones");
1183
+ const tokens = requiredArray(dto.tokens, "OfferDetail.tokens");
1110
1184
  const isin = notBlankStringOrNull(dto.isin);
1111
1185
  const ticker = notBlankStringOrNull(dto.ticker);
1112
- return {
1186
+ const base2 = {
1113
1187
  id: OfferId(dto.id),
1114
1188
  slug: OfferSlug(dto.slug),
1115
- type: dto.type,
1116
1189
  name: dto.name,
1117
1190
  asset: Asset.fromDto(dto.asset),
1118
- fundingAssets: dto.funding_assets.map(Asset.fromDto),
1119
- tokens: OfferToken.listFromDto(dto.tokens),
1120
- swapContracts: swapContracts.map(OfferSwapContract.fromDto),
1191
+ fundingAssets: fundingAssets.map(Asset.fromDto),
1192
+ tokens: OfferToken.listFromDto(tokens),
1121
1193
  about: notBlankStringOrNull(dto.about),
1122
- tagline: dto.tagline,
1123
- bannerUrl: dto.banner_url,
1124
- logoUrl: dto.logo_url,
1125
1194
  category: dto.category,
1126
1195
  issuer: notBlankStringOrNull(dto.issuer),
1127
1196
  isin: isin === null ? null : Isin(isin),
1128
1197
  ticker: ticker === null ? null : Ticker(ticker),
1129
1198
  instrumentType: notBlankStringOrNull(dto.instrument_type),
1130
1199
  listingVenue: notBlankStringOrNull(dto.listing_venue),
1131
- startsAt: new Date(dto.starts_at),
1132
1200
  endsAt: dto.ends_at ? new Date(dto.ends_at) : null,
1133
- faqs: dto.faqs.map(FaqItem.fromDto),
1134
- links: dto.links.map(Link.fromDto),
1135
- milestones: dto.milestones.map(Milestone.fromDto),
1136
- options: dto.options.map(OfferOption.fromDto),
1137
- terms: dto.terms.map(TermItem.fromDto)
1201
+ faqs: faqs.map(FaqItem.fromDto),
1202
+ links: links.map(Link.fromDto),
1203
+ milestones: milestones.map(Milestone.fromDto),
1204
+ options: options.map(OfferOption.fromDto),
1205
+ terms: terms.map(TermItem.fromDto)
1138
1206
  };
1207
+ switch (dto.type) {
1208
+ case "coinlist::token_sale":
1209
+ return {
1210
+ ...base2,
1211
+ ...OfferEditorial.fromDto(dto, "OfferDetail"),
1212
+ type: dto.type,
1213
+ logoUrl: requiredString(dto.logo_url, "OfferDetail.logo_url")
1214
+ };
1215
+ case "superstate::swap":
1216
+ return {
1217
+ ...base2,
1218
+ ...OfferEditorial.fromDto(dto, "OfferDetail"),
1219
+ type: dto.type,
1220
+ logoUrl: notBlankStringOrNull(dto.logo_url)
1221
+ };
1222
+ // `tagline`, `banner_url` and `starts_at` arrive as `null` and are left
1223
+ // on the wire, as in `Offer.fromDto`.
1224
+ case "ondo::swap":
1225
+ return {
1226
+ ...base2,
1227
+ type: dto.type,
1228
+ logoUrl: notBlankStringOrNull(dto.logo_url),
1229
+ swapContracts: requiredArray(
1230
+ dto.swap_contracts,
1231
+ "OfferDetail.swap_contracts"
1232
+ ).map(OfferSwapContract.fromDto)
1233
+ };
1234
+ default:
1235
+ return unknownTypeError(dto, "OfferDetail");
1236
+ }
1139
1237
  }
1140
1238
  };
1141
1239
  var OfferOption = {
@@ -1179,8 +1277,15 @@ var Milestone = {
1179
1277
  // src/universal/types/pagination.ts
1180
1278
  var Cursor = (value) => value;
1181
1279
  var PaginatedResponse = {
1182
- fromDto: (dto, itemMapper) => ({
1183
- data: dto.data.map(itemMapper),
1280
+ fromDto: (dto, itemMapper) => PaginatedResponse.fromDtoPage(dto, (items) => items.map(itemMapper)),
1281
+ /**
1282
+ * For a mapper that decides the page as a whole - one that drops items it
1283
+ * cannot map, such as `Offer.listFromDto` - rather than item by item. The
1284
+ * cursors are the wire's either way: dropping an item changes what the
1285
+ * page holds, not where the next page starts.
1286
+ */
1287
+ fromDtoPage: (dto, pageMapper) => ({
1288
+ data: pageMapper(dto.data),
1184
1289
  startingAfter: dto.starting_after ? Cursor(dto.starting_after) : null,
1185
1290
  startingBefore: dto.starting_before ? Cursor(dto.starting_before) : null
1186
1291
  })
@@ -1216,7 +1321,7 @@ async function fetchOffersPage(api, params, clientCreds) {
1216
1321
  Attributes.clientCredentials(clientCreds)
1217
1322
  )
1218
1323
  });
1219
- return PaginatedResponse.fromDto(pageDto, Offer.fromDto);
1324
+ return PaginatedResponse.fromDtoPage(pageDto, Offer.listFromDto);
1220
1325
  }
1221
1326
  async function fetchOfferDetails(api, id, clientCreds) {
1222
1327
  const dto = await api.send({
@@ -1452,6 +1557,151 @@ var ServerRequirementsNamespaceImpl = class extends RequirementsNamespaceImpl {
1452
1557
  // src/universal/api/nabu/config.ts
1453
1558
  var NABU_BASE_URL = "https://asset.coinlist.co";
1454
1559
 
1560
+ // src/universal/api/rpc/public-clients.ts
1561
+ var import_viem3 = require("viem");
1562
+
1563
+ // src/universal/api/rpc/frontline-transport.ts
1564
+ var import_viem2 = require("viem");
1565
+ function frontlineTransport(api, chain, logger = null) {
1566
+ const log = internalLogger(logger, "RPC");
1567
+ let nextId = 0;
1568
+ return (0, import_viem2.custom)(
1569
+ {
1570
+ async request({ method, params }) {
1571
+ const id = ++nextId;
1572
+ return sendRpc({ api, log, chain, id, method, params });
1573
+ }
1574
+ },
1575
+ // The `Sender` below already retries: `requestRetryMiddleware` makes three
1576
+ // attempts at a 5xx and `renewSessionMiddleware` re-sends once after a 401.
1577
+ // viem's own default is `retryCount: 3`, and it applies on top: an
1578
+ // `HttpError` carries no numeric `code`, so `buildRequest` wraps it in
1579
+ // `UnknownRpcError` (`code === -1`) and `shouldRetry` says yes. That reruns
1580
+ // the whole pipeline four times - twelve requests for one `eth_call`, and
1581
+ // with multicall batching one `eth_call` is a screen's worth of reads. The
1582
+ // SDK's retry policy is the one that applies, so viem's is turned off.
1583
+ { retryCount: 0 }
1584
+ );
1585
+ }
1586
+ async function sendRpc({
1587
+ api,
1588
+ log,
1589
+ chain,
1590
+ id,
1591
+ method,
1592
+ params
1593
+ }) {
1594
+ const url = rpcPath(chain);
1595
+ const startedAt = Date.now();
1596
+ log.debug(() => ({
1597
+ msg: "rpc call sent",
1598
+ fields: { id, method, chain, params }
1599
+ }));
1600
+ const response = await sendEnvelope(api, url, {
1601
+ jsonrpc: "2.0",
1602
+ id,
1603
+ method,
1604
+ params
1605
+ });
1606
+ const elapsed = Date.now() - startedAt;
1607
+ if (response.error) {
1608
+ const error = new import_viem2.RpcRequestError({
1609
+ body: { method, params },
1610
+ error: response.error,
1611
+ url
1612
+ });
1613
+ log.warning(
1614
+ () => ({
1615
+ msg: "rpc call rejected",
1616
+ cause: { type: "rpc", reason: "node-rejected" },
1617
+ fields: {
1618
+ method,
1619
+ chain,
1620
+ duration_ms: elapsed,
1621
+ "rpc.error_code": response.error?.code ?? null
1622
+ }
1623
+ }),
1624
+ error
1625
+ );
1626
+ throw error;
1627
+ }
1628
+ log.info(() => ({
1629
+ msg: "rpc call",
1630
+ fields: { method, chain, duration_ms: elapsed }
1631
+ }));
1632
+ return response.result;
1633
+ }
1634
+ function rpcPath(chain) {
1635
+ return `/v1/chains/${encodeURIComponent(chain)}/rpc`;
1636
+ }
1637
+ async function sendEnvelope(api, url, body) {
1638
+ try {
1639
+ return await api.send({
1640
+ method: "POST",
1641
+ url,
1642
+ body,
1643
+ attributes: Attributes.protected()
1644
+ });
1645
+ } catch (error) {
1646
+ if (error instanceof HttpError && isJsonRpcError(error.response.body)) {
1647
+ return error.response.body;
1648
+ }
1649
+ throw error;
1650
+ }
1651
+ }
1652
+ function isJsonRpcError(body) {
1653
+ if (typeof body !== "object" || body === null || !("error" in body)) {
1654
+ return false;
1655
+ }
1656
+ const { error } = body;
1657
+ return typeof error === "object" && error !== null && "code" in error && typeof error.code === "number";
1658
+ }
1659
+
1660
+ // src/universal/core/shared/blockchain/chain.ts
1661
+ var import_chains = require("viem/chains");
1662
+
1663
+ // src/universal/types/blockchain/ui.ts
1664
+ var FormattedAmountAssetUi = (value) => value;
1665
+
1666
+ // src/universal/core/shared/blockchain/chain.ts
1667
+ var VIEM_CHAINS = {
1668
+ ethereum_mainnet: import_chains.mainnet,
1669
+ ethereum_sepolia: import_chains.sepolia,
1670
+ base_mainnet: import_chains.base,
1671
+ base_sepolia: import_chains.baseSepolia
1672
+ };
1673
+ function viemChain(chain) {
1674
+ return VIEM_CHAINS[chain];
1675
+ }
1676
+ function chainFromId(chainId) {
1677
+ const chains = Object.keys(VIEM_CHAINS);
1678
+ const chain = chains.find((c) => String(VIEM_CHAINS[c].id) === chainId);
1679
+ if (!chain) {
1680
+ throw new ValidationError(`Unsupported EIP-155 chain id: "${chainId}"`);
1681
+ }
1682
+ return chain;
1683
+ }
1684
+
1685
+ // src/universal/api/rpc/public-clients.ts
1686
+ function publicClients(api, config, logger = null) {
1687
+ const cache = /* @__PURE__ */ new Map();
1688
+ return (chain) => {
1689
+ const cached = cache.get(chain);
1690
+ if (cached) return cached;
1691
+ const client = (0, import_viem3.createPublicClient)({
1692
+ chain: viemChain(chain),
1693
+ transport: transportFor(api, config?.[chain], chain, logger),
1694
+ batch: { multicall: true }
1695
+ });
1696
+ cache.set(chain, client);
1697
+ return client;
1698
+ };
1699
+ }
1700
+ function transportFor(api, override, chain, logger) {
1701
+ if (override === void 0) return frontlineTransport(api, chain, logger);
1702
+ return typeof override === "string" ? (0, import_viem3.http)(override) : override;
1703
+ }
1704
+
1455
1705
  // src/universal/types/providers/coin-list/token-sale.ts
1456
1706
  var ParticipationId = (value) => value;
1457
1707
  var Blockchain = (value) => value;
@@ -1566,36 +1816,15 @@ var CoinListTokenSaleNamespaceImpl = class {
1566
1816
  };
1567
1817
 
1568
1818
  // src/universal/core/shared/blockchain/formatters.ts
1569
- var import_viem = require("viem");
1570
-
1571
- // src/universal/types/blockchain/ui.ts
1572
- var FormattedAmountAssetUi = (value) => value;
1573
-
1574
- // src/universal/core/shared/blockchain/formatters.ts
1819
+ var import_viem4 = require("viem");
1575
1820
  function formatRawAmount(amount) {
1576
- return (0, import_viem.formatUnits)(amount.raw, amount.decimals);
1821
+ return (0, import_viem4.formatUnits)(amount.raw, amount.decimals);
1577
1822
  }
1578
1823
  var NA_AMOUNT_ASSET_UI = FormattedAmountAssetUi("-");
1579
1824
  var USD_FRACTION_DIGITS = AssetDecimals(2);
1580
1825
 
1581
- // src/universal/core/shared/blockchain/chain.ts
1582
- var CHAIN_IDS = {
1583
- ethereum_mainnet: 1,
1584
- ethereum_sepolia: 11155111,
1585
- base_mainnet: 8453,
1586
- base_sepolia: 84532
1587
- };
1588
- function chainFromId(chainId) {
1589
- const chains = Object.keys(CHAIN_IDS);
1590
- const chain = chains.find((c) => String(CHAIN_IDS[c]) === chainId);
1591
- if (!chain) {
1592
- throw new ValidationError(`Unsupported EIP-155 chain id: "${chainId}"`);
1593
- }
1594
- return chain;
1595
- }
1596
-
1597
1826
  // src/universal/core/shared/blockchain/math.ts
1598
- var import_viem2 = require("viem");
1827
+ var import_viem5 = require("viem");
1599
1828
  function blockchainAmountFromRawOrThrow({
1600
1829
  label,
1601
1830
  raw,
@@ -1912,39 +2141,42 @@ var OndoNamespaceImpl = class {
1912
2141
  };
1913
2142
 
1914
2143
  // src/universal/types/providers/superstate/swap.ts
1915
- var SwapAuthorization = {
1916
- fromDto: (dto) => ({
1917
- authorized: dto.authorized
1918
- })
1919
- };
1920
2144
  var SwapPreview = {
1921
- fromDto: (dto) => ({
1922
- inputAmount: parseUint256(
1923
- BigInt(dto.pay_input_amount),
1924
- "SwapPreview.pay_input_amount"
1925
- ),
1926
- fee: parseUint256(BigInt(dto.fee), "SwapPreview.fee"),
1927
- outputAmount: parseUint256(
1928
- BigInt(dto.receive_output_amount),
1929
- "SwapPreview.receive_output_amount"
1930
- )
2145
+ /** Maps the contract's `Preview { input, fee, output }` struct. */
2146
+ fromContract: (preview) => ({
2147
+ inputAmount: parseUint256(preview.input, "SwapPreview.input"),
2148
+ fee: parseUint256(preview.fee, "SwapPreview.fee"),
2149
+ outputAmount: parseUint256(preview.output, "SwapPreview.output")
1931
2150
  })
1932
2151
  };
2152
+ var PauseFlags = (value) => value;
1933
2153
  var SwapStatus = {
1934
- fromDto: (dto) => ({
1935
- stopped: parseUint256(BigInt(dto.stopped), "SwapStatus.stopped"),
1936
- swapLevel: parseUint256(BigInt(dto.swap_level), "SwapStatus.swap_level")
1937
- })
1938
- };
1939
- var TokenAllowance = {
1940
- fromDto: (dto) => ({
1941
- allowance: parseUint256(BigInt(dto.allowance), "TokenAllowance.allowance")
1942
- })
1943
- };
1944
- var TokenBalance = {
1945
- fromDto: (dto) => ({
1946
- balance: parseUint256(BigInt(dto.balance), "TokenBalance.balance")
1947
- })
2154
+ /**
2155
+ * Maps the contract's `Status { uint32 flags; State state }` struct, where
2156
+ * `State` is `0 = Active | 1 = Paused | 2 = Stopped`.
2157
+ *
2158
+ * `flags` is carried onto the `paused` arm only. On the other two the
2159
+ * contract sets it to a self-identifying marker rather than to information -
2160
+ * so repeating it would invite a caller to read meaning into a constant.
2161
+ *
2162
+ * @throws ValidationError on a `state` outside the enum. A contract that has
2163
+ * grown a fourth state is one the SDK does not model, and guessing `active`
2164
+ * would let a halted swap read as a live one.
2165
+ */
2166
+ fromContract: (status) => {
2167
+ switch (status.state) {
2168
+ case 0:
2169
+ return { state: "active" };
2170
+ case 1:
2171
+ return { state: "paused", pausedLevels: PauseFlags(status.flags) };
2172
+ case 2:
2173
+ return { state: "stopped" };
2174
+ default:
2175
+ throw new ValidationError(
2176
+ `SwapStatus.state: unknown contract state (${status.state})`
2177
+ );
2178
+ }
2179
+ }
1948
2180
  };
1949
2181
  var AllowWalletResponse = {
1950
2182
  fromDto: (dto) => {
@@ -1969,84 +2201,6 @@ var AllowWalletResponse = {
1969
2201
  };
1970
2202
 
1971
2203
  // src/universal/api/frontline/providers/superstate/swap.ts
1972
- async function getSwapAuthorization(api, params) {
1973
- const dto = await api.send({
1974
- method: "GET",
1975
- url: "/v1/wallet/authorized",
1976
- queryParams: {
1977
- chain: params.chain,
1978
- contract_address: params.contractAddress,
1979
- wallet_address: params.walletAddress
1980
- },
1981
- attributes: Attributes.protected()
1982
- });
1983
- return SwapAuthorization.fromDto(dto);
1984
- }
1985
- async function getSwapOutputToken(api, params) {
1986
- const dto = await api.send({
1987
- method: "GET",
1988
- url: "/v1/swap/output-token",
1989
- queryParams: {
1990
- chain: params.chain,
1991
- contract_address: params.contractAddress
1992
- },
1993
- attributes: Attributes.protected()
1994
- });
1995
- return toErc20Asset(dto);
1996
- }
1997
- async function getSwapPreview(api, params) {
1998
- const dto = await api.send({
1999
- method: "GET",
2000
- url: "/v1/swap/preview",
2001
- queryParams: {
2002
- chain: params.chain,
2003
- contract_address: params.contractAddress,
2004
- input_token: params.inputToken,
2005
- amount: params.amount.toString()
2006
- },
2007
- attributes: Attributes.protected()
2008
- });
2009
- return SwapPreview.fromDto(dto);
2010
- }
2011
- async function getSwapStatus(api, params) {
2012
- const dto = await api.send({
2013
- method: "GET",
2014
- url: "/v1/swap/status",
2015
- queryParams: {
2016
- chain: params.chain,
2017
- contract_address: params.contractAddress
2018
- },
2019
- attributes: Attributes.protected()
2020
- });
2021
- return SwapStatus.fromDto(dto);
2022
- }
2023
- async function getTokenAllowance(api, params) {
2024
- const dto = await api.send({
2025
- method: "GET",
2026
- url: "/v1/token/allowance",
2027
- queryParams: {
2028
- chain: params.chain,
2029
- token_address: params.tokenAddress,
2030
- owner: params.owner,
2031
- spender: params.spender
2032
- },
2033
- attributes: Attributes.protected()
2034
- });
2035
- return TokenAllowance.fromDto(dto);
2036
- }
2037
- async function getTokenBalance(api, params) {
2038
- const dto = await api.send({
2039
- method: "GET",
2040
- url: "/v1/token/balance",
2041
- queryParams: {
2042
- chain: params.chain,
2043
- token_address: params.tokenAddress,
2044
- owner: params.owner
2045
- },
2046
- attributes: Attributes.protected()
2047
- });
2048
- return TokenBalance.fromDto(dto);
2049
- }
2050
2204
  async function allowWallet(api, params) {
2051
2205
  const dto = await api.send({
2052
2206
  method: "POST",
@@ -2060,74 +2214,1114 @@ async function allowWallet(api, params) {
2060
2214
  });
2061
2215
  return AllowWalletResponse.fromDto(dto);
2062
2216
  }
2063
- function toErc20Asset(dto) {
2064
- return {
2065
- name: dto.name,
2066
- symbol: AssetSymbol(dto.symbol),
2067
- decimals: AssetDecimals(dto.decimals)
2068
- };
2069
- }
2070
-
2071
- // src/universal/core/checkout/superstate/swap-namespace.ts
2072
- var SuperstateSwapNamespaceImpl = class {
2073
- constructor(ctx) {
2074
- this.ctx = ctx;
2075
- this.log = internalLogger(ctx.logger, "SUPERSTATE");
2076
- }
2077
- async getAuthorization(params) {
2078
- return this.log.wrap("getAuthorization", params, async () => {
2079
- await this.ctx.ensureUserAuthenticated();
2080
- return getSwapAuthorization(this.ctx.api, params);
2081
- });
2082
- }
2083
- async getPreview(params) {
2084
- return this.log.wrap("getPreview", params, async () => {
2085
- await this.ctx.ensureUserAuthenticated();
2086
- return getSwapPreview(this.ctx.api, params);
2087
- });
2088
- }
2089
- async getStatus(params) {
2090
- return this.log.wrap("getStatus", params, async () => {
2091
- await this.ctx.ensureUserAuthenticated();
2092
- return getSwapStatus(this.ctx.api, params);
2093
- });
2094
- }
2095
- async getOutputToken(params) {
2096
- return this.log.wrap("getOutputToken", params, async () => {
2097
- await this.ctx.ensureUserAuthenticated();
2098
- return getSwapOutputToken(this.ctx.api, params);
2099
- });
2100
- }
2101
- async allowWallet(params) {
2102
- return this.log.wrap("allowWallet", params, async () => {
2103
- await this.ctx.ensureUserAuthenticated();
2104
- return allowWallet(this.ctx.api, params);
2105
- });
2106
- }
2107
- };
2108
2217
 
2109
- // src/universal/core/shared/blockchain/erc20/erc20-namespace.ts
2110
- var Erc20NamespaceImpl = class {
2111
- constructor(ctx) {
2112
- this.ctx = ctx;
2113
- this.log = internalLogger(ctx.logger, "ERC20");
2218
+ // src/universal/core/checkout/superstate/blockchain/abi.ts
2219
+ var SUPERSTATE_SWAP_ABI = [
2220
+ {
2221
+ type: "function",
2222
+ name: "KIND",
2223
+ inputs: [],
2224
+ outputs: [
2225
+ {
2226
+ name: "",
2227
+ type: "uint16",
2228
+ internalType: "uint16"
2229
+ }
2230
+ ],
2231
+ stateMutability: "view"
2232
+ },
2233
+ {
2234
+ type: "function",
2235
+ name: "ONE_HUNDRED_P",
2236
+ inputs: [],
2237
+ outputs: [
2238
+ {
2239
+ name: "",
2240
+ type: "uint256",
2241
+ internalType: "uint256"
2242
+ }
2243
+ ],
2244
+ stateMutability: "view"
2245
+ },
2246
+ {
2247
+ type: "function",
2248
+ name: "SWAP_LEVEL",
2249
+ inputs: [],
2250
+ outputs: [
2251
+ {
2252
+ name: "",
2253
+ type: "uint32",
2254
+ internalType: "uint32"
2255
+ }
2256
+ ],
2257
+ stateMutability: "view"
2258
+ },
2259
+ {
2260
+ type: "function",
2261
+ name: "VERSION",
2262
+ inputs: [],
2263
+ outputs: [
2264
+ {
2265
+ name: "",
2266
+ type: "uint16",
2267
+ internalType: "uint16"
2268
+ }
2269
+ ],
2270
+ stateMutability: "view"
2271
+ },
2272
+ {
2273
+ type: "function",
2274
+ name: "authorized",
2275
+ inputs: [
2276
+ {
2277
+ name: "user",
2278
+ type: "address",
2279
+ internalType: "address"
2280
+ }
2281
+ ],
2282
+ outputs: [
2283
+ {
2284
+ name: "",
2285
+ type: "bool",
2286
+ internalType: "bool"
2287
+ }
2288
+ ],
2289
+ stateMutability: "view"
2290
+ },
2291
+ {
2292
+ type: "function",
2293
+ name: "bpp",
2294
+ inputs: [
2295
+ {
2296
+ name: "amount",
2297
+ type: "uint256",
2298
+ internalType: "uint256"
2299
+ }
2300
+ ],
2301
+ outputs: [
2302
+ {
2303
+ name: "",
2304
+ type: "uint256",
2305
+ internalType: "uint256"
2306
+ }
2307
+ ],
2308
+ stateMutability: "view"
2309
+ },
2310
+ {
2311
+ type: "function",
2312
+ name: "bps",
2313
+ inputs: [],
2314
+ outputs: [
2315
+ {
2316
+ name: "",
2317
+ type: "uint256",
2318
+ internalType: "uint256"
2319
+ }
2320
+ ],
2321
+ stateMutability: "view"
2322
+ },
2323
+ {
2324
+ type: "function",
2325
+ name: "cancelOwnershipHandover",
2326
+ inputs: [],
2327
+ outputs: [],
2328
+ stateMutability: "payable"
2329
+ },
2330
+ {
2331
+ type: "function",
2332
+ name: "completeOwnershipHandover",
2333
+ inputs: [
2334
+ {
2335
+ name: "pendingOwner",
2336
+ type: "address",
2337
+ internalType: "address"
2338
+ }
2339
+ ],
2340
+ outputs: [],
2341
+ stateMutability: "payable"
2342
+ },
2343
+ {
2344
+ type: "function",
2345
+ name: "fee",
2346
+ inputs: [
2347
+ {
2348
+ name: "amount",
2349
+ type: "uint256",
2350
+ internalType: "uint256"
2351
+ }
2352
+ ],
2353
+ outputs: [
2354
+ {
2355
+ name: "",
2356
+ type: "uint256",
2357
+ internalType: "uint256"
2358
+ },
2359
+ {
2360
+ name: "",
2361
+ type: "uint256",
2362
+ internalType: "uint256"
2363
+ }
2364
+ ],
2365
+ stateMutability: "view"
2366
+ },
2367
+ {
2368
+ type: "function",
2369
+ name: "id",
2370
+ inputs: [],
2371
+ outputs: [
2372
+ {
2373
+ name: "",
2374
+ type: "bytes32",
2375
+ internalType: "bytes32"
2376
+ }
2377
+ ],
2378
+ stateMutability: "view"
2379
+ },
2380
+ {
2381
+ type: "function",
2382
+ name: "inputTokens",
2383
+ inputs: [
2384
+ {
2385
+ name: "",
2386
+ type: "address",
2387
+ internalType: "address"
2388
+ }
2389
+ ],
2390
+ outputs: [
2391
+ {
2392
+ name: "",
2393
+ type: "bool",
2394
+ internalType: "bool"
2395
+ }
2396
+ ],
2397
+ stateMutability: "view"
2398
+ },
2399
+ {
2400
+ type: "function",
2401
+ name: "outputToken",
2402
+ inputs: [],
2403
+ outputs: [
2404
+ {
2405
+ name: "",
2406
+ type: "address",
2407
+ internalType: "address"
2408
+ }
2409
+ ],
2410
+ stateMutability: "view"
2411
+ },
2412
+ {
2413
+ type: "function",
2414
+ name: "outputTokenBalance",
2415
+ inputs: [],
2416
+ outputs: [
2417
+ {
2418
+ name: "",
2419
+ type: "uint256",
2420
+ internalType: "uint256"
2421
+ }
2422
+ ],
2423
+ stateMutability: "view"
2424
+ },
2425
+ {
2426
+ type: "function",
2427
+ name: "owner",
2428
+ inputs: [],
2429
+ outputs: [
2430
+ {
2431
+ name: "result",
2432
+ type: "address",
2433
+ internalType: "address"
2434
+ }
2435
+ ],
2436
+ stateMutability: "view"
2437
+ },
2438
+ {
2439
+ type: "function",
2440
+ name: "ownershipHandoverExpiresAt",
2441
+ inputs: [
2442
+ {
2443
+ name: "pendingOwner",
2444
+ type: "address",
2445
+ internalType: "address"
2446
+ }
2447
+ ],
2448
+ outputs: [
2449
+ {
2450
+ name: "result",
2451
+ type: "uint256",
2452
+ internalType: "uint256"
2453
+ }
2454
+ ],
2455
+ stateMutability: "view"
2456
+ },
2457
+ {
2458
+ type: "function",
2459
+ name: "pause",
2460
+ inputs: [
2461
+ {
2462
+ name: "level",
2463
+ type: "uint32",
2464
+ internalType: "uint32"
2465
+ }
2466
+ ],
2467
+ outputs: [
2468
+ {
2469
+ name: "",
2470
+ type: "bool",
2471
+ internalType: "bool"
2472
+ }
2473
+ ],
2474
+ stateMutability: "nonpayable"
2475
+ },
2476
+ {
2477
+ type: "function",
2478
+ name: "paused",
2479
+ inputs: [],
2480
+ outputs: [
2481
+ {
2482
+ name: "",
2483
+ type: "uint32",
2484
+ internalType: "uint32"
2485
+ }
2486
+ ],
2487
+ stateMutability: "view"
2488
+ },
2489
+ {
2490
+ type: "function",
2491
+ name: "preview",
2492
+ inputs: [
2493
+ {
2494
+ name: "token",
2495
+ type: "address",
2496
+ internalType: "address"
2497
+ },
2498
+ {
2499
+ name: "amount",
2500
+ type: "uint256",
2501
+ internalType: "uint256"
2502
+ }
2503
+ ],
2504
+ outputs: [
2505
+ {
2506
+ name: "",
2507
+ type: "tuple",
2508
+ internalType: "struct Preview",
2509
+ components: [
2510
+ {
2511
+ name: "input",
2512
+ type: "uint256",
2513
+ internalType: "uint256"
2514
+ },
2515
+ {
2516
+ name: "fee",
2517
+ type: "uint256",
2518
+ internalType: "uint256"
2519
+ },
2520
+ {
2521
+ name: "output",
2522
+ type: "uint256",
2523
+ internalType: "uint256"
2524
+ }
2525
+ ]
2526
+ }
2527
+ ],
2528
+ stateMutability: "view"
2529
+ },
2530
+ {
2531
+ type: "function",
2532
+ name: "renounceOwnership",
2533
+ inputs: [],
2534
+ outputs: [],
2535
+ stateMutability: "payable"
2536
+ },
2537
+ {
2538
+ type: "function",
2539
+ name: "requestOwnershipHandover",
2540
+ inputs: [],
2541
+ outputs: [],
2542
+ stateMutability: "payable"
2543
+ },
2544
+ {
2545
+ type: "function",
2546
+ name: "setBps",
2547
+ inputs: [
2548
+ {
2549
+ name: "points",
2550
+ type: "uint256",
2551
+ internalType: "uint256"
2552
+ }
2553
+ ],
2554
+ outputs: [
2555
+ {
2556
+ name: "",
2557
+ type: "bool",
2558
+ internalType: "bool"
2559
+ }
2560
+ ],
2561
+ stateMutability: "nonpayable"
2562
+ },
2563
+ {
2564
+ type: "function",
2565
+ name: "setInputToken",
2566
+ inputs: [
2567
+ {
2568
+ name: "token",
2569
+ type: "address",
2570
+ internalType: "address"
2571
+ },
2572
+ {
2573
+ name: "val",
2574
+ type: "bool",
2575
+ internalType: "bool"
2576
+ }
2577
+ ],
2578
+ outputs: [
2579
+ {
2580
+ name: "",
2581
+ type: "bool",
2582
+ internalType: "bool"
2583
+ }
2584
+ ],
2585
+ stateMutability: "nonpayable"
2586
+ },
2587
+ {
2588
+ type: "function",
2589
+ name: "status",
2590
+ inputs: [],
2591
+ outputs: [
2592
+ {
2593
+ name: "",
2594
+ type: "tuple",
2595
+ internalType: "struct Status",
2596
+ components: [
2597
+ {
2598
+ name: "flags",
2599
+ type: "uint32",
2600
+ internalType: "uint32"
2601
+ },
2602
+ {
2603
+ name: "state",
2604
+ type: "uint8",
2605
+ internalType: "enum State"
2606
+ }
2607
+ ]
2608
+ }
2609
+ ],
2610
+ stateMutability: "view"
2611
+ },
2612
+ {
2613
+ type: "function",
2614
+ name: "stop",
2615
+ inputs: [],
2616
+ outputs: [
2617
+ {
2618
+ name: "",
2619
+ type: "bool",
2620
+ internalType: "bool"
2621
+ }
2622
+ ],
2623
+ stateMutability: "nonpayable"
2624
+ },
2625
+ {
2626
+ type: "function",
2627
+ name: "stopped",
2628
+ inputs: [],
2629
+ outputs: [
2630
+ {
2631
+ name: "",
2632
+ type: "bool",
2633
+ internalType: "bool"
2634
+ }
2635
+ ],
2636
+ stateMutability: "view"
2637
+ },
2638
+ {
2639
+ type: "function",
2640
+ name: "swap",
2641
+ inputs: [
2642
+ {
2643
+ name: "token",
2644
+ type: "address",
2645
+ internalType: "address"
2646
+ },
2647
+ {
2648
+ name: "amount",
2649
+ type: "uint256",
2650
+ internalType: "uint256"
2651
+ },
2652
+ {
2653
+ name: "slip",
2654
+ type: "uint256",
2655
+ internalType: "uint256"
2656
+ }
2657
+ ],
2658
+ outputs: [
2659
+ {
2660
+ name: "",
2661
+ type: "uint256",
2662
+ internalType: "uint256"
2663
+ }
2664
+ ],
2665
+ stateMutability: "nonpayable"
2666
+ },
2667
+ {
2668
+ type: "function",
2669
+ name: "tokenBalance",
2670
+ inputs: [
2671
+ {
2672
+ name: "token",
2673
+ type: "address",
2674
+ internalType: "address"
2675
+ }
2676
+ ],
2677
+ outputs: [
2678
+ {
2679
+ name: "",
2680
+ type: "uint256",
2681
+ internalType: "uint256"
2682
+ }
2683
+ ],
2684
+ stateMutability: "view"
2685
+ },
2686
+ {
2687
+ type: "function",
2688
+ name: "totals",
2689
+ inputs: [
2690
+ {
2691
+ name: "user",
2692
+ type: "address",
2693
+ internalType: "address"
2694
+ },
2695
+ {
2696
+ name: "token",
2697
+ type: "address",
2698
+ internalType: "address"
2699
+ }
2700
+ ],
2701
+ outputs: [
2702
+ {
2703
+ name: "",
2704
+ type: "tuple",
2705
+ internalType: "struct SwapTotal",
2706
+ components: [
2707
+ {
2708
+ name: "inputSum",
2709
+ type: "uint256",
2710
+ internalType: "uint256"
2711
+ },
2712
+ {
2713
+ name: "feeSum",
2714
+ type: "uint256",
2715
+ internalType: "uint256"
2716
+ },
2717
+ {
2718
+ name: "outputSum",
2719
+ type: "uint256",
2720
+ internalType: "uint256"
2721
+ },
2722
+ {
2723
+ name: "count",
2724
+ type: "uint256",
2725
+ internalType: "uint256"
2726
+ }
2727
+ ]
2728
+ }
2729
+ ],
2730
+ stateMutability: "view"
2731
+ },
2732
+ {
2733
+ type: "function",
2734
+ name: "totals",
2735
+ inputs: [
2736
+ {
2737
+ name: "token",
2738
+ type: "address",
2739
+ internalType: "address"
2740
+ }
2741
+ ],
2742
+ outputs: [
2743
+ {
2744
+ name: "",
2745
+ type: "tuple",
2746
+ internalType: "struct SwapTotal",
2747
+ components: [
2748
+ {
2749
+ name: "inputSum",
2750
+ type: "uint256",
2751
+ internalType: "uint256"
2752
+ },
2753
+ {
2754
+ name: "feeSum",
2755
+ type: "uint256",
2756
+ internalType: "uint256"
2757
+ },
2758
+ {
2759
+ name: "outputSum",
2760
+ type: "uint256",
2761
+ internalType: "uint256"
2762
+ },
2763
+ {
2764
+ name: "count",
2765
+ type: "uint256",
2766
+ internalType: "uint256"
2767
+ }
2768
+ ]
2769
+ }
2770
+ ],
2771
+ stateMutability: "view"
2772
+ },
2773
+ {
2774
+ type: "function",
2775
+ name: "transfer",
2776
+ inputs: [
2777
+ {
2778
+ name: "to",
2779
+ type: "address",
2780
+ internalType: "address"
2781
+ },
2782
+ {
2783
+ name: "amount",
2784
+ type: "uint256",
2785
+ internalType: "uint256"
2786
+ }
2787
+ ],
2788
+ outputs: [
2789
+ {
2790
+ name: "",
2791
+ type: "bool",
2792
+ internalType: "bool"
2793
+ }
2794
+ ],
2795
+ stateMutability: "nonpayable"
2796
+ },
2797
+ {
2798
+ type: "function",
2799
+ name: "transfer",
2800
+ inputs: [
2801
+ {
2802
+ name: "to",
2803
+ type: "address",
2804
+ internalType: "address"
2805
+ },
2806
+ {
2807
+ name: "token",
2808
+ type: "address",
2809
+ internalType: "address"
2810
+ },
2811
+ {
2812
+ name: "amount",
2813
+ type: "uint256",
2814
+ internalType: "uint256"
2815
+ }
2816
+ ],
2817
+ outputs: [
2818
+ {
2819
+ name: "",
2820
+ type: "bool",
2821
+ internalType: "bool"
2822
+ }
2823
+ ],
2824
+ stateMutability: "nonpayable"
2825
+ },
2826
+ {
2827
+ type: "function",
2828
+ name: "transferOwnership",
2829
+ inputs: [
2830
+ {
2831
+ name: "newOwner",
2832
+ type: "address",
2833
+ internalType: "address"
2834
+ }
2835
+ ],
2836
+ outputs: [],
2837
+ stateMutability: "payable"
2838
+ },
2839
+ {
2840
+ type: "event",
2841
+ name: "BpsUpdated",
2842
+ inputs: [
2843
+ {
2844
+ name: "prev",
2845
+ type: "uint256",
2846
+ indexed: false,
2847
+ internalType: "uint256"
2848
+ },
2849
+ {
2850
+ name: "next",
2851
+ type: "uint256",
2852
+ indexed: false,
2853
+ internalType: "uint256"
2854
+ }
2855
+ ],
2856
+ anonymous: false
2857
+ },
2858
+ {
2859
+ type: "event",
2860
+ name: "InputTokenUpdated",
2861
+ inputs: [
2862
+ {
2863
+ name: "token",
2864
+ type: "address",
2865
+ indexed: true,
2866
+ internalType: "address"
2867
+ },
2868
+ {
2869
+ name: "prev",
2870
+ type: "bool",
2871
+ indexed: false,
2872
+ internalType: "bool"
2873
+ },
2874
+ {
2875
+ name: "next",
2876
+ type: "bool",
2877
+ indexed: false,
2878
+ internalType: "bool"
2879
+ }
2880
+ ],
2881
+ anonymous: false
2882
+ },
2883
+ {
2884
+ type: "event",
2885
+ name: "OwnershipHandoverCanceled",
2886
+ inputs: [
2887
+ {
2888
+ name: "pendingOwner",
2889
+ type: "address",
2890
+ indexed: true,
2891
+ internalType: "address"
2892
+ }
2893
+ ],
2894
+ anonymous: false
2895
+ },
2896
+ {
2897
+ type: "event",
2898
+ name: "OwnershipHandoverRequested",
2899
+ inputs: [
2900
+ {
2901
+ name: "pendingOwner",
2902
+ type: "address",
2903
+ indexed: true,
2904
+ internalType: "address"
2905
+ }
2906
+ ],
2907
+ anonymous: false
2908
+ },
2909
+ {
2910
+ type: "event",
2911
+ name: "OwnershipTransferred",
2912
+ inputs: [
2913
+ {
2914
+ name: "oldOwner",
2915
+ type: "address",
2916
+ indexed: true,
2917
+ internalType: "address"
2918
+ },
2919
+ {
2920
+ name: "newOwner",
2921
+ type: "address",
2922
+ indexed: true,
2923
+ internalType: "address"
2924
+ }
2925
+ ],
2926
+ anonymous: false
2927
+ },
2928
+ {
2929
+ type: "event",
2930
+ name: "Paused",
2931
+ inputs: [
2932
+ {
2933
+ name: "previous",
2934
+ type: "uint32",
2935
+ indexed: false,
2936
+ internalType: "uint32"
2937
+ },
2938
+ {
2939
+ name: "next",
2940
+ type: "uint32",
2941
+ indexed: false,
2942
+ internalType: "uint32"
2943
+ }
2944
+ ],
2945
+ anonymous: false
2946
+ },
2947
+ {
2948
+ type: "event",
2949
+ name: "Stopped",
2950
+ inputs: [],
2951
+ anonymous: false
2952
+ },
2953
+ {
2954
+ type: "event",
2955
+ name: "Swapped",
2956
+ inputs: [
2957
+ {
2958
+ name: "user",
2959
+ type: "address",
2960
+ indexed: true,
2961
+ internalType: "address"
2962
+ },
2963
+ {
2964
+ name: "inputToken",
2965
+ type: "address",
2966
+ indexed: true,
2967
+ internalType: "address"
2968
+ },
2969
+ {
2970
+ name: "outputToken",
2971
+ type: "address",
2972
+ indexed: true,
2973
+ internalType: "address"
2974
+ },
2975
+ {
2976
+ name: "inputAmount",
2977
+ type: "uint256",
2978
+ indexed: false,
2979
+ internalType: "uint256"
2980
+ },
2981
+ {
2982
+ name: "fee",
2983
+ type: "uint256",
2984
+ indexed: false,
2985
+ internalType: "uint256"
2986
+ },
2987
+ {
2988
+ name: "outputAmount",
2989
+ type: "uint256",
2990
+ indexed: false,
2991
+ internalType: "uint256"
2992
+ }
2993
+ ],
2994
+ anonymous: false
2995
+ },
2996
+ {
2997
+ type: "event",
2998
+ name: "Transferred",
2999
+ inputs: [
3000
+ {
3001
+ name: "to",
3002
+ type: "address",
3003
+ indexed: true,
3004
+ internalType: "address"
3005
+ },
3006
+ {
3007
+ name: "token",
3008
+ type: "address",
3009
+ indexed: true,
3010
+ internalType: "address"
3011
+ },
3012
+ {
3013
+ name: "amount",
3014
+ type: "uint256",
3015
+ indexed: false,
3016
+ internalType: "uint256"
3017
+ }
3018
+ ],
3019
+ anonymous: false
3020
+ },
3021
+ {
3022
+ type: "error",
3023
+ name: "AlreadyInitialized",
3024
+ inputs: []
3025
+ },
3026
+ {
3027
+ type: "error",
3028
+ name: "InsufficientAmount",
3029
+ inputs: []
3030
+ },
3031
+ {
3032
+ type: "error",
3033
+ name: "InvalidAddress",
3034
+ inputs: []
3035
+ },
3036
+ {
3037
+ type: "error",
3038
+ name: "InvalidAmount",
3039
+ inputs: []
3040
+ },
3041
+ {
3042
+ type: "error",
3043
+ name: "IsPaused",
3044
+ inputs: [
3045
+ {
3046
+ name: "level",
3047
+ type: "uint32",
3048
+ internalType: "uint32"
3049
+ }
3050
+ ]
3051
+ },
3052
+ {
3053
+ type: "error",
3054
+ name: "IsStopped",
3055
+ inputs: []
3056
+ },
3057
+ {
3058
+ type: "error",
3059
+ name: "NewOwnerIsZeroAddress",
3060
+ inputs: []
3061
+ },
3062
+ {
3063
+ type: "error",
3064
+ name: "NoHandoverRequest",
3065
+ inputs: []
3066
+ },
3067
+ {
3068
+ type: "error",
3069
+ name: "SwapFailed",
3070
+ inputs: [
3071
+ {
3072
+ name: "user",
3073
+ type: "address",
3074
+ internalType: "address"
3075
+ },
3076
+ {
3077
+ name: "token",
3078
+ type: "address",
3079
+ internalType: "address"
3080
+ }
3081
+ ]
3082
+ },
3083
+ {
3084
+ type: "error",
3085
+ name: "Unauthorized",
3086
+ inputs: []
2114
3087
  }
2115
- async getAllowance(params) {
2116
- return this.log.wrap("getAllowance", params, async () => {
3088
+ ];
3089
+
3090
+ // src/universal/core/shared/blockchain/erc20/abi.ts
3091
+ var ERC20_ABI = [
3092
+ {
3093
+ type: "function",
3094
+ name: "allowance",
3095
+ inputs: [
3096
+ { name: "owner", type: "address" },
3097
+ { name: "spender", type: "address" }
3098
+ ],
3099
+ outputs: [{ name: "", type: "uint256" }],
3100
+ stateMutability: "view"
3101
+ },
3102
+ {
3103
+ type: "function",
3104
+ name: "approve",
3105
+ inputs: [
3106
+ { name: "spender", type: "address" },
3107
+ { name: "amount", type: "uint256" }
3108
+ ],
3109
+ outputs: [{ name: "", type: "bool" }],
3110
+ stateMutability: "nonpayable"
3111
+ },
3112
+ {
3113
+ type: "function",
3114
+ name: "balanceOf",
3115
+ inputs: [{ name: "account", type: "address" }],
3116
+ outputs: [{ name: "", type: "uint256" }],
3117
+ stateMutability: "view"
3118
+ },
3119
+ {
3120
+ type: "function",
3121
+ name: "decimals",
3122
+ inputs: [],
3123
+ outputs: [{ name: "", type: "uint8" }],
3124
+ stateMutability: "view"
3125
+ },
3126
+ {
3127
+ type: "function",
3128
+ name: "name",
3129
+ inputs: [],
3130
+ outputs: [{ name: "", type: "string" }],
3131
+ stateMutability: "view"
3132
+ },
3133
+ {
3134
+ type: "function",
3135
+ name: "symbol",
3136
+ inputs: [],
3137
+ outputs: [{ name: "", type: "string" }],
3138
+ stateMutability: "view"
3139
+ },
3140
+ {
3141
+ type: "function",
3142
+ name: "totalSupply",
3143
+ inputs: [],
3144
+ outputs: [{ name: "", type: "uint256" }],
3145
+ stateMutability: "view"
3146
+ },
3147
+ {
3148
+ type: "function",
3149
+ name: "transfer",
3150
+ inputs: [
3151
+ { name: "recipient", type: "address" },
3152
+ { name: "amount", type: "uint256" }
3153
+ ],
3154
+ outputs: [{ name: "", type: "bool" }],
3155
+ stateMutability: "nonpayable"
3156
+ },
3157
+ {
3158
+ type: "function",
3159
+ name: "transferFrom",
3160
+ inputs: [
3161
+ { name: "sender", type: "address" },
3162
+ { name: "recipient", type: "address" },
3163
+ { name: "amount", type: "uint256" }
3164
+ ],
3165
+ outputs: [{ name: "", type: "bool" }],
3166
+ stateMutability: "nonpayable"
3167
+ },
3168
+ {
3169
+ type: "event",
3170
+ name: "Approval",
3171
+ inputs: [
3172
+ { name: "owner", type: "address", indexed: true },
3173
+ { name: "spender", type: "address", indexed: true },
3174
+ { name: "value", type: "uint256", indexed: false }
3175
+ ],
3176
+ anonymous: false
3177
+ },
3178
+ {
3179
+ type: "event",
3180
+ name: "Transfer",
3181
+ inputs: [
3182
+ { name: "from", type: "address", indexed: true },
3183
+ { name: "to", type: "address", indexed: true },
3184
+ { name: "value", type: "uint256", indexed: false }
3185
+ ],
3186
+ anonymous: false
3187
+ }
3188
+ ];
3189
+
3190
+ // src/universal/api/rpc/providers/superstate/swap.ts
3191
+ async function getSwapAuthorization(clients, params) {
3192
+ return clients(params.chain).readContract({
3193
+ address: params.contractAddress,
3194
+ abi: SUPERSTATE_SWAP_ABI,
3195
+ functionName: "authorized",
3196
+ args: [params.walletAddress]
3197
+ });
3198
+ }
3199
+ async function getSwapPreview(clients, params) {
3200
+ const preview = await clients(params.chain).readContract({
3201
+ address: params.contractAddress,
3202
+ abi: SUPERSTATE_SWAP_ABI,
3203
+ functionName: "preview",
3204
+ args: [params.inputToken, params.amount]
3205
+ });
3206
+ return SwapPreview.fromContract(preview);
3207
+ }
3208
+ async function getSwapStatus(clients, params) {
3209
+ const status = await clients(params.chain).readContract({
3210
+ address: params.contractAddress,
3211
+ abi: SUPERSTATE_SWAP_ABI,
3212
+ functionName: "status"
3213
+ });
3214
+ return SwapStatus.fromContract(status);
3215
+ }
3216
+ async function getSwapOutputToken(clients, params) {
3217
+ const client = clients(params.chain);
3218
+ const tokenAddress = await client.readContract({
3219
+ address: params.contractAddress,
3220
+ abi: SUPERSTATE_SWAP_ABI,
3221
+ functionName: "outputToken"
3222
+ });
3223
+ const token = { address: EvmContractAddress(tokenAddress), abi: ERC20_ABI };
3224
+ const [name, symbol, decimals] = await client.multicall({
3225
+ contracts: [
3226
+ { ...token, functionName: "name" },
3227
+ { ...token, functionName: "symbol" },
3228
+ { ...token, functionName: "decimals" }
3229
+ ],
3230
+ allowFailure: false
3231
+ });
3232
+ return {
3233
+ name,
3234
+ symbol: AssetSymbol(symbol),
3235
+ decimals: AssetDecimals(decimals)
3236
+ };
3237
+ }
3238
+
3239
+ // src/universal/core/checkout/superstate/swap-namespace.ts
3240
+ var SuperstateSwapNamespaceImpl = class {
3241
+ constructor(ctx) {
3242
+ this.ctx = ctx;
3243
+ this.log = internalLogger(ctx.logger, "SUPERSTATE");
3244
+ }
3245
+ async getAuthorization(params) {
3246
+ return this.log.wrap(
3247
+ "getAuthorization",
3248
+ params,
3249
+ async () => getSwapAuthorization(this.ctx.rpc, params)
3250
+ );
3251
+ }
3252
+ async getPreview(params) {
3253
+ return this.log.wrap(
3254
+ "getPreview",
3255
+ params,
3256
+ async () => getSwapPreview(this.ctx.rpc, params)
3257
+ );
3258
+ }
3259
+ async getStatus(params) {
3260
+ return this.log.wrap(
3261
+ "getStatus",
3262
+ params,
3263
+ async () => getSwapStatus(this.ctx.rpc, params)
3264
+ );
3265
+ }
3266
+ async getOutputToken(params) {
3267
+ return this.log.wrap(
3268
+ "getOutputToken",
3269
+ params,
3270
+ async () => getSwapOutputToken(this.ctx.rpc, params)
3271
+ );
3272
+ }
3273
+ async allowWallet(params) {
3274
+ return this.log.wrap("allowWallet", params, async () => {
2117
3275
  await this.ctx.ensureUserAuthenticated();
2118
- return getTokenAllowance(this.ctx.api, params);
3276
+ return allowWallet(this.ctx.api, params);
2119
3277
  });
2120
3278
  }
3279
+ };
3280
+
3281
+ // src/universal/api/rpc/erc20.ts
3282
+ async function getTokenAllowance(clients, params) {
3283
+ const allowance = await clients(params.chain).readContract({
3284
+ address: params.tokenAddress,
3285
+ abi: ERC20_ABI,
3286
+ functionName: "allowance",
3287
+ args: [params.owner, params.spender]
3288
+ });
3289
+ return parseUint256(allowance, "allowance");
3290
+ }
3291
+ async function getTokenBalance(clients, params) {
3292
+ const balance = await clients(params.chain).readContract({
3293
+ address: params.tokenAddress,
3294
+ abi: ERC20_ABI,
3295
+ functionName: "balanceOf",
3296
+ args: [params.owner]
3297
+ });
3298
+ return parseUint256(balance, "balanceOf");
3299
+ }
3300
+
3301
+ // src/universal/core/shared/blockchain/erc20/erc20-namespace.ts
3302
+ var Erc20NamespaceImpl = class {
3303
+ constructor(ctx) {
3304
+ this.ctx = ctx;
3305
+ this.log = internalLogger(ctx.logger, "ERC20");
3306
+ }
3307
+ async getAllowance(params) {
3308
+ return this.log.wrap(
3309
+ "getAllowance",
3310
+ params,
3311
+ async () => getTokenAllowance(this.ctx.rpc, params)
3312
+ );
3313
+ }
2121
3314
  async getBalance(params) {
2122
- return this.log.wrap("getBalance", params, async () => {
2123
- await this.ctx.ensureUserAuthenticated();
2124
- return getTokenBalance(this.ctx.api, params);
2125
- });
3315
+ return this.log.wrap(
3316
+ "getBalance",
3317
+ params,
3318
+ async () => getTokenBalance(this.ctx.rpc, params)
3319
+ );
2126
3320
  }
2127
3321
  };
2128
3322
 
2129
3323
  // src/universal/api/nabu/tokens.ts
2130
- var import_viem3 = require("viem");
3324
+ var import_viem6 = require("viem");
2131
3325
 
2132
3326
  // src/universal/types/token-metadata.ts
2133
3327
  var TokenLogoUrl = (value) => value;
@@ -2297,7 +3491,7 @@ function assertOk(response) {
2297
3491
  }
2298
3492
  function checksummed(address) {
2299
3493
  try {
2300
- return (0, import_viem3.getAddress)(address);
3494
+ return (0, import_viem6.getAddress)(address);
2301
3495
  } catch (_) {
2302
3496
  throw new ValidationError(`Invalid EVM contract address: "${address}"`);
2303
3497
  }
@@ -2496,6 +3690,7 @@ var CoinListServerImpl = class {
2496
3690
  });
2497
3691
  const ctx = {
2498
3692
  api: this.api,
3693
+ rpc: publicClients(this.api, _config.rpc, _config.logger ?? null),
2499
3694
  logger,
2500
3695
  ensureUserAuthenticated: () => this.ensureAuthenticated(void 0),
2501
3696
  ensureAuthenticated: (clientCreds) => this.ensureAuthenticated(clientCreds)