UNPKG

@molecularlabs/nucleus-frontend

Version:
56 lines 1.82 kB
import { getPreviewFee } from "../api/teller"; import { NATIVE_TOKEN_FOR_BRIDGE_FEE } from "../constants"; import { getVaultByKey } from "../vaults"; import { prepareBridgeContractArg } from "../vaults/bridge"; const getBridgeFee = async ({ vaultKey, bridgeAmount, sourceChainId, destinationChainId, userAddress, nativeTokenForBridgeFee = NATIVE_TOKEN_FOR_BRIDGE_FEE }) => { const vault = await 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 = prepareBridgeContractArg({ bridgeChainIdentifier, userAddress, nativeTokenForBridgeFee }); const previewFee = await getPreviewFee({ shareAmount: bridgeAmount, bridgeData: bridgeContractArg, contractAddress: vault.contracts.teller, chainId: sourceChainId }); return previewFee; }; export { getBridgeFee }; //# sourceMappingURL=bridge-fees.mjs.map