UNPKG

@biconomy/abstractjs

Version:

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

36 lines 1.47 kB
import { buildBatch } from "../decorators/instructions/buildBatch.js"; /** * Groups all the instructions with the same chainId into batches. * * @param parameters - The parameters for the batching. * @param parameters.accountAddress - The account address to execute the instructions on. * @param parameters.triggerCall - The first instruction to be executed. * @param parameters.instructions - The remaining instructions to be executed. * * @returns An array of instructions, where all the same-chain instructions are batched together. */ export const batchInstructions = async (parameters) => { const { accountAddress, instructions, meeVersions } = parameters; const result = []; const batchesByChainId = new Map(); const chainIds = new Set(); for (const instruction of instructions) { const chainId = String(instruction.chainId); chainIds.add(chainId); const batch = batchesByChainId.get(chainId) || []; batch.push(instruction); batchesByChainId.set(chainId, batch); } for (const chainId of [...chainIds]) { const batch = batchesByChainId.get(chainId) || []; if (batch.length > 1) { const [batchedInx] = await buildBatch({ accountAddress, meeVersions }, { instructions: batch }); result.push(batchedInx); } else { result.push(...batch); } } return result; }; //# sourceMappingURL=batchInstructions.js.map