From f624829a4c41ddccd2b30ae2c251ff70abe864c2 Mon Sep 17 00:00:00 2001 From: Sherif Abdelmoatty Date: Sun, 15 Dec 2024 00:48:19 +0300 Subject: [PATCH] add expectedSigners to estimateUserOperationGas --- src/account/Safe/SafeAccount.ts | 72 ++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/src/account/Safe/SafeAccount.ts b/src/account/Safe/SafeAccount.ts index 5814352..d084279 100644 --- a/src/account/Safe/SafeAccount.ts +++ b/src/account/Safe/SafeAccount.ts @@ -1010,33 +1010,78 @@ export class SafeAccount extends SmartAccount { overrides: { stateOverrideSet?: StateOverrideSet; dummySignerSignaturePairs?: SignerSignaturePair[]; + expectedSigners?: Signer[]; + webAuthnSharedSigner?: string; + webAuthnSignerFactory?: string; + webAuthnSignerSingleton?: string; + eip7212WebAuthnPrecompileVerifier?: string; + eip7212WebAuthnContractVerifier?: string; } = {}, ): Promise<[bigint, bigint, bigint]> { + const validAfter = 0xffffffffffffn; + const validUntil = 0xffffffffffffn; + if (overrides.dummySignerSignaturePairs != null) { + if(overrides.expectedSigners != null){ + throw RangeError( + "Can't use both dummySignerSignaturePairs and expectedSigners overrides.", + ); + } if (overrides.dummySignerSignaturePairs.length < 1) { throw RangeError( "Number of dummy signers signature pairs can't be less than 1", ); } - - userOperation.signature = + userOperation.signature = SafeAccount.formatSignaturesToUseroperationSignature( overrides.dummySignerSignaturePairs, { - validAfter: 0xffffffffffffn, - validUntil: 0xffffffffffffn, + validAfter, + validUntil, }, ); + } else if (overrides.expectedSigners != null) { + let initCode; + + if ("initCode" in userOperation) { + initCode = userOperation.initCode; + }else{ + initCode = userOperation.factory; + } + const isInit = initCode != null && initCode != "0x"; + + const dummySignerSignaturePairs = SafeAccount.createDummySignerSignaturePairForExpectedSigners( + overrides.expectedSigners, + { + isInit, + webAuthnSharedSigner:overrides.webAuthnSharedSigner, + eip7212WebAuthnPrecompileVerifier:overrides.eip7212WebAuthnPrecompileVerifier, + eip7212WebAuthnContractVerifier:overrides.eip7212WebAuthnContractVerifier, + webAuthnSignerFactory:overrides.webAuthnSignerFactory, + webAuthnSignerSingleton:overrides.webAuthnSignerSingleton, + validAfter, + validUntil, + } + ) + userOperation.signature = + SafeAccount.formatSignaturesToUseroperationSignature( + dummySignerSignaturePairs, + { + validAfter, + validUntil, + }, + ); } else if (userOperation.signature.length < 3) { - userOperation.signature = - SafeAccount.formatSignaturesToUseroperationSignature( - [EOADummySignerSignaturePair], - { - validAfter: 0xffffffffffffn, - validUntil: 0xffffffffffffn, - }, - ); - } + userOperation.signature = + SafeAccount.formatSignaturesToUseroperationSignature( + [EOADummySignerSignaturePair], + { + validAfter, + validUntil, + }, + ); + } + const bundler = new Bundler(bundlerRpc); const inputMaxFeePerGas = userOperation.maxFeePerGas; @@ -1426,7 +1471,6 @@ export class SafeAccount extends SmartAccount { bundlerRpc, { stateOverrideSet: overrides.state_override_set, - dummySignerSignaturePairs: overrides.dummySignerSignaturePairs, }, ); verificationGasLimit +=