[audit]#2 make getExpectedTarget public

This commit is contained in:
mingda
2020-07-08 17:12:00 +08:00
parent b42f4aeb3c
commit 85eee0d1c2
3 changed files with 9 additions and 9 deletions

View File

@@ -85,7 +85,7 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
preventReentrant preventReentrant
depositQuoteAllowed depositQuoteAllowed
{ {
(, uint256 quoteTarget) = _getExpectedTarget(); (, uint256 quoteTarget) = getExpectedTarget();
uint256 totalQuoteCapital = getTotalQuoteCapital(); uint256 totalQuoteCapital = getTotalQuoteCapital();
uint256 capital = amount; uint256 capital = amount;
if (totalQuoteCapital == 0) { if (totalQuoteCapital == 0) {
@@ -104,7 +104,7 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
} }
function depositBaseTo(address to, uint256 amount) public preventReentrant depositBaseAllowed { function depositBaseTo(address to, uint256 amount) public preventReentrant depositBaseAllowed {
(uint256 baseTarget, ) = _getExpectedTarget(); (uint256 baseTarget, ) = getExpectedTarget();
uint256 totalBaseCapital = getTotalBaseCapital(); uint256 totalBaseCapital = getTotalBaseCapital();
uint256 capital = amount; uint256 capital = amount;
if (totalBaseCapital == 0) { if (totalBaseCapital == 0) {
@@ -126,7 +126,7 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
function withdrawQuoteTo(address to, uint256 amount) public preventReentrant returns (uint256) { function withdrawQuoteTo(address to, uint256 amount) public preventReentrant returns (uint256) {
// calculate capital // calculate capital
(, uint256 quoteTarget) = _getExpectedTarget(); (, uint256 quoteTarget) = getExpectedTarget();
uint256 totalQuoteCapital = getTotalQuoteCapital(); uint256 totalQuoteCapital = getTotalQuoteCapital();
require(totalQuoteCapital > 0, "NO_QUOTE_LP"); require(totalQuoteCapital > 0, "NO_QUOTE_LP");
@@ -154,7 +154,7 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
function withdrawBaseTo(address to, uint256 amount) public preventReentrant returns (uint256) { function withdrawBaseTo(address to, uint256 amount) public preventReentrant returns (uint256) {
// calculate capital // calculate capital
(uint256 baseTarget, ) = _getExpectedTarget(); (uint256 baseTarget, ) = getExpectedTarget();
uint256 totalBaseCapital = getTotalBaseCapital(); uint256 totalBaseCapital = getTotalBaseCapital();
require(totalBaseCapital > 0, "NO_BASE_LP"); require(totalBaseCapital > 0, "NO_BASE_LP");
@@ -242,7 +242,7 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
function getLpBaseBalance(address lp) public view returns (uint256 lpBalance) { function getLpBaseBalance(address lp) public view returns (uint256 lpBalance) {
uint256 totalBaseCapital = getTotalBaseCapital(); uint256 totalBaseCapital = getTotalBaseCapital();
(uint256 baseTarget, ) = _getExpectedTarget(); (uint256 baseTarget, ) = getExpectedTarget();
if (totalBaseCapital == 0) { if (totalBaseCapital == 0) {
return 0; return 0;
} }
@@ -252,7 +252,7 @@ contract LiquidityProvider is Storage, Pricing, Settlement {
function getLpQuoteBalance(address lp) public view returns (uint256 lpBalance) { function getLpQuoteBalance(address lp) public view returns (uint256 lpBalance) {
uint256 totalQuoteCapital = getTotalQuoteCapital(); uint256 totalQuoteCapital = getTotalQuoteCapital();
(, uint256 quoteTarget) = _getExpectedTarget(); (, uint256 quoteTarget) = getExpectedTarget();
if (totalQuoteCapital == 0) { if (totalQuoteCapital == 0) {
return 0; return 0;
} }

View File

@@ -151,7 +151,7 @@ contract Pricing is Storage {
// ============ Helper functions ============ // ============ Helper functions ============
function _getExpectedTarget() internal view returns (uint256 baseTarget, uint256 quoteTarget) { function getExpectedTarget() public view returns (uint256 baseTarget, uint256 quoteTarget) {
uint256 Q = _QUOTE_BALANCE_; uint256 Q = _QUOTE_BALANCE_;
uint256 B = _BASE_BALANCE_; uint256 B = _BASE_BALANCE_;
if (_R_STATUS_ == Types.RStatus.ONE) { if (_R_STATUS_ == Types.RStatus.ONE) {

View File

@@ -140,7 +140,7 @@ contract Trader is Storage, Pricing, Settlement {
uint256 newBaseTarget uint256 newBaseTarget
) )
{ {
(newBaseTarget, newQuoteTarget) = _getExpectedTarget(); (newBaseTarget, newQuoteTarget) = getExpectedTarget();
uint256 sellBaseAmount = amount; uint256 sellBaseAmount = amount;
@@ -201,7 +201,7 @@ contract Trader is Storage, Pricing, Settlement {
uint256 newBaseTarget uint256 newBaseTarget
) )
{ {
(newBaseTarget, newQuoteTarget) = _getExpectedTarget(); (newBaseTarget, newQuoteTarget) = getExpectedTarget();
// charge fee from user receive amount // charge fee from user receive amount
lpFeeBase = DecimalMath.mul(amount, _LP_FEE_RATE_); lpFeeBase = DecimalMath.mul(amount, _LP_FEE_RATE_);