@cyberk/hyperion-sdk
Version:
Hyperion SDK from Cyberk
73 lines • 2.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getExecuteSwapMutationOptions = exports.executeSwapFn = exports.getExecuteSwapQueryKey = exports.getExecuteSwapContractExecuteMsg = void 0;
const buildExecuteContractMsg_1 = require("../utils/buildExecuteContractMsg");
const getExecuteSwapContractExecuteMsg = (options) => {
const { offerAsset, askAsset, minimumReceiveAmount, to = null, deadline = null, signerAddress, offerAmount, routerAddress, } = options;
const msg = {
execute_swap_operations: {
operations: [
{
hyperion: {
offer_asset_info: {
native_token: {
denom: offerAsset,
},
},
ask_asset_info: {
native_token: {
denom: askAsset,
},
},
},
},
],
minimum_receive: minimumReceiveAmount,
to,
deadline,
},
};
return (0, buildExecuteContractMsg_1.buildExecuteContractMsg)(routerAddress, msg, signerAddress, [
{
denom: offerAsset,
amount: offerAmount,
},
]);
};
exports.getExecuteSwapContractExecuteMsg = getExecuteSwapContractExecuteMsg;
const getExecuteSwapQueryKey = (options) => {
return [
"executeSwap",
options.isSimulate ? "simulate" : "execute",
options.routerAddress,
options.offerAsset,
options.askAsset,
options.offerAmount,
options.minimumReceiveAmount,
options.signerAddress,
];
};
exports.getExecuteSwapQueryKey = getExecuteSwapQueryKey;
const executeSwapFn = async (variables) => {
const { isSimulate = false } = variables;
const { signingClient, signerAddress, fee, memo } = variables;
const message = (0, exports.getExecuteSwapContractExecuteMsg)(variables);
if (isSimulate) {
return await signingClient.simulate(signerAddress, [message], memo);
}
else {
if (!fee) {
throw new Error("Fee is required");
}
return await signingClient.signAndBroadcast(signerAddress, [message], fee, memo);
}
};
exports.executeSwapFn = executeSwapFn;
const getExecuteSwapMutationOptions = (options) => {
return {
mutationFn: async (variables) => (0, exports.executeSwapFn)({ ...variables, isSimulate: options.isSimulate }),
mutationKey: ["executeSwap", options.isSimulate ? "simulate" : "execute"],
};
};
exports.getExecuteSwapMutationOptions = getExecuteSwapMutationOptions;
//# sourceMappingURL=executeSwap.js.map