@openzeppelin/wizard 0.5.1 → 0.5.3
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/add-pausable.d.ts +1 -1
- package/dist/add-pausable.d.ts.map +1 -1
- package/dist/add-pausable.js.map +1 -1
- package/dist/api.d.ts +6 -6
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +7 -7
- package/dist/api.js.map +1 -1
- package/dist/build-generic.d.ts +7 -7
- package/dist/build-generic.d.ts.map +1 -1
- package/dist/build-generic.js +2 -1
- package/dist/build-generic.js.map +1 -1
- package/dist/common-functions.d.ts.map +1 -1
- package/dist/common-functions.js +1 -3
- package/dist/common-functions.js.map +1 -1
- package/dist/common-options.d.ts +3 -3
- package/dist/contract.d.ts +1 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +10 -6
- package/dist/contract.js.map +1 -1
- package/dist/custom.d.ts +2 -2
- package/dist/custom.d.ts.map +1 -1
- package/dist/custom.js.map +1 -1
- package/dist/environments/hardhat/package-lock.json +368 -246
- package/dist/environments/hardhat/upgradeable/package-lock.json +824 -1506
- package/dist/erc1155.d.ts +2 -2
- package/dist/erc1155.d.ts.map +1 -1
- package/dist/erc1155.js +2 -4
- package/dist/erc1155.js.map +1 -1
- package/dist/erc20.d.ts +9 -3
- package/dist/erc20.d.ts.map +1 -1
- package/dist/erc20.js +132 -11
- package/dist/erc20.js.map +1 -1
- package/dist/erc721.d.ts +3 -3
- package/dist/erc721.d.ts.map +1 -1
- package/dist/erc721.js +6 -7
- package/dist/erc721.js.map +1 -1
- package/dist/error.js +1 -1
- package/dist/error.js.map +1 -1
- package/dist/generate/alternatives.d.ts.map +1 -1
- package/dist/generate/alternatives.js.map +1 -1
- package/dist/generate/erc20.d.ts +1 -1
- package/dist/generate/erc20.d.ts.map +1 -1
- package/dist/generate/erc20.js +9 -1
- package/dist/generate/erc20.js.map +1 -1
- package/dist/generate/erc721.js.map +1 -1
- package/dist/generate/governor.d.ts +1 -1
- package/dist/generate/governor.d.ts.map +1 -1
- package/dist/generate/governor.js.map +1 -1
- package/dist/generate/sources.d.ts +1 -1
- package/dist/generate/sources.d.ts.map +1 -1
- package/dist/generate/sources.js +1 -5
- package/dist/generate/sources.js.map +1 -1
- package/dist/generate/stablecoin.d.ts.map +1 -1
- package/dist/generate/stablecoin.js +32 -15
- package/dist/generate/stablecoin.js.map +1 -1
- package/dist/get-imports.d.ts +4 -4
- package/dist/get-imports.js +4 -4
- package/dist/governor.d.ts +5 -5
- package/dist/governor.d.ts.map +1 -1
- package/dist/governor.js +19 -27
- 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/infer-transpiled.d.ts +1 -1
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js.map +1 -1
- package/dist/print-versioned.d.ts +1 -1
- package/dist/print-versioned.js +1 -1
- package/dist/print-versioned.js.map +1 -1
- package/dist/print.d.ts +1 -1
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +10 -15
- package/dist/print.js.map +1 -1
- package/dist/scripts/prepare.js +4 -2
- package/dist/scripts/prepare.js.map +1 -1
- package/dist/set-access-control.d.ts +1 -1
- package/dist/set-access-control.d.ts.map +1 -1
- package/dist/set-access-control.js +3 -3
- package/dist/set-access-control.js.map +1 -1
- package/dist/set-clock-mode.d.ts +2 -2
- package/dist/set-clock-mode.d.ts.map +1 -1
- package/dist/set-clock-mode.js +1 -1
- package/dist/set-info.d.ts +1 -1
- package/dist/set-info.d.ts.map +1 -1
- package/dist/set-upgradeable.d.ts +2 -2
- package/dist/set-upgradeable.d.ts.map +1 -1
- package/dist/set-upgradeable.js +3 -4
- package/dist/set-upgradeable.js.map +1 -1
- package/dist/stablecoin.d.ts +3 -3
- package/dist/stablecoin.d.ts.map +1 -1
- package/dist/stablecoin.js +8 -18
- package/dist/stablecoin.js.map +1 -1
- package/dist/test.js +1 -1
- package/dist/test.js.map +1 -1
- package/dist/utils/define-functions.d.ts.map +1 -1
- package/dist/utils/define-functions.js +1 -4
- package/dist/utils/define-functions.js.map +1 -1
- package/dist/utils/format-lines.d.ts.map +1 -1
- package/dist/utils/format-lines.js.map +1 -1
- package/dist/utils/map-values.d.ts.map +1 -1
- package/dist/utils/map-values.js +1 -0
- package/dist/utils/map-values.js.map +1 -1
- package/dist/utils/to-identifier.d.ts.map +1 -1
- package/dist/utils/to-identifier.js +3 -2
- package/dist/utils/to-identifier.js.map +1 -1
- package/dist/zip-foundry.d.ts +3 -3
- package/dist/zip-foundry.d.ts.map +1 -1
- package/dist/zip-foundry.js +23 -76
- package/dist/zip-foundry.js.map +1 -1
- package/dist/zip-hardhat.d.ts +3 -3
- package/dist/zip-hardhat.d.ts.map +1 -1
- package/dist/zip-hardhat.js +13 -15
- package/dist/zip-hardhat.js.map +1 -1
- package/package.json +3 -2
- package/src/add-pausable.ts +2 -1
- package/src/api.ts +55 -25
- package/src/build-generic.ts +21 -14
- package/src/common-functions.ts +1 -3
- package/src/common-options.ts +4 -4
- package/src/contract.ts +21 -19
- package/src/custom.ts +4 -3
- package/src/environments/hardhat/package-lock.json +368 -246
- package/src/environments/hardhat/upgradeable/package-lock.json +824 -1506
- package/src/erc1155.ts +8 -7
- package/src/erc20.ts +188 -23
- package/src/erc721.ts +16 -13
- package/src/error.ts +1 -1
- package/src/generate/alternatives.ts +2 -8
- package/src/generate/erc20.ts +10 -3
- package/src/generate/erc721.ts +1 -1
- package/src/generate/governor.ts +2 -1
- package/src/generate/sources.ts +11 -8
- package/src/generate/stablecoin.ts +35 -16
- package/src/get-imports.ts +5 -5
- package/src/governor.ts +56 -58
- package/src/index.ts +2 -2
- package/src/infer-transpiled.ts +2 -2
- package/src/kind.ts +0 -1
- package/src/options.ts +4 -3
- package/src/print-versioned.ts +4 -6
- package/src/print.ts +43 -45
- package/src/scripts/prepare.ts +10 -6
- package/src/set-access-control.ts +15 -9
- package/src/set-clock-mode.ts +5 -5
- package/src/set-info.ts +3 -3
- package/src/set-upgradeable.ts +6 -6
- package/src/stablecoin.ts +23 -27
- package/src/test.ts +6 -5
- package/src/utils/define-functions.ts +3 -12
- package/src/utils/duration.ts +2 -2
- package/src/utils/format-lines.ts +1 -5
- package/src/utils/map-values.ts +2 -4
- package/src/utils/to-identifier.ts +3 -2
- package/src/zip-foundry.ts +40 -102
- package/src/zip-hardhat.ts +24 -30
package/dist/zip-hardhat.js
CHANGED
|
@@ -92,22 +92,14 @@ const test = (c, opts) => {
|
|
|
92
92
|
`describe("${c.name}", function () {`,
|
|
93
93
|
[
|
|
94
94
|
'it("Test contract", async function () {',
|
|
95
|
-
(0, format_lines_1.spaceBetween)([
|
|
96
|
-
|
|
97
|
-
], getAddressVariables(args), [
|
|
98
|
-
`const instance = await ${getDeploymentCall(c, args)};`,
|
|
99
|
-
'await instance.waitForDeployment();'
|
|
100
|
-
], getExpects()),
|
|
101
|
-
'});'
|
|
95
|
+
(0, format_lines_1.spaceBetween)([`const ContractFactory = await ethers.getContractFactory("${c.name}");`], getAddressVariables(args), [`const instance = await ${getDeploymentCall(c, args)};`, 'await instance.waitForDeployment();'], getExpects()),
|
|
96
|
+
'});',
|
|
102
97
|
],
|
|
103
98
|
'});',
|
|
104
99
|
];
|
|
105
100
|
}
|
|
106
101
|
function getImports(c) {
|
|
107
|
-
return [
|
|
108
|
-
'import { expect } from "chai";',
|
|
109
|
-
`import { ${getHardhatPlugins(c).join(', ')} } from "hardhat";`,
|
|
110
|
-
];
|
|
102
|
+
return ['import { expect } from "chai";', `import { ${getHardhatPlugins(c).join(', ')} } from "hardhat";`];
|
|
111
103
|
}
|
|
112
104
|
function getExpects() {
|
|
113
105
|
if (opts !== undefined) {
|
|
@@ -144,7 +136,9 @@ function getAddressArgs(c) {
|
|
|
144
136
|
return args;
|
|
145
137
|
}
|
|
146
138
|
function getDeploymentCall(c, args) {
|
|
147
|
-
return c.upgradeable
|
|
139
|
+
return c.upgradeable
|
|
140
|
+
? `upgrades.deployProxy(ContractFactory, [${args.join(', ')}])`
|
|
141
|
+
: `ContractFactory.deploy(${args.join(', ')})`;
|
|
148
142
|
}
|
|
149
143
|
const script = (c) => {
|
|
150
144
|
const args = getAddressArgs(c);
|
|
@@ -195,7 +189,7 @@ npx hardhat run --network <network-name> scripts/deploy.ts
|
|
|
195
189
|
\`\`\`
|
|
196
190
|
`;
|
|
197
191
|
function getHardhatPlugins(c) {
|
|
198
|
-
|
|
192
|
+
const plugins = ['ethers'];
|
|
199
193
|
if (c.upgradeable) {
|
|
200
194
|
plugins.push('upgrades');
|
|
201
195
|
}
|
|
@@ -203,9 +197,13 @@ function getHardhatPlugins(c) {
|
|
|
203
197
|
}
|
|
204
198
|
async function zipHardhat(c, opts) {
|
|
205
199
|
const zip = new jszip_1.default();
|
|
206
|
-
const { default: packageJson } = c.upgradeable
|
|
200
|
+
const { default: packageJson } = c.upgradeable
|
|
201
|
+
? await Promise.resolve().then(() => __importStar(require('./environments/hardhat/upgradeable/package.json')))
|
|
202
|
+
: await Promise.resolve().then(() => __importStar(require('./environments/hardhat/package.json')));
|
|
207
203
|
packageJson.license = c.license;
|
|
208
|
-
const { default: packageLock } = c.upgradeable
|
|
204
|
+
const { default: packageLock } = c.upgradeable
|
|
205
|
+
? await Promise.resolve().then(() => __importStar(require('./environments/hardhat/upgradeable/package-lock.json')))
|
|
206
|
+
: await Promise.resolve().then(() => __importStar(require('./environments/hardhat/package-lock.json')));
|
|
209
207
|
packageLock.packages[''].license = c.license;
|
|
210
208
|
zip.file(`contracts/${c.name}.sol`, (0, print_1.printContract)(c));
|
|
211
209
|
zip.file('test/test.ts', test(c, opts));
|
package/dist/zip-hardhat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zip-hardhat.js","sourceRoot":"","sources":["../src/zip-hardhat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"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,sDAAsD,GAAC;QACtE,CAAC,CAAC,wDAAa,0CAA0C,GAAC,CAAC;IAC7D,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC;IAE7C,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,MAAM,EAAE,IAAA,qBAAa,EAAC,CAAC,CAAC,CAAC,CAAC;IACtD,GAAG,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;IACxC,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;IAClC,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE,aAAa,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC;IAC5D,GAAG,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/D,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACpE,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAC9B,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;IAEpC,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openzeppelin/wizard",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
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",
|
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
"prepare": "tsc && node dist/scripts/prepare.js",
|
|
18
18
|
"prepublish": "rimraf dist *.tsbuildinfo && hardhat clean",
|
|
19
19
|
"test": "ava",
|
|
20
|
+
"test:update-snapshots": "ava --update-snapshots",
|
|
20
21
|
"test:watch": "ava --watch",
|
|
21
|
-
"version": "node
|
|
22
|
+
"version": "node ../../../scripts/bump-changelog.js",
|
|
22
23
|
"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"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
package/src/add-pausable.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ContractBuilder, BaseFunction } from './contract';
|
|
2
|
-
import { Access
|
|
2
|
+
import type { Access } from './set-access-control';
|
|
3
|
+
import { requireAccessControl } from './set-access-control';
|
|
3
4
|
import { defineFunctions } from './utils/define-functions';
|
|
4
5
|
|
|
5
6
|
export function addPausable(c: ContractBuilder, access: Access, pausableFns: BaseFunction[]) {
|
package/src/api.ts
CHANGED
|
@@ -1,27 +1,57 @@
|
|
|
1
1
|
import type { CommonOptions } from './common-options';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import type { ERC20Options } from './erc20';
|
|
3
|
+
import {
|
|
4
|
+
printERC20,
|
|
5
|
+
defaults as erc20defaults,
|
|
6
|
+
isAccessControlRequired as erc20IsAccessControlRequired,
|
|
7
|
+
} from './erc20';
|
|
8
|
+
import type { ERC721Options } from './erc721';
|
|
9
|
+
import {
|
|
10
|
+
printERC721,
|
|
11
|
+
defaults as erc721defaults,
|
|
12
|
+
isAccessControlRequired as erc721IsAccessControlRequired,
|
|
13
|
+
} from './erc721';
|
|
14
|
+
import type { ERC1155Options } from './erc1155';
|
|
15
|
+
import {
|
|
16
|
+
printERC1155,
|
|
17
|
+
defaults as erc1155defaults,
|
|
18
|
+
isAccessControlRequired as erc1155IsAccessControlRequired,
|
|
19
|
+
} from './erc1155';
|
|
20
|
+
import type { StablecoinOptions } from './stablecoin';
|
|
21
|
+
import {
|
|
22
|
+
printStablecoin,
|
|
23
|
+
defaults as stablecoinDefaults,
|
|
24
|
+
isAccessControlRequired as stablecoinIsAccessControlRequired,
|
|
25
|
+
} from './stablecoin';
|
|
26
|
+
import type { GovernorOptions } from './governor';
|
|
27
|
+
import {
|
|
28
|
+
printGovernor,
|
|
29
|
+
defaults as governorDefaults,
|
|
30
|
+
isAccessControlRequired as governorIsAccessControlRequired,
|
|
31
|
+
} from './governor';
|
|
32
|
+
import type { CustomOptions } from './custom';
|
|
33
|
+
import {
|
|
34
|
+
printCustom,
|
|
35
|
+
defaults as customDefaults,
|
|
36
|
+
isAccessControlRequired as customIsAccessControlRequired,
|
|
37
|
+
} from './custom';
|
|
8
38
|
|
|
9
39
|
export interface WizardContractAPI<Options extends CommonOptions> {
|
|
10
40
|
/**
|
|
11
41
|
* Returns a string representation of a contract generated using the provided options. If opts is not provided, uses `defaults`.
|
|
12
42
|
*/
|
|
13
|
-
print: (opts?: Options) => string
|
|
14
|
-
|
|
43
|
+
print: (opts?: Options) => string;
|
|
44
|
+
|
|
15
45
|
/**
|
|
16
46
|
* The default options that are used for `print`.
|
|
17
47
|
*/
|
|
18
48
|
defaults: Required<Options>;
|
|
19
49
|
|
|
20
50
|
/**
|
|
21
|
-
* Whether any of the provided options require access control to be enabled. If this returns `true`, then calling `print` with the
|
|
22
|
-
* same options would cause the `access` option to default to `'ownable'` if it was `undefined` or `false`.
|
|
51
|
+
* Whether any of the provided options require access control to be enabled. If this returns `true`, then calling `print` with the
|
|
52
|
+
* same options would cause the `access` option to default to `'ownable'` if it was `undefined` or `false`.
|
|
23
53
|
*/
|
|
24
|
-
isAccessControlRequired: (opts: Partial<Options>) => boolean
|
|
54
|
+
isAccessControlRequired: (opts: Partial<Options>) => boolean;
|
|
25
55
|
}
|
|
26
56
|
|
|
27
57
|
export type ERC20 = WizardContractAPI<ERC20Options>;
|
|
@@ -35,35 +65,35 @@ export type Custom = WizardContractAPI<CustomOptions>;
|
|
|
35
65
|
export const erc20: ERC20 = {
|
|
36
66
|
print: printERC20,
|
|
37
67
|
defaults: erc20defaults,
|
|
38
|
-
isAccessControlRequired: erc20IsAccessControlRequired
|
|
39
|
-
}
|
|
68
|
+
isAccessControlRequired: erc20IsAccessControlRequired,
|
|
69
|
+
};
|
|
40
70
|
export const erc721: ERC721 = {
|
|
41
71
|
print: printERC721,
|
|
42
72
|
defaults: erc721defaults,
|
|
43
|
-
isAccessControlRequired: erc721IsAccessControlRequired
|
|
44
|
-
}
|
|
73
|
+
isAccessControlRequired: erc721IsAccessControlRequired,
|
|
74
|
+
};
|
|
45
75
|
export const erc1155: ERC1155 = {
|
|
46
76
|
print: printERC1155,
|
|
47
77
|
defaults: erc1155defaults,
|
|
48
|
-
isAccessControlRequired: erc1155IsAccessControlRequired
|
|
49
|
-
}
|
|
78
|
+
isAccessControlRequired: erc1155IsAccessControlRequired,
|
|
79
|
+
};
|
|
50
80
|
export const stablecoin: Stablecoin = {
|
|
51
81
|
print: printStablecoin,
|
|
52
82
|
defaults: stablecoinDefaults,
|
|
53
|
-
isAccessControlRequired: stablecoinIsAccessControlRequired
|
|
54
|
-
}
|
|
83
|
+
isAccessControlRequired: stablecoinIsAccessControlRequired,
|
|
84
|
+
};
|
|
55
85
|
export const realWorldAsset: RealWorldAsset = {
|
|
56
86
|
print: printStablecoin,
|
|
57
87
|
defaults: stablecoinDefaults,
|
|
58
|
-
isAccessControlRequired: stablecoinIsAccessControlRequired
|
|
59
|
-
}
|
|
88
|
+
isAccessControlRequired: stablecoinIsAccessControlRequired,
|
|
89
|
+
};
|
|
60
90
|
export const governor: Governor = {
|
|
61
91
|
print: printGovernor,
|
|
62
92
|
defaults: governorDefaults,
|
|
63
|
-
isAccessControlRequired: governorIsAccessControlRequired
|
|
64
|
-
}
|
|
93
|
+
isAccessControlRequired: governorIsAccessControlRequired,
|
|
94
|
+
};
|
|
65
95
|
export const custom: Custom = {
|
|
66
96
|
print: printCustom,
|
|
67
97
|
defaults: customDefaults,
|
|
68
|
-
isAccessControlRequired: customIsAccessControlRequired
|
|
69
|
-
}
|
|
98
|
+
isAccessControlRequired: customIsAccessControlRequired,
|
|
99
|
+
};
|
package/src/build-generic.ts
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
import { CustomOptions
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import type { CustomOptions } from './custom';
|
|
2
|
+
import { buildCustom } from './custom';
|
|
3
|
+
import type { ERC20Options } from './erc20';
|
|
4
|
+
import { buildERC20 } from './erc20';
|
|
5
|
+
import type { ERC721Options } from './erc721';
|
|
6
|
+
import { buildERC721 } from './erc721';
|
|
7
|
+
import type { ERC1155Options } from './erc1155';
|
|
8
|
+
import { buildERC1155 } from './erc1155';
|
|
9
|
+
import type { StablecoinOptions } from './stablecoin';
|
|
10
|
+
import { buildStablecoin } from './stablecoin';
|
|
11
|
+
import type { GovernorOptions } from './governor';
|
|
12
|
+
import { buildGovernor } from './governor';
|
|
13
|
+
import type { Contract } from './contract';
|
|
8
14
|
|
|
9
15
|
export interface KindedOptions {
|
|
10
|
-
ERC20:
|
|
11
|
-
ERC721:
|
|
12
|
-
ERC1155:
|
|
13
|
-
Stablecoin:
|
|
14
|
-
RealWorldAsset:
|
|
16
|
+
ERC20: { kind: 'ERC20' } & ERC20Options;
|
|
17
|
+
ERC721: { kind: 'ERC721' } & ERC721Options;
|
|
18
|
+
ERC1155: { kind: 'ERC1155' } & ERC1155Options;
|
|
19
|
+
Stablecoin: { kind: 'Stablecoin' } & StablecoinOptions;
|
|
20
|
+
RealWorldAsset: { kind: 'RealWorldAsset' } & StablecoinOptions;
|
|
15
21
|
Governor: { kind: 'Governor' } & GovernorOptions;
|
|
16
|
-
Custom:
|
|
22
|
+
Custom: { kind: 'Custom' } & CustomOptions;
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
export type GenericOptions = KindedOptions[keyof KindedOptions];
|
|
@@ -41,8 +47,9 @@ export function buildGeneric(opts: GenericOptions): Contract {
|
|
|
41
47
|
case 'Custom':
|
|
42
48
|
return buildCustom(opts);
|
|
43
49
|
|
|
44
|
-
default:
|
|
50
|
+
default: {
|
|
45
51
|
const _: never = opts;
|
|
46
52
|
throw new Error('Unknown ERC');
|
|
53
|
+
}
|
|
47
54
|
}
|
|
48
55
|
}
|
package/src/common-functions.ts
CHANGED
|
@@ -3,9 +3,7 @@ import type { BaseFunction } from './contract';
|
|
|
3
3
|
export const supportsInterface: BaseFunction = {
|
|
4
4
|
name: 'supportsInterface',
|
|
5
5
|
kind: 'public',
|
|
6
|
-
args: [
|
|
7
|
-
{ name: 'interfaceId', type: 'bytes4' },
|
|
8
|
-
],
|
|
6
|
+
args: [{ name: 'interfaceId', type: 'bytes4' }],
|
|
9
7
|
returns: ['bool'],
|
|
10
8
|
mutability: 'view',
|
|
11
9
|
};
|
package/src/common-options.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Access } from
|
|
2
|
-
import type { Info } from
|
|
3
|
-
import { defaults as infoDefaults } from
|
|
4
|
-
import type { Upgradeable } from
|
|
1
|
+
import type { Access } from './set-access-control';
|
|
2
|
+
import type { Info } from './set-info';
|
|
3
|
+
import { defaults as infoDefaults } from './set-info';
|
|
4
|
+
import type { Upgradeable } from './set-upgradeable';
|
|
5
5
|
|
|
6
6
|
export const defaults: Required<CommonOptions> = {
|
|
7
7
|
access: false,
|
package/src/contract.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface Contract {
|
|
|
13
13
|
upgradeable: boolean;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export type Value = string | number | { lit: string } | { note: string
|
|
16
|
+
export type Value = string | number | { lit: string } | { note: string; value: Value };
|
|
17
17
|
|
|
18
18
|
export interface Parent {
|
|
19
19
|
contract: ImportContract;
|
|
@@ -53,15 +53,13 @@ export interface ContractFunction extends BaseFunction {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export type FunctionKind = 'internal' | 'public';
|
|
56
|
-
export type FunctionMutability = typeof mutabilityRank[number];
|
|
56
|
+
export type FunctionMutability = (typeof mutabilityRank)[number];
|
|
57
57
|
|
|
58
58
|
// Order is important
|
|
59
59
|
const mutabilityRank = ['pure', 'view', 'nonpayable', 'payable'] as const;
|
|
60
60
|
|
|
61
61
|
function maxMutability(a: FunctionMutability, b: FunctionMutability): FunctionMutability {
|
|
62
|
-
return mutabilityRank[
|
|
63
|
-
Math.max(mutabilityRank.indexOf(a), mutabilityRank.indexOf(b))
|
|
64
|
-
]!;
|
|
62
|
+
return mutabilityRank[Math.max(mutabilityRank.indexOf(a), mutabilityRank.indexOf(b))]!;
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
export interface FunctionArgument {
|
|
@@ -94,22 +92,21 @@ export class ContractBuilder implements Contract {
|
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
get parents(): Parent[] {
|
|
97
|
-
return [...this.parentMap.values()]
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
return [...this.parentMap.values()]
|
|
96
|
+
.filter(p => !p.importOnly)
|
|
97
|
+
.sort((a, b) => {
|
|
98
|
+
if (a.contract.name === 'Initializable') {
|
|
99
|
+
return -1;
|
|
100
|
+
} else if (b.contract.name === 'Initializable') {
|
|
101
|
+
return 1;
|
|
102
|
+
} else {
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
get imports(): ImportContract[] {
|
|
109
|
-
return [
|
|
110
|
-
...[...this.parentMap.values()].map(p => p.contract),
|
|
111
|
-
...this.using.map(u => u.library),
|
|
112
|
-
];
|
|
109
|
+
return [...[...this.parentMap.values()].map(p => p.contract), ...this.using.map(u => u.library)];
|
|
113
110
|
}
|
|
114
111
|
|
|
115
112
|
get functions(): ContractFunction[] {
|
|
@@ -128,7 +125,11 @@ export class ContractBuilder implements Contract {
|
|
|
128
125
|
|
|
129
126
|
addImportOnly(contract: ImportContract): boolean {
|
|
130
127
|
const present = this.parentMap.has(contract.name);
|
|
131
|
-
this.parentMap.set(contract.name, {
|
|
128
|
+
this.parentMap.set(contract.name, {
|
|
129
|
+
contract,
|
|
130
|
+
params: [],
|
|
131
|
+
importOnly: true,
|
|
132
|
+
});
|
|
132
133
|
return !present;
|
|
133
134
|
}
|
|
134
135
|
|
|
@@ -146,6 +147,7 @@ export class ContractBuilder implements Contract {
|
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
addNatspecTag(key: string, value: string) {
|
|
150
|
+
// eslint-disable-next-line no-useless-escape
|
|
149
151
|
if (!/^(@custom:)?[a-z][a-z\-]*$/.exec(key)) throw new Error(`Invalid natspec key: ${key}`);
|
|
150
152
|
this.natspecTags.push({ key, value });
|
|
151
153
|
}
|
package/src/custom.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Contract
|
|
2
|
-
import {
|
|
1
|
+
import type { Contract } from './contract';
|
|
2
|
+
import { ContractBuilder } from './contract';
|
|
3
|
+
import type { CommonOptions } from './common-options';
|
|
4
|
+
import { withCommonDefaults, defaults as commonDefaults } from './common-options';
|
|
3
5
|
import { setUpgradeable } from './set-upgradeable';
|
|
4
6
|
import { setInfo } from './set-info';
|
|
5
7
|
import { setAccessControl } from './set-access-control';
|
|
@@ -52,4 +54,3 @@ export function buildCustom(opts: CustomOptions): Contract {
|
|
|
52
54
|
|
|
53
55
|
return c;
|
|
54
56
|
}
|
|
55
|
-
|