contracts-wizard
contracts-wizard copied to clipboard
Used named imports for Solidity
Hey @ericglau, can I work on this one?
@MukulKolpe Sure, thanks! See https://github.com/OpenZeppelin/contracts-wizard?tab=readme-ov-file#development for local development setup steps.
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!
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
{}
}
Let me know if you are still interested in taking this on, considering the above. Thanks!
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.
I was going to create a new issue for this, but found this one. @MukulKolpe how's progress?