-
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 #1
Fix Review #1
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.
|
||
amountIn = scaledAmountIn / tokenPrecisionMultipliers[tokenIn]; | ||
amountIn = scaledAmountInWithExitContribution / tokenPrecisionMultipliers[tokenIn]; |
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 +307,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 +424,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
@@ -190,21 +195,31 @@ contract GoodDollarExchangeProvider is IGoodDollarExchangeProvider, BancorExchan | |||
/** | |||
* @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 +176,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
Fix Review of
Repo:
mento-protocol/mento-core
Commit Hash:
f4e3b950b4beea4f94fd0dcd0b7170c4e86f9cf7