UNPKG

@biconomy/abstractjs

Version:

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

61 lines 2.25 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.depositor - Account address of the source chain * @param params.recipient - Account address of the destination chain * @param params.fromChainId - Source chain id for the bridge operation * @param params.toChainId - Destination chain id 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.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({ * depositor: "0xabc...", * recipient: "0xdef...", * fromChainId: 10, * toChainId: 8453, * amount: BigInt("1000000"), // 1 USDC * 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 { depositor, recipient, fromChainId, toChainId, plugin = toAcrossPlugin(), amount, tokenMapping } = params; const result = await plugin.encodeBridgeUserOp({ depositor, recipient, fromChainId, toChainId, tokenMapping, bridgingAmount: amount }); // Skip if bridge doesn't provide received amount if (!result.receivedAtDestination) return null; return { fromChainId: fromChainId, amount, receivedAtDestination: result.receivedAtDestination, plugin, userOp: result.userOp, bridgingDurationExpectedMs: result.bridgingDurationExpectedMs }; }; //# sourceMappingURL=queryBridge.js.map