UNPKG

onesec-bridge

Version:
96 lines (95 loc) 3.68 kB
import { Principal } from "@dfinity/principal"; import { Signer } from "ethers"; import { BridgingPlan } from "../.."; import { type Config } from "../../config"; import type { Deployment, EvmChain, Token } from "../../types"; /** * Builder for creating EVM to ICP token bridging plans. * * Supports two bridging modes: * - Direct bridging via `build()` - requires user to connect wallet and sign transactions * - Forwarding via `forward()` - user sends tokens to a generated forwarding address * * @example * ```typescript * // Direct bridging * const plan = await new EvmToIcpBridgeBuilder("Base", "USDC") * .receiver(icpPrincipal) * .amountInUnits(1_500_000n) // 1.5 USDC * .build(evmSigner); * * // Forwarding (no signer needed) * const plan = await new EvmToIcpBridgeBuilder("Base", "USDC") * .receiver(icpPrincipal) * .amountInUnits(1_500_000n) * .forward(); * ``` */ export declare class EvmToIcpBridgeBuilder { private evmChain; private token; private _deployment; private evmAddress?; private evmAmountInUnits?; private evmAmountInTokens?; private icpAccount?; private config?; /** * @param evmChain Source EVM chain (e.g., "Base", "Arbitrum", "Ethereum") * @param token Token to bridge (e.g., "USDC", "ICP") */ constructor(evmChain: EvmChain, token: Token); /** * Set target deployment network. * @param deployment Target network ("Mainnet", "Testnet", or "Local") */ deployment(deployment: Deployment): EvmToIcpBridgeBuilder; /** * Set sender EVM address. Optional for direct bridging (inferred from signer). * @param evmAddress EVM address sending the tokens */ sender(evmAddress: string): EvmToIcpBridgeBuilder; /** * 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): EvmToIcpBridgeBuilder; /** * 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): EvmToIcpBridgeBuilder; /** * Set ICP recipient account. * @param principal ICP principal receiving the tokens * @param subaccount Optional 32-byte subaccount */ receiver(principal: Principal, subaccount?: Uint8Array): EvmToIcpBridgeBuilder; /** * Use custom configuration instead of defaults. * @param config Custom bridge configuration */ withConfig(config: Config): EvmToIcpBridgeBuilder; /** * Build a direct bridging plan that requires wallet interaction. * * Creates a multi-step plan including: fee validation, EVM transaction approval/submission, * block confirmation, receipt validation, and ICP transfer completion. * * @param signer Ethereum signer to approve and submit transactions * @returns Executable bridging plan * @throws Error if required parameters (amount, receiver) are missing */ build(signer: Signer): Promise<BridgingPlan>; /** * Build a forwarding-based bridging plan that doesn't require wallet connection. * * Creates a plan that generates a unique forwarding address where users can send tokens. * The plan includes: fee validation, address generation, payment notification, transaction * detection, block confirmation, receipt validation, and ICP transfer completion. * * @returns Executable bridging plan that provides a forwarding address * @throws Error if required parameters (amount, receiver) are missing */ forward(): Promise<BridgingPlan>; }