Skip to content

Commit

Permalink
Revamp tooling (#83)
Browse files Browse the repository at this point in the history
* build: move deps to node_modules

* build: bump solidity version

* chore: update foundry.toml

* docs: update README.md
  • Loading branch information
madlabman authored Mar 1, 2024
1 parent c1f356d commit 20793d7
Show file tree
Hide file tree
Showing 80 changed files with 208 additions and 127 deletions.
79 changes: 64 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,98 @@ jobs:
actions:
uses: lidofinance/linters/.github/workflows/actions.yml@master

# Maybe to make it reusable workflow instead?
bootstrap:
name: Bootstrap environment
runs-on: ubuntu-latest
outputs:
cache-path: ${{ steps.cache.outputs.path }}
cache-key: ${{ steps.cache.outputs.key }}
env:
FORGE_REV: d58ab7f
JUST_TAG: 1.24.0
steps:
- name: Build cache params
id: cache
run: |
echo "path=$CACHE_PATH" >> "$GITHUB_OUTPUT"
echo "$KEY_INPUT" | md5sum | awk '{print $1}' | xargs -I% echo "key=cargobin-%-${RUNNER_OS}" >> "$GITHUB_OUTPUT"
env:
CACHE_PATH: |
~/.cargo/bin/
KEY_INPUT: |
forge:${FORGE_REV}
just:${JUST_TAG}
- uses: actions/cache@v3
id: get-cache
with:
path: ${{ steps.cache.outputs.path }}
key: ${{ steps.cache.outputs.key }}

- name: Install just
run: cargo install "just@$JUST_TAG"
if: steps.get-cache.outputs.cache-hit != 'true'

- name: Install forge
run: cargo install --git https://github.com/foundry-rs/foundry --rev "$FORGE_REV" --profile local forge
if: steps.get-cache.outputs.cache-hit != 'true'

linters:
name: Linters
runs-on: ubuntu-latest
needs: bootstrap
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
persist-credentials: false

- uses: actions/cache@v3
with:
path: ${{ needs.bootstrap.outputs.cache-path }}
key: ${{ needs.bootstrap.outputs.cache-key }}

- name: Install node
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
cache: yarn
cache-dependency-path: "**/yarn.lock"

- name: Install Node dependencies
run: yarn install --immutable
- name: Install dependencies
run: just deps

- name: Linters check
run: yarn lint:check
run: just lint

foundry:
name: Foundry project
runs-on: ubuntu-latest
needs: bootstrap
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
persist-credentials: false

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- uses: actions/cache@v3
with:
version: nightly
path: ${{ needs.bootstrap.outputs.cache-path }}
key: ${{ needs.bootstrap.outputs.cache-key }}

- name: Run Forge build
run: |
forge --version
forge build --sizes
- name: Install node
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
cache: yarn
cache-dependency-path: "**/yarn.lock"

- name: Run Forge tests
run: |
forge test -vvv
- name: Install dependencies
run: just deps

- name: Build
run: just build --sizes

- name: Run tests
run: just test
env:
RPC_URL: ${{ secrets.RPC_URL }}
9 changes: 0 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts-v4.4"]
path = lib/openzeppelin-contracts-v4.4
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "solhint:recommended",
"plugins": ["lido-csm"],
"rules": {
"compiler-version": ["error", "0.8.21"],
"compiler-version": ["error", "0.8.24"],
"no-inline-assembly": "off",
"no-unused-import": "error",
"func-named-parameters": "error",
Expand Down
17 changes: 10 additions & 7 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,27 @@ deploy_script_path := if chain == "mainnet" {
anvil_host := env_var_or_default("ANVIL_IP_ADDR", "127.0.0.1")
anvil_port := "8545"

default: clean build test-all
default: clean deps build test-all

build:
forge build --force
build *args:
forge build --force {{args}}

clean:
forge clean
rm -rf cache broadcast out
rm -rf cache broadcast out node_modules

deps:
yarn install --immutable

lint-solhint:
yarn lint:solhint

lint-check:
yarn lint:check

lint-fix:
yarn lint:fix

lint:
yarn lint:check

test-all:
just test-unit &
just test-integration
Expand Down
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

- Install [Foundry tools](https://book.getfoundry.sh/getting-started/installation)

- Install [Just](https://github.com/casey/just)

- Install project dependencies

```bash
forge install
just deps
```

- Config environment variables
Expand All @@ -21,35 +23,44 @@ cp .env.sample .env

Fill vars in the `.env` file with your own values

- Build and test contracts

```bash
just
```

### Features

- Run tests

```bash
make test # run all tests
make test-unit
make test-inegration
just test # run all tests
# or run specific tests
just test-unit
just test-inegration
```

- Install libraries
- Install dependencies

Dependencies are managed using yarn. To install new dependencies, run:

```bash
forge install rari-capital/solmate
yarn add <package-name>
```

- Deploy to local fork

```bash
make deploy-local
just deploy-local
```

- Deploy to local fork of non-mainnet chain

```bash
CHAIN=holesky make deploy-local
CHAIN=holesky just deploy-local
```

### Notes

Whenever you install new libraries using Foundry, make sure to update your
`remappings.txt` file by running `forge remappings > remappings.txt`
Whenever you install new libraries using yarn, make sure to update your
`remappings.txt`.
28 changes: 18 additions & 10 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
[profile.default]
solc = "0.8.24"
evm_version = "cancun"
optimizer = true
optimizer_runs = 1_000
bytecode_hash = "none" # The metadata hash removed from the bytecode (not the metadata itself).

src = "src"
out = "out"
libs = ["lib"]
libs = ["lib", "node_modules"]
cache_path = "cache"
optimizer = true
optimizer_runs = 1_000
evm_version = "shanghai"

block_gas_limit = 30_000_000
fs_permissions = [{ access = "write", path = "./out" }, { access = "read", path = "./test/fixtures" }]
fuzz = { runs = 256 }

fs_permissions = [
{ access = "write", path = "./out" },
{ access = "read", path = "./test/fixtures" }
]

[fmt]
line_length = 80
tab_width = 4
bracket_spacing = true
[profile.ci]
verbosity = 3
fuzz = { runs = 10_000 }

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
# See more config options https://github.com/foundry-rs/foundry/tree/master/crates/config
1 change: 0 additions & 1 deletion lib/forge-std
Submodule forge-std deleted from 3725a2
1 change: 0 additions & 1 deletion lib/openzeppelin-contracts
Submodule openzeppelin-contracts deleted from 01ef44
1 change: 0 additions & 1 deletion lib/openzeppelin-contracts-v4.4
Submodule openzeppelin-contracts-v4.4 deleted from 6bd6b7
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"postinstall": "husky install"
},
"devDependencies": {
"@openzeppelin/contracts": "5.0.1",
"@openzeppelin/contracts-v4.4": "npm:@openzeppelin/[email protected]",
"ds-test": "https://github.com/dapphub/ds-test",
"forge-std": "https://github.com/foundry-rs/forge-std.git#v1.7.6",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"prettier": "^3.0.3",
Expand Down
8 changes: 4 additions & 4 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@openzeppelin/contracts=lib/openzeppelin-contracts/contracts/
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
@openzeppelin/contracts-v4.4=lib/openzeppelin-contracts-v4.4/contracts/
@openzeppelin/contracts-v4.4/=node_modules/@openzeppelin/contracts-v4.4/
@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/
forge-std/=node_modules/forge-std/src/
ds-test/=node_modules/ds-test/src/
2 changes: 1 addition & 1 deletion script/DeployBase.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Lido <[email protected]>
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.21;
pragma solidity 0.8.24;

import "forge-std/Script.sol";

Expand Down
2 changes: 1 addition & 1 deletion script/DeployGoerli.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Lido <[email protected]>
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.21;
pragma solidity 0.8.24;

import { DeployBase } from "./DeployBase.s.sol";

Expand Down
2 changes: 1 addition & 1 deletion script/DeployHolesky.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Lido <[email protected]>
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.21;
pragma solidity 0.8.24;

import { DeployBase } from "./DeployBase.s.sol";

Expand Down
2 changes: 1 addition & 1 deletion script/DeployMainnetish.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Lido <[email protected]>
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.21;
pragma solidity 0.8.24;

import { DeployBase } from "./DeployBase.s.sol";

Expand Down
2 changes: 1 addition & 1 deletion script/utils/Json.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Lido <[email protected]>
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.21;
pragma solidity 0.8.24;

import { Vm } from "forge-std/Vm.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/CSAccounting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0

// solhint-disable-next-line one-contract-per-file
pragma solidity 0.8.21;
pragma solidity 0.8.24;

import { PausableUntil } from "base-oracle/utils/PausableUntil.sol";
import { AccessControlEnumerable } from "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/CSBondCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0

// solhint-disable-next-line one-contract-per-file
pragma solidity 0.8.21;
pragma solidity 0.8.24;

import { ILidoLocator } from "./interfaces/ILidoLocator.sol";
import { ILido } from "./interfaces/ILido.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/CSBondCurve.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0

// solhint-disable-next-line one-contract-per-file
pragma solidity 0.8.21;
pragma solidity 0.8.24;

abstract contract CSBondCurveBase {
event BondCurveAdded(uint256[] bondCurve);
Expand Down
2 changes: 1 addition & 1 deletion src/CSBondLock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0

// solhint-disable-next-line one-contract-per-file
pragma solidity 0.8.21;
pragma solidity 0.8.24;

abstract contract CSBondLockBase {
event BondLockChanged(
Expand Down
2 changes: 1 addition & 1 deletion src/CSFeeDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0

// solhint-disable-next-line one-contract-per-file
pragma solidity 0.8.21;
pragma solidity 0.8.24;

import { MerkleProof } from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/CSFeeOracle.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Lido <[email protected]>
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.21;
pragma solidity 0.8.24;

import { PausableUntil } from "base-oracle/utils/PausableUntil.sol";
import { BaseOracle } from "base-oracle/oracle/BaseOracle.sol";
Expand Down
Loading

0 comments on commit 20793d7

Please sign in to comment.