@coinlist-co/react 0.12.1-rc.14ac67e → 0.12.1-rc.6b77fc6

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 (34) hide show
  1. package/dist/{chunk-3ATIDGVR.js → chunk-2YEJXE2V.js} +1868 -841
  2. package/dist/chunk-2YEJXE2V.js.map +1 -0
  3. package/dist/{chunk-SOMNMOBU.js → chunk-DOSABR7Q.js} +136 -10
  4. package/dist/chunk-DOSABR7Q.js.map +1 -0
  5. package/dist/chunk-DX4VTV7L.js +357 -0
  6. package/dist/chunk-DX4VTV7L.js.map +1 -0
  7. package/dist/client/index.cjs +9788 -8780
  8. package/dist/client/index.cjs.map +1 -1
  9. package/dist/client/index.d.cts +469 -274
  10. package/dist/client/index.d.ts +469 -274
  11. package/dist/client/index.js +4581 -4406
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/{collections-DNbBE6Pk.d.cts → collections-C6b-rJpx.d.ts} +1 -1
  14. package/dist/{collections-DVCh4jUp.d.ts → collections-UYVlXbEh.d.cts} +1 -1
  15. package/dist/server/index.cjs +1421 -283
  16. package/dist/server/index.cjs.map +1 -1
  17. package/dist/server/index.d.cts +4 -4
  18. package/dist/server/index.d.ts +4 -4
  19. package/dist/server/index.js +6 -4
  20. package/dist/server/index.js.map +1 -1
  21. package/dist/{config-DFYAM0GD.d.cts → tokens-namespace-C-BxcYMj.d.cts} +392 -200
  22. package/dist/{config-DFYAM0GD.d.ts → tokens-namespace-C-BxcYMj.d.ts} +392 -200
  23. package/dist/{shared → universal}/index.cjs +1629 -918
  24. package/dist/universal/index.cjs.map +1 -0
  25. package/dist/{shared → universal}/index.d.cts +932 -550
  26. package/dist/{shared → universal}/index.d.ts +932 -550
  27. package/dist/{shared → universal}/index.js +18 -14
  28. package/package.json +6 -5
  29. package/dist/chunk-2XBPKC4C.js +0 -667
  30. package/dist/chunk-2XBPKC4C.js.map +0 -1
  31. package/dist/chunk-3ATIDGVR.js.map +0 -1
  32. package/dist/chunk-SOMNMOBU.js.map +0 -1
  33. package/dist/shared/index.cjs.map +0 -1
  34. /package/dist/{shared → universal}/index.js.map +0 -0
@@ -1,4 +1,4 @@
1
- // src/shared/api/http-attributes.ts
1
+ // src/universal/api/http-attributes.ts
2
2
  var empty = {};
