UNPKG

emmet.sdk

Version:
41 lines 1.91 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.estimateReceive = void 0; const viem_1 = require("viem"); const types_1 = require("../../types"); const FTBridge_1 = __importDefault(require("../../abi/FTBridge")); const getPublicClient_1 = require("./getPublicClient"); async function estimateReceive(amount, senderAddress, destinationAddress, fromChainName, toChainName, tokenSymbol) { try { const selectedChain = types_1.testnets.filter(net => net.name === fromChainName)[0]; const publicClient = (0, getPublicClient_1.getPublicClient)(senderAddress, fromChainName, [selectedChain], true); const nativeChainId = types_1.allChainNameToIndex[fromChainName]; const toChainId = types_1.allChainNameToIndex[toChainName]; const actionId = 2n ** 256n - 1n; const txHash = (0, viem_1.keccak256)((0, viem_1.encodePacked)(['uint16', 'string', 'uint16', 'string', 'uint256'], [nativeChainId, "-", toChainId, "-", actionId])); const populatedArgs = [ BigInt(amount), toChainId, tokenSymbol, destinationAddress ]; const estimation = await publicClient?.estimateContractGas({ address: `0x${selectedChain.bridge.slice(2)}`, abi: FTBridge_1.default, functionName: 'receiveInstallment', args: [txHash, populatedArgs], account: `0x${senderAddress.slice(2)}` }); const gasPrice = await publicClient.getGasPrice(); return estimation * gasPrice; } catch (error) { console.error("estimateReceive Error:", error); } return 22880n * 20n; } exports.estimateReceive = estimateReceive; //# sourceMappingURL=estimateReceive.js.map