-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fix Review #2
base: main
Are you sure you want to change the base?
Fix Review #2
Conversation
|
||
if (tokenIn == exchange.tokenAddress) { | ||
require(scaledAmountIn < exchange.tokenSupply, "amountIn is greater than tokenSupply"); | ||
// apply exit contribution | ||
scaledAmountIn = (scaledAmountIn * (MAX_WEIGHT - exchange.exitContribution)) / MAX_WEIGHT; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#557.
|
||
if (tokenIn == exchange.tokenAddress) { | ||
// apply exit contribution | ||
scaledAmountIn = (scaledAmountIn * MAX_WEIGHT) / (MAX_WEIGHT - exchange.exitContribution); | ||
require(scaledAmountIn < exchange.tokenSupply, "amountIn is greater than tokenSupply"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#557.
PoolExchange memory exchange = getPoolExchange(exchangeId); | ||
uint256 scaledReserveRatio = uint256(exchange.reserveRatio) * 1e10; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#560.
Fixes issues: #23
uint256 priceScaled = unwrap(wrap(exchange.reserveBalance).div(denominator)); | ||
|
||
price = priceScaled / tokenPrecisionMultipliers[exchange.reserveAsset]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#560.
Fixes issues: #23
@@ -165,9 +180,9 @@ contract BancorExchangeProvider is IExchangeProvider, IBancorExchangeProvider, B | |||
|
|||
/// @inheritdoc IBancorExchangeProvider | |||
function setReserve(address _reserve) public onlyOwner { | |||
require(address(_reserve) != address(0), "Reserve address must be set"); | |||
require(_reserve != address(0), "Reserve address must be set"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#545.
Fixes issues: #79
reserve = IReserve(_reserve); | ||
emit ReserveUpdated(address(_reserve)); | ||
emit ReserveUpdated(_reserve); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#545.
Fixes issues: #79
uint256 exitContribution = 0; | ||
|
||
if (tokenIn == exchange.tokenAddress) { | ||
require(scaledAmountIn < exchange.tokenSupply, "amountIn is greater than tokenSupply"); | ||
// apply exit contribution | ||
exitContribution = (scaledAmountIn * exchange.exitContribution) / MAX_WEIGHT; | ||
scaledAmountIn -= exitContribution; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#557.
uint256 scaledAmountOut = _getScaledAmountOut(exchange, tokenIn, tokenOut, scaledAmountIn); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#557.
if (exitContribution > 0) { | ||
_accountExitContribution(exchangeId, exitContribution); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#557.
|
||
uint256 exitContribution = 0; | ||
uint256 scaledAmountInWithExitContribution = scaledAmountIn; | ||
|
||
if (tokenIn == exchange.tokenAddress) { | ||
// apply exit contribution | ||
scaledAmountInWithExitContribution = (scaledAmountIn * MAX_WEIGHT) / (MAX_WEIGHT - exchange.exitContribution); | ||
require( | ||
scaledAmountInWithExitContribution < exchange.tokenSupply, | ||
"amountIn required is greater than tokenSupply" | ||
); | ||
exitContribution = scaledAmountInWithExitContribution - scaledAmountIn; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#557.
if (exitContribution > 0) { | ||
_accountExitContribution(exchangeId, exitContribution); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#557.
@@ -262,7 +310,7 @@ contract BancorExchangeProvider is IExchangeProvider, IBancorExchangeProvider, B | |||
|
|||
function _setExitContribution(bytes32 exchangeId, uint32 exitContribution) internal { | |||
require(exchanges[exchangeId].reserveAsset != address(0), "Exchange does not exist"); | |||
require(exitContribution <= MAX_WEIGHT, "Exit contribution is too high"); | |||
require(exitContribution < MAX_WEIGHT, "Exit contribution is too high"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#549.
Fixes issues: #55
/** | ||
* @notice Accounting of exit contribution on a swap. | ||
* @dev Accounting of exit contribution without changing the current price of an exchange. | ||
* this is done by updating the reserve ratio and subtracting the exit contribution from the token supply. | ||
* Formula: newRatio = (Supply * oldRatio) / (Supply - exitContribution) | ||
* @param exchangeId The ID of the pool | ||
* @param exitContribution The amount of the token to be removed from the pool, scaled to 18 decimals | ||
*/ | ||
function _accountExitContribution(bytes32 exchangeId, uint256 exitContribution) internal { | ||
PoolExchange memory exchange = getPoolExchange(exchangeId); | ||
uint256 scaledReserveRatio = uint256(exchange.reserveRatio) * 1e10; | ||
UD60x18 nominator = wrap(exchange.tokenSupply).mul(wrap(scaledReserveRatio)); | ||
UD60x18 denominator = wrap(exchange.tokenSupply - exitContribution); | ||
UD60x18 newRatioScaled = nominator.div(denominator); | ||
|
||
uint256 newRatio = unwrap(newRatioScaled) / 1e10; | ||
|
||
exchanges[exchangeId].reserveRatio = uint32(newRatio); | ||
exchanges[exchangeId].tokenSupply -= exitContribution; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#557.
@@ -362,6 +437,7 @@ contract BancorExchangeProvider is IExchangeProvider, IBancorExchangeProvider, B | |||
require(exchange.reserveRatio > 1, "Reserve ratio is too low"); | |||
require(exchange.reserveRatio <= MAX_WEIGHT, "Reserve ratio is too high"); | |||
require(exchange.exitContribution <= MAX_WEIGHT, "Exit contribution is too high"); | |||
require(exchange.reserveBalance > 0, "Reserve balance must be greater than 0"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#558.
Fixes issues: #57
|
||
// The division and multiplication by 1e10 here ensures that the new ratio used for calculating the amount to mint | ||
// is the same as the one set in the exchange but only scaled to 18 decimals. | ||
// Ignored, because the division and multiplication by 1e10 is needed see comment above. | ||
// slither-disable-next-line divide-before-multiply | ||
UD60x18 newRatio = wrap((unwrap(scaledRatio.mul(wrap(reserveRatioScalar))) / 1e10) * 1e10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#548.
Fixes issues: #21
|
||
return amountToMint; | ||
} | ||
|
||
/** | ||
* @inheritdoc IGoodDollarExchangeProvider | ||
* @dev Calculates the new reserve ratio needed to mint the G$ reward while keeping the current price the same. | ||
* calculation: newRatio = reserveBalance / (tokenSupply + reward) * currentPrice | ||
* calculation: newRatio = (tokenSupply * reserveRatio) / (tokenSupply + reward) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
function updateRatioForReward( | ||
bytes32 exchangeId, | ||
uint256 reward, | ||
uint256 maxSlippagePercentage | ||
) external onlyExpansionController whenNotPaused { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
uint256 scaledRatio = uint256(exchange.reserveRatio) * 1e10; | ||
uint256 scaledReward = reward * tokenPrecisionMultipliers[exchange.tokenAddress]; | ||
|
||
UD60x18 numerator = wrap(exchange.tokenSupply).mul(wrap(scaledRatio)); | ||
UD60x18 denominator = wrap(exchange.tokenSupply).add(wrap(scaledReward)); | ||
uint256 newScaledRatio = unwrap(numerator.div(denominator)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
UD60x18 denominator = wrap(exchange.tokenSupply).add(wrap(scaledReward)); | ||
uint256 newScaledRatio = unwrap(numerator.div(denominator)); | ||
|
||
uint32 newRatioUint = uint32(newScaledRatio / 1e10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
require(newRatioUint > 0, "New ratio must be greater than 0"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#544.
Fixes issues: #29
uint256 allowedSlippage = (exchange.reserveRatio * maxSlippagePercentage) / MAX_WEIGHT; | ||
require(exchange.reserveRatio - newRatioUint <= allowedSlippage, "Slippage exceeded"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
exchanges[exchangeId].reserveRatio = newRatioUint; | ||
exchanges[exchangeId].tokenSupply += rewardScaled; | ||
exchanges[exchangeId].tokenSupply += scaledReward; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
@@ -5,24 +5,27 @@ import { IGoodDollarExpansionController } from "contracts/interfaces/IGoodDollar | |||
import { IGoodDollarExchangeProvider } from "contracts/interfaces/IGoodDollarExchangeProvider.sol"; | |||
import { IBancorExchangeProvider } from "contracts/interfaces/IBancorExchangeProvider.sol"; | |||
import { IERC20 } from "openzeppelin-contracts-next/contracts/token/ERC20/IERC20.sol"; | |||
import { IERC20Metadata } from "openzeppelin-contracts-next/contracts/token/ERC20/extensions/IERC20Metadata.sol"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#551.
Fixes issues: #7
import { OwnableUpgradeable } from "openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol"; | ||
import { unwrap, wrap, powu } from "prb/math/UD60x18.sol"; | ||
|
||
/** | ||
* @title GoodDollarExpansionController | ||
* @notice Provides functionality to expand the supply of GoodDollars. | ||
*/ | ||
contract GoodDollarExpansionController is IGoodDollarExpansionController, PausableUpgradeable, OwnableUpgradeable { | ||
contract GoodDollarExpansionController is IGoodDollarExpansionController, OwnableUpgradeable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#552.
Fixes issues: #49
// EXPANSION_MAX_WEIGHT is the max rate that can be assigned to an exchange | ||
uint256 public constant EXPANSION_MAX_WEIGHT = 1e18; | ||
|
||
// BANCOR_MAX_WEIGHT is used for BPS calculations in GoodDollarExchangeProvider | ||
uint32 public constant BANCOR_MAX_WEIGHT = 1e8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
@@ -123,7 +125,7 @@ contract GoodDollarExpansionController is IGoodDollarExpansionController, Pausab | |||
|
|||
/// @inheritdoc IGoodDollarExpansionController | |||
function setExpansionConfig(bytes32 exchangeId, uint64 expansionRate, uint32 expansionFrequency) external onlyAvatar { | |||
require(expansionRate < MAX_WEIGHT, "Expansion rate must be less than 100%"); | |||
require(expansionRate < EXPANSION_MAX_WEIGHT, "Expansion rate must be less than 100%"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
uint256 contractReserveBalance = IERC20(exchange.reserveAsset).balanceOf(reserve) * | ||
(10 ** (18 - IERC20Metadata(exchange.reserveAsset).decimals())); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#551.
Fixes issues: #7
@@ -172,11 +178,10 @@ contract GoodDollarExpansionController is IGoodDollarExpansionController, Pausab | |||
.getPoolExchange(exchangeId); | |||
ExchangeExpansionConfig memory config = getExpansionConfig(exchangeId); | |||
|
|||
bool shouldExpand = block.timestamp > config.lastExpansion + config.expansionFrequency; | |||
bool shouldExpand = block.timestamp >= config.lastExpansion + config.expansionFrequency; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#553.
Fixes issues: #50
if (shouldExpand || config.lastExpansion == 0) { | ||
uint256 reserveRatioScalar = _getReserveRatioScalar(config); | ||
uint256 reserveRatioScalar = _getReserveRatioScalar(exchangeId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#553.
Fixes issues: #50
uint32 expectedReserveRatio = 28571423; | ||
uint256 priceBefore = exchangeProvider.currentPrice(exchangeId); | ||
|
||
vm.expectEmit(true, true, true, true); | ||
emit ReserveRatioUpdated(exchangeId, expectedReserveRatio); | ||
vm.prank(expansionControllerAddress); | ||
exchangeProvider.updateRatioForReward(exchangeId, reward); | ||
exchangeProvider.updateRatioForReward(exchangeId, reward, 1e8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
// formula newRatio = (tokenSupply * reserveRatio) / (tokenSupply + reward) | ||
// formula: newRatio = (7_000_000_000 * 0.28571428) / (7_000_000_000 + 1) = 0.28571427 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
uint32 expectedReserveRatio = 28571427; | ||
uint256 priceBefore = exchangeProvider.currentPrice(exchangeId); | ||
|
||
vm.expectEmit(true, true, true, true); | ||
emit ReserveRatioUpdated(exchangeId, expectedReserveRatio); | ||
vm.prank(expansionControllerAddress); | ||
exchangeProvider.updateRatioForReward(exchangeId, reward); | ||
exchangeProvider.updateRatioForReward(exchangeId, _reward, 1e8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
// formula newRatio = (tokenSupply * reserveRatio) / (tokenSupply + reward) | ||
// formula: newRatio = (7_000_000_000 * 0.28571428) / (7_000_000_000 + 1_000_000_000) = 0.249999995 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
|
||
uint32 expectedReserveRatio = 24999999; | ||
uint256 priceBefore = exchangeProvider.currentPrice(exchangeId); | ||
|
||
vm.expectEmit(true, true, true, true); | ||
emit ReserveRatioUpdated(exchangeId, expectedReserveRatio); | ||
vm.prank(expansionControllerAddress); | ||
exchangeProvider.updateRatioForReward(exchangeId, reward); | ||
exchangeProvider.updateRatioForReward(exchangeId, _reward, 1e8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
function test_updateRatioForReward_whenSlippageIsHigherThanAccepted_shouldRevert() public { | ||
uint256 _reward = 1_000_000_000 * 1e18; // 1 billion tokens | ||
// formula newRatio = (tokenSupply * reserveRatio) / (tokenSupply + reward) | ||
// formula: newRatio = (7_000_000_000 * 0.28571428) / (7_000_000_000 + 1_000_000_000) = 0.249999995 | ||
// slippage = (newRatio - reserveRatio) / reserveRatio = (0.249999995 - 0.28571428) / 0.28571428 ~= -0.125 | ||
|
||
uint32 expectedReserveRatio = 24999999; | ||
|
||
vm.prank(expansionControllerAddress); | ||
vm.expectRevert("Slippage exceeded"); | ||
exchangeProvider.updateRatioForReward(exchangeId, _reward, 12 * 1e6); | ||
|
||
vm.expectEmit(true, true, true, true); | ||
emit ReserveRatioUpdated(exchangeId, expectedReserveRatio); | ||
vm.prank(expansionControllerAddress); | ||
exchangeProvider.updateRatioForReward(exchangeId, _reward, 13 * 1e6); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
@@ -777,7 +802,7 @@ contract GoodDollarExchangeProviderTest_updateRatioForReward is GoodDollarExchan | |||
|
|||
vm.startPrank(expansionControllerAddress); | |||
for (uint256 i = 0; i < 5; i++) { | |||
exchangeProvider.updateRatioForReward(exchangeId, reward); | |||
exchangeProvider.updateRatioForReward(exchangeId, reward, 1e8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
@@ -805,7 +830,7 @@ contract GoodDollarExchangeProviderTest_updateRatioForReward is GoodDollarExchan | |||
uint256 priceBefore = exchangeProvider.currentPrice(exchangeId); | |||
|
|||
vm.prank(expansionControllerAddress); | |||
exchangeProvider.updateRatioForReward(exchangeId, fuzzedReward); | |||
exchangeProvider.updateRatioForReward(exchangeId, fuzzedReward, 1e8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
@@ -870,7 +895,7 @@ contract GoodDollarExchangeProviderTest_pausable is GoodDollarExchangeProviderTe | |||
exchangeProvider.mintFromInterest(exchangeId, 1e18); | |||
|
|||
vm.expectRevert("Pausable: paused"); | |||
exchangeProvider.updateRatioForReward(exchangeId, 1e18); | |||
exchangeProvider.updateRatioForReward(exchangeId, 1e18, 100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
@@ -891,6 +916,6 @@ contract GoodDollarExchangeProviderTest_pausable is GoodDollarExchangeProviderTe | |||
|
|||
exchangeProvider.mintFromExpansion(exchangeId, 1e18); | |||
exchangeProvider.mintFromInterest(exchangeId, 1e18); | |||
exchangeProvider.updateRatioForReward(exchangeId, 1e18); | |||
exchangeProvider.updateRatioForReward(exchangeId, 1e18, 1e8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
@@ -5,12 +5,15 @@ pragma solidity 0.8.18; | |||
|
|||
import { Test } from "forge-std/Test.sol"; | |||
import { ERC20Mock } from "openzeppelin-contracts-next/contracts/mocks/ERC20Mock.sol"; | |||
import { ERC20DecimalsMock } from "openzeppelin-contracts-next/contracts/mocks/ERC20DecimalsMock.sol"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#551.
Fixes issues: #7
function test_mintUBIFromReserveBalance_whenReserveAssetDecimalsIsLessThan18_shouldScaleCorrectly() public { | ||
ERC20DecimalsMock reserveToken6DecimalsMock = new ERC20DecimalsMock("Reserve Token", "RES", 6); | ||
IBancorExchangeProvider.PoolExchange memory pool2 = IBancorExchangeProvider.PoolExchange({ | ||
reserveAsset: address(reserveToken6DecimalsMock), | ||
tokenAddress: address(token), | ||
tokenSupply: 7 * 1e9 * 1e18, | ||
reserveBalance: 200_000 * 1e18, // internally scaled to 18 decimals | ||
reserveRatio: 0.2 * 1e8, // 20% | ||
exitContribution: 0.1 * 1e8 // 10% | ||
}); | ||
|
||
uint256 reserveInterest = 1000e6; | ||
deal(address(reserveToken6DecimalsMock), reserveAddress, 200_000 * 1e6 + reserveInterest); | ||
|
||
vm.mockCall( | ||
address(exchangeProvider), | ||
abi.encodeWithSelector(IBancorExchangeProvider(exchangeProvider).getPoolExchange.selector, exchangeId), | ||
abi.encode(pool2) | ||
); | ||
|
||
vm.expectCall( | ||
address(exchangeProvider), | ||
abi.encodeWithSelector( | ||
IGoodDollarExchangeProvider(exchangeProvider).mintFromInterest.selector, | ||
exchangeId, | ||
reserveInterest * 1e12 | ||
) | ||
); | ||
expansionController.mintUBIFromReserveBalance(exchangeId); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#551.
Fixes issues: #7
@@ -370,16 +404,15 @@ contract GoodDollarExpansionControllerTest_mintUBIFromExpansion is GoodDollarExp | |||
expansionController.mintUBIFromExpansion("NotSetExchangeId"); | |||
} | |||
|
|||
function test_mintUBIFromExpansion_whenShouldNotExpand_shouldNotExpand() public { | |||
function test_mintUBIFromExpansion_whenLessThanExpansionFrequencyPassed_shouldNotExpand() public { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#553.
Fixes issues: #50
// doing one initial expansion to not be first expansion | ||
// since on first expansion the expansion is always applied once. | ||
expansionController.mintUBIFromExpansion(exchangeId); | ||
|
||
IGoodDollarExpansionController.ExchangeExpansionConfig memory config = expansionController.getExpansionConfig( | ||
exchangeId | ||
); | ||
uint256 lastExpansion = config.lastExpansion; | ||
skip(lastExpansion + config.expansionFrequency - 1); | ||
skip(config.expansionFrequency - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#553.
Fixes issues: #50
@@ -465,14 +498,11 @@ contract GoodDollarExpansionControllerTest_mintUBIFromExpansion is GoodDollarExp | |||
// 1 day has passed since last expansion and expansion rate is 1% so the rate passed to the exchangeProvider | |||
// should be 0.99^1 = 0.99 | |||
uint256 reserveRatioScalar = 1e18 * 0.99; | |||
skip(expansionFrequency + 1); | |||
skip(expansionFrequency); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#553.
Fixes issues: #50
vm.expectEmit(true, true, true, true); | ||
emit ExpansionUBIMinted(exchangeId, amountToMint); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#553.
Fixes issues: #50
@@ -496,7 +529,7 @@ contract GoodDollarExpansionControllerTest_mintUBIFromExpansion is GoodDollarExp | |||
assertEq(config.lastExpansion, block.timestamp); | |||
} | |||
|
|||
function test_mintUBIFromExpansion_whenMultipleDaysPassed_shouldCalculateCorrectRateAndExpand() public { | |||
function test_mintUBIFromExpansion_whenThreeAndAHalfDaysPassed_shouldMintCorrectAmountAndSetLastExpansion() public { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#553.
Fixes issues: #50
IGoodDollarExpansionController.ExchangeExpansionConfig memory stateBefore = expansionController.getExpansionConfig( | ||
exchangeId | ||
); | ||
|
||
// 3.5 days have passed since last expansion | ||
skip((7 * expansionFrequency) / 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#553.
Fixes issues: #50
@@ -533,7 +571,7 @@ contract GoodDollarExpansionControllerTest_mintUBIFromExpansion is GoodDollarExp | |||
|
|||
assertEq(amountMinted, amountToMint); | |||
assertEq(token.balanceOf(distributionHelper), distributionHelperBalanceBefore + amountToMint); | |||
assertEq(config.lastExpansion, block.timestamp); | |||
assertEq(config.lastExpansion, stateBefore.lastExpansion + expansionFrequency * 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#553.
Fixes issues: #50
@@ -543,18 +581,14 @@ contract GoodDollarExpansionControllerTest_getExpansionScalar is GoodDollarExpan | |||
function setUp() public override { | |||
super.setUp(); | |||
expansionController = new GoodDollarExpansionControllerHarness(false); | |||
expansionController.initialize(exchangeProvider, distributionHelper, reserveAddress, avatarAddress); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#553.
Fixes issues: #50
function test_getExpansionScaler_whenStepReserveRatioScalerIs1_shouldReturn1() public { | ||
vm.prank(avatarAddress); | ||
expansionController.setExpansionConfig(exchangeId, 1e18 - 1, 1); | ||
// stepReserveRatioScalar is 1e18 - expansionRate = 1e18 - (1e18 - 1) = 1 | ||
assertEq(expansionController.exposed_getReserveRatioScalar(exchangeId), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#553.
Fixes issues: #50
vm.prank(avatarAddress); | ||
expansionController.setExpansionConfig(exchangeId, expansionRate, expansionFrequency); | ||
expansionController.setLastExpansion(exchangeId, lastExpansion); | ||
uint256 scaler = expansionController.exposed_getReserveRatioScalar(exchangeId); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#553.
Fixes issues: #50
function test_mintRewardFromReserveRatio_whenSlippageIsGreaterThan100_shouldRevert() public { | ||
vm.prank(avatarAddress); | ||
vm.expectRevert("Max slippage percentage cannot be greater than 100%"); | ||
expansionController.mintRewardFromReserveRatio(exchangeId, makeAddr("To"), 1000e18, 1e8 + 1); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
|
||
function test_mintRewardFromReserveRatio_whenCustomSlippage_shouldMintAndEmit() public { | ||
uint256 amountToMint = 1000e18; | ||
address to = makeAddr("To"); | ||
uint256 toBalanceBefore = token.balanceOf(to); | ||
|
||
vm.expectEmit(true, true, true, true); | ||
emit RewardMinted(exchangeId, to, amountToMint); | ||
|
||
vm.prank(avatarAddress); | ||
expansionController.mintRewardFromReserveRatio(exchangeId, to, amountToMint, 1); | ||
|
||
assertEq(token.balanceOf(to), toBalanceBefore + amountToMint); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#554.
Fixes issues: #59
function test_update_withZeroDeltaFlow_doesNotUpdate() public { | ||
state = harness.update(state, configL0L1LG(300, 1000, 1 days, 10000, 1000000), 0, 18); | ||
assertEq(state.netflow0, 0); | ||
assertEq(state.netflow1, 0); | ||
assertEq(state.netflowGlobal, 0); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#550.
Fixes issues: #76
function test_update_withTooSmallAmount_reverts() public { | ||
int256 tooSmall = (type(int48).min - int256(1)) * 1e18; | ||
vm.expectRevert(bytes("dFlow too small")); | ||
state = harness.update(state, configLG(500000), tooSmall, 18); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#547.
Fixes issues: #44
function test_update_withOverflowOnAdd_reverts() public { | ||
ITradingLimits.Config memory config = configLG(int48(uint48(2 ** 47))); | ||
int256 maxFlow = int256(uint256(type(uint48).max / 2)); | ||
int256 maxFlow = int256(type(int48).max); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#556.
Fixes issues: #46
state = harness.update(state, config, 1000 * 1e18, 18); | ||
|
||
vm.expectRevert(bytes("int48 addition overflow")); | ||
state = harness.update(state, config, 1 * 1e18, 18); | ||
} | ||
|
||
function test_update_withUnderflowOnAdd_reverts() public { | ||
ITradingLimits.Config memory config = configLG(int48(uint48(2 ** 47))); | ||
int256 minFlow = int256(type(int48).min); | ||
|
||
state = harness.update(state, config, (minFlow + 1000) * 1e18, 18); | ||
state = harness.update(state, config, -1000 * 1e18, 18); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#556.
Fixes issues: #46
vm.expectRevert(bytes("int48 addition overflow")); | ||
state = harness.update(state, config, 1002 * 10e18, 18); | ||
state = harness.update(state, config, -1 * 1e18, 18); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#556.
Fixes issues: #46
function exposed_getReserveRatioScalar(bytes32 exchangeId) external returns (uint256) { | ||
return _getReserveRatioScalar(exchangeId); | ||
} | ||
|
||
function setLastExpansion(bytes32 exchangeId, uint32 lastExpansion) external { | ||
exchangeExpansionConfigs[exchangeId].lastExpansion = lastExpansion; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to mento-protocol/mento-core#553.
Fixes issues: #50
Fix Review of
Repo:
mento-protocol/mento-core
Commit Hash:
20fc515c055dcf44f68c0bbbb3dec223be6bea2a