3
3
  var concat = (left, right) => ({
4
4
  ...left,
@@ -53,7 +53,7 @@ var Attributes = {
53
53
  getRequestId
54
54
  };
55
55
 
56
- // src/shared/api/http.ts
56
+ // src/universal/api/http.ts
57
57
  var HttpError = class extends Error {
58
58
  constructor(response) {
59
59
  super(`Request failed with ${response.status} status`);
@@ -177,7 +177,7 @@ var Request = {
177
177
  concatAttributes
178
178
  };
179
179
 
180
- // src/shared/types/errors.ts
180
+ // src/universal/types/errors.ts
181
181
  var NotImplementedError = class extends Error {
182
182
  constructor(message = "Not implemented yet") {
183
183
  super(message);
@@ -209,7 +209,107 @@ var MathError = class extends Error {
209
209
  }
210
210
  };
211
211
 
212
- // src/shared/api/pagination.ts
212
+ // src/universal/core/shared/blockchain/erc20/abi.ts
213
+ var ERC20_ABI = [
214
+ {
215
+ type: "function",
216
+ name: "allowance",
217
+ inputs: [
218
+ { name: "owner", type: "address" },
219
+ { name: "spender", type: "address" }
220
+ ],
221
+ outputs: [{ name: "", type: "uint256" }],
222
+ stateMutability: "view"
223
+ },
224
+ {
225
+ type: "function",
226
+ name: "approve",
227
+ inputs: [
228
+ { name: "spender", type: "address" },
229
+ { name: "amount", type: "uint256" }
230
+ ],
231
+ outputs: [{ name: "", type: "bool" }],
232
+ stateMutability: "nonpayable"
233
+ },
234
+ {
235
+ type: "function",
236
+ name: "balanceOf",
237
+ inputs: [{ name: "account", type: "address" }],
238
+ outputs: [{ name: "", type: "uint256" }],
239
+ stateMutability: "view"
240
+ },
241
+ {
242
+ type: "function",
243
+ name: "decimals",
244
+ inputs: [],
245
+ outputs: [{ name: "", type: "uint8" }],
246
+ stateMutability: "view"
247
+ },
248
+ {
249
+ type: "function",
250
+ name: "name",
251
+ inputs: [],
252
+ outputs: [{ name: "", type: "string" }],
253
+ stateMutability: "view"
254
+ },
255
+ {
256
+ type: "function",
257
+ name: "symbol",
258
+ inputs: [],
259
+ outputs: [{ name: "", type: "string" }],
260
+ stateMutability: "view"
261
+ },
262
+ {
263
+ type: "function",
264
+ name: "totalSupply",
265
+ inputs: [],
266
+ outputs: [{ name: "", type: "uint256" }],
267
+ stateMutability: "view"
268
+ },
269
+ {
270
+ type: "function",
271
+ name: "transfer",
272
+ inputs: [
273
+ { name: "recipient", type: "address" },
274
+ { name: "amount", type: "uint256" }
275
+ ],
276
+ outputs: [{ name: "", type: "bool" }],
277
+ stateMutability: "nonpayable"
278
+ },
279
+ {
280
+ type: "function",
281
+ name: "transferFrom",
282
+ inputs: [
283
+ { name: "sender", type: "address" },
284
+ { name: "recipient", type: "address" },
285
+ { name: "amount", type: "uint256" }
286
+ ],
287
+ outputs: [{ name: "", type: "bool" }],
288
+ stateMutability: "nonpayable"
289
+ },
290
+ {
291
+ type: "event",
292
+ name: "Approval",
293
+ inputs: [
294
+ { name: "owner", type: "address", indexed: true },
295
+ { name: "spender", type: "address", indexed: true },
296
+ { name: "value", type: "uint256", indexed: false }
297
+ ],
298
+ anonymous: false
299
+ },
300
+ {
301
+ type: "event",
302
+ name: "Transfer",
303
+ inputs: [
304
+ { name: "from", type: "address", indexed: true },
305
+ { name: "to", type: "address", indexed: true },
306
+ { name: "value", type: "uint256", indexed: false }
307
+ ],
308
+ anonymous: false
309
+ }
310
+ ];
311
+
312
+ // src/universal/api/pagination.ts
213
313
  async function fetchAllPages(fetchPage, baseParams) {
214
314
  const items = [];
215
315
  let cursor = null;
@@ -225,7 +325,44 @@ async function fetchAllPages(fetchPage, baseParams) {
225
325
  return items;
226
326
  }
227
327
 
228
- // src/shared/types/blockchain/core.ts
328
+ // src/universal/types/pagination.ts
329
+ var Cursor = (value) => value;
330
+ var PaginatedResponse = {
331
+ fromDto: (dto, itemMapper) => ({
332
+ data: dto.data.map(itemMapper),
333
+ startingAfter: dto.starting_after ? Cursor(dto.starting_after) : null,
334
+ startingBefore: dto.starting_before ? Cursor(dto.starting_before) : null
335
+ })
336
+ };
337
+ var PaginationParams = {
338
+ toQueryParams: (params) => {
339
+ const queryParams = {};
340
+ if (params.after) {
341
+ queryParams.starting_after = params.after;
342
+ }
343
+ if (params.before) {
344
+ queryParams.starting_before = params.before;
345
+ }
346
+ if (params.limit) {
347
+ queryParams.limit = params.limit;
348
+ }
349
+ return queryParams;
350
+ }
351
+ };
352
+
353
+ // src/universal/types/asset.ts
354
+ var AssetId = (value) => value;
355
+ var AssetCode = (value) => value;
356
+ var Asset = {
357
+ fromDto: (dto) => ({
358
+ id: AssetId(dto.id),
359
+ code: AssetCode(dto.code),
360
+ name: dto.name,
361
+ fractionalDigits: dto.fractional_digits
362
+ })
363
+ };
364
+
365
+ // src/universal/types/blockchain/core.ts
229
366
  var ETHEREUM_CHAINS = {
230
367
  ethereum_mainnet: true,
231
368
  ethereum_sepolia: true,
@@ -248,8 +385,9 @@ var SolanaChain = (value) => {
248
385
  }
249
386
  return value;
250
387
  };
388
+ var isChain = (value) => Object.keys(ETHEREUM_CHAINS).includes(value) || Object.keys(SOLANA_CHAINS).includes(value);
251
389
  var Chain = (value) => {
252
- if (!Object.keys(ETHEREUM_CHAINS).includes(value) && !Object.keys(SOLANA_CHAINS).includes(value)) {
390
+ if (!isChain(value)) {
253
391
  throw new ValidationError(`Unsupported chain: "${value}"`);
254
392
  }
255
393
  return value;
@@ -321,226 +459,316 @@ var StablecoinSymbol = (value) => value;
321
459
  var KnownAssetSymbol = StablecoinSymbol;
322
460
  var Bps = (value) => value;
323
461
 
324
- // src/shared/types/blockchain/ui.ts
325
- var FormattedAmountUi = (value) => value;
326
- var FormattedPercentUi = (value) => value;
327
- var TxExplorerUrl = (value) => value;
328
- var ShortenedWalletAddress = (value) => value;
329
- var FormattedAmountAssetUi = (value) => value;
330
- var AssetIconUrl = (value) => value;
331
-
332
- // src/shared/core/blockchain/chain.ts
333
- var CHAIN_IDS = {
334
- ethereum_mainnet: 1,
335
- ethereum_sepolia: 11155111,
336
- base_mainnet: 8453,
337
- base_sepolia: 84532
462
+ // src/universal/types/offer.ts
463
+ var OfferId = (value) => value;
464
+ var OfferSlug = (value) => value;
465
+ var Offer = {
466
+ fromDto: (dto) => {
467
+ if (!Array.isArray(dto.tokens)) {
468
+ throw new ValidationError(
469
+ `Offer.tokens: expected an array, got ${typeof dto.tokens}`
470
+ );
471
+ }
472
+ return {
473
+ id: OfferId(dto.id),
474
+ slug: OfferSlug(dto.slug),
475
+ type: dto.type,
476
+ tagline: dto.tagline,
477
+ bannerUrl: dto.banner_url,
478
+ logoUrl: dto.logo_url,
479
+ startsAt: new Date(dto.starts_at),
480
+ endsAt: dto.ends_at ? new Date(dto.ends_at) : null,
481
+ tokens: OfferToken.listFromDto(dto.tokens)
482
+ };
483
+ }
338
484
  };
339
- function getChainId(chain) {
340
- return CHAIN_IDS[chain];
485
+ var OfferToken = {
486
+ fromDto: (dto) => ({
487
+ role: dto.role,
488
+ chain: Chain(dto.chain),
489
+ address: EvmContractAddress(dto.address)
490
+ }),
491
+ /**
492
+ * Maps an offer's token list, dropping every token on a chain this SDK does
493
+ * not name. Frontline's chain registry runs ahead of {@link Chain}, and a
494
+ * plain `.map` would throw out of `Offer.fromDto` and, through
495
+ * `PaginatedResponse.fromDto`, reject the whole offers page - which is how
496
+ * one Base token blanked production's offers list. Dropping costs that
497
+ * token's metadata alone: `coinlist.tokens.get` takes an `EthereumChain`,
498
+ * so nobody could have looked it up anyway.
499
+ *
500
+ * Same shape as `TokenMetadata.fromRegistryDto`.
501
+ */
502
+ listFromDto: (dtos) => dtos.filter((dto) => isChain(dto.chain)).map(OfferToken.fromDto)
503
+ };
504
+
505
+ // src/universal/types/trading.ts
506
+ var Ticker = (value) => value;
507
+ var Isin = (value) => value;
508
+
509
+ // src/universal/core/shared/utils/crypto.ts
510
+ async function sha256(data) {
511
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
512
+ const buffer = bytes.buffer.slice(
513
+ bytes.byteOffset,
514
+ bytes.byteOffset + bytes.byteLength
515
+ );
516
+ return crypto.subtle.digest("SHA-256", buffer);
341
517
  }
342
- function chainFromId(chainId) {
343
- const chains = Object.keys(CHAIN_IDS);
344
- const chain = chains.find((c) => String(CHAIN_IDS[c]) === chainId);
345
- if (!chain) {
346
- throw new ValidationError(`Unsupported EIP-155 chain id: "${chainId}"`);
518
+ function arrayBufferToBase64Url(buffer, padding = true) {
519
+ const bytes = new Uint8Array(buffer);
520
+ let binary = "";
521
+ for (let i = 0; i < bytes.length; i++) {
522
+ binary += String.fromCharCode(bytes[i]);
347
523
  }
348
- return chain;
349
- }
350
- function getNetworkName(chain) {
351
- switch (chain) {
352
- case "ethereum_mainnet":
353
- return "Ethereum";
354
- case "ethereum_sepolia":
355
- return "Ethereum Sepolia";
356
- case "base_mainnet":
357
- return "Base";
358
- case "base_sepolia":
359
- return "Base Sepolia";
360
- default: {
361
- const _exhaustive = chain;
362
- return _exhaustive;
363
- }
524
+ let base64 = btoa(binary);
525
+ base64 = base64.replace(/\+/g, "-").replace(/\//g, "_");
526
+ if (!padding) {
527
+ base64 = base64.replace(/=+$/, "");
364
528
  }
529
+ return base64;
365
530
  }
366
- function txExplorerUrl(chain, txHash) {
367
- return TxExplorerUrl(`${explorerBaseUrl(chain)}/tx/${txHash}`);
531
+ function generateSecureRandomBase64Url(byteLength) {
532
+ const bytes = new Uint8Array(byteLength);
533
+ crypto.getRandomValues(bytes);
534
+ const buffer = bytes.buffer;
535
+ return arrayBufferToBase64Url(buffer, false);
368
536
  }
369
- function explorerBaseUrl(chain) {
370
- switch (chain) {
371
- case "ethereum_mainnet":
372
- return "https://etherscan.io";
373
- case "ethereum_sepolia":
374
- return "https://sepolia.etherscan.io";
375
- case "base_mainnet":
376
- return "https://basescan.org";
377
- case "base_sepolia":
378
- return "https://sepolia-explorer.base.org";
379
- default: {
380
- const _exhaustive = chain;
381
- return _exhaustive;
382
- }
537
+ function getUUIDv4() {
538
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
539
+ return crypto.randomUUID();
540
+ }
541
+ if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
542
+ const bytes = new Uint8Array(16);
543
+ crypto.getRandomValues(bytes);
544
+ bytes[6] = bytes[6] & 15 | 64;
545
+ bytes[8] = bytes[8] & 63 | 128;
546
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
547
+ return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(6, 8).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10, 16).join("")}`;
548
+ }
549
+ return `${Date.now()}-${Math.random().toString(36).slice(2, 12)}`;
550
+ }
551
+ function notBlankStringOrNull(value) {
552
+ if (value?.trim()) {
553
+ return value;
554
+ } else {
555
+ return null;
383
556
  }
384
557
  }
385
558
 
386
- // src/shared/types/providers/superstate/swap.ts
387
- var SwapAuthorization = {
559
+ // src/universal/types/offer-detail.ts
560
+ var OfferOptionId = (value) => value;
561
+ var OfferOptionSlug = (value) => value;
562
+ var OfferSwapContract = {
388
563
  fromDto: (dto) => ({
389
- authorized: dto.authorized
564
+ chain: Chain(dto.chain),
565
+ address: EvmContractAddress(dto.address)
390
566
  })
391
567
  };
392
- var SwapPreview = {
568
+ var OfferDetail = {
569
+ fromDto: (dto) => {
570
+ if (!Array.isArray(dto.funding_assets)) {
571
+ throw new ValidationError(
572
+ `OfferDetail.funding_assets: expected an array, got ${typeof dto.funding_assets}`
573
+ );
574
+ }
575
+ if (!Array.isArray(dto.options)) {
576
+ throw new ValidationError(
577
+ `OfferDetail.options: expected an array, got ${typeof dto.options}`
578
+ );
579
+ }
580
+ if (!Array.isArray(dto.terms)) {
581
+ throw new ValidationError(
582
+ `OfferDetail.terms: expected an array, got ${typeof dto.terms}`
583
+ );
584
+ }
585
+ if (!Array.isArray(dto.links)) {
586
+ throw new ValidationError(
587
+ `OfferDetail.links: expected an array, got ${typeof dto.links}`
588
+ );
589
+ }
590
+ if (!Array.isArray(dto.faqs)) {
591
+ throw new ValidationError(
592
+ `OfferDetail.faqs: expected an array, got ${typeof dto.faqs}`
593
+ );
594
+ }
595
+ if (!Array.isArray(dto.milestones)) {
596
+ throw new ValidationError(
597
+ `OfferDetail.milestones: expected an array, got ${typeof dto.milestones}`
598
+ );
599
+ }
600
+ if (!Array.isArray(dto.tokens)) {
601
+ throw new ValidationError(
602
+ `OfferDetail.tokens: expected an array, got ${typeof dto.tokens}`
603
+ );
604
+ }
605
+ const swapContracts = dto.swap_contracts === void 0 ? [] : dto.swap_contracts;
606
+ if (!Array.isArray(swapContracts)) {
607
+ throw new ValidationError(
608
+ `OfferDetail.swap_contracts: expected an array, got ${typeof swapContracts}`
609
+ );
610
+ }
611
+ const isin = notBlankStringOrNull(dto.isin);
612
+ const ticker = notBlankStringOrNull(dto.ticker);
613
+ return {
614
+ id: OfferId(dto.id),
615
+ slug: OfferSlug(dto.slug),
616
+ type: dto.type,
617
+ name: dto.name,
618
+ asset: Asset.fromDto(dto.asset),
619
+ fundingAssets: dto.funding_assets.map(Asset.fromDto),
620
+ tokens: OfferToken.listFromDto(dto.tokens),
621
+ swapContracts: swapContracts.map(OfferSwapContract.fromDto),
622
+ about: notBlankStringOrNull(dto.about),
623
+ tagline: dto.tagline,
624
+ bannerUrl: dto.banner_url,
625
+ logoUrl: dto.logo_url,
626
+ category: dto.category,
627
+ issuer: notBlankStringOrNull(dto.issuer),
628
+ isin: isin === null ? null : Isin(isin),
629
+ ticker: ticker === null ? null : Ticker(ticker),
630
+ instrumentType: notBlankStringOrNull(dto.instrument_type),
631
+ listingVenue: notBlankStringOrNull(dto.listing_venue),
632
+ startsAt: new Date(dto.starts_at),
633
+ endsAt: dto.ends_at ? new Date(dto.ends_at) : null,
634
+ faqs: dto.faqs.map(FaqItem.fromDto),
635
+ links: dto.links.map(Link.fromDto),
636
+ milestones: dto.milestones.map(Milestone.fromDto),
637
+ options: dto.options.map(OfferOption.fromDto),
638
+ terms: dto.terms.map(TermItem.fromDto)
639
+ };
640
+ }
641
+ };
642
+ var OfferOption = {
393
643
  fromDto: (dto) => ({
394
- inputAmount: parseUint256(
395
- BigInt(dto.pay_input_amount),
396
- "SwapPreview.pay_input_amount"
397
- ),
398
- fee: parseUint256(BigInt(dto.fee), "SwapPreview.fee"),
399
- outputAmount: parseUint256(
400
- BigInt(dto.receive_output_amount),
401
- "SwapPreview.receive_output_amount"
402
- )
644
+ id: OfferOptionId(dto.id),
645
+ slug: OfferOptionSlug(dto.slug),
646
+ bidIncrement: dto.bid_increment,
647
+ floorPriceUsd: dto.floor_price_usd,
648
+ minimumPurchaseUsd: dto.minimum_purchase_usd,
649
+ priceUsd: dto.price_usd,
650
+ saleAgreementUrl: notBlankStringOrNull(dto.sale_agreement_url),
651
+ totalTokenSupply: dto.total_token_supply
403
652
  })
404
653
  };
405
- var SwapStatus = {
654
+ var FaqItem = {
406
655
  fromDto: (dto) => ({
407
- stopped: parseUint256(BigInt(dto.stopped), "SwapStatus.stopped"),
408
- swapLevel: parseUint256(BigInt(dto.swap_level), "SwapStatus.swap_level")
656
+ question: notBlankStringOrNull(dto.question),
657
+ answer: notBlankStringOrNull(dto.answer)
409
658
  })
410
659
  };
411
- var TokenAllowance = {
660
+ var Link = {
412
661
  fromDto: (dto) => ({
413
- allowance: parseUint256(BigInt(dto.allowance), "TokenAllowance.allowance")
662
+ label: notBlankStringOrNull(dto.label),
663
+ url: notBlankStringOrNull(dto.url)
414
664
  })
415
665
  };
416
- var TokenBalance = {
666
+ var TermItem = {
417
667
  fromDto: (dto) => ({
418
- balance: parseUint256(BigInt(dto.balance), "TokenBalance.balance")
668
+ key: notBlankStringOrNull(dto.key),
669
+ value: notBlankStringOrNull(dto.value)
419
670
  })
420
671
  };
421
- var AllowWalletResponse = {
422
- fromDto: (dto) => {
423
- switch (dto.action) {
424
- case "broadcast_transaction":
425
- return {
426
- action: "broadcast_transaction",
427
- to: EvmContractAddress(dto.to),
428
- data: HexEncodedTransactionData(dto.data)
429
- };
430
- case "none":
431
- return {
432
- action: "none",
433
- alreadyAllowed: dto.already_allowed
434
- };
435
- default: {
436
- const _exhaustive = dto;
437
- return _exhaustive;
438
- }
672
+ var Milestone = {
673
+ fromDto: (dto) => ({
674
+ name: notBlankStringOrNull(dto.name),
675
+ schedule: notBlankStringOrNull(dto.schedule),
676
+ status: dto.status
677
+ })
678
+ };
679
+
680
+ // src/universal/types/providers/coin-list/token-sale.ts
681
+ var ParticipationId = (value) => value;
682
+ var Blockchain = (value) => value;
683
+ var WalletAddress = (value) => value;
684
+ var ParticipationsPaginationParams = {
685
+ toQueryParams: (params) => {
686
+ const queryParams = PaginationParams.toQueryParams(params);
687
+ if (params.offerId) {
688
+ queryParams["filters[0][field]"] = "offer_id";
689
+ queryParams["filters[0][op]"] = "==";
690
+ queryParams["filters[0][value]"] = params.offerId;
439
691
  }
692
+ return queryParams;
693
+ }
694
+ };
695
+ var Participation = {
696
+ /** Maps API DTO shape into the SDK participation domain model. */
697
+ fromDto: (dto) => {
698
+ const walletAddress = notBlankStringOrNull(dto.wallet_address);
699
+ return {
700
+ id: ParticipationId(dto.id),
701
+ offerId: OfferId(dto.offer_id),
702
+ offerOptionId: OfferOptionId(dto.offer_option_id),
703
+ status: dto.status,
704
+ amount: dto.amount,
705
+ displayAmount: dto.amount_string,
706
+ asset: Asset.fromDto(dto.asset),
707
+ chain: Blockchain(dto.chain),
708
+ insertedAt: dto.inserted_at ? new Date(dto.inserted_at) : null,
709
+ updatedAt: dto.updated_at ? new Date(dto.updated_at) : null,
710
+ walletAddress: walletAddress ? WalletAddress(walletAddress) : null
711
+ };
440
712
  }
441
713
  };
714
+ var CreateParticipationParams = {
715
+ /** Maps participation creation params into API DTO payload. */
716
+ toDto: (params) => ({
717
+ offer_id: params.offerId,
718
+ offer_option_id: params.offerOptionId,
719
+ chain: params.chain,
720
+ wallet_address: params.walletAddress,
721
+ amount: params.amount,
722
+ asset_id: params.assetId,
723
+ approval_transaction_hash: params.approvalTransactionHash
724
+ })
725
+ };
442
726
 
443
- // src/shared/api/frontline/providers/superstate/swap.ts
444
- async function getSwapAuthorization(api, params) {
445
- const dto = await api.send({
446
- method: "GET",
447
- url: "/v1/wallet/authorized",
448
- queryParams: {
449
- chain: params.chain,
450
- contract_address: params.contractAddress,
451
- wallet_address: params.walletAddress
452
- },
453
- attributes: Attributes.protected()
454
- });
455
- return SwapAuthorization.fromDto(dto);
456
- }
457
- async function getSwapOutputToken(api, params) {
458
- const dto = await api.send({
459
- method: "GET",
460
- url: "/v1/swap/output-token",
461
- queryParams: {
462
- chain: params.chain,
463
- contract_address: params.contractAddress
464
- },
465
- attributes: Attributes.protected()
466
- });
467
- return toErc20Asset(dto);
468
- }
469
- async function getSwapPreview(api, params) {
470
- const dto = await api.send({
471
- method: "GET",
472
- url: "/v1/swap/preview",
473
- queryParams: {
474
- chain: params.chain,
475
- contract_address: params.contractAddress,
476
- input_token: params.inputToken,
477
- amount: params.amount.toString()
478
- },
479
- attributes: Attributes.protected()
480
- });
481
- return SwapPreview.fromDto(dto);
482
- }
483
- async function getSwapStatus(api, params) {
484
- const dto = await api.send({
485
- method: "GET",
486
- url: "/v1/swap/status",
487
- queryParams: {
488
- chain: params.chain,
489
- contract_address: params.contractAddress
490
- },
491
- attributes: Attributes.protected()
492
- });
493
- return SwapStatus.fromDto(dto);
727
+ // src/universal/api/frontline/providers/coin-list/token-sale.ts
728
+ async function fetchParticipations(api, offerId) {
729
+ return fetchAllPages(
730
+ (params) => fetchParticipationsPage(api, params),
731
+ { offerId }
732
+ );
494
733
  }
495
- async function getTokenAllowance(api, params) {
496
- const dto = await api.send({
734
+ async function fetchParticipationsPage(api, params) {
735
+ const pageDto = await api.send({
497
736
  method: "GET",
498
- url: "/v1/token/allowance",
499
- queryParams: {
500
- chain: params.chain,
501
- token_address: params.tokenAddress,
502
- owner: params.owner,
503
- spender: params.spender
504
- },
737
+ url: "/v1/participations",
738
+ queryParams: ParticipationsPaginationParams.toQueryParams(params),
505
739
  attributes: Attributes.protected()
506
740
  });
507
- return TokenAllowance.fromDto(dto);
741
+ return PaginatedResponse.fromDto(pageDto, Participation.fromDto);
508
742
  }
509
- async function getTokenBalance(api, params) {
743
+ async function fetchParticipation(api, id) {
510
744
  const dto = await api.send({
511
745
  method: "GET",
512
- url: "/v1/token/balance",
513
- queryParams: {
514
- chain: params.chain,
515
- token_address: params.tokenAddress,
516
- owner: params.owner
517
- },
746
+ url: `/v1/participations/${id}`,
518
747
  attributes: Attributes.protected()
519
748
  });
520
- return TokenBalance.fromDto(dto);
749
+ return Participation.fromDto(dto);
521
750
  }
522
- async function allowWallet(api, params) {
751
+ async function createParticipation(api, params) {
523
752
  const dto = await api.send({
524
753
  method: "POST",
525
- url: `/v1/offers/${encodeURIComponent(params.offerId)}/allow-wallet`,
526
- body: {
527
- wallet_address: params.walletAddress,
528
- chain: params.chain,
529
- signature: params.signature
530
- },
754
+ url: "/v1/participations",
755
+ body: CreateParticipationParams.toDto(params),
531
756
  attributes: Attributes.protected()
532
757
  });
533
- return AllowWalletResponse.fromDto(dto);
534
- }
535
- function toErc20Asset(dto) {
536
- return {
537
- name: dto.name,
538
- symbol: AssetSymbol(dto.symbol),
539
- decimals: AssetDecimals(dto.decimals)
540
- };
758
+ return Participation.fromDto(dto);
541
759
  }
542
760
 
543
- // src/shared/core/observability/log-cause.ts
761
+ // src/universal/core/shared/observability/log-cause.ts
762
+ import {
763
+ BaseError,
764
+ ContractFunctionExecutionError,
765
+ ContractFunctionRevertedError,
766
+ HttpRequestError,
767
+ RpcError,
768
+ SocketClosedError,
769
+ TimeoutError,
770
+ WebSocketRequestError
771
+ } from "viem";
544
772
  function classifyLogCause(error) {
545
773
  if (error instanceof HttpError) {
546
774
  return httpCause(error);
@@ -560,8 +788,32 @@ function classifyLogCause(error) {
560
788
  if (error instanceof NotImplementedError) {
561
789
  return { type: "not-implemented" };
562
790
  }
791
+ if (error instanceof BaseError) {
792
+ const http = error.walk((e) => e instanceof HttpError);
793
+ if (http instanceof HttpError) {
794
+ return httpCause(http);
795
+ }
796
+ return { type: "rpc", reason: rpcFailureReason(error) };
797
+ }
563
798
  return { type: "generic-error", name: errorName(error) };
564
799
  }
800
+ function rpcFailureReason(error) {
801
+ if (error.walk((e) => e instanceof ContractFunctionRevertedError)) {
802
+ return "reverted";
803
+ }
804
+ if (error.walk((e) => e instanceof RpcError)) {
805
+ return "node-rejected";
806
+ }
807
+ if (error.walk(
808
+ (e) => e instanceof HttpRequestError || e instanceof WebSocketRequestError || e instanceof SocketClosedError || e instanceof TimeoutError
809
+ )) {
810
+ return "transport";
811
+ }
812
+ if (error instanceof ContractFunctionExecutionError) {
813
+ return "malformed-response";
814
+ }
815
+ return "unknown";
816
+ }
565
817
  function describeErrorUnredacted(error) {
566
818
  if (error instanceof HttpError) {
567
819
  return describeHttpErrorRedacted(error);
@@ -606,7 +858,7 @@ function apiErrorEventId(error) {
606
858
  return typeof eventId === "string" ? eventId : null;
607
859
  }
608
860
 
609
- // src/shared/core/observability/internal-logger.ts
861
+ // src/universal/core/shared/observability/internal-logger.ts
610
862
  function internalLogger(logger, scope) {
611
863
  return logger ? scopedLogger(logger, scope, {}) : noopInternalLogger;
612
864
  }
@@ -689,27 +941,47 @@ var noopInternalLogger = {
689
941
  wrap: (_op, _params, run) => run()
690
942
  };
691
943
 
692
- // src/shared/core/blockchain/erc20/erc20-namespace.ts
693
- var Erc20NamespaceImpl = class {
944
+ // src/universal/core/checkout/coin-list/token-sale-namespace.ts
945
+ var CoinListTokenSaleNamespaceImpl = class {
694
946
  constructor(ctx) {
695
947
  this.ctx = ctx;
696
- this.log = internalLogger(ctx.logger, "ERC20");
948
+ this.log = internalLogger(ctx.logger, "TOKEN_SALE");
697
949
  }
698
- async getAllowance(params) {
699
- return this.log.wrap("getAllowance", params, async () => {
950
+ async list(offerId) {
951
+ return this.log.wrap("list", offerId, async () => {
700
952
  await this.ctx.ensureUserAuthenticated();
701
- return getTokenAllowance(this.ctx.api, params);
953
+ return fetchParticipations(this.ctx.api, offerId);
702
954
  });
703
955
  }
704
- async getBalance(params) {
705
- return this.log.wrap("getBalance", params, async () => {
956
+ async listPage(params) {
957
+ return this.log.wrap("listPage", params, async () => {
958
+ await this.ctx.ensureUserAuthenticated();
959
+ return fetchParticipationsPage(this.ctx.api, params);
960
+ });
961
+ }
962
+ async get(id) {
963
+ return this.log.wrap("get", id, async () => {
706
964
  await this.ctx.ensureUserAuthenticated();
707
- return getTokenBalance(this.ctx.api, params);
965
+ return fetchParticipation(this.ctx.api, id);
966
+ });
967
+ }
968
+ async createParticipation(params) {
969
+ return this.log.wrap("createParticipation", params, async () => {
970
+ await this.ctx.ensureUserAuthenticated();
971
+ return createParticipation(this.ctx.api, params);
708
972
  });
709
973
  }
710
974
  };
711
975
 
712
- // src/shared/core/blockchain/formatters.ts
976
+ // src/universal/types/blockchain/ui.ts
977
+ var FormattedAmountUi = (value) => value;
978
+ var FormattedPercentUi = (value) => value;
979
+ var TxExplorerUrl = (value) => value;
980
+ var ShortenedWalletAddress = (value) => value;
981
+ var FormattedAmountAssetUi = (value) => value;
982
+ var AssetIconUrl = (value) => value;
983
+
984
+ // src/universal/core/shared/blockchain/formatters.ts
713
985
  import { formatUnits } from "viem";
714
986
  function shortenAddress(address) {
715
987
  const short = address.length > 10 ? `${address.slice(0, 6)}\u2026${address.slice(-4)}` : address;
@@ -804,7 +1076,65 @@ function formattedUsdPrice(amount, locale) {
804
1076
  );
805
1077
  }
806
1078
 
807
- // src/shared/core/blockchain/math.ts
1079
+ // src/universal/core/shared/blockchain/chain.ts
1080
+ import { base, baseSepolia, mainnet, sepolia } from "viem/chains";
1081
+ var VIEM_CHAINS = {
1082
+ ethereum_mainnet: mainnet,
1083
+ ethereum_sepolia: sepolia,
1084
+ base_mainnet: base,
1085
+ base_sepolia: baseSepolia
1086
+ };
1087
+ function viemChain(chain) {
1088
+ return VIEM_CHAINS[chain];
1089
+ }
1090
+ function getChainId(chain) {
1091
+ return VIEM_CHAINS[chain].id;
1092
+ }
1093
+ function chainFromId(chainId) {
1094
+ const chains = Object.keys(VIEM_CHAINS);
1095
+ const chain = chains.find((c) => String(VIEM_CHAINS[c].id) === chainId);
1096
+ if (!chain) {
1097
+ throw new ValidationError(`Unsupported EIP-155 chain id: "${chainId}"`);
1098
+ }
1099
+ return chain;
1100
+ }
1101
+ function getNetworkName(chain) {
1102
+ switch (chain) {
1103
+ case "ethereum_mainnet":
1104
+ return "Ethereum";
1105
+ case "ethereum_sepolia":
1106
+ return "Ethereum Sepolia";
1107
+ case "base_mainnet":
1108
+ return "Base";
1109
+ case "base_sepolia":
1110
+ return "Base Sepolia";
1111
+ default: {
1112
+ const _exhaustive = chain;
1113
+ return _exhaustive;
1114
+ }
1115
+ }
1116
+ }
1117
+ function txExplorerUrl(chain, txHash) {
1118
+ return TxExplorerUrl(`${explorerBaseUrl(chain)}/tx/${txHash}`);
1119
+ }
1120
+ function explorerBaseUrl(chain) {
1121
+ switch (chain) {
1122
+ case "ethereum_mainnet":
1123
+ return "https://etherscan.io";
1124
+ case "ethereum_sepolia":
1125
+ return "https://sepolia.etherscan.io";
1126
+ case "base_mainnet":
1127
+ return "https://basescan.org";
1128
+ case "base_sepolia":
1129
+ return "https://sepolia-explorer.base.org";
1130
+ default: {
1131
+ const _exhaustive = chain;
1132
+ return _exhaustive;
1133
+ }
1134
+ }
1135
+ }
1136
+
1137
+ // src/universal/core/shared/blockchain/math.ts
808
1138
  import { parseUnits } from "viem";
809
1139
  function blockchainAmountFromRawOrThrow({
810
1140
  label,
@@ -860,676 +1190,1328 @@ function parseBlockchainAmount(amount, decimals) {
860
1190
  }
861
1191
  }
862
1192
 
863
- // src/shared/types/pagination.ts
864
- var Cursor = (value) => value;
865
- var PaginatedResponse = {
866
- fromDto: (dto, itemMapper) => ({
867
- data: dto.data.map(itemMapper),
868
- startingAfter: dto.starting_after ? Cursor(dto.starting_after) : null,
869
- startingBefore: dto.starting_before ? Cursor(dto.starting_before) : null
870
- })
1193
+ // src/universal/types/providers/ondo/ondo.ts
1194
+ var OndoTradingStatus = {
1195
+ fromDto: (dto) => {
1196
+ if (!dto.tradable) return { type: "not-tradable", side: dto.side };
1197
+ return {
1198
+ type: "tradable",
1199
+ side: dto.side,
1200
+ grossMaxTokens: decimalOrNull(dto.gross_max_tokens),
1201
+ grossMaxNotionalValue: decimalOrNull(dto.gross_max_notional_value),
1202
+ grossMaxActiveNotionalValue: decimalOrNull(
1203
+ dto.gross_max_active_notional_value
1204
+ )
1205
+ };
1206
+ }
871
1207
  };
872
- var PaginationParams = {
873
- toQueryParams: (params) => {
874
- const queryParams = {};
875
- if (params.after) {
876
- queryParams.starting_after = params.after;
877
- }
878
- if (params.before) {
879
- queryParams.starting_before = params.before;
880
- }
881
- if (params.limit) {
882
- queryParams.limit = params.limit;
883
- }
884
- return queryParams;
1208
+ var decimalOrNull = (value) => value === null ? null : DecimalString(value);
1209
+ var OndoQuote = {
1210
+ fromDto: (dto) => {
1211
+ const assetDecimals = AssetDecimals(dto.asset_decimals);
1212
+ return {
1213
+ chain: chainFromId(dto.chain_id),
1214
+ ticker: Ticker(dto.ticker),
1215
+ assetAddress: EvmContractAddress(dto.asset_address),
1216
+ asset: {
1217
+ name: dto.ticker,
1218
+ symbol: AssetSymbol(dto.symbol),
1219
+ decimals: assetDecimals
1220
+ },
1221
+ side: dto.side,
1222
+ tokenBaseUnits: blockchainAmountFromRawOrThrow({
1223
+ label: "tokenBaseUnits",
1224
+ raw: dto.token_base_units,
1225
+ decimals: assetDecimals
1226
+ }),
1227
+ price: DecimalString(dto.price)
1228
+ };
885
1229
  }
886
1230
  };
887
-
888
- // src/shared/types/asset.ts
889
- var AssetId = (value) => value;
890
- var AssetCode = (value) => value;
891
- var Asset = {
892
- fromDto: (dto) => ({
893
- id: AssetId(dto.id),
894
- code: AssetCode(dto.code),
895
- name: dto.name,
896
- fractionalDigits: dto.fractional_digits
897
- })
898
- };
899
-
900
- // src/shared/types/offer.ts
901
- var OfferId = (value) => value;
902
- var OfferSlug = (value) => value;
903
- var Offer = {
1231
+ var OndoBuyTransaction = {
904
1232
  fromDto: (dto) => {
905
- if (!Array.isArray(dto.tokens)) {
906
- throw new ValidationError(
907
- `Offer.tokens: expected an array, got ${typeof dto.tokens}`
908
- );
909
- }
1233
+ const spendDecimals = AssetDecimals(dto.spend_input_decimals);
1234
+ const outputDecimals = AssetDecimals(dto.receive_output_decimals);
910
1235
  return {
911
- id: OfferId(dto.id),
912
- slug: OfferSlug(dto.slug),
913
- type: dto.type,
914
- tagline: dto.tagline,
915
- bannerUrl: dto.banner_url,
916
- logoUrl: dto.logo_url,
917
- startsAt: new Date(dto.starts_at),
918
- endsAt: dto.ends_at ? new Date(dto.ends_at) : null,
919
- tokens: dto.tokens.map(OfferToken.fromDto)
1236
+ ...parseSwapCore(dto, spendDecimals),
1237
+ side: "buy",
1238
+ fee: blockchainAmountFromRawOrThrow({
1239
+ label: "fee",
1240
+ raw: dto.fee,
1241
+ decimals: spendDecimals
1242
+ }),
1243
+ notionalValue: blockchainAmountFromRawOrThrow({
1244
+ label: "notional_value",
1245
+ raw: dto.notional_value,
1246
+ decimals: spendDecimals
1247
+ }),
1248
+ receiveOutputAmount: parsePositiveAmount({
1249
+ label: "receive_output_amount",
1250
+ raw: dto.receive_output_amount,
1251
+ decimals: outputDecimals,
1252
+ // A transaction that yields nothing is not one to sign - the user
1253
+ // would pay the deposit and receive no asset - and frontline refuses
1254
+ // to emit one. A zero here is a changed encoding, not a small order.
1255
+ // Rejecting it at the boundary is also what lets `computeOndoBuyPrice`
1256
+ // divide by it without a fallible result: the failure surfaces as the
1257
+ // data hook's ERROR state rather than as a division during render.
1258
+ reason: "a buy that yields nothing is not fillable"
1259
+ })
920
1260
  };
921
1261
  }
922
1262
  };
923
- var OfferToken = {
924
- fromDto: (dto) => ({
925
- role: dto.role,
926
- chain: Chain(dto.chain),
927
- address: EvmContractAddress(dto.address)
928
- })
1263
+ var OndoSellTransaction = {
1264
+ fromDto: (dto) => {
1265
+ const spendDecimals = AssetDecimals(dto.spend_input_decimals);
1266
+ const outputDecimals = AssetDecimals(dto.receive_output_decimals);
1267
+ const expectedQuantity = parsePositiveAmount({
1268
+ label: "expected_quantity",
1269
+ raw: dto.expected_quantity,
1270
+ decimals: outputDecimals,
1271
+ reason: "a sale that yields nothing is not fillable"
1272
+ });
1273
+ return {
1274
+ ...parseSwapCore(dto, spendDecimals),
1275
+ side: "sell",
1276
+ expected: {
1277
+ quantity: expectedQuantity,
1278
+ fee: blockchainAmountFromRawOrThrow({
1279
+ label: "expected_fee",
1280
+ raw: dto.expected_fee,
1281
+ decimals: outputDecimals
1282
+ })
1283
+ },
1284
+ minimum: {
1285
+ quantity: parseMinimumQuantity(
1286
+ dto.minimum_quantity,
1287
+ outputDecimals,
1288
+ expectedQuantity
1289
+ ),
1290
+ fee: blockchainAmountFromRawOrThrow({
1291
+ label: "minimum_fee",
1292
+ raw: dto.minimum_fee,
1293
+ decimals: outputDecimals
1294
+ })
1295
+ }
1296
+ };
1297
+ }
929
1298
  };
930
-
931
- // src/shared/core/utils/crypto.ts
932
- async function sha256(data) {
933
- const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
934
- const buffer = bytes.buffer.slice(
935
- bytes.byteOffset,
936
- bytes.byteOffset + bytes.byteLength
937
- );
938
- return crypto.subtle.digest("SHA-256", buffer);
1299
+ function parseSwapCore(dto, spendDecimals) {
1300
+ return {
1301
+ tx: {
1302
+ to: EvmContractAddress(dto.to),
1303
+ data: HexEncodedTransactionData(dto.data)
1304
+ },
1305
+ expiresAt: parseExpiresAt(dto.expires_at),
1306
+ spendInputAmount: parsePositiveAmount({
1307
+ label: "spend_input_amount",
1308
+ raw: dto.spend_input_amount,
1309
+ decimals: spendDecimals,
1310
+ // A transaction that takes nothing from the wallet is not one to sign:
1311
+ // it would settle one leg of a trade and skip the other. Frontline
1312
+ // refuses an `amount` of zero whichever way the trade runs, so this is a
1313
+ // changed encoding rather than a small order.
1314
+ //
1315
+ // Guarded on both sides rather than on the sale alone, because which
1316
+ // amount becomes the divisor in the price flips with the direction: a
1317
+ // guard placed by that would be a rule about the arithmetic rather than
1318
+ // about the trade.
1319
+ reason: "a swap that spends nothing is not fillable"
1320
+ })
1321
+ };
939
1322
  }
940
- function arrayBufferToBase64Url(buffer, padding = true) {
941
- const bytes = new Uint8Array(buffer);
942
- let binary = "";
943
- for (let i = 0; i < bytes.length; i++) {
944
- binary += String.fromCharCode(bytes[i]);
945
- }
946
- let base64 = btoa(binary);
947
- base64 = base64.replace(/\+/g, "-").replace(/\//g, "_");
948
- if (!padding) {
949
- base64 = base64.replace(/=+$/, "");
1323
+ function parseMinimumQuantity(raw, decimals, expectedQuantity) {
1324
+ const amount = parsePositiveAmount({
1325
+ label: "minimum_quantity",
1326
+ raw,
1327
+ decimals,
1328
+ reason: "a floor of zero guarantees nothing"
1329
+ });
1330
+ if (amount.raw > expectedQuantity.raw) {
1331
+ throw new ValidationError(
1332
+ `minimum_quantity: must not exceed expected_quantity ("${raw}" > "${expectedQuantity.raw}")`
1333
+ );
950
1334
  }
951
- return base64;
952
- }
953
- function generateSecureRandomBase64Url(byteLength) {
954
- const bytes = new Uint8Array(byteLength);
955
- crypto.getRandomValues(bytes);
956
- const buffer = bytes.buffer;
957
- return arrayBufferToBase64Url(buffer, false);
1335
+ return amount;
958
1336
  }
959
- function getUUIDv4() {
960
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
961
- return crypto.randomUUID();
962
- }
963
- if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
964
- const bytes = new Uint8Array(16);
965
- crypto.getRandomValues(bytes);
966
- bytes[6] = bytes[6] & 15 | 64;
967
- bytes[8] = bytes[8] & 63 | 128;
968
- const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
969
- return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(6, 8).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10, 16).join("")}`;
1337
+ function parsePositiveAmount({
1338
+ label,
1339
+ raw,
1340
+ decimals,
1341
+ reason
1342
+ }) {
1343
+ const amount = blockchainAmountFromRawOrThrow({ label, raw, decimals });
1344
+ if (amount.raw <= 0n) {
1345
+ throw new ValidationError(
1346
+ `${label}: must be greater than zero ("${raw}") - ${reason}`
1347
+ );
970
1348
  }
971
- return `${Date.now()}-${Math.random().toString(36).slice(2, 12)}`;
1349
+ return amount;
972
1350
  }
973
- function notBlankStringOrNull(value) {
974
- if (value?.trim()) {
975
- return value;
976
- } else {
977
- return null;
1351
+ function parseExpiresAt(value) {
1352
+ const date = new Date(value);
1353
+ if (Number.isNaN(date.getTime())) {
1354
+ throw new ValidationError(`expires_at: not a date ("${value}")`);
978
1355
  }
1356
+ return date;
979
1357
  }
980
1358
 
981
- // src/shared/types/offer-detail.ts
982
- var OfferOptionId = (value) => value;
983
- var OfferOptionSlug = (value) => value;
984
- var OfferSwapContract = {
985
- fromDto: (dto) => ({
986
- chain: Chain(dto.chain),
987
- address: EvmContractAddress(dto.address)
988
- })
989
- };
990
- var OfferDetail = {
991
- fromDto: (dto) => {
992
- if (!Array.isArray(dto.funding_assets)) {
993
- throw new ValidationError(
994
- `OfferDetail.funding_assets: expected an array, got ${typeof dto.funding_assets}`
995
- );
996
- }
997
- if (!Array.isArray(dto.options)) {
998
- throw new ValidationError(
999
- `OfferDetail.options: expected an array, got ${typeof dto.options}`
1000
- );
1001
- }
1002
- if (!Array.isArray(dto.terms)) {
1003
- throw new ValidationError(
1004
- `OfferDetail.terms: expected an array, got ${typeof dto.terms}`
1005
- );
1006
- }
1007
- if (!Array.isArray(dto.links)) {
1008
- throw new ValidationError(
1009
- `OfferDetail.links: expected an array, got ${typeof dto.links}`
1010
- );
1011
- }
1012
- if (!Array.isArray(dto.faqs)) {
1013
- throw new ValidationError(
1014
- `OfferDetail.faqs: expected an array, got ${typeof dto.faqs}`
1015
- );
1016
- }
1017
- if (!Array.isArray(dto.milestones)) {
1018
- throw new ValidationError(
1019
- `OfferDetail.milestones: expected an array, got ${typeof dto.milestones}`
1020
- );
1021
- }
1022
- if (!Array.isArray(dto.tokens)) {
1023
- throw new ValidationError(
1024
- `OfferDetail.tokens: expected an array, got ${typeof dto.tokens}`
1025
- );
1026
- }
1027
- const swapContracts = dto.swap_contracts === void 0 ? [] : dto.swap_contracts;
1028
- if (!Array.isArray(swapContracts)) {
1029
- throw new ValidationError(
1030
- `OfferDetail.swap_contracts: expected an array, got ${typeof swapContracts}`
1031
- );
1032
- }
1033
- return {
1034
- id: OfferId(dto.id),
1035
- slug: OfferSlug(dto.slug),
1036
- type: dto.type,
1037
- name: dto.name,
1038
- asset: Asset.fromDto(dto.asset),
1039
- fundingAssets: dto.funding_assets.map(Asset.fromDto),
1040
- tokens: dto.tokens.map(OfferToken.fromDto),
1041
- swapContracts: swapContracts.map(OfferSwapContract.fromDto),
1042
- about: notBlankStringOrNull(dto.about),
1043
- tagline: dto.tagline,
1044
- bannerUrl: dto.banner_url,
1045
- logoUrl: dto.logo_url,
1046
- category: dto.category,
1047
- startsAt: new Date(dto.starts_at),
1048
- endsAt: dto.ends_at ? new Date(dto.ends_at) : null,
1049
- faqs: dto.faqs.map(FaqItem.fromDto),
1050
- links: dto.links.map(Link.fromDto),
1051
- milestones: dto.milestones.map(Milestone.fromDto),
1052
- options: dto.options.map(OfferOption.fromDto),
1053
- terms: dto.terms.map(TermItem.fromDto)
1054
- };
1055
- }
1056
- };
1057
- var OfferOption = {
1058
- fromDto: (dto) => ({
1059
- id: OfferOptionId(dto.id),
1060
- slug: OfferOptionSlug(dto.slug),
1061
- bidIncrement: dto.bid_increment,
1062
- floorPriceUsd: dto.floor_price_usd,
1063
- minimumPurchaseUsd: dto.minimum_purchase_usd,
1064
- priceUsd: dto.price_usd,
1065
- saleAgreementUrl: notBlankStringOrNull(dto.sale_agreement_url),
1066
- totalTokenSupply: dto.total_token_supply
1067
- })
1068
- };
1069
- var FaqItem = {
1070
- fromDto: (dto) => ({
1071
- question: notBlankStringOrNull(dto.question),
1072
- answer: notBlankStringOrNull(dto.answer)
1073
- })
1074
- };
1075
- var Link = {
1076
- fromDto: (dto) => ({
1077
- label: notBlankStringOrNull(dto.label),
1078
- url: notBlankStringOrNull(dto.url)
1079
- })
1080
- };
1081
- var TermItem = {
1082
- fromDto: (dto) => ({
1083
- key: notBlankStringOrNull(dto.key),
1084
- value: notBlankStringOrNull(dto.value)
1085
- })
1086
- };
1087
- var Milestone = {
1088
- fromDto: (dto) => ({
1089
- name: notBlankStringOrNull(dto.name),
1090
- schedule: notBlankStringOrNull(dto.schedule),
1091
- status: dto.status
1092
- })
1093
- };
1094
-
1095
- // src/shared/types/providers/coin-list/token-sale.ts
1096
- var ParticipationId = (value) => value;
1097
- var Blockchain = (value) => value;
1098
- var WalletAddress = (value) => value;
1099
- var ParticipationsPaginationParams = {
1100
- toQueryParams: (params) => {
1101
- const queryParams = PaginationParams.toQueryParams(params);
1102
- if (params.offerId) {
1103
- queryParams["filters[0][field]"] = "offer_id";
1104
- queryParams["filters[0][op]"] = "==";
1105
- queryParams["filters[0][value]"] = params.offerId;
1106
- }
1107
- return queryParams;
1108
- }
1109
- };
1110
- var Participation = {
1111
- /** Maps API DTO shape into the SDK participation domain model. */
1112
- fromDto: (dto) => {
1113
- const walletAddress = notBlankStringOrNull(dto.wallet_address);
1114
- return {
1115
- id: ParticipationId(dto.id),
1116
- offerId: OfferId(dto.offer_id),
1117
- offerOptionId: OfferOptionId(dto.offer_option_id),
1118
- status: dto.status,
1119
- amount: dto.amount,
1120
- displayAmount: dto.amount_string,
1121
- asset: Asset.fromDto(dto.asset),
1122
- chain: Blockchain(dto.chain),
1123
- insertedAt: dto.inserted_at ? new Date(dto.inserted_at) : null,
1124
- updatedAt: dto.updated_at ? new Date(dto.updated_at) : null,
1125
- walletAddress: walletAddress ? WalletAddress(walletAddress) : null
1126
- };
1127
- }
1128
- };
1129
- var CreateParticipationParams = {
1130
- /** Maps participation creation params into API DTO payload. */
1131
- toDto: (params) => ({
1132
- offer_id: params.offerId,
1133
- offer_option_id: params.offerOptionId,
1134
- chain: params.chain,
1135
- wallet_address: params.walletAddress,
1136
- amount: params.amount,
1137
- asset_id: params.assetId,
1138
- approval_transaction_hash: params.approvalTransactionHash
1139
- })
1140
- };
1141
-
1142
- // src/shared/api/frontline/providers/coin-list/token-sale.ts
1143
- async function fetchParticipations(api, offerId) {
1144
- return fetchAllPages(
1145
- (params) => fetchParticipationsPage(api, params),
1146
- { offerId }
1147
- );
1148
- }
1149
- async function fetchParticipationsPage(api, params) {
1150
- const pageDto = await api.send({
1359
+ // src/universal/api/frontline/providers/ondo/ondo.ts
1360
+ async function getOndoTradingStatus(api, params) {
1361
+ const dto = await api.send({
1151
1362
  method: "GET",
1152
- url: "/v1/participations",
1153
- queryParams: ParticipationsPaginationParams.toQueryParams(params),
1363
+ url: "/v1/ondo/swap/trading-status",
1364
+ queryParams: { symbol: params.symbol, side: params.side },
1154
1365
  attributes: Attributes.protected()
1155
1366
  });
1156
- return PaginatedResponse.fromDto(pageDto, Participation.fromDto);
1367
+ return OndoTradingStatus.fromDto(dto);
1157
1368
  }
1158
- async function fetchParticipation(api, id) {
1369
+ async function getOndoQuote(api, params) {
1159
1370
  const dto = await api.send({
1160
1371
  method: "GET",
1161
- url: `/v1/participations/${id}`,
1372
+ url: "/v1/ondo/swap/quote",
1373
+ queryParams: {
1374
+ symbol: params.symbol,
1375
+ side: params.side,
1376
+ duration: params.duration,
1377
+ ...sizeParam(params)
1378
+ },
1162
1379
  attributes: Attributes.protected()
1163
1380
  });
1164
- return Participation.fromDto(dto);
1381
+ return OndoQuote.fromDto(dto);
1165
1382
  }
1166
- async function createParticipation(api, params) {
1383
+ async function buildOndoBuy(api, params) {
1167
1384
  const dto = await api.send({
1168
1385
  method: "POST",
1169
- url: "/v1/participations",
1170
- body: CreateParticipationParams.toDto(params),
1386
+ url: "/v1/ondo/swap/buy",
1387
+ body: swapBody(params),
1171
1388
  attributes: Attributes.protected()
1172
1389
  });
1173
- return Participation.fromDto(dto);
1390
+ assertSpendScaleAgrees({
1391
+ published: dto.spend_input_decimals,
1392
+ sized: params.amount,
1393
+ trade: "purchase"
1394
+ });
1395
+ return OndoBuyTransaction.fromDto(dto);
1396
+ }
1397
+ async function buildOndoSell(api, params) {
1398
+ const dto = await api.send({
1399
+ method: "POST",
1400
+ url: "/v1/ondo/swap/sell",
1401
+ body: swapBody(params),
1402
+ attributes: Attributes.protected()
1403
+ });
1404
+ assertSpendScaleAgrees({
1405
+ published: dto.spend_input_decimals,
1406
+ sized: params.amount,
1407
+ trade: "sale",
1408
+ // The two answers come from two chains, so on a testnet they can disagree
1409
+ // for a reason that is neither the caller's nor a corrupt response. Say so,
1410
+ // or a QA run reads as a puzzle rather than a diagnosis.
1411
+ note: "the quote resolves the asset on Ethereum mainnet while the swap executes on the chain requested, so these disagree until frontline serves a chain-scoped quote"
1412
+ });
1413
+ return OndoSellTransaction.fromDto(dto);
1414
+ }
1415
+ function swapBody(params) {
1416
+ return {
1417
+ symbol: params.symbol,
1418
+ chain: params.chain,
1419
+ wallet_address: params.walletAddress,
1420
+ amount: params.amount.raw.toString()
1421
+ };
1422
+ }
1423
+ function assertSpendScaleAgrees({
1424
+ published,
1425
+ sized,
1426
+ trade,
1427
+ note
1428
+ }) {
1429
+ if (published === sized.decimals) return;
1430
+ const because = note === void 0 ? "" : ` - ${note}`;
1431
+ throw new ValidationError(
1432
+ `spend_input_decimals: the ${trade} was priced in ${published} decimals but the order was sized in ${sized.decimals}${because}`
1433
+ );
1434
+ }
1435
+ function sizeParam(params) {
1436
+ const tokenAmount = "tokenAmount" in params ? params.tokenAmount : void 0;
1437
+ const notionalValue = "notionalValue" in params ? params.notionalValue : void 0;
1438
+ if (tokenAmount !== void 0) {
1439
+ if (notionalValue !== void 0) {
1440
+ throw new ValidationError(
1441
+ "An Ondo quote takes tokenAmount or notionalValue, not both"
1442
+ );
1443
+ }
1444
+ return { token_amount: formatRawAmount(tokenAmount) };
1445
+ }
1446
+ if (notionalValue === void 0) {
1447
+ throw new ValidationError(
1448
+ "An Ondo quote must be sized by tokenAmount or notionalValue"
1449
+ );
1450
+ }
1451
+ return { notional_value: notionalValue };
1174
1452
  }
1175
1453
 
1176
- // src/shared/core/checkout/coin-list/token-sale-namespace.ts
1177
- var CoinListTokenSaleNamespaceImpl = class {
1454
+ // src/universal/core/checkout/ondo/ondo-namespace.ts
1455
+ var OndoNamespaceImpl = class {
1178
1456
  constructor(ctx) {
1179
1457
  this.ctx = ctx;
1180
- this.log = internalLogger(ctx.logger, "TOKEN_SALE");
1458
+ this.log = internalLogger(ctx.logger, "ONDO");
1181
1459
  }
1182
- async list(offerId) {
1183
- return this.log.wrap("list", offerId, async () => {
1460
+ async getTradingStatus(params) {
1461
+ return this.log.wrap("getTradingStatus", params, async () => {
1184
1462
  await this.ctx.ensureUserAuthenticated();
1185
- return fetchParticipations(this.ctx.api, offerId);
1463
+ return getOndoTradingStatus(this.ctx.api, params);
1186
1464
  });
1187
1465
  }
1188
- async listPage(params) {
1189
- return this.log.wrap("listPage", params, async () => {
1466
+ async getQuote(params) {
1467
+ return this.log.wrap("getQuote", params, async () => {
1190
1468
  await this.ctx.ensureUserAuthenticated();
1191
- return fetchParticipationsPage(this.ctx.api, params);
1469
+ return getOndoQuote(this.ctx.api, params);
1192
1470
  });
1193
1471
  }
1194
- async get(id) {
1195
- return this.log.wrap("get", id, async () => {
1472
+ async buildBuyTransaction(params) {
1473
+ return this.log.wrap("buildBuyTransaction", params, async () => {
1196
1474
  await this.ctx.ensureUserAuthenticated();
1197
- return fetchParticipation(this.ctx.api, id);
1475
+ return buildOndoBuy(this.ctx.api, params);
1198
1476
  });
1199
1477
  }
1200
- async createParticipation(params) {
1201
- return this.log.wrap("createParticipation", params, async () => {
1478
+ async buildSellTransaction(params) {
1479
+ return this.log.wrap("buildSellTransaction", params, async () => {
1202
1480
  await this.ctx.ensureUserAuthenticated();
1203
- return createParticipation(this.ctx.api, params);
1481
+ return buildOndoSell(this.ctx.api, params);
1204
1482
  });
1205
1483
  }
1206
1484
  };
1207
1485
 
1208
- // src/shared/types/trading.ts
1209
- var Ticker = (value) => value;
1210
-
1211
- // src/shared/types/providers/ondo/ondo.ts
1212
- var OndoTradingStatus = {
1213
- fromDto: (dto) => {
1214
- if (!dto.tradable) return { type: "not-tradable", side: dto.side };
1215
- return {
1216
- type: "tradable",
1217
- side: dto.side,
1218
- grossMaxTokens: decimalOrNull(dto.gross_max_tokens),
1219
- grossMaxNotionalValue: decimalOrNull(dto.gross_max_notional_value),
1220
- grossMaxActiveNotionalValue: decimalOrNull(
1221
- dto.gross_max_active_notional_value
1222
- )
1223
- };
1224
- }
1225
- };
1226
- var decimalOrNull = (value) => value === null ? null : DecimalString(value);
1227
- var OndoQuote = {
1228
- fromDto: (dto) => {
1229
- const assetDecimals = AssetDecimals(dto.asset_decimals);
1230
- return {
1231
- chain: chainFromId(dto.chain_id),
1232
- ticker: Ticker(dto.ticker),
1233
- assetAddress: EvmContractAddress(dto.asset_address),
1234
- asset: {
1235
- name: dto.ticker,
1236
- symbol: AssetSymbol(dto.symbol),
1237
- decimals: assetDecimals
1486
+ // src/universal/core/checkout/superstate/blockchain/abi.ts
1487
+ var SUPERSTATE_SWAP_ABI = [
1488
+ {
1489
+ type: "function",
1490
+ name: "KIND",
1491
+ inputs: [],
1492
+ outputs: [
1493
+ {
1494
+ name: "",
1495
+ type: "uint16",
1496
+ internalType: "uint16"
1497
+ }
1498
+ ],
1499
+ stateMutability: "view"
1500
+ },
1501
+ {
1502
+ type: "function",
1503
+ name: "ONE_HUNDRED_P",
1504
+ inputs: [],
1505
+ outputs: [
1506
+ {
1507
+ name: "",
1508
+ type: "uint256",
1509
+ internalType: "uint256"
1510
+ }
1511
+ ],
1512
+ stateMutability: "view"
1513
+ },
1514
+ {
1515
+ type: "function",
1516
+ name: "SWAP_LEVEL",
1517
+ inputs: [],
1518
+ outputs: [
1519
+ {
1520
+ name: "",
1521
+ type: "uint32",
1522
+ internalType: "uint32"
1523
+ }
1524
+ ],
1525
+ stateMutability: "view"
1526
+ },
1527
+ {
1528
+ type: "function",
1529
+ name: "VERSION",
1530
+ inputs: [],
1531
+ outputs: [
1532
+ {
1533
+ name: "",
1534
+ type: "uint16",
1535
+ internalType: "uint16"
1536
+ }
1537
+ ],
1538
+ stateMutability: "view"
1539
+ },
1540
+ {
1541
+ type: "function",
1542
+ name: "authorized",
1543
+ inputs: [
1544
+ {
1545
+ name: "user",
1546
+ type: "address",
1547
+ internalType: "address"
1548
+ }
1549
+ ],
1550
+ outputs: [
1551
+ {
1552
+ name: "",
1553
+ type: "bool",
1554
+ internalType: "bool"
1555
+ }
1556
+ ],
1557
+ stateMutability: "view"
1558
+ },
1559
+ {
1560
+ type: "function",
1561
+ name: "bpp",
1562
+ inputs: [
1563
+ {
1564
+ name: "amount",
1565
+ type: "uint256",
1566
+ internalType: "uint256"
1567
+ }
1568
+ ],
1569
+ outputs: [
1570
+ {
1571
+ name: "",
1572
+ type: "uint256",
1573
+ internalType: "uint256"
1574
+ }
1575
+ ],
1576
+ stateMutability: "view"
1577
+ },
1578
+ {
1579
+ type: "function",
1580
+ name: "bps",
1581
+ inputs: [],
1582
+ outputs: [
1583
+ {
1584
+ name: "",
1585
+ type: "uint256",
1586
+ internalType: "uint256"
1587
+ }
1588
+ ],
1589
+ stateMutability: "view"
1590
+ },
1591
+ {
1592
+ type: "function",
1593
+ name: "cancelOwnershipHandover",
1594
+ inputs: [],
1595
+ outputs: [],
1596
+ stateMutability: "payable"
1597
+ },
1598
+ {
1599
+ type: "function",
1600
+ name: "completeOwnershipHandover",
1601
+ inputs: [
1602
+ {
1603
+ name: "pendingOwner",
1604
+ type: "address",
1605
+ internalType: "address"
1606
+ }
1607
+ ],
1608
+ outputs: [],
1609
+ stateMutability: "payable"
1610
+ },
1611
+ {
1612
+ type: "function",
1613
+ name: "fee",
1614
+ inputs: [
1615
+ {
1616
+ name: "amount",
1617
+ type: "uint256",
1618
+ internalType: "uint256"
1619
+ }
1620
+ ],
1621
+ outputs: [
1622
+ {
1623
+ name: "",
1624
+ type: "uint256",
1625
+ internalType: "uint256"
1238
1626
  },
1239
- side: dto.side,
1240
- tokenBaseUnits: blockchainAmountFromRawOrThrow({
1241
- label: "tokenBaseUnits",
1242
- raw: dto.token_base_units,
1243
- decimals: assetDecimals
1244
- }),
1245
- price: DecimalString(dto.price)
1246
- };
1247
- }
1248
- };
1249
- var OndoBuyTransaction = {
1250
- fromDto: (dto) => {
1251
- const spendDecimals = AssetDecimals(dto.spend_input_decimals);
1252
- const outputDecimals = AssetDecimals(dto.receive_output_decimals);
1253
- return {
1254
- ...parseSwapCore(dto, spendDecimals),
1255
- side: "buy",
1256
- fee: blockchainAmountFromRawOrThrow({
1257
- label: "fee",
1258
- raw: dto.fee,
1259
- decimals: spendDecimals
1260
- }),
1261
- notionalValue: blockchainAmountFromRawOrThrow({
1262
- label: "notional_value",
1263
- raw: dto.notional_value,
1264
- decimals: spendDecimals
1265
- }),
1266
- receiveOutputAmount: parsePositiveAmount({
1267
- label: "receive_output_amount",
1268
- raw: dto.receive_output_amount,
1269
- decimals: outputDecimals,
1270
- // A transaction that yields nothing is not one to sign - the user
1271
- // would pay the deposit and receive no asset - and frontline refuses
1272
- // to emit one. A zero here is a changed encoding, not a small order.
1273
- // Rejecting it at the boundary is also what lets `computeOndoBuyPrice`
1274
- // divide by it without a fallible result: the failure surfaces as the
1275
- // data hook's ERROR state rather than as a division during render.
1276
- reason: "a buy that yields nothing is not fillable"
1277
- })
1278
- };
1279
- }
1280
- };
1281
- var OndoSellTransaction = {
1282
- fromDto: (dto) => {
1283
- const spendDecimals = AssetDecimals(dto.spend_input_decimals);
1284
- const outputDecimals = AssetDecimals(dto.receive_output_decimals);
1285
- const expectedQuantity = parsePositiveAmount({
1286
- label: "expected_quantity",
1287
- raw: dto.expected_quantity,
1288
- decimals: outputDecimals,
1289
- reason: "a sale that yields nothing is not fillable"
1290
- });
1291
- return {
1292
- ...parseSwapCore(dto, spendDecimals),
1293
- side: "sell",
1294
- expected: {
1295
- quantity: expectedQuantity,
1296
- fee: blockchainAmountFromRawOrThrow({
1297
- label: "expected_fee",
1298
- raw: dto.expected_fee,
1299
- decimals: outputDecimals
1300
- })
1627
+ {
1628
+ name: "",
1629
+ type: "uint256",
1630
+ internalType: "uint256"
1631
+ }
1632
+ ],
1633
+ stateMutability: "view"
1634
+ },
1635
+ {
1636
+ type: "function",
1637
+ name: "id",
1638
+ inputs: [],
1639
+ outputs: [
1640
+ {
1641
+ name: "",
1642
+ type: "bytes32",
1643
+ internalType: "bytes32"
1644
+ }
1645
+ ],
1646
+ stateMutability: "view"
1647
+ },
1648
+ {
1649
+ type: "function",
1650
+ name: "inputTokens",
1651
+ inputs: [
1652
+ {
1653
+ name: "",
1654
+ type: "address",
1655
+ internalType: "address"
1656
+ }
1657
+ ],
1658
+ outputs: [
1659
+ {
1660
+ name: "",
1661
+ type: "bool",
1662
+ internalType: "bool"
1663
+ }
1664
+ ],
1665
+ stateMutability: "view"
1666
+ },
1667
+ {
1668
+ type: "function",
1669
+ name: "outputToken",
1670
+ inputs: [],
1671
+ outputs: [
1672
+ {
1673
+ name: "",
1674
+ type: "address",
1675
+ internalType: "address"
1676
+ }
1677
+ ],
1678
+ stateMutability: "view"
1679
+ },
1680
+ {
1681
+ type: "function",
1682
+ name: "outputTokenBalance",
1683
+ inputs: [],
1684
+ outputs: [
1685
+ {
1686
+ name: "",
1687
+ type: "uint256",
1688
+ internalType: "uint256"
1689
+ }
1690
+ ],
1691
+ stateMutability: "view"
1692
+ },
1693
+ {
1694
+ type: "function",
1695
+ name: "owner",
1696
+ inputs: [],
1697
+ outputs: [
1698
+ {
1699
+ name: "result",
1700
+ type: "address",
1701
+ internalType: "address"
1702
+ }
1703
+ ],
1704
+ stateMutability: "view"
1705
+ },
1706
+ {
1707
+ type: "function",
1708
+ name: "ownershipHandoverExpiresAt",
1709
+ inputs: [
1710
+ {
1711
+ name: "pendingOwner",
1712
+ type: "address",
1713
+ internalType: "address"
1714
+ }
1715
+ ],
1716
+ outputs: [
1717
+ {
1718
+ name: "result",
1719
+ type: "uint256",
1720
+ internalType: "uint256"
1721
+ }
1722
+ ],
1723
+ stateMutability: "view"
1724
+ },
1725
+ {
1726
+ type: "function",
1727
+ name: "pause",
1728
+ inputs: [
1729
+ {
1730
+ name: "level",
1731
+ type: "uint32",
1732
+ internalType: "uint32"
1733
+ }
1734
+ ],
1735
+ outputs: [
1736
+ {
1737
+ name: "",
1738
+ type: "bool",
1739
+ internalType: "bool"
1740
+ }
1741
+ ],
1742
+ stateMutability: "nonpayable"
1743
+ },
1744
+ {
1745
+ type: "function",
1746
+ name: "paused",
1747
+ inputs: [],
1748
+ outputs: [
1749
+ {
1750
+ name: "",
1751
+ type: "uint32",
1752
+ internalType: "uint32"
1753
+ }
1754
+ ],
1755
+ stateMutability: "view"
1756
+ },
1757
+ {
1758
+ type: "function",
1759
+ name: "preview",
1760
+ inputs: [
1761
+ {
1762
+ name: "token",
1763
+ type: "address",
1764
+ internalType: "address"
1301
1765
  },
1302
- minimum: {
1303
- quantity: parseMinimumQuantity(
1304
- dto.minimum_quantity,
1305
- outputDecimals,
1306
- expectedQuantity
1307
- ),
1308
- fee: blockchainAmountFromRawOrThrow({
1309
- label: "minimum_fee",
1310
- raw: dto.minimum_fee,
1311
- decimals: outputDecimals
1312
- })
1766
+ {
1767
+ name: "amount",
1768
+ type: "uint256",
1769
+ internalType: "uint256"
1313
1770
  }
1314
- };
1771
+ ],
1772
+ outputs: [
1773
+ {
1774
+ name: "",
1775
+ type: "tuple",
1776
+ internalType: "struct Preview",
1777
+ components: [
1778
+ {
1779
+ name: "input",
1780
+ type: "uint256",
1781
+ internalType: "uint256"
1782
+ },
1783
+ {
1784
+ name: "fee",
1785
+ type: "uint256",
1786
+ internalType: "uint256"
1787
+ },
1788
+ {
1789
+ name: "output",
1790
+ type: "uint256",
1791
+ internalType: "uint256"
1792
+ }
1793
+ ]
1794
+ }
1795
+ ],
1796
+ stateMutability: "view"
1797
+ },
1798
+ {
1799
+ type: "function",
1800
+ name: "renounceOwnership",
1801
+ inputs: [],
1802
+ outputs: [],
1803
+ stateMutability: "payable"
1804
+ },
1805
+ {
1806
+ type: "function",
1807
+ name: "requestOwnershipHandover",
1808
+ inputs: [],
1809
+ outputs: [],
1810
+ stateMutability: "payable"
1811
+ },
1812
+ {
1813
+ type: "function",
1814
+ name: "setBps",
1815
+ inputs: [
1816
+ {
1817
+ name: "points",
1818
+ type: "uint256",
1819
+ internalType: "uint256"
1820
+ }
1821
+ ],
1822
+ outputs: [
1823
+ {
1824
+ name: "",
1825
+ type: "bool",
1826
+ internalType: "bool"
1827
+ }
1828
+ ],
1829
+ stateMutability: "nonpayable"
1830
+ },
1831
+ {
1832
+ type: "function",
1833
+ name: "setInputToken",
1834
+ inputs: [
1835
+ {
1836
+ name: "token",
1837
+ type: "address",
1838
+ internalType: "address"
1839
+ },
1840
+ {
1841
+ name: "val",
1842
+ type: "bool",
1843
+ internalType: "bool"
1844
+ }
1845
+ ],
1846
+ outputs: [
1847
+ {
1848
+ name: "",
1849
+ type: "bool",
1850
+ internalType: "bool"
1851
+ }
1852
+ ],
1853
+ stateMutability: "nonpayable"
1854
+ },
1855
+ {
1856
+ type: "function",
1857
+ name: "status",
1858
+ inputs: [],
1859
+ outputs: [
1860
+ {
1861
+ name: "",
1862
+ type: "tuple",
1863
+ internalType: "struct Status",
1864
+ components: [
1865
+ {
1866
+ name: "flags",
1867
+ type: "uint32",
1868
+ internalType: "uint32"
1869
+ },
1870
+ {
1871
+ name: "state",
1872
+ type: "uint8",
1873
+ internalType: "enum State"
1874
+ }
1875
+ ]
1876
+ }
1877
+ ],
1878
+ stateMutability: "view"
1879
+ },
1880
+ {
1881
+ type: "function",
1882
+ name: "stop",
1883
+ inputs: [],
1884
+ outputs: [
1885
+ {
1886
+ name: "",
1887
+ type: "bool",
1888
+ internalType: "bool"
1889
+ }
1890
+ ],
1891
+ stateMutability: "nonpayable"
1892
+ },
1893
+ {
1894
+ type: "function",
1895
+ name: "stopped",
1896
+ inputs: [],
1897
+ outputs: [
1898
+ {
1899
+ name: "",
1900
+ type: "bool",
1901
+ internalType: "bool"
1902
+ }
1903
+ ],
1904
+ stateMutability: "view"
1905
+ },
1906
+ {
1907
+ type: "function",
1908
+ name: "swap",
1909
+ inputs: [
1910
+ {
1911
+ name: "token",
1912
+ type: "address",
1913
+ internalType: "address"
1914
+ },
1915
+ {
1916
+ name: "amount",
1917
+ type: "uint256",
1918
+ internalType: "uint256"
1919
+ },
1920
+ {
1921
+ name: "slip",
1922
+ type: "uint256",
1923
+ internalType: "uint256"
1924
+ }
1925
+ ],
1926
+ outputs: [
1927
+ {
1928
+ name: "",
1929
+ type: "uint256",
1930
+ internalType: "uint256"
1931
+ }
1932
+ ],
1933
+ stateMutability: "nonpayable"
1934
+ },
1935
+ {
1936
+ type: "function",
1937
+ name: "tokenBalance",
1938
+ inputs: [
1939
+ {
1940
+ name: "token",
1941
+ type: "address",
1942
+ internalType: "address"
1943
+ }
1944
+ ],
1945
+ outputs: [
1946
+ {
1947
+ name: "",
1948
+ type: "uint256",
1949
+ internalType: "uint256"
1950
+ }
1951
+ ],
1952
+ stateMutability: "view"
1953
+ },
1954
+ {
1955
+ type: "function",
1956
+ name: "totals",
1957
+ inputs: [
1958
+ {
1959
+ name: "user",
1960
+ type: "address",
1961
+ internalType: "address"
1962
+ },
1963
+ {
1964
+ name: "token",
1965
+ type: "address",
1966
+ internalType: "address"
1967
+ }
1968
+ ],
1969
+ outputs: [
1970
+ {
1971
+ name: "",
1972
+ type: "tuple",
1973
+ internalType: "struct SwapTotal",
1974
+ components: [
1975
+ {
1976
+ name: "inputSum",
1977
+ type: "uint256",
1978
+ internalType: "uint256"
1979
+ },
1980
+ {
1981
+ name: "feeSum",
1982
+ type: "uint256",
1983
+ internalType: "uint256"
1984
+ },
1985
+ {
1986
+ name: "outputSum",
1987
+ type: "uint256",
1988
+ internalType: "uint256"
1989
+ },
1990
+ {
1991
+ name: "count",
1992
+ type: "uint256",
1993
+ internalType: "uint256"
1994
+ }
1995
+ ]
1996
+ }
1997
+ ],
1998
+ stateMutability: "view"
1999
+ },
2000
+ {
2001
+ type: "function",
2002
+ name: "totals",
2003
+ inputs: [
2004
+ {
2005
+ name: "token",
2006
+ type: "address",
2007
+ internalType: "address"
2008
+ }
2009
+ ],
2010
+ outputs: [
2011
+ {
2012
+ name: "",
2013
+ type: "tuple",
2014
+ internalType: "struct SwapTotal",
2015
+ components: [
2016
+ {
2017
+ name: "inputSum",
2018
+ type: "uint256",
2019
+ internalType: "uint256"
2020
+ },
2021
+ {
2022
+ name: "feeSum",
2023
+ type: "uint256",
2024
+ internalType: "uint256"
2025
+ },
2026
+ {
2027
+ name: "outputSum",
2028
+ type: "uint256",
2029
+ internalType: "uint256"
2030
+ },
2031
+ {
2032
+ name: "count",
2033
+ type: "uint256",
2034
+ internalType: "uint256"
2035
+ }
2036
+ ]
2037
+ }
2038
+ ],
2039
+ stateMutability: "view"
2040
+ },
2041
+ {
2042
+ type: "function",
2043
+ name: "transfer",
2044
+ inputs: [
2045
+ {
2046
+ name: "to",
2047
+ type: "address",
2048
+ internalType: "address"
2049
+ },
2050
+ {
2051
+ name: "amount",
2052
+ type: "uint256",
2053
+ internalType: "uint256"
2054
+ }
2055
+ ],
2056
+ outputs: [
2057
+ {
2058
+ name: "",
2059
+ type: "bool",
2060
+ internalType: "bool"
2061
+ }
2062
+ ],
2063
+ stateMutability: "nonpayable"
2064
+ },
2065
+ {
2066
+ type: "function",
2067
+ name: "transfer",
2068
+ inputs: [
2069
+ {
2070
+ name: "to",
2071
+ type: "address",
2072
+ internalType: "address"
2073
+ },
2074
+ {
2075
+ name: "token",
2076
+ type: "address",
2077
+ internalType: "address"
2078
+ },
2079
+ {
2080
+ name: "amount",
2081
+ type: "uint256",
2082
+ internalType: "uint256"
2083
+ }
2084
+ ],
2085
+ outputs: [
2086
+ {
2087
+ name: "",
2088
+ type: "bool",
2089
+ internalType: "bool"
2090
+ }
2091
+ ],
2092
+ stateMutability: "nonpayable"
2093
+ },
2094
+ {
2095
+ type: "function",
2096
+ name: "transferOwnership",
2097
+ inputs: [
2098
+ {
2099
+ name: "newOwner",
2100
+ type: "address",
2101
+ internalType: "address"
2102
+ }
2103
+ ],
2104
+ outputs: [],
2105
+ stateMutability: "payable"
2106
+ },
2107
+ {
2108
+ type: "event",
2109
+ name: "BpsUpdated",
2110
+ inputs: [
2111
+ {
2112
+ name: "prev",
2113
+ type: "uint256",
2114
+ indexed: false,
2115
+ internalType: "uint256"
2116
+ },
2117
+ {
2118
+ name: "next",
2119
+ type: "uint256",
2120
+ indexed: false,
2121
+ internalType: "uint256"
2122
+ }
2123
+ ],
2124
+ anonymous: false
2125
+ },
2126
+ {
2127
+ type: "event",
2128
+ name: "InputTokenUpdated",
2129
+ inputs: [
2130
+ {
2131
+ name: "token",
2132
+ type: "address",
2133
+ indexed: true,
2134
+ internalType: "address"
2135
+ },
2136
+ {
2137
+ name: "prev",
2138
+ type: "bool",
2139
+ indexed: false,
2140
+ internalType: "bool"
2141
+ },
2142
+ {
2143
+ name: "next",
2144
+ type: "bool",
2145
+ indexed: false,
2146
+ internalType: "bool"
2147
+ }
2148
+ ],
2149
+ anonymous: false
2150
+ },
2151
+ {
2152
+ type: "event",
2153
+ name: "OwnershipHandoverCanceled",
2154
+ inputs: [
2155
+ {
2156
+ name: "pendingOwner",
2157
+ type: "address",
2158
+ indexed: true,
2159
+ internalType: "address"
2160
+ }
2161
+ ],
2162
+ anonymous: false
2163
+ },
2164
+ {
2165
+ type: "event",
2166
+ name: "OwnershipHandoverRequested",
2167
+ inputs: [
2168
+ {
2169
+ name: "pendingOwner",
2170
+ type: "address",
2171
+ indexed: true,
2172
+ internalType: "address"
2173
+ }
2174
+ ],
2175
+ anonymous: false
2176
+ },
2177
+ {
2178
+ type: "event",
2179
+ name: "OwnershipTransferred",
2180
+ inputs: [
2181
+ {
2182
+ name: "oldOwner",
2183
+ type: "address",
2184
+ indexed: true,
2185
+ internalType: "address"
2186
+ },
2187
+ {
2188
+ name: "newOwner",
2189
+ type: "address",
2190
+ indexed: true,
2191
+ internalType: "address"
2192
+ }
2193
+ ],
2194
+ anonymous: false
2195
+ },
2196
+ {
2197
+ type: "event",
2198
+ name: "Paused",
2199
+ inputs: [
2200
+ {
2201
+ name: "previous",
2202
+ type: "uint32",
2203
+ indexed: false,
2204
+ internalType: "uint32"
2205
+ },
2206
+ {
2207
+ name: "next",
2208
+ type: "uint32",
2209
+ indexed: false,
2210
+ internalType: "uint32"
2211
+ }
2212
+ ],
2213
+ anonymous: false
2214
+ },
2215
+ {
2216
+ type: "event",
2217
+ name: "Stopped",
2218
+ inputs: [],
2219
+ anonymous: false
2220
+ },
2221
+ {
2222
+ type: "event",
2223
+ name: "Swapped",
2224
+ inputs: [
2225
+ {
2226
+ name: "user",
2227
+ type: "address",
2228
+ indexed: true,
2229
+ internalType: "address"
2230
+ },
2231
+ {
2232
+ name: "inputToken",
2233
+ type: "address",
2234
+ indexed: true,
2235
+ internalType: "address"
2236
+ },
2237
+ {
2238
+ name: "outputToken",
2239
+ type: "address",
2240
+ indexed: true,
2241
+ internalType: "address"
2242
+ },
2243
+ {
2244
+ name: "inputAmount",
2245
+ type: "uint256",
2246
+ indexed: false,
2247
+ internalType: "uint256"
2248
+ },
2249
+ {
2250
+ name: "fee",
2251
+ type: "uint256",
2252
+ indexed: false,
2253
+ internalType: "uint256"
2254
+ },
2255
+ {
2256
+ name: "outputAmount",
2257
+ type: "uint256",
2258
+ indexed: false,
2259
+ internalType: "uint256"
2260
+ }
2261
+ ],
2262
+ anonymous: false
2263
+ },
2264
+ {
2265
+ type: "event",
2266
+ name: "Transferred",
2267
+ inputs: [
2268
+ {
2269
+ name: "to",
2270
+ type: "address",
2271
+ indexed: true,
2272
+ internalType: "address"
2273
+ },
2274
+ {
2275
+ name: "token",
2276
+ type: "address",
2277
+ indexed: true,
2278
+ internalType: "address"
2279
+ },
2280
+ {
2281
+ name: "amount",
2282
+ type: "uint256",
2283
+ indexed: false,
2284
+ internalType: "uint256"
2285
+ }
2286
+ ],
2287
+ anonymous: false
2288
+ },
2289
+ {
2290
+ type: "error",
2291
+ name: "AlreadyInitialized",
2292
+ inputs: []
2293
+ },
2294
+ {
2295
+ type: "error",
2296
+ name: "InsufficientAmount",
2297
+ inputs: []
2298
+ },
2299
+ {
2300
+ type: "error",
2301
+ name: "InvalidAddress",
2302
+ inputs: []
2303
+ },
2304
+ {
2305
+ type: "error",
2306
+ name: "InvalidAmount",
2307
+ inputs: []
2308
+ },
2309
+ {
2310
+ type: "error",
2311
+ name: "IsPaused",
2312
+ inputs: [
2313
+ {
2314
+ name: "level",
2315
+ type: "uint32",
2316
+ internalType: "uint32"
2317
+ }
2318
+ ]
2319
+ },
2320
+ {
2321
+ type: "error",
2322
+ name: "IsStopped",
2323
+ inputs: []
2324
+ },
2325
+ {
2326
+ type: "error",
2327
+ name: "NewOwnerIsZeroAddress",
2328
+ inputs: []
2329
+ },
2330
+ {
2331
+ type: "error",
2332
+ name: "NoHandoverRequest",
2333
+ inputs: []
2334
+ },
2335
+ {
2336
+ type: "error",
2337
+ name: "SwapFailed",
2338
+ inputs: [
2339
+ {
2340
+ name: "user",
2341
+ type: "address",
2342
+ internalType: "address"
2343
+ },
2344
+ {
2345
+ name: "token",
2346
+ type: "address",
2347
+ internalType: "address"
2348
+ }
2349
+ ]
2350
+ },
2351
+ {
2352
+ type: "error",
2353
+ name: "Unauthorized",
2354
+ inputs: []
1315
2355
  }
2356
+ ];
2357
+
2358
+ // src/universal/types/providers/superstate/swap.ts
2359
+ var SwapPreview = {
2360
+ /** Maps the contract's `Preview { input, fee, output }` struct. */
2361
+ fromContract: (preview) => ({
2362
+ inputAmount: parseUint256(preview.input, "SwapPreview.input"),
2363
+ fee: parseUint256(preview.fee, "SwapPreview.fee"),
2364
+ outputAmount: parseUint256(preview.output, "SwapPreview.output")
2365
+ })
1316
2366
  };
1317
- function parseSwapCore(dto, spendDecimals) {
1318
- return {
1319
- tx: {
1320
- to: EvmContractAddress(dto.to),
1321
- data: HexEncodedTransactionData(dto.data)
1322
- },
1323
- expiresAt: parseExpiresAt(dto.expires_at),
1324
- spendInputAmount: parsePositiveAmount({
1325
- label: "spend_input_amount",
1326
- raw: dto.spend_input_amount,
1327
- decimals: spendDecimals,
1328
- // A transaction that takes nothing from the wallet is not one to sign:
1329
- // it would settle one leg of a trade and skip the other. Frontline
1330
- // refuses an `amount` of zero whichever way the trade runs, so this is a
1331
- // changed encoding rather than a small order.
1332
- //
1333
- // Guarded on both sides rather than on the sale alone, because which
1334
- // amount becomes the divisor in the price flips with the direction: a
1335
- // guard placed by that would be a rule about the arithmetic rather than
1336
- // about the trade.
1337
- reason: "a swap that spends nothing is not fillable"
1338
- })
1339
- };
1340
- }
1341
- function parseMinimumQuantity(raw, decimals, expectedQuantity) {
1342
- const amount = parsePositiveAmount({
1343
- label: "minimum_quantity",
1344
- raw,
1345
- decimals,
1346
- reason: "a floor of zero guarantees nothing"
1347
- });
1348
- if (amount.raw > expectedQuantity.raw) {
1349
- throw new ValidationError(
1350
- `minimum_quantity: must not exceed expected_quantity ("${raw}" > "${expectedQuantity.raw}")`
1351
- );
1352
- }
1353
- return amount;
1354
- }
1355
- function parsePositiveAmount({
1356
- label,
1357
- raw,
1358
- decimals,
1359
- reason
1360
- }) {
1361
- const amount = blockchainAmountFromRawOrThrow({ label, raw, decimals });
1362
- if (amount.raw <= 0n) {
1363
- throw new ValidationError(
1364
- `${label}: must be greater than zero ("${raw}") - ${reason}`
1365
- );
2367
+ var PauseFlags = (value) => value;
2368
+ var SwapStatus = {
2369
+ /**
2370
+ * Maps the contract's `Status { uint32 flags; State state }` struct, where
2371
+ * `State` is `0 = Active | 1 = Paused | 2 = Stopped`.
2372
+ *
2373
+ * `flags` is carried onto the `paused` arm only. On the other two the
2374
+ * contract sets it to a self-identifying marker rather than to information -
2375
+ * so repeating it would invite a caller to read meaning into a constant.
2376
+ *
2377
+ * @throws ValidationError on a `state` outside the enum. A contract that has
2378
+ * grown a fourth state is one the SDK does not model, and guessing `active`
2379
+ * would let a halted swap read as a live one.
2380
+ */
2381
+ fromContract: (status) => {
2382
+ switch (status.state) {
2383
+ case 0:
2384
+ return { state: "active" };
2385
+ case 1:
2386
+ return { state: "paused", pausedLevels: PauseFlags(status.flags) };
2387
+ case 2:
2388
+ return { state: "stopped" };
2389
+ default:
2390
+ throw new ValidationError(
2391
+ `SwapStatus.state: unknown contract state (${status.state})`
2392
+ );
2393
+ }
1366
2394
  }
1367
- return amount;
1368
- }
1369
- function parseExpiresAt(value) {
1370
- const date = new Date(value);
1371
- if (Number.isNaN(date.getTime())) {
1372
- throw new ValidationError(`expires_at: not a date ("${value}")`);
2395
+ };
2396
+ var AllowWalletResponse = {
2397
+ fromDto: (dto) => {
2398
+ switch (dto.action) {
2399
+ case "broadcast_transaction":
2400
+ return {
2401
+ action: "broadcast_transaction",
2402
+ to: EvmContractAddress(dto.to),
2403
+ data: HexEncodedTransactionData(dto.data)
2404
+ };
2405
+ case "none":
2406
+ return {
2407
+ action: "none",
2408
+ alreadyAllowed: dto.already_allowed
2409
+ };
2410
+ default: {
2411
+ const _exhaustive = dto;
2412
+ return _exhaustive;
2413
+ }
2414
+ }
1373
2415
  }
1374
- return date;
1375
- }
2416
+ };
1376
2417
 
1377
- // src/shared/api/frontline/providers/ondo/ondo.ts
1378
- async function getOndoTradingStatus(api, params) {
1379
- const dto = await api.send({
1380
- method: "GET",
1381
- url: "/v1/ondo/swap/trading-status",
1382
- queryParams: { symbol: params.symbol, side: params.side },
1383
- attributes: Attributes.protected()
1384
- });
1385
- return OndoTradingStatus.fromDto(dto);
1386
- }
1387
- async function getOndoQuote(api, params) {
2418
+ // src/universal/api/frontline/providers/superstate/swap.ts
2419
+ async function allowWallet(api, params) {
1388
2420
  const dto = await api.send({
1389
- method: "GET",
1390
- url: "/v1/ondo/swap/quote",
1391
- queryParams: {
1392
- symbol: params.symbol,
1393
- side: params.side,
1394
- duration: params.duration,
1395
- ...sizeParam(params)
2421
+ method: "POST",
2422
+ url: `/v1/offers/${encodeURIComponent(params.offerId)}/allow-wallet`,
2423
+ body: {
2424
+ wallet_address: params.walletAddress,
2425
+ chain: params.chain,
2426
+ signature: params.signature
1396
2427
  },
1397
2428
  attributes: Attributes.protected()
1398
2429
  });
1399
- return OndoQuote.fromDto(dto);
2430
+ return AllowWalletResponse.fromDto(dto);
1400
2431
  }
1401
- async function buildOndoBuy(api, params) {
1402
- const dto = await api.send({
1403
- method: "POST",
1404
- url: "/v1/ondo/swap/buy",
1405
- body: swapBody(params),
1406
- attributes: Attributes.protected()
2432
+
2433
+ // src/universal/api/rpc/providers/superstate/swap.ts
2434
+ async function getSwapAuthorization(clients, params) {
2435
+ return clients(params.chain).readContract({
2436
+ address: params.contractAddress,
2437
+ abi: SUPERSTATE_SWAP_ABI,
2438
+ functionName: "authorized",
2439
+ args: [params.walletAddress]
1407
2440
  });
1408
- assertSpendScaleAgrees({
1409
- published: dto.spend_input_decimals,
1410
- sized: params.amount,
1411
- trade: "purchase"
2441
+ }
2442
+ async function getSwapPreview(clients, params) {
2443
+ const preview = await clients(params.chain).readContract({
2444
+ address: params.contractAddress,
2445
+ abi: SUPERSTATE_SWAP_ABI,
2446
+ functionName: "preview",
2447
+ args: [params.inputToken, params.amount]
1412
2448
  });
1413
- return OndoBuyTransaction.fromDto(dto);
2449
+ return SwapPreview.fromContract(preview);
1414
2450
  }
1415
- async function buildOndoSell(api, params) {
1416
- const dto = await api.send({
1417
- method: "POST",
1418
- url: "/v1/ondo/swap/sell",
1419
- body: swapBody(params),
1420
- attributes: Attributes.protected()
2451
+ async function getSwapStatus(clients, params) {
2452
+ const status = await clients(params.chain).readContract({
2453
+ address: params.contractAddress,
2454
+ abi: SUPERSTATE_SWAP_ABI,
2455
+ functionName: "status"
1421
2456
  });
1422
- assertSpendScaleAgrees({
1423
- published: dto.spend_input_decimals,
1424
- sized: params.amount,
1425
- trade: "sale",
1426
- // The two answers come from two chains, so on a testnet they can disagree
1427
- // for a reason that is neither the caller's nor a corrupt response. Say so,
1428
- // or a QA run reads as a puzzle rather than a diagnosis.
1429
- note: "the quote resolves the asset on Ethereum mainnet while the swap executes on the chain requested, so these disagree until frontline serves a chain-scoped quote"
2457
+ return SwapStatus.fromContract(status);
2458
+ }
2459
+ async function getSwapOutputToken(clients, params) {
2460
+ const client = clients(params.chain);
2461
+ const tokenAddress = await client.readContract({
2462
+ address: params.contractAddress,
2463
+ abi: SUPERSTATE_SWAP_ABI,
2464
+ functionName: "outputToken"
2465
+ });
2466
+ const token = { address: EvmContractAddress(tokenAddress), abi: ERC20_ABI };
2467
+ const [name, symbol, decimals] = await client.multicall({
2468
+ contracts: [
2469
+ { ...token, functionName: "name" },
2470
+ { ...token, functionName: "symbol" },
2471
+ { ...token, functionName: "decimals" }
2472
+ ],
2473
+ allowFailure: false
1430
2474
  });
1431
- return OndoSellTransaction.fromDto(dto);
1432
- }
1433
- function swapBody(params) {
1434
2475
  return {
1435
- symbol: params.symbol,
1436
- chain: params.chain,
1437
- wallet_address: params.walletAddress,
1438
- amount: params.amount.raw.toString()
2476
+ name,
2477
+ symbol: AssetSymbol(symbol),
2478
+ decimals: AssetDecimals(decimals)
1439
2479
  };
1440
2480
  }
1441
- function assertSpendScaleAgrees({
1442
- published,
1443
- sized,
1444
- trade,
1445
- note
1446
- }) {
1447
- if (published === sized.decimals) return;
1448
- const because = note === void 0 ? "" : ` - ${note}`;
1449
- throw new ValidationError(
1450
- `spend_input_decimals: the ${trade} was priced in ${published} decimals but the order was sized in ${sized.decimals}${because}`
1451
- );
1452
- }
1453
- function sizeParam(params) {
1454
- const tokenAmount = "tokenAmount" in params ? params.tokenAmount : void 0;
1455
- const notionalValue = "notionalValue" in params ? params.notionalValue : void 0;
1456
- if (tokenAmount !== void 0) {
1457
- if (notionalValue !== void 0) {
1458
- throw new ValidationError(
1459
- "An Ondo quote takes tokenAmount or notionalValue, not both"
1460
- );
1461
- }
1462
- return { token_amount: formatRawAmount(tokenAmount) };
1463
- }
1464
- if (notionalValue === void 0) {
1465
- throw new ValidationError(
1466
- "An Ondo quote must be sized by tokenAmount or notionalValue"
1467
- );
1468
- }
1469
- return { notional_value: notionalValue };
1470
- }
1471
-
1472
- // src/shared/core/checkout/ondo/ondo-namespace.ts
1473
- var OndoNamespaceImpl = class {
1474
- constructor(ctx) {
1475
- this.ctx = ctx;
1476
- this.log = internalLogger(ctx.logger, "ONDO");
1477
- }
1478
- async getTradingStatus(params) {
1479
- return this.log.wrap("getTradingStatus", params, async () => {
1480
- await this.ctx.ensureUserAuthenticated();
1481
- return getOndoTradingStatus(this.ctx.api, params);
1482
- });
1483
- }
1484
- async getQuote(params) {
1485
- return this.log.wrap("getQuote", params, async () => {
1486
- await this.ctx.ensureUserAuthenticated();
1487
- return getOndoQuote(this.ctx.api, params);
1488
- });
1489
- }
1490
- async buildBuyTransaction(params) {
1491
- return this.log.wrap("buildBuyTransaction", params, async () => {
1492
- await this.ctx.ensureUserAuthenticated();
1493
- return buildOndoBuy(this.ctx.api, params);
1494
- });
1495
- }
1496
- async buildSellTransaction(params) {
1497
- return this.log.wrap("buildSellTransaction", params, async () => {
1498
- await this.ctx.ensureUserAuthenticated();
1499
- return buildOndoSell(this.ctx.api, params);
1500
- });
1501
- }
1502
- };
1503
2481
 
1504
- // src/shared/core/checkout/superstate/swap-namespace.ts
2482
+ // src/universal/core/checkout/superstate/swap-namespace.ts
1505
2483
  var SuperstateSwapNamespaceImpl = class {
1506
2484
  constructor(ctx) {
1507
2485
  this.ctx = ctx;
1508
2486
  this.log = internalLogger(ctx.logger, "SUPERSTATE");
1509
2487
  }
1510
2488
  async getAuthorization(params) {
1511
- return this.log.wrap("getAuthorization", params, async () => {
1512
- await this.ctx.ensureUserAuthenticated();
1513
- return getSwapAuthorization(this.ctx.api, params);
1514
- });
2489
+ return this.log.wrap(
2490
+ "getAuthorization",
2491
+ params,
2492
+ async () => getSwapAuthorization(this.ctx.rpc, params)
2493
+ );
1515
2494
  }
1516
2495
  async getPreview(params) {
1517
- return this.log.wrap("getPreview", params, async () => {
1518
- await this.ctx.ensureUserAuthenticated();
1519
- return getSwapPreview(this.ctx.api, params);
1520
- });
2496
+ return this.log.wrap(
2497
+ "getPreview",
2498
+ params,
2499
+ async () => getSwapPreview(this.ctx.rpc, params)
2500
+ );
1521
2501
  }
1522
2502
  async getStatus(params) {
1523
- return this.log.wrap("getStatus", params, async () => {
1524
- await this.ctx.ensureUserAuthenticated();
1525
- return getSwapStatus(this.ctx.api, params);
1526
- });
2503
+ return this.log.wrap(
2504
+ "getStatus",
2505
+ params,
2506
+ async () => getSwapStatus(this.ctx.rpc, params)
2507
+ );
1527
2508
  }
1528
2509
  async getOutputToken(params) {
1529
- return this.log.wrap("getOutputToken", params, async () => {
1530
- await this.ctx.ensureUserAuthenticated();
1531
- return getSwapOutputToken(this.ctx.api, params);
1532
- });
2510
+ return this.log.wrap(
2511
+ "getOutputToken",
2512
+ params,
2513
+ async () => getSwapOutputToken(this.ctx.rpc, params)
2514
+ );
1533
2515
  }
1534
2516
  async allowWallet(params) {
1535
2517
  return this.log.wrap("allowWallet", params, async () => {
@@ -1539,7 +2521,7 @@ var SuperstateSwapNamespaceImpl = class {
1539
2521
  }
1540
2522
  };
1541
2523
 
1542
- // src/shared/types/document-submission.ts
2524
+ // src/universal/types/document-submission.ts
1543
2525
  var DocumentSubmission = {
1544
2526
  fromDto: (dto) => ({
1545
2527
  status: dto.status,
@@ -1547,14 +2529,14 @@ var DocumentSubmission = {
1547
2529
  })
1548
2530
  };
1549
2531
 
1550
- // src/shared/types/kyc.ts
2532
+ // src/universal/types/kyc.ts
1551
2533
  var KycToken = {
1552
2534
  fromDto: (dto) => ({
1553
2535
  token: dto.token
1554
2536
  })
1555
2537
  };
1556
2538
 
1557
- // src/shared/types/pii.ts
2539
+ // src/universal/types/pii.ts
1558
2540
  var Iso2CountryCode = (value) => value;
1559
2541
  var PiiJurisdiction = {
1560
2542
  fromDto: (dto) => ({
@@ -1582,7 +2564,7 @@ var Pii = {
1582
2564
  })
1583
2565
  };
1584
2566
 
1585
- // src/shared/types/requirement.ts
2567
+ // src/universal/types/requirement.ts
1586
2568
  var RequirementId = (value) => value;
1587
2569
  var Requirement = {
1588
2570
  fromDto: (dto) => ({
@@ -1603,7 +2585,7 @@ var RequirementStatusInfo = {
1603
2585
  )
1604
2586
  };
1605
2587
 
1606
- // src/shared/api/frontline/documents.ts
2588
+ // src/universal/api/frontline/documents.ts
1607
2589
  async function submitDocument(api, documentType, fields) {
1608
2590
  const dto = await api.send({
1609
2591
  method: "POST",
@@ -1614,7 +2596,7 @@ async function submitDocument(api, documentType, fields) {
1614
2596
  return DocumentSubmission.fromDto(dto);
1615
2597
  }
1616
2598
 
1617
- // src/shared/api/frontline/kyc.ts
2599
+ // src/universal/api/frontline/kyc.ts
1618
2600
  async function createKycToken(api, levelName, reset) {
1619
2601
  const dto = await api.send({
1620
2602
  method: "POST",
@@ -1628,7 +2610,7 @@ async function createKycToken(api, levelName, reset) {
1628
2610
  return KycToken.fromDto(dto);
1629
2611
  }
1630
2612
 
1631
- // src/shared/api/frontline/pii.ts
2613
+ // src/universal/api/frontline/pii.ts
1632
2614
  async function fetchPii(api) {
1633
2615
  const dto = await api.send({
1634
2616
  method: "GET",
@@ -1638,7 +2620,7 @@ async function fetchPii(api) {
1638
2620
  return Pii.fromDto(dto);
1639
2621
  }
1640
2622
 
1641
- // src/shared/api/frontline/requirements.ts
2623
+ // src/universal/api/frontline/requirements.ts
1642
2624
  async function fetchOfferRequirements(api, offerId, clientCreds) {
1643
2625
  const response = await api.send({
1644
2626
  method: "GET",
@@ -1664,7 +2646,7 @@ async function fetchRequirementStatuses(api, offerId) {
1664
2646
  return RequirementStatusInfo.fromStatusesDto(response);
1665
2647
  }
1666
2648
 
1667
- // src/shared/core/requirements/requirements-namespace.ts
2649
+ // src/universal/core/requirements/requirements-namespace.ts
1668
2650
  var RequirementsNamespaceImpl = class {
1669
2651
  constructor(ctx) {
1670
2652
  this.ctx = ctx;
@@ -1714,7 +2696,49 @@ var RequirementsNamespaceImpl = class {
1714
2696
  }
1715
2697
  };
1716
2698
 
1717
- // src/shared/types/token-metadata.ts
2699
+ // src/universal/api/rpc/erc20.ts
2700
+ async function getTokenAllowance(clients, params) {
2701
+ const allowance = await clients(params.chain).readContract({
2702
+ address: params.tokenAddress,
2703
+ abi: ERC20_ABI,
2704
+ functionName: "allowance",
2705
+ args: [params.owner, params.spender]
2706
+ });
2707
+ return parseUint256(allowance, "allowance");
2708
+ }
2709
+ async function getTokenBalance(clients, params) {
2710
+ const balance = await clients(params.chain).readContract({
2711
+ address: params.tokenAddress,
2712
+ abi: ERC20_ABI,
2713
+ functionName: "balanceOf",
2714
+ args: [params.owner]
2715
+ });
2716
+ return parseUint256(balance, "balanceOf");
2717
+ }
2718
+
2719
+ // src/universal/core/shared/blockchain/erc20/erc20-namespace.ts
2720
+ var Erc20NamespaceImpl = class {
2721
+ constructor(ctx) {
2722
+ this.ctx = ctx;
2723
+ this.log = internalLogger(ctx.logger, "ERC20");
2724
+ }
2725
+ async getAllowance(params) {
2726
+ return this.log.wrap(
2727
+ "getAllowance",
2728
+ params,
2729
+ async () => getTokenAllowance(this.ctx.rpc, params)
2730
+ );
2731
+ }
2732
+ async getBalance(params) {
2733
+ return this.log.wrap(
2734
+ "getBalance",
2735
+ params,
2736
+ async () => getTokenBalance(this.ctx.rpc, params)
2737
+ );
2738
+ }
2739
+ };
2740
+
2741
+ // src/universal/types/token-metadata.ts
1718
2742
  var TokenLogoUrl = (value) => value;
1719
2743
  var TokenLogo = {
1720
2744
  /** `baseUrl` is the registry origin; registry URLs are root-relative. */
@@ -1797,10 +2821,10 @@ var resolveLogoUrl = (url, baseUrl) => TokenLogoUrl(
1797
2821
  url.startsWith("http") ? url : `${baseUrl.replace(/\/$/, "")}${url}`
1798
2822
  );
1799
2823
 
1800
- // src/shared/api/nabu/tokens.ts
2824
+ // src/universal/api/nabu/tokens.ts
1801
2825
  import { getAddress } from "viem";
1802
2826
 
1803
- // src/shared/api/frontline/config.ts
2827
+ // src/universal/api/frontline/config.ts
1804
2828
  var PUBLIC_API_BASE_URL = "https://api.coinlist.co";
1805
2829
  var HEADER_API_VERSION = "X-API-Version";
1806
2830
  var HEADER_USER_AGENT = "User-Agent";
@@ -1813,7 +2837,7 @@ var VERIFY_IDENTITY_PATH = "/verify-identity";
1813
2837
  var VERIFY_IDENTITY_ACCREDITATION_PATH = "/verify-identity/accreditation_full";
1814
2838
  var WALLET_PATH = "/wallet";
1815
2839
 
1816
- // src/shared/api/http-client.ts
2840
+ // src/universal/api/http-client.ts
1817
2841
  var HttpClient = class {
1818
2842
  constructor(config, middleware = {}, logger = null, options = {}) {
1819
2843
  this.config = config;
@@ -1874,9 +2898,9 @@ var HttpClient = class {
1874
2898
  if (url.startsWith("http://") || url.startsWith("https://")) {
1875
2899
  return url;
1876
2900
  }
1877
- const base = this.config.baseUrl.replace(/\/$/, "");
2901
+ const base2 = this.config.baseUrl.replace(/\/$/, "");
1878
2902
  const path = url.startsWith("/") ? url : `/${url}`;
1879
- return base + path;
2903
+ return base2 + path;
1880
2904
  }
1881
2905
  async runBeforeRequestMiddleware(initialRequest) {
1882
2906
  let request = initialRequest;
@@ -1969,7 +2993,7 @@ function describeRequestUnredacted(request) {
1969
2993
  };
1970
2994
  }
1971
2995
 
1972
- // src/shared/api/nabu/tokens.ts
2996
+ // src/universal/api/nabu/tokens.ts
1973
2997
  function createNabuApiClient(baseUrl, logger = null) {
1974
2998
  return new HttpClient({ baseUrl }, {}, logger);
1975
2999
  }
@@ -2060,10 +3084,10 @@ function checksummed(address) {
2060
3084
  }
2061
3085
  }
2062
3086
 
2063
- // src/shared/core/tokens/tokens-namespace.ts
3087
+ // src/universal/core/tokens/tokens-namespace.ts
2064
3088
  var TokensNamespaceImpl = class {
2065
3089
  /**
2066
- * Takes the registry origin rather than a `SharedNamespaceContext`: the
3090
+ * Takes the registry origin rather than a `UniversalNamespaceContext`: the
2067
3091
  * registry is unauthenticated and on its own host, so the frontline sender
2068
3092
  * and the auth check would both be dead weight here.
2069
3093
  */
@@ -2087,7 +3111,7 @@ var TokensNamespaceImpl = class {
2087
3111
  }
2088
3112
  };
2089
3113
 
2090
- // src/shared/types/offer-option-address.ts
3114
+ // src/universal/types/offer-option-address.ts
2091
3115
  var OfferOptionAddressId = (value) => value;
2092
3116
  var OfferOptionAddress = {
2093
3117
  /** Maps the API DTO into the SDK offer-option-address domain model. */
@@ -2109,7 +3133,7 @@ var ConnectExternalWalletParams = {
2109
3133
  })
2110
3134
  };
2111
3135
 
2112
- // src/shared/types/wallet-ownership-challenge.ts
3136
+ // src/universal/types/wallet-ownership-challenge.ts
2113
3137
  var WalletOwnershipChallenge = {
2114
3138
  /** Maps the API DTO into the SDK wallet-ownership-challenge domain model. */
2115
3139
  fromDto: (dto) => ({
@@ -2148,7 +3172,7 @@ var CreateWalletOwnershipChallengeParams = {
2148
3172
  }
2149
3173
  };
2150
3174
 
2151
- // src/shared/api/frontline/wallet-connect.ts
3175
+ // src/universal/api/frontline/wallet-connect.ts
2152
3176
  async function createWalletOwnershipChallenge(api, params) {
2153
3177
  const dto = await api.send({
2154
3178
  method: "POST",
@@ -2185,7 +3209,7 @@ async function removeOptionAddress(api, offerId, addressId) {
2185
3209
  return OfferOptionAddress.fromDto(dto);
2186
3210
  }
2187
3211
 
2188
- // src/shared/core/wallets/wallets-namespace.ts
3212
+ // src/universal/core/wallets/wallets-namespace.ts
2189
3213
  var WalletsNamespaceImpl = class {
2190
3214
  constructor(ctx) {
2191
3215
  this.ctx = ctx;
@@ -2228,7 +3252,7 @@ var WalletsNamespaceImpl = class {
2228
3252
  }
2229
3253
  };
2230
3254
 
2231
- // src/shared/types/oauth-session.ts
3255
+ // src/universal/types/oauth-session.ts
2232
3256
  var ClientCredentialsOAuth = (value) => value;
2233
3257
  var OAuthRefreshToken = (value) => value;
2234
3258
  var OAuthSession = {
@@ -2244,7 +3268,7 @@ var OAuthSession = {
2244
3268
  }
2245
3269
  };
2246
3270
 
2247
- // src/shared/api/frontline/offers.ts
3271
+ // src/universal/api/frontline/offers.ts
2248
3272
  async function fetchOffers(api, clientCreds) {
2249
3273
  return fetchAllPages((params) => fetchOffersPage(api, params, clientCreds));
2250
3274
  }
@@ -2300,11 +3324,19 @@ export {
2300
3324
  describeErrorUnredacted,
2301
3325
  internalLogger,
2302
3326
  HttpClient,
3327
+ ERC20_ABI,
2303
3328
  fetchAllPages,
3329
+ Cursor,
3330
+ PaginatedResponse,
3331
+ PaginationParams,
3332
+ AssetId,
3333
+ AssetCode,
3334
+ Asset,
2304
3335
  ETHEREUM_CHAINS,
2305
3336
  EthereumChain,
2306
3337
  SOLANA_CHAINS,
2307
3338
  SolanaChain,
3339
+ isChain,
2308
3340
  Chain,
2309
3341
  EvmWalletAddress,
2310
3342
  EvmContractAddress,
@@ -2321,44 +3353,12 @@ export {
2321
3353
  StablecoinSymbol,
2322
3354
  KnownAssetSymbol,
2323
3355
  Bps,
2324
- FormattedAmountUi,
2325
- FormattedPercentUi,
2326
- TxExplorerUrl,
2327
- ShortenedWalletAddress,
2328
- FormattedAmountAssetUi,
2329
- AssetIconUrl,
2330
- getChainId,
2331
- chainFromId,
2332
- getNetworkName,
2333
- txExplorerUrl,
2334
- SwapAuthorization,
2335
- SwapPreview,
2336
- SwapStatus,
2337
- TokenAllowance,
2338
- TokenBalance,
2339
- AllowWalletResponse,
2340
- Erc20NamespaceImpl,
2341
- shortenAddress,
2342
- formatAmount,
2343
- formatRawAmount,
2344
- formatCompactAmount,
2345
- formatBpsAsPercent,
2346
- usdAmount,
2347
- assetAmount,
2348
- NA_AMOUNT_ASSET_UI,
2349
- formattedUsdPrice,
2350
- blockchainAmountFromRawOrThrow,
2351
- parseBlockchainAmount,
2352
- Cursor,
2353
- PaginatedResponse,
2354
- PaginationParams,
2355
- AssetId,
2356
- AssetCode,
2357
- Asset,
2358
3356
  OfferId,
2359
3357
  OfferSlug,
2360
3358
  Offer,
2361
3359
  OfferToken,
3360
+ Ticker,
3361
+ Isin,
2362
3362
  OfferOptionId,
2363
3363
  OfferOptionSlug,
2364
3364
  OfferSwapContract,
@@ -2375,12 +3375,38 @@ export {
2375
3375
  Participation,
2376
3376
  CreateParticipationParams,
2377
3377
  CoinListTokenSaleNamespaceImpl,
2378
- Ticker,
3378
+ FormattedAmountUi,
3379
+ FormattedPercentUi,
3380
+ TxExplorerUrl,
3381
+ ShortenedWalletAddress,
3382
+ FormattedAmountAssetUi,
3383
+ AssetIconUrl,
3384
+ shortenAddress,
3385
+ formatAmount,
3386
+ formatRawAmount,
3387
+ formatCompactAmount,
3388
+ formatBpsAsPercent,
3389
+ usdAmount,
3390
+ assetAmount,
3391
+ NA_AMOUNT_ASSET_UI,
3392
+ formattedUsdPrice,
3393
+ viemChain,
3394
+ getChainId,
3395
+ chainFromId,
3396
+ getNetworkName,
3397
+ txExplorerUrl,
3398
+ blockchainAmountFromRawOrThrow,
3399
+ parseBlockchainAmount,
2379
3400
  OndoTradingStatus,
2380
3401
  OndoQuote,
2381
3402
  OndoBuyTransaction,
2382
3403
  OndoSellTransaction,
2383
3404
  OndoNamespaceImpl,
3405
+ SUPERSTATE_SWAP_ABI,
3406
+ SwapPreview,
3407
+ PauseFlags,
3408
+ SwapStatus,
3409
+ AllowWalletResponse,
2384
3410
  SuperstateSwapNamespaceImpl,
2385
3411
  fetchOffers,
2386
3412
  fetchOffersPage,
@@ -2396,6 +3422,7 @@ export {
2396
3422
  RequirementStatusInfo,
2397
3423
  fetchOfferRequirements,
2398
3424
  RequirementsNamespaceImpl,
3425
+ Erc20NamespaceImpl,
2399
3426
  TokenLogoUrl,
2400
3427
  TokenLogo,
2401
3428
  TokenMetadata,
@@ -2410,4 +3437,4 @@ export {
2410
3437
  OAuthRefreshToken,
2411
3438
  OAuthSession
2412
3439
  };
2413
- //# sourceMappingURL=chunk-3ATIDGVR.js.map
3440
+ //# sourceMappingURL=chunk-2YEJXE2V.js.map