@sodax/dapp-kit 0.0.1-rc.3 → 0.0.1-rc.30
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/LICENSE +21 -0
- package/README.md +152 -53
- package/dist/index.d.mts +1425 -0
- package/dist/index.d.ts +1425 -4
- package/dist/index.js +931 -194
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +890 -191
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -8
- package/src/contexts/index.ts +2 -0
- package/src/core/index.ts +5 -33
- package/src/hooks/backend/README.md +135 -0
- package/src/hooks/backend/index.ts +23 -0
- package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +49 -0
- package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +61 -0
- package/src/hooks/backend/useBackendIntentByHash.ts +53 -0
- package/src/hooks/backend/useBackendIntentByTxHash.ts +52 -0
- package/src/hooks/backend/useBackendMoneyMarketAsset.ts +57 -0
- package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +67 -0
- package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +67 -0
- package/src/hooks/backend/useBackendMoneyMarketPosition.ts +56 -0
- package/src/hooks/backend/useBackendOrderbook.ts +63 -0
- package/src/hooks/bridge/index.ts +5 -0
- package/src/hooks/bridge/useBridge.ts +57 -0
- package/src/hooks/bridge/useBridgeAllowance.ts +49 -0
- package/src/hooks/bridge/useBridgeApprove.ts +68 -0
- package/src/hooks/bridge/useGetBridgeableAmount.ts +50 -0
- package/src/hooks/bridge/useGetBridgeableTokens.ts +62 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/mm/index.ts +3 -1
- package/src/hooks/mm/useBorrow.ts +20 -10
- package/src/hooks/mm/useMMAllowance.ts +55 -0
- package/src/hooks/mm/useMMApprove.ts +67 -0
- package/src/hooks/mm/useRepay.ts +20 -10
- package/src/hooks/mm/useReservesData.ts +30 -0
- package/src/hooks/mm/useReservesHumanized.ts +30 -0
- package/src/hooks/mm/useReservesList.ts +29 -0
- package/src/hooks/mm/useReservesUsdFormat.ts +38 -0
- package/src/hooks/mm/useSupply.ts +9 -6
- package/src/hooks/mm/useUserFormattedSummary.ts +54 -0
- package/src/hooks/mm/useUserReservesData.ts +30 -48
- package/src/hooks/mm/useWithdraw.ts +17 -11
- package/src/hooks/provider/useHubProvider.ts +3 -21
- package/src/hooks/provider/useSpokeProvider.ts +97 -6
- package/src/hooks/shared/index.ts +4 -2
- package/src/hooks/shared/useDeriveUserWalletAddress.ts +44 -0
- package/src/hooks/shared/useEstimateGas.ts +18 -0
- package/src/hooks/shared/useRequestTrustline.ts +82 -0
- package/src/hooks/shared/useStellarTrustlineCheck.ts +71 -0
- package/src/hooks/staking/index.ts +19 -0
- package/src/hooks/staking/useCancelUnstake.ts +52 -0
- package/src/hooks/staking/useClaim.ts +46 -0
- package/src/hooks/staking/useConvertedAssets.ts +47 -0
- package/src/hooks/staking/useInstantUnstake.ts +50 -0
- package/src/hooks/staking/useInstantUnstakeAllowance.ts +59 -0
- package/src/hooks/staking/useInstantUnstakeApprove.ts +52 -0
- package/src/hooks/staking/useInstantUnstakeRatio.ts +54 -0
- package/src/hooks/staking/useStake.ts +47 -0
- package/src/hooks/staking/useStakeAllowance.ts +57 -0
- package/src/hooks/staking/useStakeApprove.ts +50 -0
- package/src/hooks/staking/useStakeRatio.ts +53 -0
- package/src/hooks/staking/useStakingConfig.ts +40 -0
- package/src/hooks/staking/useStakingInfo.ts +50 -0
- package/src/hooks/staking/useUnstake.ts +54 -0
- package/src/hooks/staking/useUnstakeAllowance.ts +58 -0
- package/src/hooks/staking/useUnstakeApprove.ts +52 -0
- package/src/hooks/staking/useUnstakingInfo.ts +53 -0
- package/src/hooks/staking/useUnstakingInfoWithPenalty.ts +59 -0
- package/src/hooks/swap/index.ts +4 -1
- package/src/hooks/swap/useCancelSwap.ts +44 -0
- package/src/hooks/swap/useQuote.ts +20 -6
- package/src/hooks/swap/useStatus.ts +3 -3
- package/src/hooks/swap/{useCreateIntentOrder.ts → useSwap.ts} +22 -19
- package/src/hooks/swap/useSwapAllowance.ts +48 -0
- package/src/hooks/swap/useSwapApprove.ts +68 -0
- package/src/providers/SodaxProvider.tsx +7 -4
- package/dist/contexts/index.d.ts +0 -7
- package/dist/contexts/index.d.ts.map +0 -1
- package/dist/core/index.d.ts +0 -4
- package/dist/core/index.d.ts.map +0 -1
- package/dist/hooks/index.d.ts +0 -5
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/mm/index.d.ts +0 -7
- package/dist/hooks/mm/index.d.ts.map +0 -1
- package/dist/hooks/mm/useBorrow.d.ts +0 -26
- package/dist/hooks/mm/useBorrow.d.ts.map +0 -1
- package/dist/hooks/mm/useHubWalletAddress.d.ts +0 -24
- package/dist/hooks/mm/useHubWalletAddress.d.ts.map +0 -1
- package/dist/hooks/mm/useRepay.d.ts +0 -26
- package/dist/hooks/mm/useRepay.d.ts.map +0 -1
- package/dist/hooks/mm/useSupply.d.ts +0 -32
- package/dist/hooks/mm/useSupply.d.ts.map +0 -1
- package/dist/hooks/mm/useUserReservesData.d.ts +0 -9
- package/dist/hooks/mm/useUserReservesData.d.ts.map +0 -1
- package/dist/hooks/mm/useWithdraw.d.ts +0 -26
- package/dist/hooks/mm/useWithdraw.d.ts.map +0 -1
- package/dist/hooks/provider/index.d.ts +0 -3
- package/dist/hooks/provider/index.d.ts.map +0 -1
- package/dist/hooks/provider/useHubProvider.d.ts +0 -3
- package/dist/hooks/provider/useHubProvider.d.ts.map +0 -1
- package/dist/hooks/provider/useSpokeProvider.d.ts +0 -4
- package/dist/hooks/provider/useSpokeProvider.d.ts.map +0 -1
- package/dist/hooks/shared/index.d.ts +0 -4
- package/dist/hooks/shared/index.d.ts.map +0 -1
- package/dist/hooks/shared/useAllowance.d.ts +0 -3
- package/dist/hooks/shared/useAllowance.d.ts.map +0 -1
- package/dist/hooks/shared/useApprove.d.ts +0 -10
- package/dist/hooks/shared/useApprove.d.ts.map +0 -1
- package/dist/hooks/shared/useSodaxContext.d.ts +0 -8
- package/dist/hooks/shared/useSodaxContext.d.ts.map +0 -1
- package/dist/hooks/swap/index.d.ts +0 -4
- package/dist/hooks/swap/index.d.ts.map +0 -1
- package/dist/hooks/swap/useCreateIntentOrder.d.ts +0 -33
- package/dist/hooks/swap/useCreateIntentOrder.d.ts.map +0 -1
- package/dist/hooks/swap/useQuote.d.ts +0 -39
- package/dist/hooks/swap/useQuote.d.ts.map +0 -1
- package/dist/hooks/swap/useStatus.d.ts +0 -31
- package/dist/hooks/swap/useStatus.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/providers/SodaxProvider.d.ts +0 -10
- package/dist/providers/SodaxProvider.d.ts.map +0 -1
- package/dist/providers/index.d.ts +0 -2
- package/dist/providers/index.d.ts.map +0 -1
- package/src/hooks/mm/useHubWalletAddress.ts +0 -49
- package/src/hooks/shared/useAllowance.ts +0 -31
- package/src/hooks/shared/useApprove.ts +0 -53
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { createContext, useContext, useMemo } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { getXChainType, useWalletProvider, useXAccount } from '@sodax/wallet-sdk';
|
|
2
|
+
import { SpokeService, deriveUserWalletAddress, STELLAR_MAINNET_CHAIN_ID, StellarSpokeProvider, StellarSpokeService, spokeChainConfig, SONIC_MAINNET_CHAIN_ID, SonicSpokeProvider, EvmSpokeProvider, SuiSpokeProvider, IconSpokeProvider, InjectiveSpokeProvider, SolanaSpokeProvider, Sodax, hubAssets } from '@sodax/sdk';
|
|
3
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
5
4
|
import { parseUnits } from 'viem';
|
|
6
5
|
|
|
7
6
|
// src/contexts/index.ts
|
|
@@ -13,117 +12,154 @@ var useSodaxContext = () => {
|
|
|
13
12
|
}
|
|
14
13
|
return context;
|
|
15
14
|
};
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
spokeChainConfig[spokeChainId]
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
if (xChainType === "SUI") {
|
|
28
|
-
return new SuiSpokeProvider(
|
|
29
|
-
spokeChainConfig[spokeChainId],
|
|
30
|
-
walletProvider
|
|
31
|
-
);
|
|
15
|
+
function useEstimateGas(spokeProvider) {
|
|
16
|
+
return useMutation({
|
|
17
|
+
mutationFn: async (rawTx) => {
|
|
18
|
+
if (!spokeProvider) {
|
|
19
|
+
throw new Error("spokeProvider is not found");
|
|
20
|
+
}
|
|
21
|
+
const response = await SpokeService.estimateGas(rawTx, spokeProvider);
|
|
22
|
+
return response;
|
|
32
23
|
}
|
|
33
|
-
|
|
34
|
-
}, [walletProvider, xChainType, spokeChainId]);
|
|
35
|
-
return spokeProvider;
|
|
24
|
+
});
|
|
36
25
|
}
|
|
37
|
-
function
|
|
26
|
+
function useDeriveUserWalletAddress(spokeProvider, walletAddress) {
|
|
38
27
|
const { sodax } = useSodaxContext();
|
|
39
|
-
const spokeProvider = useSpokeProvider(token.xChainId);
|
|
40
28
|
return useQuery({
|
|
41
|
-
queryKey: ["
|
|
29
|
+
queryKey: ["deriveUserWalletAddress", spokeProvider?.chainConfig.chain.id, walletAddress],
|
|
42
30
|
queryFn: async () => {
|
|
43
31
|
if (!spokeProvider) {
|
|
44
|
-
|
|
32
|
+
throw new Error("Spoke provider is required");
|
|
45
33
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
34
|
+
return await deriveUserWalletAddress(spokeProvider, sodax.hubProvider, walletAddress);
|
|
35
|
+
},
|
|
36
|
+
enabled: !!spokeProvider,
|
|
37
|
+
refetchInterval: false
|
|
38
|
+
// This is a deterministic operation, no need to refetch
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function useStellarTrustlineCheck(token, amount, spokeProvider, chainId) {
|
|
42
|
+
return useQuery({
|
|
43
|
+
queryKey: ["stellar-trustline-check", token],
|
|
44
|
+
queryFn: async () => {
|
|
45
|
+
if (chainId !== STELLAR_MAINNET_CHAIN_ID) {
|
|
46
|
+
return true;
|
|
55
47
|
}
|
|
56
|
-
|
|
48
|
+
if (!spokeProvider || !token || !amount || !(spokeProvider instanceof StellarSpokeProvider)) {
|
|
49
|
+
console.error(
|
|
50
|
+
"Spoke provider, token or amount not found. Details: spokeProvider:",
|
|
51
|
+
spokeProvider,
|
|
52
|
+
"token:",
|
|
53
|
+
token,
|
|
54
|
+
"amount:",
|
|
55
|
+
amount
|
|
56
|
+
);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const response = await StellarSpokeService.hasSufficientTrustline(token, amount, spokeProvider);
|
|
60
|
+
return response;
|
|
57
61
|
},
|
|
58
|
-
enabled: !!spokeProvider
|
|
62
|
+
enabled: !!spokeProvider && !!token && !!amount
|
|
59
63
|
});
|
|
60
64
|
}
|
|
61
|
-
function
|
|
62
|
-
const { sodax } = useSodaxContext();
|
|
63
|
-
const spokeProvider = useSpokeProvider(token.xChainId);
|
|
65
|
+
function useRequestTrustline(token) {
|
|
64
66
|
const queryClient = useQueryClient();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
throw new Error("Spoke provider not found");
|
|
74
|
-
}
|
|
75
|
-
const allowance = await sodax.moneyMarket.approve(
|
|
76
|
-
token.address,
|
|
77
|
-
parseUnits(amount, token.decimals),
|
|
78
|
-
spokeProvider.chainConfig.addresses.assetManager,
|
|
79
|
-
spokeProvider
|
|
80
|
-
);
|
|
81
|
-
if (!allowance.ok) {
|
|
82
|
-
throw new Error("Failed to approve tokens");
|
|
67
|
+
return useMutation({
|
|
68
|
+
mutationFn: async ({
|
|
69
|
+
token: token2,
|
|
70
|
+
amount,
|
|
71
|
+
spokeProvider
|
|
72
|
+
}) => {
|
|
73
|
+
if (!spokeProvider || !token2 || !amount || !(spokeProvider instanceof StellarSpokeProvider)) {
|
|
74
|
+
throw new Error("Spoke provider, token or amount not found");
|
|
83
75
|
}
|
|
84
|
-
return
|
|
76
|
+
return StellarSpokeService.requestTrustline(token2, amount, spokeProvider);
|
|
85
77
|
},
|
|
86
78
|
onSuccess: () => {
|
|
87
|
-
queryClient.invalidateQueries({ queryKey: ["
|
|
79
|
+
queryClient.invalidateQueries({ queryKey: ["stellar-trustline-check", token] });
|
|
88
80
|
}
|
|
89
81
|
});
|
|
90
|
-
return {
|
|
91
|
-
approve,
|
|
92
|
-
isLoading: isPending,
|
|
93
|
-
error,
|
|
94
|
-
resetError
|
|
95
|
-
};
|
|
96
82
|
}
|
|
83
|
+
|
|
84
|
+
// src/hooks/provider/useHubProvider.ts
|
|
97
85
|
function useHubProvider() {
|
|
98
86
|
const { sodax } = useSodaxContext();
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
87
|
+
return sodax.hubProvider;
|
|
88
|
+
}
|
|
89
|
+
function useSpokeProvider(spokeChainId, walletProvider) {
|
|
90
|
+
const { rpcConfig } = useSodaxContext();
|
|
91
|
+
const xChainType = spokeChainId ? spokeChainConfig[spokeChainId]?.chain.type : void 0;
|
|
92
|
+
const spokeProvider = useMemo(() => {
|
|
93
|
+
if (!walletProvider) return void 0;
|
|
94
|
+
if (!spokeChainId) return void 0;
|
|
95
|
+
if (!xChainType) return void 0;
|
|
96
|
+
if (!rpcConfig) return void 0;
|
|
97
|
+
if (xChainType === "EVM") {
|
|
98
|
+
if (spokeChainId === SONIC_MAINNET_CHAIN_ID) {
|
|
99
|
+
return new SonicSpokeProvider(
|
|
100
|
+
walletProvider,
|
|
101
|
+
spokeChainConfig[spokeChainId]
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return new EvmSpokeProvider(
|
|
105
|
+
walletProvider,
|
|
106
|
+
spokeChainConfig[spokeChainId]
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (xChainType === "SUI") {
|
|
110
|
+
return new SuiSpokeProvider(
|
|
111
|
+
spokeChainConfig[spokeChainId],
|
|
112
|
+
walletProvider
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
if (xChainType === "ICON") {
|
|
116
|
+
return new IconSpokeProvider(
|
|
117
|
+
walletProvider,
|
|
118
|
+
spokeChainConfig[spokeChainId]
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (xChainType === "INJECTIVE") {
|
|
122
|
+
return new InjectiveSpokeProvider(
|
|
123
|
+
spokeChainConfig[spokeChainId],
|
|
124
|
+
walletProvider
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
if (xChainType === "STELLAR") {
|
|
128
|
+
const stellarConfig = spokeChainConfig[spokeChainId];
|
|
129
|
+
return new StellarSpokeProvider(
|
|
130
|
+
walletProvider,
|
|
131
|
+
stellarConfig,
|
|
132
|
+
rpcConfig.stellar ? rpcConfig.stellar : {
|
|
133
|
+
horizonRpcUrl: stellarConfig.horizonRpcUrl,
|
|
134
|
+
sorobanRpcUrl: stellarConfig.sorobanRpcUrl
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
if (xChainType === "SOLANA") {
|
|
139
|
+
return new SolanaSpokeProvider(
|
|
140
|
+
walletProvider,
|
|
141
|
+
rpcConfig.solana ? {
|
|
142
|
+
...spokeChainConfig[spokeChainId],
|
|
143
|
+
rpcUrl: rpcConfig.solana
|
|
144
|
+
} : spokeChainConfig[spokeChainId]
|
|
145
|
+
);
|
|
110
146
|
}
|
|
111
147
|
return void 0;
|
|
112
|
-
}, [xChainType,
|
|
113
|
-
return
|
|
148
|
+
}, [spokeChainId, xChainType, walletProvider, rpcConfig]);
|
|
149
|
+
return spokeProvider;
|
|
114
150
|
}
|
|
115
|
-
function useBorrow(
|
|
151
|
+
function useBorrow(spokeToken, spokeProvider) {
|
|
116
152
|
const { sodax } = useSodaxContext();
|
|
117
|
-
const spokeProvider = useSpokeProvider(spokeChainId);
|
|
118
153
|
return useMutation({
|
|
119
154
|
mutationFn: async (amount) => {
|
|
120
155
|
if (!spokeProvider) {
|
|
121
156
|
throw new Error("spokeProvider is not found");
|
|
122
157
|
}
|
|
123
|
-
const response = await sodax.moneyMarket.
|
|
158
|
+
const response = await sodax.moneyMarket.borrow(
|
|
124
159
|
{
|
|
125
|
-
token:
|
|
126
|
-
amount: parseUnits(amount,
|
|
160
|
+
token: spokeToken.address,
|
|
161
|
+
amount: parseUnits(amount, 18),
|
|
162
|
+
action: "borrow"
|
|
127
163
|
},
|
|
128
164
|
spokeProvider
|
|
129
165
|
);
|
|
@@ -135,18 +171,18 @@ function useBorrow(hubToken, spokeChainId) {
|
|
|
135
171
|
}
|
|
136
172
|
});
|
|
137
173
|
}
|
|
138
|
-
function useRepay(
|
|
174
|
+
function useRepay(spokeToken, spokeProvider) {
|
|
139
175
|
const { sodax } = useSodaxContext();
|
|
140
|
-
const spokeProvider = useSpokeProvider(spokeChainId);
|
|
141
176
|
return useMutation({
|
|
142
177
|
mutationFn: async (amount) => {
|
|
143
178
|
if (!spokeProvider) {
|
|
144
179
|
throw new Error("spokeProvider is not found");
|
|
145
180
|
}
|
|
146
|
-
const response = await sodax.moneyMarket.
|
|
181
|
+
const response = await sodax.moneyMarket.repay(
|
|
147
182
|
{
|
|
148
|
-
token:
|
|
149
|
-
amount: parseUnits(amount,
|
|
183
|
+
token: spokeToken.address,
|
|
184
|
+
amount: parseUnits(amount, spokeToken.decimals),
|
|
185
|
+
action: "repay"
|
|
150
186
|
},
|
|
151
187
|
spokeProvider
|
|
152
188
|
);
|
|
@@ -158,18 +194,18 @@ function useRepay(hubToken, spokeChainId) {
|
|
|
158
194
|
}
|
|
159
195
|
});
|
|
160
196
|
}
|
|
161
|
-
function useSupply(spokeToken) {
|
|
197
|
+
function useSupply(spokeToken, spokeProvider) {
|
|
162
198
|
const { sodax } = useSodaxContext();
|
|
163
|
-
const spokeProvider = useSpokeProvider(spokeToken.xChainId);
|
|
164
199
|
return useMutation({
|
|
165
200
|
mutationFn: async (amount) => {
|
|
166
201
|
if (!spokeProvider) {
|
|
167
202
|
throw new Error("spokeProvider is not found");
|
|
168
203
|
}
|
|
169
|
-
const response = await sodax.moneyMarket.
|
|
204
|
+
const response = await sodax.moneyMarket.supply(
|
|
170
205
|
{
|
|
171
206
|
token: spokeToken.address,
|
|
172
|
-
amount: parseUnits(amount, spokeToken.decimals)
|
|
207
|
+
amount: parseUnits(amount, spokeToken.decimals),
|
|
208
|
+
action: "supply"
|
|
173
209
|
},
|
|
174
210
|
spokeProvider
|
|
175
211
|
);
|
|
@@ -181,18 +217,19 @@ function useSupply(spokeToken) {
|
|
|
181
217
|
}
|
|
182
218
|
});
|
|
183
219
|
}
|
|
184
|
-
function useWithdraw(
|
|
220
|
+
function useWithdraw(spokeToken, spokeProvider) {
|
|
185
221
|
const { sodax } = useSodaxContext();
|
|
186
|
-
const spokeProvider = useSpokeProvider(spokeChainId);
|
|
187
222
|
return useMutation({
|
|
188
223
|
mutationFn: async (amount) => {
|
|
189
224
|
if (!spokeProvider) {
|
|
190
225
|
throw new Error("spokeProvider is not found");
|
|
191
226
|
}
|
|
192
|
-
const response = await sodax.moneyMarket.
|
|
227
|
+
const response = await sodax.moneyMarket.withdraw(
|
|
193
228
|
{
|
|
194
|
-
token:
|
|
195
|
-
|
|
229
|
+
token: spokeToken.address,
|
|
230
|
+
// vault token on hub chain decimals is 18
|
|
231
|
+
amount: parseUnits(amount, 18),
|
|
232
|
+
action: "withdraw"
|
|
196
233
|
},
|
|
197
234
|
spokeProvider
|
|
198
235
|
);
|
|
@@ -204,104 +241,102 @@ function useWithdraw(hubToken, spokeChainId) {
|
|
|
204
241
|
}
|
|
205
242
|
});
|
|
206
243
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const tokens = hubAssets[xChainId];
|
|
210
|
-
Object.keys(tokens).forEach((tokenAddress) => {
|
|
211
|
-
const token = tokens[tokenAddress];
|
|
212
|
-
allXTokens.push({
|
|
213
|
-
xChainId,
|
|
214
|
-
symbol: token.symbol,
|
|
215
|
-
name: token.name,
|
|
216
|
-
decimals: token.decimal,
|
|
217
|
-
address: tokenAddress
|
|
218
|
-
});
|
|
219
|
-
allXTokens.push({
|
|
220
|
-
xChainId: "sonic",
|
|
221
|
-
symbol: token.symbol,
|
|
222
|
-
name: token.name,
|
|
223
|
-
decimals: token.decimal,
|
|
224
|
-
address: token.vault
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
|
|
229
|
-
const tokens = hubAssets[spokeChainId];
|
|
230
|
-
const token = Object.keys(tokens).find((tokenAddress) => tokens[tokenAddress].vault === vault);
|
|
231
|
-
if (!token) {
|
|
232
|
-
throw new Error("Token not found");
|
|
233
|
-
}
|
|
234
|
-
return token;
|
|
235
|
-
};
|
|
236
|
-
function useHubWalletAddress(spokeChainId, address, hubProvider) {
|
|
244
|
+
function useUserReservesData(spokeProvider, address, refetchInterval = 5e3) {
|
|
245
|
+
const { sodax } = useSodaxContext();
|
|
237
246
|
return useQuery({
|
|
238
|
-
queryKey: ["
|
|
247
|
+
queryKey: ["userReserves", spokeProvider?.chainConfig.chain.id, address],
|
|
239
248
|
queryFn: async () => {
|
|
240
|
-
if (!
|
|
241
|
-
|
|
242
|
-
const hubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
243
|
-
spokeChainId,
|
|
244
|
-
address,
|
|
245
|
-
hubProvider
|
|
246
|
-
);
|
|
247
|
-
return hubWalletAddress;
|
|
248
|
-
} catch (error) {
|
|
249
|
-
console.log("error", error);
|
|
250
|
-
return null;
|
|
249
|
+
if (!spokeProvider) {
|
|
250
|
+
throw new Error("Spoke provider or address is not defined");
|
|
251
251
|
}
|
|
252
|
+
return await sodax.moneyMarket.data.getUserReservesData(spokeProvider);
|
|
252
253
|
},
|
|
253
|
-
enabled: !!
|
|
254
|
+
enabled: !!spokeProvider && !!address,
|
|
255
|
+
refetchInterval
|
|
254
256
|
});
|
|
255
257
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? "sonic";
|
|
261
|
-
const hubWalletProvider = useWalletProvider(hubChainId);
|
|
262
|
-
const hubProvider = useHubProvider();
|
|
263
|
-
const { address } = useXAccount(spokeChainId);
|
|
264
|
-
const { data: hubWalletAddress } = useHubWalletAddress(
|
|
265
|
-
spokeChainId,
|
|
266
|
-
address,
|
|
267
|
-
hubProvider
|
|
268
|
-
);
|
|
269
|
-
const { data: userReserves } = useQuery({
|
|
270
|
-
queryKey: ["userReserves", hubWalletAddress],
|
|
258
|
+
function useReservesData() {
|
|
259
|
+
const { sodax } = useSodaxContext();
|
|
260
|
+
return useQuery({
|
|
261
|
+
queryKey: ["reservesData"],
|
|
271
262
|
queryFn: async () => {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
263
|
+
return await sodax.moneyMarket.data.getReservesData();
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function useMMAllowance(token, amount, action, spokeProvider) {
|
|
268
|
+
const { sodax } = useSodaxContext();
|
|
269
|
+
return useQuery({
|
|
270
|
+
queryKey: ["allowance", token.address, amount, action],
|
|
271
|
+
queryFn: async () => {
|
|
272
|
+
if (!spokeProvider) throw new Error("Spoke provider is required");
|
|
273
|
+
const allowance = await sodax.moneyMarket.isAllowanceValid(
|
|
274
|
+
{
|
|
275
|
+
token: token.address,
|
|
276
|
+
amount: parseUnits(amount, token.decimals),
|
|
277
|
+
action
|
|
278
|
+
},
|
|
279
|
+
spokeProvider
|
|
280
|
+
);
|
|
281
|
+
if (allowance.ok) {
|
|
282
|
+
return allowance.value;
|
|
283
|
+
}
|
|
284
|
+
return false;
|
|
285
|
+
},
|
|
286
|
+
enabled: !!spokeProvider
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
function useMMApprove(token, spokeProvider) {
|
|
290
|
+
const { sodax } = useSodaxContext();
|
|
291
|
+
const queryClient = useQueryClient();
|
|
292
|
+
const {
|
|
293
|
+
mutateAsync: approve,
|
|
294
|
+
isPending,
|
|
295
|
+
error,
|
|
296
|
+
reset: resetError
|
|
297
|
+
} = useMutation({
|
|
298
|
+
mutationFn: async ({ amount, action }) => {
|
|
299
|
+
if (!spokeProvider) {
|
|
300
|
+
throw new Error("Spoke provider not found");
|
|
301
|
+
}
|
|
302
|
+
const allowance = await sodax.moneyMarket.approve(
|
|
303
|
+
{
|
|
304
|
+
token: token.address,
|
|
305
|
+
amount: parseUnits(amount, token.decimals),
|
|
306
|
+
action
|
|
307
|
+
},
|
|
308
|
+
spokeProvider
|
|
309
|
+
);
|
|
310
|
+
if (!allowance.ok) {
|
|
311
|
+
throw new Error("Failed to approve tokens");
|
|
312
|
+
}
|
|
313
|
+
return allowance.ok;
|
|
314
|
+
},
|
|
315
|
+
onSuccess: () => {
|
|
316
|
+
queryClient.invalidateQueries({ queryKey: ["allowance", token.address] });
|
|
317
|
+
}
|
|
298
318
|
});
|
|
299
|
-
return
|
|
319
|
+
return {
|
|
320
|
+
approve,
|
|
321
|
+
isLoading: isPending,
|
|
322
|
+
error,
|
|
323
|
+
resetError
|
|
324
|
+
};
|
|
300
325
|
}
|
|
301
326
|
var useQuote = (payload) => {
|
|
302
327
|
const { sodax } = useSodaxContext();
|
|
328
|
+
const queryKey = useMemo(() => {
|
|
329
|
+
if (!payload) return ["quote", void 0];
|
|
330
|
+
return [
|
|
331
|
+
"quote",
|
|
332
|
+
{
|
|
333
|
+
...payload,
|
|
334
|
+
amount: payload.amount.toString()
|
|
335
|
+
}
|
|
336
|
+
];
|
|
337
|
+
}, [payload]);
|
|
303
338
|
return useQuery({
|
|
304
|
-
queryKey
|
|
339
|
+
queryKey,
|
|
305
340
|
queryFn: async () => {
|
|
306
341
|
if (!payload) {
|
|
307
342
|
return void 0;
|
|
@@ -312,15 +347,21 @@ var useQuote = (payload) => {
|
|
|
312
347
|
refetchInterval: 3e3
|
|
313
348
|
});
|
|
314
349
|
};
|
|
315
|
-
function
|
|
350
|
+
function useSwap(spokeProvider) {
|
|
316
351
|
const { sodax } = useSodaxContext();
|
|
317
|
-
const
|
|
352
|
+
const queryClient = useQueryClient();
|
|
318
353
|
return useMutation({
|
|
319
354
|
mutationFn: async (params) => {
|
|
320
355
|
if (!spokeProvider) {
|
|
321
356
|
throw new Error("Spoke provider not found");
|
|
322
357
|
}
|
|
323
|
-
return sodax.solver.
|
|
358
|
+
return sodax.solver.swap({
|
|
359
|
+
intentParams: params,
|
|
360
|
+
spokeProvider
|
|
361
|
+
});
|
|
362
|
+
},
|
|
363
|
+
onSuccess: () => {
|
|
364
|
+
queryClient.invalidateQueries({ queryKey: ["xBalances"] });
|
|
324
365
|
}
|
|
325
366
|
});
|
|
326
367
|
}
|
|
@@ -335,11 +376,669 @@ var useStatus = (intent_tx_hash) => {
|
|
|
335
376
|
// 3s
|
|
336
377
|
});
|
|
337
378
|
};
|
|
338
|
-
|
|
339
|
-
const sodax =
|
|
340
|
-
return
|
|
379
|
+
function useSwapAllowance(params, spokeProvider) {
|
|
380
|
+
const { sodax } = useSodaxContext();
|
|
381
|
+
return useQuery({
|
|
382
|
+
queryKey: ["allowance", params],
|
|
383
|
+
queryFn: async () => {
|
|
384
|
+
if (!spokeProvider || !params) {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
const allowance = await sodax.solver.isAllowanceValid({
|
|
388
|
+
intentParams: params,
|
|
389
|
+
spokeProvider
|
|
390
|
+
});
|
|
391
|
+
if (allowance.ok) {
|
|
392
|
+
return allowance.value;
|
|
393
|
+
}
|
|
394
|
+
return false;
|
|
395
|
+
},
|
|
396
|
+
enabled: !!spokeProvider && !!params,
|
|
397
|
+
refetchInterval: 2e3
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
function useSwapApprove(params, spokeProvider) {
|
|
401
|
+
const { sodax } = useSodaxContext();
|
|
402
|
+
const queryClient = useQueryClient();
|
|
403
|
+
const {
|
|
404
|
+
mutateAsync: approve,
|
|
405
|
+
isPending,
|
|
406
|
+
error,
|
|
407
|
+
reset: resetError
|
|
408
|
+
} = useMutation({
|
|
409
|
+
mutationFn: async ({ params: params2 }) => {
|
|
410
|
+
if (!spokeProvider) {
|
|
411
|
+
throw new Error("Spoke provider not found");
|
|
412
|
+
}
|
|
413
|
+
if (!params2) {
|
|
414
|
+
throw new Error("Swap Params not found");
|
|
415
|
+
}
|
|
416
|
+
const allowance = await sodax.solver.approve({
|
|
417
|
+
intentParams: params2,
|
|
418
|
+
spokeProvider
|
|
419
|
+
});
|
|
420
|
+
if (!allowance.ok) {
|
|
421
|
+
throw new Error("Failed to approve input token");
|
|
422
|
+
}
|
|
423
|
+
return allowance.ok;
|
|
424
|
+
},
|
|
425
|
+
onSuccess: () => {
|
|
426
|
+
queryClient.invalidateQueries({ queryKey: ["allowance", params] });
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
return {
|
|
430
|
+
approve,
|
|
431
|
+
isLoading: isPending,
|
|
432
|
+
error,
|
|
433
|
+
resetError
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
function useCancelSwap(spokeProvider) {
|
|
437
|
+
const { sodax } = useSodaxContext();
|
|
438
|
+
return useMutation({
|
|
439
|
+
mutationFn: async ({ intent, raw = false }) => {
|
|
440
|
+
if (!spokeProvider) {
|
|
441
|
+
throw new Error("Spoke provider not found");
|
|
442
|
+
}
|
|
443
|
+
return sodax.solver.cancelIntent(intent, spokeProvider, raw);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
var useBackendIntentByTxHash = (txHash) => {
|
|
448
|
+
const { sodax } = useSodaxContext();
|
|
449
|
+
return useQuery({
|
|
450
|
+
queryKey: ["backend", "intent", "txHash", txHash],
|
|
451
|
+
queryFn: async () => {
|
|
452
|
+
if (!txHash) {
|
|
453
|
+
return void 0;
|
|
454
|
+
}
|
|
455
|
+
return sodax.backendApiService.getIntentByTxHash(txHash);
|
|
456
|
+
},
|
|
457
|
+
enabled: !!txHash && txHash.length > 0,
|
|
458
|
+
retry: 3
|
|
459
|
+
});
|
|
460
|
+
};
|
|
461
|
+
var useBackendIntentByHash = (intentHash) => {
|
|
462
|
+
const { sodax } = useSodaxContext();
|
|
463
|
+
return useQuery({
|
|
464
|
+
queryKey: ["backend", "intent", "hash", intentHash],
|
|
465
|
+
queryFn: async () => {
|
|
466
|
+
if (!intentHash) {
|
|
467
|
+
return void 0;
|
|
468
|
+
}
|
|
469
|
+
return sodax.backendApiService.getIntentByHash(intentHash);
|
|
470
|
+
},
|
|
471
|
+
enabled: !!intentHash && intentHash.length > 0,
|
|
472
|
+
retry: 3
|
|
473
|
+
});
|
|
474
|
+
};
|
|
475
|
+
var useBackendOrderbook = (params) => {
|
|
476
|
+
const { sodax } = useSodaxContext();
|
|
477
|
+
return useQuery({
|
|
478
|
+
queryKey: ["backend", "solver", "orderbook", params],
|
|
479
|
+
queryFn: async () => {
|
|
480
|
+
if (!params || !params.offset || !params.limit) {
|
|
481
|
+
return void 0;
|
|
482
|
+
}
|
|
483
|
+
return sodax.backendApiService.getOrderbook(params);
|
|
484
|
+
},
|
|
485
|
+
enabled: !!params && !!params.offset && !!params.limit,
|
|
486
|
+
staleTime: 30 * 1e3,
|
|
487
|
+
// 30 seconds for real-time data
|
|
488
|
+
retry: 3
|
|
489
|
+
});
|
|
490
|
+
};
|
|
491
|
+
var useBackendMoneyMarketPosition = (userAddress) => {
|
|
492
|
+
const { sodax } = useSodaxContext();
|
|
493
|
+
return useQuery({
|
|
494
|
+
queryKey: ["backend", "moneymarket", "position", userAddress],
|
|
495
|
+
queryFn: async () => {
|
|
496
|
+
if (!userAddress) {
|
|
497
|
+
return void 0;
|
|
498
|
+
}
|
|
499
|
+
return sodax.backendApiService.getMoneyMarketPosition(userAddress);
|
|
500
|
+
},
|
|
501
|
+
enabled: !!userAddress && userAddress.length > 0,
|
|
502
|
+
retry: 3
|
|
503
|
+
});
|
|
504
|
+
};
|
|
505
|
+
var useBackendAllMoneyMarketAssets = () => {
|
|
506
|
+
const { sodax } = useSodaxContext();
|
|
507
|
+
return useQuery({
|
|
508
|
+
queryKey: ["backend", "moneymarket", "assets", "all"],
|
|
509
|
+
queryFn: async () => {
|
|
510
|
+
return sodax.backendApiService.getAllMoneyMarketAssets();
|
|
511
|
+
},
|
|
512
|
+
retry: 3
|
|
513
|
+
});
|
|
514
|
+
};
|
|
515
|
+
var useBackendMoneyMarketAsset = (reserveAddress) => {
|
|
516
|
+
const { sodax } = useSodaxContext();
|
|
517
|
+
return useQuery({
|
|
518
|
+
queryKey: ["backend", "moneymarket", "asset", reserveAddress],
|
|
519
|
+
queryFn: async () => {
|
|
520
|
+
if (!reserveAddress) {
|
|
521
|
+
return void 0;
|
|
522
|
+
}
|
|
523
|
+
return sodax.backendApiService.getMoneyMarketAsset(reserveAddress);
|
|
524
|
+
},
|
|
525
|
+
enabled: !!reserveAddress && reserveAddress.length > 0,
|
|
526
|
+
retry: 3
|
|
527
|
+
});
|
|
528
|
+
};
|
|
529
|
+
var useBackendMoneyMarketAssetBorrowers = (params) => {
|
|
530
|
+
const { sodax } = useSodaxContext();
|
|
531
|
+
return useQuery({
|
|
532
|
+
queryKey: ["backend", "moneymarket", "asset", "borrowers", params],
|
|
533
|
+
queryFn: async () => {
|
|
534
|
+
if (!params.reserveAddress || !params.offset || !params.limit) {
|
|
535
|
+
return void 0;
|
|
536
|
+
}
|
|
537
|
+
return sodax.backendApiService.getMoneyMarketAssetBorrowers(params.reserveAddress, {
|
|
538
|
+
offset: params.offset,
|
|
539
|
+
limit: params.limit
|
|
540
|
+
});
|
|
541
|
+
},
|
|
542
|
+
enabled: !!params.reserveAddress && !!params.offset && !!params.limit,
|
|
543
|
+
retry: 3
|
|
544
|
+
});
|
|
545
|
+
};
|
|
546
|
+
var useBackendMoneyMarketAssetSuppliers = (params) => {
|
|
547
|
+
const { sodax } = useSodaxContext();
|
|
548
|
+
return useQuery({
|
|
549
|
+
queryKey: ["backend", "moneymarket", "asset", "suppliers", params],
|
|
550
|
+
queryFn: async () => {
|
|
551
|
+
if (!params.reserveAddress || !params.offset || !params.limit) {
|
|
552
|
+
return void 0;
|
|
553
|
+
}
|
|
554
|
+
return sodax.backendApiService.getMoneyMarketAssetSuppliers(params.reserveAddress, {
|
|
555
|
+
offset: params.offset,
|
|
556
|
+
limit: params.limit
|
|
557
|
+
});
|
|
558
|
+
},
|
|
559
|
+
enabled: !!params.reserveAddress && !!params.offset && !!params.limit,
|
|
560
|
+
retry: 3
|
|
561
|
+
});
|
|
562
|
+
};
|
|
563
|
+
var useBackendAllMoneyMarketBorrowers = (params) => {
|
|
564
|
+
const { sodax } = useSodaxContext();
|
|
565
|
+
return useQuery({
|
|
566
|
+
queryKey: ["backend", "moneymarket", "borrowers", "all", params],
|
|
567
|
+
queryFn: async () => {
|
|
568
|
+
if (!params || !params.offset || !params.limit) {
|
|
569
|
+
return void 0;
|
|
570
|
+
}
|
|
571
|
+
return sodax.backendApiService.getAllMoneyMarketBorrowers(params);
|
|
572
|
+
},
|
|
573
|
+
enabled: !!params && !!params.offset && !!params.limit,
|
|
574
|
+
retry: 3
|
|
575
|
+
});
|
|
576
|
+
};
|
|
577
|
+
function useBridgeAllowance(params, spokeProvider) {
|
|
578
|
+
const { sodax } = useSodaxContext();
|
|
579
|
+
return useQuery({
|
|
580
|
+
queryKey: ["bridge-allowance", params],
|
|
581
|
+
queryFn: async () => {
|
|
582
|
+
if (!spokeProvider || !params) {
|
|
583
|
+
return false;
|
|
584
|
+
}
|
|
585
|
+
const allowance = await sodax.bridge.isAllowanceValid({
|
|
586
|
+
params,
|
|
587
|
+
spokeProvider
|
|
588
|
+
});
|
|
589
|
+
if (allowance.ok) {
|
|
590
|
+
return allowance.value;
|
|
591
|
+
}
|
|
592
|
+
return false;
|
|
593
|
+
},
|
|
594
|
+
enabled: !!spokeProvider && !!params
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
function useBridgeApprove(spokeProvider) {
|
|
598
|
+
const { sodax } = useSodaxContext();
|
|
599
|
+
const queryClient = useQueryClient();
|
|
600
|
+
const {
|
|
601
|
+
mutateAsync: approve,
|
|
602
|
+
isPending,
|
|
603
|
+
error,
|
|
604
|
+
reset: resetError
|
|
605
|
+
} = useMutation({
|
|
606
|
+
mutationFn: async (params) => {
|
|
607
|
+
if (!spokeProvider) {
|
|
608
|
+
throw new Error("Spoke provider not found");
|
|
609
|
+
}
|
|
610
|
+
const allowance = await sodax.bridge.approve({
|
|
611
|
+
params,
|
|
612
|
+
spokeProvider
|
|
613
|
+
});
|
|
614
|
+
if (!allowance.ok) {
|
|
615
|
+
throw new Error("Failed to approve tokens for bridge");
|
|
616
|
+
}
|
|
617
|
+
return true;
|
|
618
|
+
},
|
|
619
|
+
onSuccess: (_, params) => {
|
|
620
|
+
queryClient.invalidateQueries({ queryKey: ["bridge-allowance", params] });
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
return {
|
|
624
|
+
approve,
|
|
625
|
+
isLoading: isPending,
|
|
626
|
+
error,
|
|
627
|
+
resetError
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
function useBridge(spokeProvider) {
|
|
631
|
+
const { sodax } = useSodaxContext();
|
|
632
|
+
return useMutation({
|
|
633
|
+
mutationFn: async (params) => {
|
|
634
|
+
if (!spokeProvider) {
|
|
635
|
+
throw new Error("Spoke provider not found");
|
|
636
|
+
}
|
|
637
|
+
const result = await sodax.bridge.bridge({
|
|
638
|
+
params,
|
|
639
|
+
spokeProvider
|
|
640
|
+
});
|
|
641
|
+
if (!result.ok) {
|
|
642
|
+
throw new Error(`Bridge failed: ${result.error.code}`);
|
|
643
|
+
}
|
|
644
|
+
return result;
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
function useGetBridgeableAmount(from, to) {
|
|
649
|
+
const { sodax } = useSodaxContext();
|
|
650
|
+
return useQuery({
|
|
651
|
+
queryKey: ["spoke-asset-manager-token-balance", from, to],
|
|
652
|
+
queryFn: async () => {
|
|
653
|
+
if (!from || !to) {
|
|
654
|
+
return 0n;
|
|
655
|
+
}
|
|
656
|
+
const result = await sodax.bridge.getBridgeableAmount(from, to);
|
|
657
|
+
if (result.ok) {
|
|
658
|
+
return result.value;
|
|
659
|
+
}
|
|
660
|
+
console.error("Error getting bridgeable amount:", result.error);
|
|
661
|
+
return 0n;
|
|
662
|
+
},
|
|
663
|
+
enabled: !!from && !!to
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
function useGetBridgeableTokens(from, to, token) {
|
|
667
|
+
const { sodax } = useSodaxContext();
|
|
668
|
+
return useQuery({
|
|
669
|
+
queryKey: ["bridgeable-tokens", from, to, token],
|
|
670
|
+
queryFn: async () => {
|
|
671
|
+
if (!from || !to || !token) {
|
|
672
|
+
return [];
|
|
673
|
+
}
|
|
674
|
+
const result = sodax.bridge.getBridgeableTokens(from, to, token);
|
|
675
|
+
if (result.ok) {
|
|
676
|
+
return result.value;
|
|
677
|
+
}
|
|
678
|
+
console.error("Error getting bridgeable tokens:", result.error);
|
|
679
|
+
return [];
|
|
680
|
+
},
|
|
681
|
+
enabled: !!from && !!to && !!token
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
function useStake(spokeProvider) {
|
|
685
|
+
const { sodax } = useSodaxContext();
|
|
686
|
+
return useMutation({
|
|
687
|
+
mutationFn: async (params) => {
|
|
688
|
+
if (!spokeProvider) {
|
|
689
|
+
throw new Error("Spoke provider not found");
|
|
690
|
+
}
|
|
691
|
+
const result = await sodax.staking.stake(params, spokeProvider);
|
|
692
|
+
if (!result.ok) {
|
|
693
|
+
throw new Error(`Stake failed: ${result.error.code}`);
|
|
694
|
+
}
|
|
695
|
+
return result.value;
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
function useStakeApprove(spokeProvider) {
|
|
700
|
+
const { sodax } = useSodaxContext();
|
|
701
|
+
return useMutation({
|
|
702
|
+
mutationFn: async (params) => {
|
|
703
|
+
if (!spokeProvider) {
|
|
704
|
+
throw new Error("Spoke provider not found");
|
|
705
|
+
}
|
|
706
|
+
const result = await sodax.staking.approve({
|
|
707
|
+
params: { ...params, action: "stake" },
|
|
708
|
+
spokeProvider
|
|
709
|
+
});
|
|
710
|
+
if (!result.ok) {
|
|
711
|
+
throw new Error(`Stake approval failed: ${result.error.code}`);
|
|
712
|
+
}
|
|
713
|
+
return result.value;
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
function useStakeAllowance(params, spokeProvider) {
|
|
718
|
+
const { sodax } = useSodaxContext();
|
|
719
|
+
return useQuery({
|
|
720
|
+
queryKey: ["soda", "stakeAllowance", params, spokeProvider?.chainConfig.chain.id],
|
|
721
|
+
queryFn: async () => {
|
|
722
|
+
if (!params || !spokeProvider) {
|
|
723
|
+
return false;
|
|
724
|
+
}
|
|
725
|
+
const result = await sodax.staking.isAllowanceValid({
|
|
726
|
+
params: { ...params, action: "stake" },
|
|
727
|
+
spokeProvider
|
|
728
|
+
});
|
|
729
|
+
if (!result.ok) {
|
|
730
|
+
throw new Error(`Allowance check failed: ${result.error.code}`);
|
|
731
|
+
}
|
|
732
|
+
return result.value;
|
|
733
|
+
},
|
|
734
|
+
enabled: !!params && !!spokeProvider,
|
|
735
|
+
refetchInterval: 5e3
|
|
736
|
+
// Refetch every 5 seconds
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
function useUnstake(spokeProvider) {
|
|
740
|
+
const { sodax } = useSodaxContext();
|
|
741
|
+
const queryClient = useQueryClient();
|
|
742
|
+
return useMutation({
|
|
743
|
+
mutationFn: async (params) => {
|
|
744
|
+
if (!spokeProvider) {
|
|
745
|
+
throw new Error("Spoke provider not found");
|
|
746
|
+
}
|
|
747
|
+
const result = await sodax.staking.unstake({ ...params, action: "unstake" }, spokeProvider);
|
|
748
|
+
if (!result.ok) {
|
|
749
|
+
throw new Error(`Unstake failed: ${result.error.code}`);
|
|
750
|
+
}
|
|
751
|
+
return result.value;
|
|
752
|
+
},
|
|
753
|
+
onSuccess: () => {
|
|
754
|
+
queryClient.invalidateQueries({ queryKey: ["stakingInfo"] });
|
|
755
|
+
queryClient.invalidateQueries({ queryKey: ["unstakingInfo"] });
|
|
756
|
+
queryClient.invalidateQueries({ queryKey: ["unstakingInfoWithPenalty"] });
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
function useClaim(spokeProvider) {
|
|
761
|
+
const { sodax } = useSodaxContext();
|
|
762
|
+
return useMutation({
|
|
763
|
+
mutationFn: async (params) => {
|
|
764
|
+
if (!spokeProvider) {
|
|
765
|
+
throw new Error("Spoke provider not found");
|
|
766
|
+
}
|
|
767
|
+
const result = await sodax.staking.claim({ ...params, action: "claim" }, spokeProvider);
|
|
768
|
+
if (!result.ok) {
|
|
769
|
+
throw new Error(`Claim failed: ${result.error.code}`);
|
|
770
|
+
}
|
|
771
|
+
return result.value;
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
function useCancelUnstake(spokeProvider) {
|
|
776
|
+
const { sodax } = useSodaxContext();
|
|
777
|
+
const queryClient = useQueryClient();
|
|
778
|
+
return useMutation({
|
|
779
|
+
mutationFn: async (params) => {
|
|
780
|
+
if (!spokeProvider) {
|
|
781
|
+
throw new Error("Spoke provider not available");
|
|
782
|
+
}
|
|
783
|
+
const result = await sodax.staking.cancelUnstake({ ...params, action: "cancelUnstake" }, spokeProvider);
|
|
784
|
+
if (!result.ok) {
|
|
785
|
+
throw new Error(`Cancel unstake failed: ${result.error.code}`);
|
|
786
|
+
}
|
|
787
|
+
return result.value;
|
|
788
|
+
},
|
|
789
|
+
onSuccess: () => {
|
|
790
|
+
queryClient.invalidateQueries({ queryKey: ["stakingInfo"] });
|
|
791
|
+
queryClient.invalidateQueries({ queryKey: ["unstakingInfo"] });
|
|
792
|
+
queryClient.invalidateQueries({ queryKey: ["unstakingInfoWithPenalty"] });
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
function useStakingInfo(spokeProvider, refetchInterval = 5e3) {
|
|
797
|
+
const { sodax } = useSodaxContext();
|
|
798
|
+
return useQuery({
|
|
799
|
+
queryKey: ["soda", "stakingInfo", spokeProvider?.chainConfig.chain.id],
|
|
800
|
+
queryFn: async () => {
|
|
801
|
+
if (!spokeProvider) {
|
|
802
|
+
throw new Error("Spoke provider not found");
|
|
803
|
+
}
|
|
804
|
+
const result = await sodax.staking.getStakingInfoFromSpoke(spokeProvider);
|
|
805
|
+
if (!result.ok) {
|
|
806
|
+
throw new Error(`Failed to fetch staking info: ${result.error.code}`);
|
|
807
|
+
}
|
|
808
|
+
return result.value;
|
|
809
|
+
},
|
|
810
|
+
enabled: !!spokeProvider,
|
|
811
|
+
refetchInterval
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
function useUnstakingInfoWithPenalty(userAddress, spokeProvider, refetchInterval = 5e3) {
|
|
815
|
+
const { sodax } = useSodaxContext();
|
|
816
|
+
return useQuery({
|
|
817
|
+
queryKey: ["soda", "unstakingInfoWithPenalty", spokeProvider?.chainConfig.chain.id, userAddress],
|
|
818
|
+
queryFn: async () => {
|
|
819
|
+
if (!spokeProvider) {
|
|
820
|
+
throw new Error("Spoke provider not found");
|
|
821
|
+
}
|
|
822
|
+
const penaltyResult = await sodax.staking.getUnstakingInfoWithPenalty(spokeProvider);
|
|
823
|
+
if (!penaltyResult.ok) {
|
|
824
|
+
throw new Error(`Failed to fetch unstaking info with penalty: ${penaltyResult.error.code}`);
|
|
825
|
+
}
|
|
826
|
+
return penaltyResult.value;
|
|
827
|
+
},
|
|
828
|
+
enabled: !!spokeProvider && !!userAddress,
|
|
829
|
+
refetchInterval
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
function useStakingConfig(refetchInterval = 3e4) {
|
|
833
|
+
const { sodax } = useSodaxContext();
|
|
834
|
+
return useQuery({
|
|
835
|
+
queryKey: ["soda", "stakingConfig"],
|
|
836
|
+
queryFn: async () => {
|
|
837
|
+
const result = await sodax.staking.getStakingConfig();
|
|
838
|
+
if (!result.ok) {
|
|
839
|
+
throw new Error(`Failed to fetch staking config: ${result.error.code}`);
|
|
840
|
+
}
|
|
841
|
+
return result.value;
|
|
842
|
+
},
|
|
843
|
+
refetchInterval
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
function useStakeRatio(amount, refetchInterval = 1e4) {
|
|
847
|
+
const { sodax } = useSodaxContext();
|
|
848
|
+
return useQuery({
|
|
849
|
+
queryKey: ["soda", "stakeRatio", amount?.toString()],
|
|
850
|
+
queryFn: async () => {
|
|
851
|
+
if (!amount || amount <= 0n) {
|
|
852
|
+
throw new Error("Amount must be greater than 0");
|
|
853
|
+
}
|
|
854
|
+
if (!sodax?.staking) {
|
|
855
|
+
throw new Error("Staking service not available");
|
|
856
|
+
}
|
|
857
|
+
const result = await sodax.staking.getStakeRatio(amount);
|
|
858
|
+
if (!result.ok) {
|
|
859
|
+
throw new Error(`Failed to fetch stake ratio: ${result.error.code}`);
|
|
860
|
+
}
|
|
861
|
+
return result.value;
|
|
862
|
+
},
|
|
863
|
+
enabled: !!amount && amount > 0n && !!sodax?.staking,
|
|
864
|
+
refetchInterval
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
function useInstantUnstakeRatio(amount, refetchInterval = 1e4) {
|
|
868
|
+
const { sodax } = useSodaxContext();
|
|
869
|
+
console.log("useInstantUnstakeRatio hook called with:", { amount: amount?.toString(), sodax: !!sodax });
|
|
870
|
+
return useQuery({
|
|
871
|
+
queryKey: ["soda", "instantUnstakeRatio", amount?.toString()],
|
|
872
|
+
queryFn: async () => {
|
|
873
|
+
console.log("useInstantUnstakeRatio queryFn called with amount:", amount?.toString());
|
|
874
|
+
if (!amount || amount <= 0n) {
|
|
875
|
+
throw new Error("Amount must be greater than 0");
|
|
876
|
+
}
|
|
877
|
+
if (!sodax?.staking) {
|
|
878
|
+
throw new Error("Staking service not available");
|
|
879
|
+
}
|
|
880
|
+
const result = await sodax.staking.getInstantUnstakeRatio(amount);
|
|
881
|
+
if (!result.ok) {
|
|
882
|
+
throw new Error(`Failed to fetch instant unstake ratio: ${result.error.code}`);
|
|
883
|
+
}
|
|
884
|
+
return result.value;
|
|
885
|
+
},
|
|
886
|
+
enabled: !!amount && amount > 0n && !!sodax?.staking,
|
|
887
|
+
refetchInterval
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
function useConvertedAssets(amount, refetchInterval = 1e4) {
|
|
891
|
+
const { sodax } = useSodaxContext();
|
|
892
|
+
console.log("useConvertedAssets hook called with:", { amount: amount?.toString(), sodax: !!sodax });
|
|
893
|
+
return useQuery({
|
|
894
|
+
queryKey: ["soda", "convertedAssets", amount?.toString()],
|
|
895
|
+
queryFn: async () => {
|
|
896
|
+
console.log("useConvertedAssets queryFn called with amount:", amount?.toString());
|
|
897
|
+
if (!amount || amount <= 0n) {
|
|
898
|
+
throw new Error("Amount must be greater than 0");
|
|
899
|
+
}
|
|
900
|
+
const result = await sodax.staking.getConvertedAssets(amount);
|
|
901
|
+
if (!result.ok) {
|
|
902
|
+
throw new Error(`Failed to fetch converted assets: ${result.error.code}`);
|
|
903
|
+
}
|
|
904
|
+
return result.value;
|
|
905
|
+
},
|
|
906
|
+
enabled: !!amount && amount > 0n && !!sodax?.staking,
|
|
907
|
+
refetchInterval
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
function useInstantUnstake(spokeProvider) {
|
|
911
|
+
const { sodax } = useSodaxContext();
|
|
912
|
+
return useMutation({
|
|
913
|
+
mutationFn: async (params) => {
|
|
914
|
+
if (!spokeProvider) {
|
|
915
|
+
throw new Error("spokeProvider is not found");
|
|
916
|
+
}
|
|
917
|
+
const result = await sodax.staking.instantUnstake({ ...params, action: "instantUnstake" }, spokeProvider);
|
|
918
|
+
if (!result.ok) {
|
|
919
|
+
throw new Error(`Instant unstake failed: ${result.error.code}`);
|
|
920
|
+
}
|
|
921
|
+
return result.value;
|
|
922
|
+
},
|
|
923
|
+
onError: (error) => {
|
|
924
|
+
console.error("Instant unstake error:", error);
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
function useUnstakeAllowance(params, spokeProvider) {
|
|
929
|
+
const { sodax } = useSodaxContext();
|
|
930
|
+
return useQuery({
|
|
931
|
+
queryKey: ["soda", "unstakeAllowance", params, spokeProvider?.chainConfig.chain.id],
|
|
932
|
+
queryFn: async () => {
|
|
933
|
+
if (!params || !spokeProvider) {
|
|
934
|
+
return false;
|
|
935
|
+
}
|
|
936
|
+
const result = await sodax.staking.isAllowanceValid({
|
|
937
|
+
params: { ...params, action: "unstake" },
|
|
938
|
+
spokeProvider
|
|
939
|
+
});
|
|
940
|
+
if (!result.ok) {
|
|
941
|
+
console.error(`Unstake allowance check failed: ${result.error.code}, error: ${result.error.error}`);
|
|
942
|
+
throw new Error(`Unstake allowance check failed: ${result.error.code}`);
|
|
943
|
+
}
|
|
944
|
+
return result.value;
|
|
945
|
+
},
|
|
946
|
+
enabled: !!params && !!spokeProvider,
|
|
947
|
+
refetchInterval: 5e3
|
|
948
|
+
// Refetch every 5 seconds
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
function useUnstakeApprove(spokeProvider) {
|
|
952
|
+
const { sodax } = useSodaxContext();
|
|
953
|
+
return useMutation({
|
|
954
|
+
mutationFn: async (params) => {
|
|
955
|
+
console.log("useUnstakeApprove called with params:", params);
|
|
956
|
+
if (!spokeProvider) {
|
|
957
|
+
throw new Error("Spoke provider not found");
|
|
958
|
+
}
|
|
959
|
+
const result = await sodax.staking.approve({
|
|
960
|
+
params: { ...params, action: "unstake" },
|
|
961
|
+
spokeProvider
|
|
962
|
+
});
|
|
963
|
+
if (!result.ok) {
|
|
964
|
+
throw new Error(`Unstake approval failed: ${result.error.code}`);
|
|
965
|
+
}
|
|
966
|
+
return result.value;
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
function useUnstakingInfo(userAddress, spokeProvider, refetchInterval = 5e3) {
|
|
971
|
+
const { sodax } = useSodaxContext();
|
|
972
|
+
return useQuery({
|
|
973
|
+
queryKey: ["soda", "unstakingInfoWithPenalty", spokeProvider?.chainConfig.chain.id, userAddress],
|
|
974
|
+
queryFn: async () => {
|
|
975
|
+
if (!spokeProvider || !userAddress) {
|
|
976
|
+
throw new Error("Spoke provider or user address not found");
|
|
977
|
+
}
|
|
978
|
+
const result = await sodax.staking.getUnstakingInfo(spokeProvider);
|
|
979
|
+
if (!result.ok) {
|
|
980
|
+
throw new Error(`Failed to fetch unstaking info: ${result.error.code}`);
|
|
981
|
+
}
|
|
982
|
+
return result.value;
|
|
983
|
+
},
|
|
984
|
+
enabled: !!spokeProvider && !!userAddress,
|
|
985
|
+
refetchInterval
|
|
986
|
+
});
|
|
987
|
+
}
|
|
988
|
+
function useInstantUnstakeApprove(spokeProvider) {
|
|
989
|
+
const { sodax } = useSodaxContext();
|
|
990
|
+
return useMutation({
|
|
991
|
+
mutationFn: async (params) => {
|
|
992
|
+
console.log("useInstantUnstakeApprove called with params:", params);
|
|
993
|
+
if (!spokeProvider) {
|
|
994
|
+
throw new Error("Spoke provider not found");
|
|
995
|
+
}
|
|
996
|
+
const result = await sodax.staking.approve({
|
|
997
|
+
params: { ...params, action: "instantUnstake" },
|
|
998
|
+
spokeProvider
|
|
999
|
+
});
|
|
1000
|
+
if (!result.ok) {
|
|
1001
|
+
throw new Error(`Instant unstake approval failed: ${result.error.code}`);
|
|
1002
|
+
}
|
|
1003
|
+
return result.value;
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
function useInstantUnstakeAllowance(params, spokeProvider) {
|
|
1008
|
+
const { sodax } = useSodaxContext();
|
|
1009
|
+
return useQuery({
|
|
1010
|
+
queryKey: ["soda", "instantUnstakeAllowance", params, spokeProvider?.chainConfig.chain.id],
|
|
1011
|
+
queryFn: async () => {
|
|
1012
|
+
if (!params || !spokeProvider) {
|
|
1013
|
+
return false;
|
|
1014
|
+
}
|
|
1015
|
+
const result = await sodax.staking.isAllowanceValid({
|
|
1016
|
+
params: { ...params, action: "instantUnstake" },
|
|
1017
|
+
spokeProvider
|
|
1018
|
+
});
|
|
1019
|
+
if (!result.ok) {
|
|
1020
|
+
console.error(`Unstake allowance check failed: ${result.error.code}, error: ${result.error.error}`);
|
|
1021
|
+
throw new Error(`Unstake allowance check failed: ${result.error.code}`);
|
|
1022
|
+
}
|
|
1023
|
+
return result.value;
|
|
1024
|
+
},
|
|
1025
|
+
enabled: !!params && !!spokeProvider,
|
|
1026
|
+
refetchInterval: 5e3
|
|
1027
|
+
// Refetch every 5 seconds
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
var SodaxProvider = ({ children, testnet = false, config, rpcConfig }) => {
|
|
1031
|
+
const sodax = new Sodax(config);
|
|
1032
|
+
return /* @__PURE__ */ React.createElement(SodaxContext.Provider, { value: { sodax, testnet, rpcConfig } }, children);
|
|
1033
|
+
};
|
|
1034
|
+
var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
|
|
1035
|
+
const tokens = hubAssets[spokeChainId];
|
|
1036
|
+
const address = Object.keys(tokens).find(
|
|
1037
|
+
(tokenAddress) => tokens[tokenAddress].vault.toLowerCase() === vault.toLowerCase()
|
|
1038
|
+
);
|
|
1039
|
+
return address;
|
|
341
1040
|
};
|
|
342
1041
|
|
|
343
|
-
export { SodaxProvider,
|
|
1042
|
+
export { SodaxProvider, getSpokeTokenAddressByVault, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelSwap, useCancelUnstake, useClaim, useConvertedAssets, useDeriveUserWalletAddress, useEstimateGas, useGetBridgeableAmount, useGetBridgeableTokens, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useMMAllowance, useMMApprove, useQuote, useRepay, useRequestTrustline, useReservesData, useSodaxContext, useSpokeProvider, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSwap, useSwapAllowance, useSwapApprove, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserReservesData, useWithdraw };
|
|
344
1043
|
//# sourceMappingURL=index.mjs.map
|
|
345
1044
|
//# sourceMappingURL=index.mjs.map
|