Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use named imports for Solidity #411

Merged
merged 18 commits into from
Nov 20, 2024
Merged
4 changes: 4 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.4.6 (2024-11-20)

- Use named imports. ([#411](https://github.com/OpenZeppelin/contracts-wizard/pull/411))

## 0.4.5 (2024-11-18)

- Add `stablecoin` and `realWorldAsset` contract types. ([#404](https://github.com/OpenZeppelin/contracts-wizard/pull/404))
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openzeppelin/wizard",
"version": "0.4.5",
"version": "0.4.6",
"description": "A boilerplate generator to get started with OpenZeppelin Contracts",
"license": "MIT",
"repository": "github:OpenZeppelin/contracts-wizard",
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/contract.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "./Bar.sol";␊
import {Bar} from "./Bar.sol";␊
contract Foo is Bar {␊
}␊
Expand All @@ -38,8 +38,8 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "./Bar.sol";␊
import "./Quux.sol";␊
import {Bar} from "./Bar.sol";␊
import {Quux} from "./Quux.sol";␊
contract Foo is Bar, Quux {␊
}␊
Expand All @@ -53,7 +53,7 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "./Bar.sol";␊
import {Bar} from "./Bar.sol";␊
contract Foo is Bar {␊
constructor() Bar("param1", "param2") {}␊
Expand All @@ -68,8 +68,8 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "./Bar.sol";␊
import "./Quux.sol";␊
import {Bar} from "./Bar.sol";␊
import {Quux} from "./Quux.sol";␊
contract Foo is Bar, Quux {␊
constructor() Bar("param1", "param2") {}␊
Expand Down Expand Up @@ -183,7 +183,7 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "./Bar.sol";␊
import {Bar} from "./Bar.sol";␊
contract Foo is Bar {␊
constructor() Bar("param1", "param2") {␊
Expand Down
Binary file modified packages/core/src/contract.test.ts.snap
Binary file not shown.
21 changes: 14 additions & 7 deletions packages/core/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface Contract {
license: string;
parents: Parent[];
natspecTags: NatspecTag[];
imports: ParentContract[];
imports: ImportContract[];
functions: ContractFunction[];
constructorCode: string[];
constructorArgs: FunctionArgument[];
Expand All @@ -16,11 +16,12 @@ export interface Contract {
export type Value = string | number | { lit: string } | { note: string, value: Value };

export interface Parent {
contract: ParentContract;
contract: ImportContract;
params: Value[];
importOnly?: boolean;
}

export interface ParentContract extends ReferencedContract {
export interface ImportContract extends ReferencedContract {
path: string;
}

Expand All @@ -30,7 +31,7 @@ export interface ReferencedContract {
}

export interface Using {
library: ParentContract;
library: ImportContract;
usingFor: string;
}

Expand Down Expand Up @@ -93,7 +94,7 @@ export class ContractBuilder implements Contract {
}

get parents(): Parent[] {
return [...this.parentMap.values()].sort((a, b) => {
return [...this.parentMap.values()].filter(p => !p.importOnly).sort((a, b) => {
if (a.contract.name === 'Initializable') {
return -1;
} else if (b.contract.name === 'Initializable') {
Expand All @@ -104,7 +105,7 @@ export class ContractBuilder implements Contract {
});
}

get imports(): ParentContract[] {
get imports(): ImportContract[] {
return [
...[...this.parentMap.values()].map(p => p.contract),
...this.using.map(u => u.library),
Expand All @@ -119,12 +120,18 @@ export class ContractBuilder implements Contract {
return [...this.variableSet];
}

addParent(contract: ParentContract, params: Value[] = []): boolean {
addParent(contract: ImportContract, params: Value[] = []): boolean {
const present = this.parentMap.has(contract.name);
this.parentMap.set(contract.name, { contract, params });
return !present;
}

addImportOnly(contract: ImportContract): boolean {
const present = this.parentMap.has(contract.name);
this.parentMap.set(contract.name, { contract, params: [], importOnly: true });
return !present;
}

addOverride(parent: ReferencedContract, baseFn: BaseFunction, mutability?: FunctionMutability) {
const fn = this.addFunction(baseFn);
fn.override.add(parent);
Expand Down
24 changes: 12 additions & 12 deletions packages/core/src/custom.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts/utils/Pausable.sol";␊
import "@openzeppelin/contracts/access/Ownable.sol";␊
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";␊
contract MyContract is Pausable, Ownable {␊
constructor(address initialOwner) Ownable(initialOwner) {}␊
Expand All @@ -48,7 +48,7 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
contract MyContract is Initializable {␊
/// @custom:oz-upgrades-unsafe-allow constructor␊
Expand All @@ -66,9 +66,9 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";␊
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";␊
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";␊
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";␊
contract MyContract is Initializable, OwnableUpgradeable, UUPSUpgradeable {␊
/// @custom:oz-upgrades-unsafe-allow constructor␊
Expand Down Expand Up @@ -109,7 +109,7 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts/access/Ownable.sol";␊
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊
contract MyContract is Ownable {␊
constructor(address initialOwner) Ownable(initialOwner) {}␊
Expand All @@ -124,7 +124,7 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts/access/AccessControl.sol";␊
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊
contract MyContract is AccessControl {␊
constructor(address defaultAdmin) {␊
Expand All @@ -141,7 +141,7 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊
import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊
contract MyContract is AccessManaged {␊
constructor(address initialAuthority) AccessManaged(initialAuthority) {}␊
Expand All @@ -156,9 +156,9 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";␊
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";␊
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";␊
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";␊
contract MyContract is Initializable, OwnableUpgradeable, UUPSUpgradeable {␊
/// @custom:oz-upgrades-unsafe-allow constructor␊
Expand Down
Binary file modified packages/core/src/custom.test.ts.snap
Binary file not shown.
78 changes: 39 additions & 39 deletions packages/core/src/erc1155.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import "@openzeppelin/contracts/access/Ownable.sol";␊
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊
contract MyToken is ERC1155, Ownable {␊
constructor(address initialOwner)␊
Expand All @@ -35,8 +35,8 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import "@openzeppelin/contracts/access/AccessControl.sol";␊
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
contract MyToken is ERC1155, AccessControl {␊
bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE");␊
Expand Down Expand Up @@ -72,8 +72,8 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊
import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
contract MyToken is ERC1155, AccessManaged {␊
constructor(address initialAuthority)␊
Expand All @@ -95,7 +95,7 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
contract MyToken is ERC1155 {␊
constructor()␊
Expand All @@ -112,9 +112,9 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import "@openzeppelin/contracts/access/Ownable.sol";␊
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";␊
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import {ERC1155Burnable} from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";␊
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊
contract MyToken is ERC1155, Ownable, ERC1155Burnable {␊
constructor(address initialOwner)␊
Expand All @@ -136,9 +136,9 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import "@openzeppelin/contracts/access/Ownable.sol";␊
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Pausable.sol";␊
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import {ERC1155Pausable} from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Pausable.sol";␊
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊
contract MyToken is ERC1155, Ownable, ERC1155Pausable {␊
constructor(address initialOwner)␊
Expand Down Expand Up @@ -177,8 +177,8 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import "@openzeppelin/contracts/access/Ownable.sol";␊
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊
contract MyToken is ERC1155, Ownable {␊
constructor(address initialOwner)␊
Expand Down Expand Up @@ -214,8 +214,8 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import "@openzeppelin/contracts/access/AccessControl.sol";␊
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";␊
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
contract MyToken is ERC1155, AccessControl {␊
bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE");␊
Expand Down Expand Up @@ -267,8 +267,8 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊
import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";␊
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
contract MyToken is ERC1155, AccessManaged {␊
constructor(address initialAuthority)␊
Expand Down Expand Up @@ -304,9 +304,9 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import "@openzeppelin/contracts/access/Ownable.sol";␊
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";␊
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
import {ERC1155Supply} from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";␊
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";␊
contract MyToken is ERC1155, Ownable, ERC1155Supply {␊
constructor(address initialOwner)␊
Expand Down Expand Up @@ -337,11 +337,11 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";␊
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";␊
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155PausableUpgradeable.sol";␊
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol";␊
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";␊
import {ERC1155Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";␊
import {ERC1155BurnableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol";␊
import {ERC1155PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155PausableUpgradeable.sol";␊
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
contract MyToken is Initializable, ERC1155Upgradeable, AccessControlUpgradeable, ERC1155PausableUpgradeable, ERC1155BurnableUpgradeable {␊
bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE");␊
Expand Down Expand Up @@ -420,12 +420,12 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";␊
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";␊
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155PausableUpgradeable.sol";␊
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol";␊
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";␊
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";␊
import {ERC1155Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";␊
import {ERC1155BurnableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol";␊
import {ERC1155PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155PausableUpgradeable.sol";␊
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";␊
contract MyToken is Initializable, ERC1155Upgradeable, AccessControlUpgradeable, ERC1155PausableUpgradeable, ERC1155BurnableUpgradeable, UUPSUpgradeable {␊
bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE");␊
Expand Down Expand Up @@ -513,12 +513,12 @@ Generated by [AVA](https://avajs.dev).
// Compatible with OpenZeppelin Contracts ^5.0.0␊
pragma solidity ^0.8.22;␊
import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";␊
import "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";␊
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155PausableUpgradeable.sol";␊
import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol";␊
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";␊
import {AccessManagedUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";␊
import {ERC1155Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";␊
import {ERC1155BurnableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol";␊
import {ERC1155PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155PausableUpgradeable.sol";␊
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";␊
contract MyToken is Initializable, ERC1155Upgradeable, AccessManagedUpgradeable, ERC1155PausableUpgradeable, ERC1155BurnableUpgradeable, UUPSUpgradeable {␊
/// @custom:oz-upgrades-unsafe-allow constructor␊
Expand Down
Binary file modified packages/core/src/erc1155.test.ts.snap
Binary file not shown.
Loading