Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare to deploy to Scroll. #40

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ forge test
The tests may take anywhere between seconds to minutes to complete depending on whether contract storage slots in scope
are cached.

In case of mysterious failures such as "failed to set up invariant testing environment", it may be caused by a Foundry issue. Try again with the following commands:

```shell
forge clean
forge build
forge test
```

## Scripting

To simulate scripts, we can pass in `--fork-url <network>` to `forge script`. The `network` can be an
Expand All @@ -85,6 +93,39 @@ To run broadcast transactions on-chain, use:
forge script DeployAutoman --rpc-url goerli --broadcast -vvvv
```

## Deployment

We use https://github.com/pcaversaccio/create2deployer to deploy contracts. If the network we want to deploy to doesn't currently have a `create2deployer` deployment then we need to first contact the owner to deploy that.

First, dry-run the deployment script on a local fork to get the `initCodeHash` of `UniV3Automan` contract:

```shell
forge script DeployAutoman --fork-url [NETWORK_NAME] -vvvv
```

The output of the above command should contain text like "Automan initCodeHash: 0xbafd4e1d1ff7f7979102d9e80884c2a93d0e1160dae77b5f88e9bca95eb5e4d0".

Second, use the initCodeHash obtained above to mine a vanity address using the following commands:

```shell
git clone https://github.com/0age/create2crunch
cd create2crunch
export FACTORY="0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2"
export CALLER="[DEPLOYER_ADDRESS_GOES_HERE]"
export INIT_CODE_HASH="[INIT_CODE_HASH_GOES_HERE]"
cargo run --release $FACTORY $CALLER $INIT_CODE_HASH
```

You should see rows like
```
0xbeef63ae5a2102506e8a352a5bb32aa8b30b3112f9d02aa0154b2000061fb0dd => 0x00006C2eEC8d3AC8720D65e400fe0079C32eee5A => 2
0xbeef63ae5a2102506e8a352a5bb32aa8b30b3112f9d02aa0154b6000064122f4 => 0x0000000054D52974711c14aB458780886579167F => 256
```
being generated. The bytes starting with "0xbeef" are salts, and the corresponding contract addresses are shown to their right. When a desired address has been mined, stop the create2crunch script and update `script/DeployAutoman.s.sol` with the mined salt.

Re-simulate `DeployAutoman` with a dry-run to verify that the deployment address matches expectation, and broadcast the transaction on-chain.


## Verification

Generate the standard JSON input and verify the contract on Etherscan with it:
Expand Down
151 changes: 151 additions & 0 deletions broadcast/DeployAutoman.s.sol/534352/run-1702490130.json

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions broadcast/DeployAutoman.s.sol/534352/run-1702490236.json

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions broadcast/DeployAutoman.s.sol/534352/run-1702490315.json

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions broadcast/DeployAutoman.s.sol/534352/run-1702490327.json

Large diffs are not rendered by default.

153 changes: 153 additions & 0 deletions broadcast/DeployAutoman.s.sol/534352/run-1702490426.json

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions broadcast/DeployAutoman.s.sol/534352/run-1702492421.json

Large diffs are not rendered by default.

95 changes: 95 additions & 0 deletions broadcast/DeployAutoman.s.sol/534352/run-1702492427.json

Large diffs are not rendered by default.

95 changes: 95 additions & 0 deletions broadcast/DeployAutoman.s.sol/534352/run-latest.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ mainnet = "${MAINNET_RPC_URL}"
goerli = "${GOERLI_RPC_URL}"
arbitrum_one = "${ARBITRUM_RPC_URL}"
optimism = "${OPTIMISM_RPC_URL}"
scroll = "https://rpc.scroll.io"

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
20 changes: 12 additions & 8 deletions script/DeployAutoman.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ contract DeployAutoman is Script {

// https://github.com/pcaversaccio/create2deployer
Create2Deployer internal constant create2deployer = Create2Deployer(0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2);
bytes32 internal constant automanSalt = 0x264c8f7bbe39c408da3dce71a4cf46c474f3f85ef17016b46b1ed382578a3ce2;
bytes32 internal constant optimalSwapSalt = 0x25d61a346cb02fb86b96a0c62b1c222e04024550d908af19ba43cc43f767df7a;
bytes32 internal constant routerProxySalt = 0x862e41240a461e611c6c023e3cf74c29b2ab80b8e2b2539de1b8b1f096922723;
bytes32 internal constant automanSalt = 0xbeef63ae5a2102506e8a352a5bb32aa8b30b3112f9d02aa0154b400009e78fae;
bytes32 internal constant optimalSwapSalt = 0xbeef63ae5a2102506e8a352a5bb32aa8b30b31127dfc30de0987800003da9a65;
bytes32 internal constant routerProxySalt = 0xbeef63ae5a2102506e8a352a5bb32aa8b30b3112bc2281f12f80c0000280f6fd;

// https://book.getfoundry.sh/tutorials/best-practices#scripts
function readInput(string memory input) internal view returns (string memory) {
Expand Down Expand Up @@ -49,7 +49,7 @@ contract DeployAutoman is Script {
// Concatenate init code with encoded arguments
bytes memory initCode = bytes.concat(type(UniV3Automan).creationCode, encodedArguments);
bytes32 initCodeHash = keccak256(initCode);
console2.log("Automan initCodeHash:");
console2.log("UniV3Automan initCodeHash:");
console2.logBytes32(initCodeHash);
// Compute the address of the contract to be deployed
UniV3Automan automan = UniV3Automan(payable(create2deployer.computeAddress(automanSalt, initCodeHash)));
Expand All @@ -76,17 +76,21 @@ contract DeployAutoman is Script {
);
}

RouterProxy routerProxy = RouterProxy(
create2deployer.computeAddress(routerProxySalt, keccak256(type(RouterProxy).creationCode))
);
initCode = type(RouterProxy).creationCode;
initCodeHash = keccak256(initCode);
console2.log("RouterProxy initCodeHash:");
console2.logBytes32(initCodeHash);
RouterProxy routerProxy = RouterProxy(create2deployer.computeAddress(routerProxySalt, initCodeHash));
if (address(routerProxy).code.length == 0) {
// Deploy routerProxy
create2deployer.deploy(0, routerProxySalt, type(RouterProxy).creationCode);
create2deployer.deploy(0, routerProxySalt, initCode);
console2.log("RouterProxy deployed at: %s", address(routerProxy));
}

initCode = bytes.concat(type(OptimalSwapRouter).creationCode, abi.encode(params.npm));
initCodeHash = keccak256(initCode);
console2.log("OptimalSwapRouter initCodeHash:");
console2.logBytes32(initCodeHash);
OptimalSwapRouter optimalSwapRouter = OptimalSwapRouter(
payable(create2deployer.computeAddress(optimalSwapSalt, initCodeHash))
);
Expand Down
9 changes: 9 additions & 0 deletions script/input/534352/automan_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"nonfungiblePositionManager": "0xB39002E4033b162fAc607fc3471E205FA2aE5967",
"owner": "0xaF327bb0AF7c282FD75ee72651f4E78D4349d517",
"feeConfig": {
"feeLimitPips": 200000000000000000,
"feeCollector": "0xaF327bb0AF7c282FD75ee72651f4E78D4349d517"
},
"controller": "0x01aB1be3518F490c9F0b97447FBb1c335EFbE600"
}