Skip to content

Commit

Permalink
fix: empty RateModel bug (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
deluca-mike authored Dec 12, 2023
1 parent 9cc2e1d commit d8d3a9e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/MToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ contract MToken is IMToken, ContinuousIndexing, ERC20Permit {
abi.encodeWithSelector(IRateModel.rate.selector)
);

rate_ = success_ ? abi.decode(returnData_, (uint256)) : 0;
rate_ = (success_ && returnData_.length >= 32) ? abi.decode(returnData_, (uint256)) : 0;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Protocol.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ContinuousIndexing } from "./ContinuousIndexing.sol";
/**
* @title Protocol
* @author M^ZERO LABS_
* @notice Core protocol of M^ZERO ecosystem.
* @notice Core protocol of M^ZERO ecosystem.
Minting Gateway of M Token for all approved by SPOG and activated minters.
*/
contract Protocol is IProtocol, ContinuousIndexing, ERC712 {
Expand Down Expand Up @@ -704,7 +704,7 @@ contract Protocol is IProtocol, ContinuousIndexing, ERC712 {
abi.encodeWithSelector(IRateModel.rate.selector)
);

rate_ = success_ ? abi.decode(returnData_, (uint256)) : 0;
rate_ = (success_ && returnData_.length >= 32) ? abi.decode(returnData_, (uint256)) : 0;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions test/MToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,10 @@ contract MTokenTests is Test {

assertEq(_mToken.hasOptedOutOfEarning(_alice), true);
}

function test_emptyRateModel() external {
_registrar.updateConfig(SPOGRegistrarReader.EARNER_RATE_MODEL, address(0));

assertEq(_mToken.rate(), 0);
}
}
6 changes: 6 additions & 0 deletions test/Protocol.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,12 @@ contract ProtocolTests is Test {
assertEq(_protocol.collateralUpdateOf(_minter1), block.timestamp);
}

function test_emptyRateModel() external {
_spogRegistrar.updateConfig(SPOGRegistrarReader.MINTER_RATE_MODEL, address(0));

assertEq(_protocol.rate(), 0);
}

function _getCollateralUpdateSignature(
address minter,
uint256 collateral,
Expand Down
4 changes: 4 additions & 0 deletions test/utils/MTokenHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ contract MTokenHarness is MToken {
function totalPrincipalOfEarningSupply() external view returns (uint256 totalPrincipalOfEarningSupply_) {
return _totalPrincipalOfEarningSupply;
}

function rate() external view returns (uint256 rate_) {
return _rate();
}
}
4 changes: 4 additions & 0 deletions test/utils/ProtocolHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ contract ProtocolHarness is Protocol {
function principalOfActiveOwedMOf(address minter_) external view returns (uint256 principalOfActiveOwedM_) {
return _principalOfActiveOwedM[minter_];
}

function rate() external view returns (uint256 rate_) {
return _rate();
}
}

0 comments on commit d8d3a9e

Please sign in to comment.