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(script): add deployment script for new StakeManagers #72

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 33 additions & 0 deletions script/DeployMigrationStakeManager.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19 <=0.9.0;

import { BaseScript } from "./Base.s.sol";
import { StakeManager } from "../contracts/StakeManager.sol";

contract DeployMigrationStakeManager is BaseScript {
error DeployMigrationStakeManager_InvalidStakeTokenAddress();

address public prevStakeManager;

address public stakeToken;

constructor(address _prevStakeManager, address _stakeToken) {
prevStakeManager = _prevStakeManager;
stakeToken = _stakeToken;
}

function run() public returns (StakeManager) {
prevStakeManager = vm.envOr({ name: "PREV_STAKE_MANAGER", defaultValue: prevStakeManager });
stakeToken = vm.envOr({ name: "STAKE_TOKEN_ADDRESS", defaultValue: stakeToken });

if (stakeToken == address(0)) {
revert DeployMigrationStakeManager_InvalidStakeTokenAddress();
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically, we can extend this and say, if prevStakeManager != address(0), then we query the stakeToken() address from the old manager.


vm.startBroadcast(broadcaster);
StakeManager stakeManager = new StakeManager(stakeToken, prevStakeManager);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing I've just realised, it probably makes sense to extend this so that it automatically activates migration in the old manager.

If we make this part of this script, however, it's probably less usable in the testing context (which I think would be fine, as in tests we can always just do new StakeManager() individually.

Let me know what you think.

vm.stopBroadcast();

return stakeManager;
}
}
22 changes: 22 additions & 0 deletions test/StakeManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

import { Test, console } from "forge-std/Test.sol";
import { Deploy } from "../script/Deploy.s.sol";
import { DeployMigrationStakeManager } from "../script/DeployMigrationStakeManager.s.sol";
import { DeploymentConfig } from "../script/DeploymentConfig.s.sol";
import { StakeManager } from "../contracts/StakeManager.sol";
import { StakeVault } from "../contracts/StakeVault.sol";
Expand Down Expand Up @@ -430,3 +431,24 @@ contract UserFlowsTest is StakeManagerTest {
assertEq(stakeManager.totalSupplyBalance(), 0);
}
}

contract DeployMigrationStakeManagerTest is StakeManagerTest {
StakeManager internal newStakeManager;

function setUp() public virtual override {
super.setUp();
DeployMigrationStakeManager deployment = new DeployMigrationStakeManager(address(stakeManager), stakeToken);
newStakeManager = deployment.run();
}

function testNewDeployment() public {
assertEq(newStakeManager.owner(), deployer);
assertEq(newStakeManager.currentEpoch(), 0);
assertEq(newStakeManager.pendingReward(), 0);
assertEq(newStakeManager.totalSupplyMP(), 0);
assertEq(newStakeManager.totalSupplyBalance(), 0);
assertEq(address(newStakeManager.stakedToken()), stakeToken);
assertEq(address(newStakeManager.oldManager()), address(stakeManager));
assertEq(newStakeManager.totalSupply(), 0);
}
}
Loading