@openzeppelin/wizard 0.10.5 → 0.10.7
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/dist/common-options.js +1 -1
- package/dist/common-options.js.map +1 -1
- package/dist/contract.d.ts +1 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +1 -1
- package/dist/contract.js.map +1 -1
- package/dist/environments/hardhat/package-lock.json +4 -4
- package/dist/environments/hardhat/package.json +1 -1
- package/dist/environments/hardhat/upgradeable/package-lock.json +9 -9
- package/dist/environments/hardhat/upgradeable/package.json +2 -2
- package/dist/erc20.d.ts +10 -2
- package/dist/erc20.d.ts.map +1 -1
- package/dist/erc20.js +125 -50
- package/dist/erc20.js.map +1 -1
- package/dist/generate/erc20.d.ts.map +1 -1
- package/dist/generate/erc20.js +25 -6
- package/dist/generate/erc20.js.map +1 -1
- package/dist/generate/stablecoin.d.ts.map +1 -1
- package/dist/generate/stablecoin.js +2 -0
- package/dist/generate/stablecoin.js.map +1 -1
- package/dist/index.d.ts +23 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -21
- package/dist/index.js.map +1 -1
- package/dist/options.d.ts +3 -0
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js.map +1 -1
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +38 -26
- package/dist/print.js.map +1 -1
- package/dist/stablecoin.d.ts.map +1 -1
- package/dist/stablecoin.js +1 -1
- package/dist/stablecoin.js.map +1 -1
- package/dist/utils/convert-strings.d.ts +21 -2
- package/dist/utils/convert-strings.d.ts.map +1 -1
- package/dist/utils/convert-strings.js +28 -4
- package/dist/utils/convert-strings.js.map +1 -1
- package/dist/utils/version.d.ts +1 -1
- package/dist/utils/version.js +1 -1
- package/openzeppelin-contracts-version.json +1 -1
- package/package.json +5 -5
- package/src/common-options.ts +1 -1
- package/src/contract.ts +2 -2
- package/src/environments/hardhat/package-lock.json +4 -4
- package/src/environments/hardhat/package.json +1 -1
- package/src/environments/hardhat/upgradeable/package-lock.json +9 -9
- package/src/environments/hardhat/upgradeable/package.json +2 -2
- package/src/erc20.ts +163 -51
- package/src/generate/erc20.ts +27 -6
- package/src/generate/stablecoin.ts +2 -0
- package/src/index.ts +30 -18
- package/src/options.ts +3 -1
- package/src/print.ts +47 -26
- package/src/stablecoin.ts +2 -1
- package/src/utils/convert-strings.ts +28 -4
- package/src/utils/version.ts +1 -1
package/src/print.ts
CHANGED
|
@@ -75,15 +75,20 @@ function printVariableOrErrorDefinitionsWithoutComments(
|
|
|
75
75
|
return withoutComments.map(v => v.code);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
type LibraryDescription = {
|
|
79
|
+
nameAndVersion: string;
|
|
80
|
+
alwaysKeepOzPrefix?: boolean;
|
|
81
|
+
};
|
|
82
|
+
|
|
78
83
|
function printCompatibleLibraryVersions(contract: Contract, opts?: Options): string {
|
|
79
|
-
const
|
|
84
|
+
const libraryDescriptions: LibraryDescription[] = [];
|
|
80
85
|
if (importsLibrary(contract, '@openzeppelin/contracts')) {
|
|
81
|
-
|
|
86
|
+
libraryDescriptions.push({ nameAndVersion: `OpenZeppelin Contracts ${compatibleContractsSemver}` });
|
|
82
87
|
}
|
|
83
88
|
if (importsLibrary(contract, '@openzeppelin/community-contracts')) {
|
|
84
89
|
try {
|
|
85
90
|
const commit = getCommunityContractsGitCommit();
|
|
86
|
-
|
|
91
|
+
libraryDescriptions.push({ nameAndVersion: `OpenZeppelin Community Contracts commit ${commit}` });
|
|
87
92
|
} catch (e) {
|
|
88
93
|
console.error(e);
|
|
89
94
|
}
|
|
@@ -91,14 +96,35 @@ function printCompatibleLibraryVersions(contract: Contract, opts?: Options): str
|
|
|
91
96
|
if (opts?.additionalCompatibleLibraries) {
|
|
92
97
|
for (const library of opts.additionalCompatibleLibraries) {
|
|
93
98
|
if (importsLibrary(contract, library.path)) {
|
|
94
|
-
|
|
99
|
+
libraryDescriptions.push({
|
|
100
|
+
nameAndVersion: `${library.name} ${library.version}`,
|
|
101
|
+
alwaysKeepOzPrefix: library.alwaysKeepOzPrefix,
|
|
102
|
+
});
|
|
95
103
|
}
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
106
|
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
if (libraryDescriptions.length === 0) {
|
|
108
|
+
return '';
|
|
109
|
+
} else if (libraryDescriptions.length === 1) {
|
|
110
|
+
return `// Compatible with ${libraryDescriptions[0]!.nameAndVersion}`;
|
|
111
|
+
} else {
|
|
112
|
+
const OZ_PREFIX_WITH_SPACE = 'OpenZeppelin ';
|
|
113
|
+
if (libraryDescriptions[0]!.nameAndVersion.startsWith(OZ_PREFIX_WITH_SPACE)) {
|
|
114
|
+
for (let i = 1; i < libraryDescriptions.length; i++) {
|
|
115
|
+
if (
|
|
116
|
+
libraryDescriptions[i]!.nameAndVersion.startsWith(OZ_PREFIX_WITH_SPACE) &&
|
|
117
|
+
!libraryDescriptions[i]!.alwaysKeepOzPrefix
|
|
118
|
+
) {
|
|
119
|
+
libraryDescriptions[i]!.nameAndVersion = libraryDescriptions[i]!.nameAndVersion.slice(
|
|
120
|
+
OZ_PREFIX_WITH_SPACE.length,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const librariesToPrint = libraryDescriptions.map(l => l.nameAndVersion);
|
|
126
|
+
return `// Compatible with ${librariesToPrint.slice(0, -1).join(', ')} and ${librariesToPrint.slice(-1)}`;
|
|
127
|
+
}
|
|
102
128
|
}
|
|
103
129
|
|
|
104
130
|
function printInheritance(contract: Contract, { transformName }: Helpers): [] | [string] {
|
|
@@ -334,30 +360,25 @@ function printNatspecTags(tags: NatspecTag[]): string[] {
|
|
|
334
360
|
}
|
|
335
361
|
|
|
336
362
|
function printImports(imports: ImportContract[], helpers: Helpers): string[] {
|
|
337
|
-
|
|
338
|
-
imports.sort((a, b) => {
|
|
339
|
-
if (a.name < b.name) return -1;
|
|
340
|
-
if (a.name > b.name) return 1;
|
|
341
|
-
return 0;
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
const lines: string[] = [];
|
|
345
|
-
imports.map(p => {
|
|
346
|
-
const importContract = helpers.transformImport(p);
|
|
347
|
-
lines.push(`import {${importContract.name}} from "${importContract.path}";`);
|
|
348
|
-
});
|
|
363
|
+
const itemByPath = new Map<string, Set<string>>();
|
|
349
364
|
|
|
350
|
-
|
|
365
|
+
for (const p of imports) {
|
|
366
|
+
const { name, path } = helpers.transformImport(p);
|
|
367
|
+
const _ = itemByPath.get(path)?.add(name) ?? itemByPath.set(path, new Set([name]));
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return Array.from(itemByPath.keys())
|
|
371
|
+
.sort()
|
|
372
|
+
.map(path => `import {${Array.from(itemByPath.get(path)!).sort().join(', ')}} from "${path}";`);
|
|
351
373
|
}
|
|
352
374
|
|
|
353
375
|
function printLibraries(contract: Contract, { transformName }: Helpers): string[] {
|
|
354
376
|
if (!contract.libraries || contract.libraries.length === 0) return [];
|
|
355
377
|
|
|
356
378
|
return contract.libraries
|
|
357
|
-
.sort((a, b) => a.library.name.localeCompare(b.library.name))
|
|
358
|
-
.
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
);
|
|
379
|
+
.sort((a, b) => a.library.name.localeCompare(b.library.name)) // Sort by import path
|
|
380
|
+
.map(lib => {
|
|
381
|
+
const sortedTypes = Array.from(lib.usingFor).sort((a, b) => a.localeCompare(b)); // Sort types
|
|
382
|
+
return `using ${transformName(lib.library)} for ${sortedTypes.join(', ')};`;
|
|
383
|
+
});
|
|
363
384
|
}
|
package/src/stablecoin.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
defaults as erc20defaults,
|
|
10
10
|
withDefaults as withERC20Defaults,
|
|
11
11
|
functions as erc20functions,
|
|
12
|
+
isAccessControlRequired as erc20isAccessControlRequired,
|
|
12
13
|
} from './erc20';
|
|
13
14
|
|
|
14
15
|
export type Limitations = 'allowlist' | 'blocklist';
|
|
@@ -41,7 +42,7 @@ export function printStablecoin(opts: StablecoinOptions = defaults): string {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
export function isAccessControlRequired(opts: Partial<StablecoinOptions>): boolean {
|
|
44
|
-
return opts
|
|
45
|
+
return erc20isAccessControlRequired(opts) || !!opts.restrictions || !!opts.freezable;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
export function buildStablecoin(opts: StablecoinOptions): Contract {
|
|
@@ -3,21 +3,32 @@ import { OptionsError } from '../error';
|
|
|
3
3
|
export const UINT256_MAX = BigInt(2) ** BigInt(256) - BigInt(1);
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Checks that a string is a valid
|
|
6
|
+
* Checks that a string is a valid number, and convert to bigint.
|
|
7
7
|
*
|
|
8
8
|
* @param value The string value to check and convert.
|
|
9
9
|
* @param field The field name to use in the error message if the value is invalid.
|
|
10
|
-
* @throws OptionsError if the value is not a valid number
|
|
10
|
+
* @throws OptionsError if the value is not a valid number.
|
|
11
11
|
* @returns The validated value as a bigint.
|
|
12
12
|
*/
|
|
13
|
-
export function
|
|
13
|
+
export function toBigInt(value: string, field: string): bigint {
|
|
14
14
|
const isValidNumber = /^\d+$/.test(value);
|
|
15
15
|
if (!isValidNumber) {
|
|
16
16
|
throw new OptionsError({
|
|
17
17
|
[field]: 'Not a valid number',
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
return BigInt(value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Checks that a bigint value fits within `uint256`.
|
|
25
|
+
*
|
|
26
|
+
* @param numValue The value to check.
|
|
27
|
+
* @param field The field name to use in the error if the value is invalid.
|
|
28
|
+
* @throws OptionsError if the value is greater than the maximum value for `uint256`.
|
|
29
|
+
* @returns The value as a bigint.
|
|
30
|
+
*/
|
|
31
|
+
export function validateUint256(numValue: bigint, field: string): bigint {
|
|
21
32
|
if (numValue > UINT256_MAX) {
|
|
22
33
|
throw new OptionsError({
|
|
23
34
|
[field]: 'Value is greater than uint256 max value',
|
|
@@ -25,3 +36,16 @@ export function toUint256(value: string, field: string): bigint {
|
|
|
25
36
|
}
|
|
26
37
|
return numValue;
|
|
27
38
|
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Checks that a string is a valid number, and fits within `uint256`.
|
|
42
|
+
* Convenience function that calls `toBigInt` and `validateUint256`.
|
|
43
|
+
*
|
|
44
|
+
* @param value The value to check.
|
|
45
|
+
* @param field The field name to use in the error if the value is invalid.
|
|
46
|
+
* @throws OptionsError if the value is not a valid number or is greater than the maximum value for `uint256`.
|
|
47
|
+
* @returns The value as a bigint.
|
|
48
|
+
*/
|
|
49
|
+
export function toUint256(value: string, field: string): bigint {
|
|
50
|
+
return validateUint256(toBigInt(value, field), field);
|
|
51
|
+
}
|
package/src/utils/version.ts
CHANGED