UNPKG

@cyberk/hyperion-sdk

Version:

Hyperion SDK from Cyberk

58 lines 2.11 kB
import { buildExecuteContractMsg } from "../utils/buildExecuteContractMsg"; import orderBy from "lodash/orderBy"; export const getCreatePairContractExecuteMsg = (options) => { const { factoryAddress, signerAddress, assets: rawAssets } = options; const sortedAssets = orderBy(rawAssets, ["denom"], ["asc"]); const msg = { create_pair: { assets: [ { info: { native_token: { denom: sortedAssets[0].denom, }, }, amount: sortedAssets[0].amount, }, { info: { native_token: { denom: sortedAssets[1].denom, }, }, amount: sortedAssets[1].amount, }, ], }, }; return buildExecuteContractMsg(factoryAddress, msg, signerAddress, []); }; export const getCreatePairQueryKey = (options) => { return [ "createPair", options.isSimulate ? "simulate" : "execute", options.factoryAddress, options.assets.map((asset) => asset.denom).join("-"), options.signerAddress, ]; }; export const getCreatePairMutationOptions = (options) => { return { mutationFn: async (variables) => { const { isSimulate = false } = options; const { signingClient, signerAddress, fee, memo } = variables; const message = getCreatePairContractExecuteMsg(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); } }, mutationKey: ["createPair", options.isSimulate ? "simulate" : "execute"], }; }; //# sourceMappingURL=createPair.js.map