diff --git a/README.md b/README.md index e8615e6..7f7c87d 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,9 @@ # fhEVM Contracts -<p align="center"> - <a href="./fhevm-whitepaper.pdf"> π Read white paper</a> |<a href="https://docs.zama.ai/fhevm"> π Documentation</a> | <a href="https://zama.ai/community"> π Community support</a> | <a href="https://github.com/zama-ai/awesome-zama"> π FHE resources by Zama</a> -</p> +## Description -<p align="center"> - <a href="https://github.com/zama-ai/fhevm/releases"><img src="https://img.shields.io/github/v/release/zama-ai/fhevm?style=flat-square"></a> - <a href="license"><img src="https://img.shields.io/badge/License-BSD--3--Clause--Clear-%23ffb243?style=flat-square"></a> - <a href="https://github.com/zama-ai/bounty-program"><img src="https://img.shields.io/badge/Contribute-Zama%20Bounty%20Program-%23ffd208?style=flat-square"></a> -</p> - -fhEVM contracts is a library for encrypted smart contract development on fhEVM. +fhEVM contracts is a Solidity library for secure smart-contract development using +[fhEVM](https://github.com/zama-ai/fhevm) and TFHE. ## Getting Started @@ -39,7 +32,8 @@ import "fhevm-contracts/contracts/token/ERC20/EncryptedERC20.sol"; contract MyERC20 is EncryptedERC20 { constructor() EncryptedERC20("MyToken", "MYTOKEN") { - _mint(1000000, msg.sender); + TFHE.setFHEVM(FHEVMConfig.defaultConfig()); + _unsafeMint(1000000, msg.sender); } } ``` @@ -48,61 +42,20 @@ contract MyERC20 is EncryptedERC20 { ### Documentation -Full, comprehensive documentation is available here: [https://docs.zama.ai/fhevm](https://docs.zama.ai/fhevm). - -### Citations - -To cite fhEVM or the whitepaper in academic papers, please use the following entries: - -```text -@Misc{fhEVM, -title={{Private smart contracts on the EVM using homomorphic encryption}}, -author={Zama}, -year={2023}, -note={\url{https://github.com/zama-ai/fhevm}}, -} -``` - -```text -@techreport{fhEVM, -author = "Morten Dahl, ClΓ©ment Danjou, Daniel Demmler, Tore Frederiksen, Petar Ivanov, -Marc Joye, Dragos Rotaru, Nigel Smart, Louis Tremblay Thibault -", -title = "Confidential EVM Smart Contracts using Fully Homomorphic Encryption", -institution = "Zama", -year = "2023" -} -``` +The full documentation is available [here](https://docs.zama.ai/fhevm). ### Contributing There are two ways to contribute to the Zama fhEVM contracts: - [Open issues](https://github.com/zama-ai/fhevm-contracts/issues/new/choose) to report bugs and typos, or to suggest - new ideas + new ideas. - Request to become an official contributor by emailing hello@zama.ai. -Becoming an approved contributor involves signing our Contributor License Agreement (CLA)). Only approved contributors -can send pull requests, so please make sure to get in touch before you do! <br></br> +Becoming an approved contributor involves signing our Contributor License Agreement (CLA). Only approved contributors +can send pull requests, so please make sure to get in touch before you do. ### License -This software is distributed under the **BSD-3-Clause-Clear** license. If you have any questions, please contact us at -hello@zama.ai. - -<p align="right"> - <a href="#table-of-contents" > β Back to top </a> -</p> - -## Support - -<a target="_blank" href="https://community.zama.ai"> - <img src="https://github.com/zama-ai/fhevm/assets/157474013/4e75e34e-df3f-4e9e-8a22-12b1d4013578"> -</a> - -π If you find this project helpful or interesting, please consider giving it a star on GitHub! Your support helps to -grow the community and motivates further development. - -<p align="right"> - <a href="#about" > β Back to top </a> -</p> +This software is distributed under the **BSD-3-Clause-Clear** license. If you have any question about the license, +please contact us at hello@zama.ai. diff --git a/contracts/governance/GovernorAlphaZama.sol b/contracts/governance/GovernorAlphaZama.sol index 74ec0e5..8adc1d1 100644 --- a/contracts/governance/GovernorAlphaZama.sol +++ b/contracts/governance/GovernorAlphaZama.sol @@ -121,6 +121,7 @@ abstract contract GovernorAlphaZama is Ownable2Step, GatewayCaller { /** * @param proposer Proposal creator. + * @param state State of the proposal. * @param eta The timestamp that the proposal will be available for execution, * it is set automatically once the vote succeeds. * @param targets The ordered list of target addresses for calls to be made. diff --git a/docs/DAO/Comp.md b/docs/DAO/Comp.md deleted file mode 100644 index 42b470d..0000000 --- a/docs/DAO/Comp.md +++ /dev/null @@ -1,220 +0,0 @@ -# Solidity API - -## Comp - -### allowedContract - -```solidity -address allowedContract -``` - -allowed smart contract - -### delegates - -```solidity -mapping(address => address) delegates -``` - -A record of each accounts delegate - -### Checkpoint - -A checkpoint for marking number of votes from a given block - -```solidity -struct Checkpoint { - uint32 fromBlock; - euint64 votes; -} -``` - -### checkpoints - -```solidity -mapping(address => mapping(uint32 => struct Comp.Checkpoint)) checkpoints -``` - -A record of votes checkpoints for each account, by index - -### numCheckpoints - -```solidity -mapping(address => uint32) numCheckpoints -``` - -The number of checkpoints for each account - -### DOMAIN_TYPEHASH - -```solidity -bytes32 DOMAIN_TYPEHASH -``` - -The EIP-712 typehash for the contract's domain - -### DELEGATION_TYPEHASH - -```solidity -bytes32 DELEGATION_TYPEHASH -``` - -The EIP-712 typehash for the delegation struct used by the contract - -### nonces - -```solidity -mapping(address => uint256) nonces -``` - -A record of states for signing / validating signatures - -### DelegateChanged - -```solidity -event DelegateChanged(address delegator, address fromDelegate, address toDelegate) -``` - -An event thats emitted when an account changes its delegate - -### DelegateVotesChanged - -```solidity -event DelegateVotesChanged(address delegate, euint64 previousBalance, euint64 newBalance) -``` - -An event thats emitted when a delegate account's vote balance changes - -### constructor - -```solidity -constructor() public -``` - -Construct a new Comp token - -### setAllowedContract - -```solidity -function setAllowedContract(address contractAddress) public -``` - -Set allowed contract that can access votes - -#### Parameters - -| Name | Type | Description | -| --------------- | ------- | -------------------------------------------------------- | -| contractAddress | address | The address of the smart contract which may access votes | - -### \_moveDelegates - -```solidity -function _moveDelegates(address srcRep, address dstRep, euint64 amount) internal -``` - -### \_writeCheckpoint - -```solidity -function _writeCheckpoint(address delegatee, uint32 nCheckpoints, euint64 oldVotes, euint64 newVotes) internal -``` - -### delegate - -```solidity -function delegate(address delegatee) public -``` - -Delegate votes from `msg.sender` to `delegatee` - -#### Parameters - -| Name | Type | Description | -| --------- | ------- | -------------------------------- | -| delegatee | address | The address to delegate votes to | - -### delegateBySig - -```solidity -function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) public -``` - -Delegates votes from signatory to `delegatee` - -#### Parameters - -| Name | Type | Description | -| --------- | ------- | -------------------------------------------------- | -| delegatee | address | The address to delegate votes to | -| nonce | uint256 | The contract state required to match the signature | -| expiry | uint256 | The time at which to expire the signature | -| v | uint8 | The recovery byte of the signature | -| r | bytes32 | Half of the ECDSA signature pair | -| s | bytes32 | Half of the ECDSA signature pair | - -### getCurrentVotes - -```solidity -function getCurrentVotes(address account) external view returns (euint64) -``` - -Gets the current votes balance for `account` - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | -------------------------------- | -| account | address | The address to get votes balance | - -#### Return Values - -| Name | Type | Description | -| ---- | ------- | ----------------------------------------- | -| [0] | euint64 | The number of current votes for `account` | - -### getPriorVotes - -```solidity -function getPriorVotes(address account, uint256 blockNumber) public view returns (euint64) -``` - -Determine the prior number of votes for an account as of a block number - -_Block number must be a finalized block or else this function will revert to prevent misinformation._ - -#### Parameters - -| Name | Type | Description | -| ----------- | ------- | ------------------------------------------- | -| account | address | The address of the account to check | -| blockNumber | uint256 | The block number to get the vote balance at | - -#### Return Values - -| Name | Type | Description | -| ---- | ------- | --------------------------------------------------------- | -| [0] | euint64 | The number of votes the account had as of the given block | - -### \_delegate - -```solidity -function _delegate(address delegator, address delegatee) internal -``` - -### safe32 - -```solidity -function safe32(uint256 n, string errorMessage) internal pure returns (uint32) -``` - -### getChainId - -```solidity -function getChainId() internal view returns (uint256) -``` - -### onlyAllowedContract - -```solidity -modifier onlyAllowedContract() -``` diff --git a/docs/DAO/GovernorZama.md b/docs/DAO/GovernorZama.md deleted file mode 100644 index 8b3565b..0000000 --- a/docs/DAO/GovernorZama.md +++ /dev/null @@ -1,383 +0,0 @@ -# Solidity API - -## GovernorZama - -### name - -```solidity -string name -``` - -The name of this contract - -### quorumVotes - -```solidity -function quorumVotes() public pure returns (uint256) -``` - -The number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed - -### proposalThreshold - -```solidity -function proposalThreshold() public pure returns (uint32) -``` - -The number of votes required in order for a voter to become a proposer - -### proposalMaxOperations - -```solidity -function proposalMaxOperations() public pure returns (uint32) -``` - -The maximum number of actions that can be included in a proposal - -### votingDelay - -```solidity -function votingDelay() public pure returns (uint32) -``` - -The delay before voting on a proposal may take place, once proposed - -### votingPeriod - -```solidity -function votingPeriod() public pure virtual returns (uint32) -``` - -The duration of voting on a proposal, in blocks - -### timelock - -```solidity -contract TimelockInterface timelock -``` - -The address of the Compound Protocol Timelock - -### comp - -```solidity -contract CompInterface comp -``` - -The address of the Compound governance token - -### guardian - -```solidity -address guardian -``` - -The address of the Governor Guardian - -### proposalCount - -```solidity -uint256 proposalCount -``` - -The total number of proposals - -### Proposal - -```solidity -struct Proposal { - uint256 id; - address proposer; - uint256 eta; - address[] targets; - uint256[] values; - string[] signatures; - bytes[] calldatas; - uint256 startBlock; - uint256 endBlock; - euint64 forVotes; - euint64 againstVotes; - bool canceled; - bool executed; - mapping(address => struct GovernorZama.Receipt) receipts; -} -``` - -### Receipt - -Ballot receipt record for a voter - -```solidity -struct Receipt { - bool hasVoted; - bool support; - euint64 votes; -} -``` - -### ProposalState - -Possible states that a proposal may be in - -```solidity -enum ProposalState { - Pending, - Active, - Canceled, - Defeated, - Succeeded, - Queued, - Expired, - Executed -} -``` - -### proposals - -```solidity -mapping(uint256 => struct GovernorZama.Proposal) proposals -``` - -The official record of all proposals ever proposed - -### latestProposalIds - -```solidity -mapping(address => uint256) latestProposalIds -``` - -The latest proposal for each proposer - -### DOMAIN_TYPEHASH - -```solidity -bytes32 DOMAIN_TYPEHASH -``` - -The EIP-712 typehash for the contract's domain - -### BALLOT_TYPEHASH - -```solidity -bytes32 BALLOT_TYPEHASH -``` - -The EIP-712 typehash for the ballot struct used by the contract - -### ProposalCreated - -```solidity -event ProposalCreated(uint256 id, address proposer, address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, uint256 startBlock, uint256 endBlock, string description) -``` - -An event emitted when a new proposal is created - -### VoteCast - -```solidity -event VoteCast(address voter, uint256 proposalId) -``` - -An event emitted when a vote has been cast on a proposal - -### ProposalCanceled - -```solidity -event ProposalCanceled(uint256 id) -``` - -An event emitted when a proposal has been canceled - -### ProposalQueued - -```solidity -event ProposalQueued(uint256 id, uint256 eta) -``` - -An event emitted when a proposal has been queued in the Timelock - -### ProposalExecuted - -```solidity -event ProposalExecuted(uint256 id) -``` - -An event emitted when a proposal has been executed in the Timelock - -### constructor - -```solidity -constructor(address timelock_, address comp_, address guardian_) public -``` - -### propose - -```solidity -function propose(address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, uint256 customVotingPeriod, string description) public returns (uint256) -``` - -### queue - -```solidity -function queue(uint256 proposalId) public -``` - -### \_queueOrRevert - -```solidity -function _queueOrRevert(address target, uint256 value, string signature, bytes data, uint256 eta) internal -``` - -### execute - -```solidity -function execute(uint256 proposalId) public payable -``` - -### cancel - -```solidity -function cancel(uint256 proposalId) public -``` - -### getActions - -```solidity -function getActions(uint256 proposalId) public view returns (address[] targets, uint256[] values, string[] signatures, bytes[] calldatas) -``` - -### getReceipt - -```solidity -function getReceipt(uint256 proposalId, address voter) public view returns (struct GovernorZama.Receipt) -``` - -### state - -```solidity -function state(uint256 proposalId) public view returns (enum GovernorZama.ProposalState) -``` - -### castVote - -```solidity -function castVote(uint256 proposalId, bytes support) public -``` - -### castVote - -```solidity -function castVote(uint256 proposalId, ebool support) public -``` - -### castVoteBySig - -```solidity -function castVoteBySig(uint256 proposalId, bytes support, uint8 v, bytes32 r, bytes32 s) public -``` - -### castVoteBySig - -```solidity -function castVoteBySig(uint256 proposalId, ebool support, uint8 v, bytes32 r, bytes32 s) public -``` - -### \_castVote - -```solidity -function _castVote(address voter, uint256 proposalId, ebool support) internal -``` - -### \_\_acceptAdmin - -```solidity -function __acceptAdmin() public -``` - -### \_\_abdicate - -```solidity -function __abdicate() public -``` - -### \_\_queueSetTimelockPendingAdmin - -```solidity -function __queueSetTimelockPendingAdmin(address newPendingAdmin, uint256 eta) public -``` - -### \_\_executeSetTimelockPendingAdmin - -```solidity -function __executeSetTimelockPendingAdmin(address newPendingAdmin, uint256 eta) public -``` - -### add256 - -```solidity -function add256(uint256 a, uint256 b) internal pure returns (uint256) -``` - -### sub256 - -```solidity -function sub256(uint256 a, uint256 b) internal pure returns (uint256) -``` - -### getChainId - -```solidity -function getChainId() internal view returns (uint256) -``` - -## TimelockInterface - -### delay - -```solidity -function delay() external view returns (uint256) -``` - -### GRACE_PERIOD - -```solidity -function GRACE_PERIOD() external view returns (uint256) -``` - -### acceptAdmin - -```solidity -function acceptAdmin() external -``` - -### queuedTransactions - -```solidity -function queuedTransactions(bytes32 hash) external view returns (bool) -``` - -### queueTransaction - -```solidity -function queueTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) external returns (bytes32) -``` - -### cancelTransaction - -```solidity -function cancelTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) external -``` - -### executeTransaction - -```solidity -function executeTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) external payable returns (bytes) -``` - -## CompInterface - -### getPriorVotes - -```solidity -function getPriorVotes(address account, uint256 blockNumber) external view returns (euint64) -``` diff --git a/docs/DAO/Timelock.md b/docs/DAO/Timelock.md deleted file mode 100644 index fa36332..0000000 --- a/docs/DAO/Timelock.md +++ /dev/null @@ -1,135 +0,0 @@ -# Solidity API - -## Timelock - -### NewAdmin - -```solidity -event NewAdmin(address newAdmin) -``` - -### NewPendingAdmin - -```solidity -event NewPendingAdmin(address newPendingAdmin) -``` - -### NewDelay - -```solidity -event NewDelay(uint256 newDelay) -``` - -### CancelTransaction - -```solidity -event CancelTransaction(bytes32 txHash, address target, uint256 value, string signature, bytes data, uint256 eta) -``` - -### ExecuteTransaction - -```solidity -event ExecuteTransaction(bytes32 txHash, address target, uint256 value, string signature, bytes data, uint256 eta) -``` - -### QueueTransaction - -```solidity -event QueueTransaction(bytes32 txHash, address target, uint256 value, string signature, bytes data, uint256 eta) -``` - -### GRACE_PERIOD - -```solidity -uint256 GRACE_PERIOD -``` - -### MINIMUM_DELAY - -```solidity -uint256 MINIMUM_DELAY -``` - -### MAXIMUM_DELAY - -```solidity -uint256 MAXIMUM_DELAY -``` - -### admin - -```solidity -address admin -``` - -### pendingAdmin - -```solidity -address pendingAdmin -``` - -### delay - -```solidity -uint256 delay -``` - -### queuedTransactions - -```solidity -mapping(bytes32 => bool) queuedTransactions -``` - -### constructor - -```solidity -constructor(address admin_, uint256 delay_) public -``` - -### receive - -```solidity -receive() external payable -``` - -### setDelay - -```solidity -function setDelay(uint256 delay_) public -``` - -### acceptAdmin - -```solidity -function acceptAdmin() public -``` - -### setPendingAdmin - -```solidity -function setPendingAdmin(address pendingAdmin_) public -``` - -### queueTransaction - -```solidity -function queueTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) public returns (bytes32) -``` - -### cancelTransaction - -```solidity -function cancelTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) public -``` - -### executeTransaction - -```solidity -function executeTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) public payable returns (bytes) -``` - -### getBlockTimestamp - -```solidity -function getBlockTimestamp() internal view returns (uint256) -``` diff --git a/docs/EncryptedERC20.md b/docs/EncryptedERC20.md deleted file mode 100644 index 477087a..0000000 --- a/docs/EncryptedERC20.md +++ /dev/null @@ -1,190 +0,0 @@ -# Solidity API - -## EncryptedERC20 - -### ErrorCodes - -```solidity -enum ErrorCodes { - NO_ERROR, - UNSUFFICIENT_BALANCE, - UNSUFFICIENT_APPROVAL -} -``` - -### AllowedErrorReencryption - -```solidity -struct AllowedErrorReencryption { - address spender; - euint8 errorCode; -} -``` - -### Transfer - -```solidity -event Transfer(uint256 transferId, address from, address to) -``` - -### Approval - -```solidity -event Approval(address owner, address spender) -``` - -### Mint - -```solidity -event Mint(address to, uint64 amount) -``` - -### \_totalSupply - -```solidity -uint64 _totalSupply -``` - -### decimals - -```solidity -uint8 decimals -``` - -### allowedErrorReencryptions - -```solidity -mapping(uint256 => struct EncryptedERC20.AllowedErrorReencryption) allowedErrorReencryptions -``` - -### balances - -```solidity -mapping(address => euint64) balances -``` - -### allowances - -```solidity -mapping(address => mapping(address => euint64)) allowances -``` - -### constructor - -```solidity -constructor(string name_, string symbol_) public -``` - -### name - -```solidity -function name() public view virtual returns (string) -``` - -### symbol - -```solidity -function symbol() public view virtual returns (string) -``` - -### totalSupply - -```solidity -function totalSupply() public view virtual returns (uint64) -``` - -### mint - -```solidity -function mint(uint64 mintedAmount) public virtual -``` - -### \_mint - -```solidity -function _mint(uint64 amount) internal virtual -``` - -### transfer - -```solidity -function transfer(address to, bytes encryptedAmount) public virtual returns (bool) -``` - -### transfer - -```solidity -function transfer(address to, euint64 amount) public virtual returns (bool) -``` - -### balanceOf - -```solidity -function balanceOf(address wallet, bytes32 publicKey, bytes signature) public view virtual returns (bytes) -``` - -### balanceOfMe - -```solidity -function balanceOfMe() public view virtual returns (euint64) -``` - -### approve - -```solidity -function approve(address spender, bytes encryptedAmount) public virtual returns (bool) -``` - -### approve - -```solidity -function approve(address spender, euint64 amount) public virtual returns (bool) -``` - -### allowance - -```solidity -function allowance(address owner, address spender, bytes32 publicKey, bytes signature) public view virtual returns (bytes) -``` - -### transferFrom - -```solidity -function transferFrom(address from, address to, bytes encryptedAmount) public virtual returns (bool) -``` - -### transferFrom - -```solidity -function transferFrom(address from, address to, euint64 amount) public virtual returns (bool) -``` - -### \_approve - -```solidity -function _approve(address owner, address spender, euint64 amount) internal virtual -``` - -### \_allowance - -```solidity -function _allowance(address owner, address spender) internal view virtual returns (euint64) -``` - -### \_updateAllowance - -```solidity -function _updateAllowance(address owner, address spender, euint64 amount) internal virtual returns (ebool, euint8) -``` - -### \_transfer - -```solidity -function _transfer(address from, address to, euint64 amount, ebool isTransferable, euint8 errorCode) internal virtual -``` - -### reencryptError - -```solidity -function reencryptError(uint256 transferId, bytes32 publicKey, bytes signature) external view virtual returns (bytes) -``` diff --git a/docs/governance/Comp.md b/docs/governance/Comp.md new file mode 100644 index 0000000..565de5f --- /dev/null +++ b/docs/governance/Comp.md @@ -0,0 +1,315 @@ +# Comp + +This contract inherits EncryptedERC20, 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. It uses encrypted votes to +delegate the voting power associated with an account's balance. + +_The delegation of votes leaks information about the account's encrypted balance to the `delegatee`._ + +## BlockNumberEqualOrHigherThanCurrentBlock + +```solidity +error BlockNumberEqualOrHigherThanCurrentBlock() +``` + +Returned if the `blockNumber` is higher or equal to the (current) `block.number`. + +_It is returned in requests to access votes._ + +## GovernorInvalid + +```solidity +error GovernorInvalid() +``` + +Returned if the `msg.sender` is not the `governor` contract. + +## SignatureExpired + +```solidity +error SignatureExpired() +``` + +Returned if the signature has expired. + +## SignatureNonceInvalid + +```solidity +error SignatureNonceInvalid() +``` + +Returned if the signature's nonce is invalid. + +## SignatureVerificationFail + +```solidity +error SignatureVerificationFail() +``` + +Returned if the signature's verification has failed. + +_See {SignatureChecker} for potential reasons._ + +## DelegateChanged + +```solidity +event DelegateChanged(address delegator, address fromDelegate, address toDelegate) +``` + +Emitted when an `account` (i.e. `delegator`) changes its delegate. + +## DelegateVotesChanged + +```solidity +event DelegateVotesChanged(address delegate) +``` + +Emitted when a `delegate` account's vote balance changes. + +## NewGovernor + +```solidity +event NewGovernor(address governor) +``` + +Emitted when the governor contract that can reencrypt votes changes. + +_WARNING: it can be set to a malicious contract, which could reencrypt all user votes._ + +## NonceIncremented + +```solidity +event NonceIncremented(address account, uint256 newNonce) +``` + +Emitted when the account cancels a signature. + +## Checkpoint + +A checkpoint for marking number of votes from a given block. + +_In Compound's implementation, `fromBlock` is defined as uint32 to allow tight-packing. However, in this implementations +`votes` is uint256-based. `fromBlock`'s type is set to uint256, which simplifies the codebase._ + +### Parameters + +| Name | Type | Description | +| --------- | ------- | -------------------------------------------- | +| fromBlock | uint256 | Block from where the checkpoint applies. | +| votes | euint64 | Total number of votes for the account power. | + +```solidity +struct Checkpoint { + uint256 fromBlock; + euint64 votes; +} +``` + +## DELEGATION_TYPEHASH + +```solidity +bytes32 DELEGATION_TYPEHASH +``` + +The EIP-712 typehash for the `Delegation` struct. + +## governor + +```solidity +address governor +``` + +The smart contract that can access encrypted votes. + +_The contract is expected to be a governor contract._ + +## delegates + +```solidity +mapping(address => address) delegates +``` + +A record of each account's `delegate`. + +## nonces + +```solidity +mapping(address => uint256) nonces +``` + +A record of states for signing/validating signatures. + +## numCheckpoints + +```solidity +mapping(address => uint32) numCheckpoints +``` + +The number of checkpoints for an `account`. + +## \_checkpoints + +```solidity +mapping(address => mapping(uint32 => struct Comp.Checkpoint)) _checkpoints +``` + +A record of votes \_checkpoints for an `account` using incremental indices. + +## constructor + +```solidity +constructor(address owner_, string name_, string symbol_, string version_, uint64 totalSupply_) internal +``` + +### Parameters + +| Name | Type | Description | +| ------------- | ------- | ---------------------------- | +| owner\_ | address | Owner address. | +| name\_ | string | Token name. | +| symbol\_ | string | Token symbol. | +| version\_ | string | Version (e.g. "0.1", "1.0"). | +| totalSupply\_ | uint64 | Total supply to mint. | + +## delegate + +```solidity +function delegate(address delegatee) public virtual +``` + +Delegate votes from `msg.sender` to `delegatee`. + +### Parameters + +| Name | Type | Description | +| --------- | ------- | --------------------------------- | +| delegatee | address | The address to delegate votes to. | + +## delegateBySig + +```solidity +function delegateBySig(address delegator, address delegatee, uint256 nonce, uint256 expiry, bytes signature) public virtual +``` + +Delegate votes from signatory to `delegatee`. + +_Signature can be either 64-byte or 65-byte long if it is from an EOA. Else, it must adhere to ERC1271. See +{https://eips.ethereum.org/EIPS/eip-1271}_ + +### Parameters + +| Name | Type | Description | +| --------- | ------- | ------------------------------------------------------------ | +| delegator | address | The account that delegates its votes. It must be the signer. | +| delegatee | address | The address to delegate votes to. | +| nonce | uint256 | The contract state required to match the signature. | +| expiry | uint256 | The time at which to expire the signature. | +| signature | bytes | The signature. | + +## incrementNonce + +```solidity +function incrementNonce() public virtual +``` + +Increment the nonce. + +_This function enables the sender to cancel a signature._ + +## getPriorVotesForGovernor + +```solidity +function getPriorVotesForGovernor(address account, uint256 blockNumber) public virtual returns (euint64 votes) +``` + +See {IComp-getPriorVotesForGovernor}. + +## getCurrentVotes + +```solidity +function getCurrentVotes(address account) public view virtual returns (euint64 votes) +``` + +Get current votes of account. + +### Parameters + +| Name | Type | Description | +| ------- | ------- | --------------- | +| account | address | Account address | + +### Return Values + +| Name | Type | Description | +| ----- | ------- | -------------------------- | +| votes | euint64 | Current (encrypted) votes. | + +## getPriorVotes + +```solidity +function getPriorVotes(address account, uint256 blockNumber) public view virtual returns (euint64 votes) +``` + +Get the prior number of votes for an account as of a block number. + +_Block number must be a finalized block or else this function will revert._ + +### Parameters + +| Name | Type | Description | +| ----------- | ------- | -------------------------------------------- | +| account | address | Account address. | +| blockNumber | uint256 | The block number to get the vote balance at. | + +### Return Values + +| Name | Type | Description | +| ----- | ------- | -------------------------------------------------- | +| votes | euint64 | Number of votes the account as of the given block. | + +## setGovernor + +```solidity +function setGovernor(address newGovernor) public virtual +``` + +Set a governor contract. + +### Parameters + +| Name | Type | Description | +| ----------- | ------- | ------------------------------------------------------ | +| newGovernor | address | New governor contract that can reencrypt/access votes. | + +## \_delegate + +```solidity +function _delegate(address delegator, address delegatee) internal virtual +``` + +## \_getPriorVote + +```solidity +function _getPriorVote(address account, uint256 blockNumber) internal view returns (euint64 votes) +``` + +## \_moveDelegates + +```solidity +function _moveDelegates(address srcRep, address dstRep, euint64 amount) internal virtual +``` + +## \_transfer + +```solidity +function _transfer(address from, address to, euint64 amount, ebool isTransferable) internal virtual +``` + +_Original restrictions to transfer from/to address(0) are removed since they are inherited._ + +## \_writeCheckpoint + +```solidity +function _writeCheckpoint(address delegatee, uint32 nCheckpoints, euint64 newVotes) internal virtual +``` diff --git a/docs/governance/CompoundTimelock.md b/docs/governance/CompoundTimelock.md new file mode 100644 index 0000000..78e1d3c --- /dev/null +++ b/docs/governance/CompoundTimelock.md @@ -0,0 +1,147 @@ +# CompoundTimelock + +This contract allows the admin to set a delay period before executing transactions. Transactions must be queued before +execution. No transaction can be executed during this period, which offers time to verify the validity of pending +transactions. It also has a grace period to allow for transactions not to be executed after a specific period following +the queuing. + +## GRACE_PERIOD + +```solidity +uint256 GRACE_PERIOD +``` + +See {ICompoundTimelock-GRACE_PERIOD}. + +## MINIMUM_DELAY + +```solidity +uint256 MINIMUM_DELAY +``` + +Minimum delay that can be set in the `setDelay` function. + +## MAXIMUM_DELAY + +```solidity +uint256 MAXIMUM_DELAY +``` + +Maximum delay that can be set in the `setDelay` function. + +## admin + +```solidity +address admin +``` + +Admin address. + +## pendingAdmin + +```solidity +address pendingAdmin +``` + +Pending admin address. + +_The transer of the admin is a two-step process._ + +## delay + +```solidity +uint256 delay +``` + +See {ICompoundTimelock-delay}. + +## queuedTransactions + +```solidity +mapping(bytes32 => bool) queuedTransactions +``` + +Return whether the transaction is queued based on its hash. + +## constructor + +```solidity +constructor(address admin_, uint256 delay_) public +``` + +### Parameters + +| Name | Type | Description | +| ------- | ------- | --------------------- | +| admin\_ | address | Admin address. | +| delay\_ | uint256 | Delay (in timestamp). | + +## receive + +```solidity +receive() external payable +``` + +## setDelay + +```solidity +function setDelay(uint256 delay_) public +``` + +Set the delay. + +_This transaction must be queued._ + +### Parameters + +| Name | Type | Description | +| ------- | ------- | --------------------- | +| delay\_ | uint256 | Delay (in timestamp). | + +## acceptAdmin + +```solidity +function acceptAdmin() public +``` + +See {ICompoundTimelock-acceptAdmin}. + +## setPendingAdmin + +```solidity +function setPendingAdmin(address pendingAdmin_) public +``` + +Set the pending admin. + +_This transaction must be queued._ + +### Parameters + +| Name | Type | Description | +| -------------- | ------- | ---------------------- | +| pendingAdmin\_ | address | Pending admin address. | + +## queueTransaction + +```solidity +function queueTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) public returns (bytes32) +``` + +See {ICompoundTimelock-queueTransaction}. + +## cancelTransaction + +```solidity +function cancelTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) public +``` + +See {ICompoundTimelock-cancelTransaction}. + +## executeTransaction + +```solidity +function executeTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) public payable returns (bytes) +``` + +See {ICompoundTimelock-executeTransaction}. diff --git a/docs/governance/GovernorAlphaZama.md b/docs/governance/GovernorAlphaZama.md new file mode 100644 index 0000000..3a1fc59 --- /dev/null +++ b/docs/governance/GovernorAlphaZama.md @@ -0,0 +1,648 @@ +# GovernorAlphaZama + +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. The contract is responsible for: + +- Proposal: A new proposal is made to introduce a change. +- Voting: Users can vote on the proposal, either in favor or against it. +- 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. + +## LengthAboveMaxOperations + +```solidity +error LengthAboveMaxOperations() +``` + +Returned if proposal contains too many changes. + +## LengthIsNull + +```solidity +error LengthIsNull() +``` + +Returned if the array length is equal to 0. + +## LengthsDoNotMatch + +```solidity +error LengthsDoNotMatch() +``` + +Returned if array lengths are not equal. + +## ProposalActionsAlreadyQueued + +```solidity +error ProposalActionsAlreadyQueued() +``` + +Returned if proposal's actions have already been queued. + +## ProposalStateInvalid + +```solidity +error ProposalStateInvalid() +``` + +Returned if the proposal state is invalid for this operation. + +_It is returned for any proposal state not matching the expected state to conduct the operation._ + +## ProposalStateNotActive + +```solidity +error ProposalStateNotActive() +``` + +Returned if the proposal's state is active but `block.number` > `endBlock`. + +## ProposalStateStillActive + +```solidity +error ProposalStateStillActive() +``` + +Returned if the proposal state is still active. + +## ProposerHasAnotherProposal + +```solidity +error ProposerHasAnotherProposal() +``` + +Returned if the proposer has another proposal in progress. + +## VoterHasAlreadyVoted + +```solidity +error VoterHasAlreadyVoted() +``` + +Returned if the voter has already cast a vote for this proposal. + +## ProposalActive + +```solidity +event ProposalActive(uint256 id) +``` + +Emitted when a proposal is now active. + +## ProposalCanceled + +```solidity +event ProposalCanceled(uint256 id) +``` + +Emitted when a proposal has been canceled. + +## ProposalCreated + +```solidity +event ProposalCreated(uint256 id, address proposer, address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, uint256 startBlock, uint256 endBlock, string description) +``` + +Emitted when a new proposal is created. + +## ProposalDefeated + +```solidity +event ProposalDefeated(uint256 id) +``` + +Emitted when a proposal is defeated either by lack of votes or by more votes against. + +## ProposalExecuted + +```solidity +event ProposalExecuted(uint256 id) +``` + +Emitted when a proposal has been executed in the Timelock. + +## ProposalQueued + +```solidity +event ProposalQueued(uint256 id, uint256 eta) +``` + +Emitted when a proposal has been queued in the Timelock. + +## ProposalRejected + +```solidity +event ProposalRejected(uint256 id) +``` + +Emitted when a proposal has been rejected since the number of votes is lower than the required threshold. + +## ProposalSucceeded + +```solidity +event ProposalSucceeded(uint256 id) +``` + +Emitted when a proposal has been rejected since the number of votes is lower than the required threshold. + +## VoteCast + +```solidity +event VoteCast(address voter, uint256 proposalId) +``` + +Emitted when a vote has been cast on a proposal. + +## ProposalState + +Possible states that a proposal may be in. + +### Parameters + +| Name | Description | +| ---------------------------- | ------------------------------------------------------------------------------------------- | +| Pending | Proposal does not exist. | +| PendingThresholdVerification | Proposal is created but token threshold verification is pending. | +| Rejected | Proposal was rejected as the proposer did not meet the token threshold. | +| Active | Proposal is active and voters can cast their votes. | +| PendingResults | Proposal is not active and the result decryption is in progress. | +| Canceled | Proposal has been canceled by the proposer or by this contract's owner. | +| Defeated | Proposal has been defeated (either not reaching the quorum or `againstVotes` > `forVotes`). | +| Succeeded | Proposal has succeeded (`forVotes` > `againstVotes`). | +| Queued | Proposal has been queued in the `Timelock`. | +| Expired | Proposal has expired (@dev This state exists only in read-only functions). | +| Executed | Proposal has been executed in the `Timelock`. | + +```solidity +enum ProposalState { + Pending, + PendingThresholdVerification, + Rejected, + Active, + PendingResults, + Canceled, + Defeated, + Succeeded, + Queued, + Expired, + Executed +} +``` + +## Proposal + +### Parameters + +| Name | Type | Description | +| --------------------- | ------------------------------- | ---------------------------------------------------------------------------------------------------------------- | +| proposer | address | Proposal creator. | +| state | GovernorAlphaZama.ProposalState | State of the proposal. | +| eta | uint256 | The timestamp that the proposal will be available for execution, it is set automatically once the vote succeeds. | +| targets | address[] | The ordered list of target addresses for calls to be made. | +| values | uint256[] | The ordered list of values (i.e. `msg.value`) to be passed to the calls to be made. | +| signatures | string[] | The ordered list of function signatures to be called. | +| calldatas | calldatas | The ordered list of calldata to be passed to each call. | +| startBlock | startBlock | The block at which voting begins: holders must delegate their votes prior to this block. | +| endBlock | endBlock | The block at which voting ends: votes must be cast prior to this block. ----------- | +| forVotes | forVotes | Current encrypted number of votes for to this proposal.----------- | +| againstVotes | againstVotes | Current encrypted number of votes in opposition to this proposal.----------- | +| forVotesDecrypted | forVotesDecrypted | For votes once decrypted by the gateway.----------- | +| againstVotesDecrypted | againstVotesDecrypted | Against votes once decrypted by the gateway.----------- | + +```solidity +struct Proposal { + address proposer; + enum GovernorAlphaZama.ProposalState state; + uint256 eta; + address[] targets; + uint256[] values; + string[] signatures; + bytes[] calldatas; + uint256 startBlock; + uint256 endBlock; + euint64 forVotes; + euint64 againstVotes; + uint64 forVotesDecrypted; + uint64 againstVotesDecrypted; +} +``` + +## ProposalInfo + +### Parameters + +| Name | Type | Description | +| ------------ | ------------------------------- | ---------------------------------------------------------------------------------------------------------------- | +| proposer | address | Proposal creator. | +| state | GovernorAlphaZama.ProposalState | State of the proposal. | +| eta | uint256 | The timestamp that the proposal will be available for execution, it is set automatically once the vote succeeds. | +| targets | address[] | The ordered list of target addresses for calls to be made. | +| values | uint256[] | The ordered list of values (i.e. `msg.value`) to be passed to the calls to be made. | +| signatures | string[] | The ordered list of function signatures to be called. | +| calldatas | calldatas | The ordered list of calldata to be passed to each call. | +| startBlock | startBlock | The block at which voting begins: holders must delegate their votes prior to this block. | +| endBlock | endBlock | The block at which voting ends: votes must be cast prior to this block. ----------- | +| forVotes | forVotesDecrypted | For votes once decrypted by the gateway.----------- | +| againstVotes | againstVotesDecrypted | Against votes once decrypted by the gateway.----------- | + +```solidity +struct ProposalInfo { + address proposer; + enum GovernorAlphaZama.ProposalState state; + uint256 eta; + address[] targets; + uint256[] values; + string[] signatures; + bytes[] calldatas; + uint256 startBlock; + uint256 endBlock; + uint64 forVotes; + uint64 againstVotes; +} +``` + +## Receipt + +Ballot receipt record for a voter. + +### Parameters + +| Name | Type | Description | +| -------- | ------- | ----------------------------------------------- | +| hasVoted | bool | Whether or not a vote has been cast. | +| support | ebool | Whether or not the voter supports the proposal. | +| support | euint64 | The number of votes cast by the voter. | + +```solidity +struct Receipt { + bool hasVoted; + ebool support; + euint64 votes; +} +``` + +## PROPOSAL_MAX_OPERATIONS + +```solidity +uint256 PROPOSAL_MAX_OPERATIONS +``` + +The maximum number of actions that can be included in a proposal. + +_It is 10 actions per proposal._ + +## PROPOSAL_THRESHOLD + +```solidity +uint256 PROPOSAL_THRESHOLD +``` + +The number of votes required for a voter to become a proposer. + +_It is set at 100,000, which is 1% of the total supply of the Comp token._ + +## QUORUM_VOTES + +```solidity +uint64 QUORUM_VOTES +``` + +The number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed. + +_It is set at 400,000, which is 4% of the total supply of the Comp token._ + +## VOTING_DELAY + +```solidity +uint256 VOTING_DELAY +``` + +The delay before voting on a proposal may take place once proposed. It is 1 block. + +## VOTING_PERIOD + +```solidity +uint256 VOTING_PERIOD +``` + +The duration of voting on a proposal, in blocks + +_It is recommended to be set at 3 days in blocks (i.e 21,600 for 12-second blocks)._ + +## COMP + +```solidity +contract IComp COMP +``` + +Comp governance token. + +## TIMELOCK + +```solidity +contract ICompoundTimelock TIMELOCK +``` + +Compound Timelock. + +## proposalCount + +```solidity +uint256 proposalCount +``` + +The total number of proposals made. It includes all proposals, including the ones that were rejected/canceled/defeated. + +## latestProposalIds + +```solidity +mapping(address => uint256) latestProposalIds +``` + +The latest proposal for each proposer. + +## \_accountReceiptForProposalId + +```solidity +mapping(uint256 => mapping(address => struct GovernorAlphaZama.Receipt)) _accountReceiptForProposalId +``` + +Ballot receipt for an account for a proposal id. + +## \_proposals + +```solidity +mapping(uint256 => struct GovernorAlphaZama.Proposal) _proposals +``` + +The official record of all proposals that have been created. + +## \_requestIdToProposalId + +```solidity +mapping(uint256 => uint256) _requestIdToProposalId +``` + +Returns the proposal id associated with the request id from the Gateway. + +_This mapping is used for decryption._ + +## constructor + +```solidity +constructor(address owner_, address timelock_, address comp_, uint256 votingPeriod_) internal +``` + +_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._ + +### Parameters + +| Name | Type | Description | +| -------------- | ------- | ------------------ | +| owner\_ | address | Owner address. | +| timelock\_ | address | Timelock contract. | +| comp\_ | address | Comp token. | +| votingPeriod\_ | uint256 | Voting period. | + +## cancel + +```solidity +function cancel(uint256 proposalId) public virtual +``` + +Cancel the proposal. + +_Only this contract's owner or the proposer can cancel. In the original GovernorAlpha, the proposer can cancel only if +her votes are still above the threshold._ + +### Parameters + +| Name | Type | Description | +| ---------- | ------- | ------------ | +| proposalId | uint256 | Proposal id. | + +## castVote + +```solidity +function castVote(uint256 proposalId, einput value, bytes inputProof) public virtual +``` + +Cast a vote. + +### Parameters + +| Name | Type | Description | +| ---------- | ------- | ---------------- | +| proposalId | uint256 | Proposal id. | +| value | einput | Encrypted value. | +| inputProof | bytes | Input proof. | + +## castVote + +```solidity +function castVote(uint256 proposalId, ebool support) public virtual +``` + +Cast a vote. + +### Parameters + +| Name | Type | Description | +| ---------- | ------- | ------------------------------------------------------- | +| proposalId | uint256 | Proposal id. | +| support | ebool | Support (true ==> `forVotes`, false ==> `againstVotes`) | + +## execute + +```solidity +function execute(uint256 proposalId) public payable virtual +``` + +Execute the proposal id. + +_Anyone can execute a proposal once it has been queued and the delay in the timelock is sufficient._ + +## propose + +```solidity +function propose(address[] targets, uint256[] values, string[] signatures, bytes[] calldatas, string description) public virtual returns (uint256 proposalId) +``` + +Start a new proposal. + +### Parameters + +| Name | Type | Description | +| ----------- | --------- | --------------------------------------- | +| targets | address[] | Target addresses. | +| values | uint256[] | Values. | +| signatures | string[] | Signatures. | +| calldatas | bytes[] | Calldatas. | +| description | string | Plain text description of the proposal. | + +### Return Values + +| Name | Type | Description | +| ---------- | ------- | ------------ | +| proposalId | uint256 | Proposal id. | + +## queue + +```solidity +function queue(uint256 proposalId) public virtual +``` + +Queue a new proposal. + +_It can be done only if the proposal has succeeded. Anyone can queue a proposal._ + +### Parameters + +| Name | Type | Description | +| ---------- | ------- | ------------ | +| proposalId | uint256 | Proposal id. | + +## requestVoteDecryption + +```solidity +function requestVoteDecryption(uint256 proposalId) public virtual +``` + +Request the vote results to be decrypted. + +_Anyone can request the decryption of the vote._ + +### Parameters + +| Name | Type | Description | +| ---------- | ------- | ------------ | +| proposalId | uint256 | Proposal id. | + +## callbackInitiateProposal + +```solidity +function callbackInitiateProposal(uint256 requestId, bool canInitiate) public virtual +``` + +_Only callable by the gateway._ + +### Parameters + +| Name | Type | Description | +| ----------- | ------- | -------------------------------------- | +| requestId | uint256 | Request id (from the Gateway) | +| canInitiate | bool | Whether the proposal can be initiated. | + +## callbackVoteDecryption + +```solidity +function callbackVoteDecryption(uint256 requestId, uint256 forVotesDecrypted, uint256 againstVotesDecrypted) public virtual +``` + +_Only callable by the gateway. If `forVotesDecrypted` == `againstVotesDecrypted`, proposal is defeated._ + +### Parameters + +| Name | Type | Description | +| --------------------- | ------- | -------------- | +| requestId | uint256 | | +| forVotesDecrypted | uint256 | For votes. | +| againstVotesDecrypted | uint256 | Against votes. | + +## acceptTimelockAdmin + +```solidity +function acceptTimelockAdmin() public virtual +``` + +_Only callable by `owner`._ + +## executeSetTimelockPendingAdmin + +```solidity +function executeSetTimelockPendingAdmin(address newPendingAdmin, uint256 eta) public virtual +``` + +_Only callable by `owner`._ + +### Parameters + +| Name | Type | Description | +| --------------- | ------- | -------------------------------------------------- | +| newPendingAdmin | address | Address of the new pending admin for the timelock. | +| eta | uint256 | Eta for executing the transaction in the timelock. | + +## queueSetTimelockPendingAdmin + +```solidity +function queueSetTimelockPendingAdmin(address newPendingAdmin, uint256 eta) public virtual +``` + +_Only callable by `owner`._ + +### Parameters + +| Name | Type | Description | +| --------------- | ------- | -------------------------------------------------- | +| newPendingAdmin | address | Address of the new pending admin for the timelock. | +| eta | uint256 | Eta for queuing the transaction in the timelock. | + +## getProposalInfo + +```solidity +function getProposalInfo(uint256 proposalId) public view virtual returns (struct GovernorAlphaZama.ProposalInfo proposalInfo) +``` + +Returns proposal information for a proposal id. + +_It returns decrypted `forVotes`/`againstVotes`. These are only available after the decryption._ + +### Parameters + +| Name | Type | Description | +| ---------- | ------- | ------------ | +| proposalId | uint256 | Proposal id. | + +### Return Values + +| Name | Type | Description | +| ------------ | ------------------------------------- | --------------------- | +| proposalInfo | struct GovernorAlphaZama.ProposalInfo | Proposal information. | + +## getReceipt + +```solidity +function getReceipt(uint256 proposalId, address account) public view virtual returns (bool, ebool, euint64) +``` + +Returns the vote receipt information for the account for a proposal id. + +### Parameters + +| Name | Type | Description | +| ---------- | ------- | ---------------- | +| proposalId | uint256 | Proposal id. | +| account | address | Account address. | + +### Return Values + +| Name | Type | Description | +| ---- | ------- | -------------------------------------------------------------------------------- | +| [0] | bool | hasVoted Whether the account has voted. | +| [1] | ebool | support The support for the account (true ==> vote for, false ==> vote against). | +| [2] | euint64 | votes The number of votes cast. | + +## \_castVote + +```solidity +function _castVote(address voter, uint256 proposalId, ebool support) internal virtual +``` + +## \_queueOrRevert + +```solidity +function _queueOrRevert(address target, uint256 value, string signature, bytes data, uint256 eta) internal virtual +``` diff --git a/docs/governance/IComp.md b/docs/governance/IComp.md new file mode 100644 index 0000000..9b17317 --- /dev/null +++ b/docs/governance/IComp.md @@ -0,0 +1,27 @@ +# IComp + +_The GovernorAlphaZama relies on this interface._ + +## getPriorVotesForGovernor + +```solidity +function getPriorVotesForGovernor(address account, uint256 blockNumber) external returns (euint64 votes) +``` + +Determine the prior number of votes for an account as of a block number. + +_Block number must be a finalized block or else this function will revert. This function can change the state since the +governor needs access in the ACL contract._ + +### Parameters + +| Name | Type | Description | +| ----------- | ------- | -------------------------------------------- | +| account | address | Account address. | +| blockNumber | uint256 | The block number to get the vote balance at. | + +### Return Values + +| Name | Type | Description | +| ----- | ------- | --------------------------------------------------------- | +| votes | euint64 | Number of votes the account as of the given block number. | diff --git a/docs/governance/ICompoundTimelock.md b/docs/governance/ICompoundTimelock.md new file mode 100644 index 0000000..8c2414a --- /dev/null +++ b/docs/governance/ICompoundTimelock.md @@ -0,0 +1,228 @@ +## ICompoundTimelock + +### DelayBelowMinimumDelay + +```solidity +error DelayBelowMinimumDelay() +``` + +Returned if the delay is below the minimum delay. + +### DelayAboveMaximumDelay + +```solidity +error DelayAboveMaximumDelay() +``` + +Returned if the delay exceeds the maximum delay. + +### ExecutionReverted + +```solidity +error ExecutionReverted() +``` + +Returned if the transaction's execution reverted. + +### SenderIsNotAdmin + +```solidity +error SenderIsNotAdmin() +``` + +Returned if the `msg.sender` is not the admin. + +### SenderIsNotTimelock + +```solidity +error SenderIsNotTimelock() +``` + +Returned if the `msg.sender` is not this contract (`CompoundTimelock`). + +### SenderIsNotPendingAdmin + +```solidity +error SenderIsNotPendingAdmin() +``` + +Returned if the `msg.sender` is not `pendingAdmin`. + +### TransactionNotQueued + +```solidity +error TransactionNotQueued() +``` + +Returned if the transaction has not been queued. + +### TransactionTooEarlyForExecution + +```solidity +error TransactionTooEarlyForExecution() +``` + +Returned if the transaction has not surpassed the time lock. + +### TransactionTooEarlyForQueuing + +```solidity +error TransactionTooEarlyForQueuing() +``` + +Returned if the estimated execution block does not satisfay the delay. + +### TransactionTooLateForExecution + +```solidity +error TransactionTooLateForExecution() +``` + +Returned if the transaction is stale (too late for execution). + +### NewAdmin + +```solidity +event NewAdmin(address newAdmin) +``` + +Emitted when there is a change of admin. + +### NewPendingAdmin + +```solidity +event NewPendingAdmin(address newPendingAdmin) +``` + +Emtited when there is a change of pending admin. + +### NewDelay + +```solidity +event NewDelay(uint256 newDelay) +``` + +Emitted when there is a new delay set. + +### CancelTransaction + +```solidity +event CancelTransaction(bytes32 txHash, address target, uint256 value, string signature, bytes data, uint256 eta) +``` + +Emitted when the queued transaction is canceled. + +### ExecuteTransaction + +```solidity +event ExecuteTransaction(bytes32 txHash, address target, uint256 value, string signature, bytes data, uint256 eta) +``` + +Emitted when the queued transaction is executed. + +### QueueTransaction + +```solidity +event QueueTransaction(bytes32 txHash, address target, uint256 value, string signature, bytes data, uint256 eta) +``` + +Emitted when a transaction is queued. + +### delay + +```solidity +function delay() external view returns (uint256) +``` + +Returns the delay (in timestamp) for a queued transaction before it can be executed. + +### GRACE_PERIOD + +```solidity +function GRACE_PERIOD() external view returns (uint256) +``` + +Returns the grace period (in timestamp). The grace period indicates how long a transaction can remain queued before it +cannot be executed again. + +### acceptAdmin + +```solidity +function acceptAdmin() external +``` + +Accept admin role. + +### queuedTransactions + +```solidity +function queuedTransactions(bytes32 hash) external view returns (bool) +``` + +Returns whether the transactions are queued. + +### queueTransaction + +```solidity +function queueTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) external returns (bytes32 hashTransaction) +``` + +Queue a transaction. + +#### Parameters + +| Name | Type | Description | +| --------- | ------- | ------------------------------------------ | +| target | address | Target address to execute the transaction. | +| value | uint256 | | +| signature | string | Function signature to execute. | +| data | bytes | The data to include in the transaction. | +| eta | uint256 | The earliest eta to queue the transaction. | + +#### Return Values + +| Name | Type | Description | +| --------------- | ------- | ----------------------- | +| hashTransaction | bytes32 | The transaction's hash. | + +### cancelTransaction + +```solidity +function cancelTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) external +``` + +Cancel a queued transaction. + +#### Parameters + +| Name | Type | Description | +| --------- | ------- | ------------------------------------------ | +| target | address | Target address to execute the transaction. | +| value | uint256 | | +| signature | string | Function signature to execute. | +| data | bytes | The data to include in the transaction. | +| eta | uint256 | The earliest eta to queue the transaction. | + +### executeTransaction + +```solidity +function executeTransaction(address target, uint256 value, string signature, bytes data, uint256 eta) external payable returns (bytes response) +``` + +Cancel a queued transaction. + +#### Parameters + +| Name | Type | Description | +| --------- | ------- | ------------------------------------------ | +| target | address | Target address to execute the transaction. | +| value | uint256 | | +| signature | string | Function signature to execute. | +| data | bytes | The data to include in the transaction. | +| eta | uint256 | The earliest eta to queue the transaction. | + +#### Return Values + +| Name | Type | Description | +| -------- | ----- | ------------------------------------------------ | +| response | bytes | The response from the transaction once executed. | diff --git a/docs/token/ERC20/EncryptedERC20.md b/docs/token/ERC20/EncryptedERC20.md new file mode 100644 index 0000000..f037e58 --- /dev/null +++ b/docs/token/ERC20/EncryptedERC20.md @@ -0,0 +1,208 @@ +# EncryptedERC20 + +This contract implements an encrypted ERC20-like token with confidential balances using Zama's FHE (Fully Homomorphic +Encryption) library. + +_It supports standard ERC20 functions such as transferring tokens, minting, and setting allowances, but uses encrypted +data types. The total supply is not encrypted._ + +## \_totalSupply + +```solidity +uint64 _totalSupply +``` + +Total supply. + +## \_name + +```solidity +string _name +``` + +Name. + +## \_symbol + +```solidity +string _symbol +``` + +Symbol. + +## \_balances + +```solidity +mapping(address => euint64) _balances +``` + +A mapping from `account` address to an encrypted `balance`. + +## \_allowances + +```solidity +mapping(address => mapping(address => euint64)) _allowances +``` + +A mapping of the form mapping(account => mapping(spender => allowance)). + +## TFHESenderNotAllowed + +```solidity +error TFHESenderNotAllowed() +``` + +Error when the `sender` is not allowed to access a value. + +## constructor + +```solidity +constructor(string name_, string symbol_) internal +``` + +### Parameters + +| Name | Type | Description | +| -------- | ------ | ------------------ | +| name\_ | string | Name of the token. | +| symbol\_ | string | Symbol. | + +## approve + +```solidity +function approve(address spender, einput encryptedAmount, bytes inputProof) public virtual returns (bool) +``` + +See {IEncryptedERC20-approve}. + +## approve + +```solidity +function approve(address spender, euint64 amount) public virtual returns (bool) +``` + +See {IEncryptedERC20-approve}. + +## transfer + +```solidity +function transfer(address to, einput encryptedAmount, bytes inputProof) public virtual returns (bool) +``` + +See {IEncryptedERC20-transfer}. + +## transfer + +```solidity +function transfer(address to, euint64 amount) public virtual returns (bool) +``` + +See {IEncryptedERC20-transfer}. + +## transferFrom + +```solidity +function transferFrom(address from, address to, einput encryptedAmount, bytes inputProof) public virtual returns (bool) +``` + +See {IEncryptedERC20-transferFrom}. + +## transferFrom + +```solidity +function transferFrom(address from, address to, euint64 amount) public virtual returns (bool) +``` + +See {IEncryptedERC20-transferFrom}. + +## allowance + +```solidity +function allowance(address owner, address spender) public view virtual returns (euint64) +``` + +See {IEncryptedERC20-allowance}. + +## balanceOf + +```solidity +function balanceOf(address account) public view virtual returns (euint64) +``` + +See {IEncryptedERC20-balanceOf}. + +## decimals + +```solidity +function decimals() public view virtual returns (uint8) +``` + +See {IEncryptedERC20-decimals}. + +## name + +```solidity +function name() public view virtual returns (string) +``` + +See {IEncryptedERC20-name}. + +## symbol + +```solidity +function symbol() public view virtual returns (string) +``` + +See {IEncryptedERC20-symbol}. + +## totalSupply + +```solidity +function totalSupply() public view virtual returns (uint64) +``` + +See {IEncryptedERC20-totalSupply}. + +## \_approve + +```solidity +function _approve(address owner, address spender, euint64 amount) internal virtual +``` + +## \_unsafeMint + +```solidity +function _unsafeMint(address account, euint64 amount) internal virtual +``` + +_It does not incorporate any overflow check. It must be implemented by the function calling it._ + +## \_transfer + +```solidity +function _transfer(address from, address to, euint64 amount, ebool isTransferable) internal virtual +``` + +## \_transferNoEvent + +```solidity +function _transferNoEvent(address from, address to, euint64 amount, ebool isTransferable) internal virtual +``` + +## \_updateAllowance + +```solidity +function _updateAllowance(address owner, address spender, euint64 amount) internal virtual returns (ebool) +``` + +## \_allowance + +```solidity +function _allowance(address owner, address spender) internal view virtual returns (euint64) +``` + +## \_isSenderAllowedForAmount + +```solidity +function _isSenderAllowedForAmount(euint64 amount) internal view virtual +``` diff --git a/docs/token/ERC20/IEncryptedERC20.md b/docs/token/ERC20/IEncryptedERC20.md new file mode 100644 index 0000000..319c7fd --- /dev/null +++ b/docs/token/ERC20/IEncryptedERC20.md @@ -0,0 +1,131 @@ +# IEncryptedERC20 + +Interface that defines ERC20-like tokens with encrypted balances. + +## Approval + +```solidity +event Approval(address owner, address spender) +``` + +Emitted when the allowance of a `spender` for an `owner` is set by a call to {approve}. + +## Transfer + +```solidity +event Transfer(address from, address to) +``` + +Emitted when tokens are moved from one account (`from`) to another (`to`). + +## ReceiverAddressNull + +```solidity +error ReceiverAddressNull() +``` + +Returned when receiver is address(0). + +## SenderAddressNull + +```solidity +error SenderAddressNull() +``` + +Returned when sender is address(0). + +## approve + +```solidity +function approve(address spender, einput encryptedAmount, bytes inputProof) external returns (bool) +``` + +Sets the `encryptedAmount` as the allowance of `spender` over the caller's tokens. + +## approve + +```solidity +function approve(address spender, euint64 amount) external returns (bool) +``` + +Sets the `amount` as the allowance of `spender` over the caller's tokens. + +## transfer + +```solidity +function transfer(address to, einput encryptedAmount, bytes inputProof) external returns (bool) +``` + +Transfers an encrypted amount from the message sender address to the `to` address. + +## transfer + +```solidity +function transfer(address to, euint64 amount) external returns (bool) +``` + +Transfers an amount from the message sender address to the `to` address. + +## transferFrom + +```solidity +function transferFrom(address from, address to, euint64 amount) external returns (bool) +``` + +Transfers `amount` tokens using the caller's allowance. + +## transferFrom + +```solidity +function transferFrom(address from, address to, einput encryptedAmount, bytes inputProof) external returns (bool) +``` + +Transfers `encryptedAmount` tokens using the caller's allowance. + +## allowance + +```solidity +function allowance(address owner, address spender) external view returns (euint64) +``` + +Returns the remaining number of tokens that `spender` is allowed to spend on behalf of the caller. + +## balanceOf + +```solidity +function balanceOf(address wallet) external view returns (euint64) +``` + +Returns the balance handle of the caller. + +## decimals + +```solidity +function decimals() external view returns (uint8) +``` + +Returns the number of decimals. + +## name + +```solidity +function name() external view returns (string) +``` + +Returns the name of the token. + +## symbol + +```solidity +function symbol() external view returns (string) +``` + +Returns the symbol of the token, usually a shorter version of the name. + +## totalSupply + +```solidity +function totalSupply() external view returns (uint64) +``` + +Returns the total supply of the token. diff --git a/docs/token/ERC20/extensions/EncryptedERC20Mintable.md b/docs/token/ERC20/extensions/EncryptedERC20Mintable.md new file mode 100644 index 0000000..3040e3d --- /dev/null +++ b/docs/token/ERC20/extensions/EncryptedERC20Mintable.md @@ -0,0 +1,41 @@ +# EncryptedERC20Mintable + +This contract inherits EncryptedERC20. + +_It allows an owner to mint tokens. Mint amounts are public._ + +## Mint + +```solidity +event Mint(address to, uint64 amount) +``` + +Emitted when `amount` tokens are minted to one account (`to`). + +## constructor + +```solidity +constructor(string name_, string symbol_, address owner_) internal +``` + +### Parameters + +| Name | Type | Description | +| -------- | ------- | ------------------ | +| name\_ | string | Name of the token. | +| symbol\_ | string | Symbol. | +| owner\_ | address | Owner address. | + +## mint + +```solidity +function mint(uint64 amount) public virtual +``` + +Mint tokens. + +### Parameters + +| Name | Type | Description | +| ------ | ------ | ------------------------- | +| amount | uint64 | Amount of tokens to mint. | diff --git a/docs/token/ERC20/extensions/EncryptedERC20WithErrors.md b/docs/token/ERC20/extensions/EncryptedERC20WithErrors.md new file mode 100644 index 0000000..d9fe5e7 --- /dev/null +++ b/docs/token/ERC20/extensions/EncryptedERC20WithErrors.md @@ -0,0 +1,90 @@ +# EncryptedERC20WithErrors + +This contract implements an encrypted ERC20-like token with confidential balances using Zama's FHE (Fully Homomorphic +Encryption) library. + +It supports standard ERC20 functions such as transferring tokens, minting, and setting allowances, but uses encrypted +data types. The total supply is not encrypted. It also supports error handling for encrypted errors. + +## TransferWithErrorHandling + +```solidity +event TransferWithErrorHandling(address from, address to, uint256 transferId) +``` + +Emitted when tokens are moved from one account (`from`) to another (`to`). + +## ErrorCodes + +Error codes allow tracking (in the storage) whether a transfer worked. + +| Name | Description | +| --------------------- | ------------------------------------------------------------------------------------------------ | +| NO_ERROR | The transfer worked as expected. | +| UNSUFFICIENT_BALANCE | The transfer failed because the from balances were strictly inferior to the amount to transfer. | +| UNSUFFICIENT_APPROVAL | The transfer failed because the sender allowance was strictly lower than the amount to transfer. | + +```solidity +enum ErrorCodes { + NO_ERROR, + UNSUFFICIENT_BALANCE, + UNSUFFICIENT_APPROVAL +} +``` + +## \_errorCodeForTransferId + +```solidity +mapping(uint256 => euint8) _errorCodeForTransferId +``` + +A mapping from transferId to the error code. + +## constructor + +```solidity +constructor(string name_, string symbol_) internal +``` + +### Parameters + +| Name | Type | Description | +| -------- | ------ | ------------------ | +| name\_ | string | Name of the token. | +| symbol\_ | string | Symbol. | + +## transfer + +```solidity +function transfer(address to, euint64 amount) public virtual returns (bool) +``` + +See {IEncryptedERC20-transfer}. + +## transferFrom + +```solidity +function transferFrom(address from, address to, euint64 amount) public virtual returns (bool) +``` + +See {IEncryptedERC20-transferFrom}. + +## getErrorCodeForTransferId + +```solidity +function getErrorCodeForTransferId(uint256 transferId) public view virtual returns (euint8 errorCode) +``` + +Returns the error code corresponding to `transferId`. + +## \_transferWithErrorCode + +```solidity +function _transferWithErrorCode(address from, address to, euint64 amount, ebool isTransferable, euint8 errorCode) internal virtual +``` + +## \_updateAllowanceWithErrorCode + +```solidity +function _updateAllowanceWithErrorCode(address owner, address spender, euint64 amount) internal virtual returns (ebool isTransferable, euint8 errorCode) +``` diff --git a/docs/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.md b/docs/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.md new file mode 100644 index 0000000..d131a03 --- /dev/null +++ b/docs/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.md @@ -0,0 +1,41 @@ +# EncryptedERC20WithErrorsMintable + +This contract inherits EncryptedERC20WithErrors. + +_It allows an owner to mint tokens. Mint amounts are public._ + +## Mint + +```solidity +event Mint(address to, uint64 amount) +``` + +Emitted when `amount` tokens are minted to one account (`to`). + +## constructor + +```solidity +constructor(string name_, string symbol_, address owner_) internal +``` + +### Parameters + +| Name | Type | Description | +| -------- | ------- | ------------------ | +| name\_ | string | Name of the token. | +| symbol\_ | string | Symbol. | +| owner\_ | address | Owner address. | + +## mint + +```solidity +function mint(uint64 amount) public virtual +``` + +Mint tokens. + +### Parameters + +| Name | Type | Description | +| ------ | ------ | ------------------------- | +| amount | uint64 | Amount of tokens to mint. | diff --git a/docs/utils/EncryptedErrors.md b/docs/utils/EncryptedErrors.md index 70fd0ca..0b92d73 100644 --- a/docs/utils/EncryptedErrors.md +++ b/docs/utils/EncryptedErrors.md @@ -1,214 +1,56 @@ -# Solidity API - ## EncryptedErrors -This abstract contract is used for error handling in the fhEVM. - -Error codes are trivially encrypted during construction inside the `errorCodes` array. - -WARNING: `errorCodes[0]` should always refer to the `NO_ERROR` code, by default. - -### constructor - -```solidity -constructor(uint8 numErrors) internal -``` - -Sets the non-null value for `numErrors` corresponding to the total number of errors. - -_`numErrors` must be non-null, note that `errorCodes[0]` corresponds to the `NO_ERROR` code._ - -#### Parameters - -| Name | Type | Description | -| --------- | ----- | ------------------------------------- | -| numErrors | uint8 | the total number of different errors. | - -### getErrorCode - -```solidity -function getErrorCode(uint8 indexCode) internal view returns (euint8) -``` - -Returns the encrypted error code at index `indexCode`. - -#### Parameters - -| Name | Type | Description | -| --------- | ----- | -------------------------------------- | -| indexCode | uint8 | the index of the requested error code. | - -#### Return Values - -| Name | Type | Description | -| ---- | ------ | ------------------------------------------------ | -| [0] | euint8 | the encrypted error code located at `indexCode`. | - -### getErrorCounter - -```solidity -function getErrorCounter() internal view returns (uint256) -``` - -Returns the total number of error codes currently stored in `errorCodesMapping`. - -#### Return Values - -| Name | Type | Description | -| ---- | ------- | -------------------------------------------------------------------- | -| [0] | uint256 | the number of error codes stored in the `errorCodesMapping` mapping. | - -### getNumErrors - -```solidity -function getNumErrors() internal view returns (uint8) -``` - -Returns the total number of the possible errors. - -#### Return Values - -| Name | Type | Description | -| ---- | ----- | -------------------------------------------------- | -| [0] | uint8 | the total number of the different possible errors. | - -### getError +This abstract contract is used for error handling in the fhEVM. Error codes are encrypted in the constructor inside the +`errorCodes` mapping. -```solidity -function getError(uint256 errorId) internal view returns (euint8) -``` - -Returns the encrypted error code which was stored in the mapping at key `errorId`. - -_`errorId` must be a valid id, i.e below the error counter._ - -#### Parameters - -| Name | Type | Description | -| ------- | ------- | ------------------------------------------------------------ | -| errorId | uint256 | the requested key stored in the `errorCodesMapping` mapping. | - -#### Return Values - -| Name | Type | Description | -| ---- | ------ | ------------------------------------------------------ | -| [0] | euint8 | the encrypted error code located at the `errorId` key. | - -### defineErrorIf - -```solidity -function defineErrorIf(ebool condition, uint8 indexCode) internal view returns (euint8) -``` - -Computes an encrypted error code, result will be either a reencryption of `errorCodes[indexCode]` if `condition` is an -encrypted `true` or of `NO_ERROR` otherwise. - -_`indexCode` must be non-null and below the total number of error codes._ - -#### Parameters - -| Name | Type | Description | -| --------- | ----- | -------------------------------------------------------------------- | -| condition | ebool | the encrypted boolean used in the cmux. | -| indexCode | uint8 | the index of the selected error code if `condition` encrypts `true`. | - -#### Return Values +_`errorCodes[0]` should always refer to the `NO_ERROR` code, by default._ -| Name | Type | Description | -| ---- | ------ | ---------------------------------------------------------- | -| [0] | euint8 | the reencrypted error code depending on `condition` value. | - -### defineErrorIfNot +### TotalNumberErrorsEqualToZero ```solidity -function defineErrorIfNot(ebool condition, uint8 indexCode) internal view returns (euint8) +error TotalNumberErrorsEqualToZero() ``` -Does the opposite of `defineErrorIf`, i.e result will be either a reencryption of `errorCodes[indexCode]` if `condition` -is an encrypted `false` or of `NO_ERROR` otherwise. - -_`indexCode` must be non-null and below the total number of error codes._ - -#### Parameters - -| Name | Type | Description | -| --------- | ----- | --------------------------------------------------------------------- | -| condition | ebool | the encrypted boolean used in the cmux. | -| indexCode | uint8 | the index of the selected error code if `condition` encrypts `false`. | +The total number of errors is equal to zero. -#### Return Values - -| Name | Type | Description | -| ---- | ------ | ---------------------------------------------------------- | -| [0] | euint8 | the reencrypted error code depending on `condition` value. | - -### changeErrorIf +### \_errorCodes ```solidity -function changeErrorIf(ebool condition, uint8 indexCode, euint8 errorCode) internal view returns (euint8) +mapping(uint8 => euint8) _errorCodes ``` -Computes an encrypted error code, result will be either a reencryption of `errorCodes[indexCode]` if `condition` is an -encrypted `true` or of `errorCode` otherwise. - -_`indexCode` must be below the total number of error codes._ - -#### Parameters +Mapping of error codes. -| Name | Type | Description | -| --------- | ------ | ------------------------------------------------------- | -| condition | ebool | the encrypted boolean used in the cmux. | -| indexCode | uint8 | | -| errorCode | euint8 | the selected error code if `condition` encrypts `true`. | +_It does not use arrays they are more expensive than mappings._ -#### Return Values - -| Name | Type | Description | -| ---- | ------ | ---------------------------------------------------------- | -| [0] | euint8 | the reencrypted error code depending on `condition` value. | - -### changeErrorIfNot +### constructor ```solidity -function changeErrorIfNot(ebool condition, uint8 indexCode, euint8 errorCode) internal view returns (euint8) +constructor(uint8 totalNumberErrors_) internal ``` -Does the opposite of `changeErrorIf`, i.e result will be either a reencryption of `errorCodes[indexCode]` if `condition` -is an encrypted `false` or of `errorCode` otherwise. +Sets the non-null value for `numErrors` corresponding to the total number of errors. -_`indexCode` must be below the total number of error codes._ +_`numErrors` must be non-null (`errorCodes[0]` corresponds to the `NO_ERROR` code)._ #### Parameters -| Name | Type | Description | -| --------- | ------ | -------------------------------------------------------- | -| condition | ebool | the encrypted boolean used in the cmux. | -| indexCode | uint8 | | -| errorCode | euint8 | the selected error code if `condition` encrypts `false`. | +| Name | Type | Description | +| ------------------- | ----- | --------------------------------- | +| totalNumberErrors\_ | uint8 | total number of different errors. | -#### Return Values - -| Name | Type | Description | -| ---- | ------ | ---------------------------------------------------------- | -| [0] | euint8 | the reencrypted error code depending on `condition` value. | - -### saveError +### getTotalNumberErrors ```solidity -function saveError(euint8 errorCode) internal returns (uint256) +function getTotalNumberErrors() external view returns (uint8 totalNumberErrors) ``` -Saves `errorCode` in storage, in the `errorCodesMapping` mapping, at the lowest unused key. This is the only stateful -function of `EncryptedErrors` abstract contract. - -#### Parameters +Returns the total number of errors. -| Name | Type | Description | -| --------- | ------ | ------------------------------------------------ | -| errorCode | euint8 | the encrypted error code to be saved in storage. | +_It does not count `NO_ERROR` as one of the errors._ #### Return Values -| Name | Type | Description | -| ---- | ------- | --------------------------------------------------------------------- | -| [0] | uint256 | the `errorId` key in `errorCodesMapping` where `errorCode` is stored. | +| Name | Type | Description | +| ----------------- | ----- | ----------------------- | +| totalNumberErrors | uint8 | total number of errors. | diff --git a/hardhat.config.ts b/hardhat.config.ts index 9dae56b..5129c20 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -10,6 +10,7 @@ import { task } from "hardhat/config"; import type { NetworkUserConfig } from "hardhat/types"; import { resolve } from "path"; import * as path from "path"; +import "solidity-docgen"; import CustomProvider from "./CustomProvider"; // Adjust the import path as needed @@ -91,7 +92,7 @@ function replaceImportStatement(filePath: string, oldImport: string, newImport: } } -task("test", async (taskArgs, hre, runSuper) => { +task("test", async (_taskArgs, hre, runSuper) => { // Run modified test task if (hre.network.name === "hardhat") { // in fhevm mode all this block is done when launching the node via `pnmp fhevm:start` @@ -136,6 +137,11 @@ task("test", async (taskArgs, hre, runSuper) => { }); const config: HardhatUserConfig = { + docgen: { + output: "docs", + pages: "files", + exclude: ["test/"], + }, defaultNetwork: "local", namedAccounts: { deployer: 0, diff --git a/package.json b/package.json index d09add4..918bdb9 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "rimraf": "^4.4.1", "solhint": "^3.6.2", "solhint-plugin-prettier": "^0.0.5", + "solidity-docgen": "^0.6.0-beta.36", "solidity-coverage": "0.8.12", "ts-generator": "^0.1.1", "ts-node": "^10.9.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 50d8483..68c80b5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -147,6 +147,9 @@ importers: solidity-coverage: specifier: 0.8.12 version: 0.8.12(hardhat@2.22.14(ts-node@10.9.2(@types/node@18.19.59)(typescript@5.4.2))(typescript@5.4.2)) + solidity-docgen: + specifier: ^0.6.0-beta.36 + version: 0.6.0-beta.36(hardhat@2.22.14(ts-node@10.9.2(@types/node@18.19.59)(typescript@5.4.2))(typescript@5.4.2)) ts-generator: specifier: ^0.1.1 version: 0.1.1 @@ -3148,6 +3151,11 @@ packages: peerDependencies: hardhat: ^2.11.0 + solidity-docgen@0.6.0-beta.36: + resolution: {integrity: sha512-f/I5G2iJgU1h0XrrjRD0hHMr7C10u276vYvm//rw1TzFcYQ4xTOyAoi9oNAHRU0JU4mY9eTuxdVc2zahdMuhaQ==} + peerDependencies: + hardhat: ^2.8.0 + source-map-support@0.5.21: resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==} @@ -7234,6 +7242,12 @@ snapshots: shelljs: 0.8.5 web3-utils: 1.10.4 + solidity-docgen@0.6.0-beta.36(hardhat@2.22.14(ts-node@10.9.2(@types/node@18.19.59)(typescript@5.4.2))(typescript@5.4.2)): + dependencies: + handlebars: 4.7.8 + hardhat: 2.22.14(ts-node@10.9.2(@types/node@18.19.59)(typescript@5.4.2))(typescript@5.4.2) + solidity-ast: 0.4.59 + source-map-support@0.5.21: dependencies: buffer-from: 1.1.2