Skip to content

Commit

Permalink
Merge pull request #10 from FhenixProtocol/v0.3.x
Browse files Browse the repository at this point in the history
v3.0
  • Loading branch information
eshelB authored Nov 14, 2024
2 parents 3f3d1ac + a9695e4 commit aecfa1f
Show file tree
Hide file tree
Showing 16 changed files with 3,401 additions and 3,444 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
# Label used to access the service container
localfhenix:
options: --name localfhenix
image: ghcr.io/fhenixprotocol/localfhenix:v0.2.3-rc.2
image: ghcr.io/fhenixprotocol/localfhenix:v0.3.2-alpha.4
ports:
- 42000:3000
- 42069:8547
Expand All @@ -43,15 +43,15 @@ jobs:
run: "pnpm typechain"

- name: "Make Money"
run: "pnpm faucet"
run: "pnpm fhenix:faucet"

- name: "Test the contracts using Hardhat Network"
run: "pnpm test"
run: "pnpm test:hardhat"

- name: "Test the contract using LocalFhenix"
run: "pnpm test:localfhenix"

- name: "Add test summary"
run: |
echo "## Test results" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pnpm task:getCount # => 6

This template contains experimental support for testing using Hardhat Network. By importing the `fhenix-hardhat-network` plugin in `hardhat.config.ts` we add support for simulated operations using Hardhat Network. These do not perform the full FHE computations, and are menant to serve as development tools to verify contract logic.

Note that in order to use the hardhat network in tasks with `--network hardhat` the tasks need to deploy the contract themselves, as the network is ephemeral. Alternatively you can use the stand-alone hardhat network by setting it as the default network in `hardhat.config.ts`.

If you have any issues or feature requests regarding this support please open a ticket in this repository

## Troubleshooting
Expand Down
52 changes: 52 additions & 0 deletions deploy/00_deployCounter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

/**
* Deploys a contract named "Counter" using the deployer account and
* constructor arguments set to the deployer address
*
* @param hre HardhatRuntimeEnvironment object.
*/
const deployCounter: DeployFunction = async function (
hre: HardhatRuntimeEnvironment,
) {
/*
On localhost, the deployer account is the one that comes with Hardhat, which is already funded.
When deploying to live networks (e.g `yarn deploy --network goerli`), the deployer account
should have sufficient balance to pay for the gas fees for contract creation.
You can generate a random account with `yarn generate` which will fill DEPLOYER_PRIVATE_KEY
with a random private key in the .env file (then used on hardhat.config.ts)
You can run the `yarn account` command to check your balance in every network.
*/
const { deployer } = await hre.getNamedAccounts();
const { deploy } = hre.deployments;

if (hre.network.name === "hardhat" && process.argv.includes("deploy")) {
console.warn("Warning: you are deploying to the in-process Hardhat network, but this network gets destroyed right after the deployment task ends.");
}
// Fund the account before deploying.
if (hre.network.name === "localfhenix") {
if ((await hre.ethers.provider.getBalance(deployer)) === 0n) {
await hre.fhenixjs.getFunds(deployer);
console.log("Received tokens from the local faucet. Ready to deploy...");
}
}

await deploy("Counter", {
from: deployer,
// Contract constructor arguments
args: [],
log: true,
// autoMine: can be passed to the deploy function to make the deployment process faster on local networks by
// automatically mining the contract deployment transaction. There is no effect on live networks.
autoMine: true,
});
};

export default deployCounter;

// Tags are useful if you have multiple deploy files and only want to run one of them.
// e.g. yarn deploy --tags Counter
deployCounter.tags = ["Counter"];
34 changes: 0 additions & 34 deletions deploy/deploy.ts

This file was deleted.

