@openzeppelin/wizard 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -3
- package/dist/account.d.ts +20 -0
- package/dist/account.d.ts.map +1 -0
- package/dist/account.js +252 -0
- package/dist/account.js.map +1 -0
- package/dist/api.d.ts +12 -7
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +6 -1
- package/dist/api.js.map +1 -1
- package/dist/build-generic.d.ts +4 -0
- package/dist/build-generic.d.ts.map +1 -1
- package/dist/build-generic.js +3 -0
- package/dist/build-generic.js.map +1 -1
- package/dist/environments/hardhat/package-lock.json +3 -3
- package/dist/environments/hardhat/upgradeable/package-lock.json +7 -7
- package/dist/erc20.js +1 -1
- package/dist/erc20.js.map +1 -1
- package/dist/generate/account.d.ts +3 -0
- package/dist/generate/account.d.ts.map +1 -0
- package/dist/generate/account.js +21 -0
- package/dist/generate/account.js.map +1 -0
- package/dist/generate/sources.d.ts.map +1 -1
- package/dist/generate/sources.js +6 -0
- package/dist/generate/sources.js.map +1 -1
- package/dist/governor.d.ts.map +1 -1
- package/dist/governor.js +7 -7
- package/dist/governor.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/kind.js +2 -1
- package/dist/kind.js.map +1 -1
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +2 -1
- package/dist/print.js.map +1 -1
- package/dist/signer.d.ts +39 -0
- package/dist/signer.d.ts.map +1 -0
- package/dist/signer.js +115 -0
- package/dist/signer.js.map +1 -0
- package/dist/solidity-version.json +1 -1
- package/dist/stablecoin.js +2 -2
- package/dist/stablecoin.js.map +1 -1
- package/dist/test.js +17 -6
- package/dist/test.js.map +1 -1
- package/dist/utils/sanitize.d.ts +2 -0
- package/dist/utils/sanitize.d.ts.map +1 -0
- package/dist/utils/sanitize.js +9 -0
- package/dist/utils/sanitize.js.map +1 -0
- package/dist/zip-foundry.js +4 -4
- package/package.json +6 -7
- package/src/account.ts +292 -0
- package/src/api.ts +16 -7
- package/src/build-generic.ts +6 -0
- package/src/environments/hardhat/package-lock.json +3 -3
- package/src/environments/hardhat/upgradeable/package-lock.json +7 -7
- package/src/erc20.ts +1 -1
- package/src/generate/account.ts +20 -0
- package/src/generate/sources.ts +7 -0
- package/src/governor.ts +9 -8
- package/src/index.ts +1 -1
- package/src/kind.ts +2 -1
- package/src/print.ts +2 -1
- package/src/signer.ts +124 -0
- package/src/solidity-version.json +1 -1
- package/src/stablecoin.ts +2 -2
- package/src/test.ts +17 -5
- package/src/utils/sanitize.ts +6 -0
- package/src/zip-foundry.ts +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openzeppelin/wizard",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "A boilerplate generator to get started with OpenZeppelin Contracts",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": "https://github.com/OpenZeppelin/contracts-wizard",
|
|
@@ -19,17 +19,16 @@
|
|
|
19
19
|
"test": "ava",
|
|
20
20
|
"test:update-snapshots": "ava --update-snapshots",
|
|
21
21
|
"test:watch": "ava --watch",
|
|
22
|
-
"version": "node ../../../scripts/bump-changelog.js",
|
|
23
22
|
"update-env": "rm ./src/environments/hardhat/package-lock.json && npm install --package-lock-only --prefix ./src/environments/hardhat && rm ./src/environments/hardhat/upgradeable/package-lock.json && npm install --package-lock-only --prefix ./src/environments/hardhat/upgradeable"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
25
|
"@openzeppelin/community-contracts": "https://github.com/OpenZeppelin/openzeppelin-community-contracts",
|
|
27
|
-
"@openzeppelin/contracts": "^5.
|
|
28
|
-
"@openzeppelin/contracts-upgradeable": "^5.
|
|
29
|
-
"@types/node": "^
|
|
26
|
+
"@openzeppelin/contracts": "^5.3.0",
|
|
27
|
+
"@openzeppelin/contracts-upgradeable": "^5.3.0",
|
|
28
|
+
"@types/node": "^20.0.0",
|
|
30
29
|
"@types/semver": "^7.5.7",
|
|
31
30
|
"ava": "^6.0.0",
|
|
32
|
-
"hardhat": "^2.
|
|
31
|
+
"hardhat": "^2.22.11",
|
|
33
32
|
"jszip": "^3.6.0",
|
|
34
33
|
"rimraf": "^5.0.0",
|
|
35
34
|
"semver": "^7.6.0",
|
|
@@ -37,4 +36,4 @@
|
|
|
37
36
|
"ts-node": "^10.4.0",
|
|
38
37
|
"typescript": "^5.0.0"
|
|
39
38
|
}
|
|
40
|
-
}
|
|
39
|
+
}
|
package/src/account.ts
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { ContractBuilder } from './contract';
|
|
2
|
+
import type { Contract } from './contract';
|
|
3
|
+
import { defineFunctions } from './utils/define-functions';
|
|
4
|
+
import { printContract } from './print';
|
|
5
|
+
import { defaults as commonDefaults, withCommonDefaults, type CommonOptions } from './common-options';
|
|
6
|
+
import { setInfo } from './set-info';
|
|
7
|
+
import { addSigner, signerFunctions, signers, type SignerOptions } from './signer';
|
|
8
|
+
|
|
9
|
+
export const defaults: Required<AccountOptions> = {
|
|
10
|
+
...commonDefaults,
|
|
11
|
+
name: 'MyAccount',
|
|
12
|
+
signatureValidation: 'ERC7739',
|
|
13
|
+
ERC721Holder: true,
|
|
14
|
+
ERC1155Holder: true,
|
|
15
|
+
signer: 'ECDSA',
|
|
16
|
+
batchedExecution: false,
|
|
17
|
+
ERC7579Modules: false,
|
|
18
|
+
} as const;
|
|
19
|
+
|
|
20
|
+
export const SignatureValidationOptions = [false, 'ERC1271', 'ERC7739'] as const;
|
|
21
|
+
export type SignatureValidationOptions = (typeof SignatureValidationOptions)[number];
|
|
22
|
+
|
|
23
|
+
export const ERC7579ModulesOptions = [false, 'AccountERC7579', 'AccountERC7579Hooked'] as const;
|
|
24
|
+
export type ERC7579ModulesOptions = (typeof ERC7579ModulesOptions)[number];
|
|
25
|
+
|
|
26
|
+
export interface AccountOptions extends CommonOptions {
|
|
27
|
+
name: string;
|
|
28
|
+
signatureValidation?: SignatureValidationOptions;
|
|
29
|
+
ERC721Holder?: boolean;
|
|
30
|
+
ERC1155Holder?: boolean;
|
|
31
|
+
signer?: SignerOptions;
|
|
32
|
+
batchedExecution?: boolean;
|
|
33
|
+
ERC7579Modules?: ERC7579ModulesOptions;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function withDefaults(opts: AccountOptions): Required<AccountOptions> {
|
|
37
|
+
return {
|
|
38
|
+
...withCommonDefaults(opts),
|
|
39
|
+
name: opts.name ?? defaults.name,
|
|
40
|
+
signatureValidation: opts.signatureValidation ?? defaults.signatureValidation,
|
|
41
|
+
ERC721Holder: opts.ERC721Holder ?? defaults.ERC721Holder,
|
|
42
|
+
ERC1155Holder: opts.ERC1155Holder ?? defaults.ERC1155Holder,
|
|
43
|
+
signer: opts.signer ?? defaults.signer,
|
|
44
|
+
batchedExecution: opts.batchedExecution ?? defaults.batchedExecution,
|
|
45
|
+
ERC7579Modules: opts.ERC7579Modules ?? defaults.ERC7579Modules,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function printAccount(opts: AccountOptions = defaults): string {
|
|
50
|
+
return printContract(buildAccount(opts));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function buildAccount(opts: AccountOptions): Contract {
|
|
54
|
+
const allOpts = withDefaults(opts);
|
|
55
|
+
|
|
56
|
+
allOpts.upgradeable = false; // Upgradeability is not yet available for the community contracts
|
|
57
|
+
allOpts.access = false; // Access control options are not used for Account
|
|
58
|
+
|
|
59
|
+
const c = new ContractBuilder(allOpts.name);
|
|
60
|
+
|
|
61
|
+
addParents(c, allOpts);
|
|
62
|
+
overrideRawSignatureValidation(c, allOpts);
|
|
63
|
+
setInfo(c, allOpts.info);
|
|
64
|
+
|
|
65
|
+
if (opts.ERC7579Modules) {
|
|
66
|
+
c.addImportOnly({
|
|
67
|
+
name: 'PackedUserOperation',
|
|
68
|
+
path: '@openzeppelin/contracts/interfaces/draft-IERC4337.sol',
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return c;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function addParents(c: ContractBuilder, opts: AccountOptions): void {
|
|
76
|
+
// Base
|
|
77
|
+
c.addParent({
|
|
78
|
+
name: 'Account',
|
|
79
|
+
path: `@openzeppelin/community-contracts/account/Account.sol`,
|
|
80
|
+
});
|
|
81
|
+
c.addOverride({ name: 'Account' }, functions._validateUserOp);
|
|
82
|
+
|
|
83
|
+
if (opts.signatureValidation === 'ERC7739') addEIP712(c, opts);
|
|
84
|
+
|
|
85
|
+
// Extensions
|
|
86
|
+
addSignatureValidation(c, opts);
|
|
87
|
+
addERC7579Modules(c, opts);
|
|
88
|
+
addSigner(c, opts.signer ?? false);
|
|
89
|
+
addMultisigFunctions(c, opts);
|
|
90
|
+
addBatchedExecution(c, opts);
|
|
91
|
+
addERC721Holder(c, opts);
|
|
92
|
+
addERC1155Holder(c, opts);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function addSignatureValidation(c: ContractBuilder, opts: AccountOptions) {
|
|
96
|
+
switch (opts.signatureValidation) {
|
|
97
|
+
case 'ERC7739':
|
|
98
|
+
c.addParent({
|
|
99
|
+
name: 'ERC7739',
|
|
100
|
+
path: '@openzeppelin/community-contracts/utils/cryptography/ERC7739.sol',
|
|
101
|
+
});
|
|
102
|
+
break;
|
|
103
|
+
case 'ERC1271':
|
|
104
|
+
c.addParent({
|
|
105
|
+
name: 'IERC1271',
|
|
106
|
+
path: '@openzeppelin/contracts/interfaces/IERC1271.sol',
|
|
107
|
+
});
|
|
108
|
+
c.addOverride({ name: 'IERC1271' }, functions.isValidSignature);
|
|
109
|
+
if (!opts.ERC7579Modules) {
|
|
110
|
+
c.setFunctionBody(
|
|
111
|
+
[
|
|
112
|
+
'return _rawSignatureValidation(hash, signature) ? IERC1271.isValidSignature.selector : bytes4(0xffffffff);',
|
|
113
|
+
],
|
|
114
|
+
functions.isValidSignature,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function addERC721Holder(c: ContractBuilder, opts: AccountOptions): void {
|
|
122
|
+
if (!opts.ERC721Holder) return;
|
|
123
|
+
c.addParent({
|
|
124
|
+
name: 'ERC721Holder',
|
|
125
|
+
path: '@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol',
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function addERC1155Holder(c: ContractBuilder, opts: AccountOptions): void {
|
|
130
|
+
if (!opts.ERC1155Holder) return;
|
|
131
|
+
c.addParent({
|
|
132
|
+
name: 'ERC1155Holder',
|
|
133
|
+
path: '@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol',
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function addBatchedExecution(c: ContractBuilder, opts: AccountOptions): void {
|
|
138
|
+
// ERC-7579 is a superset of ERC-7821
|
|
139
|
+
if (!opts.batchedExecution || !!opts.ERC7579Modules) return;
|
|
140
|
+
c.addParent({
|
|
141
|
+
name: 'ERC7821',
|
|
142
|
+
path: '@openzeppelin/community-contracts/account/extensions/ERC7821.sol',
|
|
143
|
+
});
|
|
144
|
+
c.addOverride({ name: 'ERC7821' }, functions._erc7821AuthorizedExecutor);
|
|
145
|
+
c.setFunctionBody(
|
|
146
|
+
['return caller == address(entryPoint()) || super._erc7821AuthorizedExecutor(caller, mode, executionData);'],
|
|
147
|
+
functions._erc7821AuthorizedExecutor,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function addERC7579Modules(c: ContractBuilder, opts: AccountOptions): void {
|
|
152
|
+
if (!opts.ERC7579Modules) return;
|
|
153
|
+
c.addParent({
|
|
154
|
+
name: opts.ERC7579Modules,
|
|
155
|
+
path: `@openzeppelin/community-contracts/account/extensions/${opts.ERC7579Modules}.sol`,
|
|
156
|
+
});
|
|
157
|
+
if (opts.ERC7579Modules !== 'AccountERC7579') {
|
|
158
|
+
c.addImportOnly({
|
|
159
|
+
name: 'AccountERC7579',
|
|
160
|
+
path: `@openzeppelin/community-contracts/account/extensions/AccountERC7579.sol`,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
c.addOverride({ name: 'AccountERC7579' }, functions.isValidSignature);
|
|
164
|
+
c.addOverride({ name: 'AccountERC7579' }, functions._validateUserOp);
|
|
165
|
+
|
|
166
|
+
if (opts.signatureValidation !== 'ERC7739') return;
|
|
167
|
+
c.addOverride({ name: 'ERC7739' }, functions.isValidSignature);
|
|
168
|
+
c.setFunctionBody(
|
|
169
|
+
[
|
|
170
|
+
'// ERC-7739 can return the ERC-1271 magic value, 0xffffffff (invalid) or 0x77390001 (detection).',
|
|
171
|
+
'// If the returned value is 0xffffffff, fallback to ERC-7579 validation.',
|
|
172
|
+
'bytes4 erc7739magic = ERC7739.isValidSignature(hash, signature);',
|
|
173
|
+
'return erc7739magic == bytes4(0xffffffff) ? AccountERC7579.isValidSignature(hash, signature) : erc7739magic;',
|
|
174
|
+
],
|
|
175
|
+
functions.isValidSignature,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function addMultisigFunctions(c: ContractBuilder, opts: AccountOptions): void {
|
|
180
|
+
switch (opts.signer) {
|
|
181
|
+
case 'MultisigWeighted':
|
|
182
|
+
c.addFunctionCode(
|
|
183
|
+
`_setSignerWeights(${functions.setSignerWeights.args.map(({ name }) => name).join(', ')});`,
|
|
184
|
+
functions.setSignerWeights,
|
|
185
|
+
);
|
|
186
|
+
// eslint-disable-next-line no-fallthrough
|
|
187
|
+
case 'Multisig':
|
|
188
|
+
c.addFunctionCode(`_addSigners(${functions.addSigners.args[0]!.name});`, functions.addSigners);
|
|
189
|
+
c.addFunctionCode(`_removeSigners(${functions.removeSigners.args[0]!.name});`, functions.removeSigners);
|
|
190
|
+
c.addFunctionCode(`_setThreshold(${functions.setThreshold.args[0]!.name});`, functions.setThreshold);
|
|
191
|
+
break;
|
|
192
|
+
default:
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function addEIP712(c: ContractBuilder, opts: AccountOptions): void {
|
|
197
|
+
if (opts.signatureValidation != 'ERC7739') return;
|
|
198
|
+
c.addParent(
|
|
199
|
+
{
|
|
200
|
+
name: 'EIP712',
|
|
201
|
+
path: '@openzeppelin/contracts/utils/cryptography/EIP712.sol',
|
|
202
|
+
},
|
|
203
|
+
[opts.name, '1'],
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function overrideRawSignatureValidation(c: ContractBuilder, opts: AccountOptions): void {
|
|
208
|
+
if (opts.signer && !opts.ERC7579Modules) return; // Signer implements _rawSignatureValidation alone
|
|
209
|
+
if (!opts.signer && opts.ERC7579Modules) return; // AccountERC7579 implements _rawSignatureValidation alone
|
|
210
|
+
|
|
211
|
+
// If no signer or ERC-7579 is used, we need to override the _rawSignatureValidation function
|
|
212
|
+
// to provide a custom validation logic
|
|
213
|
+
if (!opts.signer && !opts.ERC7579Modules) {
|
|
214
|
+
// Custom validation logic
|
|
215
|
+
c.addOverride({ name: 'Account' }, signerFunctions._rawSignatureValidation);
|
|
216
|
+
c.setFunctionBody(['// Custom validation logic', 'return false;'], signerFunctions._rawSignatureValidation);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Dissambiguate between Signer and AccountERC7579
|
|
220
|
+
if (opts.signer && opts.ERC7579Modules) {
|
|
221
|
+
c.addImportOnly({
|
|
222
|
+
name: 'AbstractSigner',
|
|
223
|
+
path: '@openzeppelin/community-contracts/utils/cryptography/AbstractSigner.sol',
|
|
224
|
+
});
|
|
225
|
+
c.addOverride({ name: 'AbstractSigner' }, signerFunctions._rawSignatureValidation);
|
|
226
|
+
c.addOverride({ name: 'AccountERC7579' }, signerFunctions._rawSignatureValidation);
|
|
227
|
+
c.setFunctionComments(
|
|
228
|
+
[
|
|
229
|
+
`// IMPORTANT: Make sure Signer${opts.signer} is most derived than AccountERC7579`,
|
|
230
|
+
`// in the inheritance chain (i.e. contract ... is AccountERC7579, ..., Signer${opts.signer})`,
|
|
231
|
+
'// to ensure the correct order of function resolution.',
|
|
232
|
+
'// AccountERC7579 returns false for `_rawSignatureValidation`',
|
|
233
|
+
],
|
|
234
|
+
signerFunctions._rawSignatureValidation,
|
|
235
|
+
);
|
|
236
|
+
// Base override for `_rawSignatureValidation` given MultiSignerERC7913Weighted is MultiSignerERC7913
|
|
237
|
+
if (opts.signer === 'MultisigWeighted') {
|
|
238
|
+
c.addImportOnly(signers.Multisig);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const functions = {
|
|
244
|
+
...defineFunctions({
|
|
245
|
+
isValidSignature: {
|
|
246
|
+
kind: 'public' as const,
|
|
247
|
+
mutability: 'view' as const,
|
|
248
|
+
args: [
|
|
249
|
+
{ name: 'hash', type: 'bytes32' },
|
|
250
|
+
{ name: 'signature', type: 'bytes calldata' },
|
|
251
|
+
],
|
|
252
|
+
returns: ['bytes4'],
|
|
253
|
+
},
|
|
254
|
+
_validateUserOp: {
|
|
255
|
+
kind: 'internal' as const,
|
|
256
|
+
args: [
|
|
257
|
+
{ name: 'userOp', type: 'PackedUserOperation calldata' },
|
|
258
|
+
{ name: 'userOpHash', type: 'bytes32' },
|
|
259
|
+
],
|
|
260
|
+
returns: ['uint256'],
|
|
261
|
+
},
|
|
262
|
+
_erc7821AuthorizedExecutor: {
|
|
263
|
+
kind: 'internal' as const,
|
|
264
|
+
args: [
|
|
265
|
+
{ name: 'caller', type: 'address' },
|
|
266
|
+
{ name: 'mode', type: 'bytes32' },
|
|
267
|
+
{ name: 'executionData', type: 'bytes calldata' },
|
|
268
|
+
],
|
|
269
|
+
returns: ['bool'],
|
|
270
|
+
mutability: 'view' as const,
|
|
271
|
+
},
|
|
272
|
+
addSigners: {
|
|
273
|
+
kind: 'public' as const,
|
|
274
|
+
args: [{ name: 'signers', type: 'bytes[] memory' }],
|
|
275
|
+
},
|
|
276
|
+
removeSigners: {
|
|
277
|
+
kind: 'public' as const,
|
|
278
|
+
args: [{ name: 'signers', type: 'bytes[] memory' }],
|
|
279
|
+
},
|
|
280
|
+
setThreshold: {
|
|
281
|
+
kind: 'public' as const,
|
|
282
|
+
args: [{ name: 'threshold', type: 'uint256' }],
|
|
283
|
+
},
|
|
284
|
+
setSignerWeights: {
|
|
285
|
+
kind: 'public' as const,
|
|
286
|
+
args: [
|
|
287
|
+
{ name: 'signers', type: 'bytes[] memory' },
|
|
288
|
+
{ name: 'weights', type: 'uint256[] memory' },
|
|
289
|
+
],
|
|
290
|
+
},
|
|
291
|
+
}),
|
|
292
|
+
};
|
package/src/api.ts
CHANGED
|
@@ -23,6 +23,8 @@ import {
|
|
|
23
23
|
defaults as stablecoinDefaults,
|
|
24
24
|
isAccessControlRequired as stablecoinIsAccessControlRequired,
|
|
25
25
|
} from './stablecoin';
|
|
26
|
+
import type { AccountOptions } from './account';
|
|
27
|
+
import { printAccount, defaults as accountDefaults } from './account';
|
|
26
28
|
import type { GovernorOptions } from './governor';
|
|
27
29
|
import {
|
|
28
30
|
printGovernor,
|
|
@@ -46,7 +48,9 @@ export interface WizardContractAPI<Options extends CommonOptions> {
|
|
|
46
48
|
* The default options that are used for `print`.
|
|
47
49
|
*/
|
|
48
50
|
defaults: Required<Options>;
|
|
51
|
+
}
|
|
49
52
|
|
|
53
|
+
export interface AccessControlAPI<Options extends CommonOptions> {
|
|
50
54
|
/**
|
|
51
55
|
* Whether any of the provided options require access control to be enabled. If this returns `true`, then calling `print` with the
|
|
52
56
|
* same options would cause the `access` option to default to `'ownable'` if it was `undefined` or `false`.
|
|
@@ -54,13 +58,14 @@ export interface WizardContractAPI<Options extends CommonOptions> {
|
|
|
54
58
|
isAccessControlRequired: (opts: Partial<Options>) => boolean;
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
export type ERC20 = WizardContractAPI<ERC20Options>;
|
|
58
|
-
export type ERC721 = WizardContractAPI<ERC721Options>;
|
|
59
|
-
export type ERC1155 = WizardContractAPI<ERC1155Options>;
|
|
60
|
-
export type Stablecoin = WizardContractAPI<StablecoinOptions>;
|
|
61
|
-
export type RealWorldAsset = WizardContractAPI<StablecoinOptions>;
|
|
62
|
-
export type
|
|
63
|
-
export type
|
|
61
|
+
export type ERC20 = WizardContractAPI<ERC20Options> & AccessControlAPI<ERC20Options>;
|
|
62
|
+
export type ERC721 = WizardContractAPI<ERC721Options> & AccessControlAPI<ERC721Options>;
|
|
63
|
+
export type ERC1155 = WizardContractAPI<ERC1155Options> & AccessControlAPI<ERC1155Options>;
|
|
64
|
+
export type Stablecoin = WizardContractAPI<StablecoinOptions> & AccessControlAPI<StablecoinOptions>;
|
|
65
|
+
export type RealWorldAsset = WizardContractAPI<StablecoinOptions> & AccessControlAPI<StablecoinOptions>;
|
|
66
|
+
export type Account = WizardContractAPI<AccountOptions>;
|
|
67
|
+
export type Governor = WizardContractAPI<GovernorOptions> & AccessControlAPI<GovernorOptions>;
|
|
68
|
+
export type Custom = WizardContractAPI<CustomOptions> & AccessControlAPI<CustomOptions>;
|
|
64
69
|
|
|
65
70
|
export const erc20: ERC20 = {
|
|
66
71
|
print: printERC20,
|
|
@@ -82,6 +87,10 @@ export const stablecoin: Stablecoin = {
|
|
|
82
87
|
defaults: stablecoinDefaults,
|
|
83
88
|
isAccessControlRequired: stablecoinIsAccessControlRequired,
|
|
84
89
|
};
|
|
90
|
+
export const account: Account = {
|
|
91
|
+
print: printAccount,
|
|
92
|
+
defaults: accountDefaults,
|
|
93
|
+
};
|
|
85
94
|
export const realWorldAsset: RealWorldAsset = {
|
|
86
95
|
print: printStablecoin,
|
|
87
96
|
defaults: stablecoinDefaults,
|
package/src/build-generic.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { buildStablecoin } from './stablecoin';
|
|
|
11
11
|
import type { GovernorOptions } from './governor';
|
|
12
12
|
import { buildGovernor } from './governor';
|
|
13
13
|
import type { Contract } from './contract';
|
|
14
|
+
import { buildAccount } from './account';
|
|
15
|
+
import type { AccountOptions } from './account';
|
|
14
16
|
|
|
15
17
|
export interface KindedOptions {
|
|
16
18
|
ERC20: { kind: 'ERC20' } & ERC20Options;
|
|
@@ -18,6 +20,7 @@ export interface KindedOptions {
|
|
|
18
20
|
ERC1155: { kind: 'ERC1155' } & ERC1155Options;
|
|
19
21
|
Stablecoin: { kind: 'Stablecoin' } & StablecoinOptions;
|
|
20
22
|
RealWorldAsset: { kind: 'RealWorldAsset' } & StablecoinOptions;
|
|
23
|
+
Account: { kind: 'Account' } & AccountOptions;
|
|
21
24
|
Governor: { kind: 'Governor' } & GovernorOptions;
|
|
22
25
|
Custom: { kind: 'Custom' } & CustomOptions;
|
|
23
26
|
}
|
|
@@ -41,6 +44,9 @@ export function buildGeneric(opts: GenericOptions): Contract {
|
|
|
41
44
|
case 'RealWorldAsset':
|
|
42
45
|
return buildStablecoin(opts);
|
|
43
46
|
|
|
47
|
+
case 'Account':
|
|
48
|
+
return buildAccount(opts);
|
|
49
|
+
|
|
44
50
|
case 'Governor':
|
|
45
51
|
return buildGovernor(opts);
|
|
46
52
|
|
|
@@ -1510,9 +1510,9 @@
|
|
|
1510
1510
|
}
|
|
1511
1511
|
},
|
|
1512
1512
|
"node_modules/@openzeppelin/contracts": {
|
|
1513
|
-
"version": "5.
|
|
1514
|
-
"resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-5.
|
|
1515
|
-
"integrity": "sha512-
|
|
1513
|
+
"version": "5.3.0",
|
|
1514
|
+
"resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-5.3.0.tgz",
|
|
1515
|
+
"integrity": "sha512-zj/KGoW7zxWUE8qOI++rUM18v+VeLTTzKs/DJFkSzHpQFPD/jKKF0TrMxBfGLl3kpdELCNccvB3zmofSzm4nlA==",
|
|
1516
1516
|
"dev": true,
|
|
1517
1517
|
"license": "MIT"
|
|
1518
1518
|
},
|
|
@@ -2195,20 +2195,20 @@
|
|
|
2195
2195
|
}
|
|
2196
2196
|
},
|
|
2197
2197
|
"node_modules/@openzeppelin/contracts": {
|
|
2198
|
-
"version": "5.
|
|
2199
|
-
"resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-5.
|
|
2200
|
-
"integrity": "sha512-
|
|
2198
|
+
"version": "5.3.0",
|
|
2199
|
+
"resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-5.3.0.tgz",
|
|
2200
|
+
"integrity": "sha512-zj/KGoW7zxWUE8qOI++rUM18v+VeLTTzKs/DJFkSzHpQFPD/jKKF0TrMxBfGLl3kpdELCNccvB3zmofSzm4nlA==",
|
|
2201
2201
|
"dev": true,
|
|
2202
2202
|
"license": "MIT"
|
|
2203
2203
|
},
|
|
2204
2204
|
"node_modules/@openzeppelin/contracts-upgradeable": {
|
|
2205
|
-
"version": "5.
|
|
2206
|
-
"resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-5.
|
|
2207
|
-
"integrity": "sha512-
|
|
2205
|
+
"version": "5.3.0",
|
|
2206
|
+
"resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-5.3.0.tgz",
|
|
2207
|
+
"integrity": "sha512-yVzSSyTMWO6rapGI5tuqkcLpcGGXA0UA1vScyV5EhE5yw8By3Ewex9rDUw8lfVw0iTkvR/egjfcW5vpk03lqZg==",
|
|
2208
2208
|
"dev": true,
|
|
2209
2209
|
"license": "MIT",
|
|
2210
2210
|
"peerDependencies": {
|
|
2211
|
-
"@openzeppelin/contracts": "5.
|
|
2211
|
+
"@openzeppelin/contracts": "5.3.0"
|
|
2212
2212
|
}
|
|
2213
2213
|
},
|
|
2214
2214
|
"node_modules/@openzeppelin/defender-sdk-base-client": {
|
package/src/erc20.ts
CHANGED
|
@@ -313,7 +313,7 @@ function addCrossChainBridging(
|
|
|
313
313
|
) {
|
|
314
314
|
const ERC20Bridgeable = {
|
|
315
315
|
name: 'ERC20Bridgeable',
|
|
316
|
-
path: `@openzeppelin/community-contracts/
|
|
316
|
+
path: `@openzeppelin/community-contracts/token/ERC20/extensions/ERC20Bridgeable.sol`,
|
|
317
317
|
};
|
|
318
318
|
|
|
319
319
|
c.addParent(ERC20Bridgeable);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AccountOptions } from '../account';
|
|
2
|
+
import { infoOptions } from '../set-info';
|
|
3
|
+
import { generateAlternatives } from './alternatives';
|
|
4
|
+
|
|
5
|
+
const account = {
|
|
6
|
+
name: ['MyAccount'],
|
|
7
|
+
signatureValidation: [false, 'ERC1271', 'ERC7739'] as const,
|
|
8
|
+
ERC721Holder: [false, true] as const,
|
|
9
|
+
ERC1155Holder: [false, true] as const,
|
|
10
|
+
signer: ['ERC7702', 'ECDSA', 'P256', 'RSA', 'Multisig', 'MultisigWeighted'] as const,
|
|
11
|
+
batchedExecution: [false, true] as const,
|
|
12
|
+
ERC7579Modules: [false, 'AccountERC7579', 'AccountERC7579Hooked'] as const,
|
|
13
|
+
access: [false] as const,
|
|
14
|
+
upgradeable: [false] as const,
|
|
15
|
+
info: infoOptions,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function* generateAccountOptions(): Generator<Required<AccountOptions>> {
|
|
19
|
+
yield* generateAlternatives(account);
|
|
20
|
+
}
|
package/src/generate/sources.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { generateERC20Options } from './erc20';
|
|
|
6
6
|
import { generateERC721Options } from './erc721';
|
|
7
7
|
import { generateERC1155Options } from './erc1155';
|
|
8
8
|
import { generateStablecoinOptions } from './stablecoin';
|
|
9
|
+
import { generateAccountOptions } from './account';
|
|
9
10
|
import { generateGovernorOptions } from './governor';
|
|
10
11
|
import { generateCustomOptions } from './custom';
|
|
11
12
|
import type { GenericOptions, KindedOptions } from '../build-generic';
|
|
@@ -50,6 +51,12 @@ export function* generateOptions(kind?: Kind): Generator<GenericOptions> {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
if (!kind || kind === 'Account') {
|
|
55
|
+
for (const kindOpts of generateAccountOptions()) {
|
|
56
|
+
yield { kind: 'Account', ...kindOpts };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
53
60
|
if (!kind || kind === 'Governor') {
|
|
54
61
|
for (const kindOpts of generateGovernorOptions()) {
|
|
55
62
|
yield { kind: 'Governor', ...kindOpts };
|
package/src/governor.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { supportsInterface } from './common-functions';
|
|
2
2
|
import type { CommonOptions } from './common-options';
|
|
3
3
|
import { withCommonDefaults, defaults as commonDefaults } from './common-options';
|
|
4
|
-
import type { Contract } from './contract';
|
|
4
|
+
import type { Contract, ImportContract } from './contract';
|
|
5
5
|
import { ContractBuilder } from './contract';
|
|
6
6
|
import { OptionsError } from './error';
|
|
7
7
|
import { setAccessControl } from './set-access-control';
|
|
@@ -105,15 +105,13 @@ export function buildGovernor(opts: GovernorOptions): Contract {
|
|
|
105
105
|
return c;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
const Governor: ImportContract = {
|
|
109
|
+
name: 'Governor',
|
|
110
|
+
path: '@openzeppelin/contracts/governance/Governor.sol',
|
|
111
|
+
};
|
|
112
|
+
|
|
108
113
|
function addBase(c: ContractBuilder, { name }: GovernorOptions) {
|
|
109
|
-
const Governor = {
|
|
110
|
-
name: 'Governor',
|
|
111
|
-
path: '@openzeppelin/contracts/governance/Governor.sol',
|
|
112
|
-
};
|
|
113
114
|
c.addParent(Governor, [name]);
|
|
114
|
-
c.addOverride(Governor, functions.votingDelay);
|
|
115
|
-
c.addOverride(Governor, functions.votingPeriod);
|
|
116
|
-
c.addOverride(Governor, functions.quorum);
|
|
117
115
|
c.addOverride(Governor, functions.state);
|
|
118
116
|
c.addOverride(Governor, functions.propose);
|
|
119
117
|
c.addOverride(Governor, functions.proposalNeedsQueuing);
|
|
@@ -221,6 +219,7 @@ function setVotingParameters(c: ContractBuilder, opts: Required<GovernorOptions>
|
|
|
221
219
|
} else {
|
|
222
220
|
c.setFunctionBody([`return ${delayBlocks.value}; // ${delayBlocks.note}`], functions.votingDelay);
|
|
223
221
|
}
|
|
222
|
+
c.addOverride(Governor, functions.votingDelay);
|
|
224
223
|
|
|
225
224
|
const periodBlocks = getVotingPeriod(opts);
|
|
226
225
|
if ('lit' in periodBlocks) {
|
|
@@ -228,6 +227,7 @@ function setVotingParameters(c: ContractBuilder, opts: Required<GovernorOptions>
|
|
|
228
227
|
} else {
|
|
229
228
|
c.setFunctionBody([`return ${periodBlocks.value}; // ${periodBlocks.note}`], functions.votingPeriod);
|
|
230
229
|
}
|
|
230
|
+
c.addOverride(Governor, functions.votingPeriod);
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
function setProposalThreshold(c: ContractBuilder, opts: Required<GovernorOptions>) {
|
|
@@ -308,6 +308,7 @@ function addQuorum(c: ContractBuilder, opts: Required<GovernorOptions>) {
|
|
|
308
308
|
: `return ${opts.quorumAbsolute}e${opts.decimals};`;
|
|
309
309
|
|
|
310
310
|
c.setFunctionBody([returnStatement], functions.quorum, 'pure');
|
|
311
|
+
c.addOverride(Governor, functions.quorum);
|
|
311
312
|
}
|
|
312
313
|
}
|
|
313
314
|
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,6 @@ export { OptionsError } from './error';
|
|
|
19
19
|
export type { Kind } from './kind';
|
|
20
20
|
export { sanitizeKind } from './kind';
|
|
21
21
|
|
|
22
|
-
export { erc20, erc721, erc1155, stablecoin, realWorldAsset, governor, custom } from './api';
|
|
22
|
+
export { erc20, erc721, erc1155, stablecoin, realWorldAsset, account, governor, custom } from './api';
|
|
23
23
|
|
|
24
24
|
export { compatibleContractsSemver } from './utils/version';
|
package/src/kind.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type Kind = GenericOptions['kind'];
|
|
|
4
4
|
|
|
5
5
|
export function sanitizeKind(kind: unknown): Kind {
|
|
6
6
|
if (typeof kind === 'string') {
|
|
7
|
-
const sanitized = kind.replace(/^(ERC|.)/i, c => c.toUpperCase());
|
|
7
|
+
const sanitized = kind.replace(/^(ERC|.)/i, c => c.toUpperCase()).replace(/^(RealWorldAsset)$/i, 'RealWorldAsset');
|
|
8
8
|
if (isKind(sanitized)) {
|
|
9
9
|
return sanitized;
|
|
10
10
|
}
|
|
@@ -19,6 +19,7 @@ function isKind<T>(value: Kind | T): value is Kind {
|
|
|
19
19
|
case 'ERC721':
|
|
20
20
|
case 'Stablecoin':
|
|
21
21
|
case 'RealWorldAsset':
|
|
22
|
+
case 'Account':
|
|
22
23
|
case 'Governor':
|
|
23
24
|
case 'Custom':
|
|
24
25
|
return true;
|
package/src/print.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { mapValues } from './utils/map-values';
|
|
|
16
16
|
import SOLIDITY_VERSION from './solidity-version.json';
|
|
17
17
|
import { inferTranspiled } from './infer-transpiled';
|
|
18
18
|
import { compatibleContractsSemver } from './utils/version';
|
|
19
|
+
import { stringifyUnicodeSafe } from './utils/sanitize';
|
|
19
20
|
|
|
20
21
|
export function printContract(contract: Contract, opts?: Options): string {
|
|
21
22
|
const helpers = withHelpers(contract, opts);
|
|
@@ -148,7 +149,7 @@ export function printValue(value: Value): string {
|
|
|
148
149
|
throw new Error(`Number not representable (${value})`);
|
|
149
150
|
}
|
|
150
151
|
} else {
|
|
151
|
-
return
|
|
152
|
+
return stringifyUnicodeSafe(value);
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
155
|
|