@cyberk/hyperion-sdk
Version:
Hyperion SDK from Cyberk
40 lines • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useQuote = void 0;
const react_query_1 = require("@tanstack/react-query");
const RPCs_1 = require("../constants/RPCs");
const useCosmWasmClient_1 = require("./useCosmWasmClient");
const getQuote_1 = require("../query/getQuote");
/**
* Hook to get a quote for a swap operation
* This will call simulate_swap_operations in the contract and return the quote
*/
const useQuote = ({ routerContract, offerAmount, offerAsset, askAsset, chainId, options: observerOptions, }) => {
const rpc = RPCs_1.RPCs[chainId];
if (!rpc) {
throw new Error(`RPC not found for chainId: ${chainId}`);
}
const { data: cosmwasmClient } = (0, useCosmWasmClient_1.useCosmWasmClient)({
rpc,
options: {
enabled: !!rpc,
},
});
const enabled = !!cosmwasmClient;
const { queryKey, ...options } = (0, getQuote_1.getQuoteQueryOptions)({
client: cosmwasmClient,
routerContract,
offerAmount,
offerAsset,
askAsset,
});
return (0, react_query_1.useQuery)({
...observerOptions,
...options,
// @ts-expect-error
queryKey,
enabled: Boolean(enabled && (observerOptions?.enabled ?? true)),
});
};
exports.useQuote = useQuote;
//# sourceMappingURL=useQuote.js.map