110 changes: 68 additions & 42 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,79 @@
// Plugins
// Tasks
import "./tasks";
import "@nomicfoundation/hardhat-toolbox";
import {config as dotenvConfig} from "dotenv";
import * as dotenv from "dotenv";
dotenv.config();
import { HardhatUserConfig } from "hardhat/config";
import "@typechain/hardhat";
import "@nomicfoundation/hardhat-ethers";
import "@nomicfoundation/hardhat-chai-matchers";
import "hardhat-gas-reporter";
import "solidity-coverage";
import "@nomicfoundation/hardhat-verify";
import "hardhat-deploy";
import "hardhat-deploy-ethers";
import "fhenix-hardhat-docker";
import "fhenix-hardhat-plugin";
import "fhenix-hardhat-network";
import "hardhat-deploy";
import {HardhatUserConfig} from "hardhat/config";
import {resolve} from "path";

// DOTENV_CONFIG_PATH is used to specify the path to the .env file for example in the CI
const dotenvConfigPath: string = process.env.DOTENV_CONFIG_PATH || "./.env";
dotenvConfig({ path: resolve(__dirname, dotenvConfigPath) });

const TESTNET_CHAIN_ID = 8008135;
const TESTNET_RPC_URL = "https://api.helium.fhenix.zone";

const testnetConfig = {
chainId: TESTNET_CHAIN_ID,
url: TESTNET_RPC_URL,
}

// Select either private keys or mnemonic from .env file or environment variables
const keys = process.env.KEY;
if (!keys) {
let mnemonic = process.env.MNEMONIC;
if (!mnemonic) {
throw new Error("No mnemonic or private key provided, please set MNEMONIC or KEY in your .env file");
}
testnetConfig['accounts'] = {
count: 10,
mnemonic,
path: "m/44'/60'/0'/0",
}
} else {
testnetConfig['accounts'] = [keys];
}
import "./tasks";

// If not set, it uses ours Alchemy's default API key.
// You can get your own at https://dashboard.alchemyapi.io
const providerApiKey =
process.env.ALCHEMY_API_KEY || "oKxs-03sij-U_N0iOlrSsZFr29-IqbuF";
// If not set, it uses the hardhat account 0 private key.
const deployerPrivateKey =
process.env.DEPLOYER_PRIVATE_KEY ??
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
// If not set, it uses ours Etherscan default API key.
const etherscanApiKey =
process.env.ETHERSCAN_API_KEY || "DNXJA8RX2Q3VZ4URQIWP7Z68CJXQZSC6AW";

