@coinlist-co/react 0.12.2-rc.abd9d38 → 0.12.2-rc.e1f6c82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/{chunk-45LAPB7U.js → chunk-EKLUJZ7T.js} +10 -10
- package/dist/chunk-EKLUJZ7T.js.map +1 -0
- package/dist/{chunk-HDJEDOS4.js → chunk-GIE4UWB3.js} +1207 -799
- package/dist/chunk-GIE4UWB3.js.map +1 -0
- package/dist/chunk-MJ6YXZWH.js +22 -0
- package/dist/chunk-MJ6YXZWH.js.map +1 -0
- package/dist/{chunk-M7WDZZPX.js → chunk-PIOQA6HW.js} +194 -190
- package/dist/chunk-PIOQA6HW.js.map +1 -0
- package/dist/client/index.d.ts +2977 -4267
- package/dist/client/index.js +8552 -5713
- package/dist/client/index.js.map +1 -1
- package/dist/server/index.d.ts +7 -33
- package/dist/server/index.js +8 -4
- package/dist/server/index.js.map +1 -1
- package/dist/{tokens-namespace-DrwRi0AQ.d.cts → time-Bbqlt2x7.d.ts} +2081 -2734
- package/dist/{token-registry-snapshot-C-Qs3Lgs.d.ts → token-registry-snapshot-DttZXGvY.d.ts} +74 -42
- package/dist/universal/index.d.ts +59 -998
- package/dist/universal/index.js +38 -36
- package/package.json +18 -14
- package/dist/chunk-45LAPB7U.js.map +0 -1
- package/dist/chunk-HDJEDOS4.js.map +0 -1
- package/dist/chunk-M7WDZZPX.js.map +0 -1
- package/dist/client/index.cjs +0 -17098
- package/dist/client/index.cjs.map +0 -1
- package/dist/client/index.d.cts +0 -6660
- package/dist/server/index.cjs +0 -4240
- package/dist/server/index.cjs.map +0 -1
- package/dist/server/index.d.cts +0 -378
- package/dist/time-BOCS1TbH.d.cts +0 -50
- package/dist/time-C7mhO5_a.d.ts +0 -50
- package/dist/token-registry-snapshot-CpzLmsc2.d.cts +0 -179
- package/dist/tokens-namespace-DrwRi0AQ.d.ts +0 -3364
- package/dist/universal/index.cjs +0 -4135
- package/dist/universal/index.cjs.map +0 -1
- package/dist/universal/index.d.cts +0 -1314
|
@@ -291,166 +291,6 @@ function isExpired({
|
|
|
291
291
|
return now >= expiresAt - buffer;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
// src/universal/core/shared/blockchain/erc20/abi.ts
|
|
295
|
-
var ERC20_ABI = [
|
|
296
|
-
{
|
|
297
|
-
type: "function",
|
|
298
|
-
name: "allowance",
|
|
299
|
-
inputs: [
|
|
300
|
-
{ name: "owner", type: "address" },
|
|
301
|
-
{ name: "spender", type: "address" }
|
|
302
|
-
],
|
|
303
|
-
outputs: [{ name: "", type: "uint256" }],
|
|
304
|
-
stateMutability: "view"
|
|
305
|
-
},
|
|
306
|
-
{
|
|
307
|
-
type: "function",
|
|
308
|
-
name: "approve",
|
|
309
|
-
inputs: [
|
|
310
|
-
{ name: "spender", type: "address" },
|
|
311
|
-
{ name: "amount", type: "uint256" }
|
|
312
|
-
],
|
|
313
|
-
outputs: [{ name: "", type: "bool" }],
|
|
314
|
-
stateMutability: "nonpayable"
|
|
315
|
-
},
|
|
316
|
-
{
|
|
317
|
-
type: "function",
|
|
318
|
-
name: "balanceOf",
|
|
319
|
-
inputs: [{ name: "account", type: "address" }],
|
|
320
|
-
outputs: [{ name: "", type: "uint256" }],
|
|
321
|
-
stateMutability: "view"
|
|
322
|
-
},
|
|
323
|
-
{
|
|
324
|
-
type: "function",
|
|
325
|
-
name: "decimals",
|
|
326
|
-
inputs: [],
|
|
327
|
-
outputs: [{ name: "", type: "uint8" }],
|
|
328
|
-
stateMutability: "view"
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
type: "function",
|
|
332
|
-
name: "name",
|
|
333
|
-
inputs: [],
|
|
334
|
-
outputs: [{ name: "", type: "string" }],
|
|
335
|
-
stateMutability: "view"
|
|
336
|
-
},
|
|
337
|
-
{
|
|
338
|
-
type: "function",
|
|
339
|
-
name: "symbol",
|
|
340
|
-
inputs: [],
|
|
341
|
-
outputs: [{ name: "", type: "string" }],
|
|
342
|
-
stateMutability: "view"
|
|
343
|
-
},
|
|
344
|
-
{
|
|
345
|
-
type: "function",
|
|
346
|
-
name: "totalSupply",
|
|
347
|
-
inputs: [],
|
|
348
|
-
outputs: [{ name: "", type: "uint256" }],
|
|
349
|
-
stateMutability: "view"
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
type: "function",
|
|
353
|
-
name: "transfer",
|
|
354
|
-
inputs: [
|
|
355
|
-
{ name: "recipient", type: "address" },
|
|
356
|
-
{ name: "amount", type: "uint256" }
|
|
357
|
-
],
|
|
358
|
-
outputs: [{ name: "", type: "bool" }],
|
|
359
|
-
stateMutability: "nonpayable"
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
type: "function",
|
|
363
|
-
name: "transferFrom",
|
|
364
|
-
inputs: [
|
|
365
|
-
{ name: "sender", type: "address" },
|
|
366
|
-
{ name: "recipient", type: "address" },
|
|
367
|
-
{ name: "amount", type: "uint256" }
|
|
368
|
-
],
|
|
369
|
-
outputs: [{ name: "", type: "bool" }],
|
|
370
|
-
stateMutability: "nonpayable"
|
|
371
|
-
},
|
|
372
|
-
{
|
|
373
|
-
type: "event",
|
|
374
|
-
name: "Approval",
|
|
375
|
-
inputs: [
|
|
376
|
-
{ name: "owner", type: "address", indexed: true },
|
|
377
|
-
{ name: "spender", type: "address", indexed: true },
|
|
378
|
-
{ name: "value", type: "uint256", indexed: false }
|
|
379
|
-
],
|
|
380
|
-
anonymous: false
|
|
381
|
-
},
|
|
382
|
-
{
|
|
383
|
-
type: "event",
|
|
384
|
-
name: "Transfer",
|
|
385
|
-
inputs: [
|
|
386
|
-
{ name: "from", type: "address", indexed: true },
|
|
387
|
-
{ name: "to", type: "address", indexed: true },
|
|
388
|
-
{ name: "value", type: "uint256", indexed: false }
|
|
389
|
-
],
|
|
390
|
-
anonymous: false
|
|
391
|
-
}
|
|
392
|
-
];
|
|
393
|
-
|
|
394
|
-
// src/universal/api/pagination.ts
|
|
395
|
-
async function fetchAllPages(fetchPage, baseParams) {
|
|
396
|
-
const items = [];
|
|
397
|
-
let cursor = null;
|
|
398
|
-
do {
|
|
399
|
-
const params = {
|
|
400
|
-
...baseParams ?? {},
|
|
401
|
-
after: cursor ?? void 0
|
|
402
|
-
};
|
|
403
|
-
const page = await fetchPage(params);
|
|
404
|
-
items.push(...page.data);
|
|
405
|
-
cursor = page.startingAfter;
|
|
406
|
-
} while (cursor);
|
|
407
|
-
return items;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// src/universal/types/pagination.ts
|
|
411
|
-
var Cursor = (value) => value;
|
|
412
|
-
var PaginatedResponse = {
|
|
413
|
-
fromDto: (dto, itemMapper) => PaginatedResponse.fromDtoPage(dto, (items) => items.map(itemMapper)),
|
|
414
|
-
/**
|
|
415
|
-
* For a mapper that decides the page as a whole - one that drops items it
|
|
416
|
-
* cannot map, such as `Offer.listFromDto` - rather than item by item. The
|
|
417
|
-
* cursors are the wire's either way: dropping an item changes what the
|
|
418
|
-
* page holds, not where the next page starts.
|
|
419
|
-
*/
|
|
420
|
-
fromDtoPage: (dto, pageMapper) => ({
|
|
421
|
-
data: pageMapper(dto.data),
|
|
422
|
-
startingAfter: dto.starting_after ? Cursor(dto.starting_after) : null,
|
|
423
|
-
startingBefore: dto.starting_before ? Cursor(dto.starting_before) : null
|
|
424
|
-
})
|
|
425
|
-
};
|
|
426
|
-
var PaginationParams = {
|
|
427
|
-
toQueryParams: (params) => {
|
|
428
|
-
const queryParams = {};
|
|
429
|
-
if (params.after) {
|
|
430
|
-
queryParams.starting_after = params.after;
|
|
431
|
-
}
|
|
432
|
-
if (params.before) {
|
|
433
|
-
queryParams.starting_before = params.before;
|
|
434
|
-
}
|
|
435
|
-
if (params.limit) {
|
|
436
|
-
queryParams.limit = params.limit;
|
|
437
|
-
}
|
|
438
|
-
return queryParams;
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
// src/universal/types/asset.ts
|
|
443
|
-
var AssetId = (value) => value;
|
|
444
|
-
var AssetCode = (value) => value;
|
|
445
|
-
var Asset = {
|
|
446
|
-
fromDto: (dto) => ({
|
|
447
|
-
id: AssetId(dto.id),
|
|
448
|
-
code: AssetCode(dto.code),
|
|
449
|
-
name: dto.name,
|
|
450
|
-
fractionalDigits: dto.fractional_digits
|
|
451
|
-
})
|
|
452
|
-
};
|
|
453
|
-
|
|
454
294
|
// src/universal/types/blockchain/core.ts
|
|
455
295
|
var ETHEREUM_CHAINS = {
|
|
456
296
|
ethereum_mainnet: true,
|
|
@@ -513,8 +353,18 @@ var BlockchainAmount = Object.assign(
|
|
|
513
353
|
{
|
|
514
354
|
add: (a, b) => combineAmounts(a, b, (x, y) => x + y),
|
|
515
355
|
sub: (a, b) => combineAmounts(a, b, (x, y) => x - y),
|
|
516
|
-
|
|
517
|
-
|
|
356
|
+
/**
|
|
357
|
+
* `a * b`, in `a`'s decimals - a price times a quantity. Multiplies before
|
|
358
|
+
* it rescales, then truncates towards zero. The exact inverse of `div`.
|
|
359
|
+
*/
|
|
360
|
+
mul: (a, b) => multiplyAmounts(a, b),
|
|
361
|
+
/**
|
|
362
|
+
* `a / b`, in `a`'s decimals - a price, a ratio. Rescales before it
|
|
363
|
+
* divides, then truncates towards zero.
|
|
364
|
+
*
|
|
365
|
+
* @throws MathError when `b` is zero.
|
|
366
|
+
*/
|
|
367
|
+
div: (a, b) => divideAmounts(a, b)
|
|
518
368
|
}
|
|
519
369
|
);
|
|
520
370
|
function multiplyAmounts(a, b) {
|
|
@@ -548,6 +398,66 @@ var StablecoinSymbol = (value) => value;
|
|
|
548
398
|
var KnownAssetSymbol = StablecoinSymbol;
|
|
549
399
|
var Bps = (value) => value;
|
|
550
400
|
|
|
401
|
+
// src/universal/core/shared/blockchain/math.ts
|
|
402
|
+
import { parseUnits } from "viem";
|
|
403
|
+
function blockchainAmountFromRawOrThrow({
|
|
404
|
+
label,
|
|
405
|
+
raw,
|
|
406
|
+
decimals
|
|
407
|
+
}) {
|
|
408
|
+
const trimmed = raw.trim();
|
|
409
|
+
if (trimmed === "") {
|
|
410
|
+
throw new ValidationError(`${label}: not a uint256 integer ("${raw}")`);
|
|
411
|
+
}
|
|
412
|
+
let value;
|
|
413
|
+
try {
|
|
414
|
+
value = BigInt(trimmed);
|
|
415
|
+
} catch {
|
|
416
|
+
throw new ValidationError(`${label}: not a uint256 integer ("${raw}")`);
|
|
417
|
+
}
|
|
418
|
+
try {
|
|
419
|
+
return BlockchainAmount({ raw: assertUint256(value), decimals });
|
|
420
|
+
} catch {
|
|
421
|
+
throw new ValidationError(`${label}: out of uint256 bounds (${value})`);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
function parseBlockchainAmount(amount, decimals) {
|
|
425
|
+
const trimmed = amount.trim();
|
|
426
|
+
if (trimmed === "") return { valid: false, reason: { type: "empty" } };
|
|
427
|
+
if (trimmed.startsWith("-")) {
|
|
428
|
+
return { valid: false, reason: { type: "negative" } };
|
|
429
|
+
}
|
|
430
|
+
if (/[eE]/.test(trimmed)) {
|
|
431
|
+
return { valid: false, reason: { type: "invalid-format" } };
|
|
432
|
+
}
|
|
433
|
+
if (trimmed === ".") {
|
|
434
|
+
return { valid: false, reason: { type: "invalid-format" } };
|
|
435
|
+
}
|
|
436
|
+
const normalised = trimmed.replace(/^\./, "0.").replace(/\.$/, "");
|
|
437
|
+
if (!/^\d+(\.\d+)?$/.test(normalised)) {
|
|
438
|
+
return { valid: false, reason: { type: "invalid-format" } };
|
|
439
|
+
}
|
|
440
|
+
const [, fraction = ""] = normalised.split(".");
|
|
441
|
+
if (fraction.length > decimals) {
|
|
442
|
+
return {
|
|
443
|
+
valid: false,
|
|
444
|
+
reason: { type: "too-many-decimals", maxDecimals: decimals }
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
try {
|
|
448
|
+
const raw = parseUnits(normalised, decimals);
|
|
449
|
+
if (raw > MAX_UINT_256) {
|
|
450
|
+
return { valid: false, reason: { type: "overflow" } };
|
|
451
|
+
}
|
|
452
|
+
return {
|
|
453
|
+
valid: true,
|
|
454
|
+
amount: BlockchainAmount({ raw, decimals })
|
|
455
|
+
};
|
|
456
|
+
} catch {
|
|
457
|
+
return { valid: false, reason: { type: "invalid-format" } };
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
551
461
|
// src/universal/core/shared/utils/crypto.ts
|
|
552
462
|
async function sha256(data) {
|
|
553
463
|
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
@@ -623,6 +533,12 @@ function requiredDate(value, field) {
|
|
|
623
533
|
}
|
|
624
534
|
return date;
|
|
625
535
|
}
|
|
536
|
+
function dateOrNull(value, field) {
|
|
537
|
+
return value === null ? null : requiredDate(value, field);
|
|
538
|
+
}
|
|
539
|
+
function decimalOrNull(value) {
|
|
540
|
+
return value === null ? null : DecimalString(value);
|
|
541
|
+
}
|
|
626
542
|
function requiredArray(value, field) {
|
|
627
543
|
if (!Array.isArray(value)) {
|
|
628
544
|
throw new ValidationError(
|
|
@@ -632,293 +548,274 @@ function requiredArray(value, field) {
|
|
|
632
548
|
return value;
|
|
633
549
|
}
|
|
634
550
|
|
|
635
|
-
// src/universal/types/
|
|
636
|
-
var
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
551
|
+
// src/universal/types/providers/centrifuge/centrifuge.ts
|
|
552
|
+
var CentrifugeVaultStatus = {
|
|
553
|
+
fromDto: (dto) => ({
|
|
554
|
+
chain: EthereumChain(dto.chain),
|
|
555
|
+
symbol: AssetSymbol(dto.symbol),
|
|
556
|
+
vaultAddress: EvmContractAddress(dto.vault_address),
|
|
557
|
+
linked: dto.linked,
|
|
558
|
+
permissioned: dto.permissioned,
|
|
559
|
+
membershipValidUntil: dateOrNull(
|
|
560
|
+
dto.membership_valid_until,
|
|
561
|
+
"CentrifugeVaultStatus.membership_valid_until"
|
|
562
|
+
),
|
|
563
|
+
halted: dto.halted,
|
|
564
|
+
priceUpdatedAt: dateOrNull(
|
|
565
|
+
dto.price_updated_at,
|
|
566
|
+
"CentrifugeVaultStatus.price_updated_at"
|
|
567
|
+
),
|
|
568
|
+
orderability: parseOrderability(
|
|
569
|
+
dto.can_order,
|
|
570
|
+
dto.reasons,
|
|
571
|
+
"CentrifugeVaultStatus"
|
|
572
|
+
),
|
|
573
|
+
asOf: requiredDate(dto.as_of, "CentrifugeVaultStatus.as_of")
|
|
653
574
|
})
|
|
654
575
|
};
|
|
655
|
-
var
|
|
576
|
+
var CentrifugeVaultBuyTransaction = {
|
|
656
577
|
fromDto: (dto) => {
|
|
657
|
-
const
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
578
|
+
const spendInputAmount = blockchainAmountFromRawOrThrow({
|
|
579
|
+
label: "spend_input_amount",
|
|
580
|
+
raw: dto.spend_input_amount,
|
|
581
|
+
decimals: AssetDecimals(dto.spend_input_decimals)
|
|
582
|
+
});
|
|
583
|
+
if (spendInputAmount.raw <= 0n) {
|
|
584
|
+
throw new ValidationError(
|
|
585
|
+
`spend_input_amount: must be greater than zero ("${dto.spend_input_amount}") - a deposit of nothing is not a request`
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
return {
|
|
589
|
+
...parseTransactionCore(dto, "CentrifugeVaultBuyTransaction"),
|
|
590
|
+
spendInputAmount
|
|
663
591
|
};
|
|
664
|
-
|
|
665
|
-
case "coinlist::token_sale":
|
|
666
|
-
return {
|
|
667
|
-
...base2,
|
|
668
|
-
...OfferEditorial.fromDto(dto, "Offer"),
|
|
669
|
-
type: dto.type,
|
|
670
|
-
logoUrl: requiredString(dto.logo_url, "Offer.logo_url")
|
|
671
|
-
};
|
|
672
|
-
case "superstate::swap":
|
|
673
|
-
return {
|
|
674
|
-
...base2,
|
|
675
|
-
...OfferEditorial.fromDto(dto, "Offer"),
|
|
676
|
-
type: dto.type,
|
|
677
|
-
logoUrl: notBlankStringOrNull(dto.logo_url)
|
|
678
|
-
};
|
|
679
|
-
// `tagline`, `banner_url` and `starts_at` arrive as `null` and are left
|
|
680
|
-
// on the wire: copying them would hand every consumer a `startsAt` that
|
|
681
|
-
// is 1970 for one variant and a date for the others.
|
|
682
|
-
case "ondo::swap":
|
|
683
|
-
return {
|
|
684
|
-
...base2,
|
|
685
|
-
type: dto.type,
|
|
686
|
-
logoUrl: notBlankStringOrNull(dto.logo_url)
|
|
687
|
-
};
|
|
688
|
-
default:
|
|
689
|
-
return unknownTypeError(dto, "Offer");
|
|
690
|
-
}
|
|
691
|
-
},
|
|
692
|
-
/**
|
|
693
|
-
* Maps a page of offers, dropping every offer whose `type` this SDK does not
|
|
694
|
-
* name. The same reasoning as {@link OfferToken.listFromDto}: a plain `.map`
|
|
695
|
-
* would throw out of `fromDto` and, through `PaginatedResponse.fromDto`,
|
|
696
|
-
* reject the whole page, so one offer of an unknown type would blank the
|
|
697
|
-
* grid for every offer beside it. A single offer fetched by id still
|
|
698
|
-
* throws, because there is nothing beside it to keep.
|
|
699
|
-
*/
|
|
700
|
-
listFromDto: (dtos) => dtos.filter((dto) => isOfferType(dto.type)).map(Offer.fromDto)
|
|
701
|
-
};
|
|
702
|
-
var OfferToken = {
|
|
703
|
-
fromDto: (dto) => ({
|
|
704
|
-
role: dto.role,
|
|
705
|
-
chain: Chain(dto.chain),
|
|
706
|
-
address: EvmContractAddress(dto.address)
|
|
707
|
-
}),
|
|
708
|
-
/**
|
|
709
|
-
* Maps an offer's token list, dropping every token on a chain this SDK does
|
|
710
|
-
* not name. Frontline's chain registry runs ahead of {@link Chain}, and a
|
|
711
|
-
* plain `.map` would throw out of `Offer.fromDto` and, through
|
|
712
|
-
* `PaginatedResponse.fromDto`, reject the whole offers page - which is how
|
|
713
|
-
* one Base token blanked production's offers list. Dropping costs that
|
|
714
|
-
* token's metadata alone: `coinlist.tokens.get` takes an `EthereumChain`,
|
|
715
|
-
* so nobody could have looked it up anyway.
|
|
716
|
-
*
|
|
717
|
-
* Same shape as `TokenMetadata.fromRegistryDto`.
|
|
718
|
-
*/
|
|
719
|
-
listFromDto: (dtos) => dtos.filter((dto) => isChain(dto.chain)).map(OfferToken.fromDto)
|
|
592
|
+
}
|
|
720
593
|
};
|
|
721
|
-
|
|
722
|
-
// src/universal/types/trading.ts
|
|
723
|
-
var Ticker = (value) => value;
|
|
724
|
-
var Isin = (value) => value;
|
|
725
|
-
|
|
726
|
-
// src/universal/types/offer-detail.ts
|
|
727
|
-
var OfferOptionId = (value) => value;
|
|
728
|
-
var OfferOptionSlug = (value) => value;
|
|
729
|
-
var OfferSwapContract = {
|
|
594
|
+
var CentrifugeVaultClaimTransaction = {
|
|
730
595
|
fromDto: (dto) => ({
|
|
731
|
-
|
|
732
|
-
|
|
596
|
+
...parseTransactionCore(dto, "CentrifugeVaultClaimTransaction"),
|
|
597
|
+
claimableShares: blockchainAmountFromRawOrThrow({
|
|
598
|
+
label: "claimable_shares",
|
|
599
|
+
raw: dto.claimable_shares,
|
|
600
|
+
decimals: AssetDecimals(dto.share_decimals)
|
|
601
|
+
})
|
|
733
602
|
})
|
|
734
603
|
};
|
|
735
|
-
var
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
const tokens = requiredArray(dto.tokens, "OfferDetail.tokens");
|
|
747
|
-
const isin = notBlankStringOrNull(dto.isin);
|
|
748
|
-
const ticker = notBlankStringOrNull(dto.ticker);
|
|
749
|
-
const base2 = {
|
|
750
|
-
id: OfferId(dto.id),
|
|
751
|
-
slug: OfferSlug(dto.slug),
|
|
752
|
-
name: dto.name,
|
|
753
|
-
asset: Asset.fromDto(dto.asset),
|
|
754
|
-
fundingAssets: fundingAssets.map(Asset.fromDto),
|
|
755
|
-
tokens: OfferToken.listFromDto(tokens),
|
|
756
|
-
about: notBlankStringOrNull(dto.about),
|
|
757
|
-
category: dto.category,
|
|
758
|
-
issuer: notBlankStringOrNull(dto.issuer),
|
|
759
|
-
isin: isin === null ? null : Isin(isin),
|
|
760
|
-
ticker: ticker === null ? null : Ticker(ticker),
|
|
761
|
-
instrumentType: notBlankStringOrNull(dto.instrument_type),
|
|
762
|
-
listingVenue: notBlankStringOrNull(dto.listing_venue),
|
|
763
|
-
endsAt: dto.ends_at ? new Date(dto.ends_at) : null,
|
|
764
|
-
faqs: faqs.map(FaqItem.fromDto),
|
|
765
|
-
links: links.map(Link.fromDto),
|
|
766
|
-
milestones: milestones.map(Milestone.fromDto),
|
|
767
|
-
options: options.map(OfferOption.fromDto),
|
|
768
|
-
terms: terms.map(TermItem.fromDto)
|
|
604
|
+
var CentrifugeAssets = (amount) => amount;
|
|
605
|
+
var CentrifugeShares = (amount) => amount;
|
|
606
|
+
var CentrifugeDepositPosition = {
|
|
607
|
+
fromContract: (raw, context) => {
|
|
608
|
+
const assets = (label, value) => CentrifugeAssets(contractAmount(label, value, context.assetDecimals));
|
|
609
|
+
return {
|
|
610
|
+
chain: context.chain,
|
|
611
|
+
proxy: context.proxy,
|
|
612
|
+
walletAddress: context.walletAddress,
|
|
613
|
+
pending: assets("pendingDepositRequest", raw.pendingDepositRequest),
|
|
614
|
+
claimable: assets("claimableDepositRequest", raw.claimableDepositRequest)
|
|
769
615
|
};
|
|
770
|
-
switch (dto.type) {
|
|
771
|
-
case "coinlist::token_sale":
|
|
772
|
-
return {
|
|
773
|
-
...base2,
|
|
774
|
-
...OfferEditorial.fromDto(dto, "OfferDetail"),
|
|
775
|
-
type: dto.type,
|
|
776
|
-
logoUrl: requiredString(dto.logo_url, "OfferDetail.logo_url")
|
|
777
|
-
};
|
|
778
|
-
case "superstate::swap":
|
|
779
|
-
return {
|
|
780
|
-
...base2,
|
|
781
|
-
...OfferEditorial.fromDto(dto, "OfferDetail"),
|
|
782
|
-
type: dto.type,
|
|
783
|
-
logoUrl: notBlankStringOrNull(dto.logo_url)
|
|
784
|
-
};
|
|
785
|
-
// `tagline`, `banner_url` and `starts_at` arrive as `null` and are left
|
|
786
|
-
// on the wire, as in `Offer.fromDto`.
|
|
787
|
-
case "ondo::swap":
|
|
788
|
-
return {
|
|
789
|
-
...base2,
|
|
790
|
-
type: dto.type,
|
|
791
|
-
logoUrl: notBlankStringOrNull(dto.logo_url),
|
|
792
|
-
swapContracts: requiredArray(
|
|
793
|
-
dto.swap_contracts,
|
|
794
|
-
"OfferDetail.swap_contracts"
|
|
795
|
-
).map(OfferSwapContract.fromDto)
|
|
796
|
-
};
|
|
797
|
-
default:
|
|
798
|
-
return unknownTypeError(dto, "OfferDetail");
|
|
799
|
-
}
|
|
800
616
|
}
|
|
801
617
|
};
|
|
802
|
-
var
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
}
|
|
813
|
-
};
|
|
814
|
-
var FaqItem = {
|
|
815
|
-
fromDto: (dto) => ({
|
|
816
|
-
question: notBlankStringOrNull(dto.question),
|
|
817
|
-
answer: notBlankStringOrNull(dto.answer)
|
|
818
|
-
})
|
|
618
|
+
var CentrifugeRedeemPosition = {
|
|
619
|
+
fromContract: (raw, context) => {
|
|
620
|
+
const shares = (label, value) => CentrifugeShares(contractAmount(label, value, context.shareDecimals));
|
|
621
|
+
return {
|
|
622
|
+
chain: context.chain,
|
|
623
|
+
proxy: context.proxy,
|
|
624
|
+
walletAddress: context.walletAddress,
|
|
625
|
+
pending: shares("pendingRedeemRequest", raw.pendingRedeemRequest),
|
|
626
|
+
claimable: shares("claimableRedeemRequest", raw.claimableRedeemRequest)
|
|
627
|
+
};
|
|
628
|
+
}
|
|
819
629
|
};
|
|
820
|
-
var
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
url: notBlankStringOrNull(dto.url)
|
|
824
|
-
})
|
|
630
|
+
var CentrifugeVaultLeg = {
|
|
631
|
+
/** Whether the leg has anything queued or anything ready to claim. */
|
|
632
|
+
isActive: (leg) => leg.position.pending.raw > 0n || leg.position.claimable.raw > 0n
|
|
825
633
|
};
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
634
|
+
function contractAmount(label, value, decimals) {
|
|
635
|
+
return BlockchainAmount({ raw: parseUint256(value, label), decimals });
|
|
636
|
+
}
|
|
637
|
+
var CentrifugeVaultLegId = {
|
|
638
|
+
/** Addresses compare case-insensitively: a host may pass either case. */
|
|
639
|
+
of: (leg) => [
|
|
640
|
+
leg.direction,
|
|
641
|
+
leg.position.chain,
|
|
642
|
+
leg.position.walletAddress.toLowerCase()
|
|
643
|
+
].join(":")
|
|
831
644
|
};
|
|
832
|
-
var
|
|
645
|
+
var CentrifugeVaultClaimProceedsTransaction = {
|
|
833
646
|
fromDto: (dto) => ({
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
647
|
+
...parseTransactionCore(dto, "CentrifugeVaultClaimProceedsTransaction"),
|
|
648
|
+
claimableAssets: blockchainAmountFromRawOrThrow({
|
|
649
|
+
label: "claimable_assets",
|
|
650
|
+
raw: dto.claimable_assets,
|
|
651
|
+
decimals: AssetDecimals(dto.asset_decimals)
|
|
652
|
+
})
|
|
837
653
|
})
|
|
838
654
|
};
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
const queryParams = PaginationParams.toQueryParams(params);
|
|
847
|
-
if (params.offerId) {
|
|
848
|
-
queryParams["filters[0][field]"] = "offer_id";
|
|
849
|
-
queryParams["filters[0][op]"] = "==";
|
|
850
|
-
queryParams["filters[0][value]"] = params.offerId;
|
|
655
|
+
function parseOrderability(canOrder, reasons, model) {
|
|
656
|
+
const [first, ...rest] = reasons;
|
|
657
|
+
if (canOrder) {
|
|
658
|
+
if (first !== void 0) {
|
|
659
|
+
throw new ValidationError(
|
|
660
|
+
`${model}.reasons: expected none when can_order is true, got ${JSON.stringify(reasons)}`
|
|
661
|
+
);
|
|
851
662
|
}
|
|
852
|
-
return
|
|
663
|
+
return { type: "orderable" };
|
|
853
664
|
}
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
const walletAddress = notBlankStringOrNull(dto.wallet_address);
|
|
859
|
-
return {
|
|
860
|
-
id: ParticipationId(dto.id),
|
|
861
|
-
offerId: OfferId(dto.offer_id),
|
|
862
|
-
offerOptionId: OfferOptionId(dto.offer_option_id),
|
|
863
|
-
status: dto.status,
|
|
864
|
-
amount: dto.amount,
|
|
865
|
-
displayAmount: dto.amount_string,
|
|
866
|
-
asset: Asset.fromDto(dto.asset),
|
|
867
|
-
chain: Blockchain(dto.chain),
|
|
868
|
-
insertedAt: dto.inserted_at ? new Date(dto.inserted_at) : null,
|
|
869
|
-
updatedAt: dto.updated_at ? new Date(dto.updated_at) : null,
|
|
870
|
-
walletAddress: walletAddress ? WalletAddress(walletAddress) : null
|
|
871
|
-
};
|
|
665
|
+
if (first === void 0) {
|
|
666
|
+
throw new ValidationError(
|
|
667
|
+
`${model}.reasons: expected at least one when can_order is false`
|
|
668
|
+
);
|
|
872
669
|
}
|
|
873
|
-
};
|
|
874
|
-
var CreateParticipationParams = {
|
|
875
|
-
/** Maps participation creation params into API DTO payload. */
|
|
876
|
-
toDto: (params) => ({
|
|
877
|
-
offer_id: params.offerId,
|
|
878
|
-
offer_option_id: params.offerOptionId,
|
|
879
|
-
chain: params.chain,
|
|
880
|
-
wallet_address: params.walletAddress,
|
|
881
|
-
amount: params.amount,
|
|
882
|
-
asset_id: params.assetId,
|
|
883
|
-
approval_transaction_hash: params.approvalTransactionHash
|
|
884
|
-
})
|
|
885
|
-
};
|
|
886
|
-
|
|
887
|
-
// src/universal/api/frontline/providers/coin-list/token-sale.ts
|
|
888
|
-
async function fetchParticipations(api, offerId) {
|
|
889
|
-
return fetchAllPages(
|
|
890
|
-
(params) => fetchParticipationsPage(api, params),
|
|
891
|
-
{ offerId }
|
|
892
|
-
);
|
|
670
|
+
return { type: "blocked", reasons: [first, ...rest] };
|
|
893
671
|
}
|
|
894
|
-
|
|
895
|
-
|
|
672
|
+
function parseTransactionCore(dto, model) {
|
|
673
|
+
return {
|
|
674
|
+
tx: {
|
|
675
|
+
to: EvmContractAddress(dto.to),
|
|
676
|
+
data: HexEncodedTransactionData(dto.data)
|
|
677
|
+
},
|
|
678
|
+
expiresAt: dateOrNull(dto.expires_at, `${model}.expires_at`)
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// src/universal/api/frontline/providers/centrifuge/centrifuge.ts
|
|
683
|
+
async function getCentrifugeVaultStatus(api, params) {
|
|
684
|
+
const dto = await api.send({
|
|
896
685
|
method: "GET",
|
|
897
|
-
url: "/v1/
|
|
898
|
-
queryParams:
|
|
686
|
+
url: "/v1/centrifuge/vault/status",
|
|
687
|
+
queryParams: {
|
|
688
|
+
symbol: params.symbol,
|
|
689
|
+
chain: params.chain
|
|
690
|
+
},
|
|
899
691
|
attributes: Attributes.protected()
|
|
900
692
|
});
|
|
901
|
-
return
|
|
693
|
+
return CentrifugeVaultStatus.fromDto(dto);
|
|
902
694
|
}
|
|
903
|
-
async function
|
|
695
|
+
async function buildCentrifugeVaultBuy(api, params) {
|
|
904
696
|
const dto = await api.send({
|
|
905
|
-
method: "
|
|
906
|
-
url:
|
|
697
|
+
method: "POST",
|
|
698
|
+
url: "/v1/centrifuge/vault/invest",
|
|
699
|
+
body: {
|
|
700
|
+
...walletFields(params),
|
|
701
|
+
amount: params.amount.raw.toString()
|
|
702
|
+
},
|
|
907
703
|
attributes: Attributes.protected()
|
|
908
704
|
});
|
|
909
|
-
|
|
705
|
+
if (dto.spend_input_decimals !== params.amount.decimals) {
|
|
706
|
+
throw new ValidationError(
|
|
707
|
+
`spend_input_decimals: the request was priced in ${dto.spend_input_decimals} decimals but the deposit was sized in ${params.amount.decimals}`
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
return CentrifugeVaultBuyTransaction.fromDto(dto);
|
|
910
711
|
}
|
|
911
|
-
async function
|
|
712
|
+
async function createCentrifugeVaultClaim(api, params) {
|
|
912
713
|
const dto = await api.send({
|
|
913
714
|
method: "POST",
|
|
914
|
-
url: "/v1/
|
|
915
|
-
body:
|
|
715
|
+
url: "/v1/centrifuge/vault/claim",
|
|
716
|
+
body: walletFields(params),
|
|
916
717
|
attributes: Attributes.protected()
|
|
917
718
|
});
|
|
918
|
-
return
|
|
719
|
+
return CentrifugeVaultClaimTransaction.fromDto(dto);
|
|
919
720
|
}
|
|
920
|
-
|
|
921
|
-
|
|
721
|
+
async function createCentrifugeVaultClaimProceeds(api, params) {
|
|
722
|
+
const dto = await api.send({
|
|
723
|
+
method: "POST",
|
|
724
|
+
url: "/v1/centrifuge/vault/claim-proceeds",
|
|
725
|
+
body: walletFields(params),
|
|
726
|
+
attributes: Attributes.protected()
|
|
727
|
+
});
|
|
728
|
+
return CentrifugeVaultClaimProceedsTransaction.fromDto(dto);
|
|
729
|
+
}
|
|
730
|
+
function walletFields(params) {
|
|
731
|
+
return {
|
|
732
|
+
symbol: params.symbol,
|
|
733
|
+
chain: params.chain,
|
|
734
|
+
wallet_address: params.walletAddress
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// src/universal/core/checkout/centrifuge/blockchain/abi.ts
|
|
739
|
+
var CENTRIFUGE_PROXY_ABI = [
|
|
740
|
+
{
|
|
741
|
+
type: "function",
|
|
742
|
+
name: "pendingDepositRequest",
|
|
743
|
+
inputs: [{ name: "investor", type: "address" }],
|
|
744
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
745
|
+
stateMutability: "view"
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
type: "function",
|
|
749
|
+
name: "claimableDepositRequest",
|
|
750
|
+
inputs: [{ name: "investor", type: "address" }],
|
|
751
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
752
|
+
stateMutability: "view"
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
type: "function",
|
|
756
|
+
name: "pendingRedeemRequest",
|
|
757
|
+
inputs: [{ name: "investor", type: "address" }],
|
|
758
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
759
|
+
stateMutability: "view"
|
|
760
|
+
},
|
|
761
|
+
{
|
|
762
|
+
type: "function",
|
|
763
|
+
name: "claimableRedeemRequest",
|
|
764
|
+
inputs: [{ name: "investor", type: "address" }],
|
|
765
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
766
|
+
stateMutability: "view"
|
|
767
|
+
}
|
|
768
|
+
];
|
|
769
|
+
|
|
770
|
+
// src/universal/api/rpc/providers/centrifuge/position.ts
|
|
771
|
+
async function readCentrifugeDepositPosition(clients, params) {
|
|
772
|
+
const client = clients(params.vault.chain);
|
|
773
|
+
const proxy = proxyOf(params);
|
|
774
|
+
const wallet = params.walletAddress;
|
|
775
|
+
const [pendingDepositRequest, claimableDepositRequest] = await client.multicall({
|
|
776
|
+
allowFailure: false,
|
|
777
|
+
contracts: [
|
|
778
|
+
{ ...proxy, functionName: "pendingDepositRequest", args: [wallet] },
|
|
779
|
+
{ ...proxy, functionName: "claimableDepositRequest", args: [wallet] }
|
|
780
|
+
]
|
|
781
|
+
});
|
|
782
|
+
return CentrifugeDepositPosition.fromContract(
|
|
783
|
+
{ pendingDepositRequest, claimableDepositRequest },
|
|
784
|
+
contextOf(params)
|
|
785
|
+
);
|
|
786
|
+
}
|
|
787
|
+
async function readCentrifugeRedeemPosition(clients, params) {
|
|
788
|
+
const client = clients(params.vault.chain);
|
|
789
|
+
const proxy = proxyOf(params);
|
|
790
|
+
const wallet = params.walletAddress;
|
|
791
|
+
const [pendingRedeemRequest, claimableRedeemRequest] = await client.multicall(
|
|
792
|
+
{
|
|
793
|
+
allowFailure: false,
|
|
794
|
+
contracts: [
|
|
795
|
+
{ ...proxy, functionName: "pendingRedeemRequest", args: [wallet] },
|
|
796
|
+
{ ...proxy, functionName: "claimableRedeemRequest", args: [wallet] }
|
|
797
|
+
]
|
|
798
|
+
}
|
|
799
|
+
);
|
|
800
|
+
return CentrifugeRedeemPosition.fromContract(
|
|
801
|
+
{ pendingRedeemRequest, claimableRedeemRequest },
|
|
802
|
+
contextOf(params)
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
function proxyOf(params) {
|
|
806
|
+
return { address: params.vault.proxy, abi: CENTRIFUGE_PROXY_ABI };
|
|
807
|
+
}
|
|
808
|
+
function contextOf(params) {
|
|
809
|
+
return {
|
|
810
|
+
chain: params.vault.chain,
|
|
811
|
+
proxy: params.vault.proxy,
|
|
812
|
+
walletAddress: params.walletAddress,
|
|
813
|
+
assetDecimals: params.vault.funding.decimals,
|
|
814
|
+
shareDecimals: params.vault.share.decimals
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// src/universal/core/shared/observability/log-cause.ts
|
|
922
819
|
import {
|
|
923
820
|
BaseError,
|
|
924
821
|
ContractFunctionExecutionError,
|
|
@@ -1101,34 +998,48 @@ var noopInternalLogger = {
|
|
|
1101
998
|
wrap: (_op, _params, run) => run()
|
|
1102
999
|
};
|
|
1103
1000
|
|
|
1104
|
-
// src/universal/core/checkout/
|
|
1105
|
-
var
|
|
1001
|
+
// src/universal/core/checkout/centrifuge/centrifuge-namespace.ts
|
|
1002
|
+
var CentrifugeNamespaceImpl = class {
|
|
1106
1003
|
constructor(ctx) {
|
|
1107
1004
|
this.ctx = ctx;
|
|
1108
|
-
this.log = internalLogger(ctx.logger, "
|
|
1005
|
+
this.log = internalLogger(ctx.logger, "CENTRIFUGE");
|
|
1109
1006
|
}
|
|
1110
|
-
async
|
|
1111
|
-
return this.log.wrap("
|
|
1007
|
+
async getVaultStatus(params) {
|
|
1008
|
+
return this.log.wrap("getVaultStatus", params, async () => {
|
|
1112
1009
|
await this.ctx.ensureUserAuthenticated();
|
|
1113
|
-
return
|
|
1010
|
+
return getCentrifugeVaultStatus(this.ctx.api, params);
|
|
1114
1011
|
});
|
|
1115
1012
|
}
|
|
1116
|
-
async
|
|
1117
|
-
return this.log.wrap(
|
|
1013
|
+
async readDepositPosition(params) {
|
|
1014
|
+
return this.log.wrap(
|
|
1015
|
+
"readDepositPosition",
|
|
1016
|
+
params,
|
|
1017
|
+
() => readCentrifugeDepositPosition(this.ctx.rpc, params)
|
|
1018
|
+
);
|
|
1019
|
+
}
|
|
1020
|
+
async readRedeemPosition(params) {
|
|
1021
|
+
return this.log.wrap(
|
|
1022
|
+
"readRedeemPosition",
|
|
1023
|
+
params,
|
|
1024
|
+
() => readCentrifugeRedeemPosition(this.ctx.rpc, params)
|
|
1025
|
+
);
|
|
1026
|
+
}
|
|
1027
|
+
async createClaim(params) {
|
|
1028
|
+
return this.log.wrap("createClaim", params, async () => {
|
|
1118
1029
|
await this.ctx.ensureUserAuthenticated();
|
|
1119
|
-
return
|
|
1030
|
+
return createCentrifugeVaultClaim(this.ctx.api, params);
|
|
1120
1031
|
});
|
|
1121
1032
|
}
|
|
1122
|
-
async
|
|
1123
|
-
return this.log.wrap("
|
|
1033
|
+
async createClaimProceeds(params) {
|
|
1034
|
+
return this.log.wrap("createClaimProceeds", params, async () => {
|
|
1124
1035
|
await this.ctx.ensureUserAuthenticated();
|
|
1125
|
-
return
|
|
1036
|
+
return createCentrifugeVaultClaimProceeds(this.ctx.api, params);
|
|
1126
1037
|
});
|
|
1127
1038
|
}
|
|
1128
|
-
async
|
|
1129
|
-
return this.log.wrap("
|
|
1039
|
+
async buildBuyTransaction(params) {
|
|
1040
|
+
return this.log.wrap("buildBuyTransaction", params, async () => {
|
|
1130
1041
|
await this.ctx.ensureUserAuthenticated();
|
|
1131
|
-
return
|
|
1042
|
+
return buildCentrifugeVaultBuy(this.ctx.api, params);
|
|
1132
1043
|
});
|
|
1133
1044
|
}
|
|
1134
1045
|
};
|
|
@@ -1249,6 +1160,435 @@ function formattedUsdPrice(amount, locale) {
|
|
|
1249
1160
|
);
|
|
1250
1161
|
}
|
|
1251
1162
|
|
|
1163
|
+
// src/universal/types/asset.ts
|
|
1164
|
+
var AssetId = (value) => value;
|
|
1165
|
+
var AssetCode = (value) => value;
|
|
1166
|
+
var Asset = {
|
|
1167
|
+
fromDto: (dto) => ({
|
|
1168
|
+
id: AssetId(dto.id),
|
|
1169
|
+
code: AssetCode(dto.code),
|
|
1170
|
+
name: dto.name,
|
|
1171
|
+
fractionalDigits: dto.fractional_digits
|
|
1172
|
+
})
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1175
|
+
// src/universal/types/offer.ts
|
|
1176
|
+
var OfferId = (value) => value;
|
|
1177
|
+
var OfferSlug = (value) => value;
|
|
1178
|
+
var OFFER_TYPES = {
|
|
1179
|
+
"coinlist::token_sale": true,
|
|
1180
|
+
"superstate::swap": true,
|
|
1181
|
+
"ondo::swap": true,
|
|
1182
|
+
"centrifuge::vault": true
|
|
1183
|
+
};
|
|
1184
|
+
var isOfferType = (value) => Object.keys(OFFER_TYPES).includes(value);
|
|
1185
|
+
var OfferEditorial = {
|
|
1186
|
+
/**
|
|
1187
|
+
* `model` prefixes the field in the error (`'Offer'`, `'OfferDetail'`), so
|
|
1188
|
+
* the same three checks name the payload that failed them.
|
|
1189
|
+
*/
|
|
1190
|
+
fromDto: (dto, model) => ({
|
|
1191
|
+
tagline: requiredString(dto.tagline, `${model}.tagline`),
|
|
1192
|
+
bannerUrl: requiredString(dto.banner_url, `${model}.banner_url`),
|
|
1193
|
+
startsAt: requiredDate(dto.starts_at, `${model}.starts_at`)
|
|
1194
|
+
})
|
|
1195
|
+
};
|
|
1196
|
+
var Offer = {
|
|
1197
|
+
fromDto: (dto) => {
|
|
1198
|
+
const tokens = requiredArray(dto.tokens, "Offer.tokens");
|
|
1199
|
+
const base2 = {
|
|
1200
|
+
id: OfferId(dto.id),
|
|
1201
|
+
slug: OfferSlug(dto.slug),
|
|
1202
|
+
endsAt: dto.ends_at ? new Date(dto.ends_at) : null,
|
|
1203
|
+
tokens: OfferToken.listFromDto(tokens)
|
|
1204
|
+
};
|
|
1205
|
+
switch (dto.type) {
|
|
1206
|
+
case "coinlist::token_sale":
|
|
1207
|
+
return {
|
|
1208
|
+
...base2,
|
|
1209
|
+
...OfferEditorial.fromDto(dto, "Offer"),
|
|
1210
|
+
type: dto.type,
|
|
1211
|
+
logoUrl: requiredString(dto.logo_url, "Offer.logo_url")
|
|
1212
|
+
};
|
|
1213
|
+
case "superstate::swap":
|
|
1214
|
+
return {
|
|
1215
|
+
...base2,
|
|
1216
|
+
...OfferEditorial.fromDto(dto, "Offer"),
|
|
1217
|
+
type: dto.type,
|
|
1218
|
+
logoUrl: notBlankStringOrNull(dto.logo_url)
|
|
1219
|
+
};
|
|
1220
|
+
// `tagline`, `banner_url` and `starts_at` arrive as `null` and are left
|
|
1221
|
+
// on the wire: copying them would hand every consumer a `startsAt` that
|
|
1222
|
+
// is 1970 for one variant and a date for the others.
|
|
1223
|
+
case "ondo::swap":
|
|
1224
|
+
case "centrifuge::vault":
|
|
1225
|
+
return {
|
|
1226
|
+
...base2,
|
|
1227
|
+
type: dto.type,
|
|
1228
|
+
logoUrl: notBlankStringOrNull(dto.logo_url)
|
|
1229
|
+
};
|
|
1230
|
+
default:
|
|
1231
|
+
return unknownTypeError(dto, "Offer");
|
|
1232
|
+
}
|
|
1233
|
+
},
|
|
1234
|
+
/**
|
|
1235
|
+
* Maps a page of offers, dropping every offer whose `type` this SDK does not
|
|
1236
|
+
* name. The same reasoning as {@link OfferToken.listFromDto}: a plain `.map`
|
|
1237
|
+
* would throw out of `fromDto` and, through `PaginatedResponse.fromDto`,
|
|
1238
|
+
* reject the whole page, so one offer of an unknown type would blank the
|
|
1239
|
+
* grid for every offer beside it. A single offer fetched by id still
|
|
1240
|
+
* throws, because there is nothing beside it to keep.
|
|
1241
|
+
*/
|
|
1242
|
+
listFromDto: (dtos) => dtos.filter((dto) => isOfferType(dto.type)).map(Offer.fromDto)
|
|
1243
|
+
};
|
|
1244
|
+
var OfferToken = {
|
|
1245
|
+
fromDto: (dto) => ({
|
|
1246
|
+
role: dto.role,
|
|
1247
|
+
chain: Chain(dto.chain),
|
|
1248
|
+
address: EvmContractAddress(dto.address)
|
|
1249
|
+
}),
|
|
1250
|
+
/**
|
|
1251
|
+
* Maps an offer's token list, dropping every token on a chain this SDK does
|
|
1252
|
+
* not name. Frontline's chain registry runs ahead of {@link Chain}, and a
|
|
1253
|
+
* plain `.map` would throw out of `Offer.fromDto` and, through
|
|
1254
|
+
* `PaginatedResponse.fromDto`, reject the whole offers page - which is how
|
|
1255
|
+
* one Base token blanked production's offers list. Dropping costs that
|
|
1256
|
+
* token's metadata alone: `coinlist.tokens.get` takes an `EthereumChain`,
|
|
1257
|
+
* so nobody could have looked it up anyway.
|
|
1258
|
+
*
|
|
1259
|
+
* Same shape as `TokenMetadata.fromRegistryDto`.
|
|
1260
|
+
*/
|
|
1261
|
+
listFromDto: (dtos) => dtos.filter((dto) => isChain(dto.chain)).map(OfferToken.fromDto)
|
|
1262
|
+
};
|
|
1263
|
+
|
|
1264
|
+
// src/universal/types/trading.ts
|
|
1265
|
+
var Ticker = (value) => value;
|
|
1266
|
+
var Isin = (value) => value;
|
|
1267
|
+
|
|
1268
|
+
// src/universal/types/offer-detail.ts
|
|
1269
|
+
var AsyncOfferDetail = {
|
|
1270
|
+
/**
|
|
1271
|
+
* Narrows an offer fetched generically, e.g. on an offer page, to one with
|
|
1272
|
+
* something to claim.
|
|
1273
|
+
*
|
|
1274
|
+
* An exhaustive `switch` rather than a list of async types, so a new offer
|
|
1275
|
+
* type is a compile error here until someone decides whether it settles
|
|
1276
|
+
* later.
|
|
1277
|
+
*/
|
|
1278
|
+
is: (offer) => {
|
|
1279
|
+
switch (offer.type) {
|
|
1280
|
+
case "centrifuge::vault":
|
|
1281
|
+
return true;
|
|
1282
|
+
case "ondo::swap":
|
|
1283
|
+
case "superstate::swap":
|
|
1284
|
+
case "coinlist::token_sale":
|
|
1285
|
+
return false;
|
|
1286
|
+
default: {
|
|
1287
|
+
const exhaustive = offer;
|
|
1288
|
+
return exhaustive;
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
};
|
|
1293
|
+
var OfferOptionId = (value) => value;
|
|
1294
|
+
var OfferOptionSlug = (value) => value;
|
|
1295
|
+
var OfferSwapContract = {
|
|
1296
|
+
fromDto: (dto) => ({
|
|
1297
|
+
chain: Chain(dto.chain),
|
|
1298
|
+
address: EvmContractAddress(dto.address)
|
|
1299
|
+
})
|
|
1300
|
+
};
|
|
1301
|
+
var OfferVaultContract = {
|
|
1302
|
+
fromDto: (dto) => ({
|
|
1303
|
+
chain: Chain(dto.chain),
|
|
1304
|
+
address: EvmContractAddress(dto.address)
|
|
1305
|
+
}),
|
|
1306
|
+
/**
|
|
1307
|
+
* Drops every proxy on a chain this SDK does not name, as
|
|
1308
|
+
* `OfferToken.listFromDto` does: frontline publishes the full offer-token
|
|
1309
|
+
* chain list, which runs ahead of {@link Chain}, and one unmodelled chain
|
|
1310
|
+
* should not throw away the proxies the SDK can use.
|
|
1311
|
+
*/
|
|
1312
|
+
listFromDto: (dtos) => dtos.filter((dto) => isChain(dto.chain)).map(OfferVaultContract.fromDto)
|
|
1313
|
+
};
|
|
1314
|
+
var OfferDetail = {
|
|
1315
|
+
fromDto: (dto) => {
|
|
1316
|
+
const fundingAssets = requiredArray(
|
|
1317
|
+
dto.funding_assets,
|
|
1318
|
+
"OfferDetail.funding_assets"
|
|
1319
|
+
);
|
|
1320
|
+
const options = requiredArray(dto.options, "OfferDetail.options");
|
|
1321
|
+
const terms = requiredArray(dto.terms, "OfferDetail.terms");
|
|
1322
|
+
const links = requiredArray(dto.links, "OfferDetail.links");
|
|
1323
|
+
const faqs = requiredArray(dto.faqs, "OfferDetail.faqs");
|
|
1324
|
+
const milestones = requiredArray(dto.milestones, "OfferDetail.milestones");
|
|
1325
|
+
const tokens = requiredArray(dto.tokens, "OfferDetail.tokens");
|
|
1326
|
+
const isin = notBlankStringOrNull(dto.isin);
|
|
1327
|
+
const ticker = notBlankStringOrNull(dto.ticker);
|
|
1328
|
+
const base2 = {
|
|
1329
|
+
id: OfferId(dto.id),
|
|
1330
|
+
slug: OfferSlug(dto.slug),
|
|
1331
|
+
name: dto.name,
|
|
1332
|
+
asset: Asset.fromDto(dto.asset),
|
|
1333
|
+
fundingAssets: fundingAssets.map(Asset.fromDto),
|
|
1334
|
+
tokens: OfferToken.listFromDto(tokens),
|
|
1335
|
+
about: notBlankStringOrNull(dto.about),
|
|
1336
|
+
category: dto.category,
|
|
1337
|
+
issuer: notBlankStringOrNull(dto.issuer),
|
|
1338
|
+
isin: isin === null ? null : Isin(isin),
|
|
1339
|
+
ticker: ticker === null ? null : Ticker(ticker),
|
|
1340
|
+
instrumentType: notBlankStringOrNull(dto.instrument_type),
|
|
1341
|
+
listingVenue: notBlankStringOrNull(dto.listing_venue),
|
|
1342
|
+
endsAt: dto.ends_at ? new Date(dto.ends_at) : null,
|
|
1343
|
+
faqs: faqs.map(FaqItem.fromDto),
|
|
1344
|
+
links: links.map(Link.fromDto),
|
|
1345
|
+
milestones: milestones.map(Milestone.fromDto),
|
|
1346
|
+
options: options.map(OfferOption.fromDto),
|
|
1347
|
+
terms: terms.map(TermItem.fromDto)
|
|
1348
|
+
};
|
|
1349
|
+
switch (dto.type) {
|
|
1350
|
+
case "coinlist::token_sale":
|
|
1351
|
+
return {
|
|
1352
|
+
...base2,
|
|
1353
|
+
...OfferEditorial.fromDto(dto, "OfferDetail"),
|
|
1354
|
+
type: dto.type,
|
|
1355
|
+
logoUrl: requiredString(dto.logo_url, "OfferDetail.logo_url")
|
|
1356
|
+
};
|
|
1357
|
+
case "superstate::swap":
|
|
1358
|
+
return {
|
|
1359
|
+
...base2,
|
|
1360
|
+
...OfferEditorial.fromDto(dto, "OfferDetail"),
|
|
1361
|
+
type: dto.type,
|
|
1362
|
+
logoUrl: notBlankStringOrNull(dto.logo_url)
|
|
1363
|
+
};
|
|
1364
|
+
// `tagline`, `banner_url` and `starts_at` arrive as `null` and are left
|
|
1365
|
+
// on the wire, as in `Offer.fromDto`.
|
|
1366
|
+
case "ondo::swap":
|
|
1367
|
+
return {
|
|
1368
|
+
...base2,
|
|
1369
|
+
type: dto.type,
|
|
1370
|
+
logoUrl: notBlankStringOrNull(dto.logo_url),
|
|
1371
|
+
swapContracts: requiredArray(
|
|
1372
|
+
dto.swap_contracts,
|
|
1373
|
+
"OfferDetail.swap_contracts"
|
|
1374
|
+
).map(OfferSwapContract.fromDto)
|
|
1375
|
+
};
|
|
1376
|
+
// No editorial, as for Ondo. `[]` is fine and a missing key is not, for
|
|
1377
|
+
// the same reason as `swap_contracts`: this is the spender a user
|
|
1378
|
+
// approves.
|
|
1379
|
+
case "centrifuge::vault":
|
|
1380
|
+
return {
|
|
1381
|
+
...base2,
|
|
1382
|
+
type: dto.type,
|
|
1383
|
+
logoUrl: notBlankStringOrNull(dto.logo_url),
|
|
1384
|
+
vaultContracts: OfferVaultContract.listFromDto(
|
|
1385
|
+
requiredArray(dto.vault_contracts, "OfferDetail.vault_contracts")
|
|
1386
|
+
)
|
|
1387
|
+
};
|
|
1388
|
+
default:
|
|
1389
|
+
return unknownTypeError(dto, "OfferDetail");
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
var OfferOption = {
|
|
1394
|
+
fromDto: (dto) => ({
|
|
1395
|
+
id: OfferOptionId(dto.id),
|
|
1396
|
+
slug: OfferOptionSlug(dto.slug),
|
|
1397
|
+
bidIncrement: dto.bid_increment,
|
|
1398
|
+
floorPriceUsd: dto.floor_price_usd,
|
|
1399
|
+
minimumPurchaseUsd: dto.minimum_purchase_usd,
|
|
1400
|
+
priceUsd: dto.price_usd,
|
|
1401
|
+
saleAgreementUrl: notBlankStringOrNull(dto.sale_agreement_url),
|
|
1402
|
+
totalTokenSupply: dto.total_token_supply
|
|
1403
|
+
})
|
|
1404
|
+
};
|
|
1405
|
+
var FaqItem = {
|
|
1406
|
+
fromDto: (dto) => ({
|
|
1407
|
+
question: notBlankStringOrNull(dto.question),
|
|
1408
|
+
answer: notBlankStringOrNull(dto.answer)
|
|
1409
|
+
})
|
|
1410
|
+
};
|
|
1411
|
+
var Link = {
|
|
1412
|
+
fromDto: (dto) => ({
|
|
1413
|
+
label: notBlankStringOrNull(dto.label),
|
|
1414
|
+
url: notBlankStringOrNull(dto.url)
|
|
1415
|
+
})
|
|
1416
|
+
};
|
|
1417
|
+
var TermItem = {
|
|
1418
|
+
fromDto: (dto) => ({
|
|
1419
|
+
key: notBlankStringOrNull(dto.key),
|
|
1420
|
+
value: notBlankStringOrNull(dto.value)
|
|
1421
|
+
})
|
|
1422
|
+
};
|
|
1423
|
+
var Milestone = {
|
|
1424
|
+
fromDto: (dto) => ({
|
|
1425
|
+
name: notBlankStringOrNull(dto.name),
|
|
1426
|
+
schedule: notBlankStringOrNull(dto.schedule),
|
|
1427
|
+
status: dto.status
|
|
1428
|
+
})
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
// src/universal/types/pagination.ts
|
|
1432
|
+
var Cursor = (value) => value;
|
|
1433
|
+
var PaginatedResponse = {
|
|
1434
|
+
fromDto: (dto, itemMapper) => PaginatedResponse.fromDtoPage(dto, (items) => items.map(itemMapper)),
|
|
1435
|
+
/**
|
|
1436
|
+
* For a mapper that decides the page as a whole - one that drops items it
|
|
1437
|
+
* cannot map, such as `Offer.listFromDto` - rather than item by item. The
|
|
1438
|
+
* cursors are the wire's either way: dropping an item changes what the
|
|
1439
|
+
* page holds, not where the next page starts.
|
|
1440
|
+
*/
|
|
1441
|
+
fromDtoPage: (dto, pageMapper) => ({
|
|
1442
|
+
data: pageMapper(dto.data),
|
|
1443
|
+
startingAfter: dto.starting_after ? Cursor(dto.starting_after) : null,
|
|
1444
|
+
startingBefore: dto.starting_before ? Cursor(dto.starting_before) : null
|
|
1445
|
+
})
|
|
1446
|
+
};
|
|
1447
|
+
var PaginationParams = {
|
|
1448
|
+
toQueryParams: (params) => {
|
|
1449
|
+
const queryParams = {};
|
|
1450
|
+
if (params.after) {
|
|
1451
|
+
queryParams.starting_after = params.after;
|
|
1452
|
+
}
|
|
1453
|
+
if (params.before) {
|
|
1454
|
+
queryParams.starting_before = params.before;
|
|
1455
|
+
}
|
|
1456
|
+
if (params.limit) {
|
|
1457
|
+
queryParams.limit = params.limit;
|
|
1458
|
+
}
|
|
1459
|
+
return queryParams;
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1463
|
+
// src/universal/types/providers/coin-list/token-sale.ts
|
|
1464
|
+
var ParticipationId = (value) => value;
|
|
1465
|
+
var Blockchain = (value) => value;
|
|
1466
|
+
var WalletAddress = (value) => value;
|
|
1467
|
+
var ParticipationsPaginationParams = {
|
|
1468
|
+
toQueryParams: (params) => {
|
|
1469
|
+
const queryParams = PaginationParams.toQueryParams(params);
|
|
1470
|
+
if (params.offerId) {
|
|
1471
|
+
queryParams["filters[0][field]"] = "offer_id";
|
|
1472
|
+
queryParams["filters[0][op]"] = "==";
|
|
1473
|
+
queryParams["filters[0][value]"] = params.offerId;
|
|
1474
|
+
}
|
|
1475
|
+
return queryParams;
|
|
1476
|
+
}
|
|
1477
|
+
};
|
|
1478
|
+
var Participation = {
|
|
1479
|
+
/** Maps API DTO shape into the SDK participation domain model. */
|
|
1480
|
+
fromDto: (dto) => {
|
|
1481
|
+
const walletAddress = notBlankStringOrNull(dto.wallet_address);
|
|
1482
|
+
return {
|
|
1483
|
+
id: ParticipationId(dto.id),
|
|
1484
|
+
offerId: OfferId(dto.offer_id),
|
|
1485
|
+
offerOptionId: OfferOptionId(dto.offer_option_id),
|
|
1486
|
+
status: dto.status,
|
|
1487
|
+
amount: dto.amount,
|
|
1488
|
+
displayAmount: dto.amount_string,
|
|
1489
|
+
asset: Asset.fromDto(dto.asset),
|
|
1490
|
+
chain: Blockchain(dto.chain),
|
|
1491
|
+
insertedAt: dto.inserted_at ? new Date(dto.inserted_at) : null,
|
|
1492
|
+
updatedAt: dto.updated_at ? new Date(dto.updated_at) : null,
|
|
1493
|
+
walletAddress: walletAddress ? WalletAddress(walletAddress) : null
|
|
1494
|
+
};
|
|
1495
|
+
}
|
|
1496
|
+
};
|
|
1497
|
+
var CreateParticipationParams = {
|
|
1498
|
+
/** Maps participation creation params into API DTO payload. */
|
|
1499
|
+
toDto: (params) => ({
|
|
1500
|
+
offer_id: params.offerId,
|
|
1501
|
+
offer_option_id: params.offerOptionId,
|
|
1502
|
+
chain: params.chain,
|
|
1503
|
+
wallet_address: params.walletAddress,
|
|
1504
|
+
amount: params.amount,
|
|
1505
|
+
asset_id: params.assetId,
|
|
1506
|
+
approval_transaction_hash: params.approvalTransactionHash
|
|
1507
|
+
})
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
// src/universal/api/pagination.ts
|
|
1511
|
+
async function fetchAllPages(fetchPage, baseParams) {
|
|
1512
|
+
const items = [];
|
|
1513
|
+
let cursor = null;
|
|
1514
|
+
do {
|
|
1515
|
+
const params = {
|
|
1516
|
+
...baseParams ?? {},
|
|
1517
|
+
after: cursor ?? void 0
|
|
1518
|
+
};
|
|
1519
|
+
const page = await fetchPage(params);
|
|
1520
|
+
items.push(...page.data);
|
|
1521
|
+
cursor = page.startingAfter;
|
|
1522
|
+
} while (cursor);
|
|
1523
|
+
return items;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
// src/universal/api/frontline/providers/coin-list/token-sale.ts
|
|
1527
|
+
async function fetchParticipations(api, offerId) {
|
|
1528
|
+
return fetchAllPages(
|
|
1529
|
+
(params) => fetchParticipationsPage(api, params),
|
|
1530
|
+
{ offerId }
|
|
1531
|
+
);
|
|
1532
|
+
}
|
|
1533
|
+
async function fetchParticipationsPage(api, params) {
|
|
1534
|
+
const pageDto = await api.send({
|
|
1535
|
+
method: "GET",
|
|
1536
|
+
url: "/v1/participations",
|
|
1537
|
+
queryParams: ParticipationsPaginationParams.toQueryParams(params),
|
|
1538
|
+
attributes: Attributes.protected()
|
|
1539
|
+
});
|
|
1540
|
+
return PaginatedResponse.fromDto(pageDto, Participation.fromDto);
|
|
1541
|
+
}
|
|
1542
|
+
async function fetchParticipation(api, id) {
|
|
1543
|
+
const dto = await api.send({
|
|
1544
|
+
method: "GET",
|
|
1545
|
+
url: `/v1/participations/${id}`,
|
|
1546
|
+
attributes: Attributes.protected()
|
|
1547
|
+
});
|
|
1548
|
+
return Participation.fromDto(dto);
|
|
1549
|
+
}
|
|
1550
|
+
async function createParticipation(api, params) {
|
|
1551
|
+
const dto = await api.send({
|
|
1552
|
+
method: "POST",
|
|
1553
|
+
url: "/v1/participations",
|
|
1554
|
+
body: CreateParticipationParams.toDto(params),
|
|
1555
|
+
attributes: Attributes.protected()
|
|
1556
|
+
});
|
|
1557
|
+
return Participation.fromDto(dto);
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
// src/universal/core/checkout/coin-list/token-sale-namespace.ts
|
|
1561
|
+
var CoinListTokenSaleNamespaceImpl = class {
|
|
1562
|
+
constructor(ctx) {
|
|
1563
|
+
this.ctx = ctx;
|
|
1564
|
+
this.log = internalLogger(ctx.logger, "TOKEN_SALE");
|
|
1565
|
+
}
|
|
1566
|
+
async list(offerId) {
|
|
1567
|
+
return this.log.wrap("list", offerId, async () => {
|
|
1568
|
+
await this.ctx.ensureUserAuthenticated();
|
|
1569
|
+
return fetchParticipations(this.ctx.api, offerId);
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
async listPage(params) {
|
|
1573
|
+
return this.log.wrap("listPage", params, async () => {
|
|
1574
|
+
await this.ctx.ensureUserAuthenticated();
|
|
1575
|
+
return fetchParticipationsPage(this.ctx.api, params);
|
|
1576
|
+
});
|
|
1577
|
+
}
|
|
1578
|
+
async get(id) {
|
|
1579
|
+
return this.log.wrap("get", id, async () => {
|
|
1580
|
+
await this.ctx.ensureUserAuthenticated();
|
|
1581
|
+
return fetchParticipation(this.ctx.api, id);
|
|
1582
|
+
});
|
|
1583
|
+
}
|
|
1584
|
+
async createParticipation(params) {
|
|
1585
|
+
return this.log.wrap("createParticipation", params, async () => {
|
|
1586
|
+
await this.ctx.ensureUserAuthenticated();
|
|
1587
|
+
return createParticipation(this.ctx.api, params);
|
|
1588
|
+
});
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
|
|
1252
1592
|
// src/universal/core/shared/blockchain/chain.ts
|
|
1253
1593
|
import { base, baseSepolia, mainnet, sepolia } from "viem/chains";
|
|
1254
1594
|
var VIEM_CHAINS = {
|
|
@@ -1307,66 +1647,6 @@ function explorerBaseUrl(chain) {
|
|
|
1307
1647
|
}
|
|
1308
1648
|
}
|
|
1309
1649
|
|
|
1310
|
-
// src/universal/core/shared/blockchain/math.ts
|
|
1311
|
-
import { parseUnits } from "viem";
|
|
1312
|
-
function blockchainAmountFromRawOrThrow({
|
|
1313
|
-
label,
|
|
1314
|
-
raw,
|
|
1315
|
-
decimals
|
|
1316
|
-
}) {
|
|
1317
|
-
const trimmed = raw.trim();
|
|
1318
|
-
if (trimmed === "") {
|
|
1319
|
-
throw new ValidationError(`${label}: not a uint256 integer ("${raw}")`);
|
|
1320
|
-
}
|
|
1321
|
-
let value;
|
|
1322
|
-
try {
|
|
1323
|
-
value = BigInt(trimmed);
|
|
1324
|
-
} catch {
|
|
1325
|
-
throw new ValidationError(`${label}: not a uint256 integer ("${raw}")`);
|
|
1326
|
-
}
|
|
1327
|
-
try {
|
|
1328
|
-
return BlockchainAmount({ raw: assertUint256(value), decimals });
|
|
1329
|
-
} catch {
|
|
1330
|
-
throw new ValidationError(`${label}: out of uint256 bounds (${value})`);
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
function parseBlockchainAmount(amount, decimals) {
|
|
1334
|
-
const trimmed = amount.trim();
|
|
1335
|
-
if (trimmed === "") return { valid: false, reason: { type: "empty" } };
|
|
1336
|
-
if (trimmed.startsWith("-")) {
|
|
1337
|
-
return { valid: false, reason: { type: "negative" } };
|
|
1338
|
-
}
|
|
1339
|
-
if (/[eE]/.test(trimmed)) {
|
|
1340
|
-
return { valid: false, reason: { type: "invalid-format" } };
|
|
1341
|
-
}
|
|
1342
|
-
if (trimmed === ".") {
|
|
1343
|
-
return { valid: false, reason: { type: "invalid-format" } };
|
|
1344
|
-
}
|
|
1345
|
-
const normalised = trimmed.replace(/^\./, "0.").replace(/\.$/, "");
|
|
1346
|
-
if (!/^\d+(\.\d+)?$/.test(normalised)) {
|
|
1347
|
-
return { valid: false, reason: { type: "invalid-format" } };
|
|
1348
|
-
}
|
|
1349
|
-
const [, fraction = ""] = normalised.split(".");
|
|
1350
|
-
if (fraction.length > decimals) {
|
|
1351
|
-
return {
|
|
1352
|
-
valid: false,
|
|
1353
|
-
reason: { type: "too-many-decimals", maxDecimals: decimals }
|
|
1354
|
-
};
|
|
1355
|
-
}
|
|
1356
|
-
try {
|
|
1357
|
-
const raw = parseUnits(normalised, decimals);
|
|
1358
|
-
if (raw > MAX_UINT_256) {
|
|
1359
|
-
return { valid: false, reason: { type: "overflow" } };
|
|
1360
|
-
}
|
|
1361
|
-
return {
|
|
1362
|
-
valid: true,
|
|
1363
|
-
amount: BlockchainAmount({ raw, decimals })
|
|
1364
|
-
};
|
|
1365
|
-
} catch {
|
|
1366
|
-
return { valid: false, reason: { type: "invalid-format" } };
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
1650
|
// src/universal/types/providers/ondo/ondo.ts
|
|
1371
1651
|
var OndoTradingStatus = {
|
|
1372
1652
|
fromDto: (dto) => {
|
|
@@ -1382,7 +1662,6 @@ var OndoTradingStatus = {
|
|
|
1382
1662
|
};
|
|
1383
1663
|
}
|
|
1384
1664
|
};
|
|
1385
|
-
var decimalOrNull = (value) => value === null ? null : DecimalString(value);
|
|
1386
1665
|
var OndoQuote = {
|
|
1387
1666
|
fromDto: (dto) => {
|
|
1388
1667
|
const assetDecimals = AssetDecimals(dto.asset_decimals);
|
|
@@ -1660,6 +1939,101 @@ var OndoNamespaceImpl = class {
|
|
|
1660
1939
|
}
|
|
1661
1940
|
};
|
|
1662
1941
|
|
|
1942
|
+
// src/universal/types/providers/superstate/swap.ts
|
|
1943
|
+
var SwapPreview = {
|
|
1944
|
+
/** Maps the contract's `Preview { input, fee, output }` struct. */
|
|
1945
|
+
fromContract: (preview) => ({
|
|
1946
|
+
inputAmount: parseUint256(preview.input, "SwapPreview.input"),
|
|
1947
|
+
fee: parseUint256(preview.fee, "SwapPreview.fee"),
|
|
1948
|
+
outputAmount: parseUint256(preview.output, "SwapPreview.output")
|
|
1949
|
+
})
|
|
1950
|
+
};
|
|
1951
|
+
var PauseFlags = (value) => value;
|
|
1952
|
+
var SwapStatus = {
|
|
1953
|
+
/**
|
|
1954
|
+
* Maps the contract's `Status { uint32 flags; State state }` struct, where
|
|
1955
|
+
* `State` is `0 = Active | 1 = Paused | 2 = Stopped`.
|
|
1956
|
+
*
|
|
1957
|
+
* `flags` is carried onto the `paused` arm only. On the other two the
|
|
1958
|
+
* contract sets it to a self-identifying marker rather than to information -
|
|
1959
|
+
* so repeating it would invite a caller to read meaning into a constant.
|
|
1960
|
+
*
|
|
1961
|
+
* @throws ValidationError on a `state` outside the enum. A contract that has
|
|
1962
|
+
* grown a fourth state is one the SDK does not model, and guessing `active`
|
|
1963
|
+
* would let a halted swap read as a live one.
|
|
1964
|
+
*/
|
|
1965
|
+
fromContract: (status) => {
|
|
1966
|
+
switch (status.state) {
|
|
1967
|
+
case 0:
|
|
1968
|
+
return { state: "active" };
|
|
1969
|
+
case 1:
|
|
1970
|
+
return { state: "paused", pausedLevels: PauseFlags(status.flags) };
|
|
1971
|
+
case 2:
|
|
1972
|
+
return { state: "stopped" };
|
|
1973
|
+
default:
|
|
1974
|
+
throw new ValidationError(
|
|
1975
|
+
`SwapStatus.state: unknown contract state (${status.state})`
|
|
1976
|
+
);
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
};
|
|
1980
|
+
var AllowWalletResponse = {
|
|
1981
|
+
fromDto: (dto) => {
|
|
1982
|
+
switch (dto.action) {
|
|
1983
|
+
case "broadcast_transaction":
|
|
1984
|
+
return {
|
|
1985
|
+
action: "broadcast_transaction",
|
|
1986
|
+
to: EvmContractAddress(dto.to),
|
|
1987
|
+
data: HexEncodedTransactionData(dto.data)
|
|
1988
|
+
};
|
|
1989
|
+
case "none":
|
|
1990
|
+
return {
|
|
1991
|
+
action: "none",
|
|
1992
|
+
alreadyAllowed: dto.already_allowed
|
|
1993
|
+
};
|
|
1994
|
+
default: {
|
|
1995
|
+
const _exhaustive = dto;
|
|
1996
|
+
return _exhaustive;
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
};
|
|
2001
|
+
|
|
2002
|
+
// src/universal/core/checkout/superstate/blockchain/quote.ts
|
|
2003
|
+
var SwapQuote = {
|
|
2004
|
+
/**
|
|
2005
|
+
* Assembles a {@link SwapQuote} from a raw contract {@link SwapPreview}. The
|
|
2006
|
+
* input and fee are denominated in the input token; the output in the output
|
|
2007
|
+
* token.
|
|
2008
|
+
*/
|
|
2009
|
+
fromPreview: (preview, inputDecimals, outputDecimals) => ({
|
|
2010
|
+
inputTokenAmount: BlockchainAmount({
|
|
2011
|
+
raw: preview.inputAmount,
|
|
2012
|
+
decimals: inputDecimals
|
|
2013
|
+
}),
|
|
2014
|
+
fee: BlockchainAmount({ raw: preview.fee, decimals: inputDecimals }),
|
|
2015
|
+
outputTokenAmount: BlockchainAmount({
|
|
2016
|
+
raw: preview.outputAmount,
|
|
2017
|
+
decimals: outputDecimals
|
|
2018
|
+
})
|
|
2019
|
+
})
|
|
2020
|
+
};
|
|
2021
|
+
|
|
2022
|
+
// src/universal/api/frontline/providers/superstate/swap.ts
|
|
2023
|
+
async function allowWallet(api, params) {
|
|
2024
|
+
const dto = await api.send({
|
|
2025
|
+
method: "POST",
|
|
2026
|
+
url: `/v1/offers/${encodeURIComponent(params.offerId)}/allow-wallet`,
|
|
2027
|
+
body: {
|
|
2028
|
+
wallet_address: params.walletAddress,
|
|
2029
|
+
chain: params.chain,
|
|
2030
|
+
signature: params.signature
|
|
2031
|
+
},
|
|
2032
|
+
attributes: Attributes.protected()
|
|
2033
|
+
});
|
|
2034
|
+
return AllowWalletResponse.fromDto(dto);
|
|
2035
|
+
}
|
|
2036
|
+
|
|
1663
2037
|
// src/universal/core/checkout/superstate/blockchain/abi.ts
|
|
1664
2038
|
var SUPERSTATE_SWAP_ABI = [
|
|
1665
2039
|
{
|
|
@@ -2513,100 +2887,125 @@ var SUPERSTATE_SWAP_ABI = [
|
|
|
2513
2887
|
type: "error",
|
|
2514
2888
|
name: "SwapFailed",
|
|
2515
2889
|
inputs: [
|
|
2516
|
-
{
|
|
2517
|
-
name: "user",
|
|
2518
|
-
type: "address",
|
|
2519
|
-
internalType: "address"
|
|
2520
|
-
},
|
|
2521
|
-
{
|
|
2522
|
-
name: "token",
|
|
2523
|
-
type: "address",
|
|
2524
|
-
internalType: "address"
|
|
2525
|
-
}
|
|
2526
|
-
]
|
|
2890
|
+
{
|
|
2891
|
+
name: "user",
|
|
2892
|
+
type: "address",
|
|
2893
|
+
internalType: "address"
|
|
2894
|
+
},
|
|
2895
|
+
{
|
|
2896
|
+
name: "token",
|
|
2897
|
+
type: "address",
|
|
2898
|
+
internalType: "address"
|
|
2899
|
+
}
|
|
2900
|
+
]
|
|
2901
|
+
},
|
|
2902
|
+
{
|
|
2903
|
+
type: "error",
|
|
2904
|
+
name: "Unauthorized",
|
|
2905
|
+
inputs: []
|
|
2906
|
+
}
|
|
2907
|
+
];
|
|
2908
|
+
|
|
2909
|
+
// src/universal/core/shared/blockchain/erc20/abi.ts
|
|
2910
|
+
var ERC20_ABI = [
|
|
2911
|
+
{
|
|
2912
|
+
type: "function",
|
|
2913
|
+
name: "allowance",
|
|
2914
|
+
inputs: [
|
|
2915
|
+
{ name: "owner", type: "address" },
|
|
2916
|
+
{ name: "spender", type: "address" }
|
|
2917
|
+
],
|
|
2918
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
2919
|
+
stateMutability: "view"
|
|
2920
|
+
},
|
|
2921
|
+
{
|
|
2922
|
+
type: "function",
|
|
2923
|
+
name: "approve",
|
|
2924
|
+
inputs: [
|
|
2925
|
+
{ name: "spender", type: "address" },
|
|
2926
|
+
{ name: "amount", type: "uint256" }
|
|
2927
|
+
],
|
|
2928
|
+
outputs: [{ name: "", type: "bool" }],
|
|
2929
|
+
stateMutability: "nonpayable"
|
|
2930
|
+
},
|
|
2931
|
+
{
|
|
2932
|
+
type: "function",
|
|
2933
|
+
name: "balanceOf",
|
|
2934
|
+
inputs: [{ name: "account", type: "address" }],
|
|
2935
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
2936
|
+
stateMutability: "view"
|
|
2937
|
+
},
|
|
2938
|
+
{
|
|
2939
|
+
type: "function",
|
|
2940
|
+
name: "decimals",
|
|
2941
|
+
inputs: [],
|
|
2942
|
+
outputs: [{ name: "", type: "uint8" }],
|
|
2943
|
+
stateMutability: "view"
|
|
2944
|
+
},
|
|
2945
|
+
{
|
|
2946
|
+
type: "function",
|
|
2947
|
+
name: "name",
|
|
2948
|
+
inputs: [],
|
|
2949
|
+
outputs: [{ name: "", type: "string" }],
|
|
2950
|
+
stateMutability: "view"
|
|
2951
|
+
},
|
|
2952
|
+
{
|
|
2953
|
+
type: "function",
|
|
2954
|
+
name: "symbol",
|
|
2955
|
+
inputs: [],
|
|
2956
|
+
outputs: [{ name: "", type: "string" }],
|
|
2957
|
+
stateMutability: "view"
|
|
2958
|
+
},
|
|
2959
|
+
{
|
|
2960
|
+
type: "function",
|
|
2961
|
+
name: "totalSupply",
|
|
2962
|
+
inputs: [],
|
|
2963
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
2964
|
+
stateMutability: "view"
|
|
2965
|
+
},
|
|
2966
|
+
{
|
|
2967
|
+
type: "function",
|
|
2968
|
+
name: "transfer",
|
|
2969
|
+
inputs: [
|
|
2970
|
+
{ name: "recipient", type: "address" },
|
|
2971
|
+
{ name: "amount", type: "uint256" }
|
|
2972
|
+
],
|
|
2973
|
+
outputs: [{ name: "", type: "bool" }],
|
|
2974
|
+
stateMutability: "nonpayable"
|
|
2975
|
+
},
|
|
2976
|
+
{
|
|
2977
|
+
type: "function",
|
|
2978
|
+
name: "transferFrom",
|
|
2979
|
+
inputs: [
|
|
2980
|
+
{ name: "sender", type: "address" },
|
|
2981
|
+
{ name: "recipient", type: "address" },
|
|
2982
|
+
{ name: "amount", type: "uint256" }
|
|
2983
|
+
],
|
|
2984
|
+
outputs: [{ name: "", type: "bool" }],
|
|
2985
|
+
stateMutability: "nonpayable"
|
|
2986
|
+
},
|
|
2987
|
+
{
|
|
2988
|
+
type: "event",
|
|
2989
|
+
name: "Approval",
|
|
2990
|
+
inputs: [
|
|
2991
|
+
{ name: "owner", type: "address", indexed: true },
|
|
2992
|
+
{ name: "spender", type: "address", indexed: true },
|
|
2993
|
+
{ name: "value", type: "uint256", indexed: false }
|
|
2994
|
+
],
|
|
2995
|
+
anonymous: false
|
|
2527
2996
|
},
|
|
2528
2997
|
{
|
|
2529
|
-
type: "
|
|
2530
|
-
name: "
|
|
2531
|
-
inputs: [
|
|
2998
|
+
type: "event",
|
|
2999
|
+
name: "Transfer",
|
|
3000
|
+
inputs: [
|
|
3001
|
+
{ name: "from", type: "address", indexed: true },
|
|
3002
|
+
{ name: "to", type: "address", indexed: true },
|
|
3003
|
+
{ name: "value", type: "uint256", indexed: false }
|
|
3004
|
+
],
|
|
3005
|
+
anonymous: false
|
|
2532
3006
|
}
|
|
2533
3007
|
];
|
|
2534
3008
|
|
|
2535
|
-
// src/universal/types/providers/superstate/swap.ts
|
|
2536
|
-
var SwapPreview = {
|
|
2537
|
-
/** Maps the contract's `Preview { input, fee, output }` struct. */
|
|
2538
|
-
fromContract: (preview) => ({
|
|
2539
|
-
inputAmount: parseUint256(preview.input, "SwapPreview.input"),
|
|
2540
|
-
fee: parseUint256(preview.fee, "SwapPreview.fee"),
|
|
2541
|
-
outputAmount: parseUint256(preview.output, "SwapPreview.output")
|
|
2542
|
-
})
|
|
2543
|
-
};
|
|
2544
|
-
var PauseFlags = (value) => value;
|
|
2545
|
-
var SwapStatus = {
|
|
2546
|
-
/**
|
|
2547
|
-
* Maps the contract's `Status { uint32 flags; State state }` struct, where
|
|
2548
|
-
* `State` is `0 = Active | 1 = Paused | 2 = Stopped`.
|
|
2549
|
-
*
|
|
2550
|
-
* `flags` is carried onto the `paused` arm only. On the other two the
|
|
2551
|
-
* contract sets it to a self-identifying marker rather than to information -
|
|
2552
|
-
* so repeating it would invite a caller to read meaning into a constant.
|
|
2553
|
-
*
|
|
2554
|
-
* @throws ValidationError on a `state` outside the enum. A contract that has
|
|
2555
|
-
* grown a fourth state is one the SDK does not model, and guessing `active`
|
|
2556
|
-
* would let a halted swap read as a live one.
|
|
2557
|
-
*/
|
|
2558
|
-
fromContract: (status) => {
|
|
2559
|
-
switch (status.state) {
|
|
2560
|
-
case 0:
|
|
2561
|
-
return { state: "active" };
|
|
2562
|
-
case 1:
|
|
2563
|
-
return { state: "paused", pausedLevels: PauseFlags(status.flags) };
|
|
2564
|
-
case 2:
|
|
2565
|
-
return { state: "stopped" };
|
|
2566
|
-
default:
|
|
2567
|
-
throw new ValidationError(
|
|
2568
|
-
`SwapStatus.state: unknown contract state (${status.state})`
|
|
2569
|
-
);
|
|
2570
|
-
}
|
|
2571
|
-
}
|
|
2572
|
-
};
|
|
2573
|
-
var AllowWalletResponse = {
|
|
2574
|
-
fromDto: (dto) => {
|
|
2575
|
-
switch (dto.action) {
|
|
2576
|
-
case "broadcast_transaction":
|
|
2577
|
-
return {
|
|
2578
|
-
action: "broadcast_transaction",
|
|
2579
|
-
to: EvmContractAddress(dto.to),
|
|
2580
|
-
data: HexEncodedTransactionData(dto.data)
|
|
2581
|
-
};
|
|
2582
|
-
case "none":
|
|
2583
|
-
return {
|
|
2584
|
-
action: "none",
|
|
2585
|
-
alreadyAllowed: dto.already_allowed
|
|
2586
|
-
};
|
|
2587
|
-
default: {
|
|
2588
|
-
const _exhaustive = dto;
|
|
2589
|
-
return _exhaustive;
|
|
2590
|
-
}
|
|
2591
|
-
}
|
|
2592
|
-
}
|
|
2593
|
-
};
|
|
2594
|
-
|
|
2595
|
-
// src/universal/api/frontline/providers/superstate/swap.ts
|
|
2596
|
-
async function allowWallet(api, params) {
|
|
2597
|
-
const dto = await api.send({
|
|
2598
|
-
method: "POST",
|
|
2599
|
-
url: `/v1/offers/${encodeURIComponent(params.offerId)}/allow-wallet`,
|
|
2600
|
-
body: {
|
|
2601
|
-
wallet_address: params.walletAddress,
|
|
2602
|
-
chain: params.chain,
|
|
2603
|
-
signature: params.signature
|
|
2604
|
-
},
|
|
2605
|
-
attributes: Attributes.protected()
|
|
2606
|
-
});
|
|
2607
|
-
return AllowWalletResponse.fromDto(dto);
|
|
2608
|
-
}
|
|
2609
|
-
|
|
2610
3009
|
// src/universal/api/rpc/providers/superstate/swap.ts
|
|
2611
3010
|
async function getSwapAuthorization(clients, params) {
|
|
2612
3011
|
return clients(params.chain).readContract({
|
|
@@ -2676,6 +3075,20 @@ var SuperstateSwapNamespaceImpl = class {
|
|
|
2676
3075
|
async () => getSwapPreview(this.ctx.rpc, params)
|
|
2677
3076
|
);
|
|
2678
3077
|
}
|
|
3078
|
+
async getQuote(params) {
|
|
3079
|
+
return this.log.wrap("getQuote", params, async () => {
|
|
3080
|
+
const { amount, outputTokenDecimals, ...ref } = params;
|
|
3081
|
+
const preview = await getSwapPreview(this.ctx.rpc, {
|
|
3082
|
+
...ref,
|
|
3083
|
+
amount: amount.raw
|
|
3084
|
+
});
|
|
3085
|
+
return SwapQuote.fromPreview(
|
|
3086
|
+
preview,
|
|
3087
|
+
amount.decimals,
|
|
3088
|
+
outputTokenDecimals
|
|
3089
|
+
);
|
|
3090
|
+
});
|
|
3091
|
+
}
|
|
2679
3092
|
async getStatus(params) {
|
|
2680
3093
|
return this.log.wrap(
|
|
2681
3094
|
"getStatus",
|
|
@@ -2827,47 +3240,188 @@ async function fetchRequirementStatuses(api, offerId) {
|
|
|
2827
3240
|
var RequirementsNamespaceImpl = class {
|
|
2828
3241
|
constructor(ctx) {
|
|
2829
3242
|
this.ctx = ctx;
|
|
2830
|
-
this.log = internalLogger(ctx.logger, "REQUIREMENTS");
|
|
3243
|
+
this.log = internalLogger(ctx.logger, "REQUIREMENTS");
|
|
3244
|
+
}
|
|
3245
|
+
async forOffer(offerId) {
|
|
3246
|
+
return this.log.wrap("forOffer", offerId, async () => {
|
|
3247
|
+
await this.ctx.ensureUserAuthenticated();
|
|
3248
|
+
return fetchOfferRequirements(
|
|
3249
|
+
this.ctx.api,
|
|
3250
|
+
offerId,
|
|
3251
|
+
void 0
|
|
3252
|
+
);
|
|
3253
|
+
});
|
|
3254
|
+
}
|
|
3255
|
+
async statuses(offerId) {
|
|
3256
|
+
return this.log.wrap("statuses", offerId, async () => {
|
|
3257
|
+
await this.ctx.ensureUserAuthenticated();
|
|
3258
|
+
return fetchRequirementStatuses(this.ctx.api, offerId);
|
|
3259
|
+
});
|
|
3260
|
+
}
|
|
3261
|
+
async createKycToken(params) {
|
|
3262
|
+
return this.log.wrap("createKycToken", params, async () => {
|
|
3263
|
+
await this.ctx.ensureUserAuthenticated();
|
|
3264
|
+
return createKycToken(
|
|
3265
|
+
this.ctx.api,
|
|
3266
|
+
params?.levelName,
|
|
3267
|
+
params?.reset
|
|
3268
|
+
);
|
|
3269
|
+
});
|
|
3270
|
+
}
|
|
3271
|
+
async getPii() {
|
|
3272
|
+
return this.log.wrap("getPii", void 0, async () => {
|
|
3273
|
+
await this.ctx.ensureUserAuthenticated();
|
|
3274
|
+
return fetchPii(this.ctx.api);
|
|
3275
|
+
});
|
|
3276
|
+
}
|
|
3277
|
+
async submitDocument(params) {
|
|
3278
|
+
return this.log.wrap("submitDocument", params, async () => {
|
|
3279
|
+
await this.ctx.ensureUserAuthenticated();
|
|
3280
|
+
return submitDocument(
|
|
3281
|
+
this.ctx.api,
|
|
3282
|
+
params.documentType,
|
|
3283
|
+
params.fields
|
|
3284
|
+
);
|
|
3285
|
+
});
|
|
3286
|
+
}
|
|
3287
|
+
};
|
|
3288
|
+
|
|
3289
|
+
// src/universal/types/offer-option-address.ts
|
|
3290
|
+
var OfferOptionAddressId = (value) => value;
|
|
3291
|
+
var OfferOptionAddress = {
|
|
3292
|
+
/** Maps the API DTO into the SDK offer-option-address domain model. */
|
|
3293
|
+
fromDto: (dto) => ({
|
|
3294
|
+
id: OfferOptionAddressId(dto.id),
|
|
3295
|
+
offerOptionId: OfferOptionId(dto.offer_option_id),
|
|
3296
|
+
address: EvmWalletAddress(dto.address),
|
|
3297
|
+
protocol: dto.protocol,
|
|
3298
|
+
createdAt: new Date(dto.created_at)
|
|
3299
|
+
})
|
|
3300
|
+
};
|
|
3301
|
+
var ConnectExternalWalletParams = {
|
|
3302
|
+
/** Maps connect-wallet params into the API DTO payload. */
|
|
3303
|
+
toDto: (params) => ({
|
|
3304
|
+
offer_option_id: params.offerOptionId,
|
|
3305
|
+
wallet_address: params.walletAddress,
|
|
3306
|
+
chain: params.chain,
|
|
3307
|
+
signature: params.signature
|
|
3308
|
+
})
|
|
3309
|
+
};
|
|
3310
|
+
|
|
3311
|
+
// src/universal/types/wallet-ownership-challenge.ts
|
|
3312
|
+
var WalletOwnershipChallenge = {
|
|
3313
|
+
/** Maps the API DTO into the SDK wallet-ownership-challenge domain model. */
|
|
3314
|
+
fromDto: (dto) => ({
|
|
3315
|
+
message: dto.message,
|
|
3316
|
+
expiresAt: new Date(dto.expires_at)
|
|
3317
|
+
})
|
|
3318
|
+
};
|
|
3319
|
+
var CreateWalletOwnershipChallengeParams = {
|
|
3320
|
+
/**
|
|
3321
|
+
* Maps challenge-request params into the API DTO payload. The discriminated
|
|
3322
|
+
* union guarantees SIWE fields are present exactly when `challengeType` is
|
|
3323
|
+
* `siwe`, so the mapping narrows on the discriminant.
|
|
3324
|
+
*/
|
|
3325
|
+
toDto: (params) => {
|
|
3326
|
+
switch (params.challengeType) {
|
|
3327
|
+
case "plain":
|
|
3328
|
+
return {
|
|
3329
|
+
wallet_address: params.walletAddress,
|
|
3330
|
+
chain: params.chain,
|
|
3331
|
+
challenge_type: "plain"
|
|
3332
|
+
};
|
|
3333
|
+
case "siwe":
|
|
3334
|
+
return {
|
|
3335
|
+
wallet_address: params.walletAddress,
|
|
3336
|
+
chain: params.chain,
|
|
3337
|
+
challenge_type: "siwe",
|
|
3338
|
+
domain: params.domain,
|
|
3339
|
+
uri: params.uri,
|
|
3340
|
+
statement: params.statement
|
|
3341
|
+
};
|
|
3342
|
+
default: {
|
|
3343
|
+
const _exhaustive = params;
|
|
3344
|
+
return _exhaustive;
|
|
3345
|
+
}
|
|
3346
|
+
}
|
|
3347
|
+
}
|
|
3348
|
+
};
|
|
3349
|
+
|
|
3350
|
+
// src/universal/api/frontline/wallet-connect.ts
|
|
3351
|
+
async function createWalletOwnershipChallenge(api, params) {
|
|
3352
|
+
const dto = await api.send({
|
|
3353
|
+
method: "POST",
|
|
3354
|
+
url: "/v1/wallet-ownership",
|
|
3355
|
+
body: CreateWalletOwnershipChallengeParams.toDto(params),
|
|
3356
|
+
attributes: Attributes.protected()
|
|
3357
|
+
});
|
|
3358
|
+
return WalletOwnershipChallenge.fromDto(dto);
|
|
3359
|
+
}
|
|
3360
|
+
async function connectExternalWallet(api, params) {
|
|
3361
|
+
const dto = await api.send({
|
|
3362
|
+
method: "POST",
|
|
3363
|
+
url: `/v1/offers/${params.offerId}/addresses`,
|
|
3364
|
+
body: ConnectExternalWalletParams.toDto(params),
|
|
3365
|
+
attributes: Attributes.protected()
|
|
3366
|
+
});
|
|
3367
|
+
return OfferOptionAddress.fromDto(dto);
|
|
3368
|
+
}
|
|
3369
|
+
async function listOptionAddresses(api, offerId, offerOptionId) {
|
|
3370
|
+
const { data } = await api.send({
|
|
3371
|
+
method: "GET",
|
|
3372
|
+
url: `/v1/offers/${offerId}/addresses`,
|
|
3373
|
+
queryParams: { offer_option_id: offerOptionId },
|
|
3374
|
+
attributes: Attributes.protected()
|
|
3375
|
+
});
|
|
3376
|
+
return data.map(OfferOptionAddress.fromDto);
|
|
3377
|
+
}
|
|
3378
|
+
async function removeOptionAddress(api, offerId, addressId) {
|
|
3379
|
+
const dto = await api.send({
|
|
3380
|
+
method: "DELETE",
|
|
3381
|
+
url: `/v1/offers/${offerId}/addresses/${addressId}`,
|
|
3382
|
+
attributes: Attributes.protected()
|
|
3383
|
+
});
|
|
3384
|
+
return OfferOptionAddress.fromDto(dto);
|
|
3385
|
+
}
|
|
3386
|
+
|
|
3387
|
+
// src/universal/core/wallets/wallets-namespace.ts
|
|
3388
|
+
var WalletsNamespaceImpl = class {
|
|
3389
|
+
constructor(ctx) {
|
|
3390
|
+
this.ctx = ctx;
|
|
3391
|
+
this.log = internalLogger(ctx.logger, "WALLETS");
|
|
2831
3392
|
}
|
|
2832
|
-
async
|
|
2833
|
-
return this.log.wrap("
|
|
3393
|
+
async createOwnershipChallenge(params) {
|
|
3394
|
+
return this.log.wrap("createOwnershipChallenge", params, async () => {
|
|
2834
3395
|
await this.ctx.ensureUserAuthenticated();
|
|
2835
|
-
return
|
|
3396
|
+
return createWalletOwnershipChallenge(
|
|
2836
3397
|
this.ctx.api,
|
|
2837
|
-
|
|
2838
|
-
void 0
|
|
3398
|
+
params
|
|
2839
3399
|
);
|
|
2840
3400
|
});
|
|
2841
3401
|
}
|
|
2842
|
-
async
|
|
2843
|
-
return this.log.wrap("
|
|
3402
|
+
async connectExternal(params) {
|
|
3403
|
+
return this.log.wrap("connectExternal", params, async () => {
|
|
2844
3404
|
await this.ctx.ensureUserAuthenticated();
|
|
2845
|
-
return
|
|
3405
|
+
return connectExternalWallet(this.ctx.api, params);
|
|
2846
3406
|
});
|
|
2847
3407
|
}
|
|
2848
|
-
async
|
|
2849
|
-
return this.log.wrap("
|
|
3408
|
+
async list(params) {
|
|
3409
|
+
return this.log.wrap("list", params, async () => {
|
|
2850
3410
|
await this.ctx.ensureUserAuthenticated();
|
|
2851
|
-
return
|
|
3411
|
+
return listOptionAddresses(
|
|
2852
3412
|
this.ctx.api,
|
|
2853
|
-
params
|
|
2854
|
-
params
|
|
3413
|
+
params.offerId,
|
|
3414
|
+
params.offerOptionId
|
|
2855
3415
|
);
|
|
2856
3416
|
});
|
|
2857
3417
|
}
|
|
2858
|
-
async
|
|
2859
|
-
return this.log.wrap("
|
|
2860
|
-
await this.ctx.ensureUserAuthenticated();
|
|
2861
|
-
return fetchPii(this.ctx.api);
|
|
2862
|
-
});
|
|
2863
|
-
}
|
|
2864
|
-
async submitDocument(params) {
|
|
2865
|
-
return this.log.wrap("submitDocument", params, async () => {
|
|
3418
|
+
async remove(params) {
|
|
3419
|
+
return this.log.wrap("remove", params, async () => {
|
|
2866
3420
|
await this.ctx.ensureUserAuthenticated();
|
|
2867
|
-
return
|
|
3421
|
+
return removeOptionAddress(
|
|
2868
3422
|
this.ctx.api,
|
|
2869
|
-
params.
|
|
2870
|
-
params.
|
|
3423
|
+
params.offerId,
|
|
3424
|
+
params.addressId
|
|
2871
3425
|
);
|
|
2872
3426
|
});
|
|
2873
3427
|
}
|
|
@@ -3295,163 +3849,6 @@ var TokensNamespaceImpl = class {
|
|
|
3295
3849
|
}
|
|
3296
3850
|
};
|
|
3297
3851
|
|
|
3298
|
-
// src/universal/types/offer-option-address.ts
|
|
3299
|
-
var OfferOptionAddressId = (value) => value;
|
|
3300
|
-
var OfferOptionAddress = {
|
|
3301
|
-
/** Maps the API DTO into the SDK offer-option-address domain model. */
|
|
3302
|
-
fromDto: (dto) => ({
|
|
3303
|
-
id: OfferOptionAddressId(dto.id),
|
|
3304
|
-
offerOptionId: OfferOptionId(dto.offer_option_id),
|
|
3305
|
-
address: EvmWalletAddress(dto.address),
|
|
3306
|
-
protocol: dto.protocol,
|
|
3307
|
-
createdAt: new Date(dto.created_at)
|
|
3308
|
-
})
|
|
3309
|
-
};
|
|
3310
|
-
var ConnectExternalWalletParams = {
|
|
3311
|
-
/** Maps connect-wallet params into the API DTO payload. */
|
|
3312
|
-
toDto: (params) => ({
|
|
3313
|
-
offer_option_id: params.offerOptionId,
|
|
3314
|
-
wallet_address: params.walletAddress,
|
|
3315
|
-
chain: params.chain,
|
|
3316
|
-
signature: params.signature
|
|
3317
|
-
})
|
|
3318
|
-
};
|
|
3319
|
-
|
|
3320
|
-
// src/universal/types/wallet-ownership-challenge.ts
|
|
3321
|
-
var WalletOwnershipChallenge = {
|
|
3322
|
-
/** Maps the API DTO into the SDK wallet-ownership-challenge domain model. */
|
|
3323
|
-
fromDto: (dto) => ({
|
|
3324
|
-
message: dto.message,
|
|
3325
|
-
expiresAt: new Date(dto.expires_at)
|
|
3326
|
-
})
|
|
3327
|
-
};
|
|
3328
|
-
var CreateWalletOwnershipChallengeParams = {
|
|
3329
|
-
/**
|
|
3330
|
-
* Maps challenge-request params into the API DTO payload. The discriminated
|
|
3331
|
-
* union guarantees SIWE fields are present exactly when `challengeType` is
|
|
3332
|
-
* `siwe`, so the mapping narrows on the discriminant.
|
|
3333
|
-
*/
|
|
3334
|
-
toDto: (params) => {
|
|
3335
|
-
switch (params.challengeType) {
|
|
3336
|
-
case "plain":
|
|
3337
|
-
return {
|
|
3338
|
-
wallet_address: params.walletAddress,
|
|
3339
|
-
chain: params.chain,
|
|
3340
|
-
challenge_type: "plain"
|
|
3341
|
-
};
|
|
3342
|
-
case "siwe":
|
|
3343
|
-
return {
|
|
3344
|
-
wallet_address: params.walletAddress,
|
|
3345
|
-
chain: params.chain,
|
|
3346
|
-
challenge_type: "siwe",
|
|
3347
|
-
domain: params.domain,
|
|
3348
|
-
uri: params.uri,
|
|
3349
|
-
statement: params.statement
|
|
3350
|
-
};
|
|
3351
|
-
default: {
|
|
3352
|
-
const _exhaustive = params;
|
|
3353
|
-
return _exhaustive;
|
|
3354
|
-
}
|
|
3355
|
-
}
|
|
3356
|
-
}
|
|
3357
|
-
};
|
|
3358
|
-
|
|
3359
|
-
// src/universal/api/frontline/wallet-connect.ts
|
|
3360
|
-
async function createWalletOwnershipChallenge(api, params) {
|
|
3361
|
-
const dto = await api.send({
|
|
3362
|
-
method: "POST",
|
|
3363
|
-
url: "/v1/wallet-ownership",
|
|
3364
|
-
body: CreateWalletOwnershipChallengeParams.toDto(params),
|
|
3365
|
-
attributes: Attributes.protected()
|
|
3366
|
-
});
|
|
3367
|
-
return WalletOwnershipChallenge.fromDto(dto);
|
|
3368
|
-
}
|
|
3369
|
-
async function connectExternalWallet(api, params) {
|
|
3370
|
-
const dto = await api.send({
|
|
3371
|
-
method: "POST",
|
|
3372
|
-
url: `/v1/offers/${params.offerId}/addresses`,
|
|
3373
|
-
body: ConnectExternalWalletParams.toDto(params),
|
|
3374
|
-
attributes: Attributes.protected()
|
|
3375
|
-
});
|
|
3376
|
-
return OfferOptionAddress.fromDto(dto);
|
|
3377
|
-
}
|
|
3378
|
-
async function listOptionAddresses(api, offerId, offerOptionId) {
|
|
3379
|
-
const { data } = await api.send({
|
|
3380
|
-
method: "GET",
|
|
3381
|
-
url: `/v1/offers/${offerId}/addresses`,
|
|
3382
|
-
queryParams: { offer_option_id: offerOptionId },
|
|
3383
|
-
attributes: Attributes.protected()
|
|
3384
|
-
});
|
|
3385
|
-
return data.map(OfferOptionAddress.fromDto);
|
|
3386
|
-
}
|
|
3387
|
-
async function removeOptionAddress(api, offerId, addressId) {
|
|
3388
|
-
const dto = await api.send({
|
|
3389
|
-
method: "DELETE",
|
|
3390
|
-
url: `/v1/offers/${offerId}/addresses/${addressId}`,
|
|
3391
|
-
attributes: Attributes.protected()
|
|
3392
|
-
});
|
|
3393
|
-
return OfferOptionAddress.fromDto(dto);
|
|
3394
|
-
}
|
|
3395
|
-
|
|
3396
|
-
// src/universal/core/wallets/wallets-namespace.ts
|
|
3397
|
-
var WalletsNamespaceImpl = class {
|
|
3398
|
-
constructor(ctx) {
|
|
3399
|
-
this.ctx = ctx;
|
|
3400
|
-
this.log = internalLogger(ctx.logger, "WALLETS");
|
|
3401
|
-
}
|
|
3402
|
-
async createOwnershipChallenge(params) {
|
|
3403
|
-
return this.log.wrap("createOwnershipChallenge", params, async () => {
|
|
3404
|
-
await this.ctx.ensureUserAuthenticated();
|
|
3405
|
-
return createWalletOwnershipChallenge(
|
|
3406
|
-
this.ctx.api,
|
|
3407
|
-
params
|
|
3408
|
-
);
|
|
3409
|
-
});
|
|
3410
|
-
}
|
|
3411
|
-
async connectExternal(params) {
|
|
3412
|
-
return this.log.wrap("connectExternal", params, async () => {
|
|
3413
|
-
await this.ctx.ensureUserAuthenticated();
|
|
3414
|
-
return connectExternalWallet(this.ctx.api, params);
|
|
3415
|
-
});
|
|
3416
|
-
}
|
|
3417
|
-
async list(params) {
|
|
3418
|
-
return this.log.wrap("list", params, async () => {
|
|
3419
|
-
await this.ctx.ensureUserAuthenticated();
|
|
3420
|
-
return listOptionAddresses(
|
|
3421
|
-
this.ctx.api,
|
|
3422
|
-
params.offerId,
|
|
3423
|
-
params.offerOptionId
|
|
3424
|
-
);
|
|
3425
|
-
});
|
|
3426
|
-
}
|
|
3427
|
-
async remove(params) {
|
|
3428
|
-
return this.log.wrap("remove", params, async () => {
|
|
3429
|
-
await this.ctx.ensureUserAuthenticated();
|
|
3430
|
-
return removeOptionAddress(
|
|
3431
|
-
this.ctx.api,
|
|
3432
|
-
params.offerId,
|
|
3433
|
-
params.addressId
|
|
3434
|
-
);
|
|
3435
|
-
});
|
|
3436
|
-
}
|
|
3437
|
-
};
|
|
3438
|
-
|
|
3439
|
-
// src/universal/types/oauth-session.ts
|
|
3440
|
-
var ClientCredentialsOAuth = (value) => value;
|
|
3441
|
-
var OAuthRefreshToken = (value) => value;
|
|
3442
|
-
var OAuthSession = {
|
|
3443
|
-
fromDto: (dto) => {
|
|
3444
|
-
const expiresAt = new Date(Date.now() + dto.expires_in * 1e3);
|
|
3445
|
-
return {
|
|
3446
|
-
accessToken: {
|
|
3447
|
-
value: dto.access_token,
|
|
3448
|
-
expiresAt
|
|
3449
|
-
},
|
|
3450
|
-
...dto.refresh_token != null && dto.refresh_token !== "" ? { refreshToken: OAuthRefreshToken(dto.refresh_token) } : void 0
|
|
3451
|
-
};
|
|
3452
|
-
}
|
|
3453
|
-
};
|
|
3454
|
-
|
|
3455
3852
|
// src/universal/api/frontline/offers.ts
|
|
3456
3853
|
async function fetchOffers(api, clientCreds) {
|
|
3457
3854
|
return fetchAllPages((params) => fetchOffersPage(api, params, clientCreds));
|
|
@@ -3508,6 +3905,7 @@ export {
|
|
|
3508
3905
|
ValidationError,
|
|
3509
3906
|
InvariantError,
|
|
3510
3907
|
MathError,
|
|
3908
|
+
classifyLogCause,
|
|
3511
3909
|
describeErrorUnredacted,
|
|
3512
3910
|
internalLogger,
|
|
3513
3911
|
HttpClient,
|
|
@@ -3516,13 +3914,6 @@ export {
|
|
|
3516
3914
|
Seconds,
|
|
3517
3915
|
isExpired,
|
|
3518
3916
|
ERC20_ABI,
|
|
3519
|
-
fetchAllPages,
|
|
3520
|
-
Cursor,
|
|
3521
|
-
PaginatedResponse,
|
|
3522
|
-
PaginationParams,
|
|
3523
|
-
AssetId,
|
|
3524
|
-
AssetCode,
|
|
3525
|
-
Asset,
|
|
3526
3917
|
ETHEREUM_CHAINS,
|
|
3527
3918
|
EthereumChain,
|
|
3528
3919
|
SOLANA_CHAINS,
|
|
@@ -3544,6 +3935,38 @@ export {
|
|
|
3544
3935
|
StablecoinSymbol,
|
|
3545
3936
|
KnownAssetSymbol,
|
|
3546
3937
|
Bps,
|
|
3938
|
+
blockchainAmountFromRawOrThrow,
|
|
3939
|
+
parseBlockchainAmount,
|
|
3940
|
+
CentrifugeVaultStatus,
|
|
3941
|
+
CentrifugeVaultBuyTransaction,
|
|
3942
|
+
CentrifugeVaultClaimTransaction,
|
|
3943
|
+
CentrifugeAssets,
|
|
3944
|
+
CentrifugeShares,
|
|
3945
|
+
CentrifugeDepositPosition,
|
|
3946
|
+
CentrifugeRedeemPosition,
|
|
3947
|
+
CentrifugeVaultLeg,
|
|
3948
|
+
CentrifugeVaultLegId,
|
|
3949
|
+
CentrifugeVaultClaimProceedsTransaction,
|
|
3950
|
+
CentrifugeNamespaceImpl,
|
|
3951
|
+
FormattedAmountUi,
|
|
3952
|
+
FormattedPercentUi,
|
|
3953
|
+
TxExplorerUrl,
|
|
3954
|
+
ShortenedWalletAddress,
|
|
3955
|
+
FormattedAmountAssetUi,
|
|
3956
|
+
AssetIconUrl,
|
|
3957
|
+
shortenAddress,
|
|
3958
|
+
formatAmount,
|
|
3959
|
+
formatRawAmount,
|
|
3960
|
+
formatCompactAmount,
|
|
3961
|
+
formatBpsAsPercent,
|
|
3962
|
+
usdAmount,
|
|
3963
|
+
assetAmount,
|
|
3964
|
+
NA_AMOUNT_ASSET_UI,
|
|
3965
|
+
formatShareAmount,
|
|
3966
|
+
formattedUsdPrice,
|
|
3967
|
+
AssetId,
|
|
3968
|
+
AssetCode,
|
|
3969
|
+
Asset,
|
|
3547
3970
|
OfferId,
|
|
3548
3971
|
OfferSlug,
|
|
3549
3972
|
isOfferType,
|
|
@@ -3552,15 +3975,20 @@ export {
|
|
|
3552
3975
|
OfferToken,
|
|
3553
3976
|
Ticker,
|
|
3554
3977
|
Isin,
|
|
3978
|
+
AsyncOfferDetail,
|
|
3555
3979
|
OfferOptionId,
|
|
3556
3980
|
OfferOptionSlug,
|
|
3557
3981
|
OfferSwapContract,
|
|
3982
|
+
OfferVaultContract,
|
|
3558
3983
|
OfferDetail,
|
|
3559
3984
|
OfferOption,
|
|
3560
3985
|
FaqItem,
|
|
3561
3986
|
Link,
|
|
3562
3987
|
TermItem,
|
|
3563
3988
|
Milestone,
|
|
3989
|
+
Cursor,
|
|
3990
|
+
PaginatedResponse,
|
|
3991
|
+
PaginationParams,
|
|
3564
3992
|
ParticipationId,
|
|
3565
3993
|
Blockchain,
|
|
3566
3994
|
WalletAddress,
|
|
@@ -3568,29 +3996,11 @@ export {
|
|
|
3568
3996
|
Participation,
|
|
3569
3997
|
CreateParticipationParams,
|
|
3570
3998
|
CoinListTokenSaleNamespaceImpl,
|
|
3571
|
-
FormattedAmountUi,
|
|
3572
|
-
FormattedPercentUi,
|
|
3573
|
-
TxExplorerUrl,
|
|
3574
|
-
ShortenedWalletAddress,
|
|
3575
|
-
FormattedAmountAssetUi,
|
|
3576
|
-
AssetIconUrl,
|
|
3577
|
-
shortenAddress,
|
|
3578
|
-
formatAmount,
|
|
3579
|
-
formatRawAmount,
|
|
3580
|
-
formatCompactAmount,
|
|
3581
|
-
formatBpsAsPercent,
|
|
3582
|
-
usdAmount,
|
|
3583
|
-
assetAmount,
|
|
3584
|
-
NA_AMOUNT_ASSET_UI,
|
|
3585
|
-
formatShareAmount,
|
|
3586
|
-
formattedUsdPrice,
|
|
3587
3999
|
viemChain,
|
|
3588
4000
|
getChainId,
|
|
3589
4001
|
chainFromId,
|
|
3590
4002
|
getNetworkName,
|
|
3591
4003
|
txExplorerUrl,
|
|
3592
|
-
blockchainAmountFromRawOrThrow,
|
|
3593
|
-
parseBlockchainAmount,
|
|
3594
4004
|
OndoTradingStatus,
|
|
3595
4005
|
OndoQuote,
|
|
3596
4006
|
OndoBuyTransaction,
|
|
@@ -3601,10 +4011,8 @@ export {
|
|
|
3601
4011
|
PauseFlags,
|
|
3602
4012
|
SwapStatus,
|
|
3603
4013
|
AllowWalletResponse,
|
|
4014
|
+
SwapQuote,
|
|
3604
4015
|
SuperstateSwapNamespaceImpl,
|
|
3605
|
-
fetchOffers,
|
|
3606
|
-
fetchOffersPage,
|
|
3607
|
-
fetchOfferDetails,
|
|
3608
4016
|
DocumentSubmission,
|
|
3609
4017
|
KycToken,
|
|
3610
4018
|
Iso2CountryCode,
|
|
@@ -3616,19 +4024,19 @@ export {
|
|
|
3616
4024
|
RequirementStatusInfo,
|
|
3617
4025
|
fetchOfferRequirements,
|
|
3618
4026
|
RequirementsNamespaceImpl,
|
|
3619
|
-
Erc20NamespaceImpl,
|
|
3620
|
-
TokenLogoUrl,
|
|
3621
|
-
TokenLogo,
|
|
3622
|
-
TokenMetadata,
|
|
3623
|
-
TokensNamespaceImpl,
|
|
3624
4027
|
OfferOptionAddressId,
|
|
3625
4028
|
OfferOptionAddress,
|
|
3626
4029
|
ConnectExternalWalletParams,
|
|
3627
4030
|
WalletOwnershipChallenge,
|
|
3628
4031
|
CreateWalletOwnershipChallengeParams,
|
|
3629
4032
|
WalletsNamespaceImpl,
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
4033
|
+
fetchOffers,
|
|
4034
|
+
fetchOffersPage,
|
|
4035
|
+
fetchOfferDetails,
|
|
4036
|
+
Erc20NamespaceImpl,
|
|
4037
|
+
TokenLogoUrl,
|
|
4038
|
+
TokenLogo,
|
|
4039
|
+
TokenMetadata,
|
|
4040
|
+
TokensNamespaceImpl
|
|
3633
4041
|
};
|
|
3634
|
-
//# sourceMappingURL=chunk-
|
|
4042
|
+
//# sourceMappingURL=chunk-GIE4UWB3.js.map
|