import { useQuery, type UseQueryResult } from '@tanstack/react-query'; import { useSodaxContext } from '../shared/useSodaxContext.js'; import type { ReadHookParams } from '../shared/types.js'; export type UseInstantUnstakeRatioParams = ReadHookParams< bigint, { amount: bigint | undefined; } >; /** * React hook to estimate the SODA amount received from instant-unstaking a given xSODA amount * (after slippage). Hub-only read. Throws on `!ok`. */ export function useInstantUnstakeRatio({ params, queryOptions, }: UseInstantUnstakeRatioParams = {}): UseQueryResult { const { sodax } = useSodaxContext(); const amount = params?.amount; return useQuery({ queryKey: ['staking', 'instantUnstakeRatio', amount?.toString()], queryFn: async () => { if (amount === undefined) { throw new Error('amount is required'); } const result = await sodax.staking.getInstantUnstakeRatio(amount); if (!result.ok) throw result.error; return result.value; }, enabled: amount !== undefined, refetchInterval: 10_000, ...queryOptions, }); }