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

feat: Add deploy script (SC-713) #28

Merged
merged 11 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
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
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)
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(), address(this));
hexonaut marked this conversation as resolved.
Show resolved Hide resolved
}

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

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 {
address executor = Deploy.deployExecutor(100, 1000);
address receiver = Deploy.deployOptimismReceiver(Ethereum.SPARK_PROXY, executor);

Deploy.setUpExecutorPermissions(executor, receiver);
}

}
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
46 changes: 46 additions & 0 deletions test/Deploy.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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"))
);

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));

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

}
Loading