UNPKG

@biconomy/sdk

Version:

SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.

58 lines 2.12 kB
import { toAcrossPlugin } from "../utils/toAcrossPlugin.js"; /** * Queries a bridge operation to determine expected outcomes and fees * * @param params - {@link QueryBridgeParams} Configuration for the bridge query * @param params.fromChain - Source chain for the bridge operation * @param params.toChain - Destination chain for the bridge operation * @param params.plugin - Optional bridging plugin (defaults to Across) * @param params.amount - Amount to bridge in base units (wei) * @param params.account - Smart account to execute the bridging * @param params.tokenMapping - Token addresses across chains * * @returns Promise resolving to {@link BridgeQueryResult} or null if received amount cannot be determined * * @throws Error if bridge plugin does not return a received amount * * @example * const result = await queryBridge({ * fromChain: optimism, * toChain: base, * amount: BigInt("1000000"), // 1 USDC * account: myMultichainAccount, * tokenMapping: { * deployments: [ * { chainId: 10, address: "0x123..." }, * { chainId: 8453, address: "0x456..." } * ], * on: (chainId) => deployments.find(d => d.chainId === chainId).address * } * }); * * if (result) { * console.log(`Expected to receive: ${result.receivedAtDestination}`); * console.log(`Expected duration: ${result.bridgingDurationExpectedMs}ms`); * } */ export const queryBridge = async (params) => { const { account, fromChain, toChain, plugin = toAcrossPlugin(), amount, tokenMapping } = params; const result = await plugin.encodeBridgeUserOp({ fromChain, toChain, account, tokenMapping, bridgingAmount: amount }); // Skip if bridge doesn't provide received amount if (!result.receivedAtDestination) return null; return { fromChainId: fromChain.id, amount, receivedAtDestination: result.receivedAtDestination, plugin, userOp: result.userOp, bridgingDurationExpectedMs: result.bridgingDurationExpectedMs }; }; //# sourceMappingURL=queryBridge.js.map