const config: HardhatUserConfig = {
solidity: "0.8.25",
defaultNetwork: "hardhat",
const config= {
solidity: {
version: "0.8.24",
settings: {
optimizer: {
enabled: true,
// https://docs.soliditylang.org/en/latest/using-the-compiler.html#optimizer-options
runs: 200,
},
},
},
defaultNetwork: "localfhenix",
namedAccounts: {
deployer: {
// By default, it will take the first Hardhat account as the deployer
default: 0,
},
},
networks: {
testnet: testnetConfig,
// View the networks that are pre-configured.
// If the network you are looking for is not here you can add new network settings
helium: {
url: "https://api.testnet.fhenix.zone:7747",
chainId: 42069,
accounts: [deployerPrivateKey],
},
nitrogen: {
url: "https://api.nitrogen.fhenix.zone",
chainId: 8008148,
accounts: [deployerPrivateKey],
},
localhost: {
chainId: 31337,
}
},
// configuration for harhdat-verify plugin
etherscan: {
apiKey: `${etherscanApiKey}`,
},
// configuration for etherscan-verify from hardhat-deploy plugin
verify: {
etherscan: {
apiKey: `${etherscanApiKey}`,
},
},
typechain: {
outDir: "types",
target: "ethers-v6",
sourcify: {
enabled: false,
},
};

Expand Down
80 changes: 49 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@
"version": "1.0.0",
"description": "An example repository to get you started with Fhenix development",
"scripts": {
"test": "hardhat test",
"test:localfhenix": "hardhat test --network localfhenix",
"test": "REPORT_GAS=true hardhat test --network localfhenix",
"test:hardhat": "REPORT_GAS=true hardhat test --network hardhat",
"test:localfhenix": "REPORT_GAS=true hardhat test --network localfhenix",
"clean": "rimraf ./artifacts ./cache ./coverage ./types ./coverage.json ./deployments/localfhenix",
"compile": "hardhat compile",
"--------------": "",
" --- fhenix ---": "",
" --------------": "",
"fhenix:faucet": "hardhat task:fhenix:usefaucet",
"fhenix:checkExposedEncryptedVars": "hardhat task:fhenix:checkExposedEncryptedVars",
"task:deploy": "hardhat deploy",
"task:addCount": "hardhat task:addCount",
"task:getCount": "hardhat task:getCount",
"task:getFunds": "hardhat task:getFunds",
"localfhenix:start": "hardhat localfhenix:start",
"localfhenix:stop": "hardhat localfhenix:stop",
"faucet": "hardhat task:fhenix:usefaucet"
"-------------------": "",
" --- localfhenix ---": "",
" -------------------": "",
"localfhenix:start": "hardhat localfhenix:start --clean true",
"localfhenix:faucet": "hardhat task:fhenix:usefaucet",
"localfhenix:deploy": "hardhat deploy --network localfhenix",
"localfhenix:stop": "hardhat localfhenix:stop"
},
"repository": {
"type": "git",
Expand All @@ -26,35 +36,43 @@
},
"homepage": "https://github.com/fhenixprotocol/fhenix-hardhat-example#readme",
"devDependencies": {
"@fhenixprotocol/contracts": "0.2.1",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.6",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/providers": "^5.7.1",
"@openzeppelin/contracts": "^5.0.0",
"@fhenixprotocol/contracts": "0.3.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.3",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@nomicfoundation/hardhat-network-helpers": "^1.0.10",
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.4",
"@openzeppelin/contracts": "^5.0.1",
"@nomicfoundation/hardhat-network-helpers": "^1.0.6",
"@nomicfoundation/hardhat-verify": "^2.0.3",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/chai": "^4.3.11",
"@types/fs-extra": "^11.0.4",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.19",
"axios": "^1.6.7",
"chai": "^4.3.7",
"chalk": "^4.1.2",
"dotenv": "^16.4.5",
"ethers": "^6.11.1",
"fhenix-hardhat-docker": "0.2.2",
"fhenix-hardhat-plugin": "0.2.2-alpha.0",
"fhenix-hardhat-network": "0.2.3-alpha.0",
"hardhat": "^2.20.1",
"hardhat-deploy": "^0.11.45",
"hardhat-gas-reporter": "^1.0.10",
"mocha": "^10.3.0",
"@types/eslint": "^8",
"@types/mocha": "^9.1.1",
"@types/prettier": "^2",
"@types/qrcode": "^1",
"@typescript-eslint/eslint-plugin": "latest",
"@typescript-eslint/parser": "latest",
"chai": "^4.3.6",
"eslint": "^8.26.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"ethers": "^6.10.0",
"fhenix-hardhat-docker": "^0.3.2",
"fhenix-hardhat-network": "^0.3.2",
"fhenix-hardhat-plugin": "^0.3.2",
"fhenixjs": "0.4.0",
"hardhat": "^2.19.4",
"hardhat-deploy": "^0.12.0",
"hardhat-deploy-ethers": "^0.4.1",
"hardhat-gas-reporter": "^1.0.9",
"prettier": "^2.8.4",
"rimraf": "^5.0.5",
"solidity-coverage": "^0.8.7",
"ts-node": "^10.9.2",
"typechain": "^8.3.2",
"typescript": "^5.3.3"
"solidity-coverage": "^0.8.5",
"ts-node": "^10.9.1",
"typechain": "^8.1.0",
"typescript": "^5.1.6",
"dotenv": "^16.0.3",
"envfile": "^6.18.0",
"qrcode": "^1.5.1"
}
}
Loading

0 comments on commit aecfa1f

Please sign in to comment.