import { BigNumber, ethers, Overrides } from 'ethers'; import { BridgeNetworkConfig } from './networks'; import { TokenAddressMap } from './types'; import { SignerOrProvider } from './bridgeNetwork'; export declare const DEFAULT_GAS_PRICE_PERCENT_INCREASE: BigNumber; /** * Represents the estimated gas and fees. */ export interface GasAndFeeEstimation { /** * The estimated amount of gas required to execute the transaction. */ estimatedGas: BigNumber; /** * The estimated gas price for the transaction. */ gasPrice: BigNumber; /** * The total estimated fee for the transaction. * This is calculated as the product of `estimatedGas` and `gasPrice`. */ estimatedFee: BigNumber; childNetworkEstimation?: GasAndFeeEstimation; } /** * Parameters required for a fund transfer operation. */ export interface TransferParams { /** * The amount of ETH or tokens to be transferred. */ amount: BigNumber; /** * The signer instance for signing the transaction. */ signer: ethers.Signer; destinationProvider: ethers.providers.Provider; /** * The network address of the entity receiving the funds. Defaults to the signer address. */ destinationAddress?: string; /** * The maximum cost to be paid for submitting the transaction. */ maxSubmissionCost?: BigNumber; /** * The address to return any gas that was not spent on fees. */ excessFeeRefundAddress?: string; /** * The address to refund the call value to in the event the retryable is cancelled or expires. */ callValueRefundAddress?: string; /** * Transaction overrides. */ overrides?: Overrides; } /** * Represents a bridging operation between two networks for token transfers. * Handles deposits and withdrawals of both native currencies and ERC20 tokens * across supported networks. */ export declare class Bridger { /** * The configuration of the source/origin network where the transfer initiates. */ readonly originNetwork: BridgeNetworkConfig; /** * The configuration of the target/destination network where funds will be received. */ readonly destinationNetwork: BridgeNetworkConfig; /** * Indicates if this is a deposit operation (transfer from parent to child network). * True if origin network is the parent of the destination network. */ readonly isDeposit: boolean; /** * Maps chain IDs to their corresponding token addresses for both networks. */ readonly token: TokenAddressMap; /** * If true, uses local storage for caching data. * @type {boolean} * @private */ private useLocalStorage; /** * If true, automatically approves deposit allowances. * @type {boolean} * @private */ private approveDepositAllowance; /** * Creates a new Bridger instance to manage token transfers between networks. * * @param originNetworkChainId - Chain ID of the source network * @param destinationNetworkChainId - Chain ID of the target network * @param token - Mapping of chain IDs to token addresses for both networks * @param params - Optional configuration parameters * @param params.useLocalStorage - Whether to cache data in localStorage * @param params.approveDepositAllowance - Whether to auto-approve token deposits * * @throws {UnsupportedNetworkError} If either network is not supported * @throws {BridgerError} If networks are not properly connected (parent/child relationship) * or if token addresses are missing */ constructor(originNetworkChainId: number, destinationNetworkChainId: number, token: TokenAddressMap, params?: { useLocalStorage?: boolean; approveDepositAllowance?: boolean; }); /** * Checks if this bridge uses the Cross-Chain Transfer Protocol (CCTP). * * @returns {boolean} False for base Bridger implementation */ isCctp(): boolean; /** * Estimates gas costs and fees for a token transfer operation. * Supports both deposits and withdrawals of native currencies and ERC20 tokens. * * For deposits of ERC20 tokens, also estimates the gas required on the destination chain. * * @param amount - Amount of tokens/currency to transfer * @param provider - Provider/signer for the origin network (can be RPC URL) * @param _from - Address initiating the transfer * @param destinationProvider - Provider for destination network (required for ERC20 deposits) * * @returns Promise resolving to gas and fee estimates for both networks where applicable * @throws {GasEstimationError} If estimation fails or required parameters are missing */ getGasAndFeeEstimation(amount: BigNumber, provider: SignerOrProvider, _from: string, destinationProvider?: SignerOrProvider): Promise; /** * Estimates gas costs for approving token transfers. * Only applicable for ERC20 deposits where allowance is needed. * * @param amount - Amount of tokens requiring approval * @param _provider - Provider/signer for checking allowance (can be RPC URL) * @param _from - Address that needs to approve the tokens * * @returns Promise resolving to gas estimates if approval is needed, null otherwise * @throws {Error} If token configuration is invalid */ getApprovalGasAndFeeEstimation(amount: BigNumber, _provider: SignerOrProvider, _from: string): Promise; /** * Estimates the gas and fees required for withdrawing native ETH from the origin network. * * This method calculates the estimated gas usage, gas price, and total fee for withdrawing ETH * using the ArbSys contract on the origin network. * * @param {BigNumber} amount - The amount of ETH to withdraw. * @param {ethers.Signer | ethers.providers.Provider} provider - A signer or provider for connecting to the Ethereum network. * @param {string} from - The address from which the ETH is being withdrawn. * @returns {Promise} A promise that resolves to the estimated gas and fee details. * * @throws {GasEstimationError} If the gas estimation fails or if the origin network lacks an ArbSys contract. */ private estimateWithdrawNative; /** * Estimates the gas and fees required for withdrawing an ERC20 token from the origin network. * * This method calculates the estimated gas usage, gas price, and total fee for withdrawing * an ERC20 token using the Gateway Router contract's outboundTransfer function. * * @param {BigNumber} amount - The amount of ERC20 tokens to withdraw * @param {ethers.Signer | ethers.providers.Provider} signerOrProvider - Provider or signer for the origin network * @param {string} from - The address initiating the withdrawal * @returns {Promise} Gas and fee estimates including: * - estimatedGas: Expected gas units required * - gasPrice: Current gas price * - estimatedFee: Total estimated fee (gas * gasPrice) * @throws {GasEstimationError} If estimation fails due to invalid address or missing router contract */ private estimateWithdrawERC20; /** * Estimates gas and fees for depositing ETH from the origin network to the destination network. * * @param {BigNumber} amount - Amount of ETH to deposit * @param {SignerOrProvider} _provider - Provider or signer for the origin network * @param {string} from - Address initiating the deposit * @returns {Promise} Gas and fee estimates * @throws {GasEstimationError} If inbox contract address is not configured */ private estimateDepositEth; /** * Estimates gas and fees for depositing ERC20 tokens that will be received as ETH on the destination network. * * @param {BigNumber} amount - Amount of ERC20 tokens to deposit * @param {SignerOrProvider} _provider - Provider or signer for the origin network * @param {string} from - Address initiating the deposit * @returns {Promise} Gas and fee estimates * @throws {GasEstimationError} If inbox contract address is not configured */ private estimateDepositERC20ToEth; /** * Estimates gas and fees for depositing ERC20 tokens from parent chain to child chain. * Includes gas estimates for both chains since token deposits require transactions on both networks. * * @param {BigNumber} amount - Amount of ERC20 tokens to deposit * @param {ethers.providers.Provider} parentProvider - Provider for the parent chain * @param {ethers.providers.Provider} childProvider - Provider for the child chain * @param {string} from - Address initiating the deposit * @param {number} childNativeCurrencyDecimals - Decimal places of child chain's native currency * @returns {Promise} Gas and fee estimates for both chains including: * - Parent chain estimates (estimatedGas, gasPrice, estimatedFee) * - Child chain estimates (childNetworkEstimation) * @throws {GasEstimationError} If parent gateway router contract is not configured */ private estimateDepositERC20; /** * Gets the appropriate spender address for token approvals based on the transfer type. * * For deposits: * - USDC: Returns settlement layer gateway * - ETH: Returns inbox contract * - Other ERC20: Returns parent gateway * * For withdrawals: * - Bridged USDC: Returns rollup gateway * - Other cases: Returns null * * @returns {string|null} The spender address or null if approval not needed */ private getDepositSpender; /** * Gets the current token allowance for the bridge spender. * * @param {ethers.Signer | ethers.providers.Provider | string} provider - Provider, signer or RPC URL * @param {string} account - Address to check allowance for * @returns {Promise} Current allowance amount, null if native token/no approval needed * @throws {BridgerError} If token address not found for the network */ getAllowance(provider: ethers.Signer | ethers.providers.Provider | string, account: string): Promise; /** * Gets the current allowance for the native token on the destination network. * * @param {ethers.Signer | ethers.providers.Provider | string} provider - Provider, signer or RPC URL * @param {string} account - Address to check allowance for * @returns {Promise} Current allowance amount, null if no approval needed */ getNativeAllowance(provider: ethers.Signer | ethers.providers.Provider | string, account: string): Promise; /** * Approves the specified amount of ERC20 tokens for the deposit spender. * * This method sends a transaction to approve the transfer of a specified amount of ERC20 tokens * from the signer's account to the deposit spender. The spender is determined by the deposit * logic based on the configured networks. * * @param {BigNumber} amount - The amount of ERC20 tokens to approve for transfer. * @param {ethers.Signer} signer - The signer instance used to send the approval transaction. * @returns {Promise} A promise that resolves to the transaction object of the approval. * * @throws {BridgerError} If the token address is not found or if the approval transaction fails. */ approve(amount: BigNumber, signer: ethers.Signer): Promise; approveNative(amount: BigNumber, signer: ethers.Signer): Promise; /** * Executes a token transfer between networks. * * This method initiates a transfer of either native ETH or ERC20 tokens between the origin and destination networks. * The type of transfer (deposit or withdrawal) is determined based on the configuration of the `Bridger` instance. * * @param {TransferParams} params - An object containing the parameters for the transfer: * - `amount` (BigNumber): The amount of ETH or tokens to transfer * - `signer` (ethers.Signer): The signer performing the transfer * - `destinationProvider` (ethers.providers.Provider): Provider for the destination network (required for ERC20 deposits) * - `destinationAddress` (string): The address receiving the funds. Defaults to the signer's address * - `overrides` (ethers.Overrides): Transaction overrides (optional) * * @returns {Promise} A promise that resolves to the transaction object * @throws {BridgerError} If there is an issue with the transfer operation * @throws {Error} If required parameters are missing for specific transfer types */ transfer(params: TransferParams): Promise; }