@sodax/dapp-kit 1.3.1-beta-rc1 → 1.3.1-beta-rc3
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/dist/index.d.mts +175 -4
- package/dist/index.d.ts +175 -4
- package/dist/index.js +329 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +317 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/hooks/backend/index.ts +4 -0
- package/src/hooks/backend/useBackendSubmitSwapTx.ts +55 -0
- package/src/hooks/backend/useBackendSubmitSwapTxStatus.ts +79 -0
- package/src/hooks/bitcoin/index.ts +7 -0
- package/src/hooks/bitcoin/radfiConstants.ts +2 -0
- package/src/hooks/bitcoin/useBitcoinBalance.ts +27 -0
- package/src/hooks/bitcoin/useExpiredUtxos.ts +25 -0
- package/src/hooks/bitcoin/useFundTradingWallet.ts +39 -0
- package/src/hooks/bitcoin/useRadfiAuth.ts +123 -0
- package/src/hooks/bitcoin/useRadfiSession.ts +133 -0
- package/src/hooks/bitcoin/useRenewUtxos.ts +72 -0
- package/src/hooks/bitcoin/useTradingWallet.ts +15 -0
- package/src/hooks/bitcoin/useTradingWalletBalance.ts +22 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/provider/useSpokeProvider.ts +20 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Sodax, SpokeProvider, GetEstimateGasReturnType, TxReturnType, SpokeChainId, StellarSpokeProvider, EvmHubProvider, IWalletProvider, MoneyMarketBorrowParams, MoneyMarketError, RelayErrorCode, MoneyMarketRepayParams, MoneyMarketSupplyParams, MoneyMarketWithdrawParams, UserReserveData, AggregatedReserveData, BaseCurrencyInfo, MoneyMarketParams, XToken, ReserveData, FormatReserveUSDResponse, FormatUserSummaryResponse, SolverIntentQuoteRequest, Result, SolverIntentQuoteResponse, SolverErrorResponse, SolverExecutionResponse, Intent, IntentDeliveryInfo, IntentError, IntentErrorCode, CreateIntentParams, Hex, SolverIntentStatusResponse, CreateLimitOrderParams, IntentResponse, Address as Address$1, UserIntentsResponse, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, CreateBridgeIntentParams, SpokeTxHash, HubTxHash, BridgeError, BridgeErrorCode, BridgeLimit, StakeParams, UnstakeParams, ClaimParams, CancelUnstakeParams, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeParams, SodaxConfig } from '@sodax/sdk';
|
|
2
|
-
import { RpcConfig, SpokeChainId as SpokeChainId$1, XToken as XToken$1 } from '@sodax/types';
|
|
3
|
-
import { UseMutationResult, UseQueryResult, UseQueryOptions } from '@tanstack/react-query';
|
|
1
|
+
import { Sodax, SpokeProvider, GetEstimateGasReturnType, TxReturnType, SpokeChainId, StellarSpokeProvider, EvmHubProvider, IWalletProvider, BitcoinSpokeProvider, RadfiWalletBalance, RadfiUtxo, MoneyMarketBorrowParams, MoneyMarketError, RelayErrorCode, MoneyMarketRepayParams, MoneyMarketSupplyParams, MoneyMarketWithdrawParams, UserReserveData, AggregatedReserveData, BaseCurrencyInfo, MoneyMarketParams, XToken, ReserveData, FormatReserveUSDResponse, FormatUserSummaryResponse, SolverIntentQuoteRequest, Result, SolverIntentQuoteResponse, SolverErrorResponse, SolverExecutionResponse, Intent, IntentDeliveryInfo, IntentError, IntentErrorCode, CreateIntentParams, Hex, SolverIntentStatusResponse, CreateLimitOrderParams, IntentResponse, Address as Address$1, UserIntentsResponse, RequestOverrideConfig, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, CreateBridgeIntentParams, SpokeTxHash, HubTxHash, BridgeError, BridgeErrorCode, BridgeLimit, StakeParams, UnstakeParams, ClaimParams, CancelUnstakeParams, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeParams, SodaxConfig } from '@sodax/sdk';
|
|
2
|
+
import { RpcConfig, SpokeChainId as SpokeChainId$1, SubmitSwapTxResponse, SubmitSwapTxRequest, SubmitSwapTxStatusResponse, XToken as XToken$1 } from '@sodax/types';
|
|
3
|
+
import { UseMutationResult, UseQueryResult, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
4
4
|
import { Address } from 'viem';
|
|
5
5
|
import { ReactNode, ReactElement } from 'react';
|
|
6
6
|
|
|
@@ -179,6 +179,109 @@ declare function useHubProvider(): EvmHubProvider;
|
|
|
179
179
|
*/
|
|
180
180
|
declare function useSpokeProvider(spokeChainId: SpokeChainId$1 | undefined, walletProvider?: IWalletProvider | undefined): SpokeProvider | undefined;
|
|
181
181
|
|
|
182
|
+
type RadfiSession = {
|
|
183
|
+
accessToken: string;
|
|
184
|
+
refreshToken: string;
|
|
185
|
+
tradingAddress: string;
|
|
186
|
+
publicKey: string;
|
|
187
|
+
accessTokenExpiry: number;
|
|
188
|
+
refreshTokenExpiry: number;
|
|
189
|
+
};
|
|
190
|
+
type RadfiAuthResult = {
|
|
191
|
+
accessToken: string;
|
|
192
|
+
refreshToken: string;
|
|
193
|
+
tradingAddress: string;
|
|
194
|
+
};
|
|
195
|
+
declare function saveRadfiSession(address: string, session: RadfiSession): void;
|
|
196
|
+
declare function loadRadfiSession(address: string): RadfiSession | null;
|
|
197
|
+
declare function clearRadfiSession(address: string): void;
|
|
198
|
+
declare function isAccessTokenExpired(address: string): boolean;
|
|
199
|
+
declare function isRefreshTokenExpired(address: string): boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Hook to authenticate with Radfi using BIP322 message signing.
|
|
202
|
+
* Saves full session (accessToken, refreshToken, tradingAddress, expiry) to localStorage.
|
|
203
|
+
*/
|
|
204
|
+
declare function useRadfiAuth(spokeProvider: BitcoinSpokeProvider | undefined): UseMutationResult<RadfiAuthResult, Error, void>;
|
|
205
|
+
|
|
206
|
+
type UseRadfiSessionReturn = {
|
|
207
|
+
walletAddress: string | undefined;
|
|
208
|
+
isAuthed: boolean;
|
|
209
|
+
tradingAddress: string | undefined;
|
|
210
|
+
login: () => Promise<void>;
|
|
211
|
+
isLoginPending: boolean;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Manages the full Radfi session lifecycle:
|
|
215
|
+
* - Restores session from localStorage on mount
|
|
216
|
+
* - Polls every 2s: silently refreshes accessToken before expiry, resets auth when refreshToken expires
|
|
217
|
+
* - Exposes login() and isAuthed for UI
|
|
218
|
+
*/
|
|
219
|
+
declare function useRadfiSession(spokeProvider: BitcoinSpokeProvider | undefined): UseRadfiSessionReturn;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Hook to fund the Radfi trading wallet by sending BTC from the user's personal wallet.
|
|
223
|
+
*
|
|
224
|
+
* @param {BitcoinSpokeProvider | undefined} spokeProvider - The Bitcoin spoke provider with signing capability
|
|
225
|
+
* @returns {UseMutationResult} Mutation result — input is amount in satoshis, output is transaction ID
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```tsx
|
|
229
|
+
* const { mutateAsync: fundWallet, isPending } = useFundTradingWallet(spokeProvider);
|
|
230
|
+
*
|
|
231
|
+
* const handleFund = async () => {
|
|
232
|
+
* const txId = await fundWallet(100_000n); // fund 100,000 satoshis
|
|
233
|
+
* console.log('Funded:', txId);
|
|
234
|
+
* };
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
declare function useFundTradingWallet(spokeProvider: BitcoinSpokeProvider | undefined): UseMutationResult<string, Error, bigint>;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Hook to fetch BTC balance for any Bitcoin address.
|
|
241
|
+
* Sums all UTXOs (confirmed + unconfirmed) from mempool.space API.
|
|
242
|
+
*
|
|
243
|
+
* The UTXO set already excludes spent outputs (even from unconfirmed txs),
|
|
244
|
+
* so the total is always the correct spendable balance.
|
|
245
|
+
*/
|
|
246
|
+
declare function useBitcoinBalance(address: string | undefined, rpcUrl?: string): UseQueryResult<bigint, Error>;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Hook to fetch trading wallet balance from Radfi API.
|
|
250
|
+
* Returns confirmed + pending satoshi balances.
|
|
251
|
+
*/
|
|
252
|
+
declare function useTradingWalletBalance(spokeProvider: BitcoinSpokeProvider | undefined, tradingAddress: string | undefined): UseQueryResult<RadfiWalletBalance, Error>;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Hook to fetch expired UTXOs for a trading wallet address.
|
|
256
|
+
* UTXOs that are expired or within 2 weeks of expiry are considered invalid for trading
|
|
257
|
+
* and need to be renewed via the Radfi renew-utxo flow.
|
|
258
|
+
*/
|
|
259
|
+
declare function useExpiredUtxos(spokeProvider: BitcoinSpokeProvider | undefined, tradingAddress: string | undefined): UseQueryResult<RadfiUtxo[], Error>;
|
|
260
|
+
|
|
261
|
+
type RenewUtxosParams = {
|
|
262
|
+
txIdVouts: string[];
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* Hook to renew expired UTXOs in the Radfi trading wallet.
|
|
266
|
+
*
|
|
267
|
+
* Flow:
|
|
268
|
+
* 1. Build renew-utxo transaction via Radfi API (returns unsigned PSBT)
|
|
269
|
+
* 2. User signs the PSBT with their wallet
|
|
270
|
+
* 3. Submit signed PSBT back to Radfi for co-signing and broadcasting
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```tsx
|
|
274
|
+
* const { mutateAsync: renewUtxos, isPending } = useRenewUtxos(spokeProvider);
|
|
275
|
+
*
|
|
276
|
+
* const handleRenew = async (expiredUtxos: RadfiUtxo[]) => {
|
|
277
|
+
* const txIdVouts = expiredUtxos.map(u => `${u.txId}:${u.vout}`);
|
|
278
|
+
* const txId = await renewUtxos({ txIdVouts });
|
|
279
|
+
* console.log('Renewed:', txId);
|
|
280
|
+
* };
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
declare function useRenewUtxos(spokeProvider: BitcoinSpokeProvider | undefined): UseMutationResult<string, Error, RenewUtxosParams>;
|
|
284
|
+
|
|
182
285
|
interface BorrowResponse {
|
|
183
286
|
ok: true;
|
|
184
287
|
value: [string, string];
|
|
@@ -932,6 +1035,74 @@ type UseBackendUserIntentsParams = {
|
|
|
932
1035
|
*/
|
|
933
1036
|
declare const useBackendUserIntents: ({ params, queryOptions, }: UseBackendUserIntentsParams) => UseQueryResult<UserIntentsResponse | undefined, Error>;
|
|
934
1037
|
|
|
1038
|
+
type UseBackendSubmitSwapTxParams = {
|
|
1039
|
+
apiConfig?: RequestOverrideConfig;
|
|
1040
|
+
mutationOptions?: UseMutationOptions<SubmitSwapTxResponse, Error, SubmitSwapTxRequest>;
|
|
1041
|
+
};
|
|
1042
|
+
/**
|
|
1043
|
+
* React hook for submitting a swap transaction to be processed by the backend
|
|
1044
|
+
* (relay, post execution to solver, etc.).
|
|
1045
|
+
*
|
|
1046
|
+
* @param {UseBackendSubmitSwapTxParams | undefined} params - Optional parameters:
|
|
1047
|
+
* - `mutationOptions`: React Query mutation options to customize behavior (e.g., onSuccess, onError, retry).
|
|
1048
|
+
*
|
|
1049
|
+
* @returns {UseMutationResult<SubmitSwapTxResponse, Error, SubmitSwapTxRequest>} React Query mutation result:
|
|
1050
|
+
* - `mutate` / `mutateAsync`: Functions to trigger the submission.
|
|
1051
|
+
* - `data`: The submit response on success.
|
|
1052
|
+
* - `isPending`: Loading state.
|
|
1053
|
+
* - `error`: Error instance if the mutation failed.
|
|
1054
|
+
*
|
|
1055
|
+
* @example
|
|
1056
|
+
* const { mutateAsync: submitSwapTx, isPending, error } = useBackendSubmitSwapTx();
|
|
1057
|
+
*
|
|
1058
|
+
* const result = await submitSwapTx({
|
|
1059
|
+
* txHash: '0x123...',
|
|
1060
|
+
* srcChainId: '1',
|
|
1061
|
+
* walletAddress: '0xabc...',
|
|
1062
|
+
* intent: { ... },
|
|
1063
|
+
* relayData: '0x...',
|
|
1064
|
+
* });
|
|
1065
|
+
*/
|
|
1066
|
+
declare const useBackendSubmitSwapTx: (params?: UseBackendSubmitSwapTxParams) => UseMutationResult<SubmitSwapTxResponse, Error, SubmitSwapTxRequest>;
|
|
1067
|
+
|
|
1068
|
+
type UseBackendSubmitSwapTxStatusParams = {
|
|
1069
|
+
params: {
|
|
1070
|
+
txHash: string | undefined;
|
|
1071
|
+
srcChainId?: string;
|
|
1072
|
+
};
|
|
1073
|
+
apiConfig?: RequestOverrideConfig;
|
|
1074
|
+
queryOptions?: UseQueryOptions<SubmitSwapTxStatusResponse | undefined, Error>;
|
|
1075
|
+
};
|
|
1076
|
+
/**
|
|
1077
|
+
* React hook for polling the processing status of a submitted swap transaction.
|
|
1078
|
+
*
|
|
1079
|
+
* @param {UseBackendSubmitSwapTxStatusParams | undefined} params - Parameters for the query:
|
|
1080
|
+
* - `params.txHash`: The transaction hash of the submitted swap; query is disabled if undefined or empty.
|
|
1081
|
+
* - `params.srcChainId`: Optional source chain ID to narrow the status lookup.
|
|
1082
|
+
* - `queryOptions`: Optional React Query options to override default behavior (e.g., refetchInterval, retry).
|
|
1083
|
+
*
|
|
1084
|
+
* @returns {UseQueryResult<SubmitSwapTxStatusResponse | undefined, Error>} React Query result object:
|
|
1085
|
+
* - `data`: The status response or undefined if unavailable.
|
|
1086
|
+
* - `isLoading`: Loading state.
|
|
1087
|
+
* - `error`: Error instance if the query failed.
|
|
1088
|
+
* - `refetch`: Function to re-trigger the query.
|
|
1089
|
+
*
|
|
1090
|
+
* @example
|
|
1091
|
+
* const { data: status, isLoading, error } = useBackendSubmitSwapTxStatus({
|
|
1092
|
+
* params: { txHash: '0x123...', srcChainId: '1' },
|
|
1093
|
+
* });
|
|
1094
|
+
*
|
|
1095
|
+
* if (status?.data.status === 'executed') {
|
|
1096
|
+
* console.log('Swap completed!', status.data.result);
|
|
1097
|
+
* }
|
|
1098
|
+
*
|
|
1099
|
+
* @remarks
|
|
1100
|
+
* - Query is disabled if `params` is undefined or `txHash` is undefined/empty.
|
|
1101
|
+
* - Default refetch interval is 1 second for real-time status polling.
|
|
1102
|
+
* - Uses React Query for state management, caching, and retries.
|
|
1103
|
+
*/
|
|
1104
|
+
declare const useBackendSubmitSwapTxStatus: (params: UseBackendSubmitSwapTxStatusParams | undefined) => UseQueryResult<SubmitSwapTxStatusResponse | undefined, Error>;
|
|
1105
|
+
|
|
935
1106
|
type UseBackendOrderbookParams = {
|
|
936
1107
|
queryOptions?: UseQueryOptions<OrderbookResponse | undefined, Error>;
|
|
937
1108
|
pagination?: BackendPaginationParams;
|
|
@@ -1837,4 +2008,4 @@ interface SodaxProviderProps {
|
|
|
1837
2008
|
}
|
|
1838
2009
|
declare const SodaxProvider: ({ children, testnet, config, rpcConfig }: SodaxProviderProps) => ReactElement;
|
|
1839
2010
|
|
|
1840
|
-
export { type BackendPaginationParams, MIGRATION_MODE_BNUSD, MIGRATION_MODE_ICX_SODA, type MigrationIntentParams, type MigrationMode, SodaxProvider, type UseATokenParams, type UseATokensBalancesParams, type UseBorrowParams, type UseMMAllowanceParams, type UseMMApproveParams, type UseRepayParams, type UseReservesDataParams, type UseReservesUsdFormatParams, type UseSupplyParams, type UseUserFormattedSummaryParams, type UseUserReservesDataParams, type UseWithdrawParams, useAToken, useATokensBalances, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useConvertedAssets, useCreateLimitOrder, useDeriveUserWalletAddress, useEstimateGas, useGetBridgeableAmount, useGetBridgeableTokens, useGetUserHubWalletAddress, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useMMAllowance, useMMApprove, useMigrate, useMigrationAllowance, useMigrationApprove, useQuote, useRepay, useRequestTrustline, useReservesData, useReservesUsdFormat, useSodaxContext, useSpokeProvider, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSwap, useSwapAllowance, useSwapApprove, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw };
|
|
2011
|
+
export { type BackendPaginationParams, MIGRATION_MODE_BNUSD, MIGRATION_MODE_ICX_SODA, type MigrationIntentParams, type MigrationMode, type RadfiSession, SodaxProvider, type UseATokenParams, type UseATokensBalancesParams, type UseBorrowParams, type UseMMAllowanceParams, type UseMMApproveParams, type UseRadfiSessionReturn, type UseRepayParams, type UseReservesDataParams, type UseReservesUsdFormatParams, type UseSupplyParams, type UseUserFormattedSummaryParams, type UseUserReservesDataParams, type UseWithdrawParams, clearRadfiSession, isAccessTokenExpired, isRefreshTokenExpired, loadRadfiSession, saveRadfiSession, useAToken, useATokensBalances, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendSubmitSwapTx, useBackendSubmitSwapTxStatus, useBackendUserIntents, useBitcoinBalance, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useConvertedAssets, useCreateLimitOrder, useDeriveUserWalletAddress, useEstimateGas, useExpiredUtxos, useFundTradingWallet, useGetBridgeableAmount, useGetBridgeableTokens, useGetUserHubWalletAddress, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useMMAllowance, useMMApprove, useMigrate, useMigrationAllowance, useMigrationApprove, useQuote, useRadfiAuth, useRadfiSession, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesUsdFormat, useSodaxContext, useSpokeProvider, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSwap, useSwapAllowance, useSwapApprove, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Sodax, SpokeProvider, GetEstimateGasReturnType, TxReturnType, SpokeChainId, StellarSpokeProvider, EvmHubProvider, IWalletProvider, MoneyMarketBorrowParams, MoneyMarketError, RelayErrorCode, MoneyMarketRepayParams, MoneyMarketSupplyParams, MoneyMarketWithdrawParams, UserReserveData, AggregatedReserveData, BaseCurrencyInfo, MoneyMarketParams, XToken, ReserveData, FormatReserveUSDResponse, FormatUserSummaryResponse, SolverIntentQuoteRequest, Result, SolverIntentQuoteResponse, SolverErrorResponse, SolverExecutionResponse, Intent, IntentDeliveryInfo, IntentError, IntentErrorCode, CreateIntentParams, Hex, SolverIntentStatusResponse, CreateLimitOrderParams, IntentResponse, Address as Address$1, UserIntentsResponse, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, CreateBridgeIntentParams, SpokeTxHash, HubTxHash, BridgeError, BridgeErrorCode, BridgeLimit, StakeParams, UnstakeParams, ClaimParams, CancelUnstakeParams, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeParams, SodaxConfig } from '@sodax/sdk';
|
|
2
|
-
import { RpcConfig, SpokeChainId as SpokeChainId$1, XToken as XToken$1 } from '@sodax/types';
|
|
3
|
-
import { UseMutationResult, UseQueryResult, UseQueryOptions } from '@tanstack/react-query';
|
|
1
|
+
import { Sodax, SpokeProvider, GetEstimateGasReturnType, TxReturnType, SpokeChainId, StellarSpokeProvider, EvmHubProvider, IWalletProvider, BitcoinSpokeProvider, RadfiWalletBalance, RadfiUtxo, MoneyMarketBorrowParams, MoneyMarketError, RelayErrorCode, MoneyMarketRepayParams, MoneyMarketSupplyParams, MoneyMarketWithdrawParams, UserReserveData, AggregatedReserveData, BaseCurrencyInfo, MoneyMarketParams, XToken, ReserveData, FormatReserveUSDResponse, FormatUserSummaryResponse, SolverIntentQuoteRequest, Result, SolverIntentQuoteResponse, SolverErrorResponse, SolverExecutionResponse, Intent, IntentDeliveryInfo, IntentError, IntentErrorCode, CreateIntentParams, Hex, SolverIntentStatusResponse, CreateLimitOrderParams, IntentResponse, Address as Address$1, UserIntentsResponse, RequestOverrideConfig, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, CreateBridgeIntentParams, SpokeTxHash, HubTxHash, BridgeError, BridgeErrorCode, BridgeLimit, StakeParams, UnstakeParams, ClaimParams, CancelUnstakeParams, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeParams, SodaxConfig } from '@sodax/sdk';
|
|
2
|
+
import { RpcConfig, SpokeChainId as SpokeChainId$1, SubmitSwapTxResponse, SubmitSwapTxRequest, SubmitSwapTxStatusResponse, XToken as XToken$1 } from '@sodax/types';
|
|
3
|
+
import { UseMutationResult, UseQueryResult, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
4
4
|
import { Address } from 'viem';
|
|
5
5
|
import { ReactNode, ReactElement } from 'react';
|
|
6
6
|
|
|
@@ -179,6 +179,109 @@ declare function useHubProvider(): EvmHubProvider;
|
|
|
179
179
|
*/
|
|
180
180
|
declare function useSpokeProvider(spokeChainId: SpokeChainId$1 | undefined, walletProvider?: IWalletProvider | undefined): SpokeProvider | undefined;
|
|
181
181
|
|
|
182
|
+
type RadfiSession = {
|
|
183
|
+
accessToken: string;
|
|
184
|
+
refreshToken: string;
|
|
185
|
+
tradingAddress: string;
|
|
186
|
+
publicKey: string;
|
|
187
|
+
accessTokenExpiry: number;
|
|
188
|
+
refreshTokenExpiry: number;
|
|
189
|
+
};
|
|
190
|
+
type RadfiAuthResult = {
|
|
191
|
+
accessToken: string;
|
|
192
|
+
refreshToken: string;
|
|
193
|
+
tradingAddress: string;
|
|
194
|
+
};
|
|
195
|
+
declare function saveRadfiSession(address: string, session: RadfiSession): void;
|
|
196
|
+
declare function loadRadfiSession(address: string): RadfiSession | null;
|
|
197
|
+
declare function clearRadfiSession(address: string): void;
|
|
198
|
+
declare function isAccessTokenExpired(address: string): boolean;
|
|
199
|
+
declare function isRefreshTokenExpired(address: string): boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Hook to authenticate with Radfi using BIP322 message signing.
|
|
202
|
+
* Saves full session (accessToken, refreshToken, tradingAddress, expiry) to localStorage.
|
|
203
|
+
*/
|
|
204
|
+
declare function useRadfiAuth(spokeProvider: BitcoinSpokeProvider | undefined): UseMutationResult<RadfiAuthResult, Error, void>;
|
|
205
|
+
|
|
206
|
+
type UseRadfiSessionReturn = {
|
|
207
|
+
walletAddress: string | undefined;
|
|
208
|
+
isAuthed: boolean;
|
|
209
|
+
tradingAddress: string | undefined;
|
|
210
|
+
login: () => Promise<void>;
|
|
211
|
+
isLoginPending: boolean;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Manages the full Radfi session lifecycle:
|
|
215
|
+
* - Restores session from localStorage on mount
|
|
216
|
+
* - Polls every 2s: silently refreshes accessToken before expiry, resets auth when refreshToken expires
|
|
217
|
+
* - Exposes login() and isAuthed for UI
|
|
218
|
+
*/
|
|
219
|
+
declare function useRadfiSession(spokeProvider: BitcoinSpokeProvider | undefined): UseRadfiSessionReturn;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Hook to fund the Radfi trading wallet by sending BTC from the user's personal wallet.
|
|
223
|
+
*
|
|
224
|
+
* @param {BitcoinSpokeProvider | undefined} spokeProvider - The Bitcoin spoke provider with signing capability
|
|
225
|
+
* @returns {UseMutationResult} Mutation result — input is amount in satoshis, output is transaction ID
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```tsx
|
|
229
|
+
* const { mutateAsync: fundWallet, isPending } = useFundTradingWallet(spokeProvider);
|
|
230
|
+
*
|
|
231
|
+
* const handleFund = async () => {
|
|
232
|
+
* const txId = await fundWallet(100_000n); // fund 100,000 satoshis
|
|
233
|
+
* console.log('Funded:', txId);
|
|
234
|
+
* };
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
declare function useFundTradingWallet(spokeProvider: BitcoinSpokeProvider | undefined): UseMutationResult<string, Error, bigint>;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Hook to fetch BTC balance for any Bitcoin address.
|
|
241
|
+
* Sums all UTXOs (confirmed + unconfirmed) from mempool.space API.
|
|
242
|
+
*
|
|
243
|
+
* The UTXO set already excludes spent outputs (even from unconfirmed txs),
|
|
244
|
+
* so the total is always the correct spendable balance.
|
|
245
|
+
*/
|
|
246
|
+
declare function useBitcoinBalance(address: string | undefined, rpcUrl?: string): UseQueryResult<bigint, Error>;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Hook to fetch trading wallet balance from Radfi API.
|
|
250
|
+
* Returns confirmed + pending satoshi balances.
|
|
251
|
+
*/
|
|
252
|
+
declare function useTradingWalletBalance(spokeProvider: BitcoinSpokeProvider | undefined, tradingAddress: string | undefined): UseQueryResult<RadfiWalletBalance, Error>;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Hook to fetch expired UTXOs for a trading wallet address.
|
|
256
|
+
* UTXOs that are expired or within 2 weeks of expiry are considered invalid for trading
|
|
257
|
+
* and need to be renewed via the Radfi renew-utxo flow.
|
|
258
|
+
*/
|
|
259
|
+
declare function useExpiredUtxos(spokeProvider: BitcoinSpokeProvider | undefined, tradingAddress: string | undefined): UseQueryResult<RadfiUtxo[], Error>;
|
|
260
|
+
|
|
261
|
+
type RenewUtxosParams = {
|
|
262
|
+
txIdVouts: string[];
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* Hook to renew expired UTXOs in the Radfi trading wallet.
|
|
266
|
+
*
|
|
267
|
+
* Flow:
|
|
268
|
+
* 1. Build renew-utxo transaction via Radfi API (returns unsigned PSBT)
|
|
269
|
+
* 2. User signs the PSBT with their wallet
|
|
270
|
+
* 3. Submit signed PSBT back to Radfi for co-signing and broadcasting
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```tsx
|
|
274
|
+
* const { mutateAsync: renewUtxos, isPending } = useRenewUtxos(spokeProvider);
|
|
275
|
+
*
|
|
276
|
+
* const handleRenew = async (expiredUtxos: RadfiUtxo[]) => {
|
|
277
|
+
* const txIdVouts = expiredUtxos.map(u => `${u.txId}:${u.vout}`);
|
|
278
|
+
* const txId = await renewUtxos({ txIdVouts });
|
|
279
|
+
* console.log('Renewed:', txId);
|
|
280
|
+
* };
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
declare function useRenewUtxos(spokeProvider: BitcoinSpokeProvider | undefined): UseMutationResult<string, Error, RenewUtxosParams>;
|
|
284
|
+
|
|
182
285
|
interface BorrowResponse {
|
|
183
286
|
ok: true;
|
|
184
287
|
value: [string, string];
|
|
@@ -932,6 +1035,74 @@ type UseBackendUserIntentsParams = {
|
|
|
932
1035
|
*/
|
|
933
1036
|
declare const useBackendUserIntents: ({ params, queryOptions, }: UseBackendUserIntentsParams) => UseQueryResult<UserIntentsResponse | undefined, Error>;
|
|
934
1037
|
|
|
1038
|
+
type UseBackendSubmitSwapTxParams = {
|
|
1039
|
+
apiConfig?: RequestOverrideConfig;
|
|
1040
|
+
mutationOptions?: UseMutationOptions<SubmitSwapTxResponse, Error, SubmitSwapTxRequest>;
|
|
1041
|
+
};
|
|
1042
|
+
/**
|
|
1043
|
+
* React hook for submitting a swap transaction to be processed by the backend
|
|
1044
|
+
* (relay, post execution to solver, etc.).
|
|
1045
|
+
*
|
|
1046
|
+
* @param {UseBackendSubmitSwapTxParams | undefined} params - Optional parameters:
|
|
1047
|
+
* - `mutationOptions`: React Query mutation options to customize behavior (e.g., onSuccess, onError, retry).
|
|
1048
|
+
*
|
|
1049
|
+
* @returns {UseMutationResult<SubmitSwapTxResponse, Error, SubmitSwapTxRequest>} React Query mutation result:
|
|
1050
|
+
* - `mutate` / `mutateAsync`: Functions to trigger the submission.
|
|
1051
|
+
* - `data`: The submit response on success.
|
|
1052
|
+
* - `isPending`: Loading state.
|
|
1053
|
+
* - `error`: Error instance if the mutation failed.
|
|
1054
|
+
*
|
|
1055
|
+
* @example
|
|
1056
|
+
* const { mutateAsync: submitSwapTx, isPending, error } = useBackendSubmitSwapTx();
|
|
1057
|
+
*
|
|
1058
|
+
* const result = await submitSwapTx({
|
|
1059
|
+
* txHash: '0x123...',
|
|
1060
|
+
* srcChainId: '1',
|
|
1061
|
+
* walletAddress: '0xabc...',
|
|
1062
|
+
* intent: { ... },
|
|
1063
|
+
* relayData: '0x...',
|
|
1064
|
+
* });
|
|
1065
|
+
*/
|
|
1066
|
+
declare const useBackendSubmitSwapTx: (params?: UseBackendSubmitSwapTxParams) => UseMutationResult<SubmitSwapTxResponse, Error, SubmitSwapTxRequest>;
|
|
1067
|
+
|
|
1068
|
+
type UseBackendSubmitSwapTxStatusParams = {
|
|
1069
|
+
params: {
|
|
1070
|
+
txHash: string | undefined;
|
|
1071
|
+
srcChainId?: string;
|
|
1072
|
+
};
|
|
1073
|
+
apiConfig?: RequestOverrideConfig;
|
|
1074
|
+
queryOptions?: UseQueryOptions<SubmitSwapTxStatusResponse | undefined, Error>;
|
|
1075
|
+
};
|
|
1076
|
+
/**
|
|
1077
|
+
* React hook for polling the processing status of a submitted swap transaction.
|
|
1078
|
+
*
|
|
1079
|
+
* @param {UseBackendSubmitSwapTxStatusParams | undefined} params - Parameters for the query:
|
|
1080
|
+
* - `params.txHash`: The transaction hash of the submitted swap; query is disabled if undefined or empty.
|
|
1081
|
+
* - `params.srcChainId`: Optional source chain ID to narrow the status lookup.
|
|
1082
|
+
* - `queryOptions`: Optional React Query options to override default behavior (e.g., refetchInterval, retry).
|
|
1083
|
+
*
|
|
1084
|
+
* @returns {UseQueryResult<SubmitSwapTxStatusResponse | undefined, Error>} React Query result object:
|
|
1085
|
+
* - `data`: The status response or undefined if unavailable.
|
|
1086
|
+
* - `isLoading`: Loading state.
|
|
1087
|
+
* - `error`: Error instance if the query failed.
|
|
1088
|
+
* - `refetch`: Function to re-trigger the query.
|
|
1089
|
+
*
|
|
1090
|
+
* @example
|
|
1091
|
+
* const { data: status, isLoading, error } = useBackendSubmitSwapTxStatus({
|
|
1092
|
+
* params: { txHash: '0x123...', srcChainId: '1' },
|
|
1093
|
+
* });
|
|
1094
|
+
*
|
|
1095
|
+
* if (status?.data.status === 'executed') {
|
|
1096
|
+
* console.log('Swap completed!', status.data.result);
|
|
1097
|
+
* }
|
|
1098
|
+
*
|
|
1099
|
+
* @remarks
|
|
1100
|
+
* - Query is disabled if `params` is undefined or `txHash` is undefined/empty.
|
|
1101
|
+
* - Default refetch interval is 1 second for real-time status polling.
|
|
1102
|
+
* - Uses React Query for state management, caching, and retries.
|
|
1103
|
+
*/
|
|
1104
|
+
declare const useBackendSubmitSwapTxStatus: (params: UseBackendSubmitSwapTxStatusParams | undefined) => UseQueryResult<SubmitSwapTxStatusResponse | undefined, Error>;
|
|
1105
|
+
|
|
935
1106
|
type UseBackendOrderbookParams = {
|
|
936
1107
|
queryOptions?: UseQueryOptions<OrderbookResponse | undefined, Error>;
|
|
937
1108
|
pagination?: BackendPaginationParams;
|
|
@@ -1837,4 +2008,4 @@ interface SodaxProviderProps {
|
|
|
1837
2008
|
}
|
|
1838
2009
|
declare const SodaxProvider: ({ children, testnet, config, rpcConfig }: SodaxProviderProps) => ReactElement;
|
|
1839
2010
|
|
|
1840
|
-
export { type BackendPaginationParams, MIGRATION_MODE_BNUSD, MIGRATION_MODE_ICX_SODA, type MigrationIntentParams, type MigrationMode, SodaxProvider, type UseATokenParams, type UseATokensBalancesParams, type UseBorrowParams, type UseMMAllowanceParams, type UseMMApproveParams, type UseRepayParams, type UseReservesDataParams, type UseReservesUsdFormatParams, type UseSupplyParams, type UseUserFormattedSummaryParams, type UseUserReservesDataParams, type UseWithdrawParams, useAToken, useATokensBalances, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useConvertedAssets, useCreateLimitOrder, useDeriveUserWalletAddress, useEstimateGas, useGetBridgeableAmount, useGetBridgeableTokens, useGetUserHubWalletAddress, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useMMAllowance, useMMApprove, useMigrate, useMigrationAllowance, useMigrationApprove, useQuote, useRepay, useRequestTrustline, useReservesData, useReservesUsdFormat, useSodaxContext, useSpokeProvider, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSwap, useSwapAllowance, useSwapApprove, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw };
|
|
2011
|
+
export { type BackendPaginationParams, MIGRATION_MODE_BNUSD, MIGRATION_MODE_ICX_SODA, type MigrationIntentParams, type MigrationMode, type RadfiSession, SodaxProvider, type UseATokenParams, type UseATokensBalancesParams, type UseBorrowParams, type UseMMAllowanceParams, type UseMMApproveParams, type UseRadfiSessionReturn, type UseRepayParams, type UseReservesDataParams, type UseReservesUsdFormatParams, type UseSupplyParams, type UseUserFormattedSummaryParams, type UseUserReservesDataParams, type UseWithdrawParams, clearRadfiSession, isAccessTokenExpired, isRefreshTokenExpired, loadRadfiSession, saveRadfiSession, useAToken, useATokensBalances, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendSubmitSwapTx, useBackendSubmitSwapTxStatus, useBackendUserIntents, useBitcoinBalance, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useConvertedAssets, useCreateLimitOrder, useDeriveUserWalletAddress, useEstimateGas, useExpiredUtxos, useFundTradingWallet, useGetBridgeableAmount, useGetBridgeableTokens, useGetUserHubWalletAddress, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useMMAllowance, useMMApprove, useMigrate, useMigrationAllowance, useMigrationApprove, useQuote, useRadfiAuth, useRadfiSession, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesUsdFormat, useSodaxContext, useSpokeProvider, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSwap, useSwapAllowance, useSwapApprove, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw };
|