UNPKG

@molecularlabs/nucleus-frontend

Version:
76 lines 2.79 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var bridge_fees_exports = {}; __export(bridge_fees_exports, { getBridgeFee: () => getBridgeFee }); module.exports = __toCommonJS(bridge_fees_exports); var import_teller = require("../api/teller"); var import_constants = require("../constants"); var import_vaults = require("../vaults"); var import_bridge = require("../vaults/bridge"); const getBridgeFee = async ({ vaultKey, bridgeAmount, sourceChainId, destinationChainId, userAddress, nativeTokenForBridgeFee = import_constants.NATIVE_TOKEN_FOR_BRIDGE_FEE }) => { const vault = await (0, import_vaults.getVaultByKey)(vaultKey); if (!vault) { throw new Error(`Invalid vault key: ${vaultKey}`); } if (!vault.contracts) { throw new Error(`Contracts not configured for vault ${vaultKey}`); } if (!vault.contracts.boringVault) { throw new Error( `BoringVault contract not configured for vault ${vaultKey}` ); } if (!vault.contracts.accountant) { throw new Error(`Accountant contract not configured for vault ${vaultKey}`); } if (!vault.contracts.teller) { throw new Error(`Teller contract not configured for vault ${vaultKey}`); } const sourceChain = vault.withdraw.sourceChains[sourceChainId]; if (!sourceChain) { throw new Error(`Source chain not configured for vault ${vaultKey}`); } const destinationChain = sourceChain.destinationChains[destinationChainId]; if (!destinationChain) { throw new Error(`Destination chain not configured for vault ${vaultKey}`); } const bridgeChainIdentifier = destinationChain.bridge.chainIdentifier; const bridgeContractArg = (0, import_bridge.prepareBridgeContractArg)({ bridgeChainIdentifier, userAddress, nativeTokenForBridgeFee }); const previewFee = await (0, import_teller.getPreviewFee)({ shareAmount: bridgeAmount, bridgeData: bridgeContractArg, contractAddress: vault.contracts.teller, chainId: sourceChainId }); return previewFee; }; //# sourceMappingURL=bridge-fees.js.map