Skip to content

Commit

Permalink
Merge pull request #1 from vechainfoundation/create-plugin-packages
Browse files Browse the repository at this point in the history
Create plugin packages
  • Loading branch information
andreas-papageorgiou authored Mar 20, 2023
2 parents 3c357d6 + 724d4d1 commit 6936680
Show file tree
Hide file tree
Showing 30 changed files with 4,956 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist

yarn-error.log
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@vechainfoundation:registry=https://npm.pkg.github.com
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
# hardhat-plugins
# Installation
Packages are currently published in GitHub's registry.
To obtain access you need to
- [authenticate](#authentication) and
- add the following to your project's `.npmrc` file:
```
@vechainfoundation:registry=https://npm.pkg.github.com
```
> *Note: See [Installing a package](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#installing-a-package)*
## Authentication
To obtain access to the registry you need to:
- [Create a personal GitHub access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) and
- Either:
- use `npm login`:
```
$ npm login --scope=@vechainfoundation --auth-type=legacy --registry=https://npm.pkg.github.com
> Username: USERNAME
> Password: TOKEN
```
- or add the following line with your credentials in your project's `.npmrc`:
```
//npm.pkg.github.com/:_authToken=TOKEN
```
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "root",
"version": "0.0.0",
"author": "Electi Consulting LTD",
"license": "See individual packages",
"private": true,
"workspaces": [
"packages/*"
],
"scripts": {
"build": "tsc --build packages/vechain packages/ethers packages/web3"
},
"devDependencies": {
"typescript": "^4.9.5",
"hardhat": "^2.12.7",
"ethers": "^5.7.2",
"web3": "^1.0.0-beta.36",
"mocha": "^10.2.0",
"@types/mocha": "^10.0.1",
"@vechainfoundation/hardhat-vechain": "0.0.1",
"@vechainfoundation/hardhat-ethers": "0.0.1",
"@vechainfoundation/hardhat-web3": "0.0.1"
},
"peerDependencies": {
"hardhat": "^2.12.7"
}
}
21 changes: 21 additions & 0 deletions packages/ethers/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Nomic Labs LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
37 changes: 37 additions & 0 deletions packages/ethers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# hardhat-vechain
A package extending Hardhat Ethers to use a Connex provider.

# Usage
- Modify `hardhat.config.js` to require `@vechainfoundation/hardhat-vechain` and `@vechainfoundation/hardhat-ethers`.
- Configure `networks` to include a `vechain` configuration
> *Note: A solo Thor instance should be running for the below configurations to work*
## Sample `hardhat.config.js`
```js
const {
VECHAIN_URL_SOLO
} = require("@vechainfoundation/hardhat-vechain");
require("@vechainfoundation/hardhat-ethers");

module.exports = {
solidity: {
version: "0.8.17",
},
networks: {
vechain: {
url: VECHAIN_URL_SOLO
},
}
};
```

## Testing
- Use Hardhat Ethers as usual
```js
describe("vechain-ethers", function() {
it("should be able to get signers", async function () {
const accounts = await ethers.getSigners();
assert.equals(accounts[0], "0xf077b491b355e64048ce21e3a6fc4751eeea77fa");
});
});
```
30 changes: 30 additions & 0 deletions packages/ethers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@vechain/hardhat-ethers",
"version": "0.0.1",
"license": "MIT",
"description": "Hardhat Vechain Ethers Plugin",
"repository": "github:vechainfoundation/hardhat-plugins",
"author": "Electi Consulting LTD",
"main": "dist/index.js",
"scripts": {
"build": "tsc --build"
},
"files": [
"dist",
"LICENSE",
"README.md"
],
"devDependencies": {
"ethers": "^5.0.0",
"hardhat": "^2.12.7",
"@nomiclabs/hardhat-ethers": "^2.2.2",
"@vechainfoundation/hardhat-vechain": "^0.0.1"
},
"peerDependencies": {
"ethers": "^5.0.0",
"hardhat": "^2.12.7",
"@nomiclabs/hardhat-ethers": "^2.2.2",
"@vechainfoundation/hardhat-vechain": "^0.0.1"
}
}

83 changes: 83 additions & 0 deletions packages/ethers/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { extendEnvironment } from "hardhat/config";
import { lazyObject } from "hardhat/plugins";
import type EthersT from "ethers";

import { VechainHardhatPluginError } from "@vechainfoundation/hardhat-vechain/dist/error";
import "./type-extensions";

import {
getContractAt,
getContractAtFromArtifact,
getContractFactory,
getContractFactoryFromArtifact,
getImpersonatedSigner,
getSigner,
getSigners,
} from "@nomiclabs/hardhat-ethers/internal/helpers";
import { createUpdatableTargetProxy } from "@nomiclabs/hardhat-ethers/internal/updatable-target-proxy";
import { modifyFactory, modifyProvider } from "@vechain/web3-providers-connex/dist/ethers";
import { EthersProviderWrapper } from "@nomiclabs/hardhat-ethers/internal/ethers-provider-wrapper";
import { FactoryOptions, HardhatRuntimeEnvironment } from "hardhat/types";

