Skip to content

Add default foundry#4

Merged
anxolin merged 1 commit into
mainfrom
default-foundry
Feb 18, 2026
Merged

Add default foundry#4
anxolin merged 1 commit into
mainfrom
default-foundry

Conversation

@anxolin
Copy link
Copy Markdown
Contributor

@anxolin anxolin commented Jan 21, 2026

Description

Boilerplate for a foundry project

Context

In order to have the discussions on our default configs, scripts, etc, I want to create a PR with the default foundry config, so every PR on top are the changes we want to apply to it.

This was created by running the following command in the main branch. With the excepttion of the README, which I deleted a bit of info:

# Force, cause the project is not empty
forge init --force

Out of scope

The goal of this PR is not to define the struture and confif yet, is just to commit the output of forge init --force as it is, so we can iterate and discuss the overrides of the default foundy.

Testing Instructions

Execute the following commands and ensure they are successful.

forge build
forge test
forge fmt
forge snapshot

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reccomend here we actually use a configuration file similar to what we have got with Euler, as the one provided by default with foundry has some deficiencies imo

https://github.com/cowprotocol/euler-integration-contracts/blob/master/.github/workflows/test.yml

I will also comment on specific points to track

Comment on lines +25 to +26
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should lock the foundry version. Its an extremely common thing that foundry just updates and things break. We will need to remember to update the template project from time to time unforutnately though

      - name: Install Foundry
        uses: foundry-rs/foundry-toolchain@v1
        with:
          version: v1.5.1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to do that in an interation PR. This PR aims to not change anything :)

Added a out of scope section to be more explicit on this.

run: forge fmt --check

- name: Run Forge build
run: forge build --sizes
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for best code quality, we should deny compiler notes.

      - name: Run Forge build
        run: |
          forge build --deny notes --sizes

workflow_dispatch:

env:
FOUNDRY_PROFILE: ci
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fork tests are really common, so would be nice to have this secret built in:

Also, if we can define org level secrets for all our RPCs we might want to use like $RPC_URL_1 (for mainnet, for example) that would be swell


env:
  FOUNDRY_PROFILE: ci
  FORK_RPC_URL: ${{ secrets.RPC_URL_1 }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the template should account for forked tests, but I wouldn't do it like this otherwise any random GitHub Action has access to this secret. I personally like to keep e2e tests separate from actual test in the workflow as well, but for simplicity we can just add the secret to name: Run Forge tests.

Comment thread .gitmodules
@@ -0,0 +1,3 @@
[submodule "lib/forge-std"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may consider replacing the gitmodules with NPM modules. In which case, submodules aren't necessary

This makes a lot of sense because cannon and extra linters we might use comes via a npm module also

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't really like submodules.
Well, I also don't like using package.json because we have nothing to do with JS and adding this file means we're pretending we are a JS module, and this has weird consequences sometimes.

As a concrete example, an issue I (somewhat) remember in the past is about the frontend having problems importing and updating the code from a contract repo once we introduced a package.json. This is because that files needs to (1) contain all expected parameters, like version and (2) the version parameter needs to be bumped each time anything meaningful change. If I remember correctly, not bumping the version when the code changed lead to the frontend ignoring any changes and didn't see the new updates until we realized about this issue. This hadn't been a problem before package.json was introduced, apparently previous imports would just rely on the commit hash for changes, but that was ignored after introducing that file.

I don't have an obvious best choice here, I'm fine with the code as it is at this point. Later if we think it's better, we can make this into a NPM package. I think we may want to eventually do that because a few linting tools (like solhint) are still best imported through NPM, but maybe we can try to hide this from NPM, possibly storing this file in dev/package.json or something like this.

Comment thread script/Counter.s.sol
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably remove this file. Most of the time we only use scripts for on-chain deployments, and thats pending/out of this PR scope.

Comment thread src/Counter.sol
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably tighten the required solidity version here to 0.8.30 or so

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion would be to just use:

Suggested change
pragma solidity ^0.8.13;
pragma solidity ^0.8;

I know it's sometimes recommended to be tight in the versioning, but I never found the arguments convincing. I think it's fine to be permissive here while strict in foundry.toml.
My argument for being permissive is that sometimes I need to import relatively new contracts into an old repo; specifying a strict version means that the old project wouldn't compile and still keep deterministic deployments. This could happen, for example, if we want to add a test on an old repo that includes the new contract: we'd have to bump the Solidity version of everything, and so possibly redeploy, just to make tests work.

Copy link
Copy Markdown

@kaze-cow kaze-cow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically it seems all changes from the foundry template are out of scope. so awaiting follow up PR to resolve my comments instead.

@anxolin
Copy link
Copy Markdown
Contributor Author

anxolin commented Jan 23, 2026

basically it seems all changes from the foundry template are out of scope. so awaiting follow up PR to resolve my comments instead.

Yes, all comments are relevant and should be properly iterated in follow ups. I think makes it more clear the changes we apply on the default (otherwise, people can't tell what code in this PR came from the default and what is mine)

I will add it to #2

Comment thread foundry.lock
Comment thread foundry.toml
@anxolin
Copy link
Copy Markdown
Contributor Author

anxolin commented Feb 18, 2026

@fedgiac I will add those in a follow up PR to not mix with the default foundry stuff

@anxolin anxolin merged commit f2a10e2 into main Feb 18, 2026
4 checks passed
anxolin added a commit that referenced this pull request Apr 14, 2026
## Description
Follow up on #4 with a coment from @fedgiac I didn't want to mix in the
"default foundry" setup (I'd like to have a PR with just foundry as it
is, and then we can do small PRs to add bits and pieces)


#4 (comment)

## Testing Instructions

1. Open Counter.t.sol

Invert the order of the imports, so they look like
```solidity
import {Test} from "forge-std/Test.sol";
import {Counter} from "../src/Counter.sol";
```

2. Run `forge fmt`
It should invert again the imports leaving as they were

```solidity
import {Counter} from "../src/Counter.sol";
import {Test} from "forge-std/Test.sol";
```

If you use vscode and you have a solidity plugin (like me), chances are
that the IDE formats it on save already, so no even need to do step 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants