Home

Awesome

foundry-devops

A repo to get the most recent deployment from a given environment in foundry. This way, you can do scripting off previous deployments in solidity.

It will look through your broadcast folder at your most recent deployment.

Features

Getting Started

Requirements

Installation

forge install Cyfrin/foundry-devops --no-commit
git rm -rf lib/forge-std
 rm -rf lib/forge-std
 forge install foundry-rs/forge-std@v1.8.2 --no-commit

Usage - Getting the most recent deployment

  1. Update your foundry.toml to have read permissions on the broadcast folder.
fs_permissions = [
    { access = "read", path = "./broadcast" },
    { access = "read", path = "./reports" },
]
  1. Import the package, and call DevOpsTools.get_most_recent_deployment("MyContract", chainid);

ie:

import {DevOpsTools} from "lib/foundry-devops/src/DevOpsTools.sol";
import {MyContract} from "my-contract/MyContract.sol";
.
.
.
function interactWithPreviouslyDeployedContracts() public {
    address contractAddress = DevOpsTools.get_most_recent_deployment("MyContract", block.chainid);
    MyContract myContract = MyContract(contractAddress);
    myContract.doSomething();
}

Usage - zkSync Checker

Prerequisites

The installer for Foundry-zksync.

Update or revert to a specific Foundry-zksync version with ease.
.
.
.

Usage - ZkSyncChainChecker

In your contract, you can import and inherit the abstract contract ZkSyncChainChecker to check if you are on a zkSync based chain. And add the skipZkSync modifier to any function you want to skip if you are on a zkSync based chain.

It will check both the precompiles or the chainid to determine if you are on a zkSync based chain.

import {ZkSyncChainChecker} from "lib/foundry-devops/src/ZkSyncChainChecker.sol";

contract MyContract is ZkSyncChainChecker {

  function doStuff() skipZkSync {

ZkSyncChainChecker modifiers:

ZkSyncChainChecker Functions:

Usage - FoundryZkSyncChecker

In your contract, you can import and inherit the abstract contract FoundryZkSyncChecker to check if you are on the foundry-zksync fork of foundry.

!Important: Functions and modifiers in FoundryZkSyncChecker are only available if you run foundry-zksync with the --zksync flag.

import {FoundryZkSyncChecker} from "lib/foundry-devops/src/FoundryZkSyncChecker.sol";

contract MyContract is FoundryZkSyncChecker {

  function doStuff() onlyFoundryZkSync {

You must also add ffi = true to your foundry.toml to use this feature.

FoundryZkSync modifiers:

FoundryZkSync Functions:

Testing

For testing on vanilla foundry, run:

make test

For testing with foundry-zksync, run:

make test-zksync

Limitations

Contributing

PRs are welcome!

git clone https://github.com/Cyfrin/foundry-devops
cd foundry-devops
make