@sodax/dapp-kit 2.1.0-rc.3 → 2.1.0-rc.5

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,6 @@
1
1
  import { UseMutationOptions, UseQueryOptions, UseMutationResult, MutateOptions, UseQueryResult, QueryClientConfig, QueryClient } from '@tanstack/react-query';
2
- import { Result, Sodax, SpokeChainKey, GetEstimateGasReturnType, EstimateGasParams, StellarChainKey, IStellarWalletProvider, INearWalletProvider, GetWalletProviderType, StellarAccountStatus, ActivateStellarAccountResult, IXServiceBase, XToken, EvmHubProvider, IBitcoinWalletProvider, RadfiWalletBalance, IWalletProvider, 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, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, GetSwapTokensResponseV2, RequestOverrideConfig, GetSwapTokensByChainResponseV2, QuoteResponseV2, QuoteRequestV2, QuoteQueryV2, DeadlineResponseV2, DeadlineQueryV2, AllowanceCheckResponseV2, CreateIntentParamsV2, ApproveResponseV2, CreateIntentResponseV2, SubmitIntentRequestV2, SubmitIntentResponseV2, StatusResponseV2, SwapIntentStatusCodeV2, CancelIntentRequestV2, CancelIntentResponseV2, IntentHashResponseV2, IntentRequestV2, IntentPacketResponseV2, IntentPacketRequestV2, IntentExtraDataResponseV2, IntentExtraDataRequestV2, IntentStateV2, GetIntentResponseV2, CreateLimitOrderParamsV2, CreateLimitOrderResponseV2, GasEstimateResponseV2, GasEstimateRequestV2, FeeResponseV2, SubmitTxRequestV2, SubmitTxResponseV2, SubmitTxStatusResponseV2, BridgeParams, CreateBridgeIntentParams, BridgeLimit, BridgeAllowanceCheckResponseV2, CreateBridgeIntentParamsV2, BridgeApproveResponseV2, BridgeableAmountResponseV2, BridgeQuoteRequestV2, CreateBridgeIntentResponseV2, BridgeFeeResponseV2, BridgeFeeRequestV2, BridgeableCheckResponseV2, BridgeSubmitTxRequestV2, BridgeSubmitTxResponseV2, BridgeSubmitTxStatusResponseV2, GetBridgeTokensResponseV2, GetBridgeTokensByChainResponseV2, StakeAction, StakeParams, UnstakeAction, ClaimAction, CancelUnstakeAction, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeAction, UnstakeParams, InstantUnstakeParams, PartnerFeeClaimAssetBalance, AutoSwapPreferences, FeeTokenApproveParams, FeeTokenApproveAction, HubChainKey, SetSwapPreferenceAction, PartnerFeeClaimSwapAction, IntentAutoSwapResult, PartnerFeeClaimCancelAction, GetUserIntentParams, 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, ActivateStellarAccountParams, StellarSponsorConfig, SodaxOptions } from '@sodax/sdk';
2
+ import * as _sodax_sdk from '@sodax/sdk';
3
+ import { Result, Sodax, SpokeChainKey, GetEstimateGasReturnType, EstimateGasParams, StellarChainKey, IStellarWalletProvider, INearWalletProvider, GetWalletProviderType, StellarAccountStatus, ActivateStellarAccountResult, IXServiceBase, XToken, EvmHubProvider, IBitcoinWalletProvider, RadfiWalletBalance, IWalletProvider, RadfiUtxo, MoneyMarketBorrowActionParams, TxHashPair, MoneyMarketRepayActionParams, MoneyMarketSupplyActionParams, MoneyMarketWithdrawActionParams, UserReserveData, AggregatedReserveData, BaseCurrencyInfo, ReservesDataHumanized, Address as Address$1, MoneyMarketParams, MoneyMarketApproveActionParams, TxReturnType, Erc20Token, ChainKey, ReserveDataHumanized, FormatReserveUSDResponse, FormatUserSummaryResponse, SolverIntentQuoteRequest, SwapActionParams, SwapResponse, SolverIntentStatusResponse, SolverErrorResponse, Hex, CreateIntentParams, CreateLimitOrderParams, Intent, LimitOrderActionParams, IntentResponse, UserIntentsResponse, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, GetSwapTokensResponseV2, RequestOverrideConfig, GetSwapTokensByChainResponseV2, QuoteResponseV2, QuoteRequestV2, QuoteQueryV2, DeadlineResponseV2, DeadlineQueryV2, AllowanceCheckResponseV2, CreateIntentParamsV2, ApproveResponseV2, CreateIntentResponseV2, SubmitIntentRequestV2, SubmitIntentResponseV2, StatusResponseV2, SwapIntentStatusCodeV2, CancelIntentRequestV2, CancelIntentResponseV2, IntentHashResponseV2, IntentRequestV2, IntentPacketResponseV2, IntentPacketRequestV2, IntentExtraDataResponseV2, IntentExtraDataRequestV2, IntentStateV2, GetIntentResponseV2, CreateLimitOrderParamsV2, CreateLimitOrderResponseV2, GasEstimateResponseV2, GasEstimateRequestV2, FeeResponseV2, SubmitTxRequestV2, SubmitTxResponseV2, SubmitTxStatusResponseV2, BridgeParams, CreateBridgeIntentParams, BridgeLimit, BridgeAllowanceCheckResponseV2, CreateBridgeIntentParamsV2, BridgeApproveResponseV2, BridgeableAmountResponseV2, BridgeQuoteRequestV2, CreateBridgeIntentResponseV2, BridgeFeeResponseV2, BridgeFeeRequestV2, BridgeableCheckResponseV2, BridgeSubmitTxRequestV2, BridgeSubmitTxResponseV2, BridgeSubmitTxStatusResponseV2, GetBridgeTokensResponseV2, GetBridgeTokensByChainResponseV2, StakeAction, StakeParams, UnstakeAction, ClaimAction, CancelUnstakeAction, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeAction, UnstakeParams, InstantUnstakeParams, PartnerFeeClaimAssetBalance, AutoSwapPreferences, FeeTokenApproveParams, FeeTokenApproveAction, HubChainKey, SetSwapPreferenceAction, PartnerFeeClaimSwapAction, IntentAutoSwapResult, PartnerFeeClaimCancelAction, GetUserIntentParams, 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, LeverageYieldQuoteParams, LeverageYieldEffectiveApr, LeverageYieldPosition, LeverageYieldSwapDepositParams, LeverageYieldSwapPayload, SolverExecutionRequest, SolverExecutionResponse, VaultSwapActionParams, VaultSwapResponse, LeverageYieldSwapWithdrawParams, ActivateStellarAccountParams, StellarSponsorConfig, SodaxOptions } from '@sodax/sdk';
3
4
  export * from '@sodax/sdk';
4
5
  import { Address } from 'viem';
5
6
  import { ReactNode, ReactElement } from 'react';
@@ -729,12 +730,43 @@ type UseUserFormattedSummaryParams = ReadHookParams<FormatUserSummaryResponse<Fo
729
730
  */
730
731
  declare function useUserFormattedSummary({ params, queryOptions, }?: UseUserFormattedSummaryParams): UseQueryResult<FormatUserSummaryResponse<FormatReserveUSDResponse>, Error>;
731
732
 
