Skip to content

Commit

Permalink
Merge pull request zama-ai#65 from PacificYield/various-fixes
Browse files Browse the repository at this point in the history
fix: Various fixes
  • Loading branch information
PacificYield authored Nov 22, 2024
2 parents 1aa4eb6 + c9eff27 commit 7555d43
Show file tree
Hide file tree
Showing 20 changed files with 1,272 additions and 775 deletions.
6 changes: 5 additions & 1 deletion .commitlintrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import type { UserConfig } from "@commitlint/types";
const Configuration: UserConfig = {
extends: ["@commitlint/config-conventional"],
rules: {
"type-enum": [2, "always", ["ci", "chore", "docs", "ticket", "feat", "fix", "perf", "refactor", "revert", "style"]],
"type-enum": [
2,
"always",
["ci", "chore", "docs", "ticket", "feat", "fix", "perf", "refactor", "revert", "style", "test"],
],
},
};

Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/testmock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -19,5 +22,6 @@ jobs:
- run: cp .env.example .env
- run: pnpm install
- run: pnpm prettier:check
- name: pnpm CI test:mock
run: pnpm test:mock
- run: pnpm lint:sol
- name: pnpm CI test
run: pnpm test
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
.coverage_artifacts
.coverage_cache
.coverage_contracts
abi
artifacts
build
cache
coverage
dist
fhevmTemp
node_modules
types

Expand Down
56 changes: 48 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ fhEVM contracts is a Solidity library for secure smart-contract development usin

### Installation

You can import this repo using your package manager.

```bash
# Using npm
npm install fhevm-contracts
Expand All @@ -20,29 +22,64 @@ yarn add fhevm-contracts
pnpm add fhevm-contracts
```

### A Simple Example
### Simple contract

To write Solidity contracts that use `TFHE` and/or `Gateway`, it is required to set different contract addresses.

