Skip to content

Commit

Permalink
feat: add forge fmt to ci (#363)
Browse files Browse the repository at this point in the history
* feat: ci forge fmt

* chore: forge fmt
  • Loading branch information
0xClandestine authored Jan 22, 2025
1 parent 3654478 commit d2bfd57
Show file tree
Hide file tree
Showing 101 changed files with 6,534 additions and 4,489 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/forge-fmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Forge Fmt

on:
workflow_dispatch:
push:
branches:
- master
- mainnet
- testnet-goerli
- dev
pull_request:

jobs:
check:
name: CI
strategy:
fail-fast: true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Run forge fmt
run: |
forge fmt --check
id: fmt
138 changes: 108 additions & 30 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,111 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
fs_permissions = [{ access = "read-write", path = "./" }]
gas_limit = 5000000000

ffi = true
no-match-contract = "FFI"

# Enables or disables the optimizer
optimizer = true
# Sets the number of optimizer runs
optimizer_runs = 200
# Whether or not to use the Yul intermediate representation compilation pipeline
via_ir = false
# Override the Solidity version (this overrides `auto_detect_solc`)
solc_version = '0.8.27'
# Project Configuration

# Path to contract sources relative to the root of the project.
src = "src"
# Path to the test contract sources relative to the root of the project.
test = "test"
# Path to the script contract sources relative to the root of the project.
script = "script"
# Path to store contract artifacts relative to the root of the project.
out = "out"
# Array of paths that contain libraries, relative to the root of the project.
libs = ["lib"]

# Solidity Compiler Configuration

# Defines paths for Solidity imports.
remappings = [
"@openzeppelin/=lib/openzeppelin-contracts-v4.9.0/",
"@openzeppelin-upgrades/=lib/openzeppelin-contracts-upgradeable-v4.9.0/",
"ds-test/=lib/ds-test/src/",
"forge-std/=lib/forge-std/src/"
]
# Specifies the exact version of Solidity to use, overriding auto-detection.
solc_version = '0.8.27'
# If enabled, treats Solidity compiler warnings as errors, preventing artifact generation if warnings are present.
deny_warnings = false
# If set to true, changes compilation pipeline to go through the new IR optimizer.
via_ir = false
# Whether or not to enable the Solidity optimizer.
optimizer = true
# The number of runs specifies roughly how often each opcode of the deployed code will be executed
# across the life-time of the contract. This means it is a trade-off parameter between code size (deploy cost)
# and code execution cost (cost after deployment).
optimizer_runs = 200

# Test Configuration

# Verbosity level during test execution. Higher levels provide more detailed information:
# - 2 (-vv): Logs emitted during tests are displayed.
# - 3 (-vvv): Stack traces for failing tests are displayed.
# - 4 (-vvvv): Stack traces for all tests and setup traces for failing tests are displayed.
# - 5 (-vvvvv): Stack and setup traces are always displayed.
verbosity = 0
# Enables the Foreign Function Interface (FFI) cheatcode.
# WARNING: This allows arbitrary programs to run on your computer, which poses security risks.
ffi = true
# Contracts to include in gas reports. By default, all contracts are included.
gas_reports = ["./src/**/*"]
# Show test execution progress if set to true.
show_progress = true
# Sparse mode only compiles files that match certain criteria.
sparse_mode = true

gas_limit = 5000000000
no-match-contract = "FFI"
fs_permissions = [{ access = "read-write", path = "./" }]

[profile.default.fmt]
# Single-line vs multi-line statement blocks
single_line_statement_blocks = "preserve" # Options: "single", "multi", "preserve"
# Formatting style for long function headers
multiline_func_header = "params_first" # Options: "attributes_first", "params_first", "all"
# Sort import statements alphabetically
sort_imports = false
# Maximum line length where formatter will wrap the line
line_length = 100 # Default: 120
# Number of spaces per indentation level
tab_width = 4 # Default: 4
# Whether to print spaces between brackets
bracket_spacing = false
# Style of uint/int256 types
int_types = "long" # Options: "long", "short", "preserve"
# Quotation mark style
quote_style = "double" # Options: "double", "single", "preserve"
# Style of underscores in number literals
number_underscore = "thousands" # Options: "preserve", "thousands", "remove"
# Whether or not to wrap comments at line_length
wrap_comments = false
# List of files to ignore during formatting (can use glob patterns)
# ignore = [
# "./script/**/*",
# "./test/**/*"
# ]

# TODO: Decide if we want to enable this.
# [profile.test.fmt]
# int_types = "short"
# line_length = 140
# ignore = [
# "./src/**/*"
# ]

[profile.ci.fuzz]
optimizer = false
runs = 32

[profile.intense.fuzz]
optimizer = false
runs = 15000

[profile.forktest.fuzz]
runs = 16

[rpc_endpoints]
mainnet = "${RPC_MAINNET}"
holesky = "${RPC_HOLESKY}"

[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY}" }
holesky = { key = "${ETHERSCAN_API_KEY}" }

[fmt]
bracket_spacing = false
int_types = "long"
line_length = 100
multiline_func_header = "params_first"
number_underscore = "thousands"
quote_style = "double"
tab_width = 4

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
mainnet = { key = "${ETHERSCAN_API_KEY}" }
holesky = { key = "${ETHERSCAN_API_KEY}" }
16 changes: 10 additions & 6 deletions script/utils/OperatorSetUpgradeLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
pragma solidity ^0.8.0;
// Deploy L2AVS proxy

import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {TransparentUpgradeableProxy} from
"@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";

import {Vm} from "forge-std/Vm.sol";
Expand All @@ -27,8 +28,7 @@ library OperatorSetUpgradeLib {
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
*/
bytes32 internal constant ADMIN_SLOT =
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

function upgrade(address proxy, address implementation, bytes memory data) internal {
ProxyAdmin admin = ProxyAdmin(getAdmin(proxy));
Expand All @@ -40,13 +40,17 @@ library OperatorSetUpgradeLib {
admin.upgrade(TransparentUpgradeableProxy(payable(proxy)), implementation);
}

function getAdmin(address proxy) internal view returns (address) {
function getAdmin(
address proxy
) internal view returns (address) {
bytes32 value = vm.load(proxy, ADMIN_SLOT);
return address(uint160(uint256(value)));
}

function getImplementation(address proxy) internal view returns (address) {
function getImplementation(
address proxy
) internal view returns (address) {
bytes32 value = vm.load(proxy, IMPLEMENTATION_SLOT);
return address(uint160(uint256(value)));
}
}
}
Loading

0 comments on commit d2bfd57

Please sign in to comment.