@coinlist-co/react 0.6.0 → 0.10.0

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 (39) hide show
  1. package/dist/{chunk-5C4TEVM7.js → chunk-7BJ2HAG7.js} +62 -92
  2. package/dist/chunk-7BJ2HAG7.js.map +1 -0
  3. package/dist/{chunk-5E3P7AMH.js → chunk-AAER5LOL.js} +3 -1
  4. package/dist/chunk-AAER5LOL.js.map +1 -0
  5. package/dist/chunk-GSSAB4K5.js +644 -0
  6. package/dist/chunk-GSSAB4K5.js.map +1 -0
  7. package/dist/chunk-TUZKKFNW.js +836 -0
  8. package/dist/chunk-TUZKKFNW.js.map +1 -0
  9. package/dist/client/index.cjs +3203 -412
  10. package/dist/client/index.cjs.map +1 -1
  11. package/dist/client/index.d.cts +996 -41
  12. package/dist/client/index.d.ts +996 -41
  13. package/dist/client/index.js +2069 -208
  14. package/dist/client/index.js.map +1 -1
  15. package/dist/collections-CJ24dOda.d.cts +28 -0
  16. package/dist/collections-ZYLKp8JB.d.ts +28 -0
  17. package/dist/requirement-CDi5NJI8.d.cts +1036 -0
  18. package/dist/requirement-CDi5NJI8.d.ts +1036 -0
  19. package/dist/server/index.cjs +588 -85
  20. package/dist/server/index.cjs.map +1 -1
  21. package/dist/server/index.d.cts +117 -17
  22. package/dist/server/index.d.ts +117 -17
  23. package/dist/server/index.js +92 -40
  24. package/dist/server/index.js.map +1 -1
  25. package/dist/shared/index.cjs +1334 -91
  26. package/dist/shared/index.cjs.map +1 -1
  27. package/dist/shared/index.d.cts +624 -3
  28. package/dist/shared/index.d.ts +624 -3
  29. package/dist/shared/index.js +220 -5
  30. package/dist/shared/index.js.map +1 -1
  31. package/package.json +7 -3
  32. package/dist/chunk-5C4TEVM7.js.map +0 -1
  33. package/dist/chunk-5E3P7AMH.js.map +0 -1
  34. package/dist/chunk-7SB2GKEU.js +0 -311
  35. package/dist/chunk-7SB2GKEU.js.map +0 -1
  36. package/dist/chunk-UEJVCU2J.js +0 -43
  37. package/dist/chunk-UEJVCU2J.js.map +0 -1
  38. package/dist/requirement-Dk6nYN1c.d.cts +0 -389
  39. package/dist/requirement-Dk6nYN1c.d.ts +0 -389
@@ -20,20 +20,46 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/shared/index.ts
21
21
  var shared_exports = {};
