@openzeppelin/wizard 0.10.4 → 0.10.6
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/polkadot/package-lock.json +12683 -0
- package/dist/environments/hardhat/polkadot/package.json +17 -0
- package/dist/erc20.d.ts +7 -0
- package/dist/erc20.d.ts.map +1 -1
- package/dist/erc20.js +46 -35
- package/dist/erc20.js.map +1 -1
- package/dist/get-versioned-remappings.js +3 -3
- package/dist/get-versioned-remappings.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/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/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 +3 -3
- package/src/common-options.ts +1 -1
- package/src/contract.ts +2 -2
- package/src/environments/hardhat/polkadot/package-lock.json +12683 -0
- package/src/environments/hardhat/polkadot/package.json +17 -0
- package/src/erc20.ts +55 -36
- package/src/get-versioned-remappings.ts +1 -1
- package/src/index.ts +30 -18
- package/src/options.ts +3 -1
- package/src/print.ts +47 -26
- package/src/utils/convert-strings.ts +28 -4
- 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
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
export declare const UINT256_MAX: bigint;
|
|
2
2
|
/**
|
|
3
|
-
* Checks that a string is a valid
|
|
3
|
+
* Checks that a string is a valid number, and convert to bigint.
|
|
4
4
|
*
|
|
5
5
|
* @param value The string value to check and convert.
|
|
6
6
|
* @param field The field name to use in the error message if the value is invalid.
|
|
7
|
-
* @throws OptionsError if the value is not a valid number
|
|
7
|
+
* @throws OptionsError if the value is not a valid number.
|
|
8
8
|
* @returns The validated value as a bigint.
|
|
9
9
|
*/
|
|
10
|
+
export declare function toBigInt(value: string, field: string): bigint;
|
|
11
|
+
/**
|
|
12
|
+
* Checks that a bigint value fits within `uint256`.
|
|
13
|
+
*
|
|
14
|
+
* @param numValue The value to check.
|
|
15
|
+
* @param field The field name to use in the error if the value is invalid.
|
|
16
|
+
* @throws OptionsError if the value is greater than the maximum value for `uint256`.
|
|
17
|
+
* @returns The value as a bigint.
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateUint256(numValue: bigint, field: string): bigint;
|
|
20
|
+
/**
|
|
21
|
+
* Checks that a string is a valid number, and fits within `uint256`.
|
|
22
|
+
* Convenience function that calls `toBigInt` and `validateUint256`.
|
|
23
|
+
*
|
|
24
|
+
* @param value The value to check.
|
|
25
|
+
* @param field The field name to use in the error if the value is invalid.
|
|
26
|
+
* @throws OptionsError if the value is not a valid number or is greater than the maximum value for `uint256`.
|
|
27
|
+
* @returns The value as a bigint.
|
|
28
|
+
*/
|
|
10
29
|
export declare function toUint256(value: string, field: string): bigint;
|
|
11
30
|
//# sourceMappingURL=convert-strings.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-strings.d.ts","sourceRoot":"","sources":["../../src/utils/convert-strings.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,QAAuC,CAAC;AAEhE;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"convert-strings.d.ts","sourceRoot":"","sources":["../../src/utils/convert-strings.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,QAAuC,CAAC;AAEhE;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ7D;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAOvE;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9D"}
|
|
@@ -1,25 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UINT256_MAX = void 0;
|
|
4
|
+
exports.toBigInt = toBigInt;
|
|
5
|
+
exports.validateUint256 = validateUint256;
|
|
4
6
|
exports.toUint256 = toUint256;
|
|
5
7
|
const error_1 = require("../error");
|
|
6
8
|
exports.UINT256_MAX = BigInt(2) ** BigInt(256) - BigInt(1);
|
|
7
9
|
/**
|
|
8
|
-
* Checks that a string is a valid
|
|
10
|
+
* Checks that a string is a valid number, and convert to bigint.
|
|
9
11
|
*
|
|
10
12
|
* @param value The string value to check and convert.
|
|
11
13
|
* @param field The field name to use in the error message if the value is invalid.
|
|
12
|
-
* @throws OptionsError if the value is not a valid number
|
|
14
|
+
* @throws OptionsError if the value is not a valid number.
|
|
13
15
|
* @returns The validated value as a bigint.
|
|
14
16
|
*/
|
|
15
|
-
function
|
|
17
|
+
function toBigInt(value, field) {
|
|
16
18
|
const isValidNumber = /^\d+$/.test(value);
|
|
17
19
|
if (!isValidNumber) {
|
|
18
20
|
throw new error_1.OptionsError({
|
|
19
21
|
[field]: 'Not a valid number',
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
|
-
|
|
24
|
+
return BigInt(value);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks that a bigint value fits within `uint256`.
|
|
28
|
+
*
|
|
29
|
+
* @param numValue The value to check.
|
|
30
|
+
* @param field The field name to use in the error if the value is invalid.
|
|
31
|
+
* @throws OptionsError if the value is greater than the maximum value for `uint256`.
|
|
32
|
+
* @returns The value as a bigint.
|
|
33
|
+
*/
|
|
34
|
+
function validateUint256(numValue, field) {
|
|
23
35
|
if (numValue > exports.UINT256_MAX) {
|
|
24
36
|
throw new error_1.OptionsError({
|
|
25
37
|
[field]: 'Value is greater than uint256 max value',
|
|
@@ -27,4 +39,16 @@ function toUint256(value, field) {
|
|
|
27
39
|
}
|
|
28
40
|
return numValue;
|
|
29
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Checks that a string is a valid number, and fits within `uint256`.
|
|
44
|
+
* Convenience function that calls `toBigInt` and `validateUint256`.
|
|
45
|
+
*
|
|
46
|
+
* @param value The value to check.
|
|
47
|
+
* @param field The field name to use in the error if the value is invalid.
|
|
48
|
+
* @throws OptionsError if the value is not a valid number or is greater than the maximum value for `uint256`.
|
|
49
|
+
* @returns The value as a bigint.
|
|
50
|
+
*/
|
|
51
|
+
function toUint256(value, field) {
|
|
52
|
+
return validateUint256(toBigInt(value, field), field);
|
|
53
|
+
}
|
|
30
54
|
//# sourceMappingURL=convert-strings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-strings.js","sourceRoot":"","sources":["../../src/utils/convert-strings.ts"],"names":[],"mappings":";;;AAYA,
|
|
1
|
+
{"version":3,"file":"convert-strings.js","sourceRoot":"","sources":["../../src/utils/convert-strings.ts"],"names":[],"mappings":";;;AAYA,4BAQC;AAUD,0CAOC;AAWD,8BAEC;AAlDD,oCAAwC;AAE3B,QAAA,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,SAAgB,QAAQ,CAAC,KAAa,EAAE,KAAa;IACnD,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1C,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,oBAAY,CAAC;YACrB,CAAC,KAAK,CAAC,EAAE,oBAAoB;SAC9B,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,eAAe,CAAC,QAAgB,EAAE,KAAa;IAC7D,IAAI,QAAQ,GAAG,mBAAW,EAAE,CAAC;QAC3B,MAAM,IAAI,oBAAY,CAAC;YACrB,CAAC,KAAK,CAAC,EAAE,yCAAyC;SACnD,CAAC,CAAC;IACL,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,SAAS,CAAC,KAAa,EAAE,KAAa;IACpD,OAAO,eAAe,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type JSZip from 'jszip';
|
|
2
|
+
import type { Contract } from './contract';
|
|
3
|
+
import type { GenericOptions } from './build-generic';
|
|
4
|
+
export declare function zipHardhatPolkadot(c: Contract, opts?: GenericOptions): Promise<JSZip>;
|
|
5
|
+
//# sourceMappingURL=zip-hardhat-polkadot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip-hardhat-polkadot.d.ts","sourceRoot":"","sources":["../src/zip-hardhat-polkadot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAgFtD,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,CAE3F"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.zipHardhatPolkadot = zipHardhatPolkadot;
|
|
40
|
+
const zip_hardhat_1 = require("./zip-hardhat");
|
|
41
|
+
const solidity_version_json_1 = __importDefault(require("./solidity-version.json"));
|
|
42
|
+
class HardhatPolkadotZipGenerator extends zip_hardhat_1.HardhatZipGenerator {
|
|
43
|
+
getAdditionalHardhatImports() {
|
|
44
|
+
return ['@parity/hardhat-polkadot'];
|
|
45
|
+
}
|
|
46
|
+
getHardhatConfigJsonString() {
|
|
47
|
+
return `\
|
|
48
|
+
{
|
|
49
|
+
solidity: {
|
|
50
|
+
version: "${solidity_version_json_1.default}",
|
|
51
|
+
settings: {
|
|
52
|
+
evmVersion: 'cancun',
|
|
53
|
+
optimizer: {
|
|
54
|
+
enabled: true,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
resolc: {
|
|
59
|
+
compilerSource: 'npm',
|
|
60
|
+
},
|
|
61
|
+
networks: {
|
|
62
|
+
hardhat: {
|
|
63
|
+
polkavm: true,
|
|
64
|
+
nodeConfig: {
|
|
65
|
+
nodeBinaryPath: 'INSERT_PATH_TO_REVIVE_DEV_NODE',
|
|
66
|
+
rpcPort: 8000,
|
|
67
|
+
dev: true,
|
|
68
|
+
},
|
|
69
|
+
adapterConfig: {
|
|
70
|
+
adapterBinaryPath: 'INSERT_PATH_TO_ETH_RPC_ADAPTER',
|
|
71
|
+
dev: true,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
}`;
|
|
76
|
+
}
|
|
77
|
+
async getPackageJson(c) {
|
|
78
|
+
const { default: packageJson } = await Promise.resolve().then(() => __importStar(require('./environments/hardhat/polkadot/package.json')));
|
|
79
|
+
packageJson.license = c.license;
|
|
80
|
+
return packageJson;
|
|
81
|
+
}
|
|
82
|
+
async getPackageLock(c) {
|
|
83
|
+
const { default: packageLock } = await Promise.resolve().then(() => __importStar(require('./environments/hardhat/polkadot/package-lock.json')));
|
|
84
|
+
packageLock.packages[''].license = c.license;
|
|
85
|
+
return packageLock;
|
|
86
|
+
}
|
|
87
|
+
getReadmePrerequisitesSection() {
|
|
88
|
+
return `\
|
|
89
|
+
## Prerequisites
|
|
90
|
+
|
|
91
|
+
Ensure you have the following installed:
|
|
92
|
+
- [Node.js 22.5+](https://nodejs.org/en/download/)
|
|
93
|
+
- npm 10.9.0+
|
|
94
|
+
|
|
95
|
+
`;
|
|
96
|
+
}
|
|
97
|
+
getReadmeTestingEnvironmentSetupSection() {
|
|
98
|
+
return `\
|
|
99
|
+
## Setting up a testing environment
|
|
100
|
+
|
|
101
|
+
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\`.
|
|
102
|
+
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
getGitIgnoreHardhatIgnition() {
|
|
106
|
+
return `
|
|
107
|
+
# Hardhat Ignition default folder for deployments against a local Polkadot Revive Dev node
|
|
108
|
+
ignition/deployments/chain-420420420
|
|
109
|
+
`;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function zipHardhatPolkadot(c, opts) {
|
|
113
|
+
return new HardhatPolkadotZipGenerator().zipHardhat(c, opts);
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=zip-hardhat-polkadot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip-hardhat-polkadot.js","sourceRoot":"","sources":["../src/zip-hardhat-polkadot.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,gDAEC;AAnFD,+CAAoD;AAEpD,oFAAuD;AAEvD,MAAM,2BAA4B,SAAQ,iCAAmB;IACjD,2BAA2B;QACnC,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACtC,CAAC;IAES,0BAA0B;QAClC,OAAO;;;gBAGK,+BAAgB;;;;;;;;;;;;;;;;;;;;;;;;;EAyB9B,CAAC;IACD,CAAC;IAES,KAAK,CAAC,cAAc,CAAC,CAAW;QACxC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,wDAAa,8CAA8C,GAAC,CAAC;QAC9F,WAAW,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC;QAChC,OAAO,WAAW,CAAC;IACrB,CAAC;IAES,KAAK,CAAC,cAAc,CAAC,CAAW;QACxC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,wDAAa,mDAAmD,GAAC,CAAC;QACnG,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC;QAC7C,OAAO,WAAW,CAAC;IACrB,CAAC;IAES,6BAA6B;QACrC,OAAO;;;;;;;CAOV,CAAC;IACA,CAAC;IAES,uCAAuC;QAC/C,OAAO;;;;;CAKV,CAAC;IACA,CAAC;IAES,2BAA2B;QACnC,OAAO;;;KAGN,CAAC;IACJ,CAAC;CACF;AAEM,KAAK,UAAU,kBAAkB,CAAC,CAAW,EAAE,IAAqB;IACzE,OAAO,IAAI,2BAA2B,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AAC/D,CAAC"}
|
package/dist/zip-hardhat.d.ts
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import JSZip from 'jszip';
|
|
2
2
|
import type { GenericOptions } from './build-generic';
|
|
3
3
|
import type { Contract } from './contract';
|
|
4
|
+
export declare class HardhatZipGenerator {
|
|
5
|
+
protected getAdditionalHardhatImports(): string[];
|
|
6
|
+
protected getHardhatConfigJsonString(): string;
|
|
7
|
+
protected getHardhatConfig(upgradeable: boolean): string;
|
|
8
|
+
protected getTsConfig(): string;
|
|
9
|
+
protected getGitIgnoreHardhatIgnition(): string;
|
|
10
|
+
protected getGitIgnore(): string;
|
|
11
|
+
protected getTest(c: Contract, opts?: GenericOptions): string;
|
|
12
|
+
getDeploymentCall(c: Contract, args: string[]): string;
|
|
13
|
+
protected getScript(c: Contract): string;
|
|
14
|
+
private lowerFirstCharacter;
|
|
15
|
+
protected getIgnitionModule(c: Contract): string;
|
|
16
|
+
protected getReadmeTestingEnvironmentSetupSection(): string;
|
|
17
|
+
protected getReadmePrerequisitesSection(): string;
|
|
18
|
+
protected getReadme(c: Contract): string;
|
|
19
|
+
getHardhatPlugins(c: Contract): string[];
|
|
20
|
+
protected getPackageJson(c: Contract): Promise<unknown>;
|
|
21
|
+
protected getPackageLock(c: Contract): Promise<unknown>;
|
|
22
|
+
protected getPrintContract(c: Contract): string;
|
|
23
|
+
zipHardhat(c: Contract, opts?: GenericOptions): Promise<JSZip>;
|
|
24
|
+
}
|
|
4
25
|
export declare function zipHardhat(c: Contract, opts?: GenericOptions): Promise<JSZip>;
|
|
5
26
|
//# sourceMappingURL=zip-hardhat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zip-hardhat.d.ts","sourceRoot":"","sources":["../src/zip-hardhat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"zip-hardhat.d.ts","sourceRoot":"","sources":["../src/zip-hardhat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAoB,MAAM,YAAY,CAAC;AAqF7D,qBAAa,mBAAmB;IAC9B,SAAS,CAAC,2BAA2B,IAAI,MAAM,EAAE;IAIjD,SAAS,CAAC,0BAA0B,IAAI,MAAM;IAe9C,SAAS,CAAC,gBAAgB,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM;IAgBxD,SAAS,CAAC,WAAW,IAAI,MAAM;IAgB/B,SAAS,CAAC,2BAA2B,IAAI,MAAM;IAO/C,SAAS,CAAC,YAAY,IAAI,MAAM;IAehC,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,MAAM;IAItD,iBAAiB,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM;IAW7D,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM;IA0BxC,OAAO,CAAC,mBAAmB;IAI3B,SAAS,CAAC,iBAAiB,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM;IAchD,SAAS,CAAC,uCAAuC,IAAI,MAAM;IAI3D,SAAS,CAAC,6BAA6B,IAAI,MAAM;IAIjD,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM;IA4BjC,iBAAiB,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,EAAE;cAQ/B,cAAc,CAAC,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;cAQ7C,cAAc,CAAC,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ7D,SAAS,CAAC,gBAAgB,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM;IAIzC,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC;CAwBrE;AAED,wBAAsB,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,CAEnF"}
|
package/dist/zip-hardhat.js
CHANGED
|
@@ -36,17 +36,87 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.HardhatZipGenerator = void 0;
|
|
39
40
|
exports.zipHardhat = zipHardhat;
|
|
40
41
|
const jszip_1 = __importDefault(require("jszip"));
|
|
41
42
|
const print_1 = require("./print");
|
|
42
43
|
const solidity_version_json_1 = __importDefault(require("./solidity-version.json"));
|
|
43
44
|
const format_lines_1 = require("./utils/format-lines");
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
class TestGenerator {
|
|
46
|
+
constructor(parent) {
|
|
47
|
+
this.parent = parent;
|
|
48
|
+
}
|
|
49
|
+
getContent(c, opts) {
|
|
50
|
+
return (0, format_lines_1.formatLinesWithSpaces)(2, ...(0, format_lines_1.spaceBetween)(this.getImports(c), this.getTestCase(c, opts)));
|
|
51
|
+
}
|
|
52
|
+
getTestCase(c, opts) {
|
|
53
|
+
return [
|
|
54
|
+
`describe("${c.name}", function () {`,
|
|
55
|
+
[
|
|
56
|
+
'it("Test contract", async function () {',
|
|
57
|
+
(0, format_lines_1.spaceBetween)([`const ContractFactory = await ethers.getContractFactory("${c.name}");`], this.declareVariables(c.constructorArgs), this.getDeployLines(c, c.constructorArgs.map(a => a.name)), this.getExpects(opts)),
|
|
58
|
+
'});',
|
|
59
|
+
],
|
|
60
|
+
'});',
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
getImports(c) {
|
|
64
|
+
return [
|
|
65
|
+
'import { expect } from "chai";',
|
|
66
|
+
`import { ${this.parent.getHardhatPlugins(c).join(', ')} } from "hardhat";`,
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
getExpects(opts) {
|
|
70
|
+
if (opts !== undefined) {
|
|
71
|
+
switch (opts.kind) {
|
|
72
|
+
case 'ERC20':
|
|
73
|
+
case 'ERC721':
|
|
74
|
+
return [`expect(await instance.name()).to.equal("${opts.name}");`];
|
|
75
|
+
case 'ERC1155':
|
|
76
|
+
return [`expect(await instance.uri(0)).to.equal("${opts.uri}");`];
|
|
77
|
+
case 'Account':
|
|
78
|
+
case 'Governor':
|
|
79
|
+
case 'Custom':
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
throw new Error('Unknown ERC');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
declareVariables(args) {
|
|
88
|
+
return args.flatMap((arg, i) => {
|
|
89
|
+
if (arg.type === 'address') {
|
|
90
|
+
return [`const ${arg.name} = (await ethers.getSigners())[${i}].address;`];
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return [`// TODO: Set the following constructor argument`, `// const ${arg.name} = ...;`];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
getDeployLines(c, argNames) {
|
|
98
|
+
if (c.constructorArgs.some(a => a.type !== 'address')) {
|
|
99
|
+
return [
|
|
100
|
+
`// TODO: Uncomment the below when the missing constructor arguments are set above`,
|
|
101
|
+
`// const instance = await ${this.parent.getDeploymentCall(c, argNames)};`,
|
|
102
|
+
`// await instance.waitForDeployment();`,
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return [
|
|
107
|
+
`const instance = await ${this.parent.getDeploymentCall(c, argNames)};`,
|
|
108
|
+
'await instance.waitForDeployment();',
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
class HardhatZipGenerator {
|
|
114
|
+
getAdditionalHardhatImports() {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
getHardhatConfigJsonString() {
|
|
118
|
+
return `\
|
|
119
|
+
{
|
|
50
120
|
solidity: {
|
|
51
121
|
version: "${solidity_version_json_1.default}",
|
|
52
122
|
settings: {
|
|
@@ -56,11 +126,23 @@ const config: HardhatUserConfig = {
|
|
|
56
126
|
},
|
|
57
127
|
},
|
|
58
128
|
},
|
|
59
|
-
}
|
|
129
|
+
}`;
|
|
130
|
+
}
|
|
131
|
+
getHardhatConfig(upgradeable) {
|
|
132
|
+
const additionalImports = this.getAdditionalHardhatImports();
|
|
133
|
+
const importsSection = additionalImports.length > 0 ? additionalImports.map(imp => `import "${imp}";`).join('\n') + '\n' : '';
|
|
134
|
+
return `\
|
|
135
|
+
import { HardhatUserConfig } from "hardhat/config";
|
|
136
|
+
import "@nomicfoundation/hardhat-toolbox";
|
|
137
|
+
${importsSection}${upgradeable ? `import "@openzeppelin/hardhat-upgrades";` : ''}
|
|
138
|
+
|
|
139
|
+
const config: HardhatUserConfig = ${this.getHardhatConfigJsonString()};
|
|
60
140
|
|
|
61
141
|
export default config;
|
|
62
142
|
`;
|
|
63
|
-
|
|
143
|
+
}
|
|
144
|
+
getTsConfig() {
|
|
145
|
+
return `\
|
|
64
146
|
{
|
|
65
147
|
"compilerOptions": {
|
|
66
148
|
"target": "es2020",
|
|
@@ -73,7 +155,15 @@ const tsConfig = `\
|
|
|
73
155
|
}
|
|
74
156
|
}
|
|
75
157
|
`;
|
|
76
|
-
|
|
158
|
+
}
|
|
159
|
+
getGitIgnoreHardhatIgnition() {
|
|
160
|
+
return `
|
|
161
|
+
# Hardhat Ignition default folder for deployments against a local node
|
|
162
|
+
ignition/deployments/chain-31337
|
|
163
|
+
`;
|
|
164
|
+
}
|
|
165
|
+
getGitIgnore() {
|
|
166
|
+
return `\
|
|
77
167
|
node_modules
|
|
78
168
|
.env
|
|
79
169
|
coverage
|
|
@@ -84,78 +174,29 @@ typechain-types
|
|
|
84
174
|
# Hardhat files
|
|
85
175
|
cache
|
|
86
176
|
artifacts
|
|
87
|
-
`;
|
|
88
|
-
const test = (c, opts) => {
|
|
89
|
-
return (0, format_lines_1.formatLinesWithSpaces)(2, ...(0, format_lines_1.spaceBetween)(getImports(c), getTestCase(c)));
|
|
90
|
-
function getTestCase(c) {
|
|
91
|
-
const args = getAddressArgs(c);
|
|
92
|
-
return [
|
|
93
|
-
`describe("${c.name}", function () {`,
|
|
94
|
-
[
|
|
95
|
-
'it("Test contract", async function () {',
|
|
96
|
-
(0, format_lines_1.spaceBetween)([`const ContractFactory = await ethers.getContractFactory("${c.name}");`], getAddressVariables(args), [`const instance = await ${getDeploymentCall(c, args)};`, 'await instance.waitForDeployment();'], getExpects()),
|
|
97
|
-
'});',
|
|
98
|
-
],
|
|
99
|
-
'});',
|
|
100
|
-
];
|
|
101
|
-
}
|
|
102
|
-
function getImports(c) {
|
|
103
|
-
return ['import { expect } from "chai";', `import { ${getHardhatPlugins(c).join(', ')} } from "hardhat";`];
|
|
104
|
-
}
|
|
105
|
-
function getExpects() {
|
|
106
|
-
if (opts !== undefined) {
|
|
107
|
-
switch (opts.kind) {
|
|
108
|
-
case 'ERC20':
|
|
109
|
-
case 'ERC721':
|
|
110
|
-
return [`expect(await instance.name()).to.equal("${opts.name}");`];
|
|
111
|
-
case 'ERC1155':
|
|
112
|
-
return [`expect(await instance.uri(0)).to.equal("${opts.uri}");`];
|
|
113
|
-
case 'Account':
|
|
114
|
-
case 'Governor':
|
|
115
|
-
case 'Custom':
|
|
116
|
-
break;
|
|
117
|
-
default:
|
|
118
|
-
throw new Error('Unknown ERC');
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return [];
|
|
177
|
+
${this.getGitIgnoreHardhatIgnition()}`;
|
|
122
178
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
for (let i = 0; i < args.length; i++) {
|
|
126
|
-
vars.push(`const ${args[i]} = (await ethers.getSigners())[${i}].address;`);
|
|
127
|
-
}
|
|
128
|
-
return vars;
|
|
179
|
+
getTest(c, opts) {
|
|
180
|
+
return new TestGenerator(this).getContent(c, opts);
|
|
129
181
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
182
|
+
getDeploymentCall(c, args) {
|
|
183
|
+
// TODO: remove that selector when the upgrades plugin supports @custom:oz-upgrades-unsafe-allow-reachable
|
|
184
|
+
const unsafeAllowConstructor = c.parents.find(p => ['EIP712'].includes(p.contract.name)) !== undefined;
|
|
185
|
+
return !c.upgradeable
|
|
186
|
+
? `ContractFactory.deploy(${args.join(', ')})`
|
|
187
|
+
: unsafeAllowConstructor
|
|
188
|
+
? `upgrades.deployProxy(ContractFactory, [${args.join(', ')}], { unsafeAllow: ['constructor'] })`
|
|
189
|
+
: `upgrades.deployProxy(ContractFactory, [${args.join(', ')}])`;
|
|
137
190
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
// TODO: remove that selector when the upgrades plugin supports @custom:oz-upgrades-unsafe-allow-reachable
|
|
142
|
-
const unsafeAllowConstructor = c.parents.find(p => ['EIP712'].includes(p.contract.name)) !== undefined;
|
|
143
|
-
return !c.upgradeable
|
|
144
|
-
? `ContractFactory.deploy(${args.join(', ')})`
|
|
145
|
-
: unsafeAllowConstructor
|
|
146
|
-
? `upgrades.deployProxy(ContractFactory, [${args.join(', ')}], { unsafeAllow: 'constructor' })`
|
|
147
|
-
: `upgrades.deployProxy(ContractFactory, [${args.join(', ')}])`;
|
|
148
|
-
}
|
|
149
|
-
const script = (c) => {
|
|
150
|
-
const args = getAddressArgs(c);
|
|
151
|
-
return `\
|
|
152
|
-
import { ${getHardhatPlugins(c).join(', ')} } from "hardhat";
|
|
191
|
+
getScript(c) {
|
|
192
|
+
return `\
|
|
193
|
+
import { ${this.getHardhatPlugins(c).join(', ')} } from "hardhat";
|
|
153
194
|
|
|
154
195
|
async function main() {
|
|
155
196
|
const ContractFactory = await ethers.getContractFactory("${c.name}");
|
|
156
197
|
|
|
157
|
-
${
|
|
158
|
-
const instance = await ${getDeploymentCall(c,
|
|
198
|
+
${c.constructorArgs.length > 0 ? '// TODO: Set values for the constructor arguments below' : ''}
|
|
199
|
+
const instance = await ${this.getDeploymentCall(c, c.constructorArgs.map(a => a.name))};
|
|
159
200
|
await instance.waitForDeployment();
|
|
160
201
|
|
|
161
202
|
console.log(\`${c.upgradeable ? 'Proxy' : 'Contract'} deployed to \${await instance.getAddress()}\`);
|
|
@@ -168,34 +209,42 @@ main().catch((error) => {
|
|
|
168
209
|
process.exitCode = 1;
|
|
169
210
|
});
|
|
170
211
|
`;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
212
|
+
}
|
|
213
|
+
lowerFirstCharacter(str) {
|
|
214
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
215
|
+
}
|
|
216
|
+
getIgnitionModule(c) {
|
|
217
|
+
const contractVariableName = this.lowerFirstCharacter(c.name);
|
|
218
|
+
return `import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
|
|
177
219
|
|
|
178
220
|
export default buildModule("${c.name}Module", (m) => {
|
|
179
221
|
|
|
180
|
-
${
|
|
181
|
-
const ${contractVariableName} = m.contract("${c.name}", [${
|
|
222
|
+
${c.constructorArgs.length > 0 ? '// TODO: Set values for the constructor arguments below' : ''}
|
|
223
|
+
const ${contractVariableName} = m.contract("${c.name}", [${c.constructorArgs.map(a => a.name).join(', ')}]);
|
|
182
224
|
|
|
183
225
|
return { ${contractVariableName} };
|
|
184
226
|
});
|
|
185
227
|
`;
|
|
186
|
-
}
|
|
187
|
-
|
|
228
|
+
}
|
|
229
|
+
getReadmeTestingEnvironmentSetupSection() {
|
|
230
|
+
return '';
|
|
231
|
+
}
|
|
232
|
+
getReadmePrerequisitesSection() {
|
|
233
|
+
return '';
|
|
234
|
+
}
|
|
235
|
+
getReadme(c) {
|
|
236
|
+
return `\
|
|
188
237
|
# Sample Hardhat Project
|
|
189
238
|
|
|
190
239
|
This project demonstrates a basic Hardhat use case. It comes with a contract generated by [OpenZeppelin Wizard](https://wizard.openzeppelin.com/), a test for that contract, ${c.upgradeable ? 'and a script that deploys that contract' : 'and a Hardhat Ignition module that deploys that contract'}.
|
|
191
240
|
|
|
192
|
-
## Installing dependencies
|
|
241
|
+
${this.getReadmePrerequisitesSection()}## Installing dependencies
|
|
193
242
|
|
|
194
243
|
\`\`\`
|
|
195
244
|
npm install
|
|
196
245
|
\`\`\`
|
|
197
246
|
|
|
198
|
-
## Testing the contract
|
|
247
|
+
${this.getReadmeTestingEnvironmentSetupSection()}## Testing the contract
|
|
199
248
|
|
|
200
249
|
\`\`\`
|
|
201
250
|
npm test
|
|
@@ -209,37 +258,54 @@ You can target any network from your Hardhat config using:
|
|
|
209
258
|
${c.upgradeable ? 'npx hardhat run --network <network-name> scripts/deploy.ts' : `npx hardhat ignition deploy ignition/modules/${c.name}.ts --network <network-name>`}
|
|
210
259
|
\`\`\`
|
|
211
260
|
`;
|
|
212
|
-
function getHardhatPlugins(c) {
|
|
213
|
-
const plugins = ['ethers'];
|
|
214
|
-
if (c.upgradeable) {
|
|
215
|
-
plugins.push('upgrades');
|
|
216
261
|
}
|
|
217
|
-
|
|
262
|
+
getHardhatPlugins(c) {
|
|
263
|
+
const plugins = ['ethers'];
|
|
264
|
+
if (c.upgradeable) {
|
|
265
|
+
plugins.push('upgrades');
|
|
266
|
+
}
|
|
267
|
+
return plugins;
|
|
268
|
+
}
|
|
269
|
+
async getPackageJson(c) {
|
|
270
|
+
const { default: packageJson } = c.upgradeable
|
|
271
|
+
? await Promise.resolve().then(() => __importStar(require('./environments/hardhat/upgradeable/package.json')))
|
|
272
|
+
: await Promise.resolve().then(() => __importStar(require('./environments/hardhat/package.json')));
|
|
273
|
+
packageJson.license = c.license;
|
|
274
|
+
return packageJson;
|
|
275
|
+
}
|
|
276
|
+
async getPackageLock(c) {
|
|
277
|
+
const { default: packageLock } = c.upgradeable
|
|
278
|
+
? await Promise.resolve().then(() => __importStar(require('./environments/hardhat/upgradeable/package-lock.json')))
|
|
279
|
+
: await Promise.resolve().then(() => __importStar(require('./environments/hardhat/package-lock.json')));
|
|
280
|
+
packageLock.packages[''].license = c.license;
|
|
281
|
+
return packageLock;
|
|
282
|
+
}
|
|
283
|
+
getPrintContract(c) {
|
|
284
|
+
return (0, print_1.printContract)(c);
|
|
285
|
+
}
|
|
286
|
+
async zipHardhat(c, opts) {
|
|
287
|
+
const zip = new jszip_1.default();
|
|
288
|
+
const packageJson = await this.getPackageJson(c);
|
|
289
|
+
const packageLock = await this.getPackageLock(c);
|
|
290
|
+
zip.file(`contracts/${c.name}.sol`, this.getPrintContract(c));
|
|
291
|
+
zip.file('test/test.ts', this.getTest(c, opts));
|
|
292
|
+
if (c.upgradeable) {
|
|
293
|
+
zip.file('scripts/deploy.ts', this.getScript(c));
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
zip.file(`ignition/modules/${c.name}.ts`, this.getIgnitionModule(c));
|
|
297
|
+
}
|
|
298
|
+
zip.file('.gitignore', this.getGitIgnore());
|
|
299
|
+
zip.file('hardhat.config.ts', this.getHardhatConfig(c.upgradeable));
|
|
300
|
+
zip.file('package.json', JSON.stringify(packageJson, null, 2));
|
|
301
|
+
zip.file(`package-lock.json`, JSON.stringify(packageLock, null, 2));
|
|
302
|
+
zip.file('README.md', this.getReadme(c));
|
|
303
|
+
zip.file('tsconfig.json', this.getTsConfig());
|
|
304
|
+
return zip;
|
|
305
|
+
}
|
|
218
306
|
}
|
|
307
|
+
exports.HardhatZipGenerator = HardhatZipGenerator;
|
|
219
308
|
async function zipHardhat(c, opts) {
|
|
220
|
-
|
|
221
|
-
const { default: packageJson } = c.upgradeable
|
|
222
|
-
? await Promise.resolve().then(() => __importStar(require('./environments/hardhat/upgradeable/package.json')))
|
|
223
|
-
: await Promise.resolve().then(() => __importStar(require('./environments/hardhat/package.json')));
|
|
224
|
-
packageJson.license = c.license;
|
|
225
|
-
const { default: packageLock } = c.upgradeable
|
|
226
|
-
? await Promise.resolve().then(() => __importStar(require('./environments/hardhat/upgradeable/package-lock.json')))
|
|
227
|
-
: await Promise.resolve().then(() => __importStar(require('./environments/hardhat/package-lock.json')));
|
|
228
|
-
packageLock.packages[''].license = c.license;
|
|
229
|
-
zip.file(`contracts/${c.name}.sol`, (0, print_1.printContract)(c));
|
|
230
|
-
zip.file('test/test.ts', test(c, opts));
|
|
231
|
-
if (c.upgradeable) {
|
|
232
|
-
zip.file('scripts/deploy.ts', script(c));
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
zip.file(`ignition/modules/${c.name}.ts`, ignitionModule(c));
|
|
236
|
-
}
|
|
237
|
-
zip.file('.gitignore', gitIgnore);
|
|
238
|
-
zip.file('hardhat.config.ts', hardhatConfig(c.upgradeable));
|
|
239
|
-
zip.file('package.json', JSON.stringify(packageJson, null, 2));
|
|
240
|
-
zip.file(`package-lock.json`, JSON.stringify(packageLock, null, 2));
|
|
241
|
-
zip.file('README.md', readme(c));
|
|
242
|
-
zip.file('tsconfig.json', tsConfig);
|
|
243
|
-
return zip;
|
|
309
|
+
return new HardhatZipGenerator().zipHardhat(c, opts);
|
|
244
310
|
}
|
|
245
311
|
//# sourceMappingURL=zip-hardhat.js.map
|