Skip to content

Commit

Permalink
feat: Earner Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
deluca-mike committed Jan 14, 2025
1 parent 2c7cfc7 commit 2abc438
Show file tree
Hide file tree
Showing 17 changed files with 1,681 additions and 231 deletions.
72 changes: 57 additions & 15 deletions script/DeployBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,76 @@ pragma solidity 0.8.26;
import { ContractHelper } from "../lib/common/src/libs/ContractHelper.sol";
import { Proxy } from "../lib/common/src/Proxy.sol";

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

contract DeployBase {
/**
* @dev Deploys Wrapped M Token.
* @param mToken_ The address the M Token contract.
* @param registrar_ The address the Registrar contract.
* @param excessDestination_ The address of the excess destination.
* @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 @@ -45,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 @@ -55,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.
uint64 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 @@ -54,7 +57,8 @@ contract DeployProduction is Script, DeployBase {

address expectedProxy_ = getExpectedWrappedMTokenProxy(deployer_, startNonce_);

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 @@ -68,13 +72,26 @@ contract DeployProduction is Script, DeployBase {

if (currentNonce_ != startNonce_) 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

0 comments on commit 2abc438

Please sign in to comment.