-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce deployment script for
RewardsStreamerMP
This commit introduces a deployment script for the stake manager which can later be extended to work with other networks. The deployment script is also used inside our testsuite, ensuring it's working as intended. Closes #88
- Loading branch information
Showing
7 changed files
with
183 additions
and
53 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
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,41 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.26 <=0.9.0; | ||
|
||
import { Script } from "forge-std/Script.sol"; | ||
|
||
abstract contract BaseScript is Script { | ||
/// @dev Included to enable compilation of the script without a $MNEMONIC environment variable. | ||
string internal constant TEST_MNEMONIC = "test test test test test test test test test test test junk"; | ||
|
||
/// @dev Needed for the deterministic deployments. | ||
bytes32 internal constant ZERO_SALT = bytes32(0); | ||
|
||
/// @dev The address of the transaction broadcaster. | ||
address internal broadcaster; | ||
|
||
/// @dev Used to derive the broadcaster's address if $ETH_FROM is not defined. | ||
string internal mnemonic; | ||
|
||
/// @dev Initializes the transaction broadcaster like this: | ||
/// | ||
/// - If $ETH_FROM is defined, use it. | ||
/// - Otherwise, derive the broadcaster address from $MNEMONIC. | ||
/// - If $MNEMONIC is not defined, default to a test mnemonic. | ||
/// | ||
/// The use case for $ETH_FROM is to specify the broadcaster key and its address via the command line. | ||
constructor() { | ||
address from = vm.envOr({ name: "ETH_FROM", defaultValue: address(0) }); | ||
if (from != address(0)) { | ||
broadcaster = from; | ||
} else { | ||
mnemonic = vm.envOr({ name: "MNEMONIC", defaultValue: TEST_MNEMONIC }); | ||
(broadcaster,) = deriveRememberKey({ mnemonic: mnemonic, index: 0 }); | ||
} | ||
} | ||
|
||
modifier broadcast() { | ||
vm.startBroadcast(broadcaster); | ||
_; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.26; | ||
|
||
import { BaseScript } from "./Base.s.sol"; | ||
import { DeploymentConfig } from "./DeploymentConfig.s.sol"; | ||
import { IStakeManagerProxy } from "../src/interfaces/IStakeManagerProxy.sol"; | ||
import { StakeManagerProxy } from "../src/StakeManagerProxy.sol"; | ||
import { RewardsStreamerMP } from "../src/RewardsStreamerMP.sol"; | ||
import { StakeVault } from "../src/StakeVault.sol"; | ||
|
||
contract DeployRewardsStreamerMPScript is BaseScript { | ||
function run() public returns (RewardsStreamerMP, DeploymentConfig) { | ||
DeploymentConfig deploymentConfig = new DeploymentConfig(broadcaster); | ||
(address deployer, address stakingToken) = deploymentConfig.activeNetworkConfig(); | ||
|
||
bytes memory initializeData = abi.encodeCall(RewardsStreamerMP.initialize, (deployer, stakingToken)); | ||
|
||
vm.startBroadcast(deployer); | ||
address impl = address(new RewardsStreamerMP()); | ||
address proxy = address(new StakeManagerProxy(impl, initializeData)); | ||
vm.stopBroadcast(); | ||
|
||
RewardsStreamerMP stakeManager = RewardsStreamerMP(proxy); | ||
StakeVault tempVault = new StakeVault(address(this), IStakeManagerProxy(proxy)); | ||
bytes32 vaultCodeHash = address(tempVault).codehash; | ||
|
||
vm.startBroadcast(deployer); | ||
stakeManager.setTrustedCodehash(vaultCodeHash, true); | ||
vm.stopBroadcast(); | ||
|
||
return (stakeManager, deploymentConfig); | ||
} | ||
} |
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,42 @@ | ||
//// SPDX-License-Identifier: UNLICENSED | ||
|
||
pragma solidity >=0.8.26 <=0.9.0; | ||
|
||
import { Script } from "forge-std/Script.sol"; | ||
import { MockToken } from "../test/mocks/MockToken.sol"; | ||
|
||
contract DeploymentConfig is Script { | ||
error DeploymentConfig_InvalidDeployerAddress(); | ||
error DeploymentConfig_NoConfigForChain(uint256); | ||
|
||
struct NetworkConfig { | ||
address deployer; | ||
address stakingToken; | ||
} | ||
|
||
NetworkConfig public activeNetworkConfig; | ||
|
||
address private deployer; | ||
|
||
constructor(address _broadcaster) { | ||
if (_broadcaster == address(0)) revert DeploymentConfig_InvalidDeployerAddress(); | ||
deployer = _broadcaster; | ||
if (block.chainid == 31_337) { | ||
activeNetworkConfig = getOrCreateAnvilEthConfig(); | ||
} else { | ||
revert DeploymentConfig_NoConfigForChain(block.chainid); | ||
} | ||
} | ||
|
||
function getOrCreateAnvilEthConfig() public returns (NetworkConfig memory) { | ||
MockToken stakingToken = new MockToken("Staking Token", "ST"); | ||
return NetworkConfig({ deployer: deployer, stakingToken: address(stakingToken) }); | ||
} | ||
|
||
// This function is a hack to have it excluded by `forge coverage` until | ||
// https://github.com/foundry-rs/foundry/issues/2988 is fixed. | ||
// See: https://github.com/foundry-rs/foundry/issues/2988#issuecomment-1437784542 | ||
// for more info. | ||
// solhint-disable-next-line | ||
function test() public { } | ||
} |
This file was deleted.
Oops, something went wrong.
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