[audit]#3 simplify getExpectedTarget
This commit is contained in:
@@ -91,11 +91,7 @@ contract Pricing is Storage {
|
|||||||
return Q2.sub(quoteBalance);
|
return Q2.sub(quoteBalance);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _RBelowBackToOne()
|
function _RBelowBackToOne() internal view returns (uint256 payQuoteToken) {
|
||||||
internal
|
|
||||||
view
|
|
||||||
returns (uint256 payQuoteToken, uint256 receiveBaseToken)
|
|
||||||
{
|
|
||||||
// important: carefully design the system to make sure spareBase always greater than or equal to 0
|
// important: carefully design the system to make sure spareBase always greater than or equal to 0
|
||||||
uint256 spareBase = _BASE_BALANCE_.sub(_TARGET_BASE_TOKEN_AMOUNT_);
|
uint256 spareBase = _BASE_BALANCE_.sub(_TARGET_BASE_TOKEN_AMOUNT_);
|
||||||
uint256 price = getOraclePrice();
|
uint256 price = getOraclePrice();
|
||||||
@@ -105,7 +101,7 @@ contract Pricing is Storage {
|
|||||||
_K_,
|
_K_,
|
||||||
fairAmount
|
fairAmount
|
||||||
);
|
);
|
||||||
return (newTargetQuote.sub(_QUOTE_BALANCE_), spareBase);
|
return newTargetQuote.sub(_QUOTE_BALANCE_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ R > 1 cases ============
|
// ============ R > 1 cases ============
|
||||||
@@ -132,11 +128,7 @@ contract Pricing is Storage {
|
|||||||
return _RAboveIntegrate(targetBaseAmount, B1, baseBalance);
|
return _RAboveIntegrate(targetBaseAmount, B1, baseBalance);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _RAboveBackToOne()
|
function _RAboveBackToOne() internal view returns (uint256 payBaseToken) {
|
||||||
internal
|
|
||||||
view
|
|
||||||
returns (uint256 payBaseToken, uint256 receiveQuoteToken)
|
|
||||||
{
|
|
||||||
// important: carefully design the system to make sure spareBase always greater than or equal to 0
|
// important: carefully design the system to make sure spareBase always greater than or equal to 0
|
||||||
uint256 spareQuote = _QUOTE_BALANCE_.sub(_TARGET_QUOTE_TOKEN_AMOUNT_);
|
uint256 spareQuote = _QUOTE_BALANCE_.sub(_TARGET_QUOTE_TOKEN_AMOUNT_);
|
||||||
uint256 price = getOraclePrice();
|
uint256 price = getOraclePrice();
|
||||||
@@ -146,7 +138,7 @@ contract Pricing is Storage {
|
|||||||
_K_,
|
_K_,
|
||||||
fairAmount
|
fairAmount
|
||||||
);
|
);
|
||||||
return (newTargetBase.sub(_BASE_BALANCE_), spareQuote);
|
return newTargetBase.sub(_BASE_BALANCE_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ Helper functions ============
|
// ============ Helper functions ============
|
||||||
@@ -157,11 +149,11 @@ contract Pricing is Storage {
|
|||||||
if (_R_STATUS_ == Types.RStatus.ONE) {
|
if (_R_STATUS_ == Types.RStatus.ONE) {
|
||||||
return (_TARGET_BASE_TOKEN_AMOUNT_, _TARGET_QUOTE_TOKEN_AMOUNT_);
|
return (_TARGET_BASE_TOKEN_AMOUNT_, _TARGET_QUOTE_TOKEN_AMOUNT_);
|
||||||
} else if (_R_STATUS_ == Types.RStatus.BELOW_ONE) {
|
} else if (_R_STATUS_ == Types.RStatus.BELOW_ONE) {
|
||||||
(uint256 payQuoteToken, uint256 receiveBaseToken) = _RBelowBackToOne();
|
uint256 payQuoteToken = _RBelowBackToOne();
|
||||||
return (B.sub(receiveBaseToken), Q.add(payQuoteToken));
|
return (_TARGET_BASE_TOKEN_AMOUNT_, Q.add(payQuoteToken));
|
||||||
} else if (_R_STATUS_ == Types.RStatus.ABOVE_ONE) {
|
} else if (_R_STATUS_ == Types.RStatus.ABOVE_ONE) {
|
||||||
(uint256 payBaseToken, uint256 receiveQuoteToken) = _RAboveBackToOne();
|
uint256 payBaseToken = _RAboveBackToOne();
|
||||||
return (B.add(payBaseToken), Q.sub(receiveQuoteToken));
|
return (B.add(payBaseToken), _TARGET_QUOTE_TOKEN_AMOUNT_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user