Keep Optimistic and be Superchain dApp developer!!
[!NOTE]
You can find our relevant examples here
. Geneated contract code from the Superfuse Wizard is stored here due to documentation and testing purpose.
What Is It For
One of our Swiss army knife toolset: superfuse-forge is a developer-friendly framework/library in solidity to build a variations of cross-chain contracts in superchain Ecosystem.
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
- Save deployment schemas in json file
- Separatable into each of modular and customizable deploy scripts
- Based on All-Solidity, so no context switching, no new testing syntax
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.
Quickstart
Installation
Add the superfuse-forge
using your favorite package manager, e.g., with pnpm:
pnpm init
pnpm add superfuse-forge
pnpm install
Quick Guide
- Set your working environment with foundry :
forge init my-project
cd my-project
- Add the
superfuse-forge
using your favorite package manager, e.g., with pnpm or Yarn:
pnpm add superfuse-forge
or
yarn add -D superfuse-forge
- Configure permission and remapping (e.g. with txt" for
remappings.txt
) by modifing:
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
+solc_version = '0.8.25'
+fs_permissions = [
+ { access = 'read-write', path = './deployments/' },
+ { access = 'read', path = './configs' },
+ { access = 'read', path = './test' },
+ { access = 'write', path = './deployment.json' },
+]
+[soldeer]
+remappings_location = "txt"
Then, add remappings.txt
with following lines:
@superfuse-core/=node_modules/superfuse-forge/src
@superfuse-deploy/=node_modules/superfuse-forge/script
@superfuse-test/=node_modules/superfuse-forge/test/
@forge-std-v1.9.1/=node_modules/superfuse-forge/lib/forge-std-v1.9.1/src/
@solady-v0.0.292/=node_modules/superfuse-forge/lib/solady-v0.0.292/src/
@openzeppelin-v0.4.7.3/=node_modules/superfuse-forge/lib/openzeppelin-v0.4.7.3/contracts/
@openzeppelin-v0.5.0.2/=node_modules/superfuse-forge/lib/openzeppelin-v0.5.0.2/contracts/
[!TIP]
We use @-v/ as a convention to avoid any naming conflicts with your previously installed libararies ( i.e. @solady-0.0.292/
vs @solady/
)
[!NOTE]
You can check out dependencies'versions here
.
MNEMONIC="test test test test test test test test test test test junk"
DEPLOYER_PRIVATE_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
DEPLOYER_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8
[!NOTE]
The key or menemonic here must be secret and secure. you can configure it via our Wizard, and the default values are based on above .env
. You must choose your own secret. Otherwise, it does not mimic the production deployment environment.
- Modify
.gitignore
as following.
# ...
+node_modules/
- Copy a set of smart contract including main contracts deploy scripts and test suites
rsync -av --exclude='interfaces/' --exclude='L2/' --exclude='libraries/' node_modules/superfuse-forge/src/ src/
[!NOTE]
we, for this example, also need to reconfigue the new remapping:
# ...
+@main/=src/
+@script/=script/
@superfuse-core/=node_modules/superfuse-forge/src
@superfuse-deploy/=node_modules/superfuse-forge/script
@superfuse-test/=node_modules/superfuse-forge/test/
@forge-std-v1.9.1/=node_modules/superfuse-forge/lib/forge-std-v1.9.1/src/
@solady-v0.0.292/=node_modules/superfuse-forge/lib/solady-v0.0.292/src/
@openzeppelin-v0.4.7.3/=node_modules/superfuse-forge/lib/openzeppelin-v0.4.7.3/contracts/
@openzeppelin-v0.5.0.2/=node_modules/superfuse-forge/lib/openzeppelin-v0.5.0.2/contracts/
[!TIP]
You may choose your own remapping convention that suites your needs best!!!
For Deploy script, we now want to exclude /deployer
:
rsync -av --exclude='deployer/' node_modules/superfuse-forge/script/ script/
Now, copy a test suite:
cp node_modules/superfuse-forge/test/* test/
This will take a while to compile:
forge t
[!TIP]
Behind the scene, the test suite works by replicating the same environment as production script, because it utilizes the same deployment logic script inside setUp()
as following:
import {DeployMyERC20VotesScript} from "@script/000_DeployMyERC20VotesScript.s.sol";
contract ERC20VotesTest is Test {
function setUp() external {
deployerProcedue = getDeployer();
deployerProcedue.setAutoBroadcast(false);
console.log("Setup MyERC20Votes ... ");
DeployMyERC20VotesScript myERC20VotesDeployments = new DeployMyERC20VotesScript();
myERC20Votes = myERC20VotesDeployments.deploy();
deployerProcedue.deactivatePrank();
}
}
[!NOTE]
You can chekout this