-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add deploy script (SC-713) (#28)
* 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
1 parent
fb781d3
commit 60b57c9
Showing
8 changed files
with
122 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
Submodule spark-address-registry
added at
121e0f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |