Skip to content

Commit

Permalink
feat: Smart M Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
deluca-mike committed Oct 30, 2024
1 parent b9cb6fe commit aac5bf4
Show file tree
Hide file tree
Showing 19 changed files with 2,664 additions and 2,685 deletions.
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Wrapped M Token - Smart Wrapper contract
# Smart M Token - Smart Wrapper contract

## Overview

Expand Down Expand Up @@ -35,7 +35,13 @@ cp .env.example .env
Run the following command to compile the contracts:

```bash
forge compile
npm run build
```

or

```bash
make build
```

### Coverage
Expand All @@ -46,6 +52,12 @@ Forge is used for coverage, run it with:
npm run coverage
```

or

```bash
make coverage
```

You can then consult the report by opening `coverage/index.html`:

```bash
Expand All @@ -57,19 +69,13 @@ open coverage/index.html
To run all tests:

```bash
forge test
```

Run test that matches a test contract:

```bash
forge test --mc <test-contract-name>
make tests
```

Test a specific test case:

```bash
forge test --mt <test-case-name>
./test.sh -v -t <test-case-name>
```

To run slither:
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
{
"name": "@mzero-labs/wrapped-m-token",
"name": "@mzero-labs/smart-m-token",
"version": "2.0.0",
"description": "Wrapped M Token",
"author": "M^0 Labs <[email protected]>",
"repository": {
"type": "git",
"url": "git+https://github.com/m0-foundation/wrapped-m-token.git"
"url": "git+https://github.com/m0-foundation/smart-m-token.git"
},
"bugs": {
"url": "https://github.com/m0-foundation/wrapped-m-token/issues"
"url": "https://github.com/m0-foundation/smart-m-token/issues"
},
"homepage": "https://github.com/m0-foundation/wrapped-m-token#readme",
"homepage": "https://github.com/m0-foundation/smart-m-token#readme",
"scripts": {
"build": "make -B build",
"clean": "make -B clean",
"compile": "forge compile",
"coverage": "make -B coverage",
"deploy": "make -B deploy",
"deploy-local": "make -B deploy-local",
"deploy-sepolia": "make -B deploy-sepolia",
"doc": "forge doc --serve --port 4000",
"lint-staged": "lint-staged",
"prepack": "npm run clean && npm run build",
Expand Down
38 changes: 18 additions & 20 deletions script/DeployBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ pragma solidity 0.8.26;

import { ContractHelper } from "../lib/common/src/libs/ContractHelper.sol";

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

contract DeployBase {
/**
* @dev Deploys Wrapped M Token.
* @dev Deploys Smart 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 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.
* @return smartMTokenImplementation_ The address of the deployed Smart M Token implementation.
* @return smartMTokenProxy_ The address of the deployed Smart M Token proxy.
*/
function deploy(
address mToken_,
Expand All @@ -31,24 +31,24 @@ contract DeployBase {
returns (
address earnerManagerImplementation_,
address earnerManagerProxy_,
address wrappedMTokenImplementation_,
address wrappedMTokenProxy_
address smartMTokenImplementation_,
address smartMTokenProxy_
)
{
// 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_`.
// Smart M Token Implementation constructor needs `earnerManagerProxy_`.
// Smart M Token Proxy constructor needs `smartMTokenImplementation_`.

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

earnerManagerProxy_ = address(new Proxy(earnerManagerImplementation_));

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

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

function _getExpectedEarnerManager(address deployer_, uint256 deployerNonce_) internal pure returns (address) {
Expand All @@ -70,34 +70,32 @@ contract DeployBase {
return _getExpectedEarnerManagerProxy(deployer_, deployerNonce_);
}

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

function getExpectedWrappedMTokenImplementation(
function getExpectedSmartMTokenImplementation(
address deployer_,
uint256 deployerNonce_
) public pure virtual returns (address) {
return _getExpectedWrappedMTokenImplementation(deployer_, deployerNonce_);
return _getExpectedSmartMTokenImplementation(deployer_, deployerNonce_);
}

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

function getExpectedWrappedMTokenProxy(
function getExpectedSmartMTokenProxy(
address deployer_,
uint256 deployerNonce_
) public pure virtual returns (address) {
return _getExpectedWrappedMTokenProxy(deployer_, deployerNonce_);
return _getExpectedSmartMTokenProxy(deployer_, deployerNonce_);
}

function getDeployerNonceAfterWrappedMTokenDeployment(
uint256 deployerNonce_
) public pure virtual returns (uint256) {
function getDeployerNonceAfterSmartMTokenDeployment(uint256 deployerNonce_) public pure virtual returns (uint256) {
return deployerNonce_ + 4;
}
}
22 changes: 11 additions & 11 deletions script/DeployProduction.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ 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 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 Smart M Token Proxy.
address internal constant _EXPECTED_SMART_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);
Expand All @@ -54,10 +54,10 @@ contract DeployProduction is Script, DeployBase {

if (currentNonce_ >= _DEPLOYER_PROXY_NONCE - 1) revert DeployerNonceTooHigh();

address expectedProxy_ = getExpectedWrappedMTokenProxy(deployer_, _DEPLOYER_PROXY_NONCE);
address expectedProxy_ = getExpectedSmartMTokenProxy(deployer_, _DEPLOYER_PROXY_NONCE);

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

vm.startBroadcast(deployer_);

Expand All @@ -74,19 +74,19 @@ contract DeployProduction is Script, DeployBase {
(
address earnerManagerProxy_,
address earnerManagerImplementation_,
address wrappedMTokenImplementation_,
address wrappedMTokenProxy_
address smartMTokenImplementation_,
address smartMTokenProxy_
) = deploy(_M_TOKEN, _REGISTRAR, _EXCESS_DESTINATION, _MIGRATION_ADMIN);

vm.stopBroadcast();

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_);
console2.log("Smart M Implementation address:", smartMTokenImplementation_);
console2.log("Smart M Proxy address:", smartMTokenProxy_);

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

if (earnerManagerProxy_ != _EXPECTED_EARNER_MANAGER_PROXY) {
Expand Down
Loading

0 comments on commit aac5bf4

Please sign in to comment.