@sodax/dapp-kit 2.0.0-rc.9 → 2.1.0-rc.1
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 +141 -119
- package/dist/index.d.ts +939 -63
- package/dist/index.mjs +1086 -180
- package/package.json +3 -3
- package/src/hooks/_mutationContract.test.ts +17 -2
- package/src/hooks/backend/index.ts +1 -5
- package/src/hooks/backend/types.ts +1 -1
- package/src/hooks/bitcoin/index.ts +2 -0
- package/src/hooks/bitcoin/resolveBtcReadAddress.test.ts +54 -0
- package/src/hooks/bitcoin/resolveBtcReadAddress.ts +21 -0
- package/src/hooks/bitcoin/useBitcoinTradingSetup.ts +45 -0
- package/src/hooks/bitcoin/useEnsureRadfiAccessToken.ts +57 -0
- package/src/hooks/bitcoin/useFundTradingWallet.ts +1 -1
- package/src/hooks/bitcoin/useRadfiAuth.ts +2 -2
- package/src/hooks/bitcoin/useRadfiWithdraw.ts +2 -2
- package/src/hooks/bitcoin/useRenewUtxos.ts +2 -2
- package/src/hooks/bitcoin/useTradingWallet.ts +1 -1
- package/src/hooks/bridge/useBridgeApprove.ts +2 -1
- package/src/hooks/index.ts +3 -0
- package/src/hooks/leverageYield/index.ts +9 -0
- package/src/hooks/leverageYield/useLeverageYieldDeposit.ts +40 -0
- package/src/hooks/leverageYield/useLeverageYieldEffectiveApr.ts +42 -0
- package/src/hooks/leverageYield/useLeverageYieldNotifySolver.ts +34 -0
- package/src/hooks/leverageYield/useLeverageYieldPosition.ts +40 -0
- package/src/hooks/leverageYield/useLeverageYieldPreviewRedeem.ts +43 -0
- package/src/hooks/leverageYield/useLeverageYieldShareBalances.ts +74 -0
- package/src/hooks/leverageYield/useLeverageYieldTotalAssets.ts +36 -0
- package/src/hooks/leverageYield/useLeverageYieldVaultSwap.ts +50 -0
- package/src/hooks/leverageYield/useLeverageYieldWithdraw.ts +40 -0
- package/src/hooks/migrate/useMigrationApprove.ts +1 -3
- package/src/hooks/mm/useATokensBalances.ts +7 -1
- package/src/hooks/mm/useUserFormattedSummary.ts +5 -1
- package/src/hooks/mm/useUserReservesData.ts +5 -1
- package/src/hooks/mm/useWithdraw.ts +5 -1
- package/src/hooks/partner/index.ts +4 -0
- package/src/hooks/partner/useApproveToken.ts +1 -2
- package/src/hooks/partner/useFeeClaimWithdraw.ts +88 -0
- package/src/hooks/partner/useGetIntentDetails.ts +39 -0
- package/src/hooks/partner/useGetUserIntent.ts +35 -0
- package/src/hooks/partner/usePartnerCancelIntent.ts +52 -0
- package/src/hooks/shared/index.ts +6 -0
- package/src/hooks/shared/isUserRejectedError.test.ts +42 -0
- package/src/hooks/shared/isUserRejectedError.ts +30 -0
- package/src/hooks/shared/useEstablishTrustline.test.ts +89 -0
- package/src/hooks/shared/useEstablishTrustline.ts +72 -0
- package/src/hooks/shared/useGetUserHubWalletAddress.ts +5 -1
- package/src/hooks/shared/useNearStorageCheck.ts +45 -0
- package/src/hooks/shared/useNearStorageGate.ts +60 -0
- package/src/hooks/shared/useRegisterNearStorage.ts +46 -0
- package/src/hooks/shared/useRequestTrustline.test.ts +115 -0
- package/src/hooks/shared/useRequestTrustline.ts +41 -56
- package/src/hooks/shared/useSafeMutation.ts +1 -4
- package/src/hooks/shared/useStellarGate.test.ts +99 -0
- package/src/hooks/shared/useStellarGate.ts +102 -0
- package/src/hooks/shared/useStellarTrustlineCheck.test.ts +74 -0
- package/src/hooks/shared/useStellarTrustlineCheck.ts +39 -15
- package/src/hooks/sponsoring/index.ts +4 -0
- package/src/hooks/sponsoring/useActivateStellarAccount.test.ts +74 -0
- package/src/hooks/sponsoring/useActivateStellarAccount.ts +38 -0
- package/src/hooks/sponsoring/useSponsorConfig.test.ts +46 -0
- package/src/hooks/sponsoring/useSponsorConfig.ts +31 -0
- package/src/hooks/sponsoring/useStellarAccountActive.test.ts +50 -0
- package/src/hooks/sponsoring/useStellarAccountActive.ts +45 -0
- package/src/hooks/sponsoring/useStellarAccountStatus.test.ts +90 -0
- package/src/hooks/sponsoring/useStellarAccountStatus.ts +57 -0
- package/src/hooks/staking/useStakingConfig.ts +1 -3
- package/src/hooks/staking/useStakingInfo.ts +4 -4
- package/src/hooks/staking/useUnstake.ts +5 -1
- package/src/hooks/swap/useCreateLimitOrder.ts +1 -2
- package/src/hooks/swap/useSwap.ts +1 -5
- package/src/hooks/swapsApi/index.ts +41 -0
- package/src/hooks/swapsApi/isTerminalSwapIntentStatus.test.ts +24 -0
- package/src/hooks/swapsApi/isTerminalSwapIntentStatus.ts +11 -0
- package/src/hooks/swapsApi/useSwapsApiAllowance.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiApprove.ts +42 -0
- package/src/hooks/swapsApi/useSwapsApiCancelIntent.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiCreateIntent.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiDeadline.ts +36 -0
- package/src/hooks/swapsApi/useSwapsApiEstimateGas.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiFilledIntent.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiIntent.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiIntentExtraData.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiIntentHash.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiIntentPacket.ts +43 -0
- package/src/hooks/swapsApi/useSwapsApiPartnerFee.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiQuote.ts +55 -0
- package/src/hooks/swapsApi/useSwapsApiSolverFee.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiStatus.ts +45 -0
- package/src/hooks/swapsApi/useSwapsApiSubmitIntent.ts +43 -0
- package/src/hooks/{backend/useBackendSubmitSwapTx.ts → swapsApi/useSwapsApiSubmitTx.ts} +16 -17
- package/src/hooks/swapsApi/useSwapsApiSubmitTxStatus.ts +55 -0
- package/src/hooks/swapsApi/useSwapsApiTokens.ts +34 -0
- package/src/hooks/swapsApi/useSwapsApiTokensByChain.ts +40 -0
- package/src/index.ts +1 -1
- package/src/providers/SodaxProvider.tsx +2 -3
- package/src/providers/createSodaxQueryClient.ts +1 -5
- package/src/utils/dex-utils.ts +1 -4
- package/src/utils/index.ts +2 -0
- package/src/utils/nearStorageGate.test.ts +46 -0
- package/src/utils/nearStorageGate.ts +39 -0
- package/src/utils/stellarGate.test.ts +196 -0
- package/src/utils/stellarGate.ts +84 -0
- package/src/hooks/backend/useBackendSubmitSwapTxStatus.ts +0 -59
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createContext, useCallback, useContext, useState, useRef, useEffect, useMemo } from 'react';
|
|
3
|
-
import { ChainKeys, RadfiApiError, normalizePsbtToBase64, ClService, Sodax } from '@sodax/sdk';
|
|
1
|
+
import { isSodaxError, ChainKeys, STELLAR_TRUSTLINE_MIN_XLM_STROOPS, RadfiApiError, normalizePsbtToBase64, ClService, SPONSOR_CONFIG_TTL_MS, Sodax } from '@sodax/sdk';
|
|
4
2
|
export * from '@sodax/sdk';
|
|
3
|
+
import { useMutation, useQuery, useQueryClient, useQueries, QueryClient, MutationCache } from '@tanstack/react-query';
|
|
4
|
+
import { createContext, useCallback, useContext, useRef, useState, useEffect, useMemo } from 'react';
|
|
5
5
|
import { isAddress, erc20Abi, parseUnits } from 'viem';
|
|
6
6
|
import { jsx } from 'react/jsx-runtime';
|
|
7
7
|
|
|
8
|
+
// src/hooks/shared/isUserRejectedError.ts
|
|
9
|
+
function isUserRejectedError(error) {
|
|
10
|
+
return isSodaxError(error) && error.code === "USER_REJECTED";
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
// src/hooks/shared/unwrapResult.ts
|
|
9
14
|
function unwrapResult(result) {
|
|
10
15
|
if (!result.ok) {
|
|
@@ -72,127 +77,303 @@ function useDeriveUserWalletAddress({
|
|
|
72
77
|
...queryOptions
|
|
73
78
|
});
|
|
74
79
|
}
|
|
80
|
+
function getStellarTrustlineCheckQueryOptions({
|
|
81
|
+
sodax,
|
|
82
|
+
token,
|
|
83
|
+
amount,
|
|
84
|
+
chainId,
|
|
85
|
+
walletAddress
|
|
86
|
+
}) {
|
|
87
|
+
return {
|
|
88
|
+
// Key on chain, token, account, amount so editing the amount (or switching account/chain) re-queries.
|
|
89
|
+
queryKey: ["shared", "stellarTrustlineCheck", chainId, token, walletAddress, amount?.toString()],
|
|
90
|
+
queryFn: async () => {
|
|
91
|
+
if (chainId !== ChainKeys.STELLAR_MAINNET) return true;
|
|
92
|
+
if (!walletAddress || !token || !amount) return false;
|
|
93
|
+
return sodax.spoke.stellar.hasSufficientTrustline(token, amount, walletAddress);
|
|
94
|
+
},
|
|
95
|
+
enabled: !!walletAddress && !!token && !!amount
|
|
96
|
+
};
|
|
97
|
+
}
|
|
75
98
|
function useStellarTrustlineCheck({
|
|
76
99
|
params,
|
|
77
100
|
queryOptions
|
|
78
101
|
} = {}) {
|
|
79
102
|
const { sodax } = useSodaxContext();
|
|
80
|
-
const token = params?.token;
|
|
81
|
-
const amount = params?.amount;
|
|
82
|
-
const chainId = params?.chainId;
|
|
83
|
-
const walletProvider = params?.walletProvider;
|
|
84
103
|
return useQuery({
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
},
|
|
92
|
-
enabled: !!walletProvider && !!token && !!amount,
|
|
104
|
+
...getStellarTrustlineCheckQueryOptions({
|
|
105
|
+
sodax,
|
|
106
|
+
token: params?.token,
|
|
107
|
+
amount: params?.amount,
|
|
108
|
+
chainId: params?.chainId,
|
|
109
|
+
walletAddress: params?.walletAddress
|
|
110
|
+
}),
|
|
93
111
|
...queryOptions
|
|
94
112
|
});
|
|
95
113
|
}
|
|
96
|
-
function
|
|
114
|
+
function useEstablishTrustline({
|
|
115
|
+
mutationOptions
|
|
116
|
+
} = {}) {
|
|
97
117
|
const { sodax } = useSodaxContext();
|
|
98
118
|
const queryClient = useQueryClient();
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
token: token2,
|
|
106
|
-
amount,
|
|
107
|
-
srcChainKey,
|
|
108
|
-
walletProvider
|
|
109
|
-
}) => {
|
|
110
|
-
if (!token2 || !amount) {
|
|
111
|
-
const error2 = new Error("Token and amount are required");
|
|
112
|
-
setError(error2);
|
|
113
|
-
throw error2;
|
|
119
|
+
return useSafeMutation({
|
|
120
|
+
mutationKey: ["shared", "establishTrustline"],
|
|
121
|
+
...mutationOptions,
|
|
122
|
+
mutationFn: async ({ token, amount, srcChainKey, walletProvider }) => {
|
|
123
|
+
if (!token || !amount) {
|
|
124
|
+
throw new Error("Token and amount are required");
|
|
114
125
|
}
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
const srcAddress = await walletProvider.getWalletAddress();
|
|
127
|
+
return sodax.spoke.stellar.requestTrustline({
|
|
128
|
+
raw: false,
|
|
129
|
+
srcChainKey,
|
|
130
|
+
srcAddress,
|
|
131
|
+
token,
|
|
132
|
+
amount,
|
|
133
|
+
walletProvider
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
onSuccess: async (data, vars, ctx) => {
|
|
137
|
+
const srcAddress = await vars.walletProvider.getWalletAddress().catch(() => void 0);
|
|
138
|
+
queryClient.invalidateQueries({
|
|
139
|
+
queryKey: srcAddress ? ["shared", "stellarTrustlineCheck", vars.srcChainKey, vars.token, srcAddress] : ["shared", "stellarTrustlineCheck"]
|
|
140
|
+
});
|
|
141
|
+
queryClient.invalidateQueries({
|
|
142
|
+
queryKey: srcAddress ? ["sponsoring", "stellarAccountStatus", srcAddress] : ["sponsoring", "stellarAccountStatus"]
|
|
143
|
+
});
|
|
144
|
+
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", ChainKeys.STELLAR_MAINNET] });
|
|
145
|
+
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function useRequestTrustline(token) {
|
|
150
|
+
const { mutateAsync, isPending, isSuccess, error, data } = useEstablishTrustline();
|
|
151
|
+
const requested = useRef(false);
|
|
152
|
+
const lastData = useRef(null);
|
|
153
|
+
if (isSuccess) requested.current = true;
|
|
154
|
+
if (data !== void 0) lastData.current = data;
|
|
155
|
+
const requestTrustline = useCallback(
|
|
156
|
+
async (params) => {
|
|
117
157
|
try {
|
|
118
|
-
|
|
119
|
-
const result = await sodax.spoke.stellar.requestTrustline({
|
|
120
|
-
raw: false,
|
|
121
|
-
srcChainKey,
|
|
122
|
-
srcAddress,
|
|
123
|
-
token: token2,
|
|
124
|
-
amount,
|
|
125
|
-
walletProvider
|
|
126
|
-
});
|
|
127
|
-
setData(result);
|
|
128
|
-
setIsRequested(true);
|
|
129
|
-
queryClient.invalidateQueries({ queryKey: ["shared", "stellarTrustlineCheck", token2] });
|
|
130
|
-
return result;
|
|
158
|
+
return await mutateAsync(params);
|
|
131
159
|
} catch (err) {
|
|
132
|
-
|
|
133
|
-
setError(error2);
|
|
134
|
-
throw error2;
|
|
135
|
-
} finally {
|
|
136
|
-
setIsLoading(false);
|
|
160
|
+
throw err instanceof Error ? err : new Error("Unknown error occurred");
|
|
137
161
|
}
|
|
138
162
|
},
|
|
139
|
-
[
|
|
163
|
+
[mutateAsync]
|
|
140
164
|
);
|
|
141
|
-
return {
|
|
165
|
+
return {
|
|
166
|
+
requestTrustline,
|
|
167
|
+
isLoading: isPending,
|
|
168
|
+
isRequested: requested.current,
|
|
169
|
+
error,
|
|
170
|
+
data: lastData.current
|
|
171
|
+
};
|
|
142
172
|
}
|
|
143
|
-
function
|
|
173
|
+
function useNearStorageCheck({
|
|
144
174
|
params,
|
|
145
175
|
queryOptions
|
|
146
176
|
} = {}) {
|
|
147
177
|
const { sodax } = useSodaxContext();
|
|
148
|
-
const
|
|
149
|
-
const
|
|
178
|
+
const token = params?.token;
|
|
179
|
+
const accountId = params?.accountId;
|
|
180
|
+
const chainId = params?.chainId;
|
|
150
181
|
return useQuery({
|
|
151
|
-
queryKey: ["shared", "
|
|
182
|
+
queryKey: ["shared", "nearStorageCheck", chainId, token, accountId],
|
|
152
183
|
queryFn: async () => {
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return await sodax.hubProvider.getUserHubWalletAddress(spokeAddress, spokeChainId);
|
|
184
|
+
if (chainId !== ChainKeys.NEAR_MAINNET) return true;
|
|
185
|
+
if (!token || !accountId) return false;
|
|
186
|
+
return sodax.spoke.near.isStorageRegistered(token, accountId);
|
|
157
187
|
},
|
|
158
|
-
enabled: !!
|
|
159
|
-
refetchInterval: false,
|
|
188
|
+
enabled: !!token && !!accountId,
|
|
160
189
|
...queryOptions
|
|
161
190
|
});
|
|
162
191
|
}
|
|
163
|
-
|
|
164
|
-
|
|
192
|
+
function useRegisterNearStorage({
|
|
193
|
+
mutationOptions
|
|
194
|
+
} = {}) {
|
|
195
|
+
const { sodax } = useSodaxContext();
|
|
196
|
+
const queryClient = useQueryClient();
|
|
197
|
+
return useSafeMutation({
|
|
198
|
+
mutationKey: ["shared", "registerNearStorage"],
|
|
199
|
+
...mutationOptions,
|
|
200
|
+
mutationFn: async ({ token, accountId, walletProvider, deposit }) => sodax.spoke.near.registerStorage({ token, accountId, walletProvider, deposit, raw: false }),
|
|
201
|
+
onSuccess: async (data, vars, ctx) => {
|
|
202
|
+
queryClient.invalidateQueries({
|
|
203
|
+
queryKey: ["shared", "nearStorageCheck", ChainKeys.NEAR_MAINNET, vars.token, vars.accountId]
|
|
204
|
+
});
|
|
205
|
+
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
function resolveNearStorageGate(chainKey, check) {
|
|
210
|
+
const isNear = chainKey === ChainKeys.NEAR_MAINNET;
|
|
211
|
+
const isChecking = check.isLoading;
|
|
212
|
+
const isRegistered = check.data;
|
|
165
213
|
return {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
214
|
+
isNear,
|
|
215
|
+
needsRegistration: isNear && !isChecking && isRegistered === false,
|
|
216
|
+
blocksAction: isNear && (isChecking || isRegistered === false)
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/hooks/shared/useNearStorageGate.ts
|
|
221
|
+
function useNearStorageGate({
|
|
222
|
+
dstChainKey,
|
|
223
|
+
token,
|
|
224
|
+
accountId,
|
|
225
|
+
walletProvider
|
|
226
|
+
}) {
|
|
227
|
+
const nearWalletProvider = walletProvider?.chainType === "NEAR" ? walletProvider : void 0;
|
|
228
|
+
const storageCheck = useNearStorageCheck({ params: { token, accountId, chainId: dstChainKey } });
|
|
229
|
+
const { mutateAsyncSafe: register, isPending: isRegistering } = useRegisterNearStorage();
|
|
230
|
+
const { isNear, needsRegistration, blocksAction } = resolveNearStorageGate(dstChainKey, storageCheck);
|
|
231
|
+
const registerStorage = async () => {
|
|
232
|
+
if (!nearWalletProvider || !token || !accountId) return void 0;
|
|
233
|
+
return register({ token, accountId, walletProvider: nearWalletProvider });
|
|
234
|
+
};
|
|
235
|
+
return {
|
|
236
|
+
isNear,
|
|
237
|
+
needsRegistration,
|
|
238
|
+
blocksAction,
|
|
239
|
+
isChecking: storageCheck.isLoading,
|
|
240
|
+
isRegistering,
|
|
241
|
+
registerStorage
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function unresolved(check) {
|
|
245
|
+
return check.isLoading || check.data === void 0;
|
|
246
|
+
}
|
|
247
|
+
var NOT_STELLAR = {
|
|
248
|
+
isStellar: false,
|
|
249
|
+
needsActivation: false,
|
|
250
|
+
needsFunding: false,
|
|
251
|
+
needsTrustline: false,
|
|
252
|
+
checkFailed: false,
|
|
253
|
+
blocksAction: false
|
|
254
|
+
};
|
|
255
|
+
function resolveStellarGate(chainKey, inputs) {
|
|
256
|
+
const { statusCheck, trustlineCheck, isNativeToken } = inputs;
|
|
257
|
+
if (chainKey !== ChainKeys.STELLAR_MAINNET) return NOT_STELLAR;
|
|
258
|
+
const base = {
|
|
259
|
+
isStellar: true,
|
|
260
|
+
needsActivation: false,
|
|
261
|
+
needsFunding: false,
|
|
262
|
+
needsTrustline: false,
|
|
263
|
+
checkFailed: false
|
|
264
|
+
};
|
|
265
|
+
if (statusCheck.isError) return { ...base, checkFailed: true, blocksAction: true };
|
|
266
|
+
const status = statusCheck.data;
|
|
267
|
+
if (statusCheck.isLoading || status === void 0) return { ...base, blocksAction: true };
|
|
268
|
+
if (!status.exists) return { ...base, needsActivation: true, blocksAction: true };
|
|
269
|
+
if (isNativeToken) return { ...base, blocksAction: false };
|
|
270
|
+
if (trustlineCheck.isError) return { ...base, checkFailed: true, blocksAction: true };
|
|
271
|
+
if (unresolved(trustlineCheck)) return { ...base, blocksAction: true };
|
|
272
|
+
if (trustlineCheck.data === true) return { ...base, blocksAction: false };
|
|
273
|
+
if (!status.canAffordTrustline) return { ...base, needsFunding: true, blocksAction: true };
|
|
274
|
+
return { ...base, needsTrustline: true, blocksAction: true };
|
|
275
|
+
}
|
|
276
|
+
function useActivateStellarAccount({
|
|
277
|
+
mutationOptions
|
|
278
|
+
} = {}) {
|
|
279
|
+
const { sodax } = useSodaxContext();
|
|
280
|
+
const queryClient = useQueryClient();
|
|
281
|
+
return useSafeMutation({
|
|
282
|
+
mutationKey: ["sponsoring", "activateStellarAccount"],
|
|
283
|
+
...mutationOptions,
|
|
284
|
+
mutationFn: async (vars) => unwrapResult(await sodax.sponsoring.activateStellarAccount(vars)),
|
|
285
|
+
onSuccess: async (data, vars, ctx) => {
|
|
286
|
+
queryClient.invalidateQueries({ queryKey: ["sponsoring", "stellarAccountActive", vars.address] });
|
|
287
|
+
queryClient.invalidateQueries({ queryKey: ["sponsoring", "stellarAccountStatus", vars.address] });
|
|
288
|
+
queryClient.invalidateQueries({ queryKey: ["shared", "stellarTrustlineCheck"] });
|
|
289
|
+
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", ChainKeys.STELLAR_MAINNET] });
|
|
290
|
+
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
function getStellarAccountStatusQueryOptions({
|
|
295
|
+
sodax,
|
|
296
|
+
address
|
|
297
|
+
}) {
|
|
298
|
+
return {
|
|
299
|
+
queryKey: ["sponsoring", "stellarAccountStatus", address],
|
|
169
300
|
queryFn: async () => {
|
|
170
|
-
if (!
|
|
171
|
-
|
|
301
|
+
if (!address) {
|
|
302
|
+
return {
|
|
303
|
+
exists: false,
|
|
304
|
+
nativeBalanceStroops: 0n,
|
|
305
|
+
availableBalanceStroops: 0n,
|
|
306
|
+
canAffordTrustline: false,
|
|
307
|
+
// No account to read the network reserve for; the published value is the best guess.
|
|
308
|
+
trustlineMinXlmStroops: STELLAR_TRUSTLINE_MIN_XLM_STROOPS
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
const result = await sodax.sponsoring.getStellarAccountStatus({ address });
|
|
312
|
+
if (!result.ok) throw result.error;
|
|
313
|
+
return result.value;
|
|
172
314
|
},
|
|
173
|
-
enabled: !!
|
|
174
|
-
refetchInterval: REFETCH_INTERVAL_MS
|
|
315
|
+
enabled: !!address
|
|
175
316
|
};
|
|
176
317
|
}
|
|
177
|
-
function
|
|
318
|
+
function useStellarAccountStatus({
|
|
178
319
|
params,
|
|
179
320
|
queryOptions
|
|
180
321
|
} = {}) {
|
|
322
|
+
const { sodax } = useSodaxContext();
|
|
181
323
|
return useQuery({
|
|
182
|
-
...
|
|
183
|
-
xService: params?.xService,
|
|
184
|
-
xChainId: params?.xChainId,
|
|
185
|
-
xTokens: params?.xTokens ?? [],
|
|
186
|
-
address: params?.address
|
|
187
|
-
}),
|
|
324
|
+
...getStellarAccountStatusQueryOptions({ sodax, address: params?.address }),
|
|
188
325
|
...queryOptions
|
|
189
326
|
});
|
|
190
327
|
}
|
|
191
328
|
|
|
192
|
-
// src/hooks/
|
|
193
|
-
function
|
|
329
|
+
// src/hooks/shared/useStellarGate.ts
|
|
330
|
+
function useStellarGate({
|
|
331
|
+
dstChainKey,
|
|
332
|
+
token,
|
|
333
|
+
amount,
|
|
334
|
+
address,
|
|
335
|
+
walletProvider
|
|
336
|
+
}) {
|
|
194
337
|
const { sodax } = useSodaxContext();
|
|
195
|
-
|
|
338
|
+
const isStellarDestination = dstChainKey === ChainKeys.STELLAR_MAINNET;
|
|
339
|
+
const stellarWalletProvider = walletProvider?.chainType === "STELLAR" ? walletProvider : void 0;
|
|
340
|
+
const gatedAddress = isStellarDestination ? address : void 0;
|
|
341
|
+
const statusCheck = useStellarAccountStatus({ params: { address: gatedAddress } });
|
|
342
|
+
const trustlineAddress = statusCheck.data?.exists === true ? gatedAddress : void 0;
|
|
343
|
+
const trustlineCheck = useStellarTrustlineCheck({
|
|
344
|
+
params: { token, amount, chainId: dstChainKey, walletAddress: trustlineAddress }
|
|
345
|
+
});
|
|
346
|
+
const isNativeToken = isStellarDestination && !!token && !sodax.spoke.stellar.requiresTrustline(token);
|
|
347
|
+
const state = resolveStellarGate(dstChainKey, { statusCheck, trustlineCheck, isNativeToken });
|
|
348
|
+
const { mutateAsyncSafe: activateAccount, isPending: isActivating } = useActivateStellarAccount();
|
|
349
|
+
const { mutateAsyncSafe: establishTrustline, isPending: isRequestingTrustline } = useEstablishTrustline();
|
|
350
|
+
const activate = async () => {
|
|
351
|
+
if (!stellarWalletProvider || !address) return void 0;
|
|
352
|
+
return activateAccount({ address, walletProvider: stellarWalletProvider });
|
|
353
|
+
};
|
|
354
|
+
const requestTrustline = async () => {
|
|
355
|
+
if (!stellarWalletProvider || !token || amount === void 0) return void 0;
|
|
356
|
+
return establishTrustline({
|
|
357
|
+
token,
|
|
358
|
+
amount,
|
|
359
|
+
srcChainKey: ChainKeys.STELLAR_MAINNET,
|
|
360
|
+
walletProvider: stellarWalletProvider
|
|
361
|
+
});
|
|
362
|
+
};
|
|
363
|
+
const retry = () => {
|
|
364
|
+
void statusCheck.refetch();
|
|
365
|
+
void trustlineCheck.refetch();
|
|
366
|
+
};
|
|
367
|
+
return {
|
|
368
|
+
...state,
|
|
369
|
+
isChecking: statusCheck.isLoading || trustlineCheck.isLoading,
|
|
370
|
+
error: statusCheck.error ?? trustlineCheck.error ?? void 0,
|
|
371
|
+
retry,
|
|
372
|
+
isActivating,
|
|
373
|
+
isRequestingTrustline,
|
|
374
|
+
activate,
|
|
375
|
+
requestTrustline
|
|
376
|
+
};
|
|
196
377
|
}
|
|
197
378
|
var SESSION_KEY = (address) => `radfi_session_${address}`;
|
|
198
379
|
function saveRadfiSession(address, session) {
|
|
@@ -254,7 +435,7 @@ function useRadfiAuth({
|
|
|
254
435
|
clearRadfiSession(walletAddress);
|
|
255
436
|
}
|
|
256
437
|
throw new Error(
|
|
257
|
-
"This wallet is already registered with
|
|
438
|
+
"This wallet is already registered with Bound Exchange from another session. Please clear your browser storage for this site and try again, or wait for the previous session to expire."
|
|
258
439
|
);
|
|
259
440
|
}
|
|
260
441
|
throw err;
|
|
@@ -262,6 +443,99 @@ function useRadfiAuth({
|
|
|
262
443
|
}
|
|
263
444
|
});
|
|
264
445
|
}
|
|
446
|
+
|
|
447
|
+
// src/hooks/bitcoin/resolveBtcReadAddress.ts
|
|
448
|
+
function resolveBtcReadAddress(chainKey, address) {
|
|
449
|
+
if (chainKey !== ChainKeys.BITCOIN_MAINNET) return address;
|
|
450
|
+
return loadRadfiSession(address)?.tradingAddress ?? address;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// src/hooks/shared/useGetUserHubWalletAddress.ts
|
|
454
|
+
function useGetUserHubWalletAddress({
|
|
455
|
+
params,
|
|
456
|
+
queryOptions
|
|
457
|
+
} = {}) {
|
|
458
|
+
const { sodax } = useSodaxContext();
|
|
459
|
+
const spokeChainId = params?.spokeChainId;
|
|
460
|
+
const spokeAddress = params?.spokeAddress;
|
|
461
|
+
return useQuery({
|
|
462
|
+
queryKey: ["shared", "userHubWalletAddress", spokeChainId, spokeAddress],
|
|
463
|
+
queryFn: async () => {
|
|
464
|
+
if (!spokeChainId || !spokeAddress) {
|
|
465
|
+
throw new Error("Spoke chain id and address are required");
|
|
466
|
+
}
|
|
467
|
+
return await sodax.hubProvider.getUserHubWalletAddress(
|
|
468
|
+
resolveBtcReadAddress(spokeChainId, spokeAddress),
|
|
469
|
+
spokeChainId
|
|
470
|
+
);
|
|
471
|
+
},
|
|
472
|
+
enabled: !!spokeChainId && !!spokeAddress,
|
|
473
|
+
refetchInterval: false,
|
|
474
|
+
...queryOptions
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
var REFETCH_INTERVAL_MS = 5e3;
|
|
478
|
+
function getXBalancesQueryOptions({ xService, xChainId, xTokens, address }) {
|
|
479
|
+
return {
|
|
480
|
+
// Pair symbol + address: readable in devtools, unique on-chain (symbol alone
|
|
481
|
+
// can collide — e.g. scam tokens copying legitimate ticker).
|
|
482
|
+
queryKey: ["shared", "xBalances", xChainId, xTokens.map((x) => [x.symbol, x.address]), address],
|
|
483
|
+
queryFn: async () => {
|
|
484
|
+
if (!xService) return {};
|
|
485
|
+
return xService.getBalances(address, xTokens);
|
|
486
|
+
},
|
|
487
|
+
enabled: !!xService && !!address && xTokens.length > 0,
|
|
488
|
+
refetchInterval: REFETCH_INTERVAL_MS
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
function useXBalances({
|
|
492
|
+
params,
|
|
493
|
+
queryOptions
|
|
494
|
+
} = {}) {
|
|
495
|
+
return useQuery({
|
|
496
|
+
...getXBalancesQueryOptions({
|
|
497
|
+
xService: params?.xService,
|
|
498
|
+
xChainId: params?.xChainId,
|
|
499
|
+
xTokens: params?.xTokens ?? [],
|
|
500
|
+
address: params?.address
|
|
501
|
+
}),
|
|
502
|
+
...queryOptions
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// src/hooks/provider/useHubProvider.ts
|
|
507
|
+
function useHubProvider() {
|
|
508
|
+
const { sodax } = useSodaxContext();
|
|
509
|
+
return sodax.hubProvider;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// src/hooks/bitcoin/useEnsureRadfiAccessToken.ts
|
|
513
|
+
function useEnsureRadfiAccessToken({
|
|
514
|
+
mutationOptions
|
|
515
|
+
} = {}) {
|
|
516
|
+
const { sodax } = useSodaxContext();
|
|
517
|
+
return useSafeMutation({
|
|
518
|
+
mutationKey: ["bitcoin", "ensureAccessToken"],
|
|
519
|
+
...mutationOptions,
|
|
520
|
+
mutationFn: async ({ walletProvider }) => {
|
|
521
|
+
const radfi = sodax.spoke.bitcoin.radfi;
|
|
522
|
+
const walletAddress = await walletProvider.getWalletAddress();
|
|
523
|
+
const session = loadRadfiSession(walletAddress);
|
|
524
|
+
if (session?.refreshToken && !radfi.refreshToken) {
|
|
525
|
+
radfi.setRadfiAccessToken(session.accessToken, session.refreshToken);
|
|
526
|
+
}
|
|
527
|
+
await radfi.ensureRadfiAccessToken(walletProvider);
|
|
528
|
+
const accessToken = radfi.accessToken;
|
|
529
|
+
if (!accessToken) {
|
|
530
|
+
throw new Error("Failed to obtain a Bound Exchange access token");
|
|
531
|
+
}
|
|
532
|
+
if (session) {
|
|
533
|
+
saveRadfiSession(walletAddress, { ...session, accessToken, refreshToken: radfi.refreshToken });
|
|
534
|
+
}
|
|
535
|
+
return accessToken;
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
}
|
|
265
539
|
var REFRESH_INTERVAL = 5 * 60 * 1e3;
|
|
266
540
|
function useRadfiSession(walletProvider) {
|
|
267
541
|
const { sodax } = useSodaxContext();
|
|
@@ -397,6 +671,19 @@ function useTradingWalletBalance({
|
|
|
397
671
|
...queryOptions
|
|
398
672
|
});
|
|
399
673
|
}
|
|
674
|
+
var INERT = { wallet: void 0, tradingBalance: void 0 };
|
|
675
|
+
function useBitcoinTradingSetup({
|
|
676
|
+
chainKey,
|
|
677
|
+
walletProvider,
|
|
678
|
+
address
|
|
679
|
+
}) {
|
|
680
|
+
const isBitcoin = chainKey === ChainKeys.BITCOIN_MAINNET;
|
|
681
|
+
const wallet = isBitcoin ? walletProvider : void 0;
|
|
682
|
+
const { tradingAddress } = useTradingWallet(isBitcoin ? address : void 0);
|
|
683
|
+
const { data: tradingBalance } = useTradingWalletBalance({ params: { walletProvider: wallet, tradingAddress } });
|
|
684
|
+
if (!isBitcoin) return INERT;
|
|
685
|
+
return { wallet, tradingBalance };
|
|
686
|
+
}
|
|
400
687
|
function useExpiredUtxos({
|
|
401
688
|
params,
|
|
402
689
|
queryOptions
|
|
@@ -432,7 +719,7 @@ function useRenewUtxos({
|
|
|
432
719
|
const session = loadRadfiSession(userAddress);
|
|
433
720
|
const accessToken = session?.accessToken || radfi.accessToken;
|
|
434
721
|
if (!accessToken) {
|
|
435
|
-
throw new Error("
|
|
722
|
+
throw new Error("Bound Exchange authentication required. Please login first.");
|
|
436
723
|
}
|
|
437
724
|
const buildResult = await radfi.buildRenewUtxoTransaction({ userAddress, txIdVouts }, accessToken);
|
|
438
725
|
const signedTx = await walletProvider.signTransaction(buildResult.base64Psbt, false);
|
|
@@ -460,7 +747,7 @@ function useRadfiWithdraw({
|
|
|
460
747
|
const session = loadRadfiSession(userAddress);
|
|
461
748
|
const accessToken = session?.accessToken || radfi.accessToken;
|
|
462
749
|
if (!accessToken) {
|
|
463
|
-
throw new Error("
|
|
750
|
+
throw new Error("Bound Exchange authentication required. Please login first.");
|
|
464
751
|
}
|
|
465
752
|
const buildResult = await radfi.withdrawToUser({ userAddress, amount, tokenId, withdrawTo }, accessToken);
|
|
466
753
|
const signedTx = await walletProvider.signTransaction(buildResult.base64Psbt, false);
|
|
@@ -581,7 +868,10 @@ function useUserReservesData({
|
|
|
581
868
|
if (!spokeChainKey || !userAddress) {
|
|
582
869
|
throw new Error("spokeChainKey and userAddress are required");
|
|
583
870
|
}
|
|
584
|
-
return sodax.moneyMarket.data.getUserReservesData(
|
|
871
|
+
return sodax.moneyMarket.data.getUserReservesData(
|
|
872
|
+
spokeChainKey,
|
|
873
|
+
resolveBtcReadAddress(spokeChainKey, userAddress)
|
|
874
|
+
);
|
|
585
875
|
},
|
|
586
876
|
enabled: !!spokeChainKey && !!userAddress,
|
|
587
877
|
refetchInterval: 5e3,
|
|
@@ -707,7 +997,10 @@ function useATokensBalances({
|
|
|
707
997
|
throw new Error(`Invalid aToken address: ${aToken}`);
|
|
708
998
|
}
|
|
709
999
|
}
|
|
710
|
-
const hubWalletAddress = await sodax.hubProvider.getUserHubWalletAddress(
|
|
1000
|
+
const hubWalletAddress = await sodax.hubProvider.getUserHubWalletAddress(
|
|
1001
|
+
resolveBtcReadAddress(spokeChainKey, userAddress),
|
|
1002
|
+
spokeChainKey
|
|
1003
|
+
);
|
|
711
1004
|
return sodax.moneyMarket.data.getATokensBalances(aTokens, hubWalletAddress);
|
|
712
1005
|
},
|
|
713
1006
|
enabled: aTokens.length > 0 && !!spokeChainKey && !!userAddress,
|
|
@@ -742,7 +1035,10 @@ function useUserFormattedSummary({
|
|
|
742
1035
|
}
|
|
743
1036
|
const [reserves, userReserves] = await Promise.all([
|
|
744
1037
|
sodax.moneyMarket.data.getReservesHumanized(),
|
|
745
|
-
sodax.moneyMarket.data.getUserReservesHumanized(
|
|
1038
|
+
sodax.moneyMarket.data.getUserReservesHumanized(
|
|
1039
|
+
spokeChainKey,
|
|
1040
|
+
resolveBtcReadAddress(spokeChainKey, userAddress)
|
|
1041
|
+
)
|
|
746
1042
|
]);
|
|
747
1043
|
const formattedReserves = sodax.moneyMarket.data.formatReservesUSD(
|
|
748
1044
|
sodax.moneyMarket.data.buildReserveDataWithPrice(reserves)
|
|
@@ -956,189 +1252,500 @@ var useBackendUserIntents = ({
|
|
|
956
1252
|
...queryOptions
|
|
957
1253
|
});
|
|
958
1254
|
};
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
mutationOptions
|
|
1255
|
+
var useBackendOrderbook = ({
|
|
1256
|
+
params,
|
|
1257
|
+
queryOptions
|
|
963
1258
|
} = {}) => {
|
|
964
1259
|
const { sodax } = useSodaxContext();
|
|
965
|
-
|
|
966
|
-
|
|
1260
|
+
const pagination = params?.pagination;
|
|
1261
|
+
return useQuery({
|
|
1262
|
+
queryKey: ["backend", "orderbook", pagination?.offset, pagination?.limit],
|
|
1263
|
+
queryFn: async () => {
|
|
1264
|
+
if (!pagination?.offset || !pagination?.limit) {
|
|
1265
|
+
throw new Error("Pagination offset and limit are required");
|
|
1266
|
+
}
|
|
1267
|
+
return unwrapResult(await sodax.backendApi.getOrderbook(pagination));
|
|
1268
|
+
},
|
|
1269
|
+
enabled: !!pagination?.offset && !!pagination?.limit,
|
|
1270
|
+
staleTime: 30 * 1e3,
|
|
967
1271
|
retry: 3,
|
|
968
|
-
...
|
|
969
|
-
mutationFn: async ({ request, apiConfig }) => unwrapResult(await sodax.backendApi.submitSwapTx(request, apiConfig))
|
|
1272
|
+
...queryOptions
|
|
970
1273
|
});
|
|
971
1274
|
};
|
|
972
|
-
var
|
|
1275
|
+
var useBackendMoneyMarketPosition = ({
|
|
973
1276
|
params,
|
|
974
1277
|
queryOptions
|
|
975
1278
|
} = {}) => {
|
|
976
1279
|
const { sodax } = useSodaxContext();
|
|
977
|
-
const
|
|
978
|
-
const srcChainKey = params?.srcChainKey;
|
|
979
|
-
const apiConfig = params?.apiConfig;
|
|
1280
|
+
const userAddress = params?.userAddress;
|
|
980
1281
|
return useQuery({
|
|
981
|
-
queryKey: ["backend", "
|
|
1282
|
+
queryKey: ["backend", "mm", "position", userAddress],
|
|
982
1283
|
queryFn: async () => {
|
|
983
|
-
if (!
|
|
1284
|
+
if (!userAddress) return void 0;
|
|
1285
|
+
return unwrapResult(await sodax.backendApi.getMoneyMarketPosition(userAddress));
|
|
1286
|
+
},
|
|
1287
|
+
enabled: !!userAddress && userAddress.length > 0,
|
|
1288
|
+
retry: 3,
|
|
1289
|
+
...queryOptions
|
|
1290
|
+
});
|
|
1291
|
+
};
|
|
1292
|
+
var useBackendAllMoneyMarketAssets = ({
|
|
1293
|
+
queryOptions
|
|
1294
|
+
} = {}) => {
|
|
1295
|
+
const { sodax } = useSodaxContext();
|
|
1296
|
+
return useQuery({
|
|
1297
|
+
queryKey: ["backend", "mm", "assets", "all"],
|
|
1298
|
+
queryFn: async () => {
|
|
1299
|
+
return unwrapResult(await sodax.backendApi.getAllMoneyMarketAssets());
|
|
1300
|
+
},
|
|
1301
|
+
retry: 3,
|
|
1302
|
+
...queryOptions
|
|
1303
|
+
});
|
|
1304
|
+
};
|
|
1305
|
+
var useBackendMoneyMarketAsset = ({
|
|
1306
|
+
params,
|
|
1307
|
+
queryOptions
|
|
1308
|
+
} = {}) => {
|
|
1309
|
+
const { sodax } = useSodaxContext();
|
|
1310
|
+
const reserveAddress = params?.reserveAddress;
|
|
1311
|
+
return useQuery({
|
|
1312
|
+
queryKey: ["backend", "mm", "asset", reserveAddress],
|
|
1313
|
+
queryFn: async () => {
|
|
1314
|
+
if (!reserveAddress) return void 0;
|
|
1315
|
+
return unwrapResult(await sodax.backendApi.getMoneyMarketAsset(reserveAddress));
|
|
1316
|
+
},
|
|
1317
|
+
enabled: !!reserveAddress && reserveAddress.length > 0,
|
|
1318
|
+
retry: 3,
|
|
1319
|
+
...queryOptions
|
|
1320
|
+
});
|
|
1321
|
+
};
|
|
1322
|
+
var useBackendMoneyMarketAssetBorrowers = ({
|
|
1323
|
+
params,
|
|
1324
|
+
queryOptions
|
|
1325
|
+
} = {}) => {
|
|
1326
|
+
const { sodax } = useSodaxContext();
|
|
1327
|
+
const reserveAddress = params?.reserveAddress;
|
|
1328
|
+
const pagination = params?.pagination;
|
|
1329
|
+
return useQuery({
|
|
1330
|
+
queryKey: ["backend", "mm", "asset", "borrowers", reserveAddress, pagination],
|
|
1331
|
+
queryFn: async () => {
|
|
1332
|
+
if (!reserveAddress || !pagination?.offset || !pagination?.limit) {
|
|
1333
|
+
return void 0;
|
|
1334
|
+
}
|
|
984
1335
|
return unwrapResult(
|
|
985
|
-
await sodax.backendApi.
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
},
|
|
990
|
-
apiConfig
|
|
991
|
-
)
|
|
1336
|
+
await sodax.backendApi.getMoneyMarketAssetBorrowers(reserveAddress, {
|
|
1337
|
+
offset: pagination.offset,
|
|
1338
|
+
limit: pagination.limit
|
|
1339
|
+
})
|
|
992
1340
|
);
|
|
993
1341
|
},
|
|
994
|
-
enabled: !!
|
|
1342
|
+
enabled: !!reserveAddress && !!pagination?.offset && !!pagination?.limit,
|
|
995
1343
|
retry: 3,
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1344
|
+
...queryOptions
|
|
1345
|
+
});
|
|
1346
|
+
};
|
|
1347
|
+
var useBackendMoneyMarketAssetSuppliers = ({
|
|
1348
|
+
params,
|
|
1349
|
+
queryOptions
|
|
1350
|
+
} = {}) => {
|
|
1351
|
+
const { sodax } = useSodaxContext();
|
|
1352
|
+
const reserveAddress = params?.reserveAddress;
|
|
1353
|
+
const pagination = params?.pagination;
|
|
1354
|
+
return useQuery({
|
|
1355
|
+
queryKey: ["backend", "mm", "asset", "suppliers", reserveAddress, pagination],
|
|
1356
|
+
queryFn: async () => {
|
|
1357
|
+
if (!reserveAddress || !pagination?.offset || !pagination?.limit) {
|
|
1358
|
+
return void 0;
|
|
1359
|
+
}
|
|
1360
|
+
return unwrapResult(
|
|
1361
|
+
await sodax.backendApi.getMoneyMarketAssetSuppliers(reserveAddress, {
|
|
1362
|
+
offset: pagination.offset,
|
|
1363
|
+
limit: pagination.limit
|
|
1364
|
+
})
|
|
1365
|
+
);
|
|
1000
1366
|
},
|
|
1367
|
+
enabled: !!reserveAddress && !!pagination?.offset && !!pagination?.limit,
|
|
1368
|
+
retry: 3,
|
|
1001
1369
|
...queryOptions
|
|
1002
1370
|
});
|
|
1003
1371
|
};
|
|
1004
|
-
var
|
|
1372
|
+
var useBackendAllMoneyMarketBorrowers = ({
|
|
1005
1373
|
params,
|
|
1006
1374
|
queryOptions
|
|
1007
1375
|
} = {}) => {
|
|
1008
1376
|
const { sodax } = useSodaxContext();
|
|
1009
1377
|
const pagination = params?.pagination;
|
|
1010
1378
|
return useQuery({
|
|
1011
|
-
queryKey: ["backend", "
|
|
1379
|
+
queryKey: ["backend", "mm", "borrowers", "all", pagination],
|
|
1012
1380
|
queryFn: async () => {
|
|
1013
1381
|
if (!pagination?.offset || !pagination?.limit) {
|
|
1014
|
-
|
|
1382
|
+
return void 0;
|
|
1015
1383
|
}
|
|
1016
|
-
return unwrapResult(
|
|
1384
|
+
return unwrapResult(
|
|
1385
|
+
await sodax.backendApi.getAllMoneyMarketBorrowers({
|
|
1386
|
+
offset: pagination.offset,
|
|
1387
|
+
limit: pagination.limit
|
|
1388
|
+
})
|
|
1389
|
+
);
|
|
1017
1390
|
},
|
|
1018
1391
|
enabled: !!pagination?.offset && !!pagination?.limit,
|
|
1019
|
-
staleTime: 30 * 1e3,
|
|
1020
1392
|
retry: 3,
|
|
1021
1393
|
...queryOptions
|
|
1022
1394
|
});
|
|
1023
1395
|
};
|
|
1024
|
-
var
|
|
1396
|
+
var useSwapsApiTokens = ({
|
|
1025
1397
|
params,
|
|
1026
1398
|
queryOptions
|
|
1027
1399
|
} = {}) => {
|
|
1028
1400
|
const { sodax } = useSodaxContext();
|
|
1029
|
-
const
|
|
1401
|
+
const apiConfig = params?.apiConfig;
|
|
1030
1402
|
return useQuery({
|
|
1031
|
-
queryKey: ["
|
|
1403
|
+
queryKey: ["swapsApi", "tokens"],
|
|
1404
|
+
queryFn: async () => unwrapResult(await sodax.api.swaps.getTokens(apiConfig)),
|
|
1405
|
+
retry: 3,
|
|
1406
|
+
...queryOptions
|
|
1407
|
+
});
|
|
1408
|
+
};
|
|
1409
|
+
var useSwapsApiTokensByChain = ({
|
|
1410
|
+
params,
|
|
1411
|
+
queryOptions
|
|
1412
|
+
} = {}) => {
|
|
1413
|
+
const { sodax } = useSodaxContext();
|
|
1414
|
+
const chainKey = params?.chainKey;
|
|
1415
|
+
const apiConfig = params?.apiConfig;
|
|
1416
|
+
return useQuery({
|
|
1417
|
+
queryKey: ["swapsApi", "tokens", chainKey],
|
|
1032
1418
|
queryFn: async () => {
|
|
1033
|
-
if (!
|
|
1034
|
-
return unwrapResult(await sodax.
|
|
1419
|
+
if (!chainKey) return void 0;
|
|
1420
|
+
return unwrapResult(await sodax.api.swaps.getTokensByChain(chainKey, apiConfig));
|
|
1035
1421
|
},
|
|
1036
|
-
enabled: !!
|
|
1422
|
+
enabled: !!chainKey && chainKey.length > 0,
|
|
1037
1423
|
retry: 3,
|
|
1038
1424
|
...queryOptions
|
|
1039
1425
|
});
|
|
1040
1426
|
};
|
|
1041
|
-
var
|
|
1427
|
+
var useSwapsApiQuote = ({
|
|
1428
|
+
params,
|
|
1042
1429
|
queryOptions
|
|
1043
1430
|
} = {}) => {
|
|
1044
1431
|
const { sodax } = useSodaxContext();
|
|
1432
|
+
const body = params?.body;
|
|
1433
|
+
const query = params?.query;
|
|
1434
|
+
const apiConfig = params?.apiConfig;
|
|
1045
1435
|
return useQuery({
|
|
1046
|
-
|
|
1436
|
+
// Hash the whole request body so every quote input — including partnerFee and the other
|
|
1437
|
+
// SwapExtrasV2 fields — is a cache dimension; a partnerFee change alters the quote and must
|
|
1438
|
+
// miss the cache. QuoteRequestV2 is bigint-free (compile-time guaranteed), so React Query's
|
|
1439
|
+
// default key hashing handles the object directly.
|
|
1440
|
+
queryKey: ["swapsApi", "quote", body, query?.includeTxData ?? false],
|
|
1047
1441
|
queryFn: async () => {
|
|
1048
|
-
|
|
1442
|
+
if (!body) return void 0;
|
|
1443
|
+
return unwrapResult(await sodax.api.swaps.getQuote(body, query, apiConfig));
|
|
1049
1444
|
},
|
|
1445
|
+
enabled: !!body,
|
|
1050
1446
|
retry: 3,
|
|
1051
1447
|
...queryOptions
|
|
1052
1448
|
});
|
|
1053
1449
|
};
|
|
1054
|
-
var
|
|
1450
|
+
var useSwapsApiDeadline = ({
|
|
1055
1451
|
params,
|
|
1056
1452
|
queryOptions
|
|
1057
1453
|
} = {}) => {
|
|
1058
1454
|
const { sodax } = useSodaxContext();
|
|
1059
|
-
const
|
|
1455
|
+
const query = params?.query;
|
|
1456
|
+
const apiConfig = params?.apiConfig;
|
|
1457
|
+
return useQuery({
|
|
1458
|
+
queryKey: ["swapsApi", "deadline", query?.offsetSeconds ?? null],
|
|
1459
|
+
queryFn: async () => unwrapResult(await sodax.api.swaps.getDeadline(query, apiConfig)),
|
|
1460
|
+
retry: 3,
|
|
1461
|
+
...queryOptions
|
|
1462
|
+
});
|
|
1463
|
+
};
|
|
1464
|
+
var useSwapsApiAllowance = ({
|
|
1465
|
+
params,
|
|
1466
|
+
queryOptions
|
|
1467
|
+
} = {}) => {
|
|
1468
|
+
const { sodax } = useSodaxContext();
|
|
1469
|
+
const body = params?.body;
|
|
1470
|
+
const apiConfig = params?.apiConfig;
|
|
1471
|
+
return useQuery({
|
|
1472
|
+
queryKey: ["swapsApi", "allowance", body?.srcChainKey, body?.inputToken, body?.inputAmount, body?.srcAddress],
|
|
1473
|
+
queryFn: async () => {
|
|
1474
|
+
if (!body) return void 0;
|
|
1475
|
+
return unwrapResult(await sodax.api.swaps.checkAllowance(body, apiConfig));
|
|
1476
|
+
},
|
|
1477
|
+
enabled: !!body,
|
|
1478
|
+
retry: 3,
|
|
1479
|
+
...queryOptions
|
|
1480
|
+
});
|
|
1481
|
+
};
|
|
1482
|
+
|
|
1483
|
+
// src/hooks/swapsApi/useSwapsApiApprove.ts
|
|
1484
|
+
var useSwapsApiApprove = ({
|
|
1485
|
+
mutationOptions
|
|
1486
|
+
} = {}) => {
|
|
1487
|
+
const { sodax } = useSodaxContext();
|
|
1488
|
+
return useSafeMutation({
|
|
1489
|
+
mutationKey: ["swapsApi", "approve"],
|
|
1490
|
+
retry: 3,
|
|
1491
|
+
...mutationOptions,
|
|
1492
|
+
mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.approve(body, apiConfig))
|
|
1493
|
+
});
|
|
1494
|
+
};
|
|
1495
|
+
|
|
1496
|
+
// src/hooks/swapsApi/useSwapsApiCreateIntent.ts
|
|
1497
|
+
var useSwapsApiCreateIntent = ({
|
|
1498
|
+
mutationOptions
|
|
1499
|
+
} = {}) => {
|
|
1500
|
+
const { sodax } = useSodaxContext();
|
|
1501
|
+
return useSafeMutation({
|
|
1502
|
+
mutationKey: ["swapsApi", "createIntent"],
|
|
1503
|
+
retry: 3,
|
|
1504
|
+
...mutationOptions,
|
|
1505
|
+
mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.createIntent(body, apiConfig))
|
|
1506
|
+
});
|
|
1507
|
+
};
|
|
1508
|
+
|
|
1509
|
+
// src/hooks/swapsApi/useSwapsApiSubmitIntent.ts
|
|
1510
|
+
var useSwapsApiSubmitIntent = ({
|
|
1511
|
+
mutationOptions
|
|
1512
|
+
} = {}) => {
|
|
1513
|
+
const { sodax } = useSodaxContext();
|
|
1514
|
+
return useSafeMutation({
|
|
1515
|
+
mutationKey: ["swapsApi", "submitIntent"],
|
|
1516
|
+
retry: false,
|
|
1517
|
+
...mutationOptions,
|
|
1518
|
+
mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.submitIntent(body, apiConfig))
|
|
1519
|
+
});
|
|
1520
|
+
};
|
|
1521
|
+
|
|
1522
|
+
// src/hooks/swapsApi/isTerminalSwapIntentStatus.ts
|
|
1523
|
+
var isTerminalSwapIntentStatus = (status) => status === 3 || status === 4;
|
|
1524
|
+
|
|
1525
|
+
// src/hooks/swapsApi/useSwapsApiStatus.ts
|
|
1526
|
+
var useSwapsApiStatus = ({
|
|
1527
|
+
params,
|
|
1528
|
+
queryOptions
|
|
1529
|
+
} = {}) => {
|
|
1530
|
+
const { sodax } = useSodaxContext();
|
|
1531
|
+
const intentTxHash = params?.intentTxHash;
|
|
1532
|
+
const apiConfig = params?.apiConfig;
|
|
1533
|
+
return useQuery({
|
|
1534
|
+
queryKey: ["swapsApi", "status", intentTxHash],
|
|
1535
|
+
queryFn: async () => {
|
|
1536
|
+
if (!intentTxHash) return void 0;
|
|
1537
|
+
return unwrapResult(await sodax.api.swaps.getStatus({ intentTxHash }, apiConfig));
|
|
1538
|
+
},
|
|
1539
|
+
enabled: !!intentTxHash && intentTxHash.length > 0,
|
|
1540
|
+
retry: 3,
|
|
1541
|
+
refetchInterval: (query) => isTerminalSwapIntentStatus(query.state.data?.status) ? false : 1e3,
|
|
1542
|
+
...queryOptions
|
|
1543
|
+
});
|
|
1544
|
+
};
|
|
1545
|
+
|
|
1546
|
+
// src/hooks/swapsApi/useSwapsApiCancelIntent.ts
|
|
1547
|
+
var useSwapsApiCancelIntent = ({
|
|
1548
|
+
mutationOptions
|
|
1549
|
+
} = {}) => {
|
|
1550
|
+
const { sodax } = useSodaxContext();
|
|
1551
|
+
return useSafeMutation({
|
|
1552
|
+
mutationKey: ["swapsApi", "cancelIntent"],
|
|
1553
|
+
retry: 3,
|
|
1554
|
+
...mutationOptions,
|
|
1555
|
+
mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.cancelIntent(body, apiConfig))
|
|
1556
|
+
});
|
|
1557
|
+
};
|
|
1558
|
+
var useSwapsApiIntentHash = ({
|
|
1559
|
+
params,
|
|
1560
|
+
queryOptions
|
|
1561
|
+
} = {}) => {
|
|
1562
|
+
const { sodax } = useSodaxContext();
|
|
1563
|
+
const intent = params?.intent;
|
|
1564
|
+
const apiConfig = params?.apiConfig;
|
|
1565
|
+
return useQuery({
|
|
1566
|
+
queryKey: ["swapsApi", "intentHash", intent?.intentId?.toString()],
|
|
1567
|
+
queryFn: async () => {
|
|
1568
|
+
if (!intent) return void 0;
|
|
1569
|
+
return unwrapResult(await sodax.api.swaps.getIntentHash({ intent }, apiConfig));
|
|
1570
|
+
},
|
|
1571
|
+
enabled: !!intent,
|
|
1572
|
+
retry: 3,
|
|
1573
|
+
...queryOptions
|
|
1574
|
+
});
|
|
1575
|
+
};
|
|
1576
|
+
var useSwapsApiIntentPacket = ({
|
|
1577
|
+
params,
|
|
1578
|
+
queryOptions
|
|
1579
|
+
} = {}) => {
|
|
1580
|
+
const { sodax } = useSodaxContext();
|
|
1581
|
+
const body = params?.body;
|
|
1582
|
+
const apiConfig = params?.apiConfig;
|
|
1583
|
+
return useQuery({
|
|
1584
|
+
queryKey: ["swapsApi", "intentPacket", body?.chainId, body?.fillTxHash],
|
|
1585
|
+
queryFn: async () => {
|
|
1586
|
+
if (!body) return void 0;
|
|
1587
|
+
return unwrapResult(await sodax.api.swaps.getSolvedIntentPacket(body, apiConfig));
|
|
1588
|
+
},
|
|
1589
|
+
enabled: !!body,
|
|
1590
|
+
retry: 3,
|
|
1591
|
+
...queryOptions
|
|
1592
|
+
});
|
|
1593
|
+
};
|
|
1594
|
+
var useSwapsApiIntentExtraData = ({
|
|
1595
|
+
params,
|
|
1596
|
+
queryOptions
|
|
1597
|
+
} = {}) => {
|
|
1598
|
+
const { sodax } = useSodaxContext();
|
|
1599
|
+
const body = params?.body;
|
|
1600
|
+
const apiConfig = params?.apiConfig;
|
|
1601
|
+
return useQuery({
|
|
1602
|
+
queryKey: ["swapsApi", "intentExtraData", body?.txHash ?? body?.intent?.intentId?.toString()],
|
|
1603
|
+
queryFn: async () => {
|
|
1604
|
+
if (!body || !body.txHash && !body.intent) return void 0;
|
|
1605
|
+
return unwrapResult(await sodax.api.swaps.getIntentSubmitTxExtraData(body, apiConfig));
|
|
1606
|
+
},
|
|
1607
|
+
enabled: !!body && (!!body.txHash || !!body.intent),
|
|
1608
|
+
retry: 3,
|
|
1609
|
+
...queryOptions
|
|
1610
|
+
});
|
|
1611
|
+
};
|
|
1612
|
+
var useSwapsApiFilledIntent = ({
|
|
1613
|
+
params,
|
|
1614
|
+
queryOptions
|
|
1615
|
+
} = {}) => {
|
|
1616
|
+
const { sodax } = useSodaxContext();
|
|
1617
|
+
const txHash = params?.txHash;
|
|
1618
|
+
const apiConfig = params?.apiConfig;
|
|
1619
|
+
return useQuery({
|
|
1620
|
+
queryKey: ["swapsApi", "filledIntent", txHash],
|
|
1621
|
+
queryFn: async () => {
|
|
1622
|
+
if (!txHash) return void 0;
|
|
1623
|
+
return unwrapResult(await sodax.api.swaps.getFilledIntent(txHash, apiConfig));
|
|
1624
|
+
},
|
|
1625
|
+
enabled: !!txHash && txHash.length > 0,
|
|
1626
|
+
retry: 3,
|
|
1627
|
+
...queryOptions
|
|
1628
|
+
});
|
|
1629
|
+
};
|
|
1630
|
+
var useSwapsApiIntent = ({
|
|
1631
|
+
params,
|
|
1632
|
+
queryOptions
|
|
1633
|
+
} = {}) => {
|
|
1634
|
+
const { sodax } = useSodaxContext();
|
|
1635
|
+
const txHash = params?.txHash;
|
|
1636
|
+
const apiConfig = params?.apiConfig;
|
|
1637
|
+
return useQuery({
|
|
1638
|
+
queryKey: ["swapsApi", "intent", txHash],
|
|
1639
|
+
queryFn: async () => {
|
|
1640
|
+
if (!txHash) return void 0;
|
|
1641
|
+
return unwrapResult(await sodax.api.swaps.getIntent(txHash, apiConfig));
|
|
1642
|
+
},
|
|
1643
|
+
enabled: !!txHash && txHash.length > 0,
|
|
1644
|
+
retry: 3,
|
|
1645
|
+
...queryOptions
|
|
1646
|
+
});
|
|
1647
|
+
};
|
|
1648
|
+
|
|
1649
|
+
// src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts
|
|
1650
|
+
var useSwapsApiCreateLimitOrder = ({
|
|
1651
|
+
mutationOptions
|
|
1652
|
+
} = {}) => {
|
|
1653
|
+
const { sodax } = useSodaxContext();
|
|
1654
|
+
return useSafeMutation({
|
|
1655
|
+
mutationKey: ["swapsApi", "createLimitOrder"],
|
|
1656
|
+
retry: 3,
|
|
1657
|
+
...mutationOptions,
|
|
1658
|
+
mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.createLimitOrderIntent(body, apiConfig))
|
|
1659
|
+
});
|
|
1660
|
+
};
|
|
1661
|
+
var useSwapsApiEstimateGas = ({
|
|
1662
|
+
params,
|
|
1663
|
+
queryOptions
|
|
1664
|
+
} = {}) => {
|
|
1665
|
+
const { sodax } = useSodaxContext();
|
|
1666
|
+
const body = params?.body;
|
|
1667
|
+
const apiConfig = params?.apiConfig;
|
|
1060
1668
|
return useQuery({
|
|
1061
|
-
queryKey: ["
|
|
1669
|
+
queryKey: ["swapsApi", "estimateGas", body?.chainKey, body?.tx],
|
|
1062
1670
|
queryFn: async () => {
|
|
1063
|
-
if (!
|
|
1064
|
-
return unwrapResult(await sodax.
|
|
1671
|
+
if (!body) return void 0;
|
|
1672
|
+
return unwrapResult(await sodax.api.swaps.estimateGas(body, apiConfig));
|
|
1065
1673
|
},
|
|
1066
|
-
enabled: !!
|
|
1674
|
+
enabled: !!body,
|
|
1067
1675
|
retry: 3,
|
|
1068
1676
|
...queryOptions
|
|
1069
1677
|
});
|
|
1070
1678
|
};
|
|
1071
|
-
var
|
|
1679
|
+
var useSwapsApiPartnerFee = ({
|
|
1072
1680
|
params,
|
|
1073
1681
|
queryOptions
|
|
1074
1682
|
} = {}) => {
|
|
1075
1683
|
const { sodax } = useSodaxContext();
|
|
1076
|
-
const
|
|
1077
|
-
const
|
|
1684
|
+
const amount = params?.amount;
|
|
1685
|
+
const apiConfig = params?.apiConfig;
|
|
1078
1686
|
return useQuery({
|
|
1079
|
-
queryKey: ["
|
|
1687
|
+
queryKey: ["swapsApi", "partnerFee", amount],
|
|
1080
1688
|
queryFn: async () => {
|
|
1081
|
-
if (!
|
|
1082
|
-
|
|
1083
|
-
}
|
|
1084
|
-
return unwrapResult(
|
|
1085
|
-
await sodax.backendApi.getMoneyMarketAssetBorrowers(reserveAddress, {
|
|
1086
|
-
offset: pagination.offset,
|
|
1087
|
-
limit: pagination.limit
|
|
1088
|
-
})
|
|
1089
|
-
);
|
|
1689
|
+
if (!amount) return void 0;
|
|
1690
|
+
return unwrapResult(await sodax.api.swaps.getPartnerFee({ amount }, apiConfig));
|
|
1090
1691
|
},
|
|
1091
|
-
enabled: !!
|
|
1692
|
+
enabled: !!amount && amount.length > 0,
|
|
1092
1693
|
retry: 3,
|
|
1093
1694
|
...queryOptions
|
|
1094
1695
|
});
|
|
1095
1696
|
};
|
|
1096
|
-
var
|
|
1697
|
+
var useSwapsApiSolverFee = ({
|
|
1097
1698
|
params,
|
|
1098
1699
|
queryOptions
|
|
1099
1700
|
} = {}) => {
|
|
1100
1701
|
const { sodax } = useSodaxContext();
|
|
1101
|
-
const
|
|
1102
|
-
const
|
|
1702
|
+
const amount = params?.amount;
|
|
1703
|
+
const apiConfig = params?.apiConfig;
|
|
1103
1704
|
return useQuery({
|
|
1104
|
-
queryKey: ["
|
|
1705
|
+
queryKey: ["swapsApi", "solverFee", amount],
|
|
1105
1706
|
queryFn: async () => {
|
|
1106
|
-
if (!
|
|
1107
|
-
|
|
1108
|
-
}
|
|
1109
|
-
return unwrapResult(
|
|
1110
|
-
await sodax.backendApi.getMoneyMarketAssetSuppliers(reserveAddress, {
|
|
1111
|
-
offset: pagination.offset,
|
|
1112
|
-
limit: pagination.limit
|
|
1113
|
-
})
|
|
1114
|
-
);
|
|
1707
|
+
if (!amount) return void 0;
|
|
1708
|
+
return unwrapResult(await sodax.api.swaps.getSolverFee({ amount }, apiConfig));
|
|
1115
1709
|
},
|
|
1116
|
-
enabled: !!
|
|
1710
|
+
enabled: !!amount && amount.length > 0,
|
|
1117
1711
|
retry: 3,
|
|
1118
1712
|
...queryOptions
|
|
1119
1713
|
});
|
|
1120
1714
|
};
|
|
1121
|
-
|
|
1715
|
+
|
|
1716
|
+
// src/hooks/swapsApi/useSwapsApiSubmitTx.ts
|
|
1717
|
+
var useSwapsApiSubmitTx = ({
|
|
1718
|
+
mutationOptions
|
|
1719
|
+
} = {}) => {
|
|
1720
|
+
const { sodax } = useSodaxContext();
|
|
1721
|
+
return useSafeMutation({
|
|
1722
|
+
mutationKey: ["swapsApi", "submitTx"],
|
|
1723
|
+
retry: 3,
|
|
1724
|
+
...mutationOptions,
|
|
1725
|
+
mutationFn: async ({ request, apiConfig }) => unwrapResult(await sodax.api.swaps.submitTx(request, apiConfig))
|
|
1726
|
+
});
|
|
1727
|
+
};
|
|
1728
|
+
var useSwapsApiSubmitTxStatus = ({
|
|
1122
1729
|
params,
|
|
1123
1730
|
queryOptions
|
|
1124
1731
|
} = {}) => {
|
|
1125
1732
|
const { sodax } = useSodaxContext();
|
|
1126
|
-
const
|
|
1733
|
+
const txHash = params?.txHash;
|
|
1734
|
+
const srcChainKey = params?.srcChainKey;
|
|
1735
|
+
const apiConfig = params?.apiConfig;
|
|
1127
1736
|
return useQuery({
|
|
1128
|
-
queryKey: ["
|
|
1737
|
+
queryKey: ["swapsApi", "submitTx", "status", txHash, srcChainKey],
|
|
1129
1738
|
queryFn: async () => {
|
|
1130
|
-
if (!
|
|
1131
|
-
|
|
1132
|
-
}
|
|
1133
|
-
return unwrapResult(
|
|
1134
|
-
await sodax.backendApi.getAllMoneyMarketBorrowers({
|
|
1135
|
-
offset: pagination.offset,
|
|
1136
|
-
limit: pagination.limit
|
|
1137
|
-
})
|
|
1138
|
-
);
|
|
1739
|
+
if (!txHash || !srcChainKey) return void 0;
|
|
1740
|
+
return unwrapResult(await sodax.api.swaps.getSubmitTxStatus({ txHash, srcChainKey }, apiConfig));
|
|
1139
1741
|
},
|
|
1140
|
-
enabled: !!
|
|
1742
|
+
enabled: !!txHash && txHash.length > 0 && !!srcChainKey,
|
|
1141
1743
|
retry: 3,
|
|
1744
|
+
refetchInterval: (query) => {
|
|
1745
|
+
const status = query.state.data?.data?.status;
|
|
1746
|
+
if (status === "solved" || status === "failed") return false;
|
|
1747
|
+
return 1e3;
|
|
1748
|
+
},
|
|
1142
1749
|
...queryOptions
|
|
1143
1750
|
});
|
|
1144
1751
|
};
|
|
@@ -1382,7 +1989,10 @@ function useCancelUnstake({
|
|
|
1382
1989
|
}
|
|
1383
1990
|
});
|
|
1384
1991
|
}
|
|
1385
|
-
function useStakingInfo({
|
|
1992
|
+
function useStakingInfo({
|
|
1993
|
+
params,
|
|
1994
|
+
queryOptions
|
|
1995
|
+
} = {}) {
|
|
1386
1996
|
const { sodax } = useSodaxContext();
|
|
1387
1997
|
const srcAddress = params?.srcAddress;
|
|
1388
1998
|
const srcChainKey = params?.srcChainKey;
|
|
@@ -1423,9 +2033,7 @@ function useUnstakingInfoWithPenalty({
|
|
|
1423
2033
|
...queryOptions
|
|
1424
2034
|
});
|
|
1425
2035
|
}
|
|
1426
|
-
function useStakingConfig({
|
|
1427
|
-
queryOptions
|
|
1428
|
-
} = {}) {
|
|
2036
|
+
function useStakingConfig({ queryOptions } = {}) {
|
|
1429
2037
|
const { sodax } = useSodaxContext();
|
|
1430
2038
|
return useQuery({
|
|
1431
2039
|
queryKey: ["staking", "config"],
|
|
@@ -1764,6 +2372,107 @@ function useFeeClaimSwap({
|
|
|
1764
2372
|
}
|
|
1765
2373
|
});
|
|
1766
2374
|
}
|
|
2375
|
+
function usePartnerCancelIntent({
|
|
2376
|
+
mutationOptions
|
|
2377
|
+
} = {}) {
|
|
2378
|
+
const { sodax } = useSodaxContext();
|
|
2379
|
+
const queryClient = useQueryClient();
|
|
2380
|
+
return useSafeMutation({
|
|
2381
|
+
mutationKey: ["partner", "cancelIntent"],
|
|
2382
|
+
...mutationOptions,
|
|
2383
|
+
mutationFn: async (vars) => unwrapResult(await sodax.partners.feeClaim.cancelIntent({ ...vars, raw: false })),
|
|
2384
|
+
onSuccess: async (data, vars, ctx) => {
|
|
2385
|
+
queryClient.invalidateQueries({
|
|
2386
|
+
queryKey: ["partner", "feeClaim", "assetsBalances", vars.params.srcAddress]
|
|
2387
|
+
});
|
|
2388
|
+
queryClient.invalidateQueries({
|
|
2389
|
+
queryKey: [
|
|
2390
|
+
"partner",
|
|
2391
|
+
"feeClaim",
|
|
2392
|
+
"userIntent",
|
|
2393
|
+
vars.params.srcAddress,
|
|
2394
|
+
vars.params.fromToken,
|
|
2395
|
+
vars.params.toToken
|
|
2396
|
+
]
|
|
2397
|
+
});
|
|
2398
|
+
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
2399
|
+
}
|
|
2400
|
+
});
|
|
2401
|
+
}
|
|
2402
|
+
function useGetUserIntent({ params, queryOptions } = {}) {
|
|
2403
|
+
const { sodax } = useSodaxContext();
|
|
2404
|
+
const user = params?.user;
|
|
2405
|
+
const fromToken = params?.fromToken;
|
|
2406
|
+
const toToken = params?.toToken;
|
|
2407
|
+
return useQuery({
|
|
2408
|
+
queryKey: ["partner", "feeClaim", "userIntent", user, fromToken, toToken],
|
|
2409
|
+
queryFn: async () => {
|
|
2410
|
+
if (!user || !fromToken || !toToken) {
|
|
2411
|
+
throw new Error("user, fromToken and toToken are required");
|
|
2412
|
+
}
|
|
2413
|
+
const result = await sodax.partners.feeClaim.getUserIntent({ user, fromToken, toToken });
|
|
2414
|
+
if (!result.ok) throw result.error;
|
|
2415
|
+
return result.value;
|
|
2416
|
+
},
|
|
2417
|
+
enabled: !!user && !!fromToken && !!toToken,
|
|
2418
|
+
...queryOptions
|
|
2419
|
+
});
|
|
2420
|
+
}
|
|
2421
|
+
var ZERO_HASH = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
2422
|
+
function useGetIntentDetails({
|
|
2423
|
+
params,
|
|
2424
|
+
queryOptions
|
|
2425
|
+
} = {}) {
|
|
2426
|
+
const { sodax } = useSodaxContext();
|
|
2427
|
+
const intentHash = params?.intentHash;
|
|
2428
|
+
const hasIntent = !!intentHash && intentHash !== ZERO_HASH;
|
|
2429
|
+
return useQuery({
|
|
2430
|
+
queryKey: ["partner", "feeClaim", "intentDetails", intentHash],
|
|
2431
|
+
queryFn: async () => {
|
|
2432
|
+
if (!intentHash) {
|
|
2433
|
+
throw new Error("intentHash is required");
|
|
2434
|
+
}
|
|
2435
|
+
const result = await sodax.partners.feeClaim.getIntentDetails(intentHash);
|
|
2436
|
+
if (!result.ok) throw result.error;
|
|
2437
|
+
return result.value;
|
|
2438
|
+
},
|
|
2439
|
+
enabled: hasIntent,
|
|
2440
|
+
...queryOptions
|
|
2441
|
+
});
|
|
2442
|
+
}
|
|
2443
|
+
function useFeeClaimWithdraw({
|
|
2444
|
+
mutationOptions
|
|
2445
|
+
} = {}) {
|
|
2446
|
+
const { sodax } = useSodaxContext();
|
|
2447
|
+
const queryClient = useQueryClient();
|
|
2448
|
+
return useSafeMutation({
|
|
2449
|
+
mutationKey: ["partner", "feeClaimWithdraw"],
|
|
2450
|
+
...mutationOptions,
|
|
2451
|
+
mutationFn: async ({ params, walletProvider }) => {
|
|
2452
|
+
const bridgeParams = {
|
|
2453
|
+
params: {
|
|
2454
|
+
srcChainKey: ChainKeys.SONIC_MAINNET,
|
|
2455
|
+
srcAddress: params.srcAddress,
|
|
2456
|
+
srcToken: params.feeToken,
|
|
2457
|
+
amount: params.amount,
|
|
2458
|
+
dstChainKey: params.dstChainKey,
|
|
2459
|
+
dstToken: params.dstToken,
|
|
2460
|
+
recipient: params.recipient
|
|
2461
|
+
},
|
|
2462
|
+
raw: false,
|
|
2463
|
+
walletProvider
|
|
2464
|
+
};
|
|
2465
|
+
return unwrapResult(await sodax.bridge.bridge(bridgeParams));
|
|
2466
|
+
},
|
|
2467
|
+
onSuccess: async (data, vars, ctx) => {
|
|
2468
|
+
queryClient.invalidateQueries({
|
|
2469
|
+
queryKey: ["partner", "feeClaim", "assetsBalances", vars.params.srcAddress]
|
|
2470
|
+
});
|
|
2471
|
+
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.dstChainKey] });
|
|
2472
|
+
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
2473
|
+
}
|
|
2474
|
+
});
|
|
2475
|
+
}
|
|
1767
2476
|
function useHubAssetBalances({
|
|
1768
2477
|
params,
|
|
1769
2478
|
queryOptions
|
|
@@ -2482,6 +3191,203 @@ function useClaimRewards({
|
|
|
2482
3191
|
}
|
|
2483
3192
|
});
|
|
2484
3193
|
}
|
|
3194
|
+
function useLeverageYieldEffectiveApr({
|
|
3195
|
+
params,
|
|
3196
|
+
queryOptions
|
|
3197
|
+
} = {}) {
|
|
3198
|
+
const { sodax } = useSodaxContext();
|
|
3199
|
+
const vault = params?.vault;
|
|
3200
|
+
return useQuery({
|
|
3201
|
+
queryKey: ["leverageYield", "effectiveApr", vault],
|
|
3202
|
+
queryFn: async () => {
|
|
3203
|
+
if (!vault) throw new Error("vault is required");
|
|
3204
|
+
const result = await sodax.leverageYield.getEffectiveApr(vault);
|
|
3205
|
+
if (!result.ok) throw result.error;
|
|
3206
|
+
return result.value;
|
|
3207
|
+
},
|
|
3208
|
+
enabled: !!vault,
|
|
3209
|
+
refetchInterval: 6e4,
|
|
3210
|
+
...queryOptions
|
|
3211
|
+
});
|
|
3212
|
+
}
|
|
3213
|
+
function useLeverageYieldPosition({
|
|
3214
|
+
params,
|
|
3215
|
+
queryOptions
|
|
3216
|
+
} = {}) {
|
|
3217
|
+
const { sodax } = useSodaxContext();
|
|
3218
|
+
const vault = params?.vault;
|
|
3219
|
+
return useQuery({
|
|
3220
|
+
queryKey: ["leverageYield", "position", vault],
|
|
3221
|
+
queryFn: async () => {
|
|
3222
|
+
if (!vault) throw new Error("vault is required");
|
|
3223
|
+
const result = await sodax.leverageYield.getPosition(vault);
|
|
3224
|
+
if (!result.ok) throw result.error;
|
|
3225
|
+
return result.value;
|
|
3226
|
+
},
|
|
3227
|
+
enabled: !!vault,
|
|
3228
|
+
refetchInterval: 3e4,
|
|
3229
|
+
...queryOptions
|
|
3230
|
+
});
|
|
3231
|
+
}
|
|
3232
|
+
function useLeverageYieldTotalAssets({
|
|
3233
|
+
params,
|
|
3234
|
+
queryOptions
|
|
3235
|
+
} = {}) {
|
|
3236
|
+
const { sodax } = useSodaxContext();
|
|
3237
|
+
const vault = params?.vault;
|
|
3238
|
+
return useQuery({
|
|
3239
|
+
queryKey: ["leverageYield", "totalAssets", vault],
|
|
3240
|
+
queryFn: async () => {
|
|
3241
|
+
if (!vault) throw new Error("vault is required");
|
|
3242
|
+
const result = await sodax.leverageYield.getTotalAssets(vault);
|
|
3243
|
+
if (!result.ok) throw result.error;
|
|
3244
|
+
return result.value;
|
|
3245
|
+
},
|
|
3246
|
+
enabled: !!vault,
|
|
3247
|
+
refetchInterval: 6e4,
|
|
3248
|
+
...queryOptions
|
|
3249
|
+
});
|
|
3250
|
+
}
|
|
3251
|
+
function useLeverageYieldPreviewRedeem({
|
|
3252
|
+
params,
|
|
3253
|
+
queryOptions
|
|
3254
|
+
} = {}) {
|
|
3255
|
+
const { sodax } = useSodaxContext();
|
|
3256
|
+
const vault = params?.vault;
|
|
3257
|
+
const shares = params?.shares;
|
|
3258
|
+
return useQuery({
|
|
3259
|
+
queryKey: ["leverageYield", "previewRedeem", vault, shares?.toString()],
|
|
3260
|
+
queryFn: async () => {
|
|
3261
|
+
if (!vault || shares === void 0) throw new Error("vault and shares are required");
|
|
3262
|
+
const result = await sodax.leverageYield.previewRedeem(vault, shares);
|
|
3263
|
+
if (!result.ok) throw result.error;
|
|
3264
|
+
return result.value;
|
|
3265
|
+
},
|
|
3266
|
+
enabled: !!vault && shares !== void 0,
|
|
3267
|
+
refetchInterval: 6e4,
|
|
3268
|
+
...queryOptions
|
|
3269
|
+
});
|
|
3270
|
+
}
|
|
3271
|
+
function useLeverageYieldShareBalances({
|
|
3272
|
+
params,
|
|
3273
|
+
queryOptions
|
|
3274
|
+
} = {}) {
|
|
3275
|
+
const { sodax } = useSodaxContext();
|
|
3276
|
+
const vault = params?.vault;
|
|
3277
|
+
const holders = params?.holders;
|
|
3278
|
+
return useQueries({
|
|
3279
|
+
queries: (holders ?? []).map(({ chainKey, address }) => ({
|
|
3280
|
+
queryKey: ["leverageYield", "shareBalance", vault, chainKey, address],
|
|
3281
|
+
refetchInterval: 15e3,
|
|
3282
|
+
...queryOptions,
|
|
3283
|
+
enabled: !!vault,
|
|
3284
|
+
queryFn: async () => {
|
|
3285
|
+
if (!vault) throw new Error("vault is required");
|
|
3286
|
+
const holder = await sodax.hubProvider.getUserHubWalletAddress(address, chainKey);
|
|
3287
|
+
const result = await sodax.leverageYield.getShareBalance(vault, holder);
|
|
3288
|
+
if (!result.ok) throw result.error;
|
|
3289
|
+
return { chainKey, holder, shares: result.value };
|
|
3290
|
+
}
|
|
3291
|
+
}))
|
|
3292
|
+
});
|
|
3293
|
+
}
|
|
3294
|
+
|
|
3295
|
+
// src/hooks/leverageYield/useLeverageYieldDeposit.ts
|
|
3296
|
+
function useLeverageYieldDeposit({
|
|
3297
|
+
mutationOptions
|
|
3298
|
+
} = {}) {
|
|
3299
|
+
const { sodax } = useSodaxContext();
|
|
3300
|
+
return useSafeMutation({
|
|
3301
|
+
mutationKey: ["leverageYield", "deposit"],
|
|
3302
|
+
...mutationOptions,
|
|
3303
|
+
mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.deposit(vars))
|
|
3304
|
+
});
|
|
3305
|
+
}
|
|
3306
|
+
|
|
3307
|
+
// src/hooks/leverageYield/useLeverageYieldNotifySolver.ts
|
|
3308
|
+
function useLeverageYieldNotifySolver({
|
|
3309
|
+
mutationOptions
|
|
3310
|
+
} = {}) {
|
|
3311
|
+
const { sodax } = useSodaxContext();
|
|
3312
|
+
return useSafeMutation({
|
|
3313
|
+
mutationKey: ["leverageYield", "notifySolver"],
|
|
3314
|
+
...mutationOptions,
|
|
3315
|
+
mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.notifySolver(vars))
|
|
3316
|
+
});
|
|
3317
|
+
}
|
|
3318
|
+
function useLeverageYieldVaultSwap({
|
|
3319
|
+
mutationOptions
|
|
3320
|
+
} = {}) {
|
|
3321
|
+
const { sodax } = useSodaxContext();
|
|
3322
|
+
const queryClient = useQueryClient();
|
|
3323
|
+
return useSafeMutation({
|
|
3324
|
+
mutationKey: ["leverageYield", "vaultSwap"],
|
|
3325
|
+
...mutationOptions,
|
|
3326
|
+
mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.vaultSwap({ ...vars, raw: false })),
|
|
3327
|
+
onSuccess: async (data, vars, ctx) => {
|
|
3328
|
+
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.srcChainKey] });
|
|
3329
|
+
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.dstChainKey] });
|
|
3330
|
+
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
3331
|
+
}
|
|
3332
|
+
});
|
|
3333
|
+
}
|
|
3334
|
+
|
|
3335
|
+
// src/hooks/leverageYield/useLeverageYieldWithdraw.ts
|
|
3336
|
+
function useLeverageYieldWithdraw({
|
|
3337
|
+
mutationOptions
|
|
3338
|
+
} = {}) {
|
|
3339
|
+
const { sodax } = useSodaxContext();
|
|
3340
|
+
return useSafeMutation({
|
|
3341
|
+
mutationKey: ["leverageYield", "withdraw"],
|
|
3342
|
+
...mutationOptions,
|
|
3343
|
+
mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.withdraw(vars))
|
|
3344
|
+
});
|
|
3345
|
+
}
|
|
3346
|
+
function getSponsorConfigQueryOptions({ sodax }) {
|
|
3347
|
+
return {
|
|
3348
|
+
queryKey: ["sponsoring", "sponsorConfig"],
|
|
3349
|
+
queryFn: async () => {
|
|
3350
|
+
const result = await sodax.sponsoring.getStellarSponsorConfig();
|
|
3351
|
+
if (!result.ok) throw result.error;
|
|
3352
|
+
return result.value;
|
|
3353
|
+
},
|
|
3354
|
+
staleTime: SPONSOR_CONFIG_TTL_MS
|
|
3355
|
+
};
|
|
3356
|
+
}
|
|
3357
|
+
function useSponsorConfig({
|
|
3358
|
+
queryOptions
|
|
3359
|
+
} = {}) {
|
|
3360
|
+
const { sodax } = useSodaxContext();
|
|
3361
|
+
return useQuery({
|
|
3362
|
+
...getSponsorConfigQueryOptions({ sodax }),
|
|
3363
|
+
...queryOptions
|
|
3364
|
+
});
|
|
3365
|
+
}
|
|
3366
|
+
function getStellarAccountActiveQueryOptions({
|
|
3367
|
+
sodax,
|
|
3368
|
+
address
|
|
3369
|
+
}) {
|
|
3370
|
+
return {
|
|
3371
|
+
queryKey: ["sponsoring", "stellarAccountActive", address],
|
|
3372
|
+
queryFn: async () => {
|
|
3373
|
+
if (!address) return false;
|
|
3374
|
+
const result = await sodax.sponsoring.isStellarAccountActive({ address });
|
|
3375
|
+
if (!result.ok) throw result.error;
|
|
3376
|
+
return result.value;
|
|
3377
|
+
},
|
|
3378
|
+
enabled: !!address
|
|
3379
|
+
};
|
|
3380
|
+
}
|
|
3381
|
+
function useStellarAccountActive({
|
|
3382
|
+
params,
|
|
3383
|
+
queryOptions
|
|
3384
|
+
} = {}) {
|
|
3385
|
+
const { sodax } = useSodaxContext();
|
|
3386
|
+
return useQuery({
|
|
3387
|
+
...getStellarAccountActiveQueryOptions({ sodax, address: params?.address }),
|
|
3388
|
+
...queryOptions
|
|
3389
|
+
});
|
|
3390
|
+
}
|
|
2485
3391
|
var SodaxProvider = ({ children, config }) => {
|
|
2486
3392
|
const sodax = useMemo(() => new Sodax(config), [config]);
|
|
2487
3393
|
const contextValue = useMemo(() => ({ sodax }), [sodax]);
|
|
@@ -2513,4 +3419,4 @@ function createSodaxQueryClient({
|
|
|
2513
3419
|
});
|
|
2514
3420
|
}
|
|
2515
3421
|
|
|
2516
|
-
export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, loadRadfiSession, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook,
|
|
3422
|
+
export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getSponsorConfigQueryOptions, getStellarAccountActiveQueryOptions, getStellarAccountStatusQueryOptions, getStellarTrustlineCheckQueryOptions, getXBalancesQueryOptions, isTerminalSwapIntentStatus, isUserRejectedError, loadRadfiSession, resolveNearStorageGate, resolveStellarGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useActivateStellarAccount, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstablishTrustline, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useSponsorConfig, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarAccountActive, useStellarAccountStatus, useStellarGate, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
|