Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielZlotin committed Jan 14, 2025
1 parent 40f1714 commit 99d5965
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 155 deletions.
1 change: 0 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ solc = "0.8.19"
src = "src"
out = "out"
libs = ["lib"]
ffi = true
fs_permissions = [
{ access = "read-write", path = ".forge-snapshots/"},
{ access = "read", path = "script/input/"}
Expand Down
38 changes: 38 additions & 0 deletions script/00_DeployAdmin.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.x;

import "forge-std/Script.sol";

import {BaseScript, Admin} from "script/base/BaseScript.sol";

contract DeployAdmin is BaseScript {
//address fee00 = _admin(owner, weth, 0x55669ad6a3db66a4a3bbfe640c9faa64095a75a5228cf52464f4a449257ee6c5);
//address fee01 = _admin(owner, weth, 0xab1462bd378a47c5676f45ed8b1f1de08ddf212e2525b6c82e7c2c11c41590d2);
//address fee02 = _admin(owner, weth, 0x668fa19c8dfec98130ebcc64b727ecf11105987af78936a05550a1f6679b16cc);
//address fee03 = _admin(owner, weth, 0x7622f2bb307bda72700fbabe78b8f2bc76c8d4f214e47ca34aa96b4e980947ce);

function run() public returns (address admin) {
address owner = vm.envAddress("OWNER");
address weth = vm.envAddress("WETH");

bytes32 initCodeHash = hashInitCode(type(Admin).creationCode, abi.encode(owner));
console.logBytes32(initCodeHash);

bytes32 salt = bytes32(uint256(0x9563));

admin = computeCreate2Address(salt, initCodeHash);

if (admin.code.length == 0) {
vm.broadcast();
Admin deployed = new Admin{salt: salt}(owner);
require(admin == address(deployed), "admin mismatched address");

vm.broadcast();
deployed.init(weth);
} else {
require(address(Admin(payable(admin)).weth()) != address(0), "not initialized");
require(Admin(payable(admin)).owner() == owner, "admin mismatched owner");
console.log("admin already deployed");
}
}
}
46 changes: 46 additions & 0 deletions script/01_UpdateWhitelist.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.x;

import "forge-std/Script.sol";

import {BaseScript, Admin} from "script/base/BaseScript.sol";

contract UpdateWhitelist is BaseScript {
uint256 public constant BATCH_SIZE = 300;

function run() public {
Admin admin = Admin(payable(vm.envAddress("ADMIN")));

if (address(admin).code.length == 0) {
console.log("admin not deployed");
return;
}

address[] memory list = abi.decode(
vm.parseJson(vm.readFile(string.concat(vm.projectRoot(), "/script/input/", "whitelist.json"))), (address[])
);

if (admin.allowed(list[0]) && admin.allowed(list[list.length - 1])) {
console.log("whitelist already updated");
return;
}

for (uint256 i = 0; i < list.length; i += BATCH_SIZE) {
uint256 size = i + BATCH_SIZE < list.length ? BATCH_SIZE : list.length - i;

address[] memory batch = new address[](size);
for (uint256 j = 0; j < size; j++) {
batch[j] = list[i + j];
}

vm.broadcast();
admin.allow(batch, true);

console.log("whitelist updated, batch", i);
}

require(admin.allowed(admin.owner()), "owner not allowed?");
require(admin.allowed(list[0]), "first not allowed?");
require(admin.allowed(list[list.length - 1]), "last not allowed?");
}
}
32 changes: 32 additions & 0 deletions script/02_DeployReactor.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.x;

import "forge-std/Script.sol";

import {BaseScript, Admin, Consts} from "script/base/BaseScript.sol";

import {ExclusiveDutchOrderReactor, IPermit2} from "uniswapx/src/reactors/ExclusiveDutchOrderReactor.sol";

contract DeployReactor is BaseScript {
//reactor = _reactor(bytes32(uint256(0)));
//reactor2 = _reactor(bytes32(uint256(1)));

function run() public returns (address reactor) {
bytes32 salt = vm.envOr("SALT", bytes32(0));

bytes32 initCodeHash =
hashInitCode(type(ExclusiveDutchOrderReactor).creationCode, abi.encode(Consts.PERMIT2_ADDRESS, address(0)));
console.logBytes32(initCodeHash);

reactor = computeCreate2Address(salt, initCodeHash);

if (reactor.code.length == 0) {
vm.broadcast();
ExclusiveDutchOrderReactor deployed =
new ExclusiveDutchOrderReactor{salt: salt}(IPermit2(Consts.PERMIT2_ADDRESS), address(0));
require(reactor == address(deployed), "reactor mismatched address");
} else {
console.log("reactor already deployed");
}
}
}
26 changes: 26 additions & 0 deletions script/03_DeployExecutor.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.x;

import "forge-std/Script.sol";

import {BaseScript, Admin, Consts} from "script/base/BaseScript.sol";
import {LiquidityHub, IReactor, IAllowed} from "src/LiquidityHub.sol";

contract DeployExecutor is BaseScript {
//executorPCSX = _executor(0x35db01D1425685789dCc9228d47C7A5C049388d8, 0x000066320a467dE62B1548f46465abBB82662331);

function run() public returns (address executor) {
address reactor = vm.envAddress("REACTOR");
address admin = vm.envAddress("ADMIN");

executor = computeCreate2Address(0, hashInitCode(type(LiquidityHub).creationCode, abi.encode(reactor, admin)));

if (executor.code.length == 0) {
vm.broadcast();
LiquidityHub deployed = new LiquidityHub{salt: 0}(IReactor(payable(reactor)), IAllowed(address(admin)));
require(executor == address(deployed), "executor mismatched address");
} else {
console.log("executor already deployed");
}
}
}
20 changes: 20 additions & 0 deletions script/04_DeployRepermit.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.x;

import "forge-std/Script.sol";

import {BaseScript, Admin, Consts} from "script/base/BaseScript.sol";
import {RePermit} from "src/RePermit.sol";

contract DeployRepermit is BaseScript {
function run() public returns (address repermit) {
repermit = computeCreate2Address(0, hashInitCode(type(RePermit).creationCode));

if (repermit.code.length == 0) {
vm.broadcast();
require(repermit == address(new RePermit{salt: 0}()), "repermit mismatched address");
} else {
console.log("repermit already deployed");
}
}
}
25 changes: 25 additions & 0 deletions script/05_DeployPartial.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.x;

import "forge-std/Script.sol";

import {BaseScript, Admin, Consts} from "script/base/BaseScript.sol";
import {PartialOrderReactor} from "src/PartialOrderReactor.sol";
import {RePermit} from "src/RePermit.sol";

contract DeployPartial is BaseScript {
function run() public returns (address reactorPartial) {
address repermit = vm.envAddress("REPERMIT");

reactorPartial =
computeCreate2Address(0, hashInitCode(type(PartialOrderReactor).creationCode, abi.encode(repermit)));

if (reactorPartial.code.length == 0) {
vm.broadcast();
PartialOrderReactor deployed = new PartialOrderReactor{salt: 0}(RePermit(repermit));
require(reactorPartial == address(deployed), "mismatched address");
} else {
console.log("partialreactor already deployed");
}
}
}
144 changes: 0 additions & 144 deletions script/Deploy.s.sol

This file was deleted.

36 changes: 29 additions & 7 deletions script/deployall
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/zsh
set -euo pipefail

config=script/input/config.json
deployments=script/input/deployments.json

b=false; [[ " $* " == *" -b "* ]] && b=true

trap chain EXIT

Expand All @@ -10,10 +12,30 @@ chains=(eth arb bnb matic ftm op linea blast base zkevm manta sei sonic zircuit
echo $chains | tr ' ' '\n' | parallel --keep-order "
echo \"\n🔗🔗🔗🔗🔗🔗🔗🔗🔗🔗🔗🔗 {} 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀\n\";
chain {};
forge script Deploy --broadcast" |
tee >(
grep ': address ' | sed 's/: address / /' | while read c a; do;
[[ $a != $(jq -r ".$c" $config) ]] && echo "❌ address mismatch: $c $a";
done;
) |
export ADMIN=$(jq -r '."*".admin' $deployments);
export REACTOR=$(jq -r '."*".reactor' $deployments);
export REPERMIT=$(jq -r '."*".repermit' $deployments);
#forge script DeployAdmin ${b:+--broadcast};
echo \"✔ admin\n\"
#forge script UpdateWhitelist ${b:+--broadcast};
echo \"✔ whitelist\n\"
#forge script DeployReactor ${b:+--broadcast};
echo \"✔ reactor\n\"
export SALT="0x0000000000000000000000000000000000000000000000000000000000000001"
forge script DeployReactor ${b:+--broadcast};
echo \"✔ reactor2\n\"
forge script DeployExecutor ${b:+--broadcast};
echo \"✔ executor\n\"
# forge script DeployRepermit ${b:+--broadcast};
echo \"✔ repermit\n\"
# forge script DeployPartial ${b:+--broadcast};
echo \"✔ partial\n\"
"
Loading

0 comments on commit 99d5965

Please sign in to comment.