Skip to content

Conversation

0xrusowsky
Copy link
Contributor

@0xrusowsky 0xrusowsky commented Aug 21, 2025

This PR is a follow-up of the ongoing effort to improve multichain scripting workflows:

refs:

Motivation

Currently, storing deployment addresses and params in a easy to reuse and automate manner is cumbersome and requires dealing with ffi and json/toml cheatcodes (having to manipulate entire files)

This PR build on the previously introduces readFork cheatcodes to help ease the deployment process even further.

Solution

This PR introduces writeFork cheatcodes that enable tests and scripts to persist deployment
addresses and configuration data to a dedicated TOML file, separate from foundry.toml. This provides a safe, controlled way to maintain deployment state across test runs without risking corruption of the main configuration file.

New Cheatcodes:

Check Operations:

  • checkForkVar(string key): check if a key exists for the active fork
  • checkForkChainVar(uint256 chain, string key): check if a key exists for a specific chain

Write Operation:

only possible when scripting, update memory and disk, return (bool success, bool overwritte)

  • writeForkVar(string key, <type> value): write to active fork configuration
  • writeForkChainVar(uint256 chain, string key, <type> value): write to specific chain configuration

Dedicated config file:

  • fork configurations are now stored in a separate TOML file (i.e. deployments.toml) specified via [forks].path in foundry.toml
  • this file cannot be foundry.toml nor the inheritance file informed in extends
  • similar to ffi, users decide whether to give write access to foundry (defaults to read-only)
  # foundry.toml
  [forks]
  path = "deployments.toml"  # Path to dedicated fork config file
  access = "read-write"      # Optional tonable write access (defaults to "read")
  # deployments.toml
  [mainnet]
  rpc_endpoint = "..."

  [mainnet.vars]
  weth = "0x..."
  deployed_contract = "0x..."

@0xrusowsky 0xrusowsky changed the title wip(cheats): writeFork to persist deployments feat(cheats): writeFork to persist deployment info Aug 22, 2025
@0xrusowsky 0xrusowsky changed the title feat(cheats): writeFork to persist deployment info feat(cheats): writeFork to persist scripting info Aug 22, 2025
@0xrusowsky 0xrusowsky marked this pull request as ready for review August 22, 2025 12:46
@0xrusowsky 0xrusowsky marked this pull request as draft August 22, 2025 17:36
@0xrusowsky 0xrusowsky changed the title feat(cheats): writeFork to persist scripting info feat(cheats)!: remove readFork cheatcodes Aug 22, 2025
@0xrusowsky 0xrusowsky closed this Aug 22, 2025
@github-project-automation github-project-automation bot moved this to Done in Foundry Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants