Skip to content

Commit

Permalink
Merge pull request m0-foundation#160 from MZero-Labs/feat/deploy-scri…
Browse files Browse the repository at this point in the history
…pt-fix

feat: Deploy script fix
  • Loading branch information
deluca-mike authored Mar 27, 2024
2 parents d2269da + b7b9f1b commit f4a13fb
Show file tree
Hide file tree
Showing 16 changed files with 363 additions and 309 deletions.
36 changes: 25 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
# coverage report
coverage :; forge coverage --report lcov && lcov --remove ./lcov.info -o ./lcov.info 'script/*' 'test/*' && genhtml lcov.info --branch-coverage --output-dir coverage
# include .env file and export its env vars
# (-include to ignore error if it does not exist)
-include .env

coverage-summary :; forge coverage --report summary
profile ?=default

# Deployment helpers
# Coverage report
coverage:
FOUNDRY_PROFILE=$(profile) forge coverage --no-match-path 'test/invariant/**/*.sol' --report lcov && lcov --extract lcov.info -o lcov.info 'src/*' && genhtml lcov.info -o coverage

coverage-summary:
FOUNDRY_PROFILE=$(profile) forge coverage --no-match-path 'test/invariant/**/*.sol' --report summary

deploy-local :; FOUNDRY_PROFILE=production forge script script/Deploy.s.sol --rpc-url localhost --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --broadcast -v
# Deployment helpers
deploy:
FOUNDRY_PROFILE=production forge script script/Deploy.s.sol --skip src --skip test --rpc-url mainnet --slow --broadcast -vvv

deploy-sepolia :; FOUNDRY_PROFILE=production forge script script/Deploy.s.sol --rpc-url sepolia --private-key ${ETH_PK} --broadcast -vvv
deploy-sepolia:
FOUNDRY_PROFILE=production forge script script/Deploy.s.sol --skip src --skip test --rpc-url sepolia --slow --broadcast -vvv

deploy-qa-sepolia :; FOUNDRY_PROFILE=production forge script script/Deploy.s.sol --rpc-url sepolia --broadcast -v
deploy-local:
FOUNDRY_PROFILE=production forge script script/Deploy.s.sol --skip src --skip test --rpc-url localhost --slow --broadcast -v

# Run slither
slither :; FOUNDRY_PROFILE=production forge build --build-info --skip '*/test/**' --skip '*/script/**' --force && slither --compile-force-framework foundry --ignore-compile --sarif results.sarif --config-file slither.config.json .
slither:
FOUNDRY_PROFILE=production forge build --build-info --skip '*/test/**' --skip '*/script/**' --force && slither --compile-force-framework foundry --ignore-compile --sarif results.sarif --config-file slither.config.json .

profile ?=default

# Common tasks
update:
forge update

build:
@./build.sh -p production

test:
tests:
@./test.sh -p $(profile)

fuzz:
Expand All @@ -32,7 +46,7 @@ invariant:
@./test.sh -d test/invariant -p $(profile)

gas-report:
forge test --no-match-path 'test/invariant/*' --gas-report > gasreport.ansi
FOUNDRY_PROFILE=$(profile) forge test --no-match-path 'test/invariant/*' --gas-report > gasreport.ansi

