Skip to content

Commit

Permalink
chore: add deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Dec 4, 2023
1 parent 0d03e85 commit 6a894cd
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 192 deletions.
16 changes: 5 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
export API_KEY_ALCHEMY="YOUR_API_KEY_ALCHEMY"
export API_KEY_ARBISCAN="YOUR_API_KEY_ARBISCAN"
export API_KEY_BSCSCAN="YOUR_API_KEY_BSCSCAN"
export API_KEY_ETHERSCAN="YOUR_API_KEY_ETHERSCAN"
export API_KEY_GNOSISSCAN="YOUR_API_KEY_GNOSISSCAN"
export API_KEY_INFURA="YOUR_API_KEY_INFURA"
export API_KEY_OPTIMISTIC_ETHERSCAN="YOUR_API_KEY_OPTIMISTIC_ETHERSCAN"
export API_KEY_POLYGONSCAN="YOUR_API_KEY_POLYGONSCAN"
export API_KEY_SNOWTRACE="YOUR_API_KEY_SNOWTRACE"
export MNEMONIC="YOUR_MNEMONIC"
export FOUNDRY_PROFILE="default"
export PRIVATE_KEY="0x"
export POLYGONSCAN_ZKEVM_TESTNET_API_KEY=""
export SEPOLIA_ETHERSCAN_API_KEY=""
export SEPOLIA_RPC_URL=""
export POLYGON_ZKEVM_TESTNET_RPC_URL=""
170 changes: 22 additions & 148 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Foundry Template [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] [![License: MIT][license-badge]][license]
# rln-contract [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] [![License: MIT][license-badge]][license]

[gha]: https://github.com/vacp2p/foundry-template/actions
[gha-badge]: https://github.com/vacp2p/foundry-template/actions/workflows/ci.yml/badge.svg
Expand All @@ -7,195 +7,69 @@
[license]: https://opensource.org/licenses/MIT
[license-badge]: https://img.shields.io/badge/License-MIT-blue.svg

A Foundry-based template for developing Solidity smart contracts, with sensible defaults.
A Foundry-based project for Rate Limiting Nullifiers.

