@sodax/dapp-kit 2.0.0-rc.13 → 2.0.0-rc.15

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 CHANGED
@@ -35,11 +35,11 @@ RPC URLs are injected through `config.chains`. `SodaxProvider` is the outermost
35
35
  import { QueryClientProvider } from '@tanstack/react-query';
36
36
  import { SodaxProvider, createSodaxQueryClient } from '@sodax/dapp-kit';
37
37
  import { SodaxWalletProvider, type SodaxWalletConfig } from '@sodax/wallet-sdk-react';
38
- import { ChainKeys, type DeepPartial, type SodaxConfig } from '@sodax/sdk';
38
+ import { ChainKeys, type SodaxOptions } from '@sodax/sdk';
39
39
 
40
40
  const queryClient = createSodaxQueryClient();
41
41
 
42
- const sodaxConfig: DeepPartial<SodaxConfig> = {
42
+ const sodaxConfig: SodaxOptions = {
43
43
  chains: {
44
44
  [ChainKeys.SONIC_MAINNET]: { rpcUrl: 'https://sonic-rpc.publicnode.com' },
45
45
  [ChainKeys.BSC_MAINNET]: { rpcUrl: 'https://bsc-dataseed.binance.org' },
@@ -125,7 +125,7 @@ function SwapButton({ intentParams }: { intentParams: CreateIntentParams }) {
125
125
 
126
126
  ### Provider
127
127
 
128
- - [`SodaxProvider`](src/providers/SodaxProvider.tsx) — Wraps your app, creates the `Sodax` SDK instance. Accepts `config?: DeepPartial<SodaxConfig>`.
128
+ - [`SodaxProvider`](src/providers/SodaxProvider.tsx) — Wraps your app, creates the `Sodax` SDK instance. Accepts `config?: SodaxOptions`.
129
129
  - [`createSodaxQueryClient()`](src/providers/createSodaxQueryClient.ts) — Factory for a `QueryClient` with global mutation observability (`onMutationError` hook, `meta.silent` opt-out).
130
130
 
131
131
  ### Swap Hooks
package/dist/index.d.ts CHANGED
@@ -300,6 +300,26 @@ declare function clearRadfiSession(address: string): void;
300
300
  */
301
301
  declare function useRadfiAuth({ mutationOptions, }?: MutationHookParams<RadfiAuthResult, UseRadfiAuthVars>): SafeUseMutationResult<RadfiAuthResult, Error, UseRadfiAuthVars>;
302
302
 
303
+ type UseEnsureRadfiAccessTokenVars = {
304
+ walletProvider: IBitcoinWalletProvider;
305
+ };
306
+ /**
307
+ * Ensure a valid Bound Exchange access token and return it. Refreshes the existing token (no
308
+ * signature prompt) when a refresh token is available, falling back to a full BIP322 re-auth only if
309
+ * refresh fails. Bound tokens are short-lived, so call this right before a Bitcoin-source
310
+ * createIntent — forward the returned token via the typed `extras.bound.accessToken` slot (SDK in-process)
311
+ * or the `accessToken` body field on the backend DTO — or before the client-side sign + co-sign step.
312
+ *
313
+ * @example
314
+ * const { mutateAsync: ensureToken } = useEnsureRadfiAccessToken();
315
+ * const accessToken = await ensureToken({ walletProvider });
316
+ * // SDK in-process (Bitcoin-gated extras):
317
+ * await sodax.swaps.createIntent({ params, extras: { bound: { accessToken } }, raw: true });
318
+ * // or backend createIntent — token in the body, not an x-bound-access-token header:
319
+ * await createIntent({ body: { ...body, accessToken } });
320
+ */
321
+ declare function useEnsureRadfiAccessToken({ mutationOptions, }?: MutationHookParams<string, UseEnsureRadfiAccessTokenVars>): SafeUseMutationResult<string, Error, UseEnsureRadfiAccessTokenVars>;
322
+
303
323
  type UseRadfiSessionReturn = {
304
324
  walletAddress: string | undefined;
305
325
  isAuthed: boolean;
@@ -1828,4 +1848,4 @@ interface NearStorageGateState {
1828
1848
  */
1829
1849
  declare function resolveNearStorageGate(chainKey: SpokeChainKey, check: NearStorageCheckResult): NearStorageGateState;
1830
1850
 
1831
- export { type ATokenData, type BackendPaginationParams, type CreateSodaxQueryClientOptions, type DecreaseLiquidityParamsCore, type DepositParamsCore, type LeverageYieldShareHolder, type LeverageYieldShareHolding, type MutationHookOptions, type MutationHookParams, type NearStorageCheckResult, type NearStorageGateState, type RadfiSession, type ReadHookParams, type ReadQueryOptions, type ReserveUsdFormat, type SafeUseMutationResult, SodaxProvider, type UseATokenParams, type UseATokensBalancesParams, type UseApproveTokenVars, type UseBitcoinBalanceParams, type UseBorrowVars, type UseBridgeAllowanceParams, type UseBridgeApproveVars, type UseBridgeVars, type UseClaimRewardsVars, type UseCreateDecreaseLiquidityParamsProps, type UseCreateDepositParamsProps, type UseCreateLimitOrderVars, type UseCreateSupplyLiquidityParamsProps, type UseCreateSupplyLiquidityParamsResult, type UseCreateWithdrawParamsProps, type UseDecreaseLiquidityVars, type UseDeriveUserWalletAddressParams, type UseDexAllowanceParams, type UseDexApproveVars, type UseDexDepositVars, type UseDexWithdrawVars, type UseExpiredUtxosParams, type UseFeeClaimSwapVars, type UseFetchAssetsBalancesParams, type UseFundTradingWalletVars, type UseGetAutoSwapPreferencesParams, type UseGetBridgeableAmountParams, type UseGetBridgeableTokensParams, type UseGetUserHubWalletAddressParams, type UseHubAssetBalancesParams, type UseIsTokenApprovedParams, type UseLeverageYieldDepositVars, type UseLeverageYieldEffectiveAprParams, type UseLeverageYieldNotifySolverVars, type UseLeverageYieldPositionParams, type UseLeverageYieldPreviewRedeemParams, type UseLeverageYieldShareBalancesParams, type UseLeverageYieldTotalAssetsParams, type UseLeverageYieldVaultSwapVars, type UseLeverageYieldWithdrawVars, type UseLiquidityAmountsResult, type UseMMAllowanceParams, type UseMMApproveVars, type UseMigrateBalnVars, type UseMigrateIcxToSodaVars, type UseMigratebnUSDVars, type UseMigrationAllowanceInputs, type UseMigrationAllowanceParams, type UseMigrationApproveVars, type UseNearStorageCheckParams, type UsePoolBalancesParams, type UsePoolBalancesResponse, type UsePoolDataParams, type UsePoolsParams, type UsePositionInfoParams, type UsePositionInfoResponse, type UseQuoteParams, type UseRadfiAuthVars, type UseRadfiSessionReturn, type UseRadfiWithdrawVars, type UseRegisterNearStorageVars, type UseRenewUtxosVars, type UseRepayVars, type UseReservesDataParams, type UseReservesHumanizedParams, type UseReservesListParams, type UseReservesUsdFormatParams, type UseRevertMigrateSodaToIcxVars, type UseSetSwapPreferenceVars, type UseSetSwapPreferenceVarsHub, type UseStatusParams, type UseStellarTrustlineCheckParams, type UseSupplyLiquidityVars, type UseSupplyVars, type UseSwapAllowanceParams, type UseSwapApproveVars, type UseSwapVars, type UseTradingWalletBalanceParams, type UseUserFormattedSummaryParams, type UseUserReservesDataParams, type UseWithdrawHubAssetVars, type UseWithdrawVars, type UseXBalancesParams, type WithdrawParamsCore, type XBalancesInputs, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, loadRadfiSession, resolveNearStorageGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendSubmitSwapTx, useBackendSubmitSwapTxStatus, useBackendUserIntents, useBitcoinBalance, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetUserHubWalletAddress, 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, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
1851
+ export { type ATokenData, type BackendPaginationParams, type CreateSodaxQueryClientOptions, type DecreaseLiquidityParamsCore, type DepositParamsCore, type LeverageYieldShareHolder, type LeverageYieldShareHolding, type MutationHookOptions, type MutationHookParams, type NearStorageCheckResult, type NearStorageGateState, type RadfiSession, type ReadHookParams, type ReadQueryOptions, type ReserveUsdFormat, type SafeUseMutationResult, SodaxProvider, type UseATokenParams, type UseATokensBalancesParams, type UseApproveTokenVars, type UseBitcoinBalanceParams, type UseBorrowVars, type UseBridgeAllowanceParams, type UseBridgeApproveVars, type UseBridgeVars, type UseClaimRewardsVars, type UseCreateDecreaseLiquidityParamsProps, type UseCreateDepositParamsProps, type UseCreateLimitOrderVars, type UseCreateSupplyLiquidityParamsProps, type UseCreateSupplyLiquidityParamsResult, type UseCreateWithdrawParamsProps, type UseDecreaseLiquidityVars, type UseDeriveUserWalletAddressParams, type UseDexAllowanceParams, type UseDexApproveVars, type UseDexDepositVars, type UseDexWithdrawVars, type UseEnsureRadfiAccessTokenVars, type UseExpiredUtxosParams, type UseFeeClaimSwapVars, type UseFetchAssetsBalancesParams, type UseFundTradingWalletVars, type UseGetAutoSwapPreferencesParams, type UseGetBridgeableAmountParams, type UseGetBridgeableTokensParams, type UseGetUserHubWalletAddressParams, type UseHubAssetBalancesParams, type UseIsTokenApprovedParams, type UseLeverageYieldDepositVars, type UseLeverageYieldEffectiveAprParams, type UseLeverageYieldNotifySolverVars, type UseLeverageYieldPositionParams, type UseLeverageYieldPreviewRedeemParams, type UseLeverageYieldShareBalancesParams, type UseLeverageYieldTotalAssetsParams, type UseLeverageYieldVaultSwapVars, type UseLeverageYieldWithdrawVars, type UseLiquidityAmountsResult, type UseMMAllowanceParams, type UseMMApproveVars, type UseMigrateBalnVars, type UseMigrateIcxToSodaVars, type UseMigratebnUSDVars, type UseMigrationAllowanceInputs, type UseMigrationAllowanceParams, type UseMigrationApproveVars, type UseNearStorageCheckParams, type UsePoolBalancesParams, type UsePoolBalancesResponse, type UsePoolDataParams, type UsePoolsParams, type UsePositionInfoParams, type UsePositionInfoResponse, type UseQuoteParams, type UseRadfiAuthVars, type UseRadfiSessionReturn, type UseRadfiWithdrawVars, type UseRegisterNearStorageVars, type UseRenewUtxosVars, type UseRepayVars, type UseReservesDataParams, type UseReservesHumanizedParams, type UseReservesListParams, type UseReservesUsdFormatParams, type UseRevertMigrateSodaToIcxVars, type UseSetSwapPreferenceVars, type UseSetSwapPreferenceVarsHub, type UseStatusParams, type UseStellarTrustlineCheckParams, type UseSupplyLiquidityVars, type UseSupplyVars, type UseSwapAllowanceParams, type UseSwapApproveVars, type UseSwapVars, type UseTradingWalletBalanceParams, type UseUserFormattedSummaryParams, type UseUserReservesDataParams, type UseWithdrawHubAssetVars, type UseWithdrawVars, type UseXBalancesParams, type WithdrawParamsCore, type XBalancesInputs, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, loadRadfiSession, resolveNearStorageGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendSubmitSwapTx, useBackendSubmitSwapTxStatus, useBackendUserIntents, useBitcoinBalance, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetUserHubWalletAddress, 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, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
package/dist/index.mjs CHANGED
@@ -344,6 +344,34 @@ function useHubProvider() {
344
344
  const { sodax } = useSodaxContext();
345
345
  return sodax.hubProvider;
346
346
  }
347
+
348
+ // src/hooks/bitcoin/useEnsureRadfiAccessToken.ts
349
+ function useEnsureRadfiAccessToken({
350
+ mutationOptions
351
+ } = {}) {
352
+ const { sodax } = useSodaxContext();
353
+ return useSafeMutation({
354
+ mutationKey: ["bitcoin", "ensureAccessToken"],
355
+ ...mutationOptions,
356
+ mutationFn: async ({ walletProvider }) => {
357
+ const radfi = sodax.spoke.bitcoin.radfi;
358
+ const walletAddress = await walletProvider.getWalletAddress();
359
+ const session = loadRadfiSession(walletAddress);
360
+ if (session?.refreshToken && !radfi.refreshToken) {
361
+ radfi.setRadfiAccessToken(session.accessToken, session.refreshToken);
362
+ }
363
+ await radfi.ensureRadfiAccessToken(walletProvider);
364
+ const accessToken = radfi.accessToken;
365
+ if (!accessToken) {
366
+ throw new Error("Failed to obtain a Bound Exchange access token");
367
+ }
368
+ if (session) {
369
+ saveRadfiSession(walletAddress, { ...session, accessToken, refreshToken: radfi.refreshToken });
370
+ }
371
+ return accessToken;
372
+ }
373
+ });
374
+ }
347
375
  var REFRESH_INTERVAL = 5 * 60 * 1e3;
348
376
  function useRadfiSession(walletProvider) {
349
377
  const { sodax } = useSodaxContext();
@@ -2756,4 +2784,4 @@ function createSodaxQueryClient({
2756
2784
  });
2757
2785
  }
2758
2786
 
2759
- export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, loadRadfiSession, resolveNearStorageGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendSubmitSwapTx, useBackendSubmitSwapTxStatus, useBackendUserIntents, useBitcoinBalance, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetUserHubWalletAddress, 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, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
2787
+ export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, loadRadfiSession, resolveNearStorageGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendSubmitSwapTx, useBackendSubmitSwapTxStatus, useBackendUserIntents, useBitcoinBalance, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetUserHubWalletAddress, 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, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "access": "public"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "2.0.0-rc.13",
8
+ "version": "2.0.0-rc.15",
9
9
  "description": "React hooks for building dApps on the SODAX cross-chain DeFi platform",
10
10
  "keywords": [
11
11
  "sodax",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "viem": "2.29.2",
37
- "@sodax/sdk": "2.0.0-rc.13"
37
+ "@sodax/sdk": "2.0.0-rc.15"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@arethetypeswrong/cli": "0.17.4",
@@ -44,7 +44,7 @@
44
44
  "tslib": "2.8.1",
45
45
  "tsup": "8.5.0",
46
46
  "typescript": "5.5.4",
47
- "vitest": "3.2.4"
47
+ "vitest": "3.2.6"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@tanstack/react-query": "5.x",
@@ -14,6 +14,7 @@ const HOOKS_DIR = resolve(fileURLToPath(import.meta.url), '..');
14
14
  */
15
15
  const HOOKS: Array<{ path: string; nativeThrow?: true }> = [
16
16
  { path: 'backend/useBackendSubmitSwapTx.ts' },
17
+ { path: 'bitcoin/useEnsureRadfiAccessToken.ts', nativeThrow: true },
17
18
  { path: 'bitcoin/useFundTradingWallet.ts', nativeThrow: true },
18
19
  { path: 'bitcoin/useRadfiAuth.ts', nativeThrow: true },
19
20
  { path: 'bitcoin/useRadfiWithdraw.ts', nativeThrow: true },
@@ -1,4 +1,5 @@
1
1
  export * from './useRadfiAuth.js';
2
+ export * from './useEnsureRadfiAccessToken.js';
2
3
  export * from './useRadfiSession.js';
3
4
  export * from './useFundTradingWallet.js';
4
5
  export * from './useBitcoinBalance.js';
@@ -0,0 +1,57 @@
1
+ import type { IBitcoinWalletProvider } from '@sodax/sdk';
2
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
3
+ import type { MutationHookParams } from '../shared/types.js';
4
+ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
5
+ import { loadRadfiSession, saveRadfiSession } from './useRadfiAuth.js';
6
+
7
+ export type UseEnsureRadfiAccessTokenVars = {
8
+ walletProvider: IBitcoinWalletProvider;
9
+ };
10
+
11
+ /**
12
+ * Ensure a valid Bound Exchange access token and return it. Refreshes the existing token (no
13
+ * signature prompt) when a refresh token is available, falling back to a full BIP322 re-auth only if
14
+ * refresh fails. Bound tokens are short-lived, so call this right before a Bitcoin-source
15
+ * createIntent — forward the returned token via the typed `extras.bound.accessToken` slot (SDK in-process)
16
+ * or the `accessToken` body field on the backend DTO — or before the client-side sign + co-sign step.
17
+ *
18
+ * @example
19
+ * const { mutateAsync: ensureToken } = useEnsureRadfiAccessToken();
20
+ * const accessToken = await ensureToken({ walletProvider });
21
+ * // SDK in-process (Bitcoin-gated extras):
22
+ * await sodax.swaps.createIntent({ params, extras: { bound: { accessToken } }, raw: true });
23
+ * // or backend createIntent — token in the body, not an x-bound-access-token header:
24
+ * await createIntent({ body: { ...body, accessToken } });
25
+ */
26
+ export function useEnsureRadfiAccessToken({
27
+ mutationOptions,
28
+ }: MutationHookParams<string, UseEnsureRadfiAccessTokenVars> = {}): SafeUseMutationResult<
29
+ string,
30
+ Error,
31
+ UseEnsureRadfiAccessTokenVars
32
+ > {
33
+ const { sodax } = useSodaxContext();
34
+ return useSafeMutation<string, Error, UseEnsureRadfiAccessTokenVars>({
35
+ mutationKey: ['bitcoin', 'ensureAccessToken'],
36
+ ...mutationOptions,
37
+ mutationFn: async ({ walletProvider }) => {
38
+ const radfi = sodax.spoke.bitcoin.radfi;
39
+ const walletAddress = await walletProvider.getWalletAddress();
40
+ // Seed in-memory tokens from the saved session so a refresh can run without a re-sign popup.
41
+ const session = loadRadfiSession(walletAddress);
42
+ if (session?.refreshToken && !radfi.refreshToken) {
43
+ radfi.setRadfiAccessToken(session.accessToken, session.refreshToken);
44
+ }
45
+ await radfi.ensureRadfiAccessToken(walletProvider);
46
+ const accessToken = radfi.accessToken;
47
+ if (!accessToken) {
48
+ throw new Error('Failed to obtain a Bound Exchange access token');
49
+ }
50
+ // Persist refreshed tokens so a later reload can refresh again without re-signing.
51
+ if (session) {
52
+ saveRadfiSession(walletAddress, { ...session, accessToken, refreshToken: radfi.refreshToken });
53
+ }
54
+ return accessToken;
55
+ },
56
+ });
57
+ }