@@ -2,6 +2,7 @@ import { ContractBuilder } from './contract';
22import type { Contract } from './contract' ;
33import { defineFunctions } from './utils/define-functions' ;
44import { printContract } from './print' ;
5+ import { makeUpgradeable } from './helpers' ;
56import { defaults as commonDefaults , withCommonDefaults , type CommonOptions } from './common-options' ;
67import { setInfo } from './set-info' ;
78import {
@@ -160,18 +161,17 @@ function addBatchedExecution(c: ContractBuilder, opts: AccountOptions): void {
160161function addERC7579Modules ( c : ContractBuilder , opts : AccountOptions ) : void {
161162 if ( ! opts . ERC7579Modules ) return ;
162163
163- const baseERC7579AccountName = opts . upgradeable ? 'AccountERC7579Upgradeable' : 'AccountERC7579' ;
164- const fullERC7579AccountName = opts . upgradeable ? `${ opts . ERC7579Modules } Upgradeable` : opts . ERC7579Modules ;
165- const packageName = opts . upgradeable ? 'contracts-upgradeable' : 'contracts' ;
164+ // Base AccountERC7579 account (upgradeable or not)
165+ const name = makeUpgradeable ( 'AccountERC7579' , opts . upgradeable ) ;
166166
167167 c . addParent ( {
168- name : fullERC7579AccountName ,
169- path : `@openzeppelin/${ packageName } /account/extensions/draft-${ fullERC7579AccountName } .sol` ,
168+ name : makeUpgradeable ( opts . ERC7579Modules , opts . upgradeable ) ,
169+ path : makeUpgradeable ( `@openzeppelin/contracts /account/extensions/draft-${ opts . ERC7579Modules } .sol` , opts . upgradeable ) ,
170170 } ) ;
171- if ( baseERC7579AccountName !== fullERC7579AccountName ) {
171+ if ( opts . ERC7579Modules !== 'AccountERC7579' ) {
172172 c . addImportOnly ( {
173- name : baseERC7579AccountName ,
174- path : ` @openzeppelin/${ packageName } /account/extensions/draft-${ baseERC7579AccountName } .sol` ,
173+ name : makeUpgradeable ( 'AccountERC7579' , opts . upgradeable ) ,
174+ path : makeUpgradeable ( ' @openzeppelin/contracts /account/extensions/draft-AccountERC7579 .sol' , opts . upgradeable ) ,
175175 } ) ;
176176 }
177177
@@ -203,22 +203,22 @@ function addERC7579Modules(c: ContractBuilder, opts: AccountOptions): void {
203203 }
204204
205205 // isValidSignature override
206- c . addOverride ( { name : baseERC7579AccountName } , functions . isValidSignature ) ;
206+ c . addOverride ( { name } , functions . isValidSignature ) ;
207207 if ( opts . signatureValidation === 'ERC7739' ) {
208208 c . addOverride ( { name : 'ERC7739' } , functions . isValidSignature ) ;
209209 c . setFunctionBody (
210210 [
211211 '// ERC-7739 can return the ERC-1271 magic value, 0xffffffff (invalid) or 0x77390001 (detection).' ,
212212 '// If the returned value is 0xffffffff, fallback to ERC-7579 validation.' ,
213213 'bytes4 erc7739magic = ERC7739.isValidSignature(hash, signature);' ,
214- `return erc7739magic == bytes4(0xffffffff) ? ${ baseERC7579AccountName } .isValidSignature(hash, signature) : erc7739magic;` ,
214+ `return erc7739magic == bytes4(0xffffffff) ? ${ name } .isValidSignature(hash, signature) : erc7739magic;` ,
215215 ] ,
216216 functions . isValidSignature ,
217217 ) ;
218218 }
219219
220220 // _validateUserOp override
221- c . addOverride ( { name : baseERC7579AccountName } , functions . _validateUserOp ) ;
221+ c . addOverride ( { name } , functions . _validateUserOp ) ;
222222}
223223
224224function addSignerInitializer ( c : ContractBuilder , opts : AccountOptions ) : void {
@@ -312,8 +312,8 @@ function overrideRawSignatureValidation(c: ContractBuilder, opts: AccountOptions
312312
313313 // Disambiguate between Signer and AccountERC7579
314314 if ( opts . signer && opts . ERC7579Modules ) {
315- const accountName = opts . upgradeable ? 'AccountERC7579Upgradeable' : ' AccountERC7579';
316- const signerName = opts . upgradeable ? `Signer${ opts . signer } Upgradeable` : `Signer ${ opts . signer } ` ;
315+ const accountName = makeUpgradeable ( ' AccountERC7579', opts . upgradeable ) ;
316+ const signerName = makeUpgradeable ( `Signer${ opts . signer } ` , opts . upgradeable ) ;
317317
318318 c . addImportOnly ( {
319319 name : 'AbstractSigner' ,
@@ -334,10 +334,8 @@ function overrideRawSignatureValidation(c: ContractBuilder, opts: AccountOptions
334334 // Base override for `_rawSignatureValidation` given MultiSignerERC7913Weighted is MultiSignerERC7913
335335 if ( opts . signer === 'MultisigWeighted' ) {
336336 c . addImportOnly ( {
337- name : opts . upgradeable ? `${ signers . Multisig . name } Upgradeable` : `${ signers . Multisig . name } ` ,
338- path : opts . upgradeable
339- ? signers . Multisig . path . replace ( '.sol' , 'Upgradeable.sol' ) . replace ( `/contracts/` , `/contracts-upgradeable/` )
340- : signers . Multisig . path ,
337+ name : makeUpgradeable ( signers . Multisig . name , opts . upgradeable ) ,
338+ path : makeUpgradeable ( signers . Multisig . path , opts . upgradeable ) ,
341339 } ) ;
342340 }
343341 }
0 commit comments