22
22
  __export(shared_exports, {
23
+ AllowWalletResponse: () => AllowWalletResponse,
23
24
  Asset: () => Asset,
24
25
  AssetCode: () => AssetCode,
26
+ AssetDecimals: () => AssetDecimals,
27
+ AssetIconUrl: () => AssetIconUrl,
25
28
  AssetId: () => AssetId,
29
+ AssetSymbol: () => AssetSymbol,
26
30
  AuthorizationCode: () => AuthorizationCode,
31
+ BPS_DENOM: () => BPS_DENOM,
27
32
  Blockchain: () => Blockchain,
33
+ BlockchainAmount: () => BlockchainAmount,
34
+ Bps: () => Bps,
35
+ ClientCredentialsOAuth: () => ClientCredentialsOAuth,
28
36
  ClientId: () => ClientId,
29
37
  ClientSecret: () => ClientSecret,
30
38
  CodeChallenge: () => CodeChallenge,
31
39
  CodeVerifier: () => CodeVerifier,
40
+ ConnectExternalWalletParams: () => ConnectExternalWalletParams,
32
41
  CreateParticipationParams: () => CreateParticipationParams,
42
+ CreateWalletOwnershipChallengeParams: () => CreateWalletOwnershipChallengeParams,
33
43
  Cursor: () => Cursor,
44
+ DEFAULT_AMOUNT_TO_COMPUTE_PRICE: () => DEFAULT_AMOUNT_TO_COMPUTE_PRICE,
45
+ DEFAULT_SLIPPAGE_BPS: () => DEFAULT_SLIPPAGE_BPS,
46
+ DocumentSubmission: () => DocumentSubmission,
47
+ ERC20_ABI: () => ERC20_ABI,
48
+ Erc20NamespaceImpl: () => Erc20NamespaceImpl,
49
+ EvmContractAddress: () => EvmContractAddress,
50
+ EvmWalletAddress: () => EvmWalletAddress,
34
51
  FaqItem: () => FaqItem,
52
+ FormattedAmountAssetUi: () => FormattedAmountAssetUi,
53
+ FormattedAmountUi: () => FormattedAmountUi,
54
+ FormattedPercentUi: () => FormattedPercentUi,
55
+ HexEncodedTransactionData: () => HexEncodedTransactionData,
56
+ Iso2CountryCode: () => Iso2CountryCode,
57
+ KnownAssetSymbol: () => KnownAssetSymbol,
58
+ KycToken: () => KycToken,
35
59
  Link: () => Link,
60
+ MAX_UINT_256: () => MAX_UINT_256,
36
61
  Milestone: () => Milestone,
62
+ NA_AMOUNT_ASSET_UI: () => NA_AMOUNT_ASSET_UI,
37
63
  NotAuthenticatedError: () => NotAuthenticatedError,
38
64
  NotImplementedError: () => NotImplementedError,
39
65
  OAuthRefreshToken: () => OAuthRefreshToken,
@@ -42,6 +68,8 @@ __export(shared_exports, {
42
68
  OfferDetail: () => OfferDetail,
43
69
  OfferId: () => OfferId,
44
70
  OfferOption: () => OfferOption,
71
+ OfferOptionAddress: () => OfferOptionAddress,
72
+ OfferOptionAddressId: () => OfferOptionAddressId,
45
73
  OfferOptionId: () => OfferOptionId,
46
74
  OfferOptionSlug: () => OfferOptionSlug,
47
75
  OfferSlug: () => OfferSlug,
@@ -51,17 +79,61 @@ __export(shared_exports, {
51
79
  Participation: () => Participation,
52
80
  ParticipationId: () => ParticipationId,
53
81
  ParticipationsPaginationParams: () => ParticipationsPaginationParams,
82
+ Pii: () => Pii,
83
+ PiiAddress: () => PiiAddress,
84
+ PiiJurisdiction: () => PiiJurisdiction,
54
85
  RedirectUri: () => RedirectUri,
55
86
  Requirement: () => Requirement,
56
87
  RequirementId: () => RequirementId,
57
88
  RequirementStatusInfo: () => RequirementStatusInfo,
89
+ SLIPPAGE_OPTIONS_BPS: () => SLIPPAGE_OPTIONS_BPS,
90
+ SUPERSTATE_SWAP_ABI: () => SUPERSTATE_SWAP_ABI,
91
+ SUPERSTATE_SWAP_CONTRACT_ADDRESS_SEPOLIA: () => SUPERSTATE_SWAP_CONTRACT_ADDRESS_SEPOLIA,
92
+ SUPERSTATE_TOS_URL: () => SUPERSTATE_TOS_URL,
93
+ SWAP_POLL_INTERVAL_MS: () => SWAP_POLL_INTERVAL_MS,
94
+ ShortenedWalletAddress: () => ShortenedWalletAddress,
95
+ StablecoinSymbol: () => StablecoinSymbol,
96
+ SwapAuthorization: () => SwapAuthorization,
97
+ SwapNamespaceImpl: () => SwapNamespaceImpl,
98
+ SwapPreview: () => SwapPreview,
99
+ SwapQuote: () => SwapQuote,
100
+ SwapStatus: () => SwapStatus,
101
+ TOKEN_REGISTRY: () => TOKEN_REGISTRY,
58
102
  TermItem: () => TermItem,
103
+ TokenAllowance: () => TokenAllowance,
104
+ TokenBalance: () => TokenBalance,
105
+ TokenSaleNamespaceImpl: () => TokenSaleNamespaceImpl,
106
+ TxExplorerUrl: () => TxExplorerUrl,
107
+ USDC: () => USDC,
108
+ USDC_SYMBOL: () => USDC_SYMBOL,
109
+ USDT: () => USDT,
110
+ USDT_SYMBOL: () => USDT_SYMBOL,
59
111
  User: () => User,
60
112
  UserEmail: () => UserEmail,
61
113
  UserId: () => UserId,
62
114
  WalletAddress: () => WalletAddress,
115
+ WalletOwnershipChallenge: () => WalletOwnershipChallenge,
116
+ applyBps: () => applyBps,
117
+ assertUint256: () => assertUint256,
118
+ assetAmount: () => assetAmount,
119
+ computePrice: () => computePrice,
120
+ computeSlip: () => computeSlip,
121
+ decodeSwappedOutputAmount: () => decodeSwappedOutputAmount,
63
122
  fetchAllPages: () => fetchAllPages,
64
- generatePKCEParams: () => generatePKCEParams
123
+ formatAmount: () => formatAmount,
124
+ formatBpsAsPercent: () => formatBpsAsPercent,
125
+ formatCompactAmount: () => formatCompactAmount,
126
+ formatRawAmount: () => formatRawAmount,
127
+ formattedPricePerShare: () => formattedPricePerShare,
128
+ formattedUsdPrice: () => formattedUsdPrice,
129
+ generatePKCEParams: () => generatePKCEParams,
130
+ getChainId: () => getChainId,
131
+ getNetworkName: () => getNetworkName,
132
+ isStopped: () => isStopped,
133
+ parseBlockchainAmount: () => parseBlockchainAmount,
134
+ shortenAddress: () => shortenAddress,
135
+ txExplorerUrl: () => txExplorerUrl,
136
+ usdAmount: () => usdAmount
65
137
  });
66
138
  module.exports = __toCommonJS(shared_exports);
67
139
 
@@ -104,68 +176,894 @@ var PaginationParams = {
104
176
  }
105
177
  };
106
178
 
107
- // src/shared/types/oauth.ts
108
- var AuthorizationCode = (value) => value;
109
- var CodeVerifier = (value) => value;
110
- var CodeChallenge = (value) => value;
111
- var PKCEState = (value) => value;
112
- var RedirectUri = (value) => value;
113
- var ClientId = (value) => value;
114
- var ClientSecret = (value) => value;
179
+ // src/shared/core/blockchain/abis/erc20.ts
180
+ var ERC20_ABI = [
181
+ {
182
+ type: "function",
183
+ name: "allowance",
184
+ inputs: [
185
+ { name: "owner", type: "address" },
186
+ { name: "spender", type: "address" }
187
+ ],
188
+ outputs: [{ name: "", type: "uint256" }],
189
+ stateMutability: "view"
190
+ },
191
+ {
192
+ type: "function",
193
+ name: "approve",
194
+ inputs: [
195
+ { name: "spender", type: "address" },
196
+ { name: "amount", type: "uint256" }
197
+ ],
198
+ outputs: [{ name: "", type: "bool" }],
199
+ stateMutability: "nonpayable"
200
+ },
201
+ {
202
+ type: "function",
203
+ name: "balanceOf",
204
+ inputs: [{ name: "account", type: "address" }],
205
+ outputs: [{ name: "", type: "uint256" }],
206
+ stateMutability: "view"
207
+ },
208
+ {
209
+ type: "function",
210
+ name: "decimals",
211
+ inputs: [],
212
+ outputs: [{ name: "", type: "uint8" }],
213
+ stateMutability: "view"
214
+ },
215
+ {
216
+ type: "function",
217
+ name: "name",
218
+ inputs: [],
219
+ outputs: [{ name: "", type: "string" }],
220
+ stateMutability: "view"
221
+ },
222
+ {
223
+ type: "function",
224
+ name: "symbol",
225
+ inputs: [],
226
+ outputs: [{ name: "", type: "string" }],
227
+ stateMutability: "view"
228
+ },
229
+ {
230
+ type: "function",
231
+ name: "totalSupply",
232
+ inputs: [],
233
+ outputs: [{ name: "", type: "uint256" }],
234
+ stateMutability: "view"
235
+ },
236
+ {
237
+ type: "function",
238
+ name: "transfer",
239
+ inputs: [
240
+ { name: "recipient", type: "address" },
241
+ { name: "amount", type: "uint256" }
242
+ ],
243
+ outputs: [{ name: "", type: "bool" }],
244
+ stateMutability: "nonpayable"
245
+ },
246
+ {
247
+ type: "function",
248
+ name: "transferFrom",
249
+ inputs: [
250
+ { name: "sender", type: "address" },
251
+ { name: "recipient", type: "address" },
252
+ { name: "amount", type: "uint256" }
253
+ ],
254
+ outputs: [{ name: "", type: "bool" }],
255
+ stateMutability: "nonpayable"
256
+ },
257
+ {
258
+ type: "event",
259
+ name: "Approval",
260
+ inputs: [
261
+ { name: "owner", type: "address", indexed: true },
262
+ { name: "spender", type: "address", indexed: true },
263
+ { name: "value", type: "uint256", indexed: false }
264
+ ],
265
+ anonymous: false
266
+ },
267
+ {
268
+ type: "event",
269
+ name: "Transfer",
270
+ inputs: [
271
+ { name: "from", type: "address", indexed: true },
272
+ { name: "to", type: "address", indexed: true },
273
+ { name: "value", type: "uint256", indexed: false }
274
+ ],
275
+ anonymous: false
276
+ }
277
+ ];
115
278
 
116
- // src/shared/utils.ts
117
- async function sha256(data) {
118
- const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
119
- const buffer = bytes.buffer.slice(
120
- bytes.byteOffset,
121
- bytes.byteOffset + bytes.byteLength
279
+ // src/shared/core/blockchain/abis/superstate-swap.ts
280
+ var SUPERSTATE_SWAP_ABI = [
281
+ {
282
+ type: "function",
283
+ name: "authorized",
284
+ inputs: [{ name: "user", type: "address", internalType: "address" }],
285
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
286
+ stateMutability: "view"
287
+ },
288
+ {
289
+ type: "function",
290
+ name: "stopped",
291
+ inputs: [],
292
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
293
+ stateMutability: "view"
294
+ },
295
+ {
296
+ type: "function",
297
+ name: "SWAP_LEVEL",
298
+ inputs: [],
299
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
300
+ stateMutability: "view"
301
+ },
302
+ {
303
+ type: "function",
304
+ name: "preview",
305
+ inputs: [
306
+ { name: "token", type: "address", internalType: "address" },
307
+ { name: "amount", type: "uint256", internalType: "uint256" }
308
+ ],
309
+ outputs: [
310
+ {
311
+ name: "",
312
+ type: "tuple",
313
+ internalType: "struct Preview",
314
+ components: [
315
+ { name: "input", type: "uint256", internalType: "uint256" },
316
+ { name: "fee", type: "uint256", internalType: "uint256" },
317
+ { name: "output", type: "uint256", internalType: "uint256" }
318
+ ]
319
+ }
320
+ ],
321
+ stateMutability: "view"
322
+ },
323
+ {
324
+ type: "function",
325
+ name: "swap",
326
+ inputs: [
327
+ { name: "token", type: "address", internalType: "address" },
328
+ { name: "amount", type: "uint256", internalType: "uint256" },
329
+ { name: "slip", type: "uint256", internalType: "uint256" }
330
+ ],
331
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
332
+ stateMutability: "nonpayable"
333
+ },
334
+ {
335
+ type: "function",
336
+ name: "tokenBalance",
337
+ inputs: [{ name: "token", type: "address", internalType: "address" }],
338
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
339
+ stateMutability: "view"
340
+ },
341
+ {
342
+ type: "function",
343
+ name: "outputToken",
344
+ inputs: [],
345
+ outputs: [{ name: "", type: "address", internalType: "address" }],
346
+ stateMutability: "view"
347
+ },
348
+ {
349
+ type: "function",
350
+ name: "outputTokenBalance",
351
+ inputs: [],
352
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
353
+ stateMutability: "view"
354
+ },
355
+ {
356
+ type: "function",
357
+ name: "totals",
358
+ inputs: [{ name: "token", type: "address", internalType: "address" }],
359
+ outputs: [
360
+ {
361
+ name: "",
362
+ type: "tuple",
363
+ internalType: "struct SwapTotal",
364
+ components: [
365
+ { name: "inputSum", type: "uint256", internalType: "uint256" },
366
+ { name: "feeSum", type: "uint256", internalType: "uint256" },
367
+ { name: "outputSum", type: "uint256", internalType: "uint256" },
368
+ { name: "count", type: "uint256", internalType: "uint256" }
369
+ ]
370
+ }
371
+ ],
372
+ stateMutability: "view"
373
+ },
374
+ {
375
+ type: "function",
376
+ name: "totals",
377
+ inputs: [
378
+ { name: "user", type: "address", internalType: "address" },
379
+ { name: "token", type: "address", internalType: "address" }
380
+ ],
381
+ outputs: [
382
+ {
383
+ name: "",
384
+ type: "tuple",
385
+ internalType: "struct SwapTotal",
386
+ components: [
387
+ { name: "inputSum", type: "uint256", internalType: "uint256" },
388
+ { name: "feeSum", type: "uint256", internalType: "uint256" },
389
+ { name: "outputSum", type: "uint256", internalType: "uint256" },
390
+ { name: "count", type: "uint256", internalType: "uint256" }
391
+ ]
392
+ }
393
+ ],
394
+ stateMutability: "view"
395
+ },
396
+ {
397
+ type: "function",
398
+ name: "transfer",
399
+ inputs: [
400
+ { name: "to", type: "address", internalType: "address" },
401
+ { name: "amount", type: "uint256", internalType: "uint256" }
402
+ ],
403
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
404
+ stateMutability: "nonpayable"
405
+ },
406
+ {
407
+ type: "function",
408
+ name: "transfer",
409
+ inputs: [
410
+ { name: "to", type: "address", internalType: "address" },
411
+ { name: "token", type: "address", internalType: "address" },
412
+ { name: "amount", type: "uint256", internalType: "uint256" }
413
+ ],
414
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
415
+ stateMutability: "nonpayable"
416
+ },
417
+ {
418
+ type: "function",
419
+ name: "setBps",
420
+ inputs: [{ name: "points", type: "uint256", internalType: "uint256" }],
421
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
422
+ stateMutability: "nonpayable"
423
+ },
424
+ {
425
+ type: "event",
426
+ name: "Swapped",
427
+ inputs: [
428
+ { name: "user", type: "address", indexed: true, internalType: "address" },
429
+ {
430
+ name: "inputToken",
431
+ type: "address",
432
+ indexed: true,
433
+ internalType: "address"
434
+ },
435
+ {
436
+ name: "outputToken",
437
+ type: "address",
438
+ indexed: true,
439
+ internalType: "address"
440
+ },
441
+ {
442
+ name: "inputAmount",
443
+ type: "uint256",
444
+ indexed: false,
445
+ internalType: "uint256"
446
+ },
447
+ {
448
+ name: "outputAmount",
449
+ type: "uint256",
450
+ indexed: false,
451
+ internalType: "uint256"
452
+ }
453
+ ],
454
+ anonymous: false
455
+ },
456
+ {
457
+ type: "event",
458
+ name: "Transferred",
459
+ inputs: [
460
+ { name: "to", type: "address", indexed: true, internalType: "address" },
461
+ {
462
+ name: "token",
463
+ type: "address",
464
+ indexed: true,
465
+ internalType: "address"
466
+ },
467
+ {
468
+ name: "amount",
469
+ type: "uint256",
470
+ indexed: false,
471
+ internalType: "uint256"
472
+ }
473
+ ],
474
+ anonymous: false
475
+ },
476
+ {
477
+ type: "error",
478
+ name: "InvalidAddress",
479
+ inputs: []
480
+ },
481
+ {
482
+ type: "error",
483
+ name: "InsufficientAmount",
484
+ inputs: []
485
+ },
486
+ {
487
+ type: "error",
488
+ name: "InvalidAmount",
489
+ inputs: []
490
+ },
491
+ {
492
+ type: "error",
493
+ name: "SwapFailed",
494
+ inputs: [
495
+ { name: "user", type: "address", internalType: "address" },
496
+ { name: "token", type: "address", internalType: "address" }
497
+ ]
498
+ }
499
+ ];
500
+
501
+ // src/shared/types/blockchain/core.ts
502
+ var EvmWalletAddress = (value) => value;
503
+ var EvmContractAddress = (value) => value;
504
+ var HexEncodedTransactionData = (value) => value;
505
+ var AssetDecimals = (value) => value;
506
+ var MAX_UINT_256 = 2n ** 256n - 1n;
507
+ var assertUint256 = (value) => {
508
+ if (value < 0n || value > MAX_UINT_256) {
509
+ throw new Error(`Value out of uint256 bounds: ${value}`);
510
+ }
511
+ return value;
512
+ };
513
+ var BlockchainAmount = Object.assign(
514
+ (value) => value,
515
+ {
516
+ add: (a, b) => combineAmounts(a, b, (x, y) => x + y),
517
+ sub: (a, b) => combineAmounts(a, b, (x, y) => x - y)
518
+ }
519
+ );
520
+ function combineAmounts(a, b, op) {
521
+ if (a.decimals !== b.decimals) {
522
+ throw new Error(
523
+ `Cannot combine BlockchainAmounts with different decimals: ${a.decimals} vs ${b.decimals}`
524
+ );
525
+ }
526
+ const raw = op(a.raw, b.raw);
527
+ if (raw < 0n || raw > MAX_UINT_256) {
528
+ throw new Error(`BlockchainAmount out of uint256 bounds: ${raw}`);
529
+ }
530
+ return BlockchainAmount({ raw, decimals: a.decimals });
531
+ }
532
+ var AssetSymbol = (value) => value;
533
+ var StablecoinSymbol = (value) => value;
534
+ var KnownAssetSymbol = StablecoinSymbol;
535
+ var Bps = (value) => value;
536
+
537
+ // src/shared/core/blockchain/bps.ts
538
+ var BPS_DENOM = Bps(10000n);
539
+ function applyBps(amount, bps) {
540
+ return assertUint256(amount * bps / BPS_DENOM);
541
+ }
542
+
543
+ // src/shared/types/blockchain/ui.ts
544
+ var FormattedAmountUi = (value) => value;
545
+ var FormattedPercentUi = (value) => value;
546
+ var TxExplorerUrl = (value) => value;
547
+ var ShortenedWalletAddress = (value) => value;
548
+ var FormattedAmountAssetUi = (value) => value;
549
+ var AssetIconUrl = (value) => value;
550
+
551
+ // src/shared/core/blockchain/chain.ts
552
+ function getChainId(chain) {
553
+ switch (chain) {
554
+ case "ethereum_mainnet":
555
+ return 1;
556
+ case "ethereum_sepolia":
557
+ return 11155111;
558
+ default: {
559
+ const _exhaustive = chain;
560
+ return _exhaustive;
561
+ }
562
+ }
563
+ }
564
+ function getNetworkName(chain) {
565
+ switch (chain) {
566
+ case "ethereum_mainnet":
567
+ return "Ethereum";
568
+ case "ethereum_sepolia":
569
+ return "Ethereum Sepolia";
570
+ default: {
571
+ const _exhaustive = chain;
572
+ return _exhaustive;
573
+ }
574
+ }
575
+ }
576
+ function txExplorerUrl(chain, txHash) {
577
+ return TxExplorerUrl(`${explorerBaseUrl(chain)}/tx/${txHash}`);
578
+ }
579
+ function explorerBaseUrl(chain) {
580
+ switch (chain) {
581
+ case "ethereum_mainnet":
582
+ return "https://etherscan.io";
583
+ case "ethereum_sepolia":
584
+ return "https://sepolia.etherscan.io";
585
+ default: {
586
+ const _exhaustive = chain;
587
+ return _exhaustive;
588
+ }
589
+ }
590
+ }
591
+
592
+ // src/shared/core/blockchain/formatters.ts
593
+ var import_viem = require("viem");
594
+
595
+ // src/shared/core/blockchain/swap/math.ts
596
+ function computePrice({
597
+ inputTokenAmount,
598
+ outputTokenAmount
599
+ }) {
600
+ if (outputTokenAmount.raw === 0n) return null;
601
+ const scale = 10n ** BigInt(outputTokenAmount.decimals);
602
+ const raw = assertUint256(
603
+ inputTokenAmount.raw * scale / outputTokenAmount.raw
122
604
  );
123
- return crypto.subtle.digest("SHA-256", buffer);
605
+ return BlockchainAmount({ raw, decimals: inputTokenAmount.decimals });
124
606
  }
125
- function arrayBufferToBase64Url(buffer, padding = true) {
126
- const bytes = new Uint8Array(buffer);
127
- let binary = "";
128
- for (let i = 0; i < bytes.length; i++) {
129
- binary += String.fromCharCode(bytes[i]);
607
+ function computeSlip(amount, slippage) {
608
+ const retained = Bps(assertUint256(BPS_DENOM - slippage));
609
+ const slipRaw = applyBps(amount.raw, retained);
610
+ return BlockchainAmount({ raw: slipRaw, decimals: amount.decimals });
611
+ }
612
+
613
+ // src/shared/core/blockchain/formatters.ts
614
+ function shortenAddress(address) {
615
+ const short = address.length > 10 ? `${address.slice(0, 6)}\u2026${address.slice(-4)}` : address;
616
+ return ShortenedWalletAddress(short);
617
+ }
618
+ function formatAmount(amount, locale, options) {
619
+ const decimal = formatRawAmount(amount);
620
+ let [integerPart, fractionPart = ""] = decimal.split(".");
621
+ const maxFractionDigits = options?.maxFractionDigits;
622
+ const minFractionDigits = maxFractionDigits !== void 0 ? Math.min(maxFractionDigits, amount.decimals) : Math.min(2, amount.decimals);
623
+ if (maxFractionDigits !== void 0 && fractionPart.length > maxFractionDigits) {
624
+ ({ integerPart, fractionPart } = roundFractionHalfUp(
625
+ integerPart,
626
+ fractionPart,
627
+ maxFractionDigits
628
+ ));
130
629
  }
131
- let base64 = btoa(binary);
132
- base64 = base64.replace(/\+/g, "-").replace(/\//g, "_");
133
- if (!padding) {
134
- base64 = base64.replace(/=+$/, "");
630
+ const fraction = minFractionDigits === 0 ? "" : fractionPart.padEnd(minFractionDigits, "0");
631
+ const integerFormatted = BigInt(integerPart).toLocaleString(locale);
632
+ if (minFractionDigits === 0 && fraction === "") {
633
+ return FormattedAmountUi(integerFormatted);
135
634
  }
136
- return base64;
635
+ const decimalSeparator = new Intl.NumberFormat(locale).formatToParts(1.1).find((p) => p.type === "decimal")?.value ?? ".";
636
+ return FormattedAmountUi(`${integerFormatted}${decimalSeparator}${fraction}`);
137
637
  }
138
- function generateSecureRandomBase64Url(byteLength) {
139
- const bytes = new Uint8Array(byteLength);
140
- crypto.getRandomValues(bytes);
141
- const buffer = bytes.buffer;
142
- return arrayBufferToBase64Url(buffer, false);
638
+ function roundFractionHalfUp(integerPart, fractionPart, maxFractionDigits) {
639
+ if (fractionPart.length <= maxFractionDigits) {
640
+ return { integerPart, fractionPart };
641
+ }
642
+ if (maxFractionDigits === 0) {
643
+ const roundUp = fractionPart[0] >= "5";
644
+ const integer = BigInt(integerPart) + (roundUp ? 1n : 0n);
645
+ return { integerPart: integer.toString(), fractionPart: "" };
646
+ }
647
+ const trimmed = fractionPart.slice(0, maxFractionDigits);
648
+ if (fractionPart[maxFractionDigits] < "5") {
649
+ return { integerPart, fractionPart: trimmed };
650
+ }
651
+ const digits = trimmed.split("").map((digit) => Number.parseInt(digit, 10));
652
+ let carry = 1;
653
+ for (let i = digits.length - 1; i >= 0 && carry > 0; i -= 1) {
654
+ const sum = digits[i] + carry;
655
+ if (sum === 10) {
656
+ digits[i] = 0;
657
+ carry = 1;
658
+ } else {
659
+ digits[i] = sum;
660
+ carry = 0;
661
+ }
662
+ }
663
+ return {
664
+ integerPart: carry > 0 ? (BigInt(integerPart) + 1n).toString() : integerPart,
665
+ fractionPart: digits.join("")
666
+ };
143
667
  }
144
- function notBlankStringOrNull(value) {
145
- if (value?.trim()) {
146
- return value;
147
- } else {
668
+ function formatRawAmount(amount) {
669
+ return (0, import_viem.formatUnits)(amount.raw, amount.decimals);
670
+ }
671
+ function formatCompactAmount(amount, locale) {
672
+ const value = Number(formatRawAmount(amount));
673
+ const formatted = new Intl.NumberFormat(locale, {
674
+ notation: "compact",
675
+ maximumFractionDigits: 2
676
+ }).format(value);
677
+ return FormattedAmountUi(formatted);
678
+ }
679
+ function formatBpsAsPercent(bps, locale) {
680
+ const whole = bps / 100n;
681
+ const fraction = bps % 100n;
682
+ const wholeFormatted = whole.toLocaleString(locale);
683
+ const decimalSeparator = new Intl.NumberFormat(locale).formatToParts(1.1).find((p) => p.type === "decimal")?.value ?? ".";
684
+ if (fraction === 0n) {
685
+ return FormattedPercentUi(`${wholeFormatted}%`);
686
+ }
687
+ const fractionFormatted = fraction.toString().padStart(2, "0").replace(/0+$/, "");
688
+ return FormattedPercentUi(
689
+ `${wholeFormatted}${decimalSeparator}${fractionFormatted}%`
690
+ );
691
+ }
692
+ function usdAmount(amount) {
693
+ return FormattedAmountAssetUi(`$${amount}`);
694
+ }
695
+ function assetAmount(amount, symbol) {
696
+ return FormattedAmountAssetUi(`${amount} ${symbol}`);
697
+ }
698
+ var NA_AMOUNT_ASSET_UI = FormattedAmountAssetUi("-");
699
+ var USD_FRACTION_DIGITS = AssetDecimals(2);
700
+ function formattedUsdPrice(amount, locale) {
701
+ if (!amount) return NA_AMOUNT_ASSET_UI;
702
+ return usdAmount(
703
+ formatAmount(amount, locale, { maxFractionDigits: USD_FRACTION_DIGITS })
704
+ );
705
+ }
706
+ function formattedPricePerShare(quote, locale) {
707
+ if (!quote) return NA_AMOUNT_ASSET_UI;
708
+ return formattedUsdPrice(computePrice(quote), locale);
709
+ }
710
+
711
+ // src/shared/core/blockchain/math.ts
712
+ var import_viem2 = require("viem");
713
+ function parseBlockchainAmount(amount, decimals) {
714
+ const trimmed = amount.trim();
715
+ if (trimmed === "") return { valid: false, reason: { type: "empty" } };
716
+ if (trimmed.startsWith("-")) {
717
+ return { valid: false, reason: { type: "negative" } };
718
+ }
719
+ if (/[eE]/.test(trimmed)) {
720
+ return { valid: false, reason: { type: "invalid-format" } };
721
+ }
722
+ if (!/^\d+(\.\d+)?$/.test(trimmed)) {
723
+ return { valid: false, reason: { type: "invalid-format" } };
724
+ }
725
+ const [, fraction = ""] = trimmed.split(".");
726
+ if (fraction.length > decimals) {
727
+ return {
728
+ valid: false,
729
+ reason: { type: "too-many-decimals", maxDecimals: decimals }
730
+ };
731
+ }
732
+ try {
733
+ return {
734
+ valid: true,
735
+ amount: BlockchainAmount({
736
+ raw: (0, import_viem2.parseUnits)(trimmed, decimals),
737
+ decimals
738
+ })
739
+ };
740
+ } catch {
741
+ return { valid: false, reason: { type: "invalid-format" } };
742
+ }
743
+ }
744
+
745
+ // src/shared/core/blockchain/swap/constants.ts
746
+ var SUPERSTATE_TOS_URL = "https://superstate.com/terms";
747
+ var SWAP_POLL_INTERVAL_MS = 15e3;
748
+ var DEFAULT_AMOUNT_TO_COMPUTE_PRICE = 1000000n;
749
+ var SLIPPAGE_OPTIONS_BPS = [25n, 50n, 100n, 200n, 500n].map(
750
+ (n) => Bps(n)
751
+ );
752
+ var DEFAULT_SLIPPAGE_BPS = Bps(50n);
753
+ var SUPERSTATE_SWAP_CONTRACT_ADDRESS_SEPOLIA = EvmContractAddress("0x84f8e9a6C9Cc12fe911259372EfCa5582C4ae557");
754
+
755
+ // src/shared/core/blockchain/swap/quote.ts
756
+ var SwapQuote = {
757
+ /**
758
+ * Assembles a {@link SwapQuote} from a raw contract {@link SwapPreview}. The
759
+ * input and fee are denominated in the input token; the output in the output
760
+ * token.
761
+ */
762
+ fromPreview: (preview, inputDecimals, outputDecimals) => ({
763
+ inputTokenAmount: BlockchainAmount({
764
+ raw: preview.inputAmount,
765
+ decimals: inputDecimals
766
+ }),
767
+ fee: BlockchainAmount({ raw: preview.fee, decimals: inputDecimals }),
768
+ outputTokenAmount: BlockchainAmount({
769
+ raw: preview.outputAmount,
770
+ decimals: outputDecimals
771
+ })
772
+ })
773
+ };
774
+
775
+ // src/shared/core/blockchain/swap/status.ts
776
+ function isStopped(status) {
777
+ return (status.stopped & status.swapLevel) !== 0n;
778
+ }
779
+
780
+ // src/shared/core/blockchain/swap/swapped-event.ts
781
+ var import_viem3 = require("viem");
782
+ function decodeSwappedOutputAmount(receipt, outputDecimals) {
783
+ try {
784
+ const [swapped] = (0, import_viem3.parseEventLogs)({
785
+ abi: SUPERSTATE_SWAP_ABI,
786
+ eventName: "Swapped",
787
+ logs: receipt.logs
788
+ });
789
+ if (!swapped) return null;
790
+ const raw = swapped.args.outputAmount;
791
+ if (raw < 0n || raw > MAX_UINT_256) return null;
792
+ return BlockchainAmount({ raw, decimals: outputDecimals });
793
+ } catch {
148
794
  return null;
149
795
  }
150
796
  }
151
797
 
152
- // src/shared/pkce.ts
153
- async function generatePKCEParams(config) {
154
- const state = generateSecureRandomBase64Url(32);
155
- const codeVerifier = generateSecureRandomBase64Url(32);
156
- const codeChallengeRaw = await sha256(codeVerifier);
157
- const codeChallenge = arrayBufferToBase64Url(codeChallengeRaw, false);
798
+ // src/shared/core/blockchain/token-registry.ts
799
+ var USDC_SYMBOL = StablecoinSymbol("USDC");
800
+ var USDC = {
801
+ name: "USD Coin",
802
+ symbol: USDC_SYMBOL,
803
+ decimals: AssetDecimals(6)
804
+ };
805
+ var USDT_SYMBOL = StablecoinSymbol("USDT");
806
+ var USDT = {
807
+ name: "Tether USD",
808
+ symbol: USDT_SYMBOL,
809
+ decimals: AssetDecimals(6)
810
+ };
811
+ var USDC_ADDRESSES = {
812
+ ethereum_mainnet: EvmContractAddress(
813
+ "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
814
+ ),
815
+ ethereum_sepolia: EvmContractAddress(
816
+ "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"
817
+ )
818
+ };
819
+ var USDT_ADDRESSES = {
820
+ ethereum_mainnet: EvmContractAddress(
821
+ "0xdac17f958d2ee523a2206206994597c13d831ec7"
822
+ ),
823
+ ethereum_sepolia: EvmContractAddress(
824
+ "0x7169D38820dfd117C3FA1f22a697dBA58d90BA06"
825
+ )
826
+ };
827
+ var TOKEN_REGISTRY = {
828
+ erc20: (symbol) => {
829
+ switch (symbol) {
830
+ case "USDC":
831
+ return USDC;
832
+ case "USDT":
833
+ return USDT;
834
+ default:
835
+ throw new Error(`Unknown asset symbol: ${symbol}`);
836
+ }
837
+ },
838
+ contractAddress: (symbol, chain) => {
839
+ switch (symbol) {
840
+ case "USDC":
841
+ return USDC_ADDRESSES[chain];
842
+ case "USDT":
843
+ return USDT_ADDRESSES[chain];
844
+ default:
845
+ throw new Error(`Unknown asset symbol: ${symbol}`);
846
+ }
847
+ }
848
+ };
849
+
850
+ // src/shared/api/http-attributes.ts
851
+ var empty = {};
852
+ var concat = (left, right) => ({
853
+ ...left,
854
+ ...right
855
+ });
856
+ var concatAll = (...items) => {
857
+ let result = empty;
858
+ for (const item of items) {
859
+ result = concat(result, item);
860
+ }
861
+ return result;
862
+ };
863
+ var protectedRequest = () => ({ protected: true });
864
+ var userAgent = () => ({ userAgent: true });
865
+ var idempotencyKey = () => ({
866
+ idempotencyKey: true
867
+ });
868
+ var clientCredentials = (credentials) => ({
869
+ clientCredentials: credentials
870
+ });
871
+ var retryAttempt = (attempt) => ({
872
+ retryAttempt: attempt
873
+ });
874
+ var renewAttempted = (value) => ({
875
+ renewAttempted: value
876
+ });
877
+ var isProtected = (attrs) => attrs?.protected === true;
878
+ var needUserAgent = (attrs) => attrs?.userAgent === true;
879
+ var isIdempotent = (attrs) => attrs?.idempotencyKey === true;
880
+ var getRetryAttempt = (attrs) => attrs?.retryAttempt ?? 0;
881
+ var wasRenewAttempted = (attrs) => attrs?.renewAttempted === true;
882
+ var getClientCredentials = (attrs) => attrs?.clientCredentials;
883
+ var Attributes = {
884
+ empty,
885
+ concat,
886
+ concatAll,
887
+ protected: protectedRequest,
888
+ isProtected,
889
+ userAgent,
890
+ needUserAgent,
891
+ idempotencyKey,
892
+ isIdempotent,
893
+ retryAttempt,
894
+ getRetryAttempt,
895
+ renewAttempted,
896
+ wasRenewAttempted,
897
+ clientCredentials,
898
+ getClientCredentials
899
+ };
900
+
901
+ // src/shared/types/swap.ts
902
+ var SwapAuthorization = {
903
+ fromDto: (dto) => ({
904
+ authorized: dto.authorized
905
+ })
906
+ };
907
+ var SwapPreview = {
908
+ fromDto: (dto) => ({
909
+ inputAmount: assertUint256(BigInt(dto.pay_input_amount)),
910
+ fee: assertUint256(BigInt(dto.fee)),
911
+ outputAmount: assertUint256(BigInt(dto.receive_output_amount))
912
+ })
913
+ };
914
+ var SwapStatus = {
915
+ fromDto: (dto) => ({
916
+ stopped: assertUint256(BigInt(dto.stopped)),
917
+ swapLevel: assertUint256(BigInt(dto.swap_level))
918
+ })
919
+ };
920
+ var TokenAllowance = {
921
+ fromDto: (dto) => ({
922
+ allowance: assertUint256(BigInt(dto.allowance))
923
+ })
924
+ };
925
+ var TokenBalance = {
926
+ fromDto: (dto) => ({
927
+ balance: assertUint256(BigInt(dto.balance))
928
+ })
929
+ };
930
+ var AllowWalletResponse = {
931
+ fromDto: (dto) => {
932
+ switch (dto.action) {
933
+ case "broadcast_transaction":
934
+ return {
935
+ action: "broadcast_transaction",
936
+ to: EvmContractAddress(dto.to),
937
+ data: HexEncodedTransactionData(dto.data)
938
+ };
939
+ case "none":
940
+ return {
941
+ action: "none",
942
+ alreadyAllowed: dto.already_allowed
943
+ };
944
+ default: {
945
+ const _exhaustive = dto;
946
+ return _exhaustive;
947
+ }
948
+ }
949
+ }
950
+ };
951
+
952
+ // src/shared/api/frontline/swap.ts
953
+ async function getSwapAuthorization(api, params) {
954
+ const dto = await api.send({
955
+ method: "GET",
956
+ url: "/v1/wallet/authorized",
957
+ queryParams: {
958
+ chain: params.chain,
959
+ contract_address: params.contractAddress,
960
+ wallet_address: params.walletAddress
961
+ },
962
+ attributes: Attributes.protected()
963
+ });
964
+ return SwapAuthorization.fromDto(dto);
965
+ }
966
+ async function getSwapOutputToken(api, params) {
967
+ const dto = await api.send({
968
+ method: "GET",
969
+ url: "/v1/swap/output-token",
970
+ queryParams: {
971
+ chain: params.chain,
972
+ contract_address: params.contractAddress
973
+ },
974
+ attributes: Attributes.protected()
975
+ });
976
+ return toErc20Asset(dto);
977
+ }
978
+ async function getSwapPreview(api, params) {
979
+ const dto = await api.send({
980
+ method: "GET",
981
+ url: "/v1/swap/preview",
982
+ queryParams: {
983
+ chain: params.chain,
984
+ contract_address: params.contractAddress,
985
+ input_token: params.inputToken,
986
+ amount: params.amount.toString()
987
+ },
988
+ attributes: Attributes.protected()
989
+ });
990
+ return SwapPreview.fromDto(dto);
991
+ }
992
+ async function getSwapStatus(api, params) {
993
+ const dto = await api.send({
994
+ method: "GET",
995
+ url: "/v1/swap/status",
996
+ queryParams: {
997
+ chain: params.chain,
998
+ contract_address: params.contractAddress
999
+ },
1000
+ attributes: Attributes.protected()
1001
+ });
1002
+ return SwapStatus.fromDto(dto);
1003
+ }
1004
+ async function getTokenAllowance(api, params) {
1005
+ const dto = await api.send({
1006
+ method: "GET",
1007
+ url: "/v1/token/allowance",
1008
+ queryParams: {
1009
+ chain: params.chain,
1010
+ token_address: params.tokenAddress,
1011
+ owner: params.owner,
1012
+ spender: params.spender
1013
+ },
1014
+ attributes: Attributes.protected()
1015
+ });
1016
+ return TokenAllowance.fromDto(dto);
1017
+ }
1018
+ async function getTokenBalance(api, params) {
1019
+ const dto = await api.send({
1020
+ method: "GET",
1021
+ url: "/v1/token/balance",
1022
+ queryParams: {
1023
+ chain: params.chain,
1024
+ token_address: params.tokenAddress,
1025
+ owner: params.owner
1026
+ },
1027
+ attributes: Attributes.protected()
1028
+ });
1029
+ return TokenBalance.fromDto(dto);
1030
+ }
1031
+ async function allowWallet(api, params) {
1032
+ const dto = await api.send({
1033
+ method: "POST",
1034
+ url: `/v1/offers/${encodeURIComponent(params.offerId)}/allow-wallet`,
1035
+ body: {
1036
+ wallet_address: params.walletAddress,
1037
+ chain: params.chain,
1038
+ signature: params.signature
1039
+ },
1040
+ attributes: Attributes.protected()
1041
+ });
1042
+ return AllowWalletResponse.fromDto(dto);
1043
+ }
1044
+ function toErc20Asset(dto) {
158
1045
  return {
159
- clientId: config.clientId,
160
- responseType: "code",
161
- redirectUri: config.redirectUri,
162
- codeChallenge: CodeChallenge(codeChallenge),
163
- codeChallengeMethod: "S256",
164
- state: PKCEState(state),
165
- codeVerifier: CodeVerifier(codeVerifier)
1046
+ name: dto.name,
1047
+ symbol: AssetSymbol(dto.symbol),
1048
+ decimals: AssetDecimals(dto.decimals)
166
1049
  };
167
1050
  }
168
1051
 
1052
+ // src/shared/core/erc20-namespace.ts
1053
+ var Erc20NamespaceImpl = class {
1054
+ constructor(ctx) {
1055
+ this.ctx = ctx;
1056
+ }
1057
+ async getTokenAllowance(params) {
1058
+ await this.ctx.ensureUserAuthenticated();
1059
+ return getTokenAllowance(this.ctx.api, params);
1060
+ }
1061
+ async getTokenBalance(params) {
1062
+ await this.ctx.ensureUserAuthenticated();
1063
+ return getTokenBalance(this.ctx.api, params);
1064
+ }
1065
+ };
1066
+
169
1067
  // src/shared/types/asset.ts
170
1068
  var AssetId = (value) => value;
171
1069
  var AssetCode = (value) => value;
@@ -178,35 +1076,6 @@ var Asset = {
178
1076
  })
179
1077
  };
180
1078
 
181
- // src/shared/types/errors.ts
182
- var NotImplementedError = class extends Error {
183
- constructor(message = "Not implemented yet") {
184
- super(message);
185
- this.name = "NotImplementedError";
186
- }
187
- };
188
- var NotAuthenticatedError = class extends Error {
189
- constructor(message = "The user is not authenticated. Go through the OAuth flow first!") {
190
- super(message);
191
- this.name = "NotAuthenticatedError";
192
- }
193
- };
194
-
195
- // src/shared/types/oauth-session.ts
196
- var OAuthRefreshToken = (value) => value;
197
- var OAuthSession = {
198
- fromDto: (dto) => {
199
- const expiresAt = new Date(Date.now() + dto.expires_in * 1e3);
200
- return {
201
- accessToken: {
202
- value: dto.access_token,
203
- expiresAt
204
- },
205
- ...dto.refresh_token != null && dto.refresh_token !== "" ? { refreshToken: OAuthRefreshToken(dto.refresh_token) } : void 0
206
- };
207
- }
208
- };
209
-
210
1079
  // src/shared/types/offer.ts
211
1080
  var OfferId = (value) => value;
212
1081
  var OfferSlug = (value) => value;
@@ -214,14 +1083,51 @@ var Offer = {
214
1083
  fromDto: (dto) => ({
215
1084
  id: OfferId(dto.id),
216
1085
  slug: OfferSlug(dto.slug),
217
- tagline: notBlankStringOrNull(dto.tagline),
218
- bannerUrl: notBlankStringOrNull(dto.banner_url),
219
- logoUrl: notBlankStringOrNull(dto.logo_url),
1086
+ type: dto.type,
1087
+ tagline: dto.tagline,
1088
+ bannerUrl: dto.banner_url,
1089
+ logoUrl: dto.logo_url,
220
1090
  startsAt: new Date(dto.starts_at),
221
- endsAt: new Date(dto.ends_at)
1091
+ endsAt: dto.ends_at ? new Date(dto.ends_at) : null
222
1092
  })
223
1093
  };
224
1094
 
1095
+ // src/shared/utils.ts
1096
+ async function sha256(data) {
1097
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
1098
+ const buffer = bytes.buffer.slice(
1099
+ bytes.byteOffset,
1100
+ bytes.byteOffset + bytes.byteLength
1101
+ );
1102
+ return crypto.subtle.digest("SHA-256", buffer);
1103
+ }
1104
+ function arrayBufferToBase64Url(buffer, padding = true) {
1105
+ const bytes = new Uint8Array(buffer);
1106
+ let binary = "";
1107
+ for (let i = 0; i < bytes.length; i++) {
1108
+ binary += String.fromCharCode(bytes[i]);
1109
+ }
1110
+ let base64 = btoa(binary);
1111
+ base64 = base64.replace(/\+/g, "-").replace(/\//g, "_");
1112
+ if (!padding) {
1113
+ base64 = base64.replace(/=+$/, "");
1114
+ }
1115
+ return base64;
1116
+ }
1117
+ function generateSecureRandomBase64Url(byteLength) {
1118
+ const bytes = new Uint8Array(byteLength);
1119
+ crypto.getRandomValues(bytes);
1120
+ const buffer = bytes.buffer;
1121
+ return arrayBufferToBase64Url(buffer, false);
1122
+ }
1123
+ function notBlankStringOrNull(value) {
1124
+ if (value?.trim()) {
1125
+ return value;
1126
+ } else {
1127
+ return null;
1128
+ }
1129
+ }
1130
+
225
1131
  // src/shared/types/offer-detail.ts
226
1132
  var OfferOptionId = (value) => value;
227
1133
  var OfferOptionSlug = (value) => value;
@@ -248,16 +1154,17 @@ var OfferDetail = {
248
1154
  return {
249
1155
  id: OfferId(dto.id),
250
1156
  slug: OfferSlug(dto.slug),
1157
+ type: dto.type,
251
1158
  name: dto.name,
252
1159
  asset: Asset.fromDto(dto.asset),
253
1160
  fundingAssets: dto.funding_assets.map(Asset.fromDto),
254
1161
  about: notBlankStringOrNull(dto.about),
255
- tagline: notBlankStringOrNull(dto.tagline),
256
- bannerUrl: notBlankStringOrNull(dto.banner_url),
257
- logoUrl: notBlankStringOrNull(dto.logo_url),
258
- category: notBlankStringOrNull(dto.category),
1162
+ tagline: dto.tagline,
1163
+ bannerUrl: dto.banner_url,
1164
+ logoUrl: dto.logo_url,
1165
+ category: dto.category,
259
1166
  startsAt: new Date(dto.starts_at),
260
- endsAt: new Date(dto.ends_at),
1167
+ endsAt: dto.ends_at ? new Date(dto.ends_at) : null,
261
1168
  faqs: dto.faqs.map(FaqItem.fromDto),
262
1169
  links: dto.links.map(Link.fromDto),
263
1170
  milestones: dto.milestones.map(Milestone.fromDto),
@@ -304,6 +1211,109 @@ var Milestone = {
304
1211
  })
305
1212
  };
306
1213
 
1214
+ // src/shared/types/offer-option-address.ts
1215
+ var OfferOptionAddressId = (value) => value;
1216
+ var OfferOptionAddress = {
1217
+ /** Maps the API DTO into the SDK offer-option-address domain model. */
1218
+ fromDto: (dto) => ({
1219
+ id: OfferOptionAddressId(dto.id),
1220
+ offerOptionId: OfferOptionId(dto.offer_option_id),
1221
+ address: EvmWalletAddress(dto.address),
1222
+ protocol: dto.protocol,
1223
+ createdAt: new Date(dto.created_at)
1224
+ })
1225
+ };
1226
+ var ConnectExternalWalletParams = {
1227
+ /** Maps connect-wallet params into the API DTO payload. */
1228
+ toDto: (params) => ({
1229
+ offer_option_id: params.offerOptionId,
1230
+ wallet_address: params.walletAddress,
1231
+ chain: params.chain,
1232
+ signature: params.signature
1233
+ })
1234
+ };
1235
+
1236
+ // src/shared/types/wallet-ownership-challenge.ts
1237
+ var WalletOwnershipChallenge = {
1238
+ /** Maps the API DTO into the SDK wallet-ownership-challenge domain model. */
1239
+ fromDto: (dto) => ({
1240
+ message: dto.message,
1241
+ expiresAt: new Date(dto.expires_at)
1242
+ })
1243
+ };
1244
+ var CreateWalletOwnershipChallengeParams = {
1245
+ /**
1246
+ * Maps challenge-request params into the API DTO payload. The discriminated
1247
+ * union guarantees SIWE fields are present exactly when `challengeType` is
1248
+ * `siwe`, so the mapping narrows on the discriminant.
1249
+ */
1250
+ toDto: (params) => {
1251
+ switch (params.challengeType) {
1252
+ case "plain":
1253
+ return {
1254
+ wallet_address: params.walletAddress,
1255
+ chain: params.chain,
1256
+ challenge_type: "plain"
1257
+ };
1258
+ case "siwe":
1259
+ return {
1260
+ wallet_address: params.walletAddress,
1261
+ chain: params.chain,
1262
+ challenge_type: "siwe",
1263
+ domain: params.domain,
1264
+ uri: params.uri,
1265
+ statement: params.statement
1266
+ };
1267
+ default: {
1268
+ const _exhaustive = params;
1269
+ return _exhaustive;
1270
+ }
1271
+ }
1272
+ }
1273
+ };
1274
+
1275
+ // src/shared/api/frontline/wallet-connect.ts
1276
+ async function createWalletOwnershipChallenge(api, params) {
1277
+ const dto = await api.send({
1278
+ method: "POST",
1279
+ url: "/v1/wallet-ownership",
1280
+ body: CreateWalletOwnershipChallengeParams.toDto(params),
1281
+ attributes: Attributes.protected()
1282
+ });
1283
+ return WalletOwnershipChallenge.fromDto(dto);
1284
+ }
1285
+
1286
+ // src/shared/core/swap-namespace.ts
1287
+ var SwapNamespaceImpl = class {
1288
+ constructor(ctx) {
1289
+ this.ctx = ctx;
1290
+ }
1291
+ async getAuthorization(params) {
1292
+ await this.ctx.ensureUserAuthenticated();
1293
+ return getSwapAuthorization(this.ctx.api, params);
1294
+ }
1295
+ async getPreview(params) {
1296
+ await this.ctx.ensureUserAuthenticated();
1297
+ return getSwapPreview(this.ctx.api, params);
1298
+ }
1299
+ async getStatus(params) {
1300
+ await this.ctx.ensureUserAuthenticated();
1301
+ return getSwapStatus(this.ctx.api, params);
1302
+ }
1303
+ async getOutputToken(params) {
1304
+ await this.ctx.ensureUserAuthenticated();
1305
+ return getSwapOutputToken(this.ctx.api, params);
1306
+ }
1307
+ async requestWalletOwnershipChallenge(params) {
1308
+ await this.ctx.ensureUserAuthenticated();
1309
+ return createWalletOwnershipChallenge(this.ctx.api, params);
1310
+ }
1311
+ async allowWallet(params) {
1312
+ await this.ctx.ensureUserAuthenticated();
1313
+ return allowWallet(this.ctx.api, params);
1314
+ }
1315
+ };
1316
+
307
1317
  // src/shared/types/participation.ts
308
1318
  var ParticipationId = (value) => value;
309
1319
  var Blockchain = (value) => value;
@@ -351,6 +1361,162 @@ var CreateParticipationParams = {
351
1361
  })
352
1362
  };
353
1363
 
1364
+ // src/shared/api/frontline/participations.ts
1365
+ async function fetchParticipations(api, offerId) {
1366
+ return fetchAllPages(
1367
+ (params) => fetchParticipationsPage(api, params),
1368
+ { offerId }
1369
+ );
1370
+ }
1371
+ async function fetchParticipationsPage(api, params) {
1372
+ const pageDto = await api.send({
1373
+ method: "GET",
1374
+ url: "/v1/participations",
1375
+ queryParams: ParticipationsPaginationParams.toQueryParams(params),
1376
+ attributes: Attributes.protected()
1377
+ });
1378
+ return PaginatedResponse.fromDto(pageDto, Participation.fromDto);
1379
+ }
1380
+ async function fetchParticipation(api, id) {
1381
+ const dto = await api.send({
1382
+ method: "GET",
1383
+ url: `/v1/participations/${id}`,
1384
+ attributes: Attributes.protected()
1385
+ });
1386
+ return Participation.fromDto(dto);
1387
+ }
1388
+ async function createParticipation(api, params) {
1389
+ const dto = await api.send({
1390
+ method: "POST",
1391
+ url: "/v1/participations",
1392
+ body: CreateParticipationParams.toDto(params),
1393
+ attributes: Attributes.protected()
1394
+ });
1395
+ return Participation.fromDto(dto);
1396
+ }
1397
+
1398
+ // src/shared/core/token-sale-namespace.ts
1399
+ var TokenSaleNamespaceImpl = class {
1400
+ constructor(ctx) {
1401
+ this.ctx = ctx;
1402
+ }
1403
+ async fetchParticipations(offerId) {
1404
+ await this.ctx.ensureUserAuthenticated();
1405
+ return fetchParticipations(this.ctx.api, offerId);
1406
+ }
1407
+ async fetchParticipationsPage(params) {
1408
+ await this.ctx.ensureUserAuthenticated();
1409
+ return fetchParticipationsPage(this.ctx.api, params);
1410
+ }
1411
+ async fetchParticipation(id) {
1412
+ await this.ctx.ensureUserAuthenticated();
1413
+ return fetchParticipation(this.ctx.api, id);
1414
+ }
1415
+ async createParticipation(params) {
1416
+ await this.ctx.ensureUserAuthenticated();
1417
+ return createParticipation(this.ctx.api, params);
1418
+ }
1419
+ };
1420
+
1421
+ // src/shared/types/oauth.ts
1422
+ var AuthorizationCode = (value) => value;
1423
+ var CodeVerifier = (value) => value;
1424
+ var CodeChallenge = (value) => value;
1425
+ var PKCEState = (value) => value;
1426
+ var RedirectUri = (value) => value;
1427
+ var ClientId = (value) => value;
1428
+ var ClientSecret = (value) => value;
1429
+
1430
+ // src/shared/pkce.ts
1431
+ async function generatePKCEParams(config) {
1432
+ const state = generateSecureRandomBase64Url(32);
1433
+ const codeVerifier = generateSecureRandomBase64Url(32);
1434
+ const codeChallengeRaw = await sha256(codeVerifier);
1435
+ const codeChallenge = arrayBufferToBase64Url(codeChallengeRaw, false);
1436
+ return {
1437
+ clientId: config.clientId,
1438
+ responseType: "code",
1439
+ redirectUri: config.redirectUri,
1440
+ codeChallenge: CodeChallenge(codeChallenge),
1441
+ codeChallengeMethod: "S256",
1442
+ state: PKCEState(state),
1443
+ codeVerifier: CodeVerifier(codeVerifier)
1444
+ };
1445
+ }
1446
+
1447
+ // src/shared/types/document-submission.ts
1448
+ var DocumentSubmission = {
1449
+ fromDto: (dto) => ({
1450
+ status: dto.status,
1451
+ formType: dto.form_type
1452
+ })
1453
+ };
1454
+
1455
+ // src/shared/types/errors.ts
1456
+ var NotImplementedError = class extends Error {
1457
+ constructor(message = "Not implemented yet") {
1458
+ super(message);
1459
+ this.name = "NotImplementedError";
1460
+ }
1461
+ };
1462
+ var NotAuthenticatedError = class extends Error {
1463
+ constructor(message = "The user is not authenticated. Go through the OAuth flow first!") {
1464
+ super(message);
1465
+ this.name = "NotAuthenticatedError";
1466
+ }
1467
+ };
1468
+
1469
+ // src/shared/types/kyc.ts
1470
+ var KycToken = {
1471
+ fromDto: (dto) => ({
1472
+ token: dto.token
1473
+ })
1474
+ };
1475
+
1476
+ // src/shared/types/oauth-session.ts
1477
+ var ClientCredentialsOAuth = (value) => value;
1478
+ var OAuthRefreshToken = (value) => value;
1479
+ var OAuthSession = {
1480
+ fromDto: (dto) => {
1481
+ const expiresAt = new Date(Date.now() + dto.expires_in * 1e3);
1482
+ return {
1483
+ accessToken: {
1484
+ value: dto.access_token,
1485
+ expiresAt
1486
+ },
1487
+ ...dto.refresh_token != null && dto.refresh_token !== "" ? { refreshToken: OAuthRefreshToken(dto.refresh_token) } : void 0
1488
+ };
1489
+ }
1490
+ };
1491
+
1492
+ // src/shared/types/pii.ts
1493
+ var Iso2CountryCode = (value) => value;
1494
+ var PiiJurisdiction = {
1495
+ fromDto: (dto) => ({
1496
+ iso2: Iso2CountryCode(dto.iso_2),
1497
+ name: dto.name
1498
+ })
1499
+ };
1500
+ var PiiAddress = {
1501
+ fromDto: (dto) => ({
1502
+ street: dto.street,
1503
+ city: dto.city,
1504
+ state: dto.state,
1505
+ postalCode: dto.postal_code,
1506
+ country: dto.country
1507
+ })
1508
+ };
1509
+ var Pii = {
1510
+ fromDto: (dto) => ({
1511
+ kind: dto.kind,
1512
+ fullLegalName: dto.full_legal_name,
1513
+ dateOfBirth: dto.date_of_birth,
1514
+ jurisdiction: dto.jurisdiction ? PiiJurisdiction.fromDto(dto.jurisdiction) : null,
1515
+ taxId: dto.tax_id,
1516
+ permanentAddress: PiiAddress.fromDto(dto.permanent_address)
1517
+ })
1518
+ };
1519
+
354
1520
  // src/shared/types/requirement.ts
355
1521
  var RequirementId = (value) => value;
356
1522
  var Requirement = {
@@ -361,10 +1527,15 @@ var Requirement = {
361
1527
  })
362
1528
  };
363
1529
  var RequirementStatusInfo = {
364
- fromStatusesDto: (dto) => Object.entries(dto.statuses).map(([id, status]) => ({
365
- id: RequirementId(id),
366
- status
367
- }))
1530
+ fromStatusesDto: (dto) => Object.entries(dto.statuses).map(
1531
+ ([id, value]) => typeof value === "string" ? { id: RequirementId(id), status: value, action: null } : {
1532
+ id: RequirementId(id),
1533
+ status: value.status,
1534
+ action: value.action ?? null,
1535
+ kycLevel: value.kyc_level,
1536
+ kycReset: value.kyc_reset
1537
+ }
1538
+ )
368
1539
  };
369
1540
 
370
1541
  // src/shared/types/user.ts
@@ -378,20 +1549,46 @@ var User = {
378
1549
  };
379
1550
  // Annotate the CommonJS export names for ESM import in node:
380
1551
  0 && (module.exports = {
1552
+ AllowWalletResponse,
381
1553
  Asset,
382
1554
  AssetCode,
1555
+ AssetDecimals,
1556
+ AssetIconUrl,
383
1557
  AssetId,
1558
+ AssetSymbol,
384
1559
  AuthorizationCode,
1560
+ BPS_DENOM,
385
1561
  Blockchain,
1562
+ BlockchainAmount,
1563
+ Bps,
1564
+ ClientCredentialsOAuth,
386
1565
  ClientId,
387
1566
  ClientSecret,
388
1567
  CodeChallenge,
389
1568
  CodeVerifier,
1569
+ ConnectExternalWalletParams,
390
1570
  CreateParticipationParams,
1571
+ CreateWalletOwnershipChallengeParams,
391
1572
  Cursor,
1573
+ DEFAULT_AMOUNT_TO_COMPUTE_PRICE,
1574
+ DEFAULT_SLIPPAGE_BPS,
1575
+ DocumentSubmission,
1576
+ ERC20_ABI,
1577
+ Erc20NamespaceImpl,
1578
+ EvmContractAddress,
1579
+ EvmWalletAddress,
392
1580
  FaqItem,
1581
+ FormattedAmountAssetUi,
1582
+ FormattedAmountUi,
1583
+ FormattedPercentUi,
1584
+ HexEncodedTransactionData,
1585
+ Iso2CountryCode,
1586
+ KnownAssetSymbol,
1587
+ KycToken,
393
1588
  Link,
1589
+ MAX_UINT_256,
394
1590
  Milestone,
1591
+ NA_AMOUNT_ASSET_UI,
395
1592
  NotAuthenticatedError,
396
1593
  NotImplementedError,
397
1594
  OAuthRefreshToken,
@@ -400,6 +1597,8 @@ var User = {
400
1597
  OfferDetail,
401
1598
  OfferId,
402
1599
  OfferOption,
1600
+ OfferOptionAddress,
1601
+ OfferOptionAddressId,
403
1602
  OfferOptionId,
404
1603
  OfferOptionSlug,
405
1604
  OfferSlug,
@@ -409,16 +1608,60 @@ var User = {
409
1608
  Participation,
410
1609
  ParticipationId,
411
1610
  ParticipationsPaginationParams,
1611
+ Pii,
1612
+ PiiAddress,
1613
+ PiiJurisdiction,
412
1614
  RedirectUri,
413
1615
  Requirement,
414
1616
  RequirementId,
415
1617
  RequirementStatusInfo,
1618
+ SLIPPAGE_OPTIONS_BPS,
1619
+ SUPERSTATE_SWAP_ABI,
1620
+ SUPERSTATE_SWAP_CONTRACT_ADDRESS_SEPOLIA,
1621
+ SUPERSTATE_TOS_URL,
1622
+ SWAP_POLL_INTERVAL_MS,
1623
+ ShortenedWalletAddress,
1624
+ StablecoinSymbol,
1625
+ SwapAuthorization,
1626
+ SwapNamespaceImpl,
1627
+ SwapPreview,
1628
+ SwapQuote,
1629
+ SwapStatus,
1630
+ TOKEN_REGISTRY,
416
1631
  TermItem,
1632
+ TokenAllowance,
1633
+ TokenBalance,
1634
+ TokenSaleNamespaceImpl,
1635
+ TxExplorerUrl,
1636
+ USDC,
1637
+ USDC_SYMBOL,
1638
+ USDT,
1639
+ USDT_SYMBOL,
417
1640
  User,
418
1641
  UserEmail,
419
1642
  UserId,
420
1643
  WalletAddress,
1644
+ WalletOwnershipChallenge,
1645
+ applyBps,
1646
+ assertUint256,
1647
+ assetAmount,
1648
+ computePrice,
1649
+ computeSlip,
1650
+ decodeSwappedOutputAmount,
421
1651
  fetchAllPages,
422
- generatePKCEParams
1652
+ formatAmount,
1653
+ formatBpsAsPercent,
1654
+ formatCompactAmount,
1655
+ formatRawAmount,
1656
+ formattedPricePerShare,
1657
+ formattedUsdPrice,
1658
+ generatePKCEParams,
1659
+ getChainId,
1660
+ getNetworkName,
1661
+ isStopped,
1662
+ parseBlockchainAmount,
1663
+ shortenAddress,
1664
+ txExplorerUrl,
1665
+ usdAmount
423
1666
  });
424
1667
  //# sourceMappingURL=index.cjs.map