Skip to content

Commit

Permalink
Merge pull request #16 from FhenixProtocol/v0.3.x
Browse files Browse the repository at this point in the history
V0.3.x
  • Loading branch information
eshelB authored Nov 14, 2024
2 parents e9ad860 + e67a968 commit 47f3239
Show file tree
Hide file tree
Showing 51 changed files with 7,702 additions and 1,518 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ jobs:
- run: pnpm build
- name: Read package version
id: package_version
run: echo "VERSION=$(jq -r .version < ./package.json)" >> $GITHUB_ENV
run: |
version=$(jq -r .version < ./package.json)
echo "version: $version"
echo "VERSION=$version" >> $GITHUB_ENV
- name: Determine prerelease tag
id: prerelease_check
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ typings/
# environment variables
.env

dist
# ide files
.idea

dist
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@

Fhenix Hardhat Plugin is designed to extend your Hardhat environment with additional capabilities focused on Fhenix. It integrates seamlessly with your Hardhat projects to provide a local Fhenix environment, including customized network configuration and utilities for managing funds and permits within your blockchain applications.

See also [fhenix-hardhat-docker](https://www.npmjs.com/package/fhenix-hardhat-docker) and [fhenix-hardhat-network](https://www.npmjs.com/package/fhenix-hardhat-network/) for the full experience of Fhenix-compatible extensions.

## Features

- **Local Fhenix Environment:** Automatically sets up a local Fhenix network configuration within Hardhat, allowing for easy deployment and interaction with Fhenix contracts.
- **Faucet Integration:** Enables developers to easily obtain funds for testing purposes through a simple API call to a local faucet.
- **Permit Management:** Simplifies the process of creating and storing permit signatures required for transactions, reducing the complexity of interacting with contracts that require permissions.
- **Contract Security Checks:** Checks for Fhenix-related potential vulnerabilities in your contracts.
- **Hardhat Network Enhancements:** Adds support for simulated FHE operations in the built-in Hardhat network.

If you want to see a full example in action, check out our [Hardhat Example Template](https://github.com/FhenixProtocol/fhenix-hardhat-example)!

Expand All @@ -31,6 +35,12 @@ If you wish to run your own local dev environment, please install the [fhenix-ha
pnpm install fhenix-hardhat-docker
```

Or, if you use then built-in Hardhat network:

```sh
pnpm install fhenix-hardhat-network
```

## Setup

After installation, import the plugin in your Hardhat configuration file (e.g., `hardhat.config.js`):
Expand All @@ -39,6 +49,8 @@ After installation, import the plugin in your Hardhat configuration file (e.g.,
require("fhenix-hardhat-plugin");
// if using the docker plugin
require("fhenix-hardhat-docker");
// if using the network plugin
require("fhenix-hardhat-docker");
```

or if you are using TypeScript, in your `hardhat.config.ts`:
Expand All @@ -47,6 +59,8 @@ or if you are using TypeScript, in your `hardhat.config.ts`:
import "fhenix-hardhat-plugin";
// if using the docker plugin
import "fhenix-hardhat-docker";
// if using the network plugin
import "fhenix-hardhat-network";
```

## Configuration
Expand All @@ -57,6 +71,9 @@ The plugin automatically adds a `localfhenix` network configuration to your Hard

To target this network, simply add `--network localfhenix` to your hardhat commands, or set it as the default.

Alternatively, to use the build-in hardhat network, either do nothing if you're running the in-process network, or
add `--network localhost` to your hardhat commands if you're running the standalone network via `pnpm hardhat node`, just as you would without the fhenix-hardhat-network plugin.

### Using FhenixJS from Hardhat Runtime Environment

After importing `fhenix-hardhat-plugin` hardhat will automatically extend the Hardhat Runtime Environment (HRE) with a `fhenixjs` object, providing access to Fhenix-specific functionality:
Expand Down Expand Up @@ -98,6 +115,20 @@ To request funds from the local faucet for an address, use the `getFunds` method
await hre.fhenixjs.getFunds("your_wallet_address");
```

Or use the `usefaucet` task. Omitting the address will send to the first account in the configured wallet:

```sh
pnpm hardhat run task:fhenix:usefaucet [--address <address>]
```
Or you can specify the account number if you want to specify more than one account for the mnemonic specified
```sh
pnpm task:fhenix:usefaucet --account <number>
```
If you're not using localfhenix, you have to specify the faucet url yourself:
```sh
pnpm task:fhenix:usefaucet --url <faucet-url>
```

### Encryption

```javascript
Expand All @@ -112,6 +143,8 @@ To create a permit for a contract, use the `createPermit` method:
const permit = await hre.fhenixjs.createPermit("contract_address");
```

See [FhenixJs](https://github.com/FhenixProtocol/fhenix.js) documentation for more on using the `fhenixjs` object.

## Support

For issues, suggestions, or contributions, please open an issue or pull request in the GitHub repository.
For issues, suggestions, or contributions, please open an issue or pull request in the GitHub [repository](https://github.com/FhenixProtocol/fhenix-hardhat-plugin/).
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"name": "fhenix-hardhat-plugin-root",
"version": "0.3.0-alpha.2",
"license": "MIT",
"scripts": {
"preinstall": "npx only-allow pnpm",
"format": "prettier --write --cache .",
"lint": "pnpm -r --filter='./packages/*' run lint",
"build": "pnpm -r --filter='./packages/*' run build",
"test": "pnpm -r --filter='./packages/*' run test",
"publish": "pnpm -r --filter='./packages/*' publish --no-git-checks"
},
"repository": {
"type": "git",
"url": "https://github.com/FhenixProtocol/fhenix-hardhat-plugin/"
},
"private": true,
"pnpm": {
"overrides": {
"flat@<5.0.1": ">=5.0.1",
"debug@>=3.2.0 <3.2.7": ">=3.2.7",
"minimatch@<3.0.5": ">=3.0.5"
}
}
"name": "fhenix-hardhat-plugin-root",
"version": "0.3.2",
"license": "MIT",
"scripts": {
"preinstall": "npx only-allow pnpm",
"format": "prettier --write --cache .",
"lint": "pnpm -r --filter='./packages/*' run lint",
"build": "pnpm -r --filter='./packages/*' run build",
"test": "pnpm -r --filter='./packages/*' run test",
"publish": "pnpm -r --filter='./packages/*' publish --no-git-checks"
},
"repository": {
"type": "git",
"url": "https://github.com/FhenixProtocol/fhenix-hardhat-plugin/"
},
"private": true,
"pnpm": {
"overrides": {
"flat@<5.0.1": ">=5.0.1",
"debug@>=3.2.0 <3.2.7": ">=3.2.7",
"minimatch@<3.0.5": ">=3.0.5"
}
}
}
8 changes: 8 additions & 0 deletions packages/fhenix-hardhat-docker/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# folders
artifacts
cache
contracts
node_modules/
typechain-types
# files
**/*.json
20 changes: 20 additions & 0 deletions packages/fhenix-hardhat-docker/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"env": {
"node": true
},
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "off",
"prettier/prettier": [
"warn",
{
"endOfLine": "auto"
}
]
}
}
30 changes: 30 additions & 0 deletions packages/fhenix-hardhat-docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Fhenix-Hardhat-Docker Plugin [![NPM Package][npm-badge]][npm] [![Github Actions][gha-badge]][gha] [![License: MIT][license-badge]][license]

[npm]: https://www.npmjs.org/package/fhenix-hardhat-docker
[npm-badge]: https://img.shields.io/npm/v/fhenix-hardhat-plugin.svg
[gha]: https://github.com/fhenixprotocol/fhenix-hardhat-plugin/actions
[gha-badge]: https://github.com/fhenixprotocol/fhenix-hardhat-plugin/actions/workflows/test.yml/badge.svg
[license]: https://opensource.org/licenses/MIT
[license-badge]: https://img.shields.io/badge/License-MIT-blue.svg

## Usage

- **`localfhenix:start`** To start a local dev environment using docker. By default, the instance will listen for rpc connections on port `42069`
- **`localfhenix:stop`** Stops the docker container

To start the container:

```sh
pnpm hardhat localfhenix:start
```

If starting the instance was successful, you should see the message: `Started LocalFhenix successfully at 127.0.0.1:42069`.

To stop the running container:

```sh
pnpm hardhat localfhenix:stop
```

Which will result in `Successfully shut down LocalFhenix`

18 changes: 10 additions & 8 deletions packages/fhenix-hardhat-docker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fhenix-hardhat-docker",
"version": "0.3.0-alpha.2",
"version": "0.3.2",
"description": "Hardhat plugin to run Fhenix node locally",
"repository": "github:FhenixProtocol/fhenix-hardhat-plugin",
"author": "Fhe Labs",
Expand All @@ -16,8 +16,7 @@
"fhenix"
],
"scripts": {
"lint:fix": "prettier --write 'src/**/*.{js,ts}' 'test/**/*.{js,ts}' && tslint --fix --config tslint.json --project tsconfig.json",
"lint": "tslint --config tslint.json --project tsconfig.json",
"lint": "eslint --config ./.eslintrc.json --ignore-path ./.eslintignore ./**/*.ts",
"test": "mocha --exit --recursive --timeout 60000 'test/*.test.ts'",
"build": "tsc",
"watch": "tsc -w",
Expand All @@ -34,20 +33,23 @@
"@types/chai": "^4.3.11",
"@types/mocha": "^5.2.7",
"@types/node": "^16.18.76",
"@types/eslint": "^8",
"chai": "^4.4.1",
"hardhat": "^2.0.0",
"hardhat": "^2.11.0",
"mocha": "^10.4.0",
"prettier": "2.0.5",
"ts-node": "^8.10.2",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.3.0",
"@typescript-eslint/eslint-plugin": "latest",
"@typescript-eslint/parser": "latest",
"eslint": "^8.26.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"typescript": "^5.3.3"
},
"dependencies": {
"chalk": "^4.1.2"
},
"peerDependencies": {
"hardhat": "^2.0.0"
"hardhat": "^2.11.0"
}
}
4 changes: 2 additions & 2 deletions packages/fhenix-hardhat-docker/src/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"image": "ghcr.io/fhenixprotocol/localfhenix:v0.3.0-alpha.1",
"imageArm": "ghcr.io/fhenixprotocol/localfhenix:v0.3.0-alpha.1",
"image": "ghcr.io/fhenixprotocol/localfhenix:v0.3.2",
"imageArm": "ghcr.io/fhenixprotocol/localfhenix:v0.3.2",
"container_name": "localfhenix_hh_plugin"
}
2 changes: 2 additions & 0 deletions packages/fhenix-hardhat-docker/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export const TASK_FHENIX_DOCKER_START = "localfhenix:start";
export const TASK_FHENIX_DOCKER_STOP = "localfhenix:stop";
export const LOCALFHENIX_CONTAINER_NAME = container_name;
export const SUBTASK_FHENIX_DOCKER_PULL = "localfhenix:pull";
export const SUBTASK_FHENIX_DOCKER_CLEAN_DEPLOYMENTS =
"localfhenix:cleanDeployments";
18 changes: 18 additions & 0 deletions packages/fhenix-hardhat-docker/src/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import chalk from "chalk";
import fs from "fs";
import path from "path";

export const cleanDeployments = (): void => {
console.log(chalk.green("Cleaning deployments.."));

// Get the current working directory (root of the project that imported this package)
const cwd = process.cwd();
const deploymentsPath = path.join(cwd, "deployments/localfhenix");

if (fs.existsSync(deploymentsPath)) {
fs.rmSync(deploymentsPath, { recursive: true, force: true });
console.log(chalk.green("Successfully cleaned deployments directory"));
} else {
console.log(chalk.yellow(`No deployments found in ${deploymentsPath}`));
}
};
16 changes: 16 additions & 0 deletions packages/fhenix-hardhat-docker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FHENIX_DEFAULT_IMAGE,
FHENIX_DEFAULT_IMAGE_ARM,
LOCALFHENIX_CONTAINER_NAME,
SUBTASK_FHENIX_DOCKER_CLEAN_DEPLOYMENTS,
SUBTASK_FHENIX_DOCKER_PULL,
TASK_FHENIX_DOCKER_START,
TASK_FHENIX_DOCKER_STOP,
Expand All @@ -16,6 +17,7 @@ import {
runLocalFhenixSeparateProcess,
stopLocalFhenix,
} from "./docker";
import { cleanDeployments } from "./env";

task(TASK_FHENIX_DOCKER_STOP, "Stops a LocalFhenix node").setAction(
async () => {
Expand All @@ -30,6 +32,13 @@ subtask(SUBTASK_FHENIX_DOCKER_PULL, "Pulls the latest LocalFhenix image")
pullDockerContainer(image);
});

subtask(
SUBTASK_FHENIX_DOCKER_CLEAN_DEPLOYMENTS,
"Cleans existing contract deployments",
).setAction(async () => {
cleanDeployments();
});

// Main task of the plugin. It starts the server and listens for requests.
task(TASK_FHENIX_DOCKER_START, "Starts a LocalFhenix node")
.addOptionalParam(
Expand All @@ -52,19 +61,22 @@ task(TASK_FHENIX_DOCKER_START, "Starts a LocalFhenix node")
)
.addOptionalParam("image", `Fhenix image to use`, undefined, types.string)
// .addOptionalParam('log', 'Log filter level (error, warn, info, debug) - default: info', undefined, types.string)
.addOptionalParam("clean", `Clean previous deployments`, false, types.boolean)
.setAction(
async (
{
rpc,
ws,
faucet,
image,
clean,
}: // log,
{
rpc: number;
ws: number;
faucet: number;
image: string;
clean: boolean;
// log: string;
},
{ run },
Expand All @@ -86,5 +98,9 @@ task(TASK_FHENIX_DOCKER_START, "Starts a LocalFhenix node")
console.info(
chalk.green(`Started LocalFhenix successfully at 127.0.0.1:${rpc}`),
);

if (clean) {
await run(SUBTASK_FHENIX_DOCKER_CLEAN_DEPLOYMENTS);
}
},
);
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// const path = require('path');
// process.chdir(path.join(__dirname));

const hre = require("hardhat");
import hre from "hardhat";

async function runTask(taskName) {
await hre.run(taskName);
Expand Down
1 change: 1 addition & 0 deletions packages/fhenix-hardhat-docker/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function useEnvironment(fixtureProjectName: string) {
beforeEach("Loading hardhat environment", function () {
process.chdir(path.join(__dirname, "fixture-projects", fixtureProjectName));

// eslint-disable-next-line @typescript-eslint/no-require-imports
this.hre = require("hardhat");
});

Expand Down
Loading

0 comments on commit 47f3239

Please sign in to comment.