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

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.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { UseMutationOptions, UseQueryOptions, UseMutationResult, MutateOptions, UseQueryResult, QueryClientConfig, QueryClient } from '@tanstack/react-query';
2
- import { Result, Sodax, SpokeChainKey, GetEstimateGasReturnType, EstimateGasParams, IStellarWalletProvider, StellarChainKey, INearWalletProvider, GetWalletProviderType, IXServiceBase, XToken, EvmHubProvider, IBitcoinWalletProvider, RadfiWalletBalance, RadfiUtxo, MoneyMarketBorrowActionParams, TxHashPair, MoneyMarketRepayActionParams, MoneyMarketSupplyActionParams, MoneyMarketWithdrawActionParams, UserReserveData, AggregatedReserveData, BaseCurrencyInfo, ReservesDataHumanized, Address as Address$1, MoneyMarketParams, MoneyMarketApproveActionParams, TxReturnType, Erc20Token, ChainKey, ReserveDataHumanized, FormatReserveUSDResponse, FormatUserSummaryResponse, SolverIntentQuoteResponse, SolverErrorResponse, SolverIntentQuoteRequest, SwapActionParams, SwapResponse, SolverIntentStatusResponse, Hex, CreateIntentParams, CreateLimitOrderParams, Intent, LimitOrderActionParams, IntentResponse, UserIntentsResponse, SubmitSwapTxResponse, SubmitSwapTxRequest, RequestOverrideConfig, SubmitSwapTxStatusResponse, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, BridgeParams, CreateBridgeIntentParams, BridgeLimit, StakeAction, StakeParams, UnstakeAction, ClaimAction, CancelUnstakeAction, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeAction, UnstakeParams, InstantUnstakeParams, PartnerFeeClaimAssetBalance, AutoSwapPreferences, FeeTokenApproveParams, FeeTokenApproveAction, HubChainKey, SetSwapPreferenceAction, PartnerFeeClaimSwapAction, IntentAutoSwapResult, HubAssetBalance, WithdrawHubAssetAction, IcxMigrateAction, IcxRevertMigrationAction, UnifiedBnUSDMigrateAction, BalnMigrateAction, MigrationAction, IcxMigrateParams, IcxCreateRevertMigrationParams, UnifiedBnUSDMigrateParams, BalnMigrateParams, PoolKey, PoolData, ClPositionInfo, AssetDepositAction, AssetWithdrawAction, CreateAssetDepositParams, ClSupplyParams, ClIncreaseLiquidityParams, ClLiquidityDecreaseLiquidityAction, ClDecreaseLiquidityParams, CreateAssetWithdrawParams, PoolSpokeAssets, DestinationParamsType, ClLiquidityClaimRewardsAction, SodaxOptions } from '@sodax/sdk';
2
+ import { Result, Sodax, SpokeChainKey, GetEstimateGasReturnType, EstimateGasParams, IStellarWalletProvider, StellarChainKey, INearWalletProvider, GetWalletProviderType, IXServiceBase, XToken, EvmHubProvider, IBitcoinWalletProvider, RadfiWalletBalance, RadfiUtxo, MoneyMarketBorrowActionParams, TxHashPair, MoneyMarketRepayActionParams, MoneyMarketSupplyActionParams, MoneyMarketWithdrawActionParams, UserReserveData, AggregatedReserveData, BaseCurrencyInfo, ReservesDataHumanized, Address as Address$1, MoneyMarketParams, MoneyMarketApproveActionParams, TxReturnType, Erc20Token, ChainKey, ReserveDataHumanized, FormatReserveUSDResponse, FormatUserSummaryResponse, SolverIntentQuoteResponse, SolverErrorResponse, SolverIntentQuoteRequest, SwapActionParams, SwapResponse, SolverIntentStatusResponse, Hex, CreateIntentParams, CreateLimitOrderParams, Intent, LimitOrderActionParams, IntentResponse, UserIntentsResponse, SubmitSwapTxResponse, SubmitSwapTxRequest, RequestOverrideConfig, SubmitSwapTxStatusResponse, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, BridgeParams, CreateBridgeIntentParams, BridgeLimit, StakeAction, StakeParams, UnstakeAction, ClaimAction, CancelUnstakeAction, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeAction, UnstakeParams, InstantUnstakeParams, PartnerFeeClaimAssetBalance, AutoSwapPreferences, FeeTokenApproveParams, FeeTokenApproveAction, HubChainKey, SetSwapPreferenceAction, PartnerFeeClaimSwapAction, IntentAutoSwapResult, HubAssetBalance, WithdrawHubAssetAction, IcxMigrateAction, IcxRevertMigrationAction, UnifiedBnUSDMigrateAction, BalnMigrateAction, MigrationAction, IcxMigrateParams, IcxCreateRevertMigrationParams, UnifiedBnUSDMigrateParams, BalnMigrateParams, PoolKey, PoolData, ClPositionInfo, AssetDepositAction, AssetWithdrawAction, CreateAssetDepositParams, ClSupplyParams, ClIncreaseLiquidityParams, ClLiquidityDecreaseLiquidityAction, ClDecreaseLiquidityParams, CreateAssetWithdrawParams, PoolSpokeAssets, DestinationParamsType, ClLiquidityClaimRewardsAction, LeverageYieldEffectiveApr, LeverageYieldPosition, LeverageYieldSwapDepositParams, LeverageYieldSwapPayload, SolverExecutionRequest, SolverExecutionResponse, VaultSwapActionParams, VaultSwapResponse, LeverageYieldSwapWithdrawParams, SodaxOptions } from '@sodax/sdk';
3
3
  export * from '@sodax/sdk';
4
4
  import { Address } from 'viem';
5
5
  import { ReactNode, ReactElement } from 'react';
@@ -1541,6 +1541,188 @@ type UseClaimRewardsVars<K extends SpokeChainKey = SpokeChainKey> = Omit<ClLiqui
1541
1541
  */
1542
1542
  declare function useClaimRewards<K extends SpokeChainKey = SpokeChainKey>({ mutationOptions, }?: MutationHookParams<TxHashPair, UseClaimRewardsVars<K>>): SafeUseMutationResult<TxHashPair, Error, UseClaimRewardsVars<K>>;
