Skip to content

Commit

Permalink
chore(contract): Update README and dependencies (#473)
Browse files Browse the repository at this point in the history
Reorganize dependencies by moving development-related packages to
`devDependencies`. Enhance the README for better readability with
structured formatting and shell command snippets, and add a
`.prettierignore` file to exclude certain directories from Prettier
formatting.

Introduced a new `.solhint.json` configuration file and updated key
dependencies in `package.json`. Improved code formatting rules in
`.prettierrc.js` and unified style for conditional deployer address
assignment in deployment scripts. Fixed a linting command issue in
`makefile`.
  • Loading branch information
shuhuiluo authored Jul 29, 2024
1 parent f1139c1 commit 054d95b
Show file tree
Hide file tree
Showing 8 changed files with 406 additions and 106 deletions.
9 changes: 4 additions & 5 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"extends": "solhint:recommended",
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"code-complexity": ["error", 9],
"code-complexity": ["warn", 9],
"compiler-version": ["error", "^0.8.0"],
"const-name-snakecase": "off",
"constructor-syntax": "error",
"func-visibility": ["error", { "ignoreConstructors": true }],
"max-line-length": ["error", 170],
"max-line-length": ["warn", 170],
"not-rely-on-time": "off",
"reason-string": ["warn", { "maxLength": 64 }],
"var-name-mixedcase": "off",
Expand All @@ -20,6 +18,7 @@
"func-name-mixedcase": "off",
"max-states-count": "off",
"func-named-parameters": "off",
"no-unused-import": "off"
"no-unused-import": "off",
"quotes": "off"
}
}
92 changes: 65 additions & 27 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,86 @@

<h3>Requirements</h3>

Install [yarn](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable)\
`npm install --global yarn`
Install [yarn](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable)

