From ebc192a9975981368d8c640c25e438d5f15b8ebe Mon Sep 17 00:00:00 2001 From: livingrockrises <90545960+livingrockrises@users.noreply.github.com> Date: Sat, 9 Sep 2023 12:58:32 +0400 Subject: [PATCH] buildUserOp: force encode for batch --- packages/account/src/BiconomySmartAccountV2.ts | 12 +++++++++--- packages/account/src/utils/Types.ts | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/account/src/BiconomySmartAccountV2.ts b/packages/account/src/BiconomySmartAccountV2.ts index d6ef37097..d3cb01150 100644 --- a/packages/account/src/BiconomySmartAccountV2.ts +++ b/packages/account/src/BiconomySmartAccountV2.ts @@ -312,12 +312,18 @@ export class BiconomySmartAccountV2 extends BaseSmartAccount { const data = transactions.map((element: Transaction) => element.data ?? '0x') const value = transactions.map((element: Transaction) => element.value ?? BigNumber.from('0')) + if (transactions.length === 0) { + throw new Error('Transactions array cannot be empty') + } + let callData = '' - if (transactions.length === 1) { - callData = await this.encodeExecute(to[0], value[0], data[0]) - } else { + if (transactions.length > 1 || buildUseropDto?.forceEncodeForBatch) { callData = await this.encodeExecuteBatch(to, value, data) + } else { + // transactions.length must be 1 + callData = await this.encodeExecute(to[0], value[0], data[0]) } + let nonce = BigNumber.from(0) try { nonce = await this.getNonce() diff --git a/packages/account/src/utils/Types.ts b/packages/account/src/utils/Types.ts index 975280662..c7e867b14 100644 --- a/packages/account/src/utils/Types.ts +++ b/packages/account/src/utils/Types.ts @@ -76,6 +76,7 @@ export type BuildUserOpOptions = { overrides?: Overrides skipBundlerGasEstimation?: boolean params?: ModuleInfo + forceEncodeForBatch?: boolean } export type Overrides = {