UNPKG

onesec-bridge

Version:
102 lines (101 loc) 3.73 kB
import { Agent } from "@dfinity/agent"; import { Principal } from "@dfinity/principal"; import { BridgingPlan } from "../.."; import { Config } from "../../config"; import { Deployment, EvmChain, Token } from "../../types"; /** * Builder for creating ICP to EVM token bridging plans. * * Transfers tokens from ICP ledgers to EVM networks. Requires an authenticated * agent to interact with ICP canisters on behalf of the user. * * @example * ```typescript * const agent = HttpAgent.createSync({ * identity: icpIdentity, * host: "https://ic0.app" * }); * * const plan = await new IcpToEvmBridgeBuilder(agent, "Base", "USDC") * .sender(icpPrincipal) * .receiver("0x742d35Cc6575C4B9bE904C1e13D21c4C624A9960") * .amountInUnits(1_500_000n) // 1.5 USDC * .build(); * ``` */ export declare class IcpToEvmBridgeBuilder { private agent; private evmChain; private token; private _deployment; private icpAmountInUnits?; private icpAmountInTokens?; private icpAccount?; private evmAddress?; private approveFeeInAmount; private config?; /** * @param agent Authenticated ICP agent to interact with canisters * @param evmChain Target EVM chain (e.g., "Base", "Arbitrum", "Ethereum") * @param token Token to bridge (e.g., "USDC", "ICP") */ constructor(agent: Agent, evmChain: EvmChain, token: Token); /** * Set target deployment network. * @param deployment Target network ("Mainnet", "Testnet", or "Local") */ deployment(deployment: Deployment): IcpToEvmBridgeBuilder; /** * Set sender ICP account. * @param principal ICP principal sending the tokens * @param subaccount Optional 32-byte subaccount */ sender(principal: Principal, subaccount?: Uint8Array): IcpToEvmBridgeBuilder; /** * Set EVM recipient address. * @param address EVM address receiving the tokens */ receiver(address: string): IcpToEvmBridgeBuilder; /** * Set amount to bridge in token's smallest units. * @param amount Amount in base units (e.g., 1_500_000n for 1.5 USDC) */ amountInUnits(amount: bigint): IcpToEvmBridgeBuilder; /** * Set amount to bridge in human-readable token units. * @param amount Amount in token units (e.g., 1.5 for 1.5 USDC) */ amountInTokens(amount: number): IcpToEvmBridgeBuilder; /** * Deduct the ledger approval fee from the bridging amount. * * When enabled, the approval fee is subtracted from the specified amount, so the user * only needs to have exactly the bridging amount in their account rather than * bridging amount + approval fee. * * @example * ```typescript * // Without payApproveFeeFromAmount(): User needs 1.5 USDC + approval fee * const plan1 = await builder.amountInUnits(1_500_000n).build(); * * // With payApproveFeeFromAmount(): User needs exactly 1.5 USDC, approval fee deducted from amount * const plan2 = await builder.amountInUnits(1_500_000n).payApproveFeeFromAmount().build(); * ``` */ payApproveFeeFromAmount(): IcpToEvmBridgeBuilder; /** * Use custom configuration instead of defaults. * @param config Custom bridge configuration */ withConfig(config: Config): IcpToEvmBridgeBuilder; /** * Build an ICP to EVM bridging plan. * * Creates a multi-step plan including: fee validation, ICP token approval/transfer, * EVM transaction signing/submission, block confirmation, and receipt validation. * * @returns Executable bridging plan * @throws Error if required parameters (sender, receiver, amount) are missing */ build(): Promise<BridgingPlan>; }