This is a fork of [PaulRBerg's template](https://github.com/PaulRBerg/foundry-template) and adjusted to Vac's smart
contracts unit's needs. See [Upstream differences](#upstream-differences) to learn more about how this template differs
from Paul's.

## What's Inside

- [Forge](https://github.com/foundry-rs/foundry/blob/master/forge): compile, test, fuzz, format, and deploy smart
contracts
- [Forge Std](https://github.com/foundry-rs/forge-std): collection of helpful contracts and cheatcodes for testing
- [Solhint Community](https://github.com/solhint-community/solhint-community): linter for Solidity code

## Getting Started

Click the [`Use this template`](https://github.com/vacp2p/foundry-template/generate) button at the top of the page to
create a new repository with this repo as the initial state.

Or, if you prefer to install the template manually:

```sh
$ mkdir my-project
$ cd my-project
$ forge init --template vacp2p/foundry-template
$ pnpm install # install Solhint, Prettier, and other Node.js deps
pnpm install # install Solhint, Prettier, and other Node.js deps
forge install # install Foundry's dependencies
```

If this is your first time with Foundry, check out the
[installation](https://github.com/foundry-rs/foundry#installation) instructions.

## Features

This template builds upon the frameworks and libraries mentioned above, so for details about their specific features,
please consult their respective documentation.

For example, if you're interested in exploring Foundry in more detail, you should look at the
[Foundry Book](https://book.getfoundry.sh/). In particular, you may be interested in reading the
[Writing Tests](https://book.getfoundry.sh/forge/writing-tests.html) tutorial.

### Upstream differences

As mentioned above, this template is a fork with adjustments specific to the needs of Vac's smart contract service unit.
These differences are:

- **Removal of [PRBTest](https://github.com/PaulRBerg/prb-test)** - In an attempt to keep dependence on third-party code
low, we've decided to remove this library as a standard dependency of every project within Vac. If we do see a need
for it, we might bring it back in the future.
- **PROPERTIES.md** - For invariant testing and formal verification, we've introduced a `PROPERTIES.md` to document all
protocol properties that must hold true.

### Sensible Defaults

This template comes with a set of sensible default configurations for you to use. These defaults can be found in the
following files:

```text
├── .editorconfig
├── .gitignore
├── .prettierignore
├── .prettierrc.yml
├── .solhint.json
├── foundry.toml
├── remappings.txt
└── slither.config.json
```

### VSCode Integration

This template is IDE agnostic, but for the best user experience, you may want to use it in VSCode alongside Nomic
Foundation's [Solidity extension](https://marketplace.visualstudio.com/items?itemName=NomicFoundation.hardhat-solidity).
## Usage

For guidance on how to integrate a Foundry project in VSCode, please refer to this
[guide](https://book.getfoundry.sh/config/vscode).

### GitHub Actions

This template comes with GitHub Actions pre-configured. Your contracts will be linted and tested on every push and pull
request made to the `main` branch.

You can edit the CI script in [.github/workflows/ci.yml](./.github/workflows/ci.yml).

## Writing Tests

If you would like to view the logs in the terminal output you can add the `-vvv` flag and use
[console.log](https://book.getfoundry.sh/faq?highlight=console.log#how-do-i-use-consolelog).

This template comes with an example test contract [Foo.t.sol](./test/Foo.t.sol)

## Usage

This is a list of the most frequently needed commands.

### Build

Build the contracts:
### Compilation

```sh
$ forge build
```

### Clean

Delete the build artifacts and cache directories:
forge build

```sh
$ forge clean
```

### Compile

Compile the contracts:

```sh
$ forge build
```

### Coverage

Get a test coverage report:

```sh
$ forge coverage
```

### Deploy

Deploy to Anvil:
### Format

```sh
$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545
forge fmt
```

For this script to work, you need to have a `MNEMONIC` environment variable set to a valid
[BIP39 mnemonic](https://iancoleman.io/bip39/).

For instructions on how to deploy to a testnet or mainnet, check out the
[Solidity Scripting](https://book.getfoundry.sh/tutorials/solidity-scripting.html) tutorial.

### Format
### Clean

Format the contracts:
Deletes the build artifacts and cache directories:

```sh
$ forge fmt
forge clean
```

### Gas Usage

Get a gas report:

```sh
$ forge test --gas-report
forge test --gas-report
```

### Lint
### Test

Lint the contracts:
Run the tests:

```sh
$ pnpm lint
forge test
```

#### Fixing linting issues

For any errors in solidity files, run `forge fmt`. For errors in any other file type, run `pnpm prettier:write`.
### Deployment

### Test

Run the tests:
Ensure you setup the .env file with the correct values mentioned in the .env.example file.

```sh
$ forge test
./script/deploy.sh rln
```

## Notes

1. Foundry uses [git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to manage dependencies. For
detailed instructions on working with dependencies, please refer to the
[guide](https://book.getfoundry.sh/projects/dependencies.html) in the book
2. You don't have to create a `.env` file, but filling in the environment variables may be useful when debugging and
testing against a fork.

## Related Efforts

- [abigger87/femplate](https://github.com/abigger87/femplate)
- [cleanunicorn/ethereum-smartcontract-template](https://github.com/cleanunicorn/ethereum-smartcontract-template)
- [foundry-rs/forge-template](https://github.com/foundry-rs/forge-template)
- [FrankieIsLost/forge-template](https://github.com/FrankieIsLost/forge-template)
This will deploy the RLN contract, with its associated libraries to the specified network.
If forge supports the network, it will also verify the contract on the block explorer.

## License

This project is licensed under MIT.
This project is dual licensed under MIT and APACHE-2.0.
32 changes: 16 additions & 16 deletions deployments/11155111/latest.json

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions deployments/1442/latest.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
verbosity = 4

[etherscan]
sepolia = { key = "${API_KEY_ETHERSCAN}" }
sepolia = { key = "${SEPOLIA_ETHERSCAN_API_KEY}" }
polygon-zkevm-testnet = { key = "${POLYGONSCAN_ZKEVM_TESTNET_API_KEY}" }

[fmt]
bracket_spacing = true
Expand All @@ -36,4 +37,5 @@

[rpc_endpoints]
localhost = "http://localhost:8545"
sepolia = "https://eth-sepolia.g.alchemy.com/v2/${SEPOLIA_API_KEY}"
sepolia = "${SEPOLIA_RPC_URL}"
polygon-zkevm-testnet = "${POLYGON_ZKEVM_TESTNET_RPC_URL}"
8 changes: 7 additions & 1 deletion script/DeploymentConfig.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ contract DeploymentConfig is Script {
deployer = _broadcaster;
if (block.chainid == 31_337) {
activeNetworkConfig = getOrCreateAnvilEthConfig();
} else if (block.chainid == 11155111) {
} else if (block.chainid == 11_155_111) {
activeNetworkConfig = getOrCreateSepoliaEthConfig();
} else if (block.chainid == 1442) {
activeNetworkConfig = getOrCreatePolygonZkevmConfig();
} else {
revert DeploymentConfig_NoConfigForChain(block.chainid);
}
Expand All @@ -36,6 +38,10 @@ contract DeploymentConfig is Script {
return NetworkConfig({ deployer: deployer });
}

function getOrCreatePolygonZkevmConfig() public view returns (NetworkConfig memory) {
return NetworkConfig({ deployer: deployer });
}

// This function is a hack to have it excluded by `forge coverage` until
// https://github.com/foundry-rs/foundry/issues/2988 is fixed.
// See: https://github.com/foundry-rs/foundry/issues/2988#issuecomment-1437784542
Expand Down
Loading

0 comments on commit 6a894cd

Please sign in to comment.