diff --git a/contracts/DAO/Comp.sol b/contracts/DAO/Comp.sol index 24327b0..fef7afc 100644 --- a/contracts/DAO/Comp.sol +++ b/contracts/DAO/Comp.sol @@ -3,9 +3,10 @@ pragma solidity ^0.8.20; import "fhevm/abstracts/Reencrypt.sol"; import "fhevm/lib/TFHE.sol"; -import "../EncryptedERC20.sol"; +import "../token/ERC20/EncryptedERC20.sol"; +import "@openzeppelin/contracts/access/Ownable2Step.sol"; -contract Comp is EncryptedERC20 { +contract Comp is EncryptedERC20, Ownable2Step { /// @notice allowed smart contract address public allowedContract; @@ -44,8 +45,8 @@ contract Comp is EncryptedERC20 { /** * @notice Construct a new Comp token */ - constructor() EncryptedERC20("Compound", "COMP") { - mint(1000000); + constructor() EncryptedERC20("Compound", "COMP") Ownable(msg.sender) { + _mint(1000000); } /** diff --git a/contracts/EncryptedERC20.sol b/contracts/token/ERC20/EncryptedERC20.sol similarity index 94% rename from contracts/EncryptedERC20.sol rename to contracts/token/ERC20/EncryptedERC20.sol index 2977e8b..dd0b5cb 100644 --- a/contracts/EncryptedERC20.sol +++ b/contracts/token/ERC20/EncryptedERC20.sol @@ -4,10 +4,9 @@ pragma solidity ^0.8.20; import "fhevm/lib/TFHE.sol"; import "fhevm/abstracts/Reencrypt.sol"; -import "./utils/EncryptedErrors.sol"; -import "@openzeppelin/contracts/access/Ownable2Step.sol"; +import "../../utils/EncryptedErrors.sol"; -contract EncryptedERC20 is Reencrypt, Ownable2Step, EncryptedErrors { +abstract contract EncryptedERC20 is Reencrypt, EncryptedErrors { enum ErrorCodes { NO_ERROR, UNSUFFICIENT_BALANCE, @@ -37,10 +36,7 @@ contract EncryptedERC20 is Reencrypt, Ownable2Step, EncryptedErrors { // A mapping of the form mapping(owner => mapping(spender => allowance)). mapping(address => mapping(address => euint64)) internal allowances; - constructor( - string memory name_, - string memory symbol_ - ) Ownable(msg.sender) EncryptedErrors(uint8(type(ErrorCodes).max)) { + constructor(string memory name_, string memory symbol_) EncryptedErrors(uint8(type(ErrorCodes).max)) { _name = name_; _symbol = symbol_; } @@ -60,11 +56,6 @@ contract EncryptedERC20 is Reencrypt, Ownable2Step, EncryptedErrors { return _totalSupply; } - // Increase owner's balance by the given `mintedAmount`. - function mint(uint64 mintedAmount) public virtual onlyOwner { - _mint(mintedAmount); - } - // Increase sender's balance by the given `amount`. function _mint(uint64 amount) internal virtual { balances[msg.sender] = TFHE.add(balances[msg.sender], amount); // overflow impossible because of next line diff --git a/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol b/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol new file mode 100644 index 0000000..b0ea3ab --- /dev/null +++ b/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear + +pragma solidity ^0.8.20; + +import "../EncryptedERC20.sol"; +import "@openzeppelin/contracts/access/Ownable2Step.sol"; + +contract EncryptedERC20Mintable is Ownable2Step, EncryptedERC20 { + constructor( + string memory name_, + string memory symbol_, + address owner + ) Ownable(owner) EncryptedERC20(name_, symbol_) {} + + // Increase owner's balance by the given `mintedAmount`. + function mint(uint64 mintedAmount) public virtual onlyOwner { + _mint(mintedAmount); + } +} diff --git a/test/encryptedERC20/EncryptedERC20.fixture.ts b/test/encryptedERC20/EncryptedERC20.fixture.ts index cd92f6a..87d8051 100644 --- a/test/encryptedERC20/EncryptedERC20.fixture.ts +++ b/test/encryptedERC20/EncryptedERC20.fixture.ts @@ -1,13 +1,13 @@ import { ethers } from "hardhat"; -import type { EncryptedERC20 } from "../../types"; +import type { EncryptedERC20Mintable } from "../../types"; import { getSigners } from "../signers"; -export async function deployEncryptedERC20Fixture(): Promise { +export async function deployEncryptedERC20Fixture(): Promise { const signers = await getSigners(); - const contractFactory = await ethers.getContractFactory("EncryptedERC20"); - const contract = await contractFactory.connect(signers.alice).deploy("Naraggara", "NARA"); // City of Zama's battle + const contractFactory = await ethers.getContractFactory("EncryptedERC20Mintable"); + const contract = await contractFactory.connect(signers.alice).deploy("Naraggara", "NARA", signers.alice.address); // City of Zama's battle await contract.waitForDeployment(); return contract;