@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.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var tx_js = require('cosmjs-types/cosmos/tx/v1beta1/tx.js');
|
|
|
21
21
|
var networks = require('@injectivelabs/networks');
|
|
22
22
|
var v = require('valibot');
|
|
23
23
|
var swapsApi = require('@sodax/swaps-api');
|
|
24
|
+
var bridgeApi = require('@sodax/bridge-api');
|
|
24
25
|
var BigNumber5 = require('bignumber.js');
|
|
25
26
|
var swapSdkCore = require('@pancakeswap/swap-sdk-core');
|
|
26
27
|
var v3Sdk = require('@pancakeswap/v3-sdk');
|
|
@@ -122,8 +123,8 @@ function serializeCause(cause, depth) {
|
|
|
122
123
|
}
|
|
123
124
|
function sanitizeContext(value, depth) {
|
|
124
125
|
const out = {};
|
|
125
|
-
for (const [key,
|
|
126
|
-
out[key] = sanitizeValue(
|
|
126
|
+
for (const [key, v10] of Object.entries(value)) {
|
|
127
|
+
out[key] = sanitizeValue(v10, depth + 1);
|
|
127
128
|
}
|
|
128
129
|
return out;
|
|
129
130
|
}
|
|
@@ -134,13 +135,13 @@ function sanitizeValue(value, depth) {
|
|
|
134
135
|
if (t === "bigint") return value.toString();
|
|
135
136
|
if (t === "string" || t === "number" || t === "boolean") return value;
|
|
136
137
|
if (t === "function" || t === "symbol") return safeString(value);
|
|
137
|
-
if (Array.isArray(value)) return value.map((
|
|
138
|
+
if (Array.isArray(value)) return value.map((v10) => sanitizeValue(v10, depth + 1));
|
|
138
139
|
if (value instanceof Date) return value.toISOString();
|
|
139
140
|
if (value instanceof Map) {
|
|
140
|
-
return Array.from(value.entries()).map(([k,
|
|
141
|
+
return Array.from(value.entries()).map(([k, v10]) => [sanitizeValue(k, depth + 1), sanitizeValue(v10, depth + 1)]);
|
|
141
142
|
}
|
|
142
143
|
if (value instanceof Set) {
|
|
143
|
-
return Array.from(value.values()).map((
|
|
144
|
+
return Array.from(value.values()).map((v10) => sanitizeValue(v10, depth + 1));
|
|
144
145
|
}
|
|
145
146
|
if (value instanceof Error) return { name: value.name, message: value.message };
|
|
146
147
|
if (t === "object") {
|
|
@@ -152,9 +153,9 @@ function sanitizeValue(value, depth) {
|
|
|
152
153
|
}
|
|
153
154
|
return safeString(value);
|
|
154
155
|
}
|
|
155
|
-
function safeString(
|
|
156
|
+
function safeString(v10) {
|
|
156
157
|
try {
|
|
157
|
-
return String(
|
|
158
|
+
return String(v10);
|
|
158
159
|
} catch {
|
|
159
160
|
return "[unserializable]";
|
|
160
161
|
}
|
|
@@ -370,8 +371,8 @@ var HubVaultSymbols = [
|
|
|
370
371
|
];
|
|
371
372
|
var SodaTokens = {
|
|
372
373
|
sodaBNB: {
|
|
373
|
-
symbol: "
|
|
374
|
-
name: "
|
|
374
|
+
symbol: "BNB",
|
|
375
|
+
name: "BNB",
|
|
375
376
|
decimals: 18,
|
|
376
377
|
address: "0x40Cd41b35DB9e5109ae7E54b44De8625dB320E6b",
|
|
377
378
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -379,8 +380,8 @@ var SodaTokens = {
|
|
|
379
380
|
vault: "0x40Cd41b35DB9e5109ae7E54b44De8625dB320E6b"
|
|
380
381
|
},
|
|
381
382
|
sodaAVAX: {
|
|
382
|
-
symbol: "
|
|
383
|
-
name: "
|
|
383
|
+
symbol: "AVAX",
|
|
384
|
+
name: "Avalanche",
|
|
384
385
|
decimals: 18,
|
|
385
386
|
address: "0x14238D267557E9d799016ad635B53CD15935d290",
|
|
386
387
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -389,7 +390,7 @@ var SodaTokens = {
|
|
|
389
390
|
},
|
|
390
391
|
sodaETH: {
|
|
391
392
|
symbol: "sodaETH",
|
|
392
|
-
name: "
|
|
393
|
+
name: "SODA ETH",
|
|
393
394
|
decimals: 18,
|
|
394
395
|
address: "0x4effB5813271699683C25c734F4daBc45B363709",
|
|
395
396
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -397,8 +398,8 @@ var SodaTokens = {
|
|
|
397
398
|
vault: "0x4effB5813271699683C25c734F4daBc45B363709"
|
|
398
399
|
},
|
|
399
400
|
sodaBTC: {
|
|
400
|
-
symbol: "
|
|
401
|
-
name: "
|
|
401
|
+
symbol: "BTC",
|
|
402
|
+
name: "Bitcoin",
|
|
402
403
|
decimals: 18,
|
|
403
404
|
address: "0x7A1A5555842Ad2D0eD274d09b5c4406a95799D5d",
|
|
404
405
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -407,7 +408,7 @@ var SodaTokens = {
|
|
|
407
408
|
},
|
|
408
409
|
sodaWBTC: {
|
|
409
410
|
symbol: "sodaWBTC",
|
|
410
|
-
name: "
|
|
411
|
+
name: "SODA WBTC",
|
|
411
412
|
decimals: 18,
|
|
412
413
|
address: "0x811C3fCc13f9c2a23AE2Ae2DCadacFAC6eb5f0eB",
|
|
413
414
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -415,8 +416,8 @@ var SodaTokens = {
|
|
|
415
416
|
vault: "0x811C3fCc13f9c2a23AE2Ae2DCadacFAC6eb5f0eB"
|
|
416
417
|
},
|
|
417
418
|
sodaSOL: {
|
|
418
|
-
symbol: "
|
|
419
|
-
name: "
|
|
419
|
+
symbol: "SOL",
|
|
420
|
+
name: "Solana",
|
|
420
421
|
decimals: 18,
|
|
421
422
|
address: "0xdEa692287E2cE8Cb08FA52917Be0F16b1DACDC87",
|
|
422
423
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -424,8 +425,8 @@ var SodaTokens = {
|
|
|
424
425
|
vault: "0xdEa692287E2cE8Cb08FA52917Be0F16b1DACDC87"
|
|
425
426
|
},
|
|
426
427
|
sodaXLM: {
|
|
427
|
-
symbol: "
|
|
428
|
-
name: "
|
|
428
|
+
symbol: "XLM",
|
|
429
|
+
name: "Stellar Lumens",
|
|
429
430
|
decimals: 18,
|
|
430
431
|
address: "0x6BC8C37cba91F76E68C9e6d689A9C21E4d32079B",
|
|
431
432
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -433,8 +434,8 @@ var SodaTokens = {
|
|
|
433
434
|
vault: "0x6BC8C37cba91F76E68C9e6d689A9C21E4d32079B"
|
|
434
435
|
},
|
|
435
436
|
sodaINJ: {
|
|
436
|
-
symbol: "
|
|
437
|
-
name: "
|
|
437
|
+
symbol: "INJ",
|
|
438
|
+
name: "Injective",
|
|
438
439
|
decimals: 18,
|
|
439
440
|
address: "0x1f22279C89B213944b7Ea41daCB0a868DdCDFd13",
|
|
440
441
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -442,8 +443,8 @@ var SodaTokens = {
|
|
|
442
443
|
vault: "0x1f22279C89B213944b7Ea41daCB0a868DdCDFd13"
|
|
443
444
|
},
|
|
444
445
|
sodaSUI: {
|
|
445
|
-
symbol: "
|
|
446
|
-
name: "
|
|
446
|
+
symbol: "SUI",
|
|
447
|
+
name: "Sui",
|
|
447
448
|
decimals: 18,
|
|
448
449
|
address: "0xdc5B4b00F98347E95b9F94911213DAB4C687e1e3",
|
|
449
450
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -461,7 +462,7 @@ var SodaTokens = {
|
|
|
461
462
|
},
|
|
462
463
|
sodaUSDC: {
|
|
463
464
|
symbol: "sodaUSDC",
|
|
464
|
-
name: "
|
|
465
|
+
name: "SODA USDC",
|
|
465
466
|
decimals: 18,
|
|
466
467
|
address: "0xAbbb91c0617090F0028BDC27597Cd0D038F3A833",
|
|
467
468
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -470,7 +471,7 @@ var SodaTokens = {
|
|
|
470
471
|
},
|
|
471
472
|
sodaUSDT: {
|
|
472
473
|
symbol: "sodaUSDT",
|
|
473
|
-
name: "
|
|
474
|
+
name: "SODA USDT",
|
|
474
475
|
decimals: 18,
|
|
475
476
|
address: "0xbDf1F453FCB61424011BBDDCB96cFDB30f3Fe876",
|
|
476
477
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -488,7 +489,7 @@ var SodaTokens = {
|
|
|
488
489
|
},
|
|
489
490
|
sodaS: {
|
|
490
491
|
symbol: "sodaS",
|
|
491
|
-
name: "
|
|
492
|
+
name: "SODA S",
|
|
492
493
|
decimals: 18,
|
|
493
494
|
address: "0x62ecc3Eeb80a162c57624B3fF80313FE69f5203e",
|
|
494
495
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -496,8 +497,8 @@ var SodaTokens = {
|
|
|
496
497
|
vault: "0x62ecc3Eeb80a162c57624B3fF80313FE69f5203e"
|
|
497
498
|
},
|
|
498
499
|
sodaPOL: {
|
|
499
|
-
symbol: "
|
|
500
|
-
name: "
|
|
500
|
+
symbol: "POL",
|
|
501
|
+
name: "Polygon Ecosystem Token",
|
|
501
502
|
decimals: 18,
|
|
502
503
|
address: "0x208ED38f4783328aA9eBFeC360D32e7520A9B779",
|
|
503
504
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -506,7 +507,7 @@ var SodaTokens = {
|
|
|
506
507
|
},
|
|
507
508
|
sodaSODA: {
|
|
508
509
|
symbol: "sodaSODA",
|
|
509
|
-
name: "
|
|
510
|
+
name: "SODA SODA",
|
|
510
511
|
decimals: 18,
|
|
511
512
|
address: "0x21685E341DE7844135329914Be6Bd8D16982d834",
|
|
512
513
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -514,8 +515,8 @@ var SodaTokens = {
|
|
|
514
515
|
vault: "0x21685E341DE7844135329914Be6Bd8D16982d834"
|
|
515
516
|
},
|
|
516
517
|
sodaHYPE: {
|
|
517
|
-
symbol: "
|
|
518
|
-
name: "
|
|
518
|
+
symbol: "HYPE",
|
|
519
|
+
name: "Hyperliquid",
|
|
519
520
|
decimals: 18,
|
|
520
521
|
address: "0x6E81124fC5d2Bf666B16a0A5d90066eBf35c7411",
|
|
521
522
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -523,8 +524,8 @@ var SodaTokens = {
|
|
|
523
524
|
vault: "0x6E81124fC5d2Bf666B16a0A5d90066eBf35c7411"
|
|
524
525
|
},
|
|
525
526
|
sodaRBNT: {
|
|
526
|
-
symbol: "
|
|
527
|
-
name: "
|
|
527
|
+
symbol: "RBNT",
|
|
528
|
+
name: "Redbelly Network Token",
|
|
528
529
|
decimals: 18,
|
|
529
530
|
address: "0x4B207114F9118dEAC56436e1aE3c45648783c7Ac",
|
|
530
531
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -532,8 +533,8 @@ var SodaTokens = {
|
|
|
532
533
|
vault: "0x4B207114F9118dEAC56436e1aE3c45648783c7Ac"
|
|
533
534
|
},
|
|
534
535
|
sodaLL: {
|
|
535
|
-
symbol: "
|
|
536
|
-
name: "
|
|
536
|
+
symbol: "LL",
|
|
537
|
+
name: "LightLink",
|
|
537
538
|
decimals: 18,
|
|
538
539
|
address: "0x14C5eB2D25dFb834852dFc85744875d1eCb09748",
|
|
539
540
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -541,8 +542,8 @@ var SodaTokens = {
|
|
|
541
542
|
vault: "0x14C5eB2D25dFb834852dFc85744875d1eCb09748"
|
|
542
543
|
},
|
|
543
544
|
sodaWEETH: {
|
|
544
|
-
symbol: "
|
|
545
|
-
name: "
|
|
545
|
+
symbol: "weETH",
|
|
546
|
+
name: "Wrapped eETH",
|
|
546
547
|
decimals: 18,
|
|
547
548
|
address: "0xCb6B152D3a943f25157381aFcA7fEFCD2ef5a357",
|
|
548
549
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -550,8 +551,8 @@ var SodaTokens = {
|
|
|
550
551
|
vault: "0xCb6B152D3a943f25157381aFcA7fEFCD2ef5a357"
|
|
551
552
|
},
|
|
552
553
|
sodaWSTETH: {
|
|
553
|
-
symbol: "
|
|
554
|
-
name: "
|
|
554
|
+
symbol: "wstETH",
|
|
555
|
+
name: "Wrapped liquid staked Ether",
|
|
555
556
|
decimals: 18,
|
|
556
557
|
address: "0x58b0538D7EEaeE69EF32f9F1dE5cbF32A10a977B",
|
|
557
558
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -559,8 +560,8 @@ var SodaTokens = {
|
|
|
559
560
|
vault: "0x58b0538D7EEaeE69EF32f9F1dE5cbF32A10a977B"
|
|
560
561
|
},
|
|
561
562
|
sodaNEAR: {
|
|
562
|
-
symbol: "
|
|
563
|
-
name: "
|
|
563
|
+
symbol: "NEAR",
|
|
564
|
+
name: "NEAR Protocol",
|
|
564
565
|
decimals: 18,
|
|
565
566
|
address: "0xf4ba497c9b805e4bd88a8a9e6a7b8f74984c3e39",
|
|
566
567
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -568,8 +569,8 @@ var SodaTokens = {
|
|
|
568
569
|
vault: "0xf4ba497c9b805e4bd88a8a9e6a7b8f74984c3e39"
|
|
569
570
|
},
|
|
570
571
|
sodaKAIA: {
|
|
571
|
-
symbol: "
|
|
572
|
-
name: "
|
|
572
|
+
symbol: "KAIA",
|
|
573
|
+
name: "Kaia",
|
|
573
574
|
decimals: 18,
|
|
574
575
|
address: "0xD7d41b5f803b6A40F8A6eAa34E459A4564e39891",
|
|
575
576
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -577,8 +578,8 @@ var SodaTokens = {
|
|
|
577
578
|
vault: "0xD7d41b5f803b6A40F8A6eAa34E459A4564e39891"
|
|
578
579
|
},
|
|
579
580
|
sodaSTX: {
|
|
580
|
-
symbol: "
|
|
581
|
-
name: "
|
|
581
|
+
symbol: "STX",
|
|
582
|
+
name: "Stacks",
|
|
582
583
|
decimals: 18,
|
|
583
584
|
address: "0x1Fbe5229e9d189F26bEE77E5bFa24309FdA90483",
|
|
584
585
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -586,8 +587,8 @@ var SodaTokens = {
|
|
|
586
587
|
vault: "0x1Fbe5229e9d189F26bEE77E5bFa24309FdA90483"
|
|
587
588
|
},
|
|
588
589
|
sodaSUSDS: {
|
|
589
|
-
symbol: "
|
|
590
|
-
name: "
|
|
590
|
+
symbol: "sUSDS",
|
|
591
|
+
name: "Savings USDS",
|
|
591
592
|
decimals: 18,
|
|
592
593
|
address: "0x243b0c26c8b38793908d7C64e8510f21B19B4613",
|
|
593
594
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -595,8 +596,8 @@ var SodaTokens = {
|
|
|
595
596
|
vault: "0x243b0c26c8b38793908d7C64e8510f21B19B4613"
|
|
596
597
|
},
|
|
597
598
|
sodaHBAR: {
|
|
598
|
-
symbol: "
|
|
599
|
-
name: "
|
|
599
|
+
symbol: "HBAR",
|
|
600
|
+
name: "Hedera",
|
|
600
601
|
decimals: 18,
|
|
601
602
|
address: "0x3BB956cc8922E1Ba4148dc10eD1b4Fa19aa599c4",
|
|
602
603
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -604,8 +605,8 @@ var SodaTokens = {
|
|
|
604
605
|
vault: "0x3BB956cc8922E1Ba4148dc10eD1b4Fa19aa599c4"
|
|
605
606
|
},
|
|
606
607
|
sodaJITOSOL: {
|
|
607
|
-
symbol: "
|
|
608
|
-
name: "
|
|
608
|
+
symbol: "JitoSOL",
|
|
609
|
+
name: "Jito Staked SOL",
|
|
609
610
|
decimals: 18,
|
|
610
611
|
address: "0xe1bad4400d947Bc4fa66f9c0A143D800002083a0",
|
|
611
612
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -613,8 +614,8 @@ var SodaTokens = {
|
|
|
613
614
|
vault: "0xe1bad4400d947Bc4fa66f9c0A143D800002083a0"
|
|
614
615
|
},
|
|
615
616
|
sodaUSDS: {
|
|
616
|
-
symbol: "
|
|
617
|
-
name: "
|
|
617
|
+
symbol: "USDS",
|
|
618
|
+
name: "USDS",
|
|
618
619
|
decimals: 18,
|
|
619
620
|
address: "0xA3AeFa2BAfEAB479c4Aca6024A16906bbC75566e",
|
|
620
621
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
@@ -632,6 +633,7 @@ var SodaTokens = {
|
|
|
632
633
|
},
|
|
633
634
|
SPCX: {
|
|
634
635
|
symbol: "SPCX",
|
|
636
|
+
isRwa: true,
|
|
635
637
|
name: "Space Exploration Technologies Corp. Class A Common Stock \u2022 Robinhood Token",
|
|
636
638
|
decimals: 18,
|
|
637
639
|
address: "0xB585e2EEa070eB4E4D877A707aEC3B718edb2373",
|
|
@@ -641,6 +643,7 @@ var SodaTokens = {
|
|
|
641
643
|
},
|
|
642
644
|
NVDA: {
|
|
643
645
|
symbol: "NVDA",
|
|
646
|
+
isRwa: true,
|
|
644
647
|
name: "NVIDIA \u2022 Robinhood Token",
|
|
645
648
|
decimals: 18,
|
|
646
649
|
address: "0x2D5D2250EE426cA318efBd03ddf926B23c96f74B",
|
|
@@ -650,6 +653,7 @@ var SodaTokens = {
|
|
|
650
653
|
},
|
|
651
654
|
GME: {
|
|
652
655
|
symbol: "GME",
|
|
656
|
+
isRwa: true,
|
|
653
657
|
name: "GameStop \u2022 Robinhood Token",
|
|
654
658
|
decimals: 18,
|
|
655
659
|
address: "0x996e5591e4692e2B7d8fB6926DeA4EE1950Ef394",
|
|
@@ -659,6 +663,7 @@ var SodaTokens = {
|
|
|
659
663
|
},
|
|
660
664
|
MSTR: {
|
|
661
665
|
symbol: "MSTR",
|
|
666
|
+
isRwa: true,
|
|
662
667
|
name: "Strategy Inc. \u2022 Robinhood Token",
|
|
663
668
|
decimals: 18,
|
|
664
669
|
address: "0xE0E2aF45EBf5700a90E63c41B0ecE042A240Fab1",
|
|
@@ -668,6 +673,7 @@ var SodaTokens = {
|
|
|
668
673
|
},
|
|
669
674
|
AAPL: {
|
|
670
675
|
symbol: "AAPL",
|
|
676
|
+
isRwa: true,
|
|
671
677
|
name: "Apple \u2022 Robinhood Token",
|
|
672
678
|
decimals: 18,
|
|
673
679
|
address: "0x4712D2D49Ba3be41DA334FCB3616FDdc0d745185",
|
|
@@ -677,6 +683,7 @@ var SodaTokens = {
|
|
|
677
683
|
},
|
|
678
684
|
TSLA: {
|
|
679
685
|
symbol: "TSLA",
|
|
686
|
+
isRwa: true,
|
|
680
687
|
name: "Tesla \u2022 Robinhood Token",
|
|
681
688
|
decimals: 18,
|
|
682
689
|
address: "0x8B7F46967Ed9367A70b2e046D5e26a03625d53b1",
|
|
@@ -686,6 +693,7 @@ var SodaTokens = {
|
|
|
686
693
|
},
|
|
687
694
|
MU: {
|
|
688
695
|
symbol: "MU",
|
|
696
|
+
isRwa: true,
|
|
689
697
|
name: "Micron Technology \u2022 Robinhood Token",
|
|
690
698
|
decimals: 18,
|
|
691
699
|
address: "0x108147b16186B895344F5752468190B9EE0e3A22",
|
|
@@ -695,6 +703,7 @@ var SodaTokens = {
|
|
|
695
703
|
},
|
|
696
704
|
SNDK: {
|
|
697
705
|
symbol: "SNDK",
|
|
706
|
+
isRwa: true,
|
|
698
707
|
name: "Sandisk Corporation \u2022 Robinhood Token",
|
|
699
708
|
decimals: 18,
|
|
700
709
|
address: "0x568F29855B7B46EdA38ed95771FAeC498c507EF7",
|
|
@@ -704,6 +713,7 @@ var SodaTokens = {
|
|
|
704
713
|
},
|
|
705
714
|
SPY: {
|
|
706
715
|
symbol: "SPY",
|
|
716
|
+
isRwa: true,
|
|
707
717
|
name: "SPDR S&P 500 ETF Trust \u2022 Robinhood Token",
|
|
708
718
|
decimals: 18,
|
|
709
719
|
address: "0x1816E408f0448D0CaD3e0D490bd2590d921Bb0c8",
|
|
@@ -713,6 +723,7 @@ var SodaTokens = {
|
|
|
713
723
|
},
|
|
714
724
|
QQQ: {
|
|
715
725
|
symbol: "QQQ",
|
|
726
|
+
isRwa: true,
|
|
716
727
|
name: "Invesco QQQ \u2022 Robinhood Token",
|
|
717
728
|
decimals: 18,
|
|
718
729
|
address: "0x454ab3DeFd9df0749d450b145D4516e317E3e500",
|
|
@@ -722,6 +733,7 @@ var SodaTokens = {
|
|
|
722
733
|
},
|
|
723
734
|
SGOV: {
|
|
724
735
|
symbol: "SGOV",
|
|
736
|
+
isRwa: true,
|
|
725
737
|
name: "iShares 0-3 Month Treasury Bond \u2022 Robinhood Token",
|
|
726
738
|
decimals: 18,
|
|
727
739
|
address: "0xf6938087cf794B08739b926B41FF8F1E90816E74",
|
|
@@ -731,6 +743,7 @@ var SodaTokens = {
|
|
|
731
743
|
},
|
|
732
744
|
USO: {
|
|
733
745
|
symbol: "USO",
|
|
746
|
+
isRwa: true,
|
|
734
747
|
name: "United States Oil Fund \u2022 Robinhood Token",
|
|
735
748
|
decimals: 18,
|
|
736
749
|
address: "0x8DaBbADcecfc1a0B91fc68c72301090bc220D2bc",
|
|
@@ -740,6 +753,7 @@ var SodaTokens = {
|
|
|
740
753
|
},
|
|
741
754
|
SLV: {
|
|
742
755
|
symbol: "SLV",
|
|
756
|
+
isRwa: true,
|
|
743
757
|
name: "iShares Silver Trust \u2022 Robinhood Token",
|
|
744
758
|
decimals: 18,
|
|
745
759
|
address: "0x690B92c27ac80015E57DB8cc02A81255814f49A2",
|
|
@@ -1120,6 +1134,7 @@ var solanaSupportedTokens = {
|
|
|
1120
1134
|
},
|
|
1121
1135
|
CRCLx: {
|
|
1122
1136
|
symbol: "CRCLx",
|
|
1137
|
+
isRwa: true,
|
|
1123
1138
|
name: "Circle xStock",
|
|
1124
1139
|
decimals: 8,
|
|
1125
1140
|
address: "XsueG8BtpquVJX9LVLLEGuViXUungE6WmK5YZ3p3bd1",
|
|
@@ -1129,6 +1144,7 @@ var solanaSupportedTokens = {
|
|
|
1129
1144
|
},
|
|
1130
1145
|
TSLAx: {
|
|
1131
1146
|
symbol: "TSLAx",
|
|
1147
|
+
isRwa: true,
|
|
1132
1148
|
name: "Tesla xStock",
|
|
1133
1149
|
decimals: 8,
|
|
1134
1150
|
address: "XsDoVfqeBukxuZHWhdvWHBhgEHjGNst4MLodqsJHzoB",
|
|
@@ -1138,6 +1154,7 @@ var solanaSupportedTokens = {
|
|
|
1138
1154
|
},
|
|
1139
1155
|
SPYx: {
|
|
1140
1156
|
symbol: "SPYx",
|
|
1157
|
+
isRwa: true,
|
|
1141
1158
|
name: "SP500 xStock",
|
|
1142
1159
|
decimals: 8,
|
|
1143
1160
|
address: "XsoCS1TfEyfFhfvj8EtZ528L3CaKBDBRqRapnBbDF2W",
|
|
@@ -1147,6 +1164,7 @@ var solanaSupportedTokens = {
|
|
|
1147
1164
|
},
|
|
1148
1165
|
NVDAx: {
|
|
1149
1166
|
symbol: "NVDAx",
|
|
1167
|
+
isRwa: true,
|
|
1150
1168
|
name: "NVIDIA xStock",
|
|
1151
1169
|
decimals: 8,
|
|
1152
1170
|
address: "Xsc9qvGR1efVDFGLrVsmkzv3qi45LTBjeUKSPmx9qEh",
|
|
@@ -1156,6 +1174,7 @@ var solanaSupportedTokens = {
|
|
|
1156
1174
|
},
|
|
1157
1175
|
QQQx: {
|
|
1158
1176
|
symbol: "QQQx",
|
|
1177
|
+
isRwa: true,
|
|
1159
1178
|
name: "Nasdaq xStock",
|
|
1160
1179
|
decimals: 8,
|
|
1161
1180
|
address: "Xs8S1uUs1zvS2p7iwtsG3b6fkhpvmwz4GYU3gWAmWHZ",
|
|
@@ -1165,6 +1184,7 @@ var solanaSupportedTokens = {
|
|
|
1165
1184
|
},
|
|
1166
1185
|
MSTRx: {
|
|
1167
1186
|
symbol: "MSTRx",
|
|
1187
|
+
isRwa: true,
|
|
1168
1188
|
name: "MicroStrategy xStock",
|
|
1169
1189
|
decimals: 8,
|
|
1170
1190
|
address: "XsP7xzNPvEHS1m6qfanPUGjNmdnmsLKEoNAnHjdxxyZ",
|
|
@@ -1174,6 +1194,7 @@ var solanaSupportedTokens = {
|
|
|
1174
1194
|
},
|
|
1175
1195
|
COINx: {
|
|
1176
1196
|
symbol: "COINx",
|
|
1197
|
+
isRwa: true,
|
|
1177
1198
|
name: "Coinbase xStock",
|
|
1178
1199
|
decimals: 8,
|
|
1179
1200
|
address: "Xs7ZdzSHLU9ftNJsii5fCeJhoRWSC32SQGzGQtePxNu",
|
|
@@ -1183,6 +1204,7 @@ var solanaSupportedTokens = {
|
|
|
1183
1204
|
},
|
|
1184
1205
|
GOOGLx: {
|
|
1185
1206
|
symbol: "GOOGLx",
|
|
1207
|
+
isRwa: true,
|
|
1186
1208
|
name: "Alphabet xStock",
|
|
1187
1209
|
decimals: 8,
|
|
1188
1210
|
address: "XsCPL9dNWBMvFtTmwcCA5v3xWPSMEBCszbQdiLLq6aN",
|
|
@@ -1531,6 +1553,15 @@ var baseSupportedTokens = {
|
|
|
1531
1553
|
chainKey: ChainKeys.BASE_MAINNET,
|
|
1532
1554
|
hubAsset: "0x348e086ab6f424dfc575a325c28624ed23973173",
|
|
1533
1555
|
vault: "0x348e086ab6f424dfc575a325c28624ed23973173"
|
|
1556
|
+
},
|
|
1557
|
+
sUSDS: {
|
|
1558
|
+
symbol: "sUSDS",
|
|
1559
|
+
name: "staked USDS",
|
|
1560
|
+
decimals: 18,
|
|
1561
|
+
address: "0x5875eEE11Cf8398102FdAd704C9E96607675467a",
|
|
1562
|
+
chainKey: ChainKeys.BASE_MAINNET,
|
|
1563
|
+
hubAsset: "0x807cC73f69F1aCCC50511a0390A8544cEA71baA9",
|
|
1564
|
+
vault: SodaTokens.sodaSUSDS.address
|
|
1534
1565
|
}
|
|
1535
1566
|
};
|
|
1536
1567
|
var optimismSupportedTokens = {
|
|
@@ -1614,6 +1645,15 @@ var optimismSupportedTokens = {
|
|
|
1614
1645
|
chainKey: ChainKeys.OPTIMISM_MAINNET,
|
|
1615
1646
|
hubAsset: "0xd08375176410febee9cf4591532455a4cdfe4463",
|
|
1616
1647
|
vault: "0xd08375176410febee9cf4591532455a4cdfe4463"
|
|
1648
|
+
},
|
|
1649
|
+
sUSDS: {
|
|
1650
|
+
symbol: "sUSDS",
|
|
1651
|
+
name: "staked USDS",
|
|
1652
|
+
decimals: 18,
|
|
1653
|
+
address: "0xb5B2dc7fd34C249F4be7fB1fCea07950784229e0",
|
|
1654
|
+
chainKey: ChainKeys.OPTIMISM_MAINNET,
|
|
1655
|
+
hubAsset: "0xb9a9cb8A61D30a8F6b7E24491ab83f43E817b0E2",
|
|
1656
|
+
vault: SodaTokens.sodaSUSDS.address
|
|
1617
1657
|
}
|
|
1618
1658
|
};
|
|
1619
1659
|
var bscSupportedTokens = {
|
|
@@ -2351,6 +2391,7 @@ var stellarSupportedTokens = {
|
|
|
2351
2391
|
},
|
|
2352
2392
|
SPCX: {
|
|
2353
2393
|
symbol: "SPCX",
|
|
2394
|
+
isRwa: true,
|
|
2354
2395
|
name: "SpaceX Class A",
|
|
2355
2396
|
decimals: 7,
|
|
2356
2397
|
address: "CAI4HHAYO57QICZOZ4JF7R66RLGJRD7BGTX7H6MILCITVEYYEFRYFISK",
|
|
@@ -2360,6 +2401,7 @@ var stellarSupportedTokens = {
|
|
|
2360
2401
|
},
|
|
2361
2402
|
NVDA: {
|
|
2362
2403
|
symbol: "NVDA",
|
|
2404
|
+
isRwa: true,
|
|
2363
2405
|
name: "NVIDIA",
|
|
2364
2406
|
decimals: 7,
|
|
2365
2407
|
address: "CCQFCT4FHJURUQ4RQA4NHYW5GQRHCBDXF33ADXZRTDTDVGKOJO3ZPEMY",
|
|
@@ -2369,6 +2411,7 @@ var stellarSupportedTokens = {
|
|
|
2369
2411
|
},
|
|
2370
2412
|
GME: {
|
|
2371
2413
|
symbol: "GME",
|
|
2414
|
+
isRwa: true,
|
|
2372
2415
|
name: "GameStop",
|
|
2373
2416
|
decimals: 7,
|
|
2374
2417
|
address: "CAPSLSLCTFOZM22SUIPQENMM54T24GTDRHZ5STYAO6EYMK5GGGYVKWBX",
|
|
@@ -2378,6 +2421,7 @@ var stellarSupportedTokens = {
|
|
|
2378
2421
|
},
|
|
2379
2422
|
MSTR: {
|
|
2380
2423
|
symbol: "MSTR",
|
|
2424
|
+
isRwa: true,
|
|
2381
2425
|
name: "Strategy",
|
|
2382
2426
|
decimals: 7,
|
|
2383
2427
|
address: "CAFQQXZSECLJNU76OS2OKLJQJBQHYJCVAYZJ4KGEN7VHXH5BTGNLVQND",
|
|
@@ -2387,6 +2431,7 @@ var stellarSupportedTokens = {
|
|
|
2387
2431
|
},
|
|
2388
2432
|
AAPL: {
|
|
2389
2433
|
symbol: "AAPL",
|
|
2434
|
+
isRwa: true,
|
|
2390
2435
|
name: "Apple",
|
|
2391
2436
|
decimals: 7,
|
|
2392
2437
|
address: "CAZSFDNSSR2RKJ2LIIB2Y4G4WOSYYKC4646EUJ63PQLDDHOVQYZ4HDTK",
|
|
@@ -2396,6 +2441,7 @@ var stellarSupportedTokens = {
|
|
|
2396
2441
|
},
|
|
2397
2442
|
TSLA: {
|
|
2398
2443
|
symbol: "TSLA",
|
|
2444
|
+
isRwa: true,
|
|
2399
2445
|
name: "Tesla",
|
|
2400
2446
|
decimals: 7,
|
|
2401
2447
|
address: "CARLFQDI2S2FSYFB47AZLKGUFZVGBEUVNW77SCJHHHGL2KPGT3TN5PAB",
|
|
@@ -2405,6 +2451,7 @@ var stellarSupportedTokens = {
|
|
|
2405
2451
|
},
|
|
2406
2452
|
MU: {
|
|
2407
2453
|
symbol: "MU",
|
|
2454
|
+
isRwa: true,
|
|
2408
2455
|
name: "Micron",
|
|
2409
2456
|
decimals: 7,
|
|
2410
2457
|
address: "CBPTKA32BTUEX4VFAER6AUFWQZCWJKQAMLV2PMFFN7EHLGLJN4JWIZ3F",
|
|
@@ -2414,6 +2461,7 @@ var stellarSupportedTokens = {
|
|
|
2414
2461
|
},
|
|
2415
2462
|
SNDK: {
|
|
2416
2463
|
symbol: "SNDK",
|
|
2464
|
+
isRwa: true,
|
|
2417
2465
|
name: "SanDisk",
|
|
2418
2466
|
decimals: 7,
|
|
2419
2467
|
address: "CDXNTHFMGQM33UGQBSLZI3BV5UWW62QGZLCEKOXJKMFN2W3KQZKE3LTQ",
|
|
@@ -2423,6 +2471,7 @@ var stellarSupportedTokens = {
|
|
|
2423
2471
|
},
|
|
2424
2472
|
SPY: {
|
|
2425
2473
|
symbol: "SPY",
|
|
2474
|
+
isRwa: true,
|
|
2426
2475
|
name: "SPDR S&P 500 ETF Trust",
|
|
2427
2476
|
decimals: 7,
|
|
2428
2477
|
address: "CD3ZMWOS4PZS2RQITEHBOTS27DTDP4QKOK7IEO5IB64GQKHRJYTVL3SW",
|
|
@@ -2432,6 +2481,7 @@ var stellarSupportedTokens = {
|
|
|
2432
2481
|
},
|
|
2433
2482
|
QQQ: {
|
|
2434
2483
|
symbol: "QQQ",
|
|
2484
|
+
isRwa: true,
|
|
2435
2485
|
name: "Invesco QQQ Trust",
|
|
2436
2486
|
decimals: 7,
|
|
2437
2487
|
address: "CC7DQX43J2KBK5MJACQWTNHENIYB5GUVCFXGDKQWDLUWA4VKLOOU5PWB",
|
|
@@ -2441,6 +2491,7 @@ var stellarSupportedTokens = {
|
|
|
2441
2491
|
},
|
|
2442
2492
|
SGOV: {
|
|
2443
2493
|
symbol: "SGOV",
|
|
2494
|
+
isRwa: true,
|
|
2444
2495
|
name: "iShares 0-3 Month Treasury Bond ETF",
|
|
2445
2496
|
decimals: 7,
|
|
2446
2497
|
address: "CBQMRO2JTUJ6NXVBQ3XGJV34PDTXR34DD74TLLRCW5SV2CV2NN2VDMLH",
|
|
@@ -2450,6 +2501,7 @@ var stellarSupportedTokens = {
|
|
|
2450
2501
|
},
|
|
2451
2502
|
USO: {
|
|
2452
2503
|
symbol: "USO",
|
|
2504
|
+
isRwa: true,
|
|
2453
2505
|
name: "United States Oil Fund LP",
|
|
2454
2506
|
decimals: 7,
|
|
2455
2507
|
address: "CCFRCTIW5EK2OK626V6C4YRTJCKACIRDI2GHOKWM57ZXACK2ZTWWWLC7",
|
|
@@ -2459,6 +2511,7 @@ var stellarSupportedTokens = {
|
|
|
2459
2511
|
},
|
|
2460
2512
|
SLV: {
|
|
2461
2513
|
symbol: "SLV",
|
|
2514
|
+
isRwa: true,
|
|
2462
2515
|
name: "iShares Silver Trust",
|
|
2463
2516
|
decimals: 7,
|
|
2464
2517
|
address: "CBY3U32O5T2B555HNJLX6C6HW3O2FLRSJGH472UOOHT6H6ZMGMSSZTLW",
|
|
@@ -2902,6 +2955,7 @@ var ethereumSupportedTokens = {
|
|
|
2902
2955
|
},
|
|
2903
2956
|
PAXG: {
|
|
2904
2957
|
symbol: "PAXG",
|
|
2958
|
+
isRwa: true,
|
|
2905
2959
|
name: "PAX Gold",
|
|
2906
2960
|
decimals: 18,
|
|
2907
2961
|
address: "0x45804880De22913dAFE09f4980848ECE6EcbAf78",
|
|
@@ -2911,6 +2965,7 @@ var ethereumSupportedTokens = {
|
|
|
2911
2965
|
},
|
|
2912
2966
|
XAUt: {
|
|
2913
2967
|
symbol: "XAUt",
|
|
2968
|
+
isRwa: true,
|
|
2914
2969
|
name: "Tether Gold",
|
|
2915
2970
|
decimals: 6,
|
|
2916
2971
|
address: "0x68749665FF8D2d112Fa859AA293F07A622782F38",
|
|
@@ -2953,6 +3008,15 @@ var ethereumSupportedTokens = {
|
|
|
2953
3008
|
chainKey: ChainKeys.ETHEREUM_MAINNET,
|
|
2954
3009
|
hubAsset: "0x40bea4f921355a749f460760ba6f8edd78888164",
|
|
2955
3010
|
vault: "0x40bea4f921355a749f460760ba6f8edd78888164"
|
|
3011
|
+
},
|
|
3012
|
+
sUSDS: {
|
|
3013
|
+
symbol: "sUSDS",
|
|
3014
|
+
name: "staked USDS",
|
|
3015
|
+
decimals: 18,
|
|
3016
|
+
address: "0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD",
|
|
3017
|
+
chainKey: ChainKeys.ETHEREUM_MAINNET,
|
|
3018
|
+
hubAsset: "0x1Bb5128A4837A78cb60bc52cc19079eD3F00A624",
|
|
3019
|
+
vault: SodaTokens.sodaSUSDS.address
|
|
2956
3020
|
}
|
|
2957
3021
|
};
|
|
2958
3022
|
var kaiaSupportedTokens = {
|
|
@@ -3140,6 +3204,7 @@ var hederaSupportedTokens = {
|
|
|
3140
3204
|
},
|
|
3141
3205
|
SPCX: {
|
|
3142
3206
|
symbol: "SPCX",
|
|
3207
|
+
isRwa: true,
|
|
3143
3208
|
name: "SpaceX Class A",
|
|
3144
3209
|
decimals: 8,
|
|
3145
3210
|
address: "0x0000000000000000000000000000000000a5669e",
|
|
@@ -3149,6 +3214,7 @@ var hederaSupportedTokens = {
|
|
|
3149
3214
|
},
|
|
3150
3215
|
NVDA: {
|
|
3151
3216
|
symbol: "NVDA",
|
|
3217
|
+
isRwa: true,
|
|
3152
3218
|
name: "NVIDIA",
|
|
3153
3219
|
decimals: 8,
|
|
3154
3220
|
address: "0x0000000000000000000000000000000000a5669f",
|
|
@@ -3158,6 +3224,7 @@ var hederaSupportedTokens = {
|
|
|
3158
3224
|
},
|
|
3159
3225
|
GME: {
|
|
3160
3226
|
symbol: "GME",
|
|
3227
|
+
isRwa: true,
|
|
3161
3228
|
name: "GameStop",
|
|
3162
3229
|
decimals: 8,
|
|
3163
3230
|
address: "0x0000000000000000000000000000000000a567d9",
|
|
@@ -3167,6 +3234,7 @@ var hederaSupportedTokens = {
|
|
|
3167
3234
|
},
|
|
3168
3235
|
MSTR: {
|
|
3169
3236
|
symbol: "MSTR",
|
|
3237
|
+
isRwa: true,
|
|
3170
3238
|
name: "Strategy",
|
|
3171
3239
|
decimals: 8,
|
|
3172
3240
|
address: "0x0000000000000000000000000000000000a567e0",
|
|
@@ -3176,6 +3244,7 @@ var hederaSupportedTokens = {
|
|
|
3176
3244
|
},
|
|
3177
3245
|
AAPL: {
|
|
3178
3246
|
symbol: "AAPL",
|
|
3247
|
+
isRwa: true,
|
|
3179
3248
|
name: "Apple",
|
|
3180
3249
|
decimals: 8,
|
|
3181
3250
|
address: "0x0000000000000000000000000000000000a567e1",
|
|
@@ -3185,6 +3254,7 @@ var hederaSupportedTokens = {
|
|
|
3185
3254
|
},
|
|
3186
3255
|
TSLA: {
|
|
3187
3256
|
symbol: "TSLA",
|
|
3257
|
+
isRwa: true,
|
|
3188
3258
|
name: "Tesla",
|
|
3189
3259
|
decimals: 8,
|
|
3190
3260
|
address: "0x0000000000000000000000000000000000a567e2",
|
|
@@ -3194,6 +3264,7 @@ var hederaSupportedTokens = {
|
|
|
3194
3264
|
},
|
|
3195
3265
|
MU: {
|
|
3196
3266
|
symbol: "MU",
|
|
3267
|
+
isRwa: true,
|
|
3197
3268
|
name: "Micron",
|
|
3198
3269
|
decimals: 8,
|
|
3199
3270
|
address: "0x0000000000000000000000000000000000a567e3",
|
|
@@ -3203,6 +3274,7 @@ var hederaSupportedTokens = {
|
|
|
3203
3274
|
},
|
|
3204
3275
|
SNDK: {
|
|
3205
3276
|
symbol: "SNDK",
|
|
3277
|
+
isRwa: true,
|
|
3206
3278
|
name: "SanDisk",
|
|
3207
3279
|
decimals: 8,
|
|
3208
3280
|
address: "0x0000000000000000000000000000000000a567e5",
|
|
@@ -3212,6 +3284,7 @@ var hederaSupportedTokens = {
|
|
|
3212
3284
|
},
|
|
3213
3285
|
SPY: {
|
|
3214
3286
|
symbol: "SPY",
|
|
3287
|
+
isRwa: true,
|
|
3215
3288
|
name: "SPDR S&P 500 ETF Trust",
|
|
3216
3289
|
decimals: 8,
|
|
3217
3290
|
address: "0x0000000000000000000000000000000000a567e7",
|
|
@@ -3221,6 +3294,7 @@ var hederaSupportedTokens = {
|
|
|
3221
3294
|
},
|
|
3222
3295
|
QQQ: {
|
|
3223
3296
|
symbol: "QQQ",
|
|
3297
|
+
isRwa: true,
|
|
3224
3298
|
name: "Invesco QQQ Trust",
|
|
3225
3299
|
decimals: 8,
|
|
3226
3300
|
address: "0x0000000000000000000000000000000000a567ea",
|
|
@@ -3230,6 +3304,7 @@ var hederaSupportedTokens = {
|
|
|
3230
3304
|
},
|
|
3231
3305
|
SGOV: {
|
|
3232
3306
|
symbol: "SGOV",
|
|
3307
|
+
isRwa: true,
|
|
3233
3308
|
name: "iShares 0-3 Month Treasury Bond ETF",
|
|
3234
3309
|
decimals: 8,
|
|
3235
3310
|
address: "0x0000000000000000000000000000000000a567ec",
|
|
@@ -3239,6 +3314,7 @@ var hederaSupportedTokens = {
|
|
|
3239
3314
|
},
|
|
3240
3315
|
USO: {
|
|
3241
3316
|
symbol: "USO",
|
|
3317
|
+
isRwa: true,
|
|
3242
3318
|
name: "United States Oil Fund LP",
|
|
3243
3319
|
decimals: 8,
|
|
3244
3320
|
address: "0x0000000000000000000000000000000000a567ed",
|
|
@@ -3248,6 +3324,7 @@ var hederaSupportedTokens = {
|
|
|
3248
3324
|
},
|
|
3249
3325
|
SLV: {
|
|
3250
3326
|
symbol: "SLV",
|
|
3327
|
+
isRwa: true,
|
|
3251
3328
|
name: "iShares Silver Trust",
|
|
3252
3329
|
decimals: 8,
|
|
3253
3330
|
address: "0x0000000000000000000000000000000000a567f2",
|
|
@@ -3300,6 +3377,7 @@ var robinhoodSupportedTokens = {
|
|
|
3300
3377
|
// feed exists for them, so the solver cannot price or swap them.
|
|
3301
3378
|
SPCX: {
|
|
3302
3379
|
symbol: "SPCX",
|
|
3380
|
+
isRwa: true,
|
|
3303
3381
|
name: "SpaceX Class A",
|
|
3304
3382
|
decimals: 18,
|
|
3305
3383
|
address: "0x4a0E65A3EcceC6dBe60AE065F2e7bb85Fae35eEa",
|
|
@@ -3309,6 +3387,7 @@ var robinhoodSupportedTokens = {
|
|
|
3309
3387
|
},
|
|
3310
3388
|
NVDA: {
|
|
3311
3389
|
symbol: "NVDA",
|
|
3390
|
+
isRwa: true,
|
|
3312
3391
|
name: "NVIDIA",
|
|
3313
3392
|
decimals: 18,
|
|
3314
3393
|
address: "0xd0601CE157Db5bdC3162BbaC2a2C8aF5320D9EEC",
|
|
@@ -3318,6 +3397,7 @@ var robinhoodSupportedTokens = {
|
|
|
3318
3397
|
},
|
|
3319
3398
|
GME: {
|
|
3320
3399
|
symbol: "GME",
|
|
3400
|
+
isRwa: true,
|
|
3321
3401
|
name: "GameStop",
|
|
3322
3402
|
decimals: 18,
|
|
3323
3403
|
address: "0x1b0E319c6A659F002271B69dB8A7df2F911c153E",
|
|
@@ -3327,6 +3407,7 @@ var robinhoodSupportedTokens = {
|
|
|
3327
3407
|
},
|
|
3328
3408
|
MSTR: {
|
|
3329
3409
|
symbol: "MSTR",
|
|
3410
|
+
isRwa: true,
|
|
3330
3411
|
name: "Strategy",
|
|
3331
3412
|
decimals: 18,
|
|
3332
3413
|
address: "0xec262a75e413fAfD0dF80480274532C79D42da09",
|
|
@@ -3336,6 +3417,7 @@ var robinhoodSupportedTokens = {
|
|
|
3336
3417
|
},
|
|
3337
3418
|
AAPL: {
|
|
3338
3419
|
symbol: "AAPL",
|
|
3420
|
+
isRwa: true,
|
|
3339
3421
|
name: "Apple",
|
|
3340
3422
|
decimals: 18,
|
|
3341
3423
|
address: "0xaF3D76f1834A1d425780943C99Ea8A608f8a93f9",
|
|
@@ -3345,6 +3427,7 @@ var robinhoodSupportedTokens = {
|
|
|
3345
3427
|
},
|
|
3346
3428
|
TSLA: {
|
|
3347
3429
|
symbol: "TSLA",
|
|
3430
|
+
isRwa: true,
|
|
3348
3431
|
name: "Tesla",
|
|
3349
3432
|
decimals: 18,
|
|
3350
3433
|
address: "0x322F0929c4625eD5bAd873c95208D54E1c003b2d",
|
|
@@ -3354,6 +3437,7 @@ var robinhoodSupportedTokens = {
|
|
|
3354
3437
|
},
|
|
3355
3438
|
MU: {
|
|
3356
3439
|
symbol: "MU",
|
|
3440
|
+
isRwa: true,
|
|
3357
3441
|
name: "Micron",
|
|
3358
3442
|
decimals: 18,
|
|
3359
3443
|
address: "0xfF080c8ce2E5feadaCa0Da81314Ae59D232d4afD",
|
|
@@ -3363,6 +3447,7 @@ var robinhoodSupportedTokens = {
|
|
|
3363
3447
|
},
|
|
3364
3448
|
SNDK: {
|
|
3365
3449
|
symbol: "SNDK",
|
|
3450
|
+
isRwa: true,
|
|
3366
3451
|
name: "SanDisk",
|
|
3367
3452
|
decimals: 18,
|
|
3368
3453
|
address: "0xB90A19fF0Af67f7779afF50A882A9CfF42446400",
|
|
@@ -3372,6 +3457,7 @@ var robinhoodSupportedTokens = {
|
|
|
3372
3457
|
},
|
|
3373
3458
|
SPY: {
|
|
3374
3459
|
symbol: "SPY",
|
|
3460
|
+
isRwa: true,
|
|
3375
3461
|
name: "SPDR S&P 500 ETF Trust",
|
|
3376
3462
|
decimals: 18,
|
|
3377
3463
|
address: "0x117cc2133c37B721F49dE2A7a74833232B3B4C0C",
|
|
@@ -3381,6 +3467,7 @@ var robinhoodSupportedTokens = {
|
|
|
3381
3467
|
},
|
|
3382
3468
|
QQQ: {
|
|
3383
3469
|
symbol: "QQQ",
|
|
3470
|
+
isRwa: true,
|
|
3384
3471
|
name: "Invesco QQQ Trust",
|
|
3385
3472
|
decimals: 18,
|
|
3386
3473
|
address: "0xD5f3879160bc7c32ebb4dC785F8a4F505888de68",
|
|
@@ -3390,6 +3477,7 @@ var robinhoodSupportedTokens = {
|
|
|
3390
3477
|
},
|
|
3391
3478
|
SGOV: {
|
|
3392
3479
|
symbol: "SGOV",
|
|
3480
|
+
isRwa: true,
|
|
3393
3481
|
name: "iShares 0-3 Month Treasury Bond ETF",
|
|
3394
3482
|
decimals: 18,
|
|
3395
3483
|
address: "0x92FD66527192E3e61d4DDd13322Aa222DE86F9B5",
|
|
@@ -3399,6 +3487,7 @@ var robinhoodSupportedTokens = {
|
|
|
3399
3487
|
},
|
|
3400
3488
|
USO: {
|
|
3401
3489
|
symbol: "USO",
|
|
3490
|
+
isRwa: true,
|
|
3402
3491
|
name: "United States Oil Fund LP",
|
|
3403
3492
|
decimals: 18,
|
|
3404
3493
|
address: "0xa30FA36Db767ad9eD3f7a60fC79526fB4d56D344",
|
|
@@ -3408,6 +3497,7 @@ var robinhoodSupportedTokens = {
|
|
|
3408
3497
|
},
|
|
3409
3498
|
SLV: {
|
|
3410
3499
|
symbol: "SLV",
|
|
3500
|
+
isRwa: true,
|
|
3411
3501
|
name: "iShares Silver Trust",
|
|
3412
3502
|
decimals: 18,
|
|
3413
3503
|
address: "0x411eFb0E7f985935DAec3D4C3ebaEa0d0AD7D89f",
|
|
@@ -3487,6 +3577,16 @@ var supportedTokensByChain = {
|
|
|
3487
3577
|
[ChainKeys.HEDERA_MAINNET]: hederaSupportedTokens,
|
|
3488
3578
|
[ChainKeys.ROBINHOOD_MAINNET]: robinhoodSupportedTokens
|
|
3489
3579
|
};
|
|
3580
|
+
function isRealWorldAsset(token) {
|
|
3581
|
+
const registry = supportedTokensByChain;
|
|
3582
|
+
const chainTokens = registry[token.chainKey];
|
|
3583
|
+
if (!chainTokens)
|
|
3584
|
+
return false;
|
|
3585
|
+
const tokens = Object.values(chainTokens);
|
|
3586
|
+
const normalize2 = (address2) => /^0x[0-9a-f]{40}$/i.test(address2) ? address2.toLowerCase() : address2;
|
|
3587
|
+
const address = normalize2(token.address);
|
|
3588
|
+
return tokens.some((candidate) => normalize2(candidate.address) === address && candidate.isRwa === true);
|
|
3589
|
+
}
|
|
3490
3590
|
|
|
3491
3591
|
// ../types/dist/chains/chains.js
|
|
3492
3592
|
var RelayChainIdMap = {
|
|
@@ -3851,6 +3951,14 @@ var NEAR_CHAIN_KEYS = filterChainKeysByType("NEAR");
|
|
|
3851
3951
|
var NEAR_CHAIN_KEYS_SET = new Set(NEAR_CHAIN_KEYS);
|
|
3852
3952
|
var BITCOIN_CHAIN_KEYS = filterChainKeysByType("BITCOIN");
|
|
3853
3953
|
var BITCOIN_CHAIN_KEYS_SET = new Set(BITCOIN_CHAIN_KEYS);
|
|
3954
|
+
var BOUND_API_HOST = "https://svc.bound.exchange/api";
|
|
3955
|
+
var BOUND_COMPANION_HOSTS = {
|
|
3956
|
+
[BOUND_API_HOST]: {
|
|
3957
|
+
auth: "https://auth.bound.exchange/api",
|
|
3958
|
+
transactions: "https://api.radfi.co/api"
|
|
3959
|
+
}
|
|
3960
|
+
};
|
|
3961
|
+
var DEPRECATED_BOUND_HOSTS = ["https://api.bound.exchange/api"];
|
|
3854
3962
|
var spokeChainConfig = {
|
|
3855
3963
|
[ChainKeys.SONIC_MAINNET]: {
|
|
3856
3964
|
chain: baseChainInfo[ChainKeys.SONIC_MAINNET],
|
|
@@ -4057,7 +4165,8 @@ var spokeChainConfig = {
|
|
|
4057
4165
|
supportedTokens: bitcoinSupportedTokens,
|
|
4058
4166
|
radfi: {
|
|
4059
4167
|
walletMode: "TRADING",
|
|
4060
|
-
|
|
4168
|
+
// authUrl / transactionsUrl are intentionally absent: see BOUND_COMPANION_HOSTS.
|
|
4169
|
+
apiUrl: BOUND_API_HOST,
|
|
4061
4170
|
apiKey: "",
|
|
4062
4171
|
umsUrl: "https://api.ums.bound.exchange/api",
|
|
4063
4172
|
accessToken: "",
|
|
@@ -4516,7 +4625,8 @@ var moneyMarketSupportedTokens = {
|
|
|
4516
4625
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.cbBTC,
|
|
4517
4626
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.SODA,
|
|
4518
4627
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.USDT,
|
|
4519
|
-
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.USDS
|
|
4628
|
+
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.USDS,
|
|
4629
|
+
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.sUSDS
|
|
4520
4630
|
],
|
|
4521
4631
|
[ChainKeys.OPTIMISM_MAINNET]: [
|
|
4522
4632
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.ETH,
|
|
@@ -4525,7 +4635,8 @@ var moneyMarketSupportedTokens = {
|
|
|
4525
4635
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.wstETH,
|
|
4526
4636
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.weETH,
|
|
4527
4637
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.USDT,
|
|
4528
|
-
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.SODA
|
|
4638
|
+
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.SODA,
|
|
4639
|
+
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.sUSDS
|
|
4529
4640
|
],
|
|
4530
4641
|
[ChainKeys.POLYGON_MAINNET]: [
|
|
4531
4642
|
spokeChainConfig[ChainKeys.POLYGON_MAINNET].supportedTokens.POL,
|
|
@@ -4647,7 +4758,8 @@ var moneyMarketSupportedTokens = {
|
|
|
4647
4758
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.WBTC,
|
|
4648
4759
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.WBTC_LEGACY,
|
|
4649
4760
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.LL,
|
|
4650
|
-
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.USDS
|
|
4761
|
+
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.USDS,
|
|
4762
|
+
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.sUSDS
|
|
4651
4763
|
],
|
|
4652
4764
|
[ChainKeys.REDBELLY_MAINNET]: [
|
|
4653
4765
|
spokeChainConfig[ChainKeys.REDBELLY_MAINNET].supportedTokens.bnUSD,
|
|
@@ -4880,9 +4992,10 @@ var swapSupportedTokens = {
|
|
|
4880
4992
|
spokeChainConfig[ChainKeys.SONIC_MAINNET].supportedTokens.USDT,
|
|
4881
4993
|
spokeChainConfig[ChainKeys.SONIC_MAINNET].supportedTokens.wS,
|
|
4882
4994
|
spokeChainConfig[ChainKeys.SONIC_MAINNET].supportedTokens.SODA,
|
|
4883
|
-
|
|
4884
|
-
// Swap membership is per-vault, not every SodaTokens entry:
|
|
4885
|
-
//
|
|
4995
|
+
spokeChainConfig[ChainKeys.SONIC_MAINNET].supportedTokens.USSD,
|
|
4996
|
+
// Swap membership is per-vault, not every SodaTokens entry: sodaUSDS is the one wrapper the
|
|
4997
|
+
// production solver cannot route — a `/quote` against it returns `No path was found`, where
|
|
4998
|
+
// USSD, sodaUSSD and sodaSUSDS all return real prices — so it stays out until a path exists.
|
|
4886
4999
|
SodaTokens.sodaBNB,
|
|
4887
5000
|
SodaTokens.sodaAVAX,
|
|
4888
5001
|
SodaTokens.sodaETH,
|
|
@@ -4907,8 +5020,10 @@ var swapSupportedTokens = {
|
|
|
4907
5020
|
SodaTokens.sodaNEAR,
|
|
4908
5021
|
SodaTokens.sodaKAIA,
|
|
4909
5022
|
SodaTokens.sodaSTX,
|
|
5023
|
+
SodaTokens.sodaSUSDS,
|
|
4910
5024
|
SodaTokens.sodaHBAR,
|
|
4911
5025
|
SodaTokens.sodaJITOSOL,
|
|
5026
|
+
SodaTokens.sodaUSSD,
|
|
4912
5027
|
...Object.values(LsodaTokens),
|
|
4913
5028
|
// Robinhood tokenized equities — swap-only, deliberately absent from the money market.
|
|
4914
5029
|
SodaTokens.SPCX,
|
|
@@ -4942,6 +5057,7 @@ var swapSupportedTokens = {
|
|
|
4942
5057
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.tBTC,
|
|
4943
5058
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.USDC,
|
|
4944
5059
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.USDT,
|
|
5060
|
+
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.sUSDS,
|
|
4945
5061
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.ARB,
|
|
4946
5062
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.AAVE,
|
|
4947
5063
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.LINK,
|
|
@@ -4956,6 +5072,7 @@ var swapSupportedTokens = {
|
|
|
4956
5072
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.ETH,
|
|
4957
5073
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.weETH,
|
|
4958
5074
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.USDC,
|
|
5075
|
+
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.sUSDS,
|
|
4959
5076
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.wstETH,
|
|
4960
5077
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.cbBTC,
|
|
4961
5078
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.VIRTUAL,
|
|
@@ -4966,6 +5083,7 @@ var swapSupportedTokens = {
|
|
|
4966
5083
|
[ChainKeys.OPTIMISM_MAINNET]: [
|
|
4967
5084
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.ETH,
|
|
4968
5085
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.USDC,
|
|
5086
|
+
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.sUSDS,
|
|
4969
5087
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.wstETH,
|
|
4970
5088
|
// spokeChainConfig[OPTIMISM_MAINNET_CHAIN_ID].supportedTokens.weETH, // NOTE: Not Implemented
|
|
4971
5089
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.USDT,
|
|
@@ -5133,6 +5251,7 @@ var swapSupportedTokens = {
|
|
|
5133
5251
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.ETH,
|
|
5134
5252
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.bnUSD,
|
|
5135
5253
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.USDC,
|
|
5254
|
+
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.sUSDS,
|
|
5136
5255
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.USDT,
|
|
5137
5256
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.SODA,
|
|
5138
5257
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.LL,
|
|
@@ -5239,7 +5358,7 @@ var swapSupportedTokens = {
|
|
|
5239
5358
|
]
|
|
5240
5359
|
};
|
|
5241
5360
|
var stagingSwapSupportedTokens = {
|
|
5242
|
-
[ChainKeys.SONIC_MAINNET]: [
|
|
5361
|
+
[ChainKeys.SONIC_MAINNET]: [],
|
|
5243
5362
|
[ChainKeys.AVALANCHE_MAINNET]: [],
|
|
5244
5363
|
[ChainKeys.ARBITRUM_MAINNET]: [],
|
|
5245
5364
|
[ChainKeys.BASE_MAINNET]: [
|
|
@@ -5346,7 +5465,8 @@ var leverageYieldVaults = [
|
|
|
5346
5465
|
}
|
|
5347
5466
|
];
|
|
5348
5467
|
var leverageYieldConfig = {
|
|
5349
|
-
vaults: leverageYieldVaults
|
|
5468
|
+
vaults: leverageYieldVaults,
|
|
5469
|
+
positionFactory: "0xF8fB7F200B6545295e1729Cf254482d7c116031C"
|
|
5350
5470
|
};
|
|
5351
5471
|
|
|
5352
5472
|
// ../types/dist/sodax-config/sodax-config.js
|
|
@@ -5579,7 +5699,45 @@ function isValidWalletProviderForChainKey(chainKey, walletProvider) {
|
|
|
5579
5699
|
}
|
|
5580
5700
|
|
|
5581
5701
|
// ../types/dist/index.js
|
|
5582
|
-
var CONFIG_VERSION =
|
|
5702
|
+
var CONFIG_VERSION = 2020006;
|
|
5703
|
+
var RC_STABLE = 99;
|
|
5704
|
+
var MIN_CONFIG_VERSION = 1e6;
|
|
5705
|
+
var MAX_CONFIG_VERSION = 99999999;
|
|
5706
|
+
var VERSION_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-rc\.(0|[1-9]\d*))?$/;
|
|
5707
|
+
function configVersionFor(version) {
|
|
5708
|
+
const match = typeof version === "string" ? version.match(VERSION_PATTERN) : null;
|
|
5709
|
+
if (!match)
|
|
5710
|
+
return null;
|
|
5711
|
+
const major = Number(match[1]);
|
|
5712
|
+
const minor = Number(match[2]);
|
|
5713
|
+
const patch = Number(match[3]);
|
|
5714
|
+
const rc = match[4] === void 0 ? null : Number(match[4]);
|
|
5715
|
+
if (major < 1 || major > 99 || minor > 99 || patch > 99)
|
|
5716
|
+
return null;
|
|
5717
|
+
if (rc !== null && rc > 98)
|
|
5718
|
+
return null;
|
|
5719
|
+
return major * 1e6 + minor * 1e4 + patch * 100 + (rc === null ? RC_STABLE : rc);
|
|
5720
|
+
}
|
|
5721
|
+
var unpack = (value) => {
|
|
5722
|
+
const slot = value % 100;
|
|
5723
|
+
return {
|
|
5724
|
+
major: Math.floor(value / 1e6),
|
|
5725
|
+
minor: Math.floor(value / 1e4) % 100,
|
|
5726
|
+
patch: Math.floor(value / 100) % 100,
|
|
5727
|
+
rc: slot === RC_STABLE ? null : slot
|
|
5728
|
+
};
|
|
5729
|
+
};
|
|
5730
|
+
var render = ({ major, minor, patch, rc }) => `${major}.${minor}.${patch}${rc === null ? "" : `-rc.${rc}`}`;
|
|
5731
|
+
function parseConfigVersion(value) {
|
|
5732
|
+
if (!Number.isInteger(value) || value < MIN_CONFIG_VERSION || value > MAX_CONFIG_VERSION)
|
|
5733
|
+
return null;
|
|
5734
|
+
return unpack(value);
|
|
5735
|
+
}
|
|
5736
|
+
function formatConfigVersion(value) {
|
|
5737
|
+
const parsed = parseConfigVersion(value);
|
|
5738
|
+
return parsed === null ? null : render(parsed);
|
|
5739
|
+
}
|
|
5740
|
+
var SDK_VERSION = render(unpack(CONFIG_VERSION));
|
|
5583
5741
|
|
|
5584
5742
|
// src/shared/utils/resolveTimeoutMs.ts
|
|
5585
5743
|
function resolveTimeoutMs(timeout, fallbackMs) {
|
|
@@ -15514,11 +15672,15 @@ var ConfigService = class {
|
|
|
15514
15672
|
isMoneyMarketSupportedToken(chainId, token) {
|
|
15515
15673
|
return this.sodax.moneyMarket.supportedTokens[chainId].some((t) => t.address.toLowerCase() === token.toLowerCase());
|
|
15516
15674
|
}
|
|
15675
|
+
/**
|
|
15676
|
+
* Is `asset` one of the money-market reserve assets?
|
|
15677
|
+
*
|
|
15678
|
+
* The reserve set is built from `moneyMarketHubVaults`, so its members are hub **vault**
|
|
15679
|
+
* addresses. Query it with an `XToken.vault`; an `XToken.hubAsset` only matches for the Sonic
|
|
15680
|
+
* vault shares themselves, where `hubAsset === vault`.
|
|
15681
|
+
*/
|
|
15517
15682
|
isMoneyMarketReserveAsset(asset) {
|
|
15518
|
-
return this.
|
|
15519
|
-
}
|
|
15520
|
-
isMoneyMarketReserveHubAsset(hubAsset) {
|
|
15521
|
-
return this.moneyMarketReserveAssetsSet.has(hubAsset.toLowerCase());
|
|
15683
|
+
return this.moneyMarketReserveAssetsSet.has(asset.toLowerCase());
|
|
15522
15684
|
}
|
|
15523
15685
|
loadSodaxConfigDataStructures(sodaxConfig2) {
|
|
15524
15686
|
this.hubAssetToXTokenMap = new Map(
|
|
@@ -15667,7 +15829,7 @@ function mergeSodaxConfig(base2, override) {
|
|
|
15667
15829
|
}
|
|
15668
15830
|
function encodeContractCalls(calls) {
|
|
15669
15831
|
return viem.encodeAbiParameters(viem.parseAbiParameters("(address,uint256,bytes)[]"), [
|
|
15670
|
-
calls.map((
|
|
15832
|
+
calls.map((v10) => [v10.address, v10.value, v10.data])
|
|
15671
15833
|
]);
|
|
15672
15834
|
}
|
|
15673
15835
|
async function waitForTransactionReceipt(hash, provider) {
|
|
@@ -16851,10 +17013,17 @@ var RadfiApiError = class extends Error {
|
|
|
16851
17013
|
this.cause = body;
|
|
16852
17014
|
}
|
|
16853
17015
|
};
|
|
17016
|
+
var stripSlash = (url) => url.endsWith("/") ? url.slice(0, -1) : url;
|
|
17017
|
+
var normalizeUrl = (url) => {
|
|
17018
|
+
const trimmed = url?.trim();
|
|
17019
|
+
return trimmed ? stripSlash(trimmed) : void 0;
|
|
17020
|
+
};
|
|
16854
17021
|
var RadfiProvider = class {
|
|
16855
17022
|
config;
|
|
17023
|
+
hosts;
|
|
16856
17024
|
// Client-side runtime signer (e.g. a backend's HMAC closure). Holds no credential itself — the SDK
|
|
16857
|
-
// only keeps the reference and invokes it per outbound
|
|
17025
|
+
// only keeps the reference and invokes it per outbound Bound request, on every routed host.
|
|
17026
|
+
// UMS calls bypass `request()` and stay unsigned. See `RadfiOptions` / gh-831.
|
|
16858
17027
|
signer;
|
|
16859
17028
|
accessToken = "";
|
|
16860
17029
|
refreshToken = "";
|
|
@@ -16863,12 +17032,30 @@ var RadfiProvider = class {
|
|
|
16863
17032
|
this.signer = options?.signer;
|
|
16864
17033
|
this.accessToken = config.accessToken ?? "";
|
|
16865
17034
|
this.refreshToken = config.refreshToken ?? "";
|
|
16866
|
-
if (config.apiUrl.endsWith("/")) {
|
|
16867
|
-
this.config.apiUrl = config.apiUrl.slice(0, -1);
|
|
16868
|
-
}
|
|
16869
17035
|
if (config.umsUrl?.endsWith("/")) {
|
|
16870
17036
|
this.config.umsUrl = config.umsUrl.slice(0, -1);
|
|
16871
17037
|
}
|
|
17038
|
+
const api = normalizeUrl(config.apiUrl) ?? config.apiUrl;
|
|
17039
|
+
const companions = BOUND_COMPANION_HOSTS[api] ?? {};
|
|
17040
|
+
this.hosts = {
|
|
17041
|
+
api,
|
|
17042
|
+
auth: normalizeUrl(config.authUrl) ?? companions.auth ?? api,
|
|
17043
|
+
transactions: normalizeUrl(config.transactionsUrl) ?? companions.transactions ?? api
|
|
17044
|
+
};
|
|
17045
|
+
const packaged = BOUND_COMPANION_HOSTS[BOUND_API_HOST] ?? {};
|
|
17046
|
+
const replacementFor = {
|
|
17047
|
+
apiUrl: BOUND_API_HOST,
|
|
17048
|
+
authUrl: packaged.auth ?? BOUND_API_HOST,
|
|
17049
|
+
transactionsUrl: packaged.transactions ?? BOUND_API_HOST
|
|
17050
|
+
};
|
|
17051
|
+
for (const field of ["apiUrl", "authUrl", "transactionsUrl"]) {
|
|
17052
|
+
const url = normalizeUrl(config[field]);
|
|
17053
|
+
if (url && DEPRECATED_BOUND_HOSTS.includes(url)) {
|
|
17054
|
+
throw new Error(
|
|
17055
|
+
`Bound Exchange has retired ${url}. Set chains.bitcoin.radfi.${field} to ${replacementFor[field]}, or remove it to take the packaged default.`
|
|
17056
|
+
);
|
|
17057
|
+
}
|
|
17058
|
+
}
|
|
16872
17059
|
}
|
|
16873
17060
|
/**
|
|
16874
17061
|
* Authenticate with Bound Exchange: BIP322-sign a login message, then call the Bound Exchange API.
|
|
@@ -16919,7 +17106,7 @@ var RadfiProvider = class {
|
|
|
16919
17106
|
}
|
|
16920
17107
|
}
|
|
16921
17108
|
async authenticate(params) {
|
|
16922
|
-
const res = await this.request("/auth/authenticate", {
|
|
17109
|
+
const res = await this.request("auth", "/auth/authenticate", {
|
|
16923
17110
|
method: "POST",
|
|
16924
17111
|
body: JSON.stringify(params)
|
|
16925
17112
|
});
|
|
@@ -16934,7 +17121,7 @@ var RadfiProvider = class {
|
|
|
16934
17121
|
};
|
|
16935
17122
|
}
|
|
16936
17123
|
async refreshAccessToken(refreshToken) {
|
|
16937
|
-
const res = await this.request("/auth/refresh-token", {
|
|
17124
|
+
const res = await this.request("auth", "/auth/refresh-token", {
|
|
16938
17125
|
method: "POST",
|
|
16939
17126
|
body: JSON.stringify({ refreshToken })
|
|
16940
17127
|
});
|
|
@@ -16948,7 +17135,7 @@ var RadfiProvider = class {
|
|
|
16948
17135
|
};
|
|
16949
17136
|
}
|
|
16950
17137
|
async createTradingWallet(params, accessToken) {
|
|
16951
|
-
const res = await this.request("/wallets", {
|
|
17138
|
+
const res = await this.request("auth", "/wallets", {
|
|
16952
17139
|
method: "POST",
|
|
16953
17140
|
headers: {
|
|
16954
17141
|
Authorization: `Bearer ${this.resolveAuth(accessToken)}`
|
|
@@ -16962,7 +17149,7 @@ var RadfiProvider = class {
|
|
|
16962
17149
|
return body.data;
|
|
16963
17150
|
}
|
|
16964
17151
|
async getTradingWallet(userAddress) {
|
|
16965
|
-
const res = await this.request(`/wallets/details/${userAddress}`, {
|
|
17152
|
+
const res = await this.request("auth", `/wallets/details/${userAddress}`, {
|
|
16966
17153
|
method: "GET"
|
|
16967
17154
|
});
|
|
16968
17155
|
const body = await this.parseJsonBody(res, "Trading wallet not found");
|
|
@@ -16971,9 +17158,9 @@ var RadfiProvider = class {
|
|
|
16971
17158
|
}
|
|
16972
17159
|
return body.data;
|
|
16973
17160
|
}
|
|
16974
|
-
// UMS call: goes out unsigned even when a signer is configured.
|
|
16975
|
-
//
|
|
16976
|
-
//
|
|
17161
|
+
// UMS call: goes out unsigned even when a signer is configured. UMS is separate infrastructure
|
|
17162
|
+
// on `umsUrl`, outside the api/auth/transactions routing table, and does not verify the backend
|
|
17163
|
+
// signature — so this bypasses `request()`, which signs. Same for `getExpiredUtxos`. See gh-831.
|
|
16977
17164
|
async getBalance(address) {
|
|
16978
17165
|
if (!this.config.umsUrl) {
|
|
16979
17166
|
throw new Error("RadfiConfig.umsUrl is required for getBalance");
|
|
@@ -17004,7 +17191,7 @@ var RadfiProvider = class {
|
|
|
17004
17191
|
}
|
|
17005
17192
|
}
|
|
17006
17193
|
async createWithdrawTransaction(params, accessToken) {
|
|
17007
|
-
const res = await this.request("/sodax/transaction", {
|
|
17194
|
+
const res = await this.request("api", "/sodax/transaction", {
|
|
17008
17195
|
method: "POST",
|
|
17009
17196
|
headers: {
|
|
17010
17197
|
Authorization: `Bearer ${this.resolveAuth(accessToken)}`
|
|
@@ -17033,7 +17220,7 @@ var RadfiProvider = class {
|
|
|
17033
17220
|
* gets stuck (otherwise a stuck relay eventually refunds instead of completing the swap).
|
|
17034
17221
|
*/
|
|
17035
17222
|
async requestRadfiSignature(params, accessToken) {
|
|
17036
|
-
const res = await this.request("/sodax/transaction/sign", {
|
|
17223
|
+
const res = await this.request("api", "/sodax/transaction/sign", {
|
|
17037
17224
|
method: "POST",
|
|
17038
17225
|
headers: {
|
|
17039
17226
|
Authorization: `Bearer ${this.resolveAuth(accessToken)}`
|
|
@@ -17052,8 +17239,8 @@ var RadfiProvider = class {
|
|
|
17052
17239
|
/**
|
|
17053
17240
|
* Fetch expired (or near-expiry) UTXOs for a trading wallet address from UMS API.
|
|
17054
17241
|
*
|
|
17055
|
-
* UMS call — unsigned by design, like `getBalance`:
|
|
17056
|
-
*
|
|
17242
|
+
* UMS call — unsigned by design, like `getBalance`: UMS sits outside the api/auth/transactions
|
|
17243
|
+
* routing table, so it bypasses `request()` and a configured signer never runs.
|
|
17057
17244
|
*/
|
|
17058
17245
|
async getExpiredUtxos(tradingAddress, params) {
|
|
17059
17246
|
if (!this.config.umsUrl) {
|
|
@@ -17077,7 +17264,7 @@ var RadfiProvider = class {
|
|
|
17077
17264
|
* Returns a PSBT that needs to be signed by the user.
|
|
17078
17265
|
*/
|
|
17079
17266
|
async buildRenewUtxoTransaction(params, accessToken) {
|
|
17080
|
-
const res = await this.request("/transactions", {
|
|
17267
|
+
const res = await this.request("transactions", "/transactions", {
|
|
17081
17268
|
method: "POST",
|
|
17082
17269
|
headers: {
|
|
17083
17270
|
Authorization: `Bearer ${accessToken}`
|
|
@@ -17101,7 +17288,7 @@ var RadfiProvider = class {
|
|
|
17101
17288
|
* The user signs the PSBT first, then Bound Exchange co-signs and broadcasts.
|
|
17102
17289
|
*/
|
|
17103
17290
|
async signAndBroadcastRenewUtxo(params, accessToken) {
|
|
17104
|
-
const res = await this.request("/transactions/sign", {
|
|
17291
|
+
const res = await this.request("transactions", "/transactions/sign", {
|
|
17105
17292
|
method: "POST",
|
|
17106
17293
|
headers: {
|
|
17107
17294
|
Authorization: `Bearer ${accessToken}`
|
|
@@ -17125,7 +17312,7 @@ var RadfiProvider = class {
|
|
|
17125
17312
|
* Returns an unsigned PSBT for the user to sign.
|
|
17126
17313
|
*/
|
|
17127
17314
|
async withdrawToUser(params, accessToken) {
|
|
17128
|
-
const res = await this.request("/transactions", {
|
|
17315
|
+
const res = await this.request("transactions", "/transactions", {
|
|
17129
17316
|
method: "POST",
|
|
17130
17317
|
headers: {
|
|
17131
17318
|
Authorization: `Bearer ${accessToken}`
|
|
@@ -17145,7 +17332,7 @@ var RadfiProvider = class {
|
|
|
17145
17332
|
* Sign and broadcast a withdraw transaction via Bound Exchange.
|
|
17146
17333
|
*/
|
|
17147
17334
|
async signAndBroadcastWithdraw(params, accessToken) {
|
|
17148
|
-
const res = await this.request("/transactions/sign", {
|
|
17335
|
+
const res = await this.request("transactions", "/transactions/sign", {
|
|
17149
17336
|
method: "POST",
|
|
17150
17337
|
headers: {
|
|
17151
17338
|
Authorization: `Bearer ${accessToken}`
|
|
@@ -17173,7 +17360,7 @@ var RadfiProvider = class {
|
|
|
17173
17360
|
* Get max spendable amount for a withdraw transaction (amount after fee).
|
|
17174
17361
|
*/
|
|
17175
17362
|
async getMaxWithdrawable(params, accessToken) {
|
|
17176
|
-
const res = await this.request("/transactions/max-spent", {
|
|
17363
|
+
const res = await this.request("transactions", "/transactions/max-spent", {
|
|
17177
17364
|
method: "POST",
|
|
17178
17365
|
headers: {
|
|
17179
17366
|
Authorization: `Bearer ${accessToken}`
|
|
@@ -17234,9 +17421,10 @@ var RadfiProvider = class {
|
|
|
17234
17421
|
);
|
|
17235
17422
|
}
|
|
17236
17423
|
}
|
|
17237
|
-
async request(endpoint, options) {
|
|
17238
|
-
const
|
|
17239
|
-
|
|
17424
|
+
async request(host, endpoint, options) {
|
|
17425
|
+
const baseUrl = this.hosts[host];
|
|
17426
|
+
const signed = this.signer ? await this.signer({ method: options?.method ?? "GET", path: endpoint, baseUrl }) : void 0;
|
|
17427
|
+
return fetch(`${baseUrl}${endpoint}`, {
|
|
17240
17428
|
...options,
|
|
17241
17429
|
headers: {
|
|
17242
17430
|
"Content-Type": "application/json",
|
|
@@ -17904,7 +18092,7 @@ function hexToBytes2(hex) {
|
|
|
17904
18092
|
const al = hl / 2;
|
|
17905
18093
|
if (hl % 2)
|
|
17906
18094
|
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
17907
|
-
const
|
|
18095
|
+
const array3 = new Uint8Array(al);
|
|
17908
18096
|
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
17909
18097
|
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
17910
18098
|
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
@@ -17912,9 +18100,9 @@ function hexToBytes2(hex) {
|
|
|
17912
18100
|
const char = hex[hi] + hex[hi + 1];
|
|
17913
18101
|
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
17914
18102
|
}
|
|
17915
|
-
|
|
18103
|
+
array3[ai] = n1 * 16 + n2;
|
|
17916
18104
|
}
|
|
17917
|
-
return
|
|
18105
|
+
return array3;
|
|
17918
18106
|
}
|
|
17919
18107
|
function concatBytes(...arrays) {
|
|
17920
18108
|
let sum = 0;
|
|
@@ -18544,22 +18732,22 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
|
18544
18732
|
const byte0 = Uint8Array.of(0);
|
|
18545
18733
|
const byte1 = Uint8Array.of(1);
|
|
18546
18734
|
const _maxDrbgIters = 1e3;
|
|
18547
|
-
let
|
|
18735
|
+
let v10 = u8n(hashLen);
|
|
18548
18736
|
let k = u8n(hashLen);
|
|
18549
18737
|
let i = 0;
|
|
18550
18738
|
const reset = () => {
|
|
18551
|
-
|
|
18739
|
+
v10.fill(1);
|
|
18552
18740
|
k.fill(0);
|
|
18553
18741
|
i = 0;
|
|
18554
18742
|
};
|
|
18555
|
-
const h = (...msgs) => hmacFn(k, concatBytes(
|
|
18743
|
+
const h = (...msgs) => hmacFn(k, concatBytes(v10, ...msgs));
|
|
18556
18744
|
const reseed = (seed = NULL) => {
|
|
18557
18745
|
k = h(byte0, seed);
|
|
18558
|
-
|
|
18746
|
+
v10 = h();
|
|
18559
18747
|
if (seed.length === 0)
|
|
18560
18748
|
return;
|
|
18561
18749
|
k = h(byte1, seed);
|
|
18562
|
-
|
|
18750
|
+
v10 = h();
|
|
18563
18751
|
};
|
|
18564
18752
|
const gen = () => {
|
|
18565
18753
|
if (i++ >= _maxDrbgIters)
|
|
@@ -18567,10 +18755,10 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
|
18567
18755
|
let len = 0;
|
|
18568
18756
|
const out = [];
|
|
18569
18757
|
while (len < qByteLen) {
|
|
18570
|
-
|
|
18571
|
-
const sl =
|
|
18758
|
+
v10 = h();
|
|
18759
|
+
const sl = v10.slice();
|
|
18572
18760
|
out.push(sl);
|
|
18573
|
-
len +=
|
|
18761
|
+
len += v10.length;
|
|
18574
18762
|
}
|
|
18575
18763
|
return concatBytes(...out);
|
|
18576
18764
|
};
|
|
@@ -18585,18 +18773,18 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
|
18585
18773
|
};
|
|
18586
18774
|
return genUntil;
|
|
18587
18775
|
}
|
|
18588
|
-
function validateObject(
|
|
18589
|
-
if (!
|
|
18776
|
+
function validateObject(object4, fields = {}, optFields = {}) {
|
|
18777
|
+
if (!object4 || typeof object4 !== "object")
|
|
18590
18778
|
throw new Error("expected valid options object");
|
|
18591
18779
|
function checkField(fieldName, expectedType, isOpt) {
|
|
18592
|
-
const val =
|
|
18780
|
+
const val = object4[fieldName];
|
|
18593
18781
|
if (isOpt && val === void 0)
|
|
18594
18782
|
return;
|
|
18595
18783
|
const current = typeof val;
|
|
18596
18784
|
if (current !== expectedType || val === null)
|
|
18597
18785
|
throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
|
|
18598
18786
|
}
|
|
18599
|
-
const iter = (f, isOpt) => Object.entries(f).forEach(([k,
|
|
18787
|
+
const iter = (f, isOpt) => Object.entries(f).forEach(([k, v10]) => checkField(k, v10, isOpt));
|
|
18600
18788
|
iter(fields, false);
|
|
18601
18789
|
iter(optFields, true);
|
|
18602
18790
|
}
|
|
@@ -18635,12 +18823,12 @@ function pow2(x, power, modulo) {
|
|
|
18635
18823
|
}
|
|
18636
18824
|
return res;
|
|
18637
18825
|
}
|
|
18638
|
-
function invert(
|
|
18639
|
-
if (
|
|
18826
|
+
function invert(number4, modulo) {
|
|
18827
|
+
if (number4 === _0n2)
|
|
18640
18828
|
throw new Error("invert: expected non-zero number");
|
|
18641
18829
|
if (modulo <= _0n2)
|
|
18642
18830
|
throw new Error("invert: expected positive modulus, got " + modulo);
|
|
18643
|
-
let a = mod(
|
|
18831
|
+
let a = mod(number4, modulo);
|
|
18644
18832
|
let b = modulo;
|
|
18645
18833
|
let x = _0n2, u = _1n2;
|
|
18646
18834
|
while (a !== _0n2) {
|
|
@@ -18667,9 +18855,9 @@ function sqrt3mod4(Fp, n) {
|
|
|
18667
18855
|
function sqrt5mod8(Fp, n) {
|
|
18668
18856
|
const p5div8 = (Fp.ORDER - _5n) / _8n;
|
|
18669
18857
|
const n2 = Fp.mul(n, _2n);
|
|
18670
|
-
const
|
|
18671
|
-
const nv = Fp.mul(n,
|
|
18672
|
-
const i = Fp.mul(Fp.mul(nv, _2n),
|
|
18858
|
+
const v10 = Fp.pow(n2, p5div8);
|
|
18859
|
+
const nv = Fp.mul(n, v10);
|
|
18860
|
+
const i = Fp.mul(Fp.mul(nv, _2n), v10);
|
|
18673
18861
|
const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
|
|
18674
18862
|
assertIsSquare(Fp, root, n);
|
|
18675
18863
|
return root;
|
|
@@ -19144,27 +19332,27 @@ var wNAF = class {
|
|
|
19144
19332
|
assert0(n);
|
|
19145
19333
|
return acc;
|
|
19146
19334
|
}
|
|
19147
|
-
getPrecomputes(W, point,
|
|
19335
|
+
getPrecomputes(W, point, transform) {
|
|
19148
19336
|
let comp = pointPrecomputes.get(point);
|
|
19149
19337
|
if (!comp) {
|
|
19150
19338
|
comp = this.precomputeWindow(point, W);
|
|
19151
19339
|
if (W !== 1) {
|
|
19152
|
-
if (typeof
|
|
19153
|
-
comp =
|
|
19340
|
+
if (typeof transform === "function")
|
|
19341
|
+
comp = transform(comp);
|
|
19154
19342
|
pointPrecomputes.set(point, comp);
|
|
19155
19343
|
}
|
|
19156
19344
|
}
|
|
19157
19345
|
return comp;
|
|
19158
19346
|
}
|
|
19159
|
-
cached(point, scalar,
|
|
19347
|
+
cached(point, scalar, transform) {
|
|
19160
19348
|
const W = getW(point);
|
|
19161
|
-
return this.wNAF(W, this.getPrecomputes(W, point,
|
|
19349
|
+
return this.wNAF(W, this.getPrecomputes(W, point, transform), scalar);
|
|
19162
19350
|
}
|
|
19163
|
-
unsafe(point, scalar,
|
|
19351
|
+
unsafe(point, scalar, transform, prev) {
|
|
19164
19352
|
const W = getW(point);
|
|
19165
19353
|
if (W === 1)
|
|
19166
19354
|
return this._unsafeLadder(point, scalar, prev);
|
|
19167
|
-
return this.wNAFUnsafe(W, this.getPrecomputes(W, point,
|
|
19355
|
+
return this.wNAFUnsafe(W, this.getPrecomputes(W, point, transform), scalar, prev);
|
|
19168
19356
|
}
|
|
19169
19357
|
// We calculate precomputes for elliptic curve point multiplication
|
|
19170
19358
|
// using windowed method. This specifies window size and
|
|
@@ -19251,9 +19439,9 @@ function edwards(params, extraOpts = {}) {
|
|
|
19251
19439
|
validateObject(extraOpts, {}, { uvRatio: "function" });
|
|
19252
19440
|
const MASK = _2n2 << BigInt(Fn.BYTES * 8) - _1n4;
|
|
19253
19441
|
const modP = (n) => Fp.create(n);
|
|
19254
|
-
const uvRatio2 = extraOpts.uvRatio || ((u,
|
|
19442
|
+
const uvRatio2 = extraOpts.uvRatio || ((u, v10) => {
|
|
19255
19443
|
try {
|
|
19256
|
-
return { isValid: true, value: Fp.sqrt(Fp.div(u,
|
|
19444
|
+
return { isValid: true, value: Fp.sqrt(Fp.div(u, v10)) };
|
|
19257
19445
|
} catch (e) {
|
|
19258
19446
|
return { isValid: false, value: _0n4 };
|
|
19259
19447
|
}
|
|
@@ -19349,8 +19537,8 @@ function edwards(params, extraOpts = {}) {
|
|
|
19349
19537
|
aInRange("point.y", y, _0n4, max);
|
|
19350
19538
|
const y2 = modP(y * y);
|
|
19351
19539
|
const u = modP(y2 - _1n4);
|
|
19352
|
-
const
|
|
19353
|
-
let { isValid, value: x } = uvRatio2(u,
|
|
19540
|
+
const v10 = modP(d * y2 - a);
|
|
19541
|
+
let { isValid, value: x } = uvRatio2(u, v10);
|
|
19354
19542
|
if (!isValid)
|
|
19355
19543
|
throw new Error("bad point: invalid y coordinate");
|
|
19356
19544
|
const isXOdd = (x & _1n4) === _1n4;
|
|
@@ -19690,13 +19878,13 @@ function adjustScalarBytes(bytes) {
|
|
|
19690
19878
|
return bytes;
|
|
19691
19879
|
}
|
|
19692
19880
|
var ED25519_SQRT_M1 = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
|
|
19693
|
-
function uvRatio(u,
|
|
19881
|
+
function uvRatio(u, v10) {
|
|
19694
19882
|
const P = ed25519_CURVE_p;
|
|
19695
|
-
const v32 = mod(
|
|
19696
|
-
const v72 = mod(v32 * v32 *
|
|
19883
|
+
const v32 = mod(v10 * v10 * v10, P);
|
|
19884
|
+
const v72 = mod(v32 * v32 * v10, P);
|
|
19697
19885
|
const pow = ed25519_pow_2_252_3(u * v72).pow_p_5_8;
|
|
19698
19886
|
let x = mod(u * v32 * pow, P);
|
|
19699
|
-
const vx2 = mod(
|
|
19887
|
+
const vx2 = mod(v10 * x * x, P);
|
|
19700
19888
|
const root1 = x;
|
|
19701
19889
|
const root2 = mod(x * ED25519_SQRT_M1, P);
|
|
19702
19890
|
const useRoot1 = vx2 === u;
|
|
@@ -20027,7 +20215,7 @@ function findSeatPrice(validators, maxNumberOfSeats, minimumStakeRatio, protocol
|
|
|
20027
20215
|
return findSeatPriceForProtocolAfter49(validators, maxNumberOfSeats, minimumStakeRatio);
|
|
20028
20216
|
}
|
|
20029
20217
|
function findSeatPriceForProtocolBefore49(validators, numSeats) {
|
|
20030
|
-
const stakes = validators.map((
|
|
20218
|
+
const stakes = validators.map((v10) => BigInt(v10.stake)).sort(sortBigIntAsc);
|
|
20031
20219
|
const num = BigInt(numSeats);
|
|
20032
20220
|
const stakesSum = stakes.reduce((a, b) => a + b);
|
|
20033
20221
|
if (stakesSum < num) {
|
|
@@ -20056,7 +20244,7 @@ function findSeatPriceForProtocolAfter49(validators, maxNumberOfSeats, minimumSt
|
|
|
20056
20244
|
if (minimumStakeRatio.length != 2) {
|
|
20057
20245
|
throw Error("minimumStakeRatio should have 2 elements");
|
|
20058
20246
|
}
|
|
20059
|
-
const stakes = validators.map((
|
|
20247
|
+
const stakes = validators.map((v10) => BigInt(v10.stake)).sort(sortBigIntAsc);
|
|
20060
20248
|
const stakesSum = stakes.reduce((a, b) => a + b);
|
|
20061
20249
|
if (validators.length < maxNumberOfSeats) {
|
|
20062
20250
|
return stakesSum * BigInt(minimumStakeRatio[0]) / BigInt(minimumStakeRatio[1]);
|
|
@@ -20228,10 +20416,10 @@ var DER = {
|
|
|
20228
20416
|
if (length < 128)
|
|
20229
20417
|
throw new E("tlv.decode(long): not minimal encoding");
|
|
20230
20418
|
}
|
|
20231
|
-
const
|
|
20232
|
-
if (
|
|
20419
|
+
const v10 = data.subarray(pos, pos + length);
|
|
20420
|
+
if (v10.length !== length)
|
|
20233
20421
|
throw new E("tlv.decode: wrong value length");
|
|
20234
|
-
return { v:
|
|
20422
|
+
return { v: v10, l: data.subarray(pos + length) };
|
|
20235
20423
|
}
|
|
20236
20424
|
},
|
|
20237
20425
|
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
@@ -20799,9 +20987,9 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
20799
20987
|
extraEntropy: false
|
|
20800
20988
|
};
|
|
20801
20989
|
const hasLargeCofactor = CURVE_ORDER * _2n4 < Fp.ORDER;
|
|
20802
|
-
function isBiggerThanHalfOrder(
|
|
20990
|
+
function isBiggerThanHalfOrder(number4) {
|
|
20803
20991
|
const HALF = CURVE_ORDER >> _1n6;
|
|
20804
|
-
return
|
|
20992
|
+
return number4 > HALF;
|
|
20805
20993
|
}
|
|
20806
20994
|
function validateRS(title, num) {
|
|
20807
20995
|
if (!Fn.isValidNot0(num))
|
|
@@ -20984,8 +21172,8 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
20984
21172
|
const R = Point.BASE.multiplyUnsafe(u1).add(P.multiplyUnsafe(u2));
|
|
20985
21173
|
if (R.is0())
|
|
20986
21174
|
return false;
|
|
20987
|
-
const
|
|
20988
|
-
return
|
|
21175
|
+
const v10 = Fn.create(R.x);
|
|
21176
|
+
return v10 === r;
|
|
20989
21177
|
} catch (e) {
|
|
20990
21178
|
return false;
|
|
20991
21179
|
}
|
|
@@ -24877,6 +25065,7 @@ function isTimeoutError(error) {
|
|
|
24877
25065
|
return error instanceof Error && /timed?\s?out|timeout/i.test(error.message);
|
|
24878
25066
|
}
|
|
24879
25067
|
var DEFAULT_GET_COINS_LIMIT = 10;
|
|
25068
|
+
var LATEST_PACKAGE_ID_TIMEOUT_MS = 1e4;
|
|
24880
25069
|
function toSuiObjectOwner(owner) {
|
|
24881
25070
|
switch (owner?.$kind) {
|
|
24882
25071
|
case "AddressOwner":
|
|
@@ -24945,16 +25134,20 @@ var SuiGrpcTransport = class {
|
|
|
24945
25134
|
return effects.gasUsed;
|
|
24946
25135
|
}
|
|
24947
25136
|
async fetchLatestPackageId(objectId) {
|
|
24948
|
-
let
|
|
25137
|
+
let object4;
|
|
24949
25138
|
try {
|
|
24950
|
-
({ object:
|
|
25139
|
+
({ object: object4 } = await this.client.core.getObject({
|
|
25140
|
+
objectId,
|
|
25141
|
+
include: { json: true },
|
|
25142
|
+
signal: AbortSignal.timeout(LATEST_PACKAGE_ID_TIMEOUT_MS)
|
|
25143
|
+
}));
|
|
24951
25144
|
} catch (error) {
|
|
24952
25145
|
throw new Error("Failed to fetch asset manager id", { cause: error });
|
|
24953
25146
|
}
|
|
24954
|
-
if (!
|
|
25147
|
+
if (!object4) {
|
|
24955
25148
|
throw new Error("Asset manager id not found (no data)");
|
|
24956
25149
|
}
|
|
24957
|
-
const fields =
|
|
25150
|
+
const fields = object4.json;
|
|
24958
25151
|
if (!fields) {
|
|
24959
25152
|
throw new Error("Asset manager id not found (not a move object)");
|
|
24960
25153
|
}
|
|
@@ -24991,7 +25184,11 @@ var SuiSpokeService = class {
|
|
|
24991
25184
|
transport;
|
|
24992
25185
|
/** @deprecated Renamed to `transport`, and no longer a raw `@mysten/sui` client. */
|
|
24993
25186
|
publicClient;
|
|
24994
|
-
|
|
25187
|
+
/**
|
|
25188
|
+
* `latest_package_id` reads still in flight, keyed by chain. An entry is dropped as soon as its
|
|
25189
|
+
* read settles, so concurrent callers share one request while a later build always re-reads.
|
|
25190
|
+
*/
|
|
25191
|
+
assetManagerLookups = /* @__PURE__ */ new Map();
|
|
24995
25192
|
pollingIntervalMs;
|
|
24996
25193
|
maxTimeoutMs;
|
|
24997
25194
|
constructor(config) {
|
|
@@ -25053,10 +25250,19 @@ var SuiSpokeService = class {
|
|
|
25053
25250
|
};
|
|
25054
25251
|
}
|
|
25055
25252
|
async getAssetManagerAddress(chainId) {
|
|
25056
|
-
|
|
25057
|
-
|
|
25058
|
-
|
|
25059
|
-
|
|
25253
|
+
const { packageId, moduleId, stateId } = await this.resolveAssetManager(chainId);
|
|
25254
|
+
return `${packageId}::${moduleId}::${stateId}`;
|
|
25255
|
+
}
|
|
25256
|
+
/**
|
|
25257
|
+
* An upgraded Sui package lives at a new address and the superseded one aborts on
|
|
25258
|
+
* `enforce_version`, so the id is read per call and never held between two builds.
|
|
25259
|
+
*/
|
|
25260
|
+
async resolveAssetManager(chainId) {
|
|
25261
|
+
const inFlight = this.assetManagerLookups.get(chainId);
|
|
25262
|
+
if (inFlight) return inFlight;
|
|
25263
|
+
const lookup = this.fetchAssetManagerAddress(chainId).then((address) => this.splitAddress(address)).finally(() => this.assetManagerLookups.delete(chainId));
|
|
25264
|
+
this.assetManagerLookups.set(chainId, lookup);
|
|
25265
|
+
return lookup;
|
|
25060
25266
|
}
|
|
25061
25267
|
async viewContract(tx, packageId, module, functionName, args, typeArgs = [], sender) {
|
|
25062
25268
|
tx.moveCall({
|
|
@@ -25073,12 +25279,27 @@ var SuiSpokeService = class {
|
|
|
25073
25279
|
* @returns {Promise<TxReturnType<SuiChainKey, R>>} A promise that resolves to the transaction hash or raw transaction base64 string.
|
|
25074
25280
|
*/
|
|
25075
25281
|
async deposit(params) {
|
|
25282
|
+
const { tx, assetManager } = await this.buildDepositTransaction(params);
|
|
25283
|
+
if (params.raw === true) {
|
|
25284
|
+
return {
|
|
25285
|
+
from: params.srcAddress,
|
|
25286
|
+
to: `${assetManager.packageId}::${assetManager.moduleId}::transfer`,
|
|
25287
|
+
value: params.amount,
|
|
25288
|
+
data: tx.serialize()
|
|
25289
|
+
};
|
|
25290
|
+
}
|
|
25291
|
+
return params.walletProvider.signAndExecuteTxn(tx);
|
|
25292
|
+
}
|
|
25293
|
+
/** Both deposit paths build here, so the asset manager is resolved the same way for each. */
|
|
25294
|
+
async buildDepositTransaction(params) {
|
|
25076
25295
|
const { srcAddress: from, srcChainKey, token, to, amount, data = "0x" } = params;
|
|
25077
25296
|
const isNative = isNativeToken(srcChainKey, token);
|
|
25078
25297
|
const tx = new transactions.Transaction();
|
|
25079
|
-
const coin = isNative ? await this.getNativeCoin(tx, amount) : await this.getCoin(tx, token, amount, from);
|
|
25080
25298
|
const connection = this.splitAddress(this.config.getChainConfig(srcChainKey).addresses.connection);
|
|
25081
|
-
const assetManager =
|
|
25299
|
+
const [coin, assetManager] = await Promise.all([
|
|
25300
|
+
isNative ? this.getNativeCoin(tx, amount) : this.getCoin(tx, token, amount, from),
|
|
25301
|
+
this.resolveAssetManager(srcChainKey)
|
|
25302
|
+
]);
|
|
25082
25303
|
tx.moveCall({
|
|
25083
25304
|
target: `${assetManager.packageId}::${assetManager.moduleId}::transfer`,
|
|
25084
25305
|
typeArguments: [token],
|
|
@@ -25091,15 +25312,7 @@ var SuiSpokeService = class {
|
|
|
25091
25312
|
tx.pure(bcs.bcs.vector(bcs.bcs.u8()).serialize(viem.fromHex(data, "bytes")))
|
|
25092
25313
|
]
|
|
25093
25314
|
});
|
|
25094
|
-
|
|
25095
|
-
return {
|
|
25096
|
-
from,
|
|
25097
|
-
to: `${assetManager.packageId}::${assetManager.moduleId}::transfer`,
|
|
25098
|
-
value: amount,
|
|
25099
|
-
data: tx.serialize()
|
|
25100
|
-
};
|
|
25101
|
-
}
|
|
25102
|
-
return params.walletProvider.signAndExecuteTxn(tx);
|
|
25315
|
+
return { tx, assetManager };
|
|
25103
25316
|
}
|
|
25104
25317
|
async sendMessage(params) {
|
|
25105
25318
|
const { srcAddress: from, srcChainKey, dstChainKey, dstAddress, payload } = params;
|
|
@@ -25139,7 +25352,7 @@ var SuiSpokeService = class {
|
|
|
25139
25352
|
* @returns {Promise<bigint>} The balance of the token.
|
|
25140
25353
|
*/
|
|
25141
25354
|
async getDeposit(params) {
|
|
25142
|
-
const assetmanager =
|
|
25355
|
+
const assetmanager = await this.resolveAssetManager(params.srcChainKey);
|
|
25143
25356
|
const tx = new transactions.Transaction();
|
|
25144
25357
|
const result = await this.viewContract(
|
|
25145
25358
|
tx,
|
|
@@ -29468,7 +29681,7 @@ function selectSolvedIntentPacket(packets, intentsContract) {
|
|
|
29468
29681
|
|
|
29469
29682
|
// src/swap/speed-tier.ts
|
|
29470
29683
|
var SPEED_TIER_SECONDS = {
|
|
29471
|
-
/** Either token
|
|
29684
|
+
/** Either token's vault is a money-market-reserve (sodaAsset). */
|
|
29472
29685
|
sodaAsset: 15,
|
|
29473
29686
|
/** Anything else / default. */
|
|
29474
29687
|
default: 35,
|
|
@@ -29486,7 +29699,7 @@ var secondsToTier = (seconds) => {
|
|
|
29486
29699
|
return "slow";
|
|
29487
29700
|
};
|
|
29488
29701
|
function estimateSwapSpeedTier({ srcToken, dstToken }, isSodaAssetRelated) {
|
|
29489
|
-
const eitherSodaAsset = isSodaAssetRelated(srcToken.
|
|
29702
|
+
const eitherSodaAsset = isSodaAssetRelated(srcToken.vault) || isSodaAssetRelated(dstToken.vault);
|
|
29490
29703
|
let estimatedSeconds = eitherSodaAsset ? SPEED_TIER_SECONDS.sodaAsset : SPEED_TIER_SECONDS.default;
|
|
29491
29704
|
if (isEthereumToken(srcToken) || isEthereumToken(dstToken)) {
|
|
29492
29705
|
estimatedSeconds += SPEED_TIER_SECONDS.ethereumPenalty;
|
|
@@ -29696,14 +29909,14 @@ var SwapService = class {
|
|
|
29696
29909
|
*/
|
|
29697
29910
|
async getDetailedStatus(params) {
|
|
29698
29911
|
try {
|
|
29699
|
-
const
|
|
29912
|
+
const record = await this.backendApi.swaps.getSubmitTxStatus({
|
|
29700
29913
|
txHash: params.srcTxHash,
|
|
29701
29914
|
srcChainKey: params.srcChainKey
|
|
29702
29915
|
});
|
|
29703
|
-
if (
|
|
29704
|
-
return { ok: true, value: { source: "backend", data:
|
|
29916
|
+
if (record.ok && record.value.success && !isBackendSubmitTxAbandoned(record.value.data)) {
|
|
29917
|
+
return { ok: true, value: { source: "backend", data: record.value.data } };
|
|
29705
29918
|
}
|
|
29706
|
-
const backendAnswered =
|
|
29919
|
+
const backendAnswered = record.ok || isSodaxError(record.error) && record.error.context?.status === 404;
|
|
29707
29920
|
const dstTxHash = await this.resolveHubTxHash(params, backendAnswered);
|
|
29708
29921
|
if (!dstTxHash.ok) return dstTxHash;
|
|
29709
29922
|
const solver = await this.resolveSolverStatus(
|
|
@@ -30527,13 +30740,13 @@ var SwapService = class {
|
|
|
30527
30740
|
getIntentRelayChainId(params.srcChainKey) === params.intent.srcChain,
|
|
30528
30741
|
`srcChainKey (${params.srcChainKey}) does not match intent.srcChain (${params.intent.srcChain}). Expected relay chain id ${getIntentRelayChainId(params.srcChainKey)}.`
|
|
30529
30742
|
);
|
|
30530
|
-
const
|
|
30743
|
+
const relayData = this.buildCancelRelayData(params.intent);
|
|
30531
30744
|
const coreParams = {
|
|
30532
30745
|
srcChainKey: params.srcChainKey,
|
|
30533
|
-
srcAddress:
|
|
30746
|
+
srcAddress: await this.resolveCancelSrcAddress(_params),
|
|
30534
30747
|
dstChainKey: HUB_CHAIN_KEY,
|
|
30535
|
-
dstAddress:
|
|
30536
|
-
payload:
|
|
30748
|
+
dstAddress: relayData.address,
|
|
30749
|
+
payload: relayData.payload,
|
|
30537
30750
|
skipSimulation: params.skipSimulation
|
|
30538
30751
|
};
|
|
30539
30752
|
const sendMessageParams = _params.raw ? {
|
|
@@ -30562,12 +30775,15 @@ var SwapService = class {
|
|
|
30562
30775
|
* 1. Calls `createCancelIntent` to broadcast the cancel transaction on the spoke chain.
|
|
30563
30776
|
* 2. Verifies the spoke transaction.
|
|
30564
30777
|
* 3. For non-hub source chains: submits to the relayer and polls until the cancel packet
|
|
30565
|
-
* is delivered to the hub.
|
|
30778
|
+
* is delivered to the hub. Solana submits the cancel payload alongside the tx (the spoke tx
|
|
30779
|
+
* only carries its hash) and Bitcoin relays its signed on-demand payload — see
|
|
30780
|
+
* {@link buildCancelRelayIdentity}. For hub source chains, the spoke tx hash is reused directly.
|
|
30566
30781
|
*
|
|
30567
30782
|
* @param _params - Cancel params including `srcChainKey`, the `intent`, wallet provider, and
|
|
30568
30783
|
* an optional `timeout` in milliseconds.
|
|
30569
30784
|
* @returns A `Result` containing `TxHashPair`:
|
|
30570
|
-
* - `srcChainTxHash` — cancel tx hash on the source spoke chain
|
|
30785
|
+
* - `srcChainTxHash` — cancel tx hash on the source spoke chain (Bitcoin: the relay's derived
|
|
30786
|
+
* `od:<hash>` id, since an on-demand cancel broadcasts no spoke tx).
|
|
30571
30787
|
* - `dstChainTxHash` — hub-chain (Sonic) tx hash confirming the cancellation.
|
|
30572
30788
|
*/
|
|
30573
30789
|
async cancelIntent(_params) {
|
|
@@ -30581,41 +30797,100 @@ var SwapService = class {
|
|
|
30581
30797
|
chainKey: params.srcChainKey
|
|
30582
30798
|
});
|
|
30583
30799
|
if (!verifyTxHashResult.ok) return verifyTxHashResult;
|
|
30584
|
-
|
|
30585
|
-
|
|
30586
|
-
const intentRelayChainId = params.intent.srcChain.toString();
|
|
30587
|
-
const submitPayload = {
|
|
30588
|
-
action: "submit",
|
|
30589
|
-
params: {
|
|
30590
|
-
chain_id: intentRelayChainId,
|
|
30591
|
-
tx_hash: cancelTxHash
|
|
30592
|
-
}
|
|
30593
|
-
};
|
|
30594
|
-
const submitResult = await this.submitIntent(submitPayload);
|
|
30595
|
-
if (!submitResult.ok) return submitResult;
|
|
30596
|
-
const packet = await waitUntilIntentExecuted({
|
|
30597
|
-
intentRelayChainId,
|
|
30598
|
-
srcTxHash: cancelTxHash,
|
|
30599
|
-
timeout: _params.timeout,
|
|
30600
|
-
apiUrl: this.relayerApiEndpoint
|
|
30601
|
-
});
|
|
30602
|
-
if (!packet.ok) return packet;
|
|
30603
|
-
dstIntentTxHash = packet.value.dst_tx_hash;
|
|
30604
|
-
} else {
|
|
30605
|
-
dstIntentTxHash = cancelTxHash;
|
|
30800
|
+
if (isHubChainKey(params.srcChainKey)) {
|
|
30801
|
+
return { ok: true, value: { srcChainTxHash: cancelTxHash, dstChainTxHash: cancelTxHash } };
|
|
30606
30802
|
}
|
|
30607
|
-
|
|
30803
|
+
const relayIdentity = this.buildCancelRelayIdentity(params.srcChainKey, cancelTxHash, params.intent);
|
|
30804
|
+
const packet = await relayTxAndWaitPacket({
|
|
30805
|
+
...relayIdentity,
|
|
30806
|
+
chainKey: params.srcChainKey,
|
|
30807
|
+
relayerApiEndpoint: this.relayerApiEndpoint,
|
|
30808
|
+
timeout: _params.timeout
|
|
30809
|
+
});
|
|
30810
|
+
if (!packet.ok) return packet;
|
|
30811
|
+
return {
|
|
30812
|
+
ok: true,
|
|
30813
|
+
value: {
|
|
30814
|
+
srcChainTxHash: relayIdentity.pollTxHash ?? cancelTxHash,
|
|
30815
|
+
dstChainTxHash: packet.value.dst_tx_hash
|
|
30816
|
+
}
|
|
30817
|
+
};
|
|
30608
30818
|
} catch (error) {
|
|
30609
30819
|
if (isSwapError(error)) return { ok: false, error };
|
|
30610
30820
|
return { ok: false, error: executionFailed("swap", error, { action: "cancelIntent" }) };
|
|
30611
30821
|
}
|
|
30612
30822
|
}
|
|
30823
|
+
/**
|
|
30824
|
+
* Source address the cancel `sendMessage` originates from.
|
|
30825
|
+
*
|
|
30826
|
+
* Every chain but Bitcoin signs from the address stored on the intent. A Bitcoin TRADING-mode intent
|
|
30827
|
+
* stores the trading address, yet the spoke layer expects the personal wallet: it re-derives the
|
|
30828
|
+
* trading wallet from it and picks the message-signing scheme from its address type. So Bitcoin
|
|
30829
|
+
* TRADING takes `params.srcAddress`, else the wallet provider's address (raw has no provider).
|
|
30830
|
+
*/
|
|
30831
|
+
async resolveCancelSrcAddress(_params) {
|
|
30832
|
+
const { params } = _params;
|
|
30833
|
+
if (params.srcAddress !== void 0) return params.srcAddress;
|
|
30834
|
+
if (isBitcoinChainKeyType(params.srcChainKey) && this.spoke.bitcoin.walletMode === "TRADING") {
|
|
30835
|
+
const walletProvider = _params.walletProvider;
|
|
30836
|
+
invariant(
|
|
30837
|
+
walletProvider !== void 0 && isBitcoinWalletProviderType(walletProvider),
|
|
30838
|
+
"Bitcoin TRADING-mode cancel needs the personal wallet address: pass params.srcAddress for raw: true"
|
|
30839
|
+
);
|
|
30840
|
+
return await walletProvider.getWalletAddress();
|
|
30841
|
+
}
|
|
30842
|
+
return reverseEncodeAddress(params.srcChainKey, params.intent.srcAddress);
|
|
30843
|
+
}
|
|
30844
|
+
/**
|
|
30845
|
+
* Relay extra data (`{ address, payload }`) for cancelling `intent`, for callers that relay a
|
|
30846
|
+
* `createCancelIntent` transaction themselves (`raw` mode or manual relay control).
|
|
30847
|
+
*
|
|
30848
|
+
* Solana commits only the hash of the cancel payload on-chain, so the relayer needs this alongside
|
|
30849
|
+
* the spoke tx; other chains ignore it. It is the cancel counterpart of {@link reconstructRelayData}:
|
|
30850
|
+
* the create-intent extra data does not match a cancel tx. Bitcoin cancels are on-demand instead —
|
|
30851
|
+
* relay the signed payload `createCancelIntent` returns via `BitcoinSpokeService.getOnDemandRelayIdentity`.
|
|
30852
|
+
*
|
|
30853
|
+
* @param intent - The intent being cancelled (e.g. from `getIntent(txHash)`).
|
|
30854
|
+
* @returns A `Result` containing `RelayExtraData`: `{ address: Hex; payload: Hex }`.
|
|
30855
|
+
*/
|
|
30856
|
+
getCancelIntentRelayData(intent) {
|
|
30857
|
+
try {
|
|
30858
|
+
invariant(this.config.isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
|
|
30859
|
+
return { ok: true, value: this.buildCancelRelayData(intent) };
|
|
30860
|
+
} catch (error) {
|
|
30861
|
+
return { ok: false, error };
|
|
30862
|
+
}
|
|
30863
|
+
}
|
|
30864
|
+
/**
|
|
30865
|
+
* Relay extra data for a cancel: the hub wallet that owns the intent and the `cancelIntent` call it
|
|
30866
|
+
* executes. This is exactly what `createCancelIntent` sends on-chain, so split-tx chains (Solana),
|
|
30867
|
+
* whose spoke tx carries only the payload hash, can hand the relayer the full payload.
|
|
30868
|
+
*/
|
|
30869
|
+
buildCancelRelayData(intent) {
|
|
30870
|
+
return {
|
|
30871
|
+
address: intent.creator,
|
|
30872
|
+
payload: encodeContractCalls([EvmSolverService.encodeCancelIntent(intent, this.solver.intentsContract)])
|
|
30873
|
+
};
|
|
30874
|
+
}
|
|
30875
|
+
/**
|
|
30876
|
+
* Relay submit/poll identity for a cancel, mirroring the money market's on-demand handling.
|
|
30877
|
+
*
|
|
30878
|
+
* A Bitcoin cancel broadcasts no spoke tx: `sendMessage` returns a signed payload JSON that the relay
|
|
30879
|
+
* accepts under the literal `withdraw` tx_hash and tracks under a derived `od:<hash>` id (see
|
|
30880
|
+
* {@link BitcoinSpokeService.getOnDemandRelayIdentity}). Every other chain relays and polls by its
|
|
30881
|
+
* spoke tx hash and passes the cancel relay data, which the relayer needs on Solana and ignores elsewhere.
|
|
30882
|
+
*/
|
|
30883
|
+
buildCancelRelayIdentity(srcChainKey, tx, intent) {
|
|
30884
|
+
return isBitcoinChainKeyType(srcChainKey) ? this.spoke.bitcoin.getOnDemandRelayIdentity(tx) : { srcTxHash: tx, data: this.buildCancelRelayData(intent), pollTxHash: void 0 };
|
|
30885
|
+
}
|
|
30613
30886
|
/**
|
|
30614
30887
|
* Returns the relay extra data (`address` + `payload`) required to submit an intent to the relayer API.
|
|
30615
30888
|
*
|
|
30616
|
-
*
|
|
30617
|
-
*
|
|
30618
|
-
* `
|
|
30889
|
+
* Only required when the source chain is Solana or Bitcoin, whose deposits commit a hash of the relay
|
|
30890
|
+
* payload on-chain, so the relayer needs the exact bytes bundled with the submission. For an intent
|
|
30891
|
+
* created by {@link SwapService.createIntent} the payload is byte-identical to the `relayData` that
|
|
30892
|
+
* call returned; see {@link SwapService.reconstructRelayData}, which this delegates to, for the
|
|
30893
|
+
* derivation and the one intent shape it cannot reconstruct.
|
|
30619
30894
|
*
|
|
30620
30895
|
* Accepts either a hub-chain tx hash (will fetch the intent on-chain first) or a
|
|
30621
30896
|
* pre-fetched `Intent` object directly.
|
|
@@ -30624,35 +30899,28 @@ var SwapService = class {
|
|
|
30624
30899
|
* @returns A `Result` containing `RelayExtraData`: `{ address: Hex; payload: Hex }`.
|
|
30625
30900
|
*/
|
|
30626
30901
|
async getIntentSubmitTxExtraData(params) {
|
|
30627
|
-
|
|
30628
|
-
|
|
30629
|
-
if (
|
|
30630
|
-
|
|
30631
|
-
if (!intentResult.ok) return intentResult;
|
|
30632
|
-
intent = intentResult.value;
|
|
30633
|
-
} else {
|
|
30634
|
-
intent = params.intent;
|
|
30635
|
-
}
|
|
30636
|
-
const txData = EvmSolverService.encodeCreateIntent(intent, this.solver.intentsContract);
|
|
30637
|
-
return {
|
|
30638
|
-
ok: true,
|
|
30639
|
-
value: {
|
|
30640
|
-
address: intent.creator,
|
|
30641
|
-
payload: txData.data
|
|
30642
|
-
}
|
|
30643
|
-
};
|
|
30644
|
-
} catch (error) {
|
|
30645
|
-
return { ok: false, error };
|
|
30902
|
+
if ("txHash" in params) {
|
|
30903
|
+
const intentResult = await this.getIntent(params.txHash);
|
|
30904
|
+
if (!intentResult.ok) return intentResult;
|
|
30905
|
+
return this.reconstructRelayData(intentResult.value);
|
|
30646
30906
|
}
|
|
30907
|
+
return this.reconstructRelayData(params.intent);
|
|
30647
30908
|
}
|
|
30648
30909
|
/**
|
|
30649
|
-
* Re-derives the byte-identical relay extra data (`{ address, payload }`) for
|
|
30650
|
-
*
|
|
30910
|
+
* Re-derives the byte-identical relay extra data (`{ address, payload }`) for an intent created by
|
|
30911
|
+
* {@link SwapService.createIntent} (or `swap` / `createLimitOrderIntent`) from a fully-populated
|
|
30912
|
+
* `Intent` alone — no on-chain call, no original `createIntent` return value needed.
|
|
30651
30913
|
*
|
|
30652
30914
|
* The `payload` matches exactly what `createIntent` relayed when the intent was first created:
|
|
30653
30915
|
* - Sonic-hub source — raw `createIntent(intent)` calldata.
|
|
30654
30916
|
* - Any spoke source — the `[approve, createIntent]` multicall (uniform across all spokes).
|
|
30655
30917
|
*
|
|
30918
|
+
* Not reconstructable: a `LeverageYieldService.vaultSwap` / `createVaultIntent` intent with
|
|
30919
|
+
* `hubWalletSwap`. Its `srcChain` is the hub while the relayed payload is the spoke multicall sent
|
|
30920
|
+
* through `sendMessage`, so it is indistinguishable here from a Sonic-source swap and would yield raw
|
|
30921
|
+
* `createIntent` calldata. Keep the `relayData` that call returned, or use
|
|
30922
|
+
* `sodax.api.leverageYield.getIntentSubmitTxExtraData`.
|
|
30923
|
+
*
|
|
30656
30924
|
* Byte-identity is possible because the only originally-random field, `intentId`, is already
|
|
30657
30925
|
* carried on the `Intent`; everything else in the payload is a pure function of the intent and
|
|
30658
30926
|
* the configured intents contract. Use this to rebuild relay submission data for a manual relay
|
|
@@ -30790,7 +31058,7 @@ var SwapService = class {
|
|
|
30790
31058
|
/**
|
|
30791
31059
|
* Offline, rule-based estimate of how fast a `srcToken`→`dstToken` swap will settle.
|
|
30792
31060
|
*
|
|
30793
|
-
* Derived purely from SDK config (no network / on-chain / backend call): tokens
|
|
31061
|
+
* Derived purely from SDK config (no network / on-chain / backend call): tokens whose vault is a
|
|
30794
31062
|
* money-market-reserve sodaAsset settle faster, and an Ethereum leg adds a fixed penalty. See
|
|
30795
31063
|
* {@link estimateSwapSpeedTier} for the rules.
|
|
30796
31064
|
*
|
|
@@ -30798,7 +31066,7 @@ var SwapService = class {
|
|
|
30798
31066
|
* @returns the estimated `tier` bucket and `estimatedSeconds`
|
|
30799
31067
|
*/
|
|
30800
31068
|
getSwapSpeedTier(params) {
|
|
30801
|
-
return estimateSwapSpeedTier(params, (
|
|
31069
|
+
return estimateSwapSpeedTier(params, (vault) => this.config.isMoneyMarketReserveAsset(vault));
|
|
30802
31070
|
}
|
|
30803
31071
|
};
|
|
30804
31072
|
|
|
@@ -33298,173 +33566,6 @@ var SponsoringApiService = class {
|
|
|
33298
33566
|
return this.config.baseURL;
|
|
33299
33567
|
}
|
|
33300
33568
|
};
|
|
33301
|
-
var RelayExtraDataResponseSchema = v__namespace.object({
|
|
33302
|
-
address: v__namespace.string(),
|
|
33303
|
-
payload: v__namespace.string()
|
|
33304
|
-
});
|
|
33305
|
-
var BridgeTokenSchema = v__namespace.object({
|
|
33306
|
-
symbol: v__namespace.string(),
|
|
33307
|
-
name: v__namespace.string(),
|
|
33308
|
-
decimals: v__namespace.number(),
|
|
33309
|
-
address: v__namespace.string(),
|
|
33310
|
-
chainKey: v__namespace.string(),
|
|
33311
|
-
hubAsset: v__namespace.string(),
|
|
33312
|
-
vault: v__namespace.string()
|
|
33313
|
-
});
|
|
33314
|
-
var BridgeTokensResponseSchema = v__namespace.record(v__namespace.string(), v__namespace.array(BridgeTokenSchema));
|
|
33315
|
-
var BridgeTokensByChainResponseSchema = v__namespace.array(BridgeTokenSchema);
|
|
33316
|
-
var BridgeAllowanceCheckResponseSchema = v__namespace.object({
|
|
33317
|
-
valid: v__namespace.boolean()
|
|
33318
|
-
});
|
|
33319
|
-
var makeBridgeApproveResponseSchema = (txSchema) => v__namespace.object({ tx: txSchema, resetTx: v__namespace.optional(txSchema) });
|
|
33320
|
-
var makeCreateBridgeIntentResponseSchema = (txSchema) => v__namespace.object({
|
|
33321
|
-
tx: txSchema,
|
|
33322
|
-
relayData: RelayExtraDataResponseSchema
|
|
33323
|
-
});
|
|
33324
|
-
var BridgeSubmitTxResponseSchema = v__namespace.object({
|
|
33325
|
-
success: v__namespace.boolean(),
|
|
33326
|
-
data: v__namespace.object({
|
|
33327
|
-
status: v__namespace.picklist(["inserted", "duplicate"]),
|
|
33328
|
-
message: v__namespace.string()
|
|
33329
|
-
})
|
|
33330
|
-
});
|
|
33331
|
-
var BridgePacketDataSchema = v__namespace.object({
|
|
33332
|
-
src_chain_id: v__namespace.number(),
|
|
33333
|
-
src_tx_hash: v__namespace.string(),
|
|
33334
|
-
src_address: v__namespace.string(),
|
|
33335
|
-
status: v__namespace.picklist(["pending", "validating", "executing", "executed"]),
|
|
33336
|
-
dst_chain_id: v__namespace.number(),
|
|
33337
|
-
conn_sn: v__namespace.number(),
|
|
33338
|
-
dst_address: v__namespace.string(),
|
|
33339
|
-
dst_tx_hash: v__namespace.string(),
|
|
33340
|
-
signatures: v__namespace.array(v__namespace.string()),
|
|
33341
|
-
payload: v__namespace.string()
|
|
33342
|
-
});
|
|
33343
|
-
var BridgeSubmitTxStatusResultSchema = v__namespace.object({
|
|
33344
|
-
dstIntentTxHash: v__namespace.string(),
|
|
33345
|
-
packetData: v__namespace.optional(BridgePacketDataSchema)
|
|
33346
|
-
});
|
|
33347
|
-
var BridgeSubmitTxStatusDataSchema = v__namespace.object({
|
|
33348
|
-
txHash: v__namespace.string(),
|
|
33349
|
-
srcChainKey: v__namespace.string(),
|
|
33350
|
-
status: v__namespace.string(),
|
|
33351
|
-
failedAtStep: v__namespace.optional(v__namespace.string()),
|
|
33352
|
-
failureReason: v__namespace.optional(v__namespace.string()),
|
|
33353
|
-
processingAttempts: v__namespace.number(),
|
|
33354
|
-
abandonedAt: v__namespace.optional(v__namespace.string()),
|
|
33355
|
-
result: v__namespace.optional(BridgeSubmitTxStatusResultSchema),
|
|
33356
|
-
userMessage: v__namespace.optional(v__namespace.string())
|
|
33357
|
-
});
|
|
33358
|
-
var BridgeSubmitTxStatusResponseSchema = v__namespace.object({
|
|
33359
|
-
success: v__namespace.boolean(),
|
|
33360
|
-
data: BridgeSubmitTxStatusDataSchema
|
|
33361
|
-
});
|
|
33362
|
-
var BridgeFeeResponseSchema = v__namespace.object({ fee: v__namespace.string() });
|
|
33363
|
-
var BridgeLimitSchema = v__namespace.object({
|
|
33364
|
-
amount: v__namespace.string(),
|
|
33365
|
-
decimals: v__namespace.number(),
|
|
33366
|
-
type: v__namespace.picklist(["DEPOSIT_LIMIT", "WITHDRAWAL_LIMIT"])
|
|
33367
|
-
});
|
|
33368
|
-
var BridgeableAmountResponseSchema = v__namespace.object({ limit: BridgeLimitSchema });
|
|
33369
|
-
var BridgeableCheckResponseSchema = v__namespace.object({ bridgeable: v__namespace.boolean() });
|
|
33370
|
-
var AddressSchema2 = v__namespace.custom((input) => typeof input === "string");
|
|
33371
|
-
var HexSchema = v__namespace.custom((input) => typeof input === "string");
|
|
33372
|
-
var BigintFromString = v__namespace.pipe(v__namespace.string(), v__namespace.toBigint());
|
|
33373
|
-
var BytesFromIndexRecord = v__namespace.pipe(
|
|
33374
|
-
v__namespace.record(v__namespace.string(), v__namespace.number()),
|
|
33375
|
-
v__namespace.transform((indexed) => Uint8Array.from(Object.values(indexed)))
|
|
33376
|
-
);
|
|
33377
|
-
var EvmRawTxSchema = v__namespace.object({
|
|
33378
|
-
from: AddressSchema2,
|
|
33379
|
-
to: AddressSchema2,
|
|
33380
|
-
value: BigintFromString,
|
|
33381
|
-
data: HexSchema
|
|
33382
|
-
});
|
|
33383
|
-
var SolanaRawTxSchema = v__namespace.object({
|
|
33384
|
-
from: v__namespace.string(),
|
|
33385
|
-
to: v__namespace.string(),
|
|
33386
|
-
value: BigintFromString,
|
|
33387
|
-
data: v__namespace.string()
|
|
33388
|
-
});
|
|
33389
|
-
var SuiRawTxSchema = v__namespace.object({
|
|
33390
|
-
from: HexSchema,
|
|
33391
|
-
to: v__namespace.string(),
|
|
33392
|
-
value: BigintFromString,
|
|
33393
|
-
data: v__namespace.string()
|
|
33394
|
-
});
|
|
33395
|
-
var StellarRawTxSchema = v__namespace.object({
|
|
33396
|
-
from: v__namespace.string(),
|
|
33397
|
-
to: v__namespace.string(),
|
|
33398
|
-
value: BigintFromString,
|
|
33399
|
-
data: v__namespace.string()
|
|
33400
|
-
});
|
|
33401
|
-
var BitcoinRawTxSchema = v__namespace.object({
|
|
33402
|
-
from: v__namespace.string(),
|
|
33403
|
-
to: v__namespace.string(),
|
|
33404
|
-
value: BigintFromString,
|
|
33405
|
-
data: v__namespace.string()
|
|
33406
|
-
});
|
|
33407
|
-
var InjectiveRawTxSchema = v__namespace.object({
|
|
33408
|
-
from: HexSchema,
|
|
33409
|
-
to: HexSchema,
|
|
33410
|
-
signedDoc: v__namespace.object({
|
|
33411
|
-
bodyBytes: BytesFromIndexRecord,
|
|
33412
|
-
authInfoBytes: BytesFromIndexRecord,
|
|
33413
|
-
chainId: v__namespace.string(),
|
|
33414
|
-
accountNumber: BigintFromString
|
|
33415
|
-
})
|
|
33416
|
-
});
|
|
33417
|
-
var NearRawTxSchema = v__namespace.object({
|
|
33418
|
-
signerId: v__namespace.string(),
|
|
33419
|
-
params: v__namespace.object({
|
|
33420
|
-
contractId: v__namespace.string(),
|
|
33421
|
-
method: v__namespace.string(),
|
|
33422
|
-
args: v__namespace.custom((input) => typeof input === "object" && input !== null),
|
|
33423
|
-
gas: v__namespace.optional(BigintFromString),
|
|
33424
|
-
deposit: v__namespace.optional(BigintFromString)
|
|
33425
|
-
})
|
|
33426
|
-
});
|
|
33427
|
-
var IconRawTxSchema = v__namespace.record(
|
|
33428
|
-
v__namespace.string(),
|
|
33429
|
-
v__namespace.union([v__namespace.string(), v__namespace.custom((input) => typeof input === "object" && input !== null)])
|
|
33430
|
-
);
|
|
33431
|
-
var StacksRawTxSchema = v__namespace.object({
|
|
33432
|
-
payload: v__namespace.string(),
|
|
33433
|
-
estimatedLength: v__namespace.optional(v__namespace.number())
|
|
33434
|
-
});
|
|
33435
|
-
var AnyRawTxSchema = v__namespace.custom((input) => typeof input === "object" && input !== null);
|
|
33436
|
-
function rawTxSchemaForChainKey(chainKey) {
|
|
33437
|
-
let chainType;
|
|
33438
|
-
try {
|
|
33439
|
-
chainType = getChainType(chainKey);
|
|
33440
|
-
} catch {
|
|
33441
|
-
chainType = void 0;
|
|
33442
|
-
}
|
|
33443
|
-
switch (chainType) {
|
|
33444
|
-
case "EVM":
|
|
33445
|
-
return EvmRawTxSchema;
|
|
33446
|
-
case "SOLANA":
|
|
33447
|
-
return SolanaRawTxSchema;
|
|
33448
|
-
case "SUI":
|
|
33449
|
-
return SuiRawTxSchema;
|
|
33450
|
-
case "STELLAR":
|
|
33451
|
-
return StellarRawTxSchema;
|
|
33452
|
-
case "INJECTIVE":
|
|
33453
|
-
return InjectiveRawTxSchema;
|
|
33454
|
-
case "ICON":
|
|
33455
|
-
return IconRawTxSchema;
|
|
33456
|
-
case "STACKS":
|
|
33457
|
-
return StacksRawTxSchema;
|
|
33458
|
-
case "NEAR":
|
|
33459
|
-
return NearRawTxSchema;
|
|
33460
|
-
case "BITCOIN":
|
|
33461
|
-
return BitcoinRawTxSchema;
|
|
33462
|
-
default:
|
|
33463
|
-
return AnyRawTxSchema;
|
|
33464
|
-
}
|
|
33465
|
-
}
|
|
33466
|
-
|
|
33467
|
-
// src/backendApi/BridgeApiService.ts
|
|
33468
33569
|
function toCreateBridgeIntentParamsV2(params, extras) {
|
|
33469
33570
|
return {
|
|
33470
33571
|
srcChainKey: params.srcChainKey,
|
|
@@ -33489,41 +33590,63 @@ var BridgeApiService = class {
|
|
|
33489
33590
|
trimsLegacyOverrides;
|
|
33490
33591
|
constructor(config, logger = consoleLogger, options = {}) {
|
|
33491
33592
|
this.config = config;
|
|
33492
|
-
this.headers =
|
|
33593
|
+
this.headers = mergeHeaders(config.headers);
|
|
33493
33594
|
this.logger = logger;
|
|
33494
33595
|
this.trimsLegacyOverrides = options.trimLegacyOverrides ?? true;
|
|
33495
33596
|
}
|
|
33496
33597
|
/**
|
|
33497
|
-
*
|
|
33498
|
-
*
|
|
33499
|
-
*
|
|
33500
|
-
*
|
|
33598
|
+
* Build a `@sodax/bridge-api` client for a single call. Maps the SDK's {@link BaseApiConfig}
|
|
33599
|
+
* (`baseURL`/`timeout`/`headers`) to the package's config (`baseUrl`/`timeout`/`headers`), layering
|
|
33600
|
+
* the optional per-call `RequestOverrideConfig` on top (override wins per field; headers merge).
|
|
33601
|
+
* `timeout` falls back to the backend-API default so a config that omits it still gets a ceiling
|
|
33602
|
+
* rather than an unbounded request. Constructed per call so `setHeaders` mutations and per-call
|
|
33603
|
+
* overrides both take effect without caching stale state.
|
|
33501
33604
|
*/
|
|
33502
|
-
|
|
33605
|
+
buildClient(overrideConfig) {
|
|
33606
|
+
const override = overrideConfig?.baseURL;
|
|
33607
|
+
const baseUrl = override ? this.trimsLegacyOverrides ? stripLegacyBackendMount(override) : override : this.config.baseURL;
|
|
33608
|
+
const timeout = overrideConfig?.timeout ?? this.config.timeout ?? DEFAULT_BACKEND_API_TIMEOUT;
|
|
33609
|
+
const headers = mergeHeaders(this.headers, apiKeyHeader(overrideConfig?.apiKey), overrideConfig?.headers);
|
|
33610
|
+
return new bridgeApi.BridgeApi({ baseUrl, headers, timeout });
|
|
33611
|
+
}
|
|
33612
|
+
/**
|
|
33613
|
+
* Run one delegated `BridgeApi` call and wrap it in `Result<T>`. A thrown `BridgeApiError`
|
|
33614
|
+
* (network/timeout/HTTP/parse/validation) becomes `{ ok: false }` with a canonical
|
|
33615
|
+
* `SodaxError<'EXTERNAL_API_ERROR'>`; the original error is kept as `cause`, and its
|
|
33616
|
+
* `code`/`status`/`issues` are projected into `context` so consumers can discriminate failure
|
|
33617
|
+
* kinds without unwrapping `cause`. Only a RESPONSE-shape validation failure is tagged
|
|
33618
|
+
* `reason: 'invalid_response_shape'` — a request-side validation error is a caller bug, not a
|
|
33619
|
+
* backend fault.
|
|
33620
|
+
*/
|
|
33621
|
+
async toResult(endpoint, call, overrideConfig) {
|
|
33503
33622
|
try {
|
|
33504
|
-
const
|
|
33505
|
-
|
|
33506
|
-
config: { baseURL: this.config.baseURL, timeout: this.config.timeout, headers: this.headers, ...config },
|
|
33507
|
-
// Normalized like a configured base URL: the override is the gateway root, so a legacy
|
|
33508
|
-
// `/be`-suffixed value must not nest `/bridge/*` under the data API's mount — unless the config
|
|
33509
|
-
// opted out of the legacy trim, in which case the per-call value is left exactly as given.
|
|
33510
|
-
overrideConfig: this.trimsLegacyOverrides ? normalizeOverrideBaseURL(overrideConfig) : overrideConfig,
|
|
33511
|
-
logger: this.logger,
|
|
33512
|
-
serviceLabel: "BridgeApiService"
|
|
33513
|
-
});
|
|
33514
|
-
const parsed = v__namespace.safeParse(schema, raw);
|
|
33515
|
-
if (!parsed.success) {
|
|
33516
|
-
return {
|
|
33517
|
-
ok: false,
|
|
33518
|
-
error: new SodaxError("EXTERNAL_API_ERROR", `Invalid response shape from bridge API for ${endpoint}`, {
|
|
33519
|
-
feature: "backend",
|
|
33520
|
-
context: { api: "bridge", endpoint, reason: "invalid_response_shape", issues: v__namespace.flatten(parsed.issues) }
|
|
33521
|
-
})
|
|
33522
|
-
};
|
|
33523
|
-
}
|
|
33524
|
-
return { ok: true, value: parsed.output };
|
|
33623
|
+
const value = await call(this.buildClient(overrideConfig));
|
|
33624
|
+
return { ok: true, value };
|
|
33525
33625
|
} catch (error) {
|
|
33526
|
-
|
|
33626
|
+
const context = { api: "bridge", endpoint };
|
|
33627
|
+
if (error instanceof bridgeApi.BridgeApiError) {
|
|
33628
|
+
context.code = error.code;
|
|
33629
|
+
if (error.code === "VALIDATION_ERROR" && error.context.issues !== void 0) {
|
|
33630
|
+
context.reason = "invalid_response_shape";
|
|
33631
|
+
const issues = error.context.issues;
|
|
33632
|
+
context.issues = issues instanceof v__namespace.ValiError ? v__namespace.flatten(issues.issues) : issues;
|
|
33633
|
+
}
|
|
33634
|
+
if (error.context.status !== void 0) context.status = error.context.status;
|
|
33635
|
+
if (isAuthStatus(error.context.status)) {
|
|
33636
|
+
this.logger.warn(
|
|
33637
|
+
`[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.`
|
|
33638
|
+
);
|
|
33639
|
+
}
|
|
33640
|
+
}
|
|
33641
|
+
this.logger.error(`[BridgeApiService] Request to ${endpoint} failed`, error);
|
|
33642
|
+
return {
|
|
33643
|
+
ok: false,
|
|
33644
|
+
error: new SodaxError(
|
|
33645
|
+
"EXTERNAL_API_ERROR",
|
|
33646
|
+
error instanceof Error ? error.message : `Request to ${endpoint} failed`,
|
|
33647
|
+
{ feature: "backend", cause: error, context }
|
|
33648
|
+
)
|
|
33649
|
+
};
|
|
33527
33650
|
}
|
|
33528
33651
|
}
|
|
33529
33652
|
// ──────────────────────────────────────────────────────────────────────
|
|
@@ -33535,7 +33658,7 @@ var BridgeApiService = class {
|
|
|
33535
33658
|
* @returns `Result<GetBridgeTokensResponseV2>` — map of chain key → token list.
|
|
33536
33659
|
*/
|
|
33537
33660
|
async getTokens(config) {
|
|
33538
|
-
return this.
|
|
33661
|
+
return this.toResult("/bridge/tokens", (c) => c.getTokens(), config);
|
|
33539
33662
|
}
|
|
33540
33663
|
/**
|
|
33541
33664
|
* Fetch supported bridge tokens for a single SpokeChainKey.
|
|
@@ -33544,12 +33667,7 @@ var BridgeApiService = class {
|
|
|
33544
33667
|
* @returns `Result<GetBridgeTokensByChainResponseV2>` — token list for the chain.
|
|
33545
33668
|
*/
|
|
33546
33669
|
async getTokensByChain(chainKey, config) {
|
|
33547
|
-
return this.
|
|
33548
|
-
`/bridge/tokens/${chainKey}`,
|
|
33549
|
-
{ method: "GET" },
|
|
33550
|
-
BridgeTokensByChainResponseSchema,
|
|
33551
|
-
config
|
|
33552
|
-
);
|
|
33670
|
+
return this.toResult(`/bridge/tokens/${chainKey}`, (c) => c.getTokensByChain(chainKey), config);
|
|
33553
33671
|
}
|
|
33554
33672
|
// ──────────────────────────────────────────────────────────────────────
|
|
33555
33673
|
// Allowance · approve · create intent
|
|
@@ -33560,12 +33678,7 @@ var BridgeApiService = class {
|
|
|
33560
33678
|
* @returns `Result<BridgeAllowanceCheckResponseV2>` — `{ valid }`.
|
|
33561
33679
|
*/
|
|
33562
33680
|
async checkAllowance(body, config) {
|
|
33563
|
-
return this.
|
|
33564
|
-
"/bridge/allowance/check",
|
|
33565
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33566
|
-
BridgeAllowanceCheckResponseSchema,
|
|
33567
|
-
config
|
|
33568
|
-
);
|
|
33681
|
+
return this.toResult("/bridge/allowance/check", (c) => c.checkAllowance(body), config);
|
|
33569
33682
|
}
|
|
33570
33683
|
/**
|
|
33571
33684
|
* Build an unsigned token-approval transaction for the source token.
|
|
@@ -33574,13 +33687,7 @@ var BridgeApiService = class {
|
|
|
33574
33687
|
* broadcast and mine `resetTx` first when it is present.
|
|
33575
33688
|
*/
|
|
33576
33689
|
async approve(body, config) {
|
|
33577
|
-
|
|
33578
|
-
return this.request(
|
|
33579
|
-
"/bridge/approve",
|
|
33580
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33581
|
-
makeBridgeApproveResponseSchema(txSchema),
|
|
33582
|
-
config
|
|
33583
|
-
);
|
|
33690
|
+
return this.toResult("/bridge/approve", (c) => c.approve(body), config);
|
|
33584
33691
|
}
|
|
33585
33692
|
/**
|
|
33586
33693
|
* Build an unsigned spoke-deposit (create-bridge-intent) transaction.
|
|
@@ -33588,13 +33695,7 @@ var BridgeApiService = class {
|
|
|
33588
33695
|
* @returns `Result<CreateBridgeIntentResponseV2>` — `{ tx, relayData }` (no intent struct).
|
|
33589
33696
|
*/
|
|
33590
33697
|
async createBridgeIntent(body, config) {
|
|
33591
|
-
|
|
33592
|
-
return this.request(
|
|
33593
|
-
"/bridge/intents",
|
|
33594
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33595
|
-
makeCreateBridgeIntentResponseSchema(txSchema),
|
|
33596
|
-
config
|
|
33597
|
-
);
|
|
33698
|
+
return this.toResult("/bridge/intents", (c) => c.createBridgeIntent(body), config);
|
|
33598
33699
|
}
|
|
33599
33700
|
// ──────────────────────────────────────────────────────────────────────
|
|
33600
33701
|
// Submit-tx state machine
|
|
@@ -33606,12 +33707,7 @@ var BridgeApiService = class {
|
|
|
33606
33707
|
* @returns `Result<BridgeSubmitTxResponseV2>` — `{ success, data: { status, message } }`.
|
|
33607
33708
|
*/
|
|
33608
33709
|
async submitTx(body, config) {
|
|
33609
|
-
return this.
|
|
33610
|
-
"/bridge/submit-tx",
|
|
33611
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33612
|
-
BridgeSubmitTxResponseSchema,
|
|
33613
|
-
config
|
|
33614
|
-
);
|
|
33710
|
+
return this.toResult("/bridge/submit-tx", (c) => c.submitTx(body), config);
|
|
33615
33711
|
}
|
|
33616
33712
|
/**
|
|
33617
33713
|
* Get the processing status of a submitted bridge transaction by `(txHash, srcChainKey)`.
|
|
@@ -33619,13 +33715,7 @@ var BridgeApiService = class {
|
|
|
33619
33715
|
* @returns `Result<BridgeSubmitTxStatusResponseV2>` — `{ success, data }` (processing state).
|
|
33620
33716
|
*/
|
|
33621
33717
|
async getSubmitTxStatus(query, config) {
|
|
33622
|
-
|
|
33623
|
-
return this.request(
|
|
33624
|
-
`/bridge/submit-tx/status?${queryParams.toString()}`,
|
|
33625
|
-
{ method: "GET" },
|
|
33626
|
-
BridgeSubmitTxStatusResponseSchema,
|
|
33627
|
-
config
|
|
33628
|
-
);
|
|
33718
|
+
return this.toResult("/bridge/submit-tx/status", (c) => c.getSubmitTxStatus(query), config);
|
|
33629
33719
|
}
|
|
33630
33720
|
// ──────────────────────────────────────────────────────────────────────
|
|
33631
33721
|
// Fee · bridgeable quote (read-only; mirror the SDK-core client-side methods)
|
|
@@ -33639,12 +33729,7 @@ var BridgeApiService = class {
|
|
|
33639
33729
|
* @returns `Result<BridgeFeeResponseV2>` — `{ fee }` (decimal string).
|
|
33640
33730
|
*/
|
|
33641
33731
|
async getFee(body, config) {
|
|
33642
|
-
return this.
|
|
33643
|
-
"/bridge/fee",
|
|
33644
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33645
|
-
BridgeFeeResponseSchema,
|
|
33646
|
-
config
|
|
33647
|
-
);
|
|
33732
|
+
return this.toResult("/bridge/fee", (c) => c.getFee(body), config);
|
|
33648
33733
|
}
|
|
33649
33734
|
/**
|
|
33650
33735
|
* Deposit capacity / withdrawal liquidity for a (from, to) token pair. Computable client-side in the
|
|
@@ -33653,12 +33738,7 @@ var BridgeApiService = class {
|
|
|
33653
33738
|
* @returns `Result<BridgeableAmountResponseV2>` — `{ limit }`.
|
|
33654
33739
|
*/
|
|
33655
33740
|
async getBridgeableAmount(body, config) {
|
|
33656
|
-
return this.
|
|
33657
|
-
"/bridge/bridgeable-amount",
|
|
33658
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33659
|
-
BridgeableAmountResponseSchema,
|
|
33660
|
-
config
|
|
33661
|
-
);
|
|
33741
|
+
return this.toResult("/bridge/bridgeable-amount", (c) => c.getBridgeableAmount(body), config);
|
|
33662
33742
|
}
|
|
33663
33743
|
/**
|
|
33664
33744
|
* Whether a (from, to) token pair is bridgeable. Computable client-side in the SDK core
|
|
@@ -33667,19 +33747,15 @@ var BridgeApiService = class {
|
|
|
33667
33747
|
* @returns `Result<BridgeableCheckResponseV2>` — `{ bridgeable }`.
|
|
33668
33748
|
*/
|
|
33669
33749
|
async isBridgeable(body, config) {
|
|
33670
|
-
return this.
|
|
33671
|
-
"/bridge/bridgeable/check",
|
|
33672
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33673
|
-
BridgeableCheckResponseSchema,
|
|
33674
|
-
config
|
|
33675
|
-
);
|
|
33750
|
+
return this.toResult("/bridge/bridgeable/check", (c) => c.isBridgeable(body), config);
|
|
33676
33751
|
}
|
|
33677
33752
|
// ──────────────────────────────────────────────────────────────────────
|
|
33678
33753
|
// Utilities (parity with SwapsApiService)
|
|
33679
33754
|
// ──────────────────────────────────────────────────────────────────────
|
|
33680
33755
|
/**
|
|
33681
33756
|
* Merge additional headers into the service's default header set. Existing
|
|
33682
|
-
* keys are overwritten; keys absent from `headers` are preserved.
|
|
33757
|
+
* keys are overwritten; keys absent from `headers` are preserved. Applied to
|
|
33758
|
+
* every subsequent call (the delegated client is rebuilt per call).
|
|
33683
33759
|
*/
|
|
33684
33760
|
setHeaders(headers) {
|
|
33685
33761
|
assignHeaders(this.headers, headers);
|
|
@@ -43703,6 +43779,24 @@ var isLeverageYieldPostExecutionError = isCodeMember(
|
|
|
43703
43779
|
var isLeverageYieldSwapError = isCodeMember(LEVERAGE_YIELD_SWAP_CODES);
|
|
43704
43780
|
var isLeverageYieldError = isCodeMember(LEVERAGE_YIELD_CODES);
|
|
43705
43781
|
|
|
43782
|
+
// src/leverageYield/positionFunding.ts
|
|
43783
|
+
function resolvePositionFundingAddress(chainKey, hubChainKey, token) {
|
|
43784
|
+
if (chainKey !== hubChainKey) return token?.address ?? "";
|
|
43785
|
+
if (token && isNativeToken(chainKey, token)) return token.address;
|
|
43786
|
+
return token?.hubAsset ?? token?.address ?? "";
|
|
43787
|
+
}
|
|
43788
|
+
|
|
43789
|
+
// src/leverageYield/positionIntent.ts
|
|
43790
|
+
async function reportPositionIntent(notifySolver, txHashes) {
|
|
43791
|
+
const result = await notifySolver({ intent_tx_hash: txHashes.dstChainTxHash }).catch((error2) => ({
|
|
43792
|
+
ok: false,
|
|
43793
|
+
error: error2
|
|
43794
|
+
}));
|
|
43795
|
+
if (result.ok) return { txHashes, notified: true };
|
|
43796
|
+
const { error } = result;
|
|
43797
|
+
return { txHashes, notified: false, notifyError: error instanceof Error ? error.message : String(error) };
|
|
43798
|
+
}
|
|
43799
|
+
|
|
43706
43800
|
// src/leverageYield/LeverageYieldService.ts
|
|
43707
43801
|
var leverageYieldVaultAbi = viem.parseAbi([
|
|
43708
43802
|
"function asset() view returns (address)",
|
|
@@ -43712,7 +43806,31 @@ var leverageYieldVaultAbi = viem.parseAbi([
|
|
|
43712
43806
|
"function borrowToken() view returns (address)",
|
|
43713
43807
|
"function targetLTV() view returns (uint256)"
|
|
43714
43808
|
]);
|
|
43809
|
+
var MAX_POSITION_FEE_BPS = 100;
|
|
43810
|
+
var leveragePositionFactoryAbi = viem.parseAbi([
|
|
43811
|
+
"function positionsOf(address owner) view returns (address[])",
|
|
43812
|
+
"function nextPositionIdFor(address owner) view returns (uint256)",
|
|
43813
|
+
"function predictPosition(address creator, address owner, uint256 positionId) view returns (address)",
|
|
43814
|
+
"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)",
|
|
43815
|
+
"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)"
|
|
43816
|
+
]);
|
|
43817
|
+
var leveragePositionAbi = viem.parseAbi([
|
|
43818
|
+
"function owner() view returns (address)",
|
|
43819
|
+
"function collateral() view returns (address)",
|
|
43820
|
+
"function borrowToken() view returns (address)",
|
|
43821
|
+
"function eModeCategory() view returns (uint8)",
|
|
43822
|
+
"function feeBps() view returns (uint16)",
|
|
43823
|
+
"function feeReceiver() view returns (address)",
|
|
43824
|
+
"function hasPendingOperation() view returns (bool)",
|
|
43825
|
+
"function pendingKind() view returns (uint8)",
|
|
43826
|
+
"function addLeverage(uint256 borrowAmount, uint256 minCollateralOut)",
|
|
43827
|
+
"function decreaseLeverage(uint256 collateralIn, uint256 minDebtOut, address exitAsset)",
|
|
43828
|
+
"function withdraw(uint256 amount, address to)",
|
|
43829
|
+
"function cancel()",
|
|
43830
|
+
"function settle()"
|
|
43831
|
+
]);
|
|
43715
43832
|
var INTENT_DEADLINE_BUFFER_SECONDS = 5 * 60;
|
|
43833
|
+
var BITCOIN_UNSUPPORTED_MESSAGE = "Bitcoin is not a supported source chain for leverage positions; use a supported spoke or the hub";
|
|
43716
43834
|
var ANY_SOLVER_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
43717
43835
|
var MAX_WITHDRAW_DUST_BUFFER = 1000n;
|
|
43718
43836
|
function pctToRay(aprPct) {
|
|
@@ -43769,7 +43887,7 @@ var LeverageYieldService = class {
|
|
|
43769
43887
|
}
|
|
43770
43888
|
/** Looks up a vault by its `name` field. Returns `undefined` when not registered. */
|
|
43771
43889
|
getVault(name) {
|
|
43772
|
-
return this.listVaults().find((
|
|
43890
|
+
return this.listVaults().find((v10) => v10.name === name);
|
|
43773
43891
|
}
|
|
43774
43892
|
/**
|
|
43775
43893
|
* Looks up a registered vault by its on-chain proxy address (case-insensitive).
|
|
@@ -43777,7 +43895,7 @@ var LeverageYieldService = class {
|
|
|
43777
43895
|
*/
|
|
43778
43896
|
getVaultByAddress(address) {
|
|
43779
43897
|
const normalized = address.toLowerCase();
|
|
43780
|
-
return this.listVaults().find((
|
|
43898
|
+
return this.listVaults().find((v10) => v10.vault.toLowerCase() === normalized);
|
|
43781
43899
|
}
|
|
43782
43900
|
/**
|
|
43783
43901
|
* Resolves the intent `deadline`: returns the caller-supplied value verbatim, otherwise
|
|
@@ -44366,7 +44484,12 @@ var LeverageYieldService = class {
|
|
|
44366
44484
|
}
|
|
44367
44485
|
}
|
|
44368
44486
|
/**
|
|
44369
|
-
* Notifies the solver that
|
|
44487
|
+
* Notifies the solver that an intent landed on the hub, triggering it to fill.
|
|
44488
|
+
*
|
|
44489
|
+
* REQUIRED for anything that creates an intent, not an optimisation. An intent created on the hub
|
|
44490
|
+
* is invisible to the solver until this call puts it in the task pool, so an unnotified intent
|
|
44491
|
+
* simply expires. Leverage positions post their intents on-chain from the position contract, so
|
|
44492
|
+
* the caller that sent the transaction is the only one who can report the hash.
|
|
44370
44493
|
* Leverage-yield copy of the swap domain's `postExecution` — emits only
|
|
44371
44494
|
* `EXECUTION_FAILED` / `EXTERNAL_API_ERROR` / `UNKNOWN` (relay/verify codes appear only
|
|
44372
44495
|
* on {@link LeverageYieldService.vaultSwap}, which owns the verify + relay steps).
|
|
@@ -44411,6 +44534,51 @@ var LeverageYieldService = class {
|
|
|
44411
44534
|
return { ok: false, error: executionFailed("leverageYield", error, { phase: "postExecution" }) };
|
|
44412
44535
|
}
|
|
44413
44536
|
}
|
|
44537
|
+
/**
|
|
44538
|
+
* Polls the solver for the execution status of an intent this service created.
|
|
44539
|
+
*
|
|
44540
|
+
* Pair with {@link LeverageYieldService.notifySolver}: `notifySolver` puts the intent in the
|
|
44541
|
+
* solver's task pool, this reports what became of it. `fill_tx_hash` is set only once
|
|
44542
|
+
* `status === SolverIntentStatusCode.SOLVED`.
|
|
44543
|
+
*
|
|
44544
|
+
* A `NOT_FOUND` status usually means the notification never landed rather than that the intent
|
|
44545
|
+
* does not exist — an intent created on the hub is invisible to the solver until it is told.
|
|
44546
|
+
*
|
|
44547
|
+
* @param request - `{ intent_tx_hash }` — the hub-chain (Sonic) tx hash the intent was
|
|
44548
|
+
* registered in. For a position that is the tx that called the factory or the position.
|
|
44549
|
+
*/
|
|
44550
|
+
async getIntentStatus(request) {
|
|
44551
|
+
try {
|
|
44552
|
+
const result = await SolverApiService.getStatus(
|
|
44553
|
+
request,
|
|
44554
|
+
this.config.solver,
|
|
44555
|
+
this.config.logger,
|
|
44556
|
+
void 0,
|
|
44557
|
+
this.config.apiKey
|
|
44558
|
+
);
|
|
44559
|
+
if (result.ok) return result;
|
|
44560
|
+
const detail = result.error?.detail ?? {
|
|
44561
|
+
code: -999,
|
|
44562
|
+
// SolverIntentErrorCode.UNKNOWN
|
|
44563
|
+
message: "Solver returned malformed error response"
|
|
44564
|
+
};
|
|
44565
|
+
return {
|
|
44566
|
+
ok: false,
|
|
44567
|
+
error: new SodaxError("EXTERNAL_API_ERROR", detail.message, {
|
|
44568
|
+
feature: "leverageYield",
|
|
44569
|
+
context: {
|
|
44570
|
+
phase: "lookup",
|
|
44571
|
+
api: "solver",
|
|
44572
|
+
solverCode: detail.code,
|
|
44573
|
+
solverDetail: detail
|
|
44574
|
+
}
|
|
44575
|
+
})
|
|
44576
|
+
};
|
|
44577
|
+
} catch (error) {
|
|
44578
|
+
if (isLeverageYieldPostExecutionError(error)) return { ok: false, error };
|
|
44579
|
+
return { ok: false, error: executionFailed("leverageYield", error, { phase: "lookup" }) };
|
|
44580
|
+
}
|
|
44581
|
+
}
|
|
44414
44582
|
/**
|
|
44415
44583
|
* Approves the vault's underlying asset to the leverage vault on Sonic. For callers
|
|
44416
44584
|
* interacting with the vault directly on the hub — the swap-style {@link
|
|
@@ -44719,6 +44887,1252 @@ var LeverageYieldService = class {
|
|
|
44719
44887
|
return { ok: false, error: lookupFailed("leverageYield", "getShareBalanceForUser", error, { srcChainKey }) };
|
|
44720
44888
|
}
|
|
44721
44889
|
}
|
|
44890
|
+
// ─── Leverage positions ────────────────────────────────────────────────
|
|
44891
|
+
/**
|
|
44892
|
+
* Resolves the `LeveragePositionFactory` address, or a validation error when it is missing.
|
|
44893
|
+
*
|
|
44894
|
+
* The deployed factory ships in `leverageYieldConfig`, so this only fails when an integrator
|
|
44895
|
+
* overrides it with an empty value — which is what a bad env var produces. Failing closed there is
|
|
44896
|
+
* deliberate: a placeholder address would post real intents at nothing.
|
|
44897
|
+
*/
|
|
44898
|
+
requireFactory(action) {
|
|
44899
|
+
const factory = this.config.sodaxConfig.leverageYield.positionFactory;
|
|
44900
|
+
if (!factory) {
|
|
44901
|
+
return {
|
|
44902
|
+
ok: false,
|
|
44903
|
+
error: lookupFailed(
|
|
44904
|
+
"leverageYield",
|
|
44905
|
+
action,
|
|
44906
|
+
new Error("leverageYield.positionFactory is not configured; supply the deployed factory address")
|
|
44907
|
+
)
|
|
44908
|
+
};
|
|
44909
|
+
}
|
|
44910
|
+
return { ok: true, value: factory };
|
|
44911
|
+
}
|
|
44912
|
+
/** Position clones owned by `owner`, in creation order. Empty when the owner has none. */
|
|
44913
|
+
async listPositions(owner) {
|
|
44914
|
+
const factory = this.requireFactory("listPositions");
|
|
44915
|
+
if (!factory.ok) return factory;
|
|
44916
|
+
try {
|
|
44917
|
+
const value = await this.hubProvider.publicClient.readContract({
|
|
44918
|
+
address: factory.value,
|
|
44919
|
+
abi: leveragePositionFactoryAbi,
|
|
44920
|
+
functionName: "positionsOf",
|
|
44921
|
+
args: [owner]
|
|
44922
|
+
});
|
|
44923
|
+
return { ok: true, value };
|
|
44924
|
+
} catch (error) {
|
|
44925
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
44926
|
+
return { ok: false, error: lookupFailed("leverageYield", "listPositions", error) };
|
|
44927
|
+
}
|
|
44928
|
+
}
|
|
44929
|
+
/**
|
|
44930
|
+
* Positions belonging to a user, resolved by their spoke-side address rather than a hub address.
|
|
44931
|
+
*
|
|
44932
|
+
* Positions are owned by the user's hub wallet, so discovery goes through
|
|
44933
|
+
* `getUserHubWalletAddress` — which returns the wallet router for a Sonic user and the
|
|
44934
|
+
* cross-chain wallet for a spoke user, so the same call works on every chain. Prefer this over
|
|
44935
|
+
* `listPositions` in user-facing code; passing a raw EOA finds nothing.
|
|
44936
|
+
*/
|
|
44937
|
+
async listPositionsForUser(srcChainKey, srcAddress) {
|
|
44938
|
+
try {
|
|
44939
|
+
const hubWallet = await this.hubProvider.getUserHubWalletAddress(srcAddress, srcChainKey);
|
|
44940
|
+
return await this.listPositions(hubWallet);
|
|
44941
|
+
} catch (error) {
|
|
44942
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
44943
|
+
return { ok: false, error: lookupFailed("leverageYield", "listPositionsForUser", error, { srcChainKey }) };
|
|
44944
|
+
}
|
|
44945
|
+
}
|
|
44946
|
+
/** Static descriptor of a position — owner, both legs, and the fixed eMode category. */
|
|
44947
|
+
async getPositionInfo(position) {
|
|
44948
|
+
try {
|
|
44949
|
+
const [owner, collateral, borrowToken, eModeCategory, feeBps, feeReceiver] = await Promise.all([
|
|
44950
|
+
this.hubProvider.publicClient.readContract({
|
|
44951
|
+
address: position,
|
|
44952
|
+
abi: leveragePositionAbi,
|
|
44953
|
+
functionName: "owner"
|
|
44954
|
+
}),
|
|
44955
|
+
this.hubProvider.publicClient.readContract({
|
|
44956
|
+
address: position,
|
|
44957
|
+
abi: leveragePositionAbi,
|
|
44958
|
+
functionName: "collateral"
|
|
44959
|
+
}),
|
|
44960
|
+
this.hubProvider.publicClient.readContract({
|
|
44961
|
+
address: position,
|
|
44962
|
+
abi: leveragePositionAbi,
|
|
44963
|
+
functionName: "borrowToken"
|
|
44964
|
+
}),
|
|
44965
|
+
this.hubProvider.publicClient.readContract({
|
|
44966
|
+
address: position,
|
|
44967
|
+
abi: leveragePositionAbi,
|
|
44968
|
+
functionName: "eModeCategory"
|
|
44969
|
+
}),
|
|
44970
|
+
this.hubProvider.publicClient.readContract({
|
|
44971
|
+
address: position,
|
|
44972
|
+
abi: leveragePositionAbi,
|
|
44973
|
+
functionName: "feeBps"
|
|
44974
|
+
}),
|
|
44975
|
+
this.hubProvider.publicClient.readContract({
|
|
44976
|
+
address: position,
|
|
44977
|
+
abi: leveragePositionAbi,
|
|
44978
|
+
functionName: "feeReceiver"
|
|
44979
|
+
})
|
|
44980
|
+
]);
|
|
44981
|
+
return {
|
|
44982
|
+
ok: true,
|
|
44983
|
+
value: {
|
|
44984
|
+
address: position,
|
|
44985
|
+
owner,
|
|
44986
|
+
collateral,
|
|
44987
|
+
borrowToken,
|
|
44988
|
+
eModeCategory,
|
|
44989
|
+
// From the position, not from config: config can change and an open can override it, so
|
|
44990
|
+
// what a NEW position would carry is not what THIS one does.
|
|
44991
|
+
feeBps: Number(feeBps),
|
|
44992
|
+
feeReceiver
|
|
44993
|
+
}
|
|
44994
|
+
};
|
|
44995
|
+
} catch (error) {
|
|
44996
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
44997
|
+
return { ok: false, error: lookupFailed("leverageYield", "getPositionInfo", error) };
|
|
44998
|
+
}
|
|
44999
|
+
}
|
|
45000
|
+
/**
|
|
45001
|
+
* Live AAVE account snapshot for a position. Read from the pool, not the position: the
|
|
45002
|
+
* position contract keeps no accounting of its own, so collateral, debt and health factor
|
|
45003
|
+
* all come from `getUserAccountData`.
|
|
45004
|
+
*
|
|
45005
|
+
* The pool comes from `moneyMarket.lendingPool` config rather than the position's own
|
|
45006
|
+
* `pool()` getter — same address, one fewer round trip, and it keeps the deployment address
|
|
45007
|
+
* sourced from config like the rest of the SDK.
|
|
45008
|
+
*/
|
|
45009
|
+
async getPositionAccount(position) {
|
|
45010
|
+
try {
|
|
45011
|
+
const [totalCollateralBase, totalDebtBase, availableBorrowsBase, currentLiquidationThreshold, ltv, healthFactor] = await this.hubProvider.publicClient.readContract({
|
|
45012
|
+
address: this.config.sodaxConfig.moneyMarket.lendingPool,
|
|
45013
|
+
abi: poolAbi,
|
|
45014
|
+
functionName: "getUserAccountData",
|
|
45015
|
+
args: [position]
|
|
45016
|
+
});
|
|
45017
|
+
return {
|
|
45018
|
+
ok: true,
|
|
45019
|
+
value: {
|
|
45020
|
+
totalCollateralBase,
|
|
45021
|
+
totalDebtBase,
|
|
45022
|
+
availableBorrowsBase,
|
|
45023
|
+
currentLiquidationThreshold,
|
|
45024
|
+
ltv,
|
|
45025
|
+
healthFactor
|
|
45026
|
+
}
|
|
45027
|
+
};
|
|
45028
|
+
} catch (error) {
|
|
45029
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45030
|
+
return { ok: false, error: lookupFailed("leverageYield", "getPositionAccount", error) };
|
|
45031
|
+
}
|
|
45032
|
+
}
|
|
45033
|
+
/**
|
|
45034
|
+
* The position's collateral holding, as an exact aToken balance.
|
|
45035
|
+
*
|
|
45036
|
+
* Needed to size a full exit. {@link LeverageYieldService.getPositionAccount} reports collateral
|
|
45037
|
+
* in the oracle's base currency at 8 decimals, which is fine to display but cannot name an amount:
|
|
45038
|
+
* dividing it back out by a price lands near the balance, and a `decreaseLeverage` asking for more
|
|
45039
|
+
* collateral than the position holds does not fail on submission — the hook's `transferFrom`
|
|
45040
|
+
* reverts at fill time, so the intent silently expires instead.
|
|
45041
|
+
*
|
|
45042
|
+
* Safe to act on a slightly stale read: aToken balances only grow, since interest accrues into
|
|
45043
|
+
* them, so a value from a few blocks ago is always still spendable. Selling it leaves interest
|
|
45044
|
+
* dust behind rather than coming up short.
|
|
45045
|
+
*
|
|
45046
|
+
* @param collateral The position's collateral reserve. Read from the position when omitted; pass
|
|
45047
|
+
* it if you already hold a {@link LeveragePosition} to save the round trip.
|
|
45048
|
+
*/
|
|
45049
|
+
async getPositionCollateralBalance(position, collateral) {
|
|
45050
|
+
try {
|
|
45051
|
+
const asset = collateral ?? await this.hubProvider.publicClient.readContract({
|
|
45052
|
+
address: position,
|
|
45053
|
+
abi: leveragePositionAbi,
|
|
45054
|
+
functionName: "collateral"
|
|
45055
|
+
});
|
|
45056
|
+
const reserve = await this.hubProvider.publicClient.readContract({
|
|
45057
|
+
address: this.config.sodaxConfig.moneyMarket.lendingPool,
|
|
45058
|
+
abi: poolAbi,
|
|
45059
|
+
functionName: "getReserveData",
|
|
45060
|
+
args: [asset]
|
|
45061
|
+
});
|
|
45062
|
+
const aToken = reserve.aTokenAddress;
|
|
45063
|
+
const balance = await this.hubProvider.publicClient.readContract({
|
|
45064
|
+
address: aToken,
|
|
45065
|
+
abi: viem.erc20Abi,
|
|
45066
|
+
functionName: "balanceOf",
|
|
45067
|
+
args: [position]
|
|
45068
|
+
});
|
|
45069
|
+
return { ok: true, value: { aToken, balance } };
|
|
45070
|
+
} catch (error) {
|
|
45071
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45072
|
+
return { ok: false, error: lookupFailed("leverageYield", "getPositionCollateralBalance", error) };
|
|
45073
|
+
}
|
|
45074
|
+
}
|
|
45075
|
+
/**
|
|
45076
|
+
* The position's operation slot: which operation it recorded, and whether that intent is still
|
|
45077
|
+
* live on `Intents`.
|
|
45078
|
+
*
|
|
45079
|
+
* Both are needed, because the interesting state is when they disagree. `isLive` false with a
|
|
45080
|
+
* non-zero `kind` means the intent resolved — filled, expired, or cancelled by someone else — but
|
|
45081
|
+
* the position has not been told, so its grant is still open and any debt-side contribution is
|
|
45082
|
+
* still sitting there. That is what `needsSettle` flags, and `buildSettlePosition` clears. A live
|
|
45083
|
+
* intent instead blocks any second operation until it resolves.
|
|
45084
|
+
*/
|
|
45085
|
+
async getPositionPendingState(position) {
|
|
45086
|
+
try {
|
|
45087
|
+
const [isLive, kind] = await Promise.all([
|
|
45088
|
+
this.hubProvider.publicClient.readContract({
|
|
45089
|
+
address: position,
|
|
45090
|
+
abi: leveragePositionAbi,
|
|
45091
|
+
functionName: "hasPendingOperation"
|
|
45092
|
+
}),
|
|
45093
|
+
this.hubProvider.publicClient.readContract({
|
|
45094
|
+
address: position,
|
|
45095
|
+
abi: leveragePositionAbi,
|
|
45096
|
+
functionName: "pendingKind"
|
|
45097
|
+
})
|
|
45098
|
+
]);
|
|
45099
|
+
return { ok: true, value: { kind, isLive, needsSettle: kind !== 0 && !isLive } };
|
|
45100
|
+
} catch (error) {
|
|
45101
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45102
|
+
return { ok: false, error: lookupFailed("leverageYield", "getPositionPendingState", error) };
|
|
45103
|
+
}
|
|
45104
|
+
}
|
|
45105
|
+
/** Deterministic clone address for the next position a given creator opens for `owner`. */
|
|
45106
|
+
async predictPosition(creator, owner, positionId) {
|
|
45107
|
+
const factory = this.requireFactory("predictPosition");
|
|
45108
|
+
if (!factory.ok) return factory;
|
|
45109
|
+
try {
|
|
45110
|
+
const id = positionId ?? await this.hubProvider.publicClient.readContract({
|
|
45111
|
+
address: factory.value,
|
|
45112
|
+
abi: leveragePositionFactoryAbi,
|
|
45113
|
+
functionName: "nextPositionIdFor",
|
|
45114
|
+
args: [owner]
|
|
45115
|
+
});
|
|
45116
|
+
const value = await this.hubProvider.publicClient.readContract({
|
|
45117
|
+
address: factory.value,
|
|
45118
|
+
abi: leveragePositionFactoryAbi,
|
|
45119
|
+
functionName: "predictPosition",
|
|
45120
|
+
args: [creator, owner, id]
|
|
45121
|
+
});
|
|
45122
|
+
return { ok: true, value };
|
|
45123
|
+
} catch (error) {
|
|
45124
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45125
|
+
return { ok: false, error: lookupFailed("leverageYield", "predictPosition", error) };
|
|
45126
|
+
}
|
|
45127
|
+
}
|
|
45128
|
+
// ─── Position transaction builders ─────────────────────────────────────
|
|
45129
|
+
//
|
|
45130
|
+
// Positions are driven by direct Sonic calls, not intents, so these return raw transactions
|
|
45131
|
+
// for the caller to sign with a hub wallet provider. The leverage and deleverage calls only
|
|
45132
|
+
// *post* an intent — a solver fills it afterwards, so poll `getPositionPendingState`
|
|
45133
|
+
// rather than treating the receipt as completion.
|
|
45134
|
+
/**
|
|
45135
|
+
* Opens a new position and requests leverage on it in the same transaction — the standard way
|
|
45136
|
+
* to open a leveraged position: one approve, then this.
|
|
45137
|
+
*
|
|
45138
|
+
* `initialAssets` of `collateral` is pulled from the signer, so the factory needs an allowance
|
|
45139
|
+
* first. Control is assigned to `owner`, which may differ from the signer — pass a user's hub
|
|
45140
|
+
* wallet address to have the existing cross-chain path drive the position.
|
|
45141
|
+
*
|
|
45142
|
+
* The leverage is still asynchronous: this posts the intent and a solver fills it afterwards,
|
|
45143
|
+
* so on confirmation the position is funded with the request outstanding, not yet levered. If
|
|
45144
|
+
* no solver fills it, `buildCancelPositionOperation` returns the deposit to the owner.
|
|
45145
|
+
*/
|
|
45146
|
+
/**
|
|
45147
|
+
* Turns a {@link PositionOrigin} into the tuple the factory takes, and refuses the combinations the
|
|
45148
|
+
* contract would refuse anyway — better a rejected build than a transaction that reverts.
|
|
45149
|
+
*/
|
|
45150
|
+
resolveOrigin(origin, method) {
|
|
45151
|
+
const chainId = getIntentRelayChainId(origin.chainKey);
|
|
45152
|
+
if (chainId === void 0) {
|
|
45153
|
+
return {
|
|
45154
|
+
ok: false,
|
|
45155
|
+
error: lookupFailed(
|
|
45156
|
+
"leverageYield",
|
|
45157
|
+
method,
|
|
45158
|
+
new Error(`no relay chain id for origin chain ${origin.chainKey}`)
|
|
45159
|
+
)
|
|
45160
|
+
};
|
|
45161
|
+
}
|
|
45162
|
+
const isHub = origin.chainKey === this.hubProvider.chainConfig.chain.key;
|
|
45163
|
+
if (!isHub && !origin.asset) {
|
|
45164
|
+
return {
|
|
45165
|
+
ok: false,
|
|
45166
|
+
error: lookupFailed(
|
|
45167
|
+
"leverageYield",
|
|
45168
|
+
method,
|
|
45169
|
+
new Error(`origin.asset is required for a refund to ${origin.chainKey}`)
|
|
45170
|
+
)
|
|
45171
|
+
};
|
|
45172
|
+
}
|
|
45173
|
+
return {
|
|
45174
|
+
ok: true,
|
|
45175
|
+
value: {
|
|
45176
|
+
chainId,
|
|
45177
|
+
// The chain's own encoding, not a 0x-prefixed string. `originAddress` is `bytes` on-chain and
|
|
45178
|
+
// is handed to the AssetManager as the refund destination, so a Solana or Stellar address has
|
|
45179
|
+
// to arrive in the form that chain's spoke expects — prefixing `0x` would produce a refund
|
|
45180
|
+
// address that is merely well-formed hex. EVM addresses pass through unchanged.
|
|
45181
|
+
address: encodeAddress(origin.chainKey, origin.address),
|
|
45182
|
+
// Named on the hub as well, not just off it. The asset decides what a cancellation pays back,
|
|
45183
|
+
// and zeroing it here is why someone who funded with USSD was refunded `sodaUSSD`. Callers pass
|
|
45184
|
+
// the asset only when a wrap actually happened — when the reserve IS what was deposited there is
|
|
45185
|
+
// nothing to unwrap and `address(0)` is the correct answer.
|
|
45186
|
+
asset: origin.asset ?? viem.zeroAddress
|
|
45187
|
+
}
|
|
45188
|
+
};
|
|
45189
|
+
}
|
|
45190
|
+
/**
|
|
45191
|
+
* Partner fee for a position, in the shape `PositionConfig` takes.
|
|
45192
|
+
*
|
|
45193
|
+
* Only the PERCENTAGE variant of `PartnerFee` maps: the contract stores basis points and derives
|
|
45194
|
+
* the amount per operation (`_feeFor`), so a fixed-amount fee has nowhere to go and is rejected
|
|
45195
|
+
* rather than silently dropped. Same precedence as the vault flows — per-call, then
|
|
45196
|
+
* `leverageYield.partnerFee`, then none.
|
|
45197
|
+
*
|
|
45198
|
+
* The fee is FIXED AT CREATION on-chain, so this is read when a position is created and never
|
|
45199
|
+
* again; changing the config later does not re-price positions already open.
|
|
45200
|
+
*/
|
|
45201
|
+
/**
|
|
45202
|
+
* The fee a position created NOW would carry, in basis points, plus who receives it.
|
|
45203
|
+
*
|
|
45204
|
+
* Public because a caller cannot project a position correctly without it and cannot derive it:
|
|
45205
|
+
* the fee resolves from `leverageYield.partnerFee`, then the global fee, then none, and it is
|
|
45206
|
+
* FIXED AT CREATION on-chain. Feed `feeBps` to {@link projectLeverageLeg} — the hooks require
|
|
45207
|
+
* `inputAmount + fee`, so a leverage-up borrows the fee ON TOP of what the solver is paid. Leaving
|
|
45208
|
+
* it out understates LTV and overstates the ceiling, which is the Aave `'36'` failure at fill time
|
|
45209
|
+
* this module exists to prevent: 50 bp takes a debt-side ceiling from 9.88x to about 9.44x.
|
|
45210
|
+
*
|
|
45211
|
+
* Pass the same `override` here as to the open call, or omit it on both.
|
|
45212
|
+
*/
|
|
45213
|
+
getEffectivePositionFee(override) {
|
|
45214
|
+
return this.resolvePositionFee(override, "getEffectivePositionFee");
|
|
45215
|
+
}
|
|
45216
|
+
resolvePositionFee(override, method) {
|
|
45217
|
+
const fee = override ?? this.config.leverageYieldPartnerFee;
|
|
45218
|
+
if (!fee) return { ok: true, value: { feeReceiver: viem.zeroAddress, feeBps: 0 } };
|
|
45219
|
+
if (!isPartnerFeePercentage(fee)) {
|
|
45220
|
+
return {
|
|
45221
|
+
ok: false,
|
|
45222
|
+
error: lookupFailed(
|
|
45223
|
+
"leverageYield",
|
|
45224
|
+
method,
|
|
45225
|
+
new Error("a position partner fee must be the percentage variant; PositionConfig stores basis points")
|
|
45226
|
+
)
|
|
45227
|
+
};
|
|
45228
|
+
}
|
|
45229
|
+
if (!Number.isInteger(fee.percentage) || fee.percentage < 0 || fee.percentage > MAX_POSITION_FEE_BPS) {
|
|
45230
|
+
return {
|
|
45231
|
+
ok: false,
|
|
45232
|
+
error: lookupFailed(
|
|
45233
|
+
"leverageYield",
|
|
45234
|
+
method,
|
|
45235
|
+
new Error(
|
|
45236
|
+
`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})`
|
|
45237
|
+
)
|
|
45238
|
+
)
|
|
45239
|
+
};
|
|
45240
|
+
}
|
|
45241
|
+
if (fee.percentage === 0 !== viem.isAddressEqual(fee.address, viem.zeroAddress)) {
|
|
45242
|
+
return {
|
|
45243
|
+
ok: false,
|
|
45244
|
+
error: lookupFailed(
|
|
45245
|
+
"leverageYield",
|
|
45246
|
+
method,
|
|
45247
|
+
new Error(
|
|
45248
|
+
`a position partner fee needs a rate and a receiver together, or neither (got ${fee.percentage} bps for ${fee.address})`
|
|
45249
|
+
)
|
|
45250
|
+
)
|
|
45251
|
+
};
|
|
45252
|
+
}
|
|
45253
|
+
return { ok: true, value: { feeReceiver: fee.address, feeBps: fee.percentage } };
|
|
45254
|
+
}
|
|
45255
|
+
/** A hub transaction. Every builder below produces this shape and none of them sends value. */
|
|
45256
|
+
// Generic so a builder's declared return type applies its own brand. The cast is the single one
|
|
45257
|
+
// the pattern needs — a brand is type-only and erased at runtime — and keeping it here means no
|
|
45258
|
+
// builder carries one of its own.
|
|
45259
|
+
hubTx(from, to, data) {
|
|
45260
|
+
return { from, to, value: 0n, data };
|
|
45261
|
+
}
|
|
45262
|
+
/**
|
|
45263
|
+
* The `PositionConfig` struct both factory entry points take, assembled from a resolved origin.
|
|
45264
|
+
*
|
|
45265
|
+
* Shared so the two create paths cannot drift: which side the funded reserve goes on is their only
|
|
45266
|
+
* real difference, and a field silently spelled differently in one of them would be a
|
|
45267
|
+
* mis-recorded refund destination rather than a compile error.
|
|
45268
|
+
*/
|
|
45269
|
+
positionConfig(args) {
|
|
45270
|
+
return {
|
|
45271
|
+
owner: args.owner,
|
|
45272
|
+
collateral: args.collateral,
|
|
45273
|
+
borrowToken: args.borrowToken,
|
|
45274
|
+
eModeCategory: args.eModeCategory,
|
|
45275
|
+
originChainId: args.origin.chainId,
|
|
45276
|
+
originAddress: args.origin.address,
|
|
45277
|
+
originAsset: args.origin.asset,
|
|
45278
|
+
feeReceiver: args.fee?.feeReceiver ?? viem.zeroAddress,
|
|
45279
|
+
feeBps: args.fee?.feeBps ?? 0
|
|
45280
|
+
};
|
|
45281
|
+
}
|
|
45282
|
+
buildCreatePositionAndLeverage(params) {
|
|
45283
|
+
const method = "buildCreatePositionAndLeverage";
|
|
45284
|
+
const factory = this.requireFactory(method);
|
|
45285
|
+
if (!factory.ok) return factory;
|
|
45286
|
+
const fee = this.resolvePositionFee(params.partnerFee, method);
|
|
45287
|
+
if (!fee.ok) return fee;
|
|
45288
|
+
const origin = this.resolveOrigin(params.origin, method);
|
|
45289
|
+
if (!origin.ok) return origin;
|
|
45290
|
+
return {
|
|
45291
|
+
ok: true,
|
|
45292
|
+
value: this.hubTx(
|
|
45293
|
+
params.from,
|
|
45294
|
+
factory.value,
|
|
45295
|
+
viem.encodeFunctionData({
|
|
45296
|
+
abi: leveragePositionFactoryAbi,
|
|
45297
|
+
functionName: "createPositionAndLeverage",
|
|
45298
|
+
args: [
|
|
45299
|
+
this.positionConfig({ ...params, origin: origin.value, fee: fee.value }),
|
|
45300
|
+
params.initialAssets,
|
|
45301
|
+
params.borrowAmount,
|
|
45302
|
+
params.minCollateralOut
|
|
45303
|
+
]
|
|
45304
|
+
})
|
|
45305
|
+
)
|
|
45306
|
+
};
|
|
45307
|
+
}
|
|
45308
|
+
/**
|
|
45309
|
+
* Opens a levered position starting from the **debt** token, with no collateral of your own.
|
|
45310
|
+
*
|
|
45311
|
+
* Pulls `contribution` of `borrowToken` from the signer — not the collateral. On fill the hook
|
|
45312
|
+
* supplies the solver's collateral, adds the contribution, borrows `totalInput - contribution`,
|
|
45313
|
+
* and pays the solver the total, so a holder of the debt asset lands in a levered collateral
|
|
45314
|
+
* position having never owned collateral. Requires the deployment's implementation to have a
|
|
45315
|
+
* debt-side hook configured; otherwise the position reverts with `DebtSideHookUnavailable`.
|
|
45316
|
+
*/
|
|
45317
|
+
buildCreatePositionFromDebtToken(params) {
|
|
45318
|
+
const method = "buildCreatePositionFromDebtToken";
|
|
45319
|
+
const factory = this.requireFactory(method);
|
|
45320
|
+
if (!factory.ok) return factory;
|
|
45321
|
+
const fee = this.resolvePositionFee(params.partnerFee, method);
|
|
45322
|
+
if (!fee.ok) return fee;
|
|
45323
|
+
const origin = this.resolveOrigin(params.origin, method);
|
|
45324
|
+
if (!origin.ok) return origin;
|
|
45325
|
+
return {
|
|
45326
|
+
ok: true,
|
|
45327
|
+
value: this.hubTx(
|
|
45328
|
+
params.from,
|
|
45329
|
+
factory.value,
|
|
45330
|
+
viem.encodeFunctionData({
|
|
45331
|
+
abi: leveragePositionFactoryAbi,
|
|
45332
|
+
functionName: "createPositionFromDebtToken",
|
|
45333
|
+
args: [
|
|
45334
|
+
this.positionConfig({ ...params, origin: origin.value, fee: fee.value }),
|
|
45335
|
+
params.contribution,
|
|
45336
|
+
params.totalInput,
|
|
45337
|
+
params.minCollateralOut
|
|
45338
|
+
]
|
|
45339
|
+
})
|
|
45340
|
+
)
|
|
45341
|
+
};
|
|
45342
|
+
}
|
|
45343
|
+
/** Borrows `borrowAmount` and swaps it into more collateral. `minCollateralOut` is the slippage floor. */
|
|
45344
|
+
buildAddLeverage(params) {
|
|
45345
|
+
return this.hubTx(
|
|
45346
|
+
params.from,
|
|
45347
|
+
params.position,
|
|
45348
|
+
viem.encodeFunctionData({
|
|
45349
|
+
abi: leveragePositionAbi,
|
|
45350
|
+
functionName: "addLeverage",
|
|
45351
|
+
args: [params.borrowAmount, params.minCollateralOut]
|
|
45352
|
+
})
|
|
45353
|
+
);
|
|
45354
|
+
}
|
|
45355
|
+
/**
|
|
45356
|
+
* Gives up `collateralIn` of collateral to repay debt. `minDebtOut` is the slippage floor.
|
|
45357
|
+
*
|
|
45358
|
+
* CLOSING INTO THE DEBT TOKEN is this call with the position's collateral balance, less the fee a
|
|
45359
|
+
* non-zero `feeBps` gives up on top of the input (`balance x 10_000 / (10_000 + feeBps)`) — there is
|
|
45360
|
+
* no separate close entry point, because selling everything is the same operation as selling part.
|
|
45361
|
+
* Size it with {@link LeverageYieldService.getPositionCollateralBalance}, never off
|
|
45362
|
+
* `totalCollateralBase`, and quote the full amount so `minDebtOut` reflects what the solver will
|
|
45363
|
+
* actually pay for all of it.
|
|
45364
|
+
*
|
|
45365
|
+
* What that leaves behind is worth knowing. The solver delivers more debt token than is owed, so
|
|
45366
|
+
* the hook repays the debt and hands the surplus to the position, which is the owner's equity now
|
|
45367
|
+
* denominated in the debt asset. It sits in the position until someone calls
|
|
45368
|
+
* {@link LeverageYieldService.buildSettlePosition} — that sweep is what actually delivers it, and
|
|
45369
|
+
* it goes to the position's `owner` (the hub wallet), not to whoever signed. Exiting into the
|
|
45370
|
+
* *collateral* instead means repaying only the debt and then calling
|
|
45371
|
+
* {@link LeverageYieldService.buildPositionWithdraw}, which can pay out to any address.
|
|
45372
|
+
*/
|
|
45373
|
+
buildDecreaseLeverage(params) {
|
|
45374
|
+
return this.hubTx(
|
|
45375
|
+
params.from,
|
|
45376
|
+
params.position,
|
|
45377
|
+
viem.encodeFunctionData({
|
|
45378
|
+
abi: leveragePositionAbi,
|
|
45379
|
+
functionName: "decreaseLeverage",
|
|
45380
|
+
args: [params.collateralIn, params.minDebtOut, params.exitAsset ?? viem.zeroAddress]
|
|
45381
|
+
})
|
|
45382
|
+
);
|
|
45383
|
+
}
|
|
45384
|
+
/**
|
|
45385
|
+
* Withdraws collateral out of the position. The pool rejects a withdrawal that would drop
|
|
45386
|
+
* the position below its liquidation threshold, so no client-side health check is applied
|
|
45387
|
+
* here — but note that bound is health factor 1, not a safety buffer above it.
|
|
45388
|
+
*/
|
|
45389
|
+
buildPositionWithdraw(params) {
|
|
45390
|
+
return this.hubTx(
|
|
45391
|
+
params.from,
|
|
45392
|
+
params.position,
|
|
45393
|
+
viem.encodeFunctionData({
|
|
45394
|
+
abi: leveragePositionAbi,
|
|
45395
|
+
functionName: "withdraw",
|
|
45396
|
+
args: [params.amount, params.to]
|
|
45397
|
+
})
|
|
45398
|
+
);
|
|
45399
|
+
}
|
|
45400
|
+
/**
|
|
45401
|
+
* Clears an operation that has already resolved and returns anything the position is holding
|
|
45402
|
+
* loose to its owner.
|
|
45403
|
+
*
|
|
45404
|
+
* PERMISSIONLESS, and deliberately so: it only ever tightens state, so a stranded balance can be
|
|
45405
|
+
* pushed back by anyone rather than waiting on the owner to notice. That matters because an intent
|
|
45406
|
+
* can be cancelled by a third party once past its deadline, which leaves the position resolved but
|
|
45407
|
+
* un-swept if the hook's notification did not land.
|
|
45408
|
+
*
|
|
45409
|
+
* Reverts while the intent is still live — use {@link LeverageYieldService.buildCancelPositionOperation}
|
|
45410
|
+
* to end one that has not resolved yet.
|
|
45411
|
+
*/
|
|
45412
|
+
buildSettlePosition(params) {
|
|
45413
|
+
return this.hubTx(
|
|
45414
|
+
params.from,
|
|
45415
|
+
params.position,
|
|
45416
|
+
viem.encodeFunctionData({ abi: leveragePositionAbi, functionName: "settle" })
|
|
45417
|
+
);
|
|
45418
|
+
}
|
|
45419
|
+
/**
|
|
45420
|
+
* Cancels the in-flight operation and returns the deposit.
|
|
45421
|
+
*
|
|
45422
|
+
* Nothing is escrowed when an intent is posted, so cancelling recovers nothing by itself — but
|
|
45423
|
+
* a position carrying no debt withdraws its whole collateral balance back to the owner, which
|
|
45424
|
+
* is what a leveraged open whose intent never filled needs. With debt outstanding the
|
|
45425
|
+
* collateral stays put: the pool would reject the withdrawal on its health-factor check.
|
|
45426
|
+
*/
|
|
45427
|
+
buildCancelPositionOperation(params) {
|
|
45428
|
+
return this.hubTx(
|
|
45429
|
+
params.from,
|
|
45430
|
+
params.position,
|
|
45431
|
+
viem.encodeFunctionData({ abi: leveragePositionAbi, functionName: "cancel" })
|
|
45432
|
+
);
|
|
45433
|
+
}
|
|
45434
|
+
// ─── Positions from any chain ──────────────────────────────────────────
|
|
45435
|
+
//
|
|
45436
|
+
// The builders above produce a transaction sent straight to the hub. That only works for a user
|
|
45437
|
+
// signing on the hub, and even there it has to be routed so `msg.sender` is their hub wallet —
|
|
45438
|
+
// a position's `onlyOwner` is that wallet, and an EOA cannot send as another address.
|
|
45439
|
+
//
|
|
45440
|
+
// These take over from there: the calls are encoded as a hub-wallet payload and carried by the
|
|
45441
|
+
// spoke transport, which routes them locally on the hub and relays them from anywhere else. So one
|
|
45442
|
+
// code path covers every chain, and the hub is not a special case.
|
|
45443
|
+
/**
|
|
45444
|
+
* Encodes position calls as a hub-wallet payload.
|
|
45445
|
+
*
|
|
45446
|
+
* Takes the raw transactions from the builders above and produces the `(address,uint256,bytes)[]`
|
|
45447
|
+
* payload the hub wallet executes. Public because that payload is the unit the transport takes:
|
|
45448
|
+
* pass it to `spoke.deposit` / `spoke.sendMessage` yourself when you want manual relay control,
|
|
45449
|
+
* or use {@link LeverageYieldService.openPosition} / {@link LeverageYieldService.operatePosition},
|
|
45450
|
+
* which do it for you.
|
|
45451
|
+
*/
|
|
45452
|
+
encodePositionCalls(txs) {
|
|
45453
|
+
return encodeContractCalls(
|
|
45454
|
+
txs.map((tx) => ({ address: tx.to, value: tx.value ?? 0n, data: tx.data }))
|
|
45455
|
+
);
|
|
45456
|
+
}
|
|
45457
|
+
/**
|
|
45458
|
+
* Resolves the hub reserve a spoke token funds, and the hub asset it arrives as.
|
|
45459
|
+
*
|
|
45460
|
+
* Three addresses per token and they are not interchangeable: `hubAsset` is what lands in the hub
|
|
45461
|
+
* wallet, `vault` is the 18-decimal money-market reserve a position actually uses, and the spoke
|
|
45462
|
+
* `address` is neither. Getting this wrong is silent — the wrong one is still a valid ERC-20.
|
|
45463
|
+
*/
|
|
45464
|
+
resolveFunding(srcChainKey, token, method) {
|
|
45465
|
+
const spokeToken = this.config.getSpokeTokenFromOriginalAssetAddress(srcChainKey, token) ?? this.config.getXTokenFromHubAsset(token);
|
|
45466
|
+
if (!spokeToken) {
|
|
45467
|
+
return {
|
|
45468
|
+
ok: false,
|
|
45469
|
+
error: lookupFailed(
|
|
45470
|
+
"leverageYield",
|
|
45471
|
+
method,
|
|
45472
|
+
new Error(`no hub asset registered for ${token} on ${srcChainKey}`),
|
|
45473
|
+
{ srcChainKey }
|
|
45474
|
+
)
|
|
45475
|
+
};
|
|
45476
|
+
}
|
|
45477
|
+
return {
|
|
45478
|
+
ok: true,
|
|
45479
|
+
value: {
|
|
45480
|
+
hubAsset: spokeToken.hubAsset,
|
|
45481
|
+
vault: spokeToken.vault,
|
|
45482
|
+
decimals: spokeToken.decimals
|
|
45483
|
+
}
|
|
45484
|
+
};
|
|
45485
|
+
}
|
|
45486
|
+
/**
|
|
45487
|
+
* What a refund should pay back: the asset the user actually funded with, or `undefined` when that IS
|
|
45488
|
+
* the reserve and there is nothing to unwrap.
|
|
45489
|
+
*
|
|
45490
|
+
* A named asset makes `IntentRefund` unwrap before paying, on the hub as well as off it — so someone
|
|
45491
|
+
* who deposited USSD is refunded USSD rather than `sodaUSSD`.
|
|
45492
|
+
*/
|
|
45493
|
+
refundAsset(funding) {
|
|
45494
|
+
return funding.hubAsset.toLowerCase() === funding.vault.toLowerCase() ? void 0 : funding.hubAsset;
|
|
45495
|
+
}
|
|
45496
|
+
/**
|
|
45497
|
+
* Encodes the wrap of an arriving deposit into its money-market reserve, and returns the reserve
|
|
45498
|
+
* amount that produces.
|
|
45499
|
+
*
|
|
45500
|
+
* A hub asset that is already a soda vault token IS the reserve, so nothing is wrapped. Otherwise
|
|
45501
|
+
* the vault mints 18-decimal shares one-for-one with the asset, which is what
|
|
45502
|
+
* `translateIncomingDecimals` computes — the same conversion the asset manager applies to a spoke
|
|
45503
|
+
* deposit, rather than a second implementation of it. A reserve carrying a non-zero deposit fee
|
|
45504
|
+
* would mint fewer shares than this predicts and the factory's pull would revert; both reserves in
|
|
45505
|
+
* use today are fee-free.
|
|
45506
|
+
*/
|
|
45507
|
+
encodeWrapIntoReserve(funding, amount) {
|
|
45508
|
+
if (this.config.isSodaVaultHubAsset(funding.hubAsset)) {
|
|
45509
|
+
return { calls: [], reserveAmount: amount };
|
|
45510
|
+
}
|
|
45511
|
+
return {
|
|
45512
|
+
calls: [
|
|
45513
|
+
Erc20Service.encodeApprove(funding.hubAsset, funding.vault, amount),
|
|
45514
|
+
EvmVaultTokenService.encodeDeposit(funding.vault, funding.hubAsset, amount)
|
|
45515
|
+
],
|
|
45516
|
+
reserveAmount: EvmVaultTokenService.translateIncomingDecimals(funding.decimals, amount)
|
|
45517
|
+
};
|
|
45518
|
+
}
|
|
45519
|
+
/**
|
|
45520
|
+
* Everything both opens do before they diverge: resolve the factory, the funding token's hub asset
|
|
45521
|
+
* and reserve, and the origin to refund to; predict the address the position will be created at;
|
|
45522
|
+
* and encode the wrap plus the transfer that funds it.
|
|
45523
|
+
*
|
|
45524
|
+
* Only the factory call itself differs between the collateral side and the debt side — which side
|
|
45525
|
+
* the funded reserve lands on, and the two amounts — so everything up to that point lives here
|
|
45526
|
+
* once. `calls` is returned ready to be appended to.
|
|
45527
|
+
*/
|
|
45528
|
+
async prepareOpen(params, method) {
|
|
45529
|
+
const factory = this.requireFactory(method);
|
|
45530
|
+
if (!factory.ok) return factory;
|
|
45531
|
+
const fee = this.resolvePositionFee(params.partnerFee, method);
|
|
45532
|
+
if (!fee.ok) return fee;
|
|
45533
|
+
const funding = this.resolveFunding(params.srcChainKey, params.token, method);
|
|
45534
|
+
if (!funding.ok) return funding;
|
|
45535
|
+
const origin = this.resolveOrigin(
|
|
45536
|
+
{ chainKey: params.srcChainKey, address: params.srcAddress, asset: this.refundAsset(funding.value) },
|
|
45537
|
+
method
|
|
45538
|
+
);
|
|
45539
|
+
if (!origin.ok) return origin;
|
|
45540
|
+
const predicted = await this.predictPosition(params.owner, params.owner);
|
|
45541
|
+
if (!predicted.ok) return predicted;
|
|
45542
|
+
const { calls, reserveAmount } = this.encodeWrapIntoReserve(funding.value, params.amount);
|
|
45543
|
+
calls.push(Erc20Service.encodeTransfer(funding.value.vault, predicted.value, reserveAmount));
|
|
45544
|
+
return {
|
|
45545
|
+
ok: true,
|
|
45546
|
+
value: {
|
|
45547
|
+
factory: factory.value,
|
|
45548
|
+
funding: funding.value,
|
|
45549
|
+
calls,
|
|
45550
|
+
reserveAmount,
|
|
45551
|
+
origin: origin.value,
|
|
45552
|
+
fee: fee.value
|
|
45553
|
+
}
|
|
45554
|
+
};
|
|
45555
|
+
}
|
|
45556
|
+
/**
|
|
45557
|
+
* Hub-side payload for opening a position from the collateral side.
|
|
45558
|
+
*
|
|
45559
|
+
* Wrap the arriving deposit into its reserve, TRANSFER it to the address the position will be
|
|
45560
|
+
* created at, create the position and post its leverage intent — one batch, executed by the user's
|
|
45561
|
+
* hub wallet. The position's collateral is the reserve behind `params.token`; `borrowToken` is
|
|
45562
|
+
* borrowed against it.
|
|
45563
|
+
*
|
|
45564
|
+
* Nothing is ever approved to the factory: it holds no allowance and pulls from nobody, so funding
|
|
45565
|
+
* is a transfer to `predictPosition(creator, owner, nextPositionIdFor(owner))` and the clone supplies
|
|
45566
|
+
* whatever it finds. The id is per-owner, so an unrelated user creating a position cannot move the
|
|
45567
|
+
* address out from under this batch — and because the transfer and the create are in the same batch,
|
|
45568
|
+
* a stale prediction reverts both rather than stranding the tokens.
|
|
45569
|
+
*
|
|
45570
|
+
* The owner's OWN concurrent opens are the one thing that can still advance the id between building
|
|
45571
|
+
* this payload and executing it. On the hub that reverts atomically and nothing is lost; funded from
|
|
45572
|
+
* a spoke the deposit has already landed in the user's hub wallet when the batch reverts, and is
|
|
45573
|
+
* recovered with `sodax.recovery` (see RECOVERY.md). Do not open two positions for one owner at once.
|
|
45574
|
+
*
|
|
45575
|
+
* The origin recorded on the position is `srcChainKey` / `srcAddress` / the deposited hub asset,
|
|
45576
|
+
* so a leverage intent that never fills refunds to the user on the chain they funded from — not to
|
|
45577
|
+
* the position, and not to the hub wallet.
|
|
45578
|
+
*/
|
|
45579
|
+
async buildOpenPositionData(params) {
|
|
45580
|
+
const prep = await this.prepareOpen(params, "buildOpenPositionData");
|
|
45581
|
+
if (!prep.ok) return prep;
|
|
45582
|
+
const { factory, funding, calls, reserveAmount, origin, fee } = prep.value;
|
|
45583
|
+
calls.push({
|
|
45584
|
+
address: factory,
|
|
45585
|
+
value: 0n,
|
|
45586
|
+
data: viem.encodeFunctionData({
|
|
45587
|
+
abi: leveragePositionFactoryAbi,
|
|
45588
|
+
functionName: "createPositionAndLeverage",
|
|
45589
|
+
args: [
|
|
45590
|
+
this.positionConfig({
|
|
45591
|
+
owner: params.owner,
|
|
45592
|
+
collateral: funding.vault,
|
|
45593
|
+
borrowToken: params.borrowToken,
|
|
45594
|
+
eModeCategory: params.eModeCategory ?? 0,
|
|
45595
|
+
origin,
|
|
45596
|
+
fee
|
|
45597
|
+
}),
|
|
45598
|
+
reserveAmount,
|
|
45599
|
+
params.borrowAmount,
|
|
45600
|
+
params.minCollateralOut
|
|
45601
|
+
]
|
|
45602
|
+
})
|
|
45603
|
+
});
|
|
45604
|
+
return { ok: true, value: encodeContractCalls(calls) };
|
|
45605
|
+
}
|
|
45606
|
+
/**
|
|
45607
|
+
* Hub-side payload for opening a position from the debt side.
|
|
45608
|
+
*
|
|
45609
|
+
* The mirror of {@link LeverageYieldService.buildOpenPositionData}: here the deposit is the
|
|
45610
|
+
* position's *debt* token, contributed rather than supplied, and `collateral` is the reserve the
|
|
45611
|
+
* position ends up long. The hook supplies the solver's collateral on fill and borrows only the
|
|
45612
|
+
* shortfall, so the position legitimately starts with no collateral of its own.
|
|
45613
|
+
*/
|
|
45614
|
+
async buildOpenPositionFromDebtTokenData(params) {
|
|
45615
|
+
const prep = await this.prepareOpen(params, "buildOpenPositionFromDebtTokenData");
|
|
45616
|
+
if (!prep.ok) return prep;
|
|
45617
|
+
const { factory, funding, calls, reserveAmount, origin, fee } = prep.value;
|
|
45618
|
+
calls.push({
|
|
45619
|
+
address: factory,
|
|
45620
|
+
value: 0n,
|
|
45621
|
+
data: viem.encodeFunctionData({
|
|
45622
|
+
abi: leveragePositionFactoryAbi,
|
|
45623
|
+
functionName: "createPositionFromDebtToken",
|
|
45624
|
+
args: [
|
|
45625
|
+
this.positionConfig({
|
|
45626
|
+
owner: params.owner,
|
|
45627
|
+
collateral: params.collateral,
|
|
45628
|
+
// The deposited token IS the debt side, so its reserve is the borrow token.
|
|
45629
|
+
borrowToken: funding.vault,
|
|
45630
|
+
eModeCategory: params.eModeCategory ?? 0,
|
|
45631
|
+
origin,
|
|
45632
|
+
fee
|
|
45633
|
+
}),
|
|
45634
|
+
reserveAmount,
|
|
45635
|
+
params.totalInput,
|
|
45636
|
+
params.minCollateralOut
|
|
45637
|
+
]
|
|
45638
|
+
})
|
|
45639
|
+
});
|
|
45640
|
+
return { ok: true, value: encodeContractCalls(calls) };
|
|
45641
|
+
}
|
|
45642
|
+
/**
|
|
45643
|
+
* Whether the funding token is already approved for an open from `srcChainKey`.
|
|
45644
|
+
*
|
|
45645
|
+
* The spender differs by chain and neither choice is guessable: on the hub the deposit is pulled
|
|
45646
|
+
* by the user's own hub wallet, executing inside the routed batch; on an EVM spoke it is pulled by
|
|
45647
|
+
* that spoke's asset manager. Chains with no allowance concept report `true`, and Stellar reports
|
|
45648
|
+
* whether the trustline covers the amount.
|
|
45649
|
+
*/
|
|
45650
|
+
async isPositionFundingAllowanceValid(params) {
|
|
45651
|
+
const baseCtx = { srcChainKey: params.srcChainKey, action: "allowanceCheck" };
|
|
45652
|
+
try {
|
|
45653
|
+
leverageYieldInvariant(params.amount > 0n, "amount must be greater than 0", { ...baseCtx, field: "amount" });
|
|
45654
|
+
const srcChainKey = params.srcChainKey;
|
|
45655
|
+
const inner = isHubChainKeyType(srcChainKey) || isEvmSpokeOnlyChainKeyType(srcChainKey) ? await this.spoke.isAllowanceValid({
|
|
45656
|
+
srcChainKey,
|
|
45657
|
+
token: params.token,
|
|
45658
|
+
amount: params.amount,
|
|
45659
|
+
owner: params.srcAddress,
|
|
45660
|
+
spender: await this.resolveFundingSpender(srcChainKey, params.srcAddress)
|
|
45661
|
+
}) : await this.spoke.isAllowanceValid({
|
|
45662
|
+
srcChainKey,
|
|
45663
|
+
token: params.token,
|
|
45664
|
+
amount: params.amount,
|
|
45665
|
+
owner: params.srcAddress
|
|
45666
|
+
});
|
|
45667
|
+
if (inner.ok) return inner;
|
|
45668
|
+
return { ok: false, error: allowanceCheckFailed("leverageYield", inner.error, baseCtx) };
|
|
45669
|
+
} catch (error) {
|
|
45670
|
+
if (isLeverageYieldAllowanceCheckError(error)) return { ok: false, error };
|
|
45671
|
+
return { ok: false, error: allowanceCheckFailed("leverageYield", error, baseCtx) };
|
|
45672
|
+
}
|
|
45673
|
+
}
|
|
45674
|
+
/**
|
|
45675
|
+
* Approves the funding token for an open, against the spender that chain's deposit actually uses —
|
|
45676
|
+
* see {@link LeverageYieldService.isPositionFundingAllowanceValid} for which that is.
|
|
45677
|
+
*
|
|
45678
|
+
* WAITS FOR THE APPROVAL TO LAND before returning. `Erc20Service.approve` resolves with the hash the
|
|
45679
|
+
* moment it is broadcast, so a caller that immediately re-reads the allowance sees the value from
|
|
45680
|
+
* BEFORE the approval — a UI then keeps showing "approve" and the user signs a second, pointless
|
|
45681
|
+
* approval. Returning early from a helper whose whole purpose is "the allowance is now sufficient" is
|
|
45682
|
+
* a footgun, so the wait lives here rather than in each caller.
|
|
45683
|
+
*/
|
|
45684
|
+
async approvePositionFunding(params) {
|
|
45685
|
+
const baseCtx = { srcChainKey: params.srcChainKey, action: "approve" };
|
|
45686
|
+
try {
|
|
45687
|
+
leverageYieldInvariant(params.amount > 0n, "amount must be greater than 0", { ...baseCtx, field: "amount" });
|
|
45688
|
+
const srcChainKey = params.srcChainKey;
|
|
45689
|
+
let inner = {
|
|
45690
|
+
ok: false,
|
|
45691
|
+
error: new Error(`[LeverageYieldService.approvePositionFunding] approve is unsupported on ${srcChainKey}`)
|
|
45692
|
+
};
|
|
45693
|
+
if (isHubChainKeyType(srcChainKey) || isEvmSpokeOnlyChainKeyType(srcChainKey)) {
|
|
45694
|
+
leverageYieldInvariant(viem.isAddress(params.token), "Invalid token address", { ...baseCtx, field: "token" });
|
|
45695
|
+
inner = await this.spoke.approve({
|
|
45696
|
+
srcChainKey,
|
|
45697
|
+
token: params.token,
|
|
45698
|
+
amount: params.amount,
|
|
45699
|
+
owner: params.srcAddress,
|
|
45700
|
+
spender: await this.resolveFundingSpender(srcChainKey, params.srcAddress),
|
|
45701
|
+
raw: false,
|
|
45702
|
+
// `K` stays open here, so the provider is only checkable against the chain key inside `spoke.approve`.
|
|
45703
|
+
walletProvider: params.walletProvider
|
|
45704
|
+
});
|
|
45705
|
+
} else if (isStellarChainKeyType(srcChainKey)) {
|
|
45706
|
+
inner = await this.spoke.approve({
|
|
45707
|
+
srcChainKey,
|
|
45708
|
+
token: params.token,
|
|
45709
|
+
amount: params.amount,
|
|
45710
|
+
owner: params.srcAddress,
|
|
45711
|
+
raw: false,
|
|
45712
|
+
walletProvider: params.walletProvider
|
|
45713
|
+
});
|
|
45714
|
+
}
|
|
45715
|
+
if (!inner.ok) return { ok: false, error: approveFailed("leverageYield", inner.error, baseCtx) };
|
|
45716
|
+
if (params.walletProvider && isEvmWalletProviderType(params.walletProvider)) {
|
|
45717
|
+
const receipt = await params.walletProvider.waitForTransactionReceipt(
|
|
45718
|
+
inner.value
|
|
45719
|
+
);
|
|
45720
|
+
if (receipt.status !== "success") {
|
|
45721
|
+
return { ok: false, error: approveFailed("leverageYield", "transaction reverted", baseCtx) };
|
|
45722
|
+
}
|
|
45723
|
+
} else {
|
|
45724
|
+
const landed = await this.spoke.verifyTxHash({ txHash: inner.value, chainKey: params.srcChainKey });
|
|
45725
|
+
if (!landed.ok) return { ok: false, error: approveFailed("leverageYield", landed.error, baseCtx) };
|
|
45726
|
+
}
|
|
45727
|
+
return inner;
|
|
45728
|
+
} catch (error) {
|
|
45729
|
+
if (isLeverageYieldApproveError(error)) return { ok: false, error };
|
|
45730
|
+
return { ok: false, error: approveFailed("leverageYield", error, baseCtx) };
|
|
45731
|
+
}
|
|
45732
|
+
}
|
|
45733
|
+
/**
|
|
45734
|
+
* Who pulls the deposit on an EVM source chain.
|
|
45735
|
+
*
|
|
45736
|
+
* On the hub the pull happens inside the routed batch, so the spender is the user's own hub wallet
|
|
45737
|
+
* rather than any protocol contract; on an EVM spoke it is that spoke's asset manager. Chains with
|
|
45738
|
+
* no ERC-20 allowance never reach here.
|
|
45739
|
+
*/
|
|
45740
|
+
async resolveFundingSpender(srcChainKey, srcAddress) {
|
|
45741
|
+
if (isHubChainKeyType(srcChainKey)) return await this.hubProvider.getUserHubWalletAddress(srcAddress, srcChainKey);
|
|
45742
|
+
return this.config.getChainConfig(srcChainKey).addresses.assetManager;
|
|
45743
|
+
}
|
|
45744
|
+
/**
|
|
45745
|
+
* Opens a leveraged position, funded from any chain, in one signature.
|
|
45746
|
+
*
|
|
45747
|
+
* The deposit is carried to the user's hub wallet and the position is created from inside that
|
|
45748
|
+
* same batch, so there is no window in which the funds sit on the hub unattached to a position.
|
|
45749
|
+
* On the hub this routes locally; from a spoke it relays and this waits for the hub side to land.
|
|
45750
|
+
*
|
|
45751
|
+
* WHAT IS AND IS NOT DONE WHEN THIS RESOLVES: the position exists and its leverage intent is
|
|
45752
|
+
* posted. The leverage itself is not applied — a solver fills that intent afterwards. And an
|
|
45753
|
+
* intent is invisible to the solver until its hub transaction hash is reported, so pass the
|
|
45754
|
+
* returned `dstChainTxHash` to {@link LeverageYieldService.notifySolver}; an unreported intent
|
|
45755
|
+
* simply expires and the deposit comes back.
|
|
45756
|
+
*
|
|
45757
|
+
* Spoke tokens need the spoke asset manager approved first, the same as any other deposit.
|
|
45758
|
+
*
|
|
45759
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN. Every path here has been exercised
|
|
45760
|
+
* end to end on Sonic, the hub. From a spoke the inbound half is proven only by a fork
|
|
45761
|
+
* replay of a real relayed message, and the OUTBOUND half — an exit or a cancellation
|
|
45762
|
+
* delivering the underlying back to the spoke it came from — has never run on mainnet.
|
|
45763
|
+
* Treat a non-hub `srcChainKey` as experimental until it has. Bitcoin is refused
|
|
45764
|
+
* outright — see {@link BITCOIN_UNSUPPORTED_MESSAGE}.
|
|
45765
|
+
*/
|
|
45766
|
+
async openPosition(_params) {
|
|
45767
|
+
return this.runPositionOpen(
|
|
45768
|
+
_params,
|
|
45769
|
+
"openPosition",
|
|
45770
|
+
(owner, params) => this.buildOpenPositionData({ ...params, owner })
|
|
45771
|
+
);
|
|
45772
|
+
}
|
|
45773
|
+
/**
|
|
45774
|
+
* Opens a leveraged position from the **debt** token, funded from any chain.
|
|
45775
|
+
*
|
|
45776
|
+
* Same transport and the same asynchronous settlement as
|
|
45777
|
+
* {@link LeverageYieldService.openPosition} — see there for what is and is not done when this
|
|
45778
|
+
* resolves. The difference is only which side the user funds: here they hand over debt token and
|
|
45779
|
+
* end up long collateral they never held.
|
|
45780
|
+
*
|
|
45781
|
+
* Requires the deployed implementation to have a debt-side hook configured; without one the
|
|
45782
|
+
* position reverts `DebtSideHookUnavailable`.
|
|
45783
|
+
*
|
|
45784
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN. Every path here has been exercised
|
|
45785
|
+
* end to end on Sonic, the hub. From a spoke the inbound half is proven only by a fork
|
|
45786
|
+
* replay of a real relayed message, and the OUTBOUND half — an exit or a cancellation
|
|
45787
|
+
* delivering the underlying back to the spoke it came from — has never run on mainnet.
|
|
45788
|
+
* Treat a non-hub `srcChainKey` as experimental until it has. Bitcoin is refused
|
|
45789
|
+
* outright — see {@link BITCOIN_UNSUPPORTED_MESSAGE}.
|
|
45790
|
+
*/
|
|
45791
|
+
async openPositionFromDebtToken(_params) {
|
|
45792
|
+
return this.runPositionOpen(
|
|
45793
|
+
_params,
|
|
45794
|
+
"openPositionFromDebtToken",
|
|
45795
|
+
(owner, params) => this.buildOpenPositionFromDebtTokenData({ ...params, owner })
|
|
45796
|
+
);
|
|
45797
|
+
}
|
|
45798
|
+
/**
|
|
45799
|
+
* Shared body of the two open paths. They differ only in which factory call the payload ends with,
|
|
45800
|
+
* so everything around it — owner resolution, deposit, verify, relay — lives here rather than
|
|
45801
|
+
* being written twice and drifting.
|
|
45802
|
+
*/
|
|
45803
|
+
/**
|
|
45804
|
+
* Instrumentation for both opens. Wrapping the shared runner rather than each entry point keeps
|
|
45805
|
+
* `openPosition` and `openPositionFromDebtToken` from drifting, and `action` is already threaded
|
|
45806
|
+
* through for the error context, so it doubles as the analytics action.
|
|
45807
|
+
*
|
|
45808
|
+
* `start` carries only the fields common to both param shapes — the funding side's token and
|
|
45809
|
+
* amount. The side-specific ones (`borrowToken`/`borrowAmount` vs `collateral`/`totalInput`) are
|
|
45810
|
+
* not on `PositionFundingParams`, and inventing a cast to reach them would be worse than omitting
|
|
45811
|
+
* them.
|
|
45812
|
+
*/
|
|
45813
|
+
async runPositionOpen(_params, action, build) {
|
|
45814
|
+
return this.config.analytics.trackResult(
|
|
45815
|
+
"leverageYield",
|
|
45816
|
+
action,
|
|
45817
|
+
() => this.executePositionOpen(_params, action, build),
|
|
45818
|
+
{
|
|
45819
|
+
start: () => ({
|
|
45820
|
+
srcChainKey: _params.params.srcChainKey,
|
|
45821
|
+
srcAddress: _params.params.srcAddress,
|
|
45822
|
+
inputToken: _params.params.token,
|
|
45823
|
+
inputAmount: _params.params.amount,
|
|
45824
|
+
eModeCategory: _params.params.eModeCategory
|
|
45825
|
+
}),
|
|
45826
|
+
success: (value) => ({ srcTxHash: value.srcChainTxHash, dstTxHash: value.dstChainTxHash }),
|
|
45827
|
+
failure: (error) => ({ code: error.code })
|
|
45828
|
+
}
|
|
45829
|
+
);
|
|
45830
|
+
}
|
|
45831
|
+
async executePositionOpen(_params, action, buildData) {
|
|
45832
|
+
const { params, timeout = DEFAULT_RELAY_TX_TIMEOUT } = _params;
|
|
45833
|
+
const baseCtx = {
|
|
45834
|
+
srcChainKey: params.srcChainKey,
|
|
45835
|
+
action
|
|
45836
|
+
};
|
|
45837
|
+
try {
|
|
45838
|
+
leverageYieldInvariant(!isBitcoinChainKeyType(params.srcChainKey), BITCOIN_UNSUPPORTED_MESSAGE, {
|
|
45839
|
+
...baseCtx,
|
|
45840
|
+
field: "srcChainKey"
|
|
45841
|
+
});
|
|
45842
|
+
leverageYieldInvariant(params.amount > 0n, "amount must be greater than 0", { ...baseCtx, field: "amount" });
|
|
45843
|
+
leverageYieldInvariant(params.minCollateralOut > 0n, "minCollateralOut must be greater than 0", {
|
|
45844
|
+
...baseCtx,
|
|
45845
|
+
field: "minCollateralOut"
|
|
45846
|
+
});
|
|
45847
|
+
leverageYieldInvariant(
|
|
45848
|
+
isUndefinedOrValidWalletProviderForChainKey(params.srcChainKey, _params.walletProvider),
|
|
45849
|
+
`Invalid wallet provider for chain key: ${params.srcChainKey}`,
|
|
45850
|
+
{ ...baseCtx, field: "walletProvider" }
|
|
45851
|
+
);
|
|
45852
|
+
const hubWallet = await this.hubProvider.getUserHubWalletAddress(params.srcAddress, params.srcChainKey);
|
|
45853
|
+
const data = await buildData(hubWallet, params);
|
|
45854
|
+
if (!data.ok) return data;
|
|
45855
|
+
const txResult = await this.spoke.deposit({
|
|
45856
|
+
srcChainKey: params.srcChainKey,
|
|
45857
|
+
srcAddress: params.srcAddress,
|
|
45858
|
+
to: hubWallet,
|
|
45859
|
+
token: params.token,
|
|
45860
|
+
amount: params.amount,
|
|
45861
|
+
data: data.value,
|
|
45862
|
+
skipSimulation: _params.skipSimulation ?? false,
|
|
45863
|
+
raw: false,
|
|
45864
|
+
walletProvider: _params.walletProvider
|
|
45865
|
+
});
|
|
45866
|
+
if (!txResult.ok) {
|
|
45867
|
+
if (isLeverageYieldCreateIntentError(txResult.error)) return { ok: false, error: txResult.error };
|
|
45868
|
+
return { ok: false, error: intentCreationFailed("leverageYield", txResult.error, baseCtx) };
|
|
45869
|
+
}
|
|
45870
|
+
return await this.settleHubWalletMessage(txResult.value, { address: hubWallet, payload: data.value }, baseCtx, {
|
|
45871
|
+
timeout
|
|
45872
|
+
});
|
|
45873
|
+
} catch (error) {
|
|
45874
|
+
if (isLeverageYieldSwapError(error)) return { ok: false, error };
|
|
45875
|
+
return { ok: false, error: executionFailed("leverageYield", error, { ...baseCtx, phase: "intentCreation" }) };
|
|
45876
|
+
}
|
|
45877
|
+
}
|
|
45878
|
+
/**
|
|
45879
|
+
* Which address actually funds a position from `chainKey` — what a balance must be read against,
|
|
45880
|
+
* and what the deposit is built from.
|
|
45881
|
+
*
|
|
45882
|
+
* ONE ANSWER FOR BOTH, because two answers cost an open on mainnet: the balance was read from the
|
|
45883
|
+
* registry `address` while the deposit rewrote it to `hubAsset`, so for Sonic's native S the form
|
|
45884
|
+
* showed 42 S and the batch then called `wS.transferFrom(user, hubWallet, 5e18)` against a wS
|
|
45885
|
+
* balance of zero. The approval was correct; the revert surfaced as nothing but "External call
|
|
45886
|
+
* failed". Any integrator reading a balance for a position deposit needs this same answer.
|
|
45887
|
+
*
|
|
45888
|
+
* Three addresses hang off a registry entry and they are not interchangeable:
|
|
45889
|
+
*
|
|
45890
|
+
* `address` the spoke-side original; for a bridged entry it can name another chain entirely
|
|
45891
|
+
* `hubAsset` what the user holds ON THE HUB, and the vault's deposit input
|
|
45892
|
+
* `vault` the hub money-market reserve the position ends up in
|
|
45893
|
+
*
|
|
45894
|
+
* Off the hub the answer is always `address` — that is the chain the user is on. On the hub it is
|
|
45895
|
+
* `hubAsset`, EXCEPT for a native entry: `EvmSpokeService.deposit` keys on the chain's own
|
|
45896
|
+
* `nativeToken` to send `msg.value` rather than an ERC-20 `transferFrom`, and the native entry
|
|
45897
|
+
* carries exactly that sentinel as its `address`. Rewriting that to the wrapper asks for a token
|
|
45898
|
+
* the wallet does not hold.
|
|
45899
|
+
*
|
|
45900
|
+
* @returns The funding address, or `undefined` when the token is not supported on `chainKey`.
|
|
45901
|
+
*/
|
|
45902
|
+
resolvePositionFunding(chainKey, token) {
|
|
45903
|
+
const address = resolvePositionFundingAddress(chainKey, this.hubProvider.chainConfig.chain.key, token);
|
|
45904
|
+
return address === "" ? void 0 : address;
|
|
45905
|
+
}
|
|
45906
|
+
/**
|
|
45907
|
+
* Quotes one leg of a position operation: the borrowed side when levering up, the collateral when
|
|
45908
|
+
* levering down or exiting.
|
|
45909
|
+
*
|
|
45910
|
+
* Use this rather than {@link LeverageYieldService.getQuote} for a position. Both hit the same
|
|
45911
|
+
* endpoint, but this one names the hub reserves as the pair the intent actually swaps and quotes
|
|
45912
|
+
* GROSS — see `positionLegQuote.ts` for why either alone gets the floor wrong. Feed `quotedAmount`
|
|
45913
|
+
* to {@link projectLeverageLeg}.
|
|
45914
|
+
*
|
|
45915
|
+
* A refusal is not always a dead pair: {@link isNoRouteRefusal} is also what the solver answers
|
|
45916
|
+
* for a leg that is only too small, and telling the two apart means quoting again at a healthy
|
|
45917
|
+
* notional. That size is priced, so it is the caller's to choose.
|
|
45918
|
+
*/
|
|
45919
|
+
async getPositionLegQuote(params) {
|
|
45920
|
+
const hubChainKey = this.hubProvider.chainConfig.chain.key;
|
|
45921
|
+
const quote = await this.getQuote({
|
|
45922
|
+
token_src: params.inputHubToken,
|
|
45923
|
+
token_src_blockchain_id: hubChainKey,
|
|
45924
|
+
token_dst: params.outputHubToken,
|
|
45925
|
+
token_dst_blockchain_id: hubChainKey,
|
|
45926
|
+
amount: params.amount,
|
|
45927
|
+
quote_type: "exact_input",
|
|
45928
|
+
// Explicit, not omitted: omitting it applies the configured leverage-yield fee.
|
|
45929
|
+
partnerFee: { address: viem.zeroAddress, percentage: 0 }
|
|
45930
|
+
});
|
|
45931
|
+
if (!quote.ok) return quote;
|
|
45932
|
+
return { ok: true, value: { quotedAmount: quote.value.quoted_amount } };
|
|
45933
|
+
}
|
|
45934
|
+
/**
|
|
45935
|
+
* Opens a leveraged position AND reports the intent it posts. Prefer this to
|
|
45936
|
+
* {@link LeverageYieldService.openPosition} / {@link LeverageYieldService.openPositionFromDebtToken}.
|
|
45937
|
+
*
|
|
45938
|
+
* Those two only post the intent. Reporting it is a separate call that must not be skipped — an
|
|
45939
|
+
* unreported intent expires unfilled, so the owner is left funded with leverage that never arrives
|
|
45940
|
+
* and nothing said so. Pairing them here is the difference between an API that works and one that
|
|
45941
|
+
* works only if you read the docs.
|
|
45942
|
+
*
|
|
45943
|
+
* `side` picks which asset funds the open: `'collateral'` supplies the deposit and borrows against
|
|
45944
|
+
* it, `'debt'` hands the deposit to the solver and ends up long collateral never held.
|
|
45945
|
+
*
|
|
45946
|
+
* RESOLVING MEANS THE INTENT IS LIVE, not that the position is open, and a failed notification is
|
|
45947
|
+
* still `ok: true` — see {@link LeveragePositionIntentResult}.
|
|
45948
|
+
*
|
|
45949
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN — see `operatePosition`.
|
|
45950
|
+
*/
|
|
45951
|
+
async openLeveragePosition(_params) {
|
|
45952
|
+
return this.config.analytics.trackResult(
|
|
45953
|
+
"leverageYield",
|
|
45954
|
+
"openLeveragePosition",
|
|
45955
|
+
async () => {
|
|
45956
|
+
const { side, ...rest } = _params;
|
|
45957
|
+
const opened = side === "debt" ? await this.openPositionFromDebtToken(
|
|
45958
|
+
rest
|
|
45959
|
+
) : await this.openPosition(rest);
|
|
45960
|
+
if (!opened.ok) return opened;
|
|
45961
|
+
return { ok: true, value: await reportPositionIntent(this.notifyIntent, opened.value) };
|
|
45962
|
+
},
|
|
45963
|
+
{
|
|
45964
|
+
start: () => ({ srcChainKey: _params.params.srcChainKey, side: _params.side ?? "collateral" }),
|
|
45965
|
+
success: (result) => ({ ...result.txHashes, notified: result.notified }),
|
|
45966
|
+
failure: (error) => ({ code: error.code })
|
|
45967
|
+
}
|
|
45968
|
+
);
|
|
45969
|
+
}
|
|
45970
|
+
/**
|
|
45971
|
+
* Runs position calls that POST A SOLVER INTENT — `addLeverage` and `decreaseLeverage` — and
|
|
45972
|
+
* reports it. Prefer this to {@link LeverageYieldService.operatePosition} for those two.
|
|
45973
|
+
*
|
|
45974
|
+
* USE {@link LeverageYieldService.runLeveragePositionOperation} FOR `withdraw`, `settle` AND
|
|
45975
|
+
* `cancel`. Those are synchronous on the hub and need no notification, and the split is not
|
|
45976
|
+
* cosmetic: sending a leverage change through the route-only path leaves an intent nothing will
|
|
45977
|
+
* fill, and it expires without a word. The other direction is merely noisy.
|
|
45978
|
+
*
|
|
45979
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN — see `operatePosition`.
|
|
45980
|
+
*/
|
|
45981
|
+
async submitLeveragePositionIntent(_params) {
|
|
45982
|
+
return this.config.analytics.trackResult(
|
|
45983
|
+
"leverageYield",
|
|
45984
|
+
"submitLeveragePositionIntent",
|
|
45985
|
+
async () => {
|
|
45986
|
+
const routed = await this.operatePosition(_params);
|
|
45987
|
+
if (!routed.ok) return routed;
|
|
45988
|
+
return { ok: true, value: await reportPositionIntent(this.notifyIntent, routed.value) };
|
|
45989
|
+
},
|
|
45990
|
+
{
|
|
45991
|
+
start: () => ({ srcChainKey: _params.params.srcChainKey, calls: _params.params.calls.length }),
|
|
45992
|
+
success: (result) => ({ ...result.txHashes, notified: result.notified }),
|
|
45993
|
+
failure: (error) => ({ code: error.code })
|
|
45994
|
+
}
|
|
45995
|
+
);
|
|
45996
|
+
}
|
|
45997
|
+
/**
|
|
45998
|
+
* Runs position calls that do NOT post an intent — `withdraw`, `settle` and `cancel` — as the
|
|
45999
|
+
* owning hub wallet. They are synchronous on the hub, so resolving means the work is done.
|
|
46000
|
+
*
|
|
46001
|
+
* Still routed, never sent directly: the position's `onlyOwner` is the hub wallet, so a builder's
|
|
46002
|
+
* transaction sent from the signer reverts `NotOwner`. Use
|
|
46003
|
+
* {@link LeverageYieldService.submitLeveragePositionIntent} for `addLeverage` and
|
|
46004
|
+
* `decreaseLeverage`, which this deliberately does not report.
|
|
46005
|
+
*
|
|
46006
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN, and this path carries the worst of
|
|
46007
|
+
* it: an exit or cancellation delivering the underlying back to the spoke it came from
|
|
46008
|
+
* has never run on mainnet.
|
|
46009
|
+
*/
|
|
46010
|
+
async runLeveragePositionOperation(_params) {
|
|
46011
|
+
return this.operatePosition(_params);
|
|
46012
|
+
}
|
|
46013
|
+
/** Bound once so the notify half can be handed around without losing `this`. */
|
|
46014
|
+
notifyIntent = (request) => this.notifySolver(request);
|
|
46015
|
+
/**
|
|
46016
|
+
* Runs position calls as the user's hub wallet, from any chain.
|
|
46017
|
+
*
|
|
46018
|
+
* The write counterpart to the read hooks: add or decrease leverage, withdraw, settle, cancel. No
|
|
46019
|
+
* funds move, so this is a bare message rather than a deposit — on the hub it routes locally, from
|
|
46020
|
+
* a spoke it relays and this waits for the hub side to land.
|
|
46021
|
+
*
|
|
46022
|
+
* The leverage calls only *post* an intent, so a resolved promise means the intent is live, not
|
|
46023
|
+
* that leverage moved. Report the returned `dstChainTxHash` to
|
|
46024
|
+
* {@link LeverageYieldService.notifySolver} for those two; `withdraw`, `settle` and `cancel` are
|
|
46025
|
+
* synchronous on the hub and need no notification.
|
|
46026
|
+
*
|
|
46027
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN. Every path here has been exercised
|
|
46028
|
+
* end to end on Sonic, the hub. From a spoke the inbound half is proven only by a fork
|
|
46029
|
+
* replay of a real relayed message, and the OUTBOUND half — an exit or a cancellation
|
|
46030
|
+
* delivering the underlying back to the spoke it came from — has never run on mainnet.
|
|
46031
|
+
* Treat a non-hub `srcChainKey` as experimental until it has. Bitcoin is refused
|
|
46032
|
+
* outright — see {@link BITCOIN_UNSUPPORTED_MESSAGE}.
|
|
46033
|
+
*/
|
|
46034
|
+
async operatePosition(_params) {
|
|
46035
|
+
return this.config.analytics.trackResult(
|
|
46036
|
+
"leverageYield",
|
|
46037
|
+
"operatePosition",
|
|
46038
|
+
() => this.executePositionOperation(_params),
|
|
46039
|
+
{
|
|
46040
|
+
// The calls themselves are not emitted — they are arbitrary hub calldata. The count is
|
|
46041
|
+
// enough to tell a batched adjust from a single write.
|
|
46042
|
+
start: () => ({
|
|
46043
|
+
srcChainKey: _params.params.srcChainKey,
|
|
46044
|
+
srcAddress: _params.params.srcAddress,
|
|
46045
|
+
callCount: _params.params.calls.length
|
|
46046
|
+
}),
|
|
46047
|
+
success: (value) => ({ srcTxHash: value.srcChainTxHash, dstTxHash: value.dstChainTxHash }),
|
|
46048
|
+
failure: (error) => ({ code: error.code })
|
|
46049
|
+
}
|
|
46050
|
+
);
|
|
46051
|
+
}
|
|
46052
|
+
async executePositionOperation(_params) {
|
|
46053
|
+
const { params, timeout = DEFAULT_RELAY_TX_TIMEOUT } = _params;
|
|
46054
|
+
const baseCtx = {
|
|
46055
|
+
srcChainKey: params.srcChainKey,
|
|
46056
|
+
action: "operatePosition"
|
|
46057
|
+
};
|
|
46058
|
+
try {
|
|
46059
|
+
leverageYieldInvariant(!isBitcoinChainKeyType(params.srcChainKey), BITCOIN_UNSUPPORTED_MESSAGE, {
|
|
46060
|
+
...baseCtx,
|
|
46061
|
+
field: "srcChainKey"
|
|
46062
|
+
});
|
|
46063
|
+
leverageYieldInvariant(params.calls.length > 0, "at least one call is required", {
|
|
46064
|
+
...baseCtx,
|
|
46065
|
+
field: "calls"
|
|
46066
|
+
});
|
|
46067
|
+
leverageYieldInvariant(
|
|
46068
|
+
isUndefinedOrValidWalletProviderForChainKey(params.srcChainKey, _params.walletProvider),
|
|
46069
|
+
`Invalid wallet provider for chain key: ${params.srcChainKey}`,
|
|
46070
|
+
{ ...baseCtx, field: "walletProvider" }
|
|
46071
|
+
);
|
|
46072
|
+
const hubWallet = await this.hubProvider.getUserHubWalletAddress(params.srcAddress, params.srcChainKey);
|
|
46073
|
+
const payload = this.encodePositionCalls(params.calls);
|
|
46074
|
+
const txResult = await this.spoke.sendMessage({
|
|
46075
|
+
srcChainKey: params.srcChainKey,
|
|
46076
|
+
srcAddress: params.srcAddress,
|
|
46077
|
+
dstChainKey: HUB_CHAIN_KEY,
|
|
46078
|
+
dstAddress: hubWallet,
|
|
46079
|
+
payload,
|
|
46080
|
+
skipSimulation: _params.skipSimulation ?? false,
|
|
46081
|
+
raw: false,
|
|
46082
|
+
walletProvider: _params.walletProvider
|
|
46083
|
+
});
|
|
46084
|
+
if (!txResult.ok) {
|
|
46085
|
+
if (isLeverageYieldCreateIntentError(txResult.error)) return { ok: false, error: txResult.error };
|
|
46086
|
+
return { ok: false, error: intentCreationFailed("leverageYield", txResult.error, baseCtx) };
|
|
46087
|
+
}
|
|
46088
|
+
return await this.settleHubWalletMessage(txResult.value, { address: hubWallet, payload }, baseCtx, { timeout });
|
|
46089
|
+
} catch (error) {
|
|
46090
|
+
if (isLeverageYieldSwapError(error)) return { ok: false, error };
|
|
46091
|
+
return { ok: false, error: executionFailed("leverageYield", error, { ...baseCtx, phase: "intentCreation" }) };
|
|
46092
|
+
}
|
|
46093
|
+
}
|
|
46094
|
+
/**
|
|
46095
|
+
* Verifies a submitted source transaction and, off the hub, relays it and waits for the hub side.
|
|
46096
|
+
*
|
|
46097
|
+
* Shared by both write paths because the tail is identical whether funds moved or not. The hub
|
|
46098
|
+
* short-circuit is not an optimisation: a hub transaction has already executed the calls, so there
|
|
46099
|
+
* is nothing to relay, and both hashes are the same transaction.
|
|
46100
|
+
*/
|
|
46101
|
+
async settleHubWalletMessage(srcTxHash, relayData, baseCtx, opts) {
|
|
46102
|
+
const verify = await this.spoke.verifyTxHash({ txHash: srcTxHash, chainKey: baseCtx.srcChainKey });
|
|
46103
|
+
if (!verify.ok) return { ok: false, error: verifyFailed("leverageYield", verify.error, baseCtx) };
|
|
46104
|
+
if (isHubChainKeyType(baseCtx.srcChainKey)) {
|
|
46105
|
+
const receipt = await this.hubProvider.publicClient.waitForTransactionReceipt({
|
|
46106
|
+
hash: srcTxHash,
|
|
46107
|
+
timeout: opts.timeout
|
|
46108
|
+
});
|
|
46109
|
+
if (receipt.status !== "success") {
|
|
46110
|
+
return {
|
|
46111
|
+
ok: false,
|
|
46112
|
+
error: verifyFailed("leverageYield", new Error(`hub transaction ${srcTxHash} reverted`), baseCtx)
|
|
46113
|
+
};
|
|
46114
|
+
}
|
|
46115
|
+
return { ok: true, value: { srcChainTxHash: srcTxHash, dstChainTxHash: srcTxHash } };
|
|
46116
|
+
}
|
|
46117
|
+
const packet = await relayTxAndWaitPacket({
|
|
46118
|
+
srcTxHash,
|
|
46119
|
+
data: relayData,
|
|
46120
|
+
chainKey: baseCtx.srcChainKey,
|
|
46121
|
+
relayerApiEndpoint: this.config.relay.relayerApiEndpoint,
|
|
46122
|
+
timeout: opts.timeout
|
|
46123
|
+
});
|
|
46124
|
+
if (!packet.ok) {
|
|
46125
|
+
return {
|
|
46126
|
+
ok: false,
|
|
46127
|
+
error: mapRelayFailure(packet.error, {
|
|
46128
|
+
feature: "leverageYield",
|
|
46129
|
+
action: baseCtx.action,
|
|
46130
|
+
srcChainKey: baseCtx.srcChainKey
|
|
46131
|
+
})
|
|
46132
|
+
};
|
|
46133
|
+
}
|
|
46134
|
+
return { ok: true, value: { srcChainTxHash: srcTxHash, dstChainTxHash: packet.value.dst_tx_hash } };
|
|
46135
|
+
}
|
|
44722
46136
|
};
|
|
44723
46137
|
|
|
44724
46138
|
// src/sponsoring/errors.ts
|
|
@@ -44746,12 +46160,12 @@ function toDomainCode(value) {
|
|
|
44746
46160
|
}
|
|
44747
46161
|
function readErrorBody(body) {
|
|
44748
46162
|
if (typeof body !== "object" || body === null) return {};
|
|
44749
|
-
const
|
|
44750
|
-
const retryAfterSeconds = typeof
|
|
44751
|
-
const sponsorSequence = typeof
|
|
46163
|
+
const record = body;
|
|
46164
|
+
const retryAfterSeconds = typeof record.retryAfterSeconds === "number" && Number.isFinite(record.retryAfterSeconds) && record.retryAfterSeconds > 0 ? record.retryAfterSeconds : void 0;
|
|
46165
|
+
const sponsorSequence = typeof record.sponsorSequence === "string" && /^\d+$/.test(record.sponsorSequence) ? record.sponsorSequence : void 0;
|
|
44752
46166
|
return {
|
|
44753
|
-
message: typeof
|
|
44754
|
-
code: toDomainCode(
|
|
46167
|
+
message: typeof record.message === "string" ? record.message : void 0,
|
|
46168
|
+
code: toDomainCode(record.error),
|
|
44755
46169
|
retryAfterSeconds,
|
|
44756
46170
|
sponsorSequence
|
|
44757
46171
|
};
|
|
@@ -45407,6 +46821,81 @@ var PARTNER_CODES = /* @__PURE__ */ new Set([
|
|
|
45407
46821
|
"UNKNOWN"
|
|
45408
46822
|
]);
|
|
45409
46823
|
var isPartnerError = isCodeMember(PARTNER_CODES);
|
|
46824
|
+
function sizeLeverageBorrow(request) {
|
|
46825
|
+
const { side, deposit, depositDecimals, collateralPriceUsd, borrowPriceUsd, borrowDecimals, leverage } = request;
|
|
46826
|
+
const depositTokens = Number(viem.formatUnits(deposit, depositDecimals));
|
|
46827
|
+
const depositUsd = depositTokens * (side === "debt" ? borrowPriceUsd : collateralPriceUsd);
|
|
46828
|
+
const RATIO_SCALE = 1000000000n;
|
|
46829
|
+
const ratio = borrowPriceUsd > 0 && depositTokens > 0 ? depositUsd * Math.max(leverage - 1, 0) / borrowPriceUsd / depositTokens : 0;
|
|
46830
|
+
const borrowAmount = deposit * BigInt(Math.floor(ratio * Number(RATIO_SCALE))) * 10n ** BigInt(borrowDecimals) / (RATIO_SCALE * 10n ** BigInt(depositDecimals));
|
|
46831
|
+
const depositInBorrowUnits = deposit * 10n ** BigInt(borrowDecimals) / 10n ** BigInt(depositDecimals);
|
|
46832
|
+
const intentInput = side === "debt" ? borrowAmount + depositInBorrowUnits : borrowAmount;
|
|
46833
|
+
const feeAmount = request.feeBps ? intentInput * BigInt(Math.round(request.feeBps)) / 10000n : 0n;
|
|
46834
|
+
const borrowUsd = Number(viem.formatUnits(borrowAmount, borrowDecimals)) * borrowPriceUsd;
|
|
46835
|
+
const feeUsd = Number(viem.formatUnits(feeAmount, borrowDecimals)) * borrowPriceUsd;
|
|
46836
|
+
return {
|
|
46837
|
+
borrowAmount,
|
|
46838
|
+
intentInput,
|
|
46839
|
+
depositUsd,
|
|
46840
|
+
// Taken from the amount actually being borrowed, so the projection cannot disagree with the
|
|
46841
|
+
// transaction by the rounding above.
|
|
46842
|
+
borrowUsd,
|
|
46843
|
+
feeAmount,
|
|
46844
|
+
// The fee is borrowed on top on a leverage-up, so it is debt even though the solver never sees it.
|
|
46845
|
+
debtUsd: borrowUsd + feeUsd
|
|
46846
|
+
};
|
|
46847
|
+
}
|
|
46848
|
+
function projectLeverageLeg(request, quote, risk, slippagePct) {
|
|
46849
|
+
const { side, collateralPriceUsd, leverage } = request;
|
|
46850
|
+
const sized = sizeLeverageBorrow(request);
|
|
46851
|
+
const { depositUsd, borrowUsd } = sized;
|
|
46852
|
+
const floor = quote.quotedCollateral * BigInt(Math.round((100 - slippagePct) * 100)) / 10000n;
|
|
46853
|
+
const minCollateralOut = floor > 0n ? floor : 1n;
|
|
46854
|
+
const floorUsd = Number(viem.formatUnits(minCollateralOut, quote.collateralDecimals)) * collateralPriceUsd;
|
|
46855
|
+
const quotedUsd = Number(viem.formatUnits(quote.quotedCollateral, quote.collateralDecimals)) * collateralPriceUsd;
|
|
46856
|
+
const inputUsd = side === "debt" ? depositUsd * leverage : borrowUsd;
|
|
46857
|
+
const f = inputUsd > 0 ? floorUsd / inputUsd : 0;
|
|
46858
|
+
const haircut = inputUsd > 0 ? 1 - quotedUsd / inputUsd : 0;
|
|
46859
|
+
const collateralUsd = (side === "debt" ? 0 : depositUsd) + floorUsd;
|
|
46860
|
+
const debtUsd = sized.debtUsd;
|
|
46861
|
+
const ltv = collateralUsd > 0 ? debtUsd / collateralUsd : 0;
|
|
46862
|
+
const ltvF = risk.ltv * f;
|
|
46863
|
+
const phi = (request.feeBps ?? 0) / 1e4;
|
|
46864
|
+
const denominator = 1 + phi - ltvF;
|
|
46865
|
+
const usableMaxLeverage = risk.ltv <= 0 ? 1 : denominator <= 0 ? Number.POSITIVE_INFINITY : side === "debt" ? 1 / denominator : 1 + risk.ltv / denominator;
|
|
46866
|
+
const equityUsd = collateralUsd - debtUsd;
|
|
46867
|
+
return {
|
|
46868
|
+
minCollateralOut,
|
|
46869
|
+
collateralUsd,
|
|
46870
|
+
debtUsd,
|
|
46871
|
+
exposureLeverage: equityUsd > 0 ? collateralUsd / equityUsd : Number.POSITIVE_INFINITY,
|
|
46872
|
+
ltv,
|
|
46873
|
+
healthFactor: debtUsd > 0 ? collateralUsd * risk.liquidationThreshold / debtUsd : Number.POSITIVE_INFINITY,
|
|
46874
|
+
exceedsMaxLtv: ltv > risk.ltv,
|
|
46875
|
+
haircut,
|
|
46876
|
+
inputUsd,
|
|
46877
|
+
costUsd: inputUsd * haircut + sized.debtUsd - borrowUsd,
|
|
46878
|
+
usableMaxLeverage
|
|
46879
|
+
};
|
|
46880
|
+
}
|
|
46881
|
+
|
|
46882
|
+
// src/leverageYield/positionApyMath.ts
|
|
46883
|
+
function leveragedNetApyPct(supplyApyPct, borrowApyPct, leverage) {
|
|
46884
|
+
return supplyApyPct * leverage - borrowApyPct * (leverage - 1);
|
|
46885
|
+
}
|
|
46886
|
+
function timeToBreakevenYears(supplyApyPct, borrowApyPct, toLeverage, { costUsd, equityUsd, fromLeverage }) {
|
|
46887
|
+
if (!(equityUsd > 0) || !Number.isFinite(costUsd)) return void 0;
|
|
46888
|
+
if (costUsd <= 0) return "immediate";
|
|
46889
|
+
const incrementalPct = leveragedNetApyPct(supplyApyPct, borrowApyPct, toLeverage) - leveragedNetApyPct(supplyApyPct, borrowApyPct, fromLeverage);
|
|
46890
|
+
if (!(incrementalPct > 0)) return "never";
|
|
46891
|
+
return costUsd / (equityUsd * (incrementalPct / 100));
|
|
46892
|
+
}
|
|
46893
|
+
|
|
46894
|
+
// src/leverageYield/positionLegQuote.ts
|
|
46895
|
+
function isNoRouteRefusal(error) {
|
|
46896
|
+
const message = typeof error === "object" && error !== null && "detail" in error ? error.detail?.message : error instanceof Error ? error.message : void 0;
|
|
46897
|
+
return /no path was found/i.test(message ?? "");
|
|
46898
|
+
}
|
|
45410
46899
|
/*! Bundled license information:
|
|
45411
46900
|
|
|
45412
46901
|
@noble/hashes/utils.js:
|
|
@@ -45429,6 +46918,10 @@ Object.defineProperty(exports, "SwapsApiError", {
|
|
|
45429
46918
|
enumerable: true,
|
|
45430
46919
|
get: function () { return swapsApi.SwapsApiError; }
|
|
45431
46920
|
});
|
|
46921
|
+
Object.defineProperty(exports, "BridgeApiError", {
|
|
46922
|
+
enumerable: true,
|
|
46923
|
+
get: function () { return bridgeApi.BridgeApiError; }
|
|
46924
|
+
});
|
|
45432
46925
|
exports.ALLOWANCE_CHECK_CODES = ALLOWANCE_CHECK_CODES;
|
|
45433
46926
|
exports.APPROVE_CODES = APPROVE_CODES;
|
|
45434
46927
|
exports.AssetService = AssetService;
|
|
@@ -45436,6 +46929,8 @@ exports.BACKEND_API_BASE_PATH = BACKEND_API_BASE_PATH;
|
|
|
45436
46929
|
exports.BITCOIN_CHAIN_KEYS = BITCOIN_CHAIN_KEYS;
|
|
45437
46930
|
exports.BITCOIN_CHAIN_KEYS_SET = BITCOIN_CHAIN_KEYS_SET;
|
|
45438
46931
|
exports.BITCOIN_DUST_SATS = BITCOIN_DUST_SATS;
|
|
46932
|
+
exports.BOUND_API_HOST = BOUND_API_HOST;
|
|
46933
|
+
exports.BOUND_COMPANION_HOSTS = BOUND_COMPANION_HOSTS;
|
|
45439
46934
|
exports.BTC_WALLET_ADDRESS_TYPES = BTC_WALLET_ADDRESS_TYPES;
|
|
45440
46935
|
exports.BackendApiService = BackendApiService;
|
|
45441
46936
|
exports.BackendHttpError = BackendHttpError;
|
|
@@ -45466,6 +46961,7 @@ exports.DEFAULT_RELAYER_API_ENDPOINT = DEFAULT_RELAYER_API_ENDPOINT;
|
|
|
45466
46961
|
exports.DEFAULT_RELAY_TX_TIMEOUT = DEFAULT_RELAY_TX_TIMEOUT;
|
|
45467
46962
|
exports.DEFAULT_RETRY_DELAY_MS = DEFAULT_RETRY_DELAY_MS;
|
|
45468
46963
|
exports.DEFAULT_SPONSORING_API_ENDPOINT = DEFAULT_SPONSORING_API_ENDPOINT;
|
|
46964
|
+
exports.DEPRECATED_BOUND_HOSTS = DEPRECATED_BOUND_HOSTS;
|
|
45469
46965
|
exports.DETAILED_STATUS_NOT_DELIVERED = DETAILED_STATUS_NOT_DELIVERED;
|
|
45470
46966
|
exports.DexService = DexService;
|
|
45471
46967
|
exports.EVM_CHAIN_ID_TO_KEY = EVM_CHAIN_ID_TO_KEY;
|
|
@@ -45514,6 +47010,7 @@ exports.LockupMultiplier = LockupMultiplier;
|
|
|
45514
47010
|
exports.LockupPeriod = LockupPeriod;
|
|
45515
47011
|
exports.LsodaSymbols = LsodaSymbols;
|
|
45516
47012
|
exports.LsodaTokens = LsodaTokens;
|
|
47013
|
+
exports.MAX_POSITION_FEE_BPS = MAX_POSITION_FEE_BPS;
|
|
45517
47014
|
exports.MAX_UINT256 = MAX_UINT256;
|
|
45518
47015
|
exports.MigrationService = MigrationService;
|
|
45519
47016
|
exports.MintPositionEventAbi = MintPositionEventAbi;
|
|
@@ -45538,6 +47035,7 @@ exports.RadfiApiError = RadfiApiError;
|
|
|
45538
47035
|
exports.RadfiProvider = RadfiProvider;
|
|
45539
47036
|
exports.RecoveryService = RecoveryService;
|
|
45540
47037
|
exports.RelayChainIdMap = RelayChainIdMap;
|
|
47038
|
+
exports.SDK_VERSION = SDK_VERSION;
|
|
45541
47039
|
exports.SECONDS_PER_YEAR = SECONDS_PER_YEAR;
|
|
45542
47040
|
exports.SODAX_ERROR_CODES = SODAX_ERROR_CODES;
|
|
45543
47041
|
exports.SODAX_FEATURES = SODAX_FEATURES;
|
|
@@ -45621,6 +47119,7 @@ exports.clRouterAbi = clRouterAbi;
|
|
|
45621
47119
|
exports.clTickLensAbi = clTickLensAbi;
|
|
45622
47120
|
exports.classifySponsorError = classifySponsorError;
|
|
45623
47121
|
exports.concentratedLiquidityConfig = concentratedLiquidityConfig;
|
|
47122
|
+
exports.configVersionFor = configVersionFor;
|
|
45624
47123
|
exports.connectionAbi = connectionAbi;
|
|
45625
47124
|
exports.consoleLogger = consoleLogger;
|
|
45626
47125
|
exports.convertTransactionInstructionToRaw = convertTransactionInstructionToRaw;
|
|
@@ -45643,6 +47142,7 @@ exports.estimateSwapSpeedTier = estimateSwapSpeedTier;
|
|
|
45643
47142
|
exports.ethereumSupportedTokens = ethereumSupportedTokens;
|
|
45644
47143
|
exports.executionFailed = executionFailed;
|
|
45645
47144
|
exports.formatBasisPoints = formatBasisPoints;
|
|
47145
|
+
exports.formatConfigVersion = formatConfigVersion;
|
|
45646
47146
|
exports.formatEModeCategory = formatEModeCategory;
|
|
45647
47147
|
exports.formatEModes = formatEModes;
|
|
45648
47148
|
exports.formatPercentage = formatPercentage;
|
|
@@ -45756,6 +47256,7 @@ exports.isNearChainKey = isNearChainKey;
|
|
|
45756
47256
|
exports.isNearChainKeyType = isNearChainKeyType;
|
|
45757
47257
|
exports.isNewbnUSDChainId = isNewbnUSDChainId;
|
|
45758
47258
|
exports.isNewbnUSDToken = isNewbnUSDToken;
|
|
47259
|
+
exports.isNoRouteRefusal = isNoRouteRefusal;
|
|
45759
47260
|
exports.isOptionalBitcoinWalletProviderType = isOptionalBitcoinWalletProviderType;
|
|
45760
47261
|
exports.isOptionalEvmWalletProviderType = isOptionalEvmWalletProviderType;
|
|
45761
47262
|
exports.isOptionalStellarWalletProviderType = isOptionalStellarWalletProviderType;
|
|
@@ -45765,6 +47266,7 @@ exports.isPartnerFeeAmount = isPartnerFeeAmount;
|
|
|
45765
47266
|
exports.isPartnerFeePercentage = isPartnerFeePercentage;
|
|
45766
47267
|
exports.isPostExecutionError = isPostExecutionError;
|
|
45767
47268
|
exports.isRawDestinationParams = isRawDestinationParams;
|
|
47269
|
+
exports.isRealWorldAsset = isRealWorldAsset;
|
|
45768
47270
|
exports.isRecoveryError = isRecoveryError;
|
|
45769
47271
|
exports.isResponseAddressType = isResponseAddressType;
|
|
45770
47272
|
exports.isResponseSigningType = isResponseSigningType;
|
|
@@ -45813,6 +47315,7 @@ exports.kaiaSupportedTokens = kaiaSupportedTokens;
|
|
|
45813
47315
|
exports.leverageYieldConfig = leverageYieldConfig;
|
|
45814
47316
|
exports.leverageYieldInvariant = leverageYieldInvariant;
|
|
45815
47317
|
exports.leverageYieldVaults = leverageYieldVaults;
|
|
47318
|
+
exports.leveragedNetApyPct = leveragedNetApyPct;
|
|
45816
47319
|
exports.lightlinkSupportedTokens = lightlinkSupportedTokens;
|
|
45817
47320
|
exports.lookupFailed = lookupFailed;
|
|
45818
47321
|
exports.mapRelayFailure = mapRelayFailure;
|
|
@@ -45838,6 +47341,7 @@ exports.optimismSupportedTokens = optimismSupportedTokens;
|
|
|
45838
47341
|
exports.pancakeSwapInfinityDefaultHookAbi = pancakeSwapInfinityDefaultHookAbi;
|
|
45839
47342
|
exports.pancakeSwapInfinityPoolManagerAbi = pancakeSwapInfinityPoolManagerAbi;
|
|
45840
47343
|
exports.pancakeSwapInfinityPositionManagerAbi = pancakeSwapInfinityPositionManagerAbi;
|
|
47344
|
+
exports.parseConfigVersion = parseConfigVersion;
|
|
45841
47345
|
exports.parseToStroops = parseToStroops;
|
|
45842
47346
|
exports.parseTokenArrayFromJson = parseTokenArrayFromJson;
|
|
45843
47347
|
exports.partnerInvariant = partnerInvariant;
|
|
@@ -45845,6 +47349,7 @@ exports.permit2Abi = permit2Abi;
|
|
|
45845
47349
|
exports.polygonSupportedTokens = polygonSupportedTokens;
|
|
45846
47350
|
exports.poolAbi = poolAbi;
|
|
45847
47351
|
exports.poolKeyAbi = poolKeyAbi;
|
|
47352
|
+
exports.projectLeverageLeg = projectLeverageLeg;
|
|
45848
47353
|
exports.randomUint256 = randomUint256;
|
|
45849
47354
|
exports.rayDiv = rayDiv;
|
|
45850
47355
|
exports.rayMul = rayMul;
|
|
@@ -45854,11 +47359,13 @@ exports.recoveryInvariant = recoveryInvariant;
|
|
|
45854
47359
|
exports.redbellySupportedTokens = redbellySupportedTokens;
|
|
45855
47360
|
exports.relayConfig = relayConfig;
|
|
45856
47361
|
exports.relayTxAndWaitPacket = relayTxAndWaitPacket;
|
|
47362
|
+
exports.reportPositionIntent = reportPositionIntent;
|
|
45857
47363
|
exports.requestAddress = requestAddress;
|
|
45858
47364
|
exports.requestJsonRpc = requestJsonRpc;
|
|
45859
47365
|
exports.requestSigning = requestSigning;
|
|
45860
47366
|
exports.resolveAnalytics = resolveAnalytics;
|
|
45861
47367
|
exports.resolveLogger = resolveLogger;
|
|
47368
|
+
exports.resolvePositionFundingAddress = resolvePositionFundingAddress;
|
|
45862
47369
|
exports.retry = retry;
|
|
45863
47370
|
exports.reverseEncodeAddress = reverseEncodeAddress;
|
|
45864
47371
|
exports.robinhoodChain = robinhoodChain;
|
|
@@ -45866,6 +47373,7 @@ exports.robinhoodSupportedTokens = robinhoodSupportedTokens;
|
|
|
45866
47373
|
exports.serializeAddressData = serializeAddressData;
|
|
45867
47374
|
exports.settleWalletBalances = settleWalletBalances;
|
|
45868
47375
|
exports.silentLogger = silentLogger;
|
|
47376
|
+
exports.sizeLeverageBorrow = sizeLeverageBorrow;
|
|
45869
47377
|
exports.sleep = sleep;
|
|
45870
47378
|
exports.sodaxConfig = sodaxConfig;
|
|
45871
47379
|
exports.sodaxInvariant = sodaxInvariant;
|
|
@@ -45893,6 +47401,7 @@ exports.swapExactInSingleParamsAbi = swapExactInSingleParamsAbi;
|
|
|
45893
47401
|
exports.swapInvariant = swapInvariant;
|
|
45894
47402
|
exports.swapSupportedTokens = swapSupportedTokens;
|
|
45895
47403
|
exports.swapsConfig = swapsConfig;
|
|
47404
|
+
exports.timeToBreakevenYears = timeToBreakevenYears;
|
|
45896
47405
|
exports.toCreateBridgeIntentParamsV2 = toCreateBridgeIntentParamsV2;
|
|
45897
47406
|
exports.toSuiExecutionResult = toSuiExecutionResult;
|
|
45898
47407
|
exports.toSuiExecutionStatus = toSuiExecutionStatus;
|