gas-report-hardhat:
npx hardhat test
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"author": "M^0 Labs <[email protected]>",
"license": "GPL-3.0",
"scripts": {
"coverage": "forge coverage --no-match-path 'test/invariant/**/*.sol' --report lcov && lcov --extract lcov.info -o lcov.info 'src/*' && genhtml lcov.info -o coverage",
"coverage": "make -B coverage",
"coverage-summary": "make -B coverage-summary",
"doc": "forge doc --serve --port 4000",
"prettier": "prettier --write --plugin=prettier-plugin-solidity 'script/**/*.sol' 'src/**/*.sol' 'test/**/*.sol'",
"slither": "forge build --build-info --skip '*/test/**' --skip '*/script/**' --force && slither --compile-force-framework foundry --ignore-compile --config-file slither.config.json --fail-high .",
Expand Down
28 changes: 22 additions & 6 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,34 @@

pragma solidity 0.8.23;

import { DeployBase } from "./DeployBase.s.sol";
import { Script, console2 } from "../lib/forge-std/src/Script.sol";

contract Deploy is DeployBase {
import { IMinterGateway } from "../src/interfaces/IMinterGateway.sol";

import { DeployBase } from "./DeployBase.sol";

contract Deploy is Script, DeployBase {
// NOTE: Ensure this is the correct TTG Registrar testnet/mainnet address.
address internal constant _TTG_REGISTRAR = 0x1EFeA064121f17379b267db17aCe135475514f8D;

// NOTE: Ensure this is the current nonce (transaction count) of the deploying address.
uint256 internal constant _DEPLOYER_NONCE = 0;

function run() external {
(address deployer_, ) = deriveRememberKey(vm.envString("MNEMONIC"), 0);

deploy(deployer_, _DEPLOYER_NONCE, _TTG_REGISTRAR);
console2.log("Deployer:", deployer_);

vm.startBroadcast(deployer_);

(address minterGateway_, address minterRateModel_, address earnerRateModel_) = deploy(
deployer_,
vm.getNonce(deployer_),
_TTG_REGISTRAR
);

vm.stopBroadcast();

console2.log("Minter Gateway address:", minterGateway_);
console2.log("M Token address:", IMinterGateway(minterGateway_).mToken());
console2.log("Earner Rate Model address:", earnerRateModel_);
console2.log("Minter Rate Model address:", minterRateModel_);
}
}
49 changes: 0 additions & 49 deletions script/DeployBase.s.sol

This file was deleted.

64 changes: 64 additions & 0 deletions script/DeployBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity 0.8.23;

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

import { MinterGateway } from "../src/MinterGateway.sol";
import { MToken } from "../src/MToken.sol";
import { StableEarnerRateModel } from "../src/rateModels/StableEarnerRateModel.sol";
import { MinterRateModel } from "../src/rateModels/MinterRateModel.sol";

contract DeployBase {
/**
* @dev Deploys TTG.
* @param deployer_ The address of the account deploying the contracts.
* @param deployerNonce_ The current nonce of the deployer.
* @param ttgRegistrar_ The address of the TTG Registrar.
* @return minterGateway_ The address of the deployed Minter Gateway.
* @return minterRateModel_ The address of the deployed Minter Rate Model.
* @return earnerRateModel_ The address of the deployed Earner Rate Model.
*/
function deploy(
address deployer_,
uint256 deployerNonce_,
address ttgRegistrar_
) public virtual returns (address minterGateway_, address minterRateModel_, address earnerRateModel_) {
// M token needs `minterGateway_` and `ttgRegistrar_` addresses.
// MinterGateway needs `ttgRegistrar_` and M token addresses and for `ttgRegistrar_` to be deployed.
// EarnerRateModel needs `minterGateway_` address and for `minterGateway_` to be deployed.
// MinterRateModel needs `ttgRegistrar_` address.

address mToken_ = address(new MToken(ttgRegistrar_, getExpectedMinterGateway(deployer_, deployerNonce_)));

minterGateway_ = address(new MinterGateway(ttgRegistrar_, mToken_));
minterRateModel_ = address(new MinterRateModel(ttgRegistrar_));
earnerRateModel_ = address(new StableEarnerRateModel(minterGateway_));
}

function getExpectedMToken(address deployer_, uint256 deployerNonce_) public pure virtual returns (address) {
return ContractHelper.getContractFrom(deployer_, deployerNonce_);
}

function getExpectedMinterGateway(address deployer_, uint256 deployerNonce_) public pure virtual returns (address) {
return ContractHelper.getContractFrom(deployer_, deployerNonce_ + 1);
}

function getExpectedMinterRateModel(
address deployer_,
uint256 deployerNonce_
) public pure virtual returns (address) {
return ContractHelper.getContractFrom(deployer_, deployerNonce_ + 2);
}

function getExpectedEarnerRateModel(
address deployer_,
uint256 deployerNonce_
) public pure virtual returns (address) {
return ContractHelper.getContractFrom(deployer_, deployerNonce_ + 3);
}

function getDeployerNonceAfterProtocolDeployment(uint256 deployerNonce_) public pure virtual returns (uint256) {
return deployerNonce_ + 4;
}
}
Loading

0 comments on commit f4a13fb

Please sign in to comment.