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

refactor: rename EncryptedERC20 to ConfidentialERC20 #75

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ inherited contracts.
pragma solidity ^0.8.24;

import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { EncryptedERC20 } from "fhevm-contracts/contracts/token/ERC20/EncryptedERC20.sol";
import { ConfidentialERC20 } from "fhevm-contracts/contracts/token/ERC20/ConfidentialERC20.sol";

contract MyERC20 is MockZamaFHEVMConfig, EncryptedERC20 {
constructor() EncryptedERC20("MyToken", "MYTOKEN") {
contract MyERC20 is MockZamaFHEVMConfig, ConfidentialERC20 {
constructor() ConfidentialERC20("MyToken", "MYTOKEN") {
_unsafeMint(1000000, msg.sender);
}
}
Expand All @@ -53,10 +53,10 @@ contract MyERC20 is MockZamaFHEVMConfig, EncryptedERC20 {
pragma solidity ^0.8.24;

import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { EncryptedERC20 } from "fhevm-contracts/contracts/token/ERC20/EncryptedERC20.sol";
import { ConfidentialERC20 } from "fhevm-contracts/contracts/token/ERC20/ConfidentialERC20.sol";

contract MyERC20 is SepoliaZamaFHEVMConfig, EncryptedERC20 {
constructor() EncryptedERC20("MyToken", "MYTOKEN") {
contract MyERC20 is SepoliaZamaFHEVMConfig, ConfidentialERC20 {
constructor() ConfidentialERC20("MyToken", "MYTOKEN") {
_unsafeMint(1000000, msg.sender);
}
}
Expand All @@ -68,15 +68,15 @@ These Solidity templates include governance-related and token-related contracts.

### Token

- [EncryptedERC20](./contracts/token/ERC20/EncryptedERC20.sol)
- [EncryptedERC20Mintable](./contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol)
- [EncryptedERC20WithErrors](./contracts/token/ERC20/extensions/EncryptedERC20WithErrors.sol)
- [EncryptedERC20WithErrorsMintable](./contracts/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.sol)
- [ConfidentialERC20](./contracts/token/ERC20/ConfidentialERC20.sol)
- [ConfidentialERC20Mintable](./contracts/token/ERC20/extensions/ConfidentialERC20Mintable.sol)
- [ConfidentialERC20WithErrors](./contracts/token/ERC20/extensions/ConfidentialERC20WithErrors.sol)
- [ConfidentialERC20WithErrorsMintable](./contracts/token/ERC20/extensions/ConfidentialERC20WithErrorsMintable.sol)

### Governance

- [Comp](./contracts/governance/Comp.sol)
- [GovernorAlphaZama](./contracts/governance/GovernorAlphaZama.sol)
- [ConfidentialERC20Votes](./contracts/governance/ConfidentialERC20Votes.sol)
- [ConfidentialGovernorAlpha](./contracts/governance/ConfidentialGovernorAlpha.sol)

### Utils

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import "fhevm/lib/TFHE.sol";
import { Ownable2Step, Ownable } from "@openzeppelin/contracts/access/Ownable2Step.sol";
import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import { EncryptedERC20 } from "../token/ERC20/EncryptedERC20.sol";
import { IComp } from "./IComp.sol";
import { ConfidentialERC20 } from "../token/ERC20/ConfidentialERC20.sol";
import { IConfidentialERC20Votes } from "./IConfidentialERC20Votes.sol";

/**
* @title Comp
* @notice This contract inherits EncryptedERC20, EIP712, and Ownable2Step.
* @title ConfidentialERC20Votes
* @notice This contract inherits ConfidentialERC20, EIP712, and Ownable2Step.
* This is based on the Comp.sol contract written by Compound Labs.
* see: compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol
* It is a governance token used to delegate votes, which can be used by contracts such as
* GovernorAlphaZama.sol.
* ConfidentialGovernorAlpha.sol.
* It uses encrypted votes to delegate the voting power associated
* with an account's balance.
* @dev The delegation of votes leaks information about the account's encrypted balance to the `delegatee`.
*/
abstract contract Comp is IComp, EncryptedERC20, EIP712, Ownable2Step {
abstract contract ConfidentialERC20Votes is IConfidentialERC20Votes, ConfidentialERC20, EIP712, Ownable2Step {
/// @notice Returned if the `blockNumber` is higher or equal to the (current) `block.number`.
/// @dev It is returned in requests to access votes.
error BlockNumberEqualOrHigherThanCurrentBlock();
Expand Down Expand Up @@ -97,7 +97,7 @@ abstract contract Comp is IComp, EncryptedERC20, EIP712, Ownable2Step {
string memory symbol_,
string memory version_,
uint64 totalSupply_
) EncryptedERC20(name_, symbol_) EIP712(name_, version_) Ownable(owner_) {
) ConfidentialERC20(name_, symbol_) EIP712(name_, version_) Ownable(owner_) {
_unsafeMint(owner_, totalSupply_);
_totalSupply = totalSupply_;

Expand Down Expand Up @@ -161,7 +161,7 @@ abstract contract Comp is IComp, EncryptedERC20, EIP712, Ownable2Step {
}

/**
* @notice See {IComp-getPriorVotesForGovernor}.
* @notice See {IConfidentialERC20Votes-getPriorVotesForGovernor}.
*/
function getPriorVotesForGovernor(address account, uint256 blockNumber) public virtual returns (euint64 votes) {
if (msg.sender != governor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import "fhevm/lib/TFHE.sol";
import "fhevm/gateway/GatewayCaller.sol";

import { Ownable2Step, Ownable } from "@openzeppelin/contracts/access/Ownable2Step.sol";
import { IComp } from "./IComp.sol";
import { IConfidentialERC20Votes } from "./IConfidentialERC20Votes.sol";
import { ICompoundTimelock } from "./ICompoundTimelock.sol";

/**
* @title GovernorAlphaZama
* @title ConfidentialGovernorAlpha
* @notice This is based on the GovernorAlpha.sol contract written by Compound Labs.
* see: compound-finance/compound-protocol/blob/master/contracts/Governance/GovernorAlpha.sol
* This decentralized governance system allows users to propose and vote on changes to the protocol.
Expand All @@ -19,7 +19,7 @@ import { ICompoundTimelock } from "./ICompoundTimelock.sol";
* - Quorum: A minimum number of votes (quorum) must be reached for the proposal to pass.
* - Execution: Once a proposal passes, it is executed and takes effect on the protocol.
*/
abstract contract GovernorAlphaZama is Ownable2Step, GatewayCaller {
abstract contract ConfidentialGovernorAlpha is Ownable2Step, GatewayCaller {
/// @notice Returned if proposal contains too many changes.
error LengthAboveMaxOperations();

Expand Down Expand Up @@ -197,12 +197,12 @@ abstract contract GovernorAlphaZama is Ownable2Step, GatewayCaller {
uint256 public constant PROPOSAL_MAX_OPERATIONS = 10;

/// @notice The number of votes required for a voter to become a proposer.
/// @dev It is set at 100,000, which is 1% of the total supply of the Comp token.
/// @dev It is set at 100,000, which is 1% of the total supply of the ConfidentialERC20Votes token.
uint256 public constant PROPOSAL_THRESHOLD = 100000e6;

/// @notice The number of votes in support of a proposal required in order for a quorum to be reached
/// and for a vote to succeed.
/// @dev It is set at 400,000, which is 4% of the total supply of the Comp token.
/// @dev It is set at 400,000, which is 4% of the total supply of the ConfidentialERC20Votes token.
uint64 public constant QUORUM_VOTES = 400000e6;

/// @notice The delay before voting on a proposal may take place once proposed.
Expand All @@ -214,8 +214,8 @@ abstract contract GovernorAlphaZama is Ownable2Step, GatewayCaller {
/// (i.e 21,600 for 12-second blocks).
uint256 public immutable VOTING_PERIOD;

/// @notice Comp governance token.
IComp public immutable COMP;
/// @notice ConfidentialERC20Votes governance token.
IConfidentialERC20Votes public immutable CONFIDENTIAL_ERC20_VOTES;

/// @notice Compound Timelock.
ICompoundTimelock public immutable TIMELOCK;
Expand Down Expand Up @@ -253,15 +253,15 @@ abstract contract GovernorAlphaZama is Ownable2Step, GatewayCaller {
/**
* @param owner_ Owner address.
* @param timelock_ Timelock contract.
* @param comp_ Comp token.
* @param comp_ ConfidentialERC20Votes token.
* @param votingPeriod_ Voting period.
* @dev Do not use a small value in production such as 5 or 20 to avoid security issues
* unless for testing purpose. It should by at least a few days,.
* For instance, 3 days would have a votingPeriod = 21,600 blocks if 12s per block.
*/
constructor(address owner_, address timelock_, address comp_, uint256 votingPeriod_) Ownable(owner_) {
TIMELOCK = ICompoundTimelock(timelock_);
COMP = IComp(comp_);
CONFIDENTIAL_ERC20_VOTES = IConfidentialERC20Votes(comp_);
VOTING_PERIOD = votingPeriod_;

/// @dev Store these constant-like variables in the storage.
Expand Down Expand Up @@ -443,7 +443,7 @@ abstract contract GovernorAlphaZama is Ownable2Step, GatewayCaller {

ebool canPropose = TFHE.lt(
_EUINT64_PROPOSAL_THRESHOLD,
COMP.getPriorVotesForGovernor(msg.sender, block.number - 1)
CONFIDENTIAL_ERC20_VOTES.getPriorVotesForGovernor(msg.sender, block.number - 1)
);

uint256[] memory cts = new uint256[](1);
Expand Down Expand Up @@ -645,7 +645,7 @@ abstract contract GovernorAlphaZama is Ownable2Step, GatewayCaller {
revert VoterHasAlreadyVoted();
}

euint64 votes = COMP.getPriorVotesForGovernor(voter, proposal.startBlock);
euint64 votes = CONFIDENTIAL_ERC20_VOTES.getPriorVotesForGovernor(voter, proposal.startBlock);
proposal.forVotes = TFHE.select(support, TFHE.add(proposal.forVotes, votes), proposal.forVotes);
proposal.againstVotes = TFHE.select(support, proposal.againstVotes, TFHE.add(proposal.againstVotes, votes));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ pragma solidity ^0.8.24;
import "fhevm/lib/TFHE.sol";

/**
* @title IComp
* @dev The GovernorAlphaZama relies on this interface.
* @title IConfidentialERC20Votes
* @dev The ConfidentialGovernorAlpha relies on this interface.
*/
interface IComp {
interface IConfidentialERC20Votes {
/**
* @notice Determine the prior number of votes for an account as of a block number.
* @dev Block number must be a finalized block or else this function will revert.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import { Comp } from "../../governance/Comp.sol";
import { ConfidentialERC20Votes } from "../../governance/ConfidentialERC20Votes.sol";
import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";

contract TestComp is MockZamaFHEVMConfig, Comp {
contract TestConfidentialERC20Votes is MockZamaFHEVMConfig, ConfidentialERC20Votes {
constructor(
address owner_,
string memory name_,
string memory symbol_,
string memory version_,
uint64 totalSupply_
) Comp(owner_, name_, symbol_, version_, totalSupply_) {
) ConfidentialERC20Votes(owner_, name_, symbol_, version_, totalSupply_) {
//
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import { GovernorAlphaZama } from "../../governance/GovernorAlphaZama.sol";
import { ConfidentialGovernorAlpha } from "../../governance/ConfidentialGovernorAlpha.sol";
import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { MockZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol";

contract TestGovernorAlphaZama is MockZamaFHEVMConfig, MockZamaGatewayConfig, GovernorAlphaZama {
contract TestConfidentialGovernorAlpha is MockZamaFHEVMConfig, MockZamaGatewayConfig, ConfidentialGovernorAlpha {
constructor(
address owner_,
address timelock_,
address comp_,
uint256 votingPeriod_
) GovernorAlphaZama(owner_, timelock_, comp_, votingPeriod_) {
) ConfidentialGovernorAlpha(owner_, timelock_, comp_, votingPeriod_) {
//
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import { EncryptedERC20Mintable } from "../../../token/ERC20/extensions/EncryptedERC20Mintable.sol";
import { ConfidentialERC20Mintable } from "../../../token/ERC20/extensions/ConfidentialERC20Mintable.sol";
import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";

contract TestEncryptedERC20Mintable is MockZamaFHEVMConfig, EncryptedERC20Mintable {
contract TestConfidentialERC20Mintable is MockZamaFHEVMConfig, ConfidentialERC20Mintable {
constructor(
string memory name_,
string memory symbol_,
address owner_
) EncryptedERC20Mintable(name_, symbol_, owner_) {
) ConfidentialERC20Mintable(name_, symbol_, owner_) {
//
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;

import {
ConfidentialERC20WithErrorsMintable
} from "../../../token/ERC20/extensions/ConfidentialERC20WithErrorsMintable.sol";
import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";

contract TestConfidentialERC20WithErrorsMintable is MockZamaFHEVMConfig, ConfidentialERC20WithErrorsMintable {
constructor(
string memory name_,
string memory symbol_,
address owner_
) ConfidentialERC20WithErrorsMintable(name_, symbol_, owner_) {
//
}
}

This file was deleted.

Loading