OpenZeppelin / contracts-wizard

Interactive smart contract generator based on OpenZeppelin Contracts.
https://wizard.openzeppelin.com
MIT License
244 stars 135 forks source link

Used named imports for Solidity #352

Open ericglau opened 5 months ago

MukulKolpe commented 1 month ago

Hey @ericglau, can I work on this one?

ericglau commented 1 month ago

@MukulKolpe Sure, thanks! See https://github.com/OpenZeppelin/contracts-wizard?tab=readme-ov-file#development for local development setup steps.

MukulKolpe commented 1 month ago

Hi @ericglau,

Just to clarify, the issue pertains to using named imports in the existing Solidity contracts, correct? It’s not about updating the scripts that generate the contracts after running yarn install to ensure that the generated contracts have named imports?

Additionally, there is only one Solidity contract, SafetyCheck.sol, in this context, correct?

Thank you!

ericglau commented 1 month ago

Hi @MukulKolpe, to clarify, this issue is to modify the code generator logic to generate all contracts using imports that specify the name of the symbol being imported.

For example, if ERC20 with Ownable and UUPS options were enabled, then previously the generated code was:

// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

contract MyToken is Initializable, ERC20Upgradeable, OwnableUpgradeable, UUPSUpgradeable {
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    function initialize(address initialOwner) initializer public {
        __ERC20_init("MyToken", "MTK");
        __Ownable_init(initialOwner);
        __UUPSUpgradeable_init();
    }

    function _authorizeUpgrade(address newImplementation)
        internal
        onlyOwner
        override
    {}
}

but this issue proposes to change the code generator to output the following instead:

// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;

import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.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, ERC20Upgradeable, OwnableUpgradeable, UUPSUpgradeable {
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    function initialize(address initialOwner) initializer public {
        __ERC20_init("MyToken", "MTK");
        __Ownable_init(initialOwner);
        __UUPSUpgradeable_init();
    }

    function _authorizeUpgrade(address newImplementation)
        internal
        onlyOwner
        override
    {}
}
ericglau commented 1 month ago

Let me know if you are still interested in taking this on, considering the above. Thanks!

MukulKolpe commented 1 month ago

Hey @ericglau, Thanks for the details! I'm still very much interested in working on this. I'll let you know if I have any questions.

SKYBITDev3 commented 4 weeks ago

I was going to create a new issue for this, but found this one. @MukulKolpe how's progress?