@sodax/dapp-kit 0.0.1-rc.2 → 0.0.1-rc.21
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 +30 -37
- package/dist/contexts/index.d.ts +4 -1
- package/dist/contexts/index.d.ts.map +1 -1
- package/dist/core/index.d.ts +2 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/hooks/mm/index.d.ts +3 -1
- package/dist/hooks/mm/index.d.ts.map +1 -1
- package/dist/hooks/mm/useBorrow.d.ts +13 -4
- package/dist/hooks/mm/useBorrow.d.ts.map +1 -1
- package/dist/hooks/mm/useMMAllowance.d.ts +26 -0
- package/dist/hooks/mm/useMMAllowance.d.ts.map +1 -0
- package/dist/hooks/mm/useMMApprove.d.ts +27 -0
- package/dist/hooks/mm/useMMApprove.d.ts.map +1 -0
- package/dist/hooks/mm/useRepay.d.ts +13 -4
- package/dist/hooks/mm/useRepay.d.ts.map +1 -1
- package/dist/hooks/mm/useReservesData.d.ts +19 -0
- package/dist/hooks/mm/useReservesData.d.ts.map +1 -0
- package/dist/hooks/mm/useReservesHumanized.d.ts +21 -0
- package/dist/hooks/mm/useReservesHumanized.d.ts.map +1 -0
- package/dist/hooks/mm/useReservesList.d.ts +18 -0
- package/dist/hooks/mm/useReservesList.d.ts.map +1 -0
- package/dist/hooks/mm/useReservesUsdFormat.d.ts +23 -0
- package/dist/hooks/mm/useReservesUsdFormat.d.ts.map +1 -0
- package/dist/hooks/mm/useSupply.d.ts +4 -2
- package/dist/hooks/mm/useSupply.d.ts.map +1 -1
- package/dist/hooks/mm/useUserFormattedSummary.d.ts +21 -0
- package/dist/hooks/mm/useUserFormattedSummary.d.ts.map +1 -0
- package/dist/hooks/mm/useUserReservesData.d.ts +19 -8
- package/dist/hooks/mm/useUserReservesData.d.ts.map +1 -1
- package/dist/hooks/mm/useWithdraw.d.ts +11 -4
- package/dist/hooks/mm/useWithdraw.d.ts.map +1 -1
- package/dist/hooks/provider/useHubProvider.d.ts +1 -1
- package/dist/hooks/provider/useHubProvider.d.ts.map +1 -1
- package/dist/hooks/provider/useSpokeProvider.d.ts +16 -2
- package/dist/hooks/provider/useSpokeProvider.d.ts.map +1 -1
- package/dist/hooks/shared/index.d.ts +1 -2
- package/dist/hooks/shared/index.d.ts.map +1 -1
- package/dist/hooks/shared/useEstimateGas.d.ts +4 -0
- package/dist/hooks/shared/useEstimateGas.d.ts.map +1 -0
- package/dist/hooks/swap/index.d.ts +4 -1
- package/dist/hooks/swap/index.d.ts.map +1 -1
- package/dist/hooks/swap/useCancelSwap.d.ts +29 -0
- package/dist/hooks/swap/useCancelSwap.d.ts.map +1 -0
- package/dist/hooks/swap/useQuote.d.ts +4 -4
- package/dist/hooks/swap/useQuote.d.ts.map +1 -1
- package/dist/hooks/swap/useStatus.d.ts +3 -3
- package/dist/hooks/swap/useStatus.d.ts.map +1 -1
- package/dist/hooks/swap/useSwap.d.ts +29 -0
- package/dist/hooks/swap/useSwap.d.ts.map +1 -0
- package/dist/hooks/swap/useSwapAllowance.d.ts +23 -0
- package/dist/hooks/swap/useSwapAllowance.d.ts.map +1 -0
- package/dist/hooks/swap/useSwapApprove.d.ts +25 -0
- package/dist/hooks/swap/useSwapApprove.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +244 -189
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +238 -186
- package/dist/index.mjs.map +1 -1
- package/dist/providers/SodaxProvider.d.ts +4 -2
- package/dist/providers/SodaxProvider.d.ts.map +1 -1
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +5 -6
- package/src/contexts/index.ts +4 -1
- package/src/core/index.ts +5 -33
- 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 +2 -20
- package/src/hooks/provider/useSpokeProvider.ts +91 -6
- package/src/hooks/shared/index.ts +1 -2
- package/src/hooks/shared/useEstimateGas.ts +18 -0
- package/src/hooks/swap/index.ts +4 -1
- package/src/hooks/swap/useCancelSwap.ts +44 -0
- package/src/hooks/swap/useQuote.ts +5 -5
- package/src/hooks/swap/useStatus.ts +3 -3
- package/src/hooks/swap/{useCreateIntentOrder.ts → useSwap.ts} +16 -18
- package/src/hooks/swap/useSwapAllowance.ts +47 -0
- package/src/hooks/swap/useSwapApprove.ts +68 -0
- package/src/index.ts +1 -0
- package/src/providers/SodaxProvider.tsx +22 -5
- package/src/types.ts +22 -0
- package/dist/hooks/mm/useHubWalletAddress.d.ts +0 -24
- package/dist/hooks/mm/useHubWalletAddress.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/swap/useCreateIntentOrder.d.ts +0 -33
- package/dist/hooks/swap/useCreateIntentOrder.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, spokeChainConfig, SONIC_MAINNET_CHAIN_ID, SonicSpokeProvider, EvmSpokeProvider, SuiSpokeProvider, IconSpokeProvider, InjectiveSpokeProvider, StellarSpokeProvider, SolanaSpokeProvider, Sodax, getHubChainConfig, EvmHubProvider, 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,12 +12,38 @@ var useSodaxContext = () => {
|
|
|
13
12
|
}
|
|
14
13
|
return context;
|
|
15
14
|
};
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
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;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/hooks/provider/useHubProvider.ts
|
|
28
|
+
function useHubProvider() {
|
|
29
|
+
const { hubProvider } = useSodaxContext();
|
|
30
|
+
return hubProvider;
|
|
31
|
+
}
|
|
32
|
+
function useSpokeProvider(spokeChainId, walletProvider) {
|
|
33
|
+
const { rpcConfig } = useSodaxContext();
|
|
34
|
+
const xChainType = spokeChainId ? spokeChainConfig[spokeChainId]?.chain.type : void 0;
|
|
19
35
|
const spokeProvider = useMemo(() => {
|
|
20
36
|
if (!walletProvider) return void 0;
|
|
37
|
+
if (!spokeChainId) return void 0;
|
|
38
|
+
if (!xChainType) return void 0;
|
|
39
|
+
if (!rpcConfig) return void 0;
|
|
21
40
|
if (xChainType === "EVM") {
|
|
41
|
+
if (spokeChainId === SONIC_MAINNET_CHAIN_ID) {
|
|
42
|
+
return new SonicSpokeProvider(
|
|
43
|
+
walletProvider,
|
|
44
|
+
spokeChainConfig[spokeChainId]
|
|
45
|
+
);
|
|
46
|
+
}
|
|
22
47
|
return new EvmSpokeProvider(
|
|
23
48
|
walletProvider,
|
|
24
49
|
spokeChainConfig[spokeChainId]
|
|
@@ -30,100 +55,50 @@ function useSpokeProvider(spokeChainId) {
|
|
|
30
55
|
walletProvider
|
|
31
56
|
);
|
|
32
57
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
function useAllowance(token, amount) {
|
|
38
|
-
const { sodax } = useSodaxContext();
|
|
39
|
-
const spokeProvider = useSpokeProvider(token.xChainId);
|
|
40
|
-
return useQuery({
|
|
41
|
-
queryKey: ["allowance", token.address, amount],
|
|
42
|
-
queryFn: async () => {
|
|
43
|
-
if (!spokeProvider) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
const allowance = await sodax.moneyMarket.isAllowanceValid(
|
|
47
|
-
{
|
|
48
|
-
token: token.address,
|
|
49
|
-
amount: parseUnits(amount, token.decimals)
|
|
50
|
-
},
|
|
51
|
-
spokeProvider
|
|
58
|
+
if (xChainType === "ICON") {
|
|
59
|
+
return new IconSpokeProvider(
|
|
60
|
+
walletProvider,
|
|
61
|
+
spokeChainConfig[spokeChainId]
|
|
52
62
|
);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
enabled: !!spokeProvider
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
function useApprove(token) {
|
|
62
|
-
const { sodax } = useSodaxContext();
|
|
63
|
-
const spokeProvider = useSpokeProvider(token.xChainId);
|
|
64
|
-
const queryClient = useQueryClient();
|
|
65
|
-
const {
|
|
66
|
-
mutateAsync: approve,
|
|
67
|
-
isPending,
|
|
68
|
-
error,
|
|
69
|
-
reset: resetError
|
|
70
|
-
} = useMutation({
|
|
71
|
-
mutationFn: async (amount) => {
|
|
72
|
-
if (!spokeProvider) {
|
|
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
|
|
63
|
+
}
|
|
64
|
+
if (xChainType === "INJECTIVE") {
|
|
65
|
+
return new InjectiveSpokeProvider(
|
|
66
|
+
spokeChainConfig[spokeChainId],
|
|
67
|
+
walletProvider
|
|
80
68
|
);
|
|
81
|
-
if (!allowance.ok) {
|
|
82
|
-
throw new Error("Failed to approve tokens");
|
|
83
|
-
}
|
|
84
|
-
return allowance.ok;
|
|
85
|
-
},
|
|
86
|
-
onSuccess: () => {
|
|
87
|
-
queryClient.invalidateQueries({ queryKey: ["allowance", token.address] });
|
|
88
69
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
resetError
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
function useHubProvider() {
|
|
98
|
-
const { sodax } = useSodaxContext();
|
|
99
|
-
const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id;
|
|
100
|
-
const hubRpcUrl = sodax.config?.hubProviderConfig?.hubRpcUrl;
|
|
101
|
-
const xChainType = getXChainType(hubChainId);
|
|
102
|
-
const hubProvider = useMemo(() => {
|
|
103
|
-
if (xChainType === "EVM" && hubChainId && hubRpcUrl) {
|
|
104
|
-
const hubChainCfg = getHubChainConfig(hubChainId);
|
|
105
|
-
if (!hubChainCfg) return void 0;
|
|
106
|
-
return new EvmHubProvider({
|
|
107
|
-
hubRpcUrl,
|
|
108
|
-
chainConfig: hubChainCfg
|
|
70
|
+
if (xChainType === "STELLAR") {
|
|
71
|
+
const stellarConfig = spokeChainConfig[spokeChainId];
|
|
72
|
+
return new StellarSpokeProvider(walletProvider, stellarConfig, {
|
|
73
|
+
horizonRpcUrl: stellarConfig.horizonRpcUrl,
|
|
74
|
+
sorobanRpcUrl: stellarConfig.sorobanRpcUrl
|
|
109
75
|
});
|
|
110
76
|
}
|
|
77
|
+
if (xChainType === "SOLANA") {
|
|
78
|
+
return new SolanaSpokeProvider(
|
|
79
|
+
walletProvider,
|
|
80
|
+
rpcConfig.solana ? {
|
|
81
|
+
...spokeChainConfig[spokeChainId],
|
|
82
|
+
rpcUrl: rpcConfig.solana
|
|
83
|
+
} : spokeChainConfig[spokeChainId]
|
|
84
|
+
);
|
|
85
|
+
}
|
|
111
86
|
return void 0;
|
|
112
|
-
}, [xChainType,
|
|
113
|
-
return
|
|
87
|
+
}, [spokeChainId, xChainType, walletProvider, rpcConfig]);
|
|
88
|
+
return spokeProvider;
|
|
114
89
|
}
|
|
115
|
-
function useBorrow(
|
|
90
|
+
function useBorrow(spokeToken, spokeProvider) {
|
|
116
91
|
const { sodax } = useSodaxContext();
|
|
117
|
-
const spokeProvider = useSpokeProvider(spokeChainId);
|
|
118
92
|
return useMutation({
|
|
119
93
|
mutationFn: async (amount) => {
|
|
120
94
|
if (!spokeProvider) {
|
|
121
95
|
throw new Error("spokeProvider is not found");
|
|
122
96
|
}
|
|
123
|
-
const response = await sodax.moneyMarket.
|
|
97
|
+
const response = await sodax.moneyMarket.borrow(
|
|
124
98
|
{
|
|
125
|
-
token:
|
|
126
|
-
amount: parseUnits(amount,
|
|
99
|
+
token: spokeToken.address,
|
|
100
|
+
amount: parseUnits(amount, 18),
|
|
101
|
+
action: "borrow"
|
|
127
102
|
},
|
|
128
103
|
spokeProvider
|
|
129
104
|
);
|
|
@@ -135,18 +110,18 @@ function useBorrow(hubToken, spokeChainId) {
|
|
|
135
110
|
}
|
|
136
111
|
});
|
|
137
112
|
}
|
|
138
|
-
function useRepay(
|
|
113
|
+
function useRepay(spokeToken, spokeProvider) {
|
|
139
114
|
const { sodax } = useSodaxContext();
|
|
140
|
-
const spokeProvider = useSpokeProvider(spokeChainId);
|
|
141
115
|
return useMutation({
|
|
142
116
|
mutationFn: async (amount) => {
|
|
143
117
|
if (!spokeProvider) {
|
|
144
118
|
throw new Error("spokeProvider is not found");
|
|
145
119
|
}
|
|
146
|
-
const response = await sodax.moneyMarket.
|
|
120
|
+
const response = await sodax.moneyMarket.repay(
|
|
147
121
|
{
|
|
148
|
-
token:
|
|
149
|
-
amount: parseUnits(amount,
|
|
122
|
+
token: spokeToken.address,
|
|
123
|
+
amount: parseUnits(amount, spokeToken.decimals),
|
|
124
|
+
action: "repay"
|
|
150
125
|
},
|
|
151
126
|
spokeProvider
|
|
152
127
|
);
|
|
@@ -158,18 +133,18 @@ function useRepay(hubToken, spokeChainId) {
|
|
|
158
133
|
}
|
|
159
134
|
});
|
|
160
135
|
}
|
|
161
|
-
function useSupply(spokeToken) {
|
|
136
|
+
function useSupply(spokeToken, spokeProvider) {
|
|
162
137
|
const { sodax } = useSodaxContext();
|
|
163
|
-
const spokeProvider = useSpokeProvider(spokeToken.xChainId);
|
|
164
138
|
return useMutation({
|
|
165
139
|
mutationFn: async (amount) => {
|
|
166
140
|
if (!spokeProvider) {
|
|
167
141
|
throw new Error("spokeProvider is not found");
|
|
168
142
|
}
|
|
169
|
-
const response = await sodax.moneyMarket.
|
|
143
|
+
const response = await sodax.moneyMarket.supply(
|
|
170
144
|
{
|
|
171
145
|
token: spokeToken.address,
|
|
172
|
-
amount: parseUnits(amount, spokeToken.decimals)
|
|
146
|
+
amount: parseUnits(amount, spokeToken.decimals),
|
|
147
|
+
action: "supply"
|
|
173
148
|
},
|
|
174
149
|
spokeProvider
|
|
175
150
|
);
|
|
@@ -181,18 +156,19 @@ function useSupply(spokeToken) {
|
|
|
181
156
|
}
|
|
182
157
|
});
|
|
183
158
|
}
|
|
184
|
-
function useWithdraw(
|
|
159
|
+
function useWithdraw(spokeToken, spokeProvider) {
|
|
185
160
|
const { sodax } = useSodaxContext();
|
|
186
|
-
const spokeProvider = useSpokeProvider(spokeChainId);
|
|
187
161
|
return useMutation({
|
|
188
162
|
mutationFn: async (amount) => {
|
|
189
163
|
if (!spokeProvider) {
|
|
190
164
|
throw new Error("spokeProvider is not found");
|
|
191
165
|
}
|
|
192
|
-
const response = await sodax.moneyMarket.
|
|
166
|
+
const response = await sodax.moneyMarket.withdraw(
|
|
193
167
|
{
|
|
194
|
-
token:
|
|
195
|
-
|
|
168
|
+
token: spokeToken.address,
|
|
169
|
+
// vault token on hub chain decimals is 18
|
|
170
|
+
amount: parseUnits(amount, 18),
|
|
171
|
+
action: "withdraw"
|
|
196
172
|
},
|
|
197
173
|
spokeProvider
|
|
198
174
|
);
|
|
@@ -204,99 +180,87 @@ function useWithdraw(hubToken, spokeChainId) {
|
|
|
204
180
|
}
|
|
205
181
|
});
|
|
206
182
|
}
|
|
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) {
|
|
183
|
+
function useUserReservesData(spokeProvider, address, refetchInterval = 5e3) {
|
|
184
|
+
const { sodax } = useSodaxContext();
|
|
237
185
|
return useQuery({
|
|
238
|
-
queryKey: ["
|
|
186
|
+
queryKey: ["userReserves", spokeProvider?.chainConfig.chain.id, address],
|
|
239
187
|
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;
|
|
188
|
+
if (!spokeProvider) {
|
|
189
|
+
throw new Error("Spoke provider or address is not defined");
|
|
251
190
|
}
|
|
191
|
+
return await sodax.moneyMarket.data.getUserReservesData(spokeProvider);
|
|
252
192
|
},
|
|
253
|
-
enabled: !!
|
|
193
|
+
enabled: !!spokeProvider && !!address,
|
|
194
|
+
refetchInterval
|
|
254
195
|
});
|
|
255
196
|
}
|
|
256
|
-
|
|
257
|
-
// src/hooks/mm/useUserReservesData.ts
|
|
258
|
-
function useUserReservesData(spokeChainId) {
|
|
197
|
+
function useReservesData() {
|
|
259
198
|
const { sodax } = useSodaxContext();
|
|
260
|
-
|
|
261
|
-
|
|
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],
|
|
199
|
+
return useQuery({
|
|
200
|
+
queryKey: ["reservesData"],
|
|
271
201
|
queryFn: async () => {
|
|
272
|
-
|
|
273
|
-
|
|
202
|
+
return await sodax.moneyMarket.data.getReservesData();
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function useMMAllowance(token, amount, action, spokeProvider) {
|
|
207
|
+
const { sodax } = useSodaxContext();
|
|
208
|
+
return useQuery({
|
|
209
|
+
queryKey: ["allowance", token.address, amount, action],
|
|
210
|
+
queryFn: async () => {
|
|
211
|
+
if (!spokeProvider) throw new Error("Spoke provider is required");
|
|
212
|
+
const allowance = await sodax.moneyMarket.isAllowanceValid(
|
|
213
|
+
{
|
|
214
|
+
token: token.address,
|
|
215
|
+
amount: parseUnits(amount, token.decimals),
|
|
216
|
+
action
|
|
217
|
+
},
|
|
218
|
+
spokeProvider
|
|
219
|
+
);
|
|
220
|
+
if (allowance.ok) {
|
|
221
|
+
return allowance.value;
|
|
274
222
|
}
|
|
275
|
-
|
|
276
|
-
|
|
223
|
+
return false;
|
|
224
|
+
},
|
|
225
|
+
enabled: !!spokeProvider
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
function useMMApprove(token, spokeProvider) {
|
|
229
|
+
const { sodax } = useSodaxContext();
|
|
230
|
+
const queryClient = useQueryClient();
|
|
231
|
+
const {
|
|
232
|
+
mutateAsync: approve,
|
|
233
|
+
isPending,
|
|
234
|
+
error,
|
|
235
|
+
reset: resetError
|
|
236
|
+
} = useMutation({
|
|
237
|
+
mutationFn: async ({ amount, action }) => {
|
|
238
|
+
if (!spokeProvider) {
|
|
239
|
+
throw new Error("Spoke provider not found");
|
|
277
240
|
}
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
token: allXTokens.find((t) => t.address === r.underlyingAsset)
|
|
289
|
-
};
|
|
290
|
-
});
|
|
291
|
-
} catch (error) {
|
|
292
|
-
console.log("error", error);
|
|
293
|
-
return;
|
|
241
|
+
const allowance = await sodax.moneyMarket.approve(
|
|
242
|
+
{
|
|
243
|
+
token: token.address,
|
|
244
|
+
amount: parseUnits(amount, token.decimals),
|
|
245
|
+
action
|
|
246
|
+
},
|
|
247
|
+
spokeProvider
|
|
248
|
+
);
|
|
249
|
+
if (!allowance.ok) {
|
|
250
|
+
throw new Error("Failed to approve tokens");
|
|
294
251
|
}
|
|
252
|
+
return allowance.ok;
|
|
295
253
|
},
|
|
296
|
-
|
|
297
|
-
|
|
254
|
+
onSuccess: () => {
|
|
255
|
+
queryClient.invalidateQueries({ queryKey: ["allowance", token.address] });
|
|
256
|
+
}
|
|
298
257
|
});
|
|
299
|
-
return
|
|
258
|
+
return {
|
|
259
|
+
approve,
|
|
260
|
+
isLoading: isPending,
|
|
261
|
+
error,
|
|
262
|
+
resetError
|
|
263
|
+
};
|
|
300
264
|
}
|
|
301
265
|
var useQuote = (payload) => {
|
|
302
266
|
const { sodax } = useSodaxContext();
|
|
@@ -312,15 +276,17 @@ var useQuote = (payload) => {
|
|
|
312
276
|
refetchInterval: 3e3
|
|
313
277
|
});
|
|
314
278
|
};
|
|
315
|
-
function
|
|
279
|
+
function useSwap(spokeProvider) {
|
|
316
280
|
const { sodax } = useSodaxContext();
|
|
317
|
-
const spokeProvider = useSpokeProvider(chainId);
|
|
318
281
|
return useMutation({
|
|
319
282
|
mutationFn: async (params) => {
|
|
320
283
|
if (!spokeProvider) {
|
|
321
284
|
throw new Error("Spoke provider not found");
|
|
322
285
|
}
|
|
323
|
-
return sodax.solver.
|
|
286
|
+
return sodax.solver.swap({
|
|
287
|
+
intentParams: params,
|
|
288
|
+
spokeProvider
|
|
289
|
+
});
|
|
324
290
|
}
|
|
325
291
|
});
|
|
326
292
|
}
|
|
@@ -335,11 +301,97 @@ var useStatus = (intent_tx_hash) => {
|
|
|
335
301
|
// 3s
|
|
336
302
|
});
|
|
337
303
|
};
|
|
338
|
-
|
|
304
|
+
function useSwapAllowance(params, spokeProvider) {
|
|
305
|
+
const { sodax } = useSodaxContext();
|
|
306
|
+
return useQuery({
|
|
307
|
+
queryKey: ["allowance", params],
|
|
308
|
+
queryFn: async () => {
|
|
309
|
+
if (!spokeProvider || !params) {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
const allowance = await sodax.solver.isAllowanceValid({
|
|
313
|
+
intentParams: params,
|
|
314
|
+
spokeProvider
|
|
315
|
+
});
|
|
316
|
+
if (allowance.ok) {
|
|
317
|
+
return allowance.value;
|
|
318
|
+
}
|
|
319
|
+
return false;
|
|
320
|
+
},
|
|
321
|
+
enabled: !!spokeProvider && !!params
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
function useSwapApprove(params, spokeProvider) {
|
|
325
|
+
const { sodax } = useSodaxContext();
|
|
326
|
+
const queryClient = useQueryClient();
|
|
327
|
+
const {
|
|
328
|
+
mutateAsync: approve,
|
|
329
|
+
isPending,
|
|
330
|
+
error,
|
|
331
|
+
reset: resetError
|
|
332
|
+
} = useMutation({
|
|
333
|
+
mutationFn: async ({ params: params2 }) => {
|
|
334
|
+
if (!spokeProvider) {
|
|
335
|
+
throw new Error("Spoke provider not found");
|
|
336
|
+
}
|
|
337
|
+
if (!params2) {
|
|
338
|
+
throw new Error("Swap Params not found");
|
|
339
|
+
}
|
|
340
|
+
const allowance = await sodax.solver.approve({
|
|
341
|
+
intentParams: params2,
|
|
342
|
+
spokeProvider
|
|
343
|
+
});
|
|
344
|
+
if (!allowance.ok) {
|
|
345
|
+
throw new Error("Failed to approve input token");
|
|
346
|
+
}
|
|
347
|
+
return allowance.ok;
|
|
348
|
+
},
|
|
349
|
+
onSuccess: () => {
|
|
350
|
+
queryClient.invalidateQueries({ queryKey: ["allowance", params?.inputToken] });
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
return {
|
|
354
|
+
approve,
|
|
355
|
+
isLoading: isPending,
|
|
356
|
+
error,
|
|
357
|
+
resetError
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function useCancelSwap(spokeProvider) {
|
|
361
|
+
const { sodax } = useSodaxContext();
|
|
362
|
+
return useMutation({
|
|
363
|
+
mutationFn: async ({ intent, raw = false }) => {
|
|
364
|
+
if (!spokeProvider) {
|
|
365
|
+
throw new Error("Spoke provider not found");
|
|
366
|
+
}
|
|
367
|
+
return sodax.solver.cancelIntent(intent, spokeProvider, raw);
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
var SodaxProvider = ({ children, testnet = false, config, rpcConfig }) => {
|
|
339
372
|
const sodax = new Sodax(config);
|
|
340
|
-
|
|
373
|
+
const hubChainId = config?.hubProviderConfig?.chainConfig.chain.id;
|
|
374
|
+
const hubRpcUrl = config?.hubProviderConfig?.hubRpcUrl;
|
|
375
|
+
const hubProvider = useMemo(() => {
|
|
376
|
+
if (hubChainId && hubRpcUrl) {
|
|
377
|
+
const hubChainCfg = getHubChainConfig(hubChainId);
|
|
378
|
+
return new EvmHubProvider({
|
|
379
|
+
hubRpcUrl,
|
|
380
|
+
chainConfig: hubChainCfg
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
return void 0;
|
|
384
|
+
}, [hubChainId, hubRpcUrl]);
|
|
385
|
+
return /* @__PURE__ */ React.createElement(SodaxContext.Provider, { value: { sodax, testnet, hubProvider, rpcConfig } }, children);
|
|
386
|
+
};
|
|
387
|
+
var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
|
|
388
|
+
const tokens = hubAssets[spokeChainId];
|
|
389
|
+
const address = Object.keys(tokens).find(
|
|
390
|
+
(tokenAddress) => tokens[tokenAddress].vault.toLowerCase() === vault.toLowerCase()
|
|
391
|
+
);
|
|
392
|
+
return address;
|
|
341
393
|
};
|
|
342
394
|
|
|
343
|
-
export { SodaxProvider,
|
|
395
|
+
export { SodaxProvider, getSpokeTokenAddressByVault, useBorrow, useCancelSwap, useEstimateGas, useHubProvider, useMMAllowance, useMMApprove, useQuote, useRepay, useReservesData, useSodaxContext, useSpokeProvider, useStatus, useSupply, useSwap, useSwapAllowance, useSwapApprove, useUserReservesData, useWithdraw };
|
|
344
396
|
//# sourceMappingURL=index.mjs.map
|
|
345
397
|
//# sourceMappingURL=index.mjs.map
|