contracts-wizard icon indicating copy to clipboard operation
contracts-wizard copied to clipboard

Used named imports for Solidity

Open ericglau opened this issue 10 months ago • 7 comments

ericglau avatar Apr 03 '24 14:04 ericglau

Hey @ericglau, can I work on this one?

MukulKolpe avatar Jul 12 '24 21:07 MukulKolpe

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

ericglau avatar Jul 15 '24 00:07 ericglau

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!

MukulKolpe avatar Jul 19 '24 09:07 MukulKolpe

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 avatar Jul 19 '24 14:07 ericglau

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

ericglau avatar Jul 19 '24 14:07 ericglau

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.

MukulKolpe avatar Jul 20 '24 08:07 MukulKolpe

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

SKYBITDev3 avatar Aug 07 '24 07:08 SKYBITDev3