1543
1543
 
1544
+ type UseLeverageYieldEffectiveAprParams = ReadHookParams<LeverageYieldEffectiveApr, {
1545
+ vault: Address$1 | undefined;
1546
+ }>;
1547
+ /**
1548
+ * Reads a leverage-yield vault's effective APR — AAVE supply/borrow rates plus the LSD
1549
+ * staking yield, with the vault's leverage formula re-applied on the boosted supply side.
1550
+ *
1551
+ * The underlying SDK call does the on-chain reads (AAVE rates + `targetLTV`) and the
1552
+ * off-chain LSD fetch in parallel. Rates drift slowly, so the default refresh is 60s.
1553
+ *
1554
+ * @example
1555
+ * ```typescript
1556
+ * const { data: apr } = useLeverageYieldEffectiveApr({ params: { vault: vault.vault } });
1557
+ * ```
1558
+ */
1559
+ declare function useLeverageYieldEffectiveApr({ params, queryOptions, }?: UseLeverageYieldEffectiveAprParams): UseQueryResult<LeverageYieldEffectiveApr, Error>;
1560
+
1561
+ type UseLeverageYieldPositionParams = ReadHookParams<LeverageYieldPosition, {
1562
+ vault: Address$1 | undefined;
1563
+ }>;
1564
+ /**
1565
+ * Reads a leverage-yield vault's live position snapshot via the vault's `getPositionDetails`:
1566
+ * collateral, debt, current LTV (drift vs `targetLTV`), health factor (∞ when no debt), and
1567
+ * idle (not-yet-deployed) asset.
1568
+ *
1569
+ * LTV shifts with each rebalance/rate tick, so the default refresh (30s) is faster than the
1570
+ * APR/stats reads.
1571
+ *
1572
+ * @example
1573
+ * ```typescript
1574
+ * const { data: position } = useLeverageYieldPosition({ params: { vault: vault.vault } });
1575
+ * ```
1576
+ */
1577
+ declare function useLeverageYieldPosition({ params, queryOptions, }?: UseLeverageYieldPositionParams): UseQueryResult<LeverageYieldPosition, Error>;
1578
+
1579
+ type UseLeverageYieldTotalAssetsParams = ReadHookParams<bigint, {
1580
+ vault: Address$1 | undefined;
1581
+ }>;
1582
+ /**
1583
+ * Reads a leverage-yield vault's total underlying assets (vault-asset units, 18 decimals) —
1584
+ * i.e. its TVL. Moves slowly, so the default refresh is 60s.
1585
+ *
1586
+ * @example
1587
+ * ```typescript
1588
+ * const { data: tvl } = useLeverageYieldTotalAssets({ params: { vault: vault.vault } });
1589
+ * ```
1590
+ */
1591
+ declare function useLeverageYieldTotalAssets({ params, queryOptions, }?: UseLeverageYieldTotalAssetsParams): UseQueryResult<bigint, Error>;
1592
+
1593
+ type UseLeverageYieldPreviewRedeemParams = ReadHookParams<bigint, {
1594
+ vault: Address$1 | undefined;
1595
+ shares: bigint | undefined;
1596
+ }>;
1597
+ /**
1598
+ * Reads the assets received for redeeming `shares` of a leverage-yield vault (ERC-4626
1599
+ * `previewRedeem`). Passing `10n ** 18n` (one share) yields the per-share price that creeps
1600
+ * up as the vault accrues interest. Moves slowly, so the default refresh is 60s.
1601
+ *
1602
+ * @example
1603
+ * ```typescript
1604
+ * const { data: sharePrice } = useLeverageYieldPreviewRedeem({
1605
+ * params: { vault: vault.vault, shares: 10n ** 18n },
1606
+ * });
1607
+ * ```
1608
+ */
1609
+ declare function useLeverageYieldPreviewRedeem({ params, queryOptions, }?: UseLeverageYieldPreviewRedeemParams): UseQueryResult<bigint, Error>;
1610
+
1611
+ /** A single `(chain, hub-wallet holder, share balance)` row produced by {@link useLeverageYieldShareBalances}. */
1612
+ type LeverageYieldShareHolding = {
1613
+ chainKey: SpokeChainKey;
1614
+ holder: Address$1;
1615
+ shares: bigint;
1616
+ };
1617
+ /** A `(chainKey, EOA address)` pair the user controls — one per spoke chain they may hold shares under. */
1618
+ type LeverageYieldShareHolder = {
1619
+ chainKey: SpokeChainKey;
1620
+ address: string;
1621
+ };
1622
+ type UseLeverageYieldShareBalancesParams = ReadHookParams<LeverageYieldShareHolding, {
1623
+ vault: Address$1 | undefined;
1624
+ holders: readonly LeverageYieldShareHolder[] | undefined;
1625
+ }>;
1626
+ /**
1627
+ * Reads a user's leverage-vault share (`lsoda*`) balances across every chain they may hold a
1628
+ * position under — one query per holder, fanned out via `useQueries`.
1629
+ *
1630
+ * For each `(chainKey, address)` the holder is resolved to the address that actually owns the
1631
+ * shares: the user's **derived hub wallet** on every chain, including the hub itself. Leverage
1632
+ * deposits always deliver `lsoda*` to `getUserHubWalletAddress(srcAddress, srcChainKey)` (the
1633
+ * CREATE3 user-router on Sonic for a hub-sourced deposit, the per-spoke hub wallet otherwise) —
1634
+ * never the bare EOA — so a hub-chain deposit's shares live in the router, not the signing EOA.
1635
+ * Resolving the holder the same way the deposit does is what makes a Sonic-sourced position show
1636
+ * up here instead of reading a stale zero off the EOA.
1637
+ *
1638
+ * Returns the raw `useQueries` result array (15s refresh per query); callers aggregate as needed
1639
+ * (e.g. sum `shares` for a headline total, or pick the row for the active chain).
1640
+ *
1641
+ * `useQueries` has no top-level options slot, so `queryOptions` is spread into every individual
1642
+ * query config (and applies uniformly to each holder's query).
1643
+ *
1644
+ * @example
1645
+ * ```typescript
1646
+ * const balances = useLeverageYieldShareBalances({ params: { vault: vault.vault, holders } });
1647
+ * const total = balances.reduce((acc, q) => acc + (q.data?.shares ?? 0n), 0n);
1648
+ * ```
1649
+ */
1650
+ declare function useLeverageYieldShareBalances({ params, queryOptions, }?: UseLeverageYieldShareBalancesParams): UseQueryResult<LeverageYieldShareHolding, Error>[];
1651
+
1652
+ /** Mutation variables for {@link useLeverageYieldDeposit} — the swap-style deposit inputs. */
1653
+ type UseLeverageYieldDepositVars = LeverageYieldSwapDepositParams;
1654
+ /**
1655
+ * Builds the `LeverageYieldSwapPayload` for a leverage-yield deposit (any token → `lsoda*` shares,
1656
+ * delivered to the user's hub wallet). Spread the returned payload into
1657
+ * {@link useLeverageYieldVaultSwap}.
1658
+ *
1659
+ * This is a builder, not an executor — it derives the hub wallet and assembles the intent; the
1660
+ * actual swap is relayed by `useLeverageYieldVaultSwap`. Throws on SDK failure so React Query's
1661
+ * error model engages; returns the unwrapped `LeverageYieldSwapPayload` on success.
1662
+ *
1663
+ * @example
1664
+ * ```typescript
1665
+ * const { mutateAsyncSafe: buildDeposit } = useLeverageYieldDeposit();
1666
+ * const built = await buildDeposit({ vault, srcChainKey, srcAddress, inputToken, inputAmount, minOutputAmount });
1667
+ * if (built.ok) vaultSwap({ ...built.value, walletProvider });
1668
+ * ```
1669
+ */
1670
+ declare function useLeverageYieldDeposit({ mutationOptions, }?: MutationHookParams<LeverageYieldSwapPayload, UseLeverageYieldDepositVars>): SafeUseMutationResult<LeverageYieldSwapPayload, Error, UseLeverageYieldDepositVars>;
1671
+
1672
+ /** Mutation variables for {@link useLeverageYieldNotifySolver} — the hub-side intent tx hash. */
1673
+ type UseLeverageYieldNotifySolverVars = SolverExecutionRequest;
1674
+ /**
1675
+ * Notifies the solver that a leverage-yield vault intent landed on the hub, triggering the fill.
1676
+ * The standalone notify step for the manual create → relay → notify flow: build the intent with
1677
+ * `sodax.leverageYield.createVaultIntent`, relay it yourself, then call this with the hub-side
1678
+ * intent tx hash. The end-to-end {@link useLeverageYieldVaultSwap} already calls notifySolver
1679
+ * internally — only reach for this hook when driving the relay manually.
1680
+ *
1681
+ * Throws on SDK failure so React Query's error model engages; returns the unwrapped
1682
+ * `SolverExecutionResponse` (`{ answer: 'OK', intent_hash }`) on success.
1683
+ */
1684
+ declare function useLeverageYieldNotifySolver({ mutationOptions, }?: MutationHookParams<SolverExecutionResponse, UseLeverageYieldNotifySolverVars>): SafeUseMutationResult<SolverExecutionResponse, Error, UseLeverageYieldNotifySolverVars>;
1685
+
1686
+ /**
1687
+ * Mutation variables for {@link useLeverageYieldVaultSwap}. Generic over `K extends SpokeChainKey`
1688
+ * (defaults to the full union). Sophisticated callers can lock K at the hook call site to narrow
1689
+ * the `walletProvider` and `params.srcChainKey` types.
1690
+ */
1691
+ type UseLeverageYieldVaultSwapVars<K extends SpokeChainKey = SpokeChainKey> = Omit<VaultSwapActionParams<K, false>, 'raw'>;
1692
+ /**
1693
+ * React hook for executing an end-to-end leverage-yield vault swap (deposit or withdraw).
1694
+ *
1695
+ * Spread a `LeverageYieldSwapPayload` built by {@link useLeverageYieldDeposit} /
1696
+ * {@link useLeverageYieldWithdraw} into `mutate` alongside the wallet provider:
1697
+ * `vaultSwap({ ...payload, walletProvider })`. Runs `sodax.leverageYield.vaultSwap` —
1698
+ * create intent → verify → relay → notify solver — so vault flows never touch the
1699
+ * generic swap surface.
1700
+ *
1701
+ * Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
1702
+ * `onError`, `retry`). Returns the unwrapped `VaultSwapResponse` on success.
1703
+ */
1704
+ declare function useLeverageYieldVaultSwap<K extends SpokeChainKey = SpokeChainKey>({ mutationOptions, }?: MutationHookParams<VaultSwapResponse, UseLeverageYieldVaultSwapVars<K>>): SafeUseMutationResult<VaultSwapResponse, Error, UseLeverageYieldVaultSwapVars<K>>;
1705
+
1706
+ /** Mutation variables for {@link useLeverageYieldWithdraw} — the swap-style withdraw inputs. */
1707
+ type UseLeverageYieldWithdrawVars = LeverageYieldSwapWithdrawParams;
1708
+ /**
1709
+ * Builds the `LeverageYieldSwapPayload` for a leverage-yield withdraw (`lsoda*` shares → any token).
1710
+ * The returned payload carries `hubWalletSwap: true`; spread it into
1711
+ * {@link useLeverageYieldVaultSwap}, which authorises the hub wallet to spend the shares via a
1712
+ * `Connection.sendMessage`.
1713
+ *
1714
+ * This is a builder, not an executor. Throws on SDK failure so React Query's error model engages;
1715
+ * returns the unwrapped `LeverageYieldSwapPayload` on success.
1716
+ *
1717
+ * @example
1718
+ * ```typescript
1719
+ * const { mutateAsyncSafe: buildWithdraw } = useLeverageYieldWithdraw();
1720
+ * const built = await buildWithdraw({ vault, srcChainKey, srcAddress, dstChainKey, outputToken, inputAmount, minOutputAmount });
1721
+ * if (built.ok) vaultSwap({ ...built.value, walletProvider });
1722
+ * ```
1723
+ */
1724
+ declare function useLeverageYieldWithdraw({ mutationOptions, }?: MutationHookParams<LeverageYieldSwapPayload, UseLeverageYieldWithdrawVars>): SafeUseMutationResult<LeverageYieldSwapPayload, Error, UseLeverageYieldWithdrawVars>;
1725
+
1544
1726
  interface SodaxProviderProps {
1545
1727
  children: ReactNode;
1546
1728
  /**
@@ -1646,4 +1828,4 @@ interface NearStorageGateState {
1646
1828
  */
1647
1829
  declare function resolveNearStorageGate(chainKey: SpokeChainKey, check: NearStorageCheckResult): NearStorageGateState;
1648
1830
 
1649
- export { type ATokenData, type BackendPaginationParams, type CreateSodaxQueryClientOptions, type DecreaseLiquidityParamsCore, type DepositParamsCore, 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 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, 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 };
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 };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { useMutation, useQuery, useQueryClient, QueryClient, MutationCache } from '@tanstack/react-query';
1
+ import { useMutation, useQuery, useQueryClient, useQueries, QueryClient, MutationCache } from '@tanstack/react-query';
2
2
  import { createContext, useCallback, useContext, useState, useRef, useEffect, useMemo } from 'react';
