Skip to content

Commit

Permalink
refactor: cleanup and optimize (m0-foundation#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
deluca-mike authored Apr 15, 2024
1 parent 466ccca commit 44784c6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
14 changes: 9 additions & 5 deletions src/MinterGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ contract MinterGateway is IMinterGateway, ContinuousIndexing, ERC712Extended {
) public returns (uint112 principalAmount_, uint240 amount_) {
if (maxPrincipalAmount_ == 0 || maxAmount_ == 0) revert ZeroBurnAmount();

MinterState memory minterState_ = _minterStates[minter_];
MinterState storage minterState_ = _minterStates[minter_];
bool isActive_ = minterState_.isActive;

// Revert early if minter has not been activated.
Expand Down Expand Up @@ -396,9 +396,12 @@ contract MinterGateway is IMinterGateway, ContinuousIndexing, ERC712Extended {
/// @inheritdoc IMinterGateway
function activateMinter(address minter_) external {
if (!isMinterApproved(minter_)) revert NotApprovedMinter();
if (_minterStates[minter_].isDeactivated) revert DeactivatedMinter();

_minterStates[minter_].isActive = true;
MinterState storage minterState_ = _minterStates[minter_];

if (minterState_.isDeactivated) revert DeactivatedMinter();

minterState_.isActive = true;

emit MinterActivated(minter_, msg.sender);
}
Expand Down Expand Up @@ -549,8 +552,9 @@ contract MinterGateway is IMinterGateway, ContinuousIndexing, ERC712Extended {
// If collateral was not updated by the deadline, assume that minter's collateral is zero.
if (block.timestamp >= collateralExpiryTimestampOf(minter_)) return 0;

uint240 totalPendingRetrievals_ = _minterStates[minter_].totalPendingRetrievals;
uint240 collateral_ = _minterStates[minter_].collateral;
MinterState storage minterState_ = _minterStates[minter_];
uint240 totalPendingRetrievals_ = minterState_.totalPendingRetrievals;
uint240 collateral_ = minterState_.collateral;

// If the minter's total pending retrievals is greater than their collateral, then their collateral is zero.
if (totalPendingRetrievals_ >= collateral_) return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IMinterGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ interface IMinterGateway is IContinuousIndexing, IERC712 {
) external returns (uint40 minTimestamp);

/**
* @notice Proposes retrieval of minter's offchain collateral
* @notice Proposes retrieval of minter's off-chain collateral
* @param collateral The amount of collateral to retrieve
* @return retrievalId The unique id of created retrieval proposal
*/
Expand Down
26 changes: 13 additions & 13 deletions src/libs/TTGRegistrarReader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@ library TTGRegistrarReader {
/// @notice The name of parameter in TTG that defines the earner rate model contract.
bytes32 internal constant EARNER_RATE_MODEL = "earner_rate_model";

/// @notice The earners list name in TTG.
/// @notice The parameter name in TTG that defines the earners list.
bytes32 internal constant EARNERS_LIST = "earners";

/// @notice The ignore earners list flag name in TTG.
/// @notice The parameter name in TTG that defines whether to ignore the earners list or not.
bytes32 internal constant EARNERS_LIST_IGNORED = "earners_list_ignored";

/// @notice The name of parameter in TTG that defines the time to wait for mint request to be processed
/// @notice The parameter name in TTG that defines the time to wait for mint request to be processed.
bytes32 internal constant MINT_DELAY = "mint_delay";

/// @notice The name of parameter in TTG that defines the mint ratio.
/// @notice The parameter name in TTG that defines the mint ratio.
bytes32 internal constant MINT_RATIO = "mint_ratio"; // bps

/// @notice The name of parameter in TTG that defines the time while mint request can still be processed
/// @notice The parameter name in TTG that defines the time while mint request can still be processed.
bytes32 internal constant MINT_TTL = "mint_ttl";

/// @notice The name of parameter in TTG that defines the time to freeze minter
/// @notice The parameter name in TTG that defines the time to freeze minter.
bytes32 internal constant MINTER_FREEZE_TIME = "minter_freeze_time";

/// @notice The name of parameter in TTG that defines the minter rate model contract.
/// @notice The parameter name in TTG that defines the minter rate model contract.
bytes32 internal constant MINTER_RATE_MODEL = "minter_rate_model";

/// @notice The minters list name in TTG.
/// @notice The parameter name in TTG that defines the minters list.
bytes32 internal constant MINTERS_LIST = "minters";

/// @notice The name of parameter in TTG that defines the penalty rate.
bytes32 internal constant PENALTY_RATE = "penalty_rate";
/// @notice The parameter name in TTG that defines the penalty rate.
bytes32 internal constant PENALTY_RATE = "penalty_rate"; // bps

/// @notice The name of parameter in TTG that required interval to update collateral.
/// @notice The parameter name in TTG that defines the required interval to update collateral.
bytes32 internal constant UPDATE_COLLATERAL_INTERVAL = "update_collateral_interval";

/// @notice The name of parameter that defines number of signatures required for successful collateral update
/// @notice The parameter name that defines number of signatures required for successful collateral update.
bytes32 internal constant UPDATE_COLLATERAL_VALIDATOR_THRESHOLD = "update_collateral_threshold";

/// @notice The validators list name in TTG.
/// @notice The parameter name in TTG that defines the validators list.
bytes32 internal constant VALIDATORS_LIST = "validators";

/* ============ Internal View/Pure Functions ============ */
Expand Down
11 changes: 9 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,18 @@ else
verbosity="-vvvv"
fi

if [ "$gas" = false ];
then
gasReport=""
else
gasReport="--gas-report"
fi

if [ -z "$test" ]; then
if [ -z "$directory" ]; then
forge test --match-path "test/*" $gasReport
forge test --match-path "test/*" $gasReport $verbosity
else
forge test --match-path "$directory/*.t.sol" $gasReport
forge test --match-path "$directory/*.t.sol" $gasReport $verbosity
fi
else
forge test --match-test "$test" $gasReport $verbosity
Expand Down

0 comments on commit 44784c6

Please sign in to comment.