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

Add Alternatives to OpenZeppelin to gas optimization #744

Merged
merged 3 commits into from
Oct 11, 2024

Conversation

jackleeio
Copy link
Contributor

Pre-flight checklist

Copy link

vercel bot commented Sep 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
conflux-documentation ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 10, 2024 3:53pm

Copy link
Collaborator

@0xn1c0 0xn1c0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The smart contract has some issues and cannot be compiled or deployed like that.
Issues found are:

  • The mint function is not defined in the base ERC20 contracts from Solmate or Solady by default. The mint functionality needs to be explicitly implemented in the SolmateToken and SoladyToken contracts.
  • Conflicting declarations of the ERC20 identifier, as you are importing different versions of the ERC20 contract from OpenZeppelin, Solmate, and Solady, all of which define a contract named ERC20. To fix this, you need to alias the imported contracts to avoid name conflicts. You can do this by renaming the imports for Solmate and Solady's ERC20 implementations in your Solidity file.

Here is the corrected smart contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// OpenZeppelin ERC20
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

// Solmate ERC20 (alias as SolmateERC20)
import {ERC20 as SolmateERC20} from "node_modules/solmate/src/tokens/ERC20.sol";

// Solady ERC20 (alias as SoladyERC20)
import {ERC20 as SoladyERC20} from "node_modules/solady/src/tokens/ERC20.sol";

contract OpenZeppelinToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("OpenZeppelinToken", "OZT") {
        _mint(msg.sender, initialSupply);
    }
}

contract SolmateToken is SolmateERC20 {
    constructor(uint256 initialSupply) SolmateERC20("SolmateToken", "SMT", 18) {
        _mint(msg.sender, initialSupply); // Using _mint because Solmate doesn’t provide mint by default
    }

    function mint(address to, uint256 amount) public {
        _mint(to, amount); // Implement mint function
    }
}

contract SoladyToken is SoladyERC20 {
    constructor(uint256 initialSupply) {
        _mint(msg.sender, initialSupply); // Using _mint because Solady doesn’t provide mint by default
    }

    function mint(address to, uint256 amount) public {
        _mint(to, amount); // Implement mint function
    }

    function name() public pure override returns (string memory) {
        return "SoladyToken";
    }

    function symbol() public pure override returns (string memory) {
        return "SDT";
    }

    function decimals() public pure override returns (uint8) {
        return 18;
    }
}

@0xn1c0 0xn1c0 merged commit 4ed861c into Conflux-Chain:main Oct 11, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants