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