3
3
  import { ChainKeys, RadfiApiError, normalizePsbtToBase64, ClService, Sodax } from '@sodax/sdk';
4
4
  export * from '@sodax/sdk';
@@ -2573,6 +2573,158 @@ function useClaimRewards({
2573
2573
  }
2574
2574
  });
2575
2575
  }
2576
+ function useLeverageYieldEffectiveApr({
2577
+ params,
2578
+ queryOptions
2579
+ } = {}) {
2580
+ const { sodax } = useSodaxContext();
2581
+ const vault = params?.vault;
2582
+ return useQuery({
2583
+ queryKey: ["leverageYield", "effectiveApr", vault],
2584
+ queryFn: async () => {
2585
+ if (!vault) throw new Error("vault is required");
2586
+ const result = await sodax.leverageYield.getEffectiveApr(vault);
2587
+ if (!result.ok) throw result.error;
2588
+ return result.value;
2589
+ },
2590
+ enabled: !!vault,
2591
+ refetchInterval: 6e4,
2592
+ ...queryOptions
2593
+ });
2594
+ }
2595
+ function useLeverageYieldPosition({
2596
+ params,
2597
+ queryOptions
2598
+ } = {}) {
2599
+ const { sodax } = useSodaxContext();
2600
+ const vault = params?.vault;
2601
+ return useQuery({
2602
+ queryKey: ["leverageYield", "position", vault],
2603
+ queryFn: async () => {
2604
+ if (!vault) throw new Error("vault is required");
2605
+ const result = await sodax.leverageYield.getPosition(vault);
2606
+ if (!result.ok) throw result.error;
2607
+ return result.value;
2608
+ },
2609
+ enabled: !!vault,
2610
+ refetchInterval: 3e4,
2611
+ ...queryOptions
2612
+ });
2613
+ }
2614
+ function useLeverageYieldTotalAssets({
2615
+ params,
2616
+ queryOptions
2617
+ } = {}) {
2618
+ const { sodax } = useSodaxContext();
2619
+ const vault = params?.vault;
2620
+ return useQuery({
2621
+ queryKey: ["leverageYield", "totalAssets", vault],
2622
+ queryFn: async () => {
2623
+ if (!vault) throw new Error("vault is required");
2624
+ const result = await sodax.leverageYield.getTotalAssets(vault);
2625
+ if (!result.ok) throw result.error;
2626
+ return result.value;
2627
+ },
2628
+ enabled: !!vault,
2629
+ refetchInterval: 6e4,
2630
+ ...queryOptions
2631
+ });
2632
+ }
2633
+ function useLeverageYieldPreviewRedeem({
2634
+ params,
2635
+ queryOptions
2636
+ } = {}) {
2637
+ const { sodax } = useSodaxContext();
2638
+ const vault = params?.vault;
2639
+ const shares = params?.shares;
2640
+ return useQuery({
2641
+ queryKey: ["leverageYield", "previewRedeem", vault, shares?.toString()],
2642
+ queryFn: async () => {
2643
+ if (!vault || shares === void 0) throw new Error("vault and shares are required");
2644
+ const result = await sodax.leverageYield.previewRedeem(vault, shares);
2645
+ if (!result.ok) throw result.error;
2646
+ return result.value;
2647
+ },
2648
+ enabled: !!vault && shares !== void 0,
2649
+ refetchInterval: 6e4,
2650
+ ...queryOptions
2651
+ });
2652
+ }
2653
+ function useLeverageYieldShareBalances({
2654
+ params,
2655
+ queryOptions
2656
+ } = {}) {
2657
+ const { sodax } = useSodaxContext();
2658
+ const vault = params?.vault;
2659
+ const holders = params?.holders;
2660
+ return useQueries({
2661
+ queries: (holders ?? []).map(({ chainKey, address }) => ({
2662
+ queryKey: ["leverageYield", "shareBalance", vault, chainKey, address],
2663
+ refetchInterval: 15e3,
2664
+ ...queryOptions,
2665
+ enabled: !!vault,
2666
+ queryFn: async () => {
2667
+ if (!vault) throw new Error("vault is required");
2668
+ const holder = await sodax.hubProvider.getUserHubWalletAddress(address, chainKey);
2669
+ const result = await sodax.leverageYield.getShareBalance(vault, holder);
2670
+ if (!result.ok) throw result.error;
2671
+ return { chainKey, holder, shares: result.value };
2672
+ }
2673
+ }))
2674
+ });
2675
+ }
2676
+
2677
+ // src/hooks/leverageYield/useLeverageYieldDeposit.ts
2678
+ function useLeverageYieldDeposit({
2679
+ mutationOptions
2680
+ } = {}) {
2681
+ const { sodax } = useSodaxContext();
2682
+ return useSafeMutation({
2683
+ mutationKey: ["leverageYield", "deposit"],
2684
+ ...mutationOptions,
2685
+ mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.deposit(vars))
2686
+ });
2687
+ }
2688
+
2689
+ // src/hooks/leverageYield/useLeverageYieldNotifySolver.ts
2690
+ function useLeverageYieldNotifySolver({
2691
+ mutationOptions
2692
+ } = {}) {
2693
+ const { sodax } = useSodaxContext();
2694
+ return useSafeMutation({
2695
+ mutationKey: ["leverageYield", "notifySolver"],
2696
+ ...mutationOptions,
2697
+ mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.notifySolver(vars))
2698
+ });
2699
+ }
2700
+ function useLeverageYieldVaultSwap({
2701
+ mutationOptions
2702
+ } = {}) {
2703
+ const { sodax } = useSodaxContext();
2704
+ const queryClient = useQueryClient();
2705
+ return useSafeMutation({
2706
+ mutationKey: ["leverageYield", "vaultSwap"],
2707
+ ...mutationOptions,
2708
+ mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.vaultSwap({ ...vars, raw: false })),
2709
+ onSuccess: async (data, vars, ctx) => {
2710
+ queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.srcChainKey] });
2711
+ queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.dstChainKey] });
2712
+ await mutationOptions?.onSuccess?.(data, vars, ctx);
2713
+ }
2714
+ });
2715
+ }
2716
+
2717
+ // src/hooks/leverageYield/useLeverageYieldWithdraw.ts
2718
+ function useLeverageYieldWithdraw({
2719
+ mutationOptions
2720
+ } = {}) {
2721
+ const { sodax } = useSodaxContext();
2722
+ return useSafeMutation({
2723
+ mutationKey: ["leverageYield", "withdraw"],
2724
+ ...mutationOptions,
2725
+ mutationFn: async (vars) => unwrapResult(await sodax.leverageYield.withdraw(vars))
2726
+ });
2727
+ }
2576
2728
  var SodaxProvider = ({ children, config }) => {
2577
2729
  const sodax = useMemo(() => new Sodax(config), [config]);
2578
2730
  const contextValue = useMemo(() => ({ sodax }), [sodax]);
@@ -2604,4 +2756,4 @@ function createSodaxQueryClient({
2604
2756
  });
2605
2757
  }
