UNPKG

@kaiachain/kss-bridges-celer

Version:
56 lines 2.94 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getEstimation = exports.getWithdrawInfo = exports.getTransferStatus = exports.getTransferConfigs = void 0; const gateway_pb_1 = require("../ts-proto/gateway/gateway_pb"); const GatewayServiceClientPb_1 = require("../ts-proto/gateway/GatewayServiceClientPb"); const ethers_1 = require("ethers"); const Estimate_1 = require("./Estimate"); const axios_1 = __importDefault(require("axios")); const format_1 = require("celer-web-utils/lib/format"); const getTransferConfigs = (rpc) => axios_1.default .get(`${rpc}/v2/getTransferConfigsForAll`) .then(({ data }) => data) .catch((err) => console.log(err)); exports.getTransferConfigs = getTransferConfigs; const getTransferStatus = async (rpc, transferId) => { const client = new GatewayServiceClientPb_1.WebClient(rpc, null, null); const statusRequest = new gateway_pb_1.GetTransferStatusRequest(); statusRequest.setTransferId(transferId); const transferStatus = await client.getTransferStatus(statusRequest, null); // console.log("Transfer Status:", transferStatus.toObject()) return transferStatus.toObject(); }; exports.getTransferStatus = getTransferStatus; const getWithdrawInfo = (chainId, amount, slippageTolerance) => { const withdrawInfo = new gateway_pb_1.WithdrawInfo(); withdrawInfo.setChainId(chainId); withdrawInfo.setAmount((0, format_1.safeParseUnits)(amount, 6).toString()); withdrawInfo.setSlippageTolerance(slippageTolerance); return withdrawInfo; }; exports.getWithdrawInfo = getWithdrawInfo; const getEstimation = async (rpc, addr, chainId, tokenSymbol, amount, slippageTolerance) => { const client = new GatewayServiceClientPb_1.WebClient(rpc, null, null); const withdrawInfo = (0, exports.getWithdrawInfo)(chainId, amount, slippageTolerance); const estimateRequest = (0, Estimate_1.estimateWithdrawAmt)(Array(withdrawInfo), chainId, tokenSymbol, addr); const res = await client.estimateWithdrawAmt(estimateRequest, null); let estimateResult = ""; if (!res.getErr() && res.getReqAmtMap()) { const resMap = res.getReqAmtMap(); resMap.forEach((entry, key) => { if (key === chainId) { const totleFee = (Number(entry.getBaseFee()) + Number(entry.getPercFee())).toString() || "0"; const eqValueTokenAmtBigNum = ethers_1.BigNumber.from(entry.getEqValueTokenAmt()); const feeBigNum = ethers_1.BigNumber.from(totleFee); const targetReceiveAmounts = eqValueTokenAmtBigNum.sub(feeBigNum); estimateResult = targetReceiveAmounts.toString(); } }); } return estimateResult; }; exports.getEstimation = getEstimation; //# sourceMappingURL=GetData.js.map