@sodax/sdk 2.2.0-rc.4 → 2.2.0-rc.6
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 +11 -5
- package/dist/index.cjs +1989 -480
- package/dist/index.d.cts +1112 -46
- package/dist/index.d.ts +1112 -46
- package/dist/index.mjs +1980 -490
- package/package.json +5 -4
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAbiItem, parseAbi, defineChain, isAddress, toHex, hexToBytes, encodeAbiParameters, parseAbiParameters, encodeFunctionData, erc20Abi as erc20Abi$1, createPublicClient, http, bytesToHex, keccak256, stringToBytes, fromHex, encodePacked, decodeAbiParameters, parseEventLogs, isHex, maxUint160, maxUint48, fallback } from 'viem';
|
|
1
|
+
import { getAbiItem, parseAbi, defineChain, isAddress, toHex, hexToBytes, encodeAbiParameters, parseAbiParameters, encodeFunctionData, erc20Abi as erc20Abi$1, createPublicClient, http, bytesToHex, keccak256, stringToBytes, fromHex, encodePacked, decodeAbiParameters, parseEventLogs, isHex, maxUint160, maxUint48, zeroAddress, isAddressEqual, formatUnits, fallback } from 'viem';
|
|
2
2
|
import { initEccLib, address, networks, Transaction, Psbt, payments, opcodes, script } from 'bitcoinjs-lib';
|
|
3
3
|
import { bcs } from '@mysten/sui/bcs';
|
|
4
4
|
import { PublicKey, Connection, VersionedTransaction, SystemProgram, ComputeBudgetProgram, TransactionMessage, TransactionInstruction } from '@solana/web3.js';
|
|
@@ -18,8 +18,10 @@ import { ChainGrpcWasmApi, IndexerGrpcAccountPortfolioApi, TxGrpcApi, toBase64,
|
|
|
18
18
|
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx.js';
|
|
19
19
|
import { getNetworkEndpoints, Network } from '@injectivelabs/networks';
|
|
20
20
|
import * as v from 'valibot';
|
|
21
|
-
import { SwapsApi, SwapsApiError, rawTxSchemaForChainKey
|
|
21
|
+
import { SwapsApi, SwapsApiError, rawTxSchemaForChainKey, makeQuoteResponseSchema, DeadlineResponseSchema, AllowanceCheckResponseSchema, makeApproveResponseSchema, makeCreateIntentResponseSchema, SubmitIntentResponseSchema, StatusResponseSchema, makeCancelIntentResponseSchema, IntentHashResponseSchema, IntentPacketResponseSchema, RelayExtraDataResponseSchema, IntentStateSchema, IntentResponseSchema as IntentResponseSchema$1, GasEstimateResponseSchema, FeeResponseSchema, SubmitTxResponseSchema, SubmitTxStatusResponseSchema } from '@sodax/swaps-api';
|
|
22
22
|
export { SwapsApiError } from '@sodax/swaps-api';
|
|
23
|
+
import { BridgeApi, BridgeApiError } from '@sodax/bridge-api';
|
|
24
|
+
export { BridgeApiError } from '@sodax/bridge-api';
|
|
23
25
|
import BigNumber5, { BigNumber } from 'bignumber.js';
|
|
24
26
|
import { Token, Price } from '@pancakeswap/swap-sdk-core';
|
|
25
27
|
import { sqrtRatioX96ToPrice, PositionMath, tickToPrice, TickMath, maxLiquidityForAmount0Precise, maxLiquidityForAmount1, maxLiquidityForAmounts } from '@pancakeswap/v3-sdk';
|
|
@@ -94,8 +96,8 @@ function serializeCause(cause, depth) {
|
|
|
94
96
|
}
|
|
95
97
|
function sanitizeContext(value, depth) {
|
|
96
98
|
const out = {};
|
|
97
|
-
for (const [key,
|
|
98
|
-
out[key] = sanitizeValue(
|
|
99
|
+
for (const [key, v10] of Object.entries(value)) {
|
|
100
|
+
out[key] = sanitizeValue(v10, depth + 1);
|
|
99
101
|
}
|
|
100
102
|
return out;
|
|
101
103
|
}
|
|
@@ -106,13 +108,13 @@ function sanitizeValue(value, depth) {
|
|
|
106
108
|
if (t === "bigint") return value.toString();
|
|
107
109
|
if (t === "string" || t === "number" || t === "boolean") return value;
|
|
108
110
|
if (t === "function" || t === "symbol") return safeString(value);
|
|
109
|
-
if (Array.isArray(value)) return value.map((
|
|
111
|
+
if (Array.isArray(value)) return value.map((v10) => sanitizeValue(v10, depth + 1));
|
|
110
112
|
if (value instanceof Date) return value.toISOString();
|
|
111
113
|
if (value instanceof Map) {
|
|
112
|
-
return Array.from(value.entries()).map(([k,
|
|
114
|
+
return Array.from(value.entries()).map(([k, v10]) => [sanitizeValue(k, depth + 1), sanitizeValue(v10, depth + 1)]);
|
|
113
115
|
}
|
|
114
116
|
if (value instanceof Set) {
|
|
115
|
-
return Array.from(value.values()).map((
|
|
117
|
+
return Array.from(value.values()).map((v10) => sanitizeValue(v10, depth + 1));
|
|
116
118
|
}
|
|
117
119
|
if (value instanceof Error) return { name: value.name, message: value.message };
|
|
118
120
|
if (t === "object") {
|
|
@@ -124,9 +126,9 @@ function sanitizeValue(value, depth) {
|
|
|
124
126
|
}
|
|
125
127
|
return safeString(value);
|
|
126
128
|
}
|
|
127
|
-
function safeString(
|
|
129
|
+
function safeString(v10) {
|
|
128
130
|
try {
|
|
129
|
-
return String(
|
|
131
|
+
return String(v10);
|
|
130
132
|
} catch {
|
|
131
133
|
return "[unserializable]";
|
|
132
134
|
}
|
|
@@ -342,8 +344,8 @@ var HubVaultSymbols = [
|
|
|
342
344
|
];
|
|
343
345
|
var SodaTokens = {
|
|
344
346
|
sodaBNB: {
|
|
345
|
-
symbol: "
|
|
346
|
-
name: "
|
|
347
|
+
symbol: "BNB",
|
|
348
|
+
name: "BNB",
|
|
347
349
|
decimals: 18,
|
|
348
350
|
address: "0x40Cd41b35DB9e5109ae7E54b44De8625dB320E6b",
|
|
349
351
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -351,8 +353,8 @@ var SodaTokens = {
|
|
|
351
353
|
vault: "0x40Cd41b35DB9e5109ae7E54b44De8625dB320E6b"
|
|
352
354
|
},
|
|
353
355
|
sodaAVAX: {
|
|
354
|
-
symbol: "
|
|
355
|
-
name: "
|
|
356
|
+
symbol: "AVAX",
|
|
357
|
+
name: "Avalanche",
|
|
356
358
|
decimals: 18,
|
|
357
359
|
address: "0x14238D267557E9d799016ad635B53CD15935d290",
|
|
358
360
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -361,7 +363,7 @@ var SodaTokens = {
|
|
|
361
363
|
},
|
|
362
364
|
sodaETH: {
|
|
363
365
|
symbol: "sodaETH",
|
|
364
|
-
name: "
|
|
366
|
+
name: "SODA ETH",
|
|
365
367
|
decimals: 18,
|
|
366
368
|
address: "0x4effB5813271699683C25c734F4daBc45B363709",
|
|
367
369
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -369,8 +371,8 @@ var SodaTokens = {
|
|
|
369
371
|
vault: "0x4effB5813271699683C25c734F4daBc45B363709"
|
|
370
372
|
},
|
|
371
373
|
sodaBTC: {
|
|
372
|
-
symbol: "
|
|
373
|
-
name: "
|
|
374
|
+
symbol: "BTC",
|
|
375
|
+
name: "Bitcoin",
|
|
374
376
|
decimals: 18,
|
|
375
377
|
address: "0x7A1A5555842Ad2D0eD274d09b5c4406a95799D5d",
|
|
376
378
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -379,7 +381,7 @@ var SodaTokens = {
|
|
|
379
381
|
},
|
|
380
382
|
sodaWBTC: {
|
|
381
383
|
symbol: "sodaWBTC",
|
|
382
|
-
name: "
|
|
384
|
+
name: "SODA WBTC",
|
|
383
385
|
decimals: 18,
|
|
384
386
|
address: "0x811C3fCc13f9c2a23AE2Ae2DCadacFAC6eb5f0eB",
|
|
385
387
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -387,8 +389,8 @@ var SodaTokens = {
|
|
|
387
389
|
vault: "0x811C3fCc13f9c2a23AE2Ae2DCadacFAC6eb5f0eB"
|
|
388
390
|
},
|
|
389
391
|
sodaSOL: {
|
|
390
|
-
symbol: "
|
|
391
|
-
name: "
|
|
392
|
+
symbol: "SOL",
|
|
393
|
+
name: "Solana",
|
|
392
394
|
decimals: 18,
|
|
393
395
|
address: "0xdEa692287E2cE8Cb08FA52917Be0F16b1DACDC87",
|
|
394
396
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -396,8 +398,8 @@ var SodaTokens = {
|
|
|
396
398
|
vault: "0xdEa692287E2cE8Cb08FA52917Be0F16b1DACDC87"
|
|
397
399
|
},
|
|
398
400
|
sodaXLM: {
|
|
399
|
-
symbol: "
|
|
400
|
-
name: "
|
|
401
|
+
symbol: "XLM",
|
|
402
|
+
name: "Stellar Lumens",
|
|
401
403
|
decimals: 18,
|
|
402
404
|
address: "0x6BC8C37cba91F76E68C9e6d689A9C21E4d32079B",
|
|
403
405
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -405,8 +407,8 @@ var SodaTokens = {
|
|
|
405
407
|
vault: "0x6BC8C37cba91F76E68C9e6d689A9C21E4d32079B"
|
|
406
408
|
},
|
|
407
409
|
sodaINJ: {
|
|
408
|
-
symbol: "
|
|
409
|
-
name: "
|
|
410
|
+
symbol: "INJ",
|
|
411
|
+
name: "Injective",
|
|
410
412
|
decimals: 18,
|
|
411
413
|
address: "0x1f22279C89B213944b7Ea41daCB0a868DdCDFd13",
|
|
412
414
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -414,8 +416,8 @@ var SodaTokens = {
|
|
|
414
416
|
vault: "0x1f22279C89B213944b7Ea41daCB0a868DdCDFd13"
|
|
415
417
|
},
|
|
416
418
|
sodaSUI: {
|
|
417
|
-
symbol: "
|
|
418
|
-
name: "
|
|
419
|
+
symbol: "SUI",
|
|
420
|
+
name: "Sui",
|
|
419
421
|
decimals: 18,
|
|
420
422
|
address: "0xdc5B4b00F98347E95b9F94911213DAB4C687e1e3",
|
|
421
423
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -433,7 +435,7 @@ var SodaTokens = {
|
|
|
433
435
|
},
|
|
434
436
|
sodaUSDC: {
|
|
435
437
|
symbol: "sodaUSDC",
|
|
436
|
-
name: "
|
|
438
|
+
name: "SODA USDC",
|
|
437
439
|
decimals: 18,
|
|
438
440
|
address: "0xAbbb91c0617090F0028BDC27597Cd0D038F3A833",
|
|
439
441
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -442,7 +444,7 @@ var SodaTokens = {
|
|
|
442
444
|
},
|
|
443
445
|
sodaUSDT: {
|
|
444
446
|
symbol: "sodaUSDT",
|
|
445
|
-
name: "
|
|
447
|
+
name: "SODA USDT",
|
|
446
448
|
decimals: 18,
|
|
447
449
|
address: "0xbDf1F453FCB61424011BBDDCB96cFDB30f3Fe876",
|
|
448
450
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -460,7 +462,7 @@ var SodaTokens = {
|
|
|
460
462
|
},
|
|
461
463
|
sodaS: {
|
|
462
464
|
symbol: "sodaS",
|
|
463
|
-
name: "
|
|
465
|
+
name: "SODA S",
|
|
464
466
|
decimals: 18,
|
|
465
467
|
address: "0x62ecc3Eeb80a162c57624B3fF80313FE69f5203e",
|
|
466
468
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -468,8 +470,8 @@ var SodaTokens = {
|
|
|
468
470
|
vault: "0x62ecc3Eeb80a162c57624B3fF80313FE69f5203e"
|
|
469
471
|
},
|
|
470
472
|
sodaPOL: {
|
|
471
|
-
symbol: "
|
|
472
|
-
name: "
|
|
473
|
+
symbol: "POL",
|
|
474
|
+
name: "Polygon Ecosystem Token",
|
|
473
475
|
decimals: 18,
|
|
474
476
|
address: "0x208ED38f4783328aA9eBFeC360D32e7520A9B779",
|
|
475
477
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -478,7 +480,7 @@ var SodaTokens = {
|
|
|
478
480
|
},
|
|
479
481
|
sodaSODA: {
|
|
480
482
|
symbol: "sodaSODA",
|
|
481
|
-
name: "
|
|
483
|
+
name: "SODA SODA",
|
|
482
484
|
decimals: 18,
|
|
483
485
|
address: "0x21685E341DE7844135329914Be6Bd8D16982d834",
|
|
484
486
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -486,8 +488,8 @@ var SodaTokens = {
|
|
|
486
488
|
vault: "0x21685E341DE7844135329914Be6Bd8D16982d834"
|
|
487
489
|
},
|
|
488
490
|
sodaHYPE: {
|
|
489
|
-
symbol: "
|
|
490
|
-
name: "
|
|
491
|
+
symbol: "HYPE",
|
|
492
|
+
name: "Hyperliquid",
|
|
491
493
|
decimals: 18,
|
|
492
494
|
address: "0x6E81124fC5d2Bf666B16a0A5d90066eBf35c7411",
|
|
493
495
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -495,8 +497,8 @@ var SodaTokens = {
|
|
|
495
497
|
vault: "0x6E81124fC5d2Bf666B16a0A5d90066eBf35c7411"
|
|
496
498
|
},
|
|
497
499
|
sodaRBNT: {
|
|
498
|
-
symbol: "
|
|
499
|
-
name: "
|
|
500
|
+
symbol: "RBNT",
|
|
501
|
+
name: "Redbelly Network Token",
|
|
500
502
|
decimals: 18,
|
|
501
503
|
address: "0x4B207114F9118dEAC56436e1aE3c45648783c7Ac",
|
|
502
504
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -504,8 +506,8 @@ var SodaTokens = {
|
|
|
504
506
|
vault: "0x4B207114F9118dEAC56436e1aE3c45648783c7Ac"
|
|
505
507
|
},
|
|
506
508
|
sodaLL: {
|
|
507
|
-
symbol: "
|
|
508
|
-
name: "
|
|
509
|
+
symbol: "LL",
|
|
510
|
+
name: "LightLink",
|
|
509
511
|
decimals: 18,
|
|
510
512
|
address: "0x14C5eB2D25dFb834852dFc85744875d1eCb09748",
|
|
511
513
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -513,8 +515,8 @@ var SodaTokens = {
|
|
|
513
515
|
vault: "0x14C5eB2D25dFb834852dFc85744875d1eCb09748"
|
|
514
516
|
},
|
|
515
517
|
sodaWEETH: {
|
|
516
|
-
symbol: "
|
|
517
|
-
name: "
|
|
518
|
+
symbol: "weETH",
|
|
519
|
+
name: "Wrapped eETH",
|
|
518
520
|
decimals: 18,
|
|
519
521
|
address: "0xCb6B152D3a943f25157381aFcA7fEFCD2ef5a357",
|
|
520
522
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -522,8 +524,8 @@ var SodaTokens = {
|
|
|
522
524
|
vault: "0xCb6B152D3a943f25157381aFcA7fEFCD2ef5a357"
|
|
523
525
|
},
|
|
524
526
|
sodaWSTETH: {
|
|
525
|
-
symbol: "
|
|
526
|
-
name: "
|
|
527
|
+
symbol: "wstETH",
|
|
528
|
+
name: "Wrapped liquid staked Ether",
|
|
527
529
|
decimals: 18,
|
|
528
530
|
address: "0x58b0538D7EEaeE69EF32f9F1dE5cbF32A10a977B",
|
|
529
531
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -531,8 +533,8 @@ var SodaTokens = {
|
|
|
531
533
|
vault: "0x58b0538D7EEaeE69EF32f9F1dE5cbF32A10a977B"
|
|
532
534
|
},
|
|
533
535
|
sodaNEAR: {
|
|
534
|
-
symbol: "
|
|
535
|
-
name: "
|
|
536
|
+
symbol: "NEAR",
|
|
537
|
+
name: "NEAR Protocol",
|
|
536
538
|
decimals: 18,
|
|
537
539
|
address: "0xf4ba497c9b805e4bd88a8a9e6a7b8f74984c3e39",
|
|
538
540
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -540,8 +542,8 @@ var SodaTokens = {
|
|
|
540
542
|
vault: "0xf4ba497c9b805e4bd88a8a9e6a7b8f74984c3e39"
|
|
541
543
|
},
|
|
542
544
|
sodaKAIA: {
|
|
543
|
-
symbol: "
|
|
544
|
-
name: "
|
|
545
|
+
symbol: "KAIA",
|
|
546
|
+
name: "Kaia",
|
|
545
547
|
decimals: 18,
|
|
546
548
|
address: "0xD7d41b5f803b6A40F8A6eAa34E459A4564e39891",
|
|
547
549
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -549,8 +551,8 @@ var SodaTokens = {
|
|
|
549
551
|
vault: "0xD7d41b5f803b6A40F8A6eAa34E459A4564e39891"
|
|
550
552
|
},
|
|
551
553
|
sodaSTX: {
|
|
552
|
-
symbol: "
|
|
553
|
-
name: "
|
|
554
|
+
symbol: "STX",
|
|
555
|
+
name: "Stacks",
|
|
554
556
|
decimals: 18,
|
|
555
557
|
address: "0x1Fbe5229e9d189F26bEE77E5bFa24309FdA90483",
|
|
556
558
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -558,8 +560,8 @@ var SodaTokens = {
|
|
|
558
560
|
vault: "0x1Fbe5229e9d189F26bEE77E5bFa24309FdA90483"
|
|
559
561
|
},
|
|
560
562
|
sodaSUSDS: {
|
|
561
|
-
symbol: "
|
|
562
|
-
name: "
|
|
563
|
+
symbol: "sUSDS",
|
|
564
|
+
name: "Savings USDS",
|
|
563
565
|
decimals: 18,
|
|
564
566
|
address: "0x243b0c26c8b38793908d7C64e8510f21B19B4613",
|
|
565
567
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -567,8 +569,8 @@ var SodaTokens = {
|
|
|
567
569
|
vault: "0x243b0c26c8b38793908d7C64e8510f21B19B4613"
|
|
568
570
|
},
|
|
569
571
|
sodaHBAR: {
|
|
570
|
-
symbol: "
|
|
571
|
-
name: "
|
|
572
|
+
symbol: "HBAR",
|
|
573
|
+
name: "Hedera",
|
|
572
574
|
decimals: 18,
|
|
573
575
|
address: "0x3BB956cc8922E1Ba4148dc10eD1b4Fa19aa599c4",
|
|
574
576
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -576,8 +578,8 @@ var SodaTokens = {
|
|
|
576
578
|
vault: "0x3BB956cc8922E1Ba4148dc10eD1b4Fa19aa599c4"
|
|
577
579
|
},
|
|
578
580
|
sodaJITOSOL: {
|
|
579
|
-
symbol: "
|
|
580
|
-
name: "
|
|
581
|
+
symbol: "JitoSOL",
|
|
582
|
+
name: "Jito Staked SOL",
|
|
581
583
|
decimals: 18,
|
|
582
584
|
address: "0xe1bad4400d947Bc4fa66f9c0A143D800002083a0",
|
|
583
585
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -585,8 +587,8 @@ var SodaTokens = {
|
|
|
585
587
|
vault: "0xe1bad4400d947Bc4fa66f9c0A143D800002083a0"
|
|
586
588
|
},
|
|
587
589
|
sodaUSDS: {
|
|
588
|
-
symbol: "
|
|
589
|
-
name: "
|
|
590
|
+
symbol: "USDS",
|
|
591
|
+
name: "USDS",
|
|
590
592
|
decimals: 18,
|
|
591
593
|
address: "0xA3AeFa2BAfEAB479c4Aca6024A16906bbC75566e",
|
|
592
594
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -604,6 +606,7 @@ var SodaTokens = {
|
|
|
604
606
|
},
|
|
605
607
|
SPCX: {
|
|
606
608
|
symbol: "SPCX",
|
|
609
|
+
isRwa: true,
|
|
607
610
|
name: "Space Exploration Technologies Corp. Class A Common Stock \u2022 Robinhood Token",
|
|
608
611
|
decimals: 18,
|
|
609
612
|
address: "0xB585e2EEa070eB4E4D877A707aEC3B718edb2373",
|
|
@@ -613,6 +616,7 @@ var SodaTokens = {
|
|
|
613
616
|
},
|
|
614
617
|
NVDA: {
|
|
615
618
|
symbol: "NVDA",
|
|
619
|
+
isRwa: true,
|
|
616
620
|
name: "NVIDIA \u2022 Robinhood Token",
|
|
617
621
|
decimals: 18,
|
|
618
622
|
address: "0x2D5D2250EE426cA318efBd03ddf926B23c96f74B",
|
|
@@ -622,6 +626,7 @@ var SodaTokens = {
|
|
|
622
626
|
},
|
|
623
627
|
GME: {
|
|
624
628
|
symbol: "GME",
|
|
629
|
+
isRwa: true,
|
|
625
630
|
name: "GameStop \u2022 Robinhood Token",
|
|
626
631
|
decimals: 18,
|
|
627
632
|
address: "0x996e5591e4692e2B7d8fB6926DeA4EE1950Ef394",
|
|
@@ -631,6 +636,7 @@ var SodaTokens = {
|
|
|
631
636
|
},
|
|
632
637
|
MSTR: {
|
|
633
638
|
symbol: "MSTR",
|
|
639
|
+
isRwa: true,
|
|
634
640
|
name: "Strategy Inc. \u2022 Robinhood Token",
|
|
635
641
|
decimals: 18,
|
|
636
642
|
address: "0xE0E2aF45EBf5700a90E63c41B0ecE042A240Fab1",
|
|
@@ -640,6 +646,7 @@ var SodaTokens = {
|
|
|
640
646
|
},
|
|
641
647
|
AAPL: {
|
|
642
648
|
symbol: "AAPL",
|
|
649
|
+
isRwa: true,
|
|
643
650
|
name: "Apple \u2022 Robinhood Token",
|
|
644
651
|
decimals: 18,
|
|
645
652
|
address: "0x4712D2D49Ba3be41DA334FCB3616FDdc0d745185",
|
|
@@ -649,6 +656,7 @@ var SodaTokens = {
|
|
|
649
656
|
},
|
|
650
657
|
TSLA: {
|
|
651
658
|
symbol: "TSLA",
|
|
659
|
+
isRwa: true,
|
|
652
660
|
name: "Tesla \u2022 Robinhood Token",
|
|
653
661
|
decimals: 18,
|
|
654
662
|
address: "0x8B7F46967Ed9367A70b2e046D5e26a03625d53b1",
|
|
@@ -658,6 +666,7 @@ var SodaTokens = {
|
|
|
658
666
|
},
|
|
659
667
|
MU: {
|
|
660
668
|
symbol: "MU",
|
|
669
|
+
isRwa: true,
|
|
661
670
|
name: "Micron Technology \u2022 Robinhood Token",
|
|
662
671
|
decimals: 18,
|
|
663
672
|
address: "0x108147b16186B895344F5752468190B9EE0e3A22",
|
|
@@ -667,6 +676,7 @@ var SodaTokens = {
|
|
|
667
676
|
},
|
|
668
677
|
SNDK: {
|
|
669
678
|
symbol: "SNDK",
|
|
679
|
+
isRwa: true,
|
|
670
680
|
name: "Sandisk Corporation \u2022 Robinhood Token",
|
|
671
681
|
decimals: 18,
|
|
672
682
|
address: "0x568F29855B7B46EdA38ed95771FAeC498c507EF7",
|
|
@@ -676,6 +686,7 @@ var SodaTokens = {
|
|
|
676
686
|
},
|
|
677
687
|
SPY: {
|
|
678
688
|
symbol: "SPY",
|
|
689
|
+
isRwa: true,
|
|
679
690
|
name: "SPDR S&P 500 ETF Trust \u2022 Robinhood Token",
|
|
680
691
|
decimals: 18,
|
|
681
692
|
address: "0x1816E408f0448D0CaD3e0D490bd2590d921Bb0c8",
|
|
@@ -685,6 +696,7 @@ var SodaTokens = {
|
|
|
685
696
|
},
|
|
686
697
|
QQQ: {
|
|
687
698
|
symbol: "QQQ",
|
|
699
|
+
isRwa: true,
|
|
688
700
|
name: "Invesco QQQ \u2022 Robinhood Token",
|
|
689
701
|
decimals: 18,
|
|
690
702
|
address: "0x454ab3DeFd9df0749d450b145D4516e317E3e500",
|
|
@@ -694,6 +706,7 @@ var SodaTokens = {
|
|
|
694
706
|
},
|
|
695
707
|
SGOV: {
|
|
696
708
|
symbol: "SGOV",
|
|
709
|
+
isRwa: true,
|
|
697
710
|
name: "iShares 0-3 Month Treasury Bond \u2022 Robinhood Token",
|
|
698
711
|
decimals: 18,
|
|
699
712
|
address: "0xf6938087cf794B08739b926B41FF8F1E90816E74",
|
|
@@ -703,6 +716,7 @@ var SodaTokens = {
|
|
|
703
716
|
},
|
|
704
717
|
USO: {
|
|
705
718
|
symbol: "USO",
|
|
719
|
+
isRwa: true,
|
|
706
720
|
name: "United States Oil Fund \u2022 Robinhood Token",
|
|
707
721
|
decimals: 18,
|
|
708
722
|
address: "0x8DaBbADcecfc1a0B91fc68c72301090bc220D2bc",
|
|
@@ -712,6 +726,7 @@ var SodaTokens = {
|
|
|
712
726
|
},
|
|
713
727
|
SLV: {
|
|
714
728
|
symbol: "SLV",
|
|
729
|
+
isRwa: true,
|
|
715
730
|
name: "iShares Silver Trust \u2022 Robinhood Token",
|
|
716
731
|
decimals: 18,
|
|
717
732
|
address: "0x690B92c27ac80015E57DB8cc02A81255814f49A2",
|
|
@@ -1092,6 +1107,7 @@ var solanaSupportedTokens = {
|
|
|
1092
1107
|
},
|
|
1093
1108
|
CRCLx: {
|
|
1094
1109
|
symbol: "CRCLx",
|
|
1110
|
+
isRwa: true,
|
|
1095
1111
|
name: "Circle xStock",
|
|
1096
1112
|
decimals: 8,
|
|
1097
1113
|
address: "XsueG8BtpquVJX9LVLLEGuViXUungE6WmK5YZ3p3bd1",
|
|
@@ -1101,6 +1117,7 @@ var solanaSupportedTokens = {
|
|
|
1101
1117
|
},
|
|
1102
1118
|
TSLAx: {
|
|
1103
1119
|
symbol: "TSLAx",
|
|
1120
|
+
isRwa: true,
|
|
1104
1121
|
name: "Tesla xStock",
|
|
1105
1122
|
decimals: 8,
|
|
1106
1123
|
address: "XsDoVfqeBukxuZHWhdvWHBhgEHjGNst4MLodqsJHzoB",
|
|
@@ -1110,6 +1127,7 @@ var solanaSupportedTokens = {
|
|
|
1110
1127
|
},
|
|
1111
1128
|
SPYx: {
|
|
1112
1129
|
symbol: "SPYx",
|
|
1130
|
+
isRwa: true,
|
|
1113
1131
|
name: "SP500 xStock",
|
|
1114
1132
|
decimals: 8,
|
|
1115
1133
|
address: "XsoCS1TfEyfFhfvj8EtZ528L3CaKBDBRqRapnBbDF2W",
|
|
@@ -1119,6 +1137,7 @@ var solanaSupportedTokens = {
|
|
|
1119
1137
|
},
|
|
1120
1138
|
NVDAx: {
|
|
1121
1139
|
symbol: "NVDAx",
|
|
1140
|
+
isRwa: true,
|
|
1122
1141
|
name: "NVIDIA xStock",
|
|
1123
1142
|
decimals: 8,
|
|
1124
1143
|
address: "Xsc9qvGR1efVDFGLrVsmkzv3qi45LTBjeUKSPmx9qEh",
|
|
@@ -1128,6 +1147,7 @@ var solanaSupportedTokens = {
|
|
|
1128
1147
|
},
|
|
1129
1148
|
QQQx: {
|
|
1130
1149
|
symbol: "QQQx",
|
|
1150
|
+
isRwa: true,
|
|
1131
1151
|
name: "Nasdaq xStock",
|
|
1132
1152
|
decimals: 8,
|
|
1133
1153
|
address: "Xs8S1uUs1zvS2p7iwtsG3b6fkhpvmwz4GYU3gWAmWHZ",
|
|
@@ -1137,6 +1157,7 @@ var solanaSupportedTokens = {
|
|
|
1137
1157
|
},
|
|
1138
1158
|
MSTRx: {
|
|
1139
1159
|
symbol: "MSTRx",
|
|
1160
|
+
isRwa: true,
|
|
1140
1161
|
name: "MicroStrategy xStock",
|
|
1141
1162
|
decimals: 8,
|
|
1142
1163
|
address: "XsP7xzNPvEHS1m6qfanPUGjNmdnmsLKEoNAnHjdxxyZ",
|
|
@@ -1146,6 +1167,7 @@ var solanaSupportedTokens = {
|
|
|
1146
1167
|
},
|
|
1147
1168
|
COINx: {
|
|
1148
1169
|
symbol: "COINx",
|
|
1170
|
+
isRwa: true,
|
|
1149
1171
|
name: "Coinbase xStock",
|
|
1150
1172
|
decimals: 8,
|
|
1151
1173
|
address: "Xs7ZdzSHLU9ftNJsii5fCeJhoRWSC32SQGzGQtePxNu",
|
|
@@ -1155,6 +1177,7 @@ var solanaSupportedTokens = {
|
|
|
1155
1177
|
},
|
|
1156
1178
|
GOOGLx: {
|
|
1157
1179
|
symbol: "GOOGLx",
|
|
1180
|
+
isRwa: true,
|
|
1158
1181
|
name: "Alphabet xStock",
|
|
1159
1182
|
decimals: 8,
|
|
1160
1183
|
address: "XsCPL9dNWBMvFtTmwcCA5v3xWPSMEBCszbQdiLLq6aN",
|
|
@@ -1503,6 +1526,15 @@ var baseSupportedTokens = {
|
|
|
1503
1526
|
chainKey: ChainKeys.BASE_MAINNET,
|
|
1504
1527
|
hubAsset: "0x348e086ab6f424dfc575a325c28624ed23973173",
|
|
1505
1528
|
vault: "0x348e086ab6f424dfc575a325c28624ed23973173"
|
|
1529
|
+
},
|
|
1530
|
+
sUSDS: {
|
|
1531
|
+
symbol: "sUSDS",
|
|
1532
|
+
name: "staked USDS",
|
|
1533
|
+
decimals: 18,
|
|
1534
|
+
address: "0x5875eEE11Cf8398102FdAd704C9E96607675467a",
|
|
1535
|
+
chainKey: ChainKeys.BASE_MAINNET,
|
|
1536
|
+
hubAsset: "0x807cC73f69F1aCCC50511a0390A8544cEA71baA9",
|
|
1537
|
+
vault: SodaTokens.sodaSUSDS.address
|
|
1506
1538
|
}
|
|
1507
1539
|
};
|
|
1508
1540
|
var optimismSupportedTokens = {
|
|
@@ -1586,6 +1618,15 @@ var optimismSupportedTokens = {
|
|
|
1586
1618
|
chainKey: ChainKeys.OPTIMISM_MAINNET,
|
|
1587
1619
|
hubAsset: "0xd08375176410febee9cf4591532455a4cdfe4463",
|
|
1588
1620
|
vault: "0xd08375176410febee9cf4591532455a4cdfe4463"
|
|
1621
|
+
},
|
|
1622
|
+
sUSDS: {
|
|
1623
|
+
symbol: "sUSDS",
|
|
1624
|
+
name: "staked USDS",
|
|
1625
|
+
decimals: 18,
|
|
1626
|
+
address: "0xb5B2dc7fd34C249F4be7fB1fCea07950784229e0",
|
|
1627
|
+
chainKey: ChainKeys.OPTIMISM_MAINNET,
|
|
1628
|
+
hubAsset: "0xb9a9cb8A61D30a8F6b7E24491ab83f43E817b0E2",
|
|
1629
|
+
vault: SodaTokens.sodaSUSDS.address
|
|
1589
1630
|
}
|
|
1590
1631
|
};
|
|
1591
1632
|
var bscSupportedTokens = {
|
|
@@ -2323,6 +2364,7 @@ var stellarSupportedTokens = {
|
|
|
2323
2364
|
},
|
|
2324
2365
|
SPCX: {
|
|
2325
2366
|
symbol: "SPCX",
|
|
2367
|
+
isRwa: true,
|
|
2326
2368
|
name: "SpaceX Class A",
|
|
2327
2369
|
decimals: 7,
|
|
2328
2370
|
address: "CAI4HHAYO57QICZOZ4JF7R66RLGJRD7BGTX7H6MILCITVEYYEFRYFISK",
|
|
@@ -2332,6 +2374,7 @@ var stellarSupportedTokens = {
|
|
|
2332
2374
|
},
|
|
2333
2375
|
NVDA: {
|
|
2334
2376
|
symbol: "NVDA",
|
|
2377
|
+
isRwa: true,
|
|
2335
2378
|
name: "NVIDIA",
|
|
2336
2379
|
decimals: 7,
|
|
2337
2380
|
address: "CCQFCT4FHJURUQ4RQA4NHYW5GQRHCBDXF33ADXZRTDTDVGKOJO3ZPEMY",
|
|
@@ -2341,6 +2384,7 @@ var stellarSupportedTokens = {
|
|
|
2341
2384
|
},
|
|
2342
2385
|
GME: {
|
|
2343
2386
|
symbol: "GME",
|
|
2387
|
+
isRwa: true,
|
|
2344
2388
|
name: "GameStop",
|
|
2345
2389
|
decimals: 7,
|
|
2346
2390
|
address: "CAPSLSLCTFOZM22SUIPQENMM54T24GTDRHZ5STYAO6EYMK5GGGYVKWBX",
|
|
@@ -2350,6 +2394,7 @@ var stellarSupportedTokens = {
|
|
|
2350
2394
|
},
|
|
2351
2395
|
MSTR: {
|
|
2352
2396
|
symbol: "MSTR",
|
|
2397
|
+
isRwa: true,
|
|
2353
2398
|
name: "Strategy",
|
|
2354
2399
|
decimals: 7,
|
|
2355
2400
|
address: "CAFQQXZSECLJNU76OS2OKLJQJBQHYJCVAYZJ4KGEN7VHXH5BTGNLVQND",
|
|
@@ -2359,6 +2404,7 @@ var stellarSupportedTokens = {
|
|
|
2359
2404
|
},
|
|
2360
2405
|
AAPL: {
|
|
2361
2406
|
symbol: "AAPL",
|
|
2407
|
+
isRwa: true,
|
|
2362
2408
|
name: "Apple",
|
|
2363
2409
|
decimals: 7,
|
|
2364
2410
|
address: "CAZSFDNSSR2RKJ2LIIB2Y4G4WOSYYKC4646EUJ63PQLDDHOVQYZ4HDTK",
|
|
@@ -2368,6 +2414,7 @@ var stellarSupportedTokens = {
|
|
|
2368
2414
|
},
|
|
2369
2415
|
TSLA: {
|
|
2370
2416
|
symbol: "TSLA",
|
|
2417
|
+
isRwa: true,
|
|
2371
2418
|
name: "Tesla",
|
|
2372
2419
|
decimals: 7,
|
|
2373
2420
|
address: "CARLFQDI2S2FSYFB47AZLKGUFZVGBEUVNW77SCJHHHGL2KPGT3TN5PAB",
|
|
@@ -2377,6 +2424,7 @@ var stellarSupportedTokens = {
|
|
|
2377
2424
|
},
|
|
2378
2425
|
MU: {
|
|
2379
2426
|
symbol: "MU",
|
|
2427
|
+
isRwa: true,
|
|
2380
2428
|
name: "Micron",
|
|
2381
2429
|
decimals: 7,
|
|
2382
2430
|
address: "CBPTKA32BTUEX4VFAER6AUFWQZCWJKQAMLV2PMFFN7EHLGLJN4JWIZ3F",
|
|
@@ -2386,6 +2434,7 @@ var stellarSupportedTokens = {
|
|
|
2386
2434
|
},
|
|
2387
2435
|
SNDK: {
|
|
2388
2436
|
symbol: "SNDK",
|
|
2437
|
+
isRwa: true,
|
|
2389
2438
|
name: "SanDisk",
|
|
2390
2439
|
decimals: 7,
|
|
2391
2440
|
address: "CDXNTHFMGQM33UGQBSLZI3BV5UWW62QGZLCEKOXJKMFN2W3KQZKE3LTQ",
|
|
@@ -2395,6 +2444,7 @@ var stellarSupportedTokens = {
|
|
|
2395
2444
|
},
|
|
2396
2445
|
SPY: {
|
|
2397
2446
|
symbol: "SPY",
|
|
2447
|
+
isRwa: true,
|
|
2398
2448
|
name: "SPDR S&P 500 ETF Trust",
|
|
2399
2449
|
decimals: 7,
|
|
2400
2450
|
address: "CD3ZMWOS4PZS2RQITEHBOTS27DTDP4QKOK7IEO5IB64GQKHRJYTVL3SW",
|
|
@@ -2404,6 +2454,7 @@ var stellarSupportedTokens = {
|
|
|
2404
2454
|
},
|
|
2405
2455
|
QQQ: {
|
|
2406
2456
|
symbol: "QQQ",
|
|
2457
|
+
isRwa: true,
|
|
2407
2458
|
name: "Invesco QQQ Trust",
|
|
2408
2459
|
decimals: 7,
|
|
2409
2460
|
address: "CC7DQX43J2KBK5MJACQWTNHENIYB5GUVCFXGDKQWDLUWA4VKLOOU5PWB",
|
|
@@ -2413,6 +2464,7 @@ var stellarSupportedTokens = {
|
|
|
2413
2464
|
},
|
|
2414
2465
|
SGOV: {
|
|
2415
2466
|
symbol: "SGOV",
|
|
2467
|
+
isRwa: true,
|
|
2416
2468
|
name: "iShares 0-3 Month Treasury Bond ETF",
|
|
2417
2469
|
decimals: 7,
|
|
2418
2470
|
address: "CBQMRO2JTUJ6NXVBQ3XGJV34PDTXR34DD74TLLRCW5SV2CV2NN2VDMLH",
|
|
@@ -2422,6 +2474,7 @@ var stellarSupportedTokens = {
|
|
|
2422
2474
|
},
|
|
2423
2475
|
USO: {
|
|
2424
2476
|
symbol: "USO",
|
|
2477
|
+
isRwa: true,
|
|
2425
2478
|
name: "United States Oil Fund LP",
|
|
2426
2479
|
decimals: 7,
|
|
2427
2480
|
address: "CCFRCTIW5EK2OK626V6C4YRTJCKACIRDI2GHOKWM57ZXACK2ZTWWWLC7",
|
|
@@ -2431,6 +2484,7 @@ var stellarSupportedTokens = {
|
|
|
2431
2484
|
},
|
|
2432
2485
|
SLV: {
|
|
2433
2486
|
symbol: "SLV",
|
|
2487
|
+
isRwa: true,
|
|
2434
2488
|
name: "iShares Silver Trust",
|
|
2435
2489
|
decimals: 7,
|
|
2436
2490
|
address: "CBY3U32O5T2B555HNJLX6C6HW3O2FLRSJGH472UOOHT6H6ZMGMSSZTLW",
|
|
@@ -2874,6 +2928,7 @@ var ethereumSupportedTokens = {
|
|
|
2874
2928
|
},
|
|
2875
2929
|
PAXG: {
|
|
2876
2930
|
symbol: "PAXG",
|
|
2931
|
+
isRwa: true,
|
|
2877
2932
|
name: "PAX Gold",
|
|
2878
2933
|
decimals: 18,
|
|
2879
2934
|
address: "0x45804880De22913dAFE09f4980848ECE6EcbAf78",
|
|
@@ -2883,6 +2938,7 @@ var ethereumSupportedTokens = {
|
|
|
2883
2938
|
},
|
|
2884
2939
|
XAUt: {
|
|
2885
2940
|
symbol: "XAUt",
|
|
2941
|
+
isRwa: true,
|
|
2886
2942
|
name: "Tether Gold",
|
|
2887
2943
|
decimals: 6,
|
|
2888
2944
|
address: "0x68749665FF8D2d112Fa859AA293F07A622782F38",
|
|
@@ -2925,6 +2981,15 @@ var ethereumSupportedTokens = {
|
|
|
2925
2981
|
chainKey: ChainKeys.ETHEREUM_MAINNET,
|
|
2926
2982
|
hubAsset: "0x40bea4f921355a749f460760ba6f8edd78888164",
|
|
2927
2983
|
vault: "0x40bea4f921355a749f460760ba6f8edd78888164"
|
|
2984
|
+
},
|
|
2985
|
+
sUSDS: {
|
|
2986
|
+
symbol: "sUSDS",
|
|
2987
|
+
name: "staked USDS",
|
|
2988
|
+
decimals: 18,
|
|
2989
|
+
address: "0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD",
|
|
2990
|
+
chainKey: ChainKeys.ETHEREUM_MAINNET,
|
|
2991
|
+
hubAsset: "0x1Bb5128A4837A78cb60bc52cc19079eD3F00A624",
|
|
2992
|
+
vault: SodaTokens.sodaSUSDS.address
|
|
2928
2993
|
}
|
|
2929
2994
|
};
|
|
2930
2995
|
var kaiaSupportedTokens = {
|
|
@@ -3112,6 +3177,7 @@ var hederaSupportedTokens = {
|
|
|
3112
3177
|
},
|
|
3113
3178
|
SPCX: {
|
|
3114
3179
|
symbol: "SPCX",
|
|
3180
|
+
isRwa: true,
|
|
3115
3181
|
name: "SpaceX Class A",
|
|
3116
3182
|
decimals: 8,
|
|
3117
3183
|
address: "0x0000000000000000000000000000000000a5669e",
|
|
@@ -3121,6 +3187,7 @@ var hederaSupportedTokens = {
|
|
|
3121
3187
|
},
|
|
3122
3188
|
NVDA: {
|
|
3123
3189
|
symbol: "NVDA",
|
|
3190
|
+
isRwa: true,
|
|
3124
3191
|
name: "NVIDIA",
|
|
3125
3192
|
decimals: 8,
|
|
3126
3193
|
address: "0x0000000000000000000000000000000000a5669f",
|
|
@@ -3130,6 +3197,7 @@ var hederaSupportedTokens = {
|
|
|
3130
3197
|
},
|
|
3131
3198
|
GME: {
|
|
3132
3199
|
symbol: "GME",
|
|
3200
|
+
isRwa: true,
|
|
3133
3201
|
name: "GameStop",
|
|
3134
3202
|
decimals: 8,
|
|
3135
3203
|
address: "0x0000000000000000000000000000000000a567d9",
|
|
@@ -3139,6 +3207,7 @@ var hederaSupportedTokens = {
|
|
|
3139
3207
|
},
|
|
3140
3208
|
MSTR: {
|
|
3141
3209
|
symbol: "MSTR",
|
|
3210
|
+
isRwa: true,
|
|
3142
3211
|
name: "Strategy",
|
|
3143
3212
|
decimals: 8,
|
|
3144
3213
|
address: "0x0000000000000000000000000000000000a567e0",
|
|
@@ -3148,6 +3217,7 @@ var hederaSupportedTokens = {
|
|
|
3148
3217
|
},
|
|
3149
3218
|
AAPL: {
|
|
3150
3219
|
symbol: "AAPL",
|
|
3220
|
+
isRwa: true,
|
|
3151
3221
|
name: "Apple",
|
|
3152
3222
|
decimals: 8,
|
|
3153
3223
|
address: "0x0000000000000000000000000000000000a567e1",
|
|
@@ -3157,6 +3227,7 @@ var hederaSupportedTokens = {
|
|
|
3157
3227
|
},
|
|
3158
3228
|
TSLA: {
|
|
3159
3229
|
symbol: "TSLA",
|
|
3230
|
+
isRwa: true,
|
|
3160
3231
|
name: "Tesla",
|
|
3161
3232
|
decimals: 8,
|
|
3162
3233
|
address: "0x0000000000000000000000000000000000a567e2",
|
|
@@ -3166,6 +3237,7 @@ var hederaSupportedTokens = {
|
|
|
3166
3237
|
},
|
|
3167
3238
|
MU: {
|
|
3168
3239
|
symbol: "MU",
|
|
3240
|
+
isRwa: true,
|
|
3169
3241
|
name: "Micron",
|
|
3170
3242
|
decimals: 8,
|
|
3171
3243
|
address: "0x0000000000000000000000000000000000a567e3",
|
|
@@ -3175,6 +3247,7 @@ var hederaSupportedTokens = {
|
|
|
3175
3247
|
},
|
|
3176
3248
|
SNDK: {
|
|
3177
3249
|
symbol: "SNDK",
|
|
3250
|
+
isRwa: true,
|
|
3178
3251
|
name: "SanDisk",
|
|
3179
3252
|
decimals: 8,
|
|
3180
3253
|
address: "0x0000000000000000000000000000000000a567e5",
|
|
@@ -3184,6 +3257,7 @@ var hederaSupportedTokens = {
|
|
|
3184
3257
|
},
|
|
3185
3258
|
SPY: {
|
|
3186
3259
|
symbol: "SPY",
|
|
3260
|
+
isRwa: true,
|
|
3187
3261
|
name: "SPDR S&P 500 ETF Trust",
|
|
3188
3262
|
decimals: 8,
|
|
3189
3263
|
address: "0x0000000000000000000000000000000000a567e7",
|
|
@@ -3193,6 +3267,7 @@ var hederaSupportedTokens = {
|
|
|
3193
3267
|
},
|
|
3194
3268
|
QQQ: {
|
|
3195
3269
|
symbol: "QQQ",
|
|
3270
|
+
isRwa: true,
|
|
3196
3271
|
name: "Invesco QQQ Trust",
|
|
3197
3272
|
decimals: 8,
|
|
3198
3273
|
address: "0x0000000000000000000000000000000000a567ea",
|
|
@@ -3202,6 +3277,7 @@ var hederaSupportedTokens = {
|
|
|
3202
3277
|
},
|
|
3203
3278
|
SGOV: {
|
|
3204
3279
|
symbol: "SGOV",
|
|
3280
|
+
isRwa: true,
|
|
3205
3281
|
name: "iShares 0-3 Month Treasury Bond ETF",
|
|
3206
3282
|
decimals: 8,
|
|
3207
3283
|
address: "0x0000000000000000000000000000000000a567ec",
|
|
@@ -3211,6 +3287,7 @@ var hederaSupportedTokens = {
|
|
|
3211
3287
|
},
|
|
3212
3288
|
USO: {
|
|
3213
3289
|
symbol: "USO",
|
|
3290
|
+
isRwa: true,
|
|
3214
3291
|
name: "United States Oil Fund LP",
|
|
3215
3292
|
decimals: 8,
|
|
3216
3293
|
address: "0x0000000000000000000000000000000000a567ed",
|
|
@@ -3220,6 +3297,7 @@ var hederaSupportedTokens = {
|
|
|
3220
3297
|
},
|
|
3221
3298
|
SLV: {
|
|
3222
3299
|
symbol: "SLV",
|
|
3300
|
+
isRwa: true,
|
|
3223
3301
|
name: "iShares Silver Trust",
|
|
3224
3302
|
decimals: 8,
|
|
3225
3303
|
address: "0x0000000000000000000000000000000000a567f2",
|
|
@@ -3272,6 +3350,7 @@ var robinhoodSupportedTokens = {
|
|
|
3272
3350
|
// feed exists for them, so the solver cannot price or swap them.
|
|
3273
3351
|
SPCX: {
|
|
3274
3352
|
symbol: "SPCX",
|
|
3353
|
+
isRwa: true,
|
|
3275
3354
|
name: "SpaceX Class A",
|
|
3276
3355
|
decimals: 18,
|
|
3277
3356
|
address: "0x4a0E65A3EcceC6dBe60AE065F2e7bb85Fae35eEa",
|
|
@@ -3281,6 +3360,7 @@ var robinhoodSupportedTokens = {
|
|
|
3281
3360
|
},
|
|
3282
3361
|
NVDA: {
|
|
3283
3362
|
symbol: "NVDA",
|
|
3363
|
+
isRwa: true,
|
|
3284
3364
|
name: "NVIDIA",
|
|
3285
3365
|
decimals: 18,
|
|
3286
3366
|
address: "0xd0601CE157Db5bdC3162BbaC2a2C8aF5320D9EEC",
|
|
@@ -3290,6 +3370,7 @@ var robinhoodSupportedTokens = {
|
|
|
3290
3370
|
},
|
|
3291
3371
|
GME: {
|
|
3292
3372
|
symbol: "GME",
|
|
3373
|
+
isRwa: true,
|
|
3293
3374
|
name: "GameStop",
|
|
3294
3375
|
decimals: 18,
|
|
3295
3376
|
address: "0x1b0E319c6A659F002271B69dB8A7df2F911c153E",
|
|
@@ -3299,6 +3380,7 @@ var robinhoodSupportedTokens = {
|
|
|
3299
3380
|
},
|
|
3300
3381
|
MSTR: {
|
|
3301
3382
|
symbol: "MSTR",
|
|
3383
|
+
isRwa: true,
|
|
3302
3384
|
name: "Strategy",
|
|
3303
3385
|
decimals: 18,
|
|
3304
3386
|
address: "0xec262a75e413fAfD0dF80480274532C79D42da09",
|
|
@@ -3308,6 +3390,7 @@ var robinhoodSupportedTokens = {
|
|
|
3308
3390
|
},
|
|
3309
3391
|
AAPL: {
|
|
3310
3392
|
symbol: "AAPL",
|
|
3393
|
+
isRwa: true,
|
|
3311
3394
|
name: "Apple",
|
|
3312
3395
|
decimals: 18,
|
|
3313
3396
|
address: "0xaF3D76f1834A1d425780943C99Ea8A608f8a93f9",
|
|
@@ -3317,6 +3400,7 @@ var robinhoodSupportedTokens = {
|
|
|
3317
3400
|
},
|
|
3318
3401
|
TSLA: {
|
|
3319
3402
|
symbol: "TSLA",
|
|
3403
|
+
isRwa: true,
|
|
3320
3404
|
name: "Tesla",
|
|
3321
3405
|
decimals: 18,
|
|
3322
3406
|
address: "0x322F0929c4625eD5bAd873c95208D54E1c003b2d",
|
|
@@ -3326,6 +3410,7 @@ var robinhoodSupportedTokens = {
|
|
|
3326
3410
|
},
|
|
3327
3411
|
MU: {
|
|
3328
3412
|
symbol: "MU",
|
|
3413
|
+
isRwa: true,
|
|
3329
3414
|
name: "Micron",
|
|
3330
3415
|
decimals: 18,
|
|
3331
3416
|
address: "0xfF080c8ce2E5feadaCa0Da81314Ae59D232d4afD",
|
|
@@ -3335,6 +3420,7 @@ var robinhoodSupportedTokens = {
|
|
|
3335
3420
|
},
|
|
3336
3421
|
SNDK: {
|
|
3337
3422
|
symbol: "SNDK",
|
|
3423
|
+
isRwa: true,
|
|
3338
3424
|
name: "SanDisk",
|
|
3339
3425
|
decimals: 18,
|
|
3340
3426
|
address: "0xB90A19fF0Af67f7779afF50A882A9CfF42446400",
|
|
@@ -3344,6 +3430,7 @@ var robinhoodSupportedTokens = {
|
|
|
3344
3430
|
},
|
|
3345
3431
|
SPY: {
|
|
3346
3432
|
symbol: "SPY",
|
|
3433
|
+
isRwa: true,
|
|
3347
3434
|
name: "SPDR S&P 500 ETF Trust",
|
|
3348
3435
|
decimals: 18,
|
|
3349
3436
|
address: "0x117cc2133c37B721F49dE2A7a74833232B3B4C0C",
|
|
@@ -3353,6 +3440,7 @@ var robinhoodSupportedTokens = {
|
|
|
3353
3440
|
},
|
|
3354
3441
|
QQQ: {
|
|
3355
3442
|
symbol: "QQQ",
|
|
3443
|
+
isRwa: true,
|
|
3356
3444
|
name: "Invesco QQQ Trust",
|
|
3357
3445
|
decimals: 18,
|
|
3358
3446
|
address: "0xD5f3879160bc7c32ebb4dC785F8a4F505888de68",
|
|
@@ -3362,6 +3450,7 @@ var robinhoodSupportedTokens = {
|
|
|
3362
3450
|
},
|
|
3363
3451
|
SGOV: {
|
|
3364
3452
|
symbol: "SGOV",
|
|
3453
|
+
isRwa: true,
|
|
3365
3454
|
name: "iShares 0-3 Month Treasury Bond ETF",
|
|
3366
3455
|
decimals: 18,
|
|
3367
3456
|
address: "0x92FD66527192E3e61d4DDd13322Aa222DE86F9B5",
|
|
@@ -3371,6 +3460,7 @@ var robinhoodSupportedTokens = {
|
|
|
3371
3460
|
},
|
|
3372
3461
|
USO: {
|
|
3373
3462
|
symbol: "USO",
|
|
3463
|
+
isRwa: true,
|
|
3374
3464
|
name: "United States Oil Fund LP",
|
|
3375
3465
|
decimals: 18,
|
|
3376
3466
|
address: "0xa30FA36Db767ad9eD3f7a60fC79526fB4d56D344",
|
|
@@ -3380,6 +3470,7 @@ var robinhoodSupportedTokens = {
|
|
|
3380
3470
|
},
|
|
3381
3471
|
SLV: {
|
|
3382
3472
|
symbol: "SLV",
|
|
3473
|
+
isRwa: true,
|
|
3383
3474
|
name: "iShares Silver Trust",
|
|
3384
3475
|
decimals: 18,
|
|
3385
3476
|
address: "0x411eFb0E7f985935DAec3D4C3ebaEa0d0AD7D89f",
|
|
@@ -3459,6 +3550,16 @@ var supportedTokensByChain = {
|
|
|
3459
3550
|
[ChainKeys.HEDERA_MAINNET]: hederaSupportedTokens,
|
|
3460
3551
|
[ChainKeys.ROBINHOOD_MAINNET]: robinhoodSupportedTokens
|
|
3461
3552
|
};
|
|
3553
|
+
function isRealWorldAsset(token) {
|
|
3554
|
+
const registry = supportedTokensByChain;
|
|
3555
|
+
const chainTokens = registry[token.chainKey];
|
|
3556
|
+
if (!chainTokens)
|
|
3557
|
+
return false;
|
|
3558
|
+
const tokens = Object.values(chainTokens);
|
|
3559
|
+
const normalize2 = (address2) => /^0x[0-9a-f]{40}$/i.test(address2) ? address2.toLowerCase() : address2;
|
|
3560
|
+
const address = normalize2(token.address);
|
|
3561
|
+
return tokens.some((candidate) => normalize2(candidate.address) === address && candidate.isRwa === true);
|
|
3562
|
+
}
|
|
3462
3563
|
|
|
3463
3564
|
// ../types/dist/chains/chains.js
|
|
3464
3565
|
var RelayChainIdMap = {
|
|
@@ -3823,6 +3924,14 @@ var NEAR_CHAIN_KEYS = filterChainKeysByType("NEAR");
|
|
|
3823
3924
|
var NEAR_CHAIN_KEYS_SET = new Set(NEAR_CHAIN_KEYS);
|
|
3824
3925
|
var BITCOIN_CHAIN_KEYS = filterChainKeysByType("BITCOIN");
|
|
3825
3926
|
var BITCOIN_CHAIN_KEYS_SET = new Set(BITCOIN_CHAIN_KEYS);
|
|
3927
|
+
var BOUND_API_HOST = "https://svc.bound.exchange/api";
|
|
3928
|
+
var BOUND_COMPANION_HOSTS = {
|
|
3929
|
+
[BOUND_API_HOST]: {
|
|
3930
|
+
auth: "https://auth.bound.exchange/api",
|
|
3931
|
+
transactions: "https://api.radfi.co/api"
|
|
3932
|
+
}
|
|
3933
|
+
};
|
|
3934
|
+
var DEPRECATED_BOUND_HOSTS = ["https://api.bound.exchange/api"];
|
|
3826
3935
|
var spokeChainConfig = {
|
|
3827
3936
|
[ChainKeys.SONIC_MAINNET]: {
|
|
3828
3937
|
chain: baseChainInfo[ChainKeys.SONIC_MAINNET],
|
|
@@ -4029,7 +4138,8 @@ var spokeChainConfig = {
|
|
|
4029
4138
|
supportedTokens: bitcoinSupportedTokens,
|
|
4030
4139
|
radfi: {
|
|
4031
4140
|
walletMode: "TRADING",
|
|
4032
|
-
|
|
4141
|
+
// authUrl / transactionsUrl are intentionally absent: see BOUND_COMPANION_HOSTS.
|
|
4142
|
+
apiUrl: BOUND_API_HOST,
|
|
4033
4143
|
apiKey: "",
|
|
4034
4144
|
umsUrl: "https://api.ums.bound.exchange/api",
|
|
4035
4145
|
accessToken: "",
|
|
@@ -4488,7 +4598,8 @@ var moneyMarketSupportedTokens = {
|
|
|
4488
4598
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.cbBTC,
|
|
4489
4599
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.SODA,
|
|
4490
4600
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.USDT,
|
|
4491
|
-
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.USDS
|
|
4601
|
+
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.USDS,
|
|
4602
|
+
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.sUSDS
|
|
4492
4603
|
],
|
|
4493
4604
|
[ChainKeys.OPTIMISM_MAINNET]: [
|
|
4494
4605
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.ETH,
|
|
@@ -4497,7 +4608,8 @@ var moneyMarketSupportedTokens = {
|
|
|
4497
4608
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.wstETH,
|
|
4498
4609
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.weETH,
|
|
4499
4610
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.USDT,
|
|
4500
|
-
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.SODA
|
|
4611
|
+
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.SODA,
|
|
4612
|
+
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.sUSDS
|
|
4501
4613
|
],
|
|
4502
4614
|
[ChainKeys.POLYGON_MAINNET]: [
|
|
4503
4615
|
spokeChainConfig[ChainKeys.POLYGON_MAINNET].supportedTokens.POL,
|
|
@@ -4619,7 +4731,8 @@ var moneyMarketSupportedTokens = {
|
|
|
4619
4731
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.WBTC,
|
|
4620
4732
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.WBTC_LEGACY,
|
|
4621
4733
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.LL,
|
|
4622
|
-
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.USDS
|
|
4734
|
+
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.USDS,
|
|
4735
|
+
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.sUSDS
|
|
4623
4736
|
],
|
|
4624
4737
|
[ChainKeys.REDBELLY_MAINNET]: [
|
|
4625
4738
|
spokeChainConfig[ChainKeys.REDBELLY_MAINNET].supportedTokens.bnUSD,
|
|
@@ -4852,9 +4965,10 @@ var swapSupportedTokens = {
|
|
|
4852
4965
|
spokeChainConfig[ChainKeys.SONIC_MAINNET].supportedTokens.USDT,
|
|
4853
4966
|
spokeChainConfig[ChainKeys.SONIC_MAINNET].supportedTokens.wS,
|
|
4854
4967
|
spokeChainConfig[ChainKeys.SONIC_MAINNET].supportedTokens.SODA,
|
|
4855
|
-
|
|
4856
|
-
// Swap membership is per-vault, not every SodaTokens entry:
|
|
4857
|
-
//
|
|
4968
|
+
spokeChainConfig[ChainKeys.SONIC_MAINNET].supportedTokens.USSD,
|
|
4969
|
+
// Swap membership is per-vault, not every SodaTokens entry: sodaUSDS is the one wrapper the
|
|
4970
|
+
// production solver cannot route — a `/quote` against it returns `No path was found`, where
|
|
4971
|
+
// USSD, sodaUSSD and sodaSUSDS all return real prices — so it stays out until a path exists.
|
|
4858
4972
|
SodaTokens.sodaBNB,
|
|
4859
4973
|
SodaTokens.sodaAVAX,
|
|
4860
4974
|
SodaTokens.sodaETH,
|
|
@@ -4879,8 +4993,10 @@ var swapSupportedTokens = {
|
|
|
4879
4993
|
SodaTokens.sodaNEAR,
|
|
4880
4994
|
SodaTokens.sodaKAIA,
|
|
4881
4995
|
SodaTokens.sodaSTX,
|
|
4996
|
+
SodaTokens.sodaSUSDS,
|
|
4882
4997
|
SodaTokens.sodaHBAR,
|
|
4883
4998
|
SodaTokens.sodaJITOSOL,
|
|
4999
|
+
SodaTokens.sodaUSSD,
|
|
4884
5000
|
...Object.values(LsodaTokens),
|
|
4885
5001
|
// Robinhood tokenized equities — swap-only, deliberately absent from the money market.
|
|
4886
5002
|
SodaTokens.SPCX,
|
|
@@ -4914,6 +5030,7 @@ var swapSupportedTokens = {
|
|
|
4914
5030
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.tBTC,
|
|
4915
5031
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.USDC,
|
|
4916
5032
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.USDT,
|
|
5033
|
+
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.sUSDS,
|
|
4917
5034
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.ARB,
|
|
4918
5035
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.AAVE,
|
|
4919
5036
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.LINK,
|
|
@@ -4928,6 +5045,7 @@ var swapSupportedTokens = {
|
|
|
4928
5045
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.ETH,
|
|
4929
5046
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.weETH,
|
|
4930
5047
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.USDC,
|
|
5048
|
+
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.sUSDS,
|
|
4931
5049
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.wstETH,
|
|
4932
5050
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.cbBTC,
|
|
4933
5051
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.VIRTUAL,
|
|
@@ -4938,6 +5056,7 @@ var swapSupportedTokens = {
|
|
|
4938
5056
|
[ChainKeys.OPTIMISM_MAINNET]: [
|
|
4939
5057
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.ETH,
|
|
4940
5058
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.USDC,
|
|
5059
|
+
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.sUSDS,
|
|
4941
5060
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.wstETH,
|
|
4942
5061
|
// spokeChainConfig[OPTIMISM_MAINNET_CHAIN_ID].supportedTokens.weETH, // NOTE: Not Implemented
|
|
4943
5062
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.USDT,
|
|
@@ -5105,6 +5224,7 @@ var swapSupportedTokens = {
|
|
|
5105
5224
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.ETH,
|
|
5106
5225
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.bnUSD,
|
|
5107
5226
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.USDC,
|
|
5227
|
+
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.sUSDS,
|
|
5108
5228
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.USDT,
|
|
5109
5229
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.SODA,
|
|
5110
5230
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.LL,
|
|
@@ -5211,7 +5331,7 @@ var swapSupportedTokens = {
|
|
|
5211
5331
|
]
|
|
5212
5332
|
};
|
|
5213
5333
|
var stagingSwapSupportedTokens = {
|
|
5214
|
-
[ChainKeys.SONIC_MAINNET]: [
|
|
5334
|
+
[ChainKeys.SONIC_MAINNET]: [],
|
|
5215
5335
|
[ChainKeys.AVALANCHE_MAINNET]: [],
|
|
5216
5336
|
[ChainKeys.ARBITRUM_MAINNET]: [],
|
|
5217
5337
|
[ChainKeys.BASE_MAINNET]: [
|
|
@@ -5318,7 +5438,8 @@ var leverageYieldVaults = [
|
|
|
5318
5438
|
}
|
|
5319
5439
|
];
|
|
5320
5440
|
var leverageYieldConfig = {
|
|
5321
|
-
vaults: leverageYieldVaults
|
|
5441
|
+
vaults: leverageYieldVaults,
|
|
5442
|
+
positionFactory: "0xF8fB7F200B6545295e1729Cf254482d7c116031C"
|
|
5322
5443
|
};
|
|
5323
5444
|
|
|
5324
5445
|
// ../types/dist/sodax-config/sodax-config.js
|
|
@@ -5551,7 +5672,45 @@ function isValidWalletProviderForChainKey(chainKey, walletProvider) {
|
|
|
5551
5672
|
}
|
|
5552
5673
|
|
|
5553
5674
|
// ../types/dist/index.js
|
|
5554
|
-
var CONFIG_VERSION =
|
|
5675
|
+
var CONFIG_VERSION = 2020006;
|
|
5676
|
+
var RC_STABLE = 99;
|
|
5677
|
+
var MIN_CONFIG_VERSION = 1e6;
|
|
5678
|
+
var MAX_CONFIG_VERSION = 99999999;
|
|
5679
|
+
var VERSION_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-rc\.(0|[1-9]\d*))?$/;
|
|
5680
|
+
function configVersionFor(version) {
|
|
5681
|
+
const match = typeof version === "string" ? version.match(VERSION_PATTERN) : null;
|
|
5682
|
+
if (!match)
|
|
5683
|
+
return null;
|
|
5684
|
+
const major = Number(match[1]);
|
|
5685
|
+
const minor = Number(match[2]);
|
|
5686
|
+
const patch = Number(match[3]);
|
|
5687
|
+
const rc = match[4] === void 0 ? null : Number(match[4]);
|
|
5688
|
+
if (major < 1 || major > 99 || minor > 99 || patch > 99)
|
|
5689
|
+
return null;
|
|
5690
|
+
if (rc !== null && rc > 98)
|
|
5691
|
+
return null;
|
|
5692
|
+
return major * 1e6 + minor * 1e4 + patch * 100 + (rc === null ? RC_STABLE : rc);
|
|
5693
|
+
}
|
|
5694
|
+
var unpack = (value) => {
|
|
5695
|
+
const slot = value % 100;
|
|
5696
|
+
return {
|
|
5697
|
+
major: Math.floor(value / 1e6),
|
|
5698
|
+
minor: Math.floor(value / 1e4) % 100,
|
|
5699
|
+
patch: Math.floor(value / 100) % 100,
|
|
5700
|
+
rc: slot === RC_STABLE ? null : slot
|
|
5701
|
+
};
|
|
5702
|
+
};
|
|
5703
|
+
var render = ({ major, minor, patch, rc }) => `${major}.${minor}.${patch}${rc === null ? "" : `-rc.${rc}`}`;
|
|
5704
|
+
function parseConfigVersion(value) {
|
|
5705
|
+
if (!Number.isInteger(value) || value < MIN_CONFIG_VERSION || value > MAX_CONFIG_VERSION)
|
|
5706
|
+
return null;
|
|
5707
|
+
return unpack(value);
|
|
5708
|
+
}
|
|
5709
|
+
function formatConfigVersion(value) {
|
|
5710
|
+
const parsed = parseConfigVersion(value);
|
|
5711
|
+
return parsed === null ? null : render(parsed);
|
|
5712
|
+
}
|
|
5713
|
+
var SDK_VERSION = render(unpack(CONFIG_VERSION));
|
|
5555
5714
|
|
|
5556
5715
|
// src/shared/utils/resolveTimeoutMs.ts
|
|
5557
5716
|
function resolveTimeoutMs(timeout, fallbackMs) {
|
|
@@ -15486,11 +15645,15 @@ var ConfigService = class {
|
|
|
15486
15645
|
isMoneyMarketSupportedToken(chainId, token) {
|
|
15487
15646
|
return this.sodax.moneyMarket.supportedTokens[chainId].some((t) => t.address.toLowerCase() === token.toLowerCase());
|
|
15488
15647
|
}
|
|
15648
|
+
/**
|
|
15649
|
+
* Is `asset` one of the money-market reserve assets?
|
|
15650
|
+
*
|
|
15651
|
+
* The reserve set is built from `moneyMarketHubVaults`, so its members are hub **vault**
|
|
15652
|
+
* addresses. Query it with an `XToken.vault`; an `XToken.hubAsset` only matches for the Sonic
|
|
15653
|
+
* vault shares themselves, where `hubAsset === vault`.
|
|
15654
|
+
*/
|
|
15489
15655
|
isMoneyMarketReserveAsset(asset) {
|
|
15490
|
-
return this.
|
|
15491
|
-
}
|
|
15492
|
-
isMoneyMarketReserveHubAsset(hubAsset) {
|
|
15493
|
-
return this.moneyMarketReserveAssetsSet.has(hubAsset.toLowerCase());
|
|
15656
|
+
return this.moneyMarketReserveAssetsSet.has(asset.toLowerCase());
|
|
15494
15657
|
}
|
|
15495
15658
|
loadSodaxConfigDataStructures(sodaxConfig2) {
|
|
15496
15659
|
this.hubAssetToXTokenMap = new Map(
|
|
@@ -15639,7 +15802,7 @@ function mergeSodaxConfig(base2, override) {
|
|
|
15639
15802
|
}
|
|
15640
15803
|
function encodeContractCalls(calls) {
|
|
15641
15804
|
return encodeAbiParameters(parseAbiParameters("(address,uint256,bytes)[]"), [
|
|
15642
|
-
calls.map((
|
|
15805
|
+
calls.map((v10) => [v10.address, v10.value, v10.data])
|
|
15643
15806
|
]);
|
|
15644
15807
|
}
|
|
15645
15808
|
async function waitForTransactionReceipt(hash, provider) {
|
|
@@ -16823,10 +16986,17 @@ var RadfiApiError = class extends Error {
|
|
|
16823
16986
|
this.cause = body;
|
|
16824
16987
|
}
|
|
16825
16988
|
};
|
|
16989
|
+
var stripSlash = (url) => url.endsWith("/") ? url.slice(0, -1) : url;
|
|
16990
|
+
var normalizeUrl = (url) => {
|
|
16991
|
+
const trimmed = url?.trim();
|
|
16992
|
+
return trimmed ? stripSlash(trimmed) : void 0;
|
|
16993
|
+
};
|
|
16826
16994
|
var RadfiProvider = class {
|
|
16827
16995
|
config;
|
|
16996
|
+
hosts;
|
|
16828
16997
|
// Client-side runtime signer (e.g. a backend's HMAC closure). Holds no credential itself — the SDK
|
|
16829
|
-
// only keeps the reference and invokes it per outbound
|
|
16998
|
+
// only keeps the reference and invokes it per outbound Bound request, on every routed host.
|
|
16999
|
+
// UMS calls bypass `request()` and stay unsigned. See `RadfiOptions` / gh-831.
|
|
16830
17000
|
signer;
|
|
16831
17001
|
accessToken = "";
|
|
16832
17002
|
refreshToken = "";
|
|
@@ -16835,12 +17005,30 @@ var RadfiProvider = class {
|
|
|
16835
17005
|
this.signer = options?.signer;
|
|
16836
17006
|
this.accessToken = config.accessToken ?? "";
|
|
16837
17007
|
this.refreshToken = config.refreshToken ?? "";
|
|
16838
|
-
if (config.apiUrl.endsWith("/")) {
|
|
16839
|
-
this.config.apiUrl = config.apiUrl.slice(0, -1);
|
|
16840
|
-
}
|
|
16841
17008
|
if (config.umsUrl?.endsWith("/")) {
|
|
16842
17009
|
this.config.umsUrl = config.umsUrl.slice(0, -1);
|
|
16843
17010
|
}
|
|
17011
|
+
const api = normalizeUrl(config.apiUrl) ?? config.apiUrl;
|
|
17012
|
+
const companions = BOUND_COMPANION_HOSTS[api] ?? {};
|
|
17013
|
+
this.hosts = {
|
|
17014
|
+
api,
|
|
17015
|
+
auth: normalizeUrl(config.authUrl) ?? companions.auth ?? api,
|
|
17016
|
+
transactions: normalizeUrl(config.transactionsUrl) ?? companions.transactions ?? api
|
|
17017
|
+
};
|
|
17018
|
+
const packaged = BOUND_COMPANION_HOSTS[BOUND_API_HOST] ?? {};
|
|
17019
|
+
const replacementFor = {
|
|
17020
|
+
apiUrl: BOUND_API_HOST,
|
|
17021
|
+
authUrl: packaged.auth ?? BOUND_API_HOST,
|
|
17022
|
+
transactionsUrl: packaged.transactions ?? BOUND_API_HOST
|
|
17023
|
+
};
|
|
17024
|
+
for (const field of ["apiUrl", "authUrl", "transactionsUrl"]) {
|
|
17025
|
+
const url = normalizeUrl(config[field]);
|
|
17026
|
+
if (url && DEPRECATED_BOUND_HOSTS.includes(url)) {
|
|
17027
|
+
throw new Error(
|
|
17028
|
+
`Bound Exchange has retired ${url}. Set chains.bitcoin.radfi.${field} to ${replacementFor[field]}, or remove it to take the packaged default.`
|
|
17029
|
+
);
|
|
17030
|
+
}
|
|
17031
|
+
}
|
|
16844
17032
|
}
|
|
16845
17033
|
/**
|
|
16846
17034
|
* Authenticate with Bound Exchange: BIP322-sign a login message, then call the Bound Exchange API.
|
|
@@ -16891,7 +17079,7 @@ var RadfiProvider = class {
|
|
|
16891
17079
|
}
|
|
16892
17080
|
}
|
|
16893
17081
|
async authenticate(params) {
|
|
16894
|
-
const res = await this.request("/auth/authenticate", {
|
|
17082
|
+
const res = await this.request("auth", "/auth/authenticate", {
|
|
16895
17083
|
method: "POST",
|
|
16896
17084
|
body: JSON.stringify(params)
|
|
16897
17085
|
});
|
|
@@ -16906,7 +17094,7 @@ var RadfiProvider = class {
|
|
|
16906
17094
|
};
|
|
16907
17095
|
}
|
|
16908
17096
|
async refreshAccessToken(refreshToken) {
|
|
16909
|
-
const res = await this.request("/auth/refresh-token", {
|
|
17097
|
+
const res = await this.request("auth", "/auth/refresh-token", {
|
|
16910
17098
|
method: "POST",
|
|
16911
17099
|
body: JSON.stringify({ refreshToken })
|
|
16912
17100
|
});
|
|
@@ -16920,7 +17108,7 @@ var RadfiProvider = class {
|
|
|
16920
17108
|
};
|
|
16921
17109
|
}
|
|
16922
17110
|
async createTradingWallet(params, accessToken) {
|
|
16923
|
-
const res = await this.request("/wallets", {
|
|
17111
|
+
const res = await this.request("auth", "/wallets", {
|
|
16924
17112
|
method: "POST",
|
|
16925
17113
|
headers: {
|
|
16926
17114
|
Authorization: `Bearer ${this.resolveAuth(accessToken)}`
|
|
@@ -16934,7 +17122,7 @@ var RadfiProvider = class {
|
|
|
16934
17122
|
return body.data;
|
|
16935
17123
|
}
|
|
16936
17124
|
async getTradingWallet(userAddress) {
|
|
16937
|
-
const res = await this.request(`/wallets/details/${userAddress}`, {
|
|
17125
|
+
const res = await this.request("auth", `/wallets/details/${userAddress}`, {
|
|
16938
17126
|
method: "GET"
|
|
16939
17127
|
});
|
|
16940
17128
|
const body = await this.parseJsonBody(res, "Trading wallet not found");
|
|
@@ -16943,9 +17131,9 @@ var RadfiProvider = class {
|
|
|
16943
17131
|
}
|
|
16944
17132
|
return body.data;
|
|
16945
17133
|
}
|
|
16946
|
-
// UMS call: goes out unsigned even when a signer is configured.
|
|
16947
|
-
//
|
|
16948
|
-
//
|
|
17134
|
+
// UMS call: goes out unsigned even when a signer is configured. UMS is separate infrastructure
|
|
17135
|
+
// on `umsUrl`, outside the api/auth/transactions routing table, and does not verify the backend
|
|
17136
|
+
// signature — so this bypasses `request()`, which signs. Same for `getExpiredUtxos`. See gh-831.
|
|
16949
17137
|
async getBalance(address) {
|
|
16950
17138
|
if (!this.config.umsUrl) {
|
|
16951
17139
|
throw new Error("RadfiConfig.umsUrl is required for getBalance");
|
|
@@ -16976,7 +17164,7 @@ var RadfiProvider = class {
|
|
|
16976
17164
|
}
|
|
16977
17165
|
}
|
|
16978
17166
|
async createWithdrawTransaction(params, accessToken) {
|
|
16979
|
-
const res = await this.request("/sodax/transaction", {
|
|
17167
|
+
const res = await this.request("api", "/sodax/transaction", {
|
|
16980
17168
|
method: "POST",
|
|
16981
17169
|
headers: {
|
|
16982
17170
|
Authorization: `Bearer ${this.resolveAuth(accessToken)}`
|
|
@@ -17005,7 +17193,7 @@ var RadfiProvider = class {
|
|
|
17005
17193
|
* gets stuck (otherwise a stuck relay eventually refunds instead of completing the swap).
|
|
17006
17194
|
*/
|
|
17007
17195
|
async requestRadfiSignature(params, accessToken) {
|
|
17008
|
-
const res = await this.request("/sodax/transaction/sign", {
|
|
17196
|
+
const res = await this.request("api", "/sodax/transaction/sign", {
|
|
17009
17197
|
method: "POST",
|
|
17010
17198
|
headers: {
|
|
17011
17199
|
Authorization: `Bearer ${this.resolveAuth(accessToken)}`
|
|
@@ -17024,8 +17212,8 @@ var RadfiProvider = class {
|
|
|
17024
17212
|
/**
|
|
17025
17213
|
* Fetch expired (or near-expiry) UTXOs for a trading wallet address from UMS API.
|
|
17026
17214
|
*
|
|
17027
|
-
* UMS call — unsigned by design, like `getBalance`:
|
|
17028
|
-
*
|
|
17215
|
+
* UMS call — unsigned by design, like `getBalance`: UMS sits outside the api/auth/transactions
|
|
17216
|
+
* routing table, so it bypasses `request()` and a configured signer never runs.
|
|
17029
17217
|
*/
|
|
17030
17218
|
async getExpiredUtxos(tradingAddress, params) {
|
|
17031
17219
|
if (!this.config.umsUrl) {
|
|
@@ -17049,7 +17237,7 @@ var RadfiProvider = class {
|
|
|
17049
17237
|
* Returns a PSBT that needs to be signed by the user.
|
|
17050
17238
|
*/
|
|
17051
17239
|
async buildRenewUtxoTransaction(params, accessToken) {
|
|
17052
|
-
const res = await this.request("/transactions", {
|
|
17240
|
+
const res = await this.request("transactions", "/transactions", {
|
|
17053
17241
|
method: "POST",
|
|
17054
17242
|
headers: {
|
|
17055
17243
|
Authorization: `Bearer ${accessToken}`
|
|
@@ -17073,7 +17261,7 @@ var RadfiProvider = class {
|
|
|
17073
17261
|
* The user signs the PSBT first, then Bound Exchange co-signs and broadcasts.
|
|
17074
17262
|
*/
|
|
17075
17263
|
async signAndBroadcastRenewUtxo(params, accessToken) {
|
|
17076
|
-
const res = await this.request("/transactions/sign", {
|
|
17264
|
+
const res = await this.request("transactions", "/transactions/sign", {
|
|
17077
17265
|
method: "POST",
|
|
17078
17266
|
headers: {
|
|
17079
17267
|
Authorization: `Bearer ${accessToken}`
|
|
@@ -17097,7 +17285,7 @@ var RadfiProvider = class {
|
|
|
17097
17285
|
* Returns an unsigned PSBT for the user to sign.
|
|
17098
17286
|
*/
|
|
17099
17287
|
async withdrawToUser(params, accessToken) {
|
|
17100
|
-
const res = await this.request("/transactions", {
|
|
17288
|
+
const res = await this.request("transactions", "/transactions", {
|
|
17101
17289
|
method: "POST",
|
|
17102
17290
|
headers: {
|
|
17103
17291
|
Authorization: `Bearer ${accessToken}`
|
|
@@ -17117,7 +17305,7 @@ var RadfiProvider = class {
|
|
|
17117
17305
|
* Sign and broadcast a withdraw transaction via Bound Exchange.
|
|
17118
17306
|
*/
|
|
17119
17307
|
async signAndBroadcastWithdraw(params, accessToken) {
|
|
17120
|
-
const res = await this.request("/transactions/sign", {
|
|
17308
|
+
const res = await this.request("transactions", "/transactions/sign", {
|
|
17121
17309
|
method: "POST",
|
|
17122
17310
|
headers: {
|
|
17123
17311
|
Authorization: `Bearer ${accessToken}`
|
|
@@ -17145,7 +17333,7 @@ var RadfiProvider = class {
|
|
|
17145
17333
|
* Get max spendable amount for a withdraw transaction (amount after fee).
|
|
17146
17334
|
*/
|
|
17147
17335
|
async getMaxWithdrawable(params, accessToken) {
|
|
17148
|
-
const res = await this.request("/transactions/max-spent", {
|
|
17336
|
+
const res = await this.request("transactions", "/transactions/max-spent", {
|
|
17149
17337
|
method: "POST",
|
|
17150
17338
|
headers: {
|
|
17151
17339
|
Authorization: `Bearer ${accessToken}`
|
|
@@ -17206,9 +17394,10 @@ var RadfiProvider = class {
|
|
|
17206
17394
|
);
|
|
17207
17395
|
}
|
|
17208
17396
|
}
|
|
17209
|
-
async request(endpoint, options) {
|
|
17210
|
-
const
|
|
17211
|
-
|
|
17397
|
+
async request(host, endpoint, options) {
|
|
17398
|
+
const baseUrl = this.hosts[host];
|
|
17399
|
+
const signed = this.signer ? await this.signer({ method: options?.method ?? "GET", path: endpoint, baseUrl }) : void 0;
|
|
17400
|
+
return fetch(`${baseUrl}${endpoint}`, {
|
|
17212
17401
|
...options,
|
|
17213
17402
|
headers: {
|
|
17214
17403
|
"Content-Type": "application/json",
|
|
@@ -17876,7 +18065,7 @@ function hexToBytes2(hex) {
|
|
|
17876
18065
|
const al = hl / 2;
|
|
17877
18066
|
if (hl % 2)
|
|
17878
18067
|
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
17879
|
-
const
|
|
18068
|
+
const array3 = new Uint8Array(al);
|
|
17880
18069
|
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
17881
18070
|
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
17882
18071
|
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
@@ -17884,9 +18073,9 @@ function hexToBytes2(hex) {
|
|
|
17884
18073
|
const char = hex[hi] + hex[hi + 1];
|
|
17885
18074
|
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
17886
18075
|
}
|
|
17887
|
-
|
|
18076
|
+
array3[ai] = n1 * 16 + n2;
|
|
17888
18077
|
}
|
|
17889
|
-
return
|
|
18078
|
+
return array3;
|
|
17890
18079
|
}
|
|
17891
18080
|
function concatBytes(...arrays) {
|
|
17892
18081
|
let sum = 0;
|
|
@@ -18516,22 +18705,22 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
|
18516
18705
|
const byte0 = Uint8Array.of(0);
|
|
18517
18706
|
const byte1 = Uint8Array.of(1);
|
|
18518
18707
|
const _maxDrbgIters = 1e3;
|
|
18519
|
-
let
|
|
18708
|
+
let v10 = u8n(hashLen);
|
|
18520
18709
|
let k = u8n(hashLen);
|
|
18521
18710
|
let i = 0;
|
|
18522
18711
|
const reset = () => {
|
|
18523
|
-
|
|
18712
|
+
v10.fill(1);
|
|
18524
18713
|
k.fill(0);
|
|
18525
18714
|
i = 0;
|
|
18526
18715
|
};
|
|
18527
|
-
const h = (...msgs) => hmacFn(k, concatBytes(
|
|
18716
|
+
const h = (...msgs) => hmacFn(k, concatBytes(v10, ...msgs));
|
|
18528
18717
|
const reseed = (seed = NULL) => {
|
|
18529
18718
|
k = h(byte0, seed);
|
|
18530
|
-
|
|
18719
|
+
v10 = h();
|
|
18531
18720
|
if (seed.length === 0)
|
|
18532
18721
|
return;
|
|
18533
18722
|
k = h(byte1, seed);
|
|
18534
|
-
|
|
18723
|
+
v10 = h();
|
|
18535
18724
|
};
|
|
18536
18725
|
const gen = () => {
|
|
18537
18726
|
if (i++ >= _maxDrbgIters)
|
|
@@ -18539,10 +18728,10 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
|
18539
18728
|
let len = 0;
|
|
18540
18729
|
const out = [];
|
|
18541
18730
|
while (len < qByteLen) {
|
|
18542
|
-
|
|
18543
|
-
const sl =
|
|
18731
|
+
v10 = h();
|
|
18732
|
+
const sl = v10.slice();
|
|
18544
18733
|
out.push(sl);
|
|
18545
|
-
len +=
|
|
18734
|
+
len += v10.length;
|
|
18546
18735
|
}
|
|
18547
18736
|
return concatBytes(...out);
|
|
18548
18737
|
};
|
|
@@ -18557,18 +18746,18 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
|
18557
18746
|
};
|
|
18558
18747
|
return genUntil;
|
|
18559
18748
|
}
|
|
18560
|
-
function validateObject(
|
|
18561
|
-
if (!
|
|
18749
|
+
function validateObject(object4, fields = {}, optFields = {}) {
|
|
18750
|
+
if (!object4 || typeof object4 !== "object")
|
|
18562
18751
|
throw new Error("expected valid options object");
|
|
18563
18752
|
function checkField(fieldName, expectedType, isOpt) {
|
|
18564
|
-
const val =
|
|
18753
|
+
const val = object4[fieldName];
|
|
18565
18754
|
if (isOpt && val === void 0)
|
|
18566
18755
|
return;
|
|
18567
18756
|
const current = typeof val;
|
|
18568
18757
|
if (current !== expectedType || val === null)
|
|
18569
18758
|
throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
|
|
18570
18759
|
}
|
|
18571
|
-
const iter = (f, isOpt) => Object.entries(f).forEach(([k,
|
|
18760
|
+
const iter = (f, isOpt) => Object.entries(f).forEach(([k, v10]) => checkField(k, v10, isOpt));
|
|
18572
18761
|
iter(fields, false);
|
|
18573
18762
|
iter(optFields, true);
|
|
18574
18763
|
}
|
|
@@ -18607,12 +18796,12 @@ function pow2(x, power, modulo) {
|
|
|
18607
18796
|
}
|
|
18608
18797
|
return res;
|
|
18609
18798
|
}
|
|
18610
|
-
function invert(
|
|
18611
|
-
if (
|
|
18799
|
+
function invert(number4, modulo) {
|
|
18800
|
+
if (number4 === _0n2)
|
|
18612
18801
|
throw new Error("invert: expected non-zero number");
|
|
18613
18802
|
if (modulo <= _0n2)
|
|
18614
18803
|
throw new Error("invert: expected positive modulus, got " + modulo);
|
|
18615
|
-
let a = mod(
|
|
18804
|
+
let a = mod(number4, modulo);
|
|
18616
18805
|
let b = modulo;
|
|
18617
18806
|
let x = _0n2, u = _1n2;
|
|
18618
18807
|
while (a !== _0n2) {
|
|
@@ -18639,9 +18828,9 @@ function sqrt3mod4(Fp, n) {
|
|
|
18639
18828
|
function sqrt5mod8(Fp, n) {
|
|
18640
18829
|
const p5div8 = (Fp.ORDER - _5n) / _8n;
|
|
18641
18830
|
const n2 = Fp.mul(n, _2n);
|
|
18642
|
-
const
|
|
18643
|
-
const nv = Fp.mul(n,
|
|
18644
|
-
const i = Fp.mul(Fp.mul(nv, _2n),
|
|
18831
|
+
const v10 = Fp.pow(n2, p5div8);
|
|
18832
|
+
const nv = Fp.mul(n, v10);
|
|
18833
|
+
const i = Fp.mul(Fp.mul(nv, _2n), v10);
|
|
18645
18834
|
const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
|
|
18646
18835
|
assertIsSquare(Fp, root, n);
|
|
18647
18836
|
return root;
|
|
@@ -19116,27 +19305,27 @@ var wNAF = class {
|
|
|
19116
19305
|
assert0(n);
|
|
19117
19306
|
return acc;
|
|
19118
19307
|
}
|
|
19119
|
-
getPrecomputes(W, point,
|
|
19308
|
+
getPrecomputes(W, point, transform) {
|
|
19120
19309
|
let comp = pointPrecomputes.get(point);
|
|
19121
19310
|
if (!comp) {
|
|
19122
19311
|
comp = this.precomputeWindow(point, W);
|
|
19123
19312
|
if (W !== 1) {
|
|
19124
|
-
if (typeof
|
|
19125
|
-
comp =
|
|
19313
|
+
if (typeof transform === "function")
|
|
19314
|
+
comp = transform(comp);
|
|
19126
19315
|
pointPrecomputes.set(point, comp);
|
|
19127
19316
|
}
|
|
19128
19317
|
}
|
|
19129
19318
|
return comp;
|
|
19130
19319
|
}
|
|
19131
|
-
cached(point, scalar,
|
|
19320
|
+
cached(point, scalar, transform) {
|
|
19132
19321
|
const W = getW(point);
|
|
19133
|
-
return this.wNAF(W, this.getPrecomputes(W, point,
|
|
19322
|
+
return this.wNAF(W, this.getPrecomputes(W, point, transform), scalar);
|
|
19134
19323
|
}
|
|
19135
|
-
unsafe(point, scalar,
|
|
19324
|
+
unsafe(point, scalar, transform, prev) {
|
|
19136
19325
|
const W = getW(point);
|
|
19137
19326
|
if (W === 1)
|
|
19138
19327
|
return this._unsafeLadder(point, scalar, prev);
|
|
19139
|
-
return this.wNAFUnsafe(W, this.getPrecomputes(W, point,
|
|
19328
|
+
return this.wNAFUnsafe(W, this.getPrecomputes(W, point, transform), scalar, prev);
|
|
19140
19329
|
}
|
|
19141
19330
|
// We calculate precomputes for elliptic curve point multiplication
|
|
19142
19331
|
// using windowed method. This specifies window size and
|
|
@@ -19223,9 +19412,9 @@ function edwards(params, extraOpts = {}) {
|
|
|
19223
19412
|
validateObject(extraOpts, {}, { uvRatio: "function" });
|
|
19224
19413
|
const MASK = _2n2 << BigInt(Fn.BYTES * 8) - _1n4;
|
|
19225
19414
|
const modP = (n) => Fp.create(n);
|
|
19226
|
-
const uvRatio2 = extraOpts.uvRatio || ((u,
|
|
19415
|
+
const uvRatio2 = extraOpts.uvRatio || ((u, v10) => {
|
|
19227
19416
|
try {
|
|
19228
|
-
return { isValid: true, value: Fp.sqrt(Fp.div(u,
|
|
19417
|
+
return { isValid: true, value: Fp.sqrt(Fp.div(u, v10)) };
|
|
19229
19418
|
} catch (e) {
|
|
19230
19419
|
return { isValid: false, value: _0n4 };
|
|
19231
19420
|
}
|
|
@@ -19321,8 +19510,8 @@ function edwards(params, extraOpts = {}) {
|
|
|
19321
19510
|
aInRange("point.y", y, _0n4, max);
|
|
19322
19511
|
const y2 = modP(y * y);
|
|
19323
19512
|
const u = modP(y2 - _1n4);
|
|
19324
|
-
const
|
|
19325
|
-
let { isValid, value: x } = uvRatio2(u,
|
|
19513
|
+
const v10 = modP(d * y2 - a);
|
|
19514
|
+
let { isValid, value: x } = uvRatio2(u, v10);
|
|
19326
19515
|
if (!isValid)
|
|
19327
19516
|
throw new Error("bad point: invalid y coordinate");
|
|
19328
19517
|
const isXOdd = (x & _1n4) === _1n4;
|
|
@@ -19662,13 +19851,13 @@ function adjustScalarBytes(bytes) {
|
|
|
19662
19851
|
return bytes;
|
|
19663
19852
|
}
|
|
19664
19853
|
var ED25519_SQRT_M1 = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
|
|
19665
|
-
function uvRatio(u,
|
|
19854
|
+
function uvRatio(u, v10) {
|
|
19666
19855
|
const P = ed25519_CURVE_p;
|
|
19667
|
-
const v32 = mod(
|
|
19668
|
-
const v72 = mod(v32 * v32 *
|
|
19856
|
+
const v32 = mod(v10 * v10 * v10, P);
|
|
19857
|
+
const v72 = mod(v32 * v32 * v10, P);
|
|
19669
19858
|
const pow = ed25519_pow_2_252_3(u * v72).pow_p_5_8;
|
|
19670
19859
|
let x = mod(u * v32 * pow, P);
|
|
19671
|
-
const vx2 = mod(
|
|
19860
|
+
const vx2 = mod(v10 * x * x, P);
|
|
19672
19861
|
const root1 = x;
|
|
19673
19862
|
const root2 = mod(x * ED25519_SQRT_M1, P);
|
|
19674
19863
|
const useRoot1 = vx2 === u;
|
|
@@ -19999,7 +20188,7 @@ function findSeatPrice(validators, maxNumberOfSeats, minimumStakeRatio, protocol
|
|
|
19999
20188
|
return findSeatPriceForProtocolAfter49(validators, maxNumberOfSeats, minimumStakeRatio);
|
|
20000
20189
|
}
|
|
20001
20190
|
function findSeatPriceForProtocolBefore49(validators, numSeats) {
|
|
20002
|
-
const stakes = validators.map((
|
|
20191
|
+
const stakes = validators.map((v10) => BigInt(v10.stake)).sort(sortBigIntAsc);
|
|
20003
20192
|
const num = BigInt(numSeats);
|
|
20004
20193
|
const stakesSum = stakes.reduce((a, b) => a + b);
|
|
20005
20194
|
if (stakesSum < num) {
|
|
@@ -20028,7 +20217,7 @@ function findSeatPriceForProtocolAfter49(validators, maxNumberOfSeats, minimumSt
|
|
|
20028
20217
|
if (minimumStakeRatio.length != 2) {
|
|
20029
20218
|
throw Error("minimumStakeRatio should have 2 elements");
|
|
20030
20219
|
}
|
|
20031
|
-
const stakes = validators.map((
|
|
20220
|
+
const stakes = validators.map((v10) => BigInt(v10.stake)).sort(sortBigIntAsc);
|
|
20032
20221
|
const stakesSum = stakes.reduce((a, b) => a + b);
|
|
20033
20222
|
if (validators.length < maxNumberOfSeats) {
|
|
20034
20223
|
return stakesSum * BigInt(minimumStakeRatio[0]) / BigInt(minimumStakeRatio[1]);
|
|
@@ -20200,10 +20389,10 @@ var DER = {
|
|
|
20200
20389
|
if (length < 128)
|
|
20201
20390
|
throw new E("tlv.decode(long): not minimal encoding");
|
|
20202
20391
|
}
|
|
20203
|
-
const
|
|
20204
|
-
if (
|
|
20392
|
+
const v10 = data.subarray(pos, pos + length);
|
|
20393
|
+
if (v10.length !== length)
|
|
20205
20394
|
throw new E("tlv.decode: wrong value length");
|
|
20206
|
-
return { v:
|
|
20395
|
+
return { v: v10, l: data.subarray(pos + length) };
|
|
20207
20396
|
}
|
|
20208
20397
|
},
|
|
20209
20398
|
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
@@ -20771,9 +20960,9 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
20771
20960
|
extraEntropy: false
|
|
20772
20961
|
};
|
|
20773
20962
|
const hasLargeCofactor = CURVE_ORDER * _2n4 < Fp.ORDER;
|
|
20774
|
-
function isBiggerThanHalfOrder(
|
|
20963
|
+
function isBiggerThanHalfOrder(number4) {
|
|
20775
20964
|
const HALF = CURVE_ORDER >> _1n6;
|
|
20776
|
-
return
|
|
20965
|
+
return number4 > HALF;
|
|
20777
20966
|
}
|
|
20778
20967
|
function validateRS(title, num) {
|
|
20779
20968
|
if (!Fn.isValidNot0(num))
|
|
@@ -20956,8 +21145,8 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
20956
21145
|
const R = Point.BASE.multiplyUnsafe(u1).add(P.multiplyUnsafe(u2));
|
|
20957
21146
|
if (R.is0())
|
|
20958
21147
|
return false;
|
|
20959
|
-
const
|
|
20960
|
-
return
|
|
21148
|
+
const v10 = Fn.create(R.x);
|
|
21149
|
+
return v10 === r;
|
|
20961
21150
|
} catch (e) {
|
|
20962
21151
|
return false;
|
|
20963
21152
|
}
|
|
@@ -24849,6 +25038,7 @@ function isTimeoutError(error) {
|
|
|
24849
25038
|
return error instanceof Error && /timed?\s?out|timeout/i.test(error.message);
|
|
24850
25039
|
}
|
|
24851
25040
|
var DEFAULT_GET_COINS_LIMIT = 10;
|
|
25041
|
+
var LATEST_PACKAGE_ID_TIMEOUT_MS = 1e4;
|
|
24852
25042
|
function toSuiObjectOwner(owner) {
|
|
24853
25043
|
switch (owner?.$kind) {
|
|
24854
25044
|
case "AddressOwner":
|
|
@@ -24917,16 +25107,20 @@ var SuiGrpcTransport = class {
|
|
|
24917
25107
|
return effects.gasUsed;
|
|
24918
25108
|
}
|
|
24919
25109
|
async fetchLatestPackageId(objectId) {
|
|
24920
|
-
let
|
|
25110
|
+
let object4;
|
|
24921
25111
|
try {
|
|
24922
|
-
({ object:
|
|
25112
|
+
({ object: object4 } = await this.client.core.getObject({
|
|
25113
|
+
objectId,
|
|
25114
|
+
include: { json: true },
|
|
25115
|
+
signal: AbortSignal.timeout(LATEST_PACKAGE_ID_TIMEOUT_MS)
|
|
25116
|
+
}));
|
|
24923
25117
|
} catch (error) {
|
|
24924
25118
|
throw new Error("Failed to fetch asset manager id", { cause: error });
|
|
24925
25119
|
}
|
|
24926
|
-
if (!
|
|
25120
|
+
if (!object4) {
|
|
24927
25121
|
throw new Error("Asset manager id not found (no data)");
|
|
24928
25122
|
}
|
|
24929
|
-
const fields =
|
|
25123
|
+
const fields = object4.json;
|
|
24930
25124
|
if (!fields) {
|
|
24931
25125
|
throw new Error("Asset manager id not found (not a move object)");
|
|
24932
25126
|
}
|
|
@@ -24963,7 +25157,11 @@ var SuiSpokeService = class {
|
|
|
24963
25157
|
transport;
|
|
24964
25158
|
/** @deprecated Renamed to `transport`, and no longer a raw `@mysten/sui` client. */
|
|
24965
25159
|
publicClient;
|
|
24966
|
-
|
|
25160
|
+
/**
|
|
25161
|
+
* `latest_package_id` reads still in flight, keyed by chain. An entry is dropped as soon as its
|
|
25162
|
+
* read settles, so concurrent callers share one request while a later build always re-reads.
|
|
25163
|
+
*/
|
|
25164
|
+
assetManagerLookups = /* @__PURE__ */ new Map();
|
|
24967
25165
|
pollingIntervalMs;
|
|
24968
25166
|
maxTimeoutMs;
|
|
24969
25167
|
constructor(config) {
|
|
@@ -25025,10 +25223,19 @@ var SuiSpokeService = class {
|
|
|
25025
25223
|
};
|
|
25026
25224
|
}
|
|
25027
25225
|
async getAssetManagerAddress(chainId) {
|
|
25028
|
-
|
|
25029
|
-
|
|
25030
|
-
|
|
25031
|
-
|
|
25226
|
+
const { packageId, moduleId, stateId } = await this.resolveAssetManager(chainId);
|
|
25227
|
+
return `${packageId}::${moduleId}::${stateId}`;
|
|
25228
|
+
}
|
|
25229
|
+
/**
|
|
25230
|
+
* An upgraded Sui package lives at a new address and the superseded one aborts on
|
|
25231
|
+
* `enforce_version`, so the id is read per call and never held between two builds.
|
|
25232
|
+
*/
|
|
25233
|
+
async resolveAssetManager(chainId) {
|
|
25234
|
+
const inFlight = this.assetManagerLookups.get(chainId);
|
|
25235
|
+
if (inFlight) return inFlight;
|
|
25236
|
+
const lookup = this.fetchAssetManagerAddress(chainId).then((address) => this.splitAddress(address)).finally(() => this.assetManagerLookups.delete(chainId));
|
|
25237
|
+
this.assetManagerLookups.set(chainId, lookup);
|
|
25238
|
+
return lookup;
|
|
25032
25239
|
}
|
|
25033
25240
|
async viewContract(tx, packageId, module, functionName, args, typeArgs = [], sender) {
|
|
25034
25241
|
tx.moveCall({
|
|
@@ -25045,12 +25252,27 @@ var SuiSpokeService = class {
|
|
|
25045
25252
|
* @returns {Promise<TxReturnType<SuiChainKey, R>>} A promise that resolves to the transaction hash or raw transaction base64 string.
|
|
25046
25253
|
*/
|
|
25047
25254
|
async deposit(params) {
|
|
25255
|
+
const { tx, assetManager } = await this.buildDepositTransaction(params);
|
|
25256
|
+
if (params.raw === true) {
|
|
25257
|
+
return {
|
|
25258
|
+
from: params.srcAddress,
|
|
25259
|
+
to: `${assetManager.packageId}::${assetManager.moduleId}::transfer`,
|
|
25260
|
+
value: params.amount,
|
|
25261
|
+
data: tx.serialize()
|
|
25262
|
+
};
|
|
25263
|
+
}
|
|
25264
|
+
return params.walletProvider.signAndExecuteTxn(tx);
|
|
25265
|
+
}
|
|
25266
|
+
/** Both deposit paths build here, so the asset manager is resolved the same way for each. */
|
|
25267
|
+
async buildDepositTransaction(params) {
|
|
25048
25268
|
const { srcAddress: from, srcChainKey, token, to, amount, data = "0x" } = params;
|
|
25049
25269
|
const isNative = isNativeToken(srcChainKey, token);
|
|
25050
25270
|
const tx = new Transaction$1();
|
|
25051
|
-
const coin = isNative ? await this.getNativeCoin(tx, amount) : await this.getCoin(tx, token, amount, from);
|
|
25052
25271
|
const connection = this.splitAddress(this.config.getChainConfig(srcChainKey).addresses.connection);
|
|
25053
|
-
const assetManager =
|
|
25272
|
+
const [coin, assetManager] = await Promise.all([
|
|
25273
|
+
isNative ? this.getNativeCoin(tx, amount) : this.getCoin(tx, token, amount, from),
|
|
25274
|
+
this.resolveAssetManager(srcChainKey)
|
|
25275
|
+
]);
|
|
25054
25276
|
tx.moveCall({
|
|
25055
25277
|
target: `${assetManager.packageId}::${assetManager.moduleId}::transfer`,
|
|
25056
25278
|
typeArguments: [token],
|
|
@@ -25063,15 +25285,7 @@ var SuiSpokeService = class {
|
|
|
25063
25285
|
tx.pure(bcs.vector(bcs.u8()).serialize(fromHex(data, "bytes")))
|
|
25064
25286
|
]
|
|
25065
25287
|
});
|
|
25066
|
-
|
|
25067
|
-
return {
|
|
25068
|
-
from,
|
|
25069
|
-
to: `${assetManager.packageId}::${assetManager.moduleId}::transfer`,
|
|
25070
|
-
value: amount,
|
|
25071
|
-
data: tx.serialize()
|
|
25072
|
-
};
|
|
25073
|
-
}
|
|
25074
|
-
return params.walletProvider.signAndExecuteTxn(tx);
|
|
25288
|
+
return { tx, assetManager };
|
|
25075
25289
|
}
|
|
25076
25290
|
async sendMessage(params) {
|
|
25077
25291
|
const { srcAddress: from, srcChainKey, dstChainKey, dstAddress, payload } = params;
|
|
@@ -25111,7 +25325,7 @@ var SuiSpokeService = class {
|
|
|
25111
25325
|
* @returns {Promise<bigint>} The balance of the token.
|
|
25112
25326
|
*/
|
|
25113
25327
|
async getDeposit(params) {
|
|
25114
|
-
const assetmanager =
|
|
25328
|
+
const assetmanager = await this.resolveAssetManager(params.srcChainKey);
|
|
25115
25329
|
const tx = new Transaction$1();
|
|
25116
25330
|
const result = await this.viewContract(
|
|
25117
25331
|
tx,
|
|
@@ -29440,7 +29654,7 @@ function selectSolvedIntentPacket(packets, intentsContract) {
|
|
|
29440
29654
|
|
|
29441
29655
|
// src/swap/speed-tier.ts
|
|
29442
29656
|
var SPEED_TIER_SECONDS = {
|
|
29443
|
-
/** Either token
|
|
29657
|
+
/** Either token's vault is a money-market-reserve (sodaAsset). */
|
|
29444
29658
|
sodaAsset: 15,
|
|
29445
29659
|
/** Anything else / default. */
|
|
29446
29660
|
default: 35,
|
|
@@ -29458,7 +29672,7 @@ var secondsToTier = (seconds) => {
|
|
|
29458
29672
|
return "slow";
|
|
29459
29673
|
};
|
|
29460
29674
|
function estimateSwapSpeedTier({ srcToken, dstToken }, isSodaAssetRelated) {
|
|
29461
|
-
const eitherSodaAsset = isSodaAssetRelated(srcToken.
|
|
29675
|
+
const eitherSodaAsset = isSodaAssetRelated(srcToken.vault) || isSodaAssetRelated(dstToken.vault);
|
|
29462
29676
|
let estimatedSeconds = eitherSodaAsset ? SPEED_TIER_SECONDS.sodaAsset : SPEED_TIER_SECONDS.default;
|
|
29463
29677
|
if (isEthereumToken(srcToken) || isEthereumToken(dstToken)) {
|
|
29464
29678
|
estimatedSeconds += SPEED_TIER_SECONDS.ethereumPenalty;
|
|
@@ -29668,14 +29882,14 @@ var SwapService = class {
|
|
|
29668
29882
|
*/
|
|
29669
29883
|
async getDetailedStatus(params) {
|
|
29670
29884
|
try {
|
|
29671
|
-
const
|
|
29885
|
+
const record = await this.backendApi.swaps.getSubmitTxStatus({
|
|
29672
29886
|
txHash: params.srcTxHash,
|
|
29673
29887
|
srcChainKey: params.srcChainKey
|
|
29674
29888
|
});
|
|
29675
|
-
if (
|
|
29676
|
-
return { ok: true, value: { source: "backend", data:
|
|
29889
|
+
if (record.ok && record.value.success && !isBackendSubmitTxAbandoned(record.value.data)) {
|
|
29890
|
+
return { ok: true, value: { source: "backend", data: record.value.data } };
|
|
29677
29891
|
}
|
|
29678
|
-
const backendAnswered =
|
|
29892
|
+
const backendAnswered = record.ok || isSodaxError(record.error) && record.error.context?.status === 404;
|
|
29679
29893
|
const dstTxHash = await this.resolveHubTxHash(params, backendAnswered);
|
|
29680
29894
|
if (!dstTxHash.ok) return dstTxHash;
|
|
29681
29895
|
const solver = await this.resolveSolverStatus(
|
|
@@ -30499,13 +30713,13 @@ var SwapService = class {
|
|
|
30499
30713
|
getIntentRelayChainId(params.srcChainKey) === params.intent.srcChain,
|
|
30500
30714
|
`srcChainKey (${params.srcChainKey}) does not match intent.srcChain (${params.intent.srcChain}). Expected relay chain id ${getIntentRelayChainId(params.srcChainKey)}.`
|
|
30501
30715
|
);
|
|
30502
|
-
const
|
|
30716
|
+
const relayData = this.buildCancelRelayData(params.intent);
|
|
30503
30717
|
const coreParams = {
|
|
30504
30718
|
srcChainKey: params.srcChainKey,
|
|
30505
|
-
srcAddress:
|
|
30719
|
+
srcAddress: await this.resolveCancelSrcAddress(_params),
|
|
30506
30720
|
dstChainKey: HUB_CHAIN_KEY,
|
|
30507
|
-
dstAddress:
|
|
30508
|
-
payload:
|
|
30721
|
+
dstAddress: relayData.address,
|
|
30722
|
+
payload: relayData.payload,
|
|
30509
30723
|
skipSimulation: params.skipSimulation
|
|
30510
30724
|
};
|
|
30511
30725
|
const sendMessageParams = _params.raw ? {
|
|
@@ -30534,12 +30748,15 @@ var SwapService = class {
|
|
|
30534
30748
|
* 1. Calls `createCancelIntent` to broadcast the cancel transaction on the spoke chain.
|
|
30535
30749
|
* 2. Verifies the spoke transaction.
|
|
30536
30750
|
* 3. For non-hub source chains: submits to the relayer and polls until the cancel packet
|
|
30537
|
-
* is delivered to the hub.
|
|
30751
|
+
* is delivered to the hub. Solana submits the cancel payload alongside the tx (the spoke tx
|
|
30752
|
+
* only carries its hash) and Bitcoin relays its signed on-demand payload — see
|
|
30753
|
+
* {@link buildCancelRelayIdentity}. For hub source chains, the spoke tx hash is reused directly.
|
|
30538
30754
|
*
|
|
30539
30755
|
* @param _params - Cancel params including `srcChainKey`, the `intent`, wallet provider, and
|
|
30540
30756
|
* an optional `timeout` in milliseconds.
|
|
30541
30757
|
* @returns A `Result` containing `TxHashPair`:
|
|
30542
|
-
* - `srcChainTxHash` — cancel tx hash on the source spoke chain
|
|
30758
|
+
* - `srcChainTxHash` — cancel tx hash on the source spoke chain (Bitcoin: the relay's derived
|
|
30759
|
+
* `od:<hash>` id, since an on-demand cancel broadcasts no spoke tx).
|
|
30543
30760
|
* - `dstChainTxHash` — hub-chain (Sonic) tx hash confirming the cancellation.
|
|
30544
30761
|
*/
|
|
30545
30762
|
async cancelIntent(_params) {
|
|
@@ -30553,41 +30770,100 @@ var SwapService = class {
|
|
|
30553
30770
|
chainKey: params.srcChainKey
|
|
30554
30771
|
});
|
|
30555
30772
|
if (!verifyTxHashResult.ok) return verifyTxHashResult;
|
|
30556
|
-
|
|
30557
|
-
|
|
30558
|
-
const intentRelayChainId = params.intent.srcChain.toString();
|
|
30559
|
-
const submitPayload = {
|
|
30560
|
-
action: "submit",
|
|
30561
|
-
params: {
|
|
30562
|
-
chain_id: intentRelayChainId,
|
|
30563
|
-
tx_hash: cancelTxHash
|
|
30564
|
-
}
|
|
30565
|
-
};
|
|
30566
|
-
const submitResult = await this.submitIntent(submitPayload);
|
|
30567
|
-
if (!submitResult.ok) return submitResult;
|
|
30568
|
-
const packet = await waitUntilIntentExecuted({
|
|
30569
|
-
intentRelayChainId,
|
|
30570
|
-
srcTxHash: cancelTxHash,
|
|
30571
|
-
timeout: _params.timeout,
|
|
30572
|
-
apiUrl: this.relayerApiEndpoint
|
|
30573
|
-
});
|
|
30574
|
-
if (!packet.ok) return packet;
|
|
30575
|
-
dstIntentTxHash = packet.value.dst_tx_hash;
|
|
30576
|
-
} else {
|
|
30577
|
-
dstIntentTxHash = cancelTxHash;
|
|
30773
|
+
if (isHubChainKey(params.srcChainKey)) {
|
|
30774
|
+
return { ok: true, value: { srcChainTxHash: cancelTxHash, dstChainTxHash: cancelTxHash } };
|
|
30578
30775
|
}
|
|
30579
|
-
|
|
30776
|
+
const relayIdentity = this.buildCancelRelayIdentity(params.srcChainKey, cancelTxHash, params.intent);
|
|
30777
|
+
const packet = await relayTxAndWaitPacket({
|
|
30778
|
+
...relayIdentity,
|
|
30779
|
+
chainKey: params.srcChainKey,
|
|
30780
|
+
relayerApiEndpoint: this.relayerApiEndpoint,
|
|
30781
|
+
timeout: _params.timeout
|
|
30782
|
+
});
|
|
30783
|
+
if (!packet.ok) return packet;
|
|
30784
|
+
return {
|
|
30785
|
+
ok: true,
|
|
30786
|
+
value: {
|
|
30787
|
+
srcChainTxHash: relayIdentity.pollTxHash ?? cancelTxHash,
|
|
30788
|
+
dstChainTxHash: packet.value.dst_tx_hash
|
|
30789
|
+
}
|
|
30790
|
+
};
|
|
30580
30791
|
} catch (error) {
|
|
30581
30792
|
if (isSwapError(error)) return { ok: false, error };
|
|
30582
30793
|
return { ok: false, error: executionFailed("swap", error, { action: "cancelIntent" }) };
|
|
30583
30794
|
}
|
|
30584
30795
|
}
|
|
30796
|
+
/**
|
|
30797
|
+
* Source address the cancel `sendMessage` originates from.
|
|
30798
|
+
*
|
|
30799
|
+
* Every chain but Bitcoin signs from the address stored on the intent. A Bitcoin TRADING-mode intent
|
|
30800
|
+
* stores the trading address, yet the spoke layer expects the personal wallet: it re-derives the
|
|
30801
|
+
* trading wallet from it and picks the message-signing scheme from its address type. So Bitcoin
|
|
30802
|
+
* TRADING takes `params.srcAddress`, else the wallet provider's address (raw has no provider).
|
|
30803
|
+
*/
|
|
30804
|
+
async resolveCancelSrcAddress(_params) {
|
|
30805
|
+
const { params } = _params;
|
|
30806
|
+
if (params.srcAddress !== void 0) return params.srcAddress;
|
|
30807
|
+
if (isBitcoinChainKeyType(params.srcChainKey) && this.spoke.bitcoin.walletMode === "TRADING") {
|
|
30808
|
+
const walletProvider = _params.walletProvider;
|
|
30809
|
+
invariant(
|
|
30810
|
+
walletProvider !== void 0 && isBitcoinWalletProviderType(walletProvider),
|
|
30811
|
+
"Bitcoin TRADING-mode cancel needs the personal wallet address: pass params.srcAddress for raw: true"
|
|
30812
|
+
);
|
|
30813
|
+
return await walletProvider.getWalletAddress();
|
|
30814
|
+
}
|
|
30815
|
+
return reverseEncodeAddress(params.srcChainKey, params.intent.srcAddress);
|
|
30816
|
+
}
|
|
30817
|
+
/**
|
|
30818
|
+
* Relay extra data (`{ address, payload }`) for cancelling `intent`, for callers that relay a
|
|
30819
|
+
* `createCancelIntent` transaction themselves (`raw` mode or manual relay control).
|
|
30820
|
+
*
|
|
30821
|
+
* Solana commits only the hash of the cancel payload on-chain, so the relayer needs this alongside
|
|
30822
|
+
* the spoke tx; other chains ignore it. It is the cancel counterpart of {@link reconstructRelayData}:
|
|
30823
|
+
* the create-intent extra data does not match a cancel tx. Bitcoin cancels are on-demand instead —
|
|
30824
|
+
* relay the signed payload `createCancelIntent` returns via `BitcoinSpokeService.getOnDemandRelayIdentity`.
|
|
30825
|
+
*
|
|
30826
|
+
* @param intent - The intent being cancelled (e.g. from `getIntent(txHash)`).
|
|
30827
|
+
* @returns A `Result` containing `RelayExtraData`: `{ address: Hex; payload: Hex }`.
|
|
30828
|
+
*/
|
|
30829
|
+
getCancelIntentRelayData(intent) {
|
|
30830
|
+
try {
|
|
30831
|
+
invariant(this.config.isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
|
|
30832
|
+
return { ok: true, value: this.buildCancelRelayData(intent) };
|
|
30833
|
+
} catch (error) {
|
|
30834
|
+
return { ok: false, error };
|
|
30835
|
+
}
|
|
30836
|
+
}
|
|
30837
|
+
/**
|
|
30838
|
+
* Relay extra data for a cancel: the hub wallet that owns the intent and the `cancelIntent` call it
|
|
30839
|
+
* executes. This is exactly what `createCancelIntent` sends on-chain, so split-tx chains (Solana),
|
|
30840
|
+
* whose spoke tx carries only the payload hash, can hand the relayer the full payload.
|
|
30841
|
+
*/
|
|
30842
|
+
buildCancelRelayData(intent) {
|
|
30843
|
+
return {
|
|
30844
|
+
address: intent.creator,
|
|
30845
|
+
payload: encodeContractCalls([EvmSolverService.encodeCancelIntent(intent, this.solver.intentsContract)])
|
|
30846
|
+
};
|
|
30847
|
+
}
|
|
30848
|
+
/**
|
|
30849
|
+
* Relay submit/poll identity for a cancel, mirroring the money market's on-demand handling.
|
|
30850
|
+
*
|
|
30851
|
+
* A Bitcoin cancel broadcasts no spoke tx: `sendMessage` returns a signed payload JSON that the relay
|
|
30852
|
+
* accepts under the literal `withdraw` tx_hash and tracks under a derived `od:<hash>` id (see
|
|
30853
|
+
* {@link BitcoinSpokeService.getOnDemandRelayIdentity}). Every other chain relays and polls by its
|
|
30854
|
+
* spoke tx hash and passes the cancel relay data, which the relayer needs on Solana and ignores elsewhere.
|
|
30855
|
+
*/
|
|
30856
|
+
buildCancelRelayIdentity(srcChainKey, tx, intent) {
|
|
30857
|
+
return isBitcoinChainKeyType(srcChainKey) ? this.spoke.bitcoin.getOnDemandRelayIdentity(tx) : { srcTxHash: tx, data: this.buildCancelRelayData(intent), pollTxHash: void 0 };
|
|
30858
|
+
}
|
|
30585
30859
|
/**
|
|
30586
30860
|
* Returns the relay extra data (`address` + `payload`) required to submit an intent to the relayer API.
|
|
30587
30861
|
*
|
|
30588
|
-
*
|
|
30589
|
-
*
|
|
30590
|
-
* `
|
|
30862
|
+
* Only required when the source chain is Solana or Bitcoin, whose deposits commit a hash of the relay
|
|
30863
|
+
* payload on-chain, so the relayer needs the exact bytes bundled with the submission. For an intent
|
|
30864
|
+
* created by {@link SwapService.createIntent} the payload is byte-identical to the `relayData` that
|
|
30865
|
+
* call returned; see {@link SwapService.reconstructRelayData}, which this delegates to, for the
|
|
30866
|
+
* derivation and the one intent shape it cannot reconstruct.
|
|
30591
30867
|
*
|
|
30592
30868
|
* Accepts either a hub-chain tx hash (will fetch the intent on-chain first) or a
|
|
30593
30869
|
* pre-fetched `Intent` object directly.
|
|
@@ -30596,35 +30872,28 @@ var SwapService = class {
|
|
|
30596
30872
|
* @returns A `Result` containing `RelayExtraData`: `{ address: Hex; payload: Hex }`.
|
|
30597
30873
|
*/
|
|
30598
30874
|
async getIntentSubmitTxExtraData(params) {
|
|
30599
|
-
|
|
30600
|
-
|
|
30601
|
-
if (
|
|
30602
|
-
|
|
30603
|
-
if (!intentResult.ok) return intentResult;
|
|
30604
|
-
intent = intentResult.value;
|
|
30605
|
-
} else {
|
|
30606
|
-
intent = params.intent;
|
|
30607
|
-
}
|
|
30608
|
-
const txData = EvmSolverService.encodeCreateIntent(intent, this.solver.intentsContract);
|
|
30609
|
-
return {
|
|
30610
|
-
ok: true,
|
|
30611
|
-
value: {
|
|
30612
|
-
address: intent.creator,
|
|
30613
|
-
payload: txData.data
|
|
30614
|
-
}
|
|
30615
|
-
};
|
|
30616
|
-
} catch (error) {
|
|
30617
|
-
return { ok: false, error };
|
|
30875
|
+
if ("txHash" in params) {
|
|
30876
|
+
const intentResult = await this.getIntent(params.txHash);
|
|
30877
|
+
if (!intentResult.ok) return intentResult;
|
|
30878
|
+
return this.reconstructRelayData(intentResult.value);
|
|
30618
30879
|
}
|
|
30880
|
+
return this.reconstructRelayData(params.intent);
|
|
30619
30881
|
}
|
|
30620
30882
|
/**
|
|
30621
|
-
* Re-derives the byte-identical relay extra data (`{ address, payload }`) for
|
|
30622
|
-
*
|
|
30883
|
+
* Re-derives the byte-identical relay extra data (`{ address, payload }`) for an intent created by
|
|
30884
|
+
* {@link SwapService.createIntent} (or `swap` / `createLimitOrderIntent`) from a fully-populated
|
|
30885
|
+
* `Intent` alone — no on-chain call, no original `createIntent` return value needed.
|
|
30623
30886
|
*
|
|
30624
30887
|
* The `payload` matches exactly what `createIntent` relayed when the intent was first created:
|
|
30625
30888
|
* - Sonic-hub source — raw `createIntent(intent)` calldata.
|
|
30626
30889
|
* - Any spoke source — the `[approve, createIntent]` multicall (uniform across all spokes).
|
|
30627
30890
|
*
|
|
30891
|
+
* Not reconstructable: a `LeverageYieldService.vaultSwap` / `createVaultIntent` intent with
|
|
30892
|
+
* `hubWalletSwap`. Its `srcChain` is the hub while the relayed payload is the spoke multicall sent
|
|
30893
|
+
* through `sendMessage`, so it is indistinguishable here from a Sonic-source swap and would yield raw
|
|
30894
|
+
* `createIntent` calldata. Keep the `relayData` that call returned, or use
|
|
30895
|
+
* `sodax.api.leverageYield.getIntentSubmitTxExtraData`.
|
|
30896
|
+
*
|
|
30628
30897
|
* Byte-identity is possible because the only originally-random field, `intentId`, is already
|
|
30629
30898
|
* carried on the `Intent`; everything else in the payload is a pure function of the intent and
|
|
30630
30899
|
* the configured intents contract. Use this to rebuild relay submission data for a manual relay
|
|
@@ -30762,7 +31031,7 @@ var SwapService = class {
|
|
|
30762
31031
|
/**
|
|
30763
31032
|
* Offline, rule-based estimate of how fast a `srcToken`→`dstToken` swap will settle.
|
|
30764
31033
|
*
|
|
30765
|
-
* Derived purely from SDK config (no network / on-chain / backend call): tokens
|
|
31034
|
+
* Derived purely from SDK config (no network / on-chain / backend call): tokens whose vault is a
|
|
30766
31035
|
* money-market-reserve sodaAsset settle faster, and an Ethereum leg adds a fixed penalty. See
|
|
30767
31036
|
* {@link estimateSwapSpeedTier} for the rules.
|
|
30768
31037
|
*
|
|
@@ -30770,7 +31039,7 @@ var SwapService = class {
|
|
|
30770
31039
|
* @returns the estimated `tier` bucket and `estimatedSeconds`
|
|
30771
31040
|
*/
|
|
30772
31041
|
getSwapSpeedTier(params) {
|
|
30773
|
-
return estimateSwapSpeedTier(params, (
|
|
31042
|
+
return estimateSwapSpeedTier(params, (vault) => this.config.isMoneyMarketReserveAsset(vault));
|
|
30774
31043
|
}
|
|
30775
31044
|
};
|
|
30776
31045
|
|
|
@@ -33270,173 +33539,6 @@ var SponsoringApiService = class {
|
|
|
33270
33539
|
return this.config.baseURL;
|
|
33271
33540
|
}
|
|
33272
33541
|
};
|
|
33273
|
-
var RelayExtraDataResponseSchema = v.object({
|
|
33274
|
-
address: v.string(),
|
|
33275
|
-
payload: v.string()
|
|
33276
|
-
});
|
|
33277
|
-
var BridgeTokenSchema = v.object({
|
|
33278
|
-
symbol: v.string(),
|
|
33279
|
-
name: v.string(),
|
|
33280
|
-
decimals: v.number(),
|
|
33281
|
-
address: v.string(),
|
|
33282
|
-
chainKey: v.string(),
|
|
33283
|
-
hubAsset: v.string(),
|
|
33284
|
-
vault: v.string()
|
|
33285
|
-
});
|
|
33286
|
-
var BridgeTokensResponseSchema = v.record(v.string(), v.array(BridgeTokenSchema));
|
|
33287
|
-
var BridgeTokensByChainResponseSchema = v.array(BridgeTokenSchema);
|
|
33288
|
-
var BridgeAllowanceCheckResponseSchema = v.object({
|
|
33289
|
-
valid: v.boolean()
|
|
33290
|
-
});
|
|
33291
|
-
var makeBridgeApproveResponseSchema = (txSchema) => v.object({ tx: txSchema, resetTx: v.optional(txSchema) });
|
|
33292
|
-
var makeCreateBridgeIntentResponseSchema = (txSchema) => v.object({
|
|
33293
|
-
tx: txSchema,
|
|
33294
|
-
relayData: RelayExtraDataResponseSchema
|
|
33295
|
-
});
|
|
33296
|
-
var BridgeSubmitTxResponseSchema = v.object({
|
|
33297
|
-
success: v.boolean(),
|
|
33298
|
-
data: v.object({
|
|
33299
|
-
status: v.picklist(["inserted", "duplicate"]),
|
|
33300
|
-
message: v.string()
|
|
33301
|
-
})
|
|
33302
|
-
});
|
|
33303
|
-
var BridgePacketDataSchema = v.object({
|
|
33304
|
-
src_chain_id: v.number(),
|
|
33305
|
-
src_tx_hash: v.string(),
|
|
33306
|
-
src_address: v.string(),
|
|
33307
|
-
status: v.picklist(["pending", "validating", "executing", "executed"]),
|
|
33308
|
-
dst_chain_id: v.number(),
|
|
33309
|
-
conn_sn: v.number(),
|
|
33310
|
-
dst_address: v.string(),
|
|
33311
|
-
dst_tx_hash: v.string(),
|
|
33312
|
-
signatures: v.array(v.string()),
|
|
33313
|
-
payload: v.string()
|
|
33314
|
-
});
|
|
33315
|
-
var BridgeSubmitTxStatusResultSchema = v.object({
|
|
33316
|
-
dstIntentTxHash: v.string(),
|
|
33317
|
-
packetData: v.optional(BridgePacketDataSchema)
|
|
33318
|
-
});
|
|
33319
|
-
var BridgeSubmitTxStatusDataSchema = v.object({
|
|
33320
|
-
txHash: v.string(),
|
|
33321
|
-
srcChainKey: v.string(),
|
|
33322
|
-
status: v.string(),
|
|
33323
|
-
failedAtStep: v.optional(v.string()),
|
|
33324
|
-
failureReason: v.optional(v.string()),
|
|
33325
|
-
processingAttempts: v.number(),
|
|
33326
|
-
abandonedAt: v.optional(v.string()),
|
|
33327
|
-
result: v.optional(BridgeSubmitTxStatusResultSchema),
|
|
33328
|
-
userMessage: v.optional(v.string())
|
|
33329
|
-
});
|
|
33330
|
-
var BridgeSubmitTxStatusResponseSchema = v.object({
|
|
33331
|
-
success: v.boolean(),
|
|
33332
|
-
data: BridgeSubmitTxStatusDataSchema
|
|
33333
|
-
});
|
|
33334
|
-
var BridgeFeeResponseSchema = v.object({ fee: v.string() });
|
|
33335
|
-
var BridgeLimitSchema = v.object({
|
|
33336
|
-
amount: v.string(),
|
|
33337
|
-
decimals: v.number(),
|
|
33338
|
-
type: v.picklist(["DEPOSIT_LIMIT", "WITHDRAWAL_LIMIT"])
|
|
33339
|
-
});
|
|
33340
|
-
var BridgeableAmountResponseSchema = v.object({ limit: BridgeLimitSchema });
|
|
33341
|
-
var BridgeableCheckResponseSchema = v.object({ bridgeable: v.boolean() });
|
|
33342
|
-
var AddressSchema2 = v.custom((input) => typeof input === "string");
|
|
33343
|
-
var HexSchema = v.custom((input) => typeof input === "string");
|
|
33344
|
-
var BigintFromString = v.pipe(v.string(), v.toBigint());
|
|
33345
|
-
var BytesFromIndexRecord = v.pipe(
|
|
33346
|
-
v.record(v.string(), v.number()),
|
|
33347
|
-
v.transform((indexed) => Uint8Array.from(Object.values(indexed)))
|
|
33348
|
-
);
|
|
33349
|
-
var EvmRawTxSchema = v.object({
|
|
33350
|
-
from: AddressSchema2,
|
|
33351
|
-
to: AddressSchema2,
|
|
33352
|
-
value: BigintFromString,
|
|
33353
|
-
data: HexSchema
|
|
33354
|
-
});
|
|
33355
|
-
var SolanaRawTxSchema = v.object({
|
|
33356
|
-
from: v.string(),
|
|
33357
|
-
to: v.string(),
|
|
33358
|
-
value: BigintFromString,
|
|
33359
|
-
data: v.string()
|
|
33360
|
-
});
|
|
33361
|
-
var SuiRawTxSchema = v.object({
|
|
33362
|
-
from: HexSchema,
|
|
33363
|
-
to: v.string(),
|
|
33364
|
-
value: BigintFromString,
|
|
33365
|
-
data: v.string()
|
|
33366
|
-
});
|
|
33367
|
-
var StellarRawTxSchema = v.object({
|
|
33368
|
-
from: v.string(),
|
|
33369
|
-
to: v.string(),
|
|
33370
|
-
value: BigintFromString,
|
|
33371
|
-
data: v.string()
|
|
33372
|
-
});
|
|
33373
|
-
var BitcoinRawTxSchema = v.object({
|
|
33374
|
-
from: v.string(),
|
|
33375
|
-
to: v.string(),
|
|
33376
|
-
value: BigintFromString,
|
|
33377
|
-
data: v.string()
|
|
33378
|
-
});
|
|
33379
|
-
var InjectiveRawTxSchema = v.object({
|
|
33380
|
-
from: HexSchema,
|
|
33381
|
-
to: HexSchema,
|
|
33382
|
-
signedDoc: v.object({
|
|
33383
|
-
bodyBytes: BytesFromIndexRecord,
|
|
33384
|
-
authInfoBytes: BytesFromIndexRecord,
|
|
33385
|
-
chainId: v.string(),
|
|
33386
|
-
accountNumber: BigintFromString
|
|
33387
|
-
})
|
|
33388
|
-
});
|
|
33389
|
-
var NearRawTxSchema = v.object({
|
|
33390
|
-
signerId: v.string(),
|
|
33391
|
-
params: v.object({
|
|
33392
|
-
contractId: v.string(),
|
|
33393
|
-
method: v.string(),
|
|
33394
|
-
args: v.custom((input) => typeof input === "object" && input !== null),
|
|
33395
|
-
gas: v.optional(BigintFromString),
|
|
33396
|
-
deposit: v.optional(BigintFromString)
|
|
33397
|
-
})
|
|
33398
|
-
});
|
|
33399
|
-
var IconRawTxSchema = v.record(
|
|
33400
|
-
v.string(),
|
|
33401
|
-
v.union([v.string(), v.custom((input) => typeof input === "object" && input !== null)])
|
|
33402
|
-
);
|
|
33403
|
-
var StacksRawTxSchema = v.object({
|
|
33404
|
-
payload: v.string(),
|
|
33405
|
-
estimatedLength: v.optional(v.number())
|
|
33406
|
-
});
|
|
33407
|
-
var AnyRawTxSchema = v.custom((input) => typeof input === "object" && input !== null);
|
|
33408
|
-
function rawTxSchemaForChainKey(chainKey) {
|
|
33409
|
-
let chainType;
|
|
33410
|
-
try {
|
|
33411
|
-
chainType = getChainType(chainKey);
|
|
33412
|
-
} catch {
|
|
33413
|
-
chainType = void 0;
|
|
33414
|
-
}
|
|
33415
|
-
switch (chainType) {
|
|
33416
|
-
case "EVM":
|
|
33417
|
-
return EvmRawTxSchema;
|
|
33418
|
-
case "SOLANA":
|
|
33419
|
-
return SolanaRawTxSchema;
|
|
33420
|
-
case "SUI":
|
|
33421
|
-
return SuiRawTxSchema;
|
|
33422
|
-
case "STELLAR":
|
|
33423
|
-
return StellarRawTxSchema;
|
|
33424
|
-
case "INJECTIVE":
|
|
33425
|
-
return InjectiveRawTxSchema;
|
|
33426
|
-
case "ICON":
|
|
33427
|
-
return IconRawTxSchema;
|
|
33428
|
-
case "STACKS":
|
|
33429
|
-
return StacksRawTxSchema;
|
|
33430
|
-
case "NEAR":
|
|
33431
|
-
return NearRawTxSchema;
|
|
33432
|
-
case "BITCOIN":
|
|
33433
|
-
return BitcoinRawTxSchema;
|
|
33434
|
-
default:
|
|
33435
|
-
return AnyRawTxSchema;
|
|
33436
|
-
}
|
|
33437
|
-
}
|
|
33438
|
-
|
|
33439
|
-
// src/backendApi/BridgeApiService.ts
|
|
33440
33542
|
function toCreateBridgeIntentParamsV2(params, extras) {
|
|
33441
33543
|
return {
|
|
33442
33544
|
srcChainKey: params.srcChainKey,
|
|
@@ -33461,41 +33563,63 @@ var BridgeApiService = class {
|
|
|
33461
33563
|
trimsLegacyOverrides;
|
|
33462
33564
|
constructor(config, logger = consoleLogger, options = {}) {
|
|
33463
33565
|
this.config = config;
|
|
33464
|
-
this.headers =
|
|
33566
|
+
this.headers = mergeHeaders(config.headers);
|
|
33465
33567
|
this.logger = logger;
|
|
33466
33568
|
this.trimsLegacyOverrides = options.trimLegacyOverrides ?? true;
|
|
33467
33569
|
}
|
|
33468
33570
|
/**
|
|
33469
|
-
*
|
|
33470
|
-
*
|
|
33471
|
-
*
|
|
33472
|
-
*
|
|
33571
|
+
* Build a `@sodax/bridge-api` client for a single call. Maps the SDK's {@link BaseApiConfig}
|
|
33572
|
+
* (`baseURL`/`timeout`/`headers`) to the package's config (`baseUrl`/`timeout`/`headers`), layering
|
|
33573
|
+
* the optional per-call `RequestOverrideConfig` on top (override wins per field; headers merge).
|
|
33574
|
+
* `timeout` falls back to the backend-API default so a config that omits it still gets a ceiling
|
|
33575
|
+
* rather than an unbounded request. Constructed per call so `setHeaders` mutations and per-call
|
|
33576
|
+
* overrides both take effect without caching stale state.
|
|
33473
33577
|
*/
|
|
33474
|
-
|
|
33578
|
+
buildClient(overrideConfig) {
|
|
33579
|
+
const override = overrideConfig?.baseURL;
|
|
33580
|
+
const baseUrl = override ? this.trimsLegacyOverrides ? stripLegacyBackendMount(override) : override : this.config.baseURL;
|
|
33581
|
+
const timeout = overrideConfig?.timeout ?? this.config.timeout ?? DEFAULT_BACKEND_API_TIMEOUT;
|
|
33582
|
+
const headers = mergeHeaders(this.headers, apiKeyHeader(overrideConfig?.apiKey), overrideConfig?.headers);
|
|
33583
|
+
return new BridgeApi({ baseUrl, headers, timeout });
|
|
33584
|
+
}
|
|
33585
|
+
/**
|
|
33586
|
+
* Run one delegated `BridgeApi` call and wrap it in `Result<T>`. A thrown `BridgeApiError`
|
|
33587
|
+
* (network/timeout/HTTP/parse/validation) becomes `{ ok: false }` with a canonical
|
|
33588
|
+
* `SodaxError<'EXTERNAL_API_ERROR'>`; the original error is kept as `cause`, and its
|
|
33589
|
+
* `code`/`status`/`issues` are projected into `context` so consumers can discriminate failure
|
|
33590
|
+
* kinds without unwrapping `cause`. Only a RESPONSE-shape validation failure is tagged
|
|
33591
|
+
* `reason: 'invalid_response_shape'` — a request-side validation error is a caller bug, not a
|
|
33592
|
+
* backend fault.
|
|
33593
|
+
*/
|
|
33594
|
+
async toResult(endpoint, call, overrideConfig) {
|
|
33475
33595
|
try {
|
|
33476
|
-
const
|
|
33477
|
-
|
|
33478
|
-
config: { baseURL: this.config.baseURL, timeout: this.config.timeout, headers: this.headers, ...config },
|
|
33479
|
-
// Normalized like a configured base URL: the override is the gateway root, so a legacy
|
|
33480
|
-
// `/be`-suffixed value must not nest `/bridge/*` under the data API's mount — unless the config
|
|
33481
|
-
// opted out of the legacy trim, in which case the per-call value is left exactly as given.
|
|
33482
|
-
overrideConfig: this.trimsLegacyOverrides ? normalizeOverrideBaseURL(overrideConfig) : overrideConfig,
|
|
33483
|
-
logger: this.logger,
|
|
33484
|
-
serviceLabel: "BridgeApiService"
|
|
33485
|
-
});
|
|
33486
|
-
const parsed = v.safeParse(schema, raw);
|
|
33487
|
-
if (!parsed.success) {
|
|
33488
|
-
return {
|
|
33489
|
-
ok: false,
|
|
33490
|
-
error: new SodaxError("EXTERNAL_API_ERROR", `Invalid response shape from bridge API for ${endpoint}`, {
|
|
33491
|
-
feature: "backend",
|
|
33492
|
-
context: { api: "bridge", endpoint, reason: "invalid_response_shape", issues: v.flatten(parsed.issues) }
|
|
33493
|
-
})
|
|
33494
|
-
};
|
|
33495
|
-
}
|
|
33496
|
-
return { ok: true, value: parsed.output };
|
|
33596
|
+
const value = await call(this.buildClient(overrideConfig));
|
|
33597
|
+
return { ok: true, value };
|
|
33497
33598
|
} catch (error) {
|
|
33498
|
-
|
|
33599
|
+
const context = { api: "bridge", endpoint };
|
|
33600
|
+
if (error instanceof BridgeApiError) {
|
|
33601
|
+
context.code = error.code;
|
|
33602
|
+
if (error.code === "VALIDATION_ERROR" && error.context.issues !== void 0) {
|
|
33603
|
+
context.reason = "invalid_response_shape";
|
|
33604
|
+
const issues = error.context.issues;
|
|
33605
|
+
context.issues = issues instanceof v.ValiError ? v.flatten(issues.issues) : issues;
|
|
33606
|
+
}
|
|
33607
|
+
if (error.context.status !== void 0) context.status = error.context.status;
|
|
33608
|
+
if (isAuthStatus(error.context.status)) {
|
|
33609
|
+
this.logger.warn(
|
|
33610
|
+
`[BridgeApiService] ${endpoint} was rejected by the bridge API key guard (${error.context.status}). Configure a valid partner API key \u2014 new Sodax({ apiKey }) \u2014 see docs/CONFIGURE_SDK.md.`
|
|
33611
|
+
);
|
|
33612
|
+
}
|
|
33613
|
+
}
|
|
33614
|
+
this.logger.error(`[BridgeApiService] Request to ${endpoint} failed`, error);
|
|
33615
|
+
return {
|
|
33616
|
+
ok: false,
|
|
33617
|
+
error: new SodaxError(
|
|
33618
|
+
"EXTERNAL_API_ERROR",
|
|
33619
|
+
error instanceof Error ? error.message : `Request to ${endpoint} failed`,
|
|
33620
|
+
{ feature: "backend", cause: error, context }
|
|
33621
|
+
)
|
|
33622
|
+
};
|
|
33499
33623
|
}
|
|
33500
33624
|
}
|
|
33501
33625
|
// ──────────────────────────────────────────────────────────────────────
|
|
@@ -33507,7 +33631,7 @@ var BridgeApiService = class {
|
|
|
33507
33631
|
* @returns `Result<GetBridgeTokensResponseV2>` — map of chain key → token list.
|
|
33508
33632
|
*/
|
|
33509
33633
|
async getTokens(config) {
|
|
33510
|
-
return this.
|
|
33634
|
+
return this.toResult("/bridge/tokens", (c) => c.getTokens(), config);
|
|
33511
33635
|
}
|
|
33512
33636
|
/**
|
|
33513
33637
|
* Fetch supported bridge tokens for a single SpokeChainKey.
|
|
@@ -33516,12 +33640,7 @@ var BridgeApiService = class {
|
|
|
33516
33640
|
* @returns `Result<GetBridgeTokensByChainResponseV2>` — token list for the chain.
|
|
33517
33641
|
*/
|
|
33518
33642
|
async getTokensByChain(chainKey, config) {
|
|
33519
|
-
return this.
|
|
33520
|
-
`/bridge/tokens/${chainKey}`,
|
|
33521
|
-
{ method: "GET" },
|
|
33522
|
-
BridgeTokensByChainResponseSchema,
|
|
33523
|
-
config
|
|
33524
|
-
);
|
|
33643
|
+
return this.toResult(`/bridge/tokens/${chainKey}`, (c) => c.getTokensByChain(chainKey), config);
|
|
33525
33644
|
}
|
|
33526
33645
|
// ──────────────────────────────────────────────────────────────────────
|
|
33527
33646
|
// Allowance · approve · create intent
|
|
@@ -33532,12 +33651,7 @@ var BridgeApiService = class {
|
|
|
33532
33651
|
* @returns `Result<BridgeAllowanceCheckResponseV2>` — `{ valid }`.
|
|
33533
33652
|
*/
|
|
33534
33653
|
async checkAllowance(body, config) {
|
|
33535
|
-
return this.
|
|
33536
|
-
"/bridge/allowance/check",
|
|
33537
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33538
|
-
BridgeAllowanceCheckResponseSchema,
|
|
33539
|
-
config
|
|
33540
|
-
);
|
|
33654
|
+
return this.toResult("/bridge/allowance/check", (c) => c.checkAllowance(body), config);
|
|
33541
33655
|
}
|
|
33542
33656
|
/**
|
|
33543
33657
|
* Build an unsigned token-approval transaction for the source token.
|
|
@@ -33546,13 +33660,7 @@ var BridgeApiService = class {
|
|
|
33546
33660
|
* broadcast and mine `resetTx` first when it is present.
|
|
33547
33661
|
*/
|
|
33548
33662
|
async approve(body, config) {
|
|
33549
|
-
|
|
33550
|
-
return this.request(
|
|
33551
|
-
"/bridge/approve",
|
|
33552
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33553
|
-
makeBridgeApproveResponseSchema(txSchema),
|
|
33554
|
-
config
|
|
33555
|
-
);
|
|
33663
|
+
return this.toResult("/bridge/approve", (c) => c.approve(body), config);
|
|
33556
33664
|
}
|
|
33557
33665
|
/**
|
|
33558
33666
|
* Build an unsigned spoke-deposit (create-bridge-intent) transaction.
|
|
@@ -33560,13 +33668,7 @@ var BridgeApiService = class {
|
|
|
33560
33668
|
* @returns `Result<CreateBridgeIntentResponseV2>` — `{ tx, relayData }` (no intent struct).
|
|
33561
33669
|
*/
|
|
33562
33670
|
async createBridgeIntent(body, config) {
|
|
33563
|
-
|
|
33564
|
-
return this.request(
|
|
33565
|
-
"/bridge/intents",
|
|
33566
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33567
|
-
makeCreateBridgeIntentResponseSchema(txSchema),
|
|
33568
|
-
config
|
|
33569
|
-
);
|
|
33671
|
+
return this.toResult("/bridge/intents", (c) => c.createBridgeIntent(body), config);
|
|
33570
33672
|
}
|
|
33571
33673
|
// ──────────────────────────────────────────────────────────────────────
|
|
33572
33674
|
// Submit-tx state machine
|
|
@@ -33578,12 +33680,7 @@ var BridgeApiService = class {
|
|
|
33578
33680
|
* @returns `Result<BridgeSubmitTxResponseV2>` — `{ success, data: { status, message } }`.
|
|
33579
33681
|
*/
|
|
33580
33682
|
async submitTx(body, config) {
|
|
33581
|
-
return this.
|
|
33582
|
-
"/bridge/submit-tx",
|
|
33583
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33584
|
-
BridgeSubmitTxResponseSchema,
|
|
33585
|
-
config
|
|
33586
|
-
);
|
|
33683
|
+
return this.toResult("/bridge/submit-tx", (c) => c.submitTx(body), config);
|
|
33587
33684
|
}
|
|
33588
33685
|
/**
|
|
33589
33686
|
* Get the processing status of a submitted bridge transaction by `(txHash, srcChainKey)`.
|
|
@@ -33591,13 +33688,7 @@ var BridgeApiService = class {
|
|
|
33591
33688
|
* @returns `Result<BridgeSubmitTxStatusResponseV2>` — `{ success, data }` (processing state).
|
|
33592
33689
|
*/
|
|
33593
33690
|
async getSubmitTxStatus(query, config) {
|
|
33594
|
-
|
|
33595
|
-
return this.request(
|
|
33596
|
-
`/bridge/submit-tx/status?${queryParams.toString()}`,
|
|
33597
|
-
{ method: "GET" },
|
|
33598
|
-
BridgeSubmitTxStatusResponseSchema,
|
|
33599
|
-
config
|
|
33600
|
-
);
|
|
33691
|
+
return this.toResult("/bridge/submit-tx/status", (c) => c.getSubmitTxStatus(query), config);
|
|
33601
33692
|
}
|
|
33602
33693
|
// ──────────────────────────────────────────────────────────────────────
|
|
33603
33694
|
// Fee · bridgeable quote (read-only; mirror the SDK-core client-side methods)
|
|
@@ -33611,12 +33702,7 @@ var BridgeApiService = class {
|
|
|
33611
33702
|
* @returns `Result<BridgeFeeResponseV2>` — `{ fee }` (decimal string).
|
|
33612
33703
|
*/
|
|
33613
33704
|
async getFee(body, config) {
|
|
33614
|
-
return this.
|
|
33615
|
-
"/bridge/fee",
|
|
33616
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33617
|
-
BridgeFeeResponseSchema,
|
|
33618
|
-
config
|
|
33619
|
-
);
|
|
33705
|
+
return this.toResult("/bridge/fee", (c) => c.getFee(body), config);
|
|
33620
33706
|
}
|
|
33621
33707
|
/**
|
|
33622
33708
|
* Deposit capacity / withdrawal liquidity for a (from, to) token pair. Computable client-side in the
|
|
@@ -33625,12 +33711,7 @@ var BridgeApiService = class {
|
|
|
33625
33711
|
* @returns `Result<BridgeableAmountResponseV2>` — `{ limit }`.
|
|
33626
33712
|
*/
|
|
33627
33713
|
async getBridgeableAmount(body, config) {
|
|
33628
|
-
return this.
|
|
33629
|
-
"/bridge/bridgeable-amount",
|
|
33630
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33631
|
-
BridgeableAmountResponseSchema,
|
|
33632
|
-
config
|
|
33633
|
-
);
|
|
33714
|
+
return this.toResult("/bridge/bridgeable-amount", (c) => c.getBridgeableAmount(body), config);
|
|
33634
33715
|
}
|
|
33635
33716
|
/**
|
|
33636
33717
|
* Whether a (from, to) token pair is bridgeable. Computable client-side in the SDK core
|
|
@@ -33639,19 +33720,15 @@ var BridgeApiService = class {
|
|
|
33639
33720
|
* @returns `Result<BridgeableCheckResponseV2>` — `{ bridgeable }`.
|
|
33640
33721
|
*/
|
|
33641
33722
|
async isBridgeable(body, config) {
|
|
33642
|
-
return this.
|
|
33643
|
-
"/bridge/bridgeable/check",
|
|
33644
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33645
|
-
BridgeableCheckResponseSchema,
|
|
33646
|
-
config
|
|
33647
|
-
);
|
|
33723
|
+
return this.toResult("/bridge/bridgeable/check", (c) => c.isBridgeable(body), config);
|
|
33648
33724
|
}
|
|
33649
33725
|
// ──────────────────────────────────────────────────────────────────────
|
|
33650
33726
|
// Utilities (parity with SwapsApiService)
|
|
33651
33727
|
// ──────────────────────────────────────────────────────────────────────
|
|
33652
33728
|
/**
|
|
33653
33729
|
* Merge additional headers into the service's default header set. Existing
|
|
33654
|
-
* keys are overwritten; keys absent from `headers` are preserved.
|
|
33730
|
+
* keys are overwritten; keys absent from `headers` are preserved. Applied to
|
|
33731
|
+
* every subsequent call (the delegated client is rebuilt per call).
|
|
33655
33732
|
*/
|
|
33656
33733
|
setHeaders(headers) {
|
|
33657
33734
|
assignHeaders(this.headers, headers);
|
|
@@ -33984,7 +34061,7 @@ var LeverageYieldApiService = class _LeverageYieldApiService {
|
|
|
33984
34061
|
*/
|
|
33985
34062
|
async getDepositQuote(body, query, config) {
|
|
33986
34063
|
const endpoint = query?.includeTxData ? "/leverage-yield/quote/deposit?includeTxData=true" : "/leverage-yield/quote/deposit";
|
|
33987
|
-
const txSchema = rawTxSchemaForChainKey
|
|
34064
|
+
const txSchema = rawTxSchemaForChainKey(body.tokenSrcChainKey);
|
|
33988
34065
|
return this.request(
|
|
33989
34066
|
endpoint,
|
|
33990
34067
|
{ method: "POST", body: toJsonBody(body) },
|
|
@@ -34001,7 +34078,7 @@ var LeverageYieldApiService = class _LeverageYieldApiService {
|
|
|
34001
34078
|
*/
|
|
34002
34079
|
async getWithdrawQuote(body, query, config) {
|
|
34003
34080
|
const endpoint = query?.includeTxData ? "/leverage-yield/quote/withdraw?includeTxData=true" : "/leverage-yield/quote/withdraw";
|
|
34004
|
-
const txSchema = rawTxSchemaForChainKey
|
|
34081
|
+
const txSchema = rawTxSchemaForChainKey(body.srcChainKey);
|
|
34005
34082
|
return this.request(
|
|
34006
34083
|
endpoint,
|
|
34007
34084
|
{ method: "POST", body: toJsonBody(body) },
|
|
@@ -34047,7 +34124,7 @@ var LeverageYieldApiService = class _LeverageYieldApiService {
|
|
|
34047
34124
|
* @returns `Result<ApproveResponseV2>` — `{ tx }` (chain-specific unsigned tx).
|
|
34048
34125
|
*/
|
|
34049
34126
|
async approve(body, config) {
|
|
34050
|
-
const txSchema = rawTxSchemaForChainKey
|
|
34127
|
+
const txSchema = rawTxSchemaForChainKey(body.srcChainKey);
|
|
34051
34128
|
return this.request(
|
|
34052
34129
|
"/leverage-yield/approve",
|
|
34053
34130
|
{ method: "POST", body: toJsonBody(body) },
|
|
@@ -34061,7 +34138,7 @@ var LeverageYieldApiService = class _LeverageYieldApiService {
|
|
|
34061
34138
|
* @returns `Result<CreateIntentResponseV2>` — `{ tx, intent, relayData }`.
|
|
34062
34139
|
*/
|
|
34063
34140
|
async createDepositIntent(body, config) {
|
|
34064
|
-
const txSchema = rawTxSchemaForChainKey
|
|
34141
|
+
const txSchema = rawTxSchemaForChainKey(body.srcChainKey);
|
|
34065
34142
|
return this.request(
|
|
34066
34143
|
"/leverage-yield/intents/deposit",
|
|
34067
34144
|
{ method: "POST", body: toJsonBody(body) },
|
|
@@ -34076,7 +34153,7 @@ var LeverageYieldApiService = class _LeverageYieldApiService {
|
|
|
34076
34153
|
* @returns `Result<CreateIntentResponseV2>` — `{ tx, intent, relayData }`.
|
|
34077
34154
|
*/
|
|
34078
34155
|
async createWithdrawIntent(body, config) {
|
|
34079
|
-
const txSchema = rawTxSchemaForChainKey
|
|
34156
|
+
const txSchema = rawTxSchemaForChainKey(body.srcChainKey);
|
|
34080
34157
|
return this.request(
|
|
34081
34158
|
"/leverage-yield/intents/withdraw",
|
|
34082
34159
|
{ method: "POST", body: toJsonBody(body) },
|
|
@@ -34120,7 +34197,7 @@ var LeverageYieldApiService = class _LeverageYieldApiService {
|
|
|
34120
34197
|
* @returns `Result<CancelIntentResponseV2>` — `{ tx }`.
|
|
34121
34198
|
*/
|
|
34122
34199
|
async cancelIntent(body, config) {
|
|
34123
|
-
const txSchema = rawTxSchemaForChainKey
|
|
34200
|
+
const txSchema = rawTxSchemaForChainKey(body.srcChainKey);
|
|
34124
34201
|
return this.request(
|
|
34125
34202
|
"/leverage-yield/intents/cancel",
|
|
34126
34203
|
{ method: "POST", body: toJsonBody({ ...body, intent: _LeverageYieldApiService.toWireIntent(body.intent) }) },
|
|
@@ -34165,7 +34242,7 @@ var LeverageYieldApiService = class _LeverageYieldApiService {
|
|
|
34165
34242
|
return this.request(
|
|
34166
34243
|
"/leverage-yield/intents/extra-data",
|
|
34167
34244
|
{ method: "POST", body: toJsonBody(normalized) },
|
|
34168
|
-
RelayExtraDataResponseSchema
|
|
34245
|
+
RelayExtraDataResponseSchema,
|
|
34169
34246
|
config
|
|
34170
34247
|
);
|
|
34171
34248
|
}
|
|
@@ -43675,6 +43752,24 @@ var isLeverageYieldPostExecutionError = isCodeMember(
|
|
|
43675
43752
|
var isLeverageYieldSwapError = isCodeMember(LEVERAGE_YIELD_SWAP_CODES);
|
|
43676
43753
|
var isLeverageYieldError = isCodeMember(LEVERAGE_YIELD_CODES);
|
|
43677
43754
|
|
|
43755
|
+
// src/leverageYield/positionFunding.ts
|
|
43756
|
+
function resolvePositionFundingAddress(chainKey, hubChainKey, token) {
|
|
43757
|
+
if (chainKey !== hubChainKey) return token?.address ?? "";
|
|
43758
|
+
if (token && isNativeToken(chainKey, token)) return token.address;
|
|
43759
|
+
return token?.hubAsset ?? token?.address ?? "";
|
|
43760
|
+
}
|
|
43761
|
+
|
|
43762
|
+
// src/leverageYield/positionIntent.ts
|
|
43763
|
+
async function reportPositionIntent(notifySolver, txHashes) {
|
|
43764
|
+
const result = await notifySolver({ intent_tx_hash: txHashes.dstChainTxHash }).catch((error2) => ({
|
|
43765
|
+
ok: false,
|
|
43766
|
+
error: error2
|
|
43767
|
+
}));
|
|
43768
|
+
if (result.ok) return { txHashes, notified: true };
|
|
43769
|
+
const { error } = result;
|
|
43770
|
+
return { txHashes, notified: false, notifyError: error instanceof Error ? error.message : String(error) };
|
|
43771
|
+
}
|
|
43772
|
+
|
|
43678
43773
|
// src/leverageYield/LeverageYieldService.ts
|
|
43679
43774
|
var leverageYieldVaultAbi = parseAbi([
|
|
43680
43775
|
"function asset() view returns (address)",
|
|
@@ -43684,7 +43779,31 @@ var leverageYieldVaultAbi = parseAbi([
|
|
|
43684
43779
|
"function borrowToken() view returns (address)",
|
|
43685
43780
|
"function targetLTV() view returns (uint256)"
|
|
43686
43781
|
]);
|
|
43782
|
+
var MAX_POSITION_FEE_BPS = 100;
|
|
43783
|
+
var leveragePositionFactoryAbi = parseAbi([
|
|
43784
|
+
"function positionsOf(address owner) view returns (address[])",
|
|
43785
|
+
"function nextPositionIdFor(address owner) view returns (uint256)",
|
|
43786
|
+
"function predictPosition(address creator, address owner, uint256 positionId) view returns (address)",
|
|
43787
|
+
"function createPositionAndLeverage((address owner, address collateral, address borrowToken, uint8 eModeCategory, uint256 originChainId, bytes originAddress, address originAsset, address feeReceiver, uint16 feeBps) cfg, uint256 initialAssets, uint256 borrowAmount, uint256 minCollateralOut) returns (address)",
|
|
43788
|
+
"function createPositionFromDebtToken((address owner, address collateral, address borrowToken, uint8 eModeCategory, uint256 originChainId, bytes originAddress, address originAsset, address feeReceiver, uint16 feeBps) cfg, uint256 contribution, uint256 totalInput, uint256 minCollateralOut) returns (address)"
|
|
43789
|
+
]);
|
|
43790
|
+
var leveragePositionAbi = parseAbi([
|
|
43791
|
+
"function owner() view returns (address)",
|
|
43792
|
+
"function collateral() view returns (address)",
|
|
43793
|
+
"function borrowToken() view returns (address)",
|
|
43794
|
+
"function eModeCategory() view returns (uint8)",
|
|
43795
|
+
"function feeBps() view returns (uint16)",
|
|
43796
|
+
"function feeReceiver() view returns (address)",
|
|
43797
|
+
"function hasPendingOperation() view returns (bool)",
|
|
43798
|
+
"function pendingKind() view returns (uint8)",
|
|
43799
|
+
"function addLeverage(uint256 borrowAmount, uint256 minCollateralOut)",
|
|
43800
|
+
"function decreaseLeverage(uint256 collateralIn, uint256 minDebtOut, address exitAsset)",
|
|
43801
|
+
"function withdraw(uint256 amount, address to)",
|
|
43802
|
+
"function cancel()",
|
|
43803
|
+
"function settle()"
|
|
43804
|
+
]);
|
|
43687
43805
|
var INTENT_DEADLINE_BUFFER_SECONDS = 5 * 60;
|
|
43806
|
+
var BITCOIN_UNSUPPORTED_MESSAGE = "Bitcoin is not a supported source chain for leverage positions; use a supported spoke or the hub";
|
|
43688
43807
|
var ANY_SOLVER_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
43689
43808
|
var MAX_WITHDRAW_DUST_BUFFER = 1000n;
|
|
43690
43809
|
function pctToRay(aprPct) {
|
|
@@ -43741,7 +43860,7 @@ var LeverageYieldService = class {
|
|
|
43741
43860
|
}
|
|
43742
43861
|
/** Looks up a vault by its `name` field. Returns `undefined` when not registered. */
|
|
43743
43862
|
getVault(name) {
|
|
43744
|
-
return this.listVaults().find((
|
|
43863
|
+
return this.listVaults().find((v10) => v10.name === name);
|
|
43745
43864
|
}
|
|
43746
43865
|
/**
|
|
43747
43866
|
* Looks up a registered vault by its on-chain proxy address (case-insensitive).
|
|
@@ -43749,7 +43868,7 @@ var LeverageYieldService = class {
|
|
|
43749
43868
|
*/
|
|
43750
43869
|
getVaultByAddress(address) {
|
|
43751
43870
|
const normalized = address.toLowerCase();
|
|
43752
|
-
return this.listVaults().find((
|
|
43871
|
+
return this.listVaults().find((v10) => v10.vault.toLowerCase() === normalized);
|
|
43753
43872
|
}
|
|
43754
43873
|
/**
|
|
43755
43874
|
* Resolves the intent `deadline`: returns the caller-supplied value verbatim, otherwise
|
|
@@ -44338,7 +44457,12 @@ var LeverageYieldService = class {
|
|
|
44338
44457
|
}
|
|
44339
44458
|
}
|
|
44340
44459
|
/**
|
|
44341
|
-
* Notifies the solver that
|
|
44460
|
+
* Notifies the solver that an intent landed on the hub, triggering it to fill.
|
|
44461
|
+
*
|
|
44462
|
+
* REQUIRED for anything that creates an intent, not an optimisation. An intent created on the hub
|
|
44463
|
+
* is invisible to the solver until this call puts it in the task pool, so an unnotified intent
|
|
44464
|
+
* simply expires. Leverage positions post their intents on-chain from the position contract, so
|
|
44465
|
+
* the caller that sent the transaction is the only one who can report the hash.
|
|
44342
44466
|
* Leverage-yield copy of the swap domain's `postExecution` — emits only
|
|
44343
44467
|
* `EXECUTION_FAILED` / `EXTERNAL_API_ERROR` / `UNKNOWN` (relay/verify codes appear only
|
|
44344
44468
|
* on {@link LeverageYieldService.vaultSwap}, which owns the verify + relay steps).
|
|
@@ -44383,6 +44507,51 @@ var LeverageYieldService = class {
|
|
|
44383
44507
|
return { ok: false, error: executionFailed("leverageYield", error, { phase: "postExecution" }) };
|
|
44384
44508
|
}
|
|
44385
44509
|
}
|
|
44510
|
+
/**
|
|
44511
|
+
* Polls the solver for the execution status of an intent this service created.
|
|
44512
|
+
*
|
|
44513
|
+
* Pair with {@link LeverageYieldService.notifySolver}: `notifySolver` puts the intent in the
|
|
44514
|
+
* solver's task pool, this reports what became of it. `fill_tx_hash` is set only once
|
|
44515
|
+
* `status === SolverIntentStatusCode.SOLVED`.
|
|
44516
|
+
*
|
|
44517
|
+
* A `NOT_FOUND` status usually means the notification never landed rather than that the intent
|
|
44518
|
+
* does not exist — an intent created on the hub is invisible to the solver until it is told.
|
|
44519
|
+
*
|
|
44520
|
+
* @param request - `{ intent_tx_hash }` — the hub-chain (Sonic) tx hash the intent was
|
|
44521
|
+
* registered in. For a position that is the tx that called the factory or the position.
|
|
44522
|
+
*/
|
|
44523
|
+
async getIntentStatus(request) {
|
|
44524
|
+
try {
|
|
44525
|
+
const result = await SolverApiService.getStatus(
|
|
44526
|
+
request,
|
|
44527
|
+
this.config.solver,
|
|
44528
|
+
this.config.logger,
|
|
44529
|
+
void 0,
|
|
44530
|
+
this.config.apiKey
|
|
44531
|
+
);
|
|
44532
|
+
if (result.ok) return result;
|
|
44533
|
+
const detail = result.error?.detail ?? {
|
|
44534
|
+
code: -999,
|
|
44535
|
+
// SolverIntentErrorCode.UNKNOWN
|
|
44536
|
+
message: "Solver returned malformed error response"
|
|
44537
|
+
};
|
|
44538
|
+
return {
|
|
44539
|
+
ok: false,
|
|
44540
|
+
error: new SodaxError("EXTERNAL_API_ERROR", detail.message, {
|
|
44541
|
+
feature: "leverageYield",
|
|
44542
|
+
context: {
|
|
44543
|
+
phase: "lookup",
|
|
44544
|
+
api: "solver",
|
|
44545
|
+
solverCode: detail.code,
|
|
44546
|
+
solverDetail: detail
|
|
44547
|
+
}
|
|
44548
|
+
})
|
|
44549
|
+
};
|
|
44550
|
+
} catch (error) {
|
|
44551
|
+
if (isLeverageYieldPostExecutionError(error)) return { ok: false, error };
|
|
44552
|
+
return { ok: false, error: executionFailed("leverageYield", error, { phase: "lookup" }) };
|
|
44553
|
+
}
|
|
44554
|
+
}
|
|
44386
44555
|
/**
|
|
44387
44556
|
* Approves the vault's underlying asset to the leverage vault on Sonic. For callers
|
|
44388
44557
|
* interacting with the vault directly on the hub — the swap-style {@link
|
|
@@ -44691,6 +44860,1252 @@ var LeverageYieldService = class {
|
|
|
44691
44860
|
return { ok: false, error: lookupFailed("leverageYield", "getShareBalanceForUser", error, { srcChainKey }) };
|
|
44692
44861
|
}
|
|
44693
44862
|
}
|
|
44863
|
+
// ─── Leverage positions ────────────────────────────────────────────────
|
|
44864
|
+
/**
|
|
44865
|
+
* Resolves the `LeveragePositionFactory` address, or a validation error when it is missing.
|
|
44866
|
+
*
|
|
44867
|
+
* The deployed factory ships in `leverageYieldConfig`, so this only fails when an integrator
|
|
44868
|
+
* overrides it with an empty value — which is what a bad env var produces. Failing closed there is
|
|
44869
|
+
* deliberate: a placeholder address would post real intents at nothing.
|
|
44870
|
+
*/
|
|
44871
|
+
requireFactory(action) {
|
|
44872
|
+
const factory = this.config.sodaxConfig.leverageYield.positionFactory;
|
|
44873
|
+
if (!factory) {
|
|
44874
|
+
return {
|
|
44875
|
+
ok: false,
|
|
44876
|
+
error: lookupFailed(
|
|
44877
|
+
"leverageYield",
|
|
44878
|
+
action,
|
|
44879
|
+
new Error("leverageYield.positionFactory is not configured; supply the deployed factory address")
|
|
44880
|
+
)
|
|
44881
|
+
};
|
|
44882
|
+
}
|
|
44883
|
+
return { ok: true, value: factory };
|
|
44884
|
+
}
|
|
44885
|
+
/** Position clones owned by `owner`, in creation order. Empty when the owner has none. */
|
|
44886
|
+
async listPositions(owner) {
|
|
44887
|
+
const factory = this.requireFactory("listPositions");
|
|
44888
|
+
if (!factory.ok) return factory;
|
|
44889
|
+
try {
|
|
44890
|
+
const value = await this.hubProvider.publicClient.readContract({
|
|
44891
|
+
address: factory.value,
|
|
44892
|
+
abi: leveragePositionFactoryAbi,
|
|
44893
|
+
functionName: "positionsOf",
|
|
44894
|
+
args: [owner]
|
|
44895
|
+
});
|
|
44896
|
+
return { ok: true, value };
|
|
44897
|
+
} catch (error) {
|
|
44898
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
44899
|
+
return { ok: false, error: lookupFailed("leverageYield", "listPositions", error) };
|
|
44900
|
+
}
|
|
44901
|
+
}
|
|
44902
|
+
/**
|
|
44903
|
+
* Positions belonging to a user, resolved by their spoke-side address rather than a hub address.
|
|
44904
|
+
*
|
|
44905
|
+
* Positions are owned by the user's hub wallet, so discovery goes through
|
|
44906
|
+
* `getUserHubWalletAddress` — which returns the wallet router for a Sonic user and the
|
|
44907
|
+
* cross-chain wallet for a spoke user, so the same call works on every chain. Prefer this over
|
|
44908
|
+
* `listPositions` in user-facing code; passing a raw EOA finds nothing.
|
|
44909
|
+
*/
|
|
44910
|
+
async listPositionsForUser(srcChainKey, srcAddress) {
|
|
44911
|
+
try {
|
|
44912
|
+
const hubWallet = await this.hubProvider.getUserHubWalletAddress(srcAddress, srcChainKey);
|
|
44913
|
+
return await this.listPositions(hubWallet);
|
|
44914
|
+
} catch (error) {
|
|
44915
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
44916
|
+
return { ok: false, error: lookupFailed("leverageYield", "listPositionsForUser", error, { srcChainKey }) };
|
|
44917
|
+
}
|
|
44918
|
+
}
|
|
44919
|
+
/** Static descriptor of a position — owner, both legs, and the fixed eMode category. */
|
|
44920
|
+
async getPositionInfo(position) {
|
|
44921
|
+
try {
|
|
44922
|
+
const [owner, collateral, borrowToken, eModeCategory, feeBps, feeReceiver] = await Promise.all([
|
|
44923
|
+
this.hubProvider.publicClient.readContract({
|
|
44924
|
+
address: position,
|
|
44925
|
+
abi: leveragePositionAbi,
|
|
44926
|
+
functionName: "owner"
|
|
44927
|
+
}),
|
|
44928
|
+
this.hubProvider.publicClient.readContract({
|
|
44929
|
+
address: position,
|
|
44930
|
+
abi: leveragePositionAbi,
|
|
44931
|
+
functionName: "collateral"
|
|
44932
|
+
}),
|
|
44933
|
+
this.hubProvider.publicClient.readContract({
|
|
44934
|
+
address: position,
|
|
44935
|
+
abi: leveragePositionAbi,
|
|
44936
|
+
functionName: "borrowToken"
|
|
44937
|
+
}),
|
|
44938
|
+
this.hubProvider.publicClient.readContract({
|
|
44939
|
+
address: position,
|
|
44940
|
+
abi: leveragePositionAbi,
|
|
44941
|
+
functionName: "eModeCategory"
|
|
44942
|
+
}),
|
|
44943
|
+
this.hubProvider.publicClient.readContract({
|
|
44944
|
+
address: position,
|
|
44945
|
+
abi: leveragePositionAbi,
|
|
44946
|
+
functionName: "feeBps"
|
|
44947
|
+
}),
|
|
44948
|
+
this.hubProvider.publicClient.readContract({
|
|
44949
|
+
address: position,
|
|
44950
|
+
abi: leveragePositionAbi,
|
|
44951
|
+
functionName: "feeReceiver"
|
|
44952
|
+
})
|
|
44953
|
+
]);
|
|
44954
|
+
return {
|
|
44955
|
+
ok: true,
|
|
44956
|
+
value: {
|
|
44957
|
+
address: position,
|
|
44958
|
+
owner,
|
|
44959
|
+
collateral,
|
|
44960
|
+
borrowToken,
|
|
44961
|
+
eModeCategory,
|
|
44962
|
+
// From the position, not from config: config can change and an open can override it, so
|
|
44963
|
+
// what a NEW position would carry is not what THIS one does.
|
|
44964
|
+
feeBps: Number(feeBps),
|
|
44965
|
+
feeReceiver
|
|
44966
|
+
}
|
|
44967
|
+
};
|
|
44968
|
+
} catch (error) {
|
|
44969
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
44970
|
+
return { ok: false, error: lookupFailed("leverageYield", "getPositionInfo", error) };
|
|
44971
|
+
}
|
|
44972
|
+
}
|
|
44973
|
+
/**
|
|
44974
|
+
* Live AAVE account snapshot for a position. Read from the pool, not the position: the
|
|
44975
|
+
* position contract keeps no accounting of its own, so collateral, debt and health factor
|
|
44976
|
+
* all come from `getUserAccountData`.
|
|
44977
|
+
*
|
|
44978
|
+
* The pool comes from `moneyMarket.lendingPool` config rather than the position's own
|
|
44979
|
+
* `pool()` getter — same address, one fewer round trip, and it keeps the deployment address
|
|
44980
|
+
* sourced from config like the rest of the SDK.
|
|
44981
|
+
*/
|
|
44982
|
+
async getPositionAccount(position) {
|
|
44983
|
+
try {
|
|
44984
|
+
const [totalCollateralBase, totalDebtBase, availableBorrowsBase, currentLiquidationThreshold, ltv, healthFactor] = await this.hubProvider.publicClient.readContract({
|
|
44985
|
+
address: this.config.sodaxConfig.moneyMarket.lendingPool,
|
|
44986
|
+
abi: poolAbi,
|
|
44987
|
+
functionName: "getUserAccountData",
|
|
44988
|
+
args: [position]
|
|
44989
|
+
});
|
|
44990
|
+
return {
|
|
44991
|
+
ok: true,
|
|
44992
|
+
value: {
|
|
44993
|
+
totalCollateralBase,
|
|
44994
|
+
totalDebtBase,
|
|
44995
|
+
availableBorrowsBase,
|
|
44996
|
+
currentLiquidationThreshold,
|
|
44997
|
+
ltv,
|
|
44998
|
+
healthFactor
|
|
44999
|
+
}
|
|
45000
|
+
};
|
|
45001
|
+
} catch (error) {
|
|
45002
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45003
|
+
return { ok: false, error: lookupFailed("leverageYield", "getPositionAccount", error) };
|
|
45004
|
+
}
|
|
45005
|
+
}
|
|
45006
|
+
/**
|
|
45007
|
+
* The position's collateral holding, as an exact aToken balance.
|
|
45008
|
+
*
|
|
45009
|
+
* Needed to size a full exit. {@link LeverageYieldService.getPositionAccount} reports collateral
|
|
45010
|
+
* in the oracle's base currency at 8 decimals, which is fine to display but cannot name an amount:
|
|
45011
|
+
* dividing it back out by a price lands near the balance, and a `decreaseLeverage` asking for more
|
|
45012
|
+
* collateral than the position holds does not fail on submission — the hook's `transferFrom`
|
|
45013
|
+
* reverts at fill time, so the intent silently expires instead.
|
|
45014
|
+
*
|
|
45015
|
+
* Safe to act on a slightly stale read: aToken balances only grow, since interest accrues into
|
|
45016
|
+
* them, so a value from a few blocks ago is always still spendable. Selling it leaves interest
|
|
45017
|
+
* dust behind rather than coming up short.
|
|
45018
|
+
*
|
|
45019
|
+
* @param collateral The position's collateral reserve. Read from the position when omitted; pass
|
|
45020
|
+
* it if you already hold a {@link LeveragePosition} to save the round trip.
|
|
45021
|
+
*/
|
|
45022
|
+
async getPositionCollateralBalance(position, collateral) {
|
|
45023
|
+
try {
|
|
45024
|
+
const asset = collateral ?? await this.hubProvider.publicClient.readContract({
|
|
45025
|
+
address: position,
|
|
45026
|
+
abi: leveragePositionAbi,
|
|
45027
|
+
functionName: "collateral"
|
|
45028
|
+
});
|
|
45029
|
+
const reserve = await this.hubProvider.publicClient.readContract({
|
|
45030
|
+
address: this.config.sodaxConfig.moneyMarket.lendingPool,
|
|
45031
|
+
abi: poolAbi,
|
|
45032
|
+
functionName: "getReserveData",
|
|
45033
|
+
args: [asset]
|
|
45034
|
+
});
|
|
45035
|
+
const aToken = reserve.aTokenAddress;
|
|
45036
|
+
const balance = await this.hubProvider.publicClient.readContract({
|
|
45037
|
+
address: aToken,
|
|
45038
|
+
abi: erc20Abi$1,
|
|
45039
|
+
functionName: "balanceOf",
|
|
45040
|
+
args: [position]
|
|
45041
|
+
});
|
|
45042
|
+
return { ok: true, value: { aToken, balance } };
|
|
45043
|
+
} catch (error) {
|
|
45044
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45045
|
+
return { ok: false, error: lookupFailed("leverageYield", "getPositionCollateralBalance", error) };
|
|
45046
|
+
}
|
|
45047
|
+
}
|
|
45048
|
+
/**
|
|
45049
|
+
* The position's operation slot: which operation it recorded, and whether that intent is still
|
|
45050
|
+
* live on `Intents`.
|
|
45051
|
+
*
|
|
45052
|
+
* Both are needed, because the interesting state is when they disagree. `isLive` false with a
|
|
45053
|
+
* non-zero `kind` means the intent resolved — filled, expired, or cancelled by someone else — but
|
|
45054
|
+
* the position has not been told, so its grant is still open and any debt-side contribution is
|
|
45055
|
+
* still sitting there. That is what `needsSettle` flags, and `buildSettlePosition` clears. A live
|
|
45056
|
+
* intent instead blocks any second operation until it resolves.
|
|
45057
|
+
*/
|
|
45058
|
+
async getPositionPendingState(position) {
|
|
45059
|
+
try {
|
|
45060
|
+
const [isLive, kind] = await Promise.all([
|
|
45061
|
+
this.hubProvider.publicClient.readContract({
|
|
45062
|
+
address: position,
|
|
45063
|
+
abi: leveragePositionAbi,
|
|
45064
|
+
functionName: "hasPendingOperation"
|
|
45065
|
+
}),
|
|
45066
|
+
this.hubProvider.publicClient.readContract({
|
|
45067
|
+
address: position,
|
|
45068
|
+
abi: leveragePositionAbi,
|
|
45069
|
+
functionName: "pendingKind"
|
|
45070
|
+
})
|
|
45071
|
+
]);
|
|
45072
|
+
return { ok: true, value: { kind, isLive, needsSettle: kind !== 0 && !isLive } };
|
|
45073
|
+
} catch (error) {
|
|
45074
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45075
|
+
return { ok: false, error: lookupFailed("leverageYield", "getPositionPendingState", error) };
|
|
45076
|
+
}
|
|
45077
|
+
}
|
|
45078
|
+
/** Deterministic clone address for the next position a given creator opens for `owner`. */
|
|
45079
|
+
async predictPosition(creator, owner, positionId) {
|
|
45080
|
+
const factory = this.requireFactory("predictPosition");
|
|
45081
|
+
if (!factory.ok) return factory;
|
|
45082
|
+
try {
|
|
45083
|
+
const id = positionId ?? await this.hubProvider.publicClient.readContract({
|
|
45084
|
+
address: factory.value,
|
|
45085
|
+
abi: leveragePositionFactoryAbi,
|
|
45086
|
+
functionName: "nextPositionIdFor",
|
|
45087
|
+
args: [owner]
|
|
45088
|
+
});
|
|
45089
|
+
const value = await this.hubProvider.publicClient.readContract({
|
|
45090
|
+
address: factory.value,
|
|
45091
|
+
abi: leveragePositionFactoryAbi,
|
|
45092
|
+
functionName: "predictPosition",
|
|
45093
|
+
args: [creator, owner, id]
|
|
45094
|
+
});
|
|
45095
|
+
return { ok: true, value };
|
|
45096
|
+
} catch (error) {
|
|
45097
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45098
|
+
return { ok: false, error: lookupFailed("leverageYield", "predictPosition", error) };
|
|
45099
|
+
}
|
|
45100
|
+
}
|
|
45101
|
+
// ─── Position transaction builders ─────────────────────────────────────
|
|
45102
|
+
//
|
|
45103
|
+
// Positions are driven by direct Sonic calls, not intents, so these return raw transactions
|
|
45104
|
+
// for the caller to sign with a hub wallet provider. The leverage and deleverage calls only
|
|
45105
|
+
// *post* an intent — a solver fills it afterwards, so poll `getPositionPendingState`
|
|
45106
|
+
// rather than treating the receipt as completion.
|
|
45107
|
+
/**
|
|
45108
|
+
* Opens a new position and requests leverage on it in the same transaction — the standard way
|
|
45109
|
+
* to open a leveraged position: one approve, then this.
|
|
45110
|
+
*
|
|
45111
|
+
* `initialAssets` of `collateral` is pulled from the signer, so the factory needs an allowance
|
|
45112
|
+
* first. Control is assigned to `owner`, which may differ from the signer — pass a user's hub
|
|
45113
|
+
* wallet address to have the existing cross-chain path drive the position.
|
|
45114
|
+
*
|
|
45115
|
+
* The leverage is still asynchronous: this posts the intent and a solver fills it afterwards,
|
|
45116
|
+
* so on confirmation the position is funded with the request outstanding, not yet levered. If
|
|
45117
|
+
* no solver fills it, `buildCancelPositionOperation` returns the deposit to the owner.
|
|
45118
|
+
*/
|
|
45119
|
+
/**
|
|
45120
|
+
* Turns a {@link PositionOrigin} into the tuple the factory takes, and refuses the combinations the
|
|
45121
|
+
* contract would refuse anyway — better a rejected build than a transaction that reverts.
|
|
45122
|
+
*/
|
|
45123
|
+
resolveOrigin(origin, method) {
|
|
45124
|
+
const chainId = getIntentRelayChainId(origin.chainKey);
|
|
45125
|
+
if (chainId === void 0) {
|
|
45126
|
+
return {
|
|
45127
|
+
ok: false,
|
|
45128
|
+
error: lookupFailed(
|
|
45129
|
+
"leverageYield",
|
|
45130
|
+
method,
|
|
45131
|
+
new Error(`no relay chain id for origin chain ${origin.chainKey}`)
|
|
45132
|
+
)
|
|
45133
|
+
};
|
|
45134
|
+
}
|
|
45135
|
+
const isHub = origin.chainKey === this.hubProvider.chainConfig.chain.key;
|
|
45136
|
+
if (!isHub && !origin.asset) {
|
|
45137
|
+
return {
|
|
45138
|
+
ok: false,
|
|
45139
|
+
error: lookupFailed(
|
|
45140
|
+
"leverageYield",
|
|
45141
|
+
method,
|
|
45142
|
+
new Error(`origin.asset is required for a refund to ${origin.chainKey}`)
|
|
45143
|
+
)
|
|
45144
|
+
};
|
|
45145
|
+
}
|
|
45146
|
+
return {
|
|
45147
|
+
ok: true,
|
|
45148
|
+
value: {
|
|
45149
|
+
chainId,
|
|
45150
|
+
// The chain's own encoding, not a 0x-prefixed string. `originAddress` is `bytes` on-chain and
|
|
45151
|
+
// is handed to the AssetManager as the refund destination, so a Solana or Stellar address has
|
|
45152
|
+
// to arrive in the form that chain's spoke expects — prefixing `0x` would produce a refund
|
|
45153
|
+
// address that is merely well-formed hex. EVM addresses pass through unchanged.
|
|
45154
|
+
address: encodeAddress(origin.chainKey, origin.address),
|
|
45155
|
+
// Named on the hub as well, not just off it. The asset decides what a cancellation pays back,
|
|
45156
|
+
// and zeroing it here is why someone who funded with USSD was refunded `sodaUSSD`. Callers pass
|
|
45157
|
+
// the asset only when a wrap actually happened — when the reserve IS what was deposited there is
|
|
45158
|
+
// nothing to unwrap and `address(0)` is the correct answer.
|
|
45159
|
+
asset: origin.asset ?? zeroAddress
|
|
45160
|
+
}
|
|
45161
|
+
};
|
|
45162
|
+
}
|
|
45163
|
+
/**
|
|
45164
|
+
* Partner fee for a position, in the shape `PositionConfig` takes.
|
|
45165
|
+
*
|
|
45166
|
+
* Only the PERCENTAGE variant of `PartnerFee` maps: the contract stores basis points and derives
|
|
45167
|
+
* the amount per operation (`_feeFor`), so a fixed-amount fee has nowhere to go and is rejected
|
|
45168
|
+
* rather than silently dropped. Same precedence as the vault flows — per-call, then
|
|
45169
|
+
* `leverageYield.partnerFee`, then none.
|
|
45170
|
+
*
|
|
45171
|
+
* The fee is FIXED AT CREATION on-chain, so this is read when a position is created and never
|
|
45172
|
+
* again; changing the config later does not re-price positions already open.
|
|
45173
|
+
*/
|
|
45174
|
+
/**
|
|
45175
|
+
* The fee a position created NOW would carry, in basis points, plus who receives it.
|
|
45176
|
+
*
|
|
45177
|
+
* Public because a caller cannot project a position correctly without it and cannot derive it:
|
|
45178
|
+
* the fee resolves from `leverageYield.partnerFee`, then the global fee, then none, and it is
|
|
45179
|
+
* FIXED AT CREATION on-chain. Feed `feeBps` to {@link projectLeverageLeg} — the hooks require
|
|
45180
|
+
* `inputAmount + fee`, so a leverage-up borrows the fee ON TOP of what the solver is paid. Leaving
|
|
45181
|
+
* it out understates LTV and overstates the ceiling, which is the Aave `'36'` failure at fill time
|
|
45182
|
+
* this module exists to prevent: 50 bp takes a debt-side ceiling from 9.88x to about 9.44x.
|
|
45183
|
+
*
|
|
45184
|
+
* Pass the same `override` here as to the open call, or omit it on both.
|
|
45185
|
+
*/
|
|
45186
|
+
getEffectivePositionFee(override) {
|
|
45187
|
+
return this.resolvePositionFee(override, "getEffectivePositionFee");
|
|
45188
|
+
}
|
|
45189
|
+
resolvePositionFee(override, method) {
|
|
45190
|
+
const fee = override ?? this.config.leverageYieldPartnerFee;
|
|
45191
|
+
if (!fee) return { ok: true, value: { feeReceiver: zeroAddress, feeBps: 0 } };
|
|
45192
|
+
if (!isPartnerFeePercentage(fee)) {
|
|
45193
|
+
return {
|
|
45194
|
+
ok: false,
|
|
45195
|
+
error: lookupFailed(
|
|
45196
|
+
"leverageYield",
|
|
45197
|
+
method,
|
|
45198
|
+
new Error("a position partner fee must be the percentage variant; PositionConfig stores basis points")
|
|
45199
|
+
)
|
|
45200
|
+
};
|
|
45201
|
+
}
|
|
45202
|
+
if (!Number.isInteger(fee.percentage) || fee.percentage < 0 || fee.percentage > MAX_POSITION_FEE_BPS) {
|
|
45203
|
+
return {
|
|
45204
|
+
ok: false,
|
|
45205
|
+
error: lookupFailed(
|
|
45206
|
+
"leverageYield",
|
|
45207
|
+
method,
|
|
45208
|
+
new Error(
|
|
45209
|
+
`a position partner fee must be a whole number of basis points between 0 and MAX_POSITION_FEE_BPS (${MAX_POSITION_FEE_BPS}) (got ${fee.percentage})`
|
|
45210
|
+
)
|
|
45211
|
+
)
|
|
45212
|
+
};
|
|
45213
|
+
}
|
|
45214
|
+
if (fee.percentage === 0 !== isAddressEqual(fee.address, zeroAddress)) {
|
|
45215
|
+
return {
|
|
45216
|
+
ok: false,
|
|
45217
|
+
error: lookupFailed(
|
|
45218
|
+
"leverageYield",
|
|
45219
|
+
method,
|
|
45220
|
+
new Error(
|
|
45221
|
+
`a position partner fee needs a rate and a receiver together, or neither (got ${fee.percentage} bps for ${fee.address})`
|
|
45222
|
+
)
|
|
45223
|
+
)
|
|
45224
|
+
};
|
|
45225
|
+
}
|
|
45226
|
+
return { ok: true, value: { feeReceiver: fee.address, feeBps: fee.percentage } };
|
|
45227
|
+
}
|
|
45228
|
+
/** A hub transaction. Every builder below produces this shape and none of them sends value. */
|
|
45229
|
+
// Generic so a builder's declared return type applies its own brand. The cast is the single one
|
|
45230
|
+
// the pattern needs — a brand is type-only and erased at runtime — and keeping it here means no
|
|
45231
|
+
// builder carries one of its own.
|
|
45232
|
+
hubTx(from, to, data) {
|
|
45233
|
+
return { from, to, value: 0n, data };
|
|
45234
|
+
}
|
|
45235
|
+
/**
|
|
45236
|
+
* The `PositionConfig` struct both factory entry points take, assembled from a resolved origin.
|
|
45237
|
+
*
|
|
45238
|
+
* Shared so the two create paths cannot drift: which side the funded reserve goes on is their only
|
|
45239
|
+
* real difference, and a field silently spelled differently in one of them would be a
|
|
45240
|
+
* mis-recorded refund destination rather than a compile error.
|
|
45241
|
+
*/
|
|
45242
|
+
positionConfig(args) {
|
|
45243
|
+
return {
|
|
45244
|
+
owner: args.owner,
|
|
45245
|
+
collateral: args.collateral,
|
|
45246
|
+
borrowToken: args.borrowToken,
|
|
45247
|
+
eModeCategory: args.eModeCategory,
|
|
45248
|
+
originChainId: args.origin.chainId,
|
|
45249
|
+
originAddress: args.origin.address,
|
|
45250
|
+
originAsset: args.origin.asset,
|
|
45251
|
+
feeReceiver: args.fee?.feeReceiver ?? zeroAddress,
|
|
45252
|
+
feeBps: args.fee?.feeBps ?? 0
|
|
45253
|
+
};
|
|
45254
|
+
}
|
|
45255
|
+
buildCreatePositionAndLeverage(params) {
|
|
45256
|
+
const method = "buildCreatePositionAndLeverage";
|
|
45257
|
+
const factory = this.requireFactory(method);
|
|
45258
|
+
if (!factory.ok) return factory;
|
|
45259
|
+
const fee = this.resolvePositionFee(params.partnerFee, method);
|
|
45260
|
+
if (!fee.ok) return fee;
|
|
45261
|
+
const origin = this.resolveOrigin(params.origin, method);
|
|
45262
|
+
if (!origin.ok) return origin;
|
|
45263
|
+
return {
|
|
45264
|
+
ok: true,
|
|
45265
|
+
value: this.hubTx(
|
|
45266
|
+
params.from,
|
|
45267
|
+
factory.value,
|
|
45268
|
+
encodeFunctionData({
|
|
45269
|
+
abi: leveragePositionFactoryAbi,
|
|
45270
|
+
functionName: "createPositionAndLeverage",
|
|
45271
|
+
args: [
|
|
45272
|
+
this.positionConfig({ ...params, origin: origin.value, fee: fee.value }),
|
|
45273
|
+
params.initialAssets,
|
|
45274
|
+
params.borrowAmount,
|
|
45275
|
+
params.minCollateralOut
|
|
45276
|
+
]
|
|
45277
|
+
})
|
|
45278
|
+
)
|
|
45279
|
+
};
|
|
45280
|
+
}
|
|
45281
|
+
/**
|
|
45282
|
+
* Opens a levered position starting from the **debt** token, with no collateral of your own.
|
|
45283
|
+
*
|
|
45284
|
+
* Pulls `contribution` of `borrowToken` from the signer — not the collateral. On fill the hook
|
|
45285
|
+
* supplies the solver's collateral, adds the contribution, borrows `totalInput - contribution`,
|
|
45286
|
+
* and pays the solver the total, so a holder of the debt asset lands in a levered collateral
|
|
45287
|
+
* position having never owned collateral. Requires the deployment's implementation to have a
|
|
45288
|
+
* debt-side hook configured; otherwise the position reverts with `DebtSideHookUnavailable`.
|
|
45289
|
+
*/
|
|
45290
|
+
buildCreatePositionFromDebtToken(params) {
|
|
45291
|
+
const method = "buildCreatePositionFromDebtToken";
|
|
45292
|
+
const factory = this.requireFactory(method);
|
|
45293
|
+
if (!factory.ok) return factory;
|
|
45294
|
+
const fee = this.resolvePositionFee(params.partnerFee, method);
|
|
45295
|
+
if (!fee.ok) return fee;
|
|
45296
|
+
const origin = this.resolveOrigin(params.origin, method);
|
|
45297
|
+
if (!origin.ok) return origin;
|
|
45298
|
+
return {
|
|
45299
|
+
ok: true,
|
|
45300
|
+
value: this.hubTx(
|
|
45301
|
+
params.from,
|
|
45302
|
+
factory.value,
|
|
45303
|
+
encodeFunctionData({
|
|
45304
|
+
abi: leveragePositionFactoryAbi,
|
|
45305
|
+
functionName: "createPositionFromDebtToken",
|
|
45306
|
+
args: [
|
|
45307
|
+
this.positionConfig({ ...params, origin: origin.value, fee: fee.value }),
|
|
45308
|
+
params.contribution,
|
|
45309
|
+
params.totalInput,
|
|
45310
|
+
params.minCollateralOut
|
|
45311
|
+
]
|
|
45312
|
+
})
|
|
45313
|
+
)
|
|
45314
|
+
};
|
|
45315
|
+
}
|
|
45316
|
+
/** Borrows `borrowAmount` and swaps it into more collateral. `minCollateralOut` is the slippage floor. */
|
|
45317
|
+
buildAddLeverage(params) {
|
|
45318
|
+
return this.hubTx(
|
|
45319
|
+
params.from,
|
|
45320
|
+
params.position,
|
|
45321
|
+
encodeFunctionData({
|
|
45322
|
+
abi: leveragePositionAbi,
|
|
45323
|
+
functionName: "addLeverage",
|
|
45324
|
+
args: [params.borrowAmount, params.minCollateralOut]
|
|
45325
|
+
})
|
|
45326
|
+
);
|
|
45327
|
+
}
|
|
45328
|
+
/**
|
|
45329
|
+
* Gives up `collateralIn` of collateral to repay debt. `minDebtOut` is the slippage floor.
|
|
45330
|
+
*
|
|
45331
|
+
* CLOSING INTO THE DEBT TOKEN is this call with the position's collateral balance, less the fee a
|
|
45332
|
+
* non-zero `feeBps` gives up on top of the input (`balance x 10_000 / (10_000 + feeBps)`) — there is
|
|
45333
|
+
* no separate close entry point, because selling everything is the same operation as selling part.
|
|
45334
|
+
* Size it with {@link LeverageYieldService.getPositionCollateralBalance}, never off
|
|
45335
|
+
* `totalCollateralBase`, and quote the full amount so `minDebtOut` reflects what the solver will
|
|
45336
|
+
* actually pay for all of it.
|
|
45337
|
+
*
|
|
45338
|
+
* What that leaves behind is worth knowing. The solver delivers more debt token than is owed, so
|
|
45339
|
+
* the hook repays the debt and hands the surplus to the position, which is the owner's equity now
|
|
45340
|
+
* denominated in the debt asset. It sits in the position until someone calls
|
|
45341
|
+
* {@link LeverageYieldService.buildSettlePosition} — that sweep is what actually delivers it, and
|
|
45342
|
+
* it goes to the position's `owner` (the hub wallet), not to whoever signed. Exiting into the
|
|
45343
|
+
* *collateral* instead means repaying only the debt and then calling
|
|
45344
|
+
* {@link LeverageYieldService.buildPositionWithdraw}, which can pay out to any address.
|
|
45345
|
+
*/
|
|
45346
|
+
buildDecreaseLeverage(params) {
|
|
45347
|
+
return this.hubTx(
|
|
45348
|
+
params.from,
|
|
45349
|
+
params.position,
|
|
45350
|
+
encodeFunctionData({
|
|
45351
|
+
abi: leveragePositionAbi,
|
|
45352
|
+
functionName: "decreaseLeverage",
|
|
45353
|
+
args: [params.collateralIn, params.minDebtOut, params.exitAsset ?? zeroAddress]
|
|
45354
|
+
})
|
|
45355
|
+
);
|
|
45356
|
+
}
|
|
45357
|
+
/**
|
|
45358
|
+
* Withdraws collateral out of the position. The pool rejects a withdrawal that would drop
|
|
45359
|
+
* the position below its liquidation threshold, so no client-side health check is applied
|
|
45360
|
+
* here — but note that bound is health factor 1, not a safety buffer above it.
|
|
45361
|
+
*/
|
|
45362
|
+
buildPositionWithdraw(params) {
|
|
45363
|
+
return this.hubTx(
|
|
45364
|
+
params.from,
|
|
45365
|
+
params.position,
|
|
45366
|
+
encodeFunctionData({
|
|
45367
|
+
abi: leveragePositionAbi,
|
|
45368
|
+
functionName: "withdraw",
|
|
45369
|
+
args: [params.amount, params.to]
|
|
45370
|
+
})
|
|
45371
|
+
);
|
|
45372
|
+
}
|
|
45373
|
+
/**
|
|
45374
|
+
* Clears an operation that has already resolved and returns anything the position is holding
|
|
45375
|
+
* loose to its owner.
|
|
45376
|
+
*
|
|
45377
|
+
* PERMISSIONLESS, and deliberately so: it only ever tightens state, so a stranded balance can be
|
|
45378
|
+
* pushed back by anyone rather than waiting on the owner to notice. That matters because an intent
|
|
45379
|
+
* can be cancelled by a third party once past its deadline, which leaves the position resolved but
|
|
45380
|
+
* un-swept if the hook's notification did not land.
|
|
45381
|
+
*
|
|
45382
|
+
* Reverts while the intent is still live — use {@link LeverageYieldService.buildCancelPositionOperation}
|
|
45383
|
+
* to end one that has not resolved yet.
|
|
45384
|
+
*/
|
|
45385
|
+
buildSettlePosition(params) {
|
|
45386
|
+
return this.hubTx(
|
|
45387
|
+
params.from,
|
|
45388
|
+
params.position,
|
|
45389
|
+
encodeFunctionData({ abi: leveragePositionAbi, functionName: "settle" })
|
|
45390
|
+
);
|
|
45391
|
+
}
|
|
45392
|
+
/**
|
|
45393
|
+
* Cancels the in-flight operation and returns the deposit.
|
|
45394
|
+
*
|
|
45395
|
+
* Nothing is escrowed when an intent is posted, so cancelling recovers nothing by itself — but
|
|
45396
|
+
* a position carrying no debt withdraws its whole collateral balance back to the owner, which
|
|
45397
|
+
* is what a leveraged open whose intent never filled needs. With debt outstanding the
|
|
45398
|
+
* collateral stays put: the pool would reject the withdrawal on its health-factor check.
|
|
45399
|
+
*/
|
|
45400
|
+
buildCancelPositionOperation(params) {
|
|
45401
|
+
return this.hubTx(
|
|
45402
|
+
params.from,
|
|
45403
|
+
params.position,
|
|
45404
|
+
encodeFunctionData({ abi: leveragePositionAbi, functionName: "cancel" })
|
|
45405
|
+
);
|
|
45406
|
+
}
|
|
45407
|
+
// ─── Positions from any chain ──────────────────────────────────────────
|
|
45408
|
+
//
|
|
45409
|
+
// The builders above produce a transaction sent straight to the hub. That only works for a user
|
|
45410
|
+
// signing on the hub, and even there it has to be routed so `msg.sender` is their hub wallet —
|
|
45411
|
+
// a position's `onlyOwner` is that wallet, and an EOA cannot send as another address.
|
|
45412
|
+
//
|
|
45413
|
+
// These take over from there: the calls are encoded as a hub-wallet payload and carried by the
|
|
45414
|
+
// spoke transport, which routes them locally on the hub and relays them from anywhere else. So one
|
|
45415
|
+
// code path covers every chain, and the hub is not a special case.
|
|
45416
|
+
/**
|
|
45417
|
+
* Encodes position calls as a hub-wallet payload.
|
|
45418
|
+
*
|
|
45419
|
+
* Takes the raw transactions from the builders above and produces the `(address,uint256,bytes)[]`
|
|
45420
|
+
* payload the hub wallet executes. Public because that payload is the unit the transport takes:
|
|
45421
|
+
* pass it to `spoke.deposit` / `spoke.sendMessage` yourself when you want manual relay control,
|
|
45422
|
+
* or use {@link LeverageYieldService.openPosition} / {@link LeverageYieldService.operatePosition},
|
|
45423
|
+
* which do it for you.
|
|
45424
|
+
*/
|
|
45425
|
+
encodePositionCalls(txs) {
|
|
45426
|
+
return encodeContractCalls(
|
|
45427
|
+
txs.map((tx) => ({ address: tx.to, value: tx.value ?? 0n, data: tx.data }))
|
|
45428
|
+
);
|
|
45429
|
+
}
|
|
45430
|
+
/**
|
|
45431
|
+
* Resolves the hub reserve a spoke token funds, and the hub asset it arrives as.
|
|
45432
|
+
*
|
|
45433
|
+
* Three addresses per token and they are not interchangeable: `hubAsset` is what lands in the hub
|
|
45434
|
+
* wallet, `vault` is the 18-decimal money-market reserve a position actually uses, and the spoke
|
|
45435
|
+
* `address` is neither. Getting this wrong is silent — the wrong one is still a valid ERC-20.
|
|
45436
|
+
*/
|
|
45437
|
+
resolveFunding(srcChainKey, token, method) {
|
|
45438
|
+
const spokeToken = this.config.getSpokeTokenFromOriginalAssetAddress(srcChainKey, token) ?? this.config.getXTokenFromHubAsset(token);
|
|
45439
|
+
if (!spokeToken) {
|
|
45440
|
+
return {
|
|
45441
|
+
ok: false,
|
|
45442
|
+
error: lookupFailed(
|
|
45443
|
+
"leverageYield",
|
|
45444
|
+
method,
|
|
45445
|
+
new Error(`no hub asset registered for ${token} on ${srcChainKey}`),
|
|
45446
|
+
{ srcChainKey }
|
|
45447
|
+
)
|
|
45448
|
+
};
|
|
45449
|
+
}
|
|
45450
|
+
return {
|
|
45451
|
+
ok: true,
|
|
45452
|
+
value: {
|
|
45453
|
+
hubAsset: spokeToken.hubAsset,
|
|
45454
|
+
vault: spokeToken.vault,
|
|
45455
|
+
decimals: spokeToken.decimals
|
|
45456
|
+
}
|
|
45457
|
+
};
|
|
45458
|
+
}
|
|
45459
|
+
/**
|
|
45460
|
+
* What a refund should pay back: the asset the user actually funded with, or `undefined` when that IS
|
|
45461
|
+
* the reserve and there is nothing to unwrap.
|
|
45462
|
+
*
|
|
45463
|
+
* A named asset makes `IntentRefund` unwrap before paying, on the hub as well as off it — so someone
|
|
45464
|
+
* who deposited USSD is refunded USSD rather than `sodaUSSD`.
|
|
45465
|
+
*/
|
|
45466
|
+
refundAsset(funding) {
|
|
45467
|
+
return funding.hubAsset.toLowerCase() === funding.vault.toLowerCase() ? void 0 : funding.hubAsset;
|
|
45468
|
+
}
|
|
45469
|
+
/**
|
|
45470
|
+
* Encodes the wrap of an arriving deposit into its money-market reserve, and returns the reserve
|
|
45471
|
+
* amount that produces.
|
|
45472
|
+
*
|
|
45473
|
+
* A hub asset that is already a soda vault token IS the reserve, so nothing is wrapped. Otherwise
|
|
45474
|
+
* the vault mints 18-decimal shares one-for-one with the asset, which is what
|
|
45475
|
+
* `translateIncomingDecimals` computes — the same conversion the asset manager applies to a spoke
|
|
45476
|
+
* deposit, rather than a second implementation of it. A reserve carrying a non-zero deposit fee
|
|
45477
|
+
* would mint fewer shares than this predicts and the factory's pull would revert; both reserves in
|
|
45478
|
+
* use today are fee-free.
|
|
45479
|
+
*/
|
|
45480
|
+
encodeWrapIntoReserve(funding, amount) {
|
|
45481
|
+
if (this.config.isSodaVaultHubAsset(funding.hubAsset)) {
|
|
45482
|
+
return { calls: [], reserveAmount: amount };
|
|
45483
|
+
}
|
|
45484
|
+
return {
|
|
45485
|
+
calls: [
|
|
45486
|
+
Erc20Service.encodeApprove(funding.hubAsset, funding.vault, amount),
|
|
45487
|
+
EvmVaultTokenService.encodeDeposit(funding.vault, funding.hubAsset, amount)
|
|
45488
|
+
],
|
|
45489
|
+
reserveAmount: EvmVaultTokenService.translateIncomingDecimals(funding.decimals, amount)
|
|
45490
|
+
};
|
|
45491
|
+
}
|
|
45492
|
+
/**
|
|
45493
|
+
* Everything both opens do before they diverge: resolve the factory, the funding token's hub asset
|
|
45494
|
+
* and reserve, and the origin to refund to; predict the address the position will be created at;
|
|
45495
|
+
* and encode the wrap plus the transfer that funds it.
|
|
45496
|
+
*
|
|
45497
|
+
* Only the factory call itself differs between the collateral side and the debt side — which side
|
|
45498
|
+
* the funded reserve lands on, and the two amounts — so everything up to that point lives here
|
|
45499
|
+
* once. `calls` is returned ready to be appended to.
|
|
45500
|
+
*/
|
|
45501
|
+
async prepareOpen(params, method) {
|
|
45502
|
+
const factory = this.requireFactory(method);
|
|
45503
|
+
if (!factory.ok) return factory;
|
|
45504
|
+
const fee = this.resolvePositionFee(params.partnerFee, method);
|
|
45505
|
+
if (!fee.ok) return fee;
|
|
45506
|
+
const funding = this.resolveFunding(params.srcChainKey, params.token, method);
|
|
45507
|
+
if (!funding.ok) return funding;
|
|
45508
|
+
const origin = this.resolveOrigin(
|
|
45509
|
+
{ chainKey: params.srcChainKey, address: params.srcAddress, asset: this.refundAsset(funding.value) },
|
|
45510
|
+
method
|
|
45511
|
+
);
|
|
45512
|
+
if (!origin.ok) return origin;
|
|
45513
|
+
const predicted = await this.predictPosition(params.owner, params.owner);
|
|
45514
|
+
if (!predicted.ok) return predicted;
|
|
45515
|
+
const { calls, reserveAmount } = this.encodeWrapIntoReserve(funding.value, params.amount);
|
|
45516
|
+
calls.push(Erc20Service.encodeTransfer(funding.value.vault, predicted.value, reserveAmount));
|
|
45517
|
+
return {
|
|
45518
|
+
ok: true,
|
|
45519
|
+
value: {
|
|
45520
|
+
factory: factory.value,
|
|
45521
|
+
funding: funding.value,
|
|
45522
|
+
calls,
|
|
45523
|
+
reserveAmount,
|
|
45524
|
+
origin: origin.value,
|
|
45525
|
+
fee: fee.value
|
|
45526
|
+
}
|
|
45527
|
+
};
|
|
45528
|
+
}
|
|
45529
|
+
/**
|
|
45530
|
+
* Hub-side payload for opening a position from the collateral side.
|
|
45531
|
+
*
|
|
45532
|
+
* Wrap the arriving deposit into its reserve, TRANSFER it to the address the position will be
|
|
45533
|
+
* created at, create the position and post its leverage intent — one batch, executed by the user's
|
|
45534
|
+
* hub wallet. The position's collateral is the reserve behind `params.token`; `borrowToken` is
|
|
45535
|
+
* borrowed against it.
|
|
45536
|
+
*
|
|
45537
|
+
* Nothing is ever approved to the factory: it holds no allowance and pulls from nobody, so funding
|
|
45538
|
+
* is a transfer to `predictPosition(creator, owner, nextPositionIdFor(owner))` and the clone supplies
|
|
45539
|
+
* whatever it finds. The id is per-owner, so an unrelated user creating a position cannot move the
|
|
45540
|
+
* address out from under this batch — and because the transfer and the create are in the same batch,
|
|
45541
|
+
* a stale prediction reverts both rather than stranding the tokens.
|
|
45542
|
+
*
|
|
45543
|
+
* The owner's OWN concurrent opens are the one thing that can still advance the id between building
|
|
45544
|
+
* this payload and executing it. On the hub that reverts atomically and nothing is lost; funded from
|
|
45545
|
+
* a spoke the deposit has already landed in the user's hub wallet when the batch reverts, and is
|
|
45546
|
+
* recovered with `sodax.recovery` (see RECOVERY.md). Do not open two positions for one owner at once.
|
|
45547
|
+
*
|
|
45548
|
+
* The origin recorded on the position is `srcChainKey` / `srcAddress` / the deposited hub asset,
|
|
45549
|
+
* so a leverage intent that never fills refunds to the user on the chain they funded from — not to
|
|
45550
|
+
* the position, and not to the hub wallet.
|
|
45551
|
+
*/
|
|
45552
|
+
async buildOpenPositionData(params) {
|
|
45553
|
+
const prep = await this.prepareOpen(params, "buildOpenPositionData");
|
|
45554
|
+
if (!prep.ok) return prep;
|
|
45555
|
+
const { factory, funding, calls, reserveAmount, origin, fee } = prep.value;
|
|
45556
|
+
calls.push({
|
|
45557
|
+
address: factory,
|
|
45558
|
+
value: 0n,
|
|
45559
|
+
data: encodeFunctionData({
|
|
45560
|
+
abi: leveragePositionFactoryAbi,
|
|
45561
|
+
functionName: "createPositionAndLeverage",
|
|
45562
|
+
args: [
|
|
45563
|
+
this.positionConfig({
|
|
45564
|
+
owner: params.owner,
|
|
45565
|
+
collateral: funding.vault,
|
|
45566
|
+
borrowToken: params.borrowToken,
|
|
45567
|
+
eModeCategory: params.eModeCategory ?? 0,
|
|
45568
|
+
origin,
|
|
45569
|
+
fee
|
|
45570
|
+
}),
|
|
45571
|
+
reserveAmount,
|
|
45572
|
+
params.borrowAmount,
|
|
45573
|
+
params.minCollateralOut
|
|
45574
|
+
]
|
|
45575
|
+
})
|
|
45576
|
+
});
|
|
45577
|
+
return { ok: true, value: encodeContractCalls(calls) };
|
|
45578
|
+
}
|
|
45579
|
+
/**
|
|
45580
|
+
* Hub-side payload for opening a position from the debt side.
|
|
45581
|
+
*
|
|
45582
|
+
* The mirror of {@link LeverageYieldService.buildOpenPositionData}: here the deposit is the
|
|
45583
|
+
* position's *debt* token, contributed rather than supplied, and `collateral` is the reserve the
|
|
45584
|
+
* position ends up long. The hook supplies the solver's collateral on fill and borrows only the
|
|
45585
|
+
* shortfall, so the position legitimately starts with no collateral of its own.
|
|
45586
|
+
*/
|
|
45587
|
+
async buildOpenPositionFromDebtTokenData(params) {
|
|
45588
|
+
const prep = await this.prepareOpen(params, "buildOpenPositionFromDebtTokenData");
|
|
45589
|
+
if (!prep.ok) return prep;
|
|
45590
|
+
const { factory, funding, calls, reserveAmount, origin, fee } = prep.value;
|
|
45591
|
+
calls.push({
|
|
45592
|
+
address: factory,
|
|
45593
|
+
value: 0n,
|
|
45594
|
+
data: encodeFunctionData({
|
|
45595
|
+
abi: leveragePositionFactoryAbi,
|
|
45596
|
+
functionName: "createPositionFromDebtToken",
|
|
45597
|
+
args: [
|
|
45598
|
+
this.positionConfig({
|
|
45599
|
+
owner: params.owner,
|
|
45600
|
+
collateral: params.collateral,
|
|
45601
|
+
// The deposited token IS the debt side, so its reserve is the borrow token.
|
|
45602
|
+
borrowToken: funding.vault,
|
|
45603
|
+
eModeCategory: params.eModeCategory ?? 0,
|
|
45604
|
+
origin,
|
|
45605
|
+
fee
|
|
45606
|
+
}),
|
|
45607
|
+
reserveAmount,
|
|
45608
|
+
params.totalInput,
|
|
45609
|
+
params.minCollateralOut
|
|
45610
|
+
]
|
|
45611
|
+
})
|
|
45612
|
+
});
|
|
45613
|
+
return { ok: true, value: encodeContractCalls(calls) };
|
|
45614
|
+
}
|
|
45615
|
+
/**
|
|
45616
|
+
* Whether the funding token is already approved for an open from `srcChainKey`.
|
|
45617
|
+
*
|
|
45618
|
+
* The spender differs by chain and neither choice is guessable: on the hub the deposit is pulled
|
|
45619
|
+
* by the user's own hub wallet, executing inside the routed batch; on an EVM spoke it is pulled by
|
|
45620
|
+
* that spoke's asset manager. Chains with no allowance concept report `true`, and Stellar reports
|
|
45621
|
+
* whether the trustline covers the amount.
|
|
45622
|
+
*/
|
|
45623
|
+
async isPositionFundingAllowanceValid(params) {
|
|
45624
|
+
const baseCtx = { srcChainKey: params.srcChainKey, action: "allowanceCheck" };
|
|
45625
|
+
try {
|
|
45626
|
+
leverageYieldInvariant(params.amount > 0n, "amount must be greater than 0", { ...baseCtx, field: "amount" });
|
|
45627
|
+
const srcChainKey = params.srcChainKey;
|
|
45628
|
+
const inner = isHubChainKeyType(srcChainKey) || isEvmSpokeOnlyChainKeyType(srcChainKey) ? await this.spoke.isAllowanceValid({
|
|
45629
|
+
srcChainKey,
|
|
45630
|
+
token: params.token,
|
|
45631
|
+
amount: params.amount,
|
|
45632
|
+
owner: params.srcAddress,
|
|
45633
|
+
spender: await this.resolveFundingSpender(srcChainKey, params.srcAddress)
|
|
45634
|
+
}) : await this.spoke.isAllowanceValid({
|
|
45635
|
+
srcChainKey,
|
|
45636
|
+
token: params.token,
|
|
45637
|
+
amount: params.amount,
|
|
45638
|
+
owner: params.srcAddress
|
|
45639
|
+
});
|
|
45640
|
+
if (inner.ok) return inner;
|
|
45641
|
+
return { ok: false, error: allowanceCheckFailed("leverageYield", inner.error, baseCtx) };
|
|
45642
|
+
} catch (error) {
|
|
45643
|
+
if (isLeverageYieldAllowanceCheckError(error)) return { ok: false, error };
|
|
45644
|
+
return { ok: false, error: allowanceCheckFailed("leverageYield", error, baseCtx) };
|
|
45645
|
+
}
|
|
45646
|
+
}
|
|
45647
|
+
/**
|
|
45648
|
+
* Approves the funding token for an open, against the spender that chain's deposit actually uses —
|
|
45649
|
+
* see {@link LeverageYieldService.isPositionFundingAllowanceValid} for which that is.
|
|
45650
|
+
*
|
|
45651
|
+
* WAITS FOR THE APPROVAL TO LAND before returning. `Erc20Service.approve` resolves with the hash the
|
|
45652
|
+
* moment it is broadcast, so a caller that immediately re-reads the allowance sees the value from
|
|
45653
|
+
* BEFORE the approval — a UI then keeps showing "approve" and the user signs a second, pointless
|
|
45654
|
+
* approval. Returning early from a helper whose whole purpose is "the allowance is now sufficient" is
|
|
45655
|
+
* a footgun, so the wait lives here rather than in each caller.
|
|
45656
|
+
*/
|
|
45657
|
+
async approvePositionFunding(params) {
|
|
45658
|
+
const baseCtx = { srcChainKey: params.srcChainKey, action: "approve" };
|
|
45659
|
+
try {
|
|
45660
|
+
leverageYieldInvariant(params.amount > 0n, "amount must be greater than 0", { ...baseCtx, field: "amount" });
|
|
45661
|
+
const srcChainKey = params.srcChainKey;
|
|
45662
|
+
let inner = {
|
|
45663
|
+
ok: false,
|
|
45664
|
+
error: new Error(`[LeverageYieldService.approvePositionFunding] approve is unsupported on ${srcChainKey}`)
|
|
45665
|
+
};
|
|
45666
|
+
if (isHubChainKeyType(srcChainKey) || isEvmSpokeOnlyChainKeyType(srcChainKey)) {
|
|
45667
|
+
leverageYieldInvariant(isAddress(params.token), "Invalid token address", { ...baseCtx, field: "token" });
|
|
45668
|
+
inner = await this.spoke.approve({
|
|
45669
|
+
srcChainKey,
|
|
45670
|
+
token: params.token,
|
|
45671
|
+
amount: params.amount,
|
|
45672
|
+
owner: params.srcAddress,
|
|
45673
|
+
spender: await this.resolveFundingSpender(srcChainKey, params.srcAddress),
|
|
45674
|
+
raw: false,
|
|
45675
|
+
// `K` stays open here, so the provider is only checkable against the chain key inside `spoke.approve`.
|
|
45676
|
+
walletProvider: params.walletProvider
|
|
45677
|
+
});
|
|
45678
|
+
} else if (isStellarChainKeyType(srcChainKey)) {
|
|
45679
|
+
inner = await this.spoke.approve({
|
|
45680
|
+
srcChainKey,
|
|
45681
|
+
token: params.token,
|
|
45682
|
+
amount: params.amount,
|
|
45683
|
+
owner: params.srcAddress,
|
|
45684
|
+
raw: false,
|
|
45685
|
+
walletProvider: params.walletProvider
|
|
45686
|
+
});
|
|
45687
|
+
}
|
|
45688
|
+
if (!inner.ok) return { ok: false, error: approveFailed("leverageYield", inner.error, baseCtx) };
|
|
45689
|
+
if (params.walletProvider && isEvmWalletProviderType(params.walletProvider)) {
|
|
45690
|
+
const receipt = await params.walletProvider.waitForTransactionReceipt(
|
|
45691
|
+
inner.value
|
|
45692
|
+
);
|
|
45693
|
+
if (receipt.status !== "success") {
|
|
45694
|
+
return { ok: false, error: approveFailed("leverageYield", "transaction reverted", baseCtx) };
|
|
45695
|
+
}
|
|
45696
|
+
} else {
|
|
45697
|
+
const landed = await this.spoke.verifyTxHash({ txHash: inner.value, chainKey: params.srcChainKey });
|
|
45698
|
+
if (!landed.ok) return { ok: false, error: approveFailed("leverageYield", landed.error, baseCtx) };
|
|
45699
|
+
}
|
|
45700
|
+
return inner;
|
|
45701
|
+
} catch (error) {
|
|
45702
|
+
if (isLeverageYieldApproveError(error)) return { ok: false, error };
|
|
45703
|
+
return { ok: false, error: approveFailed("leverageYield", error, baseCtx) };
|
|
45704
|
+
}
|
|
45705
|
+
}
|
|
45706
|
+
/**
|
|
45707
|
+
* Who pulls the deposit on an EVM source chain.
|
|
45708
|
+
*
|
|
45709
|
+
* On the hub the pull happens inside the routed batch, so the spender is the user's own hub wallet
|
|
45710
|
+
* rather than any protocol contract; on an EVM spoke it is that spoke's asset manager. Chains with
|
|
45711
|
+
* no ERC-20 allowance never reach here.
|
|
45712
|
+
*/
|
|
45713
|
+
async resolveFundingSpender(srcChainKey, srcAddress) {
|
|
45714
|
+
if (isHubChainKeyType(srcChainKey)) return await this.hubProvider.getUserHubWalletAddress(srcAddress, srcChainKey);
|
|
45715
|
+
return this.config.getChainConfig(srcChainKey).addresses.assetManager;
|
|
45716
|
+
}
|
|
45717
|
+
/**
|
|
45718
|
+
* Opens a leveraged position, funded from any chain, in one signature.
|
|
45719
|
+
*
|
|
45720
|
+
* The deposit is carried to the user's hub wallet and the position is created from inside that
|
|
45721
|
+
* same batch, so there is no window in which the funds sit on the hub unattached to a position.
|
|
45722
|
+
* On the hub this routes locally; from a spoke it relays and this waits for the hub side to land.
|
|
45723
|
+
*
|
|
45724
|
+
* WHAT IS AND IS NOT DONE WHEN THIS RESOLVES: the position exists and its leverage intent is
|
|
45725
|
+
* posted. The leverage itself is not applied — a solver fills that intent afterwards. And an
|
|
45726
|
+
* intent is invisible to the solver until its hub transaction hash is reported, so pass the
|
|
45727
|
+
* returned `dstChainTxHash` to {@link LeverageYieldService.notifySolver}; an unreported intent
|
|
45728
|
+
* simply expires and the deposit comes back.
|
|
45729
|
+
*
|
|
45730
|
+
* Spoke tokens need the spoke asset manager approved first, the same as any other deposit.
|
|
45731
|
+
*
|
|
45732
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN. Every path here has been exercised
|
|
45733
|
+
* end to end on Sonic, the hub. From a spoke the inbound half is proven only by a fork
|
|
45734
|
+
* replay of a real relayed message, and the OUTBOUND half — an exit or a cancellation
|
|
45735
|
+
* delivering the underlying back to the spoke it came from — has never run on mainnet.
|
|
45736
|
+
* Treat a non-hub `srcChainKey` as experimental until it has. Bitcoin is refused
|
|
45737
|
+
* outright — see {@link BITCOIN_UNSUPPORTED_MESSAGE}.
|
|
45738
|
+
*/
|
|
45739
|
+
async openPosition(_params) {
|
|
45740
|
+
return this.runPositionOpen(
|
|
45741
|
+
_params,
|
|
45742
|
+
"openPosition",
|
|
45743
|
+
(owner, params) => this.buildOpenPositionData({ ...params, owner })
|
|
45744
|
+
);
|
|
45745
|
+
}
|
|
45746
|
+
/**
|
|
45747
|
+
* Opens a leveraged position from the **debt** token, funded from any chain.
|
|
45748
|
+
*
|
|
45749
|
+
* Same transport and the same asynchronous settlement as
|
|
45750
|
+
* {@link LeverageYieldService.openPosition} — see there for what is and is not done when this
|
|
45751
|
+
* resolves. The difference is only which side the user funds: here they hand over debt token and
|
|
45752
|
+
* end up long collateral they never held.
|
|
45753
|
+
*
|
|
45754
|
+
* Requires the deployed implementation to have a debt-side hook configured; without one the
|
|
45755
|
+
* position reverts `DebtSideHookUnavailable`.
|
|
45756
|
+
*
|
|
45757
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN. Every path here has been exercised
|
|
45758
|
+
* end to end on Sonic, the hub. From a spoke the inbound half is proven only by a fork
|
|
45759
|
+
* replay of a real relayed message, and the OUTBOUND half — an exit or a cancellation
|
|
45760
|
+
* delivering the underlying back to the spoke it came from — has never run on mainnet.
|
|
45761
|
+
* Treat a non-hub `srcChainKey` as experimental until it has. Bitcoin is refused
|
|
45762
|
+
* outright — see {@link BITCOIN_UNSUPPORTED_MESSAGE}.
|
|
45763
|
+
*/
|
|
45764
|
+
async openPositionFromDebtToken(_params) {
|
|
45765
|
+
return this.runPositionOpen(
|
|
45766
|
+
_params,
|
|
45767
|
+
"openPositionFromDebtToken",
|
|
45768
|
+
(owner, params) => this.buildOpenPositionFromDebtTokenData({ ...params, owner })
|
|
45769
|
+
);
|
|
45770
|
+
}
|
|
45771
|
+
/**
|
|
45772
|
+
* Shared body of the two open paths. They differ only in which factory call the payload ends with,
|
|
45773
|
+
* so everything around it — owner resolution, deposit, verify, relay — lives here rather than
|
|
45774
|
+
* being written twice and drifting.
|
|
45775
|
+
*/
|
|
45776
|
+
/**
|
|
45777
|
+
* Instrumentation for both opens. Wrapping the shared runner rather than each entry point keeps
|
|
45778
|
+
* `openPosition` and `openPositionFromDebtToken` from drifting, and `action` is already threaded
|
|
45779
|
+
* through for the error context, so it doubles as the analytics action.
|
|
45780
|
+
*
|
|
45781
|
+
* `start` carries only the fields common to both param shapes — the funding side's token and
|
|
45782
|
+
* amount. The side-specific ones (`borrowToken`/`borrowAmount` vs `collateral`/`totalInput`) are
|
|
45783
|
+
* not on `PositionFundingParams`, and inventing a cast to reach them would be worse than omitting
|
|
45784
|
+
* them.
|
|
45785
|
+
*/
|
|
45786
|
+
async runPositionOpen(_params, action, build) {
|
|
45787
|
+
return this.config.analytics.trackResult(
|
|
45788
|
+
"leverageYield",
|
|
45789
|
+
action,
|
|
45790
|
+
() => this.executePositionOpen(_params, action, build),
|
|
45791
|
+
{
|
|
45792
|
+
start: () => ({
|
|
45793
|
+
srcChainKey: _params.params.srcChainKey,
|
|
45794
|
+
srcAddress: _params.params.srcAddress,
|
|
45795
|
+
inputToken: _params.params.token,
|
|
45796
|
+
inputAmount: _params.params.amount,
|
|
45797
|
+
eModeCategory: _params.params.eModeCategory
|
|
45798
|
+
}),
|
|
45799
|
+
success: (value) => ({ srcTxHash: value.srcChainTxHash, dstTxHash: value.dstChainTxHash }),
|
|
45800
|
+
failure: (error) => ({ code: error.code })
|
|
45801
|
+
}
|
|
45802
|
+
);
|
|
45803
|
+
}
|
|
45804
|
+
async executePositionOpen(_params, action, buildData) {
|
|
45805
|
+
const { params, timeout = DEFAULT_RELAY_TX_TIMEOUT } = _params;
|
|
45806
|
+
const baseCtx = {
|
|
45807
|
+
srcChainKey: params.srcChainKey,
|
|
45808
|
+
action
|
|
45809
|
+
};
|
|
45810
|
+
try {
|
|
45811
|
+
leverageYieldInvariant(!isBitcoinChainKeyType(params.srcChainKey), BITCOIN_UNSUPPORTED_MESSAGE, {
|
|
45812
|
+
...baseCtx,
|
|
45813
|
+
field: "srcChainKey"
|
|
45814
|
+
});
|
|
45815
|
+
leverageYieldInvariant(params.amount > 0n, "amount must be greater than 0", { ...baseCtx, field: "amount" });
|
|
45816
|
+
leverageYieldInvariant(params.minCollateralOut > 0n, "minCollateralOut must be greater than 0", {
|
|
45817
|
+
...baseCtx,
|
|
45818
|
+
field: "minCollateralOut"
|
|
45819
|
+
});
|
|
45820
|
+
leverageYieldInvariant(
|
|
45821
|
+
isUndefinedOrValidWalletProviderForChainKey(params.srcChainKey, _params.walletProvider),
|
|
45822
|
+
`Invalid wallet provider for chain key: ${params.srcChainKey}`,
|
|
45823
|
+
{ ...baseCtx, field: "walletProvider" }
|
|
45824
|
+
);
|
|
45825
|
+
const hubWallet = await this.hubProvider.getUserHubWalletAddress(params.srcAddress, params.srcChainKey);
|
|
45826
|
+
const data = await buildData(hubWallet, params);
|
|
45827
|
+
if (!data.ok) return data;
|
|
45828
|
+
const txResult = await this.spoke.deposit({
|
|
45829
|
+
srcChainKey: params.srcChainKey,
|
|
45830
|
+
srcAddress: params.srcAddress,
|
|
45831
|
+
to: hubWallet,
|
|
45832
|
+
token: params.token,
|
|
45833
|
+
amount: params.amount,
|
|
45834
|
+
data: data.value,
|
|
45835
|
+
skipSimulation: _params.skipSimulation ?? false,
|
|
45836
|
+
raw: false,
|
|
45837
|
+
walletProvider: _params.walletProvider
|
|
45838
|
+
});
|
|
45839
|
+
if (!txResult.ok) {
|
|
45840
|
+
if (isLeverageYieldCreateIntentError(txResult.error)) return { ok: false, error: txResult.error };
|
|
45841
|
+
return { ok: false, error: intentCreationFailed("leverageYield", txResult.error, baseCtx) };
|
|
45842
|
+
}
|
|
45843
|
+
return await this.settleHubWalletMessage(txResult.value, { address: hubWallet, payload: data.value }, baseCtx, {
|
|
45844
|
+
timeout
|
|
45845
|
+
});
|
|
45846
|
+
} catch (error) {
|
|
45847
|
+
if (isLeverageYieldSwapError(error)) return { ok: false, error };
|
|
45848
|
+
return { ok: false, error: executionFailed("leverageYield", error, { ...baseCtx, phase: "intentCreation" }) };
|
|
45849
|
+
}
|
|
45850
|
+
}
|
|
45851
|
+
/**
|
|
45852
|
+
* Which address actually funds a position from `chainKey` — what a balance must be read against,
|
|
45853
|
+
* and what the deposit is built from.
|
|
45854
|
+
*
|
|
45855
|
+
* ONE ANSWER FOR BOTH, because two answers cost an open on mainnet: the balance was read from the
|
|
45856
|
+
* registry `address` while the deposit rewrote it to `hubAsset`, so for Sonic's native S the form
|
|
45857
|
+
* showed 42 S and the batch then called `wS.transferFrom(user, hubWallet, 5e18)` against a wS
|
|
45858
|
+
* balance of zero. The approval was correct; the revert surfaced as nothing but "External call
|
|
45859
|
+
* failed". Any integrator reading a balance for a position deposit needs this same answer.
|
|
45860
|
+
*
|
|
45861
|
+
* Three addresses hang off a registry entry and they are not interchangeable:
|
|
45862
|
+
*
|
|
45863
|
+
* `address` the spoke-side original; for a bridged entry it can name another chain entirely
|
|
45864
|
+
* `hubAsset` what the user holds ON THE HUB, and the vault's deposit input
|
|
45865
|
+
* `vault` the hub money-market reserve the position ends up in
|
|
45866
|
+
*
|
|
45867
|
+
* Off the hub the answer is always `address` — that is the chain the user is on. On the hub it is
|
|
45868
|
+
* `hubAsset`, EXCEPT for a native entry: `EvmSpokeService.deposit` keys on the chain's own
|
|
45869
|
+
* `nativeToken` to send `msg.value` rather than an ERC-20 `transferFrom`, and the native entry
|
|
45870
|
+
* carries exactly that sentinel as its `address`. Rewriting that to the wrapper asks for a token
|
|
45871
|
+
* the wallet does not hold.
|
|
45872
|
+
*
|
|
45873
|
+
* @returns The funding address, or `undefined` when the token is not supported on `chainKey`.
|
|
45874
|
+
*/
|
|
45875
|
+
resolvePositionFunding(chainKey, token) {
|
|
45876
|
+
const address = resolvePositionFundingAddress(chainKey, this.hubProvider.chainConfig.chain.key, token);
|
|
45877
|
+
return address === "" ? void 0 : address;
|
|
45878
|
+
}
|
|
45879
|
+
/**
|
|
45880
|
+
* Quotes one leg of a position operation: the borrowed side when levering up, the collateral when
|
|
45881
|
+
* levering down or exiting.
|
|
45882
|
+
*
|
|
45883
|
+
* Use this rather than {@link LeverageYieldService.getQuote} for a position. Both hit the same
|
|
45884
|
+
* endpoint, but this one names the hub reserves as the pair the intent actually swaps and quotes
|
|
45885
|
+
* GROSS — see `positionLegQuote.ts` for why either alone gets the floor wrong. Feed `quotedAmount`
|
|
45886
|
+
* to {@link projectLeverageLeg}.
|
|
45887
|
+
*
|
|
45888
|
+
* A refusal is not always a dead pair: {@link isNoRouteRefusal} is also what the solver answers
|
|
45889
|
+
* for a leg that is only too small, and telling the two apart means quoting again at a healthy
|
|
45890
|
+
* notional. That size is priced, so it is the caller's to choose.
|
|
45891
|
+
*/
|
|
45892
|
+
async getPositionLegQuote(params) {
|
|
45893
|
+
const hubChainKey = this.hubProvider.chainConfig.chain.key;
|
|
45894
|
+
const quote = await this.getQuote({
|
|
45895
|
+
token_src: params.inputHubToken,
|
|
45896
|
+
token_src_blockchain_id: hubChainKey,
|
|
45897
|
+
token_dst: params.outputHubToken,
|
|
45898
|
+
token_dst_blockchain_id: hubChainKey,
|
|
45899
|
+
amount: params.amount,
|
|
45900
|
+
quote_type: "exact_input",
|
|
45901
|
+
// Explicit, not omitted: omitting it applies the configured leverage-yield fee.
|
|
45902
|
+
partnerFee: { address: zeroAddress, percentage: 0 }
|
|
45903
|
+
});
|
|
45904
|
+
if (!quote.ok) return quote;
|
|
45905
|
+
return { ok: true, value: { quotedAmount: quote.value.quoted_amount } };
|
|
45906
|
+
}
|
|
45907
|
+
/**
|
|
45908
|
+
* Opens a leveraged position AND reports the intent it posts. Prefer this to
|
|
45909
|
+
* {@link LeverageYieldService.openPosition} / {@link LeverageYieldService.openPositionFromDebtToken}.
|
|
45910
|
+
*
|
|
45911
|
+
* Those two only post the intent. Reporting it is a separate call that must not be skipped — an
|
|
45912
|
+
* unreported intent expires unfilled, so the owner is left funded with leverage that never arrives
|
|
45913
|
+
* and nothing said so. Pairing them here is the difference between an API that works and one that
|
|
45914
|
+
* works only if you read the docs.
|
|
45915
|
+
*
|
|
45916
|
+
* `side` picks which asset funds the open: `'collateral'` supplies the deposit and borrows against
|
|
45917
|
+
* it, `'debt'` hands the deposit to the solver and ends up long collateral never held.
|
|
45918
|
+
*
|
|
45919
|
+
* RESOLVING MEANS THE INTENT IS LIVE, not that the position is open, and a failed notification is
|
|
45920
|
+
* still `ok: true` — see {@link LeveragePositionIntentResult}.
|
|
45921
|
+
*
|
|
45922
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN — see `operatePosition`.
|
|
45923
|
+
*/
|
|
45924
|
+
async openLeveragePosition(_params) {
|
|
45925
|
+
return this.config.analytics.trackResult(
|
|
45926
|
+
"leverageYield",
|
|
45927
|
+
"openLeveragePosition",
|
|
45928
|
+
async () => {
|
|
45929
|
+
const { side, ...rest } = _params;
|
|
45930
|
+
const opened = side === "debt" ? await this.openPositionFromDebtToken(
|
|
45931
|
+
rest
|
|
45932
|
+
) : await this.openPosition(rest);
|
|
45933
|
+
if (!opened.ok) return opened;
|
|
45934
|
+
return { ok: true, value: await reportPositionIntent(this.notifyIntent, opened.value) };
|
|
45935
|
+
},
|
|
45936
|
+
{
|
|
45937
|
+
start: () => ({ srcChainKey: _params.params.srcChainKey, side: _params.side ?? "collateral" }),
|
|
45938
|
+
success: (result) => ({ ...result.txHashes, notified: result.notified }),
|
|
45939
|
+
failure: (error) => ({ code: error.code })
|
|
45940
|
+
}
|
|
45941
|
+
);
|
|
45942
|
+
}
|
|
45943
|
+
/**
|
|
45944
|
+
* Runs position calls that POST A SOLVER INTENT — `addLeverage` and `decreaseLeverage` — and
|
|
45945
|
+
* reports it. Prefer this to {@link LeverageYieldService.operatePosition} for those two.
|
|
45946
|
+
*
|
|
45947
|
+
* USE {@link LeverageYieldService.runLeveragePositionOperation} FOR `withdraw`, `settle` AND
|
|
45948
|
+
* `cancel`. Those are synchronous on the hub and need no notification, and the split is not
|
|
45949
|
+
* cosmetic: sending a leverage change through the route-only path leaves an intent nothing will
|
|
45950
|
+
* fill, and it expires without a word. The other direction is merely noisy.
|
|
45951
|
+
*
|
|
45952
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN — see `operatePosition`.
|
|
45953
|
+
*/
|
|
45954
|
+
async submitLeveragePositionIntent(_params) {
|
|
45955
|
+
return this.config.analytics.trackResult(
|
|
45956
|
+
"leverageYield",
|
|
45957
|
+
"submitLeveragePositionIntent",
|
|
45958
|
+
async () => {
|
|
45959
|
+
const routed = await this.operatePosition(_params);
|
|
45960
|
+
if (!routed.ok) return routed;
|
|
45961
|
+
return { ok: true, value: await reportPositionIntent(this.notifyIntent, routed.value) };
|
|
45962
|
+
},
|
|
45963
|
+
{
|
|
45964
|
+
start: () => ({ srcChainKey: _params.params.srcChainKey, calls: _params.params.calls.length }),
|
|
45965
|
+
success: (result) => ({ ...result.txHashes, notified: result.notified }),
|
|
45966
|
+
failure: (error) => ({ code: error.code })
|
|
45967
|
+
}
|
|
45968
|
+
);
|
|
45969
|
+
}
|
|
45970
|
+
/**
|
|
45971
|
+
* Runs position calls that do NOT post an intent — `withdraw`, `settle` and `cancel` — as the
|
|
45972
|
+
* owning hub wallet. They are synchronous on the hub, so resolving means the work is done.
|
|
45973
|
+
*
|
|
45974
|
+
* Still routed, never sent directly: the position's `onlyOwner` is the hub wallet, so a builder's
|
|
45975
|
+
* transaction sent from the signer reverts `NotOwner`. Use
|
|
45976
|
+
* {@link LeverageYieldService.submitLeveragePositionIntent} for `addLeverage` and
|
|
45977
|
+
* `decreaseLeverage`, which this deliberately does not report.
|
|
45978
|
+
*
|
|
45979
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN, and this path carries the worst of
|
|
45980
|
+
* it: an exit or cancellation delivering the underlying back to the spoke it came from
|
|
45981
|
+
* has never run on mainnet.
|
|
45982
|
+
*/
|
|
45983
|
+
async runLeveragePositionOperation(_params) {
|
|
45984
|
+
return this.operatePosition(_params);
|
|
45985
|
+
}
|
|
45986
|
+
/** Bound once so the notify half can be handed around without losing `this`. */
|
|
45987
|
+
notifyIntent = (request) => this.notifySolver(request);
|
|
45988
|
+
/**
|
|
45989
|
+
* Runs position calls as the user's hub wallet, from any chain.
|
|
45990
|
+
*
|
|
45991
|
+
* The write counterpart to the read hooks: add or decrease leverage, withdraw, settle, cancel. No
|
|
45992
|
+
* funds move, so this is a bare message rather than a deposit — on the hub it routes locally, from
|
|
45993
|
+
* a spoke it relays and this waits for the hub side to land.
|
|
45994
|
+
*
|
|
45995
|
+
* The leverage calls only *post* an intent, so a resolved promise means the intent is live, not
|
|
45996
|
+
* that leverage moved. Report the returned `dstChainTxHash` to
|
|
45997
|
+
* {@link LeverageYieldService.notifySolver} for those two; `withdraw`, `settle` and `cancel` are
|
|
45998
|
+
* synchronous on the hub and need no notification.
|
|
45999
|
+
*
|
|
46000
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN. Every path here has been exercised
|
|
46001
|
+
* end to end on Sonic, the hub. From a spoke the inbound half is proven only by a fork
|
|
46002
|
+
* replay of a real relayed message, and the OUTBOUND half — an exit or a cancellation
|
|
46003
|
+
* delivering the underlying back to the spoke it came from — has never run on mainnet.
|
|
46004
|
+
* Treat a non-hub `srcChainKey` as experimental until it has. Bitcoin is refused
|
|
46005
|
+
* outright — see {@link BITCOIN_UNSUPPORTED_MESSAGE}.
|
|
46006
|
+
*/
|
|
46007
|
+
async operatePosition(_params) {
|
|
46008
|
+
return this.config.analytics.trackResult(
|
|
46009
|
+
"leverageYield",
|
|
46010
|
+
"operatePosition",
|
|
46011
|
+
() => this.executePositionOperation(_params),
|
|
46012
|
+
{
|
|
46013
|
+
// The calls themselves are not emitted — they are arbitrary hub calldata. The count is
|
|
46014
|
+
// enough to tell a batched adjust from a single write.
|
|
46015
|
+
start: () => ({
|
|
46016
|
+
srcChainKey: _params.params.srcChainKey,
|
|
46017
|
+
srcAddress: _params.params.srcAddress,
|
|
46018
|
+
callCount: _params.params.calls.length
|
|
46019
|
+
}),
|
|
46020
|
+
success: (value) => ({ srcTxHash: value.srcChainTxHash, dstTxHash: value.dstChainTxHash }),
|
|
46021
|
+
failure: (error) => ({ code: error.code })
|
|
46022
|
+
}
|
|
46023
|
+
);
|
|
46024
|
+
}
|
|
46025
|
+
async executePositionOperation(_params) {
|
|
46026
|
+
const { params, timeout = DEFAULT_RELAY_TX_TIMEOUT } = _params;
|
|
46027
|
+
const baseCtx = {
|
|
46028
|
+
srcChainKey: params.srcChainKey,
|
|
46029
|
+
action: "operatePosition"
|
|
46030
|
+
};
|
|
46031
|
+
try {
|
|
46032
|
+
leverageYieldInvariant(!isBitcoinChainKeyType(params.srcChainKey), BITCOIN_UNSUPPORTED_MESSAGE, {
|
|
46033
|
+
...baseCtx,
|
|
46034
|
+
field: "srcChainKey"
|
|
46035
|
+
});
|
|
46036
|
+
leverageYieldInvariant(params.calls.length > 0, "at least one call is required", {
|
|
46037
|
+
...baseCtx,
|
|
46038
|
+
field: "calls"
|
|
46039
|
+
});
|
|
46040
|
+
leverageYieldInvariant(
|
|
46041
|
+
isUndefinedOrValidWalletProviderForChainKey(params.srcChainKey, _params.walletProvider),
|
|
46042
|
+
`Invalid wallet provider for chain key: ${params.srcChainKey}`,
|
|
46043
|
+
{ ...baseCtx, field: "walletProvider" }
|
|
46044
|
+
);
|
|
46045
|
+
const hubWallet = await this.hubProvider.getUserHubWalletAddress(params.srcAddress, params.srcChainKey);
|
|
46046
|
+
const payload = this.encodePositionCalls(params.calls);
|
|
46047
|
+
const txResult = await this.spoke.sendMessage({
|
|
46048
|
+
srcChainKey: params.srcChainKey,
|
|
46049
|
+
srcAddress: params.srcAddress,
|
|
46050
|
+
dstChainKey: HUB_CHAIN_KEY,
|
|
46051
|
+
dstAddress: hubWallet,
|
|
46052
|
+
payload,
|
|
46053
|
+
skipSimulation: _params.skipSimulation ?? false,
|
|
46054
|
+
raw: false,
|
|
46055
|
+
walletProvider: _params.walletProvider
|
|
46056
|
+
});
|
|
46057
|
+
if (!txResult.ok) {
|
|
46058
|
+
if (isLeverageYieldCreateIntentError(txResult.error)) return { ok: false, error: txResult.error };
|
|
46059
|
+
return { ok: false, error: intentCreationFailed("leverageYield", txResult.error, baseCtx) };
|
|
46060
|
+
}
|
|
46061
|
+
return await this.settleHubWalletMessage(txResult.value, { address: hubWallet, payload }, baseCtx, { timeout });
|
|
46062
|
+
} catch (error) {
|
|
46063
|
+
if (isLeverageYieldSwapError(error)) return { ok: false, error };
|
|
46064
|
+
return { ok: false, error: executionFailed("leverageYield", error, { ...baseCtx, phase: "intentCreation" }) };
|
|
46065
|
+
}
|
|
46066
|
+
}
|
|
46067
|
+
/**
|
|
46068
|
+
* Verifies a submitted source transaction and, off the hub, relays it and waits for the hub side.
|
|
46069
|
+
*
|
|
46070
|
+
* Shared by both write paths because the tail is identical whether funds moved or not. The hub
|
|
46071
|
+
* short-circuit is not an optimisation: a hub transaction has already executed the calls, so there
|
|
46072
|
+
* is nothing to relay, and both hashes are the same transaction.
|
|
46073
|
+
*/
|
|
46074
|
+
async settleHubWalletMessage(srcTxHash, relayData, baseCtx, opts) {
|
|
46075
|
+
const verify = await this.spoke.verifyTxHash({ txHash: srcTxHash, chainKey: baseCtx.srcChainKey });
|
|
46076
|
+
if (!verify.ok) return { ok: false, error: verifyFailed("leverageYield", verify.error, baseCtx) };
|
|
46077
|
+
if (isHubChainKeyType(baseCtx.srcChainKey)) {
|
|
46078
|
+
const receipt = await this.hubProvider.publicClient.waitForTransactionReceipt({
|
|
46079
|
+
hash: srcTxHash,
|
|
46080
|
+
timeout: opts.timeout
|
|
46081
|
+
});
|
|
46082
|
+
if (receipt.status !== "success") {
|
|
46083
|
+
return {
|
|
46084
|
+
ok: false,
|
|
46085
|
+
error: verifyFailed("leverageYield", new Error(`hub transaction ${srcTxHash} reverted`), baseCtx)
|
|
46086
|
+
};
|
|
46087
|
+
}
|
|
46088
|
+
return { ok: true, value: { srcChainTxHash: srcTxHash, dstChainTxHash: srcTxHash } };
|
|
46089
|
+
}
|
|
46090
|
+
const packet = await relayTxAndWaitPacket({
|
|
46091
|
+
srcTxHash,
|
|
46092
|
+
data: relayData,
|
|
46093
|
+
chainKey: baseCtx.srcChainKey,
|
|
46094
|
+
relayerApiEndpoint: this.config.relay.relayerApiEndpoint,
|
|
46095
|
+
timeout: opts.timeout
|
|
46096
|
+
});
|
|
46097
|
+
if (!packet.ok) {
|
|
46098
|
+
return {
|
|
46099
|
+
ok: false,
|
|
46100
|
+
error: mapRelayFailure(packet.error, {
|
|
46101
|
+
feature: "leverageYield",
|
|
46102
|
+
action: baseCtx.action,
|
|
46103
|
+
srcChainKey: baseCtx.srcChainKey
|
|
46104
|
+
})
|
|
46105
|
+
};
|
|
46106
|
+
}
|
|
46107
|
+
return { ok: true, value: { srcChainTxHash: srcTxHash, dstChainTxHash: packet.value.dst_tx_hash } };
|
|
46108
|
+
}
|
|
44694
46109
|
};
|
|
44695
46110
|
|
|
44696
46111
|
// src/sponsoring/errors.ts
|
|
@@ -44718,12 +46133,12 @@ function toDomainCode(value) {
|
|
|
44718
46133
|
}
|
|
44719
46134
|
function readErrorBody(body) {
|
|
44720
46135
|
if (typeof body !== "object" || body === null) return {};
|
|
44721
|
-
const
|
|
44722
|
-
const retryAfterSeconds = typeof
|
|
44723
|
-
const sponsorSequence = typeof
|
|
46136
|
+
const record = body;
|
|
46137
|
+
const retryAfterSeconds = typeof record.retryAfterSeconds === "number" && Number.isFinite(record.retryAfterSeconds) && record.retryAfterSeconds > 0 ? record.retryAfterSeconds : void 0;
|
|
46138
|
+
const sponsorSequence = typeof record.sponsorSequence === "string" && /^\d+$/.test(record.sponsorSequence) ? record.sponsorSequence : void 0;
|
|
44724
46139
|
return {
|
|
44725
|
-
message: typeof
|
|
44726
|
-
code: toDomainCode(
|
|
46140
|
+
message: typeof record.message === "string" ? record.message : void 0,
|
|
46141
|
+
code: toDomainCode(record.error),
|
|
44727
46142
|
retryAfterSeconds,
|
|
44728
46143
|
sponsorSequence
|
|
44729
46144
|
};
|
|
@@ -45379,6 +46794,81 @@ var PARTNER_CODES = /* @__PURE__ */ new Set([
|
|
|
45379
46794
|
"UNKNOWN"
|
|
45380
46795
|
]);
|
|
45381
46796
|
var isPartnerError = isCodeMember(PARTNER_CODES);
|
|
46797
|
+
function sizeLeverageBorrow(request) {
|
|
46798
|
+
const { side, deposit, depositDecimals, collateralPriceUsd, borrowPriceUsd, borrowDecimals, leverage } = request;
|
|
46799
|
+
const depositTokens = Number(formatUnits(deposit, depositDecimals));
|
|
46800
|
+
const depositUsd = depositTokens * (side === "debt" ? borrowPriceUsd : collateralPriceUsd);
|
|
46801
|
+
const RATIO_SCALE = 1000000000n;
|
|
46802
|
+
const ratio = borrowPriceUsd > 0 && depositTokens > 0 ? depositUsd * Math.max(leverage - 1, 0) / borrowPriceUsd / depositTokens : 0;
|
|
46803
|
+
const borrowAmount = deposit * BigInt(Math.floor(ratio * Number(RATIO_SCALE))) * 10n ** BigInt(borrowDecimals) / (RATIO_SCALE * 10n ** BigInt(depositDecimals));
|
|
46804
|
+
const depositInBorrowUnits = deposit * 10n ** BigInt(borrowDecimals) / 10n ** BigInt(depositDecimals);
|
|
46805
|
+
const intentInput = side === "debt" ? borrowAmount + depositInBorrowUnits : borrowAmount;
|
|
46806
|
+
const feeAmount = request.feeBps ? intentInput * BigInt(Math.round(request.feeBps)) / 10000n : 0n;
|
|
46807
|
+
const borrowUsd = Number(formatUnits(borrowAmount, borrowDecimals)) * borrowPriceUsd;
|
|
46808
|
+
const feeUsd = Number(formatUnits(feeAmount, borrowDecimals)) * borrowPriceUsd;
|
|
46809
|
+
return {
|
|
46810
|
+
borrowAmount,
|
|
46811
|
+
intentInput,
|
|
46812
|
+
depositUsd,
|
|
46813
|
+
// Taken from the amount actually being borrowed, so the projection cannot disagree with the
|
|
46814
|
+
// transaction by the rounding above.
|
|
46815
|
+
borrowUsd,
|
|
46816
|
+
feeAmount,
|
|
46817
|
+
// The fee is borrowed on top on a leverage-up, so it is debt even though the solver never sees it.
|
|
46818
|
+
debtUsd: borrowUsd + feeUsd
|
|
46819
|
+
};
|
|
46820
|
+
}
|
|
46821
|
+
function projectLeverageLeg(request, quote, risk, slippagePct) {
|
|
46822
|
+
const { side, collateralPriceUsd, leverage } = request;
|
|
46823
|
+
const sized = sizeLeverageBorrow(request);
|
|
46824
|
+
const { depositUsd, borrowUsd } = sized;
|
|
46825
|
+
const floor = quote.quotedCollateral * BigInt(Math.round((100 - slippagePct) * 100)) / 10000n;
|
|
46826
|
+
const minCollateralOut = floor > 0n ? floor : 1n;
|
|
46827
|
+
const floorUsd = Number(formatUnits(minCollateralOut, quote.collateralDecimals)) * collateralPriceUsd;
|
|
46828
|
+
const quotedUsd = Number(formatUnits(quote.quotedCollateral, quote.collateralDecimals)) * collateralPriceUsd;
|
|
46829
|
+
const inputUsd = side === "debt" ? depositUsd * leverage : borrowUsd;
|
|
46830
|
+
const f = inputUsd > 0 ? floorUsd / inputUsd : 0;
|
|
46831
|
+
const haircut = inputUsd > 0 ? 1 - quotedUsd / inputUsd : 0;
|
|
46832
|
+
const collateralUsd = (side === "debt" ? 0 : depositUsd) + floorUsd;
|
|
46833
|
+
const debtUsd = sized.debtUsd;
|
|
46834
|
+
const ltv = collateralUsd > 0 ? debtUsd / collateralUsd : 0;
|
|
46835
|
+
const ltvF = risk.ltv * f;
|
|
46836
|
+
const phi = (request.feeBps ?? 0) / 1e4;
|
|
46837
|
+
const denominator = 1 + phi - ltvF;
|
|
46838
|
+
const usableMaxLeverage = risk.ltv <= 0 ? 1 : denominator <= 0 ? Number.POSITIVE_INFINITY : side === "debt" ? 1 / denominator : 1 + risk.ltv / denominator;
|
|
46839
|
+
const equityUsd = collateralUsd - debtUsd;
|
|
46840
|
+
return {
|
|
46841
|
+
minCollateralOut,
|
|
46842
|
+
collateralUsd,
|
|
46843
|
+
debtUsd,
|
|
46844
|
+
exposureLeverage: equityUsd > 0 ? collateralUsd / equityUsd : Number.POSITIVE_INFINITY,
|
|
46845
|
+
ltv,
|
|
46846
|
+
healthFactor: debtUsd > 0 ? collateralUsd * risk.liquidationThreshold / debtUsd : Number.POSITIVE_INFINITY,
|
|
46847
|
+
exceedsMaxLtv: ltv > risk.ltv,
|
|
46848
|
+
haircut,
|
|
46849
|
+
inputUsd,
|
|
46850
|
+
costUsd: inputUsd * haircut + sized.debtUsd - borrowUsd,
|
|
46851
|
+
usableMaxLeverage
|
|
46852
|
+
};
|
|
46853
|
+
}
|
|
46854
|
+
|
|
46855
|
+
// src/leverageYield/positionApyMath.ts
|
|
46856
|
+
function leveragedNetApyPct(supplyApyPct, borrowApyPct, leverage) {
|
|
46857
|
+
return supplyApyPct * leverage - borrowApyPct * (leverage - 1);
|
|
46858
|
+
}
|
|
46859
|
+
function timeToBreakevenYears(supplyApyPct, borrowApyPct, toLeverage, { costUsd, equityUsd, fromLeverage }) {
|
|
46860
|
+
if (!(equityUsd > 0) || !Number.isFinite(costUsd)) return void 0;
|
|
46861
|
+
if (costUsd <= 0) return "immediate";
|
|
46862
|
+
const incrementalPct = leveragedNetApyPct(supplyApyPct, borrowApyPct, toLeverage) - leveragedNetApyPct(supplyApyPct, borrowApyPct, fromLeverage);
|
|
46863
|
+
if (!(incrementalPct > 0)) return "never";
|
|
46864
|
+
return costUsd / (equityUsd * (incrementalPct / 100));
|
|
46865
|
+
}
|
|
46866
|
+
|
|
46867
|
+
// src/leverageYield/positionLegQuote.ts
|
|
46868
|
+
function isNoRouteRefusal(error) {
|
|
46869
|
+
const message = typeof error === "object" && error !== null && "detail" in error ? error.detail?.message : error instanceof Error ? error.message : void 0;
|
|
46870
|
+
return /no path was found/i.test(message ?? "");
|
|
46871
|
+
}
|
|
45382
46872
|
/*! Bundled license information:
|
|
45383
46873
|
|
|
45384
46874
|
@noble/hashes/utils.js:
|
|
@@ -45397,4 +46887,4 @@ var isPartnerError = isCodeMember(PARTNER_CODES);
|
|
|
45397
46887
|
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
45398
46888
|
*/
|
|
45399
46889
|
|
|
45400
|
-
export { ALLOWANCE_CHECK_CODES, APPROVE_CODES, AssetService, BACKEND_API_BASE_PATH, BITCOIN_CHAIN_KEYS, BITCOIN_CHAIN_KEYS_SET, BITCOIN_DUST_SATS, BTC_WALLET_ADDRESS_TYPES, BackendApiService, BackendHttpError, BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BitcoinSpokeService, BnUSDMigrationService, BridgeApiService, BridgeService, CHAIN_KEYS, CHAIN_LOGO_BASE_URL, CONFIG_VERSION, CREATE_INTENT_CODES, ChainKeys, ChainTypeArr, ClService, ConfigService, CustomSorobanServer, CustomStellarAccount, DEFAULT_API_BASE_URL, DEFAULT_BACKEND_API_ENDPOINT, DEFAULT_BACKEND_API_HEADERS, DEFAULT_BACKEND_API_TIMEOUT, DEFAULT_DEADLINE_OFFSET, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, DEFAULT_SPONSORING_API_ENDPOINT, DETAILED_STATUS_NOT_DELIVERED, DexService, EVM_CHAIN_ID_TO_KEY, EVM_CHAIN_KEYS, EVM_CHAIN_KEYS_SET, EVM_SPOKE_ONLY_CHAIN_KEYS, EVM_SPOKE_ONLY_CHAIN_KEYS_SET, Erc20Service, Erc4626Service, EvmAssetManagerService, EvmHubProvider, EvmSolverService, EvmSpokeService, EvmVaultTokenService, FEE_PERCENTAGE_SCALE, GAS_ESTIMATION_CODES, HALF_RAY, HALF_WAD, HUB_CHAIN_KEY, HookKind, HookService, HttpRelayError, HubVaultSymbols, ICON_CHAIN_KEYS, ICON_CHAIN_KEYS_SET, ICON_TX_RESULT_WAIT_MAX_RETRY, INJECTIVE_CHAIN_KEYS, INJECTIVE_CHAIN_KEYS_SET, INTENT_CHAIN_IDS, IconSpokeService, IcxMigrationService, Injective20Token, InjectiveSpokeService, IntentCreatedEventAbi, IntentDataService, IntentDataType, IntentFilledEventAbi, IntentRelayChainIdToChainKey, IntentsAbi, LOOKUP_CODES, LTV_PRECISION, LendingPoolService, LeverageYieldApiService, LeverageYieldService, LockupMultiplier, LockupPeriod, LsodaSymbols, LsodaTokens, MAX_UINT256, MigrationService, MintPositionEventAbi, MoneyMarketDataService, MoneyMarketService, NEAR_CHAIN_KEYS, NEAR_CHAIN_KEYS_SET, NEAR_DEFAULT_GAS, NEAR_STORAGE_DEPOSIT, NearSpokeService, ORACLE_CANDLE_INTERVALS, PartnerFeeClaimService, PartnerService, Permit2Service, ProtocolIntentsAbi, RAY, RAY_DECIMALS, RELAY_ERROR_CODES, RELAY_FALLBACK_FLOOR_MS, RELAY_REQUEST_TIMEOUT_MS, RadfiApiError, RadfiProvider, RecoveryService, RelayChainIdMap, SECONDS_PER_YEAR, SODAX_ERROR_CODES, SODAX_FEATURES, SOLANA_CHAIN_KEYS, SOLANA_CHAIN_KEYS_SET, SONIC_CHAIN_KEYS, SONIC_CHAIN_KEYS_SET, SPEED_TIER_SECONDS, SPEED_TIER_THRESHOLDS, SPONSORING_API_ERROR_CODES, SPONSORING_API_STELLAR_BASE_PATH, SPONSOR_CONFIG_TTL_MS, STACKS_CHAIN_KEYS, STACKS_CHAIN_KEYS_SET, STELLAR_BASE_RESERVE_TTL_MS, STELLAR_CHAIN_KEYS, STELLAR_CHAIN_KEYS_SET, STELLAR_TRUSTLINE_MIN_XLM_STROOPS, SUI_CHAIN_KEYS, SUI_CHAIN_KEYS_SET, SodaTokens, Sodax, SodaxError, SolanaSpokeService, SolverApiService, SolverIntentErrorCode, SolverIntentStatusCode, SonicSpokeService, SpokeService, SponsoringApiService, SponsoringService, StacksSpokeService, StakingLogic, StakingService, StatATokenAddresses, StellarSpokeService, SuiGrpcTransport, SuiSpokeService, SupportedMigrationTokens, SwapService, SwapsApiService, TOKEN_LOGO_BASE_URL, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, adjustAmountByFee, allowanceCheckFailed, apiConfig, approveFailed, arbitrumSupportedTokens, assetManagerAbi, avalancheSupportedTokens, balnSwapAbi, baseChainInfo, baseSupportedTokens, binomialApproximatedRayPow, bitcoinSupportedTokens, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bridgeConfig, bridgeInvariant, bscSupportedTokens, calcOpReturnOutputVbytes, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, canonicalizeBitcoinAddress, clPoolAbi, clPoolManagerAbi, clPositionManagerAbi, clQuoterAbi, clRouterAbi, clTickLensAbi, classifySponsorError, concentratedLiquidityConfig, connectionAbi, consoleLogger, convertTransactionInstructionToRaw, createBalanceCollector, createInvariant, deepMerge, defaultHookAbi, detectBitcoinAddressType, dexConfig, dexInvariant, dexPools, encodeAddress, encodeBtcPayloadToBytes, encodeContractCalls, encodeTokenIdentifier, erc20Abi, erc4626Abi, estimateBitcoinTxSize, estimateSwapSpeedTier, ethereumSupportedTokens, executionFailed, formatBasisPoints, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, gasEstimationFailed, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getAssetManagerIdl, getAssetManagerProgram, getChainKeyFromRelayChainId, getChainType, getCompoundedBalance, getConcentratedLiquidityConfig, getConnectionIdl, getConnectionProgram, getEvmChainKeyByChainId, getEvmViemChain, getIconAddressBytes, getIntentRelayChainId, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getPacket, getProvider, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getSolverConfig, getSpokeHook, getSpokeHooks, getStagingSolverTokens, getSupportedSolverTokens, getTransactionPackets, getbnUSDToken, hederaSupportedTokens, hexToBigInt, hexToSolanaAddress, hubConfig, hyper, hyperevmSupportedTokens, iconSupportedTokens, injectiveSupportedTokens, intentCreationFailed, isApprovalSupportedChainKeyType, isAuthFailure, isAuthStatus, isBackendHttpError, isBalnMigrateParams, isBitcoinChainKey, isBitcoinChainKeyType, isBitcoinWalletProviderType, isBridgeAllowanceCheckError, isBridgeApproveError, isBridgeCreateIntentError, isBridgeError, isBridgeLookupError, isBridgeOrchestrationError, isCodeMember, isDexApproveError, isDexCreateIntentError, isDexError, isEvmChainKey, isEvmChainKeyType, isEvmSpokeChainConfig, isEvmSpokeOnlyChainKey, isEvmSpokeOnlyChainKeyType, isEvmWalletProviderType, isFeatureError, isFillEvent, isHookSupportedToken, isHubChainKey, isHubChainKeyType, isIconAddress, isIconChainKey, isIconChainKeyType, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveChainKey, isInjectiveChainKeyType, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isLeverageYieldAllowanceCheckError, isLeverageYieldApproveError, isLeverageYieldCreateIntentError, isLeverageYieldError, isLeverageYieldLookupError, isLeverageYieldPostExecutionError, isLeverageYieldSwapError, isMigrateOrchestrationError, isMigrationAllowanceCheckError, isMigrationApproveError, isMigrationCreateIntentError, isMigrationError, isMigrationLookupError, isMoneyMarketAllowanceCheckError, isMoneyMarketApproveError, isMoneyMarketCreateIntentError, isMoneyMarketError, isMoneyMarketGasEstimationError, isMoneyMarketOrchestrationError, isNativeBitcoinToken, isNativeBitcoinTransfer, isNativeToken, isNearChainKey, isNearChainKeyType, isNewbnUSDChainId, isNewbnUSDToken, isOptionalBitcoinWalletProviderType, isOptionalEvmWalletProviderType, isOptionalStellarWalletProviderType, isOracleCandleInterval, isPartnerError, isPartnerFeeAmount, isPartnerFeePercentage, isPostExecutionError, isRawDestinationParams, isRecoveryError, isResponseAddressType, isResponseSigningType, isRevertMigrationOrchestrationError, isSodaxError, isSolanaChainKey, isSolanaChainKeyType, isSolanaNativeToken, isSonicChainKey, isSonicChainKeyType, isSpokeApproveParamsEvmSpoke, isSpokeApproveParamsHub, isSpokeApproveParamsStellar, isSpokeChainKey, isSpokeIsAllowanceValidParamsEvmSpoke, isSpokeIsAllowanceValidParamsHub, isSpokeIsAllowanceValidParamsStellar, isSponsoringConfigError, isSponsoringLookupError, isSponsoringOrchestrationError, isStacksChainKey, isStacksChainKeyType, isStakeOrchestrationError, isStakingAllowanceCheckError, isStakingApproveError, isStakingCreateIntentError, isStakingError, isStakingInfoFetchError, isStakingOrchestrationError, isStellarChainKey, isStellarChainKeyType, isStellarWalletProviderType, isSuiChainKey, isSuiChainKeyType, isSupportedBitcoinAddressType, isSwapCreateIntentError, isSwapError, isSwapSupportedToken, isUndefinedOrValidWalletProviderForChainKey, isUnifiedBnUSDMigrateParams, isValidBitcoinAddress, isValidInjectiveAddress, isValidNearAccountId, isValidWalletProviderForChainKey, kaiaSupportedTokens, leverageYieldConfig, leverageYieldInvariant, leverageYieldVaults, lightlinkSupportedTokens, lookupFailed, mapRelayFailure, mergeSodaxConfig, messageOf, migrationInvariant, mintPositionParamsAbi, mmInvariant, modifyLiquidityParamsAbi, moneyMarketConfig, moneyMarketReserveAssets, moneyMarketSupportedTokens, nativeToUSD, nearSupportedTokens, newbnUSDSpokeChainIds, noopAnalytics, normalize, normalizeBN, normalizePsbtToBase64, normalizeSignatureToBase64, normalizedToUsd, optimismSupportedTokens, pancakeSwapInfinityDefaultHookAbi, pancakeSwapInfinityPoolManagerAbi, pancakeSwapInfinityPositionManagerAbi, parseToStroops, parseTokenArrayFromJson, partnerInvariant, permit2Abi, polygonSupportedTokens, poolAbi, poolKeyAbi, randomUint256, rayDiv, rayMul, rayPow, rayToWad, recoveryInvariant, redbellySupportedTokens, relayConfig, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, resolveAnalytics, resolveLogger, retry, reverseEncodeAddress, robinhoodChain, robinhoodSupportedTokens, serializeAddressData, settleWalletBalances, silentLogger, sleep, sodaxConfig, sodaxInvariant, solanaSupportedTokens, solverConfig, sonicSupportedTokens, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainKeysSet, spokeHooks, sponsoringInvariant, stacksSupportedTokens, stagingSwapSupportedTokens, stakedSodaAbi, stakingInvariant, stakingRouterAbi, stataTokenFactoryAbi, stellarSupportedTokens, submitTransaction, suiSupportedTokens, supportedSpokeChains, supportedTokensByChain, swapExactInSingleParamsAbi, swapInvariant, swapSupportedTokens, swapsConfig, toCreateBridgeIntentParamsV2, toSuiExecutionResult, toSuiExecutionStatus, toSuiPaginatedCoins, tokenLogo, tokenLogoSlug, uiPoolDataAbi, universalRouterAbi, unknownFailed, usesBip322MessageSigning, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, verifyFailed, wadToRay, waitForStacksTransaction, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|
|
46890
|
+
export { ALLOWANCE_CHECK_CODES, APPROVE_CODES, AssetService, BACKEND_API_BASE_PATH, BITCOIN_CHAIN_KEYS, BITCOIN_CHAIN_KEYS_SET, BITCOIN_DUST_SATS, BOUND_API_HOST, BOUND_COMPANION_HOSTS, BTC_WALLET_ADDRESS_TYPES, BackendApiService, BackendHttpError, BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BitcoinSpokeService, BnUSDMigrationService, BridgeApiService, BridgeService, CHAIN_KEYS, CHAIN_LOGO_BASE_URL, CONFIG_VERSION, CREATE_INTENT_CODES, ChainKeys, ChainTypeArr, ClService, ConfigService, CustomSorobanServer, CustomStellarAccount, DEFAULT_API_BASE_URL, DEFAULT_BACKEND_API_ENDPOINT, DEFAULT_BACKEND_API_HEADERS, DEFAULT_BACKEND_API_TIMEOUT, DEFAULT_DEADLINE_OFFSET, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, DEFAULT_SPONSORING_API_ENDPOINT, DEPRECATED_BOUND_HOSTS, DETAILED_STATUS_NOT_DELIVERED, DexService, EVM_CHAIN_ID_TO_KEY, EVM_CHAIN_KEYS, EVM_CHAIN_KEYS_SET, EVM_SPOKE_ONLY_CHAIN_KEYS, EVM_SPOKE_ONLY_CHAIN_KEYS_SET, Erc20Service, Erc4626Service, EvmAssetManagerService, EvmHubProvider, EvmSolverService, EvmSpokeService, EvmVaultTokenService, FEE_PERCENTAGE_SCALE, GAS_ESTIMATION_CODES, HALF_RAY, HALF_WAD, HUB_CHAIN_KEY, HookKind, HookService, HttpRelayError, HubVaultSymbols, ICON_CHAIN_KEYS, ICON_CHAIN_KEYS_SET, ICON_TX_RESULT_WAIT_MAX_RETRY, INJECTIVE_CHAIN_KEYS, INJECTIVE_CHAIN_KEYS_SET, INTENT_CHAIN_IDS, IconSpokeService, IcxMigrationService, Injective20Token, InjectiveSpokeService, IntentCreatedEventAbi, IntentDataService, IntentDataType, IntentFilledEventAbi, IntentRelayChainIdToChainKey, IntentsAbi, LOOKUP_CODES, LTV_PRECISION, LendingPoolService, LeverageYieldApiService, LeverageYieldService, LockupMultiplier, LockupPeriod, LsodaSymbols, LsodaTokens, MAX_POSITION_FEE_BPS, MAX_UINT256, MigrationService, MintPositionEventAbi, MoneyMarketDataService, MoneyMarketService, NEAR_CHAIN_KEYS, NEAR_CHAIN_KEYS_SET, NEAR_DEFAULT_GAS, NEAR_STORAGE_DEPOSIT, NearSpokeService, ORACLE_CANDLE_INTERVALS, PartnerFeeClaimService, PartnerService, Permit2Service, ProtocolIntentsAbi, RAY, RAY_DECIMALS, RELAY_ERROR_CODES, RELAY_FALLBACK_FLOOR_MS, RELAY_REQUEST_TIMEOUT_MS, RadfiApiError, RadfiProvider, RecoveryService, RelayChainIdMap, SDK_VERSION, SECONDS_PER_YEAR, SODAX_ERROR_CODES, SODAX_FEATURES, SOLANA_CHAIN_KEYS, SOLANA_CHAIN_KEYS_SET, SONIC_CHAIN_KEYS, SONIC_CHAIN_KEYS_SET, SPEED_TIER_SECONDS, SPEED_TIER_THRESHOLDS, SPONSORING_API_ERROR_CODES, SPONSORING_API_STELLAR_BASE_PATH, SPONSOR_CONFIG_TTL_MS, STACKS_CHAIN_KEYS, STACKS_CHAIN_KEYS_SET, STELLAR_BASE_RESERVE_TTL_MS, STELLAR_CHAIN_KEYS, STELLAR_CHAIN_KEYS_SET, STELLAR_TRUSTLINE_MIN_XLM_STROOPS, SUI_CHAIN_KEYS, SUI_CHAIN_KEYS_SET, SodaTokens, Sodax, SodaxError, SolanaSpokeService, SolverApiService, SolverIntentErrorCode, SolverIntentStatusCode, SonicSpokeService, SpokeService, SponsoringApiService, SponsoringService, StacksSpokeService, StakingLogic, StakingService, StatATokenAddresses, StellarSpokeService, SuiGrpcTransport, SuiSpokeService, SupportedMigrationTokens, SwapService, SwapsApiService, TOKEN_LOGO_BASE_URL, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, adjustAmountByFee, allowanceCheckFailed, apiConfig, approveFailed, arbitrumSupportedTokens, assetManagerAbi, avalancheSupportedTokens, balnSwapAbi, baseChainInfo, baseSupportedTokens, binomialApproximatedRayPow, bitcoinSupportedTokens, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bridgeConfig, bridgeInvariant, bscSupportedTokens, calcOpReturnOutputVbytes, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, canonicalizeBitcoinAddress, clPoolAbi, clPoolManagerAbi, clPositionManagerAbi, clQuoterAbi, clRouterAbi, clTickLensAbi, classifySponsorError, concentratedLiquidityConfig, configVersionFor, connectionAbi, consoleLogger, convertTransactionInstructionToRaw, createBalanceCollector, createInvariant, deepMerge, defaultHookAbi, detectBitcoinAddressType, dexConfig, dexInvariant, dexPools, encodeAddress, encodeBtcPayloadToBytes, encodeContractCalls, encodeTokenIdentifier, erc20Abi, erc4626Abi, estimateBitcoinTxSize, estimateSwapSpeedTier, ethereumSupportedTokens, executionFailed, formatBasisPoints, formatConfigVersion, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, gasEstimationFailed, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getAssetManagerIdl, getAssetManagerProgram, getChainKeyFromRelayChainId, getChainType, getCompoundedBalance, getConcentratedLiquidityConfig, getConnectionIdl, getConnectionProgram, getEvmChainKeyByChainId, getEvmViemChain, getIconAddressBytes, getIntentRelayChainId, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getPacket, getProvider, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getSolverConfig, getSpokeHook, getSpokeHooks, getStagingSolverTokens, getSupportedSolverTokens, getTransactionPackets, getbnUSDToken, hederaSupportedTokens, hexToBigInt, hexToSolanaAddress, hubConfig, hyper, hyperevmSupportedTokens, iconSupportedTokens, injectiveSupportedTokens, intentCreationFailed, isApprovalSupportedChainKeyType, isAuthFailure, isAuthStatus, isBackendHttpError, isBalnMigrateParams, isBitcoinChainKey, isBitcoinChainKeyType, isBitcoinWalletProviderType, isBridgeAllowanceCheckError, isBridgeApproveError, isBridgeCreateIntentError, isBridgeError, isBridgeLookupError, isBridgeOrchestrationError, isCodeMember, isDexApproveError, isDexCreateIntentError, isDexError, isEvmChainKey, isEvmChainKeyType, isEvmSpokeChainConfig, isEvmSpokeOnlyChainKey, isEvmSpokeOnlyChainKeyType, isEvmWalletProviderType, isFeatureError, isFillEvent, isHookSupportedToken, isHubChainKey, isHubChainKeyType, isIconAddress, isIconChainKey, isIconChainKeyType, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveChainKey, isInjectiveChainKeyType, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isLeverageYieldAllowanceCheckError, isLeverageYieldApproveError, isLeverageYieldCreateIntentError, isLeverageYieldError, isLeverageYieldLookupError, isLeverageYieldPostExecutionError, isLeverageYieldSwapError, isMigrateOrchestrationError, isMigrationAllowanceCheckError, isMigrationApproveError, isMigrationCreateIntentError, isMigrationError, isMigrationLookupError, isMoneyMarketAllowanceCheckError, isMoneyMarketApproveError, isMoneyMarketCreateIntentError, isMoneyMarketError, isMoneyMarketGasEstimationError, isMoneyMarketOrchestrationError, isNativeBitcoinToken, isNativeBitcoinTransfer, isNativeToken, isNearChainKey, isNearChainKeyType, isNewbnUSDChainId, isNewbnUSDToken, isNoRouteRefusal, isOptionalBitcoinWalletProviderType, isOptionalEvmWalletProviderType, isOptionalStellarWalletProviderType, isOracleCandleInterval, isPartnerError, isPartnerFeeAmount, isPartnerFeePercentage, isPostExecutionError, isRawDestinationParams, isRealWorldAsset, isRecoveryError, isResponseAddressType, isResponseSigningType, isRevertMigrationOrchestrationError, isSodaxError, isSolanaChainKey, isSolanaChainKeyType, isSolanaNativeToken, isSonicChainKey, isSonicChainKeyType, isSpokeApproveParamsEvmSpoke, isSpokeApproveParamsHub, isSpokeApproveParamsStellar, isSpokeChainKey, isSpokeIsAllowanceValidParamsEvmSpoke, isSpokeIsAllowanceValidParamsHub, isSpokeIsAllowanceValidParamsStellar, isSponsoringConfigError, isSponsoringLookupError, isSponsoringOrchestrationError, isStacksChainKey, isStacksChainKeyType, isStakeOrchestrationError, isStakingAllowanceCheckError, isStakingApproveError, isStakingCreateIntentError, isStakingError, isStakingInfoFetchError, isStakingOrchestrationError, isStellarChainKey, isStellarChainKeyType, isStellarWalletProviderType, isSuiChainKey, isSuiChainKeyType, isSupportedBitcoinAddressType, isSwapCreateIntentError, isSwapError, isSwapSupportedToken, isUndefinedOrValidWalletProviderForChainKey, isUnifiedBnUSDMigrateParams, isValidBitcoinAddress, isValidInjectiveAddress, isValidNearAccountId, isValidWalletProviderForChainKey, kaiaSupportedTokens, leverageYieldConfig, leverageYieldInvariant, leverageYieldVaults, leveragedNetApyPct, lightlinkSupportedTokens, lookupFailed, mapRelayFailure, mergeSodaxConfig, messageOf, migrationInvariant, mintPositionParamsAbi, mmInvariant, modifyLiquidityParamsAbi, moneyMarketConfig, moneyMarketReserveAssets, moneyMarketSupportedTokens, nativeToUSD, nearSupportedTokens, newbnUSDSpokeChainIds, noopAnalytics, normalize, normalizeBN, normalizePsbtToBase64, normalizeSignatureToBase64, normalizedToUsd, optimismSupportedTokens, pancakeSwapInfinityDefaultHookAbi, pancakeSwapInfinityPoolManagerAbi, pancakeSwapInfinityPositionManagerAbi, parseConfigVersion, parseToStroops, parseTokenArrayFromJson, partnerInvariant, permit2Abi, polygonSupportedTokens, poolAbi, poolKeyAbi, projectLeverageLeg, randomUint256, rayDiv, rayMul, rayPow, rayToWad, recoveryInvariant, redbellySupportedTokens, relayConfig, relayTxAndWaitPacket, reportPositionIntent, requestAddress, requestJsonRpc, requestSigning, resolveAnalytics, resolveLogger, resolvePositionFundingAddress, retry, reverseEncodeAddress, robinhoodChain, robinhoodSupportedTokens, serializeAddressData, settleWalletBalances, silentLogger, sizeLeverageBorrow, sleep, sodaxConfig, sodaxInvariant, solanaSupportedTokens, solverConfig, sonicSupportedTokens, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainKeysSet, spokeHooks, sponsoringInvariant, stacksSupportedTokens, stagingSwapSupportedTokens, stakedSodaAbi, stakingInvariant, stakingRouterAbi, stataTokenFactoryAbi, stellarSupportedTokens, submitTransaction, suiSupportedTokens, supportedSpokeChains, supportedTokensByChain, swapExactInSingleParamsAbi, swapInvariant, swapSupportedTokens, swapsConfig, timeToBreakevenYears, toCreateBridgeIntentParamsV2, toSuiExecutionResult, toSuiExecutionStatus, toSuiPaginatedCoins, tokenLogo, tokenLogoSlug, uiPoolDataAbi, universalRouterAbi, unknownFailed, usesBip322MessageSigning, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, verifyFailed, wadToRay, waitForStacksTransaction, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|