@coinlist-co/react 0.11.1-rc.8cfcd2a → 0.11.1-rc.e102bdb
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/dist/{chunk-ZVB6KWZ2.js → chunk-7CTH4KPU.js} +254 -61
- package/dist/chunk-7CTH4KPU.js.map +1 -0
- package/dist/{chunk-5KYO7OOX.js → chunk-LSPZETDH.js} +58 -25
- package/dist/chunk-LSPZETDH.js.map +1 -0
- package/dist/{chunk-AQIHCFW4.js → chunk-UZUQALFY.js} +2 -2
- package/dist/client/index.cjs +4585 -2330
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +2995 -1672
- package/dist/client/index.d.ts +2995 -1672
- package/dist/client/index.js +4404 -2383
- package/dist/client/index.js.map +1 -1
- package/dist/{collections-DrJFEDHl.d.cts → collections-BBI_XydI.d.cts} +1 -1
- package/dist/{collections-pLtrj6fw.d.ts → collections-BrX9rRWc.d.ts} +1 -1
- package/dist/{config-C6vlghJY.d.cts → config-CMl1bR3F.d.cts} +472 -130
- package/dist/{config-C6vlghJY.d.ts → config-CMl1bR3F.d.ts} +472 -130
- package/dist/server/index.cjs +242 -59
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +2 -2
- package/dist/server/index.js.map +1 -1
- package/dist/shared/index.cjs +315 -84
- package/dist/shared/index.cjs.map +1 -1
- package/dist/shared/index.d.cts +85 -16
- package/dist/shared/index.d.ts +85 -16
- package/dist/shared/index.js +16 -6
- package/package.json +1 -1
- package/dist/chunk-5KYO7OOX.js.map +0 -1
- package/dist/chunk-ZVB6KWZ2.js.map +0 -1
- /package/dist/{chunk-AQIHCFW4.js.map → chunk-UZUQALFY.js.map} +0 -0
package/dist/shared/index.cjs
CHANGED
|
@@ -45,6 +45,7 @@ __export(shared_exports, {
|
|
|
45
45
|
Cursor: () => Cursor,
|
|
46
46
|
DEFAULT_AMOUNT_TO_COMPUTE_PRICE: () => DEFAULT_AMOUNT_TO_COMPUTE_PRICE,
|
|
47
47
|
DEFAULT_ONDO_AMOUNT_TO_COMPUTE_PRICE: () => DEFAULT_ONDO_AMOUNT_TO_COMPUTE_PRICE,
|
|
48
|
+
DEFAULT_ONDO_SELL_TOKENS_TO_COMPUTE_PRICE: () => DEFAULT_ONDO_SELL_TOKENS_TO_COMPUTE_PRICE,
|
|
48
49
|
DEFAULT_SLIPPAGE_BPS: () => DEFAULT_SLIPPAGE_BPS,
|
|
49
50
|
DecimalString: () => DecimalString,
|
|
50
51
|
DocumentSubmission: () => DocumentSubmission,
|
|
@@ -67,6 +68,7 @@ __export(shared_exports, {
|
|
|
67
68
|
Link: () => Link,
|
|
68
69
|
MAX_ASSET_DECIMALS: () => MAX_ASSET_DECIMALS,
|
|
69
70
|
MAX_UINT_256: () => MAX_UINT_256,
|
|
71
|
+
MathError: () => MathError,
|
|
70
72
|
Milestone: () => Milestone,
|
|
71
73
|
NA_AMOUNT_ASSET_UI: () => NA_AMOUNT_ASSET_UI,
|
|
72
74
|
NotAuthenticatedError: () => NotAuthenticatedError,
|
|
@@ -75,6 +77,7 @@ __export(shared_exports, {
|
|
|
75
77
|
OAuthSession: () => OAuthSession,
|
|
76
78
|
ONDO_POLL_INTERVAL_MS: () => ONDO_POLL_INTERVAL_MS,
|
|
77
79
|
ONDO_QUOTE_EXPIRY_THRESHOLD_MS: () => ONDO_QUOTE_EXPIRY_THRESHOLD_MS,
|
|
80
|
+
ONDO_SETTLEMENT_ASSET: () => ONDO_SETTLEMENT_ASSET,
|
|
78
81
|
ONDO_SUPPORTED_INPUT_ASSETS: () => ONDO_SUPPORTED_INPUT_ASSETS,
|
|
79
82
|
Offer: () => Offer,
|
|
80
83
|
OfferDetail: () => OfferDetail,
|
|
@@ -87,9 +90,10 @@ __export(shared_exports, {
|
|
|
87
90
|
OfferSlug: () => OfferSlug,
|
|
88
91
|
OfferToken: () => OfferToken,
|
|
89
92
|
OffersNamespaceImpl: () => OffersNamespaceImpl,
|
|
93
|
+
OndoBuyTransaction: () => OndoBuyTransaction,
|
|
90
94
|
OndoNamespaceImpl: () => OndoNamespaceImpl,
|
|
91
95
|
OndoQuote: () => OndoQuote,
|
|
92
|
-
|
|
96
|
+
OndoSellTransaction: () => OndoSellTransaction,
|
|
93
97
|
OndoTradingStatus: () => OndoTradingStatus,
|
|
94
98
|
PKCEState: () => PKCEState,
|
|
95
99
|
PaginatedResponse: () => PaginatedResponse,
|
|
@@ -149,7 +153,8 @@ __export(shared_exports, {
|
|
|
149
153
|
assetAmount: () => assetAmount,
|
|
150
154
|
blockchainAmountFromRawOrThrow: () => blockchainAmountFromRawOrThrow,
|
|
151
155
|
chainFromId: () => chainFromId,
|
|
152
|
-
|
|
156
|
+
computeOndoBuyPrice: () => computeOndoBuyPrice,
|
|
157
|
+
computeOndoSellPrice: () => computeOndoSellPrice,
|
|
153
158
|
computePrice: () => computePrice,
|
|
154
159
|
computeSlip: () => computeSlip,
|
|
155
160
|
decodeSwappedOutputAmount: () => decodeSwappedOutputAmount,
|
|
@@ -442,11 +447,19 @@ var InvariantError = class extends Error {
|
|
|
442
447
|
this.name = "InvariantError";
|
|
443
448
|
}
|
|
444
449
|
};
|
|
450
|
+
var MathError = class extends Error {
|
|
451
|
+
constructor(message) {
|
|
452
|
+
super(message);
|
|
453
|
+
this.name = "MathError";
|
|
454
|
+
}
|
|
455
|
+
};
|
|
445
456
|
|
|
446
457
|
// src/shared/types/blockchain/core.ts
|
|
447
458
|
var ETHEREUM_CHAINS = {
|
|
448
459
|
ethereum_mainnet: true,
|
|
449
|
-
ethereum_sepolia: true
|
|
460
|
+
ethereum_sepolia: true,
|
|
461
|
+
base_mainnet: true,
|
|
462
|
+
base_sepolia: true
|
|
450
463
|
};
|
|
451
464
|
var EthereumChain = (value) => {
|
|
452
465
|
if (!Object.keys(ETHEREUM_CHAINS).includes(value)) {
|
|
@@ -501,9 +514,25 @@ var BlockchainAmount = Object.assign(
|
|
|
501
514
|
(value) => value,
|
|
502
515
|
{
|
|
503
516
|
add: (a, b) => combineAmounts(a, b, (x, y) => x + y),
|
|
504
|
-
sub: (a, b) => combineAmounts(a, b, (x, y) => x - y)
|
|
517
|
+
sub: (a, b) => combineAmounts(a, b, (x, y) => x - y),
|
|
518
|
+
mul: multiplyAmounts,
|
|
519
|
+
div: divideAmounts
|
|
505
520
|
}
|
|
506
521
|
);
|
|
522
|
+
function multiplyAmounts(a, b) {
|
|
523
|
+
const product = a.raw * b.raw;
|
|
524
|
+
return BlockchainAmount({
|
|
525
|
+
raw: product / 10n ** BigInt(b.decimals),
|
|
526
|
+
decimals: a.decimals
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
function divideAmounts(a, b) {
|
|
530
|
+
if (b.raw === 0n) {
|
|
531
|
+
throw new MathError("Cannot divide a BlockchainAmount by zero");
|
|
532
|
+
}
|
|
533
|
+
const scaled = a.raw * 10n ** BigInt(b.decimals);
|
|
534
|
+
return BlockchainAmount({ raw: scaled / b.raw, decimals: a.decimals });
|
|
535
|
+
}
|
|
507
536
|
function combineAmounts(a, b, op) {
|
|
508
537
|
if (a.decimals !== b.decimals) {
|
|
509
538
|
throw new InvariantError(
|
|
@@ -538,7 +567,9 @@ var AssetIconUrl = (value) => value;
|
|
|
538
567
|
// src/shared/core/blockchain/chain.ts
|
|
539
568
|
var CHAIN_IDS = {
|
|
540
569
|
ethereum_mainnet: 1,
|
|
541
|
-
ethereum_sepolia: 11155111
|
|
570
|
+
ethereum_sepolia: 11155111,
|
|
571
|
+
base_mainnet: 8453,
|
|
572
|
+
base_sepolia: 84532
|
|
542
573
|
};
|
|
543
574
|
function getChainId(chain) {
|
|
544
575
|
return CHAIN_IDS[chain];
|
|
@@ -557,6 +588,10 @@ function getNetworkName(chain) {
|
|
|
557
588
|
return "Ethereum";
|
|
558
589
|
case "ethereum_sepolia":
|
|
559
590
|
return "Ethereum Sepolia";
|
|
591
|
+
case "base_mainnet":
|
|
592
|
+
return "Base";
|
|
593
|
+
case "base_sepolia":
|
|
594
|
+
return "Base Sepolia";
|
|
560
595
|
default: {
|
|
561
596
|
const _exhaustive = chain;
|
|
562
597
|
return _exhaustive;
|
|
@@ -572,6 +607,10 @@ function explorerBaseUrl(chain) {
|
|
|
572
607
|
return "https://etherscan.io";
|
|
573
608
|
case "ethereum_sepolia":
|
|
574
609
|
return "https://sepolia.etherscan.io";
|
|
610
|
+
case "base_mainnet":
|
|
611
|
+
return "https://basescan.org";
|
|
612
|
+
case "base_sepolia":
|
|
613
|
+
return "https://sepolia-explorer.base.org";
|
|
575
614
|
default: {
|
|
576
615
|
const _exhaustive = chain;
|
|
577
616
|
return _exhaustive;
|
|
@@ -847,6 +886,9 @@ function classifyLogCause(error) {
|
|
|
847
886
|
if (error instanceof InvariantError) {
|
|
848
887
|
return { type: "invariant", message: error.message };
|
|
849
888
|
}
|
|
889
|
+
if (error instanceof MathError) {
|
|
890
|
+
return { type: "math", message: error.message };
|
|
891
|
+
}
|
|
850
892
|
if (error instanceof NotAuthenticatedError) {
|
|
851
893
|
return { type: "not-authenticated" };
|
|
852
894
|
}
|
|
@@ -1172,6 +1214,12 @@ var USDC_ADDRESSES = {
|
|
|
1172
1214
|
),
|
|
1173
1215
|
ethereum_sepolia: EvmContractAddress(
|
|
1174
1216
|
"0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"
|
|
1217
|
+
),
|
|
1218
|
+
base_mainnet: EvmContractAddress(
|
|
1219
|
+
"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
|
|
1220
|
+
),
|
|
1221
|
+
base_sepolia: EvmContractAddress(
|
|
1222
|
+
"0x036CbD53842c5426634e7929541eC2318f3dCF7e"
|
|
1175
1223
|
)
|
|
1176
1224
|
};
|
|
1177
1225
|
var USDT_ADDRESSES = {
|
|
@@ -1180,7 +1228,11 @@ var USDT_ADDRESSES = {
|
|
|
1180
1228
|
),
|
|
1181
1229
|
ethereum_sepolia: EvmContractAddress(
|
|
1182
1230
|
"0x7169D38820dfd117C3FA1f22a697dBA58d90BA06"
|
|
1183
|
-
)
|
|
1231
|
+
),
|
|
1232
|
+
base_mainnet: EvmContractAddress(
|
|
1233
|
+
"0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2"
|
|
1234
|
+
),
|
|
1235
|
+
base_sepolia: null
|
|
1184
1236
|
};
|
|
1185
1237
|
var TOKEN_REGISTRY = {
|
|
1186
1238
|
erc20: (symbol) => {
|
|
@@ -1193,16 +1245,17 @@ var TOKEN_REGISTRY = {
|
|
|
1193
1245
|
throw new InvariantError(`Unknown asset symbol: ${symbol}`);
|
|
1194
1246
|
}
|
|
1195
1247
|
},
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1248
|
+
/**
|
|
1249
|
+
* USDC's contract on `chain`. USDC is deployed on every chain the SDK
|
|
1250
|
+
* models, so the table is total and the answer is never `null`.
|
|
1251
|
+
*/
|
|
1252
|
+
usdcAddress: (chain) => USDC_ADDRESSES[chain],
|
|
1253
|
+
/**
|
|
1254
|
+
* USDT's contract on `chain`, or `null` where Tether publishes none —
|
|
1255
|
+
* Base Sepolia today. The honest answer, never a fake address a balance
|
|
1256
|
+
* read would call.
|
|
1257
|
+
*/
|
|
1258
|
+
usdtAddress: (chain) => USDT_ADDRESSES[chain]
|
|
1206
1259
|
};
|
|
1207
1260
|
|
|
1208
1261
|
// src/shared/types/pagination.ts
|
|
@@ -1499,30 +1552,49 @@ function ondoSwapContractAddress(chain) {
|
|
|
1499
1552
|
var ONDO_POLL_INTERVAL_MS = 15e3;
|
|
1500
1553
|
var ONDO_QUOTE_EXPIRY_THRESHOLD_MS = 5e3;
|
|
1501
1554
|
var DEFAULT_ONDO_AMOUNT_TO_COMPUTE_PRICE = DecimalString("1000");
|
|
1555
|
+
var ONDO_SETTLEMENT_ASSET = USDC_SYMBOL;
|
|
1556
|
+
var DEFAULT_ONDO_SELL_TOKENS_TO_COMPUTE_PRICE = 1;
|
|
1502
1557
|
var ONDO_SUPPORTED_INPUT_ASSETS = [
|
|
1503
1558
|
USDC_SYMBOL
|
|
1504
1559
|
];
|
|
1505
1560
|
|
|
1506
1561
|
// src/shared/core/checkout/ondo/math.ts
|
|
1507
|
-
function
|
|
1562
|
+
function computeOndoBuyPrice(transaction) {
|
|
1508
1563
|
const { notionalValue, receiveOutputAmount } = transaction;
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1564
|
+
return pricePerShare({
|
|
1565
|
+
usd: notionalValue,
|
|
1566
|
+
shares: receiveOutputAmount
|
|
1567
|
+
});
|
|
1568
|
+
}
|
|
1569
|
+
function computeOndoSellPrice(transaction) {
|
|
1570
|
+
const { expected, spendInputAmount } = transaction;
|
|
1571
|
+
return pricePerShare({
|
|
1572
|
+
usd: grossProceeds(expected),
|
|
1573
|
+
shares: spendInputAmount
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
function grossProceeds(expected) {
|
|
1577
|
+
const raw = expected.quantity.raw + expected.fee.raw;
|
|
1578
|
+
if (raw > MAX_UINT_256) {
|
|
1579
|
+
throw new MathError(`Ondo sell proceeds: out of uint256 bounds (${raw})`);
|
|
1513
1580
|
}
|
|
1514
|
-
|
|
1515
|
-
|
|
1581
|
+
return BlockchainAmount.add(expected.quantity, expected.fee);
|
|
1582
|
+
}
|
|
1583
|
+
function pricePerShare({
|
|
1584
|
+
usd,
|
|
1585
|
+
shares
|
|
1586
|
+
}) {
|
|
1587
|
+
const price = BlockchainAmount.div(usd, shares);
|
|
1516
1588
|
return BlockchainAmount({
|
|
1517
|
-
raw: assertPriceFits(raw),
|
|
1518
|
-
decimals:
|
|
1589
|
+
raw: assertPriceFits(price.raw),
|
|
1590
|
+
decimals: price.decimals
|
|
1519
1591
|
});
|
|
1520
1592
|
}
|
|
1521
1593
|
function assertPriceFits(raw) {
|
|
1522
1594
|
try {
|
|
1523
1595
|
return assertUint256(raw);
|
|
1524
1596
|
} catch {
|
|
1525
|
-
throw new
|
|
1597
|
+
throw new MathError(`Ondo price: out of uint256 bounds (${raw})`);
|
|
1526
1598
|
}
|
|
1527
1599
|
}
|
|
1528
1600
|
|
|
@@ -1567,47 +1639,122 @@ var OndoQuote = {
|
|
|
1567
1639
|
};
|
|
1568
1640
|
}
|
|
1569
1641
|
};
|
|
1570
|
-
var
|
|
1642
|
+
var OndoBuyTransaction = {
|
|
1571
1643
|
fromDto: (dto) => {
|
|
1572
|
-
const
|
|
1644
|
+
const spendDecimals = AssetDecimals(dto.spend_input_decimals);
|
|
1573
1645
|
const outputDecimals = AssetDecimals(dto.receive_output_decimals);
|
|
1574
1646
|
return {
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
data: HexEncodedTransactionData(dto.data)
|
|
1578
|
-
},
|
|
1579
|
-
expiresAt: parseExpiresAt(dto.expires_at),
|
|
1580
|
-
payInputAmount: blockchainAmountFromRawOrThrow({
|
|
1581
|
-
label: "pay_input_amount",
|
|
1582
|
-
raw: dto.pay_input_amount,
|
|
1583
|
-
decimals: inputDecimals
|
|
1584
|
-
}),
|
|
1647
|
+
...parseSwapCore(dto, spendDecimals),
|
|
1648
|
+
side: "buy",
|
|
1585
1649
|
fee: blockchainAmountFromRawOrThrow({
|
|
1586
1650
|
label: "fee",
|
|
1587
1651
|
raw: dto.fee,
|
|
1588
|
-
decimals:
|
|
1652
|
+
decimals: spendDecimals
|
|
1589
1653
|
}),
|
|
1590
1654
|
notionalValue: blockchainAmountFromRawOrThrow({
|
|
1591
1655
|
label: "notional_value",
|
|
1592
1656
|
raw: dto.notional_value,
|
|
1593
|
-
decimals:
|
|
1657
|
+
decimals: spendDecimals
|
|
1594
1658
|
}),
|
|
1595
|
-
receiveOutputAmount:
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1659
|
+
receiveOutputAmount: parsePositiveAmount({
|
|
1660
|
+
label: "receive_output_amount",
|
|
1661
|
+
raw: dto.receive_output_amount,
|
|
1662
|
+
decimals: outputDecimals,
|
|
1663
|
+
// A transaction that yields nothing is not one to sign - the user
|
|
1664
|
+
// would pay the deposit and receive no asset - and frontline refuses
|
|
1665
|
+
// to emit one. A zero here is a changed encoding, not a small order.
|
|
1666
|
+
// Rejecting it at the boundary is also what lets `computeOndoBuyPrice`
|
|
1667
|
+
// divide by it without a fallible result: the failure surfaces as the
|
|
1668
|
+
// data hook's ERROR state rather than as a division during render.
|
|
1669
|
+
reason: "a buy that yields nothing is not fillable"
|
|
1670
|
+
})
|
|
1599
1671
|
};
|
|
1600
1672
|
}
|
|
1601
1673
|
};
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1674
|
+
var OndoSellTransaction = {
|
|
1675
|
+
fromDto: (dto) => {
|
|
1676
|
+
const spendDecimals = AssetDecimals(dto.spend_input_decimals);
|
|
1677
|
+
const outputDecimals = AssetDecimals(dto.receive_output_decimals);
|
|
1678
|
+
const expectedQuantity = parsePositiveAmount({
|
|
1679
|
+
label: "expected_quantity",
|
|
1680
|
+
raw: dto.expected_quantity,
|
|
1681
|
+
decimals: outputDecimals,
|
|
1682
|
+
reason: "a sale that yields nothing is not fillable"
|
|
1683
|
+
});
|
|
1684
|
+
return {
|
|
1685
|
+
...parseSwapCore(dto, spendDecimals),
|
|
1686
|
+
side: "sell",
|
|
1687
|
+
expected: {
|
|
1688
|
+
quantity: expectedQuantity,
|
|
1689
|
+
fee: blockchainAmountFromRawOrThrow({
|
|
1690
|
+
label: "expected_fee",
|
|
1691
|
+
raw: dto.expected_fee,
|
|
1692
|
+
decimals: outputDecimals
|
|
1693
|
+
})
|
|
1694
|
+
},
|
|
1695
|
+
minimum: {
|
|
1696
|
+
quantity: parseMinimumQuantity(
|
|
1697
|
+
dto.minimum_quantity,
|
|
1698
|
+
outputDecimals,
|
|
1699
|
+
expectedQuantity
|
|
1700
|
+
),
|
|
1701
|
+
fee: blockchainAmountFromRawOrThrow({
|
|
1702
|
+
label: "minimum_fee",
|
|
1703
|
+
raw: dto.minimum_fee,
|
|
1704
|
+
decimals: outputDecimals
|
|
1705
|
+
})
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
};
|
|
1710
|
+
function parseSwapCore(dto, spendDecimals) {
|
|
1711
|
+
return {
|
|
1712
|
+
tx: {
|
|
1713
|
+
to: EvmContractAddress(dto.to),
|
|
1714
|
+
data: HexEncodedTransactionData(dto.data)
|
|
1715
|
+
},
|
|
1716
|
+
expiresAt: parseExpiresAt(dto.expires_at),
|
|
1717
|
+
spendInputAmount: parsePositiveAmount({
|
|
1718
|
+
label: "spend_input_amount",
|
|
1719
|
+
raw: dto.spend_input_amount,
|
|
1720
|
+
decimals: spendDecimals,
|
|
1721
|
+
// A transaction that takes nothing from the wallet is not one to sign:
|
|
1722
|
+
// it would settle one leg of a trade and skip the other. Frontline
|
|
1723
|
+
// refuses an `amount` of zero whichever way the trade runs, so this is a
|
|
1724
|
+
// changed encoding rather than a small order.
|
|
1725
|
+
//
|
|
1726
|
+
// Guarded on both sides rather than on the sale alone, because which
|
|
1727
|
+
// amount becomes the divisor in the price flips with the direction: a
|
|
1728
|
+
// guard placed by that would be a rule about the arithmetic rather than
|
|
1729
|
+
// about the trade.
|
|
1730
|
+
reason: "a swap that spends nothing is not fillable"
|
|
1731
|
+
})
|
|
1732
|
+
};
|
|
1733
|
+
}
|
|
1734
|
+
function parseMinimumQuantity(raw, decimals, expectedQuantity) {
|
|
1735
|
+
const amount = parsePositiveAmount({
|
|
1736
|
+
label: "minimum_quantity",
|
|
1605
1737
|
raw,
|
|
1606
|
-
decimals
|
|
1738
|
+
decimals,
|
|
1739
|
+
reason: "a floor of zero guarantees nothing"
|
|
1607
1740
|
});
|
|
1741
|
+
if (amount.raw > expectedQuantity.raw) {
|
|
1742
|
+
throw new ValidationError(
|
|
1743
|
+
`minimum_quantity: must not exceed expected_quantity ("${raw}" > "${expectedQuantity.raw}")`
|
|
1744
|
+
);
|
|
1745
|
+
}
|
|
1746
|
+
return amount;
|
|
1747
|
+
}
|
|
1748
|
+
function parsePositiveAmount({
|
|
1749
|
+
label,
|
|
1750
|
+
raw,
|
|
1751
|
+
decimals,
|
|
1752
|
+
reason
|
|
1753
|
+
}) {
|
|
1754
|
+
const amount = blockchainAmountFromRawOrThrow({ label, raw, decimals });
|
|
1608
1755
|
if (amount.raw <= 0n) {
|
|
1609
1756
|
throw new ValidationError(
|
|
1610
|
-
|
|
1757
|
+
`${label}: must be greater than zero ("${raw}") - ${reason}`
|
|
1611
1758
|
);
|
|
1612
1759
|
}
|
|
1613
1760
|
return amount;
|
|
@@ -1644,27 +1791,57 @@ async function getOndoQuote(api, params) {
|
|
|
1644
1791
|
});
|
|
1645
1792
|
return OndoQuote.fromDto(dto);
|
|
1646
1793
|
}
|
|
1647
|
-
async function
|
|
1794
|
+
async function buildOndoBuy(api, params) {
|
|
1648
1795
|
const dto = await api.send({
|
|
1649
1796
|
method: "POST",
|
|
1650
|
-
url: "/v1/ondo/swap/
|
|
1651
|
-
body:
|
|
1652
|
-
symbol: params.symbol,
|
|
1653
|
-
chain: params.chain,
|
|
1654
|
-
wallet_address: params.walletAddress,
|
|
1655
|
-
amount: params.amount.raw.toString()
|
|
1656
|
-
},
|
|
1797
|
+
url: "/v1/ondo/swap/buy",
|
|
1798
|
+
body: swapBody(params),
|
|
1657
1799
|
attributes: Attributes.protected()
|
|
1658
1800
|
});
|
|
1659
|
-
|
|
1660
|
-
|
|
1801
|
+
assertSpendScaleAgrees({
|
|
1802
|
+
published: dto.spend_input_decimals,
|
|
1803
|
+
sized: params.amount,
|
|
1804
|
+
trade: "purchase"
|
|
1805
|
+
});
|
|
1806
|
+
return OndoBuyTransaction.fromDto(dto);
|
|
1661
1807
|
}
|
|
1662
|
-
function
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
)
|
|
1667
|
-
|
|
1808
|
+
async function buildOndoSell(api, params) {
|
|
1809
|
+
const dto = await api.send({
|
|
1810
|
+
method: "POST",
|
|
1811
|
+
url: "/v1/ondo/swap/sell",
|
|
1812
|
+
body: swapBody(params),
|
|
1813
|
+
attributes: Attributes.protected()
|
|
1814
|
+
});
|
|
1815
|
+
assertSpendScaleAgrees({
|
|
1816
|
+
published: dto.spend_input_decimals,
|
|
1817
|
+
sized: params.amount,
|
|
1818
|
+
trade: "sale",
|
|
1819
|
+
// The two answers come from two chains, so on a testnet they can disagree
|
|
1820
|
+
// for a reason that is neither the caller's nor a corrupt response. Say so,
|
|
1821
|
+
// or a QA run reads as a puzzle rather than a diagnosis.
|
|
1822
|
+
note: "the quote resolves the asset on Ethereum mainnet while the swap executes on the chain requested, so these disagree until frontline serves a chain-scoped quote"
|
|
1823
|
+
});
|
|
1824
|
+
return OndoSellTransaction.fromDto(dto);
|
|
1825
|
+
}
|
|
1826
|
+
function swapBody(params) {
|
|
1827
|
+
return {
|
|
1828
|
+
symbol: params.symbol,
|
|
1829
|
+
chain: params.chain,
|
|
1830
|
+
wallet_address: params.walletAddress,
|
|
1831
|
+
amount: params.amount.raw.toString()
|
|
1832
|
+
};
|
|
1833
|
+
}
|
|
1834
|
+
function assertSpendScaleAgrees({
|
|
1835
|
+
published,
|
|
1836
|
+
sized,
|
|
1837
|
+
trade,
|
|
1838
|
+
note
|
|
1839
|
+
}) {
|
|
1840
|
+
if (published === sized.decimals) return;
|
|
1841
|
+
const because = note === void 0 ? "" : ` - ${note}`;
|
|
1842
|
+
throw new ValidationError(
|
|
1843
|
+
`spend_input_decimals: the ${trade} was priced in ${published} decimals but the order was sized in ${sized.decimals}${because}`
|
|
1844
|
+
);
|
|
1668
1845
|
}
|
|
1669
1846
|
function sizeParam(params) {
|
|
1670
1847
|
const tokenAmount = "tokenAmount" in params ? params.tokenAmount : void 0;
|
|
@@ -1703,10 +1880,16 @@ var OndoNamespaceImpl = class {
|
|
|
1703
1880
|
return getOndoQuote(this.ctx.api, params);
|
|
1704
1881
|
});
|
|
1705
1882
|
}
|
|
1706
|
-
async
|
|
1707
|
-
return this.log.wrap("
|
|
1883
|
+
async buildBuyTransaction(params) {
|
|
1884
|
+
return this.log.wrap("buildBuyTransaction", params, async () => {
|
|
1885
|
+
await this.ctx.ensureUserAuthenticated();
|
|
1886
|
+
return buildOndoBuy(this.ctx.api, params);
|
|
1887
|
+
});
|
|
1888
|
+
}
|
|
1889
|
+
async buildSellTransaction(params) {
|
|
1890
|
+
return this.log.wrap("buildSellTransaction", params, async () => {
|
|
1708
1891
|
await this.ctx.ensureUserAuthenticated();
|
|
1709
|
-
return
|
|
1892
|
+
return buildOndoSell(this.ctx.api, params);
|
|
1710
1893
|
});
|
|
1711
1894
|
}
|
|
1712
1895
|
};
|
|
@@ -2473,27 +2656,47 @@ var TokenMetadata = {
|
|
|
2473
2656
|
logoDark: dto.logo_dark === void 0 ? null : TokenLogo.fromDto(dto.logo_dark, baseUrl)
|
|
2474
2657
|
};
|
|
2475
2658
|
},
|
|
2659
|
+
/**
|
|
2660
|
+
* Maps the complete registry snapshot to every token it lists across the
|
|
2661
|
+
* chains this SDK models, skipping native coins and chains outside
|
|
2662
|
+
* {@link EthereumChain} (e.g. Solana) rather than failing on them — the
|
|
2663
|
+
* registry may serve chains ahead of the SDK's type surface.
|
|
2664
|
+
*/
|
|
2665
|
+
fromRegistryDto: (dto, baseUrl) => {
|
|
2666
|
+
assertSupportedSchemaVersion(dto.schema_version);
|
|
2667
|
+
return dto.chains.flatMap((chainDto) => {
|
|
2668
|
+
let chain;
|
|
2669
|
+
try {
|
|
2670
|
+
chain = EthereumChain(chainDto.chain);
|
|
2671
|
+
} catch {
|
|
2672
|
+
return [];
|
|
2673
|
+
}
|
|
2674
|
+
return tokensOfChain(chain, chainDto.assets, baseUrl);
|
|
2675
|
+
});
|
|
2676
|
+
},
|
|
2476
2677
|
/**
|
|
2477
2678
|
* Maps a chain snapshot to the tokens it lists, skipping the chain's native
|
|
2478
2679
|
* coin (`kind: 'COIN'`, no contract address).
|
|
2479
2680
|
*/
|
|
2480
2681
|
fromChainAssetsDto: (dto, baseUrl) => {
|
|
2481
2682
|
assertSupportedSchemaVersion(dto.schema_version);
|
|
2482
|
-
|
|
2483
|
-
return dto.assets.filter((asset) => asset.kind === "TOKEN" && asset.address !== void 0).map((asset) => ({
|
|
2484
|
-
identifier: {
|
|
2485
|
-
chain,
|
|
2486
|
-
// The filter above cannot narrow `address` for the type checker.
|
|
2487
|
-
address: EvmContractAddress(asset.address)
|
|
2488
|
-
},
|
|
2489
|
-
name: asset.name,
|
|
2490
|
-
symbol: AssetSymbol(asset.symbol),
|
|
2491
|
-
decimals: AssetDecimals(asset.decimals),
|
|
2492
|
-
logo: TokenLogo.fromDto(asset.logo, baseUrl),
|
|
2493
|
-
logoDark: asset.logo_dark === void 0 ? null : TokenLogo.fromDto(asset.logo_dark, baseUrl)
|
|
2494
|
-
}));
|
|
2683
|
+
return tokensOfChain(EthereumChain(dto.chain), dto.assets, baseUrl);
|
|
2495
2684
|
}
|
|
2496
2685
|
};
|
|
2686
|
+
function tokensOfChain(chain, assets, baseUrl) {
|
|
2687
|
+
return assets.filter((asset) => asset.kind === "TOKEN" && asset.address !== void 0).map((asset) => ({
|
|
2688
|
+
identifier: {
|
|
2689
|
+
chain,
|
|
2690
|
+
// The filter above cannot narrow `address` for the type checker.
|
|
2691
|
+
address: EvmContractAddress(asset.address)
|
|
2692
|
+
},
|
|
2693
|
+
name: asset.name,
|
|
2694
|
+
symbol: AssetSymbol(asset.symbol),
|
|
2695
|
+
decimals: AssetDecimals(asset.decimals),
|
|
2696
|
+
logo: TokenLogo.fromDto(asset.logo, baseUrl),
|
|
2697
|
+
logoDark: asset.logo_dark === void 0 ? null : TokenLogo.fromDto(asset.logo_dark, baseUrl)
|
|
2698
|
+
}));
|
|
2699
|
+
}
|
|
2497
2700
|
function assertSupportedSchemaVersion(version) {
|
|
2498
2701
|
if (version !== 1) {
|
|
2499
2702
|
throw new ValidationError(
|
|
@@ -2562,6 +2765,29 @@ async function fetchTokensMetadata(client, chain) {
|
|
|
2562
2765
|
}
|
|
2563
2766
|
return TokenMetadata.fromChainAssetsDto(response.body, client.config.baseUrl);
|
|
2564
2767
|
}
|
|
2768
|
+
async function fetchAllTokensMetadata(client) {
|
|
2769
|
+
let response;
|
|
2770
|
+
try {
|
|
2771
|
+
response = await client.send({
|
|
2772
|
+
method: "GET",
|
|
2773
|
+
url: `/assets.json`
|
|
2774
|
+
});
|
|
2775
|
+
} catch (error) {
|
|
2776
|
+
if (isRegistryHtmlFallback(error)) {
|
|
2777
|
+
throw new ValidationError(
|
|
2778
|
+
"Token registry returned non-JSON for the complete snapshot"
|
|
2779
|
+
);
|
|
2780
|
+
}
|
|
2781
|
+
throw error;
|
|
2782
|
+
}
|
|
2783
|
+
assertOk(response);
|
|
2784
|
+
if (response.body === null) {
|
|
2785
|
+
throw new ValidationError(
|
|
2786
|
+
"Token registry returned an empty complete snapshot"
|
|
2787
|
+
);
|
|
2788
|
+
}
|
|
2789
|
+
return TokenMetadata.fromRegistryDto(response.body, client.config.baseUrl);
|
|
2790
|
+
}
|
|
2565
2791
|
function isRegistryHtmlFallback(error) {
|
|
2566
2792
|
return error instanceof HttpError && error.response.status >= 200 && error.response.status < 300;
|
|
2567
2793
|
}
|
|
@@ -2600,7 +2826,7 @@ var TokensNamespaceImpl = class {
|
|
|
2600
2826
|
return this.log.wrap(
|
|
2601
2827
|
"list",
|
|
2602
2828
|
chain,
|
|
2603
|
-
() => fetchTokensMetadata(this.api, chain)
|
|
2829
|
+
() => chain === void 0 ? fetchAllTokensMetadata(this.api) : fetchTokensMetadata(this.api, chain)
|
|
2604
2830
|
);
|
|
2605
2831
|
}
|
|
2606
2832
|
};
|
|
@@ -2803,6 +3029,7 @@ var User = {
|
|
|
2803
3029
|
Cursor,
|
|
2804
3030
|
DEFAULT_AMOUNT_TO_COMPUTE_PRICE,
|
|
2805
3031
|
DEFAULT_ONDO_AMOUNT_TO_COMPUTE_PRICE,
|
|
3032
|
+
DEFAULT_ONDO_SELL_TOKENS_TO_COMPUTE_PRICE,
|
|
2806
3033
|
DEFAULT_SLIPPAGE_BPS,
|
|
2807
3034
|
DecimalString,
|
|
2808
3035
|
DocumentSubmission,
|
|
@@ -2825,6 +3052,7 @@ var User = {
|
|
|
2825
3052
|
Link,
|
|
2826
3053
|
MAX_ASSET_DECIMALS,
|
|
2827
3054
|
MAX_UINT_256,
|
|
3055
|
+
MathError,
|
|
2828
3056
|
Milestone,
|
|
2829
3057
|
NA_AMOUNT_ASSET_UI,
|
|
2830
3058
|
NotAuthenticatedError,
|
|
@@ -2833,6 +3061,7 @@ var User = {
|
|
|
2833
3061
|
OAuthSession,
|
|
2834
3062
|
ONDO_POLL_INTERVAL_MS,
|
|
2835
3063
|
ONDO_QUOTE_EXPIRY_THRESHOLD_MS,
|
|
3064
|
+
ONDO_SETTLEMENT_ASSET,
|
|
2836
3065
|
ONDO_SUPPORTED_INPUT_ASSETS,
|
|
2837
3066
|
Offer,
|
|
2838
3067
|
OfferDetail,
|
|
@@ -2845,9 +3074,10 @@ var User = {
|
|
|
2845
3074
|
OfferSlug,
|
|
2846
3075
|
OfferToken,
|
|
2847
3076
|
OffersNamespaceImpl,
|
|
3077
|
+
OndoBuyTransaction,
|
|
2848
3078
|
OndoNamespaceImpl,
|
|
2849
3079
|
OndoQuote,
|
|
2850
|
-
|
|
3080
|
+
OndoSellTransaction,
|
|
2851
3081
|
OndoTradingStatus,
|
|
2852
3082
|
PKCEState,
|
|
2853
3083
|
PaginatedResponse,
|
|
@@ -2907,7 +3137,8 @@ var User = {
|
|
|
2907
3137
|
assetAmount,
|
|
2908
3138
|
blockchainAmountFromRawOrThrow,
|
|
2909
3139
|
chainFromId,
|
|
2910
|
-
|
|
3140
|
+
computeOndoBuyPrice,
|
|
3141
|
+
computeOndoSellPrice,
|
|
2911
3142
|
computePrice,
|
|
2912
3143
|
computeSlip,
|
|
2913
3144
|
decodeSwappedOutputAmount,
|