@@ -2,13 +2,11 @@ import { ContractBuilder } from './contract';
2
2
import type { Contract } from './contract' ;
3
3
import { defineFunctions } from './utils/define-functions' ;
4
4
import { printContract } from './print' ;
5
- import { makeUpgradeable } from './helpers' ;
6
5
import { defaults as commonDefaults , withCommonDefaults , type CommonOptions } from './common-options' ;
6
+ import { upgradeableName } from './options' ;
7
7
import { setInfo } from './set-info' ;
8
8
import {
9
- addLockingConstructorAllowReachable ,
10
9
addSigner ,
11
- signerArgs ,
12
10
signerFunctions ,
13
11
signers ,
14
12
type SignerOptions ,
@@ -75,6 +73,7 @@ export function buildAccount(opts: AccountOptions): Contract {
75
73
c . addImportOnly ( {
76
74
name : 'PackedUserOperation' ,
77
75
path : '@openzeppelin/contracts/interfaces/draft-IERC4337.sol' ,
76
+ transpiled : false , // PackedUserOperation doesn't start with "I" so its not recognized as an "interface object"
78
77
} ) ;
79
78
}
80
79
@@ -86,16 +85,16 @@ function addParents(c: ContractBuilder, opts: AccountOptions): void {
86
85
c . addParent ( {
87
86
name : 'Account' ,
88
87
path : `@openzeppelin/contracts/account/Account.sol` ,
88
+ transpiled : false ,
89
89
} ) ;
90
- c . addOverride ( { name : 'Account' } , functions . _validateUserOp ) ;
90
+ c . addOverride ( { name : 'Account' , transpiled : false } , functions . _validateUserOp ) ;
91
91
92
92
if ( opts . signatureValidation === 'ERC7739' ) addEIP712 ( c , opts ) ;
93
93
94
94
// Extensions
95
95
addSignatureValidation ( c , opts ) ;
96
96
addERC7579Modules ( c , opts ) ;
97
97
addSigner ( c , opts . signer ?? false , opts . upgradeable ?? false ) ;
98
- addSignerInitializer ( c , opts ) ;
99
98
addMultisigFunctions ( c , opts ) ;
100
99
addBatchedExecution ( c , opts ) ;
101
100
addERC721Holder ( c , opts ) ;
@@ -108,6 +107,7 @@ function addSignatureValidation(c: ContractBuilder, opts: AccountOptions) {
108
107
c . addParent ( {
109
108
name : 'ERC7739' ,
110
109
path : '@openzeppelin/contracts/utils/cryptography/signers/draft-ERC7739.sol' ,
110
+ transpiled : false ,
111
111
} ) ;
112
112
break ;
113
113
case 'ERC1271' :
@@ -133,6 +133,7 @@ function addERC721Holder(c: ContractBuilder, opts: AccountOptions): void {
133
133
c . addParent ( {
134
134
name : 'ERC721Holder' ,
135
135
path : '@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol' ,
136
+ transpiled : false ,
136
137
} ) ;
137
138
}
138
139
@@ -141,6 +142,7 @@ function addERC1155Holder(c: ContractBuilder, opts: AccountOptions): void {
141
142
c . addParent ( {
142
143
name : 'ERC1155Holder' ,
143
144
path : '@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol' ,
145
+ transpiled : false ,
144
146
} ) ;
145
147
}
146
148
@@ -150,8 +152,9 @@ function addBatchedExecution(c: ContractBuilder, opts: AccountOptions): void {
150
152
c . addParent ( {
151
153
name : 'ERC7821' ,
152
154
path : '@openzeppelin/contracts/account/extensions/draft-ERC7821.sol' ,
155
+ transpiled : false ,
153
156
} ) ;
154
- c . addOverride ( { name : 'ERC7821' } , functions . _erc7821AuthorizedExecutor ) ;
157
+ c . addOverride ( { name : 'ERC7821' , transpiled : false } , functions . _erc7821AuthorizedExecutor ) ;
155
158
c . setFunctionBody (
156
159
[ 'return caller == address(entryPoint()) || super._erc7821AuthorizedExecutor(caller, mode, executionData);' ] ,
157
160
functions . _erc7821AuthorizedExecutor ,
@@ -162,59 +165,38 @@ function addERC7579Modules(c: ContractBuilder, opts: AccountOptions): void {
162
165
if ( ! opts . ERC7579Modules ) return ;
163
166
164
167
// Base AccountERC7579 account (upgradeable or not)
165
- const name = makeUpgradeable ( 'AccountERC7579' , opts . upgradeable ) ;
168
+ const name = 'AccountERC7579' ;
166
169
167
170
c . addParent ( {
168
- name : makeUpgradeable ( opts . ERC7579Modules , opts . upgradeable ) ,
169
- path : makeUpgradeable (
170
- `@openzeppelin/contracts/account/extensions/draft-${ opts . ERC7579Modules } .sol` ,
171
- opts . upgradeable ,
172
- ) ,
171
+ name : opts . ERC7579Modules ,
172
+ path : `@openzeppelin/contracts/account/extensions/draft-${ opts . ERC7579Modules } .sol` ,
173
173
} ) ;
174
174
if ( opts . ERC7579Modules !== 'AccountERC7579' ) {
175
175
c . addImportOnly ( {
176
- name : makeUpgradeable ( 'AccountERC7579' , opts . upgradeable ) ,
177
- path : makeUpgradeable ( '@openzeppelin/contracts/account/extensions/draft-AccountERC7579.sol' , opts . upgradeable ) ,
176
+ name : 'AccountERC7579' ,
177
+ path : '@openzeppelin/contracts/account/extensions/draft-AccountERC7579.sol' ,
178
178
} ) ;
179
179
}
180
180
181
181
// Accounts that use ERC7579 without a signer must be constructed with at least one module (executor of validation)
182
182
if ( ! opts . signer ) {
183
- const args = [
184
- { type : 'uint256' , name : 'moduleTypeId' } ,
185
- { type : 'address' , name : 'module' } ,
186
- { type : 'bytes calldata' , name : 'initData' } ,
187
- ] ;
188
- const body = [
189
- 'require(moduleTypeId == MODULE_TYPE_VALIDATOR || moduleTypeId == MODULE_TYPE_EXECUTOR);' ,
190
- '_installModule(moduleTypeId, module, initData);' ,
191
- ] ;
192
- if ( opts . upgradeable ) {
193
- c . addParent ( {
194
- name : 'Initializable' ,
195
- path : '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol' ,
196
- } ) ;
197
- addLockingConstructorAllowReachable ( c ) ;
198
-
199
- const fn = { name : 'initialize' , kind : 'public' as const , args } ;
200
- c . addModifier ( 'initializer' , fn ) ;
201
- c . setFunctionBody ( body , fn ) ;
202
- } else {
203
- for ( const arg of args ) c . addConstructorArgument ( arg ) ;
204
- for ( const line of body ) c . addConstructorCode ( line ) ;
205
- }
183
+ c . addConstructorArgument ( { type : 'uint256' , name : 'moduleTypeId' } ) ;
184
+ c . addConstructorArgument ( { type : 'address' , name : 'module' } ) ;
185
+ c . addConstructorArgument ( { type : 'bytes calldata' , name : 'initData' } ) ;
186
+ c . addConstructorCode ( 'require(moduleTypeId == MODULE_TYPE_VALIDATOR || moduleTypeId == MODULE_TYPE_EXECUTOR);' ) ;
187
+ c . addConstructorCode ( '_installModule(moduleTypeId, module, initData);' ) ;
206
188
}
207
189
208
190
// isValidSignature override
209
191
c . addOverride ( { name } , functions . isValidSignature ) ;
210
192
if ( opts . signatureValidation === 'ERC7739' ) {
211
- c . addOverride ( { name : 'ERC7739' } , functions . isValidSignature ) ;
193
+ c . addOverride ( { name : 'ERC7739' , transpiled : false } , functions . isValidSignature ) ;
212
194
c . setFunctionBody (
213
195
[
214
196
'// ERC-7739 can return the ERC-1271 magic value, 0xffffffff (invalid) or 0x77390001 (detection).' ,
215
197
'// If the returned value is 0xffffffff, fallback to ERC-7579 validation.' ,
216
198
'bytes4 erc7739magic = ERC7739.isValidSignature(hash, signature);' ,
217
- `return erc7739magic == bytes4(0xffffffff) ? ${ name } .isValidSignature(hash, signature) : erc7739magic;` ,
199
+ `return erc7739magic == bytes4(0xffffffff) ? ${ opts . upgradeable ? upgradeableName ( name ) : name } .isValidSignature(hash, signature) : erc7739magic;` ,
218
200
] ,
219
201
functions . isValidSignature ,
220
202
) ;
@@ -224,51 +206,6 @@ function addERC7579Modules(c: ContractBuilder, opts: AccountOptions): void {
224
206
c . addOverride ( { name } , functions . _validateUserOp ) ;
225
207
}
226
208
227
- function addSignerInitializer ( c : ContractBuilder , opts : AccountOptions ) : void {
228
- if ( opts . upgradeable ) {
229
- if ( ! opts . signer ) {
230
- addLockingConstructorAllowReachable ( c ) ;
231
- }
232
- return ; // Initializer added in signer.ts
233
- }
234
- if ( ! opts . signer || opts . signer === 'ERC7702' ) return ; // No initialization required
235
-
236
- c . addParent ( {
237
- name : 'Initializable' ,
238
- path : opts . upgradeable
239
- ? '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'
240
- : '@openzeppelin/contracts/proxy/utils/Initializable.sol' ,
241
- } ) ;
242
-
243
- addLockingConstructorAllowReachable ( c , [
244
- '// Accounts are typically deployed and initialized as clones during their first user op,' ,
245
- '// therefore, initializers are disabled for the implementation contract' ,
246
- ] ) ;
247
-
248
- const fn = { name : 'initialize' , kind : 'public' as const , args : signerArgs [ opts . signer ] } ;
249
- c . addModifier ( 'initializer' , fn ) ;
250
-
251
- switch ( opts . signer ) {
252
- case 'Multisig' :
253
- c . addFunctionCode ( `_addSigners(${ signerArgs [ opts . signer ] [ 0 ] ! . name } );` , fn ) ;
254
- c . addFunctionCode ( `_setThreshold(${ signerArgs [ opts . signer ] [ 1 ] ! . name } );` , fn ) ;
255
- break ;
256
- case 'MultisigWeighted' :
257
- c . addFunctionCode ( `_addSigners(${ signerArgs [ opts . signer ] [ 0 ] ! . name } );` , fn ) ;
258
- c . addFunctionCode (
259
- `_setSignerWeights(${ signerArgs [ opts . signer ] [ 0 ] ! . name } , ${ signerArgs [ opts . signer ] [ 1 ] ! . name } );` ,
260
- fn ,
261
- ) ;
262
- c . addFunctionCode ( `_setThreshold(${ signerArgs [ opts . signer ] [ 2 ] ! . name } );` , fn ) ;
263
- break ;
264
- case 'ECDSA' :
265
- case 'P256' :
266
- case 'RSA' :
267
- c . addFunctionCode ( `_setSigner(${ signerArgs [ opts . signer ] . map ( ( { name } ) => name ) . join ( ', ' ) } );` , fn ) ;
268
- break ;
269
- }
270
- }
271
-
272
209
function addMultisigFunctions ( c : ContractBuilder , opts : AccountOptions ) : void {
273
210
switch ( opts . signer ) {
274
211
case 'MultisigWeighted' :
@@ -296,6 +233,7 @@ function addEIP712(c: ContractBuilder, opts: AccountOptions): void {
296
233
{
297
234
name : 'EIP712' ,
298
235
path : '@openzeppelin/contracts/utils/cryptography/EIP712.sol' ,
236
+ transpiled : false , // do not use the upgradeable variant for in Accounts
299
237
} ,
300
238
[ opts . name , '1' ] ,
301
239
) ;
@@ -309,21 +247,22 @@ function overrideRawSignatureValidation(c: ContractBuilder, opts: AccountOptions
309
247
// to provide a custom validation logic
310
248
if ( ! opts . signer && ! opts . ERC7579Modules ) {
311
249
// Custom validation logic
312
- c . addOverride ( { name : 'Account' } , signerFunctions . _rawSignatureValidation ) ;
250
+ c . addOverride ( { name : 'Account' , transpiled : false } , signerFunctions . _rawSignatureValidation ) ;
313
251
c . setFunctionBody ( [ '// Custom validation logic' , 'return false;' ] , signerFunctions . _rawSignatureValidation ) ;
314
252
}
315
253
316
254
// Disambiguate between Signer and AccountERC7579
317
255
if ( opts . signer && opts . ERC7579Modules ) {
318
- const accountName = makeUpgradeable ( 'AccountERC7579' , opts . upgradeable ) ;
319
- const signerName = makeUpgradeable ( `Signer${ opts . signer } ` , opts . upgradeable ) ;
256
+ const accountName = opts . upgradeable ? upgradeableName ( 'AccountERC7579' ) : 'AccountERC7579' ;
257
+ const signerName = opts . upgradeable ? upgradeableName ( `Signer${ opts . signer } ` ) : `Signer ${ opts . signer } ` ;
320
258
321
259
c . addImportOnly ( {
322
260
name : 'AbstractSigner' ,
323
261
path : '@openzeppelin/contracts/utils/cryptography/signers/AbstractSigner.sol' ,
262
+ transpiled : false ,
324
263
} ) ;
325
- c . addOverride ( { name : 'AbstractSigner' } , signerFunctions . _rawSignatureValidation ) ;
326
- c . addOverride ( { name : accountName } , signerFunctions . _rawSignatureValidation ) ;
264
+ c . addOverride ( { name : 'AbstractSigner' , transpiled : false } , signerFunctions . _rawSignatureValidation ) ;
265
+ c . addOverride ( { name : 'AccountERC7579' } , signerFunctions . _rawSignatureValidation ) ;
327
266
c . setFunctionComments (
328
267
[
329
268
`// IMPORTANT: Make sure ${ signerName } is most derived than ${ accountName } ` ,
@@ -337,8 +276,8 @@ function overrideRawSignatureValidation(c: ContractBuilder, opts: AccountOptions
337
276
// Base override for `_rawSignatureValidation` given MultiSignerERC7913Weighted is MultiSignerERC7913
338
277
if ( opts . signer === 'MultisigWeighted' ) {
339
278
c . addImportOnly ( {
340
- name : makeUpgradeable ( signers . Multisig . name , opts . upgradeable ) ,
341
- path : makeUpgradeable ( signers . Multisig . path , opts . upgradeable ) ,
279
+ name : signers . Multisig . name ,
280
+ path : signers . Multisig . path ,
342
281
} ) ;
343
282
}
344
283
}
0 commit comments