@molecularlabs/nucleus-frontend
Version:
Nucleus BoringVault Frontend SDK
100 lines • 3.75 kB
JavaScript
;
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_exports = {};
__export(bridge_exports, {
prepareBridgeContractArg: () => prepareBridgeContractArg,
prepareBridgeTransactionData: () => prepareBridgeTransactionData
});
module.exports = __toCommonJS(bridge_exports);
var import__ = require(".");
var import_teller = require("../api/teller");
var import_vault_config = require("../api/vault-config");
var import_constants = require("../constants");
var import_cross_chain_teller_base_abi = require("../contracts/cross-chain-teller-base-abi");
const prepareBridgeContractArg = ({
bridgeChainIdentifier,
userAddress,
nativeTokenForBridgeFee = import_constants.NATIVE_TOKEN_FOR_BRIDGE_FEE
}) => {
return {
chainSelector: bridgeChainIdentifier,
destinationChainReceiver: userAddress,
bridgeFeeToken: nativeTokenForBridgeFee,
messageGas: BigInt(1e5),
data: "0x"
};
};
const prepareBridgeTransactionData = async ({
vaultKey,
bridgeAmount,
sourceChainId,
destinationChainId,
userAddress
}) => {
const nativeTokenForBridgeFee = import_constants.NATIVE_TOKEN_FOR_BRIDGE_FEE;
const vault = await (0, import__.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 normalizedSourceChainId = (0, import_vault_config.toChainId)(sourceChainId);
const sourceChain = vault.withdraw.sourceChains[normalizedSourceChainId];
if (!sourceChain) {
throw new Error(`Source chain not configured for vault ${vaultKey}`);
}
const normalizedDestinationChainId = (0, import_vault_config.toChainId)(destinationChainId);
const destinationChain = sourceChain.destinationChains[normalizedDestinationChainId];
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 (0, import_teller.getPreviewFee)({
shareAmount: bridgeAmount,
bridgeData: bridgeContractArg,
contractAddress: vault.contracts.teller,
chainId: normalizedSourceChainId
});
return {
abi: import_cross_chain_teller_base_abi.CrossChainTellerBaseAbi,
address: vault.contracts.teller,
functionName: "bridge",
args: [bridgeAmount, bridgeContractArg],
chainId: normalizedSourceChainId,
value: previewFee
};
};
//# sourceMappingURL=bridge.js.map