@sodax/sdk 2.2.0-rc.5 → 2.2.0-rc.7
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 +2567 -420
- package/dist/index.d.cts +1272 -60
- package/dist/index.d.ts +1272 -60
- package/dist/index.mjs +2562 -430
- package/package.json +8 -7
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAbiItem, parseAbi, defineChain, isAddress, toHex, hexToBytes, encodeAbiParameters, parseAbiParameters, encodeFunctionData, erc20Abi as erc20Abi$1, createPublicClient, http, bytesToHex, keccak256, stringToBytes, fromHex, encodePacked, decodeAbiParameters, parseEventLogs, isHex, maxUint160, maxUint48, fallback } from 'viem';
|
|
1
|
+
import { getAbiItem, parseAbi, defineChain, isAddress, toHex, hexToBytes, encodeAbiParameters, parseAbiParameters, encodeFunctionData, erc20Abi as erc20Abi$1, createPublicClient, http, bytesToHex, keccak256, stringToBytes, fromHex, encodePacked, decodeAbiParameters, parseEventLogs, isHex, maxUint160, maxUint48, zeroAddress, isAddressEqual, formatUnits, fallback } from 'viem';
|
|
2
2
|
import { initEccLib, address, networks, Transaction, Psbt, payments, opcodes, script } from 'bitcoinjs-lib';
|
|
3
3
|
import { bcs } from '@mysten/sui/bcs';
|
|
4
4
|
import { PublicKey, Connection, VersionedTransaction, SystemProgram, ComputeBudgetProgram, TransactionMessage, TransactionInstruction } from '@solana/web3.js';
|
|
@@ -18,8 +18,10 @@ import { ChainGrpcWasmApi, IndexerGrpcAccountPortfolioApi, TxGrpcApi, toBase64,
|
|
|
18
18
|
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx.js';
|
|
19
19
|
import { getNetworkEndpoints, Network } from '@injectivelabs/networks';
|
|
20
20
|
import * as v from 'valibot';
|
|
21
|
-
import { SwapsApi, SwapsApiError, rawTxSchemaForChainKey
|
|
21
|
+
import { SwapsApi, SwapsApiError, rawTxSchemaForChainKey, makeQuoteResponseSchema, DeadlineResponseSchema, AllowanceCheckResponseSchema, makeApproveResponseSchema, makeCreateIntentResponseSchema, SubmitIntentResponseSchema, StatusResponseSchema, makeCancelIntentResponseSchema, IntentHashResponseSchema, IntentPacketResponseSchema, RelayExtraDataResponseSchema, IntentStateSchema, IntentResponseSchema as IntentResponseSchema$1, GasEstimateResponseSchema, FeeResponseSchema, SubmitTxResponseSchema, SubmitTxStatusResponseSchema } from '@sodax/swaps-api';
|
|
22
22
|
export { SwapsApiError } from '@sodax/swaps-api';
|
|
23
|
+
import { BridgeApi, BridgeApiError } from '@sodax/bridge-api';
|
|
24
|
+
export { BridgeApiError } from '@sodax/bridge-api';
|
|
23
25
|
import BigNumber5, { BigNumber } from 'bignumber.js';
|
|
24
26
|
import { Token, Price } from '@pancakeswap/swap-sdk-core';
|
|
25
27
|
import { sqrtRatioX96ToPrice, PositionMath, tickToPrice, TickMath, maxLiquidityForAmount0Precise, maxLiquidityForAmount1, maxLiquidityForAmounts } from '@pancakeswap/v3-sdk';
|
|
@@ -94,8 +96,8 @@ function serializeCause(cause, depth) {
|
|
|
94
96
|
}
|
|
95
97
|
function sanitizeContext(value, depth) {
|
|
96
98
|
const out = {};
|
|
97
|
-
for (const [key,
|
|
98
|
-
out[key] = sanitizeValue(
|
|
99
|
+
for (const [key, v10] of Object.entries(value)) {
|
|
100
|
+
out[key] = sanitizeValue(v10, depth + 1);
|
|
99
101
|
}
|
|
100
102
|
return out;
|
|
101
103
|
}
|
|
@@ -106,13 +108,13 @@ function sanitizeValue(value, depth) {
|
|
|
106
108
|
if (t === "bigint") return value.toString();
|
|
107
109
|
if (t === "string" || t === "number" || t === "boolean") return value;
|
|
108
110
|
if (t === "function" || t === "symbol") return safeString(value);
|
|
109
|
-
if (Array.isArray(value)) return value.map((
|
|
111
|
+
if (Array.isArray(value)) return value.map((v10) => sanitizeValue(v10, depth + 1));
|
|
110
112
|
if (value instanceof Date) return value.toISOString();
|
|
111
113
|
if (value instanceof Map) {
|
|
112
|
-
return Array.from(value.entries()).map(([k,
|
|
114
|
+
return Array.from(value.entries()).map(([k, v10]) => [sanitizeValue(k, depth + 1), sanitizeValue(v10, depth + 1)]);
|
|
113
115
|
}
|
|
114
116
|
if (value instanceof Set) {
|
|
115
|
-
return Array.from(value.values()).map((
|
|
117
|
+
return Array.from(value.values()).map((v10) => sanitizeValue(v10, depth + 1));
|
|
116
118
|
}
|
|
117
119
|
if (value instanceof Error) return { name: value.name, message: value.message };
|
|
118
120
|
if (t === "object") {
|
|
@@ -124,9 +126,9 @@ function sanitizeValue(value, depth) {
|
|
|
124
126
|
}
|
|
125
127
|
return safeString(value);
|
|
126
128
|
}
|
|
127
|
-
function safeString(
|
|
129
|
+
function safeString(v10) {
|
|
128
130
|
try {
|
|
129
|
-
return String(
|
|
131
|
+
return String(v10);
|
|
130
132
|
} catch {
|
|
131
133
|
return "[unserializable]";
|
|
132
134
|
}
|
|
@@ -338,7 +340,18 @@ var HubVaultSymbols = [
|
|
|
338
340
|
"QQQ",
|
|
339
341
|
"SGOV",
|
|
340
342
|
"USO",
|
|
341
|
-
"SLV"
|
|
343
|
+
"SLV",
|
|
344
|
+
"GOOGL",
|
|
345
|
+
"AMZN",
|
|
346
|
+
"MSFT",
|
|
347
|
+
"META",
|
|
348
|
+
"CRCL",
|
|
349
|
+
"COIN",
|
|
350
|
+
"PLTR",
|
|
351
|
+
"TSM",
|
|
352
|
+
"AMD",
|
|
353
|
+
"INTC",
|
|
354
|
+
"BABA"
|
|
342
355
|
];
|
|
343
356
|
var SodaTokens = {
|
|
344
357
|
sodaBNB: {
|
|
@@ -731,6 +744,116 @@ var SodaTokens = {
|
|
|
731
744
|
chainKey: ChainKeys.SONIC_MAINNET,
|
|
732
745
|
hubAsset: "0x690B92c27ac80015E57DB8cc02A81255814f49A2",
|
|
733
746
|
vault: "0x690B92c27ac80015E57DB8cc02A81255814f49A2"
|
|
747
|
+
},
|
|
748
|
+
GOOGL: {
|
|
749
|
+
symbol: "GOOGL",
|
|
750
|
+
isRwa: true,
|
|
751
|
+
name: "Alphabet Class A \u2022 Robinhood Token",
|
|
752
|
+
decimals: 18,
|
|
753
|
+
address: "0xBdB4445a05726E26C26EA30dF0C1970DF4Cf4Be3",
|
|
754
|
+
chainKey: ChainKeys.SONIC_MAINNET,
|
|
755
|
+
hubAsset: "0xBdB4445a05726E26C26EA30dF0C1970DF4Cf4Be3",
|
|
756
|
+
vault: "0xBdB4445a05726E26C26EA30dF0C1970DF4Cf4Be3"
|
|
757
|
+
},
|
|
758
|
+
AMZN: {
|
|
759
|
+
symbol: "AMZN",
|
|
760
|
+
isRwa: true,
|
|
761
|
+
name: "Amazon \u2022 Robinhood Token",
|
|
762
|
+
decimals: 18,
|
|
763
|
+
address: "0xc467cAC3e69C2eb41Cc9b32Aa1A7a54F942243Ba",
|
|
764
|
+
chainKey: ChainKeys.SONIC_MAINNET,
|
|
765
|
+
hubAsset: "0xc467cAC3e69C2eb41Cc9b32Aa1A7a54F942243Ba",
|
|
766
|
+
vault: "0xc467cAC3e69C2eb41Cc9b32Aa1A7a54F942243Ba"
|
|
767
|
+
},
|
|
768
|
+
MSFT: {
|
|
769
|
+
symbol: "MSFT",
|
|
770
|
+
isRwa: true,
|
|
771
|
+
name: "Microsoft \u2022 Robinhood Token",
|
|
772
|
+
decimals: 18,
|
|
773
|
+
address: "0x66A3bc5a66D3c66dc42031775Ea3eedc37347FeC",
|
|
774
|
+
chainKey: ChainKeys.SONIC_MAINNET,
|
|
775
|
+
hubAsset: "0x66A3bc5a66D3c66dc42031775Ea3eedc37347FeC",
|
|
776
|
+
vault: "0x66A3bc5a66D3c66dc42031775Ea3eedc37347FeC"
|
|
777
|
+
},
|
|
778
|
+
META: {
|
|
779
|
+
symbol: "META",
|
|
780
|
+
isRwa: true,
|
|
781
|
+
name: "Meta Platforms \u2022 Robinhood Token",
|
|
782
|
+
decimals: 18,
|
|
783
|
+
address: "0xB7686E0a03542230927CAC76Fe7566656439F3c6",
|
|
784
|
+
chainKey: ChainKeys.SONIC_MAINNET,
|
|
785
|
+
hubAsset: "0xB7686E0a03542230927CAC76Fe7566656439F3c6",
|
|
786
|
+
vault: "0xB7686E0a03542230927CAC76Fe7566656439F3c6"
|
|
787
|
+
},
|
|
788
|
+
CRCL: {
|
|
789
|
+
symbol: "CRCL",
|
|
790
|
+
isRwa: true,
|
|
791
|
+
name: "Circle Internet Group \u2022 Robinhood Token",
|
|
792
|
+
decimals: 18,
|
|
793
|
+
address: "0x1e264ceEEb59F7425D64362Bf12A5b2648B6e66d",
|
|
794
|
+
chainKey: ChainKeys.SONIC_MAINNET,
|
|
795
|
+
hubAsset: "0x1e264ceEEb59F7425D64362Bf12A5b2648B6e66d",
|
|
796
|
+
vault: "0x1e264ceEEb59F7425D64362Bf12A5b2648B6e66d"
|
|
797
|
+
},
|
|
798
|
+
COIN: {
|
|
799
|
+
symbol: "COIN",
|
|
800
|
+
isRwa: true,
|
|
801
|
+
name: "Coinbase \u2022 Robinhood Token",
|
|
802
|
+
decimals: 18,
|
|
803
|
+
address: "0x5540d60F879F5D470bF9Ed7d23FFd59Acc10da0c",
|
|
804
|
+
chainKey: ChainKeys.SONIC_MAINNET,
|
|
805
|
+
hubAsset: "0x5540d60F879F5D470bF9Ed7d23FFd59Acc10da0c",
|
|
806
|
+
vault: "0x5540d60F879F5D470bF9Ed7d23FFd59Acc10da0c"
|
|
807
|
+
},
|
|
808
|
+
PLTR: {
|
|
809
|
+
symbol: "PLTR",
|
|
810
|
+
isRwa: true,
|
|
811
|
+
name: "Palantir Technologies \u2022 Robinhood Token",
|
|
812
|
+
decimals: 18,
|
|
813
|
+
address: "0xA24710Ab6A5e1ef3a7CF3a0333d8bE2bf22782DC",
|
|
814
|
+
chainKey: ChainKeys.SONIC_MAINNET,
|
|
815
|
+
hubAsset: "0xA24710Ab6A5e1ef3a7CF3a0333d8bE2bf22782DC",
|
|
816
|
+
vault: "0xA24710Ab6A5e1ef3a7CF3a0333d8bE2bf22782DC"
|
|
817
|
+
},
|
|
818
|
+
TSM: {
|
|
819
|
+
symbol: "TSM",
|
|
820
|
+
isRwa: true,
|
|
821
|
+
name: "Taiwan Semiconductor Manufacturing \u2022 Robinhood Token",
|
|
822
|
+
decimals: 18,
|
|
823
|
+
address: "0xAF9992b0cA54e014ff1EC7fA77AADE973Dba793e",
|
|
824
|
+
chainKey: ChainKeys.SONIC_MAINNET,
|
|
825
|
+
hubAsset: "0xAF9992b0cA54e014ff1EC7fA77AADE973Dba793e",
|
|
826
|
+
vault: "0xAF9992b0cA54e014ff1EC7fA77AADE973Dba793e"
|
|
827
|
+
},
|
|
828
|
+
AMD: {
|
|
829
|
+
symbol: "AMD",
|
|
830
|
+
isRwa: true,
|
|
831
|
+
name: "AMD \u2022 Robinhood Token",
|
|
832
|
+
decimals: 18,
|
|
833
|
+
address: "0xc8124Db156d8F6C7446C040c503FFEAe82383D1B",
|
|
834
|
+
chainKey: ChainKeys.SONIC_MAINNET,
|
|
835
|
+
hubAsset: "0xc8124Db156d8F6C7446C040c503FFEAe82383D1B",
|
|
836
|
+
vault: "0xc8124Db156d8F6C7446C040c503FFEAe82383D1B"
|
|
837
|
+
},
|
|
838
|
+
INTC: {
|
|
839
|
+
symbol: "INTC",
|
|
840
|
+
isRwa: true,
|
|
841
|
+
name: "Intel \u2022 Robinhood Token",
|
|
842
|
+
decimals: 18,
|
|
843
|
+
address: "0x5352F9Bf2f58720f8a8CC4D4eDEE56700Bd3d053",
|
|
844
|
+
chainKey: ChainKeys.SONIC_MAINNET,
|
|
845
|
+
hubAsset: "0x5352F9Bf2f58720f8a8CC4D4eDEE56700Bd3d053",
|
|
846
|
+
vault: "0x5352F9Bf2f58720f8a8CC4D4eDEE56700Bd3d053"
|
|
847
|
+
},
|
|
848
|
+
BABA: {
|
|
849
|
+
symbol: "BABA",
|
|
850
|
+
isRwa: true,
|
|
851
|
+
name: "Alibaba \u2022 Robinhood Token",
|
|
852
|
+
decimals: 18,
|
|
853
|
+
address: "0x1BeD0547D76F6424e9A3465b36F6dcDCF798A5cf",
|
|
854
|
+
chainKey: ChainKeys.SONIC_MAINNET,
|
|
855
|
+
hubAsset: "0x1BeD0547D76F6424e9A3465b36F6dcDCF798A5cf",
|
|
856
|
+
vault: "0x1BeD0547D76F6424e9A3465b36F6dcDCF798A5cf"
|
|
734
857
|
}
|
|
735
858
|
};
|
|
736
859
|
var LsodaSymbols = ["lsodaWEETH", "lsodaWSTETH", "lsodaJITOSOL", "lsodaSUSDS"];
|
|
@@ -1524,6 +1647,15 @@ var baseSupportedTokens = {
|
|
|
1524
1647
|
chainKey: ChainKeys.BASE_MAINNET,
|
|
1525
1648
|
hubAsset: "0x348e086ab6f424dfc575a325c28624ed23973173",
|
|
1526
1649
|
vault: "0x348e086ab6f424dfc575a325c28624ed23973173"
|
|
1650
|
+
},
|
|
1651
|
+
sUSDS: {
|
|
1652
|
+
symbol: "sUSDS",
|
|
1653
|
+
name: "staked USDS",
|
|
1654
|
+
decimals: 18,
|
|
1655
|
+
address: "0x5875eEE11Cf8398102FdAd704C9E96607675467a",
|
|
1656
|
+
chainKey: ChainKeys.BASE_MAINNET,
|
|
1657
|
+
hubAsset: "0x807cC73f69F1aCCC50511a0390A8544cEA71baA9",
|
|
1658
|
+
vault: SodaTokens.sodaSUSDS.address
|
|
1527
1659
|
}
|
|
1528
1660
|
};
|
|
1529
1661
|
var optimismSupportedTokens = {
|
|
@@ -1607,6 +1739,15 @@ var optimismSupportedTokens = {
|
|
|
1607
1739
|
chainKey: ChainKeys.OPTIMISM_MAINNET,
|
|
1608
1740
|
hubAsset: "0xd08375176410febee9cf4591532455a4cdfe4463",
|
|
1609
1741
|
vault: "0xd08375176410febee9cf4591532455a4cdfe4463"
|
|
1742
|
+
},
|
|
1743
|
+
sUSDS: {
|
|
1744
|
+
symbol: "sUSDS",
|
|
1745
|
+
name: "staked USDS",
|
|
1746
|
+
decimals: 18,
|
|
1747
|
+
address: "0xb5B2dc7fd34C249F4be7fB1fCea07950784229e0",
|
|
1748
|
+
chainKey: ChainKeys.OPTIMISM_MAINNET,
|
|
1749
|
+
hubAsset: "0xb9a9cb8A61D30a8F6b7E24491ab83f43E817b0E2",
|
|
1750
|
+
vault: SodaTokens.sodaSUSDS.address
|
|
1610
1751
|
}
|
|
1611
1752
|
};
|
|
1612
1753
|
var bscSupportedTokens = {
|
|
@@ -2471,6 +2612,116 @@ var stellarSupportedTokens = {
|
|
|
2471
2612
|
chainKey: ChainKeys.STELLAR_MAINNET,
|
|
2472
2613
|
hubAsset: "0x7eaF987431ce072feBEB2124fEB4d1cEf8Cf4e2e",
|
|
2473
2614
|
vault: SodaTokens.SLV.address
|
|
2615
|
+
},
|
|
2616
|
+
GOOGL: {
|
|
2617
|
+
symbol: "GOOGL",
|
|
2618
|
+
isRwa: true,
|
|
2619
|
+
name: "Alphabet Class A",
|
|
2620
|
+
decimals: 7,
|
|
2621
|
+
address: "CCZLQHO22HLQARS26KNSJ4DU3FCFG45VG6RZQOQDQ4MHTSUVGRX57VWD",
|
|
2622
|
+
chainKey: ChainKeys.STELLAR_MAINNET,
|
|
2623
|
+
hubAsset: "0x3DE82bcf9D6a1CE8CB9b9eBCD6fC2916c548CD19",
|
|
2624
|
+
vault: SodaTokens.GOOGL.address
|
|
2625
|
+
},
|
|
2626
|
+
AMZN: {
|
|
2627
|
+
symbol: "AMZN",
|
|
2628
|
+
isRwa: true,
|
|
2629
|
+
name: "Amazon",
|
|
2630
|
+
decimals: 7,
|
|
2631
|
+
address: "CBN6JFMCVKXOIRRERGPH7CGY7RIIHGRLVSFJCD3KBMYSUEZAQR3MJ7TF",
|
|
2632
|
+
chainKey: ChainKeys.STELLAR_MAINNET,
|
|
2633
|
+
hubAsset: "0x30A6383A1d39b40B038EB82fd0F1fb7F77580623",
|
|
2634
|
+
vault: SodaTokens.AMZN.address
|
|
2635
|
+
},
|
|
2636
|
+
MSFT: {
|
|
2637
|
+
symbol: "MSFT",
|
|
2638
|
+
isRwa: true,
|
|
2639
|
+
name: "Microsoft",
|
|
2640
|
+
decimals: 7,
|
|
2641
|
+
address: "CA53FXC2RF3BNIGLCPE3PNS3SZ2AONVRKH46AIHPEJOA54LGI2DYSOAD",
|
|
2642
|
+
chainKey: ChainKeys.STELLAR_MAINNET,
|
|
2643
|
+
hubAsset: "0xDb89f97afc524c95a02a001aE16fe946e2f2e4A6",
|
|
2644
|
+
vault: SodaTokens.MSFT.address
|
|
2645
|
+
},
|
|
2646
|
+
META: {
|
|
2647
|
+
symbol: "META",
|
|
2648
|
+
isRwa: true,
|
|
2649
|
+
name: "Meta",
|
|
2650
|
+
decimals: 7,
|
|
2651
|
+
address: "CA4AXIRO72PC566XUIYVN2365347I7TVGYULXW7QDVCIXBOEFFRXGP67",
|
|
2652
|
+
chainKey: ChainKeys.STELLAR_MAINNET,
|
|
2653
|
+
hubAsset: "0xd2ff91513Cc08b5Bf4A07F1829A04273Bb902445",
|
|
2654
|
+
vault: SodaTokens.META.address
|
|
2655
|
+
},
|
|
2656
|
+
CRCL: {
|
|
2657
|
+
symbol: "CRCL",
|
|
2658
|
+
isRwa: true,
|
|
2659
|
+
name: "Circle",
|
|
2660
|
+
decimals: 7,
|
|
2661
|
+
address: "CDMRGHCY23UVTFYYW6U2NBYGME2VVPDO6OJXLZMM7FNGVFX3V42SAA4C",
|
|
2662
|
+
chainKey: ChainKeys.STELLAR_MAINNET,
|
|
2663
|
+
hubAsset: "0x1599b2754f0fC9429b3CDA12823B19eb2463F1cc",
|
|
2664
|
+
vault: SodaTokens.CRCL.address
|
|
2665
|
+
},
|
|
2666
|
+
COIN: {
|
|
2667
|
+
symbol: "COIN",
|
|
2668
|
+
isRwa: true,
|
|
2669
|
+
name: "Coinbase",
|
|
2670
|
+
decimals: 7,
|
|
2671
|
+
address: "CAKCNNQFIYAQBU7RXWPW3ZH4IWDXGMXUB6WTGCEZSI2EZ6WSTCCCEFHO",
|
|
2672
|
+
chainKey: ChainKeys.STELLAR_MAINNET,
|
|
2673
|
+
hubAsset: "0xaaB281239e25d7E637b4053C832D9b3b495c0261",
|
|
2674
|
+
vault: SodaTokens.COIN.address
|
|
2675
|
+
},
|
|
2676
|
+
PLTR: {
|
|
2677
|
+
symbol: "PLTR",
|
|
2678
|
+
isRwa: true,
|
|
2679
|
+
name: "Palantir",
|
|
2680
|
+
decimals: 7,
|
|
2681
|
+
address: "CC3EVVVQAB2BZFAJHPZWVRANTVVS37OJXNJKR2DVPAMG5FOYRPIIGCEV",
|
|
2682
|
+
chainKey: ChainKeys.STELLAR_MAINNET,
|
|
2683
|
+
hubAsset: "0x948195294e506cd42C00418269ab0E53EFAE5171",
|
|
2684
|
+
vault: SodaTokens.PLTR.address
|
|
2685
|
+
},
|
|
2686
|
+
TSM: {
|
|
2687
|
+
symbol: "TSM",
|
|
2688
|
+
isRwa: true,
|
|
2689
|
+
name: "Taiwan Semiconductor",
|
|
2690
|
+
decimals: 7,
|
|
2691
|
+
address: "CBZFBO44J4RSRZZ7PT7BHLLID6L7C4HL77YLVFCNIIXZQKVLNL6VEAD6",
|
|
2692
|
+
chainKey: ChainKeys.STELLAR_MAINNET,
|
|
2693
|
+
hubAsset: "0x276a0aB35C5eBD286076F69c58dA6AbB22c326Bf",
|
|
2694
|
+
vault: SodaTokens.TSM.address
|
|
2695
|
+
},
|
|
2696
|
+
AMD: {
|
|
2697
|
+
symbol: "AMD",
|
|
2698
|
+
isRwa: true,
|
|
2699
|
+
name: "AMD",
|
|
2700
|
+
decimals: 7,
|
|
2701
|
+
address: "CCIE4OXPJUPLNRLGAENNSDEZTQUXTXKAPU322Z3HMATZSR2S2DAAGYQD",
|
|
2702
|
+
chainKey: ChainKeys.STELLAR_MAINNET,
|
|
2703
|
+
hubAsset: "0x16a8d54d04Ee9cbcC57Fe7C4838bEA83294Fb646",
|
|
2704
|
+
vault: SodaTokens.AMD.address
|
|
2705
|
+
},
|
|
2706
|
+
INTC: {
|
|
2707
|
+
symbol: "INTC",
|
|
2708
|
+
isRwa: true,
|
|
2709
|
+
name: "Intel",
|
|
2710
|
+
decimals: 7,
|
|
2711
|
+
address: "CBD7GPTTHNFWBX7CYOM7O3N2TCZIAYT6FT4LCAXKX4JCZ3ZJL2IF7E4B",
|
|
2712
|
+
chainKey: ChainKeys.STELLAR_MAINNET,
|
|
2713
|
+
hubAsset: "0x34FC8F280c7C345A9aFC6E00F652F75b1fB2bd22",
|
|
2714
|
+
vault: SodaTokens.INTC.address
|
|
2715
|
+
},
|
|
2716
|
+
BABA: {
|
|
2717
|
+
symbol: "BABA",
|
|
2718
|
+
isRwa: true,
|
|
2719
|
+
name: "Alibaba",
|
|
2720
|
+
decimals: 7,
|
|
2721
|
+
address: "CDARDTMGSEXTYJDSKDEAA52DCYX3OZEP7SOLSF5CT3QSSAGBETWH7LO3",
|
|
2722
|
+
chainKey: ChainKeys.STELLAR_MAINNET,
|
|
2723
|
+
hubAsset: "0x83ac05C492188B46dd15d5611dEEFA6b23c7D479",
|
|
2724
|
+
vault: SodaTokens.BABA.address
|
|
2474
2725
|
}
|
|
2475
2726
|
};
|
|
2476
2727
|
var suiSupportedTokens = {
|
|
@@ -2961,6 +3212,15 @@ var ethereumSupportedTokens = {
|
|
|
2961
3212
|
chainKey: ChainKeys.ETHEREUM_MAINNET,
|
|
2962
3213
|
hubAsset: "0x40bea4f921355a749f460760ba6f8edd78888164",
|
|
2963
3214
|
vault: "0x40bea4f921355a749f460760ba6f8edd78888164"
|
|
3215
|
+
},
|
|
3216
|
+
sUSDS: {
|
|
3217
|
+
symbol: "sUSDS",
|
|
3218
|
+
name: "staked USDS",
|
|
3219
|
+
decimals: 18,
|
|
3220
|
+
address: "0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD",
|
|
3221
|
+
chainKey: ChainKeys.ETHEREUM_MAINNET,
|
|
3222
|
+
hubAsset: "0x1Bb5128A4837A78cb60bc52cc19079eD3F00A624",
|
|
3223
|
+
vault: SodaTokens.sodaSUSDS.address
|
|
2964
3224
|
}
|
|
2965
3225
|
};
|
|
2966
3226
|
var kaiaSupportedTokens = {
|
|
@@ -3275,6 +3535,116 @@ var hederaSupportedTokens = {
|
|
|
3275
3535
|
chainKey: ChainKeys.HEDERA_MAINNET,
|
|
3276
3536
|
hubAsset: "0x914672C5336f5E00126e431368005f7C22aCe952",
|
|
3277
3537
|
vault: SodaTokens.SLV.address
|
|
3538
|
+
},
|
|
3539
|
+
GOOGL: {
|
|
3540
|
+
symbol: "GOOGL",
|
|
3541
|
+
isRwa: true,
|
|
3542
|
+
name: "Alphabet Class A",
|
|
3543
|
+
decimals: 8,
|
|
3544
|
+
address: "0x0000000000000000000000000000000000a605ce",
|
|
3545
|
+
chainKey: ChainKeys.HEDERA_MAINNET,
|
|
3546
|
+
hubAsset: "0xA4942e1edE99034b11657C8a0978f8E2342980b4",
|
|
3547
|
+
vault: SodaTokens.GOOGL.address
|
|
3548
|
+
},
|
|
3549
|
+
AMZN: {
|
|
3550
|
+
symbol: "AMZN",
|
|
3551
|
+
isRwa: true,
|
|
3552
|
+
name: "Amazon",
|
|
3553
|
+
decimals: 8,
|
|
3554
|
+
address: "0x0000000000000000000000000000000000a605d0",
|
|
3555
|
+
chainKey: ChainKeys.HEDERA_MAINNET,
|
|
3556
|
+
hubAsset: "0x13E3E4eaaa02bbD0A32094c6C7078D4ABa24cd04",
|
|
3557
|
+
vault: SodaTokens.AMZN.address
|
|
3558
|
+
},
|
|
3559
|
+
MSFT: {
|
|
3560
|
+
symbol: "MSFT",
|
|
3561
|
+
isRwa: true,
|
|
3562
|
+
name: "Microsoft",
|
|
3563
|
+
decimals: 8,
|
|
3564
|
+
address: "0x0000000000000000000000000000000000a605d2",
|
|
3565
|
+
chainKey: ChainKeys.HEDERA_MAINNET,
|
|
3566
|
+
hubAsset: "0x5b9838715bbeFF2E8752961C418f64CAB3e7B2eD",
|
|
3567
|
+
vault: SodaTokens.MSFT.address
|
|
3568
|
+
},
|
|
3569
|
+
META: {
|
|
3570
|
+
symbol: "META",
|
|
3571
|
+
isRwa: true,
|
|
3572
|
+
name: "Meta",
|
|
3573
|
+
decimals: 8,
|
|
3574
|
+
address: "0x0000000000000000000000000000000000a605d3",
|
|
3575
|
+
chainKey: ChainKeys.HEDERA_MAINNET,
|
|
3576
|
+
hubAsset: "0xbe8a7cAFABe2399b4d751A5545017cc09D83FFc9",
|
|
3577
|
+
vault: SodaTokens.META.address
|
|
3578
|
+
},
|
|
3579
|
+
CRCL: {
|
|
3580
|
+
symbol: "CRCL",
|
|
3581
|
+
isRwa: true,
|
|
3582
|
+
name: "Circle",
|
|
3583
|
+
decimals: 8,
|
|
3584
|
+
address: "0x0000000000000000000000000000000000a605d4",
|
|
3585
|
+
chainKey: ChainKeys.HEDERA_MAINNET,
|
|
3586
|
+
hubAsset: "0x13c16a6a19a637fBf370CcA8d7f4bD38d207b620",
|
|
3587
|
+
vault: SodaTokens.CRCL.address
|
|
3588
|
+
},
|
|
3589
|
+
COIN: {
|
|
3590
|
+
symbol: "COIN",
|
|
3591
|
+
isRwa: true,
|
|
3592
|
+
name: "Coinbase",
|
|
3593
|
+
decimals: 8,
|
|
3594
|
+
address: "0x0000000000000000000000000000000000a605d6",
|
|
3595
|
+
chainKey: ChainKeys.HEDERA_MAINNET,
|
|
3596
|
+
hubAsset: "0x4d82303a0cf66f3D98E8140a1668567E748685De",
|
|
3597
|
+
vault: SodaTokens.COIN.address
|
|
3598
|
+
},
|
|
3599
|
+
PLTR: {
|
|
3600
|
+
symbol: "PLTR",
|
|
3601
|
+
isRwa: true,
|
|
3602
|
+
name: "Palantir",
|
|
3603
|
+
decimals: 8,
|
|
3604
|
+
address: "0x0000000000000000000000000000000000a605d7",
|
|
3605
|
+
chainKey: ChainKeys.HEDERA_MAINNET,
|
|
3606
|
+
hubAsset: "0xEC98d565853064667Ec5512bc6B7183D54b9EF40",
|
|
3607
|
+
vault: SodaTokens.PLTR.address
|
|
3608
|
+
},
|
|
3609
|
+
TSM: {
|
|
3610
|
+
symbol: "TSM",
|
|
3611
|
+
isRwa: true,
|
|
3612
|
+
name: "Taiwan Semiconductor",
|
|
3613
|
+
decimals: 8,
|
|
3614
|
+
address: "0x0000000000000000000000000000000000a605d9",
|
|
3615
|
+
chainKey: ChainKeys.HEDERA_MAINNET,
|
|
3616
|
+
hubAsset: "0x87FB178434B5832Df1Defa3E3E51dA3e4F1ECb10",
|
|
3617
|
+
vault: SodaTokens.TSM.address
|
|
3618
|
+
},
|
|
3619
|
+
AMD: {
|
|
3620
|
+
symbol: "AMD",
|
|
3621
|
+
isRwa: true,
|
|
3622
|
+
name: "AMD",
|
|
3623
|
+
decimals: 8,
|
|
3624
|
+
address: "0x0000000000000000000000000000000000a605db",
|
|
3625
|
+
chainKey: ChainKeys.HEDERA_MAINNET,
|
|
3626
|
+
hubAsset: "0x26b9C3af52e764b8362cDD273b443E576F960e36",
|
|
3627
|
+
vault: SodaTokens.AMD.address
|
|
3628
|
+
},
|
|
3629
|
+
INTC: {
|
|
3630
|
+
symbol: "INTC",
|
|
3631
|
+
isRwa: true,
|
|
3632
|
+
name: "Intel",
|
|
3633
|
+
decimals: 8,
|
|
3634
|
+
address: "0x0000000000000000000000000000000000a605dc",
|
|
3635
|
+
chainKey: ChainKeys.HEDERA_MAINNET,
|
|
3636
|
+
hubAsset: "0xb4Fe614a0566e64A0352645485BB4EbCaf8F3a9E",
|
|
3637
|
+
vault: SodaTokens.INTC.address
|
|
3638
|
+
},
|
|
3639
|
+
BABA: {
|
|
3640
|
+
symbol: "BABA",
|
|
3641
|
+
isRwa: true,
|
|
3642
|
+
name: "Alibaba",
|
|
3643
|
+
decimals: 8,
|
|
3644
|
+
address: "0x0000000000000000000000000000000000a605dd",
|
|
3645
|
+
chainKey: ChainKeys.HEDERA_MAINNET,
|
|
3646
|
+
hubAsset: "0x5e69df859F7c2b170E5fdAdbD59d06C2CD287753",
|
|
3647
|
+
vault: SodaTokens.BABA.address
|
|
3278
3648
|
}
|
|
3279
3649
|
};
|
|
3280
3650
|
var robinhoodSupportedTokens = {
|
|
@@ -3448,6 +3818,116 @@ var robinhoodSupportedTokens = {
|
|
|
3448
3818
|
chainKey: ChainKeys.ROBINHOOD_MAINNET,
|
|
3449
3819
|
hubAsset: "0x17348849806c8b1b5d1d3abbcb527d05d21d09d5",
|
|
3450
3820
|
vault: SodaTokens.SLV.address
|
|
3821
|
+
},
|
|
3822
|
+
GOOGL: {
|
|
3823
|
+
symbol: "GOOGL",
|
|
3824
|
+
isRwa: true,
|
|
3825
|
+
name: "Alphabet Class A",
|
|
3826
|
+
decimals: 18,
|
|
3827
|
+
address: "0x2e0847E8910a9732eB3fb1bb4b70a580ADAD4FE3",
|
|
3828
|
+
chainKey: ChainKeys.ROBINHOOD_MAINNET,
|
|
3829
|
+
hubAsset: "0xb99725463347b57cb6b38e3670e79bae68361178",
|
|
3830
|
+
vault: SodaTokens.GOOGL.address
|
|
3831
|
+
},
|
|
3832
|
+
AMZN: {
|
|
3833
|
+
symbol: "AMZN",
|
|
3834
|
+
isRwa: true,
|
|
3835
|
+
name: "Amazon",
|
|
3836
|
+
decimals: 18,
|
|
3837
|
+
address: "0x12f190a9F9d7D37a250758b26824B97CE941bF54",
|
|
3838
|
+
chainKey: ChainKeys.ROBINHOOD_MAINNET,
|
|
3839
|
+
hubAsset: "0x191b01f7816f927eede6603bae14979a80880f2e",
|
|
3840
|
+
vault: SodaTokens.AMZN.address
|
|
3841
|
+
},
|
|
3842
|
+
MSFT: {
|
|
3843
|
+
symbol: "MSFT",
|
|
3844
|
+
isRwa: true,
|
|
3845
|
+
name: "Microsoft",
|
|
3846
|
+
decimals: 18,
|
|
3847
|
+
address: "0xe93237C50D904957Cf27E7B1133b510C669c2e74",
|
|
3848
|
+
chainKey: ChainKeys.ROBINHOOD_MAINNET,
|
|
3849
|
+
hubAsset: "0x54cd74d27c647cccc7d151c198a82a8f3371ca35",
|
|
3850
|
+
vault: SodaTokens.MSFT.address
|
|
3851
|
+
},
|
|
3852
|
+
META: {
|
|
3853
|
+
symbol: "META",
|
|
3854
|
+
isRwa: true,
|
|
3855
|
+
name: "Meta",
|
|
3856
|
+
decimals: 18,
|
|
3857
|
+
address: "0xc0D6457C16Cc70d6790Dd43521C899C87ce02f35",
|
|
3858
|
+
chainKey: ChainKeys.ROBINHOOD_MAINNET,
|
|
3859
|
+
hubAsset: "0xf5661eefaebb0ed9f33c543fa606ad77646eb1f9",
|
|
3860
|
+
vault: SodaTokens.META.address
|
|
3861
|
+
},
|
|
3862
|
+
CRCL: {
|
|
3863
|
+
symbol: "CRCL",
|
|
3864
|
+
isRwa: true,
|
|
3865
|
+
name: "Circle",
|
|
3866
|
+
decimals: 18,
|
|
3867
|
+
address: "0xdF0992E440dD0be65BD8439b609d6D4366bf1CB5",
|
|
3868
|
+
chainKey: ChainKeys.ROBINHOOD_MAINNET,
|
|
3869
|
+
hubAsset: "0x18f4018af0bf9fc42cbf8c0b458a838bc2dccf43",
|
|
3870
|
+
vault: SodaTokens.CRCL.address
|
|
3871
|
+
},
|
|
3872
|
+
COIN: {
|
|
3873
|
+
symbol: "COIN",
|
|
3874
|
+
isRwa: true,
|
|
3875
|
+
name: "Coinbase",
|
|
3876
|
+
decimals: 18,
|
|
3877
|
+
address: "0x6330D8C3178a418788dF01a47479c0ce7CCF450b",
|
|
3878
|
+
chainKey: ChainKeys.ROBINHOOD_MAINNET,
|
|
3879
|
+
hubAsset: "0x91789d24454c40c753bdd5bc7ada7bb91848d13c",
|
|
3880
|
+
vault: SodaTokens.COIN.address
|
|
3881
|
+
},
|
|
3882
|
+
PLTR: {
|
|
3883
|
+
symbol: "PLTR",
|
|
3884
|
+
isRwa: true,
|
|
3885
|
+
name: "Palantir",
|
|
3886
|
+
decimals: 18,
|
|
3887
|
+
address: "0x894E1EC2D74FFE5AEF8Dc8A9e84686acCB964F2A",
|
|
3888
|
+
chainKey: ChainKeys.ROBINHOOD_MAINNET,
|
|
3889
|
+
hubAsset: "0x99864e96d71860e6e5d25887a10da823685af1ee",
|
|
3890
|
+
vault: SodaTokens.PLTR.address
|
|
3891
|
+
},
|
|
3892
|
+
TSM: {
|
|
3893
|
+
symbol: "TSM",
|
|
3894
|
+
isRwa: true,
|
|
3895
|
+
name: "Taiwan Semiconductor",
|
|
3896
|
+
decimals: 18,
|
|
3897
|
+
address: "0x58FfE4a942d3885bAa22D7520691F611EF09e7AA",
|
|
3898
|
+
chainKey: ChainKeys.ROBINHOOD_MAINNET,
|
|
3899
|
+
hubAsset: "0x5912b35ed196b129f4ad36ffd8717f2913df09bf",
|
|
3900
|
+
vault: SodaTokens.TSM.address
|
|
3901
|
+
},
|
|
3902
|
+
AMD: {
|
|
3903
|
+
symbol: "AMD",
|
|
3904
|
+
isRwa: true,
|
|
3905
|
+
name: "AMD",
|
|
3906
|
+
decimals: 18,
|
|
3907
|
+
address: "0x86923f96303D656E4aa86D9d42D1e57ad2023fdC",
|
|
3908
|
+
chainKey: ChainKeys.ROBINHOOD_MAINNET,
|
|
3909
|
+
hubAsset: "0x433d44c65f20e4a776aed6c23838739d3155a692",
|
|
3910
|
+
vault: SodaTokens.AMD.address
|
|
3911
|
+
},
|
|
3912
|
+
INTC: {
|
|
3913
|
+
symbol: "INTC",
|
|
3914
|
+
isRwa: true,
|
|
3915
|
+
name: "Intel",
|
|
3916
|
+
decimals: 18,
|
|
3917
|
+
address: "0xc72b96e0E48ecd4DC75E1e45396e26300BC39681",
|
|
3918
|
+
chainKey: ChainKeys.ROBINHOOD_MAINNET,
|
|
3919
|
+
hubAsset: "0xd20c60e725317c7873964a6b1d345b2507526e59",
|
|
3920
|
+
vault: SodaTokens.INTC.address
|
|
3921
|
+
},
|
|
3922
|
+
BABA: {
|
|
3923
|
+
symbol: "BABA",
|
|
3924
|
+
isRwa: true,
|
|
3925
|
+
name: "Alibaba",
|
|
3926
|
+
decimals: 18,
|
|
3927
|
+
address: "0xad25Ac6C84D497db898fa1E8387bf6Af3532a1c4",
|
|
3928
|
+
chainKey: ChainKeys.ROBINHOOD_MAINNET,
|
|
3929
|
+
hubAsset: "0xf721a074bd9fc05ba1f7cb432149a74acfb49d73",
|
|
3930
|
+
vault: SodaTokens.BABA.address
|
|
3451
3931
|
}
|
|
3452
3932
|
};
|
|
3453
3933
|
var stacksSupportedTokens = {
|
|
@@ -4286,6 +4766,61 @@ var spokeChainConfig = {
|
|
|
4286
4766
|
assetCode: "SLV",
|
|
4287
4767
|
contractId: "CBY3U32O5T2B555HNJLX6C6HW3O2FLRSJGH472UOOHT6H6ZMGMSSZTLW",
|
|
4288
4768
|
assetIssuer: "GDYUTHY75A7WUZJQDPOP66FB32BOYGZRXHWTWO4Q6LQTANT5X3V5HNFA"
|
|
4769
|
+
},
|
|
4770
|
+
{
|
|
4771
|
+
assetCode: "GOOGL",
|
|
4772
|
+
contractId: "CCZLQHO22HLQARS26KNSJ4DU3FCFG45VG6RZQOQDQ4MHTSUVGRX57VWD",
|
|
4773
|
+
assetIssuer: "GDYUTHY75A7WUZJQDPOP66FB32BOYGZRXHWTWO4Q6LQTANT5X3V5HNFA"
|
|
4774
|
+
},
|
|
4775
|
+
{
|
|
4776
|
+
assetCode: "AMZN",
|
|
4777
|
+
contractId: "CBN6JFMCVKXOIRRERGPH7CGY7RIIHGRLVSFJCD3KBMYSUEZAQR3MJ7TF",
|
|
4778
|
+
assetIssuer: "GDYUTHY75A7WUZJQDPOP66FB32BOYGZRXHWTWO4Q6LQTANT5X3V5HNFA"
|
|
4779
|
+
},
|
|
4780
|
+
{
|
|
4781
|
+
assetCode: "MSFT",
|
|
4782
|
+
contractId: "CA53FXC2RF3BNIGLCPE3PNS3SZ2AONVRKH46AIHPEJOA54LGI2DYSOAD",
|
|
4783
|
+
assetIssuer: "GDYUTHY75A7WUZJQDPOP66FB32BOYGZRXHWTWO4Q6LQTANT5X3V5HNFA"
|
|
4784
|
+
},
|
|
4785
|
+
{
|
|
4786
|
+
assetCode: "META",
|
|
4787
|
+
contractId: "CA4AXIRO72PC566XUIYVN2365347I7TVGYULXW7QDVCIXBOEFFRXGP67",
|
|
4788
|
+
assetIssuer: "GDYUTHY75A7WUZJQDPOP66FB32BOYGZRXHWTWO4Q6LQTANT5X3V5HNFA"
|
|
4789
|
+
},
|
|
4790
|
+
{
|
|
4791
|
+
assetCode: "CRCL",
|
|
4792
|
+
contractId: "CDMRGHCY23UVTFYYW6U2NBYGME2VVPDO6OJXLZMM7FNGVFX3V42SAA4C",
|
|
4793
|
+
assetIssuer: "GDYUTHY75A7WUZJQDPOP66FB32BOYGZRXHWTWO4Q6LQTANT5X3V5HNFA"
|
|
4794
|
+
},
|
|
4795
|
+
{
|
|
4796
|
+
assetCode: "COIN",
|
|
4797
|
+
contractId: "CAKCNNQFIYAQBU7RXWPW3ZH4IWDXGMXUB6WTGCEZSI2EZ6WSTCCCEFHO",
|
|
4798
|
+
assetIssuer: "GDYUTHY75A7WUZJQDPOP66FB32BOYGZRXHWTWO4Q6LQTANT5X3V5HNFA"
|
|
4799
|
+
},
|
|
4800
|
+
{
|
|
4801
|
+
assetCode: "PLTR",
|
|
4802
|
+
contractId: "CC3EVVVQAB2BZFAJHPZWVRANTVVS37OJXNJKR2DVPAMG5FOYRPIIGCEV",
|
|
4803
|
+
assetIssuer: "GDYUTHY75A7WUZJQDPOP66FB32BOYGZRXHWTWO4Q6LQTANT5X3V5HNFA"
|
|
4804
|
+
},
|
|
4805
|
+
{
|
|
4806
|
+
assetCode: "TSM",
|
|
4807
|
+
contractId: "CBZFBO44J4RSRZZ7PT7BHLLID6L7C4HL77YLVFCNIIXZQKVLNL6VEAD6",
|
|
4808
|
+
assetIssuer: "GDYUTHY75A7WUZJQDPOP66FB32BOYGZRXHWTWO4Q6LQTANT5X3V5HNFA"
|
|
4809
|
+
},
|
|
4810
|
+
{
|
|
4811
|
+
assetCode: "AMD",
|
|
4812
|
+
contractId: "CCIE4OXPJUPLNRLGAENNSDEZTQUXTXKAPU322Z3HMATZSR2S2DAAGYQD",
|
|
4813
|
+
assetIssuer: "GDYUTHY75A7WUZJQDPOP66FB32BOYGZRXHWTWO4Q6LQTANT5X3V5HNFA"
|
|
4814
|
+
},
|
|
4815
|
+
{
|
|
4816
|
+
assetCode: "INTC",
|
|
4817
|
+
contractId: "CBD7GPTTHNFWBX7CYOM7O3N2TCZIAYT6FT4LCAXKX4JCZ3ZJL2IF7E4B",
|
|
4818
|
+
assetIssuer: "GDYUTHY75A7WUZJQDPOP66FB32BOYGZRXHWTWO4Q6LQTANT5X3V5HNFA"
|
|
4819
|
+
},
|
|
4820
|
+
{
|
|
4821
|
+
assetCode: "BABA",
|
|
4822
|
+
contractId: "CDARDTMGSEXTYJDSKDEAA52DCYX3OZEP7SOLSF5CT3QSSAGBETWH7LO3",
|
|
4823
|
+
assetIssuer: "GDYUTHY75A7WUZJQDPOP66FB32BOYGZRXHWTWO4Q6LQTANT5X3V5HNFA"
|
|
4289
4824
|
}
|
|
4290
4825
|
],
|
|
4291
4826
|
supportedTokens: stellarSupportedTokens,
|
|
@@ -4569,7 +5104,8 @@ var moneyMarketSupportedTokens = {
|
|
|
4569
5104
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.cbBTC,
|
|
4570
5105
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.SODA,
|
|
4571
5106
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.USDT,
|
|
4572
|
-
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.USDS
|
|
5107
|
+
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.USDS,
|
|
5108
|
+
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.sUSDS
|
|
4573
5109
|
],
|
|
4574
5110
|
[ChainKeys.OPTIMISM_MAINNET]: [
|
|
4575
5111
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.ETH,
|
|
@@ -4578,7 +5114,8 @@ var moneyMarketSupportedTokens = {
|
|
|
4578
5114
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.wstETH,
|
|
4579
5115
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.weETH,
|
|
4580
5116
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.USDT,
|
|
4581
|
-
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.SODA
|
|
5117
|
+
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.SODA,
|
|
5118
|
+
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.sUSDS
|
|
4582
5119
|
],
|
|
4583
5120
|
[ChainKeys.POLYGON_MAINNET]: [
|
|
4584
5121
|
spokeChainConfig[ChainKeys.POLYGON_MAINNET].supportedTokens.POL,
|
|
@@ -4700,7 +5237,8 @@ var moneyMarketSupportedTokens = {
|
|
|
4700
5237
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.WBTC,
|
|
4701
5238
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.WBTC_LEGACY,
|
|
4702
5239
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.LL,
|
|
4703
|
-
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.USDS
|
|
5240
|
+
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.USDS,
|
|
5241
|
+
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.sUSDS
|
|
4704
5242
|
],
|
|
4705
5243
|
[ChainKeys.REDBELLY_MAINNET]: [
|
|
4706
5244
|
spokeChainConfig[ChainKeys.REDBELLY_MAINNET].supportedTokens.bnUSD,
|
|
@@ -4933,9 +5471,10 @@ var swapSupportedTokens = {
|
|
|
4933
5471
|
spokeChainConfig[ChainKeys.SONIC_MAINNET].supportedTokens.USDT,
|
|
4934
5472
|
spokeChainConfig[ChainKeys.SONIC_MAINNET].supportedTokens.wS,
|
|
4935
5473
|
spokeChainConfig[ChainKeys.SONIC_MAINNET].supportedTokens.SODA,
|
|
4936
|
-
|
|
4937
|
-
// Swap membership is per-vault, not every SodaTokens entry:
|
|
4938
|
-
//
|
|
5474
|
+
spokeChainConfig[ChainKeys.SONIC_MAINNET].supportedTokens.USSD,
|
|
5475
|
+
// Swap membership is per-vault, not every SodaTokens entry: sodaUSDS is the one wrapper the
|
|
5476
|
+
// production solver cannot route — a `/quote` against it returns `No path was found`, where
|
|
5477
|
+
// USSD, sodaUSSD and sodaSUSDS all return real prices — so it stays out until a path exists.
|
|
4939
5478
|
SodaTokens.sodaBNB,
|
|
4940
5479
|
SodaTokens.sodaAVAX,
|
|
4941
5480
|
SodaTokens.sodaETH,
|
|
@@ -4960,8 +5499,10 @@ var swapSupportedTokens = {
|
|
|
4960
5499
|
SodaTokens.sodaNEAR,
|
|
4961
5500
|
SodaTokens.sodaKAIA,
|
|
4962
5501
|
SodaTokens.sodaSTX,
|
|
5502
|
+
SodaTokens.sodaSUSDS,
|
|
4963
5503
|
SodaTokens.sodaHBAR,
|
|
4964
5504
|
SodaTokens.sodaJITOSOL,
|
|
5505
|
+
SodaTokens.sodaUSSD,
|
|
4965
5506
|
...Object.values(LsodaTokens),
|
|
4966
5507
|
// Robinhood tokenized equities — swap-only, deliberately absent from the money market.
|
|
4967
5508
|
SodaTokens.SPCX,
|
|
@@ -4976,7 +5517,18 @@ var swapSupportedTokens = {
|
|
|
4976
5517
|
SodaTokens.QQQ,
|
|
4977
5518
|
SodaTokens.SGOV,
|
|
4978
5519
|
SodaTokens.USO,
|
|
4979
|
-
SodaTokens.SLV
|
|
5520
|
+
SodaTokens.SLV,
|
|
5521
|
+
SodaTokens.GOOGL,
|
|
5522
|
+
SodaTokens.AMZN,
|
|
5523
|
+
SodaTokens.MSFT,
|
|
5524
|
+
SodaTokens.META,
|
|
5525
|
+
SodaTokens.CRCL,
|
|
5526
|
+
SodaTokens.COIN,
|
|
5527
|
+
SodaTokens.PLTR,
|
|
5528
|
+
SodaTokens.TSM,
|
|
5529
|
+
SodaTokens.AMD,
|
|
5530
|
+
SodaTokens.INTC,
|
|
5531
|
+
SodaTokens.BABA
|
|
4980
5532
|
],
|
|
4981
5533
|
[ChainKeys.AVALANCHE_MAINNET]: [
|
|
4982
5534
|
spokeChainConfig[ChainKeys.AVALANCHE_MAINNET].supportedTokens.AVAX,
|
|
@@ -4995,6 +5547,7 @@ var swapSupportedTokens = {
|
|
|
4995
5547
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.tBTC,
|
|
4996
5548
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.USDC,
|
|
4997
5549
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.USDT,
|
|
5550
|
+
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.sUSDS,
|
|
4998
5551
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.ARB,
|
|
4999
5552
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.AAVE,
|
|
5000
5553
|
spokeChainConfig[ChainKeys.ARBITRUM_MAINNET].supportedTokens.LINK,
|
|
@@ -5009,6 +5562,7 @@ var swapSupportedTokens = {
|
|
|
5009
5562
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.ETH,
|
|
5010
5563
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.weETH,
|
|
5011
5564
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.USDC,
|
|
5565
|
+
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.sUSDS,
|
|
5012
5566
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.wstETH,
|
|
5013
5567
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.cbBTC,
|
|
5014
5568
|
spokeChainConfig[ChainKeys.BASE_MAINNET].supportedTokens.VIRTUAL,
|
|
@@ -5019,6 +5573,7 @@ var swapSupportedTokens = {
|
|
|
5019
5573
|
[ChainKeys.OPTIMISM_MAINNET]: [
|
|
5020
5574
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.ETH,
|
|
5021
5575
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.USDC,
|
|
5576
|
+
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.sUSDS,
|
|
5022
5577
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.wstETH,
|
|
5023
5578
|
// spokeChainConfig[OPTIMISM_MAINNET_CHAIN_ID].supportedTokens.weETH, // NOTE: Not Implemented
|
|
5024
5579
|
spokeChainConfig[ChainKeys.OPTIMISM_MAINNET].supportedTokens.USDT,
|
|
@@ -5148,7 +5703,18 @@ var swapSupportedTokens = {
|
|
|
5148
5703
|
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.QQQ,
|
|
5149
5704
|
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.SGOV,
|
|
5150
5705
|
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.USO,
|
|
5151
|
-
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.SLV
|
|
5706
|
+
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.SLV,
|
|
5707
|
+
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.GOOGL,
|
|
5708
|
+
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.AMZN,
|
|
5709
|
+
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.MSFT,
|
|
5710
|
+
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.META,
|
|
5711
|
+
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.CRCL,
|
|
5712
|
+
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.COIN,
|
|
5713
|
+
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.PLTR,
|
|
5714
|
+
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.TSM,
|
|
5715
|
+
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.AMD,
|
|
5716
|
+
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.INTC,
|
|
5717
|
+
spokeChainConfig[ChainKeys.STELLAR_MAINNET].supportedTokens.BABA
|
|
5152
5718
|
],
|
|
5153
5719
|
[ChainKeys.SUI_MAINNET]: [
|
|
5154
5720
|
spokeChainConfig[ChainKeys.SUI_MAINNET].supportedTokens.SUI,
|
|
@@ -5186,6 +5752,7 @@ var swapSupportedTokens = {
|
|
|
5186
5752
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.ETH,
|
|
5187
5753
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.bnUSD,
|
|
5188
5754
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.USDC,
|
|
5755
|
+
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.sUSDS,
|
|
5189
5756
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.USDT,
|
|
5190
5757
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.SODA,
|
|
5191
5758
|
spokeChainConfig[ChainKeys.ETHEREUM_MAINNET].supportedTokens.LL,
|
|
@@ -5267,7 +5834,18 @@ var swapSupportedTokens = {
|
|
|
5267
5834
|
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.QQQ,
|
|
5268
5835
|
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.SGOV,
|
|
5269
5836
|
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.USO,
|
|
5270
|
-
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.SLV
|
|
5837
|
+
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.SLV,
|
|
5838
|
+
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.GOOGL,
|
|
5839
|
+
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.AMZN,
|
|
5840
|
+
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.MSFT,
|
|
5841
|
+
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.META,
|
|
5842
|
+
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.CRCL,
|
|
5843
|
+
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.COIN,
|
|
5844
|
+
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.PLTR,
|
|
5845
|
+
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.TSM,
|
|
5846
|
+
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.AMD,
|
|
5847
|
+
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.INTC,
|
|
5848
|
+
spokeChainConfig[ChainKeys.HEDERA_MAINNET].supportedTokens.BABA
|
|
5271
5849
|
],
|
|
5272
5850
|
[ChainKeys.ROBINHOOD_MAINNET]: [
|
|
5273
5851
|
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.ETH,
|
|
@@ -5288,11 +5866,22 @@ var swapSupportedTokens = {
|
|
|
5288
5866
|
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.QQQ,
|
|
5289
5867
|
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.SGOV,
|
|
5290
5868
|
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.USO,
|
|
5291
|
-
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.SLV
|
|
5869
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.SLV,
|
|
5870
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.GOOGL,
|
|
5871
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.AMZN,
|
|
5872
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.MSFT,
|
|
5873
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.META,
|
|
5874
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.CRCL,
|
|
5875
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.COIN,
|
|
5876
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.PLTR,
|
|
5877
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.TSM,
|
|
5878
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.AMD,
|
|
5879
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.INTC,
|
|
5880
|
+
spokeChainConfig[ChainKeys.ROBINHOOD_MAINNET].supportedTokens.BABA
|
|
5292
5881
|
]
|
|
5293
5882
|
};
|
|
5294
5883
|
var stagingSwapSupportedTokens = {
|
|
5295
|
-
[ChainKeys.SONIC_MAINNET]: [
|
|
5884
|
+
[ChainKeys.SONIC_MAINNET]: [],
|
|
5296
5885
|
[ChainKeys.AVALANCHE_MAINNET]: [],
|
|
5297
5886
|
[ChainKeys.ARBITRUM_MAINNET]: [],
|
|
5298
5887
|
[ChainKeys.BASE_MAINNET]: [
|
|
@@ -5399,7 +5988,8 @@ var leverageYieldVaults = [
|
|
|
5399
5988
|
}
|
|
5400
5989
|
];
|
|
5401
5990
|
var leverageYieldConfig = {
|
|
5402
|
-
vaults: leverageYieldVaults
|
|
5991
|
+
vaults: leverageYieldVaults,
|
|
5992
|
+
positionFactory: "0xF8fB7F200B6545295e1729Cf254482d7c116031C"
|
|
5403
5993
|
};
|
|
5404
5994
|
|
|
5405
5995
|
// ../types/dist/sodax-config/sodax-config.js
|
|
@@ -5632,7 +6222,45 @@ function isValidWalletProviderForChainKey(chainKey, walletProvider) {
|
|
|
5632
6222
|
}
|
|
5633
6223
|
|
|
5634
6224
|
// ../types/dist/index.js
|
|
5635
|
-
var CONFIG_VERSION =
|
|
6225
|
+
var CONFIG_VERSION = 2020007;
|
|
6226
|
+
var RC_STABLE = 99;
|
|
6227
|
+
var MIN_CONFIG_VERSION = 1e6;
|
|
6228
|
+
var MAX_CONFIG_VERSION = 99999999;
|
|
6229
|
+
var VERSION_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-rc\.(0|[1-9]\d*))?$/;
|
|
6230
|
+
function configVersionFor(version) {
|
|
6231
|
+
const match = typeof version === "string" ? version.match(VERSION_PATTERN) : null;
|
|
6232
|
+
if (!match)
|
|
6233
|
+
return null;
|
|
6234
|
+
const major = Number(match[1]);
|
|
6235
|
+
const minor = Number(match[2]);
|
|
6236
|
+
const patch = Number(match[3]);
|
|
6237
|
+
const rc = match[4] === void 0 ? null : Number(match[4]);
|
|
6238
|
+
if (major < 1 || major > 99 || minor > 99 || patch > 99)
|
|
6239
|
+
return null;
|
|
6240
|
+
if (rc !== null && rc > 98)
|
|
6241
|
+
return null;
|
|
6242
|
+
return major * 1e6 + minor * 1e4 + patch * 100 + (rc === null ? RC_STABLE : rc);
|
|
6243
|
+
}
|
|
6244
|
+
var unpack = (value) => {
|
|
6245
|
+
const slot = value % 100;
|
|
6246
|
+
return {
|
|
6247
|
+
major: Math.floor(value / 1e6),
|
|
6248
|
+
minor: Math.floor(value / 1e4) % 100,
|
|
6249
|
+
patch: Math.floor(value / 100) % 100,
|
|
6250
|
+
rc: slot === RC_STABLE ? null : slot
|
|
6251
|
+
};
|
|
6252
|
+
};
|
|
6253
|
+
var render = ({ major, minor, patch, rc }) => `${major}.${minor}.${patch}${rc === null ? "" : `-rc.${rc}`}`;
|
|
6254
|
+
function parseConfigVersion(value) {
|
|
6255
|
+
if (!Number.isInteger(value) || value < MIN_CONFIG_VERSION || value > MAX_CONFIG_VERSION)
|
|
6256
|
+
return null;
|
|
6257
|
+
return unpack(value);
|
|
6258
|
+
}
|
|
6259
|
+
function formatConfigVersion(value) {
|
|
6260
|
+
const parsed = parseConfigVersion(value);
|
|
6261
|
+
return parsed === null ? null : render(parsed);
|
|
6262
|
+
}
|
|
6263
|
+
var SDK_VERSION = render(unpack(CONFIG_VERSION));
|
|
5636
6264
|
|
|
5637
6265
|
// src/shared/utils/resolveTimeoutMs.ts
|
|
5638
6266
|
function resolveTimeoutMs(timeout, fallbackMs) {
|
|
@@ -5847,12 +6475,12 @@ function canonicalizeBitcoinAddress(address$1) {
|
|
|
5847
6475
|
}
|
|
5848
6476
|
}
|
|
5849
6477
|
function normalizePsbtToBase64(signedPsbt) {
|
|
5850
|
-
const
|
|
5851
|
-
return
|
|
6478
|
+
const isHex3 = /^[0-9a-fA-F]+$/.test(signedPsbt);
|
|
6479
|
+
return isHex3 ? Buffer.from(signedPsbt, "hex").toString("base64") : signedPsbt;
|
|
5852
6480
|
}
|
|
5853
6481
|
function normalizeSignatureToBase64(signature) {
|
|
5854
|
-
const
|
|
5855
|
-
return
|
|
6482
|
+
const isHex3 = /^[0-9a-fA-F]+$/.test(signature);
|
|
6483
|
+
return isHex3 ? Buffer.from(signature, "hex").toString("base64") : signature;
|
|
5856
6484
|
}
|
|
5857
6485
|
function isNativeBitcoinTransfer(config, chainKey, token) {
|
|
5858
6486
|
return isBitcoinChainKeyType(chainKey) && !!token && isNativeBitcoinToken(config.getChainConfig(chainKey), token.address);
|
|
@@ -15567,11 +16195,15 @@ var ConfigService = class {
|
|
|
15567
16195
|
isMoneyMarketSupportedToken(chainId, token) {
|
|
15568
16196
|
return this.sodax.moneyMarket.supportedTokens[chainId].some((t) => t.address.toLowerCase() === token.toLowerCase());
|
|
15569
16197
|
}
|
|
16198
|
+
/**
|
|
16199
|
+
* Is `asset` one of the money-market reserve assets?
|
|
16200
|
+
*
|
|
16201
|
+
* The reserve set is built from `moneyMarketHubVaults`, so its members are hub **vault**
|
|
16202
|
+
* addresses. Query it with an `XToken.vault`; an `XToken.hubAsset` only matches for the Sonic
|
|
16203
|
+
* vault shares themselves, where `hubAsset === vault`.
|
|
16204
|
+
*/
|
|
15570
16205
|
isMoneyMarketReserveAsset(asset) {
|
|
15571
|
-
return this.
|
|
15572
|
-
}
|
|
15573
|
-
isMoneyMarketReserveHubAsset(hubAsset) {
|
|
15574
|
-
return this.moneyMarketReserveAssetsSet.has(hubAsset.toLowerCase());
|
|
16206
|
+
return this.moneyMarketReserveAssetsSet.has(asset.toLowerCase());
|
|
15575
16207
|
}
|
|
15576
16208
|
loadSodaxConfigDataStructures(sodaxConfig2) {
|
|
15577
16209
|
this.hubAssetToXTokenMap = new Map(
|
|
@@ -15664,10 +16296,12 @@ var ConfigService = class {
|
|
|
15664
16296
|
get bridgeUseBackendSubmitTx() {
|
|
15665
16297
|
return this.bridge.useBackendSubmitTx ?? this.sodax.bridgeOptions?.useBackendSubmitTx ?? true;
|
|
15666
16298
|
}
|
|
15667
|
-
//
|
|
15668
|
-
//
|
|
16299
|
+
// Same ON default as the two above, and for the same reason: any backend non-success falls back
|
|
16300
|
+
// to the client-side relay, so the default costs a rejected attempt at worst. No deprecated
|
|
16301
|
+
// second-precedence key here — leverage yield arrived after `swapsOptions` / `bridgeOptions` were
|
|
16302
|
+
// already deprecated, so it never had one.
|
|
15669
16303
|
get leverageYieldUseBackendSubmitTx() {
|
|
15670
|
-
return this.leverageYield.useBackendSubmitTx ??
|
|
16304
|
+
return this.leverageYield.useBackendSubmitTx ?? true;
|
|
15671
16305
|
}
|
|
15672
16306
|
get dex() {
|
|
15673
16307
|
return this.sodax.dex;
|
|
@@ -15720,7 +16354,7 @@ function mergeSodaxConfig(base2, override) {
|
|
|
15720
16354
|
}
|
|
15721
16355
|
function encodeContractCalls(calls) {
|
|
15722
16356
|
return encodeAbiParameters(parseAbiParameters("(address,uint256,bytes)[]"), [
|
|
15723
|
-
calls.map((
|
|
16357
|
+
calls.map((v10) => [v10.address, v10.value, v10.data])
|
|
15724
16358
|
]);
|
|
15725
16359
|
}
|
|
15726
16360
|
async function waitForTransactionReceipt(hash, provider) {
|
|
@@ -17983,7 +18617,7 @@ function hexToBytes2(hex) {
|
|
|
17983
18617
|
const al = hl / 2;
|
|
17984
18618
|
if (hl % 2)
|
|
17985
18619
|
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
17986
|
-
const
|
|
18620
|
+
const array3 = new Uint8Array(al);
|
|
17987
18621
|
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
17988
18622
|
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
17989
18623
|
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
@@ -17991,9 +18625,9 @@ function hexToBytes2(hex) {
|
|
|
17991
18625
|
const char = hex[hi] + hex[hi + 1];
|
|
17992
18626
|
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
17993
18627
|
}
|
|
17994
|
-
|
|
18628
|
+
array3[ai] = n1 * 16 + n2;
|
|
17995
18629
|
}
|
|
17996
|
-
return
|
|
18630
|
+
return array3;
|
|
17997
18631
|
}
|
|
17998
18632
|
function concatBytes(...arrays) {
|
|
17999
18633
|
let sum = 0;
|
|
@@ -18623,22 +19257,22 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
|
18623
19257
|
const byte0 = Uint8Array.of(0);
|
|
18624
19258
|
const byte1 = Uint8Array.of(1);
|
|
18625
19259
|
const _maxDrbgIters = 1e3;
|
|
18626
|
-
let
|
|
19260
|
+
let v10 = u8n(hashLen);
|
|
18627
19261
|
let k = u8n(hashLen);
|
|
18628
19262
|
let i = 0;
|
|
18629
19263
|
const reset = () => {
|
|
18630
|
-
|
|
19264
|
+
v10.fill(1);
|
|
18631
19265
|
k.fill(0);
|
|
18632
19266
|
i = 0;
|
|
18633
19267
|
};
|
|
18634
|
-
const h = (...msgs) => hmacFn(k, concatBytes(
|
|
19268
|
+
const h = (...msgs) => hmacFn(k, concatBytes(v10, ...msgs));
|
|
18635
19269
|
const reseed = (seed = NULL) => {
|
|
18636
19270
|
k = h(byte0, seed);
|
|
18637
|
-
|
|
19271
|
+
v10 = h();
|
|
18638
19272
|
if (seed.length === 0)
|
|
18639
19273
|
return;
|
|
18640
19274
|
k = h(byte1, seed);
|
|
18641
|
-
|
|
19275
|
+
v10 = h();
|
|
18642
19276
|
};
|
|
18643
19277
|
const gen = () => {
|
|
18644
19278
|
if (i++ >= _maxDrbgIters)
|
|
@@ -18646,10 +19280,10 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
|
18646
19280
|
let len = 0;
|
|
18647
19281
|
const out = [];
|
|
18648
19282
|
while (len < qByteLen) {
|
|
18649
|
-
|
|
18650
|
-
const sl =
|
|
19283
|
+
v10 = h();
|
|
19284
|
+
const sl = v10.slice();
|
|
18651
19285
|
out.push(sl);
|
|
18652
|
-
len +=
|
|
19286
|
+
len += v10.length;
|
|
18653
19287
|
}
|
|
18654
19288
|
return concatBytes(...out);
|
|
18655
19289
|
};
|
|
@@ -18664,18 +19298,18 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
|
18664
19298
|
};
|
|
18665
19299
|
return genUntil;
|
|
18666
19300
|
}
|
|
18667
|
-
function validateObject(
|
|
18668
|
-
if (!
|
|
19301
|
+
function validateObject(object4, fields = {}, optFields = {}) {
|
|
19302
|
+
if (!object4 || typeof object4 !== "object")
|
|
18669
19303
|
throw new Error("expected valid options object");
|
|
18670
19304
|
function checkField(fieldName, expectedType, isOpt) {
|
|
18671
|
-
const val =
|
|
19305
|
+
const val = object4[fieldName];
|
|
18672
19306
|
if (isOpt && val === void 0)
|
|
18673
19307
|
return;
|
|
18674
19308
|
const current = typeof val;
|
|
18675
19309
|
if (current !== expectedType || val === null)
|
|
18676
19310
|
throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
|
|
18677
19311
|
}
|
|
18678
|
-
const iter = (f, isOpt) => Object.entries(f).forEach(([k,
|
|
19312
|
+
const iter = (f, isOpt) => Object.entries(f).forEach(([k, v10]) => checkField(k, v10, isOpt));
|
|
18679
19313
|
iter(fields, false);
|
|
18680
19314
|
iter(optFields, true);
|
|
18681
19315
|
}
|
|
@@ -18714,12 +19348,12 @@ function pow2(x, power, modulo) {
|
|
|
18714
19348
|
}
|
|
18715
19349
|
return res;
|
|
18716
19350
|
}
|
|
18717
|
-
function invert(
|
|
18718
|
-
if (
|
|
19351
|
+
function invert(number4, modulo) {
|
|
19352
|
+
if (number4 === _0n2)
|
|
18719
19353
|
throw new Error("invert: expected non-zero number");
|
|
18720
19354
|
if (modulo <= _0n2)
|
|
18721
19355
|
throw new Error("invert: expected positive modulus, got " + modulo);
|
|
18722
|
-
let a = mod(
|
|
19356
|
+
let a = mod(number4, modulo);
|
|
18723
19357
|
let b = modulo;
|
|
18724
19358
|
let x = _0n2, u = _1n2;
|
|
18725
19359
|
while (a !== _0n2) {
|
|
@@ -18746,9 +19380,9 @@ function sqrt3mod4(Fp, n) {
|
|
|
18746
19380
|
function sqrt5mod8(Fp, n) {
|
|
18747
19381
|
const p5div8 = (Fp.ORDER - _5n) / _8n;
|
|
18748
19382
|
const n2 = Fp.mul(n, _2n);
|
|
18749
|
-
const
|
|
18750
|
-
const nv = Fp.mul(n,
|
|
18751
|
-
const i = Fp.mul(Fp.mul(nv, _2n),
|
|
19383
|
+
const v10 = Fp.pow(n2, p5div8);
|
|
19384
|
+
const nv = Fp.mul(n, v10);
|
|
19385
|
+
const i = Fp.mul(Fp.mul(nv, _2n), v10);
|
|
18752
19386
|
const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
|
|
18753
19387
|
assertIsSquare(Fp, root, n);
|
|
18754
19388
|
return root;
|
|
@@ -19223,27 +19857,27 @@ var wNAF = class {
|
|
|
19223
19857
|
assert0(n);
|
|
19224
19858
|
return acc;
|
|
19225
19859
|
}
|
|
19226
|
-
getPrecomputes(W, point,
|
|
19860
|
+
getPrecomputes(W, point, transform) {
|
|
19227
19861
|
let comp = pointPrecomputes.get(point);
|
|
19228
19862
|
if (!comp) {
|
|
19229
19863
|
comp = this.precomputeWindow(point, W);
|
|
19230
19864
|
if (W !== 1) {
|
|
19231
|
-
if (typeof
|
|
19232
|
-
comp =
|
|
19865
|
+
if (typeof transform === "function")
|
|
19866
|
+
comp = transform(comp);
|
|
19233
19867
|
pointPrecomputes.set(point, comp);
|
|
19234
19868
|
}
|
|
19235
19869
|
}
|
|
19236
19870
|
return comp;
|
|
19237
19871
|
}
|
|
19238
|
-
cached(point, scalar,
|
|
19872
|
+
cached(point, scalar, transform) {
|
|
19239
19873
|
const W = getW(point);
|
|
19240
|
-
return this.wNAF(W, this.getPrecomputes(W, point,
|
|
19874
|
+
return this.wNAF(W, this.getPrecomputes(W, point, transform), scalar);
|
|
19241
19875
|
}
|
|
19242
|
-
unsafe(point, scalar,
|
|
19876
|
+
unsafe(point, scalar, transform, prev) {
|
|
19243
19877
|
const W = getW(point);
|
|
19244
19878
|
if (W === 1)
|
|
19245
19879
|
return this._unsafeLadder(point, scalar, prev);
|
|
19246
|
-
return this.wNAFUnsafe(W, this.getPrecomputes(W, point,
|
|
19880
|
+
return this.wNAFUnsafe(W, this.getPrecomputes(W, point, transform), scalar, prev);
|
|
19247
19881
|
}
|
|
19248
19882
|
// We calculate precomputes for elliptic curve point multiplication
|
|
19249
19883
|
// using windowed method. This specifies window size and
|
|
@@ -19330,9 +19964,9 @@ function edwards(params, extraOpts = {}) {
|
|
|
19330
19964
|
validateObject(extraOpts, {}, { uvRatio: "function" });
|
|
19331
19965
|
const MASK = _2n2 << BigInt(Fn.BYTES * 8) - _1n4;
|
|
19332
19966
|
const modP = (n) => Fp.create(n);
|
|
19333
|
-
const uvRatio2 = extraOpts.uvRatio || ((u,
|
|
19967
|
+
const uvRatio2 = extraOpts.uvRatio || ((u, v10) => {
|
|
19334
19968
|
try {
|
|
19335
|
-
return { isValid: true, value: Fp.sqrt(Fp.div(u,
|
|
19969
|
+
return { isValid: true, value: Fp.sqrt(Fp.div(u, v10)) };
|
|
19336
19970
|
} catch (e) {
|
|
19337
19971
|
return { isValid: false, value: _0n4 };
|
|
19338
19972
|
}
|
|
@@ -19428,8 +20062,8 @@ function edwards(params, extraOpts = {}) {
|
|
|
19428
20062
|
aInRange("point.y", y, _0n4, max);
|
|
19429
20063
|
const y2 = modP(y * y);
|
|
19430
20064
|
const u = modP(y2 - _1n4);
|
|
19431
|
-
const
|
|
19432
|
-
let { isValid, value: x } = uvRatio2(u,
|
|
20065
|
+
const v10 = modP(d * y2 - a);
|
|
20066
|
+
let { isValid, value: x } = uvRatio2(u, v10);
|
|
19433
20067
|
if (!isValid)
|
|
19434
20068
|
throw new Error("bad point: invalid y coordinate");
|
|
19435
20069
|
const isXOdd = (x & _1n4) === _1n4;
|
|
@@ -19769,13 +20403,13 @@ function adjustScalarBytes(bytes) {
|
|
|
19769
20403
|
return bytes;
|
|
19770
20404
|
}
|
|
19771
20405
|
var ED25519_SQRT_M1 = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
|
|
19772
|
-
function uvRatio(u,
|
|
20406
|
+
function uvRatio(u, v10) {
|
|
19773
20407
|
const P = ed25519_CURVE_p;
|
|
19774
|
-
const v32 = mod(
|
|
19775
|
-
const v72 = mod(v32 * v32 *
|
|
20408
|
+
const v32 = mod(v10 * v10 * v10, P);
|
|
20409
|
+
const v72 = mod(v32 * v32 * v10, P);
|
|
19776
20410
|
const pow = ed25519_pow_2_252_3(u * v72).pow_p_5_8;
|
|
19777
20411
|
let x = mod(u * v32 * pow, P);
|
|
19778
|
-
const vx2 = mod(
|
|
20412
|
+
const vx2 = mod(v10 * x * x, P);
|
|
19779
20413
|
const root1 = x;
|
|
19780
20414
|
const root2 = mod(x * ED25519_SQRT_M1, P);
|
|
19781
20415
|
const useRoot1 = vx2 === u;
|
|
@@ -20106,7 +20740,7 @@ function findSeatPrice(validators, maxNumberOfSeats, minimumStakeRatio, protocol
|
|
|
20106
20740
|
return findSeatPriceForProtocolAfter49(validators, maxNumberOfSeats, minimumStakeRatio);
|
|
20107
20741
|
}
|
|
20108
20742
|
function findSeatPriceForProtocolBefore49(validators, numSeats) {
|
|
20109
|
-
const stakes = validators.map((
|
|
20743
|
+
const stakes = validators.map((v10) => BigInt(v10.stake)).sort(sortBigIntAsc);
|
|
20110
20744
|
const num = BigInt(numSeats);
|
|
20111
20745
|
const stakesSum = stakes.reduce((a, b) => a + b);
|
|
20112
20746
|
if (stakesSum < num) {
|
|
@@ -20135,7 +20769,7 @@ function findSeatPriceForProtocolAfter49(validators, maxNumberOfSeats, minimumSt
|
|
|
20135
20769
|
if (minimumStakeRatio.length != 2) {
|
|
20136
20770
|
throw Error("minimumStakeRatio should have 2 elements");
|
|
20137
20771
|
}
|
|
20138
|
-
const stakes = validators.map((
|
|
20772
|
+
const stakes = validators.map((v10) => BigInt(v10.stake)).sort(sortBigIntAsc);
|
|
20139
20773
|
const stakesSum = stakes.reduce((a, b) => a + b);
|
|
20140
20774
|
if (validators.length < maxNumberOfSeats) {
|
|
20141
20775
|
return stakesSum * BigInt(minimumStakeRatio[0]) / BigInt(minimumStakeRatio[1]);
|
|
@@ -20307,10 +20941,10 @@ var DER = {
|
|
|
20307
20941
|
if (length < 128)
|
|
20308
20942
|
throw new E("tlv.decode(long): not minimal encoding");
|
|
20309
20943
|
}
|
|
20310
|
-
const
|
|
20311
|
-
if (
|
|
20944
|
+
const v10 = data.subarray(pos, pos + length);
|
|
20945
|
+
if (v10.length !== length)
|
|
20312
20946
|
throw new E("tlv.decode: wrong value length");
|
|
20313
|
-
return { v:
|
|
20947
|
+
return { v: v10, l: data.subarray(pos + length) };
|
|
20314
20948
|
}
|
|
20315
20949
|
},
|
|
20316
20950
|
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
@@ -20878,9 +21512,9 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
20878
21512
|
extraEntropy: false
|
|
20879
21513
|
};
|
|
20880
21514
|
const hasLargeCofactor = CURVE_ORDER * _2n4 < Fp.ORDER;
|
|
20881
|
-
function isBiggerThanHalfOrder(
|
|
21515
|
+
function isBiggerThanHalfOrder(number4) {
|
|
20882
21516
|
const HALF = CURVE_ORDER >> _1n6;
|
|
20883
|
-
return
|
|
21517
|
+
return number4 > HALF;
|
|
20884
21518
|
}
|
|
20885
21519
|
function validateRS(title, num) {
|
|
20886
21520
|
if (!Fn.isValidNot0(num))
|
|
@@ -21063,8 +21697,8 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
21063
21697
|
const R = Point.BASE.multiplyUnsafe(u1).add(P.multiplyUnsafe(u2));
|
|
21064
21698
|
if (R.is0())
|
|
21065
21699
|
return false;
|
|
21066
|
-
const
|
|
21067
|
-
return
|
|
21700
|
+
const v10 = Fn.create(R.x);
|
|
21701
|
+
return v10 === r;
|
|
21068
21702
|
} catch (e) {
|
|
21069
21703
|
return false;
|
|
21070
21704
|
}
|
|
@@ -24956,6 +25590,7 @@ function isTimeoutError(error) {
|
|
|
24956
25590
|
return error instanceof Error && /timed?\s?out|timeout/i.test(error.message);
|
|
24957
25591
|
}
|
|
24958
25592
|
var DEFAULT_GET_COINS_LIMIT = 10;
|
|
25593
|
+
var LATEST_PACKAGE_ID_TIMEOUT_MS = 1e4;
|
|
24959
25594
|
function toSuiObjectOwner(owner) {
|
|
24960
25595
|
switch (owner?.$kind) {
|
|
24961
25596
|
case "AddressOwner":
|
|
@@ -25024,16 +25659,20 @@ var SuiGrpcTransport = class {
|
|
|
25024
25659
|
return effects.gasUsed;
|
|
25025
25660
|
}
|
|
25026
25661
|
async fetchLatestPackageId(objectId) {
|
|
25027
|
-
let
|
|
25662
|
+
let object4;
|
|
25028
25663
|
try {
|
|
25029
|
-
({ object:
|
|
25664
|
+
({ object: object4 } = await this.client.core.getObject({
|
|
25665
|
+
objectId,
|
|
25666
|
+
include: { json: true },
|
|
25667
|
+
signal: AbortSignal.timeout(LATEST_PACKAGE_ID_TIMEOUT_MS)
|
|
25668
|
+
}));
|
|
25030
25669
|
} catch (error) {
|
|
25031
25670
|
throw new Error("Failed to fetch asset manager id", { cause: error });
|
|
25032
25671
|
}
|
|
25033
|
-
if (!
|
|
25672
|
+
if (!object4) {
|
|
25034
25673
|
throw new Error("Asset manager id not found (no data)");
|
|
25035
25674
|
}
|
|
25036
|
-
const fields =
|
|
25675
|
+
const fields = object4.json;
|
|
25037
25676
|
if (!fields) {
|
|
25038
25677
|
throw new Error("Asset manager id not found (not a move object)");
|
|
25039
25678
|
}
|
|
@@ -25070,7 +25709,11 @@ var SuiSpokeService = class {
|
|
|
25070
25709
|
transport;
|
|
25071
25710
|
/** @deprecated Renamed to `transport`, and no longer a raw `@mysten/sui` client. */
|
|
25072
25711
|
publicClient;
|
|
25073
|
-
|
|
25712
|
+
/**
|
|
25713
|
+
* `latest_package_id` reads still in flight, keyed by chain. An entry is dropped as soon as its
|
|
25714
|
+
* read settles, so concurrent callers share one request while a later build always re-reads.
|
|
25715
|
+
*/
|
|
25716
|
+
assetManagerLookups = /* @__PURE__ */ new Map();
|
|
25074
25717
|
pollingIntervalMs;
|
|
25075
25718
|
maxTimeoutMs;
|
|
25076
25719
|
constructor(config) {
|
|
@@ -25132,10 +25775,19 @@ var SuiSpokeService = class {
|
|
|
25132
25775
|
};
|
|
25133
25776
|
}
|
|
25134
25777
|
async getAssetManagerAddress(chainId) {
|
|
25135
|
-
|
|
25136
|
-
|
|
25137
|
-
|
|
25138
|
-
|
|
25778
|
+
const { packageId, moduleId, stateId } = await this.resolveAssetManager(chainId);
|
|
25779
|
+
return `${packageId}::${moduleId}::${stateId}`;
|
|
25780
|
+
}
|
|
25781
|
+
/**
|
|
25782
|
+
* An upgraded Sui package lives at a new address and the superseded one aborts on
|
|
25783
|
+
* `enforce_version`, so the id is read per call and never held between two builds.
|
|
25784
|
+
*/
|
|
25785
|
+
async resolveAssetManager(chainId) {
|
|
25786
|
+
const inFlight = this.assetManagerLookups.get(chainId);
|
|
25787
|
+
if (inFlight) return inFlight;
|
|
25788
|
+
const lookup = this.fetchAssetManagerAddress(chainId).then((address) => this.splitAddress(address)).finally(() => this.assetManagerLookups.delete(chainId));
|
|
25789
|
+
this.assetManagerLookups.set(chainId, lookup);
|
|
25790
|
+
return lookup;
|
|
25139
25791
|
}
|
|
25140
25792
|
async viewContract(tx, packageId, module, functionName, args, typeArgs = [], sender) {
|
|
25141
25793
|
tx.moveCall({
|
|
@@ -25152,12 +25804,27 @@ var SuiSpokeService = class {
|
|
|
25152
25804
|
* @returns {Promise<TxReturnType<SuiChainKey, R>>} A promise that resolves to the transaction hash or raw transaction base64 string.
|
|
25153
25805
|
*/
|
|
25154
25806
|
async deposit(params) {
|
|
25807
|
+
const { tx, assetManager } = await this.buildDepositTransaction(params);
|
|
25808
|
+
if (params.raw === true) {
|
|
25809
|
+
return {
|
|
25810
|
+
from: params.srcAddress,
|
|
25811
|
+
to: `${assetManager.packageId}::${assetManager.moduleId}::transfer`,
|
|
25812
|
+
value: params.amount,
|
|
25813
|
+
data: tx.serialize()
|
|
25814
|
+
};
|
|
25815
|
+
}
|
|
25816
|
+
return params.walletProvider.signAndExecuteTxn(tx);
|
|
25817
|
+
}
|
|
25818
|
+
/** Both deposit paths build here, so the asset manager is resolved the same way for each. */
|
|
25819
|
+
async buildDepositTransaction(params) {
|
|
25155
25820
|
const { srcAddress: from, srcChainKey, token, to, amount, data = "0x" } = params;
|
|
25156
25821
|
const isNative = isNativeToken(srcChainKey, token);
|
|
25157
25822
|
const tx = new Transaction$1();
|
|
25158
|
-
const coin = isNative ? await this.getNativeCoin(tx, amount) : await this.getCoin(tx, token, amount, from);
|
|
25159
25823
|
const connection = this.splitAddress(this.config.getChainConfig(srcChainKey).addresses.connection);
|
|
25160
|
-
const assetManager =
|
|
25824
|
+
const [coin, assetManager] = await Promise.all([
|
|
25825
|
+
isNative ? this.getNativeCoin(tx, amount) : this.getCoin(tx, token, amount, from),
|
|
25826
|
+
this.resolveAssetManager(srcChainKey)
|
|
25827
|
+
]);
|
|
25161
25828
|
tx.moveCall({
|
|
25162
25829
|
target: `${assetManager.packageId}::${assetManager.moduleId}::transfer`,
|
|
25163
25830
|
typeArguments: [token],
|
|
@@ -25170,15 +25837,7 @@ var SuiSpokeService = class {
|
|
|
25170
25837
|
tx.pure(bcs.vector(bcs.u8()).serialize(fromHex(data, "bytes")))
|
|
25171
25838
|
]
|
|
25172
25839
|
});
|
|
25173
|
-
|
|
25174
|
-
return {
|
|
25175
|
-
from,
|
|
25176
|
-
to: `${assetManager.packageId}::${assetManager.moduleId}::transfer`,
|
|
25177
|
-
value: amount,
|
|
25178
|
-
data: tx.serialize()
|
|
25179
|
-
};
|
|
25180
|
-
}
|
|
25181
|
-
return params.walletProvider.signAndExecuteTxn(tx);
|
|
25840
|
+
return { tx, assetManager };
|
|
25182
25841
|
}
|
|
25183
25842
|
async sendMessage(params) {
|
|
25184
25843
|
const { srcAddress: from, srcChainKey, dstChainKey, dstAddress, payload } = params;
|
|
@@ -25218,7 +25877,7 @@ var SuiSpokeService = class {
|
|
|
25218
25877
|
* @returns {Promise<bigint>} The balance of the token.
|
|
25219
25878
|
*/
|
|
25220
25879
|
async getDeposit(params) {
|
|
25221
|
-
const assetmanager =
|
|
25880
|
+
const assetmanager = await this.resolveAssetManager(params.srcChainKey);
|
|
25222
25881
|
const tx = new Transaction$1();
|
|
25223
25882
|
const result = await this.viewContract(
|
|
25224
25883
|
tx,
|
|
@@ -28949,6 +29608,39 @@ var EvmHubProvider = class {
|
|
|
28949
29608
|
}
|
|
28950
29609
|
};
|
|
28951
29610
|
|
|
29611
|
+
// src/backendApi/detailedStatusRouting.ts
|
|
29612
|
+
var DETAILED_STATUS_NOT_DELIVERED = "relay_not_delivered";
|
|
29613
|
+
function isBackendSubmitTxAbandoned(data) {
|
|
29614
|
+
return data.status === "failed" || Boolean(data.abandonedAt);
|
|
29615
|
+
}
|
|
29616
|
+
async function resolveDeliveredPacket(params) {
|
|
29617
|
+
const { srcChainKey, srcTxHash, relayerApiEndpoint, backendAnswered } = params;
|
|
29618
|
+
const relayChainId = getIntentRelayChainId(srcChainKey);
|
|
29619
|
+
const packets = await getTransactionPackets(
|
|
29620
|
+
{ action: "get_transaction_packets", params: { chain_id: relayChainId.toString(), tx_hash: srcTxHash } },
|
|
29621
|
+
relayerApiEndpoint,
|
|
29622
|
+
RELAY_REQUEST_TIMEOUT_MS
|
|
29623
|
+
);
|
|
29624
|
+
if (!packets.ok) {
|
|
29625
|
+
const notIndexed = packets.error instanceof HttpRelayError && packets.error.status === 404;
|
|
29626
|
+
return { ok: false, cause: packets.error, budgetable: notIndexed && backendAnswered };
|
|
29627
|
+
}
|
|
29628
|
+
if (!packets.value?.success || !Array.isArray(packets.value.data)) {
|
|
29629
|
+
return { ok: false, cause: new Error("relay returned no usable transaction packets"), budgetable: false };
|
|
29630
|
+
}
|
|
29631
|
+
const delivered = packets.value.data.find(
|
|
29632
|
+
(packet) => typeof packet?.src_tx_hash === "string" && packet.src_tx_hash.toLowerCase() === srcTxHash.toLowerCase() && packet.src_chain_id === Number(relayChainId) && packet.status === "executed" && typeof packet.dst_tx_hash === "string" && packet.dst_tx_hash.length > 0
|
|
29633
|
+
);
|
|
29634
|
+
if (!delivered) {
|
|
29635
|
+
return {
|
|
29636
|
+
ok: false,
|
|
29637
|
+
cause: new Error("relay has not delivered a packet for this source tx yet"),
|
|
29638
|
+
budgetable: backendAnswered
|
|
29639
|
+
};
|
|
29640
|
+
}
|
|
29641
|
+
return { ok: true, packet: delivered };
|
|
29642
|
+
}
|
|
29643
|
+
|
|
28952
29644
|
// src/backendApi/api-utils.ts
|
|
28953
29645
|
var API_KEY_HEADER = "x-api-key";
|
|
28954
29646
|
function apiKeyHeader(apiKey) {
|
|
@@ -29547,7 +30239,7 @@ function selectSolvedIntentPacket(packets, intentsContract) {
|
|
|
29547
30239
|
|
|
29548
30240
|
// src/swap/speed-tier.ts
|
|
29549
30241
|
var SPEED_TIER_SECONDS = {
|
|
29550
|
-
/** Either token
|
|
30242
|
+
/** Either token's vault is a money-market-reserve (sodaAsset). */
|
|
29551
30243
|
sodaAsset: 15,
|
|
29552
30244
|
/** Anything else / default. */
|
|
29553
30245
|
default: 35,
|
|
@@ -29565,7 +30257,7 @@ var secondsToTier = (seconds) => {
|
|
|
29565
30257
|
return "slow";
|
|
29566
30258
|
};
|
|
29567
30259
|
function estimateSwapSpeedTier({ srcToken, dstToken }, isSodaAssetRelated) {
|
|
29568
|
-
const eitherSodaAsset = isSodaAssetRelated(srcToken.
|
|
30260
|
+
const eitherSodaAsset = isSodaAssetRelated(srcToken.vault) || isSodaAssetRelated(dstToken.vault);
|
|
29569
30261
|
let estimatedSeconds = eitherSodaAsset ? SPEED_TIER_SECONDS.sodaAsset : SPEED_TIER_SECONDS.default;
|
|
29570
30262
|
if (isEthereumToken(srcToken) || isEthereumToken(dstToken)) {
|
|
29571
30263
|
estimatedSeconds += SPEED_TIER_SECONDS.ethereumPenalty;
|
|
@@ -29573,12 +30265,6 @@ function estimateSwapSpeedTier({ srcToken, dstToken }, isSodaAssetRelated) {
|
|
|
29573
30265
|
return { tier: secondsToTier(estimatedSeconds), estimatedSeconds };
|
|
29574
30266
|
}
|
|
29575
30267
|
|
|
29576
|
-
// src/swap/detailedStatus.ts
|
|
29577
|
-
var DETAILED_STATUS_NOT_DELIVERED = "relay_not_delivered";
|
|
29578
|
-
function isBackendSubmitTxAbandoned(data) {
|
|
29579
|
-
return data.status === "failed" || Boolean(data.abandonedAt);
|
|
29580
|
-
}
|
|
29581
|
-
|
|
29582
30268
|
// src/swap/errors.ts
|
|
29583
30269
|
var swapInvariant = createInvariant("swap");
|
|
29584
30270
|
var POST_EXECUTION_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
@@ -29775,14 +30461,22 @@ var SwapService = class {
|
|
|
29775
30461
|
*/
|
|
29776
30462
|
async getDetailedStatus(params) {
|
|
29777
30463
|
try {
|
|
29778
|
-
const
|
|
30464
|
+
const record = await this.backendApi.swaps.getSubmitTxStatus({
|
|
29779
30465
|
txHash: params.srcTxHash,
|
|
29780
30466
|
srcChainKey: params.srcChainKey
|
|
29781
30467
|
});
|
|
29782
|
-
if (
|
|
29783
|
-
return { ok: true, value: { source: "backend", data:
|
|
30468
|
+
if (record.ok && record.value.success && !isBackendSubmitTxAbandoned(record.value.data)) {
|
|
30469
|
+
return { ok: true, value: { source: "backend", data: record.value.data } };
|
|
30470
|
+
}
|
|
30471
|
+
if (!record.ok && isSodaxError(record.error) && isAuthFailure(record.error)) {
|
|
30472
|
+
return {
|
|
30473
|
+
ok: false,
|
|
30474
|
+
error: this.detailedStatusLookupFailed(record.error, params.srcChainKey, {
|
|
30475
|
+
status: record.error.context?.status
|
|
30476
|
+
})
|
|
30477
|
+
};
|
|
29784
30478
|
}
|
|
29785
|
-
const backendAnswered =
|
|
30479
|
+
const backendAnswered = record.ok || isSodaxError(record.error) && record.error.context?.status === 404;
|
|
29786
30480
|
const dstTxHash = await this.resolveHubTxHash(params, backendAnswered);
|
|
29787
30481
|
if (!dstTxHash.ok) return dstTxHash;
|
|
29788
30482
|
const solver = await this.resolveSolverStatus(
|
|
@@ -29803,48 +30497,23 @@ var SwapService = class {
|
|
|
29803
30497
|
* is simply "no hash yet".
|
|
29804
30498
|
*/
|
|
29805
30499
|
async resolveHubTxHash(key, backendAnswered) {
|
|
29806
|
-
const missReason = backendAnswered ? DETAILED_STATUS_NOT_DELIVERED : void 0;
|
|
29807
30500
|
let hubTxHash = key.srcTxHash;
|
|
29808
30501
|
if (!isHubChainKeyType(key.srcChainKey)) {
|
|
29809
|
-
const
|
|
29810
|
-
|
|
29811
|
-
|
|
29812
|
-
|
|
29813
|
-
|
|
29814
|
-
|
|
29815
|
-
|
|
29816
|
-
RELAY_REQUEST_TIMEOUT_MS
|
|
29817
|
-
);
|
|
29818
|
-
if (!packets.ok) {
|
|
29819
|
-
const notIndexed = packets.error instanceof HttpRelayError && packets.error.status === 404;
|
|
29820
|
-
return {
|
|
29821
|
-
ok: false,
|
|
29822
|
-
error: this.detailedStatusLookupFailed(packets.error, key.srcChainKey, notIndexed ? missReason : void 0)
|
|
29823
|
-
};
|
|
29824
|
-
}
|
|
29825
|
-
if (!packets.value?.success || !Array.isArray(packets.value.data)) {
|
|
29826
|
-
return {
|
|
29827
|
-
ok: false,
|
|
29828
|
-
error: this.detailedStatusLookupFailed(
|
|
29829
|
-
new Error("relay returned no usable transaction packets"),
|
|
29830
|
-
key.srcChainKey
|
|
29831
|
-
)
|
|
29832
|
-
};
|
|
29833
|
-
}
|
|
29834
|
-
const delivered = packets.value.data.find(
|
|
29835
|
-
(packet) => typeof packet?.src_tx_hash === "string" && packet.src_tx_hash.toLowerCase() === key.srcTxHash.toLowerCase() && packet.src_chain_id === Number(relayChainId) && packet.status === "executed" && typeof packet.dst_tx_hash === "string" && packet.dst_tx_hash.length > 0
|
|
29836
|
-
);
|
|
29837
|
-
if (!delivered) {
|
|
30502
|
+
const delivered = await resolveDeliveredPacket({
|
|
30503
|
+
srcChainKey: key.srcChainKey,
|
|
30504
|
+
srcTxHash: key.srcTxHash,
|
|
30505
|
+
relayerApiEndpoint: this.relayerApiEndpoint,
|
|
30506
|
+
backendAnswered
|
|
30507
|
+
});
|
|
30508
|
+
if (!delivered.ok) {
|
|
29838
30509
|
return {
|
|
29839
30510
|
ok: false,
|
|
29840
|
-
error: this.detailedStatusLookupFailed(
|
|
29841
|
-
|
|
29842
|
-
|
|
29843
|
-
missReason
|
|
29844
|
-
)
|
|
30511
|
+
error: this.detailedStatusLookupFailed(delivered.cause, key.srcChainKey, {
|
|
30512
|
+
reason: delivered.budgetable ? DETAILED_STATUS_NOT_DELIVERED : void 0
|
|
30513
|
+
})
|
|
29845
30514
|
};
|
|
29846
30515
|
}
|
|
29847
|
-
hubTxHash = delivered.dst_tx_hash;
|
|
30516
|
+
hubTxHash = delivered.packet.dst_tx_hash;
|
|
29848
30517
|
}
|
|
29849
30518
|
if (isHex(hubTxHash)) return { ok: true, value: hubTxHash };
|
|
29850
30519
|
return {
|
|
@@ -29858,10 +30527,12 @@ var SwapService = class {
|
|
|
29858
30527
|
/**
|
|
29859
30528
|
* `reason` is set only for {@link DETAILED_STATUS_NOT_DELIVERED} — the miss a caller can bound
|
|
29860
30529
|
* with a retry budget. Leaving it off marks a dependency that is failing right now, which a
|
|
29861
|
-
* caller should keep retrying rather than give up on.
|
|
30530
|
+
* caller should keep retrying rather than give up on. `status` is lifted for a rejected key so
|
|
30531
|
+
* `isAuthFailure` recognises the wrapped error; it reads `context.status` and does not walk the
|
|
30532
|
+
* cause chain.
|
|
29862
30533
|
*/
|
|
29863
|
-
detailedStatusLookupFailed(cause, srcChainKey,
|
|
29864
|
-
return lookupFailed("swap", "getDetailedStatus", cause, { srcChainKey, action: "swap",
|
|
30534
|
+
detailedStatusLookupFailed(cause, srcChainKey, extra) {
|
|
30535
|
+
return lookupFailed("swap", "getDetailedStatus", cause, { srcChainKey, action: "swap", ...extra });
|
|
29865
30536
|
}
|
|
29866
30537
|
/**
|
|
29867
30538
|
* Notifies the solver API that an intent has been registered on the hub chain, triggering
|
|
@@ -30924,7 +31595,7 @@ var SwapService = class {
|
|
|
30924
31595
|
/**
|
|
30925
31596
|
* Offline, rule-based estimate of how fast a `srcToken`→`dstToken` swap will settle.
|
|
30926
31597
|
*
|
|
30927
|
-
* Derived purely from SDK config (no network / on-chain / backend call): tokens
|
|
31598
|
+
* Derived purely from SDK config (no network / on-chain / backend call): tokens whose vault is a
|
|
30928
31599
|
* money-market-reserve sodaAsset settle faster, and an Ethereum leg adds a fixed penalty. See
|
|
30929
31600
|
* {@link estimateSwapSpeedTier} for the rules.
|
|
30930
31601
|
*
|
|
@@ -30932,7 +31603,7 @@ var SwapService = class {
|
|
|
30932
31603
|
* @returns the estimated `tier` bucket and `estimatedSeconds`
|
|
30933
31604
|
*/
|
|
30934
31605
|
getSwapSpeedTier(params) {
|
|
30935
|
-
return estimateSwapSpeedTier(params, (
|
|
31606
|
+
return estimateSwapSpeedTier(params, (vault) => this.config.isMoneyMarketReserveAsset(vault));
|
|
30936
31607
|
}
|
|
30937
31608
|
};
|
|
30938
31609
|
|
|
@@ -33432,173 +34103,6 @@ var SponsoringApiService = class {
|
|
|
33432
34103
|
return this.config.baseURL;
|
|
33433
34104
|
}
|
|
33434
34105
|
};
|
|
33435
|
-
var RelayExtraDataResponseSchema = v.object({
|
|
33436
|
-
address: v.string(),
|
|
33437
|
-
payload: v.string()
|
|
33438
|
-
});
|
|
33439
|
-
var BridgeTokenSchema = v.object({
|
|
33440
|
-
symbol: v.string(),
|
|
33441
|
-
name: v.string(),
|
|
33442
|
-
decimals: v.number(),
|
|
33443
|
-
address: v.string(),
|
|
33444
|
-
chainKey: v.string(),
|
|
33445
|
-
hubAsset: v.string(),
|
|
33446
|
-
vault: v.string()
|
|
33447
|
-
});
|
|
33448
|
-
var BridgeTokensResponseSchema = v.record(v.string(), v.array(BridgeTokenSchema));
|
|
33449
|
-
var BridgeTokensByChainResponseSchema = v.array(BridgeTokenSchema);
|
|
33450
|
-
var BridgeAllowanceCheckResponseSchema = v.object({
|
|
33451
|
-
valid: v.boolean()
|
|
33452
|
-
});
|
|
33453
|
-
var makeBridgeApproveResponseSchema = (txSchema) => v.object({ tx: txSchema, resetTx: v.optional(txSchema) });
|
|
33454
|
-
var makeCreateBridgeIntentResponseSchema = (txSchema) => v.object({
|
|
33455
|
-
tx: txSchema,
|
|
33456
|
-
relayData: RelayExtraDataResponseSchema
|
|
33457
|
-
});
|
|
33458
|
-
var BridgeSubmitTxResponseSchema = v.object({
|
|
33459
|
-
success: v.boolean(),
|
|
33460
|
-
data: v.object({
|
|
33461
|
-
status: v.picklist(["inserted", "duplicate"]),
|
|
33462
|
-
message: v.string()
|
|
33463
|
-
})
|
|
33464
|
-
});
|
|
33465
|
-
var BridgePacketDataSchema = v.object({
|
|
33466
|
-
src_chain_id: v.number(),
|
|
33467
|
-
src_tx_hash: v.string(),
|
|
33468
|
-
src_address: v.string(),
|
|
33469
|
-
status: v.picklist(["pending", "validating", "executing", "executed"]),
|
|
33470
|
-
dst_chain_id: v.number(),
|
|
33471
|
-
conn_sn: v.number(),
|
|
33472
|
-
dst_address: v.string(),
|
|
33473
|
-
dst_tx_hash: v.string(),
|
|
33474
|
-
signatures: v.array(v.string()),
|
|
33475
|
-
payload: v.string()
|
|
33476
|
-
});
|
|
33477
|
-
var BridgeSubmitTxStatusResultSchema = v.object({
|
|
33478
|
-
dstIntentTxHash: v.string(),
|
|
33479
|
-
packetData: v.optional(BridgePacketDataSchema)
|
|
33480
|
-
});
|
|
33481
|
-
var BridgeSubmitTxStatusDataSchema = v.object({
|
|
33482
|
-
txHash: v.string(),
|
|
33483
|
-
srcChainKey: v.string(),
|
|
33484
|
-
status: v.string(),
|
|
33485
|
-
failedAtStep: v.optional(v.string()),
|
|
33486
|
-
failureReason: v.optional(v.string()),
|
|
33487
|
-
processingAttempts: v.number(),
|
|
33488
|
-
abandonedAt: v.optional(v.string()),
|
|
33489
|
-
result: v.optional(BridgeSubmitTxStatusResultSchema),
|
|
33490
|
-
userMessage: v.optional(v.string())
|
|
33491
|
-
});
|
|
33492
|
-
var BridgeSubmitTxStatusResponseSchema = v.object({
|
|
33493
|
-
success: v.boolean(),
|
|
33494
|
-
data: BridgeSubmitTxStatusDataSchema
|
|
33495
|
-
});
|
|
33496
|
-
var BridgeFeeResponseSchema = v.object({ fee: v.string() });
|
|
33497
|
-
var BridgeLimitSchema = v.object({
|
|
33498
|
-
amount: v.string(),
|
|
33499
|
-
decimals: v.number(),
|
|
33500
|
-
type: v.picklist(["DEPOSIT_LIMIT", "WITHDRAWAL_LIMIT"])
|
|
33501
|
-
});
|
|
33502
|
-
var BridgeableAmountResponseSchema = v.object({ limit: BridgeLimitSchema });
|
|
33503
|
-
var BridgeableCheckResponseSchema = v.object({ bridgeable: v.boolean() });
|
|
33504
|
-
var AddressSchema2 = v.custom((input) => typeof input === "string");
|
|
33505
|
-
var HexSchema = v.custom((input) => typeof input === "string");
|
|
33506
|
-
var BigintFromString = v.pipe(v.string(), v.toBigint());
|
|
33507
|
-
var BytesFromIndexRecord = v.pipe(
|
|
33508
|
-
v.record(v.string(), v.number()),
|
|
33509
|
-
v.transform((indexed) => Uint8Array.from(Object.values(indexed)))
|
|
33510
|
-
);
|
|
33511
|
-
var EvmRawTxSchema = v.object({
|
|
33512
|
-
from: AddressSchema2,
|
|
33513
|
-
to: AddressSchema2,
|
|
33514
|
-
value: BigintFromString,
|
|
33515
|
-
data: HexSchema
|
|
33516
|
-
});
|
|
33517
|
-
var SolanaRawTxSchema = v.object({
|
|
33518
|
-
from: v.string(),
|
|
33519
|
-
to: v.string(),
|
|
33520
|
-
value: BigintFromString,
|
|
33521
|
-
data: v.string()
|
|
33522
|
-
});
|
|
33523
|
-
var SuiRawTxSchema = v.object({
|
|
33524
|
-
from: HexSchema,
|
|
33525
|
-
to: v.string(),
|
|
33526
|
-
value: BigintFromString,
|
|
33527
|
-
data: v.string()
|
|
33528
|
-
});
|
|
33529
|
-
var StellarRawTxSchema = v.object({
|
|
33530
|
-
from: v.string(),
|
|
33531
|
-
to: v.string(),
|
|
33532
|
-
value: BigintFromString,
|
|
33533
|
-
data: v.string()
|
|
33534
|
-
});
|
|
33535
|
-
var BitcoinRawTxSchema = v.object({
|
|
33536
|
-
from: v.string(),
|
|
33537
|
-
to: v.string(),
|
|
33538
|
-
value: BigintFromString,
|
|
33539
|
-
data: v.string()
|
|
33540
|
-
});
|
|
33541
|
-
var InjectiveRawTxSchema = v.object({
|
|
33542
|
-
from: HexSchema,
|
|
33543
|
-
to: HexSchema,
|
|
33544
|
-
signedDoc: v.object({
|
|
33545
|
-
bodyBytes: BytesFromIndexRecord,
|
|
33546
|
-
authInfoBytes: BytesFromIndexRecord,
|
|
33547
|
-
chainId: v.string(),
|
|
33548
|
-
accountNumber: BigintFromString
|
|
33549
|
-
})
|
|
33550
|
-
});
|
|
33551
|
-
var NearRawTxSchema = v.object({
|
|
33552
|
-
signerId: v.string(),
|
|
33553
|
-
params: v.object({
|
|
33554
|
-
contractId: v.string(),
|
|
33555
|
-
method: v.string(),
|
|
33556
|
-
args: v.custom((input) => typeof input === "object" && input !== null),
|
|
33557
|
-
gas: v.optional(BigintFromString),
|
|
33558
|
-
deposit: v.optional(BigintFromString)
|
|
33559
|
-
})
|
|
33560
|
-
});
|
|
33561
|
-
var IconRawTxSchema = v.record(
|
|
33562
|
-
v.string(),
|
|
33563
|
-
v.union([v.string(), v.custom((input) => typeof input === "object" && input !== null)])
|
|
33564
|
-
);
|
|
33565
|
-
var StacksRawTxSchema = v.object({
|
|
33566
|
-
payload: v.string(),
|
|
33567
|
-
estimatedLength: v.optional(v.number())
|
|
33568
|
-
});
|
|
33569
|
-
var AnyRawTxSchema = v.custom((input) => typeof input === "object" && input !== null);
|
|
33570
|
-
function rawTxSchemaForChainKey(chainKey) {
|
|
33571
|
-
let chainType;
|
|
33572
|
-
try {
|
|
33573
|
-
chainType = getChainType(chainKey);
|
|
33574
|
-
} catch {
|
|
33575
|
-
chainType = void 0;
|
|
33576
|
-
}
|
|
33577
|
-
switch (chainType) {
|
|
33578
|
-
case "EVM":
|
|
33579
|
-
return EvmRawTxSchema;
|
|
33580
|
-
case "SOLANA":
|
|
33581
|
-
return SolanaRawTxSchema;
|
|
33582
|
-
case "SUI":
|
|
33583
|
-
return SuiRawTxSchema;
|
|
33584
|
-
case "STELLAR":
|
|
33585
|
-
return StellarRawTxSchema;
|
|
33586
|
-
case "INJECTIVE":
|
|
33587
|
-
return InjectiveRawTxSchema;
|
|
33588
|
-
case "ICON":
|
|
33589
|
-
return IconRawTxSchema;
|
|
33590
|
-
case "STACKS":
|
|
33591
|
-
return StacksRawTxSchema;
|
|
33592
|
-
case "NEAR":
|
|
33593
|
-
return NearRawTxSchema;
|
|
33594
|
-
case "BITCOIN":
|
|
33595
|
-
return BitcoinRawTxSchema;
|
|
33596
|
-
default:
|
|
33597
|
-
return AnyRawTxSchema;
|
|
33598
|
-
}
|
|
33599
|
-
}
|
|
33600
|
-
|
|
33601
|
-
// src/backendApi/BridgeApiService.ts
|
|
33602
34106
|
function toCreateBridgeIntentParamsV2(params, extras) {
|
|
33603
34107
|
return {
|
|
33604
34108
|
srcChainKey: params.srcChainKey,
|
|
@@ -33623,41 +34127,63 @@ var BridgeApiService = class {
|
|
|
33623
34127
|
trimsLegacyOverrides;
|
|
33624
34128
|
constructor(config, logger = consoleLogger, options = {}) {
|
|
33625
34129
|
this.config = config;
|
|
33626
|
-
this.headers =
|
|
34130
|
+
this.headers = mergeHeaders(config.headers);
|
|
33627
34131
|
this.logger = logger;
|
|
33628
34132
|
this.trimsLegacyOverrides = options.trimLegacyOverrides ?? true;
|
|
33629
34133
|
}
|
|
33630
34134
|
/**
|
|
33631
|
-
*
|
|
33632
|
-
*
|
|
33633
|
-
*
|
|
33634
|
-
*
|
|
34135
|
+
* Build a `@sodax/bridge-api` client for a single call. Maps the SDK's {@link BaseApiConfig}
|
|
34136
|
+
* (`baseURL`/`timeout`/`headers`) to the package's config (`baseUrl`/`timeout`/`headers`), layering
|
|
34137
|
+
* the optional per-call `RequestOverrideConfig` on top (override wins per field; headers merge).
|
|
34138
|
+
* `timeout` falls back to the backend-API default so a config that omits it still gets a ceiling
|
|
34139
|
+
* rather than an unbounded request. Constructed per call so `setHeaders` mutations and per-call
|
|
34140
|
+
* overrides both take effect without caching stale state.
|
|
33635
34141
|
*/
|
|
33636
|
-
|
|
34142
|
+
buildClient(overrideConfig) {
|
|
34143
|
+
const override = overrideConfig?.baseURL;
|
|
34144
|
+
const baseUrl = override ? this.trimsLegacyOverrides ? stripLegacyBackendMount(override) : override : this.config.baseURL;
|
|
34145
|
+
const timeout = overrideConfig?.timeout ?? this.config.timeout ?? DEFAULT_BACKEND_API_TIMEOUT;
|
|
34146
|
+
const headers = mergeHeaders(this.headers, apiKeyHeader(overrideConfig?.apiKey), overrideConfig?.headers);
|
|
34147
|
+
return new BridgeApi({ baseUrl, headers, timeout });
|
|
34148
|
+
}
|
|
34149
|
+
/**
|
|
34150
|
+
* Run one delegated `BridgeApi` call and wrap it in `Result<T>`. A thrown `BridgeApiError`
|
|
34151
|
+
* (network/timeout/HTTP/parse/validation) becomes `{ ok: false }` with a canonical
|
|
34152
|
+
* `SodaxError<'EXTERNAL_API_ERROR'>`; the original error is kept as `cause`, and its
|
|
34153
|
+
* `code`/`status`/`issues` are projected into `context` so consumers can discriminate failure
|
|
34154
|
+
* kinds without unwrapping `cause`. Only a RESPONSE-shape validation failure is tagged
|
|
34155
|
+
* `reason: 'invalid_response_shape'` — a request-side validation error is a caller bug, not a
|
|
34156
|
+
* backend fault.
|
|
34157
|
+
*/
|
|
34158
|
+
async toResult(endpoint, call, overrideConfig) {
|
|
33637
34159
|
try {
|
|
33638
|
-
const
|
|
33639
|
-
|
|
33640
|
-
config: { baseURL: this.config.baseURL, timeout: this.config.timeout, headers: this.headers, ...config },
|
|
33641
|
-
// Normalized like a configured base URL: the override is the gateway root, so a legacy
|
|
33642
|
-
// `/be`-suffixed value must not nest `/bridge/*` under the data API's mount — unless the config
|
|
33643
|
-
// opted out of the legacy trim, in which case the per-call value is left exactly as given.
|
|
33644
|
-
overrideConfig: this.trimsLegacyOverrides ? normalizeOverrideBaseURL(overrideConfig) : overrideConfig,
|
|
33645
|
-
logger: this.logger,
|
|
33646
|
-
serviceLabel: "BridgeApiService"
|
|
33647
|
-
});
|
|
33648
|
-
const parsed = v.safeParse(schema, raw);
|
|
33649
|
-
if (!parsed.success) {
|
|
33650
|
-
return {
|
|
33651
|
-
ok: false,
|
|
33652
|
-
error: new SodaxError("EXTERNAL_API_ERROR", `Invalid response shape from bridge API for ${endpoint}`, {
|
|
33653
|
-
feature: "backend",
|
|
33654
|
-
context: { api: "bridge", endpoint, reason: "invalid_response_shape", issues: v.flatten(parsed.issues) }
|
|
33655
|
-
})
|
|
33656
|
-
};
|
|
33657
|
-
}
|
|
33658
|
-
return { ok: true, value: parsed.output };
|
|
34160
|
+
const value = await call(this.buildClient(overrideConfig));
|
|
34161
|
+
return { ok: true, value };
|
|
33659
34162
|
} catch (error) {
|
|
33660
|
-
|
|
34163
|
+
const context = { api: "bridge", endpoint };
|
|
34164
|
+
if (error instanceof BridgeApiError) {
|
|
34165
|
+
context.code = error.code;
|
|
34166
|
+
if (error.code === "VALIDATION_ERROR" && error.context.issues !== void 0) {
|
|
34167
|
+
context.reason = "invalid_response_shape";
|
|
34168
|
+
const issues = error.context.issues;
|
|
34169
|
+
context.issues = issues instanceof v.ValiError ? v.flatten(issues.issues) : issues;
|
|
34170
|
+
}
|
|
34171
|
+
if (error.context.status !== void 0) context.status = error.context.status;
|
|
34172
|
+
if (isAuthStatus(error.context.status)) {
|
|
34173
|
+
this.logger.warn(
|
|
34174
|
+
`[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.`
|
|
34175
|
+
);
|
|
34176
|
+
}
|
|
34177
|
+
}
|
|
34178
|
+
this.logger.error(`[BridgeApiService] Request to ${endpoint} failed`, error);
|
|
34179
|
+
return {
|
|
34180
|
+
ok: false,
|
|
34181
|
+
error: new SodaxError(
|
|
34182
|
+
"EXTERNAL_API_ERROR",
|
|
34183
|
+
error instanceof Error ? error.message : `Request to ${endpoint} failed`,
|
|
34184
|
+
{ feature: "backend", cause: error, context }
|
|
34185
|
+
)
|
|
34186
|
+
};
|
|
33661
34187
|
}
|
|
33662
34188
|
}
|
|
33663
34189
|
// ──────────────────────────────────────────────────────────────────────
|
|
@@ -33669,7 +34195,7 @@ var BridgeApiService = class {
|
|
|
33669
34195
|
* @returns `Result<GetBridgeTokensResponseV2>` — map of chain key → token list.
|
|
33670
34196
|
*/
|
|
33671
34197
|
async getTokens(config) {
|
|
33672
|
-
return this.
|
|
34198
|
+
return this.toResult("/bridge/tokens", (c) => c.getTokens(), config);
|
|
33673
34199
|
}
|
|
33674
34200
|
/**
|
|
33675
34201
|
* Fetch supported bridge tokens for a single SpokeChainKey.
|
|
@@ -33678,12 +34204,7 @@ var BridgeApiService = class {
|
|
|
33678
34204
|
* @returns `Result<GetBridgeTokensByChainResponseV2>` — token list for the chain.
|
|
33679
34205
|
*/
|
|
33680
34206
|
async getTokensByChain(chainKey, config) {
|
|
33681
|
-
return this.
|
|
33682
|
-
`/bridge/tokens/${chainKey}`,
|
|
33683
|
-
{ method: "GET" },
|
|
33684
|
-
BridgeTokensByChainResponseSchema,
|
|
33685
|
-
config
|
|
33686
|
-
);
|
|
34207
|
+
return this.toResult(`/bridge/tokens/${chainKey}`, (c) => c.getTokensByChain(chainKey), config);
|
|
33687
34208
|
}
|
|
33688
34209
|
// ──────────────────────────────────────────────────────────────────────
|
|
33689
34210
|
// Allowance · approve · create intent
|
|
@@ -33694,12 +34215,7 @@ var BridgeApiService = class {
|
|
|
33694
34215
|
* @returns `Result<BridgeAllowanceCheckResponseV2>` — `{ valid }`.
|
|
33695
34216
|
*/
|
|
33696
34217
|
async checkAllowance(body, config) {
|
|
33697
|
-
return this.
|
|
33698
|
-
"/bridge/allowance/check",
|
|
33699
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33700
|
-
BridgeAllowanceCheckResponseSchema,
|
|
33701
|
-
config
|
|
33702
|
-
);
|
|
34218
|
+
return this.toResult("/bridge/allowance/check", (c) => c.checkAllowance(body), config);
|
|
33703
34219
|
}
|
|
33704
34220
|
/**
|
|
33705
34221
|
* Build an unsigned token-approval transaction for the source token.
|
|
@@ -33708,13 +34224,7 @@ var BridgeApiService = class {
|
|
|
33708
34224
|
* broadcast and mine `resetTx` first when it is present.
|
|
33709
34225
|
*/
|
|
33710
34226
|
async approve(body, config) {
|
|
33711
|
-
|
|
33712
|
-
return this.request(
|
|
33713
|
-
"/bridge/approve",
|
|
33714
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33715
|
-
makeBridgeApproveResponseSchema(txSchema),
|
|
33716
|
-
config
|
|
33717
|
-
);
|
|
34227
|
+
return this.toResult("/bridge/approve", (c) => c.approve(body), config);
|
|
33718
34228
|
}
|
|
33719
34229
|
/**
|
|
33720
34230
|
* Build an unsigned spoke-deposit (create-bridge-intent) transaction.
|
|
@@ -33722,13 +34232,7 @@ var BridgeApiService = class {
|
|
|
33722
34232
|
* @returns `Result<CreateBridgeIntentResponseV2>` — `{ tx, relayData }` (no intent struct).
|
|
33723
34233
|
*/
|
|
33724
34234
|
async createBridgeIntent(body, config) {
|
|
33725
|
-
|
|
33726
|
-
return this.request(
|
|
33727
|
-
"/bridge/intents",
|
|
33728
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33729
|
-
makeCreateBridgeIntentResponseSchema(txSchema),
|
|
33730
|
-
config
|
|
33731
|
-
);
|
|
34235
|
+
return this.toResult("/bridge/intents", (c) => c.createBridgeIntent(body), config);
|
|
33732
34236
|
}
|
|
33733
34237
|
// ──────────────────────────────────────────────────────────────────────
|
|
33734
34238
|
// Submit-tx state machine
|
|
@@ -33740,12 +34244,7 @@ var BridgeApiService = class {
|
|
|
33740
34244
|
* @returns `Result<BridgeSubmitTxResponseV2>` — `{ success, data: { status, message } }`.
|
|
33741
34245
|
*/
|
|
33742
34246
|
async submitTx(body, config) {
|
|
33743
|
-
return this.
|
|
33744
|
-
"/bridge/submit-tx",
|
|
33745
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33746
|
-
BridgeSubmitTxResponseSchema,
|
|
33747
|
-
config
|
|
33748
|
-
);
|
|
34247
|
+
return this.toResult("/bridge/submit-tx", (c) => c.submitTx(body), config);
|
|
33749
34248
|
}
|
|
33750
34249
|
/**
|
|
33751
34250
|
* Get the processing status of a submitted bridge transaction by `(txHash, srcChainKey)`.
|
|
@@ -33753,13 +34252,7 @@ var BridgeApiService = class {
|
|
|
33753
34252
|
* @returns `Result<BridgeSubmitTxStatusResponseV2>` — `{ success, data }` (processing state).
|
|
33754
34253
|
*/
|
|
33755
34254
|
async getSubmitTxStatus(query, config) {
|
|
33756
|
-
|
|
33757
|
-
return this.request(
|
|
33758
|
-
`/bridge/submit-tx/status?${queryParams.toString()}`,
|
|
33759
|
-
{ method: "GET" },
|
|
33760
|
-
BridgeSubmitTxStatusResponseSchema,
|
|
33761
|
-
config
|
|
33762
|
-
);
|
|
34255
|
+
return this.toResult("/bridge/submit-tx/status", (c) => c.getSubmitTxStatus(query), config);
|
|
33763
34256
|
}
|
|
33764
34257
|
// ──────────────────────────────────────────────────────────────────────
|
|
33765
34258
|
// Fee · bridgeable quote (read-only; mirror the SDK-core client-side methods)
|
|
@@ -33773,12 +34266,7 @@ var BridgeApiService = class {
|
|
|
33773
34266
|
* @returns `Result<BridgeFeeResponseV2>` — `{ fee }` (decimal string).
|
|
33774
34267
|
*/
|
|
33775
34268
|
async getFee(body, config) {
|
|
33776
|
-
return this.
|
|
33777
|
-
"/bridge/fee",
|
|
33778
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33779
|
-
BridgeFeeResponseSchema,
|
|
33780
|
-
config
|
|
33781
|
-
);
|
|
34269
|
+
return this.toResult("/bridge/fee", (c) => c.getFee(body), config);
|
|
33782
34270
|
}
|
|
33783
34271
|
/**
|
|
33784
34272
|
* Deposit capacity / withdrawal liquidity for a (from, to) token pair. Computable client-side in the
|
|
@@ -33787,12 +34275,7 @@ var BridgeApiService = class {
|
|
|
33787
34275
|
* @returns `Result<BridgeableAmountResponseV2>` — `{ limit }`.
|
|
33788
34276
|
*/
|
|
33789
34277
|
async getBridgeableAmount(body, config) {
|
|
33790
|
-
return this.
|
|
33791
|
-
"/bridge/bridgeable-amount",
|
|
33792
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33793
|
-
BridgeableAmountResponseSchema,
|
|
33794
|
-
config
|
|
33795
|
-
);
|
|
34278
|
+
return this.toResult("/bridge/bridgeable-amount", (c) => c.getBridgeableAmount(body), config);
|
|
33796
34279
|
}
|
|
33797
34280
|
/**
|
|
33798
34281
|
* Whether a (from, to) token pair is bridgeable. Computable client-side in the SDK core
|
|
@@ -33801,19 +34284,15 @@ var BridgeApiService = class {
|
|
|
33801
34284
|
* @returns `Result<BridgeableCheckResponseV2>` — `{ bridgeable }`.
|
|
33802
34285
|
*/
|
|
33803
34286
|
async isBridgeable(body, config) {
|
|
33804
|
-
return this.
|
|
33805
|
-
"/bridge/bridgeable/check",
|
|
33806
|
-
{ method: "POST", body: toJsonBody(body) },
|
|
33807
|
-
BridgeableCheckResponseSchema,
|
|
33808
|
-
config
|
|
33809
|
-
);
|
|
34287
|
+
return this.toResult("/bridge/bridgeable/check", (c) => c.isBridgeable(body), config);
|
|
33810
34288
|
}
|
|
33811
34289
|
// ──────────────────────────────────────────────────────────────────────
|
|
33812
34290
|
// Utilities (parity with SwapsApiService)
|
|
33813
34291
|
// ──────────────────────────────────────────────────────────────────────
|
|
33814
34292
|
/**
|
|
33815
34293
|
* Merge additional headers into the service's default header set. Existing
|
|
33816
|
-
* keys are overwritten; keys absent from `headers` are preserved.
|
|
34294
|
+
* keys are overwritten; keys absent from `headers` are preserved. Applied to
|
|
34295
|
+
* every subsequent call (the delegated client is rebuilt per call).
|
|
33817
34296
|
*/
|
|
33818
34297
|
setHeaders(headers) {
|
|
33819
34298
|
assignHeaders(this.headers, headers);
|
|
@@ -34146,7 +34625,7 @@ var LeverageYieldApiService = class _LeverageYieldApiService {
|
|
|
34146
34625
|
*/
|
|
34147
34626
|
async getDepositQuote(body, query, config) {
|
|
34148
34627
|
const endpoint = query?.includeTxData ? "/leverage-yield/quote/deposit?includeTxData=true" : "/leverage-yield/quote/deposit";
|
|
34149
|
-
const txSchema = rawTxSchemaForChainKey
|
|
34628
|
+
const txSchema = rawTxSchemaForChainKey(body.tokenSrcChainKey);
|
|
34150
34629
|
return this.request(
|
|
34151
34630
|
endpoint,
|
|
34152
34631
|
{ method: "POST", body: toJsonBody(body) },
|
|
@@ -34163,7 +34642,7 @@ var LeverageYieldApiService = class _LeverageYieldApiService {
|
|
|
34163
34642
|
*/
|
|
34164
34643
|
async getWithdrawQuote(body, query, config) {
|
|
34165
34644
|
const endpoint = query?.includeTxData ? "/leverage-yield/quote/withdraw?includeTxData=true" : "/leverage-yield/quote/withdraw";
|
|
34166
|
-
const txSchema = rawTxSchemaForChainKey
|
|
34645
|
+
const txSchema = rawTxSchemaForChainKey(body.srcChainKey);
|
|
34167
34646
|
return this.request(
|
|
34168
34647
|
endpoint,
|
|
34169
34648
|
{ method: "POST", body: toJsonBody(body) },
|
|
@@ -34209,7 +34688,7 @@ var LeverageYieldApiService = class _LeverageYieldApiService {
|
|
|
34209
34688
|
* @returns `Result<ApproveResponseV2>` — `{ tx }` (chain-specific unsigned tx).
|
|
34210
34689
|
*/
|
|
34211
34690
|
async approve(body, config) {
|
|
34212
|
-
const txSchema = rawTxSchemaForChainKey
|
|
34691
|
+
const txSchema = rawTxSchemaForChainKey(body.srcChainKey);
|
|
34213
34692
|
return this.request(
|
|
34214
34693
|
"/leverage-yield/approve",
|
|
34215
34694
|
{ method: "POST", body: toJsonBody(body) },
|
|
@@ -34223,7 +34702,7 @@ var LeverageYieldApiService = class _LeverageYieldApiService {
|
|
|
34223
34702
|
* @returns `Result<CreateIntentResponseV2>` — `{ tx, intent, relayData }`.
|
|
34224
34703
|
*/
|
|
34225
34704
|
async createDepositIntent(body, config) {
|
|
34226
|
-
const txSchema = rawTxSchemaForChainKey
|
|
34705
|
+
const txSchema = rawTxSchemaForChainKey(body.srcChainKey);
|
|
34227
34706
|
return this.request(
|
|
34228
34707
|
"/leverage-yield/intents/deposit",
|
|
34229
34708
|
{ method: "POST", body: toJsonBody(body) },
|
|
@@ -34238,7 +34717,7 @@ var LeverageYieldApiService = class _LeverageYieldApiService {
|
|
|
34238
34717
|
* @returns `Result<CreateIntentResponseV2>` — `{ tx, intent, relayData }`.
|
|
34239
34718
|
*/
|
|
34240
34719
|
async createWithdrawIntent(body, config) {
|
|
34241
|
-
const txSchema = rawTxSchemaForChainKey
|
|
34720
|
+
const txSchema = rawTxSchemaForChainKey(body.srcChainKey);
|
|
34242
34721
|
return this.request(
|
|
34243
34722
|
"/leverage-yield/intents/withdraw",
|
|
34244
34723
|
{ method: "POST", body: toJsonBody(body) },
|
|
@@ -34282,7 +34761,7 @@ var LeverageYieldApiService = class _LeverageYieldApiService {
|
|
|
34282
34761
|
* @returns `Result<CancelIntentResponseV2>` — `{ tx }`.
|
|
34283
34762
|
*/
|
|
34284
34763
|
async cancelIntent(body, config) {
|
|
34285
|
-
const txSchema = rawTxSchemaForChainKey
|
|
34764
|
+
const txSchema = rawTxSchemaForChainKey(body.srcChainKey);
|
|
34286
34765
|
return this.request(
|
|
34287
34766
|
"/leverage-yield/intents/cancel",
|
|
34288
34767
|
{ method: "POST", body: toJsonBody({ ...body, intent: _LeverageYieldApiService.toWireIntent(body.intent) }) },
|
|
@@ -34327,7 +34806,7 @@ var LeverageYieldApiService = class _LeverageYieldApiService {
|
|
|
34327
34806
|
return this.request(
|
|
34328
34807
|
"/leverage-yield/intents/extra-data",
|
|
34329
34808
|
{ method: "POST", body: toJsonBody(normalized) },
|
|
34330
|
-
RelayExtraDataResponseSchema
|
|
34809
|
+
RelayExtraDataResponseSchema,
|
|
34331
34810
|
config
|
|
34332
34811
|
);
|
|
34333
34812
|
}
|
|
@@ -35664,6 +36143,80 @@ var BridgeService = class {
|
|
|
35664
36143
|
}
|
|
35665
36144
|
return encodeContractCalls(calls);
|
|
35666
36145
|
}
|
|
36146
|
+
/**
|
|
36147
|
+
* Answers "what is the status of this bridge?" from the **source-chain** tx — the one identifier a
|
|
36148
|
+
* caller always holds. It does not define a new status: it routes to whichever of the two existing
|
|
36149
|
+
* sources can answer, and returns that source's payload unmodified.
|
|
36150
|
+
*
|
|
36151
|
+
* `sodax.api.bridge.getSubmitTxStatus` cannot answer for every bridge. Sometimes there is no
|
|
36152
|
+
* record — `useBackendSubmitTx: false`, or the submit itself never landed. More often the record
|
|
36153
|
+
* exists but is stale: the backend path POSTs the tx first and only falls back to the client-side
|
|
36154
|
+
* relay once that stalls, so a fallback-completed bridge leaves behind whatever state the backend
|
|
36155
|
+
* last reached, including a record it abandoned outright. Neither shape reflects what happened.
|
|
36156
|
+
*
|
|
36157
|
+
* 1. Read the backend record; return it while it is still in play.
|
|
36158
|
+
* 2. Otherwise return the delivered relay packet, which is terminal by construction.
|
|
36159
|
+
*
|
|
36160
|
+
* A rejected API key is the one failure that does **not** fall through to step 2: the status route
|
|
36161
|
+
* is key-guarded, so degrading would bury a 401/403 behind a relay error and leave a poller
|
|
36162
|
+
* retrying a request only a corrected key can satisfy. It surfaces with `context.status` instead,
|
|
36163
|
+
* which is what `isAuthFailure` reads.
|
|
36164
|
+
*
|
|
36165
|
+
* A point-in-time read; poll it yourself, or use dapp-kit's `useBridgeDetailedStatus`.
|
|
36166
|
+
*
|
|
36167
|
+
* @param params - `srcChainKey` and `srcTxHash` of the source-chain bridge transaction.
|
|
36168
|
+
* @param config - Optional per-request override for the backend read (e.g. a per-action API key).
|
|
36169
|
+
* The relay leg is unauthenticated and takes none.
|
|
36170
|
+
* @returns A `Result` containing a {@link DetailedBridgeStatus}. Fails with `LOOKUP_FAILED` when no
|
|
36171
|
+
* source can answer yet — usually the relay has not delivered the packet. Branch on
|
|
36172
|
+
* `error.context.reason`: `DETAILED_STATUS_NOT_DELIVERED` is the ambiguous miss a caller should
|
|
36173
|
+
* bound with a retry budget; anything else is a dependency failing right now, so keep retrying.
|
|
36174
|
+
*/
|
|
36175
|
+
async getDetailedStatus(params, config) {
|
|
36176
|
+
try {
|
|
36177
|
+
const record = await this.backendApi.bridge.getSubmitTxStatus(
|
|
36178
|
+
{ txHash: params.srcTxHash, srcChainKey: params.srcChainKey },
|
|
36179
|
+
config
|
|
36180
|
+
);
|
|
36181
|
+
if (record.ok && record.value.success && !isBackendSubmitTxAbandoned(record.value.data)) {
|
|
36182
|
+
return { ok: true, value: { source: "backend", data: record.value.data } };
|
|
36183
|
+
}
|
|
36184
|
+
if (!record.ok && isSodaxError(record.error) && isAuthFailure(record.error)) {
|
|
36185
|
+
return {
|
|
36186
|
+
ok: false,
|
|
36187
|
+
error: this.detailedStatusLookupFailed(record.error, params.srcChainKey, {
|
|
36188
|
+
status: record.error.context?.status
|
|
36189
|
+
})
|
|
36190
|
+
};
|
|
36191
|
+
}
|
|
36192
|
+
const backendAnswered = record.ok || isSodaxError(record.error) && record.error.context?.status === 404;
|
|
36193
|
+
const delivered = await resolveDeliveredPacket({
|
|
36194
|
+
srcChainKey: params.srcChainKey,
|
|
36195
|
+
srcTxHash: params.srcTxHash,
|
|
36196
|
+
relayerApiEndpoint: this.config.relay.relayerApiEndpoint,
|
|
36197
|
+
backendAnswered
|
|
36198
|
+
});
|
|
36199
|
+
if (!delivered.ok) {
|
|
36200
|
+
return {
|
|
36201
|
+
ok: false,
|
|
36202
|
+
error: this.detailedStatusLookupFailed(delivered.cause, params.srcChainKey, {
|
|
36203
|
+
reason: delivered.budgetable ? DETAILED_STATUS_NOT_DELIVERED : void 0
|
|
36204
|
+
})
|
|
36205
|
+
};
|
|
36206
|
+
}
|
|
36207
|
+
return { ok: true, value: { source: "relay", data: delivered.packet } };
|
|
36208
|
+
} catch (error) {
|
|
36209
|
+
return { ok: false, error: this.detailedStatusLookupFailed(error, params.srcChainKey) };
|
|
36210
|
+
}
|
|
36211
|
+
}
|
|
36212
|
+
/**
|
|
36213
|
+
* `reason` is set only for {@link DETAILED_STATUS_NOT_DELIVERED} — the miss a caller can bound with
|
|
36214
|
+
* a retry budget. `status` is lifted for a rejected key so `isAuthFailure` recognises the wrapped
|
|
36215
|
+
* error; it reads `context.status` and does not walk the cause chain.
|
|
36216
|
+
*/
|
|
36217
|
+
detailedStatusLookupFailed(cause, srcChainKey, extra) {
|
|
36218
|
+
return lookupFailed("bridge", "getDetailedStatus", cause, { srcChainKey, action: "bridge", ...extra });
|
|
36219
|
+
}
|
|
35667
36220
|
/**
|
|
35668
36221
|
* Returns the maximum amount that can currently be bridged between two tokens,
|
|
35669
36222
|
* taking into account both deposit capacity on the source side and withdrawal liquidity
|
|
@@ -43837,6 +44390,24 @@ var isLeverageYieldPostExecutionError = isCodeMember(
|
|
|
43837
44390
|
var isLeverageYieldSwapError = isCodeMember(LEVERAGE_YIELD_SWAP_CODES);
|
|
43838
44391
|
var isLeverageYieldError = isCodeMember(LEVERAGE_YIELD_CODES);
|
|
43839
44392
|
|
|
44393
|
+
// src/leverageYield/positionFunding.ts
|
|
44394
|
+
function resolvePositionFundingAddress(chainKey, hubChainKey, token) {
|
|
44395
|
+
if (chainKey !== hubChainKey) return token?.address ?? "";
|
|
44396
|
+
if (token && isNativeToken(chainKey, token)) return token.address;
|
|
44397
|
+
return token?.hubAsset ?? token?.address ?? "";
|
|
44398
|
+
}
|
|
44399
|
+
|
|
44400
|
+
// src/leverageYield/positionIntent.ts
|
|
44401
|
+
async function reportPositionIntent(notifySolver, txHashes) {
|
|
44402
|
+
const result = await notifySolver({ intent_tx_hash: txHashes.dstChainTxHash }).catch((error2) => ({
|
|
44403
|
+
ok: false,
|
|
44404
|
+
error: error2
|
|
44405
|
+
}));
|
|
44406
|
+
if (result.ok) return { txHashes, notified: true };
|
|
44407
|
+
const { error } = result;
|
|
44408
|
+
return { txHashes, notified: false, notifyError: error instanceof Error ? error.message : String(error) };
|
|
44409
|
+
}
|
|
44410
|
+
|
|
43840
44411
|
// src/leverageYield/LeverageYieldService.ts
|
|
43841
44412
|
var leverageYieldVaultAbi = parseAbi([
|
|
43842
44413
|
"function asset() view returns (address)",
|
|
@@ -43846,7 +44417,33 @@ var leverageYieldVaultAbi = parseAbi([
|
|
|
43846
44417
|
"function borrowToken() view returns (address)",
|
|
43847
44418
|
"function targetLTV() view returns (uint256)"
|
|
43848
44419
|
]);
|
|
44420
|
+
var MAX_POSITION_FEE_BPS = 100;
|
|
44421
|
+
var leveragePositionFactoryAbi = parseAbi([
|
|
44422
|
+
"function positionsOf(address owner) view returns (address[])",
|
|
44423
|
+
"function nextPositionIdFor(address owner) view returns (uint256)",
|
|
44424
|
+
"function predictPosition(address creator, address owner, uint256 positionId) view returns (address)",
|
|
44425
|
+
"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)",
|
|
44426
|
+
"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)"
|
|
44427
|
+
]);
|
|
44428
|
+
var leveragePositionAbi = parseAbi([
|
|
44429
|
+
"function owner() view returns (address)",
|
|
44430
|
+
"function collateral() view returns (address)",
|
|
44431
|
+
"function borrowToken() view returns (address)",
|
|
44432
|
+
"function eModeCategory() view returns (uint8)",
|
|
44433
|
+
"function feeBps() view returns (uint16)",
|
|
44434
|
+
"function feeReceiver() view returns (address)",
|
|
44435
|
+
"function hasPendingOperation() view returns (bool)",
|
|
44436
|
+
"function pendingKind() view returns (uint8)",
|
|
44437
|
+
"function addLeverage(uint256 borrowAmount, uint256 minCollateralOut)",
|
|
44438
|
+
"function decreaseLeverage(uint256 collateralIn, uint256 minDebtOut, address exitAsset)",
|
|
44439
|
+
"function withdraw(uint256 amount, address to)",
|
|
44440
|
+
"function cancel()",
|
|
44441
|
+
"function settle()"
|
|
44442
|
+
]);
|
|
43849
44443
|
var INTENT_DEADLINE_BUFFER_SECONDS = 5 * 60;
|
|
44444
|
+
var RECONCILE_TIMEOUT_MS2 = 5e3;
|
|
44445
|
+
var DETAILED_STATUS_SOLVER_TIMEOUT_MS2 = 5e3;
|
|
44446
|
+
var BITCOIN_UNSUPPORTED_MESSAGE = "Bitcoin is not a supported source chain for leverage positions; use a supported spoke or the hub";
|
|
43850
44447
|
var ANY_SOLVER_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
43851
44448
|
var MAX_WITHDRAW_DUST_BUFFER = 1000n;
|
|
43852
44449
|
function pctToRay(aprPct) {
|
|
@@ -43883,9 +44480,9 @@ var LeverageYieldService = class {
|
|
|
43883
44480
|
spoke;
|
|
43884
44481
|
backendApi;
|
|
43885
44482
|
/**
|
|
43886
|
-
* Effective backend submit-tx flow (`leverageYield.useBackendSubmitTx`, default
|
|
43887
|
-
* `ConfigService`, like `config.leverageYieldPartnerFee`, so the config
|
|
43888
|
-
* never disagree.
|
|
44483
|
+
* Effective backend submit-tx flow (`leverageYield.useBackendSubmitTx`, default ON; opt out with
|
|
44484
|
+
* `false`). Read live off `ConfigService`, like `config.leverageYieldPartnerFee`, so the config
|
|
44485
|
+
* object and the behavior can never disagree.
|
|
43889
44486
|
*/
|
|
43890
44487
|
get useBackendSubmitTx() {
|
|
43891
44488
|
return this.config.leverageYieldUseBackendSubmitTx;
|
|
@@ -43903,7 +44500,7 @@ var LeverageYieldService = class {
|
|
|
43903
44500
|
}
|
|
43904
44501
|
/** Looks up a vault by its `name` field. Returns `undefined` when not registered. */
|
|
43905
44502
|
getVault(name) {
|
|
43906
|
-
return this.listVaults().find((
|
|
44503
|
+
return this.listVaults().find((v10) => v10.name === name);
|
|
43907
44504
|
}
|
|
43908
44505
|
/**
|
|
43909
44506
|
* Looks up a registered vault by its on-chain proxy address (case-insensitive).
|
|
@@ -43911,7 +44508,7 @@ var LeverageYieldService = class {
|
|
|
43911
44508
|
*/
|
|
43912
44509
|
getVaultByAddress(address) {
|
|
43913
44510
|
const normalized = address.toLowerCase();
|
|
43914
|
-
return this.listVaults().find((
|
|
44511
|
+
return this.listVaults().find((v10) => v10.vault.toLowerCase() === normalized);
|
|
43915
44512
|
}
|
|
43916
44513
|
/**
|
|
43917
44514
|
* Resolves the intent `deadline`: returns the caller-supplied value verbatim, otherwise
|
|
@@ -44377,10 +44974,11 @@ var LeverageYieldService = class {
|
|
|
44377
44974
|
);
|
|
44378
44975
|
}
|
|
44379
44976
|
/**
|
|
44380
|
-
* Client-side vault-swap completion (the
|
|
44977
|
+
* Client-side vault-swap completion (the opt-out path, and the fallback): verify the broadcast
|
|
44978
|
+
* intent tx landed,
|
|
44381
44979
|
* relay it to the hub (Sonic) — or use it directly when the source IS the hub — then notify the
|
|
44382
44980
|
* solver via {@link LeverageYieldService.notifySolver} and build the {@link VaultSwapResponse}.
|
|
44383
|
-
* Extracted from `vaultSwap()` so the
|
|
44981
|
+
* Extracted from `vaultSwap()` so the default backend 2-step path ({@link LeverageYieldService.submitTx})
|
|
44384
44982
|
* can fall back to it on any non-success. Leverage-yield copy of `SwapService.fallbackSwapSteps`.
|
|
44385
44983
|
*/
|
|
44386
44984
|
async fallbackVaultSwapSteps(_params, created, timeoutMs) {
|
|
@@ -44438,7 +45036,8 @@ var LeverageYieldService = class {
|
|
|
44438
45036
|
};
|
|
44439
45037
|
}
|
|
44440
45038
|
/**
|
|
44441
|
-
* Backend 2-step vault-swap path (opt
|
|
45039
|
+
* Backend 2-step vault-swap path (the default; opt out with `leverageYield.useBackendSubmitTx:
|
|
45040
|
+
* false`): hand the
|
|
44442
45041
|
* broadcast intent tx to the leverage-yield API (`POST /leverage-yield/submit-tx`); the backend
|
|
44443
45042
|
* relays + post-executes server-side. Polls `getSubmitTxStatus` until `solved`, then reconstructs
|
|
44444
45043
|
* the same {@link VaultSwapResponse} the client-side path returns.
|
|
@@ -44477,6 +45076,10 @@ var LeverageYieldService = class {
|
|
|
44477
45076
|
operation: _params.hubWalletSwap ? "withdraw" : "deposit"
|
|
44478
45077
|
},
|
|
44479
45078
|
statusQuery: { txHash: spokeTxHash, srcChainKey },
|
|
45079
|
+
// Per-action key wins over the instance one for both legs of the attempt — the submit POST
|
|
45080
|
+
// and its status polls. Undefined leaves the configured key in place; the same per-action
|
|
45081
|
+
// override `extras.partnerFee` already has, travelling per call.
|
|
45082
|
+
overrideConfig: { apiKey: _params.extras?.apiKey },
|
|
44480
45083
|
// A vault deposit/withdraw IS a solver swap, so terminal success is `solved` — not bridge's
|
|
44481
45084
|
// `executed`.
|
|
44482
45085
|
terminalStatus: "solved",
|
|
@@ -44500,7 +45103,12 @@ var LeverageYieldService = class {
|
|
|
44500
45103
|
}
|
|
44501
45104
|
}
|
|
44502
45105
|
/**
|
|
44503
|
-
* Notifies the solver that
|
|
45106
|
+
* Notifies the solver that an intent landed on the hub, triggering it to fill.
|
|
45107
|
+
*
|
|
45108
|
+
* REQUIRED for anything that creates an intent, not an optimisation. An intent created on the hub
|
|
45109
|
+
* is invisible to the solver until this call puts it in the task pool, so an unnotified intent
|
|
45110
|
+
* simply expires. Leverage positions post their intents on-chain from the position contract, so
|
|
45111
|
+
* the caller that sent the transaction is the only one who can report the hash.
|
|
44504
45112
|
* Leverage-yield copy of the swap domain's `postExecution` — emits only
|
|
44505
45113
|
* `EXECUTION_FAILED` / `EXTERNAL_API_ERROR` / `UNKNOWN` (relay/verify codes appear only
|
|
44506
45114
|
* on {@link LeverageYieldService.vaultSwap}, which owns the verify + relay steps).
|
|
@@ -44545,6 +45153,209 @@ var LeverageYieldService = class {
|
|
|
44545
45153
|
return { ok: false, error: executionFailed("leverageYield", error, { phase: "postExecution" }) };
|
|
44546
45154
|
}
|
|
44547
45155
|
}
|
|
45156
|
+
/**
|
|
45157
|
+
* Polls the solver for the execution status of an intent this service created.
|
|
45158
|
+
*
|
|
45159
|
+
* Pair with {@link LeverageYieldService.notifySolver}: `notifySolver` puts the intent in the
|
|
45160
|
+
* solver's task pool, this reports what became of it. `fill_tx_hash` is set only once
|
|
45161
|
+
* `status === SolverIntentStatusCode.SOLVED`.
|
|
45162
|
+
*
|
|
45163
|
+
* A `NOT_FOUND` status usually means the notification never landed rather than that the intent
|
|
45164
|
+
* does not exist — an intent created on the hub is invisible to the solver until it is told.
|
|
45165
|
+
*
|
|
45166
|
+
* Reports the solver verbatim. It does NOT reconcile a `NOT_FOUND` against the backend's durable
|
|
45167
|
+
* record the way {@link LeverageYieldService.getDetailedStatus} does — a restarted solver answers
|
|
45168
|
+
* `NOT_FOUND` for intents it already filled, and that read resolves it. Keeping this one
|
|
45169
|
+
* unreconciled is deliberate: it has shipped with this contract, and folding the reconcile in
|
|
45170
|
+
* would turn a `NOT_FOUND` behind an unreadable backend into an error for every existing caller.
|
|
45171
|
+
* Prefer `getDetailedStatus` when you hold the source tx hash.
|
|
45172
|
+
*
|
|
45173
|
+
* @param request - `{ intent_tx_hash }` — the hub-chain (Sonic) tx hash the intent was
|
|
45174
|
+
* registered in. For a position that is the tx that called the factory or the position.
|
|
45175
|
+
*/
|
|
45176
|
+
async getIntentStatus(request) {
|
|
45177
|
+
try {
|
|
45178
|
+
const result = await this.solverStatus(request);
|
|
45179
|
+
if (result.ok) return result;
|
|
45180
|
+
const detail = result.error?.detail ?? {
|
|
45181
|
+
code: SolverIntentErrorCode.UNKNOWN,
|
|
45182
|
+
message: "Solver returned malformed error response"
|
|
45183
|
+
};
|
|
45184
|
+
return {
|
|
45185
|
+
ok: false,
|
|
45186
|
+
error: new SodaxError("EXTERNAL_API_ERROR", detail.message, {
|
|
45187
|
+
feature: "leverageYield",
|
|
45188
|
+
context: {
|
|
45189
|
+
phase: "lookup",
|
|
45190
|
+
api: "solver",
|
|
45191
|
+
solverCode: detail.code,
|
|
45192
|
+
solverDetail: detail
|
|
45193
|
+
}
|
|
45194
|
+
})
|
|
45195
|
+
};
|
|
45196
|
+
} catch (error) {
|
|
45197
|
+
if (isLeverageYieldPostExecutionError(error)) return { ok: false, error };
|
|
45198
|
+
return { ok: false, error: executionFailed("leverageYield", error, { phase: "lookup" }) };
|
|
45199
|
+
}
|
|
45200
|
+
}
|
|
45201
|
+
/**
|
|
45202
|
+
* The raw solver read, in the solver's own vocabulary. Both public status surfaces start here; the
|
|
45203
|
+
* api key is the 5th argument, and leaving it out let a keyed partner notify and then fail to poll.
|
|
45204
|
+
*/
|
|
45205
|
+
async solverStatus(request, timeoutMs, apiKey) {
|
|
45206
|
+
return SolverApiService.getStatus(
|
|
45207
|
+
request,
|
|
45208
|
+
this.config.solver,
|
|
45209
|
+
this.config.logger,
|
|
45210
|
+
timeoutMs,
|
|
45211
|
+
apiKey || this.config.apiKey
|
|
45212
|
+
);
|
|
45213
|
+
}
|
|
45214
|
+
/**
|
|
45215
|
+
* {@link LeverageYieldService.solverStatus} plus the durable-record reconcile, for
|
|
45216
|
+
* {@link LeverageYieldService.getDetailedStatus}. Deliberately not shared with
|
|
45217
|
+
* {@link LeverageYieldService.getIntentStatus}: the reconcile turns a `NOT_FOUND` behind an
|
|
45218
|
+
* unreadable backend into an error, which is right for a polled read that would otherwise spend a
|
|
45219
|
+
* budget on an unverified miss, and wrong to impose on a surface that already ships without it.
|
|
45220
|
+
*
|
|
45221
|
+
* `timeoutMs` bounds the solver request alone. The reconcile carries its own
|
|
45222
|
+
* {@link RECONCILE_TIMEOUT_MS}, so a bounded call can cost both.
|
|
45223
|
+
*/
|
|
45224
|
+
async resolveSolverStatus(request, timeoutMs, apiKey) {
|
|
45225
|
+
const solverResult = await this.solverStatus(request, timeoutMs, apiKey);
|
|
45226
|
+
const forgotten = !solverResult.ok || solverResult.value.status === SolverIntentStatusCode.NOT_FOUND;
|
|
45227
|
+
if (!forgotten) return solverResult;
|
|
45228
|
+
const timeout = Math.min(RECONCILE_TIMEOUT_MS2, this.backendApi.requestTimeoutMs);
|
|
45229
|
+
const intent = await this.backendApi.getIntentByTxHash(request.intent_tx_hash, { timeout, apiKey });
|
|
45230
|
+
const settled = intent.ok ? intent.value.events.filter(isFillEvent).find((fill) => fill.intentState.remainingInput === "0") : void 0;
|
|
45231
|
+
if (settled) return { ok: true, value: { status: SolverIntentStatusCode.SOLVED, fill_tx_hash: settled.txHash } };
|
|
45232
|
+
const backendAnswered = intent.ok || isSodaxError(intent.error) && intent.error.context?.status === 404;
|
|
45233
|
+
if (solverResult.ok && !backendAnswered) {
|
|
45234
|
+
return {
|
|
45235
|
+
ok: false,
|
|
45236
|
+
error: {
|
|
45237
|
+
detail: {
|
|
45238
|
+
code: SolverIntentErrorCode.UNKNOWN,
|
|
45239
|
+
message: "solver reported NOT_FOUND and the durable intent record could not be read to verify it"
|
|
45240
|
+
}
|
|
45241
|
+
}
|
|
45242
|
+
};
|
|
45243
|
+
}
|
|
45244
|
+
return solverResult;
|
|
45245
|
+
}
|
|
45246
|
+
/**
|
|
45247
|
+
* Reads a vault swap's status from its source-chain transaction — the identifier a caller always
|
|
45248
|
+
* holds after `vaultSwap()`.
|
|
45249
|
+
*
|
|
45250
|
+
* **Routes; does not translate.** Returns the backend submit-tx record while it is in play,
|
|
45251
|
+
* otherwise the solver's answer via the hub tx hash resolved from the relay packet. The result is
|
|
45252
|
+
* tagged with `source` (discriminate on it) and carries that source's payload unmodified.
|
|
45253
|
+
*
|
|
45254
|
+
* `sodax.api.leverageYield.getSubmitTxStatus` cannot answer for every vault swap. Sometimes there
|
|
45255
|
+
* is no record — `useBackendSubmitTx: false`, or the submit was rejected. More often the record
|
|
45256
|
+
* exists but is stale: the backend path POSTs first and falls back to the client-side relay once
|
|
45257
|
+
* that stalls, so a fallback-completed vault swap leaves behind whatever state the backend last
|
|
45258
|
+
* reached, including a record it abandoned outright.
|
|
45259
|
+
*
|
|
45260
|
+
* **Any** unusable backend response routes to the solver — a 404, a transport or server error, or
|
|
45261
|
+
* a record the backend gave up on. A rejected API key is the exception: it is not a source with
|
|
45262
|
+
* nothing to say, it is a configuration problem only a corrected key resolves, so routing it on
|
|
45263
|
+
* would bury it behind a relay or solver error and leave a poller retrying a request that cannot
|
|
45264
|
+
* succeed. The same rule the swap and bridge siblings apply. It holds here even though
|
|
45265
|
+
* `GET /leverage-yield/submit-tx/status` declares no scope of its own: whether a key is checked
|
|
45266
|
+
* is a per-deployment setting, so this must not assume the read is unauthenticated.
|
|
45267
|
+
*
|
|
45268
|
+
* A point-in-time read; poll it yourself, or use dapp-kit's `useLeverageYieldDetailedStatus`.
|
|
45269
|
+
*
|
|
45270
|
+
* @param params - `srcChainKey` and `srcTxHash` of the source-chain vault-swap transaction.
|
|
45271
|
+
* @param config - Optional per-request override. Its `apiKey` reaches every keyed leg — the
|
|
45272
|
+
* submit-tx record read, the solver read, and the durable-intent read a solver `NOT_FOUND` falls
|
|
45273
|
+
* back to — so one override keys the whole call. The relay leg is unauthenticated and takes none.
|
|
45274
|
+
* @returns A `Result` containing a {@link DetailedLeverageYieldStatus}. Fails with `LOOKUP_FAILED`
|
|
45275
|
+
* when no source can answer yet. Branch on `error.context.reason`:
|
|
45276
|
+
* `DETAILED_STATUS_NOT_DELIVERED` is the ambiguous miss a caller should bound with a retry
|
|
45277
|
+
* budget; anything else is a dependency failing right now, so keep retrying.
|
|
45278
|
+
*/
|
|
45279
|
+
async getDetailedStatus(params, config) {
|
|
45280
|
+
try {
|
|
45281
|
+
const record = await this.backendApi.leverageYield.getSubmitTxStatus(
|
|
45282
|
+
{ txHash: params.srcTxHash, srcChainKey: params.srcChainKey },
|
|
45283
|
+
config
|
|
45284
|
+
);
|
|
45285
|
+
if (record.ok && record.value.success && !isBackendSubmitTxAbandoned(record.value.data)) {
|
|
45286
|
+
return { ok: true, value: { source: "backend", data: record.value.data } };
|
|
45287
|
+
}
|
|
45288
|
+
if (!record.ok && isSodaxError(record.error) && isAuthFailure(record.error)) {
|
|
45289
|
+
return {
|
|
45290
|
+
ok: false,
|
|
45291
|
+
error: this.detailedStatusLookupFailed(record.error, params.srcChainKey, {
|
|
45292
|
+
status: record.error.context?.status
|
|
45293
|
+
})
|
|
45294
|
+
};
|
|
45295
|
+
}
|
|
45296
|
+
const backendAnswered = record.ok || isSodaxError(record.error) && record.error.context?.status === 404;
|
|
45297
|
+
const dstTxHash = await this.resolveHubTxHash(params, backendAnswered);
|
|
45298
|
+
if (!dstTxHash.ok) return dstTxHash;
|
|
45299
|
+
const solver = await this.resolveSolverStatus(
|
|
45300
|
+
{ intent_tx_hash: dstTxHash.value },
|
|
45301
|
+
DETAILED_STATUS_SOLVER_TIMEOUT_MS2,
|
|
45302
|
+
config?.apiKey
|
|
45303
|
+
);
|
|
45304
|
+
if (!solver.ok) {
|
|
45305
|
+
return { ok: false, error: this.detailedStatusLookupFailed(solver.error, params.srcChainKey) };
|
|
45306
|
+
}
|
|
45307
|
+
return { ok: true, value: { source: "solver", dstTxHash: dstTxHash.value, data: solver.value } };
|
|
45308
|
+
} catch (error) {
|
|
45309
|
+
return { ok: false, error: this.detailedStatusLookupFailed(error, params.srcChainKey) };
|
|
45310
|
+
}
|
|
45311
|
+
}
|
|
45312
|
+
/**
|
|
45313
|
+
* The hub-chain tx hash the solver is keyed on. A hub-source vault swap has no relay leg — the
|
|
45314
|
+
* source tx *is* the hub tx. Otherwise the delivered relay packet carries it, so an undelivered
|
|
45315
|
+
* packet is simply "no hash yet".
|
|
45316
|
+
*/
|
|
45317
|
+
async resolveHubTxHash(key, backendAnswered) {
|
|
45318
|
+
let hubTxHash = key.srcTxHash;
|
|
45319
|
+
if (!isHubChainKeyType(key.srcChainKey)) {
|
|
45320
|
+
const delivered = await resolveDeliveredPacket({
|
|
45321
|
+
srcChainKey: key.srcChainKey,
|
|
45322
|
+
srcTxHash: key.srcTxHash,
|
|
45323
|
+
relayerApiEndpoint: this.config.relay.relayerApiEndpoint,
|
|
45324
|
+
backendAnswered
|
|
45325
|
+
});
|
|
45326
|
+
if (!delivered.ok) {
|
|
45327
|
+
return {
|
|
45328
|
+
ok: false,
|
|
45329
|
+
error: this.detailedStatusLookupFailed(delivered.cause, key.srcChainKey, {
|
|
45330
|
+
reason: delivered.budgetable ? DETAILED_STATUS_NOT_DELIVERED : void 0
|
|
45331
|
+
})
|
|
45332
|
+
};
|
|
45333
|
+
}
|
|
45334
|
+
hubTxHash = delivered.packet.dst_tx_hash;
|
|
45335
|
+
}
|
|
45336
|
+
if (isHex(hubTxHash)) return { ok: true, value: hubTxHash };
|
|
45337
|
+
return {
|
|
45338
|
+
ok: false,
|
|
45339
|
+
error: this.detailedStatusLookupFailed(
|
|
45340
|
+
new Error(`hub tx hash is not a hex string: ${hubTxHash}`),
|
|
45341
|
+
key.srcChainKey
|
|
45342
|
+
)
|
|
45343
|
+
};
|
|
45344
|
+
}
|
|
45345
|
+
/**
|
|
45346
|
+
* `reason` is set only for {@link DETAILED_STATUS_NOT_DELIVERED} — the miss a caller can bound
|
|
45347
|
+
* with a retry budget. Leaving it off marks a dependency that is failing right now, which a
|
|
45348
|
+
* caller should keep retrying rather than give up on. `status` is lifted for a rejected key so
|
|
45349
|
+
* `isAuthFailure` recognises the wrapped error; it reads `context.status` and does not walk the
|
|
45350
|
+
* cause chain.
|
|
45351
|
+
*/
|
|
45352
|
+
detailedStatusLookupFailed(cause, srcChainKey, extra) {
|
|
45353
|
+
return lookupFailed("leverageYield", "getDetailedStatus", cause, {
|
|
45354
|
+
srcChainKey,
|
|
45355
|
+
action: "vaultSwap",
|
|
45356
|
+
...extra
|
|
45357
|
+
});
|
|
45358
|
+
}
|
|
44548
45359
|
/**
|
|
44549
45360
|
* Approves the vault's underlying asset to the leverage vault on Sonic. For callers
|
|
44550
45361
|
* interacting with the vault directly on the hub — the swap-style {@link
|
|
@@ -44853,6 +45664,1252 @@ var LeverageYieldService = class {
|
|
|
44853
45664
|
return { ok: false, error: lookupFailed("leverageYield", "getShareBalanceForUser", error, { srcChainKey }) };
|
|
44854
45665
|
}
|
|
44855
45666
|
}
|
|
45667
|
+
// ─── Leverage positions ────────────────────────────────────────────────
|
|
45668
|
+
/**
|
|
45669
|
+
* Resolves the `LeveragePositionFactory` address, or a validation error when it is missing.
|
|
45670
|
+
*
|
|
45671
|
+
* The deployed factory ships in `leverageYieldConfig`, so this only fails when an integrator
|
|
45672
|
+
* overrides it with an empty value — which is what a bad env var produces. Failing closed there is
|
|
45673
|
+
* deliberate: a placeholder address would post real intents at nothing.
|
|
45674
|
+
*/
|
|
45675
|
+
requireFactory(action) {
|
|
45676
|
+
const factory = this.config.sodaxConfig.leverageYield.positionFactory;
|
|
45677
|
+
if (!factory) {
|
|
45678
|
+
return {
|
|
45679
|
+
ok: false,
|
|
45680
|
+
error: lookupFailed(
|
|
45681
|
+
"leverageYield",
|
|
45682
|
+
action,
|
|
45683
|
+
new Error("leverageYield.positionFactory is not configured; supply the deployed factory address")
|
|
45684
|
+
)
|
|
45685
|
+
};
|
|
45686
|
+
}
|
|
45687
|
+
return { ok: true, value: factory };
|
|
45688
|
+
}
|
|
45689
|
+
/** Position clones owned by `owner`, in creation order. Empty when the owner has none. */
|
|
45690
|
+
async listPositions(owner) {
|
|
45691
|
+
const factory = this.requireFactory("listPositions");
|
|
45692
|
+
if (!factory.ok) return factory;
|
|
45693
|
+
try {
|
|
45694
|
+
const value = await this.hubProvider.publicClient.readContract({
|
|
45695
|
+
address: factory.value,
|
|
45696
|
+
abi: leveragePositionFactoryAbi,
|
|
45697
|
+
functionName: "positionsOf",
|
|
45698
|
+
args: [owner]
|
|
45699
|
+
});
|
|
45700
|
+
return { ok: true, value };
|
|
45701
|
+
} catch (error) {
|
|
45702
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45703
|
+
return { ok: false, error: lookupFailed("leverageYield", "listPositions", error) };
|
|
45704
|
+
}
|
|
45705
|
+
}
|
|
45706
|
+
/**
|
|
45707
|
+
* Positions belonging to a user, resolved by their spoke-side address rather than a hub address.
|
|
45708
|
+
*
|
|
45709
|
+
* Positions are owned by the user's hub wallet, so discovery goes through
|
|
45710
|
+
* `getUserHubWalletAddress` — which returns the wallet router for a Sonic user and the
|
|
45711
|
+
* cross-chain wallet for a spoke user, so the same call works on every chain. Prefer this over
|
|
45712
|
+
* `listPositions` in user-facing code; passing a raw EOA finds nothing.
|
|
45713
|
+
*/
|
|
45714
|
+
async listPositionsForUser(srcChainKey, srcAddress) {
|
|
45715
|
+
try {
|
|
45716
|
+
const hubWallet = await this.hubProvider.getUserHubWalletAddress(srcAddress, srcChainKey);
|
|
45717
|
+
return await this.listPositions(hubWallet);
|
|
45718
|
+
} catch (error) {
|
|
45719
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45720
|
+
return { ok: false, error: lookupFailed("leverageYield", "listPositionsForUser", error, { srcChainKey }) };
|
|
45721
|
+
}
|
|
45722
|
+
}
|
|
45723
|
+
/** Static descriptor of a position — owner, both legs, and the fixed eMode category. */
|
|
45724
|
+
async getPositionInfo(position) {
|
|
45725
|
+
try {
|
|
45726
|
+
const [owner, collateral, borrowToken, eModeCategory, feeBps, feeReceiver] = await Promise.all([
|
|
45727
|
+
this.hubProvider.publicClient.readContract({
|
|
45728
|
+
address: position,
|
|
45729
|
+
abi: leveragePositionAbi,
|
|
45730
|
+
functionName: "owner"
|
|
45731
|
+
}),
|
|
45732
|
+
this.hubProvider.publicClient.readContract({
|
|
45733
|
+
address: position,
|
|
45734
|
+
abi: leveragePositionAbi,
|
|
45735
|
+
functionName: "collateral"
|
|
45736
|
+
}),
|
|
45737
|
+
this.hubProvider.publicClient.readContract({
|
|
45738
|
+
address: position,
|
|
45739
|
+
abi: leveragePositionAbi,
|
|
45740
|
+
functionName: "borrowToken"
|
|
45741
|
+
}),
|
|
45742
|
+
this.hubProvider.publicClient.readContract({
|
|
45743
|
+
address: position,
|
|
45744
|
+
abi: leveragePositionAbi,
|
|
45745
|
+
functionName: "eModeCategory"
|
|
45746
|
+
}),
|
|
45747
|
+
this.hubProvider.publicClient.readContract({
|
|
45748
|
+
address: position,
|
|
45749
|
+
abi: leveragePositionAbi,
|
|
45750
|
+
functionName: "feeBps"
|
|
45751
|
+
}),
|
|
45752
|
+
this.hubProvider.publicClient.readContract({
|
|
45753
|
+
address: position,
|
|
45754
|
+
abi: leveragePositionAbi,
|
|
45755
|
+
functionName: "feeReceiver"
|
|
45756
|
+
})
|
|
45757
|
+
]);
|
|
45758
|
+
return {
|
|
45759
|
+
ok: true,
|
|
45760
|
+
value: {
|
|
45761
|
+
address: position,
|
|
45762
|
+
owner,
|
|
45763
|
+
collateral,
|
|
45764
|
+
borrowToken,
|
|
45765
|
+
eModeCategory,
|
|
45766
|
+
// From the position, not from config: config can change and an open can override it, so
|
|
45767
|
+
// what a NEW position would carry is not what THIS one does.
|
|
45768
|
+
feeBps: Number(feeBps),
|
|
45769
|
+
feeReceiver
|
|
45770
|
+
}
|
|
45771
|
+
};
|
|
45772
|
+
} catch (error) {
|
|
45773
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45774
|
+
return { ok: false, error: lookupFailed("leverageYield", "getPositionInfo", error) };
|
|
45775
|
+
}
|
|
45776
|
+
}
|
|
45777
|
+
/**
|
|
45778
|
+
* Live AAVE account snapshot for a position. Read from the pool, not the position: the
|
|
45779
|
+
* position contract keeps no accounting of its own, so collateral, debt and health factor
|
|
45780
|
+
* all come from `getUserAccountData`.
|
|
45781
|
+
*
|
|
45782
|
+
* The pool comes from `moneyMarket.lendingPool` config rather than the position's own
|
|
45783
|
+
* `pool()` getter — same address, one fewer round trip, and it keeps the deployment address
|
|
45784
|
+
* sourced from config like the rest of the SDK.
|
|
45785
|
+
*/
|
|
45786
|
+
async getPositionAccount(position) {
|
|
45787
|
+
try {
|
|
45788
|
+
const [totalCollateralBase, totalDebtBase, availableBorrowsBase, currentLiquidationThreshold, ltv, healthFactor] = await this.hubProvider.publicClient.readContract({
|
|
45789
|
+
address: this.config.sodaxConfig.moneyMarket.lendingPool,
|
|
45790
|
+
abi: poolAbi,
|
|
45791
|
+
functionName: "getUserAccountData",
|
|
45792
|
+
args: [position]
|
|
45793
|
+
});
|
|
45794
|
+
return {
|
|
45795
|
+
ok: true,
|
|
45796
|
+
value: {
|
|
45797
|
+
totalCollateralBase,
|
|
45798
|
+
totalDebtBase,
|
|
45799
|
+
availableBorrowsBase,
|
|
45800
|
+
currentLiquidationThreshold,
|
|
45801
|
+
ltv,
|
|
45802
|
+
healthFactor
|
|
45803
|
+
}
|
|
45804
|
+
};
|
|
45805
|
+
} catch (error) {
|
|
45806
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45807
|
+
return { ok: false, error: lookupFailed("leverageYield", "getPositionAccount", error) };
|
|
45808
|
+
}
|
|
45809
|
+
}
|
|
45810
|
+
/**
|
|
45811
|
+
* The position's collateral holding, as an exact aToken balance.
|
|
45812
|
+
*
|
|
45813
|
+
* Needed to size a full exit. {@link LeverageYieldService.getPositionAccount} reports collateral
|
|
45814
|
+
* in the oracle's base currency at 8 decimals, which is fine to display but cannot name an amount:
|
|
45815
|
+
* dividing it back out by a price lands near the balance, and a `decreaseLeverage` asking for more
|
|
45816
|
+
* collateral than the position holds does not fail on submission — the hook's `transferFrom`
|
|
45817
|
+
* reverts at fill time, so the intent silently expires instead.
|
|
45818
|
+
*
|
|
45819
|
+
* Safe to act on a slightly stale read: aToken balances only grow, since interest accrues into
|
|
45820
|
+
* them, so a value from a few blocks ago is always still spendable. Selling it leaves interest
|
|
45821
|
+
* dust behind rather than coming up short.
|
|
45822
|
+
*
|
|
45823
|
+
* @param collateral The position's collateral reserve. Read from the position when omitted; pass
|
|
45824
|
+
* it if you already hold a {@link LeveragePosition} to save the round trip.
|
|
45825
|
+
*/
|
|
45826
|
+
async getPositionCollateralBalance(position, collateral) {
|
|
45827
|
+
try {
|
|
45828
|
+
const asset = collateral ?? await this.hubProvider.publicClient.readContract({
|
|
45829
|
+
address: position,
|
|
45830
|
+
abi: leveragePositionAbi,
|
|
45831
|
+
functionName: "collateral"
|
|
45832
|
+
});
|
|
45833
|
+
const reserve = await this.hubProvider.publicClient.readContract({
|
|
45834
|
+
address: this.config.sodaxConfig.moneyMarket.lendingPool,
|
|
45835
|
+
abi: poolAbi,
|
|
45836
|
+
functionName: "getReserveData",
|
|
45837
|
+
args: [asset]
|
|
45838
|
+
});
|
|
45839
|
+
const aToken = reserve.aTokenAddress;
|
|
45840
|
+
const balance = await this.hubProvider.publicClient.readContract({
|
|
45841
|
+
address: aToken,
|
|
45842
|
+
abi: erc20Abi$1,
|
|
45843
|
+
functionName: "balanceOf",
|
|
45844
|
+
args: [position]
|
|
45845
|
+
});
|
|
45846
|
+
return { ok: true, value: { aToken, balance } };
|
|
45847
|
+
} catch (error) {
|
|
45848
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45849
|
+
return { ok: false, error: lookupFailed("leverageYield", "getPositionCollateralBalance", error) };
|
|
45850
|
+
}
|
|
45851
|
+
}
|
|
45852
|
+
/**
|
|
45853
|
+
* The position's operation slot: which operation it recorded, and whether that intent is still
|
|
45854
|
+
* live on `Intents`.
|
|
45855
|
+
*
|
|
45856
|
+
* Both are needed, because the interesting state is when they disagree. `isLive` false with a
|
|
45857
|
+
* non-zero `kind` means the intent resolved — filled, expired, or cancelled by someone else — but
|
|
45858
|
+
* the position has not been told, so its grant is still open and any debt-side contribution is
|
|
45859
|
+
* still sitting there. That is what `needsSettle` flags, and `buildSettlePosition` clears. A live
|
|
45860
|
+
* intent instead blocks any second operation until it resolves.
|
|
45861
|
+
*/
|
|
45862
|
+
async getPositionPendingState(position) {
|
|
45863
|
+
try {
|
|
45864
|
+
const [isLive, kind] = await Promise.all([
|
|
45865
|
+
this.hubProvider.publicClient.readContract({
|
|
45866
|
+
address: position,
|
|
45867
|
+
abi: leveragePositionAbi,
|
|
45868
|
+
functionName: "hasPendingOperation"
|
|
45869
|
+
}),
|
|
45870
|
+
this.hubProvider.publicClient.readContract({
|
|
45871
|
+
address: position,
|
|
45872
|
+
abi: leveragePositionAbi,
|
|
45873
|
+
functionName: "pendingKind"
|
|
45874
|
+
})
|
|
45875
|
+
]);
|
|
45876
|
+
return { ok: true, value: { kind, isLive, needsSettle: kind !== 0 && !isLive } };
|
|
45877
|
+
} catch (error) {
|
|
45878
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45879
|
+
return { ok: false, error: lookupFailed("leverageYield", "getPositionPendingState", error) };
|
|
45880
|
+
}
|
|
45881
|
+
}
|
|
45882
|
+
/** Deterministic clone address for the next position a given creator opens for `owner`. */
|
|
45883
|
+
async predictPosition(creator, owner, positionId) {
|
|
45884
|
+
const factory = this.requireFactory("predictPosition");
|
|
45885
|
+
if (!factory.ok) return factory;
|
|
45886
|
+
try {
|
|
45887
|
+
const id = positionId ?? await this.hubProvider.publicClient.readContract({
|
|
45888
|
+
address: factory.value,
|
|
45889
|
+
abi: leveragePositionFactoryAbi,
|
|
45890
|
+
functionName: "nextPositionIdFor",
|
|
45891
|
+
args: [owner]
|
|
45892
|
+
});
|
|
45893
|
+
const value = await this.hubProvider.publicClient.readContract({
|
|
45894
|
+
address: factory.value,
|
|
45895
|
+
abi: leveragePositionFactoryAbi,
|
|
45896
|
+
functionName: "predictPosition",
|
|
45897
|
+
args: [creator, owner, id]
|
|
45898
|
+
});
|
|
45899
|
+
return { ok: true, value };
|
|
45900
|
+
} catch (error) {
|
|
45901
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
45902
|
+
return { ok: false, error: lookupFailed("leverageYield", "predictPosition", error) };
|
|
45903
|
+
}
|
|
45904
|
+
}
|
|
45905
|
+
// ─── Position transaction builders ─────────────────────────────────────
|
|
45906
|
+
//
|
|
45907
|
+
// Positions are driven by direct Sonic calls, not intents, so these return raw transactions
|
|
45908
|
+
// for the caller to sign with a hub wallet provider. The leverage and deleverage calls only
|
|
45909
|
+
// *post* an intent — a solver fills it afterwards, so poll `getPositionPendingState`
|
|
45910
|
+
// rather than treating the receipt as completion.
|
|
45911
|
+
/**
|
|
45912
|
+
* Opens a new position and requests leverage on it in the same transaction — the standard way
|
|
45913
|
+
* to open a leveraged position: one approve, then this.
|
|
45914
|
+
*
|
|
45915
|
+
* `initialAssets` of `collateral` is pulled from the signer, so the factory needs an allowance
|
|
45916
|
+
* first. Control is assigned to `owner`, which may differ from the signer — pass a user's hub
|
|
45917
|
+
* wallet address to have the existing cross-chain path drive the position.
|
|
45918
|
+
*
|
|
45919
|
+
* The leverage is still asynchronous: this posts the intent and a solver fills it afterwards,
|
|
45920
|
+
* so on confirmation the position is funded with the request outstanding, not yet levered. If
|
|
45921
|
+
* no solver fills it, `buildCancelPositionOperation` returns the deposit to the owner.
|
|
45922
|
+
*/
|
|
45923
|
+
/**
|
|
45924
|
+
* Turns a {@link PositionOrigin} into the tuple the factory takes, and refuses the combinations the
|
|
45925
|
+
* contract would refuse anyway — better a rejected build than a transaction that reverts.
|
|
45926
|
+
*/
|
|
45927
|
+
resolveOrigin(origin, method) {
|
|
45928
|
+
const chainId = getIntentRelayChainId(origin.chainKey);
|
|
45929
|
+
if (chainId === void 0) {
|
|
45930
|
+
return {
|
|
45931
|
+
ok: false,
|
|
45932
|
+
error: lookupFailed(
|
|
45933
|
+
"leverageYield",
|
|
45934
|
+
method,
|
|
45935
|
+
new Error(`no relay chain id for origin chain ${origin.chainKey}`)
|
|
45936
|
+
)
|
|
45937
|
+
};
|
|
45938
|
+
}
|
|
45939
|
+
const isHub = origin.chainKey === this.hubProvider.chainConfig.chain.key;
|
|
45940
|
+
if (!isHub && !origin.asset) {
|
|
45941
|
+
return {
|
|
45942
|
+
ok: false,
|
|
45943
|
+
error: lookupFailed(
|
|
45944
|
+
"leverageYield",
|
|
45945
|
+
method,
|
|
45946
|
+
new Error(`origin.asset is required for a refund to ${origin.chainKey}`)
|
|
45947
|
+
)
|
|
45948
|
+
};
|
|
45949
|
+
}
|
|
45950
|
+
return {
|
|
45951
|
+
ok: true,
|
|
45952
|
+
value: {
|
|
45953
|
+
chainId,
|
|
45954
|
+
// The chain's own encoding, not a 0x-prefixed string. `originAddress` is `bytes` on-chain and
|
|
45955
|
+
// is handed to the AssetManager as the refund destination, so a Solana or Stellar address has
|
|
45956
|
+
// to arrive in the form that chain's spoke expects — prefixing `0x` would produce a refund
|
|
45957
|
+
// address that is merely well-formed hex. EVM addresses pass through unchanged.
|
|
45958
|
+
address: encodeAddress(origin.chainKey, origin.address),
|
|
45959
|
+
// Named on the hub as well, not just off it. The asset decides what a cancellation pays back,
|
|
45960
|
+
// and zeroing it here is why someone who funded with USSD was refunded `sodaUSSD`. Callers pass
|
|
45961
|
+
// the asset only when a wrap actually happened — when the reserve IS what was deposited there is
|
|
45962
|
+
// nothing to unwrap and `address(0)` is the correct answer.
|
|
45963
|
+
asset: origin.asset ?? zeroAddress
|
|
45964
|
+
}
|
|
45965
|
+
};
|
|
45966
|
+
}
|
|
45967
|
+
/**
|
|
45968
|
+
* Partner fee for a position, in the shape `PositionConfig` takes.
|
|
45969
|
+
*
|
|
45970
|
+
* Only the PERCENTAGE variant of `PartnerFee` maps: the contract stores basis points and derives
|
|
45971
|
+
* the amount per operation (`_feeFor`), so a fixed-amount fee has nowhere to go and is rejected
|
|
45972
|
+
* rather than silently dropped. Same precedence as the vault flows — per-call, then
|
|
45973
|
+
* `leverageYield.partnerFee`, then none.
|
|
45974
|
+
*
|
|
45975
|
+
* The fee is FIXED AT CREATION on-chain, so this is read when a position is created and never
|
|
45976
|
+
* again; changing the config later does not re-price positions already open.
|
|
45977
|
+
*/
|
|
45978
|
+
/**
|
|
45979
|
+
* The fee a position created NOW would carry, in basis points, plus who receives it.
|
|
45980
|
+
*
|
|
45981
|
+
* Public because a caller cannot project a position correctly without it and cannot derive it:
|
|
45982
|
+
* the fee resolves from `leverageYield.partnerFee`, then the global fee, then none, and it is
|
|
45983
|
+
* FIXED AT CREATION on-chain. Feed `feeBps` to {@link projectLeverageLeg} — the hooks require
|
|
45984
|
+
* `inputAmount + fee`, so a leverage-up borrows the fee ON TOP of what the solver is paid. Leaving
|
|
45985
|
+
* it out understates LTV and overstates the ceiling, which is the Aave `'36'` failure at fill time
|
|
45986
|
+
* this module exists to prevent: 50 bp takes a debt-side ceiling from 9.88x to about 9.44x.
|
|
45987
|
+
*
|
|
45988
|
+
* Pass the same `override` here as to the open call, or omit it on both.
|
|
45989
|
+
*/
|
|
45990
|
+
getEffectivePositionFee(override) {
|
|
45991
|
+
return this.resolvePositionFee(override, "getEffectivePositionFee");
|
|
45992
|
+
}
|
|
45993
|
+
resolvePositionFee(override, method) {
|
|
45994
|
+
const fee = override ?? this.config.leverageYieldPartnerFee;
|
|
45995
|
+
if (!fee) return { ok: true, value: { feeReceiver: zeroAddress, feeBps: 0 } };
|
|
45996
|
+
if (!isPartnerFeePercentage(fee)) {
|
|
45997
|
+
return {
|
|
45998
|
+
ok: false,
|
|
45999
|
+
error: lookupFailed(
|
|
46000
|
+
"leverageYield",
|
|
46001
|
+
method,
|
|
46002
|
+
new Error("a position partner fee must be the percentage variant; PositionConfig stores basis points")
|
|
46003
|
+
)
|
|
46004
|
+
};
|
|
46005
|
+
}
|
|
46006
|
+
if (!Number.isInteger(fee.percentage) || fee.percentage < 0 || fee.percentage > MAX_POSITION_FEE_BPS) {
|
|
46007
|
+
return {
|
|
46008
|
+
ok: false,
|
|
46009
|
+
error: lookupFailed(
|
|
46010
|
+
"leverageYield",
|
|
46011
|
+
method,
|
|
46012
|
+
new Error(
|
|
46013
|
+
`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})`
|
|
46014
|
+
)
|
|
46015
|
+
)
|
|
46016
|
+
};
|
|
46017
|
+
}
|
|
46018
|
+
if (fee.percentage === 0 !== isAddressEqual(fee.address, zeroAddress)) {
|
|
46019
|
+
return {
|
|
46020
|
+
ok: false,
|
|
46021
|
+
error: lookupFailed(
|
|
46022
|
+
"leverageYield",
|
|
46023
|
+
method,
|
|
46024
|
+
new Error(
|
|
46025
|
+
`a position partner fee needs a rate and a receiver together, or neither (got ${fee.percentage} bps for ${fee.address})`
|
|
46026
|
+
)
|
|
46027
|
+
)
|
|
46028
|
+
};
|
|
46029
|
+
}
|
|
46030
|
+
return { ok: true, value: { feeReceiver: fee.address, feeBps: fee.percentage } };
|
|
46031
|
+
}
|
|
46032
|
+
/** A hub transaction. Every builder below produces this shape and none of them sends value. */
|
|
46033
|
+
// Generic so a builder's declared return type applies its own brand. The cast is the single one
|
|
46034
|
+
// the pattern needs — a brand is type-only and erased at runtime — and keeping it here means no
|
|
46035
|
+
// builder carries one of its own.
|
|
46036
|
+
hubTx(from, to, data) {
|
|
46037
|
+
return { from, to, value: 0n, data };
|
|
46038
|
+
}
|
|
46039
|
+
/**
|
|
46040
|
+
* The `PositionConfig` struct both factory entry points take, assembled from a resolved origin.
|
|
46041
|
+
*
|
|
46042
|
+
* Shared so the two create paths cannot drift: which side the funded reserve goes on is their only
|
|
46043
|
+
* real difference, and a field silently spelled differently in one of them would be a
|
|
46044
|
+
* mis-recorded refund destination rather than a compile error.
|
|
46045
|
+
*/
|
|
46046
|
+
positionConfig(args) {
|
|
46047
|
+
return {
|
|
46048
|
+
owner: args.owner,
|
|
46049
|
+
collateral: args.collateral,
|
|
46050
|
+
borrowToken: args.borrowToken,
|
|
46051
|
+
eModeCategory: args.eModeCategory,
|
|
46052
|
+
originChainId: args.origin.chainId,
|
|
46053
|
+
originAddress: args.origin.address,
|
|
46054
|
+
originAsset: args.origin.asset,
|
|
46055
|
+
feeReceiver: args.fee?.feeReceiver ?? zeroAddress,
|
|
46056
|
+
feeBps: args.fee?.feeBps ?? 0
|
|
46057
|
+
};
|
|
46058
|
+
}
|
|
46059
|
+
buildCreatePositionAndLeverage(params) {
|
|
46060
|
+
const method = "buildCreatePositionAndLeverage";
|
|
46061
|
+
const factory = this.requireFactory(method);
|
|
46062
|
+
if (!factory.ok) return factory;
|
|
46063
|
+
const fee = this.resolvePositionFee(params.partnerFee, method);
|
|
46064
|
+
if (!fee.ok) return fee;
|
|
46065
|
+
const origin = this.resolveOrigin(params.origin, method);
|
|
46066
|
+
if (!origin.ok) return origin;
|
|
46067
|
+
return {
|
|
46068
|
+
ok: true,
|
|
46069
|
+
value: this.hubTx(
|
|
46070
|
+
params.from,
|
|
46071
|
+
factory.value,
|
|
46072
|
+
encodeFunctionData({
|
|
46073
|
+
abi: leveragePositionFactoryAbi,
|
|
46074
|
+
functionName: "createPositionAndLeverage",
|
|
46075
|
+
args: [
|
|
46076
|
+
this.positionConfig({ ...params, origin: origin.value, fee: fee.value }),
|
|
46077
|
+
params.initialAssets,
|
|
46078
|
+
params.borrowAmount,
|
|
46079
|
+
params.minCollateralOut
|
|
46080
|
+
]
|
|
46081
|
+
})
|
|
46082
|
+
)
|
|
46083
|
+
};
|
|
46084
|
+
}
|
|
46085
|
+
/**
|
|
46086
|
+
* Opens a levered position starting from the **debt** token, with no collateral of your own.
|
|
46087
|
+
*
|
|
46088
|
+
* Pulls `contribution` of `borrowToken` from the signer — not the collateral. On fill the hook
|
|
46089
|
+
* supplies the solver's collateral, adds the contribution, borrows `totalInput - contribution`,
|
|
46090
|
+
* and pays the solver the total, so a holder of the debt asset lands in a levered collateral
|
|
46091
|
+
* position having never owned collateral. Requires the deployment's implementation to have a
|
|
46092
|
+
* debt-side hook configured; otherwise the position reverts with `DebtSideHookUnavailable`.
|
|
46093
|
+
*/
|
|
46094
|
+
buildCreatePositionFromDebtToken(params) {
|
|
46095
|
+
const method = "buildCreatePositionFromDebtToken";
|
|
46096
|
+
const factory = this.requireFactory(method);
|
|
46097
|
+
if (!factory.ok) return factory;
|
|
46098
|
+
const fee = this.resolvePositionFee(params.partnerFee, method);
|
|
46099
|
+
if (!fee.ok) return fee;
|
|
46100
|
+
const origin = this.resolveOrigin(params.origin, method);
|
|
46101
|
+
if (!origin.ok) return origin;
|
|
46102
|
+
return {
|
|
46103
|
+
ok: true,
|
|
46104
|
+
value: this.hubTx(
|
|
46105
|
+
params.from,
|
|
46106
|
+
factory.value,
|
|
46107
|
+
encodeFunctionData({
|
|
46108
|
+
abi: leveragePositionFactoryAbi,
|
|
46109
|
+
functionName: "createPositionFromDebtToken",
|
|
46110
|
+
args: [
|
|
46111
|
+
this.positionConfig({ ...params, origin: origin.value, fee: fee.value }),
|
|
46112
|
+
params.contribution,
|
|
46113
|
+
params.totalInput,
|
|
46114
|
+
params.minCollateralOut
|
|
46115
|
+
]
|
|
46116
|
+
})
|
|
46117
|
+
)
|
|
46118
|
+
};
|
|
46119
|
+
}
|
|
46120
|
+
/** Borrows `borrowAmount` and swaps it into more collateral. `minCollateralOut` is the slippage floor. */
|
|
46121
|
+
buildAddLeverage(params) {
|
|
46122
|
+
return this.hubTx(
|
|
46123
|
+
params.from,
|
|
46124
|
+
params.position,
|
|
46125
|
+
encodeFunctionData({
|
|
46126
|
+
abi: leveragePositionAbi,
|
|
46127
|
+
functionName: "addLeverage",
|
|
46128
|
+
args: [params.borrowAmount, params.minCollateralOut]
|
|
46129
|
+
})
|
|
46130
|
+
);
|
|
46131
|
+
}
|
|
46132
|
+
/**
|
|
46133
|
+
* Gives up `collateralIn` of collateral to repay debt. `minDebtOut` is the slippage floor.
|
|
46134
|
+
*
|
|
46135
|
+
* CLOSING INTO THE DEBT TOKEN is this call with the position's collateral balance, less the fee a
|
|
46136
|
+
* non-zero `feeBps` gives up on top of the input (`balance x 10_000 / (10_000 + feeBps)`) — there is
|
|
46137
|
+
* no separate close entry point, because selling everything is the same operation as selling part.
|
|
46138
|
+
* Size it with {@link LeverageYieldService.getPositionCollateralBalance}, never off
|
|
46139
|
+
* `totalCollateralBase`, and quote the full amount so `minDebtOut` reflects what the solver will
|
|
46140
|
+
* actually pay for all of it.
|
|
46141
|
+
*
|
|
46142
|
+
* What that leaves behind is worth knowing. The solver delivers more debt token than is owed, so
|
|
46143
|
+
* the hook repays the debt and hands the surplus to the position, which is the owner's equity now
|
|
46144
|
+
* denominated in the debt asset. It sits in the position until someone calls
|
|
46145
|
+
* {@link LeverageYieldService.buildSettlePosition} — that sweep is what actually delivers it, and
|
|
46146
|
+
* it goes to the position's `owner` (the hub wallet), not to whoever signed. Exiting into the
|
|
46147
|
+
* *collateral* instead means repaying only the debt and then calling
|
|
46148
|
+
* {@link LeverageYieldService.buildPositionWithdraw}, which can pay out to any address.
|
|
46149
|
+
*/
|
|
46150
|
+
buildDecreaseLeverage(params) {
|
|
46151
|
+
return this.hubTx(
|
|
46152
|
+
params.from,
|
|
46153
|
+
params.position,
|
|
46154
|
+
encodeFunctionData({
|
|
46155
|
+
abi: leveragePositionAbi,
|
|
46156
|
+
functionName: "decreaseLeverage",
|
|
46157
|
+
args: [params.collateralIn, params.minDebtOut, params.exitAsset ?? zeroAddress]
|
|
46158
|
+
})
|
|
46159
|
+
);
|
|
46160
|
+
}
|
|
46161
|
+
/**
|
|
46162
|
+
* Withdraws collateral out of the position. The pool rejects a withdrawal that would drop
|
|
46163
|
+
* the position below its liquidation threshold, so no client-side health check is applied
|
|
46164
|
+
* here — but note that bound is health factor 1, not a safety buffer above it.
|
|
46165
|
+
*/
|
|
46166
|
+
buildPositionWithdraw(params) {
|
|
46167
|
+
return this.hubTx(
|
|
46168
|
+
params.from,
|
|
46169
|
+
params.position,
|
|
46170
|
+
encodeFunctionData({
|
|
46171
|
+
abi: leveragePositionAbi,
|
|
46172
|
+
functionName: "withdraw",
|
|
46173
|
+
args: [params.amount, params.to]
|
|
46174
|
+
})
|
|
46175
|
+
);
|
|
46176
|
+
}
|
|
46177
|
+
/**
|
|
46178
|
+
* Clears an operation that has already resolved and returns anything the position is holding
|
|
46179
|
+
* loose to its owner.
|
|
46180
|
+
*
|
|
46181
|
+
* PERMISSIONLESS, and deliberately so: it only ever tightens state, so a stranded balance can be
|
|
46182
|
+
* pushed back by anyone rather than waiting on the owner to notice. That matters because an intent
|
|
46183
|
+
* can be cancelled by a third party once past its deadline, which leaves the position resolved but
|
|
46184
|
+
* un-swept if the hook's notification did not land.
|
|
46185
|
+
*
|
|
46186
|
+
* Reverts while the intent is still live — use {@link LeverageYieldService.buildCancelPositionOperation}
|
|
46187
|
+
* to end one that has not resolved yet.
|
|
46188
|
+
*/
|
|
46189
|
+
buildSettlePosition(params) {
|
|
46190
|
+
return this.hubTx(
|
|
46191
|
+
params.from,
|
|
46192
|
+
params.position,
|
|
46193
|
+
encodeFunctionData({ abi: leveragePositionAbi, functionName: "settle" })
|
|
46194
|
+
);
|
|
46195
|
+
}
|
|
46196
|
+
/**
|
|
46197
|
+
* Cancels the in-flight operation and returns the deposit.
|
|
46198
|
+
*
|
|
46199
|
+
* Nothing is escrowed when an intent is posted, so cancelling recovers nothing by itself — but
|
|
46200
|
+
* a position carrying no debt withdraws its whole collateral balance back to the owner, which
|
|
46201
|
+
* is what a leveraged open whose intent never filled needs. With debt outstanding the
|
|
46202
|
+
* collateral stays put: the pool would reject the withdrawal on its health-factor check.
|
|
46203
|
+
*/
|
|
46204
|
+
buildCancelPositionOperation(params) {
|
|
46205
|
+
return this.hubTx(
|
|
46206
|
+
params.from,
|
|
46207
|
+
params.position,
|
|
46208
|
+
encodeFunctionData({ abi: leveragePositionAbi, functionName: "cancel" })
|
|
46209
|
+
);
|
|
46210
|
+
}
|
|
46211
|
+
// ─── Positions from any chain ──────────────────────────────────────────
|
|
46212
|
+
//
|
|
46213
|
+
// The builders above produce a transaction sent straight to the hub. That only works for a user
|
|
46214
|
+
// signing on the hub, and even there it has to be routed so `msg.sender` is their hub wallet —
|
|
46215
|
+
// a position's `onlyOwner` is that wallet, and an EOA cannot send as another address.
|
|
46216
|
+
//
|
|
46217
|
+
// These take over from there: the calls are encoded as a hub-wallet payload and carried by the
|
|
46218
|
+
// spoke transport, which routes them locally on the hub and relays them from anywhere else. So one
|
|
46219
|
+
// code path covers every chain, and the hub is not a special case.
|
|
46220
|
+
/**
|
|
46221
|
+
* Encodes position calls as a hub-wallet payload.
|
|
46222
|
+
*
|
|
46223
|
+
* Takes the raw transactions from the builders above and produces the `(address,uint256,bytes)[]`
|
|
46224
|
+
* payload the hub wallet executes. Public because that payload is the unit the transport takes:
|
|
46225
|
+
* pass it to `spoke.deposit` / `spoke.sendMessage` yourself when you want manual relay control,
|
|
46226
|
+
* or use {@link LeverageYieldService.openPosition} / {@link LeverageYieldService.operatePosition},
|
|
46227
|
+
* which do it for you.
|
|
46228
|
+
*/
|
|
46229
|
+
encodePositionCalls(txs) {
|
|
46230
|
+
return encodeContractCalls(
|
|
46231
|
+
txs.map((tx) => ({ address: tx.to, value: tx.value ?? 0n, data: tx.data }))
|
|
46232
|
+
);
|
|
46233
|
+
}
|
|
46234
|
+
/**
|
|
46235
|
+
* Resolves the hub reserve a spoke token funds, and the hub asset it arrives as.
|
|
46236
|
+
*
|
|
46237
|
+
* Three addresses per token and they are not interchangeable: `hubAsset` is what lands in the hub
|
|
46238
|
+
* wallet, `vault` is the 18-decimal money-market reserve a position actually uses, and the spoke
|
|
46239
|
+
* `address` is neither. Getting this wrong is silent — the wrong one is still a valid ERC-20.
|
|
46240
|
+
*/
|
|
46241
|
+
resolveFunding(srcChainKey, token, method) {
|
|
46242
|
+
const spokeToken = this.config.getSpokeTokenFromOriginalAssetAddress(srcChainKey, token) ?? this.config.getXTokenFromHubAsset(token);
|
|
46243
|
+
if (!spokeToken) {
|
|
46244
|
+
return {
|
|
46245
|
+
ok: false,
|
|
46246
|
+
error: lookupFailed(
|
|
46247
|
+
"leverageYield",
|
|
46248
|
+
method,
|
|
46249
|
+
new Error(`no hub asset registered for ${token} on ${srcChainKey}`),
|
|
46250
|
+
{ srcChainKey }
|
|
46251
|
+
)
|
|
46252
|
+
};
|
|
46253
|
+
}
|
|
46254
|
+
return {
|
|
46255
|
+
ok: true,
|
|
46256
|
+
value: {
|
|
46257
|
+
hubAsset: spokeToken.hubAsset,
|
|
46258
|
+
vault: spokeToken.vault,
|
|
46259
|
+
decimals: spokeToken.decimals
|
|
46260
|
+
}
|
|
46261
|
+
};
|
|
46262
|
+
}
|
|
46263
|
+
/**
|
|
46264
|
+
* What a refund should pay back: the asset the user actually funded with, or `undefined` when that IS
|
|
46265
|
+
* the reserve and there is nothing to unwrap.
|
|
46266
|
+
*
|
|
46267
|
+
* A named asset makes `IntentRefund` unwrap before paying, on the hub as well as off it — so someone
|
|
46268
|
+
* who deposited USSD is refunded USSD rather than `sodaUSSD`.
|
|
46269
|
+
*/
|
|
46270
|
+
refundAsset(funding) {
|
|
46271
|
+
return funding.hubAsset.toLowerCase() === funding.vault.toLowerCase() ? void 0 : funding.hubAsset;
|
|
46272
|
+
}
|
|
46273
|
+
/**
|
|
46274
|
+
* Encodes the wrap of an arriving deposit into its money-market reserve, and returns the reserve
|
|
46275
|
+
* amount that produces.
|
|
46276
|
+
*
|
|
46277
|
+
* A hub asset that is already a soda vault token IS the reserve, so nothing is wrapped. Otherwise
|
|
46278
|
+
* the vault mints 18-decimal shares one-for-one with the asset, which is what
|
|
46279
|
+
* `translateIncomingDecimals` computes — the same conversion the asset manager applies to a spoke
|
|
46280
|
+
* deposit, rather than a second implementation of it. A reserve carrying a non-zero deposit fee
|
|
46281
|
+
* would mint fewer shares than this predicts and the factory's pull would revert; both reserves in
|
|
46282
|
+
* use today are fee-free.
|
|
46283
|
+
*/
|
|
46284
|
+
encodeWrapIntoReserve(funding, amount) {
|
|
46285
|
+
if (this.config.isSodaVaultHubAsset(funding.hubAsset)) {
|
|
46286
|
+
return { calls: [], reserveAmount: amount };
|
|
46287
|
+
}
|
|
46288
|
+
return {
|
|
46289
|
+
calls: [
|
|
46290
|
+
Erc20Service.encodeApprove(funding.hubAsset, funding.vault, amount),
|
|
46291
|
+
EvmVaultTokenService.encodeDeposit(funding.vault, funding.hubAsset, amount)
|
|
46292
|
+
],
|
|
46293
|
+
reserveAmount: EvmVaultTokenService.translateIncomingDecimals(funding.decimals, amount)
|
|
46294
|
+
};
|
|
46295
|
+
}
|
|
46296
|
+
/**
|
|
46297
|
+
* Everything both opens do before they diverge: resolve the factory, the funding token's hub asset
|
|
46298
|
+
* and reserve, and the origin to refund to; predict the address the position will be created at;
|
|
46299
|
+
* and encode the wrap plus the transfer that funds it.
|
|
46300
|
+
*
|
|
46301
|
+
* Only the factory call itself differs between the collateral side and the debt side — which side
|
|
46302
|
+
* the funded reserve lands on, and the two amounts — so everything up to that point lives here
|
|
46303
|
+
* once. `calls` is returned ready to be appended to.
|
|
46304
|
+
*/
|
|
46305
|
+
async prepareOpen(params, method) {
|
|
46306
|
+
const factory = this.requireFactory(method);
|
|
46307
|
+
if (!factory.ok) return factory;
|
|
46308
|
+
const fee = this.resolvePositionFee(params.partnerFee, method);
|
|
46309
|
+
if (!fee.ok) return fee;
|
|
46310
|
+
const funding = this.resolveFunding(params.srcChainKey, params.token, method);
|
|
46311
|
+
if (!funding.ok) return funding;
|
|
46312
|
+
const origin = this.resolveOrigin(
|
|
46313
|
+
{ chainKey: params.srcChainKey, address: params.srcAddress, asset: this.refundAsset(funding.value) },
|
|
46314
|
+
method
|
|
46315
|
+
);
|
|
46316
|
+
if (!origin.ok) return origin;
|
|
46317
|
+
const predicted = await this.predictPosition(params.owner, params.owner);
|
|
46318
|
+
if (!predicted.ok) return predicted;
|
|
46319
|
+
const { calls, reserveAmount } = this.encodeWrapIntoReserve(funding.value, params.amount);
|
|
46320
|
+
calls.push(Erc20Service.encodeTransfer(funding.value.vault, predicted.value, reserveAmount));
|
|
46321
|
+
return {
|
|
46322
|
+
ok: true,
|
|
46323
|
+
value: {
|
|
46324
|
+
factory: factory.value,
|
|
46325
|
+
funding: funding.value,
|
|
46326
|
+
calls,
|
|
46327
|
+
reserveAmount,
|
|
46328
|
+
origin: origin.value,
|
|
46329
|
+
fee: fee.value
|
|
46330
|
+
}
|
|
46331
|
+
};
|
|
46332
|
+
}
|
|
46333
|
+
/**
|
|
46334
|
+
* Hub-side payload for opening a position from the collateral side.
|
|
46335
|
+
*
|
|
46336
|
+
* Wrap the arriving deposit into its reserve, TRANSFER it to the address the position will be
|
|
46337
|
+
* created at, create the position and post its leverage intent — one batch, executed by the user's
|
|
46338
|
+
* hub wallet. The position's collateral is the reserve behind `params.token`; `borrowToken` is
|
|
46339
|
+
* borrowed against it.
|
|
46340
|
+
*
|
|
46341
|
+
* Nothing is ever approved to the factory: it holds no allowance and pulls from nobody, so funding
|
|
46342
|
+
* is a transfer to `predictPosition(creator, owner, nextPositionIdFor(owner))` and the clone supplies
|
|
46343
|
+
* whatever it finds. The id is per-owner, so an unrelated user creating a position cannot move the
|
|
46344
|
+
* address out from under this batch — and because the transfer and the create are in the same batch,
|
|
46345
|
+
* a stale prediction reverts both rather than stranding the tokens.
|
|
46346
|
+
*
|
|
46347
|
+
* The owner's OWN concurrent opens are the one thing that can still advance the id between building
|
|
46348
|
+
* this payload and executing it. On the hub that reverts atomically and nothing is lost; funded from
|
|
46349
|
+
* a spoke the deposit has already landed in the user's hub wallet when the batch reverts, and is
|
|
46350
|
+
* recovered with `sodax.recovery` (see RECOVERY.md). Do not open two positions for one owner at once.
|
|
46351
|
+
*
|
|
46352
|
+
* The origin recorded on the position is `srcChainKey` / `srcAddress` / the deposited hub asset,
|
|
46353
|
+
* so a leverage intent that never fills refunds to the user on the chain they funded from — not to
|
|
46354
|
+
* the position, and not to the hub wallet.
|
|
46355
|
+
*/
|
|
46356
|
+
async buildOpenPositionData(params) {
|
|
46357
|
+
const prep = await this.prepareOpen(params, "buildOpenPositionData");
|
|
46358
|
+
if (!prep.ok) return prep;
|
|
46359
|
+
const { factory, funding, calls, reserveAmount, origin, fee } = prep.value;
|
|
46360
|
+
calls.push({
|
|
46361
|
+
address: factory,
|
|
46362
|
+
value: 0n,
|
|
46363
|
+
data: encodeFunctionData({
|
|
46364
|
+
abi: leveragePositionFactoryAbi,
|
|
46365
|
+
functionName: "createPositionAndLeverage",
|
|
46366
|
+
args: [
|
|
46367
|
+
this.positionConfig({
|
|
46368
|
+
owner: params.owner,
|
|
46369
|
+
collateral: funding.vault,
|
|
46370
|
+
borrowToken: params.borrowToken,
|
|
46371
|
+
eModeCategory: params.eModeCategory ?? 0,
|
|
46372
|
+
origin,
|
|
46373
|
+
fee
|
|
46374
|
+
}),
|
|
46375
|
+
reserveAmount,
|
|
46376
|
+
params.borrowAmount,
|
|
46377
|
+
params.minCollateralOut
|
|
46378
|
+
]
|
|
46379
|
+
})
|
|
46380
|
+
});
|
|
46381
|
+
return { ok: true, value: encodeContractCalls(calls) };
|
|
46382
|
+
}
|
|
46383
|
+
/**
|
|
46384
|
+
* Hub-side payload for opening a position from the debt side.
|
|
46385
|
+
*
|
|
46386
|
+
* The mirror of {@link LeverageYieldService.buildOpenPositionData}: here the deposit is the
|
|
46387
|
+
* position's *debt* token, contributed rather than supplied, and `collateral` is the reserve the
|
|
46388
|
+
* position ends up long. The hook supplies the solver's collateral on fill and borrows only the
|
|
46389
|
+
* shortfall, so the position legitimately starts with no collateral of its own.
|
|
46390
|
+
*/
|
|
46391
|
+
async buildOpenPositionFromDebtTokenData(params) {
|
|
46392
|
+
const prep = await this.prepareOpen(params, "buildOpenPositionFromDebtTokenData");
|
|
46393
|
+
if (!prep.ok) return prep;
|
|
46394
|
+
const { factory, funding, calls, reserveAmount, origin, fee } = prep.value;
|
|
46395
|
+
calls.push({
|
|
46396
|
+
address: factory,
|
|
46397
|
+
value: 0n,
|
|
46398
|
+
data: encodeFunctionData({
|
|
46399
|
+
abi: leveragePositionFactoryAbi,
|
|
46400
|
+
functionName: "createPositionFromDebtToken",
|
|
46401
|
+
args: [
|
|
46402
|
+
this.positionConfig({
|
|
46403
|
+
owner: params.owner,
|
|
46404
|
+
collateral: params.collateral,
|
|
46405
|
+
// The deposited token IS the debt side, so its reserve is the borrow token.
|
|
46406
|
+
borrowToken: funding.vault,
|
|
46407
|
+
eModeCategory: params.eModeCategory ?? 0,
|
|
46408
|
+
origin,
|
|
46409
|
+
fee
|
|
46410
|
+
}),
|
|
46411
|
+
reserveAmount,
|
|
46412
|
+
params.totalInput,
|
|
46413
|
+
params.minCollateralOut
|
|
46414
|
+
]
|
|
46415
|
+
})
|
|
46416
|
+
});
|
|
46417
|
+
return { ok: true, value: encodeContractCalls(calls) };
|
|
46418
|
+
}
|
|
46419
|
+
/**
|
|
46420
|
+
* Whether the funding token is already approved for an open from `srcChainKey`.
|
|
46421
|
+
*
|
|
46422
|
+
* The spender differs by chain and neither choice is guessable: on the hub the deposit is pulled
|
|
46423
|
+
* by the user's own hub wallet, executing inside the routed batch; on an EVM spoke it is pulled by
|
|
46424
|
+
* that spoke's asset manager. Chains with no allowance concept report `true`, and Stellar reports
|
|
46425
|
+
* whether the trustline covers the amount.
|
|
46426
|
+
*/
|
|
46427
|
+
async isPositionFundingAllowanceValid(params) {
|
|
46428
|
+
const baseCtx = { srcChainKey: params.srcChainKey, action: "allowanceCheck" };
|
|
46429
|
+
try {
|
|
46430
|
+
leverageYieldInvariant(params.amount > 0n, "amount must be greater than 0", { ...baseCtx, field: "amount" });
|
|
46431
|
+
const srcChainKey = params.srcChainKey;
|
|
46432
|
+
const inner = isHubChainKeyType(srcChainKey) || isEvmSpokeOnlyChainKeyType(srcChainKey) ? await this.spoke.isAllowanceValid({
|
|
46433
|
+
srcChainKey,
|
|
46434
|
+
token: params.token,
|
|
46435
|
+
amount: params.amount,
|
|
46436
|
+
owner: params.srcAddress,
|
|
46437
|
+
spender: await this.resolveFundingSpender(srcChainKey, params.srcAddress)
|
|
46438
|
+
}) : await this.spoke.isAllowanceValid({
|
|
46439
|
+
srcChainKey,
|
|
46440
|
+
token: params.token,
|
|
46441
|
+
amount: params.amount,
|
|
46442
|
+
owner: params.srcAddress
|
|
46443
|
+
});
|
|
46444
|
+
if (inner.ok) return inner;
|
|
46445
|
+
return { ok: false, error: allowanceCheckFailed("leverageYield", inner.error, baseCtx) };
|
|
46446
|
+
} catch (error) {
|
|
46447
|
+
if (isLeverageYieldAllowanceCheckError(error)) return { ok: false, error };
|
|
46448
|
+
return { ok: false, error: allowanceCheckFailed("leverageYield", error, baseCtx) };
|
|
46449
|
+
}
|
|
46450
|
+
}
|
|
46451
|
+
/**
|
|
46452
|
+
* Approves the funding token for an open, against the spender that chain's deposit actually uses —
|
|
46453
|
+
* see {@link LeverageYieldService.isPositionFundingAllowanceValid} for which that is.
|
|
46454
|
+
*
|
|
46455
|
+
* WAITS FOR THE APPROVAL TO LAND before returning. `Erc20Service.approve` resolves with the hash the
|
|
46456
|
+
* moment it is broadcast, so a caller that immediately re-reads the allowance sees the value from
|
|
46457
|
+
* BEFORE the approval — a UI then keeps showing "approve" and the user signs a second, pointless
|
|
46458
|
+
* approval. Returning early from a helper whose whole purpose is "the allowance is now sufficient" is
|
|
46459
|
+
* a footgun, so the wait lives here rather than in each caller.
|
|
46460
|
+
*/
|
|
46461
|
+
async approvePositionFunding(params) {
|
|
46462
|
+
const baseCtx = { srcChainKey: params.srcChainKey, action: "approve" };
|
|
46463
|
+
try {
|
|
46464
|
+
leverageYieldInvariant(params.amount > 0n, "amount must be greater than 0", { ...baseCtx, field: "amount" });
|
|
46465
|
+
const srcChainKey = params.srcChainKey;
|
|
46466
|
+
let inner = {
|
|
46467
|
+
ok: false,
|
|
46468
|
+
error: new Error(`[LeverageYieldService.approvePositionFunding] approve is unsupported on ${srcChainKey}`)
|
|
46469
|
+
};
|
|
46470
|
+
if (isHubChainKeyType(srcChainKey) || isEvmSpokeOnlyChainKeyType(srcChainKey)) {
|
|
46471
|
+
leverageYieldInvariant(isAddress(params.token), "Invalid token address", { ...baseCtx, field: "token" });
|
|
46472
|
+
inner = await this.spoke.approve({
|
|
46473
|
+
srcChainKey,
|
|
46474
|
+
token: params.token,
|
|
46475
|
+
amount: params.amount,
|
|
46476
|
+
owner: params.srcAddress,
|
|
46477
|
+
spender: await this.resolveFundingSpender(srcChainKey, params.srcAddress),
|
|
46478
|
+
raw: false,
|
|
46479
|
+
// `K` stays open here, so the provider is only checkable against the chain key inside `spoke.approve`.
|
|
46480
|
+
walletProvider: params.walletProvider
|
|
46481
|
+
});
|
|
46482
|
+
} else if (isStellarChainKeyType(srcChainKey)) {
|
|
46483
|
+
inner = await this.spoke.approve({
|
|
46484
|
+
srcChainKey,
|
|
46485
|
+
token: params.token,
|
|
46486
|
+
amount: params.amount,
|
|
46487
|
+
owner: params.srcAddress,
|
|
46488
|
+
raw: false,
|
|
46489
|
+
walletProvider: params.walletProvider
|
|
46490
|
+
});
|
|
46491
|
+
}
|
|
46492
|
+
if (!inner.ok) return { ok: false, error: approveFailed("leverageYield", inner.error, baseCtx) };
|
|
46493
|
+
if (params.walletProvider && isEvmWalletProviderType(params.walletProvider)) {
|
|
46494
|
+
const receipt = await params.walletProvider.waitForTransactionReceipt(
|
|
46495
|
+
inner.value
|
|
46496
|
+
);
|
|
46497
|
+
if (receipt.status !== "success") {
|
|
46498
|
+
return { ok: false, error: approveFailed("leverageYield", "transaction reverted", baseCtx) };
|
|
46499
|
+
}
|
|
46500
|
+
} else {
|
|
46501
|
+
const landed = await this.spoke.verifyTxHash({ txHash: inner.value, chainKey: params.srcChainKey });
|
|
46502
|
+
if (!landed.ok) return { ok: false, error: approveFailed("leverageYield", landed.error, baseCtx) };
|
|
46503
|
+
}
|
|
46504
|
+
return inner;
|
|
46505
|
+
} catch (error) {
|
|
46506
|
+
if (isLeverageYieldApproveError(error)) return { ok: false, error };
|
|
46507
|
+
return { ok: false, error: approveFailed("leverageYield", error, baseCtx) };
|
|
46508
|
+
}
|
|
46509
|
+
}
|
|
46510
|
+
/**
|
|
46511
|
+
* Who pulls the deposit on an EVM source chain.
|
|
46512
|
+
*
|
|
46513
|
+
* On the hub the pull happens inside the routed batch, so the spender is the user's own hub wallet
|
|
46514
|
+
* rather than any protocol contract; on an EVM spoke it is that spoke's asset manager. Chains with
|
|
46515
|
+
* no ERC-20 allowance never reach here.
|
|
46516
|
+
*/
|
|
46517
|
+
async resolveFundingSpender(srcChainKey, srcAddress) {
|
|
46518
|
+
if (isHubChainKeyType(srcChainKey)) return await this.hubProvider.getUserHubWalletAddress(srcAddress, srcChainKey);
|
|
46519
|
+
return this.config.getChainConfig(srcChainKey).addresses.assetManager;
|
|
46520
|
+
}
|
|
46521
|
+
/**
|
|
46522
|
+
* Opens a leveraged position, funded from any chain, in one signature.
|
|
46523
|
+
*
|
|
46524
|
+
* The deposit is carried to the user's hub wallet and the position is created from inside that
|
|
46525
|
+
* same batch, so there is no window in which the funds sit on the hub unattached to a position.
|
|
46526
|
+
* On the hub this routes locally; from a spoke it relays and this waits for the hub side to land.
|
|
46527
|
+
*
|
|
46528
|
+
* WHAT IS AND IS NOT DONE WHEN THIS RESOLVES: the position exists and its leverage intent is
|
|
46529
|
+
* posted. The leverage itself is not applied — a solver fills that intent afterwards. And an
|
|
46530
|
+
* intent is invisible to the solver until its hub transaction hash is reported, so pass the
|
|
46531
|
+
* returned `dstChainTxHash` to {@link LeverageYieldService.notifySolver}; an unreported intent
|
|
46532
|
+
* simply expires and the deposit comes back.
|
|
46533
|
+
*
|
|
46534
|
+
* Spoke tokens need the spoke asset manager approved first, the same as any other deposit.
|
|
46535
|
+
*
|
|
46536
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN. Every path here has been exercised
|
|
46537
|
+
* end to end on Sonic, the hub. From a spoke the inbound half is proven only by a fork
|
|
46538
|
+
* replay of a real relayed message, and the OUTBOUND half — an exit or a cancellation
|
|
46539
|
+
* delivering the underlying back to the spoke it came from — has never run on mainnet.
|
|
46540
|
+
* Treat a non-hub `srcChainKey` as experimental until it has. Bitcoin is refused
|
|
46541
|
+
* outright — see {@link BITCOIN_UNSUPPORTED_MESSAGE}.
|
|
46542
|
+
*/
|
|
46543
|
+
async openPosition(_params) {
|
|
46544
|
+
return this.runPositionOpen(
|
|
46545
|
+
_params,
|
|
46546
|
+
"openPosition",
|
|
46547
|
+
(owner, params) => this.buildOpenPositionData({ ...params, owner })
|
|
46548
|
+
);
|
|
46549
|
+
}
|
|
46550
|
+
/**
|
|
46551
|
+
* Opens a leveraged position from the **debt** token, funded from any chain.
|
|
46552
|
+
*
|
|
46553
|
+
* Same transport and the same asynchronous settlement as
|
|
46554
|
+
* {@link LeverageYieldService.openPosition} — see there for what is and is not done when this
|
|
46555
|
+
* resolves. The difference is only which side the user funds: here they hand over debt token and
|
|
46556
|
+
* end up long collateral they never held.
|
|
46557
|
+
*
|
|
46558
|
+
* Requires the deployed implementation to have a debt-side hook configured; without one the
|
|
46559
|
+
* position reverts `DebtSideHookUnavailable`.
|
|
46560
|
+
*
|
|
46561
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN. Every path here has been exercised
|
|
46562
|
+
* end to end on Sonic, the hub. From a spoke the inbound half is proven only by a fork
|
|
46563
|
+
* replay of a real relayed message, and the OUTBOUND half — an exit or a cancellation
|
|
46564
|
+
* delivering the underlying back to the spoke it came from — has never run on mainnet.
|
|
46565
|
+
* Treat a non-hub `srcChainKey` as experimental until it has. Bitcoin is refused
|
|
46566
|
+
* outright — see {@link BITCOIN_UNSUPPORTED_MESSAGE}.
|
|
46567
|
+
*/
|
|
46568
|
+
async openPositionFromDebtToken(_params) {
|
|
46569
|
+
return this.runPositionOpen(
|
|
46570
|
+
_params,
|
|
46571
|
+
"openPositionFromDebtToken",
|
|
46572
|
+
(owner, params) => this.buildOpenPositionFromDebtTokenData({ ...params, owner })
|
|
46573
|
+
);
|
|
46574
|
+
}
|
|
46575
|
+
/**
|
|
46576
|
+
* Shared body of the two open paths. They differ only in which factory call the payload ends with,
|
|
46577
|
+
* so everything around it — owner resolution, deposit, verify, relay — lives here rather than
|
|
46578
|
+
* being written twice and drifting.
|
|
46579
|
+
*/
|
|
46580
|
+
/**
|
|
46581
|
+
* Instrumentation for both opens. Wrapping the shared runner rather than each entry point keeps
|
|
46582
|
+
* `openPosition` and `openPositionFromDebtToken` from drifting, and `action` is already threaded
|
|
46583
|
+
* through for the error context, so it doubles as the analytics action.
|
|
46584
|
+
*
|
|
46585
|
+
* `start` carries only the fields common to both param shapes — the funding side's token and
|
|
46586
|
+
* amount. The side-specific ones (`borrowToken`/`borrowAmount` vs `collateral`/`totalInput`) are
|
|
46587
|
+
* not on `PositionFundingParams`, and inventing a cast to reach them would be worse than omitting
|
|
46588
|
+
* them.
|
|
46589
|
+
*/
|
|
46590
|
+
async runPositionOpen(_params, action, build) {
|
|
46591
|
+
return this.config.analytics.trackResult(
|
|
46592
|
+
"leverageYield",
|
|
46593
|
+
action,
|
|
46594
|
+
() => this.executePositionOpen(_params, action, build),
|
|
46595
|
+
{
|
|
46596
|
+
start: () => ({
|
|
46597
|
+
srcChainKey: _params.params.srcChainKey,
|
|
46598
|
+
srcAddress: _params.params.srcAddress,
|
|
46599
|
+
inputToken: _params.params.token,
|
|
46600
|
+
inputAmount: _params.params.amount,
|
|
46601
|
+
eModeCategory: _params.params.eModeCategory
|
|
46602
|
+
}),
|
|
46603
|
+
success: (value) => ({ srcTxHash: value.srcChainTxHash, dstTxHash: value.dstChainTxHash }),
|
|
46604
|
+
failure: (error) => ({ code: error.code })
|
|
46605
|
+
}
|
|
46606
|
+
);
|
|
46607
|
+
}
|
|
46608
|
+
async executePositionOpen(_params, action, buildData) {
|
|
46609
|
+
const { params, timeout = DEFAULT_RELAY_TX_TIMEOUT } = _params;
|
|
46610
|
+
const baseCtx = {
|
|
46611
|
+
srcChainKey: params.srcChainKey,
|
|
46612
|
+
action
|
|
46613
|
+
};
|
|
46614
|
+
try {
|
|
46615
|
+
leverageYieldInvariant(!isBitcoinChainKeyType(params.srcChainKey), BITCOIN_UNSUPPORTED_MESSAGE, {
|
|
46616
|
+
...baseCtx,
|
|
46617
|
+
field: "srcChainKey"
|
|
46618
|
+
});
|
|
46619
|
+
leverageYieldInvariant(params.amount > 0n, "amount must be greater than 0", { ...baseCtx, field: "amount" });
|
|
46620
|
+
leverageYieldInvariant(params.minCollateralOut > 0n, "minCollateralOut must be greater than 0", {
|
|
46621
|
+
...baseCtx,
|
|
46622
|
+
field: "minCollateralOut"
|
|
46623
|
+
});
|
|
46624
|
+
leverageYieldInvariant(
|
|
46625
|
+
isUndefinedOrValidWalletProviderForChainKey(params.srcChainKey, _params.walletProvider),
|
|
46626
|
+
`Invalid wallet provider for chain key: ${params.srcChainKey}`,
|
|
46627
|
+
{ ...baseCtx, field: "walletProvider" }
|
|
46628
|
+
);
|
|
46629
|
+
const hubWallet = await this.hubProvider.getUserHubWalletAddress(params.srcAddress, params.srcChainKey);
|
|
46630
|
+
const data = await buildData(hubWallet, params);
|
|
46631
|
+
if (!data.ok) return data;
|
|
46632
|
+
const txResult = await this.spoke.deposit({
|
|
46633
|
+
srcChainKey: params.srcChainKey,
|
|
46634
|
+
srcAddress: params.srcAddress,
|
|
46635
|
+
to: hubWallet,
|
|
46636
|
+
token: params.token,
|
|
46637
|
+
amount: params.amount,
|
|
46638
|
+
data: data.value,
|
|
46639
|
+
skipSimulation: _params.skipSimulation ?? false,
|
|
46640
|
+
raw: false,
|
|
46641
|
+
walletProvider: _params.walletProvider
|
|
46642
|
+
});
|
|
46643
|
+
if (!txResult.ok) {
|
|
46644
|
+
if (isLeverageYieldCreateIntentError(txResult.error)) return { ok: false, error: txResult.error };
|
|
46645
|
+
return { ok: false, error: intentCreationFailed("leverageYield", txResult.error, baseCtx) };
|
|
46646
|
+
}
|
|
46647
|
+
return await this.settleHubWalletMessage(txResult.value, { address: hubWallet, payload: data.value }, baseCtx, {
|
|
46648
|
+
timeout
|
|
46649
|
+
});
|
|
46650
|
+
} catch (error) {
|
|
46651
|
+
if (isLeverageYieldSwapError(error)) return { ok: false, error };
|
|
46652
|
+
return { ok: false, error: executionFailed("leverageYield", error, { ...baseCtx, phase: "intentCreation" }) };
|
|
46653
|
+
}
|
|
46654
|
+
}
|
|
46655
|
+
/**
|
|
46656
|
+
* Which address actually funds a position from `chainKey` — what a balance must be read against,
|
|
46657
|
+
* and what the deposit is built from.
|
|
46658
|
+
*
|
|
46659
|
+
* ONE ANSWER FOR BOTH, because two answers cost an open on mainnet: the balance was read from the
|
|
46660
|
+
* registry `address` while the deposit rewrote it to `hubAsset`, so for Sonic's native S the form
|
|
46661
|
+
* showed 42 S and the batch then called `wS.transferFrom(user, hubWallet, 5e18)` against a wS
|
|
46662
|
+
* balance of zero. The approval was correct; the revert surfaced as nothing but "External call
|
|
46663
|
+
* failed". Any integrator reading a balance for a position deposit needs this same answer.
|
|
46664
|
+
*
|
|
46665
|
+
* Three addresses hang off a registry entry and they are not interchangeable:
|
|
46666
|
+
*
|
|
46667
|
+
* `address` the spoke-side original; for a bridged entry it can name another chain entirely
|
|
46668
|
+
* `hubAsset` what the user holds ON THE HUB, and the vault's deposit input
|
|
46669
|
+
* `vault` the hub money-market reserve the position ends up in
|
|
46670
|
+
*
|
|
46671
|
+
* Off the hub the answer is always `address` — that is the chain the user is on. On the hub it is
|
|
46672
|
+
* `hubAsset`, EXCEPT for a native entry: `EvmSpokeService.deposit` keys on the chain's own
|
|
46673
|
+
* `nativeToken` to send `msg.value` rather than an ERC-20 `transferFrom`, and the native entry
|
|
46674
|
+
* carries exactly that sentinel as its `address`. Rewriting that to the wrapper asks for a token
|
|
46675
|
+
* the wallet does not hold.
|
|
46676
|
+
*
|
|
46677
|
+
* @returns The funding address, or `undefined` when the token is not supported on `chainKey`.
|
|
46678
|
+
*/
|
|
46679
|
+
resolvePositionFunding(chainKey, token) {
|
|
46680
|
+
const address = resolvePositionFundingAddress(chainKey, this.hubProvider.chainConfig.chain.key, token);
|
|
46681
|
+
return address === "" ? void 0 : address;
|
|
46682
|
+
}
|
|
46683
|
+
/**
|
|
46684
|
+
* Quotes one leg of a position operation: the borrowed side when levering up, the collateral when
|
|
46685
|
+
* levering down or exiting.
|
|
46686
|
+
*
|
|
46687
|
+
* Use this rather than {@link LeverageYieldService.getQuote} for a position. Both hit the same
|
|
46688
|
+
* endpoint, but this one names the hub reserves as the pair the intent actually swaps and quotes
|
|
46689
|
+
* GROSS — see `positionLegQuote.ts` for why either alone gets the floor wrong. Feed `quotedAmount`
|
|
46690
|
+
* to {@link projectLeverageLeg}.
|
|
46691
|
+
*
|
|
46692
|
+
* A refusal is not always a dead pair: {@link isNoRouteRefusal} is also what the solver answers
|
|
46693
|
+
* for a leg that is only too small, and telling the two apart means quoting again at a healthy
|
|
46694
|
+
* notional. That size is priced, so it is the caller's to choose.
|
|
46695
|
+
*/
|
|
46696
|
+
async getPositionLegQuote(params) {
|
|
46697
|
+
const hubChainKey = this.hubProvider.chainConfig.chain.key;
|
|
46698
|
+
const quote = await this.getQuote({
|
|
46699
|
+
token_src: params.inputHubToken,
|
|
46700
|
+
token_src_blockchain_id: hubChainKey,
|
|
46701
|
+
token_dst: params.outputHubToken,
|
|
46702
|
+
token_dst_blockchain_id: hubChainKey,
|
|
46703
|
+
amount: params.amount,
|
|
46704
|
+
quote_type: "exact_input",
|
|
46705
|
+
// Explicit, not omitted: omitting it applies the configured leverage-yield fee.
|
|
46706
|
+
partnerFee: { address: zeroAddress, percentage: 0 }
|
|
46707
|
+
});
|
|
46708
|
+
if (!quote.ok) return quote;
|
|
46709
|
+
return { ok: true, value: { quotedAmount: quote.value.quoted_amount } };
|
|
46710
|
+
}
|
|
46711
|
+
/**
|
|
46712
|
+
* Opens a leveraged position AND reports the intent it posts. Prefer this to
|
|
46713
|
+
* {@link LeverageYieldService.openPosition} / {@link LeverageYieldService.openPositionFromDebtToken}.
|
|
46714
|
+
*
|
|
46715
|
+
* Those two only post the intent. Reporting it is a separate call that must not be skipped — an
|
|
46716
|
+
* unreported intent expires unfilled, so the owner is left funded with leverage that never arrives
|
|
46717
|
+
* and nothing said so. Pairing them here is the difference between an API that works and one that
|
|
46718
|
+
* works only if you read the docs.
|
|
46719
|
+
*
|
|
46720
|
+
* `side` picks which asset funds the open: `'collateral'` supplies the deposit and borrows against
|
|
46721
|
+
* it, `'debt'` hands the deposit to the solver and ends up long collateral never held.
|
|
46722
|
+
*
|
|
46723
|
+
* RESOLVING MEANS THE INTENT IS LIVE, not that the position is open, and a failed notification is
|
|
46724
|
+
* still `ok: true` — see {@link LeveragePositionIntentResult}.
|
|
46725
|
+
*
|
|
46726
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN — see `operatePosition`.
|
|
46727
|
+
*/
|
|
46728
|
+
async openLeveragePosition(_params) {
|
|
46729
|
+
return this.config.analytics.trackResult(
|
|
46730
|
+
"leverageYield",
|
|
46731
|
+
"openLeveragePosition",
|
|
46732
|
+
async () => {
|
|
46733
|
+
const { side, ...rest } = _params;
|
|
46734
|
+
const opened = side === "debt" ? await this.openPositionFromDebtToken(
|
|
46735
|
+
rest
|
|
46736
|
+
) : await this.openPosition(rest);
|
|
46737
|
+
if (!opened.ok) return opened;
|
|
46738
|
+
return { ok: true, value: await reportPositionIntent(this.notifyIntent, opened.value) };
|
|
46739
|
+
},
|
|
46740
|
+
{
|
|
46741
|
+
start: () => ({ srcChainKey: _params.params.srcChainKey, side: _params.side ?? "collateral" }),
|
|
46742
|
+
success: (result) => ({ ...result.txHashes, notified: result.notified }),
|
|
46743
|
+
failure: (error) => ({ code: error.code })
|
|
46744
|
+
}
|
|
46745
|
+
);
|
|
46746
|
+
}
|
|
46747
|
+
/**
|
|
46748
|
+
* Runs position calls that POST A SOLVER INTENT — `addLeverage` and `decreaseLeverage` — and
|
|
46749
|
+
* reports it. Prefer this to {@link LeverageYieldService.operatePosition} for those two.
|
|
46750
|
+
*
|
|
46751
|
+
* USE {@link LeverageYieldService.runLeveragePositionOperation} FOR `withdraw`, `settle` AND
|
|
46752
|
+
* `cancel`. Those are synchronous on the hub and need no notification, and the split is not
|
|
46753
|
+
* cosmetic: sending a leverage change through the route-only path leaves an intent nothing will
|
|
46754
|
+
* fill, and it expires without a word. The other direction is merely noisy.
|
|
46755
|
+
*
|
|
46756
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN — see `operatePosition`.
|
|
46757
|
+
*/
|
|
46758
|
+
async submitLeveragePositionIntent(_params) {
|
|
46759
|
+
return this.config.analytics.trackResult(
|
|
46760
|
+
"leverageYield",
|
|
46761
|
+
"submitLeveragePositionIntent",
|
|
46762
|
+
async () => {
|
|
46763
|
+
const routed = await this.operatePosition(_params);
|
|
46764
|
+
if (!routed.ok) return routed;
|
|
46765
|
+
return { ok: true, value: await reportPositionIntent(this.notifyIntent, routed.value) };
|
|
46766
|
+
},
|
|
46767
|
+
{
|
|
46768
|
+
start: () => ({ srcChainKey: _params.params.srcChainKey, calls: _params.params.calls.length }),
|
|
46769
|
+
success: (result) => ({ ...result.txHashes, notified: result.notified }),
|
|
46770
|
+
failure: (error) => ({ code: error.code })
|
|
46771
|
+
}
|
|
46772
|
+
);
|
|
46773
|
+
}
|
|
46774
|
+
/**
|
|
46775
|
+
* Runs position calls that do NOT post an intent — `withdraw`, `settle` and `cancel` — as the
|
|
46776
|
+
* owning hub wallet. They are synchronous on the hub, so resolving means the work is done.
|
|
46777
|
+
*
|
|
46778
|
+
* Still routed, never sent directly: the position's `onlyOwner` is the hub wallet, so a builder's
|
|
46779
|
+
* transaction sent from the signer reverts `NotOwner`. Use
|
|
46780
|
+
* {@link LeverageYieldService.submitLeveragePositionIntent} for `addLeverage` and
|
|
46781
|
+
* `decreaseLeverage`, which this deliberately does not report.
|
|
46782
|
+
*
|
|
46783
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN, and this path carries the worst of
|
|
46784
|
+
* it: an exit or cancellation delivering the underlying back to the spoke it came from
|
|
46785
|
+
* has never run on mainnet.
|
|
46786
|
+
*/
|
|
46787
|
+
async runLeveragePositionOperation(_params) {
|
|
46788
|
+
return this.operatePosition(_params);
|
|
46789
|
+
}
|
|
46790
|
+
/** Bound once so the notify half can be handed around without losing `this`. */
|
|
46791
|
+
notifyIntent = (request) => this.notifySolver(request);
|
|
46792
|
+
/**
|
|
46793
|
+
* Runs position calls as the user's hub wallet, from any chain.
|
|
46794
|
+
*
|
|
46795
|
+
* The write counterpart to the read hooks: add or decrease leverage, withdraw, settle, cancel. No
|
|
46796
|
+
* funds move, so this is a bare message rather than a deposit — on the hub it routes locally, from
|
|
46797
|
+
* a spoke it relays and this waits for the hub side to land.
|
|
46798
|
+
*
|
|
46799
|
+
* The leverage calls only *post* an intent, so a resolved promise means the intent is live, not
|
|
46800
|
+
* that leverage moved. Report the returned `dstChainTxHash` to
|
|
46801
|
+
* {@link LeverageYieldService.notifySolver} for those two; `withdraw`, `settle` and `cancel` are
|
|
46802
|
+
* synchronous on the hub and need no notification.
|
|
46803
|
+
*
|
|
46804
|
+
* @experimental OFF-HUB (SPOKE) ORIGINS ARE UNVERIFIED ON-CHAIN. Every path here has been exercised
|
|
46805
|
+
* end to end on Sonic, the hub. From a spoke the inbound half is proven only by a fork
|
|
46806
|
+
* replay of a real relayed message, and the OUTBOUND half — an exit or a cancellation
|
|
46807
|
+
* delivering the underlying back to the spoke it came from — has never run on mainnet.
|
|
46808
|
+
* Treat a non-hub `srcChainKey` as experimental until it has. Bitcoin is refused
|
|
46809
|
+
* outright — see {@link BITCOIN_UNSUPPORTED_MESSAGE}.
|
|
46810
|
+
*/
|
|
46811
|
+
async operatePosition(_params) {
|
|
46812
|
+
return this.config.analytics.trackResult(
|
|
46813
|
+
"leverageYield",
|
|
46814
|
+
"operatePosition",
|
|
46815
|
+
() => this.executePositionOperation(_params),
|
|
46816
|
+
{
|
|
46817
|
+
// The calls themselves are not emitted — they are arbitrary hub calldata. The count is
|
|
46818
|
+
// enough to tell a batched adjust from a single write.
|
|
46819
|
+
start: () => ({
|
|
46820
|
+
srcChainKey: _params.params.srcChainKey,
|
|
46821
|
+
srcAddress: _params.params.srcAddress,
|
|
46822
|
+
callCount: _params.params.calls.length
|
|
46823
|
+
}),
|
|
46824
|
+
success: (value) => ({ srcTxHash: value.srcChainTxHash, dstTxHash: value.dstChainTxHash }),
|
|
46825
|
+
failure: (error) => ({ code: error.code })
|
|
46826
|
+
}
|
|
46827
|
+
);
|
|
46828
|
+
}
|
|
46829
|
+
async executePositionOperation(_params) {
|
|
46830
|
+
const { params, timeout = DEFAULT_RELAY_TX_TIMEOUT } = _params;
|
|
46831
|
+
const baseCtx = {
|
|
46832
|
+
srcChainKey: params.srcChainKey,
|
|
46833
|
+
action: "operatePosition"
|
|
46834
|
+
};
|
|
46835
|
+
try {
|
|
46836
|
+
leverageYieldInvariant(!isBitcoinChainKeyType(params.srcChainKey), BITCOIN_UNSUPPORTED_MESSAGE, {
|
|
46837
|
+
...baseCtx,
|
|
46838
|
+
field: "srcChainKey"
|
|
46839
|
+
});
|
|
46840
|
+
leverageYieldInvariant(params.calls.length > 0, "at least one call is required", {
|
|
46841
|
+
...baseCtx,
|
|
46842
|
+
field: "calls"
|
|
46843
|
+
});
|
|
46844
|
+
leverageYieldInvariant(
|
|
46845
|
+
isUndefinedOrValidWalletProviderForChainKey(params.srcChainKey, _params.walletProvider),
|
|
46846
|
+
`Invalid wallet provider for chain key: ${params.srcChainKey}`,
|
|
46847
|
+
{ ...baseCtx, field: "walletProvider" }
|
|
46848
|
+
);
|
|
46849
|
+
const hubWallet = await this.hubProvider.getUserHubWalletAddress(params.srcAddress, params.srcChainKey);
|
|
46850
|
+
const payload = this.encodePositionCalls(params.calls);
|
|
46851
|
+
const txResult = await this.spoke.sendMessage({
|
|
46852
|
+
srcChainKey: params.srcChainKey,
|
|
46853
|
+
srcAddress: params.srcAddress,
|
|
46854
|
+
dstChainKey: HUB_CHAIN_KEY,
|
|
46855
|
+
dstAddress: hubWallet,
|
|
46856
|
+
payload,
|
|
46857
|
+
skipSimulation: _params.skipSimulation ?? false,
|
|
46858
|
+
raw: false,
|
|
46859
|
+
walletProvider: _params.walletProvider
|
|
46860
|
+
});
|
|
46861
|
+
if (!txResult.ok) {
|
|
46862
|
+
if (isLeverageYieldCreateIntentError(txResult.error)) return { ok: false, error: txResult.error };
|
|
46863
|
+
return { ok: false, error: intentCreationFailed("leverageYield", txResult.error, baseCtx) };
|
|
46864
|
+
}
|
|
46865
|
+
return await this.settleHubWalletMessage(txResult.value, { address: hubWallet, payload }, baseCtx, { timeout });
|
|
46866
|
+
} catch (error) {
|
|
46867
|
+
if (isLeverageYieldSwapError(error)) return { ok: false, error };
|
|
46868
|
+
return { ok: false, error: executionFailed("leverageYield", error, { ...baseCtx, phase: "intentCreation" }) };
|
|
46869
|
+
}
|
|
46870
|
+
}
|
|
46871
|
+
/**
|
|
46872
|
+
* Verifies a submitted source transaction and, off the hub, relays it and waits for the hub side.
|
|
46873
|
+
*
|
|
46874
|
+
* Shared by both write paths because the tail is identical whether funds moved or not. The hub
|
|
46875
|
+
* short-circuit is not an optimisation: a hub transaction has already executed the calls, so there
|
|
46876
|
+
* is nothing to relay, and both hashes are the same transaction.
|
|
46877
|
+
*/
|
|
46878
|
+
async settleHubWalletMessage(srcTxHash, relayData, baseCtx, opts) {
|
|
46879
|
+
const verify = await this.spoke.verifyTxHash({ txHash: srcTxHash, chainKey: baseCtx.srcChainKey });
|
|
46880
|
+
if (!verify.ok) return { ok: false, error: verifyFailed("leverageYield", verify.error, baseCtx) };
|
|
46881
|
+
if (isHubChainKeyType(baseCtx.srcChainKey)) {
|
|
46882
|
+
const receipt = await this.hubProvider.publicClient.waitForTransactionReceipt({
|
|
46883
|
+
hash: srcTxHash,
|
|
46884
|
+
timeout: opts.timeout
|
|
46885
|
+
});
|
|
46886
|
+
if (receipt.status !== "success") {
|
|
46887
|
+
return {
|
|
46888
|
+
ok: false,
|
|
46889
|
+
error: verifyFailed("leverageYield", new Error(`hub transaction ${srcTxHash} reverted`), baseCtx)
|
|
46890
|
+
};
|
|
46891
|
+
}
|
|
46892
|
+
return { ok: true, value: { srcChainTxHash: srcTxHash, dstChainTxHash: srcTxHash } };
|
|
46893
|
+
}
|
|
46894
|
+
const packet = await relayTxAndWaitPacket({
|
|
46895
|
+
srcTxHash,
|
|
46896
|
+
data: relayData,
|
|
46897
|
+
chainKey: baseCtx.srcChainKey,
|
|
46898
|
+
relayerApiEndpoint: this.config.relay.relayerApiEndpoint,
|
|
46899
|
+
timeout: opts.timeout
|
|
46900
|
+
});
|
|
46901
|
+
if (!packet.ok) {
|
|
46902
|
+
return {
|
|
46903
|
+
ok: false,
|
|
46904
|
+
error: mapRelayFailure(packet.error, {
|
|
46905
|
+
feature: "leverageYield",
|
|
46906
|
+
action: baseCtx.action,
|
|
46907
|
+
srcChainKey: baseCtx.srcChainKey
|
|
46908
|
+
})
|
|
46909
|
+
};
|
|
46910
|
+
}
|
|
46911
|
+
return { ok: true, value: { srcChainTxHash: srcTxHash, dstChainTxHash: packet.value.dst_tx_hash } };
|
|
46912
|
+
}
|
|
44856
46913
|
};
|
|
44857
46914
|
|
|
44858
46915
|
// src/sponsoring/errors.ts
|
|
@@ -44880,12 +46937,12 @@ function toDomainCode(value) {
|
|
|
44880
46937
|
}
|
|
44881
46938
|
function readErrorBody(body) {
|
|
44882
46939
|
if (typeof body !== "object" || body === null) return {};
|
|
44883
|
-
const
|
|
44884
|
-
const retryAfterSeconds = typeof
|
|
44885
|
-
const sponsorSequence = typeof
|
|
46940
|
+
const record = body;
|
|
46941
|
+
const retryAfterSeconds = typeof record.retryAfterSeconds === "number" && Number.isFinite(record.retryAfterSeconds) && record.retryAfterSeconds > 0 ? record.retryAfterSeconds : void 0;
|
|
46942
|
+
const sponsorSequence = typeof record.sponsorSequence === "string" && /^\d+$/.test(record.sponsorSequence) ? record.sponsorSequence : void 0;
|
|
44886
46943
|
return {
|
|
44887
|
-
message: typeof
|
|
44888
|
-
code: toDomainCode(
|
|
46944
|
+
message: typeof record.message === "string" ? record.message : void 0,
|
|
46945
|
+
code: toDomainCode(record.error),
|
|
44889
46946
|
retryAfterSeconds,
|
|
44890
46947
|
sponsorSequence
|
|
44891
46948
|
};
|
|
@@ -45541,6 +47598,81 @@ var PARTNER_CODES = /* @__PURE__ */ new Set([
|
|
|
45541
47598
|
"UNKNOWN"
|
|
45542
47599
|
]);
|
|
45543
47600
|
var isPartnerError = isCodeMember(PARTNER_CODES);
|
|
47601
|
+
function sizeLeverageBorrow(request) {
|
|
47602
|
+
const { side, deposit, depositDecimals, collateralPriceUsd, borrowPriceUsd, borrowDecimals, leverage } = request;
|
|
47603
|
+
const depositTokens = Number(formatUnits(deposit, depositDecimals));
|
|
47604
|
+
const depositUsd = depositTokens * (side === "debt" ? borrowPriceUsd : collateralPriceUsd);
|
|
47605
|
+
const RATIO_SCALE = 1000000000n;
|
|
47606
|
+
const ratio = borrowPriceUsd > 0 && depositTokens > 0 ? depositUsd * Math.max(leverage - 1, 0) / borrowPriceUsd / depositTokens : 0;
|
|
47607
|
+
const borrowAmount = deposit * BigInt(Math.floor(ratio * Number(RATIO_SCALE))) * 10n ** BigInt(borrowDecimals) / (RATIO_SCALE * 10n ** BigInt(depositDecimals));
|
|
47608
|
+
const depositInBorrowUnits = deposit * 10n ** BigInt(borrowDecimals) / 10n ** BigInt(depositDecimals);
|
|
47609
|
+
const intentInput = side === "debt" ? borrowAmount + depositInBorrowUnits : borrowAmount;
|
|
47610
|
+
const feeAmount = request.feeBps ? intentInput * BigInt(Math.round(request.feeBps)) / 10000n : 0n;
|
|
47611
|
+
const borrowUsd = Number(formatUnits(borrowAmount, borrowDecimals)) * borrowPriceUsd;
|
|
47612
|
+
const feeUsd = Number(formatUnits(feeAmount, borrowDecimals)) * borrowPriceUsd;
|
|
47613
|
+
return {
|
|
47614
|
+
borrowAmount,
|
|
47615
|
+
intentInput,
|
|
47616
|
+
depositUsd,
|
|
47617
|
+
// Taken from the amount actually being borrowed, so the projection cannot disagree with the
|
|
47618
|
+
// transaction by the rounding above.
|
|
47619
|
+
borrowUsd,
|
|
47620
|
+
feeAmount,
|
|
47621
|
+
// The fee is borrowed on top on a leverage-up, so it is debt even though the solver never sees it.
|
|
47622
|
+
debtUsd: borrowUsd + feeUsd
|
|
47623
|
+
};
|
|
47624
|
+
}
|
|
47625
|
+
function projectLeverageLeg(request, quote, risk, slippagePct) {
|
|
47626
|
+
const { side, collateralPriceUsd, leverage } = request;
|
|
47627
|
+
const sized = sizeLeverageBorrow(request);
|
|
47628
|
+
const { depositUsd, borrowUsd } = sized;
|
|
47629
|
+
const floor = quote.quotedCollateral * BigInt(Math.round((100 - slippagePct) * 100)) / 10000n;
|
|
47630
|
+
const minCollateralOut = floor > 0n ? floor : 1n;
|
|
47631
|
+
const floorUsd = Number(formatUnits(minCollateralOut, quote.collateralDecimals)) * collateralPriceUsd;
|
|
47632
|
+
const quotedUsd = Number(formatUnits(quote.quotedCollateral, quote.collateralDecimals)) * collateralPriceUsd;
|
|
47633
|
+
const inputUsd = side === "debt" ? depositUsd * leverage : borrowUsd;
|
|
47634
|
+
const f = inputUsd > 0 ? floorUsd / inputUsd : 0;
|
|
47635
|
+
const haircut = inputUsd > 0 ? 1 - quotedUsd / inputUsd : 0;
|
|
47636
|
+
const collateralUsd = (side === "debt" ? 0 : depositUsd) + floorUsd;
|
|
47637
|
+
const debtUsd = sized.debtUsd;
|
|
47638
|
+
const ltv = collateralUsd > 0 ? debtUsd / collateralUsd : 0;
|
|
47639
|
+
const ltvF = risk.ltv * f;
|
|
47640
|
+
const phi = (request.feeBps ?? 0) / 1e4;
|
|
47641
|
+
const denominator = 1 + phi - ltvF;
|
|
47642
|
+
const usableMaxLeverage = risk.ltv <= 0 ? 1 : denominator <= 0 ? Number.POSITIVE_INFINITY : side === "debt" ? 1 / denominator : 1 + risk.ltv / denominator;
|
|
47643
|
+
const equityUsd = collateralUsd - debtUsd;
|
|
47644
|
+
return {
|
|
47645
|
+
minCollateralOut,
|
|
47646
|
+
collateralUsd,
|
|
47647
|
+
debtUsd,
|
|
47648
|
+
exposureLeverage: equityUsd > 0 ? collateralUsd / equityUsd : Number.POSITIVE_INFINITY,
|
|
47649
|
+
ltv,
|
|
47650
|
+
healthFactor: debtUsd > 0 ? collateralUsd * risk.liquidationThreshold / debtUsd : Number.POSITIVE_INFINITY,
|
|
47651
|
+
exceedsMaxLtv: ltv > risk.ltv,
|
|
47652
|
+
haircut,
|
|
47653
|
+
inputUsd,
|
|
47654
|
+
costUsd: inputUsd * haircut + sized.debtUsd - borrowUsd,
|
|
47655
|
+
usableMaxLeverage
|
|
47656
|
+
};
|
|
47657
|
+
}
|
|
47658
|
+
|
|
47659
|
+
// src/leverageYield/positionApyMath.ts
|
|
47660
|
+
function leveragedNetApyPct(supplyApyPct, borrowApyPct, leverage) {
|
|
47661
|
+
return supplyApyPct * leverage - borrowApyPct * (leverage - 1);
|
|
47662
|
+
}
|
|
47663
|
+
function timeToBreakevenYears(supplyApyPct, borrowApyPct, toLeverage, { costUsd, equityUsd, fromLeverage }) {
|
|
47664
|
+
if (!(equityUsd > 0) || !Number.isFinite(costUsd)) return void 0;
|
|
47665
|
+
if (costUsd <= 0) return "immediate";
|
|
47666
|
+
const incrementalPct = leveragedNetApyPct(supplyApyPct, borrowApyPct, toLeverage) - leveragedNetApyPct(supplyApyPct, borrowApyPct, fromLeverage);
|
|
47667
|
+
if (!(incrementalPct > 0)) return "never";
|
|
47668
|
+
return costUsd / (equityUsd * (incrementalPct / 100));
|
|
47669
|
+
}
|
|
47670
|
+
|
|
47671
|
+
// src/leverageYield/positionLegQuote.ts
|
|
47672
|
+
function isNoRouteRefusal(error) {
|
|
47673
|
+
const message = typeof error === "object" && error !== null && "detail" in error ? error.detail?.message : error instanceof Error ? error.message : void 0;
|
|
47674
|
+
return /no path was found/i.test(message ?? "");
|
|
47675
|
+
}
|
|
45544
47676
|
/*! Bundled license information:
|
|
45545
47677
|
|
|
45546
47678
|
@noble/hashes/utils.js:
|
|
@@ -45559,4 +47691,4 @@ var isPartnerError = isCodeMember(PARTNER_CODES);
|
|
|
45559
47691
|
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
45560
47692
|
*/
|
|
45561
47693
|
|
|
45562
|
-
export { ALLOWANCE_CHECK_CODES, APPROVE_CODES, AssetService, BACKEND_API_BASE_PATH, BITCOIN_CHAIN_KEYS, BITCOIN_CHAIN_KEYS_SET, BITCOIN_DUST_SATS, BOUND_API_HOST, BOUND_COMPANION_HOSTS, BTC_WALLET_ADDRESS_TYPES, BackendApiService, BackendHttpError, BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BitcoinSpokeService, BnUSDMigrationService, BridgeApiService, BridgeService, CHAIN_KEYS, CHAIN_LOGO_BASE_URL, CONFIG_VERSION, CREATE_INTENT_CODES, ChainKeys, ChainTypeArr, ClService, ConfigService, CustomSorobanServer, CustomStellarAccount, DEFAULT_API_BASE_URL, DEFAULT_BACKEND_API_ENDPOINT, DEFAULT_BACKEND_API_HEADERS, DEFAULT_BACKEND_API_TIMEOUT, DEFAULT_DEADLINE_OFFSET, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, DEFAULT_SPONSORING_API_ENDPOINT, DEPRECATED_BOUND_HOSTS, DETAILED_STATUS_NOT_DELIVERED, DexService, EVM_CHAIN_ID_TO_KEY, EVM_CHAIN_KEYS, EVM_CHAIN_KEYS_SET, EVM_SPOKE_ONLY_CHAIN_KEYS, EVM_SPOKE_ONLY_CHAIN_KEYS_SET, Erc20Service, Erc4626Service, EvmAssetManagerService, EvmHubProvider, EvmSolverService, EvmSpokeService, EvmVaultTokenService, FEE_PERCENTAGE_SCALE, GAS_ESTIMATION_CODES, HALF_RAY, HALF_WAD, HUB_CHAIN_KEY, HookKind, HookService, HttpRelayError, HubVaultSymbols, ICON_CHAIN_KEYS, ICON_CHAIN_KEYS_SET, ICON_TX_RESULT_WAIT_MAX_RETRY, INJECTIVE_CHAIN_KEYS, INJECTIVE_CHAIN_KEYS_SET, INTENT_CHAIN_IDS, IconSpokeService, IcxMigrationService, Injective20Token, InjectiveSpokeService, IntentCreatedEventAbi, IntentDataService, IntentDataType, IntentFilledEventAbi, IntentRelayChainIdToChainKey, IntentsAbi, LOOKUP_CODES, LTV_PRECISION, LendingPoolService, LeverageYieldApiService, LeverageYieldService, LockupMultiplier, LockupPeriod, LsodaSymbols, LsodaTokens, MAX_UINT256, MigrationService, MintPositionEventAbi, MoneyMarketDataService, MoneyMarketService, NEAR_CHAIN_KEYS, NEAR_CHAIN_KEYS_SET, NEAR_DEFAULT_GAS, NEAR_STORAGE_DEPOSIT, NearSpokeService, ORACLE_CANDLE_INTERVALS, PartnerFeeClaimService, PartnerService, Permit2Service, ProtocolIntentsAbi, RAY, RAY_DECIMALS, RELAY_ERROR_CODES, RELAY_FALLBACK_FLOOR_MS, RELAY_REQUEST_TIMEOUT_MS, RadfiApiError, RadfiProvider, RecoveryService, RelayChainIdMap, SECONDS_PER_YEAR, SODAX_ERROR_CODES, SODAX_FEATURES, SOLANA_CHAIN_KEYS, SOLANA_CHAIN_KEYS_SET, SONIC_CHAIN_KEYS, SONIC_CHAIN_KEYS_SET, SPEED_TIER_SECONDS, SPEED_TIER_THRESHOLDS, SPONSORING_API_ERROR_CODES, SPONSORING_API_STELLAR_BASE_PATH, SPONSOR_CONFIG_TTL_MS, STACKS_CHAIN_KEYS, STACKS_CHAIN_KEYS_SET, STELLAR_BASE_RESERVE_TTL_MS, STELLAR_CHAIN_KEYS, STELLAR_CHAIN_KEYS_SET, STELLAR_TRUSTLINE_MIN_XLM_STROOPS, SUI_CHAIN_KEYS, SUI_CHAIN_KEYS_SET, SodaTokens, Sodax, SodaxError, SolanaSpokeService, SolverApiService, SolverIntentErrorCode, SolverIntentStatusCode, SonicSpokeService, SpokeService, SponsoringApiService, SponsoringService, StacksSpokeService, StakingLogic, StakingService, StatATokenAddresses, StellarSpokeService, SuiGrpcTransport, SuiSpokeService, SupportedMigrationTokens, SwapService, SwapsApiService, TOKEN_LOGO_BASE_URL, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, adjustAmountByFee, allowanceCheckFailed, apiConfig, approveFailed, arbitrumSupportedTokens, assetManagerAbi, avalancheSupportedTokens, balnSwapAbi, baseChainInfo, baseSupportedTokens, binomialApproximatedRayPow, bitcoinSupportedTokens, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bridgeConfig, bridgeInvariant, bscSupportedTokens, calcOpReturnOutputVbytes, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, canonicalizeBitcoinAddress, clPoolAbi, clPoolManagerAbi, clPositionManagerAbi, clQuoterAbi, clRouterAbi, clTickLensAbi, classifySponsorError, concentratedLiquidityConfig, connectionAbi, consoleLogger, convertTransactionInstructionToRaw, createBalanceCollector, createInvariant, deepMerge, defaultHookAbi, detectBitcoinAddressType, dexConfig, dexInvariant, dexPools, encodeAddress, encodeBtcPayloadToBytes, encodeContractCalls, encodeTokenIdentifier, erc20Abi, erc4626Abi, estimateBitcoinTxSize, estimateSwapSpeedTier, ethereumSupportedTokens, executionFailed, formatBasisPoints, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, gasEstimationFailed, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getAssetManagerIdl, getAssetManagerProgram, getChainKeyFromRelayChainId, getChainType, getCompoundedBalance, getConcentratedLiquidityConfig, getConnectionIdl, getConnectionProgram, getEvmChainKeyByChainId, getEvmViemChain, getIconAddressBytes, getIntentRelayChainId, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getPacket, getProvider, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getSolverConfig, getSpokeHook, getSpokeHooks, getStagingSolverTokens, getSupportedSolverTokens, getTransactionPackets, getbnUSDToken, hederaSupportedTokens, hexToBigInt, hexToSolanaAddress, hubConfig, hyper, hyperevmSupportedTokens, iconSupportedTokens, injectiveSupportedTokens, intentCreationFailed, isApprovalSupportedChainKeyType, isAuthFailure, isAuthStatus, isBackendHttpError, isBalnMigrateParams, isBitcoinChainKey, isBitcoinChainKeyType, isBitcoinWalletProviderType, isBridgeAllowanceCheckError, isBridgeApproveError, isBridgeCreateIntentError, isBridgeError, isBridgeLookupError, isBridgeOrchestrationError, isCodeMember, isDexApproveError, isDexCreateIntentError, isDexError, isEvmChainKey, isEvmChainKeyType, isEvmSpokeChainConfig, isEvmSpokeOnlyChainKey, isEvmSpokeOnlyChainKeyType, isEvmWalletProviderType, isFeatureError, isFillEvent, isHookSupportedToken, isHubChainKey, isHubChainKeyType, isIconAddress, isIconChainKey, isIconChainKeyType, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveChainKey, isInjectiveChainKeyType, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isLeverageYieldAllowanceCheckError, isLeverageYieldApproveError, isLeverageYieldCreateIntentError, isLeverageYieldError, isLeverageYieldLookupError, isLeverageYieldPostExecutionError, isLeverageYieldSwapError, isMigrateOrchestrationError, isMigrationAllowanceCheckError, isMigrationApproveError, isMigrationCreateIntentError, isMigrationError, isMigrationLookupError, isMoneyMarketAllowanceCheckError, isMoneyMarketApproveError, isMoneyMarketCreateIntentError, isMoneyMarketError, isMoneyMarketGasEstimationError, isMoneyMarketOrchestrationError, isNativeBitcoinToken, isNativeBitcoinTransfer, isNativeToken, isNearChainKey, isNearChainKeyType, isNewbnUSDChainId, isNewbnUSDToken, isOptionalBitcoinWalletProviderType, isOptionalEvmWalletProviderType, isOptionalStellarWalletProviderType, isOracleCandleInterval, isPartnerError, isPartnerFeeAmount, isPartnerFeePercentage, isPostExecutionError, isRawDestinationParams, isRealWorldAsset, isRecoveryError, isResponseAddressType, isResponseSigningType, isRevertMigrationOrchestrationError, isSodaxError, isSolanaChainKey, isSolanaChainKeyType, isSolanaNativeToken, isSonicChainKey, isSonicChainKeyType, isSpokeApproveParamsEvmSpoke, isSpokeApproveParamsHub, isSpokeApproveParamsStellar, isSpokeChainKey, isSpokeIsAllowanceValidParamsEvmSpoke, isSpokeIsAllowanceValidParamsHub, isSpokeIsAllowanceValidParamsStellar, isSponsoringConfigError, isSponsoringLookupError, isSponsoringOrchestrationError, isStacksChainKey, isStacksChainKeyType, isStakeOrchestrationError, isStakingAllowanceCheckError, isStakingApproveError, isStakingCreateIntentError, isStakingError, isStakingInfoFetchError, isStakingOrchestrationError, isStellarChainKey, isStellarChainKeyType, isStellarWalletProviderType, isSuiChainKey, isSuiChainKeyType, isSupportedBitcoinAddressType, isSwapCreateIntentError, isSwapError, isSwapSupportedToken, isUndefinedOrValidWalletProviderForChainKey, isUnifiedBnUSDMigrateParams, isValidBitcoinAddress, isValidInjectiveAddress, isValidNearAccountId, isValidWalletProviderForChainKey, kaiaSupportedTokens, leverageYieldConfig, leverageYieldInvariant, leverageYieldVaults, lightlinkSupportedTokens, lookupFailed, mapRelayFailure, mergeSodaxConfig, messageOf, migrationInvariant, mintPositionParamsAbi, mmInvariant, modifyLiquidityParamsAbi, moneyMarketConfig, moneyMarketReserveAssets, moneyMarketSupportedTokens, nativeToUSD, nearSupportedTokens, newbnUSDSpokeChainIds, noopAnalytics, normalize, normalizeBN, normalizePsbtToBase64, normalizeSignatureToBase64, normalizedToUsd, optimismSupportedTokens, pancakeSwapInfinityDefaultHookAbi, pancakeSwapInfinityPoolManagerAbi, pancakeSwapInfinityPositionManagerAbi, parseToStroops, parseTokenArrayFromJson, partnerInvariant, permit2Abi, polygonSupportedTokens, poolAbi, poolKeyAbi, randomUint256, rayDiv, rayMul, rayPow, rayToWad, recoveryInvariant, redbellySupportedTokens, relayConfig, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, resolveAnalytics, resolveLogger, retry, reverseEncodeAddress, robinhoodChain, robinhoodSupportedTokens, serializeAddressData, settleWalletBalances, silentLogger, sleep, sodaxConfig, sodaxInvariant, solanaSupportedTokens, solverConfig, sonicSupportedTokens, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainKeysSet, spokeHooks, sponsoringInvariant, stacksSupportedTokens, stagingSwapSupportedTokens, stakedSodaAbi, stakingInvariant, stakingRouterAbi, stataTokenFactoryAbi, stellarSupportedTokens, submitTransaction, suiSupportedTokens, supportedSpokeChains, supportedTokensByChain, swapExactInSingleParamsAbi, swapInvariant, swapSupportedTokens, swapsConfig, toCreateBridgeIntentParamsV2, toSuiExecutionResult, toSuiExecutionStatus, toSuiPaginatedCoins, tokenLogo, tokenLogoSlug, uiPoolDataAbi, universalRouterAbi, unknownFailed, usesBip322MessageSigning, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, verifyFailed, wadToRay, waitForStacksTransaction, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|
|
47694
|
+
export { ALLOWANCE_CHECK_CODES, APPROVE_CODES, AssetService, BACKEND_API_BASE_PATH, BITCOIN_CHAIN_KEYS, BITCOIN_CHAIN_KEYS_SET, BITCOIN_DUST_SATS, BOUND_API_HOST, BOUND_COMPANION_HOSTS, BTC_WALLET_ADDRESS_TYPES, BackendApiService, BackendHttpError, BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BitcoinSpokeService, BnUSDMigrationService, BridgeApiService, BridgeService, CHAIN_KEYS, CHAIN_LOGO_BASE_URL, CONFIG_VERSION, CREATE_INTENT_CODES, ChainKeys, ChainTypeArr, ClService, ConfigService, CustomSorobanServer, CustomStellarAccount, DEFAULT_API_BASE_URL, DEFAULT_BACKEND_API_ENDPOINT, DEFAULT_BACKEND_API_HEADERS, DEFAULT_BACKEND_API_TIMEOUT, DEFAULT_DEADLINE_OFFSET, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, DEFAULT_SPONSORING_API_ENDPOINT, DEPRECATED_BOUND_HOSTS, DETAILED_STATUS_NOT_DELIVERED, DexService, EVM_CHAIN_ID_TO_KEY, EVM_CHAIN_KEYS, EVM_CHAIN_KEYS_SET, EVM_SPOKE_ONLY_CHAIN_KEYS, EVM_SPOKE_ONLY_CHAIN_KEYS_SET, Erc20Service, Erc4626Service, EvmAssetManagerService, EvmHubProvider, EvmSolverService, EvmSpokeService, EvmVaultTokenService, FEE_PERCENTAGE_SCALE, GAS_ESTIMATION_CODES, HALF_RAY, HALF_WAD, HUB_CHAIN_KEY, HookKind, HookService, HttpRelayError, HubVaultSymbols, ICON_CHAIN_KEYS, ICON_CHAIN_KEYS_SET, ICON_TX_RESULT_WAIT_MAX_RETRY, INJECTIVE_CHAIN_KEYS, INJECTIVE_CHAIN_KEYS_SET, INTENT_CHAIN_IDS, IconSpokeService, IcxMigrationService, Injective20Token, InjectiveSpokeService, IntentCreatedEventAbi, IntentDataService, IntentDataType, IntentFilledEventAbi, IntentRelayChainIdToChainKey, IntentsAbi, LOOKUP_CODES, LTV_PRECISION, LendingPoolService, LeverageYieldApiService, LeverageYieldService, LockupMultiplier, LockupPeriod, LsodaSymbols, LsodaTokens, MAX_POSITION_FEE_BPS, MAX_UINT256, MigrationService, MintPositionEventAbi, MoneyMarketDataService, MoneyMarketService, NEAR_CHAIN_KEYS, NEAR_CHAIN_KEYS_SET, NEAR_DEFAULT_GAS, NEAR_STORAGE_DEPOSIT, NearSpokeService, ORACLE_CANDLE_INTERVALS, PartnerFeeClaimService, PartnerService, Permit2Service, ProtocolIntentsAbi, RAY, RAY_DECIMALS, RELAY_ERROR_CODES, RELAY_FALLBACK_FLOOR_MS, RELAY_REQUEST_TIMEOUT_MS, RadfiApiError, RadfiProvider, RecoveryService, RelayChainIdMap, SDK_VERSION, SECONDS_PER_YEAR, SODAX_ERROR_CODES, SODAX_FEATURES, SOLANA_CHAIN_KEYS, SOLANA_CHAIN_KEYS_SET, SONIC_CHAIN_KEYS, SONIC_CHAIN_KEYS_SET, SPEED_TIER_SECONDS, SPEED_TIER_THRESHOLDS, SPONSORING_API_ERROR_CODES, SPONSORING_API_STELLAR_BASE_PATH, SPONSOR_CONFIG_TTL_MS, STACKS_CHAIN_KEYS, STACKS_CHAIN_KEYS_SET, STELLAR_BASE_RESERVE_TTL_MS, STELLAR_CHAIN_KEYS, STELLAR_CHAIN_KEYS_SET, STELLAR_TRUSTLINE_MIN_XLM_STROOPS, SUI_CHAIN_KEYS, SUI_CHAIN_KEYS_SET, SodaTokens, Sodax, SodaxError, SolanaSpokeService, SolverApiService, SolverIntentErrorCode, SolverIntentStatusCode, SonicSpokeService, SpokeService, SponsoringApiService, SponsoringService, StacksSpokeService, StakingLogic, StakingService, StatATokenAddresses, StellarSpokeService, SuiGrpcTransport, SuiSpokeService, SupportedMigrationTokens, SwapService, SwapsApiService, TOKEN_LOGO_BASE_URL, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, adjustAmountByFee, allowanceCheckFailed, apiConfig, approveFailed, arbitrumSupportedTokens, assetManagerAbi, avalancheSupportedTokens, balnSwapAbi, baseChainInfo, baseSupportedTokens, binomialApproximatedRayPow, bitcoinSupportedTokens, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bridgeConfig, bridgeInvariant, bscSupportedTokens, calcOpReturnOutputVbytes, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, canonicalizeBitcoinAddress, clPoolAbi, clPoolManagerAbi, clPositionManagerAbi, clQuoterAbi, clRouterAbi, clTickLensAbi, classifySponsorError, concentratedLiquidityConfig, configVersionFor, connectionAbi, consoleLogger, convertTransactionInstructionToRaw, createBalanceCollector, createInvariant, deepMerge, defaultHookAbi, detectBitcoinAddressType, dexConfig, dexInvariant, dexPools, encodeAddress, encodeBtcPayloadToBytes, encodeContractCalls, encodeTokenIdentifier, erc20Abi, erc4626Abi, estimateBitcoinTxSize, estimateSwapSpeedTier, ethereumSupportedTokens, executionFailed, formatBasisPoints, formatConfigVersion, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, gasEstimationFailed, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getAssetManagerIdl, getAssetManagerProgram, getChainKeyFromRelayChainId, getChainType, getCompoundedBalance, getConcentratedLiquidityConfig, getConnectionIdl, getConnectionProgram, getEvmChainKeyByChainId, getEvmViemChain, getIconAddressBytes, getIntentRelayChainId, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getPacket, getProvider, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getSolverConfig, getSpokeHook, getSpokeHooks, getStagingSolverTokens, getSupportedSolverTokens, getTransactionPackets, getbnUSDToken, hederaSupportedTokens, hexToBigInt, hexToSolanaAddress, hubConfig, hyper, hyperevmSupportedTokens, iconSupportedTokens, injectiveSupportedTokens, intentCreationFailed, isApprovalSupportedChainKeyType, isAuthFailure, isAuthStatus, isBackendHttpError, isBalnMigrateParams, isBitcoinChainKey, isBitcoinChainKeyType, isBitcoinWalletProviderType, isBridgeAllowanceCheckError, isBridgeApproveError, isBridgeCreateIntentError, isBridgeError, isBridgeLookupError, isBridgeOrchestrationError, isCodeMember, isDexApproveError, isDexCreateIntentError, isDexError, isEvmChainKey, isEvmChainKeyType, isEvmSpokeChainConfig, isEvmSpokeOnlyChainKey, isEvmSpokeOnlyChainKeyType, isEvmWalletProviderType, isFeatureError, isFillEvent, isHookSupportedToken, isHubChainKey, isHubChainKeyType, isIconAddress, isIconChainKey, isIconChainKeyType, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveChainKey, isInjectiveChainKeyType, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isLeverageYieldAllowanceCheckError, isLeverageYieldApproveError, isLeverageYieldCreateIntentError, isLeverageYieldError, isLeverageYieldLookupError, isLeverageYieldPostExecutionError, isLeverageYieldSwapError, isMigrateOrchestrationError, isMigrationAllowanceCheckError, isMigrationApproveError, isMigrationCreateIntentError, isMigrationError, isMigrationLookupError, isMoneyMarketAllowanceCheckError, isMoneyMarketApproveError, isMoneyMarketCreateIntentError, isMoneyMarketError, isMoneyMarketGasEstimationError, isMoneyMarketOrchestrationError, isNativeBitcoinToken, isNativeBitcoinTransfer, isNativeToken, isNearChainKey, isNearChainKeyType, isNewbnUSDChainId, isNewbnUSDToken, isNoRouteRefusal, isOptionalBitcoinWalletProviderType, isOptionalEvmWalletProviderType, isOptionalStellarWalletProviderType, isOracleCandleInterval, isPartnerError, isPartnerFeeAmount, isPartnerFeePercentage, isPostExecutionError, isRawDestinationParams, isRealWorldAsset, isRecoveryError, isResponseAddressType, isResponseSigningType, isRevertMigrationOrchestrationError, isSodaxError, isSolanaChainKey, isSolanaChainKeyType, isSolanaNativeToken, isSonicChainKey, isSonicChainKeyType, isSpokeApproveParamsEvmSpoke, isSpokeApproveParamsHub, isSpokeApproveParamsStellar, isSpokeChainKey, isSpokeIsAllowanceValidParamsEvmSpoke, isSpokeIsAllowanceValidParamsHub, isSpokeIsAllowanceValidParamsStellar, isSponsoringConfigError, isSponsoringLookupError, isSponsoringOrchestrationError, isStacksChainKey, isStacksChainKeyType, isStakeOrchestrationError, isStakingAllowanceCheckError, isStakingApproveError, isStakingCreateIntentError, isStakingError, isStakingInfoFetchError, isStakingOrchestrationError, isStellarChainKey, isStellarChainKeyType, isStellarWalletProviderType, isSuiChainKey, isSuiChainKeyType, isSupportedBitcoinAddressType, isSwapCreateIntentError, isSwapError, isSwapSupportedToken, isUndefinedOrValidWalletProviderForChainKey, isUnifiedBnUSDMigrateParams, isValidBitcoinAddress, isValidInjectiveAddress, isValidNearAccountId, isValidWalletProviderForChainKey, kaiaSupportedTokens, leverageYieldConfig, leverageYieldInvariant, leverageYieldVaults, leveragedNetApyPct, lightlinkSupportedTokens, lookupFailed, mapRelayFailure, mergeSodaxConfig, messageOf, migrationInvariant, mintPositionParamsAbi, mmInvariant, modifyLiquidityParamsAbi, moneyMarketConfig, moneyMarketReserveAssets, moneyMarketSupportedTokens, nativeToUSD, nearSupportedTokens, newbnUSDSpokeChainIds, noopAnalytics, normalize, normalizeBN, normalizePsbtToBase64, normalizeSignatureToBase64, normalizedToUsd, optimismSupportedTokens, pancakeSwapInfinityDefaultHookAbi, pancakeSwapInfinityPoolManagerAbi, pancakeSwapInfinityPositionManagerAbi, parseConfigVersion, parseToStroops, parseTokenArrayFromJson, partnerInvariant, permit2Abi, polygonSupportedTokens, poolAbi, poolKeyAbi, projectLeverageLeg, randomUint256, rayDiv, rayMul, rayPow, rayToWad, recoveryInvariant, redbellySupportedTokens, relayConfig, relayTxAndWaitPacket, reportPositionIntent, requestAddress, requestJsonRpc, requestSigning, resolveAnalytics, resolveLogger, resolvePositionFundingAddress, retry, reverseEncodeAddress, robinhoodChain, robinhoodSupportedTokens, serializeAddressData, settleWalletBalances, silentLogger, sizeLeverageBorrow, sleep, sodaxConfig, sodaxInvariant, solanaSupportedTokens, solverConfig, sonicSupportedTokens, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainKeysSet, spokeHooks, sponsoringInvariant, stacksSupportedTokens, stagingSwapSupportedTokens, stakedSodaAbi, stakingInvariant, stakingRouterAbi, stataTokenFactoryAbi, stellarSupportedTokens, submitTransaction, suiSupportedTokens, supportedSpokeChains, supportedTokensByChain, swapExactInSingleParamsAbi, swapInvariant, swapSupportedTokens, swapsConfig, timeToBreakevenYears, toCreateBridgeIntentParamsV2, toSuiExecutionResult, toSuiExecutionStatus, toSuiPaginatedCoins, tokenLogo, tokenLogoSlug, uiPoolDataAbi, universalRouterAbi, unknownFailed, usesBip322MessageSigning, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, verifyFailed, wadToRay, waitForStacksTransaction, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|