@sodax/dapp-kit 2.0.0-rc.2 → 2.0.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -63
- package/dist/index.d.ts +11 -4
- package/dist/index.mjs +3 -6
- package/package.json +31 -19
- package/src/providers/SodaxProvider.tsx +15 -11
- package/ai-exported/AGENTS.md +0 -134
- package/ai-exported/integration/README.md +0 -49
- package/ai-exported/integration/ai-rules.md +0 -79
- package/ai-exported/integration/architecture.md +0 -274
- package/ai-exported/integration/features/README.md +0 -29
- package/ai-exported/integration/features/auxiliary-services.md +0 -169
- package/ai-exported/integration/features/bitcoin.md +0 -87
- package/ai-exported/integration/features/bridge.md +0 -91
- package/ai-exported/integration/features/dex.md +0 -152
- package/ai-exported/integration/features/migration.md +0 -118
- package/ai-exported/integration/features/money-market.md +0 -116
- package/ai-exported/integration/features/staking.md +0 -123
- package/ai-exported/integration/features/swap.md +0 -101
- package/ai-exported/integration/quickstart.md +0 -187
- package/ai-exported/integration/recipes/README.md +0 -136
- package/ai-exported/integration/recipes/backend-queries.md +0 -157
- package/ai-exported/integration/recipes/bitcoin.md +0 -193
- package/ai-exported/integration/recipes/bridge.md +0 -174
- package/ai-exported/integration/recipes/dex.md +0 -204
- package/ai-exported/integration/recipes/invalidations.md +0 -115
- package/ai-exported/integration/recipes/migration.md +0 -212
- package/ai-exported/integration/recipes/money-market.md +0 -206
- package/ai-exported/integration/recipes/mutation-error-handling.md +0 -118
- package/ai-exported/integration/recipes/observability.md +0 -93
- package/ai-exported/integration/recipes/setup.md +0 -144
- package/ai-exported/integration/recipes/staking.md +0 -202
- package/ai-exported/integration/recipes/swap.md +0 -272
- package/ai-exported/integration/recipes/wallet-connectivity.md +0 -101
- package/ai-exported/integration/reference/README.md +0 -12
- package/ai-exported/integration/reference/glossary.md +0 -188
- package/ai-exported/integration/reference/hooks-index.md +0 -190
- package/ai-exported/integration/reference/public-api.md +0 -110
- package/ai-exported/integration/reference/querykey-conventions.md +0 -179
- package/ai-exported/migration/README.md +0 -60
- package/ai-exported/migration/ai-rules.md +0 -81
- package/ai-exported/migration/breaking-changes/hook-signatures.md +0 -233
- package/ai-exported/migration/breaking-changes/querykey-conventions.md +0 -108
- package/ai-exported/migration/breaking-changes/result-handling.md +0 -211
- package/ai-exported/migration/breaking-changes/sdk-leakage.md +0 -165
- package/ai-exported/migration/checklist.md +0 -89
- package/ai-exported/migration/features/README.md +0 -34
- package/ai-exported/migration/features/auxiliary-services.md +0 -114
- package/ai-exported/migration/features/bitcoin.md +0 -88
- package/ai-exported/migration/features/bridge.md +0 -123
- package/ai-exported/migration/features/dex.md +0 -101
- package/ai-exported/migration/features/migration.md +0 -120
- package/ai-exported/migration/features/money-market.md +0 -97
- package/ai-exported/migration/features/staking.md +0 -109
- package/ai-exported/migration/features/swap.md +0 -118
- package/ai-exported/migration/recipes.md +0 -188
- package/ai-exported/migration/reference/README.md +0 -15
- package/ai-exported/migration/reference/deleted-hooks.md +0 -110
- package/ai-exported/migration/reference/error-shape-crosswalk.md +0 -144
- package/ai-exported/migration/reference/renamed-hooks.md +0 -66
- package/dist/index.cjs +0 -2642
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1550
- package/dist/index.mjs.map +0 -1
package/dist/index.cjs
DELETED
|
@@ -1,2642 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var reactQuery = require('@tanstack/react-query');
|
|
4
|
-
var react = require('react');
|
|
5
|
-
var sdk = require('@sodax/sdk');
|
|
6
|
-
var viem = require('viem');
|
|
7
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
-
|
|
9
|
-
// src/hooks/shared/unwrapResult.ts
|
|
10
|
-
function unwrapResult(result) {
|
|
11
|
-
if (!result.ok) {
|
|
12
|
-
if (result.error instanceof Error) throw result.error;
|
|
13
|
-
const e = result.error;
|
|
14
|
-
const msg = e?.detail?.code ?? e?.detail?.message ?? e?.message ?? "SDK call failed";
|
|
15
|
-
throw new Error(msg, { cause: result.error });
|
|
16
|
-
}
|
|
17
|
-
return result.value;
|
|
18
|
-
}
|
|
19
|
-
async function toResult(promise) {
|
|
20
|
-
try {
|
|
21
|
-
const value = await promise;
|
|
22
|
-
return { ok: true, value };
|
|
23
|
-
} catch (error) {
|
|
24
|
-
return { ok: false, error };
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function useSafeMutation(options) {
|
|
28
|
-
const mutation = reactQuery.useMutation(options);
|
|
29
|
-
const { mutateAsync } = mutation;
|
|
30
|
-
const mutateAsyncSafe = react.useCallback(
|
|
31
|
-
(vars, opts) => toResult(mutateAsync(vars, opts)),
|
|
32
|
-
[mutateAsync]
|
|
33
|
-
);
|
|
34
|
-
return { ...mutation, mutateAsyncSafe };
|
|
35
|
-
}
|
|
36
|
-
var SodaxContext = react.createContext(null);
|
|
37
|
-
var useSodaxContext = () => {
|
|
38
|
-
const context = react.useContext(SodaxContext);
|
|
39
|
-
if (!context) {
|
|
40
|
-
throw new Error("useSodaxContext must be used within a SodaxProvider");
|
|
41
|
-
}
|
|
42
|
-
return context;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// src/hooks/shared/useEstimateGas.ts
|
|
46
|
-
function useEstimateGas({
|
|
47
|
-
mutationOptions
|
|
48
|
-
} = {}) {
|
|
49
|
-
const { sodax } = useSodaxContext();
|
|
50
|
-
return useSafeMutation({
|
|
51
|
-
mutationKey: ["shared", "estimateGas"],
|
|
52
|
-
...mutationOptions,
|
|
53
|
-
mutationFn: async (params) => unwrapResult(await sodax.spoke.estimateGas(params))
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function useDeriveUserWalletAddress({
|
|
57
|
-
params,
|
|
58
|
-
queryOptions
|
|
59
|
-
} = {}) {
|
|
60
|
-
const { sodax } = useSodaxContext();
|
|
61
|
-
const spokeChainId = params?.spokeChainId;
|
|
62
|
-
const spokeAddress = params?.spokeAddress;
|
|
63
|
-
return reactQuery.useQuery({
|
|
64
|
-
queryKey: ["shared", "deriveUserWalletAddress", spokeChainId, spokeAddress],
|
|
65
|
-
queryFn: async () => {
|
|
66
|
-
if (!spokeChainId || !spokeAddress) {
|
|
67
|
-
throw new Error("Spoke chain id and address are required");
|
|
68
|
-
}
|
|
69
|
-
return await sodax.hubProvider.getUserHubWalletAddress(spokeAddress, spokeChainId);
|
|
70
|
-
},
|
|
71
|
-
enabled: !!spokeChainId && !!spokeAddress,
|
|
72
|
-
refetchInterval: false,
|
|
73
|
-
...queryOptions
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
function useStellarTrustlineCheck({
|
|
77
|
-
params,
|
|
78
|
-
queryOptions
|
|
79
|
-
} = {}) {
|
|
80
|
-
const { sodax } = useSodaxContext();
|
|
81
|
-
const token = params?.token;
|
|
82
|
-
const amount = params?.amount;
|
|
83
|
-
const chainId = params?.chainId;
|
|
84
|
-
const walletProvider = params?.walletProvider;
|
|
85
|
-
return reactQuery.useQuery({
|
|
86
|
-
queryKey: ["shared", "stellarTrustlineCheck", token],
|
|
87
|
-
queryFn: async () => {
|
|
88
|
-
if (chainId !== sdk.ChainKeys.STELLAR_MAINNET) return true;
|
|
89
|
-
if (!walletProvider || !token || !amount) return false;
|
|
90
|
-
const walletAddress = await walletProvider.getWalletAddress();
|
|
91
|
-
return sodax.spoke.stellar.hasSufficientTrustline(token, amount, walletAddress);
|
|
92
|
-
},
|
|
93
|
-
enabled: !!walletProvider && !!token && !!amount,
|
|
94
|
-
...queryOptions
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
function useRequestTrustline(token) {
|
|
98
|
-
const { sodax } = useSodaxContext();
|
|
99
|
-
const queryClient = reactQuery.useQueryClient();
|
|
100
|
-
const [isLoading, setIsLoading] = react.useState(false);
|
|
101
|
-
const [isRequested, setIsRequested] = react.useState(false);
|
|
102
|
-
const [error, setError] = react.useState(null);
|
|
103
|
-
const [data, setData] = react.useState(null);
|
|
104
|
-
const requestTrustline = react.useCallback(
|
|
105
|
-
async ({
|
|
106
|
-
token: token2,
|
|
107
|
-
amount,
|
|
108
|
-
srcChainKey,
|
|
109
|
-
walletProvider
|
|
110
|
-
}) => {
|
|
111
|
-
if (!token2 || !amount) {
|
|
112
|
-
const error2 = new Error("Token and amount are required");
|
|
113
|
-
setError(error2);
|
|
114
|
-
throw error2;
|
|
115
|
-
}
|
|
116
|
-
setIsLoading(true);
|
|
117
|
-
setError(null);
|
|
118
|
-
try {
|
|
119
|
-
const srcAddress = await walletProvider.getWalletAddress();
|
|
120
|
-
const result = await sodax.spoke.stellar.requestTrustline({
|
|
121
|
-
raw: false,
|
|
122
|
-
srcChainKey,
|
|
123
|
-
srcAddress,
|
|
124
|
-
token: token2,
|
|
125
|
-
amount,
|
|
126
|
-
walletProvider
|
|
127
|
-
});
|
|
128
|
-
setData(result);
|
|
129
|
-
setIsRequested(true);
|
|
130
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "stellarTrustlineCheck", token2] });
|
|
131
|
-
return result;
|
|
132
|
-
} catch (err) {
|
|
133
|
-
const error2 = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
134
|
-
setError(error2);
|
|
135
|
-
throw error2;
|
|
136
|
-
} finally {
|
|
137
|
-
setIsLoading(false);
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
[queryClient, sodax]
|
|
141
|
-
);
|
|
142
|
-
return { requestTrustline, isLoading, isRequested, error, data };
|
|
143
|
-
}
|
|
144
|
-
function useGetUserHubWalletAddress({
|
|
145
|
-
params,
|
|
146
|
-
queryOptions
|
|
147
|
-
} = {}) {
|
|
148
|
-
const { sodax } = useSodaxContext();
|
|
149
|
-
const spokeChainId = params?.spokeChainId;
|
|
150
|
-
const spokeAddress = params?.spokeAddress;
|
|
151
|
-
return reactQuery.useQuery({
|
|
152
|
-
queryKey: ["shared", "userHubWalletAddress", spokeChainId, spokeAddress],
|
|
153
|
-
queryFn: async () => {
|
|
154
|
-
if (!spokeChainId || !spokeAddress) {
|
|
155
|
-
throw new Error("Spoke chain id and address are required");
|
|
156
|
-
}
|
|
157
|
-
return await sodax.hubProvider.getUserHubWalletAddress(spokeAddress, spokeChainId);
|
|
158
|
-
},
|
|
159
|
-
enabled: !!spokeChainId && !!spokeAddress,
|
|
160
|
-
refetchInterval: false,
|
|
161
|
-
...queryOptions
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
var REFETCH_INTERVAL_MS = 5e3;
|
|
165
|
-
function getXBalancesQueryOptions({ xService, xChainId, xTokens, address }) {
|
|
166
|
-
return {
|
|
167
|
-
// Pair symbol + address: readable in devtools, unique on-chain (symbol alone
|
|
168
|
-
// can collide — e.g. scam tokens copying legitimate ticker).
|
|
169
|
-
queryKey: ["shared", "xBalances", xChainId, xTokens.map((x) => [x.symbol, x.address]), address],
|
|
170
|
-
queryFn: async () => {
|
|
171
|
-
if (!xService) return {};
|
|
172
|
-
return xService.getBalances(address, xTokens);
|
|
173
|
-
},
|
|
174
|
-
enabled: !!xService && !!address && xTokens.length > 0,
|
|
175
|
-
refetchInterval: REFETCH_INTERVAL_MS
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
function useXBalances({
|
|
179
|
-
params,
|
|
180
|
-
queryOptions
|
|
181
|
-
} = {}) {
|
|
182
|
-
return reactQuery.useQuery({
|
|
183
|
-
...getXBalancesQueryOptions({
|
|
184
|
-
xService: params?.xService,
|
|
185
|
-
xChainId: params?.xChainId,
|
|
186
|
-
xTokens: params?.xTokens ?? [],
|
|
187
|
-
address: params?.address
|
|
188
|
-
}),
|
|
189
|
-
...queryOptions
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// src/hooks/provider/useHubProvider.ts
|
|
194
|
-
function useHubProvider() {
|
|
195
|
-
const { sodax } = useSodaxContext();
|
|
196
|
-
return sodax.hubProvider;
|
|
197
|
-
}
|
|
198
|
-
var SESSION_KEY = (address) => `radfi_session_${address}`;
|
|
199
|
-
function saveRadfiSession(address, session) {
|
|
200
|
-
try {
|
|
201
|
-
localStorage.setItem(SESSION_KEY(address), JSON.stringify(session));
|
|
202
|
-
} catch {
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
function loadRadfiSession(address) {
|
|
206
|
-
try {
|
|
207
|
-
const raw = localStorage.getItem(SESSION_KEY(address));
|
|
208
|
-
return raw ? JSON.parse(raw) : null;
|
|
209
|
-
} catch {
|
|
210
|
-
return null;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function clearRadfiSession(address) {
|
|
214
|
-
try {
|
|
215
|
-
localStorage.removeItem(SESSION_KEY(address));
|
|
216
|
-
} catch {
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
function useRadfiAuth({
|
|
220
|
-
mutationOptions
|
|
221
|
-
} = {}) {
|
|
222
|
-
const { sodax } = useSodaxContext();
|
|
223
|
-
return useSafeMutation({
|
|
224
|
-
mutationKey: ["bitcoin", "radfiAuth"],
|
|
225
|
-
...mutationOptions,
|
|
226
|
-
mutationFn: async ({ walletProvider }) => {
|
|
227
|
-
const radfi = sodax.spoke.bitcoin.radfi;
|
|
228
|
-
const walletAddress = await walletProvider.getWalletAddress();
|
|
229
|
-
const existingSession = loadRadfiSession(walletAddress);
|
|
230
|
-
const cachedPublicKey = existingSession?.publicKey;
|
|
231
|
-
try {
|
|
232
|
-
const { accessToken, refreshToken, tradingAddress, publicKey } = await radfi.authenticateWithWallet(
|
|
233
|
-
walletProvider,
|
|
234
|
-
cachedPublicKey
|
|
235
|
-
);
|
|
236
|
-
saveRadfiSession(walletAddress, { accessToken, refreshToken, tradingAddress, publicKey });
|
|
237
|
-
return { accessToken, refreshToken, tradingAddress };
|
|
238
|
-
} catch (err) {
|
|
239
|
-
const isAlreadyRegistered = err instanceof sdk.RadfiApiError && err.code === "4008";
|
|
240
|
-
if (isAlreadyRegistered && existingSession?.refreshToken) {
|
|
241
|
-
try {
|
|
242
|
-
const refreshed = await radfi.refreshAccessToken(existingSession.refreshToken);
|
|
243
|
-
radfi.setRadfiAccessToken(refreshed.accessToken, refreshed.refreshToken);
|
|
244
|
-
saveRadfiSession(walletAddress, {
|
|
245
|
-
...existingSession,
|
|
246
|
-
accessToken: refreshed.accessToken,
|
|
247
|
-
refreshToken: refreshed.refreshToken
|
|
248
|
-
});
|
|
249
|
-
return {
|
|
250
|
-
accessToken: refreshed.accessToken,
|
|
251
|
-
refreshToken: refreshed.refreshToken,
|
|
252
|
-
tradingAddress: existingSession.tradingAddress
|
|
253
|
-
};
|
|
254
|
-
} catch {
|
|
255
|
-
clearRadfiSession(walletAddress);
|
|
256
|
-
}
|
|
257
|
-
throw new Error(
|
|
258
|
-
"This wallet is already registered with Radfi from another session. Please clear your browser storage for this site and try again, or wait for the previous session to expire."
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
throw err;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
var REFRESH_INTERVAL = 5 * 60 * 1e3;
|
|
267
|
-
function useRadfiSession(walletProvider) {
|
|
268
|
-
const { sodax } = useSodaxContext();
|
|
269
|
-
const [walletAddress, setWalletAddress] = react.useState();
|
|
270
|
-
const [isAuthed, setIsAuthed] = react.useState(false);
|
|
271
|
-
const [tradingAddress, setTradingAddress] = react.useState();
|
|
272
|
-
const isRefreshingRef = react.useRef(false);
|
|
273
|
-
const silentRefresh = react.useCallback(
|
|
274
|
-
async (address) => {
|
|
275
|
-
if (!walletProvider || isRefreshingRef.current) return;
|
|
276
|
-
isRefreshingRef.current = true;
|
|
277
|
-
try {
|
|
278
|
-
const session = loadRadfiSession(address);
|
|
279
|
-
if (!session?.refreshToken) {
|
|
280
|
-
setIsAuthed(false);
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
const radfi = sodax.spoke.bitcoin.radfi;
|
|
284
|
-
const { accessToken, refreshToken } = await radfi.refreshAccessToken(session.refreshToken);
|
|
285
|
-
const updated = { ...session, accessToken, refreshToken };
|
|
286
|
-
saveRadfiSession(address, updated);
|
|
287
|
-
radfi.setRadfiAccessToken(accessToken, refreshToken);
|
|
288
|
-
setIsAuthed(true);
|
|
289
|
-
setTradingAddress(updated.tradingAddress || void 0);
|
|
290
|
-
} catch {
|
|
291
|
-
clearRadfiSession(address);
|
|
292
|
-
sodax.spoke.bitcoin.radfi.setRadfiAccessToken("", "");
|
|
293
|
-
setIsAuthed(false);
|
|
294
|
-
setTradingAddress(void 0);
|
|
295
|
-
} finally {
|
|
296
|
-
isRefreshingRef.current = false;
|
|
297
|
-
}
|
|
298
|
-
},
|
|
299
|
-
[walletProvider, sodax]
|
|
300
|
-
);
|
|
301
|
-
react.useEffect(() => {
|
|
302
|
-
if (!walletProvider) return;
|
|
303
|
-
setIsAuthed(false);
|
|
304
|
-
setTradingAddress(void 0);
|
|
305
|
-
setWalletAddress(void 0);
|
|
306
|
-
walletProvider.getWalletAddress().then((addr) => {
|
|
307
|
-
setWalletAddress(addr);
|
|
308
|
-
const session = loadRadfiSession(addr);
|
|
309
|
-
if (!session?.refreshToken) return;
|
|
310
|
-
silentRefresh(addr);
|
|
311
|
-
}).catch(() => {
|
|
312
|
-
});
|
|
313
|
-
}, [walletProvider, silentRefresh]);
|
|
314
|
-
react.useEffect(() => {
|
|
315
|
-
if (!walletAddress || !walletProvider) return;
|
|
316
|
-
const id = setInterval(() => {
|
|
317
|
-
silentRefresh(walletAddress);
|
|
318
|
-
}, REFRESH_INTERVAL);
|
|
319
|
-
return () => clearInterval(id);
|
|
320
|
-
}, [walletAddress, walletProvider, silentRefresh]);
|
|
321
|
-
const { mutateAsyncSafe: loginMutateSafe, isPending: isLoginPending } = useRadfiAuth();
|
|
322
|
-
const login = react.useCallback(async () => {
|
|
323
|
-
if (!walletProvider) {
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
const result = await loginMutateSafe({ walletProvider });
|
|
327
|
-
if (!result.ok) {
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
setIsAuthed(true);
|
|
331
|
-
setTradingAddress(result.value.tradingAddress || void 0);
|
|
332
|
-
}, [loginMutateSafe, walletProvider]);
|
|
333
|
-
return { walletAddress, isAuthed, tradingAddress, login, isLoginPending };
|
|
334
|
-
}
|
|
335
|
-
function useFundTradingWallet({
|
|
336
|
-
mutationOptions
|
|
337
|
-
} = {}) {
|
|
338
|
-
const { sodax } = useSodaxContext();
|
|
339
|
-
const queryClient = reactQuery.useQueryClient();
|
|
340
|
-
return useSafeMutation({
|
|
341
|
-
mutationKey: ["bitcoin", "fundTradingWallet"],
|
|
342
|
-
...mutationOptions,
|
|
343
|
-
mutationFn: async ({ amount, walletProvider }) => {
|
|
344
|
-
const walletAddress = await walletProvider.getWalletAddress();
|
|
345
|
-
return sodax.spoke.bitcoin.fundTradingWallet(amount, walletAddress, walletProvider);
|
|
346
|
-
},
|
|
347
|
-
onSuccess: async (data, vars, ctx) => {
|
|
348
|
-
queryClient.invalidateQueries({ queryKey: ["bitcoin", "balance"] });
|
|
349
|
-
queryClient.invalidateQueries({ queryKey: ["bitcoin", "tradingWalletBalance"] });
|
|
350
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", sdk.ChainKeys.BITCOIN_MAINNET] });
|
|
351
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
var DEFAULT_RPC_URL = "https://mempool.space/api";
|
|
356
|
-
function useBitcoinBalance({
|
|
357
|
-
params,
|
|
358
|
-
queryOptions
|
|
359
|
-
} = {}) {
|
|
360
|
-
const address = params?.address;
|
|
361
|
-
const rpcUrl = params?.rpcUrl ?? DEFAULT_RPC_URL;
|
|
362
|
-
return reactQuery.useQuery({
|
|
363
|
-
queryKey: ["bitcoin", "balance", address],
|
|
364
|
-
queryFn: async () => {
|
|
365
|
-
if (!address) return 0n;
|
|
366
|
-
const response = await fetch(`${rpcUrl}/address/${address}/utxo`);
|
|
367
|
-
if (!response.ok) return 0n;
|
|
368
|
-
const utxos = await response.json();
|
|
369
|
-
return BigInt(utxos.reduce((sum, utxo) => sum + utxo.value, 0));
|
|
370
|
-
},
|
|
371
|
-
enabled: !!address,
|
|
372
|
-
...queryOptions
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
// src/hooks/bitcoin/useTradingWallet.ts
|
|
377
|
-
function useTradingWallet(walletAddress) {
|
|
378
|
-
if (!walletAddress) return { tradingAddress: void 0 };
|
|
379
|
-
const session = loadRadfiSession(walletAddress);
|
|
380
|
-
return { tradingAddress: session?.tradingAddress || void 0 };
|
|
381
|
-
}
|
|
382
|
-
function useTradingWalletBalance({
|
|
383
|
-
params,
|
|
384
|
-
queryOptions
|
|
385
|
-
} = {}) {
|
|
386
|
-
const { sodax } = useSodaxContext();
|
|
387
|
-
const walletProvider = params?.walletProvider;
|
|
388
|
-
const tradingAddress = params?.tradingAddress;
|
|
389
|
-
return reactQuery.useQuery({
|
|
390
|
-
queryKey: ["bitcoin", "tradingWalletBalance", tradingAddress],
|
|
391
|
-
queryFn: () => {
|
|
392
|
-
if (!walletProvider || !tradingAddress) {
|
|
393
|
-
throw new Error("walletProvider and tradingAddress are required");
|
|
394
|
-
}
|
|
395
|
-
return sodax.spoke.bitcoin.radfi.getBalance(tradingAddress);
|
|
396
|
-
},
|
|
397
|
-
enabled: !!walletProvider && !!tradingAddress,
|
|
398
|
-
...queryOptions
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
function useExpiredUtxos({
|
|
402
|
-
params,
|
|
403
|
-
queryOptions
|
|
404
|
-
} = {}) {
|
|
405
|
-
const { sodax } = useSodaxContext();
|
|
406
|
-
const walletProvider = params?.walletProvider;
|
|
407
|
-
const tradingAddress = params?.tradingAddress;
|
|
408
|
-
return reactQuery.useQuery({
|
|
409
|
-
queryKey: ["bitcoin", "expiredUtxos", tradingAddress],
|
|
410
|
-
queryFn: async () => {
|
|
411
|
-
if (!walletProvider || !tradingAddress) {
|
|
412
|
-
throw new Error("walletProvider and tradingAddress are required");
|
|
413
|
-
}
|
|
414
|
-
const result = await sodax.spoke.bitcoin.radfi.getExpiredUtxos(tradingAddress);
|
|
415
|
-
return result.data;
|
|
416
|
-
},
|
|
417
|
-
enabled: !!walletProvider && !!tradingAddress,
|
|
418
|
-
refetchInterval: 6e4,
|
|
419
|
-
...queryOptions
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
function useRenewUtxos({
|
|
423
|
-
mutationOptions
|
|
424
|
-
} = {}) {
|
|
425
|
-
const { sodax } = useSodaxContext();
|
|
426
|
-
const queryClient = reactQuery.useQueryClient();
|
|
427
|
-
return useSafeMutation({
|
|
428
|
-
mutationKey: ["bitcoin", "renewUtxos"],
|
|
429
|
-
...mutationOptions,
|
|
430
|
-
mutationFn: async ({ txIdVouts, walletProvider }) => {
|
|
431
|
-
const radfi = sodax.spoke.bitcoin.radfi;
|
|
432
|
-
const userAddress = await walletProvider.getWalletAddress();
|
|
433
|
-
const session = loadRadfiSession(userAddress);
|
|
434
|
-
const accessToken = session?.accessToken || radfi.accessToken;
|
|
435
|
-
if (!accessToken) {
|
|
436
|
-
throw new Error("Radfi authentication required. Please login first.");
|
|
437
|
-
}
|
|
438
|
-
const buildResult = await radfi.buildRenewUtxoTransaction({ userAddress, txIdVouts }, accessToken);
|
|
439
|
-
const signedTx = await walletProvider.signTransaction(buildResult.base64Psbt, false);
|
|
440
|
-
const signedBase64Tx = sdk.normalizePsbtToBase64(signedTx);
|
|
441
|
-
return radfi.signAndBroadcastRenewUtxo({ userAddress, signedBase64Tx }, accessToken);
|
|
442
|
-
},
|
|
443
|
-
onSuccess: async (data, vars, ctx) => {
|
|
444
|
-
queryClient.invalidateQueries({ queryKey: ["bitcoin", "expiredUtxos"] });
|
|
445
|
-
queryClient.invalidateQueries({ queryKey: ["bitcoin", "tradingWalletBalance"] });
|
|
446
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
447
|
-
}
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
function useRadfiWithdraw({
|
|
451
|
-
mutationOptions
|
|
452
|
-
} = {}) {
|
|
453
|
-
const { sodax } = useSodaxContext();
|
|
454
|
-
const queryClient = reactQuery.useQueryClient();
|
|
455
|
-
return useSafeMutation({
|
|
456
|
-
mutationKey: ["bitcoin", "radfiWithdraw"],
|
|
457
|
-
...mutationOptions,
|
|
458
|
-
mutationFn: async ({ amount, tokenId, withdrawTo, walletProvider }) => {
|
|
459
|
-
const radfi = sodax.spoke.bitcoin.radfi;
|
|
460
|
-
const userAddress = await walletProvider.getWalletAddress();
|
|
461
|
-
const session = loadRadfiSession(userAddress);
|
|
462
|
-
const accessToken = session?.accessToken || radfi.accessToken;
|
|
463
|
-
if (!accessToken) {
|
|
464
|
-
throw new Error("Radfi authentication required. Please login first.");
|
|
465
|
-
}
|
|
466
|
-
const buildResult = await radfi.withdrawToUser({ userAddress, amount, tokenId, withdrawTo }, accessToken);
|
|
467
|
-
const signedTx = await walletProvider.signTransaction(buildResult.base64Psbt, false);
|
|
468
|
-
const signedBase64Tx = sdk.normalizePsbtToBase64(signedTx);
|
|
469
|
-
const txId = await radfi.signAndBroadcastWithdraw({ userAddress, signedBase64Tx }, accessToken);
|
|
470
|
-
return { txId, fee: buildResult.fee.totalFee };
|
|
471
|
-
},
|
|
472
|
-
onSuccess: async (data, vars, ctx) => {
|
|
473
|
-
queryClient.invalidateQueries({ queryKey: ["bitcoin", "tradingWalletBalance"] });
|
|
474
|
-
queryClient.invalidateQueries({ queryKey: ["bitcoin", "balance"] });
|
|
475
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", sdk.ChainKeys.BITCOIN_MAINNET] });
|
|
476
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
function useBorrow({
|
|
481
|
-
mutationOptions
|
|
482
|
-
} = {}) {
|
|
483
|
-
const { sodax } = useSodaxContext();
|
|
484
|
-
const queryClient = reactQuery.useQueryClient();
|
|
485
|
-
return useSafeMutation({
|
|
486
|
-
mutationKey: ["mm", "borrow"],
|
|
487
|
-
...mutationOptions,
|
|
488
|
-
mutationFn: async (vars) => unwrapResult(await sodax.moneyMarket.borrow({ ...vars, raw: false })),
|
|
489
|
-
onSuccess: async (data, vars, ctx) => {
|
|
490
|
-
const { params } = vars;
|
|
491
|
-
queryClient.invalidateQueries({ queryKey: ["mm", "userReservesData", params.srcChainKey, params.srcAddress] });
|
|
492
|
-
queryClient.invalidateQueries({
|
|
493
|
-
queryKey: ["mm", "userFormattedSummary", params.srcChainKey, params.srcAddress]
|
|
494
|
-
});
|
|
495
|
-
queryClient.invalidateQueries({ queryKey: ["mm", "aTokensBalances"] });
|
|
496
|
-
const balanceChains = /* @__PURE__ */ new Set([params.srcChainKey, params.dstChainKey ?? params.srcChainKey]);
|
|
497
|
-
for (const chainKey of balanceChains) {
|
|
498
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", chainKey] });
|
|
499
|
-
}
|
|
500
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
501
|
-
}
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
function useRepay({
|
|
505
|
-
mutationOptions
|
|
506
|
-
} = {}) {
|
|
507
|
-
const { sodax } = useSodaxContext();
|
|
508
|
-
const queryClient = reactQuery.useQueryClient();
|
|
509
|
-
return useSafeMutation({
|
|
510
|
-
mutationKey: ["mm", "repay"],
|
|
511
|
-
...mutationOptions,
|
|
512
|
-
mutationFn: async (vars) => unwrapResult(await sodax.moneyMarket.repay({ ...vars, raw: false })),
|
|
513
|
-
onSuccess: async (data, vars, ctx) => {
|
|
514
|
-
const { params } = vars;
|
|
515
|
-
queryClient.invalidateQueries({ queryKey: ["mm", "userReservesData", params.srcChainKey, params.srcAddress] });
|
|
516
|
-
queryClient.invalidateQueries({
|
|
517
|
-
queryKey: ["mm", "userFormattedSummary", params.srcChainKey, params.srcAddress]
|
|
518
|
-
});
|
|
519
|
-
queryClient.invalidateQueries({ queryKey: ["mm", "aTokensBalances"] });
|
|
520
|
-
queryClient.invalidateQueries({ queryKey: ["mm", "allowance", params.srcChainKey, params.token, params.action] });
|
|
521
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", params.srcChainKey] });
|
|
522
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
523
|
-
}
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
function useSupply({
|
|
527
|
-
mutationOptions
|
|
528
|
-
} = {}) {
|
|
529
|
-
const { sodax } = useSodaxContext();
|
|
530
|
-
const queryClient = reactQuery.useQueryClient();
|
|
531
|
-
return useSafeMutation({
|
|
532
|
-
mutationKey: ["mm", "supply"],
|
|
533
|
-
...mutationOptions,
|
|
534
|
-
mutationFn: async (vars) => unwrapResult(await sodax.moneyMarket.supply({ ...vars, raw: false })),
|
|
535
|
-
onSuccess: async (data, vars, ctx) => {
|
|
536
|
-
const { params } = vars;
|
|
537
|
-
queryClient.invalidateQueries({ queryKey: ["mm", "userReservesData", params.srcChainKey, params.srcAddress] });
|
|
538
|
-
queryClient.invalidateQueries({
|
|
539
|
-
queryKey: ["mm", "userFormattedSummary", params.srcChainKey, params.srcAddress]
|
|
540
|
-
});
|
|
541
|
-
queryClient.invalidateQueries({ queryKey: ["mm", "aTokensBalances"] });
|
|
542
|
-
queryClient.invalidateQueries({ queryKey: ["mm", "allowance", params.srcChainKey, params.token, params.action] });
|
|
543
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", params.srcChainKey] });
|
|
544
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
function useWithdraw({
|
|
549
|
-
mutationOptions
|
|
550
|
-
} = {}) {
|
|
551
|
-
const { sodax } = useSodaxContext();
|
|
552
|
-
const queryClient = reactQuery.useQueryClient();
|
|
553
|
-
return useSafeMutation({
|
|
554
|
-
mutationKey: ["mm", "withdraw"],
|
|
555
|
-
...mutationOptions,
|
|
556
|
-
mutationFn: async (vars) => unwrapResult(await sodax.moneyMarket.withdraw({ ...vars, raw: false })),
|
|
557
|
-
onSuccess: async (data, vars, ctx) => {
|
|
558
|
-
const { params } = vars;
|
|
559
|
-
queryClient.invalidateQueries({ queryKey: ["mm", "userReservesData", params.srcChainKey, params.srcAddress] });
|
|
560
|
-
queryClient.invalidateQueries({
|
|
561
|
-
queryKey: ["mm", "userFormattedSummary", params.srcChainKey, params.srcAddress]
|
|
562
|
-
});
|
|
563
|
-
queryClient.invalidateQueries({ queryKey: ["mm", "aTokensBalances"] });
|
|
564
|
-
const balanceChains = /* @__PURE__ */ new Set([params.srcChainKey, params.dstChainKey ?? params.srcChainKey]);
|
|
565
|
-
for (const chainKey of balanceChains) {
|
|
566
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", chainKey] });
|
|
567
|
-
}
|
|
568
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
569
|
-
}
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
function useUserReservesData({
|
|
573
|
-
params,
|
|
574
|
-
queryOptions
|
|
575
|
-
} = {}) {
|
|
576
|
-
const { sodax } = useSodaxContext();
|
|
577
|
-
const spokeChainKey = params?.spokeChainKey;
|
|
578
|
-
const userAddress = params?.userAddress;
|
|
579
|
-
return reactQuery.useQuery({
|
|
580
|
-
queryKey: ["mm", "userReservesData", spokeChainKey, userAddress],
|
|
581
|
-
queryFn: async () => {
|
|
582
|
-
if (!spokeChainKey || !userAddress) {
|
|
583
|
-
throw new Error("spokeChainKey and userAddress are required");
|
|
584
|
-
}
|
|
585
|
-
return sodax.moneyMarket.data.getUserReservesData(spokeChainKey, userAddress);
|
|
586
|
-
},
|
|
587
|
-
enabled: !!spokeChainKey && !!userAddress,
|
|
588
|
-
refetchInterval: 5e3,
|
|
589
|
-
...queryOptions
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
function useReservesData({
|
|
593
|
-
queryOptions
|
|
594
|
-
} = {}) {
|
|
595
|
-
const { sodax } = useSodaxContext();
|
|
596
|
-
return reactQuery.useQuery({
|
|
597
|
-
queryKey: ["mm", "reservesData"],
|
|
598
|
-
queryFn: async () => sodax.moneyMarket.data.getReservesData(),
|
|
599
|
-
refetchInterval: 5e3,
|
|
600
|
-
...queryOptions
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
function useReservesHumanized({
|
|
604
|
-
queryOptions
|
|
605
|
-
} = {}) {
|
|
606
|
-
const { sodax } = useSodaxContext();
|
|
607
|
-
return reactQuery.useQuery({
|
|
608
|
-
queryKey: ["mm", "reservesHumanized"],
|
|
609
|
-
queryFn: async () => sodax.moneyMarket.data.getReservesHumanized(),
|
|
610
|
-
refetchInterval: 5e3,
|
|
611
|
-
...queryOptions
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
function useReservesList({
|
|
615
|
-
queryOptions
|
|
616
|
-
} = {}) {
|
|
617
|
-
const { sodax } = useSodaxContext();
|
|
618
|
-
return reactQuery.useQuery({
|
|
619
|
-
queryKey: ["mm", "reservesList"],
|
|
620
|
-
queryFn: async () => sodax.moneyMarket.data.getReservesList(),
|
|
621
|
-
...queryOptions
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
function useMMAllowance({
|
|
625
|
-
params,
|
|
626
|
-
queryOptions
|
|
627
|
-
} = {}) {
|
|
628
|
-
const { sodax } = useSodaxContext();
|
|
629
|
-
const payload = params?.payload;
|
|
630
|
-
return reactQuery.useQuery({
|
|
631
|
-
queryKey: ["mm", "allowance", payload?.srcChainKey, payload?.token, payload?.action],
|
|
632
|
-
queryFn: async () => {
|
|
633
|
-
if (!payload) {
|
|
634
|
-
throw new Error("Params are required");
|
|
635
|
-
}
|
|
636
|
-
if (payload.action === "borrow" || payload.action === "withdraw") {
|
|
637
|
-
return true;
|
|
638
|
-
}
|
|
639
|
-
const result = await sodax.moneyMarket.isAllowanceValid({ params: payload });
|
|
640
|
-
if (!result.ok) throw result.error;
|
|
641
|
-
return result.value;
|
|
642
|
-
},
|
|
643
|
-
enabled: !!payload && payload.action !== "borrow" && payload.action !== "withdraw",
|
|
644
|
-
refetchInterval: 5e3,
|
|
645
|
-
gcTime: 0,
|
|
646
|
-
...queryOptions
|
|
647
|
-
});
|
|
648
|
-
}
|
|
649
|
-
function useMMApprove({
|
|
650
|
-
mutationOptions
|
|
651
|
-
} = {}) {
|
|
652
|
-
const { sodax } = useSodaxContext();
|
|
653
|
-
const queryClient = reactQuery.useQueryClient();
|
|
654
|
-
return useSafeMutation({
|
|
655
|
-
mutationKey: ["mm", "approve"],
|
|
656
|
-
...mutationOptions,
|
|
657
|
-
mutationFn: async (vars) => unwrapResult(await sodax.moneyMarket.approve({ ...vars, raw: false })),
|
|
658
|
-
onSuccess: async (data, vars, ctx) => {
|
|
659
|
-
const { params } = vars;
|
|
660
|
-
queryClient.invalidateQueries({
|
|
661
|
-
queryKey: ["mm", "allowance", params.srcChainKey, params.token, params.action]
|
|
662
|
-
});
|
|
663
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
664
|
-
}
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
function useAToken({ params, queryOptions } = {}) {
|
|
668
|
-
const { sodax } = useSodaxContext();
|
|
669
|
-
const aToken = params?.aToken;
|
|
670
|
-
return reactQuery.useQuery({
|
|
671
|
-
queryKey: ["mm", "aToken", aToken],
|
|
672
|
-
queryFn: async () => {
|
|
673
|
-
if (!aToken) {
|
|
674
|
-
throw new Error("aToken address is required");
|
|
675
|
-
}
|
|
676
|
-
if (!viem.isAddress(aToken)) {
|
|
677
|
-
throw new Error("aToken address is not a valid address");
|
|
678
|
-
}
|
|
679
|
-
const aTokenData = await sodax.moneyMarket.data.getATokenData(aToken);
|
|
680
|
-
return {
|
|
681
|
-
...aTokenData,
|
|
682
|
-
chainKey: sodax.hubProvider.chainConfig.chain.key
|
|
683
|
-
};
|
|
684
|
-
},
|
|
685
|
-
enabled: !!aToken && viem.isAddress(aToken ?? ""),
|
|
686
|
-
...queryOptions
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
function useATokensBalances({
|
|
690
|
-
params,
|
|
691
|
-
queryOptions
|
|
692
|
-
} = {}) {
|
|
693
|
-
const { sodax } = useSodaxContext();
|
|
694
|
-
const aTokens = params?.aTokens ?? [];
|
|
695
|
-
const spokeChainKey = params?.spokeChainKey;
|
|
696
|
-
const userAddress = params?.userAddress;
|
|
697
|
-
return reactQuery.useQuery({
|
|
698
|
-
queryKey: ["mm", "aTokensBalances", aTokens, spokeChainKey, userAddress],
|
|
699
|
-
queryFn: async () => {
|
|
700
|
-
if (aTokens.length === 0) {
|
|
701
|
-
return /* @__PURE__ */ new Map();
|
|
702
|
-
}
|
|
703
|
-
if (!spokeChainKey || !userAddress) {
|
|
704
|
-
throw new Error("spokeChainKey and userAddress are required");
|
|
705
|
-
}
|
|
706
|
-
for (const aToken of aTokens) {
|
|
707
|
-
if (!viem.isAddress(aToken)) {
|
|
708
|
-
throw new Error(`Invalid aToken address: ${aToken}`);
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
const hubWalletAddress = await sodax.hubProvider.getUserHubWalletAddress(userAddress, spokeChainKey);
|
|
712
|
-
return sodax.moneyMarket.data.getATokensBalances(aTokens, hubWalletAddress);
|
|
713
|
-
},
|
|
714
|
-
enabled: aTokens.length > 0 && !!spokeChainKey && !!userAddress,
|
|
715
|
-
...queryOptions
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
function useReservesUsdFormat({
|
|
719
|
-
queryOptions
|
|
720
|
-
} = {}) {
|
|
721
|
-
const { sodax } = useSodaxContext();
|
|
722
|
-
return reactQuery.useQuery({
|
|
723
|
-
queryKey: ["mm", "reservesUsdFormat"],
|
|
724
|
-
queryFn: async () => {
|
|
725
|
-
const reserves = await sodax.moneyMarket.data.getReservesHumanized();
|
|
726
|
-
return sodax.moneyMarket.data.formatReservesUSD(sodax.moneyMarket.data.buildReserveDataWithPrice(reserves));
|
|
727
|
-
},
|
|
728
|
-
...queryOptions
|
|
729
|
-
});
|
|
730
|
-
}
|
|
731
|
-
function useUserFormattedSummary({
|
|
732
|
-
params,
|
|
733
|
-
queryOptions
|
|
734
|
-
} = {}) {
|
|
735
|
-
const { sodax } = useSodaxContext();
|
|
736
|
-
const spokeChainKey = params?.spokeChainKey;
|
|
737
|
-
const userAddress = params?.userAddress;
|
|
738
|
-
return reactQuery.useQuery({
|
|
739
|
-
queryKey: ["mm", "userFormattedSummary", spokeChainKey, userAddress],
|
|
740
|
-
queryFn: async () => {
|
|
741
|
-
if (!spokeChainKey || !userAddress) {
|
|
742
|
-
throw new Error("spokeChainKey and userAddress are required");
|
|
743
|
-
}
|
|
744
|
-
const [reserves, userReserves] = await Promise.all([
|
|
745
|
-
sodax.moneyMarket.data.getReservesHumanized(),
|
|
746
|
-
sodax.moneyMarket.data.getUserReservesHumanized(spokeChainKey, userAddress)
|
|
747
|
-
]);
|
|
748
|
-
const formattedReserves = sodax.moneyMarket.data.formatReservesUSD(
|
|
749
|
-
sodax.moneyMarket.data.buildReserveDataWithPrice(reserves)
|
|
750
|
-
);
|
|
751
|
-
return sodax.moneyMarket.data.formatUserSummary(
|
|
752
|
-
sodax.moneyMarket.data.buildUserSummaryRequest(reserves, formattedReserves, userReserves)
|
|
753
|
-
);
|
|
754
|
-
},
|
|
755
|
-
enabled: !!spokeChainKey && !!userAddress,
|
|
756
|
-
refetchInterval: 5e3,
|
|
757
|
-
...queryOptions
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
var useQuote = ({
|
|
761
|
-
params,
|
|
762
|
-
queryOptions
|
|
763
|
-
} = {}) => {
|
|
764
|
-
const { sodax } = useSodaxContext();
|
|
765
|
-
const payload = params?.payload;
|
|
766
|
-
return reactQuery.useQuery({
|
|
767
|
-
queryKey: ["swap", "quote", payload && { ...payload, amount: payload.amount.toString() }],
|
|
768
|
-
queryFn: async () => {
|
|
769
|
-
if (!payload) {
|
|
770
|
-
return void 0;
|
|
771
|
-
}
|
|
772
|
-
return sodax.swaps.getQuote(payload);
|
|
773
|
-
},
|
|
774
|
-
enabled: !!payload,
|
|
775
|
-
refetchInterval: 3e3,
|
|
776
|
-
...queryOptions
|
|
777
|
-
});
|
|
778
|
-
};
|
|
779
|
-
function useSwap({
|
|
780
|
-
mutationOptions
|
|
781
|
-
} = {}) {
|
|
782
|
-
const { sodax } = useSodaxContext();
|
|
783
|
-
const queryClient = reactQuery.useQueryClient();
|
|
784
|
-
return useSafeMutation({
|
|
785
|
-
mutationKey: ["swap"],
|
|
786
|
-
...mutationOptions,
|
|
787
|
-
mutationFn: async (vars) => unwrapResult(await sodax.swaps.swap({ ...vars, raw: false })),
|
|
788
|
-
onSuccess: async (data, vars, ctx) => {
|
|
789
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.srcChainKey] });
|
|
790
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.dstChainKey] });
|
|
791
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
var useStatus = ({
|
|
796
|
-
params,
|
|
797
|
-
queryOptions
|
|
798
|
-
} = {}) => {
|
|
799
|
-
const { sodax } = useSodaxContext();
|
|
800
|
-
const intentTxHash = params?.intentTxHash;
|
|
801
|
-
return reactQuery.useQuery({
|
|
802
|
-
queryKey: ["swap", "status", intentTxHash],
|
|
803
|
-
queryFn: async () => {
|
|
804
|
-
if (!intentTxHash) return void 0;
|
|
805
|
-
return sodax.swaps.getStatus({ intent_tx_hash: intentTxHash });
|
|
806
|
-
},
|
|
807
|
-
enabled: !!intentTxHash,
|
|
808
|
-
refetchInterval: 3e3,
|
|
809
|
-
...queryOptions
|
|
810
|
-
});
|
|
811
|
-
};
|
|
812
|
-
function useSwapAllowance({
|
|
813
|
-
params,
|
|
814
|
-
queryOptions
|
|
815
|
-
} = {}) {
|
|
816
|
-
const { sodax } = useSodaxContext();
|
|
817
|
-
const payload = params?.payload;
|
|
818
|
-
const srcChainKey = params?.srcChainKey;
|
|
819
|
-
const walletProvider = params?.walletProvider;
|
|
820
|
-
return reactQuery.useQuery({
|
|
821
|
-
// Extract the (chain, owner, token, amount) tuple that actually scopes the allowance —
|
|
822
|
-
// raw-object keys break per Rule 4 (bigints) and churn on every render.
|
|
823
|
-
queryKey: [
|
|
824
|
-
"swap",
|
|
825
|
-
"allowance",
|
|
826
|
-
payload?.srcChainKey,
|
|
827
|
-
payload?.srcAddress,
|
|
828
|
-
payload?.inputToken,
|
|
829
|
-
payload?.inputAmount?.toString()
|
|
830
|
-
],
|
|
831
|
-
queryFn: async () => {
|
|
832
|
-
if (!srcChainKey || !walletProvider || !payload) {
|
|
833
|
-
return false;
|
|
834
|
-
}
|
|
835
|
-
const allowance = await sodax.swaps.isAllowanceValid({
|
|
836
|
-
params: payload,
|
|
837
|
-
raw: false,
|
|
838
|
-
walletProvider
|
|
839
|
-
});
|
|
840
|
-
return allowance.ok ? allowance.value : false;
|
|
841
|
-
},
|
|
842
|
-
enabled: !!srcChainKey && !!walletProvider && !!payload,
|
|
843
|
-
refetchInterval: 2e3,
|
|
844
|
-
...queryOptions
|
|
845
|
-
});
|
|
846
|
-
}
|
|
847
|
-
function useSwapApprove({
|
|
848
|
-
mutationOptions
|
|
849
|
-
} = {}) {
|
|
850
|
-
const { sodax } = useSodaxContext();
|
|
851
|
-
const queryClient = reactQuery.useQueryClient();
|
|
852
|
-
return useSafeMutation({
|
|
853
|
-
mutationKey: ["swap", "approve"],
|
|
854
|
-
...mutationOptions,
|
|
855
|
-
mutationFn: async ({ params, walletProvider }) => unwrapResult(
|
|
856
|
-
await sodax.swaps.approve({
|
|
857
|
-
params,
|
|
858
|
-
raw: false,
|
|
859
|
-
walletProvider
|
|
860
|
-
})
|
|
861
|
-
),
|
|
862
|
-
onSuccess: async (data, vars, ctx) => {
|
|
863
|
-
queryClient.invalidateQueries({ queryKey: ["swap", "allowance"] });
|
|
864
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
865
|
-
}
|
|
866
|
-
});
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
// src/hooks/swap/useCancelSwap.ts
|
|
870
|
-
function useCancelSwap({
|
|
871
|
-
mutationOptions
|
|
872
|
-
} = {}) {
|
|
873
|
-
const { sodax } = useSodaxContext();
|
|
874
|
-
return useSafeMutation({
|
|
875
|
-
mutationKey: ["swap", "cancel"],
|
|
876
|
-
...mutationOptions,
|
|
877
|
-
mutationFn: async ({ srcChainKey, walletProvider, intent }) => unwrapResult(await sodax.swaps.cancelIntent({ params: { srcChainKey, intent }, walletProvider }))
|
|
878
|
-
});
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
// src/hooks/swap/useCreateLimitOrder.ts
|
|
882
|
-
function useCreateLimitOrder({
|
|
883
|
-
mutationOptions
|
|
884
|
-
} = {}) {
|
|
885
|
-
const { sodax } = useSodaxContext();
|
|
886
|
-
return useSafeMutation({
|
|
887
|
-
mutationKey: ["swap", "limitOrder", "create"],
|
|
888
|
-
...mutationOptions,
|
|
889
|
-
mutationFn: async (vars) => unwrapResult(await sodax.swaps.createLimitOrder({ ...vars, raw: false }))
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
// src/hooks/swap/useCancelLimitOrder.ts
|
|
894
|
-
function useCancelLimitOrder({
|
|
895
|
-
mutationOptions
|
|
896
|
-
} = {}) {
|
|
897
|
-
const { sodax } = useSodaxContext();
|
|
898
|
-
return useSafeMutation({
|
|
899
|
-
mutationKey: ["swap", "limitOrder", "cancel"],
|
|
900
|
-
...mutationOptions,
|
|
901
|
-
mutationFn: async ({ srcChainKey, walletProvider, intent, timeout }) => unwrapResult(await sodax.swaps.cancelLimitOrder({ params: { srcChainKey, intent }, walletProvider, timeout }))
|
|
902
|
-
});
|
|
903
|
-
}
|
|
904
|
-
var useBackendIntentByTxHash = ({
|
|
905
|
-
params,
|
|
906
|
-
queryOptions
|
|
907
|
-
} = {}) => {
|
|
908
|
-
const { sodax } = useSodaxContext();
|
|
909
|
-
const txHash = params?.txHash;
|
|
910
|
-
return reactQuery.useQuery({
|
|
911
|
-
queryKey: ["backend", "intent", "txHash", txHash],
|
|
912
|
-
queryFn: async () => {
|
|
913
|
-
if (!txHash) return void 0;
|
|
914
|
-
const result = await sodax.backendApi.getIntentByTxHash(txHash);
|
|
915
|
-
return result.ok ? result.value : void 0;
|
|
916
|
-
},
|
|
917
|
-
enabled: !!txHash && txHash.length > 0,
|
|
918
|
-
retry: 3,
|
|
919
|
-
refetchInterval: 1e3,
|
|
920
|
-
...queryOptions
|
|
921
|
-
});
|
|
922
|
-
};
|
|
923
|
-
var useBackendIntentByHash = ({
|
|
924
|
-
params,
|
|
925
|
-
queryOptions
|
|
926
|
-
} = {}) => {
|
|
927
|
-
const { sodax } = useSodaxContext();
|
|
928
|
-
const intentHash = params?.intentHash;
|
|
929
|
-
return reactQuery.useQuery({
|
|
930
|
-
queryKey: ["backend", "intent", "hash", intentHash],
|
|
931
|
-
queryFn: async () => {
|
|
932
|
-
if (!intentHash) return void 0;
|
|
933
|
-
const result = await sodax.backendApi.getIntentByHash(intentHash);
|
|
934
|
-
return result.ok ? result.value : void 0;
|
|
935
|
-
},
|
|
936
|
-
enabled: !!intentHash && intentHash.length > 0,
|
|
937
|
-
retry: 3,
|
|
938
|
-
...queryOptions
|
|
939
|
-
});
|
|
940
|
-
};
|
|
941
|
-
var useBackendUserIntents = ({
|
|
942
|
-
params,
|
|
943
|
-
queryOptions
|
|
944
|
-
} = {}) => {
|
|
945
|
-
const { sodax } = useSodaxContext();
|
|
946
|
-
const userAddress = params?.userAddress;
|
|
947
|
-
const startDate = params?.startDate;
|
|
948
|
-
const endDate = params?.endDate;
|
|
949
|
-
return reactQuery.useQuery({
|
|
950
|
-
queryKey: ["backend", "intent", "user", userAddress, startDate, endDate],
|
|
951
|
-
queryFn: async () => {
|
|
952
|
-
if (!userAddress) return void 0;
|
|
953
|
-
return unwrapResult(await sodax.backendApi.getUserIntents({ userAddress, startDate, endDate }));
|
|
954
|
-
},
|
|
955
|
-
enabled: !!userAddress && userAddress.length > 0,
|
|
956
|
-
retry: 3,
|
|
957
|
-
...queryOptions
|
|
958
|
-
});
|
|
959
|
-
};
|
|
960
|
-
|
|
961
|
-
// src/hooks/backend/useBackendSubmitSwapTx.ts
|
|
962
|
-
var useBackendSubmitSwapTx = ({
|
|
963
|
-
mutationOptions
|
|
964
|
-
} = {}) => {
|
|
965
|
-
const { sodax } = useSodaxContext();
|
|
966
|
-
return useSafeMutation({
|
|
967
|
-
mutationKey: ["backend", "submitSwapTx"],
|
|
968
|
-
retry: 3,
|
|
969
|
-
...mutationOptions,
|
|
970
|
-
mutationFn: async ({ request, apiConfig }) => unwrapResult(await sodax.backendApi.submitSwapTx(request, apiConfig))
|
|
971
|
-
});
|
|
972
|
-
};
|
|
973
|
-
var useBackendSubmitSwapTxStatus = ({
|
|
974
|
-
params,
|
|
975
|
-
queryOptions
|
|
976
|
-
} = {}) => {
|
|
977
|
-
const { sodax } = useSodaxContext();
|
|
978
|
-
const txHash = params?.txHash;
|
|
979
|
-
const srcChainKey = params?.srcChainKey;
|
|
980
|
-
const apiConfig = params?.apiConfig;
|
|
981
|
-
return reactQuery.useQuery({
|
|
982
|
-
queryKey: ["backend", "submitSwapTx", "status", txHash, srcChainKey],
|
|
983
|
-
queryFn: async () => {
|
|
984
|
-
if (!txHash) return void 0;
|
|
985
|
-
return unwrapResult(
|
|
986
|
-
await sodax.backendApi.getSubmitSwapTxStatus(
|
|
987
|
-
{
|
|
988
|
-
txHash,
|
|
989
|
-
srcChainKey
|
|
990
|
-
},
|
|
991
|
-
apiConfig
|
|
992
|
-
)
|
|
993
|
-
);
|
|
994
|
-
},
|
|
995
|
-
enabled: !!txHash && txHash.length > 0,
|
|
996
|
-
retry: 3,
|
|
997
|
-
refetchInterval: (query) => {
|
|
998
|
-
const status = query.state.data?.data?.status;
|
|
999
|
-
if (status === "executed" || status === "failed") return false;
|
|
1000
|
-
return 1e3;
|
|
1001
|
-
},
|
|
1002
|
-
...queryOptions
|
|
1003
|
-
});
|
|
1004
|
-
};
|
|
1005
|
-
var useBackendOrderbook = ({
|
|
1006
|
-
params,
|
|
1007
|
-
queryOptions
|
|
1008
|
-
} = {}) => {
|
|
1009
|
-
const { sodax } = useSodaxContext();
|
|
1010
|
-
const pagination = params?.pagination;
|
|
1011
|
-
return reactQuery.useQuery({
|
|
1012
|
-
queryKey: ["backend", "orderbook", pagination?.offset, pagination?.limit],
|
|
1013
|
-
queryFn: async () => {
|
|
1014
|
-
if (!pagination?.offset || !pagination?.limit) {
|
|
1015
|
-
throw new Error("Pagination offset and limit are required");
|
|
1016
|
-
}
|
|
1017
|
-
return unwrapResult(await sodax.backendApi.getOrderbook(pagination));
|
|
1018
|
-
},
|
|
1019
|
-
enabled: !!pagination?.offset && !!pagination?.limit,
|
|
1020
|
-
staleTime: 30 * 1e3,
|
|
1021
|
-
retry: 3,
|
|
1022
|
-
...queryOptions
|
|
1023
|
-
});
|
|
1024
|
-
};
|
|
1025
|
-
var useBackendMoneyMarketPosition = ({
|
|
1026
|
-
params,
|
|
1027
|
-
queryOptions
|
|
1028
|
-
} = {}) => {
|
|
1029
|
-
const { sodax } = useSodaxContext();
|
|
1030
|
-
const userAddress = params?.userAddress;
|
|
1031
|
-
return reactQuery.useQuery({
|
|
1032
|
-
queryKey: ["backend", "mm", "position", userAddress],
|
|
1033
|
-
queryFn: async () => {
|
|
1034
|
-
if (!userAddress) return void 0;
|
|
1035
|
-
return unwrapResult(await sodax.backendApi.getMoneyMarketPosition(userAddress));
|
|
1036
|
-
},
|
|
1037
|
-
enabled: !!userAddress && userAddress.length > 0,
|
|
1038
|
-
retry: 3,
|
|
1039
|
-
...queryOptions
|
|
1040
|
-
});
|
|
1041
|
-
};
|
|
1042
|
-
var useBackendAllMoneyMarketAssets = ({
|
|
1043
|
-
queryOptions
|
|
1044
|
-
} = {}) => {
|
|
1045
|
-
const { sodax } = useSodaxContext();
|
|
1046
|
-
return reactQuery.useQuery({
|
|
1047
|
-
queryKey: ["backend", "mm", "assets", "all"],
|
|
1048
|
-
queryFn: async () => {
|
|
1049
|
-
return unwrapResult(await sodax.backendApi.getAllMoneyMarketAssets());
|
|
1050
|
-
},
|
|
1051
|
-
retry: 3,
|
|
1052
|
-
...queryOptions
|
|
1053
|
-
});
|
|
1054
|
-
};
|
|
1055
|
-
var useBackendMoneyMarketAsset = ({
|
|
1056
|
-
params,
|
|
1057
|
-
queryOptions
|
|
1058
|
-
} = {}) => {
|
|
1059
|
-
const { sodax } = useSodaxContext();
|
|
1060
|
-
const reserveAddress = params?.reserveAddress;
|
|
1061
|
-
return reactQuery.useQuery({
|
|
1062
|
-
queryKey: ["backend", "mm", "asset", reserveAddress],
|
|
1063
|
-
queryFn: async () => {
|
|
1064
|
-
if (!reserveAddress) return void 0;
|
|
1065
|
-
return unwrapResult(await sodax.backendApi.getMoneyMarketAsset(reserveAddress));
|
|
1066
|
-
},
|
|
1067
|
-
enabled: !!reserveAddress && reserveAddress.length > 0,
|
|
1068
|
-
retry: 3,
|
|
1069
|
-
...queryOptions
|
|
1070
|
-
});
|
|
1071
|
-
};
|
|
1072
|
-
var useBackendMoneyMarketAssetBorrowers = ({
|
|
1073
|
-
params,
|
|
1074
|
-
queryOptions
|
|
1075
|
-
} = {}) => {
|
|
1076
|
-
const { sodax } = useSodaxContext();
|
|
1077
|
-
const reserveAddress = params?.reserveAddress;
|
|
1078
|
-
const pagination = params?.pagination;
|
|
1079
|
-
return reactQuery.useQuery({
|
|
1080
|
-
queryKey: ["backend", "mm", "asset", "borrowers", reserveAddress, pagination],
|
|
1081
|
-
queryFn: async () => {
|
|
1082
|
-
if (!reserveAddress || !pagination?.offset || !pagination?.limit) {
|
|
1083
|
-
return void 0;
|
|
1084
|
-
}
|
|
1085
|
-
return unwrapResult(
|
|
1086
|
-
await sodax.backendApi.getMoneyMarketAssetBorrowers(reserveAddress, {
|
|
1087
|
-
offset: pagination.offset,
|
|
1088
|
-
limit: pagination.limit
|
|
1089
|
-
})
|
|
1090
|
-
);
|
|
1091
|
-
},
|
|
1092
|
-
enabled: !!reserveAddress && !!pagination?.offset && !!pagination?.limit,
|
|
1093
|
-
retry: 3,
|
|
1094
|
-
...queryOptions
|
|
1095
|
-
});
|
|
1096
|
-
};
|
|
1097
|
-
var useBackendMoneyMarketAssetSuppliers = ({
|
|
1098
|
-
params,
|
|
1099
|
-
queryOptions
|
|
1100
|
-
} = {}) => {
|
|
1101
|
-
const { sodax } = useSodaxContext();
|
|
1102
|
-
const reserveAddress = params?.reserveAddress;
|
|
1103
|
-
const pagination = params?.pagination;
|
|
1104
|
-
return reactQuery.useQuery({
|
|
1105
|
-
queryKey: ["backend", "mm", "asset", "suppliers", reserveAddress, pagination],
|
|
1106
|
-
queryFn: async () => {
|
|
1107
|
-
if (!reserveAddress || !pagination?.offset || !pagination?.limit) {
|
|
1108
|
-
return void 0;
|
|
1109
|
-
}
|
|
1110
|
-
return unwrapResult(
|
|
1111
|
-
await sodax.backendApi.getMoneyMarketAssetSuppliers(reserveAddress, {
|
|
1112
|
-
offset: pagination.offset,
|
|
1113
|
-
limit: pagination.limit
|
|
1114
|
-
})
|
|
1115
|
-
);
|
|
1116
|
-
},
|
|
1117
|
-
enabled: !!reserveAddress && !!pagination?.offset && !!pagination?.limit,
|
|
1118
|
-
retry: 3,
|
|
1119
|
-
...queryOptions
|
|
1120
|
-
});
|
|
1121
|
-
};
|
|
1122
|
-
var useBackendAllMoneyMarketBorrowers = ({
|
|
1123
|
-
params,
|
|
1124
|
-
queryOptions
|
|
1125
|
-
} = {}) => {
|
|
1126
|
-
const { sodax } = useSodaxContext();
|
|
1127
|
-
const pagination = params?.pagination;
|
|
1128
|
-
return reactQuery.useQuery({
|
|
1129
|
-
queryKey: ["backend", "mm", "borrowers", "all", pagination],
|
|
1130
|
-
queryFn: async () => {
|
|
1131
|
-
if (!pagination?.offset || !pagination?.limit) {
|
|
1132
|
-
return void 0;
|
|
1133
|
-
}
|
|
1134
|
-
return unwrapResult(
|
|
1135
|
-
await sodax.backendApi.getAllMoneyMarketBorrowers({
|
|
1136
|
-
offset: pagination.offset,
|
|
1137
|
-
limit: pagination.limit
|
|
1138
|
-
})
|
|
1139
|
-
);
|
|
1140
|
-
},
|
|
1141
|
-
enabled: !!pagination?.offset && !!pagination?.limit,
|
|
1142
|
-
retry: 3,
|
|
1143
|
-
...queryOptions
|
|
1144
|
-
});
|
|
1145
|
-
};
|
|
1146
|
-
function useBridge({
|
|
1147
|
-
mutationOptions
|
|
1148
|
-
} = {}) {
|
|
1149
|
-
const { sodax } = useSodaxContext();
|
|
1150
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1151
|
-
return useSafeMutation({
|
|
1152
|
-
mutationKey: ["bridge"],
|
|
1153
|
-
...mutationOptions,
|
|
1154
|
-
mutationFn: async (vars) => unwrapResult(await sodax.bridge.bridge({ ...vars, raw: false })),
|
|
1155
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1156
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.srcChainKey] });
|
|
1157
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.dstChainKey] });
|
|
1158
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1159
|
-
}
|
|
1160
|
-
});
|
|
1161
|
-
}
|
|
1162
|
-
function useBridgeAllowance({
|
|
1163
|
-
params,
|
|
1164
|
-
queryOptions
|
|
1165
|
-
} = {}) {
|
|
1166
|
-
const { sodax } = useSodaxContext();
|
|
1167
|
-
const payload = params?.payload;
|
|
1168
|
-
const walletProvider = params?.walletProvider;
|
|
1169
|
-
return reactQuery.useQuery({
|
|
1170
|
-
// Extract the (chain, owner, token, amount) tuple that actually scopes the allowance —
|
|
1171
|
-
// raw-object keys break per Rule 4 (bigints) and churn on every render.
|
|
1172
|
-
queryKey: [
|
|
1173
|
-
"bridge",
|
|
1174
|
-
"allowance",
|
|
1175
|
-
payload?.srcChainKey,
|
|
1176
|
-
payload?.srcAddress,
|
|
1177
|
-
payload?.srcToken,
|
|
1178
|
-
payload?.amount?.toString()
|
|
1179
|
-
],
|
|
1180
|
-
queryFn: async () => {
|
|
1181
|
-
if (!payload || !walletProvider) {
|
|
1182
|
-
return false;
|
|
1183
|
-
}
|
|
1184
|
-
const result = await sodax.bridge.isAllowanceValid({
|
|
1185
|
-
params: payload,
|
|
1186
|
-
raw: false,
|
|
1187
|
-
walletProvider
|
|
1188
|
-
});
|
|
1189
|
-
return result.ok ? result.value : false;
|
|
1190
|
-
},
|
|
1191
|
-
enabled: !!payload && !!walletProvider,
|
|
1192
|
-
refetchInterval: 2e3,
|
|
1193
|
-
gcTime: 0,
|
|
1194
|
-
...queryOptions
|
|
1195
|
-
});
|
|
1196
|
-
}
|
|
1197
|
-
function useBridgeApprove({
|
|
1198
|
-
mutationOptions
|
|
1199
|
-
} = {}) {
|
|
1200
|
-
const { sodax } = useSodaxContext();
|
|
1201
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1202
|
-
return useSafeMutation({
|
|
1203
|
-
mutationKey: ["bridge", "approve"],
|
|
1204
|
-
...mutationOptions,
|
|
1205
|
-
mutationFn: async (vars) => unwrapResult(await sodax.bridge.approve({ ...vars, raw: false })),
|
|
1206
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1207
|
-
queryClient.invalidateQueries({ queryKey: ["bridge", "allowance"] });
|
|
1208
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1209
|
-
}
|
|
1210
|
-
});
|
|
1211
|
-
}
|
|
1212
|
-
function useGetBridgeableAmount({
|
|
1213
|
-
params,
|
|
1214
|
-
queryOptions
|
|
1215
|
-
} = {}) {
|
|
1216
|
-
const { sodax } = useSodaxContext();
|
|
1217
|
-
const from = params?.from;
|
|
1218
|
-
const to = params?.to;
|
|
1219
|
-
return reactQuery.useQuery({
|
|
1220
|
-
queryKey: ["bridge", "bridgeableAmount", from, to],
|
|
1221
|
-
queryFn: async () => {
|
|
1222
|
-
if (!from || !to) {
|
|
1223
|
-
throw new Error("from and to tokens are required");
|
|
1224
|
-
}
|
|
1225
|
-
const result = await sodax.bridge.getBridgeableAmount(from, to);
|
|
1226
|
-
if (!result.ok) {
|
|
1227
|
-
throw result.error;
|
|
1228
|
-
}
|
|
1229
|
-
return result.value;
|
|
1230
|
-
},
|
|
1231
|
-
enabled: !!from && !!to,
|
|
1232
|
-
...queryOptions
|
|
1233
|
-
});
|
|
1234
|
-
}
|
|
1235
|
-
function useGetBridgeableTokens({
|
|
1236
|
-
params,
|
|
1237
|
-
queryOptions
|
|
1238
|
-
} = {}) {
|
|
1239
|
-
const { sodax } = useSodaxContext();
|
|
1240
|
-
const from = params?.from;
|
|
1241
|
-
const to = params?.to;
|
|
1242
|
-
const token = params?.token;
|
|
1243
|
-
return reactQuery.useQuery({
|
|
1244
|
-
queryKey: ["bridge", "bridgeableTokens", from, to, token],
|
|
1245
|
-
queryFn: () => {
|
|
1246
|
-
if (!from || !to || !token) {
|
|
1247
|
-
throw new Error("from, to and token are required");
|
|
1248
|
-
}
|
|
1249
|
-
const result = sodax.bridge.getBridgeableTokens(from, to, token);
|
|
1250
|
-
if (!result.ok) {
|
|
1251
|
-
throw result.error;
|
|
1252
|
-
}
|
|
1253
|
-
return result.value;
|
|
1254
|
-
},
|
|
1255
|
-
enabled: !!from && !!to && !!token,
|
|
1256
|
-
...queryOptions
|
|
1257
|
-
});
|
|
1258
|
-
}
|
|
1259
|
-
function useStake({
|
|
1260
|
-
mutationOptions
|
|
1261
|
-
} = {}) {
|
|
1262
|
-
const { sodax } = useSodaxContext();
|
|
1263
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1264
|
-
return useSafeMutation({
|
|
1265
|
-
mutationKey: ["staking", "stake"],
|
|
1266
|
-
...mutationOptions,
|
|
1267
|
-
mutationFn: async (vars) => unwrapResult(await sodax.staking.stake({ ...vars, raw: false })),
|
|
1268
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1269
|
-
const { params } = vars;
|
|
1270
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "info", params.srcChainKey, params.srcAddress] });
|
|
1271
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "allowance", params.srcChainKey, "stake"] });
|
|
1272
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "stakeRatio"] });
|
|
1273
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "convertedAssets"] });
|
|
1274
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", params.srcChainKey] });
|
|
1275
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1276
|
-
}
|
|
1277
|
-
});
|
|
1278
|
-
}
|
|
1279
|
-
function useStakeApprove({
|
|
1280
|
-
mutationOptions
|
|
1281
|
-
} = {}) {
|
|
1282
|
-
const { sodax } = useSodaxContext();
|
|
1283
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1284
|
-
return useSafeMutation({
|
|
1285
|
-
mutationKey: ["staking", "approve", "stake"],
|
|
1286
|
-
...mutationOptions,
|
|
1287
|
-
mutationFn: async ({ params, walletProvider }) => unwrapResult(
|
|
1288
|
-
await sodax.staking.approve({
|
|
1289
|
-
params: { ...params, action: "stake" },
|
|
1290
|
-
raw: false,
|
|
1291
|
-
walletProvider
|
|
1292
|
-
})
|
|
1293
|
-
),
|
|
1294
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1295
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "allowance", vars.params.srcChainKey, "stake"] });
|
|
1296
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1297
|
-
}
|
|
1298
|
-
});
|
|
1299
|
-
}
|
|
1300
|
-
function useStakeAllowance({
|
|
1301
|
-
params,
|
|
1302
|
-
queryOptions
|
|
1303
|
-
} = {}) {
|
|
1304
|
-
const { sodax } = useSodaxContext();
|
|
1305
|
-
const payload = params?.payload;
|
|
1306
|
-
return reactQuery.useQuery({
|
|
1307
|
-
queryKey: ["staking", "allowance", payload?.srcChainKey, "stake", payload?.srcAddress, payload?.amount?.toString()],
|
|
1308
|
-
queryFn: async () => {
|
|
1309
|
-
if (!payload) {
|
|
1310
|
-
throw new Error("Params are required");
|
|
1311
|
-
}
|
|
1312
|
-
const result = await sodax.staking.isAllowanceValid({
|
|
1313
|
-
params: { ...payload, action: "stake" },
|
|
1314
|
-
raw: true
|
|
1315
|
-
});
|
|
1316
|
-
if (!result.ok) throw result.error;
|
|
1317
|
-
return result.value;
|
|
1318
|
-
},
|
|
1319
|
-
enabled: !!payload,
|
|
1320
|
-
refetchInterval: 5e3,
|
|
1321
|
-
gcTime: 0,
|
|
1322
|
-
...queryOptions
|
|
1323
|
-
});
|
|
1324
|
-
}
|
|
1325
|
-
function useUnstake({
|
|
1326
|
-
mutationOptions
|
|
1327
|
-
} = {}) {
|
|
1328
|
-
const { sodax } = useSodaxContext();
|
|
1329
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1330
|
-
return useSafeMutation({
|
|
1331
|
-
mutationKey: ["staking", "unstake"],
|
|
1332
|
-
...mutationOptions,
|
|
1333
|
-
mutationFn: async (vars) => unwrapResult(await sodax.staking.unstake({ ...vars, raw: false })),
|
|
1334
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1335
|
-
const { params } = vars;
|
|
1336
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "info", params.srcChainKey, params.srcAddress] });
|
|
1337
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "unstakingInfo", params.srcChainKey, params.srcAddress] });
|
|
1338
|
-
queryClient.invalidateQueries({
|
|
1339
|
-
queryKey: ["staking", "unstakingInfoWithPenalty", params.srcChainKey, params.srcAddress]
|
|
1340
|
-
});
|
|
1341
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "allowance", params.srcChainKey, "unstake"] });
|
|
1342
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1343
|
-
}
|
|
1344
|
-
});
|
|
1345
|
-
}
|
|
1346
|
-
function useClaim({
|
|
1347
|
-
mutationOptions
|
|
1348
|
-
} = {}) {
|
|
1349
|
-
const { sodax } = useSodaxContext();
|
|
1350
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1351
|
-
return useSafeMutation({
|
|
1352
|
-
mutationKey: ["staking", "claim"],
|
|
1353
|
-
...mutationOptions,
|
|
1354
|
-
mutationFn: async (vars) => unwrapResult(await sodax.staking.claim({ ...vars, raw: false })),
|
|
1355
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1356
|
-
const { params } = vars;
|
|
1357
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "unstakingInfo", params.srcChainKey, params.srcAddress] });
|
|
1358
|
-
queryClient.invalidateQueries({
|
|
1359
|
-
queryKey: ["staking", "unstakingInfoWithPenalty", params.srcChainKey, params.srcAddress]
|
|
1360
|
-
});
|
|
1361
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", params.srcChainKey] });
|
|
1362
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1363
|
-
}
|
|
1364
|
-
});
|
|
1365
|
-
}
|
|
1366
|
-
function useCancelUnstake({
|
|
1367
|
-
mutationOptions
|
|
1368
|
-
} = {}) {
|
|
1369
|
-
const { sodax } = useSodaxContext();
|
|
1370
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1371
|
-
return useSafeMutation({
|
|
1372
|
-
mutationKey: ["staking", "cancelUnstake"],
|
|
1373
|
-
...mutationOptions,
|
|
1374
|
-
mutationFn: async (vars) => unwrapResult(await sodax.staking.cancelUnstake({ ...vars, raw: false })),
|
|
1375
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1376
|
-
const { params } = vars;
|
|
1377
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "unstakingInfo", params.srcChainKey, params.srcAddress] });
|
|
1378
|
-
queryClient.invalidateQueries({
|
|
1379
|
-
queryKey: ["staking", "unstakingInfoWithPenalty", params.srcChainKey, params.srcAddress]
|
|
1380
|
-
});
|
|
1381
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "info", params.srcChainKey, params.srcAddress] });
|
|
1382
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1383
|
-
}
|
|
1384
|
-
});
|
|
1385
|
-
}
|
|
1386
|
-
function useStakingInfo({ params, queryOptions } = {}) {
|
|
1387
|
-
const { sodax } = useSodaxContext();
|
|
1388
|
-
const srcAddress = params?.srcAddress;
|
|
1389
|
-
const srcChainKey = params?.srcChainKey;
|
|
1390
|
-
return reactQuery.useQuery({
|
|
1391
|
-
queryKey: ["staking", "info", srcChainKey, srcAddress],
|
|
1392
|
-
queryFn: async () => {
|
|
1393
|
-
if (!srcAddress || !srcChainKey) {
|
|
1394
|
-
throw new Error("srcAddress and srcChainKey are required");
|
|
1395
|
-
}
|
|
1396
|
-
const result = await sodax.staking.getStakingInfoFromSpoke(srcAddress, srcChainKey);
|
|
1397
|
-
if (!result.ok) throw result.error;
|
|
1398
|
-
return result.value;
|
|
1399
|
-
},
|
|
1400
|
-
enabled: !!srcAddress && !!srcChainKey,
|
|
1401
|
-
refetchInterval: 5e3,
|
|
1402
|
-
...queryOptions
|
|
1403
|
-
});
|
|
1404
|
-
}
|
|
1405
|
-
function useUnstakingInfoWithPenalty({
|
|
1406
|
-
params,
|
|
1407
|
-
queryOptions
|
|
1408
|
-
} = {}) {
|
|
1409
|
-
const { sodax } = useSodaxContext();
|
|
1410
|
-
const srcAddress = params?.srcAddress;
|
|
1411
|
-
const srcChainKey = params?.srcChainKey;
|
|
1412
|
-
return reactQuery.useQuery({
|
|
1413
|
-
queryKey: ["staking", "unstakingInfoWithPenalty", srcChainKey, srcAddress],
|
|
1414
|
-
queryFn: async () => {
|
|
1415
|
-
if (!srcAddress || !srcChainKey) {
|
|
1416
|
-
throw new Error("srcAddress and srcChainKey are required");
|
|
1417
|
-
}
|
|
1418
|
-
const result = await sodax.staking.getUnstakingInfoWithPenalty(srcAddress, srcChainKey);
|
|
1419
|
-
if (!result.ok) throw result.error;
|
|
1420
|
-
return result.value;
|
|
1421
|
-
},
|
|
1422
|
-
enabled: !!srcAddress && !!srcChainKey,
|
|
1423
|
-
refetchInterval: 5e3,
|
|
1424
|
-
...queryOptions
|
|
1425
|
-
});
|
|
1426
|
-
}
|
|
1427
|
-
function useStakingConfig({
|
|
1428
|
-
queryOptions
|
|
1429
|
-
} = {}) {
|
|
1430
|
-
const { sodax } = useSodaxContext();
|
|
1431
|
-
return reactQuery.useQuery({
|
|
1432
|
-
queryKey: ["staking", "config"],
|
|
1433
|
-
queryFn: async () => {
|
|
1434
|
-
const result = await sodax.staking.getStakingConfig();
|
|
1435
|
-
if (!result.ok) throw result.error;
|
|
1436
|
-
return result.value;
|
|
1437
|
-
},
|
|
1438
|
-
staleTime: Number.POSITIVE_INFINITY,
|
|
1439
|
-
...queryOptions
|
|
1440
|
-
});
|
|
1441
|
-
}
|
|
1442
|
-
function useStakeRatio({
|
|
1443
|
-
params,
|
|
1444
|
-
queryOptions
|
|
1445
|
-
} = {}) {
|
|
1446
|
-
const { sodax } = useSodaxContext();
|
|
1447
|
-
const amount = params?.amount;
|
|
1448
|
-
return reactQuery.useQuery({
|
|
1449
|
-
queryKey: ["staking", "stakeRatio", amount?.toString()],
|
|
1450
|
-
queryFn: async () => {
|
|
1451
|
-
if (amount === void 0) {
|
|
1452
|
-
throw new Error("amount is required");
|
|
1453
|
-
}
|
|
1454
|
-
const result = await sodax.staking.getStakeRatio(amount);
|
|
1455
|
-
if (!result.ok) throw result.error;
|
|
1456
|
-
return result.value;
|
|
1457
|
-
},
|
|
1458
|
-
enabled: amount !== void 0,
|
|
1459
|
-
refetchInterval: 1e4,
|
|
1460
|
-
...queryOptions
|
|
1461
|
-
});
|
|
1462
|
-
}
|
|
1463
|
-
function useInstantUnstakeRatio({
|
|
1464
|
-
params,
|
|
1465
|
-
queryOptions
|
|
1466
|
-
} = {}) {
|
|
1467
|
-
const { sodax } = useSodaxContext();
|
|
1468
|
-
const amount = params?.amount;
|
|
1469
|
-
return reactQuery.useQuery({
|
|
1470
|
-
queryKey: ["staking", "instantUnstakeRatio", amount?.toString()],
|
|
1471
|
-
queryFn: async () => {
|
|
1472
|
-
if (amount === void 0) {
|
|
1473
|
-
throw new Error("amount is required");
|
|
1474
|
-
}
|
|
1475
|
-
const result = await sodax.staking.getInstantUnstakeRatio(amount);
|
|
1476
|
-
if (!result.ok) throw result.error;
|
|
1477
|
-
return result.value;
|
|
1478
|
-
},
|
|
1479
|
-
enabled: amount !== void 0,
|
|
1480
|
-
refetchInterval: 1e4,
|
|
1481
|
-
...queryOptions
|
|
1482
|
-
});
|
|
1483
|
-
}
|
|
1484
|
-
function useConvertedAssets({
|
|
1485
|
-
params,
|
|
1486
|
-
queryOptions
|
|
1487
|
-
} = {}) {
|
|
1488
|
-
const { sodax } = useSodaxContext();
|
|
1489
|
-
const amount = params?.amount;
|
|
1490
|
-
return reactQuery.useQuery({
|
|
1491
|
-
queryKey: ["staking", "convertedAssets", amount?.toString()],
|
|
1492
|
-
queryFn: async () => {
|
|
1493
|
-
if (amount === void 0) {
|
|
1494
|
-
throw new Error("amount is required");
|
|
1495
|
-
}
|
|
1496
|
-
const result = await sodax.staking.getConvertedAssets(amount);
|
|
1497
|
-
if (!result.ok) throw result.error;
|
|
1498
|
-
return result.value;
|
|
1499
|
-
},
|
|
1500
|
-
enabled: amount !== void 0,
|
|
1501
|
-
refetchInterval: 1e4,
|
|
1502
|
-
...queryOptions
|
|
1503
|
-
});
|
|
1504
|
-
}
|
|
1505
|
-
function useInstantUnstake({
|
|
1506
|
-
mutationOptions
|
|
1507
|
-
} = {}) {
|
|
1508
|
-
const { sodax } = useSodaxContext();
|
|
1509
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1510
|
-
return useSafeMutation({
|
|
1511
|
-
mutationKey: ["staking", "instantUnstake"],
|
|
1512
|
-
...mutationOptions,
|
|
1513
|
-
mutationFn: async (vars) => unwrapResult(await sodax.staking.instantUnstake({ ...vars, raw: false })),
|
|
1514
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1515
|
-
const { params } = vars;
|
|
1516
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "info", params.srcChainKey, params.srcAddress] });
|
|
1517
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "instantUnstakeRatio"] });
|
|
1518
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "allowance", params.srcChainKey, "instantUnstake"] });
|
|
1519
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", params.srcChainKey] });
|
|
1520
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1521
|
-
}
|
|
1522
|
-
});
|
|
1523
|
-
}
|
|
1524
|
-
function useUnstakeAllowance({
|
|
1525
|
-
params,
|
|
1526
|
-
queryOptions
|
|
1527
|
-
} = {}) {
|
|
1528
|
-
const { sodax } = useSodaxContext();
|
|
1529
|
-
const payload = params?.payload;
|
|
1530
|
-
return reactQuery.useQuery({
|
|
1531
|
-
queryKey: [
|
|
1532
|
-
"staking",
|
|
1533
|
-
"allowance",
|
|
1534
|
-
payload?.srcChainKey,
|
|
1535
|
-
"unstake",
|
|
1536
|
-
payload?.srcAddress,
|
|
1537
|
-
payload?.amount?.toString()
|
|
1538
|
-
],
|
|
1539
|
-
queryFn: async () => {
|
|
1540
|
-
if (!payload) {
|
|
1541
|
-
throw new Error("Params are required");
|
|
1542
|
-
}
|
|
1543
|
-
const result = await sodax.staking.isAllowanceValid({
|
|
1544
|
-
params: { ...payload, action: "unstake" },
|
|
1545
|
-
raw: true
|
|
1546
|
-
});
|
|
1547
|
-
if (!result.ok) throw result.error;
|
|
1548
|
-
return result.value;
|
|
1549
|
-
},
|
|
1550
|
-
enabled: !!payload,
|
|
1551
|
-
refetchInterval: 5e3,
|
|
1552
|
-
gcTime: 0,
|
|
1553
|
-
...queryOptions
|
|
1554
|
-
});
|
|
1555
|
-
}
|
|
1556
|
-
function useUnstakeApprove({
|
|
1557
|
-
mutationOptions
|
|
1558
|
-
} = {}) {
|
|
1559
|
-
const { sodax } = useSodaxContext();
|
|
1560
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1561
|
-
return useSafeMutation({
|
|
1562
|
-
mutationKey: ["staking", "approve", "unstake"],
|
|
1563
|
-
...mutationOptions,
|
|
1564
|
-
mutationFn: async ({ params, walletProvider }) => unwrapResult(
|
|
1565
|
-
await sodax.staking.approve({
|
|
1566
|
-
params: { ...params, action: "unstake" },
|
|
1567
|
-
raw: false,
|
|
1568
|
-
walletProvider
|
|
1569
|
-
})
|
|
1570
|
-
),
|
|
1571
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1572
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "allowance", vars.params.srcChainKey, "unstake"] });
|
|
1573
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1574
|
-
}
|
|
1575
|
-
});
|
|
1576
|
-
}
|
|
1577
|
-
function useUnstakingInfo({
|
|
1578
|
-
params,
|
|
1579
|
-
queryOptions
|
|
1580
|
-
} = {}) {
|
|
1581
|
-
const { sodax } = useSodaxContext();
|
|
1582
|
-
const srcAddress = params?.srcAddress;
|
|
1583
|
-
const srcChainKey = params?.srcChainKey;
|
|
1584
|
-
return reactQuery.useQuery({
|
|
1585
|
-
queryKey: ["staking", "unstakingInfo", srcChainKey, srcAddress],
|
|
1586
|
-
queryFn: async () => {
|
|
1587
|
-
if (!srcAddress || !srcChainKey) {
|
|
1588
|
-
throw new Error("srcAddress and srcChainKey are required");
|
|
1589
|
-
}
|
|
1590
|
-
const result = await sodax.staking.getUnstakingInfo(srcAddress, srcChainKey);
|
|
1591
|
-
if (!result.ok) throw result.error;
|
|
1592
|
-
return result.value;
|
|
1593
|
-
},
|
|
1594
|
-
enabled: !!srcAddress && !!srcChainKey,
|
|
1595
|
-
refetchInterval: 5e3,
|
|
1596
|
-
...queryOptions
|
|
1597
|
-
});
|
|
1598
|
-
}
|
|
1599
|
-
function useInstantUnstakeApprove({
|
|
1600
|
-
mutationOptions
|
|
1601
|
-
} = {}) {
|
|
1602
|
-
const { sodax } = useSodaxContext();
|
|
1603
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1604
|
-
return useSafeMutation({
|
|
1605
|
-
mutationKey: ["staking", "approve", "instantUnstake"],
|
|
1606
|
-
...mutationOptions,
|
|
1607
|
-
mutationFn: async ({ params, walletProvider }) => unwrapResult(
|
|
1608
|
-
await sodax.staking.approve({
|
|
1609
|
-
params: { ...params, action: "instantUnstake" },
|
|
1610
|
-
raw: false,
|
|
1611
|
-
walletProvider
|
|
1612
|
-
})
|
|
1613
|
-
),
|
|
1614
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1615
|
-
queryClient.invalidateQueries({
|
|
1616
|
-
queryKey: ["staking", "allowance", vars.params.srcChainKey, "instantUnstake"]
|
|
1617
|
-
});
|
|
1618
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1619
|
-
}
|
|
1620
|
-
});
|
|
1621
|
-
}
|
|
1622
|
-
function useInstantUnstakeAllowance({
|
|
1623
|
-
params,
|
|
1624
|
-
queryOptions
|
|
1625
|
-
} = {}) {
|
|
1626
|
-
const { sodax } = useSodaxContext();
|
|
1627
|
-
const payload = params?.payload;
|
|
1628
|
-
return reactQuery.useQuery({
|
|
1629
|
-
queryKey: [
|
|
1630
|
-
"staking",
|
|
1631
|
-
"allowance",
|
|
1632
|
-
payload?.srcChainKey,
|
|
1633
|
-
"instantUnstake",
|
|
1634
|
-
payload?.srcAddress,
|
|
1635
|
-
payload?.amount?.toString()
|
|
1636
|
-
],
|
|
1637
|
-
queryFn: async () => {
|
|
1638
|
-
if (!payload) {
|
|
1639
|
-
throw new Error("Params are required");
|
|
1640
|
-
}
|
|
1641
|
-
const result = await sodax.staking.isAllowanceValid({
|
|
1642
|
-
params: { ...payload, action: "instantUnstake" },
|
|
1643
|
-
raw: true
|
|
1644
|
-
});
|
|
1645
|
-
if (!result.ok) throw result.error;
|
|
1646
|
-
return result.value;
|
|
1647
|
-
},
|
|
1648
|
-
enabled: !!payload,
|
|
1649
|
-
refetchInterval: 5e3,
|
|
1650
|
-
gcTime: 0,
|
|
1651
|
-
...queryOptions
|
|
1652
|
-
});
|
|
1653
|
-
}
|
|
1654
|
-
function useFetchAssetsBalances({
|
|
1655
|
-
params,
|
|
1656
|
-
queryOptions
|
|
1657
|
-
} = {}) {
|
|
1658
|
-
const { sodax } = useSodaxContext();
|
|
1659
|
-
const queryAddress = params?.queryAddress;
|
|
1660
|
-
return reactQuery.useQuery({
|
|
1661
|
-
queryKey: ["partner", "feeClaim", "assetsBalances", queryAddress],
|
|
1662
|
-
queryFn: async () => {
|
|
1663
|
-
if (!queryAddress) {
|
|
1664
|
-
throw new Error("queryAddress is required");
|
|
1665
|
-
}
|
|
1666
|
-
const result = await sodax.partners.feeClaim.fetchAssetsBalances(queryAddress);
|
|
1667
|
-
if (!result.ok) throw result.error;
|
|
1668
|
-
return result.value;
|
|
1669
|
-
},
|
|
1670
|
-
enabled: !!queryAddress,
|
|
1671
|
-
...queryOptions
|
|
1672
|
-
});
|
|
1673
|
-
}
|
|
1674
|
-
function useGetAutoSwapPreferences({
|
|
1675
|
-
params,
|
|
1676
|
-
queryOptions
|
|
1677
|
-
} = {}) {
|
|
1678
|
-
const { sodax } = useSodaxContext();
|
|
1679
|
-
const queryAddress = params?.queryAddress;
|
|
1680
|
-
return reactQuery.useQuery({
|
|
1681
|
-
queryKey: ["partner", "feeClaim", "autoSwapPreferences", queryAddress],
|
|
1682
|
-
queryFn: async () => {
|
|
1683
|
-
if (!queryAddress) {
|
|
1684
|
-
throw new Error("queryAddress is required");
|
|
1685
|
-
}
|
|
1686
|
-
const result = await sodax.partners.feeClaim.getAutoSwapPreferences(queryAddress);
|
|
1687
|
-
if (!result.ok) throw result.error;
|
|
1688
|
-
return result.value;
|
|
1689
|
-
},
|
|
1690
|
-
enabled: !!queryAddress,
|
|
1691
|
-
...queryOptions
|
|
1692
|
-
});
|
|
1693
|
-
}
|
|
1694
|
-
function useIsTokenApproved({
|
|
1695
|
-
params,
|
|
1696
|
-
queryOptions
|
|
1697
|
-
} = {}) {
|
|
1698
|
-
const { sodax } = useSodaxContext();
|
|
1699
|
-
const payload = params?.payload;
|
|
1700
|
-
return reactQuery.useQuery({
|
|
1701
|
-
queryKey: ["partner", "feeClaim", "isTokenApproved", payload?.srcChainKey, payload?.srcAddress, payload?.token],
|
|
1702
|
-
queryFn: async () => {
|
|
1703
|
-
if (!payload) {
|
|
1704
|
-
throw new Error("params are required");
|
|
1705
|
-
}
|
|
1706
|
-
const result = await sodax.partners.feeClaim.isTokenApproved(payload);
|
|
1707
|
-
if (!result.ok) throw result.error;
|
|
1708
|
-
return result.value;
|
|
1709
|
-
},
|
|
1710
|
-
enabled: !!payload,
|
|
1711
|
-
refetchInterval: 5e3,
|
|
1712
|
-
gcTime: 0,
|
|
1713
|
-
...queryOptions
|
|
1714
|
-
});
|
|
1715
|
-
}
|
|
1716
|
-
function useApproveToken({
|
|
1717
|
-
mutationOptions
|
|
1718
|
-
} = {}) {
|
|
1719
|
-
const { sodax } = useSodaxContext();
|
|
1720
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1721
|
-
return useSafeMutation({
|
|
1722
|
-
mutationKey: ["partner", "approveToken"],
|
|
1723
|
-
...mutationOptions,
|
|
1724
|
-
mutationFn: async (vars) => unwrapResult(await sodax.partners.feeClaim.approveToken({ ...vars, raw: false })),
|
|
1725
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1726
|
-
const { params } = vars;
|
|
1727
|
-
queryClient.invalidateQueries({
|
|
1728
|
-
queryKey: ["partner", "feeClaim", "isTokenApproved", params.srcChainKey, params.srcAddress, params.token]
|
|
1729
|
-
});
|
|
1730
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1731
|
-
}
|
|
1732
|
-
});
|
|
1733
|
-
}
|
|
1734
|
-
function useSetSwapPreference({
|
|
1735
|
-
mutationOptions
|
|
1736
|
-
} = {}) {
|
|
1737
|
-
const { sodax } = useSodaxContext();
|
|
1738
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1739
|
-
return useSafeMutation({
|
|
1740
|
-
mutationKey: ["partner", "setSwapPreference"],
|
|
1741
|
-
...mutationOptions,
|
|
1742
|
-
mutationFn: async (vars) => unwrapResult(await sodax.partners.feeClaim.setSwapPreference({ ...vars, raw: false })),
|
|
1743
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1744
|
-
queryClient.invalidateQueries({
|
|
1745
|
-
queryKey: ["partner", "feeClaim", "autoSwapPreferences", vars.params.srcAddress]
|
|
1746
|
-
});
|
|
1747
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1748
|
-
}
|
|
1749
|
-
});
|
|
1750
|
-
}
|
|
1751
|
-
function useFeeClaimSwap({
|
|
1752
|
-
mutationOptions
|
|
1753
|
-
} = {}) {
|
|
1754
|
-
const { sodax } = useSodaxContext();
|
|
1755
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1756
|
-
return useSafeMutation({
|
|
1757
|
-
mutationKey: ["partner", "feeClaimSwap"],
|
|
1758
|
-
...mutationOptions,
|
|
1759
|
-
mutationFn: async (vars) => unwrapResult(await sodax.partners.feeClaim.swap({ ...vars, raw: false })),
|
|
1760
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1761
|
-
queryClient.invalidateQueries({
|
|
1762
|
-
queryKey: ["partner", "feeClaim", "assetsBalances", vars.params.srcAddress]
|
|
1763
|
-
});
|
|
1764
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1765
|
-
}
|
|
1766
|
-
});
|
|
1767
|
-
}
|
|
1768
|
-
function useHubAssetBalances({
|
|
1769
|
-
params,
|
|
1770
|
-
queryOptions
|
|
1771
|
-
} = {}) {
|
|
1772
|
-
const { sodax } = useSodaxContext();
|
|
1773
|
-
const chainKey = params?.chainKey;
|
|
1774
|
-
const srcAddress = params?.srcAddress;
|
|
1775
|
-
return reactQuery.useQuery({
|
|
1776
|
-
queryKey: ["recovery", "hubAssetBalances", chainKey, srcAddress],
|
|
1777
|
-
queryFn: async () => {
|
|
1778
|
-
if (!chainKey || !srcAddress) {
|
|
1779
|
-
throw new Error("chainKey and srcAddress are required");
|
|
1780
|
-
}
|
|
1781
|
-
const result = await sodax.recovery.fetchHubAssetBalances({ chainKey, srcAddress });
|
|
1782
|
-
if (!result.ok) throw result.error;
|
|
1783
|
-
return result.value;
|
|
1784
|
-
},
|
|
1785
|
-
enabled: !!chainKey && !!srcAddress,
|
|
1786
|
-
staleTime: 1e4,
|
|
1787
|
-
...queryOptions
|
|
1788
|
-
});
|
|
1789
|
-
}
|
|
1790
|
-
function useWithdrawHubAsset({
|
|
1791
|
-
mutationOptions
|
|
1792
|
-
} = {}) {
|
|
1793
|
-
const { sodax } = useSodaxContext();
|
|
1794
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1795
|
-
return useSafeMutation({
|
|
1796
|
-
mutationKey: ["recovery", "withdrawHubAsset"],
|
|
1797
|
-
...mutationOptions,
|
|
1798
|
-
mutationFn: async (vars) => unwrapResult(await sodax.recovery.withdrawHubAsset({ ...vars, raw: false })),
|
|
1799
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1800
|
-
const { params } = vars;
|
|
1801
|
-
queryClient.invalidateQueries({
|
|
1802
|
-
queryKey: ["recovery", "hubAssetBalances", params.srcChainKey, params.srcAddress]
|
|
1803
|
-
});
|
|
1804
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", params.srcChainKey] });
|
|
1805
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1806
|
-
}
|
|
1807
|
-
});
|
|
1808
|
-
}
|
|
1809
|
-
function useMigrateIcxToSoda({
|
|
1810
|
-
mutationOptions
|
|
1811
|
-
} = {}) {
|
|
1812
|
-
const { sodax } = useSodaxContext();
|
|
1813
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1814
|
-
return useSafeMutation({
|
|
1815
|
-
mutationKey: ["migrate", "icxToSoda"],
|
|
1816
|
-
...mutationOptions,
|
|
1817
|
-
mutationFn: async (vars) => unwrapResult(await sodax.migration.migrateIcxToSoda({ ...vars, raw: false })),
|
|
1818
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1819
|
-
queryClient.invalidateQueries({ queryKey: ["migrate", "allowance"] });
|
|
1820
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.srcChainKey] });
|
|
1821
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", sdk.ChainKeys.SONIC_MAINNET] });
|
|
1822
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1823
|
-
}
|
|
1824
|
-
});
|
|
1825
|
-
}
|
|
1826
|
-
function useRevertMigrateSodaToIcx({
|
|
1827
|
-
mutationOptions
|
|
1828
|
-
} = {}) {
|
|
1829
|
-
const { sodax } = useSodaxContext();
|
|
1830
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1831
|
-
return useSafeMutation({
|
|
1832
|
-
mutationKey: ["migrate", "revertSodaToIcx"],
|
|
1833
|
-
...mutationOptions,
|
|
1834
|
-
mutationFn: async (vars) => unwrapResult(await sodax.migration.revertMigrateSodaToIcx({ ...vars, raw: false })),
|
|
1835
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1836
|
-
queryClient.invalidateQueries({ queryKey: ["migrate", "allowance"] });
|
|
1837
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.srcChainKey] });
|
|
1838
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", sdk.ChainKeys.ICON_MAINNET] });
|
|
1839
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1840
|
-
}
|
|
1841
|
-
});
|
|
1842
|
-
}
|
|
1843
|
-
function useMigratebnUSD({
|
|
1844
|
-
mutationOptions
|
|
1845
|
-
} = {}) {
|
|
1846
|
-
const { sodax } = useSodaxContext();
|
|
1847
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1848
|
-
return useSafeMutation({
|
|
1849
|
-
mutationKey: ["migrate", "bnUSD"],
|
|
1850
|
-
...mutationOptions,
|
|
1851
|
-
mutationFn: async (vars) => unwrapResult(await sodax.migration.migratebnUSD({ ...vars, raw: false })),
|
|
1852
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1853
|
-
const { params } = vars;
|
|
1854
|
-
queryClient.invalidateQueries({ queryKey: ["migrate", "allowance"] });
|
|
1855
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", params.srcChainKey] });
|
|
1856
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", params.dstChainKey] });
|
|
1857
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1858
|
-
}
|
|
1859
|
-
});
|
|
1860
|
-
}
|
|
1861
|
-
function useMigrateBaln({
|
|
1862
|
-
mutationOptions
|
|
1863
|
-
} = {}) {
|
|
1864
|
-
const { sodax } = useSodaxContext();
|
|
1865
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1866
|
-
return useSafeMutation({
|
|
1867
|
-
mutationKey: ["migrate", "baln"],
|
|
1868
|
-
...mutationOptions,
|
|
1869
|
-
mutationFn: async (vars) => unwrapResult(await sodax.migration.migrateBaln({ ...vars, raw: false })),
|
|
1870
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1871
|
-
queryClient.invalidateQueries({ queryKey: ["migrate", "allowance"] });
|
|
1872
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", sdk.ChainKeys.ICON_MAINNET] });
|
|
1873
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", sdk.ChainKeys.SONIC_MAINNET] });
|
|
1874
|
-
queryClient.invalidateQueries({ queryKey: ["staking", "info"] });
|
|
1875
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1876
|
-
}
|
|
1877
|
-
});
|
|
1878
|
-
}
|
|
1879
|
-
function useMigrationApprove({
|
|
1880
|
-
mutationOptions
|
|
1881
|
-
} = {}) {
|
|
1882
|
-
const { sodax } = useSodaxContext();
|
|
1883
|
-
const queryClient = reactQuery.useQueryClient();
|
|
1884
|
-
return useSafeMutation({
|
|
1885
|
-
mutationKey: ["migrate", "approve"],
|
|
1886
|
-
...mutationOptions,
|
|
1887
|
-
mutationFn: async ({ action, ...actionParams }) => unwrapResult(
|
|
1888
|
-
await sodax.migration.approve(
|
|
1889
|
-
{ ...actionParams, raw: false },
|
|
1890
|
-
action
|
|
1891
|
-
)
|
|
1892
|
-
),
|
|
1893
|
-
onSuccess: async (data, vars, ctx) => {
|
|
1894
|
-
queryClient.invalidateQueries({ queryKey: ["migrate", "allowance"] });
|
|
1895
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
1896
|
-
}
|
|
1897
|
-
});
|
|
1898
|
-
}
|
|
1899
|
-
var REFETCH_INTERVAL_MS2 = 2e3;
|
|
1900
|
-
function useMigrationAllowance({
|
|
1901
|
-
params,
|
|
1902
|
-
queryOptions
|
|
1903
|
-
} = {}) {
|
|
1904
|
-
const { sodax } = useSodaxContext();
|
|
1905
|
-
const migrationParams = params?.params;
|
|
1906
|
-
const action = params?.action;
|
|
1907
|
-
return reactQuery.useQuery({
|
|
1908
|
-
// Extract the (chain, owner, token, amount) tuple that actually scopes the allowance —
|
|
1909
|
-
// raw-object keys break per Rule 4 (bigints) and churn on every render.
|
|
1910
|
-
queryKey: [
|
|
1911
|
-
"migrate",
|
|
1912
|
-
"allowance",
|
|
1913
|
-
action,
|
|
1914
|
-
migrationParams?.srcChainKey,
|
|
1915
|
-
migrationParams?.srcAddress,
|
|
1916
|
-
migrationParams && "srcbnUSD" in migrationParams ? migrationParams.srcbnUSD : void 0,
|
|
1917
|
-
migrationParams?.amount?.toString()
|
|
1918
|
-
],
|
|
1919
|
-
queryFn: async () => {
|
|
1920
|
-
if (!migrationParams || !action) return false;
|
|
1921
|
-
const result = await sodax.migration.isAllowanceValid(migrationParams, action);
|
|
1922
|
-
return result.ok ? result.value : false;
|
|
1923
|
-
},
|
|
1924
|
-
enabled: !!migrationParams && !!action,
|
|
1925
|
-
refetchInterval: REFETCH_INTERVAL_MS2,
|
|
1926
|
-
...queryOptions
|
|
1927
|
-
});
|
|
1928
|
-
}
|
|
1929
|
-
function usePools({ queryOptions } = {}) {
|
|
1930
|
-
const { sodax } = useSodaxContext();
|
|
1931
|
-
return reactQuery.useQuery({
|
|
1932
|
-
queryKey: ["dex", "pools"],
|
|
1933
|
-
queryFn: () => sodax.dex.clService.getPools(),
|
|
1934
|
-
staleTime: Number.POSITIVE_INFINITY,
|
|
1935
|
-
...queryOptions
|
|
1936
|
-
});
|
|
1937
|
-
}
|
|
1938
|
-
function usePoolData({ params, queryOptions } = {}) {
|
|
1939
|
-
const { sodax } = useSodaxContext();
|
|
1940
|
-
const poolKey = params?.poolKey ?? null;
|
|
1941
|
-
return reactQuery.useQuery({
|
|
1942
|
-
queryKey: ["dex", "poolData", poolKey],
|
|
1943
|
-
queryFn: async () => {
|
|
1944
|
-
if (!poolKey) {
|
|
1945
|
-
throw new Error("Pool key is required");
|
|
1946
|
-
}
|
|
1947
|
-
const result = await sodax.dex.clService.getPoolData(poolKey, sodax.hubProvider.publicClient);
|
|
1948
|
-
if (!result.ok) throw result.error;
|
|
1949
|
-
return result.value;
|
|
1950
|
-
},
|
|
1951
|
-
enabled: poolKey !== null,
|
|
1952
|
-
staleTime: 1e4,
|
|
1953
|
-
refetchInterval: 3e4,
|
|
1954
|
-
...queryOptions
|
|
1955
|
-
});
|
|
1956
|
-
}
|
|
1957
|
-
function usePoolBalances({
|
|
1958
|
-
params,
|
|
1959
|
-
queryOptions
|
|
1960
|
-
} = {}) {
|
|
1961
|
-
const { sodax } = useSodaxContext();
|
|
1962
|
-
const poolData = params?.poolData ?? null;
|
|
1963
|
-
const poolKey = params?.poolKey ?? null;
|
|
1964
|
-
const spokeChainKey = params?.spokeChainKey;
|
|
1965
|
-
const userAddress = params?.userAddress;
|
|
1966
|
-
return reactQuery.useQuery({
|
|
1967
|
-
queryKey: ["dex", "poolBalances", poolData?.poolId, spokeChainKey, userAddress],
|
|
1968
|
-
queryFn: async () => {
|
|
1969
|
-
if (!poolData || !poolKey || !spokeChainKey || !userAddress) {
|
|
1970
|
-
throw new Error("poolData, poolKey, spokeChainKey, and userAddress are required");
|
|
1971
|
-
}
|
|
1972
|
-
const hubWallet = await sodax.hubProvider.getUserHubWalletAddress(userAddress, spokeChainKey);
|
|
1973
|
-
const [token0Balance, token1Balance] = await Promise.all([
|
|
1974
|
-
sodax.hubProvider.publicClient.readContract({
|
|
1975
|
-
address: poolData.token0.address,
|
|
1976
|
-
abi: viem.erc20Abi,
|
|
1977
|
-
functionName: "balanceOf",
|
|
1978
|
-
args: [hubWallet]
|
|
1979
|
-
}),
|
|
1980
|
-
sodax.hubProvider.publicClient.readContract({
|
|
1981
|
-
address: poolData.token1.address,
|
|
1982
|
-
abi: viem.erc20Abi,
|
|
1983
|
-
functionName: "balanceOf",
|
|
1984
|
-
args: [hubWallet]
|
|
1985
|
-
})
|
|
1986
|
-
]);
|
|
1987
|
-
return { token0Balance, token1Balance };
|
|
1988
|
-
},
|
|
1989
|
-
enabled: !!poolData && !!poolKey && !!spokeChainKey && !!userAddress,
|
|
1990
|
-
staleTime: 5e3,
|
|
1991
|
-
refetchInterval: 1e4,
|
|
1992
|
-
...queryOptions
|
|
1993
|
-
});
|
|
1994
|
-
}
|
|
1995
|
-
function usePositionInfo({
|
|
1996
|
-
params,
|
|
1997
|
-
queryOptions
|
|
1998
|
-
} = {}) {
|
|
1999
|
-
const { sodax } = useSodaxContext();
|
|
2000
|
-
const tokenId = params?.tokenId ?? null;
|
|
2001
|
-
const poolKey = params?.poolKey ?? null;
|
|
2002
|
-
return reactQuery.useQuery({
|
|
2003
|
-
queryKey: ["dex", "positionInfo", tokenId, poolKey],
|
|
2004
|
-
queryFn: async () => {
|
|
2005
|
-
if (!tokenId || !poolKey) {
|
|
2006
|
-
throw new Error("Token ID and pool key are required");
|
|
2007
|
-
}
|
|
2008
|
-
const infoResult = await sodax.dex.clService.getPositionInfo(BigInt(tokenId), sodax.hubProvider.publicClient);
|
|
2009
|
-
if (!infoResult.ok) throw infoResult.error;
|
|
2010
|
-
const info = infoResult.value;
|
|
2011
|
-
const isValid = info.poolKey.currency0.toLowerCase() === poolKey.currency0.toLowerCase() && info.poolKey.currency1.toLowerCase() === poolKey.currency1.toLowerCase() && info.poolKey.fee === poolKey.fee;
|
|
2012
|
-
return { positionInfo: info, isValid };
|
|
2013
|
-
},
|
|
2014
|
-
enabled: tokenId !== null && tokenId !== "" && poolKey !== null,
|
|
2015
|
-
staleTime: 1e4,
|
|
2016
|
-
...queryOptions
|
|
2017
|
-
});
|
|
2018
|
-
}
|
|
2019
|
-
function useDexDeposit({
|
|
2020
|
-
mutationOptions
|
|
2021
|
-
} = {}) {
|
|
2022
|
-
const { sodax } = useSodaxContext();
|
|
2023
|
-
const queryClient = reactQuery.useQueryClient();
|
|
2024
|
-
return useSafeMutation({
|
|
2025
|
-
mutationKey: ["dex", "deposit"],
|
|
2026
|
-
...mutationOptions,
|
|
2027
|
-
mutationFn: async (vars) => unwrapResult(await sodax.dex.assetService.deposit({ ...vars, raw: false })),
|
|
2028
|
-
onSuccess: async (data, vars, ctx) => {
|
|
2029
|
-
const { params } = vars;
|
|
2030
|
-
queryClient.invalidateQueries({ queryKey: ["dex", "poolBalances", params.srcChainKey, params.srcAddress] });
|
|
2031
|
-
queryClient.invalidateQueries({
|
|
2032
|
-
queryKey: ["dex", "allowance", params.srcChainKey, params.asset, params.amount.toString()]
|
|
2033
|
-
});
|
|
2034
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", params.srcChainKey] });
|
|
2035
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
2036
|
-
}
|
|
2037
|
-
});
|
|
2038
|
-
}
|
|
2039
|
-
function useDexWithdraw({
|
|
2040
|
-
mutationOptions
|
|
2041
|
-
} = {}) {
|
|
2042
|
-
const { sodax } = useSodaxContext();
|
|
2043
|
-
const queryClient = reactQuery.useQueryClient();
|
|
2044
|
-
return useSafeMutation({
|
|
2045
|
-
mutationKey: ["dex", "withdraw"],
|
|
2046
|
-
...mutationOptions,
|
|
2047
|
-
mutationFn: async (vars) => unwrapResult(await sodax.dex.assetService.withdraw({ ...vars, raw: false })),
|
|
2048
|
-
onSuccess: async (data, vars, ctx) => {
|
|
2049
|
-
const { params } = vars;
|
|
2050
|
-
queryClient.invalidateQueries({ queryKey: ["dex", "poolBalances", params.srcChainKey, params.srcAddress] });
|
|
2051
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", params.srcChainKey] });
|
|
2052
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
2053
|
-
}
|
|
2054
|
-
});
|
|
2055
|
-
}
|
|
2056
|
-
function useDexAllowance({
|
|
2057
|
-
params,
|
|
2058
|
-
queryOptions
|
|
2059
|
-
} = {}) {
|
|
2060
|
-
const { sodax } = useSodaxContext();
|
|
2061
|
-
const payload = params?.payload;
|
|
2062
|
-
return reactQuery.useQuery({
|
|
2063
|
-
queryKey: ["dex", "allowance", payload?.srcChainKey, payload?.asset, payload?.amount?.toString()],
|
|
2064
|
-
queryFn: async () => {
|
|
2065
|
-
if (!payload) {
|
|
2066
|
-
throw new Error("Params are required");
|
|
2067
|
-
}
|
|
2068
|
-
const result = await sodax.dex.assetService.isAllowanceValid({ params: payload, raw: true });
|
|
2069
|
-
if (!result.ok) throw result.error;
|
|
2070
|
-
return result.value;
|
|
2071
|
-
},
|
|
2072
|
-
enabled: !!payload,
|
|
2073
|
-
refetchInterval: 5e3,
|
|
2074
|
-
gcTime: 0,
|
|
2075
|
-
...queryOptions
|
|
2076
|
-
});
|
|
2077
|
-
}
|
|
2078
|
-
function useDexApprove({
|
|
2079
|
-
mutationOptions
|
|
2080
|
-
} = {}) {
|
|
2081
|
-
const { sodax } = useSodaxContext();
|
|
2082
|
-
const queryClient = reactQuery.useQueryClient();
|
|
2083
|
-
return useSafeMutation({
|
|
2084
|
-
mutationKey: ["dex", "approve"],
|
|
2085
|
-
...mutationOptions,
|
|
2086
|
-
mutationFn: async (vars) => unwrapResult(await sodax.dex.assetService.approve({ ...vars, raw: false })),
|
|
2087
|
-
onSuccess: async (data, vars, ctx) => {
|
|
2088
|
-
const { params } = vars;
|
|
2089
|
-
queryClient.invalidateQueries({
|
|
2090
|
-
queryKey: ["dex", "allowance", params.srcChainKey, params.asset, params.amount.toString()]
|
|
2091
|
-
});
|
|
2092
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
2093
|
-
}
|
|
2094
|
-
});
|
|
2095
|
-
}
|
|
2096
|
-
function useLiquidityAmounts(minPrice, maxPrice, poolData) {
|
|
2097
|
-
const [liquidityToken0Amount, setLiquidityToken0Amount] = react.useState("");
|
|
2098
|
-
const [liquidityToken1Amount, setLiquidityToken1Amount] = react.useState("");
|
|
2099
|
-
const [lastEditedToken, setLastEditedToken] = react.useState(null);
|
|
2100
|
-
const { minPriceNum, maxPriceNum, isValidPriceRange } = react.useMemo(() => {
|
|
2101
|
-
const parsedMin = Number.parseFloat(minPrice);
|
|
2102
|
-
const parsedMax = Number.parseFloat(maxPrice);
|
|
2103
|
-
const isValid = parsedMin > 0 && parsedMax > 0 && parsedMin < parsedMax;
|
|
2104
|
-
return { minPriceNum: parsedMin, maxPriceNum: parsedMax, isValidPriceRange: isValid };
|
|
2105
|
-
}, [minPrice, maxPrice]);
|
|
2106
|
-
const { tickLower, tickUpper, currentTick } = react.useMemo(() => {
|
|
2107
|
-
if (!poolData || !isValidPriceRange) {
|
|
2108
|
-
return { tickLower: null, tickUpper: null, currentTick: null };
|
|
2109
|
-
}
|
|
2110
|
-
try {
|
|
2111
|
-
const lower = sdk.ClService.priceToTick(minPriceNum, poolData.token0, poolData.token1, poolData.tickSpacing);
|
|
2112
|
-
const upper = sdk.ClService.priceToTick(maxPriceNum, poolData.token0, poolData.token1, poolData.tickSpacing);
|
|
2113
|
-
return { tickLower: lower, tickUpper: upper, currentTick: BigInt(poolData.currentTick) };
|
|
2114
|
-
} catch (err) {
|
|
2115
|
-
console.error("Failed to calculate ticks:", err);
|
|
2116
|
-
return { tickLower: null, tickUpper: null, currentTick: null };
|
|
2117
|
-
}
|
|
2118
|
-
}, [minPriceNum, maxPriceNum, poolData, isValidPriceRange]);
|
|
2119
|
-
const handleToken0AmountChange = react.useCallback(
|
|
2120
|
-
(value) => {
|
|
2121
|
-
setLiquidityToken0Amount(value);
|
|
2122
|
-
setLastEditedToken("token0");
|
|
2123
|
-
if (!value || !poolData || !tickLower || !tickUpper || !currentTick) return;
|
|
2124
|
-
const amount0 = Number.parseFloat(value);
|
|
2125
|
-
if (amount0 <= 0 || !isValidPriceRange) return;
|
|
2126
|
-
try {
|
|
2127
|
-
const amount0BigInt = BigInt(Math.floor(amount0 * 10 ** poolData.token0.decimals));
|
|
2128
|
-
const amount1BigInt = sdk.ClService.calculateAmount1FromAmount0(
|
|
2129
|
-
amount0BigInt,
|
|
2130
|
-
tickLower,
|
|
2131
|
-
tickUpper,
|
|
2132
|
-
currentTick,
|
|
2133
|
-
poolData.sqrtPriceX96
|
|
2134
|
-
);
|
|
2135
|
-
const amount1 = Number(amount1BigInt) / 10 ** poolData.token1.decimals;
|
|
2136
|
-
setLiquidityToken1Amount(amount1.toFixed(6));
|
|
2137
|
-
} catch (err) {
|
|
2138
|
-
console.error("Failed to calculate token1 amount:", err);
|
|
2139
|
-
}
|
|
2140
|
-
},
|
|
2141
|
-
[poolData, tickLower, tickUpper, currentTick, isValidPriceRange]
|
|
2142
|
-
);
|
|
2143
|
-
const handleToken1AmountChange = react.useCallback(
|
|
2144
|
-
(value) => {
|
|
2145
|
-
setLiquidityToken1Amount(value);
|
|
2146
|
-
setLastEditedToken("token1");
|
|
2147
|
-
if (!value || !poolData || !tickLower || !tickUpper || !currentTick) return;
|
|
2148
|
-
const amount1 = Number.parseFloat(value);
|
|
2149
|
-
if (amount1 <= 0 || !isValidPriceRange) return;
|
|
2150
|
-
try {
|
|
2151
|
-
const amount1BigInt = BigInt(Math.floor(amount1 * 10 ** poolData.token1.decimals));
|
|
2152
|
-
const amount0BigInt = sdk.ClService.calculateAmount0FromAmount1(
|
|
2153
|
-
amount1BigInt,
|
|
2154
|
-
tickLower,
|
|
2155
|
-
tickUpper,
|
|
2156
|
-
currentTick,
|
|
2157
|
-
poolData.sqrtPriceX96
|
|
2158
|
-
);
|
|
2159
|
-
const amount0 = Number(amount0BigInt) / 10 ** poolData.token0.decimals;
|
|
2160
|
-
setLiquidityToken0Amount(amount0.toFixed(6));
|
|
2161
|
-
} catch (err) {
|
|
2162
|
-
console.error("Failed to calculate token0 amount:", err);
|
|
2163
|
-
}
|
|
2164
|
-
},
|
|
2165
|
-
[poolData, tickLower, tickUpper, currentTick, isValidPriceRange]
|
|
2166
|
-
);
|
|
2167
|
-
react.useEffect(() => {
|
|
2168
|
-
if (!poolData || !tickLower || !tickUpper || !lastEditedToken || !isValidPriceRange) return;
|
|
2169
|
-
if (lastEditedToken === "token0" && liquidityToken0Amount) {
|
|
2170
|
-
handleToken0AmountChange(liquidityToken0Amount);
|
|
2171
|
-
} else if (lastEditedToken === "token1" && liquidityToken1Amount) {
|
|
2172
|
-
handleToken1AmountChange(liquidityToken1Amount);
|
|
2173
|
-
}
|
|
2174
|
-
}, [
|
|
2175
|
-
poolData,
|
|
2176
|
-
lastEditedToken,
|
|
2177
|
-
liquidityToken0Amount,
|
|
2178
|
-
liquidityToken1Amount,
|
|
2179
|
-
handleToken0AmountChange,
|
|
2180
|
-
handleToken1AmountChange,
|
|
2181
|
-
tickLower,
|
|
2182
|
-
tickUpper,
|
|
2183
|
-
isValidPriceRange
|
|
2184
|
-
]);
|
|
2185
|
-
return {
|
|
2186
|
-
liquidityToken0Amount,
|
|
2187
|
-
liquidityToken1Amount,
|
|
2188
|
-
lastEditedToken,
|
|
2189
|
-
setLiquidityToken0Amount,
|
|
2190
|
-
setLiquidityToken1Amount,
|
|
2191
|
-
handleToken0AmountChange,
|
|
2192
|
-
handleToken1AmountChange
|
|
2193
|
-
};
|
|
2194
|
-
}
|
|
2195
|
-
function useSupplyLiquidity({
|
|
2196
|
-
mutationOptions
|
|
2197
|
-
} = {}) {
|
|
2198
|
-
const { sodax } = useSodaxContext();
|
|
2199
|
-
const queryClient = reactQuery.useQueryClient();
|
|
2200
|
-
return useSafeMutation({
|
|
2201
|
-
mutationKey: ["dex", "supplyLiquidity"],
|
|
2202
|
-
...mutationOptions,
|
|
2203
|
-
mutationFn: async ({ params, walletProvider, timeout }) => {
|
|
2204
|
-
const sharedParams = {
|
|
2205
|
-
srcChainKey: params.srcChainKey,
|
|
2206
|
-
srcAddress: params.srcAddress,
|
|
2207
|
-
poolKey: params.poolKey,
|
|
2208
|
-
tickLower: params.tickLower,
|
|
2209
|
-
tickUpper: params.tickUpper,
|
|
2210
|
-
liquidity: params.liquidity,
|
|
2211
|
-
amount0Max: params.amount0Max,
|
|
2212
|
-
amount1Max: params.amount1Max,
|
|
2213
|
-
sqrtPriceX96: params.sqrtPriceX96
|
|
2214
|
-
};
|
|
2215
|
-
if (params.tokenId !== void 0 && params.isValidPosition) {
|
|
2216
|
-
const increaseParams = {
|
|
2217
|
-
...sharedParams,
|
|
2218
|
-
tokenId: typeof params.tokenId === "bigint" ? params.tokenId : BigInt(params.tokenId)
|
|
2219
|
-
};
|
|
2220
|
-
return unwrapResult(
|
|
2221
|
-
await sodax.dex.clService.increaseLiquidity({ params: increaseParams, raw: false, walletProvider, timeout })
|
|
2222
|
-
);
|
|
2223
|
-
}
|
|
2224
|
-
return unwrapResult(
|
|
2225
|
-
await sodax.dex.clService.supplyLiquidity({ params: sharedParams, raw: false, walletProvider, timeout })
|
|
2226
|
-
);
|
|
2227
|
-
},
|
|
2228
|
-
onSuccess: async (data, vars, ctx) => {
|
|
2229
|
-
const { params } = vars;
|
|
2230
|
-
if (params.tokenId !== void 0 && params.isValidPosition) {
|
|
2231
|
-
const tokenIdStr = String(params.tokenId);
|
|
2232
|
-
queryClient.invalidateQueries({ queryKey: ["dex", "positionInfo", tokenIdStr, params.poolKey] });
|
|
2233
|
-
} else {
|
|
2234
|
-
queryClient.invalidateQueries({ queryKey: ["dex", "positionInfo"] });
|
|
2235
|
-
}
|
|
2236
|
-
queryClient.invalidateQueries({ queryKey: ["dex", "poolData", params.poolKey] });
|
|
2237
|
-
queryClient.invalidateQueries({ queryKey: ["dex", "poolBalances", params.srcChainKey, params.srcAddress] });
|
|
2238
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", params.srcChainKey] });
|
|
2239
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
2240
|
-
}
|
|
2241
|
-
});
|
|
2242
|
-
}
|
|
2243
|
-
function useDecreaseLiquidity({
|
|
2244
|
-
mutationOptions
|
|
2245
|
-
} = {}) {
|
|
2246
|
-
const { sodax } = useSodaxContext();
|
|
2247
|
-
const queryClient = reactQuery.useQueryClient();
|
|
2248
|
-
return useSafeMutation({
|
|
2249
|
-
mutationKey: ["dex", "decreaseLiquidity"],
|
|
2250
|
-
...mutationOptions,
|
|
2251
|
-
mutationFn: async (vars) => unwrapResult(await sodax.dex.clService.decreaseLiquidity({ ...vars, raw: false })),
|
|
2252
|
-
onSuccess: async (data, vars, ctx) => {
|
|
2253
|
-
const { params } = vars;
|
|
2254
|
-
queryClient.invalidateQueries({
|
|
2255
|
-
queryKey: ["dex", "positionInfo", params.tokenId.toString(), params.poolKey]
|
|
2256
|
-
});
|
|
2257
|
-
queryClient.invalidateQueries({ queryKey: ["dex", "poolData", params.poolKey] });
|
|
2258
|
-
queryClient.invalidateQueries({ queryKey: ["dex", "poolBalances", params.srcChainKey, params.srcAddress] });
|
|
2259
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
2260
|
-
}
|
|
2261
|
-
});
|
|
2262
|
-
}
|
|
2263
|
-
function createDecreaseLiquidityParamsProps({
|
|
2264
|
-
poolKey,
|
|
2265
|
-
tokenId,
|
|
2266
|
-
percentage,
|
|
2267
|
-
positionInfo,
|
|
2268
|
-
slippageTolerance
|
|
2269
|
-
}) {
|
|
2270
|
-
const percentageNum = Number.parseFloat(String(percentage));
|
|
2271
|
-
const slippage = Number.parseFloat(String(slippageTolerance));
|
|
2272
|
-
if (percentageNum <= 0 || percentageNum > 100) {
|
|
2273
|
-
throw new Error("Percentage must be between 0 and 100");
|
|
2274
|
-
}
|
|
2275
|
-
if (slippage <= 0 || slippage > 100) {
|
|
2276
|
-
throw new Error("Slippage must be between 0 and 100");
|
|
2277
|
-
}
|
|
2278
|
-
const liquidityToRemove = percentageNum === 100 ? positionInfo.liquidity : positionInfo.liquidity * BigInt(Math.floor(percentageNum * 100)) / 10000n;
|
|
2279
|
-
const expectedAmount0 = percentageNum === 100 ? positionInfo.amount0 : positionInfo.amount0 * BigInt(Math.floor(percentageNum * 100)) / 10000n;
|
|
2280
|
-
const expectedAmount1 = percentageNum === 100 ? positionInfo.amount1 : positionInfo.amount1 * BigInt(Math.floor(percentageNum * 100)) / 10000n;
|
|
2281
|
-
const slippageMultiplier = BigInt(Math.floor((100 - slippage) * 100));
|
|
2282
|
-
const amount0Min = expectedAmount0 * slippageMultiplier / 10000n;
|
|
2283
|
-
const amount1Min = expectedAmount1 * slippageMultiplier / 10000n;
|
|
2284
|
-
return {
|
|
2285
|
-
poolKey,
|
|
2286
|
-
tokenId: BigInt(tokenId),
|
|
2287
|
-
liquidity: liquidityToRemove,
|
|
2288
|
-
amount0Min,
|
|
2289
|
-
amount1Min
|
|
2290
|
-
};
|
|
2291
|
-
}
|
|
2292
|
-
function createDepositParamsProps({
|
|
2293
|
-
tokenIndex,
|
|
2294
|
-
amount,
|
|
2295
|
-
poolData,
|
|
2296
|
-
poolSpokeAssets
|
|
2297
|
-
}) {
|
|
2298
|
-
const amountNum = Number.parseFloat(String(amount));
|
|
2299
|
-
if (!amount || amountNum <= 0) {
|
|
2300
|
-
throw new Error("Amount must be greater than 0");
|
|
2301
|
-
}
|
|
2302
|
-
const token = tokenIndex === 0 ? poolData.token0 : poolData.token1;
|
|
2303
|
-
const originalAsset = tokenIndex === 0 ? poolSpokeAssets.token0 : poolSpokeAssets.token1;
|
|
2304
|
-
return {
|
|
2305
|
-
asset: originalAsset.address,
|
|
2306
|
-
// Use deposit token decimals (original asset) for correct unit parsing
|
|
2307
|
-
amount: viem.parseUnits(String(amount), originalAsset.decimals),
|
|
2308
|
-
poolToken: token.address
|
|
2309
|
-
};
|
|
2310
|
-
}
|
|
2311
|
-
function createSupplyLiquidityParamsProps({
|
|
2312
|
-
poolData,
|
|
2313
|
-
poolKey,
|
|
2314
|
-
minPrice,
|
|
2315
|
-
maxPrice,
|
|
2316
|
-
liquidityToken0Amount,
|
|
2317
|
-
liquidityToken1Amount,
|
|
2318
|
-
slippageTolerance,
|
|
2319
|
-
positionId,
|
|
2320
|
-
isValidPosition
|
|
2321
|
-
}) {
|
|
2322
|
-
const slippage = Number.parseFloat(String(slippageTolerance));
|
|
2323
|
-
if (slippage <= 0 || slippage > 100) {
|
|
2324
|
-
throw new Error("Slippage must be between 0 and 100");
|
|
2325
|
-
}
|
|
2326
|
-
const minPriceNum = Number.parseFloat(minPrice);
|
|
2327
|
-
const maxPriceNum = Number.parseFloat(maxPrice);
|
|
2328
|
-
const amount0 = Number.parseFloat(liquidityToken0Amount);
|
|
2329
|
-
const amount1 = Number.parseFloat(liquidityToken1Amount);
|
|
2330
|
-
if (minPriceNum <= 0 || maxPriceNum <= 0 || amount0 <= 0 || amount1 <= 0) {
|
|
2331
|
-
throw new Error("All values must be greater than 0");
|
|
2332
|
-
}
|
|
2333
|
-
if (minPriceNum >= maxPriceNum) {
|
|
2334
|
-
throw new Error("Min price must be less than max price");
|
|
2335
|
-
}
|
|
2336
|
-
const amount0BigInt = viem.parseUnits(liquidityToken0Amount, poolData.token0.decimals);
|
|
2337
|
-
const amount1BigInt = viem.parseUnits(liquidityToken1Amount, poolData.token1.decimals);
|
|
2338
|
-
const token0 = poolData.token0;
|
|
2339
|
-
const token1 = poolData.token1;
|
|
2340
|
-
const tickSpacing = poolData.tickSpacing;
|
|
2341
|
-
const tickLower = sdk.ClService.priceToTick(minPriceNum, token0, token1, tickSpacing);
|
|
2342
|
-
const tickUpper = sdk.ClService.priceToTick(maxPriceNum, token0, token1, tickSpacing);
|
|
2343
|
-
const liquidity = sdk.ClService.calculateLiquidityFromAmounts(
|
|
2344
|
-
amount0BigInt,
|
|
2345
|
-
amount1BigInt,
|
|
2346
|
-
tickLower,
|
|
2347
|
-
tickUpper,
|
|
2348
|
-
BigInt(poolData.currentTick)
|
|
2349
|
-
);
|
|
2350
|
-
const { amount0Max, amount1Max } = sdk.ClService.calculateMaxAmountsForSlippage(
|
|
2351
|
-
liquidity,
|
|
2352
|
-
tickLower,
|
|
2353
|
-
tickUpper,
|
|
2354
|
-
BigInt(poolData.currentTick),
|
|
2355
|
-
poolData.sqrtPriceX96,
|
|
2356
|
-
slippage
|
|
2357
|
-
);
|
|
2358
|
-
const tokenId = positionId ? BigInt(positionId) : void 0;
|
|
2359
|
-
return {
|
|
2360
|
-
poolKey,
|
|
2361
|
-
tickLower,
|
|
2362
|
-
tickUpper,
|
|
2363
|
-
liquidity,
|
|
2364
|
-
amount0Max,
|
|
2365
|
-
amount1Max,
|
|
2366
|
-
sqrtPriceX96: poolData.sqrtPriceX96,
|
|
2367
|
-
positionId,
|
|
2368
|
-
isValidPosition,
|
|
2369
|
-
tokenId
|
|
2370
|
-
};
|
|
2371
|
-
}
|
|
2372
|
-
function createWithdrawParamsProps({
|
|
2373
|
-
tokenIndex,
|
|
2374
|
-
amount,
|
|
2375
|
-
poolData,
|
|
2376
|
-
poolSpokeAssets,
|
|
2377
|
-
dst
|
|
2378
|
-
}) {
|
|
2379
|
-
const amountNum = Number.parseFloat(String(amount));
|
|
2380
|
-
if (!amount || amountNum <= 0) {
|
|
2381
|
-
throw new Error("Please enter a valid amount");
|
|
2382
|
-
}
|
|
2383
|
-
const token = tokenIndex === 0 ? poolData.token0 : poolData.token1;
|
|
2384
|
-
const originalAsset = tokenIndex === 0 ? poolSpokeAssets.token0 : poolSpokeAssets.token1;
|
|
2385
|
-
return {
|
|
2386
|
-
asset: originalAsset.address,
|
|
2387
|
-
amount: viem.parseUnits(String(amount), token.decimals),
|
|
2388
|
-
poolToken: token.address,
|
|
2389
|
-
dst
|
|
2390
|
-
};
|
|
2391
|
-
}
|
|
2392
|
-
|
|
2393
|
-
// src/hooks/dex/useCreateDepositParams.ts
|
|
2394
|
-
function useCreateDepositParams({
|
|
2395
|
-
tokenIndex,
|
|
2396
|
-
amount,
|
|
2397
|
-
poolData,
|
|
2398
|
-
poolSpokeAssets
|
|
2399
|
-
}) {
|
|
2400
|
-
return react.useMemo(() => {
|
|
2401
|
-
if (!amount || Number.parseFloat(String(amount)) <= 0) {
|
|
2402
|
-
return void 0;
|
|
2403
|
-
}
|
|
2404
|
-
return createDepositParamsProps({ tokenIndex, amount, poolData, poolSpokeAssets });
|
|
2405
|
-
}, [tokenIndex, amount, poolData, poolSpokeAssets]);
|
|
2406
|
-
}
|
|
2407
|
-
function useCreateSupplyLiquidityParams({
|
|
2408
|
-
poolData,
|
|
2409
|
-
poolKey,
|
|
2410
|
-
minPrice,
|
|
2411
|
-
maxPrice,
|
|
2412
|
-
liquidityToken0Amount,
|
|
2413
|
-
liquidityToken1Amount,
|
|
2414
|
-
slippageTolerance,
|
|
2415
|
-
positionId,
|
|
2416
|
-
isValidPosition
|
|
2417
|
-
}) {
|
|
2418
|
-
return react.useMemo(() => {
|
|
2419
|
-
return createSupplyLiquidityParamsProps({
|
|
2420
|
-
poolData,
|
|
2421
|
-
poolKey,
|
|
2422
|
-
minPrice,
|
|
2423
|
-
maxPrice,
|
|
2424
|
-
liquidityToken0Amount,
|
|
2425
|
-
liquidityToken1Amount,
|
|
2426
|
-
slippageTolerance,
|
|
2427
|
-
positionId,
|
|
2428
|
-
isValidPosition
|
|
2429
|
-
});
|
|
2430
|
-
}, [
|
|
2431
|
-
minPrice,
|
|
2432
|
-
maxPrice,
|
|
2433
|
-
liquidityToken0Amount,
|
|
2434
|
-
liquidityToken1Amount,
|
|
2435
|
-
slippageTolerance,
|
|
2436
|
-
poolData,
|
|
2437
|
-
poolKey,
|
|
2438
|
-
positionId,
|
|
2439
|
-
isValidPosition
|
|
2440
|
-
]);
|
|
2441
|
-
}
|
|
2442
|
-
function useCreateDecreaseLiquidityParams({
|
|
2443
|
-
poolKey,
|
|
2444
|
-
tokenId,
|
|
2445
|
-
percentage,
|
|
2446
|
-
positionInfo,
|
|
2447
|
-
slippageTolerance
|
|
2448
|
-
}) {
|
|
2449
|
-
return react.useMemo(() => {
|
|
2450
|
-
return createDecreaseLiquidityParamsProps({ poolKey, tokenId, percentage, positionInfo, slippageTolerance });
|
|
2451
|
-
}, [poolKey, tokenId, percentage, positionInfo, slippageTolerance]);
|
|
2452
|
-
}
|
|
2453
|
-
function useCreateWithdrawParams({
|
|
2454
|
-
tokenIndex,
|
|
2455
|
-
amount,
|
|
2456
|
-
poolData,
|
|
2457
|
-
poolSpokeAssets,
|
|
2458
|
-
dst
|
|
2459
|
-
}) {
|
|
2460
|
-
return react.useMemo(() => {
|
|
2461
|
-
if (!amount || Number.parseFloat(String(amount)) <= 0) {
|
|
2462
|
-
return void 0;
|
|
2463
|
-
}
|
|
2464
|
-
return createWithdrawParamsProps({ tokenIndex, amount, poolData, poolSpokeAssets, dst });
|
|
2465
|
-
}, [tokenIndex, amount, poolData, poolSpokeAssets, dst]);
|
|
2466
|
-
}
|
|
2467
|
-
function useClaimRewards({
|
|
2468
|
-
mutationOptions
|
|
2469
|
-
} = {}) {
|
|
2470
|
-
const { sodax } = useSodaxContext();
|
|
2471
|
-
const queryClient = reactQuery.useQueryClient();
|
|
2472
|
-
return useSafeMutation({
|
|
2473
|
-
mutationKey: ["dex", "claimRewards"],
|
|
2474
|
-
...mutationOptions,
|
|
2475
|
-
mutationFn: async (vars) => unwrapResult(await sodax.dex.clService.claimRewards({ ...vars, raw: false })),
|
|
2476
|
-
onSuccess: async (data, vars, ctx) => {
|
|
2477
|
-
const { params } = vars;
|
|
2478
|
-
queryClient.invalidateQueries({
|
|
2479
|
-
queryKey: ["dex", "positionInfo", params.tokenId.toString(), params.poolKey]
|
|
2480
|
-
});
|
|
2481
|
-
queryClient.invalidateQueries({ queryKey: ["dex", "poolBalances", params.srcChainKey, params.srcAddress] });
|
|
2482
|
-
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
2483
|
-
}
|
|
2484
|
-
});
|
|
2485
|
-
}
|
|
2486
|
-
var SodaxProvider = ({ children, config }) => {
|
|
2487
|
-
const configRef = react.useRef(config);
|
|
2488
|
-
const frozen = configRef.current;
|
|
2489
|
-
const sodax = react.useMemo(() => new sdk.Sodax(frozen), [frozen]);
|
|
2490
|
-
return /* @__PURE__ */ jsxRuntime.jsx(SodaxContext.Provider, { value: { sodax }, children });
|
|
2491
|
-
};
|
|
2492
|
-
var defaultOnMutationError = (error) => {
|
|
2493
|
-
console.error("[sodax] Mutation error:", error);
|
|
2494
|
-
};
|
|
2495
|
-
function createSodaxQueryClient({
|
|
2496
|
-
onMutationError = defaultOnMutationError,
|
|
2497
|
-
config
|
|
2498
|
-
} = {}) {
|
|
2499
|
-
if (config?.mutationCache) {
|
|
2500
|
-
config.mutationCache.subscribe((event) => {
|
|
2501
|
-
if (event.type === "updated" && event.action.type === "error" && event.mutation.options.meta?.silent !== true) {
|
|
2502
|
-
onMutationError(event.action.error);
|
|
2503
|
-
}
|
|
2504
|
-
});
|
|
2505
|
-
return new reactQuery.QueryClient(config);
|
|
2506
|
-
}
|
|
2507
|
-
return new reactQuery.QueryClient({
|
|
2508
|
-
...config,
|
|
2509
|
-
mutationCache: new reactQuery.MutationCache({
|
|
2510
|
-
onError: (error, _vars, _ctx, mutation) => {
|
|
2511
|
-
if (mutation.options.meta?.silent === true) return;
|
|
2512
|
-
onMutationError(error);
|
|
2513
|
-
}
|
|
2514
|
-
})
|
|
2515
|
-
});
|
|
2516
|
-
}
|
|
2517
|
-
|
|
2518
|
-
exports.SodaxProvider = SodaxProvider;
|
|
2519
|
-
exports.clearRadfiSession = clearRadfiSession;
|
|
2520
|
-
exports.createDecreaseLiquidityParamsProps = createDecreaseLiquidityParamsProps;
|
|
2521
|
-
exports.createDepositParamsProps = createDepositParamsProps;
|
|
2522
|
-
exports.createSodaxQueryClient = createSodaxQueryClient;
|
|
2523
|
-
exports.createSupplyLiquidityParamsProps = createSupplyLiquidityParamsProps;
|
|
2524
|
-
exports.createWithdrawParamsProps = createWithdrawParamsProps;
|
|
2525
|
-
exports.getXBalancesQueryOptions = getXBalancesQueryOptions;
|
|
2526
|
-
exports.loadRadfiSession = loadRadfiSession;
|
|
2527
|
-
exports.saveRadfiSession = saveRadfiSession;
|
|
2528
|
-
exports.toResult = toResult;
|
|
2529
|
-
exports.unwrapResult = unwrapResult;
|
|
2530
|
-
exports.useAToken = useAToken;
|
|
2531
|
-
exports.useATokensBalances = useATokensBalances;
|
|
2532
|
-
exports.useApproveToken = useApproveToken;
|
|
2533
|
-
exports.useBackendAllMoneyMarketAssets = useBackendAllMoneyMarketAssets;
|
|
2534
|
-
exports.useBackendAllMoneyMarketBorrowers = useBackendAllMoneyMarketBorrowers;
|
|
2535
|
-
exports.useBackendIntentByHash = useBackendIntentByHash;
|
|
2536
|
-
exports.useBackendIntentByTxHash = useBackendIntentByTxHash;
|
|
2537
|
-
exports.useBackendMoneyMarketAsset = useBackendMoneyMarketAsset;
|
|
2538
|
-
exports.useBackendMoneyMarketAssetBorrowers = useBackendMoneyMarketAssetBorrowers;
|
|
2539
|
-
exports.useBackendMoneyMarketAssetSuppliers = useBackendMoneyMarketAssetSuppliers;
|
|
2540
|
-
exports.useBackendMoneyMarketPosition = useBackendMoneyMarketPosition;
|
|
2541
|
-
exports.useBackendOrderbook = useBackendOrderbook;
|
|
2542
|
-
exports.useBackendSubmitSwapTx = useBackendSubmitSwapTx;
|
|
2543
|
-
exports.useBackendSubmitSwapTxStatus = useBackendSubmitSwapTxStatus;
|
|
2544
|
-
exports.useBackendUserIntents = useBackendUserIntents;
|
|
2545
|
-
exports.useBitcoinBalance = useBitcoinBalance;
|
|
2546
|
-
exports.useBorrow = useBorrow;
|
|
2547
|
-
exports.useBridge = useBridge;
|
|
2548
|
-
exports.useBridgeAllowance = useBridgeAllowance;
|
|
2549
|
-
exports.useBridgeApprove = useBridgeApprove;
|
|
2550
|
-
exports.useCancelLimitOrder = useCancelLimitOrder;
|
|
2551
|
-
exports.useCancelSwap = useCancelSwap;
|
|
2552
|
-
exports.useCancelUnstake = useCancelUnstake;
|
|
2553
|
-
exports.useClaim = useClaim;
|
|
2554
|
-
exports.useClaimRewards = useClaimRewards;
|
|
2555
|
-
exports.useConvertedAssets = useConvertedAssets;
|
|
2556
|
-
exports.useCreateDecreaseLiquidityParams = useCreateDecreaseLiquidityParams;
|
|
2557
|
-
exports.useCreateDepositParams = useCreateDepositParams;
|
|
2558
|
-
exports.useCreateLimitOrder = useCreateLimitOrder;
|
|
2559
|
-
exports.useCreateSupplyLiquidityParams = useCreateSupplyLiquidityParams;
|
|
2560
|
-
exports.useCreateWithdrawParams = useCreateWithdrawParams;
|
|
2561
|
-
exports.useDecreaseLiquidity = useDecreaseLiquidity;
|
|
2562
|
-
exports.useDeriveUserWalletAddress = useDeriveUserWalletAddress;
|
|
2563
|
-
exports.useDexAllowance = useDexAllowance;
|
|
2564
|
-
exports.useDexApprove = useDexApprove;
|
|
2565
|
-
exports.useDexDeposit = useDexDeposit;
|
|
2566
|
-
exports.useDexWithdraw = useDexWithdraw;
|
|
2567
|
-
exports.useEstimateGas = useEstimateGas;
|
|
2568
|
-
exports.useExpiredUtxos = useExpiredUtxos;
|
|
2569
|
-
exports.useFeeClaimSwap = useFeeClaimSwap;
|
|
2570
|
-
exports.useFetchAssetsBalances = useFetchAssetsBalances;
|
|
2571
|
-
exports.useFundTradingWallet = useFundTradingWallet;
|
|
2572
|
-
exports.useGetAutoSwapPreferences = useGetAutoSwapPreferences;
|
|
2573
|
-
exports.useGetBridgeableAmount = useGetBridgeableAmount;
|
|
2574
|
-
exports.useGetBridgeableTokens = useGetBridgeableTokens;
|
|
2575
|
-
exports.useGetUserHubWalletAddress = useGetUserHubWalletAddress;
|
|
2576
|
-
exports.useHubAssetBalances = useHubAssetBalances;
|
|
2577
|
-
exports.useHubProvider = useHubProvider;
|
|
2578
|
-
exports.useInstantUnstake = useInstantUnstake;
|
|
2579
|
-
exports.useInstantUnstakeAllowance = useInstantUnstakeAllowance;
|
|
2580
|
-
exports.useInstantUnstakeApprove = useInstantUnstakeApprove;
|
|
2581
|
-
exports.useInstantUnstakeRatio = useInstantUnstakeRatio;
|
|
2582
|
-
exports.useIsTokenApproved = useIsTokenApproved;
|
|
2583
|
-
exports.useLiquidityAmounts = useLiquidityAmounts;
|
|
2584
|
-
exports.useMMAllowance = useMMAllowance;
|
|
2585
|
-
exports.useMMApprove = useMMApprove;
|
|
2586
|
-
exports.useMigrateBaln = useMigrateBaln;
|
|
2587
|
-
exports.useMigrateIcxToSoda = useMigrateIcxToSoda;
|
|
2588
|
-
exports.useMigratebnUSD = useMigratebnUSD;
|
|
2589
|
-
exports.useMigrationAllowance = useMigrationAllowance;
|
|
2590
|
-
exports.useMigrationApprove = useMigrationApprove;
|
|
2591
|
-
exports.usePoolBalances = usePoolBalances;
|
|
2592
|
-
exports.usePoolData = usePoolData;
|
|
2593
|
-
exports.usePools = usePools;
|
|
2594
|
-
exports.usePositionInfo = usePositionInfo;
|
|
2595
|
-
exports.useQuote = useQuote;
|
|
2596
|
-
exports.useRadfiAuth = useRadfiAuth;
|
|
2597
|
-
exports.useRadfiSession = useRadfiSession;
|
|
2598
|
-
exports.useRadfiWithdraw = useRadfiWithdraw;
|
|
2599
|
-
exports.useRenewUtxos = useRenewUtxos;
|
|
2600
|
-
exports.useRepay = useRepay;
|
|
2601
|
-
exports.useRequestTrustline = useRequestTrustline;
|
|
2602
|
-
exports.useReservesData = useReservesData;
|
|
2603
|
-
exports.useReservesHumanized = useReservesHumanized;
|
|
2604
|
-
exports.useReservesList = useReservesList;
|
|
2605
|
-
exports.useReservesUsdFormat = useReservesUsdFormat;
|
|
2606
|
-
exports.useRevertMigrateSodaToIcx = useRevertMigrateSodaToIcx;
|
|
2607
|
-
exports.useSafeMutation = useSafeMutation;
|
|
2608
|
-
exports.useSetSwapPreference = useSetSwapPreference;
|
|
2609
|
-
exports.useSodaxContext = useSodaxContext;
|
|
2610
|
-
exports.useStake = useStake;
|
|
2611
|
-
exports.useStakeAllowance = useStakeAllowance;
|
|
2612
|
-
exports.useStakeApprove = useStakeApprove;
|
|
2613
|
-
exports.useStakeRatio = useStakeRatio;
|
|
2614
|
-
exports.useStakingConfig = useStakingConfig;
|
|
2615
|
-
exports.useStakingInfo = useStakingInfo;
|
|
2616
|
-
exports.useStatus = useStatus;
|
|
2617
|
-
exports.useStellarTrustlineCheck = useStellarTrustlineCheck;
|
|
2618
|
-
exports.useSupply = useSupply;
|
|
2619
|
-
exports.useSupplyLiquidity = useSupplyLiquidity;
|
|
2620
|
-
exports.useSwap = useSwap;
|
|
2621
|
-
exports.useSwapAllowance = useSwapAllowance;
|
|
2622
|
-
exports.useSwapApprove = useSwapApprove;
|
|
2623
|
-
exports.useTradingWallet = useTradingWallet;
|
|
2624
|
-
exports.useTradingWalletBalance = useTradingWalletBalance;
|
|
2625
|
-
exports.useUnstake = useUnstake;
|
|
2626
|
-
exports.useUnstakeAllowance = useUnstakeAllowance;
|
|
2627
|
-
exports.useUnstakeApprove = useUnstakeApprove;
|
|
2628
|
-
exports.useUnstakingInfo = useUnstakingInfo;
|
|
2629
|
-
exports.useUnstakingInfoWithPenalty = useUnstakingInfoWithPenalty;
|
|
2630
|
-
exports.useUserFormattedSummary = useUserFormattedSummary;
|
|
2631
|
-
exports.useUserReservesData = useUserReservesData;
|
|
2632
|
-
exports.useWithdraw = useWithdraw;
|
|
2633
|
-
exports.useWithdrawHubAsset = useWithdrawHubAsset;
|
|
2634
|
-
exports.useXBalances = useXBalances;
|
|
2635
|
-
Object.keys(sdk).forEach(function (k) {
|
|
2636
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
2637
|
-
enumerable: true,
|
|
2638
|
-
get: function () { return sdk[k]; }
|
|
2639
|
-
});
|
|
2640
|
-
});
|
|
2641
|
-
//# sourceMappingURL=index.cjs.map
|
|
2642
|
-
//# sourceMappingURL=index.cjs.map
|