Skip to content

Commit

Permalink
feat: Add deploy script (SC-713) (#28)
Browse files Browse the repository at this point in the history
* feat: deploy lib working

* feat: start script

* forge install: spark-address-registry

* feat: add initial script

* fix: rm guardian

* feat: working deploy

* feat: demonstrate issue

* feat: fix test

* fix: use sender flag

* feat: fix script

* feat: add logs
  • Loading branch information
lucas-manuel authored Oct 8, 2024
1 parent fb781d3 commit 60b57c9
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/spark-address-registry"]
path = lib/spark-address-registry
url = https://github.com/marsfoundation/spark-address-registry
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
deploy-base :; forge script script/Deploy.s.sol:DeployBaseExecutor --sender ${ETH_FROM} --broadcast --verify

33 changes: 33 additions & 0 deletions deploy/Deploy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;

import { OptimismReceiver } from 'lib/xchain-helpers/src/receivers/OptimismReceiver.sol';

import { Executor } from 'src/Executor.sol';

library Deploy {

function deployExecutor(uint256 delay, uint256 gracePeriod)
internal returns (address executor)
{
executor = address(new Executor(delay, gracePeriod));
}

function deployOptimismReceiver(address l1Authority, address executor)
internal returns (address receiver)
{
receiver = address(new OptimismReceiver(l1Authority, executor));
}

function setUpExecutorPermissions(address executor_, address receiver, address deployer)
internal
{
// NOTE: Using implementation instead of interface because OZ didn't define
// DEFAULT_ADMIN_ROLE in the IAccessControl interface.
Executor executor = Executor(executor_);

executor.grantRole(executor.SUBMISSION_ROLE(), receiver);
executor.revokeRole(executor.DEFAULT_ADMIN_ROLE(), deployer);
}

}
1 change: 1 addition & 0 deletions lib/spark-address-registry
Submodule spark-address-registry added at 121e0f
30 changes: 30 additions & 0 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;

import { console } from "forge-std/console.sol";

import { Ethereum } from "lib/spark-address-registry/src/Ethereum.sol";

import { Script } from 'forge-std/Script.sol';

import { Deploy } from "../deploy/Deploy.sol";

contract DeployBaseExecutor is Script {

function run() public {
vm.createSelectFork(getChain("base").rpcUrl);

vm.startBroadcast();

address executor = Deploy.deployExecutor(100, 1000);
address receiver = Deploy.deployOptimismReceiver(Ethereum.SPARK_PROXY, executor);

console.log("executor deployed at:", executor);
console.log("receiver deployed at:", receiver);

Deploy.setUpExecutorPermissions(executor, receiver, msg.sender);

vm.stopBroadcast();
}

}
2 changes: 1 addition & 1 deletion test/ArbitrumOneCrosschainTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract ArbitrumOneCrosschainTest is CrosschainTestBase {
));

mainnet.selectFork();
vm.deal(L1_EXECUTOR, 0.01 ether);
vm.deal(L1_SPARK_PROXY, 0.01 ether);
}

function relayMessagesAcrossBridge() internal override {
Expand Down
8 changes: 4 additions & 4 deletions test/CrosschainTestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ abstract contract CrosschainTestBase is Test {

event TestEvent();

address constant L1_EXECUTOR = 0x3300f198988e4C9C63F75dF86De36421f06af8c4;
address constant L1_SPARK_PROXY = 0x3300f198988e4C9C63F75dF86De36421f06af8c4;
address constant L1_PAUSE_PROXY = 0xBE8E3e3618f7474F8cB1d074A26afFef007E98FB;
address GUARDIAN = makeAddr('guardian');

L2BridgeExecutorArguments defaultL2BridgeExecutorArgs = L2BridgeExecutorArguments({
ethereumGovernanceExecutor: L1_EXECUTOR,
ethereumGovernanceExecutor: L1_SPARK_PROXY,
delay: 600,
gracePeriod: 1200,
guardian: GUARDIAN
Expand Down Expand Up @@ -86,7 +86,7 @@ abstract contract CrosschainTestBase is Test {
);

vm.prank(L1_PAUSE_PROXY);
IL1Executor(L1_EXECUTOR).exec(
IL1Executor(L1_SPARK_PROXY).exec(
address(crosschainPayload),
abi.encodeWithSelector(IPayload.execute.selector)
);
Expand Down Expand Up @@ -335,7 +335,7 @@ abstract contract CrosschainTestBase is Test {
);

vm.prank(L1_PAUSE_PROXY);
IL1Executor(L1_EXECUTOR).exec(
IL1Executor(L1_SPARK_PROXY).exec(
address(crosschainPayload),
abi.encodeWithSelector(IPayload.execute.selector)
);
Expand Down
48 changes: 48 additions & 0 deletions test/Deploy.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;

import 'forge-std/Test.sol';

import { OptimismReceiver } from 'lib/xchain-helpers/src/receivers/OptimismReceiver.sol';

import { Deploy } from "../deploy/Deploy.sol";

import { Executor } from 'src/Executor.sol';

contract DeployTests is Test {

function test_deployExecutor() public {
Executor executor = Executor(Deploy.deployExecutor(100, 1000));

assertEq(executor.delay(), 100);
assertEq(executor.gracePeriod(), 1000);
}

function test_deployOptimismReceiver() public {
OptimismReceiver receiver = OptimismReceiver(
Deploy.deployOptimismReceiver(makeAddr("l1Authority"), makeAddr("executor"))
);

assertEq(OptimismReceiver(receiver).l1Authority(), makeAddr("l1Authority"));
assertEq(OptimismReceiver(receiver).target(), makeAddr("executor"));
}

function test_setUpExecutorPermissions() public {
Executor executor = Executor(Deploy.deployExecutor(100, 1000));

OptimismReceiver receiver = OptimismReceiver(
Deploy.deployOptimismReceiver(makeAddr("l1Authority"), makeAddr("executor"))
);

address deployer = address(this);

assertEq(executor.hasRole(executor.SUBMISSION_ROLE(), address(receiver)), false);
assertEq(executor.hasRole(executor.DEFAULT_ADMIN_ROLE(), address(this)), true);

Deploy.setUpExecutorPermissions(address(executor), address(receiver), deployer);

assertEq(executor.hasRole(executor.SUBMISSION_ROLE(), address(receiver)), true);
assertEq(executor.hasRole(executor.DEFAULT_ADMIN_ROLE(), address(this)), false);
}

}

0 comments on commit 60b57c9

Please sign in to comment.