Note
You can find our alpha mvp and relevant examples here
Warning
The code is not audited yet. Please use it carefully in production.
One of our Swiss army knife toolset: redprint-forge is a developer-friendly framework/library in solidity to modify & deploy OPStack ’s contracts in a modular style.
The features include:
-
Type-safe smart contract deployment
-
Re-usable smart contract deployment and testing pipeline
-
Standardized framework, minimizing developer mistake and enhancing better security
-
All-Solidity-based so no context switching, no new scripting syntax in other languages
-
Tx Management via Safe Smart Contract Deploy Script
Together with Redprint Wizard UI
, which is a code generator/ interactive playground oriented for OPStack development, it does not only help novice developers to deploy OPStack's smart contracts to deploy on OP mainnet, but also help them to use generated deployment script in their own projects.
- Fork
optimism
's monorepo:
git clone --depth 1 --branch v1.9.4 https://github.com/ethereum-optimism/optimism.git
Note
All OPStack's contracts are based on v1.9.4
. So, you may just run:
git clone https://github.com/ethereum-optimism/optimism.git
- Enter the working ditectory:
cd optimism/packages/contracts-bedrock
- Add the
redprint-forge
using your favorite package manager, e.g., with pnpm:
pnpm init
pnpm add redprint-forge
pnpm install
- Modify OPStack 's remapping as following:
[profile.default]
# Compilation settings
src = 'src'
out = 'forge-artifacts'
script = 'scripts'
optimizer = true
optimizer_runs = 999999
remappings = [
'@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts',
'@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts',
'@openzeppelin/contracts-v5/=lib/openzeppelin-contracts-v5/contracts',
'@rari-capital/solmate/=lib/solmate',
'@lib-keccak/=lib/lib-keccak/contracts/lib',
'@solady/=lib/solady/src',
'forge-std/=lib/forge-std/src',
'ds-test/=lib/forge-std/lib/ds-test/src',
'safe-contracts/=lib/safe-contracts/contracts',
'kontrol-cheatcodes/=lib/kontrol-cheatcodes/src',
'gelato/=lib/automate/contracts'
+ '@redprint-core/=src/',
+ '@redprint-deploy/=node_modules/redprint-forge/script',
+ '@scripts/=scripts/',
+ '@redprint-test/=node_modules/redprint-forge/test/',
+ '@redprint-forge-std/=lib/forge-std/src',
+ '@redprint-openzeppelin/=lib/openzeppelin-contracts/contracts',
+ '@redprint-openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts',
+ '@redprint-safe-contracts/=lib/safe-contracts/contracts',
+ '@redprint-lib-keccak/=lib/lib-keccak/contracts/lib',
+ '@redprint-solady/=lib/solady/src',
]
...
Tip
We use @redprint-/ as a convention to avoid any naming conflicts with your previously installed libararies ( i.e. @redprint-forge-std/
vs @forge-std/
)
- Copy
.env
and modify as following.
RPC_URL_localhost=http://localhost:8545
#secret management
MNEMONIC="test test test test test test test test test test test junk"
# local network 's default private key so it is still not exposed
DEPLOYER_PRIVATE_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
DEPLOYER_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8
# script/Config.sol
DEPLOYMENT_OUTFILE=deployments/31337/.save.json
DEPLOY_CONFIG_PATH=deploy-config/hardhat.json
CHAIN_ID=
IMPL_SALT=$(openssl rand -hex 32)
STATE_DUMP_PATH=
SIG=
DEPLOY_FILE=
DRIPPIE_OWNER_PRIVATE_KEY=9000
# deploy-Config
GS_ADMIN_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8
GS_BATCHER_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8
GS_PROPOSER_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8
GS_SEQUENCER_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8
L1_RPC_URL=http://localhost:8545
- Copy a set of deploy scripts:
cp node_modules/redprint-forge/script/example/* scripts/
Now, copy a test suite:
cp node_modules/redprint-forge/test/DeployAll.t.sol test/
- Compile and run test:
This will take a while to compile:
forge b
Then run a test command against a copied set of deploy scripts:
forge test -vvvv --match-path test/DeployAll.t.sol
Note
Behind the scene, the test suite works by replicating the same environment as production script, because it utilizes the samr deployment logic script inside setUp()
as following:
/** ... */
// deployment logic
import {DeployAllScript} from "@scripts/000_DeployAll.s.sol";
contract DeployAll_Test is Test {
/** ... */
function setUp() external {
/** ... */
deployerProcedue = getDeployer();
deployerProcedue.setAutoBroadcast(false);
DeployAllScript allDeployments = new DeployAllScript();
allDeployments.run();
deployerProcedue.deactivatePrank();
}
/** ... */
}
You can write solidity script, then execute it from command-line in order to make any smart contract calls, or send transactions from your own safe multi-sig wallet.
You can access both _upgradeAndCallViaSafe
and _callViaSafe
easily by inheriting and using from in redprint-forge
module ’s parent contract SafeScript
.
Let’s see a practical example when initializing one of OPStack's proxy contract ( eg. ProtocolVersions
) by calling _upgradeAndCallViaSafe
:
/** ... */
// `redprint-forge` 's core engine
import { SafeScript} from "@redprint-deploy/safe-management/SafeScript.sol";
/** ... */
contract DeployAndInitializeProtocolVersionsScript is DeployScript, SafeScript {
/** ... */
function initializeProtocolVersions() public {
console.log("Upgrading and initializing ProtocolVersions proxy");
/** ... */
address proxyAdmin = deployer.mustGetAddress("ProxyAdmin");
address safe = deployer.mustGetAddress("SystemOwnerSafe");
/** ... */
_upgradeAndCallViaSafe({
_proxyAdmin: proxyAdmin,
_safe: safe,
_owner: owner,
_proxy: payable(protocolVersionsProxy),
_implementation: protocolVersions,
_innerCallData: abi.encodeCall(
ProtocolVersions.initialize,
(
finalSystemOwner,
ProtocolVersion.wrap(requiredProtocolVersion),
ProtocolVersion.wrap(recommendedProtocolVersion)
)
)
});
/** ... */
}
}
Note
You can the see full example here: 03B_DeployAndInitializeProtocolVersions.s.sol
Let’s see another example at SafeScript
itselfs. Our internal function just calls _callViaSafe
:
/** ... */
abstract contract SafeScript {
/** ... */
function _upgradeAndCallViaSafe( address _owner, address _proxyAdmin, address _safe, address _proxy, address _implementation, bytes memory _innerCallData) internal {
bytes memory data =
abi.encodeCall(ProxyAdmin.upgradeAndCall, (payable(_proxy), _implementation, _innerCallData));
Safe safe = Safe(payable(_safe));
_callViaSafe({ _safe: safe, _owner: _owner, _target: _proxyAdmin, _data: data });
}
/** ... */
}
We are currently still in an experimental phase leading up to a first audit and would love to hear your feedback on how we can improve Reprint
.
If you want to say thank you or/and support active development of redprint-forge:
- Add a GitHub Star to the project.
- Tweet about redprint.
- Write interesting articles about the project on Medium, or your personal blog.
- Keep Optimistic !!
This project would not have been possible to build without the advanced iniatiative from opensource software including forge-deploy, so we are deeply thankful for their contributions in our web3 ecosystem.
If we’ve overlooked anyone, please open an issue so we can correct it. While we always aim to acknowledge the inspirations and code we utilize, mistakes can happen in a team setting, and a reference might unintentionally be missed.