Download [Foundry](https://github.com/foundry-rs/foundry)\
`curl -L https://foundry.paradigm.xyz | bash`
```shell
npm install --global yarn
```

Then after reloading PATH, to install it run:\
`./scripts/foundry-up.sh`
Download [Foundry](https://github.com/foundry-rs/foundry)

If you see a warning about libusb, install it by running:\
`brew install libusb`
```shell
curl -L https://foundry.paradigm.xyz | bash
```

Then after reloading PATH, to install it run:

```shell
./scripts/foundry-up.sh
```

If you see a warning about libusb, install it by running:

```shell
brew install libusb
```

<h3>Project setup</h3>

Clone the repo\
Run `yarn`
Clone the repo, then:

```shell
yarn
```

<b>To compile the smart contracts located in `./contracts`:</b>

```shell
forge build
```

Compiled contracts will be output to the `./out` folder

<b>To run the solidity unit tests:</b>

```shell
forge test
```

You can add verbosity to the tests by adding `-vvvv` (1-4 levels) to the command

<b>To start a local ethereum blockchain:</b>

<b>To compile the smart contracts located in `/contracts`:</b>\
Run `forge build`\
Compiled contracts will be output to the `/artifacts` folder
```shell
anvil
```

<b>To run the solidity unit tests:</b>\
Run `forge test`\
You can add verbosity to the tests by adding `-vvvv` (1-4 levels) to the command
It will generate a set of 10 public/private keys with 10k ether each. Save one of these private keys for deployment
below.\
It starts listening on `http://127.0.0.1:8545`\
If you want to interact with anvil via a front end, you will need to add the local network to Metamask
with `ChainID=1337`

<b>To start a local ethereum blockchain:</b>\
Run `anvil`\
It will generate a set of 10 public/private keys with 10k ether each. Save one of these private keys for deployment below.\
It starts listening on `http://127.0.0.1:8545`\
If you want to interact with anvil via a front end, you will need to add the local network to Metamask with `ChainID=1337`
<b>To start a local base blockchain and river blockchain run</b>

<b>To start a local base blockchain and river blockchain run</b>\
`./scripts/bc-all-start.sh`
```shell
./scripts/bc-all-start.sh
```

<b>To deploy our contracts to your local base and river instances</b>

1. duplicate `.env.localhost` file in the [contracts](/contracts/) folder of the project and rename it to `.env` (this is excluded from git via .gitignore)
1. duplicate `.env.localhost` file in the [contracts](.) folder of the project and rename it to `.env` (this is excluded
from git via .gitignore)
2. run `export RIVER_ENV="local_single"` from your terminal
3. you will then run `./scripts/deploy-contracts.sh` to deploy the entire suite of contracts to your local base-anvil and river-anvil chains.
3. you will then run `./scripts/deploy-contracts.sh` to deploy the entire suite of contracts to your local base-anvil
and river-anvil chains.

<b>To deploy a single diamond base contract to your local anvil instance</b>\
from within the `contracts/` folder you can run `make deploy-base-anvil contract=Deploy[Contract]` you will replace the `[Contract]` part with the contract you want to deploy, you can see all the contracts available for deployment in [this](/contracts/scripts/deployments) part of the project.
from within the `contracts/` folder you can run `make deploy-base-anvil contract=Deploy[Contract]` you will replace
the `[Contract]` part with the contract you want to deploy, you can see all the contracts available for deployment
in [this](./scripts/deployments) part of the project.

<b>To deploy a facet base contract to your local anvil instance</b>\
from within the `contracts/` folder you can run `make deploy-base-anvil contract=Deploy[Facet] type=facet` you will replace the `[Facet]` part with the contract you want to deploy, you can see all the facets available for deployment in [this](/contracts/scripts/deployments/facets) part of the project.
from within the `contracts/` folder you can run `make deploy-base-anvil contract=Deploy[Facet] type=facet` you will
replace the `[Facet]` part with the contract you want to deploy, you can see all the facets available for deployment
in [this](./scripts/deployments/facets) part of the project.
2 changes: 1 addition & 1 deletion contracts/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ snapshot :; forge snapshot

format :; yarn prettier --write .

lint :; yarn solhint "{scripts,src,test/**/*.sol}"
lint :; yarn solhint "{scripts,src,test}/**/*.sol"

anvil :; anvil -m 'test test test test test test test test test test test junk'

Expand Down
15 changes: 7 additions & 8 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@
"dependencies": {
"@openzeppelin/contracts": "^5.0.2",
"@openzeppelin/contracts-upgradeable": "^5.0.2",
"@prb/math": "^4.0.2",
"@prb/test": "^0.6.4",
"@prb/math": "^4.0.3",
"account-abstraction": "github:eth-infinitism/account-abstraction",
"base64": "github:Brechtpd/base64",
"ds-test": "github:dapphub/ds-test",
"forge-std": "github:foundry-rs/forge-std#v1"
"base64": "github:Brechtpd/base64"
},
"devDependencies": {
"@prb/test": "^0.6.4",
"ds-test": "github:dapphub/ds-test",
"forge-std": "github:foundry-rs/forge-std#v1",
"prettier": "^2.8.8",
"prettier-plugin-solidity": "^1.1.3",
"solhint": "^3.4.1",
"solhint-plugin-prettier": "^0.0.5"
"prettier-plugin-solidity": "^1.3.1",
"solhint": "^5.0.2"
}
}
8 changes: 5 additions & 3 deletions contracts/scripts/common/Deployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ abstract contract Deployer is Script, DeployBase {
: vm.envUint("TESTNET_PRIVATE_KEY");

address potential = vm.addr(pk);
address deployer = isAnvil() ? potential : msg.sender != potential
? msg.sender
: potential;
address deployer = isAnvil()
? potential
: msg.sender != potential
? msg.sender
: potential;

if (!isTesting()) {
info(
Expand Down
8 changes: 5 additions & 3 deletions contracts/scripts/common/Interaction.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ abstract contract Interaction is Script, DeployBase {
: vm.envUint("TESTNET_PRIVATE_KEY");

address potential = vm.addr(pk);
address deployer = isAnvil() ? potential : msg.sender != potential
? msg.sender
: potential;
address deployer = isAnvil()
? potential
: msg.sender != potential
? msg.sender
: potential;

info(
string.concat(
Expand Down
1 change: 1 addition & 0 deletions packages/prettier-config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module.exports = {
arrowParens: 'always',
endOfLine: 'lf',
plugins: ['prettier-plugin-solidity'],
printWidth: 80,
semi: true,
singleQuote: false,
Expand Down
Loading

0 comments on commit 054d95b

Please sign in to comment.