Fortunately, [the fhevm repo)](https://github.com/zama-ai/fhevm), one of this repo's dependencies, exports config files
that can be inherited to simplify the process.

#### Using the mock network (for testing)

```solidity
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;
import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { EncryptedERC20 } from "fhevm-contracts/contracts/token/ERC20/EncryptedERC20.sol";
contract MyERC20 is MockZamaFHEVMConfig, EncryptedERC20 {
constructor() EncryptedERC20("MyToken", "MYTOKEN") {
_unsafeMint(1000000, msg.sender);
}
}
```

#### Using Sepolia

```solidity
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;
import "fhevm/lib/TFHE.sol";
import "fhevm-contracts/contracts/token/ERC20/EncryptedERC20.sol";
import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol";
import { EncryptedERC20 } from "fhevm-contracts/contracts/token/ERC20/EncryptedERC20.sol";
contract MyERC20 is EncryptedERC20 {
contract MyERC20 is SepoliaZamaFHEVMConfig, EncryptedERC20 {
constructor() EncryptedERC20("MyToken", "MYTOKEN") {
TFHE.setFHEVM(FHEVMConfig.defaultConfig());
_unsafeMint(1000000, msg.sender);
}
}
```

## Resources
## Available contracts

As of version 0.2, these Solidity templates include governance-related and token-related contracts.

### Documentation
### Token

The full documentation is available [here](https://docs.zama.ai/fhevm).
- [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)

### Governance

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

### Utils

- [EncryptedErrors](./contracts/utils/EncryptedErrors.sol)

### Contributing

Expand All @@ -57,5 +94,8 @@ can send pull requests, so please make sure to get in touch before you do.

### License

> [!CAUTION] Smart contracts are a nascent technology that carry a high level of technical risk and uncertainty. You are
> solely responsible for any use of the fhEVM Contracts and you assume all risks associated with any such use.
This software is distributed under the **BSD-3-Clause-Clear** license. If you have any question about the license,
please contact us at [email protected].
1 change: 1 addition & 0 deletions contracts/governance/ICompoundTimelock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ interface ICompoundTimelock {
* The grace period indicates how long a transaction can remain queued before it cannot be
* executed again.
*/
/* solhint-disable func-name-mixedcase*/
function GRACE_PERIOD() external view returns (uint256);

/**
Expand Down
10 changes: 0 additions & 10 deletions contracts/test/DefaultFHEVMConfig.sol

This file was deleted.

10 changes: 0 additions & 10 deletions contracts/test/DefaultGatewayConfig.sol

This file was deleted.

4 changes: 2 additions & 2 deletions contracts/test/governance/TestComp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity ^0.8.24;

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

contract TestComp is DefaultFHEVMConfig, Comp {
contract TestComp is MockZamaFHEVMConfig, Comp {
constructor(
address owner_,
string memory name_,
Expand Down
6 changes: 3 additions & 3 deletions contracts/test/governance/TestGovernorAlphaZama.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity ^0.8.24;

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

contract TestGovernorAlphaZama is DefaultFHEVMConfig, DefaultGatewayConfig, GovernorAlphaZama {
contract TestGovernorAlphaZama is MockZamaFHEVMConfig, MockZamaGatewayConfig, GovernorAlphaZama {
constructor(
address owner_,
address timelock_,
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/token/ERC20/TestEncryptedERC20Mintable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity ^0.8.24;

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

contract TestEncryptedERC20Mintable is DefaultFHEVMConfig, EncryptedERC20Mintable {
contract TestEncryptedERC20Mintable is MockZamaFHEVMConfig, EncryptedERC20Mintable {
constructor(
string memory name_,
string memory symbol_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity ^0.8.24;

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

contract TestEncryptedERC20WithErrorsMintable is DefaultFHEVMConfig, EncryptedERC20WithErrorsMintable {
contract TestEncryptedERC20WithErrorsMintable is MockZamaFHEVMConfig, EncryptedERC20WithErrorsMintable {
constructor(
string memory name_,
string memory symbol_,
Expand Down
4 changes: 1 addition & 3 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import "@nomicfoundation/hardhat-toolbox";
import "@openzeppelin/hardhat-upgrades";
import dotenv from "dotenv";
import * as fs from "fs-extra";
import "hardhat-deploy";
import "hardhat-ignore-warnings";
import type { HardhatUserConfig } from "hardhat/config";
import { extendProvider } from "hardhat/config";
import { task } from "hardhat/config";
import { extendProvider, task } from "hardhat/config";
import type { NetworkUserConfig } from "hardhat/types";
import { resolve } from "path";
import * as path from "path";
Expand Down
64 changes: 26 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,51 @@
},
"license": "BSD-3-Clause",
"devDependencies": {
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@commitlint/cli": "^19.6.0",
"@commitlint/config-conventional": "^19.6.0",
"@commitlint/types": "^19.5.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.6",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@nomicfoundation/hardhat-network-helpers": "^1.0.10",
"@nomicfoundation/hardhat-toolbox": "^3.0.0",
"@nomicfoundation/hardhat-verify": "^1.1.1",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.8",
"@nomicfoundation/hardhat-ethers": "^3.0.8",
"@nomicfoundation/hardhat-network-helpers": "^1.0.12",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@openzeppelin/hardhat-upgrades": "^3.5.0",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@typechain/ethers-v6": "^0.4.3",
"@typechain/hardhat": "^8.0.3",
"@types/chai": "^4.3.12",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/chai": "^5.0.1",
"@types/fs-extra": "^9.0.13",
"@types/mocha": "^10.0.6",
"@types/node": "^18.19.59",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/parser": "^8.15.0",
"chai": "^4.4.1",
"cross-env": "^7.0.3",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint-config-prettier": "^8.10.0",
"ethers": "^6.11.1",
"fhevm": "^0.6.0-0",
"eslint": "^9.15.0",
"eslint-config-prettier": "^9.1.0",
"ethers": "^6.13.4",
"fhevm": "0.6.0-1",
"fhevm-core-contracts": "0.1.0-2",
"fhevmjs": "^0.6.0-4",
"fs-extra": "^10.1.0",
"fs-extra": "^11.2.0",
"hardhat": "2.22.14",
"hardhat-deploy": "^0.11.45",
"hardhat-gas-reporter": "^1.0.10",
"hardhat-ignore-warnings": "^0.2.11",
"hardhat-preprocessor": "^0.1.5",
"husky": "^9.1.6",
"lodash": "^4.17.21",
"mocha": "^10.3.0",
"prettier": "^2.8.8",
"mocha": "^10.8.2",
"prettier": "^3.3.3",
"prettier-plugin-solidity": "^1.3.1",
"rimraf": "^4.4.1",
"solhint": "^3.6.2",
"solhint-plugin-prettier": "^0.0.5",
"rimraf": "^6.0.1",
"solhint": "^5.0.3",
"solhint-plugin-prettier": "^0.1.0",
"solidity-coverage": "0.8.13",
"solidity-docgen": "^0.6.0-beta.36",
"solidity-coverage": "0.8.12",
"ts-generator": "^0.1.1",
"ts-node": "^10.9.2",
"typechain": "^8.3.2",
"typescript": "^5.4.2"
"typescript": "^5.6.3"
},
"files": [
"contracts/governance/",
Expand Down Expand Up @@ -87,24 +85,14 @@
"prettier:check": "prettier --check \"**/*.{js,json,md,sol,ts,yml}\"",
"prettier:write": "prettier --write \"**/*.{js,json,md,sol,ts,yml}\"",
"typechain": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat typechain",
"test": "hardhat test",
"test:mock": "HARDHAT_NETWORK=hardhat npx hardhat test --network hardhat",
"coverage:mock": "npx hardhat coverage",
"test": "HARDHAT_NETWORK=hardhat npx hardhat test",
"coverage": "npx hardhat coverage",
"task:getEthereumAddress": "hardhat task:getEthereumAddress",
"task:accounts": "hardhat task:accounts",
"fhevm:start": "./launch-fhevm.sh",
"fhevm:stop": "docker rm -f fhevm",
"fhevm:restart": "fhevm:stop && fhevm:start",
"fhevm:faucet": "npm run fhevm:faucet:alice && sleep 5 && npm run fhevm:faucet:bob && sleep 5 && npm run fhevm:faucet:carol && sleep 5 && npm run fhevm:faucet:dave && sleep 5 && npm run fhevm:faucet:eve",
"fhevm:faucet:alice": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressAlice)",
"fhevm:faucet:bob": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressBob)",
"fhevm:faucet:carol": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressCarol)",
"fhevm:faucet:dave": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressDave)",
"fhevm:faucet:eve": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressEve)"
"task:accounts": "hardhat task:accounts"
},
"dependencies": {
"@openzeppelin/contracts-upgradeable": "5.0.2",
"@openzeppelin/contracts": "5.0.2",
"@openzeppelin/contracts-upgradeable": "5.0.2",
"extra-bigint": "^1.1.18",
"sqlite3": "^5.1.7"
}
Expand Down
Loading

0 comments on commit 7555d43

Please sign in to comment.