2606
2758
 
2607
- 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, 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 };
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 };
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "access": "public"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "2.0.0-rc.12",
8
+ "version": "2.0.0-rc.13",
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.12"
37
+ "@sodax/sdk": "2.0.0-rc.13"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@arethetypeswrong/cli": "0.17.4",
@@ -26,6 +26,10 @@ const HOOKS: Array<{ path: string; nativeThrow?: true }> = [
26
26
  { path: 'dex/useDexDeposit.ts' },
27
27
  { path: 'dex/useDexWithdraw.ts' },
28
28
  { path: 'dex/useSupplyLiquidity.ts' },
29
+ { path: 'leverageYield/useLeverageYieldDeposit.ts' },
30
+ { path: 'leverageYield/useLeverageYieldNotifySolver.ts' },
31
+ { path: 'leverageYield/useLeverageYieldVaultSwap.ts' },
32
+ { path: 'leverageYield/useLeverageYieldWithdraw.ts' },
29
33
  { path: 'migrate/useMigrateBaln.ts' },
30
34
  { path: 'migrate/useMigrateIcxToSoda.ts' },
31
35
  { path: 'migrate/useMigratebnUSD.ts' },
@@ -10,3 +10,4 @@ export * from './partner/index.js';
10
10
  export * from './recovery/index.js';
11
11
  export * from './migrate/index.js';
12
12
  export * from './dex/index.js';
13
+ export * from './leverageYield/index.js';
@@ -0,0 +1,9 @@
1
+ export * from './useLeverageYieldEffectiveApr.js';
2
+ export * from './useLeverageYieldPosition.js';
3
+ export * from './useLeverageYieldTotalAssets.js';
4
+ export * from './useLeverageYieldPreviewRedeem.js';
5
+ export * from './useLeverageYieldShareBalances.js';
6
+ export * from './useLeverageYieldDeposit.js';
7
+ export * from './useLeverageYieldNotifySolver.js';
8
+ export * from './useLeverageYieldVaultSwap.js';
9
+ export * from './useLeverageYieldWithdraw.js';
@@ -0,0 +1,40 @@
1
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
2
+ import type { LeverageYieldSwapPayload, LeverageYieldSwapDepositParams } from '@sodax/sdk';
3
+ import type { MutationHookParams } from '../shared/types.js';
4
+ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
5
+ import { unwrapResult } from '../shared/unwrapResult.js';
6
+
7
+ /** Mutation variables for {@link useLeverageYieldDeposit} — the swap-style deposit inputs. */
8
+ export type UseLeverageYieldDepositVars = LeverageYieldSwapDepositParams;
9
+
10
+ /**
11
+ * Builds the `LeverageYieldSwapPayload` for a leverage-yield deposit (any token → `lsoda*` shares,
12
+ * delivered to the user's hub wallet). Spread the returned payload into
13
+ * {@link useLeverageYieldVaultSwap}.
14
+ *
15
+ * This is a builder, not an executor — it derives the hub wallet and assembles the intent; the
16
+ * actual swap is relayed by `useLeverageYieldVaultSwap`. Throws on SDK failure so React Query's
17
+ * error model engages; returns the unwrapped `LeverageYieldSwapPayload` on success.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const { mutateAsyncSafe: buildDeposit } = useLeverageYieldDeposit();
22
+ * const built = await buildDeposit({ vault, srcChainKey, srcAddress, inputToken, inputAmount, minOutputAmount });
23
+ * if (built.ok) vaultSwap({ ...built.value, walletProvider });
24
+ * ```
25
+ */
26
+ export function useLeverageYieldDeposit({
27
+ mutationOptions,
28
+ }: MutationHookParams<LeverageYieldSwapPayload, UseLeverageYieldDepositVars> = {}): SafeUseMutationResult<
29
+ LeverageYieldSwapPayload,
30
+ Error,
31
+ UseLeverageYieldDepositVars
32
+ > {
33
+ const { sodax } = useSodaxContext();
34
+
35
+ return useSafeMutation<LeverageYieldSwapPayload, Error, UseLeverageYieldDepositVars>({
36
+ mutationKey: ['leverageYield', 'deposit'],
37
+ ...mutationOptions,
38
+ mutationFn: async vars => unwrapResult(await sodax.leverageYield.deposit(vars)),
39
+ });
40
+ }
@@ -0,0 +1,42 @@
1
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
3
+ import type { Address, LeverageYieldEffectiveApr } from '@sodax/sdk';
4
+ import type { ReadHookParams } from '../shared/types.js';
5
+
6
+ export type UseLeverageYieldEffectiveAprParams = ReadHookParams<
7
+ LeverageYieldEffectiveApr,
8
+ { vault: Address | undefined }
9
+ >;
10
+
11
+ /**
12
+ * Reads a leverage-yield vault's effective APR — AAVE supply/borrow rates plus the LSD
13
+ * staking yield, with the vault's leverage formula re-applied on the boosted supply side.
14
+ *
15
+ * The underlying SDK call does the on-chain reads (AAVE rates + `targetLTV`) and the
16
+ * off-chain LSD fetch in parallel. Rates drift slowly, so the default refresh is 60s.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const { data: apr } = useLeverageYieldEffectiveApr({ params: { vault: vault.vault } });
21
+ * ```
22
+ */
23
+ export function useLeverageYieldEffectiveApr({
24
+ params,
25
+ queryOptions,
26
+ }: UseLeverageYieldEffectiveAprParams = {}): UseQueryResult<LeverageYieldEffectiveApr, Error> {
27
+ const { sodax } = useSodaxContext();
28
+ const vault = params?.vault;
29
+
30
+ return useQuery<LeverageYieldEffectiveApr, Error>({
31
+ queryKey: ['leverageYield', 'effectiveApr', vault],
32
+ queryFn: async () => {
33
+ if (!vault) throw new Error('vault is required');
34
+ const result = await sodax.leverageYield.getEffectiveApr(vault);
35
+ if (!result.ok) throw result.error;
36
+ return result.value;
37
+ },
38
+ enabled: !!vault,
39
+ refetchInterval: 60_000,
40
+ ...queryOptions,
41
+ });
42
+ }
@@ -0,0 +1,34 @@
1
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
2
+ import type { SolverExecutionRequest, SolverExecutionResponse } from '@sodax/sdk';
3
+ import type { MutationHookParams } from '../shared/types.js';
4
+ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
5
+ import { unwrapResult } from '../shared/unwrapResult.js';
6
+
7
+ /** Mutation variables for {@link useLeverageYieldNotifySolver} — the hub-side intent tx hash. */
8
+ export type UseLeverageYieldNotifySolverVars = SolverExecutionRequest;
9
+
10
+ /**
11
+ * Notifies the solver that a leverage-yield vault intent landed on the hub, triggering the fill.
12
+ * The standalone notify step for the manual create → relay → notify flow: build the intent with
13
+ * `sodax.leverageYield.createVaultIntent`, relay it yourself, then call this with the hub-side
14
+ * intent tx hash. The end-to-end {@link useLeverageYieldVaultSwap} already calls notifySolver
15
+ * internally — only reach for this hook when driving the relay manually.
16
+ *
17
+ * Throws on SDK failure so React Query's error model engages; returns the unwrapped
18
+ * `SolverExecutionResponse` (`{ answer: 'OK', intent_hash }`) on success.
19
+ */
20
+ export function useLeverageYieldNotifySolver({
21
+ mutationOptions,
22
+ }: MutationHookParams<SolverExecutionResponse, UseLeverageYieldNotifySolverVars> = {}): SafeUseMutationResult<
23
+ SolverExecutionResponse,
24
+ Error,
25
+ UseLeverageYieldNotifySolverVars
26
+ > {
27
+ const { sodax } = useSodaxContext();
28
+
29
+ return useSafeMutation<SolverExecutionResponse, Error, UseLeverageYieldNotifySolverVars>({
30
+ mutationKey: ['leverageYield', 'notifySolver'],
31
+ ...mutationOptions,
32
+ mutationFn: async vars => unwrapResult(await sodax.leverageYield.notifySolver(vars)),
33
+ });
34
+ }
@@ -0,0 +1,40 @@
1
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
3
+ import type { Address, LeverageYieldPosition } from '@sodax/sdk';
4
+ import type { ReadHookParams } from '../shared/types.js';
5
+
6
+ export type UseLeverageYieldPositionParams = ReadHookParams<LeverageYieldPosition, { vault: Address | undefined }>;
7
+
8
+ /**
9
+ * Reads a leverage-yield vault's live position snapshot via the vault's `getPositionDetails`:
10
+ * collateral, debt, current LTV (drift vs `targetLTV`), health factor (∞ when no debt), and
11
+ * idle (not-yet-deployed) asset.
12
+ *
13
+ * LTV shifts with each rebalance/rate tick, so the default refresh (30s) is faster than the
14
+ * APR/stats reads.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const { data: position } = useLeverageYieldPosition({ params: { vault: vault.vault } });
19
+ * ```
20
+ */
21
+ export function useLeverageYieldPosition({
22
+ params,
23
+ queryOptions,
24
+ }: UseLeverageYieldPositionParams = {}): UseQueryResult<LeverageYieldPosition, Error> {
25
+ const { sodax } = useSodaxContext();
26
+ const vault = params?.vault;
27
+
28
+ return useQuery<LeverageYieldPosition, Error>({
29
+ queryKey: ['leverageYield', 'position', vault],
30
+ queryFn: async () => {
31
+ if (!vault) throw new Error('vault is required');
32
+ const result = await sodax.leverageYield.getPosition(vault);
33
+ if (!result.ok) throw result.error;
34
+ return result.value;
35
+ },
36
+ enabled: !!vault,
37
+ refetchInterval: 30_000,
38
+ ...queryOptions,
39
+ });
40
+ }
@@ -0,0 +1,43 @@
1
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
3
+ import type { Address } from '@sodax/sdk';
4
+ import type { ReadHookParams } from '../shared/types.js';
5
+
6
+ export type UseLeverageYieldPreviewRedeemParams = ReadHookParams<
7
+ bigint,
8
+ { vault: Address | undefined; shares: bigint | undefined }
9
+ >;
10
+
11
+ /**
12
+ * Reads the assets received for redeeming `shares` of a leverage-yield vault (ERC-4626
13
+ * `previewRedeem`). Passing `10n ** 18n` (one share) yields the per-share price that creeps
14
+ * up as the vault accrues interest. Moves slowly, so the default refresh is 60s.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const { data: sharePrice } = useLeverageYieldPreviewRedeem({
19
+ * params: { vault: vault.vault, shares: 10n ** 18n },
20
+ * });
21
+ * ```
22
+ */
23
+ export function useLeverageYieldPreviewRedeem({
24
+ params,
25
+ queryOptions,
26
+ }: UseLeverageYieldPreviewRedeemParams = {}): UseQueryResult<bigint, Error> {
27
+ const { sodax } = useSodaxContext();
28
+ const vault = params?.vault;
29
+ const shares = params?.shares;
30
+
31
+ return useQuery<bigint, Error>({
32
+ queryKey: ['leverageYield', 'previewRedeem', vault, shares?.toString()],
33
+ queryFn: async () => {
34
+ if (!vault || shares === undefined) throw new Error('vault and shares are required');
35
+ const result = await sodax.leverageYield.previewRedeem(vault, shares);
36
+ if (!result.ok) throw result.error;
37
+ return result.value;
38
+ },
39
+ enabled: !!vault && shares !== undefined,
40
+ refetchInterval: 60_000,
41
+ ...queryOptions,
42
+ });
43
+ }
@@ -0,0 +1,74 @@
1
+ import { useQueries, type UseQueryResult } from '@tanstack/react-query';
2
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
3
+ import type { Address, SpokeChainKey } from '@sodax/sdk';
4
+ import type { ReadHookParams } from '../shared/types.js';
5
+
6
+ /** A single `(chain, hub-wallet holder, share balance)` row produced by {@link useLeverageYieldShareBalances}. */
7
+ export type LeverageYieldShareHolding = {
8
+ chainKey: SpokeChainKey;
9
+ holder: Address;
10
+ shares: bigint;
11
+ };
12
+
13
+ /** A `(chainKey, EOA address)` pair the user controls — one per spoke chain they may hold shares under. */
14
+ export type LeverageYieldShareHolder = {
15
+ chainKey: SpokeChainKey;
16
+ address: string;
17
+ };
18
+
19
+ export type UseLeverageYieldShareBalancesParams = ReadHookParams<
20
+ LeverageYieldShareHolding,
21
+ { vault: Address | undefined; holders: readonly LeverageYieldShareHolder[] | undefined }
22
+ >;
23
+
24
+ /**
25
+ * Reads a user's leverage-vault share (`lsoda*`) balances across every chain they may hold a
26
+ * position under — one query per holder, fanned out via `useQueries`.
27
+ *
28
+ * For each `(chainKey, address)` the holder is resolved to the address that actually owns the
29
+ * shares: the user's **derived hub wallet** on every chain, including the hub itself. Leverage
30
+ * deposits always deliver `lsoda*` to `getUserHubWalletAddress(srcAddress, srcChainKey)` (the
31
+ * CREATE3 user-router on Sonic for a hub-sourced deposit, the per-spoke hub wallet otherwise) —
32
+ * never the bare EOA — so a hub-chain deposit's shares live in the router, not the signing EOA.
33
+ * Resolving the holder the same way the deposit does is what makes a Sonic-sourced position show
34
+ * up here instead of reading a stale zero off the EOA.
35
+ *
36
+ * Returns the raw `useQueries` result array (15s refresh per query); callers aggregate as needed
37
+ * (e.g. sum `shares` for a headline total, or pick the row for the active chain).
38
+ *
39
+ * `useQueries` has no top-level options slot, so `queryOptions` is spread into every individual
40
+ * query config (and applies uniformly to each holder's query).
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const balances = useLeverageYieldShareBalances({ params: { vault: vault.vault, holders } });
45
+ * const total = balances.reduce((acc, q) => acc + (q.data?.shares ?? 0n), 0n);
46
+ * ```
47
+ */
48
+ export function useLeverageYieldShareBalances({
49
+ params,
50
+ queryOptions,
51
+ }: UseLeverageYieldShareBalancesParams = {}): UseQueryResult<LeverageYieldShareHolding, Error>[] {
52
+ const { sodax } = useSodaxContext();
53
+ const vault = params?.vault;
54
+ const holders = params?.holders;
55
+
56
+ return useQueries({
57
+ queries: (holders ?? []).map(({ chainKey, address }) => ({
58
+ queryKey: ['leverageYield', 'shareBalance', vault, chainKey, address] as const,
59
+ refetchInterval: 15_000,
60
+ ...queryOptions,
61
+ enabled: !!vault,
62
+ queryFn: async (): Promise<LeverageYieldShareHolding> => {
63
+ if (!vault) throw new Error('vault is required');
64
+ // Always the derived hub wallet — on the hub chain too. A leverage deposit delivers
65
+ // shares to getUserHubWalletAddress(...), the CREATE3 router on Sonic, never the EOA,
66
+ // so reading balanceOf(EOA) for the hub chain would always come back zero.
67
+ const holder = await sodax.hubProvider.getUserHubWalletAddress(address, chainKey);
68
+ const result = await sodax.leverageYield.getShareBalance(vault, holder);
69
+ if (!result.ok) throw result.error;
70
+ return { chainKey, holder, shares: result.value };
71
+ },
72
+ })),
73
+ });
74
+ }
@@ -0,0 +1,36 @@
1
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
3
+ import type { Address } from '@sodax/sdk';
4
+ import type { ReadHookParams } from '../shared/types.js';
5
+
6
+ export type UseLeverageYieldTotalAssetsParams = ReadHookParams<bigint, { vault: Address | undefined }>;
7
+
8
+ /**
9
+ * Reads a leverage-yield vault's total underlying assets (vault-asset units, 18 decimals) —
10
+ * i.e. its TVL. Moves slowly, so the default refresh is 60s.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const { data: tvl } = useLeverageYieldTotalAssets({ params: { vault: vault.vault } });
15
+ * ```
16
+ */
17
+ export function useLeverageYieldTotalAssets({
18
+ params,
19
+ queryOptions,
20
+ }: UseLeverageYieldTotalAssetsParams = {}): UseQueryResult<bigint, Error> {
21
+ const { sodax } = useSodaxContext();
22
+ const vault = params?.vault;
23
+
24
+ return useQuery<bigint, Error>({
25
+ queryKey: ['leverageYield', 'totalAssets', vault],
26
+ queryFn: async () => {
27
+ if (!vault) throw new Error('vault is required');
28
+ const result = await sodax.leverageYield.getTotalAssets(vault);
29
+ if (!result.ok) throw result.error;
30
+ return result.value;
31
+ },
32
+ enabled: !!vault,
33
+ refetchInterval: 60_000,
34
+ ...queryOptions,
35
+ });
36
+ }
@@ -0,0 +1,50 @@
1
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
2
+ import type { SpokeChainKey, VaultSwapActionParams, VaultSwapResponse } from '@sodax/sdk';
3
+ import { useQueryClient } from '@tanstack/react-query';
4
+ import type { MutationHookParams } from '../shared/types.js';
5
+ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
6
+ import { unwrapResult } from '../shared/unwrapResult.js';
7
+
8
+ /**
9
+ * Mutation variables for {@link useLeverageYieldVaultSwap}. Generic over `K extends SpokeChainKey`
10
+ * (defaults to the full union). Sophisticated callers can lock K at the hook call site to narrow
11
+ * the `walletProvider` and `params.srcChainKey` types.
12
+ */
13
+ export type UseLeverageYieldVaultSwapVars<K extends SpokeChainKey = SpokeChainKey> = Omit<
14
+ VaultSwapActionParams<K, false>,
15
+ 'raw'
16
+ >;
17
+
18
+ /**
19
+ * React hook for executing an end-to-end leverage-yield vault swap (deposit or withdraw).
20
+ *
21
+ * Spread a `LeverageYieldSwapPayload` built by {@link useLeverageYieldDeposit} /
22
+ * {@link useLeverageYieldWithdraw} into `mutate` alongside the wallet provider:
23
+ * `vaultSwap({ ...payload, walletProvider })`. Runs `sodax.leverageYield.vaultSwap` —
24
+ * create intent → verify → relay → notify solver — so vault flows never touch the
25
+ * generic swap surface.
26
+ *
27
+ * Throws on SDK failure so React Query's native error model engages (`isError`, `error`,
28
+ * `onError`, `retry`). Returns the unwrapped `VaultSwapResponse` on success.
29
+ */
30
+ export function useLeverageYieldVaultSwap<K extends SpokeChainKey = SpokeChainKey>({
31
+ mutationOptions,
32
+ }: MutationHookParams<VaultSwapResponse, UseLeverageYieldVaultSwapVars<K>> = {}): SafeUseMutationResult<
33
+ VaultSwapResponse,
34
+ Error,
35
+ UseLeverageYieldVaultSwapVars<K>
36
+ > {
37
+ const { sodax } = useSodaxContext();
38
+ const queryClient = useQueryClient();
39
+
40
+ return useSafeMutation<VaultSwapResponse, Error, UseLeverageYieldVaultSwapVars<K>>({
41
+ mutationKey: ['leverageYield', 'vaultSwap'],
42
+ ...mutationOptions,
43
+ mutationFn: async vars => unwrapResult(await sodax.leverageYield.vaultSwap({ ...vars, raw: false })),
44
+ onSuccess: async (data, vars, ctx) => {
45
+ queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', vars.params.srcChainKey] });
46
+ queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', vars.params.dstChainKey] });
47
+ await mutationOptions?.onSuccess?.(data, vars, ctx);
48
+ },
49
+ });
50
+ }
@@ -0,0 +1,40 @@
1
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
2
+ import type { LeverageYieldSwapPayload, LeverageYieldSwapWithdrawParams } from '@sodax/sdk';
3
+ import type { MutationHookParams } from '../shared/types.js';
4
+ import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
5
+ import { unwrapResult } from '../shared/unwrapResult.js';
6
+
7
+ /** Mutation variables for {@link useLeverageYieldWithdraw} — the swap-style withdraw inputs. */
8
+ export type UseLeverageYieldWithdrawVars = LeverageYieldSwapWithdrawParams;
9
+
10
+ /**
11
+ * Builds the `LeverageYieldSwapPayload` for a leverage-yield withdraw (`lsoda*` shares → any token).
12
+ * The returned payload carries `hubWalletSwap: true`; spread it into
13
+ * {@link useLeverageYieldVaultSwap}, which authorises the hub wallet to spend the shares via a
14
+ * `Connection.sendMessage`.
15
+ *
16
+ * This is a builder, not an executor. Throws on SDK failure so React Query's error model engages;
17
+ * returns the unwrapped `LeverageYieldSwapPayload` on success.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const { mutateAsyncSafe: buildWithdraw } = useLeverageYieldWithdraw();
22
+ * const built = await buildWithdraw({ vault, srcChainKey, srcAddress, dstChainKey, outputToken, inputAmount, minOutputAmount });
23
+ * if (built.ok) vaultSwap({ ...built.value, walletProvider });
24
+ * ```
25
+ */
26
+ export function useLeverageYieldWithdraw({
27
+ mutationOptions,
28
+ }: MutationHookParams<LeverageYieldSwapPayload, UseLeverageYieldWithdrawVars> = {}): SafeUseMutationResult<
29
+ LeverageYieldSwapPayload,
30
+ Error,
31
+ UseLeverageYieldWithdrawVars
32
+ > {
33
+ const { sodax } = useSodaxContext();
34
+
35
+ return useSafeMutation<LeverageYieldSwapPayload, Error, UseLeverageYieldWithdrawVars>({
36
+ mutationKey: ['leverageYield', 'withdraw'],
37
+ ...mutationOptions,
38
+ mutationFn: async vars => unwrapResult(await sodax.leverageYield.withdraw(vars)),
39
+ });
40
+ }