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 16, 2025
1 parent 7d256ec commit accb16b
Show file tree
Hide file tree
Showing 18 changed files with 1,879 additions and 270 deletions.
41 changes: 29 additions & 12 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ contract DeployProduction is Script, DeployBase {
address deployer_ = vm.rememberKey(vm.envUint("PRIVATE_KEY"));
address expectedDeployer_ = vm.envAddress("DEPLOYER");

uint64 deployerProxyNonce_ = uint64(vm.envUint("DEPLOYER_PROXY_NONCE"));
uint64 deployerWrappedMProxyNonce_ = uint64(vm.envUint("DEPLOYER_WRAPPED_M_PROXY_NONCE"));

address registrar_ = vm.envAddress("REGISTRAR");
address excessDestination_ = vm.envAddress("EXCESS_DESTINATION");
address mToken_ = vm.envAddress("M_TOKEN");
address migrationAdmin_ = vm.envAddress("MIGRATION_ADMIN");
address expectedProxy_ = vm.envAddress("EXPECTED_PROXY");
address wrappedMMigrationAdmin_ = vm.envAddress("WRAPPED_M_MIGRATION_ADMIN");
address earnerManagerMigrationAdmin_ = vm.envAddress("EARNER_MANAGER_MIGRATION_ADMIN");
address expectedWrappedMProxy_ = vm.envAddress("EXPECTED_WRAPPED_M_PROXY");

console2.log("Deployer:", deployer_);

Expand All @@ -38,15 +39,22 @@ contract DeployProduction is Script, DeployBase {
uint64 currentNonce_ = vm.getNonce(deployer_);

uint64 startNonce_ = currentNonce_;
address implementation_;
address proxy_;
address earnerManagerImplementation_;
address earnerManagerProxy_;
address wrappedMTokenImplementation_;
address wrappedMTokenProxy_;

while (true) {
if (startNonce_ > deployerProxyNonce_) revert DeployerNonceTooHigh();
if (startNonce_ > deployerWrappedMProxyNonce_) revert DeployerNonceTooHigh();

(implementation_, proxy_) = mockDeploy(deployer_, startNonce_);
(
earnerManagerImplementation_,
earnerManagerProxy_,
wrappedMTokenImplementation_,
wrappedMTokenProxy_
) = mockDeploy(deployer_, startNonce_);

if (proxy_ == expectedProxy_) break;
if (wrappedMTokenProxy_ == expectedWrappedMProxy_) break;

++startNonce_;
}
Expand All @@ -63,13 +71,22 @@ contract DeployProduction is Script, DeployBase {

if (currentNonce_ != startNonce_) revert UnexpectedDeployerNonce();

(implementation_, proxy_) = deployUpgrade(mToken_, registrar_, excessDestination_, migrationAdmin_);
(earnerManagerImplementation_, earnerManagerProxy_, wrappedMTokenImplementation_, wrappedMTokenProxy_) = deploy(
mToken_,
registrar_,
excessDestination_,
wrappedMMigrationAdmin_,
earnerManagerMigrationAdmin_
);

vm.stopBroadcast();

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

if (proxy_ != expectedProxy_) revert ResultingProxyMismatch(expectedProxy_, proxy_);
if (wrappedMTokenProxy_ != expectedWrappedMProxy_)
revert ResultingProxyMismatch(expectedWrappedMProxy_, wrappedMTokenProxy_);
}
}
163 changes: 120 additions & 43 deletions script/DeployBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,87 +5,164 @@ pragma solidity 0.8.26;
import { ContractHelper } from "../lib/common/src/libs/ContractHelper.sol";
import { Proxy } from "../lib/common/src/Proxy.sol";

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

contract DeployBase {
/**
* @dev Deploys Wrapped M Token.
* @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 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 wrappedMMigrationAdmin_ The address of the Wrapped M Migration Admin.
* @param earnerManagerMigrationAdmin_ The address of the Earner Manager 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_`, `excessDestination_`, and `migrationAdmin_` addresses.
// Proxy needs `implementation_` addresses.
address wrappedMMigrationAdmin_,
address earnerManagerMigrationAdmin_
)
public
virtual
returns (
address earnerManagerImplementation_,
address earnerManagerProxy_,
address wrappedMTokenImplementation_,
address wrappedMTokenProxy_
)
{
// Earner Manager Implementation constructor needs only known values.
// Earner Manager Proxy 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_, earnerManagerMigrationAdmin_));

earnerManagerProxy_ = address(new Proxy(earnerManagerImplementation_));

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

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

/**
* @dev Deploys Wrapped M Token components needed to upgrade an existing Wrapped M 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 implementation_ The address of the deployed Wrapped M Token implementation.
* @return migrator_ The address of the deployed Migrator.
* @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 wrappedMMigrationAdmin_ The address of the Wrapped M Migration Admin.
* @param earnerManagerMigrationAdmin_ The address of the Earner Manager 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 wrappedMTokenMigrator_ The address of the deployed Wrapped M Token Migrator.
*/
function deployUpgrade(
address mToken_,
address registrar_,
address excessDestination_,
address migrationAdmin_
) public virtual returns (address implementation_, address migrator_) {
// Wrapped M token needs `mToken_`, `registrar_`, `excessDestination_`, and `migrationAdmin_` addresses.
// Migrator needs `implementation_` addresses.
address wrappedMMigrationAdmin_,
address earnerManagerMigrationAdmin_
)
public
virtual
returns (
address earnerManagerImplementation_,
address earnerManagerProxy_,
address wrappedMTokenImplementation_,
address wrappedMTokenMigrator_
)
{
// Earner Manager Implementation constructor needs only known values.
// Earner Manager Proxy constructor needs `earnerManagerImplementation_`.
// Wrapped M Token Implementation constructor needs `earnerManagerProxy_`.
// Migrator needs `wrappedMTokenImplementation_` addresses.

earnerManagerImplementation_ = address(new EarnerManager(registrar_, earnerManagerMigrationAdmin_));

earnerManagerProxy_ = address(new Proxy(earnerManagerImplementation_));

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

implementation_ = address(new WrappedMToken(mToken_, registrar_, excessDestination_, migrationAdmin_));
migrator_ = address(new MigratorV1(implementation_));
wrappedMTokenMigrator_ = address(new WrappedMTokenMigratorV1(wrappedMTokenImplementation_));
}

/**
* @dev Mock deploys Wrapped M Token, returning the would-be addresses.
* @param deployer_ The address of the deployer.
* @param deployerNonce_ The nonce of the deployer.
* @return implementation_ The address of the would-be Wrapped M Token implementation.
* @return proxy_ The address of the would-be Wrapped M Token proxy.
* @param deployer_ The address of the deployer.
* @param deployerNonce_ The nonce of the deployer.
* @return earnerManagerImplementation_ The address of the would-be Earner Manager implementation.
* @return earnerManagerProxy_ The address of the would-be Earner Manager proxy.
* @return wrappedMTokenImplementation_ The address of the would-be Wrapped M Token implementation.
* @return wrappedMTokenProxy_ The address of the would-be Wrapped M Token proxy.
*/
function mockDeploy(
address deployer_,
uint256 deployerNonce_
) public view virtual returns (address implementation_, address proxy_) {
// Wrapped M token needs `mToken_`, `registrar_`, `excessDestination_`, and `migrationAdmin_` addresses.
// Proxy needs `implementation_` addresses.
)
public
view
virtual
returns (
address earnerManagerImplementation_,
address earnerManagerProxy_,
address wrappedMTokenImplementation_,
address wrappedMTokenProxy_
)
{
// Earner Manager Implementation constructor needs only known values.
// Earner Manager Proxy constructor needs `earnerManagerImplementation_`.
// Wrapped M Token Implementation constructor needs `earnerManagerProxy_`.
// Wrapped M Token Proxy constructor needs `wrappedMTokenImplementation_`.

implementation_ = ContractHelper.getContractFrom(deployer_, deployerNonce_);
proxy_ = ContractHelper.getContractFrom(deployer_, deployerNonce_ + 1);
earnerManagerImplementation_ = ContractHelper.getContractFrom(deployer_, deployerNonce_);
earnerManagerProxy_ = ContractHelper.getContractFrom(deployer_, deployerNonce_ + 1);
wrappedMTokenImplementation_ = ContractHelper.getContractFrom(deployer_, deployerNonce_ + 2);
wrappedMTokenProxy_ = ContractHelper.getContractFrom(deployer_, deployerNonce_ + 3);
}

/**
* @dev Mock deploys Wrapped M Token, returning the would-be addresses.
* @param deployer_ The address of the deployer.
* @param deployerNonce_ The nonce of the deployer.
* @return implementation_ The address of the would-be Wrapped M Token implementation.
* @return migrator_ The address of the would-be Migrator.
* @param deployer_ The address of the deployer.
* @param deployerNonce_ The nonce of the deployer.
* @return earnerManagerImplementation_ The address of the would-be Earner Manager implementation.
* @return earnerManagerProxy_ The address of the would-be Earner Manager proxy.
* @return wrappedMTokenImplementation_ The address of the would-be Wrapped M Token implementation.
* @return wrappedMTokenMigrator_ The address of the deployed Wrapped M Token Migrator.
*/
function mockDeployUpgrade(
address deployer_,
uint256 deployerNonce_
) public view virtual returns (address implementation_, address migrator_) {
// Wrapped M token needs `mToken_`, `registrar_`, `excessDestination_`, and `migrationAdmin_` addresses.
// Migrator needs `implementation_` addresses.
)
public
view
virtual
returns (
address earnerManagerImplementation_,
address earnerManagerProxy_,
address wrappedMTokenImplementation_,
address wrappedMTokenMigrator_
)
{
// Earner Manager Implementation constructor needs only known values.
// Earner Manager Proxy constructor needs `earnerManagerImplementation_`.
// Wrapped M Token Implementation constructor needs `earnerManagerProxy_`.
// Migrator needs `wrappedMTokenImplementation_` addresses.

implementation_ = ContractHelper.getContractFrom(deployer_, deployerNonce_);
migrator_ = ContractHelper.getContractFrom(deployer_, deployerNonce_ + 1);
earnerManagerImplementation_ = ContractHelper.getContractFrom(deployer_, deployerNonce_);
earnerManagerProxy_ = ContractHelper.getContractFrom(deployer_, deployerNonce_ + 1);
wrappedMTokenImplementation_ = ContractHelper.getContractFrom(deployer_, deployerNonce_ + 2);
wrappedMTokenMigrator_ = ContractHelper.getContractFrom(deployer_, deployerNonce_ + 3);
}
}
47 changes: 36 additions & 11 deletions script/DeployUpgradeMainnet.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ contract DeployUpgradeMainnet is Script, DeployBase {
address internal constant _M_TOKEN = 0x866A2BF4E572CbcF37D5071A7a58503Bfb36be1b;

// NOTE: Ensure this is the correct Migration Admin mainnet address.
address internal constant _MIGRATION_ADMIN = 0x431169728D75bd02f4053435b87D15c8d1FB2C72;
address internal constant _WRAPPED_M_MIGRATION_ADMIN = 0x431169728D75bd02f4053435b87D15c8d1FB2C72;

address internal constant _PROXY = 0x437cc33344a0B27A429f795ff6B469C72698B291; // Mainnet address for the Proxy.
// NOTE: Ensure this is the correct Migration Admin mainnet address.
address internal constant _EARNER_MANAGER_MIGRATION_ADMIN = 0x431169728D75bd02f4053435b87D15c8d1FB2C72;

address internal constant _WRAPPED_M_PROXY = 0x437cc33344a0B27A429f795ff6B469C72698B291; // Mainnet address for the Proxy.

// NOTE: Ensure this is the correct mainnet deployer to use.
address internal constant _EXPECTED_DEPLOYER = 0xF2f1ACbe0BA726fEE8d75f3E32900526874740BB;
Expand All @@ -36,7 +39,7 @@ contract DeployUpgradeMainnet is Script, DeployBase {
uint64 internal constant _DEPLOYER_MIGRATOR_NONCE = 40;

// NOTE: Ensure this is the correct expected mainnet address for the Migrator.
address internal constant _EXPECTED_MIGRATOR = address(0);
address internal constant _EXPECTED_WRAPPED_M_MIGRATOR = address(0);

function run() external {
address deployer_ = vm.rememberKey(vm.envUint("PRIVATE_KEY"));
Expand All @@ -48,15 +51,22 @@ contract DeployUpgradeMainnet is Script, DeployBase {
uint64 currentNonce_ = vm.getNonce(deployer_);

uint64 startNonce_ = currentNonce_;
address implementation_;
address migrator_;
address earnerManagerImplementation_;
address earnerManagerProxy_;
address wrappedMTokenImplementation_;
address wrappedMTokenMigrator_;

while (true) {
if (startNonce_ > _DEPLOYER_MIGRATOR_NONCE) revert DeployerNonceTooHigh();

(implementation_, migrator_) = mockDeployUpgrade(deployer_, startNonce_);
(
earnerManagerImplementation_,
earnerManagerProxy_,
wrappedMTokenImplementation_,
wrappedMTokenMigrator_
) = mockDeployUpgrade(deployer_, startNonce_);

if (migrator_ == _EXPECTED_MIGRATOR) break;
if (wrappedMTokenMigrator_ == _EXPECTED_WRAPPED_M_MIGRATOR) break;

++startNonce_;
}
Expand All @@ -73,13 +83,28 @@ contract DeployUpgradeMainnet is Script, DeployBase {

if (currentNonce_ != startNonce_) revert UnexpectedDeployerNonce();

(implementation_, migrator_) = deployUpgrade(_M_TOKEN, _REGISTRAR, _EXCESS_DESTINATION, _MIGRATION_ADMIN);
(
earnerManagerImplementation_,
earnerManagerProxy_,
wrappedMTokenImplementation_,
wrappedMTokenMigrator_
) = deployUpgrade(
_M_TOKEN,
_REGISTRAR,
_EXCESS_DESTINATION,
_WRAPPED_M_MIGRATION_ADMIN,
_EARNER_MANAGER_MIGRATION_ADMIN
);

vm.stopBroadcast();

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

if (migrator_ != _EXPECTED_MIGRATOR) revert ResultingMigratorMismatch(_EXPECTED_MIGRATOR, migrator_);
if (wrappedMTokenMigrator_ != _EXPECTED_WRAPPED_M_MIGRATOR) {
revert ResultingMigratorMismatch(_EXPECTED_WRAPPED_M_MIGRATOR, wrappedMTokenMigrator_);
}
}
}
Loading

0 comments on commit accb16b

Please sign in to comment.