UNPKG

@molecularlabs/nucleus-frontend

Version:
171 lines (167 loc) 8.4 kB
import { Address, erc20Abi } from 'viem'; import { BridgeData } from '../../api/teller.js'; import { ChainId } from '../../api/vault-config.js'; import { TellerAbi } from '../../contracts/teller-abi.js'; import { VaultKey } from '../config.js'; import { TokenKey } from '../tokens.js'; import 'viem/chains'; /** * @file Deposit functionality for Nucleus vaults * @module vaults/deposit */ /** * Parameters required for preparing a deposit transaction * @interface PrepareDepositTransactionDataParams * @property {VaultKey} vaultKey - Unique identifier for the target vault * @property {Address} userAddress - Ethereum address of the user making the deposit * @property {string} depositTokenSymbol - Symbol of the token being deposited (e.g., 'WETH', 'USDC') * @property {string} depositAmount - Amount of assets to deposit as a decimal string (e.g., "1.5") * @property {number | string} chainId - ID of the chain where the deposit will occur * @property {number} [slippage] - Maximum acceptable slippage percentage as a decimal (e.g., 0.01 for 1%) */ interface PrepareDepositTransactionDataParams { vaultKey: VaultKey; userAddress: Address; depositTokenSymbol: TokenKey; depositAmount: string; chainId: ChainId; slippage?: number; } /** * Result object containing transaction data for a deposit operation * @interface DepositTransactionData * @property {typeof TellerAbi} abi - ABI for the Teller contract * @property {Address} address - Address of the Teller contract * @property {'deposit'} functionName - Name of the function to call * @property {[Address, bigint, bigint]} args - Arguments for the deposit function: * [depositAsset, depositAmount, minimumMint] * @property {number} chainId - ID of the chain where the transaction should be executed */ interface DepositTransactionData { abi: typeof TellerAbi; address: Address; functionName: "deposit"; args: [Address, bigint, bigint]; chainId: number; } /** * Prepares the transaction data needed to deposit assets into a vault * * This function calculates the minimum amount of vault tokens to be minted based on * the current exchange rate and the specified slippage tolerance. It returns a transaction * object that can be used with viem or ethers.js to execute the deposit. * * @example * ```typescript * const depositData = await prepareDepositData({ * vaultKey: 'bobaeth', * userAddress: '0x1234...', * depositTokenSymbol: 'WETH', * depositAmount: "1.0", // 1 WETH * chainId: 1, * slippage: 0.01, // 1% slippage * }); * ``` * * @param {PrepareDepositTransactionDataParams} params - Parameters for the deposit operation * @param {VaultKey} params.vaultKey - Unique identifier for the vault * @param {Address} params.userAddress - Ethereum address of the user making the deposit * @param {string} params.depositTokenSymbol - Symbol of the token being deposited * @param {string} params.depositAmount - Amount of assets to deposit as a string * @param {number | string} params.chainId - ID of the chain where the deposit will occur * @param {number} [params.slippage=DEFAULT_DEPOSIT_SLIPPAGE] - Maximum acceptable slippage percentage * * @returns {Promise<DepositTransactionData>} Promise resolving to the prepared transaction data * @throws {Error} If the vault key is invalid or if contracts are not properly configured */ declare const prepareDepositTransactionData: ({ vaultKey, depositTokenSymbol, depositAmount, chainId, slippage, }: PrepareDepositTransactionDataParams) => Promise<DepositTransactionData>; /** * Parameters required for preparing a deposit and bridge transaction * @interface PrepareDepositAndBridgeTransactionDataParams * @property {VaultKey} vaultKey - Unique identifier for the target vault * @property {string} depositTokenSymbol - Symbol of the token being deposited * @property {string} depositAmount - Amount of assets to deposit as a string * @property {number | string} sourceChainId - ID of the chain where the deposit originates * @property {number | string} destinationChainId - ID of the chain where tokens will be bridged to * @property {Address} userAddress - Ethereum address of the user making the deposit * @property {number} [slippage] - Maximum acceptable slippage percentage (defaults to DEFAULT_DEPOSIT_SLIPPAGE) */ interface PrepareDepositAndBridgeTransactionDataParams { depositAmount: string; depositTokenSymbol: TokenKey; destinationChainId: ChainId; slippage?: number; sourceChainId: ChainId; userAddress: Address; vaultKey: VaultKey; } /** * Result object containing transaction data for a deposit and bridge operation * @interface DepositAndBridgeTransactionData * @property {typeof TellerAbi} abi - ABI for the Teller contract * @property {Address} address - Address of the Teller contract * @property {'depositAndBridge'} functionName - Name of the function to call * @property {[Address, bigint, bigint, BridgeData]} args - Arguments for the depositAndBridge function: * - depositAsset: Address of the token being deposited * - depositAmount: Amount of tokens to deposit in base units (e.g., wei) * - minimumMint: Minimum amount of vault tokens to receive after slippage * - bridgeData: Data required for cross-chain bridging * @property {number} chainId - ID of the chain where the transaction should be executed * @property {bigint} value - Amount of native token to send with the transaction (for bridge fees) */ interface DepositAndBridgeTransactionData { abi: typeof TellerAbi; address: Address; functionName: "depositAndBridge"; args: [Address, bigint, bigint, BridgeData]; chainId: number; value: bigint; } /** * Prepares the transaction data needed to deposit assets into a vault and bridge them to another chain * * This function calculates the minimum amount of vault tokens to be minted based on * the current exchange rate and the specified slippage tolerance, then prepares the bridge data * for cross-chain transfer. It returns a transaction object that can be used with viem or ethers.js * to execute the deposit and bridge operation. * * @example * ```typescript * const depositAndBridgeData = await prepareDepositAndBridgeData({ * vaultKey: 'bobaeth', * depositTokenSymbol: 'WETH', * depositAmount: "1.0", // 1 WETH * sourceChainId: 1, * destinationChainId: 10, * userAddress: '0x1234...', * slippage: 0.01, // 1% slippage * }); * ``` * * @param {PrepareDepositAndBridgeTransactionDataParams} params - Parameters for the deposit and bridge operation * @param {VaultKey} params.vaultKey - Unique identifier for the vault * @param {string} params.depositTokenSymbol - Symbol of the token being deposited * @param {string} params.depositAmount - Amount of assets to deposit as a string * @param {number | string} params.sourceChainId - ID of the chain where the deposit originates * @param {number | string} params.destinationChainId - ID of the chain where tokens will be bridged to * @param {Address} params.userAddress - Ethereum address of the user making the deposit * @param {number} [params.slippage=DEFAULT_DEPOSIT_SLIPPAGE] - Maximum acceptable slippage percentage * * @returns {Promise<DepositAndBridgeTransactionData>} Promise resolving to the prepared transaction data * @throws {Error} If the vault key is invalid or if contracts are not properly configured */ declare const prepareDepositAndBridgeTransactionData: ({ depositAmount, depositTokenSymbol, destinationChainId, slippage, sourceChainId, userAddress, vaultKey, }: PrepareDepositAndBridgeTransactionDataParams) => Promise<DepositAndBridgeTransactionData>; interface PrepareApproveDepositTokenParams { vaultKey: VaultKey; depositTokenSymbol: string; depositAmount?: string; chainId: ChainId; } interface ApproveDepositTokenTransactionData { abi: typeof erc20Abi; address: Address; functionName: "approve"; args: [Address, bigint]; } declare const prepareApproveDepositToken: ({ vaultKey, depositTokenSymbol, depositAmount, chainId, }: PrepareApproveDepositTokenParams) => Promise<ApproveDepositTokenTransactionData>; export { type ApproveDepositTokenTransactionData, type DepositAndBridgeTransactionData, type DepositTransactionData, prepareApproveDepositToken, prepareDepositAndBridgeTransactionData, prepareDepositTransactionData };