UNPKG

@cyberk/hyperion-sdk

Version:

Hyperion SDK from Cyberk

36 lines 1.17 kB
import { useQuery } from "@tanstack/react-query"; import { RPCs } from "../constants/RPCs"; import { useCosmWasmClient } from "./useCosmWasmClient"; import { getQuoteQueryOptions, } from "../query/getQuote"; /** * Hook to get a quote for a swap operation * This will call simulate_swap_operations in the contract and return the quote */ export const useQuote = ({ routerContract, offerAmount, offerAsset, askAsset, chainId, options: observerOptions, }) => { const rpc = RPCs[chainId]; if (!rpc) { throw new Error(`RPC not found for chainId: ${chainId}`); } const { data: cosmwasmClient } = useCosmWasmClient({ rpc, options: { enabled: !!rpc, }, }); const enabled = !!cosmwasmClient; const { queryKey, ...options } = getQuoteQueryOptions({ client: cosmwasmClient, routerContract, offerAmount, offerAsset, askAsset, }); return useQuery({ ...observerOptions, ...options, // @ts-expect-error queryKey, enabled: Boolean(enabled && (observerOptions?.enabled ?? true)), }); }; //# sourceMappingURL=useQuote.js.map