Skip to content

Commit

Permalink
Merge pull request #53 from Aperture-Finance/deploySlipstreamOptismAu…
Browse files Browse the repository at this point in the history
…tomanV1

deploy slipstream optimism automanV1
  • Loading branch information
tommyzhao451 authored Feb 6, 2025
2 parents 64e87ab + 63f89c5 commit 8186766
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 15 deletions.
103 changes: 103 additions & 0 deletions broadcast/DeploySlipStreamAutoman.s.sol/10/run-1729109749.json

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions broadcast/DeploySlipStreamAutoman.s.sol/10/run-latest.json

Large diffs are not rendered by default.

41 changes: 26 additions & 15 deletions script/DeploySlipStreamAutoman.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import {SlipStreamAutoman} from "../src/SlipStreamAutoman.sol";

contract DeploySlipStreamAutoman is Script {
struct DeployParams {
// Has to be alphabetically ordered per https://book.getfoundry.sh/cheatcodes/parse-json
address controller;
SlipStreamAutoman.FeeConfig feeConfig;
INPM npm;
address optimalSwapRouter; // Deploy optimal swap router if parsed as address(0).
address owner;
}

// https://github.com/pcaversaccio/create2deployer
Create2Deployer internal constant create2deployer = Create2Deployer(0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2);
bytes32 internal constant automanSalt = 0xbeef63ae5a2102506e8a352a5bb32aa8b30b31126953ca40d4c6ca0b940d0000;
// bytes32 internal constant automanSalt = 0xbeef63ae5a2102506e8a352a5bb32aa8b30b31126953ca40d4c6ca0b940d0000; // base
bytes32 internal constant automanSalt = 0xbeef63ae5a2102506e8a352a5bb32aa8b30b31127768c4952381669250020000; // optimism
bytes32 internal constant optimalSwapSalt = 0xbeef63ae5a2102506e8a352a5bb32aa8b30b3112ebdfde3902472dbfc10c0000;

// https://book.getfoundry.sh/tutorials/best-practices#scripts
Expand All @@ -43,18 +46,23 @@ contract DeploySlipStreamAutoman is Script {
console.log("Deploying automan with params: %s", json);
DeployParams memory params = abi.decode(vm.parseJson(json), (DeployParams));

// Deploy SlipStreamOptimalSwapRouter.
bytes memory initCode = bytes.concat(type(SlipStreamOptimalSwapRouter).creationCode, abi.encode(params.npm));
bytes32 initCodeHash = keccak256(initCode);
console2.log("OptimalSwapRouter initCodeHash:");
console2.logBytes32(initCodeHash);
SlipStreamOptimalSwapRouter optimalSwapRouter = SlipStreamOptimalSwapRouter(
payable(create2deployer.computeAddress(optimalSwapSalt, initCodeHash))
);
if (address(optimalSwapRouter).code.length == 0) {
// Deploy optimalSwapRouter
create2deployer.deploy(0, optimalSwapSalt, initCode);
console2.log("SlipStreamOptimalSwapRouter deployed at: %s", address(optimalSwapRouter));
// Conditionally deploy SlipStreamOptimalSwapRouter.
bytes memory initCode;
bytes32 initCodeHash;
if (params.optimalSwapRouter == address(0)) {
initCode = bytes.concat(type(SlipStreamOptimalSwapRouter).creationCode, abi.encode(params.npm));
initCodeHash = keccak256(initCode);
console2.log("OptimalSwapRouter initCodeHash:");
console2.logBytes32(initCodeHash);
SlipStreamOptimalSwapRouter optimalSwapRouter = SlipStreamOptimalSwapRouter(
payable(create2deployer.computeAddress(optimalSwapSalt, initCodeHash))
);
if (address(optimalSwapRouter).code.length == 0) {
// Deploy optimalSwapRouter
create2deployer.deploy(0, optimalSwapSalt, initCode);
console2.log("SlipStreamOptimalSwapRouter deployed at: %s", address(optimalSwapRouter));
}
params.optimalSwapRouter = address(optimalSwapRouter);
}

// Deploy SlipStreamAutoman.
Expand All @@ -73,11 +81,14 @@ contract DeploySlipStreamAutoman is Script {

// Set up automan
automan.setFeeConfig(params.feeConfig);
address[] memory controllers = new address[](1);
controllers[0] = params.controller;
bool[] memory statuses = new bool[](1);
statuses[0] = true;
address[] memory controllers = new address[](1);
controllers[0] = params.controller;
automan.setControllers(controllers, statuses);
address[] memory swapRouters = new address[](1);
swapRouters[0] = params.optimalSwapRouter;
automan.setSwapRouters(swapRouters, statuses);

// Transfer ownership to the owner
automan.transferOwnership(params.owner);
Expand Down
10 changes: 10 additions & 0 deletions script/SlipStreamAutoman_input/10/automan_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"nonfungiblePositionManager": "0x416b433906b1B72FA758e166e239c43d68dC6F29",
"owner": "0x0EDD0A75fd824Ff414247188d483fbB3E4a8e37c",
"feeConfig": {
"feeLimitPips": 500000000000000000,
"feeCollector": "0x0EDD0A75fd824Ff414247188d483fbB3E4a8e37c"
},
"controller": "0x40725D97f5352dfBf749de29ed328Ac6189e51A9",
"optimalSwapRouter": "0x920eE1aDa5C16E82BB0d7876a174407D63C8ec09"
}

0 comments on commit 8186766

Please sign in to comment.