732
- type UseQuoteParams = ReadHookParams<Result<SolverIntentQuoteResponse, SolverErrorResponse> | undefined, {
733
+ /**
734
+ * Derived from the SDK method rather than restated, so the error union stays exact and cannot
735
+ * drift. `undefined` is the disabled state, before a `payload` exists.
736
+ */
737
+ type SwapQuote = Awaited<ReturnType<Sodax['swaps']['getQuote']>> | undefined;
738
+ type UseQuoteParams = ReadHookParams<SwapQuote, {
733
739
  payload: SolverIntentQuoteRequest | undefined;
734
740
  }>;
741
+ type SwapQuoteReader = {
742
+ swaps: Pick<Sodax['swaps'], 'getQuote' | 'partnerFee'>;
743
+ };
744
+ declare function getSwapQuoteQueryOptions({ sodax, payload, }: {
745
+ sodax: SwapQuoteReader;
746
+ payload: SolverIntentQuoteRequest | undefined;
747
+ }): {
748
+ queryKey: (string | {
749
+ token_src: string;
750
+ token_src_blockchain_id: "0xa86a.avax" | "0xa4b1.arbitrum" | "0x2105.base" | "0x38.bsc" | "injective-1" | "sonic" | "0x1.icon" | "sui" | "0xa.optimism" | "0x89.polygon" | "solana" | "stellar" | "hyper" | "lightlink" | "near" | "ethereum" | "bitcoin" | "redbelly" | "0x2019.kaia" | "stacks" | "hedera";
751
+ token_dst: string;
752
+ token_dst_blockchain_id: "0xa86a.avax" | "0xa4b1.arbitrum" | "0x2105.base" | "0x38.bsc" | "injective-1" | "sonic" | "0x1.icon" | "sui" | "0xa.optimism" | "0x89.polygon" | "solana" | "stellar" | "hyper" | "lightlink" | "near" | "ethereum" | "bitcoin" | "redbelly" | "0x2019.kaia" | "stacks" | "hedera";
753
+ amount: string;
754
+ quote_type: "exact_input";
755
+ partnerFee: _sodax_sdk.PartnerFeePercentage | {
756
+ amount: string;
757
+ address: _sodax_sdk.Address;
758
+ } | undefined;
759
+ } | undefined)[];
760
+ queryFn: () => Promise<SwapQuote>;
761
+ enabled: boolean;
762
+ refetchInterval: number;
763
+ };
735
764
  /**
736
765
  * Hook for fetching a quote for an intent-based swap.
737
766
  *
767
+ * For a leverage-yield vault deposit or withdraw use `useLeverageYieldQuote` instead — this hook
768
+ * deducts the effective *swap* fee, which is not what a vault intent charges.
769
+ *
738
770
  * @example
739
771
  * ```typescript
740
772
  * const { data: quote, isLoading } = useQuote({ params: { payload } });
@@ -743,8 +775,9 @@ type UseQuoteParams = ReadHookParams<Result<SolverIntentQuoteResponse, SolverErr
743
775
  * @remarks
744
776
  * - The quote is automatically refreshed every 3 seconds
745
777
  * - The query is disabled when payload is undefined
778
+ * - Returns the SDK `Result` as `data`; branch on `data?.ok` rather than reading `isError`
746
779
  */
747
- declare const useQuote: ({ params, queryOptions, }?: UseQuoteParams) => UseQueryResult<Result<SolverIntentQuoteResponse, SolverErrorResponse> | undefined>;
780
+ declare const useQuote: ({ params, queryOptions }?: UseQuoteParams) => UseQueryResult<SwapQuote>;
748
781
 
749
782
  /**
750
783
  * Mutation variables for {@link useSwap}. Generic over `K extends SpokeChainKey` (defaults to the
@@ -1013,6 +1046,7 @@ type UseSwapsApiQuoteParams = ReadHookParams<QuoteResponseV2 | undefined, {
1013
1046
  * tokenSrc: '0x...', tokenSrcChainKey: '0xa4b1.arbitrum',
1014
1047
  * tokenDst: '0x...', tokenDstChainKey: 'sonic',
1015
1048
  * amount: '1000000', quoteType: 'exact_input',
1049
+ * partnerFee: { address: '0xSonicFeeReceiver', percentage: 10 },
1016
1050
  * },
1017
1051
  * },
1018
1052
  * });
@@ -2306,6 +2340,78 @@ type UseClaimRewardsVars<K extends SpokeChainKey = SpokeChainKey> = Omit<ClLiqui
2306
2340
  */
2307
2341
  declare function useClaimRewards<K extends SpokeChainKey = SpokeChainKey>({ mutationOptions, }?: MutationHookParams<TxHashPair, UseClaimRewardsVars<K>>): SafeUseMutationResult<TxHashPair, Error, UseClaimRewardsVars<K>>;
2308
2342
 
2343
+ /**
2344
+ * Derived from the SDK method rather than restated, so the public error union
2345
+ * (`SolverErrorResponse | LeverageYieldLookupError`) stays exact and cannot drift.
2346
+ * `undefined` is the disabled state, before a `payload` exists.
2347
+ */
2348
+ type LeverageYieldQuote = Awaited<ReturnType<Sodax['leverageYield']['getQuote']>> | undefined;
2349
+ type UseLeverageYieldQuoteParams = ReadHookParams<LeverageYieldQuote, {
2350
+ payload: LeverageYieldQuoteParams | undefined;
2351
+ }>;
2352
+ type LeverageYieldQuoteReader = {
2353
+ config: Pick<Sodax['config'], 'leverageYieldPartnerFee'>;
2354
+ leverageYield: Pick<Sodax['leverageYield'], 'getQuote'>;
2355
+ };
2356
+ declare function getLeverageYieldQuoteQueryOptions({ sodax, payload, }: {
2357
+ sodax: LeverageYieldQuoteReader;
2358
+ payload: LeverageYieldQuoteParams | undefined;
2359
+ }): {
2360
+ queryKey: (string | {
2361
+ token_src: string;
2362
+ token_src_blockchain_id: "0xa86a.avax" | "0xa4b1.arbitrum" | "0x2105.base" | "0x38.bsc" | "injective-1" | "sonic" | "0x1.icon" | "sui" | "0xa.optimism" | "0x89.polygon" | "solana" | "stellar" | "hyper" | "lightlink" | "near" | "ethereum" | "bitcoin" | "redbelly" | "0x2019.kaia" | "stacks" | "hedera";
2363
+ token_dst: string;
2364
+ token_dst_blockchain_id: "0xa86a.avax" | "0xa4b1.arbitrum" | "0x2105.base" | "0x38.bsc" | "injective-1" | "sonic" | "0x1.icon" | "sui" | "0xa.optimism" | "0x89.polygon" | "solana" | "stellar" | "hyper" | "lightlink" | "near" | "ethereum" | "bitcoin" | "redbelly" | "0x2019.kaia" | "stacks" | "hedera";
2365
+ amount: string;
2366
+ quote_type: "exact_input";
2367
+ partnerFee: _sodax_sdk.PartnerFeePercentage | {
2368
+ amount: string;
2369
+ address: _sodax_sdk.Address;
2370
+ } | undefined;
2371
+ } | undefined)[];
2372
+ queryFn: () => Promise<LeverageYieldQuote>;
2373
+ enabled: boolean;
2374
+ refetchInterval: number;
2375
+ };
2376
+ /**
2377
+ * Quotes a leverage-yield vault deposit or withdraw. Pass the vault address as `token_dst` to
2378
+ * quote a deposit, or as `token_src` to quote a withdraw; subtract your slippage tolerance from
2379
+ * `quoted_amount` to size `minOutputAmount`.
2380
+ *
2381
+ * Use this rather than {@link useQuote}: the swap quote deducts the effective *swap* fee, while a
2382
+ * vault intent charges the effective *leverage-yield* fee, so the two disagree whenever the feature
2383
+ * fees differ. When overriding the fee per intent, pass the same `partnerFee` here and to whichever
2384
+ * builder you use — `useLeverageYieldDeposit`, `useLeverageYieldWithdraw`, or
2385
+ * `useLeverageYieldVaultSwap` — or omit it on all of them, which resolves the same configured fee on
2386
+ * each side. Both directions are charged, so this applies to withdrawals as much as deposits.
2387
+ *
2388
+ * Returns the SDK `Result` as query data rather than unwrapping it, matching {@link useQuote}: a
2389
+ * quote failure ("no path", thin liquidity) is an expected UI branch, and keeping the `Result`
2390
+ * preserves the solver's `detail.code` instead of flattening it to an error message.
2391
+ *
2392
+ * @example
2393
+ * ```typescript
2394
+ * const { data: quote } = useLeverageYieldQuote({
2395
+ * params: {
2396
+ * payload: {
2397
+ * token_src: inputToken,
2398
+ * token_src_blockchain_id: ChainKeys.ARBITRUM_MAINNET,
2399
+ * token_dst: vault.vault,
2400
+ * token_dst_blockchain_id: ChainKeys.SONIC_MAINNET,
2401
+ * amount: parseUnits('1', 18),
2402
+ * quote_type: 'exact_input',
2403
+ * },
2404
+ * },
2405
+ * });
2406
+ * if (quote?.ok) setMinOutput((quote.value.quoted_amount * 9_950n) / 10_000n);
2407
+ * ```
2408
+ *
2409
+ * @remarks
2410
+ * - Refreshes every 3 seconds, like `useQuote` — solver prices go stale.
2411
+ * - Disabled while `payload` is undefined.
2412
+ */
2413
+ declare function useLeverageYieldQuote({ params, queryOptions, }?: UseLeverageYieldQuoteParams): UseQueryResult<LeverageYieldQuote, Error>;
2414
+
2309
2415
  type UseLeverageYieldEffectiveAprParams = ReadHookParams<LeverageYieldEffectiveApr, {
2310
2416
  vault: Address$1 | undefined;
2311
2417
  }>;
@@ -2652,4 +2758,4 @@ interface NearStorageGateState {
2652
2758
  */
2653
2759
  declare function resolveNearStorageGate(chainKey: SpokeChainKey, check: NearStorageCheckResult): NearStorageGateState;
2654
2760
 
2655
- export { type ATokenData, type BackendPaginationParams, type BitcoinTradingSetup, 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 StellarCheckResult, type StellarGate, type StellarGateInputs, type StellarGateState, type SwapsApiApprovalHashes, type UseATokenParams, type UseATokensBalancesParams, type UseActivateStellarAccountVars, type UseApproveTokenVars, type UseBitcoinBalanceParams, type UseBitcoinTradingSetupParams, type UseBorrowVars, type UseBridgeAllowanceParams, type UseBridgeApiAllowanceParams, type UseBridgeApiApproveVars, type UseBridgeApiBridgeableAmountParams, type UseBridgeApiCreateBridgeIntentVars, type UseBridgeApiFeeParams, type UseBridgeApiIsBridgeableParams, type UseBridgeApiSubmitTxStatusParams, type UseBridgeApiSubmitTxVars, type UseBridgeApiTokensByChainParams, type UseBridgeApiTokensParams, 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 UseEstablishTrustlineVars, type UseExpiredUtxosParams, type UseFeeClaimSwapVars, type UseFeeClaimWithdrawVars, type UseFetchAssetsBalancesParams, type UseFundTradingWalletVars, type UseGetAutoSwapPreferencesParams, type UseGetBridgeableAmountParams, type UseGetBridgeableTokensParams, type UseGetIntentDetailsParams, type UseGetUserHubWalletAddressParams, type UseGetUserIntentParams, 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 UsePartnerCancelIntentVars, 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 UseSponsorConfigParams, type UseStatusParams, type UseStellarAccountActiveParams, type UseStellarAccountStatusParams, type UseStellarGateParams, type UseStellarTrustlineCheckParams, type UseSupplyLiquidityVars, type UseSupplyVars, type UseSwapAllowanceParams, type UseSwapApproveVars, type UseSwapVars, type UseSwapsApiAllowanceParams, type UseSwapsApiApproveAndBroadcastVars, type UseSwapsApiApproveVars, type UseSwapsApiCancelIntentVars, type UseSwapsApiCreateIntentVars, type UseSwapsApiCreateLimitOrderVars, type UseSwapsApiDeadlineParams, type UseSwapsApiEstimateGasParams, type UseSwapsApiFilledIntentParams, type UseSwapsApiIntentExtraDataParams, type UseSwapsApiIntentHashParams, type UseSwapsApiIntentPacketParams, type UseSwapsApiIntentParams, type UseSwapsApiPartnerFeeParams, type UseSwapsApiQuoteParams, type UseSwapsApiSolverFeeParams, type UseSwapsApiStatusParams, type UseSwapsApiSubmitIntentVars, type UseSwapsApiSubmitTxStatusParams, type UseSwapsApiSubmitTxVars, type UseSwapsApiTokensByChainParams, type UseSwapsApiTokensParams, type UseTradingWalletBalanceParams, type UseUserFormattedSummaryParams, type UseUserReservesDataParams, type UseWithdrawHubAssetVars, type UseWithdrawVars, type UseXBalancesParams, type WithdrawParamsCore, type XBalancesInputs, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getSponsorConfigQueryOptions, getStellarAccountActiveQueryOptions, getStellarAccountStatusQueryOptions, getStellarTrustlineCheckQueryOptions, getXBalancesQueryOptions, isTerminalSwapIntentStatus, isUserRejectedError, loadRadfiSession, resolveNearStorageGate, resolveStellarGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useActivateStellarAccount, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApiAllowance, useBridgeApiApprove, useBridgeApiBridgeableAmount, useBridgeApiCreateBridgeIntent, useBridgeApiFee, useBridgeApiIsBridgeable, useBridgeApiSubmitTx, useBridgeApiSubmitTxStatus, useBridgeApiTokens, useBridgeApiTokensByChain, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstablishTrustline, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useSponsorConfig, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarAccountActive, useStellarAccountStatus, useStellarGate, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiApproveAndBroadcast, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
2761
+ export { type ATokenData, type BackendPaginationParams, type BitcoinTradingSetup, 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 StellarCheckResult, type StellarGate, type StellarGateInputs, type StellarGateState, type SwapsApiApprovalHashes, type UseATokenParams, type UseATokensBalancesParams, type UseActivateStellarAccountVars, type UseApproveTokenVars, type UseBitcoinBalanceParams, type UseBitcoinTradingSetupParams, type UseBorrowVars, type UseBridgeAllowanceParams, type UseBridgeApiAllowanceParams, type UseBridgeApiApproveVars, type UseBridgeApiBridgeableAmountParams, type UseBridgeApiCreateBridgeIntentVars, type UseBridgeApiFeeParams, type UseBridgeApiIsBridgeableParams, type UseBridgeApiSubmitTxStatusParams, type UseBridgeApiSubmitTxVars, type UseBridgeApiTokensByChainParams, type UseBridgeApiTokensParams, 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 UseEstablishTrustlineVars, type UseExpiredUtxosParams, type UseFeeClaimSwapVars, type UseFeeClaimWithdrawVars, type UseFetchAssetsBalancesParams, type UseFundTradingWalletVars, type UseGetAutoSwapPreferencesParams, type UseGetBridgeableAmountParams, type UseGetBridgeableTokensParams, type UseGetIntentDetailsParams, type UseGetUserHubWalletAddressParams, type UseGetUserIntentParams, type UseHubAssetBalancesParams, type UseIsTokenApprovedParams, type UseLeverageYieldDepositVars, type UseLeverageYieldEffectiveAprParams, type UseLeverageYieldNotifySolverVars, type UseLeverageYieldPositionParams, type UseLeverageYieldPreviewRedeemParams, type UseLeverageYieldQuoteParams, 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 UsePartnerCancelIntentVars, 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 UseSponsorConfigParams, type UseStatusParams, type UseStellarAccountActiveParams, type UseStellarAccountStatusParams, type UseStellarGateParams, type UseStellarTrustlineCheckParams, type UseSupplyLiquidityVars, type UseSupplyVars, type UseSwapAllowanceParams, type UseSwapApproveVars, type UseSwapVars, type UseSwapsApiAllowanceParams, type UseSwapsApiApproveAndBroadcastVars, type UseSwapsApiApproveVars, type UseSwapsApiCancelIntentVars, type UseSwapsApiCreateIntentVars, type UseSwapsApiCreateLimitOrderVars, type UseSwapsApiDeadlineParams, type UseSwapsApiEstimateGasParams, type UseSwapsApiFilledIntentParams, type UseSwapsApiIntentExtraDataParams, type UseSwapsApiIntentHashParams, type UseSwapsApiIntentPacketParams, type UseSwapsApiIntentParams, type UseSwapsApiPartnerFeeParams, type UseSwapsApiQuoteParams, type UseSwapsApiSolverFeeParams, type UseSwapsApiStatusParams, type UseSwapsApiSubmitIntentVars, type UseSwapsApiSubmitTxStatusParams, type UseSwapsApiSubmitTxVars, type UseSwapsApiTokensByChainParams, type UseSwapsApiTokensParams, type UseTradingWalletBalanceParams, type UseUserFormattedSummaryParams, type UseUserReservesDataParams, type UseWithdrawHubAssetVars, type UseWithdrawVars, type UseXBalancesParams, type WithdrawParamsCore, type XBalancesInputs, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getLeverageYieldQuoteQueryOptions, getSponsorConfigQueryOptions, getStellarAccountActiveQueryOptions, getStellarAccountStatusQueryOptions, getStellarTrustlineCheckQueryOptions, getSwapQuoteQueryOptions, getXBalancesQueryOptions, isTerminalSwapIntentStatus, isUserRejectedError, loadRadfiSession, resolveNearStorageGate, resolveStellarGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useActivateStellarAccount, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApiAllowance, useBridgeApiApprove, useBridgeApiBridgeableAmount, useBridgeApiCreateBridgeIntent, useBridgeApiFee, useBridgeApiIsBridgeable, useBridgeApiSubmitTx, useBridgeApiSubmitTxStatus, useBridgeApiTokens, useBridgeApiTokensByChain, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstablishTrustline, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldQuote, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useSponsorConfig, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarAccountActive, useStellarAccountStatus, useStellarGate, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiApproveAndBroadcast, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
package/dist/index.mjs CHANGED
@@ -1052,14 +1052,28 @@ function useUserFormattedSummary({
1052
1052
  ...queryOptions
1053
1053
  });
1054
1054
  }
1055
- var useQuote = ({
1056
- params,
1057
- queryOptions
1058
- } = {}) => {
1059
- const { sodax } = useSodaxContext();
1060
- const payload = params?.payload;
1061
- return useQuery({
1062
- queryKey: ["swap", "quote", payload && { ...payload, amount: payload.amount.toString() }],
1055
+ function feeKeyPart(fee) {
1056
+ if (!fee) return void 0;
1057
+ return "amount" in fee ? { ...fee, amount: fee.amount.toString() } : fee;
1058
+ }
1059
+ function quoteKeyPart(payload, configuredFee) {
1060
+ if (!payload) return void 0;
1061
+ return {
1062
+ token_src: payload.token_src,
1063
+ token_src_blockchain_id: payload.token_src_blockchain_id,
1064
+ token_dst: payload.token_dst,
1065
+ token_dst_blockchain_id: payload.token_dst_blockchain_id,
1066
+ amount: String(payload.amount),
1067
+ quote_type: payload.quote_type,
1068
+ partnerFee: feeKeyPart(configuredFee)
1069
+ };
1070
+ }
1071
+ function getSwapQuoteQueryOptions({
1072
+ sodax,
1073
+ payload
1074
+ }) {
1075
+ return {
1076
+ queryKey: ["swap", "quote", quoteKeyPart(payload, sodax.swaps.partnerFee)],
1063
1077
  queryFn: async () => {
1064
1078
  if (!payload) {
1065
1079
  return void 0;
@@ -1067,7 +1081,13 @@ var useQuote = ({
1067
1081
  return sodax.swaps.getQuote(payload);
1068
1082
  },
1069
1083
  enabled: !!payload,
1070
- refetchInterval: 3e3,
1084
+ refetchInterval: 3e3
1085
+ };
1086
+ }
1087
+ var useQuote = ({ params, queryOptions } = {}) => {
1088
+ const { sodax } = useSodaxContext();
1089
+ return useQuery({
1090
+ ...getSwapQuoteQueryOptions({ sodax, payload: params?.payload }),
1071
1091
  ...queryOptions
1072
1092
  });
1073
1093
  };
@@ -3407,6 +3427,47 @@ function useClaimRewards({
3407
3427
  }
3408
3428
  });
3409
3429
  }
3430
+ function feeKeyPart2(fee) {
3431
+ if (!fee) return void 0;
3432
+ return "amount" in fee ? { ...fee, amount: fee.amount.toString() } : fee;
3433
+ }
3434
+ function quoteKeyPart2(payload, effectiveFee) {
3435
+ if (!payload) return void 0;
3436
+ return {
3437
+ token_src: payload.token_src,
3438
+ token_src_blockchain_id: payload.token_src_blockchain_id,
3439
+ token_dst: payload.token_dst,
3440
+ token_dst_blockchain_id: payload.token_dst_blockchain_id,
3441
+ amount: String(payload.amount),
3442
+ quote_type: payload.quote_type,
3443
+ partnerFee: feeKeyPart2(effectiveFee)
3444
+ };
3445
+ }
3446
+ function getLeverageYieldQuoteQueryOptions({
3447
+ sodax,
3448
+ payload
3449
+ }) {
3450
+ const effectiveFee = payload?.partnerFee ?? sodax.config.leverageYieldPartnerFee;
3451
+ return {
3452
+ queryKey: ["leverageYield", "quote", quoteKeyPart2(payload, effectiveFee)],
3453
+ queryFn: async () => {
3454
+ if (!payload) return void 0;
3455
+ return sodax.leverageYield.getQuote(payload);
3456
+ },
3457
+ enabled: !!payload,
3458
+ refetchInterval: 3e3
3459
+ };
3460
+ }
3461
+ function useLeverageYieldQuote({
3462
+ params,
3463
+ queryOptions
3464
+ } = {}) {
3465
+ const { sodax } = useSodaxContext();
3466
+ return useQuery({
3467
+ ...getLeverageYieldQuoteQueryOptions({ sodax, payload: params?.payload }),
3468
+ ...queryOptions
3469
+ });
3470
+ }
3410
3471
  function useLeverageYieldEffectiveApr({
3411
3472
  params,
3412
3473
  queryOptions
@@ -3635,4 +3696,4 @@ function createSodaxQueryClient({
3635
3696
  });
3636
3697
  }
3637
3698
 
3638
- export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getSponsorConfigQueryOptions, getStellarAccountActiveQueryOptions, getStellarAccountStatusQueryOptions, getStellarTrustlineCheckQueryOptions, getXBalancesQueryOptions, isTerminalSwapIntentStatus, isUserRejectedError, loadRadfiSession, resolveNearStorageGate, resolveStellarGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useActivateStellarAccount, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApiAllowance, useBridgeApiApprove, useBridgeApiBridgeableAmount, useBridgeApiCreateBridgeIntent, useBridgeApiFee, useBridgeApiIsBridgeable, useBridgeApiSubmitTx, useBridgeApiSubmitTxStatus, useBridgeApiTokens, useBridgeApiTokensByChain, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstablishTrustline, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useSponsorConfig, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarAccountActive, useStellarAccountStatus, useStellarGate, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiApproveAndBroadcast, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
3699
+ export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getLeverageYieldQuoteQueryOptions, getSponsorConfigQueryOptions, getStellarAccountActiveQueryOptions, getStellarAccountStatusQueryOptions, getStellarTrustlineCheckQueryOptions, getSwapQuoteQueryOptions, getXBalancesQueryOptions, isTerminalSwapIntentStatus, isUserRejectedError, loadRadfiSession, resolveNearStorageGate, resolveStellarGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useActivateStellarAccount, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApiAllowance, useBridgeApiApprove, useBridgeApiBridgeableAmount, useBridgeApiCreateBridgeIntent, useBridgeApiFee, useBridgeApiIsBridgeable, useBridgeApiSubmitTx, useBridgeApiSubmitTxStatus, useBridgeApiTokens, useBridgeApiTokensByChain, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstablishTrustline, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldQuote, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useSponsorConfig, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarAccountActive, useStellarAccountStatus, useStellarGate, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiApproveAndBroadcast, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "access": "public"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "2.1.0-rc.3",
8
+ "version": "2.1.0-rc.5",
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.1.0-rc.3"
37
+ "@sodax/sdk": "2.1.0-rc.5"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@arethetypeswrong/cli": "0.17.4",
@@ -1,3 +1,4 @@
1
+ export * from './useLeverageYieldQuote.js';
1
2
  export * from './useLeverageYieldEffectiveApr.js';
2
3
  export * from './useLeverageYieldPosition.js';
3
4
  export * from './useLeverageYieldTotalAssets.js';
@@ -0,0 +1,175 @@
1
+ import {
2
+ ChainKeys,
3
+ type LeverageYieldQuoteParams,
4
+ type PartnerFee,
5
+ type Sodax,
6
+ SolverIntentErrorCode,
7
+ } from '@sodax/sdk';
8
+ import { hashKey } from '@tanstack/react-query';
9
+ import { describe, expect, it, vi } from 'vitest';
10
+ import { getLeverageYieldQuoteQueryOptions } from './useLeverageYieldQuote.js';
11
+
12
+ const VAULT = '0xD09de2f5070699A909c0FD32fb5A909d3886701D';
13
+ const INPUT_TOKEN = '0x35751007a407ca6FEFfE80b3cB397736D2cf4dbe';
14
+ const FEE_RECIPIENT = '0x4444444444444444444444444444444444444444' as const;
15
+
16
+ const PAYLOAD: LeverageYieldQuoteParams = {
17
+ token_src: INPUT_TOKEN,
18
+ token_src_blockchain_id: ChainKeys.ARBITRUM_MAINNET,
19
+ token_dst: VAULT,
20
+ token_dst_blockchain_id: ChainKeys.SONIC_MAINNET,
21
+ amount: 1_000_000n,
22
+ quote_type: 'exact_input',
23
+ };
24
+
25
+ /** The SDK's own quote Result, derived so the doubles stay honest without an unsafe cast. */
26
+ type QuoteResult = Awaited<ReturnType<Sodax['leverageYield']['getQuote']>>;
27
+
28
+ const QUOTE: QuoteResult = { ok: true, value: { quoted_amount: 990_000n } };
29
+
30
+ const makeSodax = (result: QuoteResult = QUOTE, leverageYieldPartnerFee?: PartnerFee) => {
31
+ const getQuote = vi.fn(async () => result);
32
+ return { sodax: { config: { leverageYieldPartnerFee }, leverageYield: { getQuote } }, getQuote };
33
+ };
34
+
35
+ describe('getLeverageYieldQuoteQueryOptions', () => {
36
+ it('keys on the leverageYield feature and the quote action', () => {
37
+ const { sodax } = makeSodax();
38
+ const { queryKey } = getLeverageYieldQuoteQueryOptions({ sodax, payload: PAYLOAD });
39
+ expect(queryKey[0]).toBe('leverageYield');
40
+ expect(queryKey[1]).toBe('quote');
41
+ });
42
+
43
+ it('returns the SDK Result unwrapped-free so callers can branch on `ok`', async () => {
44
+ const { sodax, getQuote } = makeSodax();
45
+ await expect(getLeverageYieldQuoteQueryOptions({ sodax, payload: PAYLOAD }).queryFn()).resolves.toEqual(QUOTE);
46
+ expect(getQuote).toHaveBeenCalledWith(PAYLOAD);
47
+ });
48
+
49
+ it('passes a solver failure through as data rather than throwing', async () => {
50
+ const error = { detail: { code: SolverIntentErrorCode.NO_PATH_FOUND, message: 'no path' } };
51
+ const { sodax } = makeSodax({ ok: false, error });
52
+ await expect(getLeverageYieldQuoteQueryOptions({ sodax, payload: PAYLOAD }).queryFn()).resolves.toEqual({
53
+ ok: false,
54
+ error,
55
+ });
56
+ });
57
+
58
+ it('is disabled and resolves undefined without calling the SDK when payload is undefined', async () => {
59
+ const { sodax, getQuote } = makeSodax();
60
+ const options = getLeverageYieldQuoteQueryOptions({ sodax, payload: undefined });
61
+ expect(options.enabled).toBe(false);
62
+ await expect(options.queryFn()).resolves.toBeUndefined();
63
+ expect(getQuote).not.toHaveBeenCalled();
64
+ });
65
+
66
+ // React Query hashes keys with JSON.stringify, which throws on bigint. Both bigint sites
67
+ // (`amount` and a fixed-amount `partnerFee`) must be stringified or every render crashes.
68
+ it('produces a hashable key for a percentage partner fee', () => {
69
+ const partnerFee = { address: FEE_RECIPIENT, percentage: 100 } satisfies PartnerFee;
70
+ const { sodax } = makeSodax();
71
+ const { queryKey } = getLeverageYieldQuoteQueryOptions({ sodax, payload: { ...PAYLOAD, partnerFee } });
72
+ expect(() => hashKey(queryKey)).not.toThrow();
73
+ });
74
+
75
+ it('produces a hashable key for a fixed-amount (bigint) partner fee', () => {
76
+ const partnerFee = { address: FEE_RECIPIENT, amount: 5_000n } satisfies PartnerFee;
77
+ const { sodax } = makeSodax();
78
+ const { queryKey } = getLeverageYieldQuoteQueryOptions({ sodax, payload: { ...PAYLOAD, partnerFee } });
79
+ expect(() => hashKey(queryKey)).not.toThrow();
80
+ expect(hashKey(queryKey)).toContain('5000');
81
+ });
82
+
83
+ it('keys two quotes that differ only by partner fee separately', () => {
84
+ const { sodax } = makeSodax();
85
+ const base = getLeverageYieldQuoteQueryOptions({ sodax, payload: PAYLOAD }).queryKey;
86
+ const withFee = getLeverageYieldQuoteQueryOptions({
87
+ sodax,
88
+ payload: { ...PAYLOAD, partnerFee: { address: FEE_RECIPIENT, percentage: 100 } },
89
+ }).queryKey;
90
+ // Sharing a cache entry would serve a quote priced on a different net input.
91
+ expect(hashKey(base)).not.toBe(hashKey(withFee));
92
+ });
93
+
94
+ it('keys the amount as a string so it survives hashing', () => {
95
+ const { sodax } = makeSodax();
96
+ const { queryKey } = getLeverageYieldQuoteQueryOptions({ sodax, payload: PAYLOAD });
97
+ expect(hashKey(queryKey)).toContain('"amount":"1000000"');
98
+ });
99
+
100
+ // The configured fee is a real input to the quote whenever payload.partnerFee is omitted, so it
101
+ // has to participate in the key — otherwise differently-configured providers share a cache entry
102
+ // and a reconfigured provider serves the previous fee's quote.
103
+ it('keys the configured leverageYield fee when the payload omits partnerFee', () => {
104
+ const noFee = getLeverageYieldQuoteQueryOptions({ sodax: makeSodax().sodax, payload: PAYLOAD }).queryKey;
105
+ const withConfigFee = getLeverageYieldQuoteQueryOptions({
106
+ sodax: makeSodax(QUOTE, { address: FEE_RECIPIENT, percentage: 100 }).sodax,
107
+ payload: PAYLOAD,
108
+ }).queryKey;
109
+
110
+ expect(hashKey(noFee)).not.toBe(hashKey(withConfigFee));
111
+ });
112
+
113
+ it('keys two differently-configured providers apart for an identical payload', () => {
114
+ const a = getLeverageYieldQuoteQueryOptions({
115
+ sodax: makeSodax(QUOTE, { address: FEE_RECIPIENT, percentage: 100 }).sodax,
116
+ payload: PAYLOAD,
117
+ }).queryKey;
118
+ const b = getLeverageYieldQuoteQueryOptions({
119
+ sodax: makeSodax(QUOTE, { address: FEE_RECIPIENT, percentage: 25 }).sodax,
120
+ payload: PAYLOAD,
121
+ }).queryKey;
122
+
123
+ expect(hashKey(a)).not.toBe(hashKey(b));
124
+ });
125
+
126
+ it('keys a bigint configured fee without throwing', () => {
127
+ const { sodax } = makeSodax(QUOTE, { address: FEE_RECIPIENT, amount: 7_000n });
128
+ const { queryKey } = getLeverageYieldQuoteQueryOptions({ sodax, payload: PAYLOAD });
129
+ expect(() => hashKey(queryKey)).not.toThrow();
130
+ expect(hashKey(queryKey)).toContain('7000');
131
+ });
132
+
133
+ // Pins the allow-list. If `LeverageYieldQuoteParams` gains a field, this fails and forces a
134
+ // decision about whether it belongs in the key — rather than a spread silently carrying a new
135
+ // bigint in and crashing `hashKey` at render time.
136
+ it('keys exactly the known request fields', () => {
137
+ const { sodax } = makeSodax();
138
+ const { queryKey } = getLeverageYieldQuoteQueryOptions({ sodax, payload: PAYLOAD });
139
+
140
+ expect(Object.keys(queryKey[2] as object).sort()).toEqual(
141
+ [
142
+ 'amount',
143
+ 'partnerFee',
144
+ 'quote_type',
145
+ 'token_dst',
146
+ 'token_dst_blockchain_id',
147
+ 'token_src',
148
+ 'token_src_blockchain_id',
149
+ ].sort(),
150
+ );
151
+ });
152
+
153
+ // Key derivation runs during render, so it must not throw on a payload assembled from
154
+ // partially-validated form state — the SDK's own validation reports that as a Result.
155
+ it('derives a hashable key even when amount is missing', () => {
156
+ const { sodax } = makeSodax();
157
+ const malformed = { ...PAYLOAD, amount: undefined } as unknown as LeverageYieldQuoteParams;
158
+
159
+ const { queryKey } = getLeverageYieldQuoteQueryOptions({ sodax, payload: malformed });
160
+
161
+ expect(() => hashKey(queryKey)).not.toThrow();
162
+ expect(hashKey(queryKey)).toContain('"amount":"undefined"');
163
+ });
164
+
165
+ it('lets an explicit payload partnerFee win over the configured fee in the key', () => {
166
+ const explicitFee = { address: FEE_RECIPIENT, percentage: 10 } satisfies PartnerFee;
167
+ const { sodax } = makeSodax(QUOTE, { address: FEE_RECIPIENT, percentage: 100 });
168
+ const { queryKey } = getLeverageYieldQuoteQueryOptions({
169
+ sodax,
170
+ payload: { ...PAYLOAD, partnerFee: explicitFee },
171
+ });
172
+ // Mirrors getQuote's own precedence: per-call override beats the configured fee.
173
+ expect(hashKey(queryKey)).toContain('"percentage":10');
174
+ });
175
+ });
@@ -0,0 +1,124 @@
1
+ import type { LeverageYieldQuoteParams, PartnerFee, Sodax } from '@sodax/sdk';
2
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
3
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
4
+ import type { ReadHookParams } from '../shared/types.js';
5
+
6
+ /**
7
+ * Derived from the SDK method rather than restated, so the public error union
8
+ * (`SolverErrorResponse | LeverageYieldLookupError`) stays exact and cannot drift.
9
+ * `undefined` is the disabled state, before a `payload` exists.
10
+ */
11
+ type LeverageYieldQuote = Awaited<ReturnType<Sodax['leverageYield']['getQuote']>> | undefined;
12
+
13
+ export type UseLeverageYieldQuoteParams = ReadHookParams<
14
+ LeverageYieldQuote,
15
+ { payload: LeverageYieldQuoteParams | undefined }
16
+ >;
17
+
18
+ type LeverageYieldQuoteReader = {
19
+ config: Pick<Sodax['config'], 'leverageYieldPartnerFee'>;
20
+ leverageYield: Pick<Sodax['leverageYield'], 'getQuote'>;
21
+ };
22
+
23
+ /** React Query hashes keys with `JSON.stringify`, which throws on a bigint fee amount. */
24
+ function feeKeyPart(fee: PartnerFee | undefined) {
25
+ if (!fee) return undefined;
26
+ return 'amount' in fee ? { ...fee, amount: fee.amount.toString() } : fee;
27
+ }
28
+
29
+ /**
30
+ * Keys on the **effective** fee, not `payload.partnerFee`: when the caller omits it, `getQuote`
31
+ * falls back to `config.leverageYieldPartnerFee`, so the configured fee is a real input to the
32
+ * result. Leaving it out lets two providers configured with different fees share one cache entry,
33
+ * and lets a reconfigured provider serve the previous fee's quote until the next poll — either way
34
+ * a `minOutputAmount` derived from that quote can be unfillable.
35
+ *
36
+ * Fields are named explicitly rather than spread. A spread would carry any future bigint field on
37
+ * `SolverIntentQuoteRequest` straight into the key, and React Query hashes keys with
38
+ * `JSON.stringify`, which throws on bigint — so a spread fails *open* into a render crash, while an
39
+ * allow-list fails *closed* into a missing key segment. Add new fields here deliberately.
40
+ *
41
+ * `String(...)` rather than `.toString()`: a payload assembled from partially-validated form state
42
+ * may not have an `amount` yet, and key derivation runs during render. Staying total lets the SDK's
43
+ * own validation surface it as a `VALIDATION_FAILED` result instead of throwing past React Query.
44
+ */
45
+ function quoteKeyPart(payload: LeverageYieldQuoteParams | undefined, effectiveFee: PartnerFee | undefined) {
46
+ if (!payload) return undefined;
47
+ return {
48
+ token_src: payload.token_src,
49
+ token_src_blockchain_id: payload.token_src_blockchain_id,
50
+ token_dst: payload.token_dst,
51
+ token_dst_blockchain_id: payload.token_dst_blockchain_id,
52
+ amount: String(payload.amount),
53
+ quote_type: payload.quote_type,
54
+ partnerFee: feeKeyPart(effectiveFee),
55
+ };
56
+ }
57
+
58
+ export function getLeverageYieldQuoteQueryOptions({
59
+ sodax,
60
+ payload,
61
+ }: {
62
+ sodax: LeverageYieldQuoteReader;
63
+ payload: LeverageYieldQuoteParams | undefined;
64
+ }) {
65
+ const effectiveFee = payload?.partnerFee ?? sodax.config.leverageYieldPartnerFee;
66
+ return {
67
+ queryKey: ['leverageYield', 'quote', quoteKeyPart(payload, effectiveFee)],
68
+ queryFn: async (): Promise<LeverageYieldQuote> => {
69
+ if (!payload) return undefined;
70
+ return sodax.leverageYield.getQuote(payload);
71
+ },
72
+ enabled: !!payload,
73
+ refetchInterval: 3000,
74
+ };
75
+ }
76
+
77
+ /**
78
+ * Quotes a leverage-yield vault deposit or withdraw. Pass the vault address as `token_dst` to
79
+ * quote a deposit, or as `token_src` to quote a withdraw; subtract your slippage tolerance from
80
+ * `quoted_amount` to size `minOutputAmount`.
81
+ *
82
+ * Use this rather than {@link useQuote}: the swap quote deducts the effective *swap* fee, while a
83
+ * vault intent charges the effective *leverage-yield* fee, so the two disagree whenever the feature
84
+ * fees differ. When overriding the fee per intent, pass the same `partnerFee` here and to whichever
85
+ * builder you use — `useLeverageYieldDeposit`, `useLeverageYieldWithdraw`, or
86
+ * `useLeverageYieldVaultSwap` — or omit it on all of them, which resolves the same configured fee on
87
+ * each side. Both directions are charged, so this applies to withdrawals as much as deposits.
88
+ *
89
+ * Returns the SDK `Result` as query data rather than unwrapping it, matching {@link useQuote}: a
90
+ * quote failure ("no path", thin liquidity) is an expected UI branch, and keeping the `Result`
91
+ * preserves the solver's `detail.code` instead of flattening it to an error message.
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const { data: quote } = useLeverageYieldQuote({
96
+ * params: {
97
+ * payload: {
98
+ * token_src: inputToken,
99
+ * token_src_blockchain_id: ChainKeys.ARBITRUM_MAINNET,
100
+ * token_dst: vault.vault,
101
+ * token_dst_blockchain_id: ChainKeys.SONIC_MAINNET,
102
+ * amount: parseUnits('1', 18),
103
+ * quote_type: 'exact_input',
104
+ * },
105
+ * },
106
+ * });
107
+ * if (quote?.ok) setMinOutput((quote.value.quoted_amount * 9_950n) / 10_000n);
108
+ * ```
109
+ *
110
+ * @remarks
111
+ * - Refreshes every 3 seconds, like `useQuote` — solver prices go stale.
112
+ * - Disabled while `payload` is undefined.
113
+ */
114
+ export function useLeverageYieldQuote({
115
+ params,
116
+ queryOptions,
117
+ }: UseLeverageYieldQuoteParams = {}): UseQueryResult<LeverageYieldQuote, Error> {
118
+ const { sodax } = useSodaxContext();
119
+
120
+ return useQuery<LeverageYieldQuote, Error>({
121
+ ...getLeverageYieldQuoteQueryOptions({ sodax, payload: params?.payload }),
122
+ ...queryOptions,
123
+ });
124
+ }
@@ -0,0 +1,136 @@
1
+ import {
2
+ ChainKeys,
3
+ type PartnerFee,
4
+ type Sodax,
5
+ type SolverIntentQuoteRequest,
6
+ SolverIntentErrorCode,
7
+ } from '@sodax/sdk';
8
+ import { hashKey } from '@tanstack/react-query';
9
+ import { describe, expect, it, vi } from 'vitest';
10
+ import { getSwapQuoteQueryOptions } from './useQuote.js';
11
+
12
+ const TOKEN_SRC = '0x2170Ed0880ac9A755fd29B2688956BD959F933F8';
13
+ const TOKEN_DST = '0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f';
14
+ const FEE_RECIPIENT = '0x4444444444444444444444444444444444444444' as const;
15
+
16
+ const PAYLOAD: SolverIntentQuoteRequest = {
17
+ token_src: TOKEN_SRC,
18
+ token_src_blockchain_id: ChainKeys.BSC_MAINNET,
19
+ token_dst: TOKEN_DST,
20
+ token_dst_blockchain_id: ChainKeys.ARBITRUM_MAINNET,
21
+ amount: 1_000_000n,
22
+ quote_type: 'exact_input',
23
+ };
24
+
25
+ /** The SDK's own quote Result, derived so the doubles stay honest without an unsafe cast. */
26
+ type QuoteResult = Awaited<ReturnType<Sodax['swaps']['getQuote']>>;
27
+
28
+ const QUOTE: QuoteResult = { ok: true, value: { quoted_amount: 990_000n } };
29
+
30
+ const makeSodax = (result: QuoteResult = QUOTE, partnerFee?: PartnerFee) => {
31
+ const getQuote = vi.fn(async () => result);
32
+ return { sodax: { swaps: { getQuote, partnerFee } }, getQuote };
33
+ };
34
+
35
+ describe('getSwapQuoteQueryOptions', () => {
36
+ it('keys on the swap feature and the quote action', () => {
37
+ const { sodax } = makeSodax();
38
+ const { queryKey } = getSwapQuoteQueryOptions({ sodax, payload: PAYLOAD });
39
+ expect(queryKey[0]).toBe('swap');
40
+ expect(queryKey[1]).toBe('quote');
41
+ });
42
+
43
+ it('returns the SDK Result as data so callers can branch on `ok`', async () => {
44
+ const { sodax, getQuote } = makeSodax();
45
+ await expect(getSwapQuoteQueryOptions({ sodax, payload: PAYLOAD }).queryFn()).resolves.toEqual(QUOTE);
46
+ expect(getQuote).toHaveBeenCalledWith(PAYLOAD);
47
+ });
48
+
49
+ it('passes a solver failure through as data rather than throwing', async () => {
50
+ const error = { detail: { code: SolverIntentErrorCode.NO_PATH_FOUND, message: 'no path' } };
51
+ const { sodax } = makeSodax({ ok: false, error });
52
+ await expect(getSwapQuoteQueryOptions({ sodax, payload: PAYLOAD }).queryFn()).resolves.toEqual({
53
+ ok: false,
54
+ error,
55
+ });
56
+ });
57
+
58
+ it('is disabled and resolves undefined without calling the SDK when payload is undefined', async () => {
59
+ const { sodax, getQuote } = makeSodax();
60
+ const options = getSwapQuoteQueryOptions({ sodax, payload: undefined });
61
+ expect(options.enabled).toBe(false);
62
+ await expect(options.queryFn()).resolves.toBeUndefined();
63
+ expect(getQuote).not.toHaveBeenCalled();
64
+ });
65
+
66
+ it('keys the amount as a string so it survives hashing', () => {
67
+ const { sodax } = makeSodax();
68
+ const { queryKey } = getSwapQuoteQueryOptions({ sodax, payload: PAYLOAD });
69
+ expect(hashKey(queryKey)).toContain('"amount":"1000000"');
70
+ });
71
+
72
+ // `getQuote` deducts the configured fee from `amount` before quoting, so it is an input to the
73
+ // result even though it never appears in `payload`. Two providers with different swap fees must
74
+ // not share a cache entry, and a reconfigured provider must not serve the old fee's quote.
75
+ it('keys the configured swap partner fee', () => {
76
+ const noFee = getSwapQuoteQueryOptions({ sodax: makeSodax().sodax, payload: PAYLOAD }).queryKey;
77
+ const withFee = getSwapQuoteQueryOptions({
78
+ sodax: makeSodax(QUOTE, { address: FEE_RECIPIENT, percentage: 100 }).sodax,
79
+ payload: PAYLOAD,
80
+ }).queryKey;
81
+
82
+ expect(hashKey(noFee)).not.toBe(hashKey(withFee));
83
+ });
84
+
85
+ it('keys two differently-configured providers apart for an identical payload', () => {
86
+ const a = getSwapQuoteQueryOptions({
87
+ sodax: makeSodax(QUOTE, { address: FEE_RECIPIENT, percentage: 100 }).sodax,
88
+ payload: PAYLOAD,
89
+ }).queryKey;
90
+ const b = getSwapQuoteQueryOptions({
91
+ sodax: makeSodax(QUOTE, { address: FEE_RECIPIENT, percentage: 25 }).sodax,
92
+ payload: PAYLOAD,
93
+ }).queryKey;
94
+
95
+ expect(hashKey(a)).not.toBe(hashKey(b));
96
+ });
97
+
98
+ it('keys a bigint configured fee without throwing', () => {
99
+ const { sodax } = makeSodax(QUOTE, { address: FEE_RECIPIENT, amount: 7_000n });
100
+ const { queryKey } = getSwapQuoteQueryOptions({ sodax, payload: PAYLOAD });
101
+ expect(() => hashKey(queryKey)).not.toThrow();
102
+ expect(hashKey(queryKey)).toContain('7000');
103
+ });
104
+
105
+ // Pins the allow-list. If `SolverIntentQuoteRequest` gains a field, this fails and forces a
106
+ // decision about whether it belongs in the key — rather than a spread silently carrying a new
107
+ // bigint in and crashing `hashKey` at render time.
108
+ it('keys exactly the known request fields', () => {
109
+ const { sodax } = makeSodax();
110
+ const { queryKey } = getSwapQuoteQueryOptions({ sodax, payload: PAYLOAD });
111
+
112
+ expect(Object.keys(queryKey[2] as object).sort()).toEqual(
113
+ [
114
+ 'amount',
115
+ 'partnerFee',
116
+ 'quote_type',
117
+ 'token_dst',
118
+ 'token_dst_blockchain_id',
119
+ 'token_src',
120
+ 'token_src_blockchain_id',
121
+ ].sort(),
122
+ );
123
+ });
124
+
125
+ // Key derivation runs during render, so it must not throw on a payload assembled from
126
+ // partially-validated form state.
127
+ it('derives a hashable key even when amount is missing', () => {
128
+ const { sodax } = makeSodax();
129
+ const malformed = { ...PAYLOAD, amount: undefined } as unknown as SolverIntentQuoteRequest;
130
+
131
+ const { queryKey } = getSwapQuoteQueryOptions({ sodax, payload: malformed });
132
+
133
+ expect(() => hashKey(queryKey)).not.toThrow();
134
+ expect(hashKey(queryKey)).toContain('"amount":"undefined"');
135
+ });
136
+ });
@@ -1,17 +1,79 @@
1
- import type { SolverErrorResponse, SolverIntentQuoteRequest, SolverIntentQuoteResponse } from '@sodax/sdk';
2
- import type { Result } from '@sodax/sdk';
1
+ import type { PartnerFee, Sodax, SolverIntentQuoteRequest } from '@sodax/sdk';
3
2
  import { useSodaxContext } from '../shared/useSodaxContext.js';
4
3
  import { useQuery, type UseQueryResult } from '@tanstack/react-query';
5
4
  import type { ReadHookParams } from '../shared/types.js';
6
5
 
7
- export type UseQuoteParams = ReadHookParams<
8
- Result<SolverIntentQuoteResponse, SolverErrorResponse> | undefined,
9
- { payload: SolverIntentQuoteRequest | undefined }
10
- >;
6
+ /**
7
+ * Derived from the SDK method rather than restated, so the error union stays exact and cannot
8
+ * drift. `undefined` is the disabled state, before a `payload` exists.
9
+ */
10
+ type SwapQuote = Awaited<ReturnType<Sodax['swaps']['getQuote']>> | undefined;
11
+
12
+ export type UseQuoteParams = ReadHookParams<SwapQuote, { payload: SolverIntentQuoteRequest | undefined }>;
13
+
14
+ type SwapQuoteReader = { swaps: Pick<Sodax['swaps'], 'getQuote' | 'partnerFee'> };
15
+
16
+ /** React Query hashes keys with `JSON.stringify`, which throws on a bigint fee amount. */
17
+ function feeKeyPart(fee: PartnerFee | undefined) {
18
+ if (!fee) return undefined;
19
+ return 'amount' in fee ? { ...fee, amount: fee.amount.toString() } : fee;
20
+ }
21
+
22
+ /**
23
+ * Includes the configured partner fee: `getQuote` deducts it from `amount` before quoting, so it
24
+ * is a real input to the result even though it never appears in `payload`. Leaving it out lets two
25
+ * providers configured with different fees share one cache entry, and lets a reconfigured provider
26
+ * serve the previous fee's quote until the next poll — either way a `minOutputAmount` derived from
27
+ * that quote can be unfillable.
28
+ *
29
+ * Fields are named explicitly rather than spread. A spread would carry any future bigint field on
30
+ * `SolverIntentQuoteRequest` straight into the key, and `JSON.stringify` throws on bigint — so a
31
+ * spread fails *open* into a render crash, while an allow-list fails *closed* into a missing key
32
+ * segment. Add new fields here deliberately.
33
+ *
34
+ * `String(...)` rather than `.toString()`: a payload assembled from partially-validated form state
35
+ * may not have an `amount` yet, and key derivation runs during render. Staying total lets the SDK's
36
+ * own validation surface it instead of throwing past React Query.
37
+ */
38
+ function quoteKeyPart(payload: SolverIntentQuoteRequest | undefined, configuredFee: PartnerFee | undefined) {
39
+ if (!payload) return undefined;
40
+ return {
41
+ token_src: payload.token_src,
42
+ token_src_blockchain_id: payload.token_src_blockchain_id,
43
+ token_dst: payload.token_dst,
44
+ token_dst_blockchain_id: payload.token_dst_blockchain_id,
45
+ amount: String(payload.amount),
46
+ quote_type: payload.quote_type,
47
+ partnerFee: feeKeyPart(configuredFee),
48
+ };
49
+ }
50
+
51
+ export function getSwapQuoteQueryOptions({
52
+ sodax,
53
+ payload,
54
+ }: {
55
+ sodax: SwapQuoteReader;
56
+ payload: SolverIntentQuoteRequest | undefined;
57
+ }) {
58
+ return {
59
+ queryKey: ['swap', 'quote', quoteKeyPart(payload, sodax.swaps.partnerFee)],
60
+ queryFn: async (): Promise<SwapQuote> => {
61
+ if (!payload) {
62
+ return undefined;
63
+ }
64
+ return sodax.swaps.getQuote(payload);
65
+ },
66
+ enabled: !!payload,
67
+ refetchInterval: 3000,
68
+ };
69
+ }
11
70
 
12
71
  /**
13
72
  * Hook for fetching a quote for an intent-based swap.
14
73
  *
74
+ * For a leverage-yield vault deposit or withdraw use `useLeverageYieldQuote` instead — this hook
75
+ * deducts the effective *swap* fee, which is not what a vault intent charges.
76
+ *
15
77
  * @example
16
78
  * ```typescript
17
79
  * const { data: quote, isLoading } = useQuote({ params: { payload } });
@@ -20,24 +82,13 @@ export type UseQuoteParams = ReadHookParams<
20
82
  * @remarks
21
83
  * - The quote is automatically refreshed every 3 seconds
22
84
  * - The query is disabled when payload is undefined
85
+ * - Returns the SDK `Result` as `data`; branch on `data?.ok` rather than reading `isError`
23
86
  */
24
- export const useQuote = ({
25
- params,
26
- queryOptions,
27
- }: UseQuoteParams = {}): UseQueryResult<Result<SolverIntentQuoteResponse, SolverErrorResponse> | undefined> => {
87
+ export const useQuote = ({ params, queryOptions }: UseQuoteParams = {}): UseQueryResult<SwapQuote> => {
28
88
  const { sodax } = useSodaxContext();
29
- const payload = params?.payload;
30
89
 
31
90
  return useQuery({
32
- queryKey: ['swap', 'quote', payload && { ...payload, amount: payload.amount.toString() }],
33
- queryFn: async () => {
34
- if (!payload) {
35
- return undefined;
36
- }
37
- return sodax.swaps.getQuote(payload);
38
- },
39
- enabled: !!payload,
40
- refetchInterval: 3000,
91
+ ...getSwapQuoteQueryOptions({ sodax, payload: params?.payload }),
41
92
  ...queryOptions,
42
93
  });
43
94
  };
@@ -25,6 +25,7 @@ export type UseSwapsApiQuoteParams = ReadHookParams<
25
25
  * tokenSrc: '0x...', tokenSrcChainKey: '0xa4b1.arbitrum',
26
26
  * tokenDst: '0x...', tokenDstChainKey: 'sonic',
27
27
  * amount: '1000000', quoteType: 'exact_input',
28
+ * partnerFee: { address: '0xSonicFeeReceiver', percentage: 10 },
28
29
  * },
29
30
  * },
30
31
  * });