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: Upgradable Earner Manager #86

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
71 changes: 57 additions & 14 deletions script/DeployBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,76 @@ pragma solidity 0.8.26;
import { ContractHelper } from "../lib/common/src/libs/ContractHelper.sol";

import { WrappedMToken } from "../src/WrappedMToken.sol";
import { EarnerManager } from "../src/EarnerManager.sol";
import { Proxy } from "../src/Proxy.sol";

contract DeployBase {
/**
* @dev Deploys Wrapped M Token.
* @param mToken_ The address the M Token contract.
* @param registrar_ The address the Registrar contract.
* @param migrationAdmin_ The address the Migration Admin.
* @return implementation_ The address of the deployed Wrapped M Token implementation.
* @return proxy_ The address of the deployed Wrapped M Token proxy.
* @param mToken_ The address of the M Token contract.
* @param registrar_ The address of the Registrar contract.
* @param excessDestination_ The address of the excess destination.
* @param migrationAdmin_ The address of the Migration Admin.
* @return earnerManagerImplementation_ The address of the deployed Earner Manager implementation.
* @return earnerManagerProxy_ The address of the deployed Earner Manager proxy.
* @return wrappedMTokenImplementation_ The address of the deployed Wrapped M Token implementation.
* @return wrappedMTokenProxy_ The address of the deployed Wrapped M Token proxy.
*/
function deploy(
address mToken_,
address registrar_,
address excessDestination_,
address migrationAdmin_
) public virtual returns (address implementation_, address proxy_) {
// Wrapped M token needs `mToken_`, `registrar_`, and `migrationAdmin_` addresses.
// Proxy needs `implementation_` addresses.
)
public
virtual
returns (
address earnerManagerImplementation_,
address earnerManagerProxy_,
address wrappedMTokenImplementation_,
address wrappedMTokenProxy_
)
{
// Earner Manager Proxy constructor needs only known values.
// Earner Manager Implementation constructor needs `earnerManagerImplementation_`.
// Wrapped M Token Implementation constructor needs `earnerManagerProxy_`.
// Wrapped M Token Proxy constructor needs `wrappedMTokenImplementation_`.

implementation_ = address(new WrappedMToken(mToken_, registrar_, excessDestination_, migrationAdmin_));
proxy_ = address(new Proxy(implementation_));
earnerManagerImplementation_ = address(new EarnerManager(registrar_, migrationAdmin_));

earnerManagerProxy_ = address(new Proxy(earnerManagerImplementation_));

wrappedMTokenImplementation_ = address(
new WrappedMToken(mToken_, registrar_, earnerManagerProxy_, excessDestination_, migrationAdmin_)
);

wrappedMTokenProxy_ = address(new Proxy(wrappedMTokenImplementation_));
}

function _getExpectedEarnerManager(address deployer_, uint256 deployerNonce_) internal pure returns (address) {
return ContractHelper.getContractFrom(deployer_, deployerNonce_);
}

function getExpectedEarnerManager(address deployer_, uint256 deployerNonce_) public pure virtual returns (address) {
return _getExpectedEarnerManager(deployer_, deployerNonce_);
}

function _getExpectedEarnerManagerProxy(address deployer_, uint256 deployerNonce_) internal pure returns (address) {
return ContractHelper.getContractFrom(deployer_, deployerNonce_ + 1);
}

function getExpectedEarnerManagerProxy(
address deployer_,
uint256 deployerNonce_
) public pure virtual returns (address) {
return _getExpectedEarnerManagerProxy(deployer_, deployerNonce_);
}

function _getExpectedWrappedMTokenImplementation(
address deployer_,
uint256 deployerNonce_
) internal pure returns (address) {
return ContractHelper.getContractFrom(deployer_, deployerNonce_);
return ContractHelper.getContractFrom(deployer_, deployerNonce_ + 2);
}

function getExpectedWrappedMTokenImplementation(
Expand All @@ -44,7 +85,7 @@ contract DeployBase {
}

function _getExpectedWrappedMTokenProxy(address deployer_, uint256 deployerNonce_) internal pure returns (address) {
return ContractHelper.getContractFrom(deployer_, deployerNonce_ + 1);
return ContractHelper.getContractFrom(deployer_, deployerNonce_ + 3);
}

function getExpectedWrappedMTokenProxy(
Expand All @@ -54,7 +95,9 @@ contract DeployBase {
return _getExpectedWrappedMTokenProxy(deployer_, deployerNonce_);
}

function getDeployerNonceAfterProtocolDeployment(uint256 deployerNonce_) public pure virtual returns (uint256) {
return deployerNonce_ + 2;
function getDeployerNonceAfterWrappedMTokenDeployment(
uint256 deployerNonce_
) public pure virtual returns (uint256) {
return deployerNonce_ + 4;
}
}
31 changes: 24 additions & 7 deletions script/DeployProduction.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ contract DeployProduction is Script, DeployBase {
// NOTE: Ensure this is the correct nonce to use to deploy the Proxy on testnet/mainnet.
uint256 internal constant _DEPLOYER_PROXY_NONCE = 40;

// NOTE: Ensure this is the correct expected testnet/mainnet address for the Proxy.
address internal constant _EXPECTED_PROXY = 0x437cc33344a0B27A429f795ff6B469C72698B291;
// NOTE: Ensure this is the correct expected testnet/mainnet address for the Wrapped M Token Proxy.
address internal constant _EXPECTED_WRAPPED_M_TOKEN_PROXY = address(0);

// NOTE: Ensure this is the correct expected testnet/mainnet address for the Earner Manager Proxy.
address internal constant _EXPECTED_EARNER_MANAGER_PROXY = address(0);

function run() external {
address deployer_ = vm.rememberKey(vm.envUint("PRIVATE_KEY"));
Expand All @@ -53,7 +56,8 @@ contract DeployProduction is Script, DeployBase {

address expectedProxy_ = getExpectedWrappedMTokenProxy(deployer_, _DEPLOYER_PROXY_NONCE);

if (expectedProxy_ != _EXPECTED_PROXY) revert ExpectedProxyMismatch(_EXPECTED_PROXY, expectedProxy_);
if (expectedProxy_ != _EXPECTED_WRAPPED_M_TOKEN_PROXY)
revert ExpectedProxyMismatch(_EXPECTED_WRAPPED_M_TOKEN_PROXY, expectedProxy_);

vm.startBroadcast(deployer_);

Expand All @@ -67,13 +71,26 @@ contract DeployProduction is Script, DeployBase {

if (currentNonce_ != _DEPLOYER_PROXY_NONCE - 1) revert UnexpectedDeployerNonce();

(address implementation_, address proxy_) = deploy(_M_TOKEN, _REGISTRAR, _EXCESS_DESTINATION, _MIGRATION_ADMIN);
(
address earnerManagerProxy_,
address earnerManagerImplementation_,
address wrappedMTokenImplementation_,
address wrappedMTokenProxy_
) = deploy(_M_TOKEN, _REGISTRAR, _EXCESS_DESTINATION, _MIGRATION_ADMIN);

vm.stopBroadcast();

console2.log("Wrapped M Implementation address:", implementation_);
console2.log("Wrapped M Proxy address:", proxy_);
console2.log("Earner Manager Proxy address:", earnerManagerProxy_);
console2.log("Earner Manager Implementation address:", earnerManagerImplementation_);
console2.log("Wrapped M Implementation address:", wrappedMTokenImplementation_);
console2.log("Wrapped M Proxy address:", wrappedMTokenProxy_);

if (wrappedMTokenProxy_ != _EXPECTED_WRAPPED_M_TOKEN_PROXY) {
revert ResultingProxyMismatch(_EXPECTED_WRAPPED_M_TOKEN_PROXY, wrappedMTokenProxy_);
}

if (proxy_ != _EXPECTED_PROXY) revert ResultingProxyMismatch(_EXPECTED_PROXY, proxy_);
if (earnerManagerProxy_ != _EXPECTED_EARNER_MANAGER_PROXY) {
revert ResultingProxyMismatch(_EXPECTED_EARNER_MANAGER_PROXY, earnerManagerProxy_);
}
}
}
Loading
Loading