Skip to content

Commit

Permalink
Add local mainnet fork project
Browse files Browse the repository at this point in the history
I expect that this will be used a lot in the future,
so it made sense to add this tool into the project.
  • Loading branch information
Gergo Nagy committed Mar 6, 2022
1 parent 3e09551 commit 3e3415d
Show file tree
Hide file tree
Showing 10 changed files with 34,890 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ module.exports = {
},
],
},
ignorePatterns: ["dist/", "extension-reload.js", "**/validate/*.js"],
ignorePatterns: [
"dist/",
"extension-reload.js",
"**/validate/*.js",
"**/local-chain/**",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./.tsconfig-eslint.json",
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ Before committing code to this repository or a fork/branch that you intend to
submit for inclusion, please make sure you've installed the pre-commit hooks
by running `pre-commit install`. The macOS setup script does this for you.

#### Local mainnet fork setup for development

For more detailed description see `./dev-utils/local-chain/README.md`

Quick Start:

```
$ cd dev-utils/local-chain
$ yarn install
$ yarn start
```

### Commit signing

Commits on the Tally repository are all required to be signed.
Expand Down
47 changes: 47 additions & 0 deletions dev-utils/local-chain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Local chain for development

This is a sample hardhat project that has been modified to run a local fork of the mainnet.
The extension can interact with this chain and contracts can be deployed to it.
The chain loses it's state on restart.

The important configuration is in `hardhat.config.js`.

- `chainId: 1337`: At the moment we know that this works but chainId 1 does not. (03/06/2022)
- With `chainId: 1` if there is almost any wallet communication — at the moment — the fork becomes unresponsive quickly.
The time it takes is not deterministric. Had it working for hours but usually it breaks after a couple of seconds.
- `mining.auto: false;` and `mining.interval: 5000` is set so it's easy to see if the chain becomes unresponsive.

## Setup

> This project is intentionally not part of the yarn workspace, because it's not part of the application,
> but a simple a tool for development. Because of this, it needs to be setup as a separate node project.
```
$ cd dev-utils/local-chain
$ yarn install
$ yarn start
```

## API key for alchemy

There is a separate application for this, and that api key is used in the config.

## Original README

(Basic Sample Hardhat Project)

https://hardhat.org/getting-started/

This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts.

Try running some of the following tasks:

```shell
npx hardhat accounts
npx hardhat compile
npx hardhat clean
npx hardhat test
npx hardhat node
node scripts/sample-script.js
npx hardhat help
```
22 changes: 22 additions & 0 deletions dev-utils/local-chain/contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

import "hardhat/console.sol";

contract Greeter {
string private greeting;

constructor(string memory _greeting) {
console.log("Deploying a Greeter with greeting:", _greeting);
greeting = _greeting;
}

function greet() public view returns (string memory) {
return greeting;
}

function setGreeting(string memory _greeting) public {
console.log("Changing greeting from '%s' to '%s'", greeting, _greeting);
greeting = _greeting;
}
}
40 changes: 40 additions & 0 deletions dev-utils/local-chain/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require("@nomiclabs/hardhat-waffle")

// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners()

for (const account of accounts) {
console.log(account.address)
}
})

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more

/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: "0.8.4",
networks: {
hardhat: {
loggingEnabled: true,
chainId: 1337,
forking: {
enabled: true,
url: "https://eth-mainnet.alchemyapi.io/v2/AwMJLURd9d9VYP_Q2tG7gr52tSP_wBiA",
},
allowUnlimitedContractSize: true,
timeout: 5000,
mining: {
auto: false,
interval: 5000,
mempool: {
order: "fifo",
},
},
},
},
}
Loading

0 comments on commit 3e3415d

Please sign in to comment.