const registerCustomInspection = (BigNumber: any) => {
const inspectCustomSymbol = Symbol.for("nodejs.util.inspect.custom");

BigNumber.prototype[inspectCustomSymbol] = function () {
return `BigNumber { value: "${this.toString()}" }`;
};
};

extendEnvironment(hre => {
if (hre.vechain === undefined) {
if (hre.network.name === "vechain") {
throw new VechainHardhatPluginError("Ethers plugin requires hardhat-vechain");
} else {
return;
}
}
hre.ethers = lazyObject(() => {
const { ethers } = require("ethers") as typeof EthersT;
registerCustomInspection(ethers.BigNumber);

const provider = hre.vechain!;
const jsonRpcProvider = modifyProvider(new EthersProviderWrapper(provider as any));
const { proxy } = createUpdatableTargetProxy(jsonRpcProvider);

return {
...ethers,

provider: proxy,

getSigner: (address: string) => getSigner(hre, address),
getSigners: () => getSigners(hre),
getContractAtFromArtifact: getContractAtFromArtifact.bind(null, hre),
getContractAt: getContractAt.bind(null, hre),
getImpersonatedSigner: (address: string) =>
getImpersonatedSigner(hre, address),
getContractFactory: ((...args: any[]) => {
const bound = getContractFactory.bind(null, hre) as any;
return bound(...args).then(modifyFactory);
}) as any,
getContractFactoryFromArtifact: ((...args: any[]) => {
const bound = getContractFactoryFromArtifact.bind(null, hre) as any;
return bound(...args).then(modifyFactory);
}) as any,
deployContract: (async (
hre: HardhatRuntimeEnvironment,
name: string,
argsOrSignerOrOptions?: any[] | EthersT.Signer | FactoryOptions,
signerOrOptions?: EthersT.Signer | FactoryOptions
) => {
let args = [];
if (Array.isArray(argsOrSignerOrOptions)) {
args = argsOrSignerOrOptions;
} else {
signerOrOptions = argsOrSignerOrOptions;
}
const bound = getContractFactory.bind(null, hre) as any;
const factory = await bound(name, signerOrOptions).then(modifyFactory);
return factory.deploy(...args);
}).bind(null, hre) as any
};
});
});
2 changes: 2 additions & 0 deletions packages/ethers/src/type-extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "@vechainfoundation/hardhat-vechain/dist/type-extensions";
import "@nomiclabs/hardhat-ethers/internal/type-extensions";
7 changes: 7 additions & 0 deletions packages/ethers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
},
}
21 changes: 21 additions & 0 deletions packages/vechain/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Nomic Labs LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
37 changes: 37 additions & 0 deletions packages/vechain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# hardhat-vechain
A package extending the Hardhat environment with a `vechain` field.
The field contains a Hardhat `EthereumProvider` enabling requests via Connex.

# Usage
- Modify `hardhat.config.js` to include `require("@vechainfoundation/hardhat-vechain")`
- Configure `networks` to include a `vechain` configuration
> *Note: A solo Thor instance should be running for the below configurations to work*
## Sample `hardhat.config.js`
```js
const {
VECHAIN_URL_SOLO
} = require("@vechainfoundation/hardhat-vechain");

module.exports = {
solidity: {
version: "0.8.17",
},
networks: {
vechain: {
url: VECHAIN_URL_SOLO
},
}
};
```

## Testing
- Access the provider using the globally available `vechain`
```js
describe("vechain", function() {
it("should be able to send requests", async function () {
const accounts = await vechain.request(method: "eth_accounts");
assert.equals(accounts[0], "0xf077b491b355e64048ce21e3a6fc4751eeea77fa");
});
});
```
30 changes: 30 additions & 0 deletions packages/vechain/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@vechain/hardhat-vechain",
"version": "0.0.1",
"description": "Hardhat plugin for a VeChain provider",
"homepage": "https://github.com/vechainfoundation/hardhat-plugins",
"repository": "github:vechainfoundation/hardhat-plugins",
"author": "Electi Consulting LTD",
"main": "dist/index.js",
"files": [
"dist",
"LICENSE",
"README.md"
],
"scripts": {
"build": "tsc --build"
},
"dependencies": {
"ethers": "^5.7.2",
"thor-devkit": "^2.0.6",
"@vechain/connex-driver": "^2.0.12",
"@vechain/connex-framework": "^2.0.12",
"@vechain/web3-providers-connex": "^1.0.0"
},
"devDependencies": {
"hardhat": "^2.12.7"
},
"peerDependencies": {
"hardhat": "^2.12.7"
}
}
Loading

0 comments on commit 6936680

Please sign in to comment.