@openzeppelin/wizard 0.10.3 → 0.10.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/dist/contract.d.ts +13 -4
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +34 -11
- package/dist/contract.js.map +1 -1
- package/dist/environments/hardhat/polkadot/package-lock.json +12683 -0
- package/dist/environments/hardhat/polkadot/package.json +17 -0
- package/dist/get-versioned-remappings.js +3 -3
- package/dist/get-versioned-remappings.js.map +1 -1
- package/dist/governor.d.ts +2 -1
- package/dist/governor.d.ts.map +1 -1
- package/dist/governor.js.map +1 -1
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -1
- package/dist/index.js.map +1 -1
- package/dist/options.d.ts +8 -0
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +1 -0
- package/dist/options.js.map +1 -1
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +41 -12
- package/dist/print.js.map +1 -1
- package/dist/stablecoin.d.ts +1 -0
- package/dist/stablecoin.d.ts.map +1 -1
- package/dist/stablecoin.js.map +1 -1
- package/dist/utils/imports-libraries.d.ts +1 -1
- package/dist/utils/imports-libraries.d.ts.map +1 -1
- package/dist/utils/imports-libraries.js +3 -3
- package/dist/utils/imports-libraries.js.map +1 -1
- package/dist/zip-hardhat-polkadot.d.ts +5 -0
- package/dist/zip-hardhat-polkadot.d.ts.map +1 -0
- package/dist/zip-hardhat-polkadot.js +115 -0
- package/dist/zip-hardhat-polkadot.js.map +1 -0
- package/dist/zip-hardhat.d.ts +21 -0
- package/dist/zip-hardhat.d.ts.map +1 -1
- package/dist/zip-hardhat.js +181 -115
- package/dist/zip-hardhat.js.map +1 -1
- package/package.json +2 -2
- package/src/contract.ts +49 -14
- package/src/environments/hardhat/polkadot/package-lock.json +12683 -0
- package/src/environments/hardhat/polkadot/package.json +17 -0
- package/src/get-versioned-remappings.ts +1 -1
- package/src/governor.ts +3 -1
- package/src/index.ts +13 -2
- package/src/options.ts +5 -0
- package/src/print.ts +44 -11
- package/src/stablecoin.ts +2 -0
- package/src/utils/imports-libraries.ts +2 -2
- package/src/zip-hardhat-polkadot.ts +86 -0
- package/src/zip-hardhat.ts +203 -129
- /package/{openzeppelin-contracts-version.d.ts → openzeppelin-contracts-version.json.d.ts} +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hardhat-sample",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "hardhat test"
|
|
8
|
+
},
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@openzeppelin/contracts": "^5.5.0",
|
|
13
|
+
"@parity/hardhat-polkadot": "^0.2.7",
|
|
14
|
+
"@nomicfoundation/hardhat-toolbox": "^6.1.0",
|
|
15
|
+
"hardhat": "^2.22.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CommonOptions } from './common-options';
|
|
2
|
-
import contractsVersion from '../openzeppelin-contracts-version';
|
|
2
|
+
import contractsVersion from '../openzeppelin-contracts-version.json';
|
|
3
3
|
|
|
4
4
|
export function getVersionedRemappings(opts?: CommonOptions): string[] {
|
|
5
5
|
const remappings = [`@openzeppelin/contracts/=@openzeppelin/contracts@${contractsVersion.version}/`];
|
package/src/governor.ts
CHANGED
|
@@ -40,6 +40,8 @@ export function printGovernor(opts: GovernorOptions = defaults): string {
|
|
|
40
40
|
return printContract(buildGovernor(opts));
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
export type QuorumMode = 'percent' | 'absolute';
|
|
44
|
+
|
|
43
45
|
export interface GovernorOptions extends CommonOptions {
|
|
44
46
|
name: string;
|
|
45
47
|
delay: string;
|
|
@@ -47,7 +49,7 @@ export interface GovernorOptions extends CommonOptions {
|
|
|
47
49
|
blockTime?: number;
|
|
48
50
|
proposalThreshold?: string;
|
|
49
51
|
decimals?: number;
|
|
50
|
-
quorumMode?:
|
|
52
|
+
quorumMode?: QuorumMode;
|
|
51
53
|
quorumPercent?: number;
|
|
52
54
|
quorumAbsolute?: string;
|
|
53
55
|
votes?: VotesOptions;
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export type { GenericOptions, KindedOptions } from './build-generic';
|
|
2
2
|
export { buildGeneric } from './build-generic';
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export { generateAlternatives } from './generate/alternatives';
|
|
5
|
+
|
|
6
|
+
export type { Contract, BaseFunction, Value, ReferencedContract } from './contract';
|
|
5
7
|
export { ContractBuilder } from './contract';
|
|
6
8
|
|
|
7
9
|
export { printContract } from './print';
|
|
@@ -11,7 +13,9 @@ export type { Upgradeable } from './set-upgradeable';
|
|
|
11
13
|
export type { Info } from './set-info';
|
|
12
14
|
|
|
13
15
|
export { premintPattern, chainIdPattern } from './erc20';
|
|
14
|
-
export { defaults as infoDefaults } from './set-info';
|
|
16
|
+
export { defaults as infoDefaults, infoOptions, setInfo } from './set-info';
|
|
17
|
+
export { accessOptions, setAccessControl, requireAccessControl } from './set-access-control';
|
|
18
|
+
export { addPausable } from './add-pausable';
|
|
15
19
|
|
|
16
20
|
export type { OptionsErrorMessages } from './error';
|
|
17
21
|
export { OptionsError } from './error';
|
|
@@ -20,8 +24,15 @@ export type { Kind } from './kind';
|
|
|
20
24
|
export { sanitizeKind } from './kind';
|
|
21
25
|
|
|
22
26
|
export { erc20, erc721, erc1155, stablecoin, realWorldAsset, account, governor, custom } from './api';
|
|
27
|
+
export type { WizardContractAPI, AccessControlAPI } from './api';
|
|
23
28
|
|
|
24
29
|
export { compatibleContractsSemver } from './utils/version';
|
|
30
|
+
export { findCover } from './utils/find-cover';
|
|
31
|
+
export { defineFunctions } from './utils/define-functions';
|
|
32
|
+
|
|
33
|
+
export type { CommonOptions } from './common-options';
|
|
34
|
+
export { withCommonDefaults, defaults as commonDefaults } from './common-options';
|
|
35
|
+
export { supportsInterface } from './common-functions';
|
|
25
36
|
|
|
26
37
|
export type { ERC20Options } from './erc20';
|
|
27
38
|
export type { ERC721Options } from './erc721';
|
package/src/options.ts
CHANGED
|
@@ -27,6 +27,10 @@ export function upgradeableImport(p: ImportContract): ImportContract {
|
|
|
27
27
|
|
|
28
28
|
export interface Options {
|
|
29
29
|
transformImport?: (parent: ImportContract) => ImportContract;
|
|
30
|
+
/**
|
|
31
|
+
* Add additional libraries to the compatibility banner printed at the top of the contract.
|
|
32
|
+
*/
|
|
33
|
+
additionalCompatibleLibraries?: { name: string; path: string; version: string }[];
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
export interface Helpers extends Required<Options> {
|
|
@@ -45,5 +49,6 @@ export function withHelpers(contract: Contract, opts: Options = {}): Helpers {
|
|
|
45
49
|
const p2 = contractUpgradeable && inferTranspiled(p1) ? upgradeableImport(p1) : p1;
|
|
46
50
|
return opts.transformImport?.(p2) ?? p2;
|
|
47
51
|
},
|
|
52
|
+
additionalCompatibleLibraries: opts.additionalCompatibleLibraries ?? [],
|
|
48
53
|
};
|
|
49
54
|
}
|
package/src/print.ts
CHANGED
|
@@ -19,7 +19,7 @@ import SOLIDITY_VERSION from './solidity-version.json';
|
|
|
19
19
|
import { inferTranspiled } from './infer-transpiled';
|
|
20
20
|
import { compatibleContractsSemver } from './utils/version';
|
|
21
21
|
import { stringifyUnicodeSafe } from './utils/sanitize';
|
|
22
|
-
import {
|
|
22
|
+
import { importsLibrary } from './utils/imports-libraries';
|
|
23
23
|
import { getCommunityContractsGitCommit } from './utils/community-contracts-git-commit';
|
|
24
24
|
|
|
25
25
|
export function printContract(contract: Contract, opts?: Options): string {
|
|
@@ -32,17 +32,19 @@ export function printContract(contract: Contract, opts?: Options): string {
|
|
|
32
32
|
...spaceBetween(
|
|
33
33
|
[
|
|
34
34
|
`// SPDX-License-Identifier: ${contract.license}`,
|
|
35
|
-
printCompatibleLibraryVersions(contract),
|
|
35
|
+
printCompatibleLibraryVersions(contract, opts),
|
|
36
36
|
`pragma solidity ^${SOLIDITY_VERSION};`,
|
|
37
37
|
],
|
|
38
38
|
|
|
39
39
|
printImports(contract.imports, helpers),
|
|
40
40
|
|
|
41
41
|
[
|
|
42
|
+
...printTopLevelComments(contract.topLevelComments, contract.natspecTags.length > 0),
|
|
42
43
|
...printNatspecTags(contract.natspecTags),
|
|
43
44
|
[`contract ${contract.name}`, ...printInheritance(contract, helpers), '{'].join(' '),
|
|
44
45
|
|
|
45
46
|
spaceBetween(
|
|
47
|
+
printLibraries(contract, helpers),
|
|
46
48
|
...structs,
|
|
47
49
|
printVariableOrErrorDefinitionsWithComments(contract.variableOrErrorDefinitions),
|
|
48
50
|
printVariableOrErrorDefinitionsWithoutComments(contract.variableOrErrorDefinitions),
|
|
@@ -73,25 +75,38 @@ function printVariableOrErrorDefinitionsWithoutComments(
|
|
|
73
75
|
return withoutComments.map(v => v.code);
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
function printCompatibleLibraryVersions(contract: Contract): string {
|
|
77
|
-
|
|
78
|
-
if (
|
|
78
|
+
function printCompatibleLibraryVersions(contract: Contract, opts?: Options): string {
|
|
79
|
+
const libraries: string[] = [];
|
|
80
|
+
if (importsLibrary(contract, '@openzeppelin/contracts')) {
|
|
81
|
+
libraries.push(`OpenZeppelin Contracts ${compatibleContractsSemver}`);
|
|
82
|
+
}
|
|
83
|
+
if (importsLibrary(contract, '@openzeppelin/community-contracts')) {
|
|
79
84
|
try {
|
|
80
85
|
const commit = getCommunityContractsGitCommit();
|
|
81
|
-
|
|
86
|
+
libraries.push(`Community Contracts commit ${commit}`);
|
|
82
87
|
} catch (e) {
|
|
83
88
|
console.error(e);
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
|
-
|
|
91
|
+
if (opts?.additionalCompatibleLibraries) {
|
|
92
|
+
for (const library of opts.additionalCompatibleLibraries) {
|
|
93
|
+
if (importsLibrary(contract, library.path)) {
|
|
94
|
+
libraries.push(`${library.name} ${library.version}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (libraries.length === 0) return '';
|
|
100
|
+
if (libraries.length === 1) return `// Compatible with ${libraries[0]}`;
|
|
101
|
+
return `// Compatible with ${libraries.slice(0, -1).join(', ')} and ${libraries.slice(-1)}`;
|
|
87
102
|
}
|
|
88
103
|
|
|
89
104
|
function printInheritance(contract: Contract, { transformName }: Helpers): [] | [string] {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return [];
|
|
105
|
+
const visibleParents = contract.parents.filter(p => !p.constructionOnly);
|
|
106
|
+
if (visibleParents.length > 0) {
|
|
107
|
+
return ['is ' + visibleParents.map(p => transformName(p.contract)).join(', ')];
|
|
94
108
|
}
|
|
109
|
+
return [];
|
|
95
110
|
}
|
|
96
111
|
|
|
97
112
|
function printConstructor(contract: Contract, helpers: Helpers): Lines[] {
|
|
@@ -308,6 +323,12 @@ function printArgument(arg: FunctionArgument, { transformName }: Helpers): strin
|
|
|
308
323
|
return [type, arg.name].join(' ');
|
|
309
324
|
}
|
|
310
325
|
|
|
326
|
+
function printTopLevelComments(comments: string[], withExtraBlankLine: boolean = false): string[] {
|
|
327
|
+
const lines = comments.map(comment => `// ${comment}`);
|
|
328
|
+
if (comments.length > 0 && withExtraBlankLine) lines.push('//');
|
|
329
|
+
return lines;
|
|
330
|
+
}
|
|
331
|
+
|
|
311
332
|
function printNatspecTags(tags: NatspecTag[]): string[] {
|
|
312
333
|
return tags.map(({ key, value }) => `/// ${key} ${value}`);
|
|
313
334
|
}
|
|
@@ -328,3 +349,15 @@ function printImports(imports: ImportContract[], helpers: Helpers): string[] {
|
|
|
328
349
|
|
|
329
350
|
return lines;
|
|
330
351
|
}
|
|
352
|
+
|
|
353
|
+
function printLibraries(contract: Contract, { transformName }: Helpers): string[] {
|
|
354
|
+
if (!contract.libraries || contract.libraries.length === 0) return [];
|
|
355
|
+
|
|
356
|
+
return contract.libraries
|
|
357
|
+
.sort((a, b) => a.library.name.localeCompare(b.library.name))
|
|
358
|
+
.flatMap(lib =>
|
|
359
|
+
[...lib.usingFor]
|
|
360
|
+
.sort((a, b) => a.localeCompare(b))
|
|
361
|
+
.map(type => `using ${transformName(lib.library)} for ${type};`),
|
|
362
|
+
);
|
|
363
|
+
}
|
package/src/stablecoin.ts
CHANGED
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
functions as erc20functions,
|
|
12
12
|
} from './erc20';
|
|
13
13
|
|
|
14
|
+
export type Limitations = 'allowlist' | 'blocklist';
|
|
15
|
+
|
|
14
16
|
export interface StablecoinOptions extends ERC20Options {
|
|
15
17
|
restrictions?: false | 'allowlist' | 'blocklist';
|
|
16
18
|
freezable?: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Contract } from '../contract';
|
|
2
2
|
|
|
3
|
-
export function
|
|
4
|
-
return contract.imports.some(i => i.path.startsWith(
|
|
3
|
+
export function importsLibrary(contract: Contract, library: string) {
|
|
4
|
+
return contract.imports.some(i => i.path.startsWith(library));
|
|
5
5
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type JSZip from 'jszip';
|
|
2
|
+
import type { Contract } from './contract';
|
|
3
|
+
import { HardhatZipGenerator } from './zip-hardhat';
|
|
4
|
+
import type { GenericOptions } from './build-generic';
|
|
5
|
+
import SOLIDITY_VERSION from './solidity-version.json';
|
|
6
|
+
|
|
7
|
+
class HardhatPolkadotZipGenerator extends HardhatZipGenerator {
|
|
8
|
+
protected getAdditionalHardhatImports(): string[] {
|
|
9
|
+
return ['@parity/hardhat-polkadot'];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
protected getHardhatConfigJsonString(): string {
|
|
13
|
+
return `\
|
|
14
|
+
{
|
|
15
|
+
solidity: {
|
|
16
|
+
version: "${SOLIDITY_VERSION}",
|
|
17
|
+
settings: {
|
|
18
|
+
evmVersion: 'cancun',
|
|
19
|
+
optimizer: {
|
|
20
|
+
enabled: true,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
resolc: {
|
|
25
|
+
compilerSource: 'npm',
|
|
26
|
+
},
|
|
27
|
+
networks: {
|
|
28
|
+
hardhat: {
|
|
29
|
+
polkavm: true,
|
|
30
|
+
nodeConfig: {
|
|
31
|
+
nodeBinaryPath: 'INSERT_PATH_TO_REVIVE_DEV_NODE',
|
|
32
|
+
rpcPort: 8000,
|
|
33
|
+
dev: true,
|
|
34
|
+
},
|
|
35
|
+
adapterConfig: {
|
|
36
|
+
adapterBinaryPath: 'INSERT_PATH_TO_ETH_RPC_ADAPTER',
|
|
37
|
+
dev: true,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protected async getPackageJson(c: Contract): Promise<unknown> {
|
|
45
|
+
const { default: packageJson } = await import('./environments/hardhat/polkadot/package.json');
|
|
46
|
+
packageJson.license = c.license;
|
|
47
|
+
return packageJson;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected async getPackageLock(c: Contract): Promise<unknown> {
|
|
51
|
+
const { default: packageLock } = await import('./environments/hardhat/polkadot/package-lock.json');
|
|
52
|
+
packageLock.packages[''].license = c.license;
|
|
53
|
+
return packageLock;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
protected getReadmePrerequisitesSection(): string {
|
|
57
|
+
return `\
|
|
58
|
+
## Prerequisites
|
|
59
|
+
|
|
60
|
+
Ensure you have the following installed:
|
|
61
|
+
- [Node.js 22.5+](https://nodejs.org/en/download/)
|
|
62
|
+
- npm 10.9.0+
|
|
63
|
+
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected getReadmeTestingEnvironmentSetupSection(): string {
|
|
68
|
+
return `\
|
|
69
|
+
## Setting up a testing environment
|
|
70
|
+
|
|
71
|
+
Follow the steps in [Polkadot's documentation](https://docs.polkadot.com/smart-contracts/dev-environments/local-dev-node/) to set up a local development node and replace the placeholder values \`INSERT_PATH_TO_REVIVE_DEV_NODE\` and \`INSERT_PATH_TO_ETH_RPC_ADAPTER\` in \`hardhat.config.ts\`.
|
|
72
|
+
|
|
73
|
+
`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
protected getGitIgnoreHardhatIgnition(): string {
|
|
77
|
+
return `
|
|
78
|
+
# Hardhat Ignition default folder for deployments against a local Polkadot Revive Dev node
|
|
79
|
+
ignition/deployments/chain-420420420
|
|
80
|
+
`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function zipHardhatPolkadot(c: Contract, opts?: GenericOptions): Promise<JSZip> {
|
|
85
|
+
return new HardhatPolkadotZipGenerator().zipHardhat(c, opts);
|
|
86
|
+
}
|