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

Open
wants to merge 1 commit into
base: feat/no-claim-on-transfer-2
Choose a base branch
from
Open
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
35 changes: 23 additions & 12 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ 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 expectedProxy_ = vm.envAddress("EXPECTED_PROXY");
address expectedWrappedMProxy_ = vm.envAddress("EXPECTED_WRAPPED_M_PROXY");

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

Expand All @@ -34,15 +34,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 @@ -59,18 +66,22 @@ contract DeployProduction is Script, DeployBase {

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

(implementation_, proxy_) = deploy(
(earnerManagerImplementation_, earnerManagerProxy_, wrappedMTokenImplementation_, wrappedMTokenProxy_) = deploy(
vm.envAddress("M_TOKEN"),
vm.envAddress("REGISTRAR"),
vm.envAddress("EXCESS_DESTINATION"),
vm.envAddress("MIGRATION_ADMIN")
vm.envAddress("WRAPPED_M_MIGRATION_ADMIN"),
vm.envAddress("EARNER_MANAGER_MIGRATION_ADMIN")
);

vm.stopBroadcast();

console2.log("Wrapped M Implementation address:", implementation_);
console2.log("Wrapped M Proxy 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,88 +5,165 @@ 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_,
address wrappedMMigrationAdmin_,
address earnerManagerMigrationAdmin_,
address[] memory earners_
) public virtual returns (address implementation_, address migrator_) {
// Wrapped M token needs `mToken_`, `registrar_`, `excessDestination_`, and `migrationAdmin_` addresses.
// Migrator needs `implementation_` addresses.
)
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_, earners_));
wrappedMTokenMigrator_ = address(new WrappedMTokenMigratorV1(wrappedMTokenImplementation_, earners_));
}

/**
* @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);
}
}
44 changes: 32 additions & 12 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);

// NOTE: Ensure this is the correct and complete list of earners on mainnet.
address[] internal _earners = [
Expand Down Expand Up @@ -87,15 +90,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 @@ -118,19 +128,29 @@ contract DeployUpgradeMainnet is Script, DeployBase {
earners_[index_] = _earners[index_];
}

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

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