Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add foundry support #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "packages/contracts/lib/forge-std"]
path = packages/contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
3 changes: 0 additions & 3 deletions packages/contracts/.eslintrc.js

This file was deleted.

90 changes: 0 additions & 90 deletions packages/contracts/.eslintrc.json

This file was deleted.

13 changes: 11 additions & 2 deletions packages/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# Hardhat
build/
# Foundry
cache/
out/
.env
broadcast/

# JS
node_modules/

#yarn
*.log
14 changes: 14 additions & 0 deletions packages/contracts/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "solhint:recommended",
"rules": {
"code-complexity": ["error", 8],
"compiler-version": ["error", ">=0.8.0 <0.8.20"],
"func-name-mixedcase": "off",
"func-visibility": ["error", { "ignoreConstructors": true }],
"max-line-length": ["error", 120],
"named-parameters-mapping": "warn",
"no-console": "off",
"not-rely-on-time": "off",
"one-contract-per-file": "off"
}
}
20 changes: 20 additions & 0 deletions packages/contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Byor Contracts

## Usage
```bash
# Install
$ cd packages/contracts && forge install

# Build
$ yarn build

# Test
$ yarn test

# Deploy to anvil
# open new terminal window
$ anvil
# update your .env file with a private key given to you by Anvil
$ source .env
$ yarn deploy:localhost
```
6 changes: 6 additions & 0 deletions packages/contracts/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[profile.default]
src = "src"
out = "out"
libs = ["node_modules", "lib"]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
17 changes: 0 additions & 17 deletions packages/contracts/hardhat.config.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/contracts/lib/forge-std
Submodule forge-std added at f73c73
37 changes: 9 additions & 28 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,18 @@
"version": "0.1.0",
"private": true,
"scripts": {
"deploy": "hardhat run scripts/deploy.ts",
"test": "hardhat test",
"compile": "hardhat compile",
"clean": "rm -rf build",
"deploy": "forge script script/deploy.s.sol:DeployScript --broadcast",
"deploy:localhost": "yarn deploy --fork-url http://localhost:8545 --private-keys $PRIVATE_KEY",
"test": "forge test",
"compile": "forge build",
"clean": "rm -rf cache out",
"format:fix": "prettier --write .",
"format": "prettier --check .",
"lint:fix": "yarn lint --fix",
"lint": "eslint --ext .ts,.tsx --max-warnings 0 test scripts",
"typecheck": "tsc --noEmit"
"lint": "forge fmt --check && solhint {script,src,test}/**/*.sol",
"typecheck": "forge build"
},
"devDependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.6",
"@nomicfoundation/hardhat-network-helpers": "^1.0.8",
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@typechain/ethers-v5": "^10.2.1",
"@typechain/hardhat": "^6.1.6",
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"@types/node": "^20.1.2",
"chai": "^4.3.7",
"ethers": "^5.0.0",
"hardhat-gas-reporter": "^1.0.9",
"solidity-coverage": "^0.8.2",
"ts-node": "^10.9.1",
"typechain": "^8.1.1"
},
"dependencies": {
"hardhat": "^2.14.0"
"prettier": "^3.1.0",
"solhint": "^4.0.0"
}
}
2 changes: 2 additions & 0 deletions packages/contracts/remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
12 changes: 12 additions & 0 deletions packages/contracts/script/deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script} from "forge-std/Script.sol";
import {Inputs} from "../src/Inputs.sol";

contract DeployScript is Script {
function run() public returns (Inputs inputs) {
vm.broadcast();
inputs = new Inputs();
}
}
68 changes: 0 additions & 68 deletions packages/contracts/scripts/deploy.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/contracts/src/Caller.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import './Inputs.sol';
import {Inputs} from "./Inputs.sol";

// Only used for testing
contract Caller {
Inputs inputs;
Inputs internal inputs;

constructor(address inputsContract) {
inputs = Inputs(inputsContract);
Expand Down
35 changes: 35 additions & 0 deletions packages/contracts/test/Inputs.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test} from "forge-std/Test.sol";
import {Inputs} from "../src/Inputs.sol";
import {Caller} from "../src/Caller.sol";

contract InputsTest is Test {
bytes private constant RANDOM_BYTES = "0x12345678907654321234567890987654321234567890987654";
address private constant BOB = address(0xb0b);
Inputs private inputs;
Caller private caller;

event BatchAppended(address sender);

function setUp() public {
inputs = new Inputs();
caller = new Caller(address(inputs));
}

function testEventBatchAppended() public {
// should emit BatchAppended event.
// expect address `bob` to be emitted.
vm.prank(BOB, BOB);
vm.expectEmit();
emit BatchAppended(BOB);
inputs.appendBatch(RANDOM_BYTES);
}

function testRevertCaller() public {
// should revert if called from a contract
vm.expectRevert();
caller.appendBatch(RANDOM_BYTES);
}
}
33 changes: 0 additions & 33 deletions packages/contracts/test/Inputs.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/contracts/tsconfig.json

This file was deleted.