diff --git a/contracts/DODOPrivatePool/impl/DPP.sol b/contracts/DODOPrivatePool/impl/DPP.sol index e3aa069..dd90c9e 100644 --- a/contracts/DODOPrivatePool/impl/DPP.sol +++ b/contracts/DODOPrivatePool/impl/DPP.sol @@ -28,22 +28,26 @@ contract DPP is DPPTrader { address tradePermissionManager ) external { initOwner(owner); - _MAINTAINER_ = maintainer; + + require(baseTokenAddress != quoteTokenAddress, "BASE_QUOTE_CAN_NOT_BE_SAME"); _BASE_TOKEN_ = IERC20(baseTokenAddress); _QUOTE_TOKEN_ = IERC20(quoteTokenAddress); + _LP_FEE_RATE_MODEL_ = IFeeRateModel(lpFeeRateModel); _MT_FEE_RATE_MODEL_ = IFeeRateModel(mtFeeRateModel); _I_ = IExternalValue(iSource); _K_ = IExternalValue(kSource); _GAS_PRICE_LIMIT_ = IExternalValue(gasPriceSource); _TRADE_PERMISSION_ = IPermissionManager(tradePermissionManager); + _MAINTAINER_ = maintainer; + _resetTargetAndReserve(); _checkIK(); - require(_BASE_TOKEN_ != _QUOTE_TOKEN_, "BASE_QUOTE_CAN_NOT_BE_SAME"); } // ============ Version Control ============ - function version() external pure returns (uint256) { - return 100; // 1.0.0 + + function version() external pure returns (string memory) { + return "DPP 1.0.0"; } } diff --git a/contracts/DODOPrivatePool/impl/DPPTrader.sol b/contracts/DODOPrivatePool/impl/DPPTrader.sol index 14dc47e..4456001 100644 --- a/contracts/DODOPrivatePool/impl/DPPTrader.sol +++ b/contracts/DODOPrivatePool/impl/DPPTrader.sol @@ -17,6 +17,16 @@ import {IDODOCallee} from "../../intf/IDODOCallee.sol"; contract DPPTrader is DPPVault { using SafeMath for uint256; + // ============ Events ============ + + event DODOSwap( + address indexed fromToken, + address indexed toToken, + uint256 fromAmount, + uint256 toAmount, + address trader + ); + // ============ Modifiers ============ modifier isBuyAllow(address trader) { @@ -43,7 +53,7 @@ contract DPPTrader is DPPVault { external preventReentrant limitGasPrice - isSellAllow(to) + isSellAllow(to) // set DVM address in trade permission returns (uint256 receiveQuoteAmount) { uint256 baseInput = getBaseInput(); @@ -54,6 +64,7 @@ contract DPPTrader is DPPVault { _transferQuoteOut(to, receiveQuoteAmount); _transferQuoteOut(_MAINTAINER_, mtFee); + _sync(); // update TARGET if (_RState_ != newRState) { @@ -61,9 +72,13 @@ contract DPPTrader is DPPVault { _BASE_TARGET_ = newBaseTarget; } - _syncReserve(); - - return receiveQuoteAmount; + emit DODOSwap( + address(_BASE_TOKEN_), + address(_QUOTE_TOKEN_), + baseInput, + receiveQuoteAmount, + tx.origin + ); } function sellQuote(address to) @@ -85,6 +100,7 @@ contract DPPTrader is DPPVault { _transferBaseOut(to, receiveBaseAmount); _transferBaseOut(_MAINTAINER_, mtFee); + _sync(); // update TARGET if (_RState_ != newRState) { @@ -92,9 +108,13 @@ contract DPPTrader is DPPVault { _QUOTE_TARGET_ = newQuoteTarget; } - _syncReserve(); - - return receiveBaseAmount; + emit DODOSwap( + address(_QUOTE_TOKEN_), + address(_BASE_TOKEN_), + quoteInput, + receiveBaseAmount, + tx.origin + ); } function flashLoan( @@ -105,6 +125,7 @@ contract DPPTrader is DPPVault { ) external preventReentrant { _transferBaseOut(assetTo, baseAmount); _transferQuoteOut(assetTo, quoteAmount); + if (data.length > 0) IDODOCallee(assetTo).DPPFlashLoanCall(msg.sender, baseAmount, quoteAmount, data); @@ -120,13 +141,13 @@ contract DPPTrader is DPPVault { // sell quote case // quote input + base output if (baseBalance < _BASE_RESERVE_) { + uint256 quoteInput = quoteBalance.sub(_QUOTE_RESERVE_); ( uint256 receiveBaseAmount, uint256 mtFee, PMMPricing.RState newRState, uint256 newQuoteTarget - ) = querySellQuote(tx.origin, quoteBalance.sub(_QUOTE_RESERVE_)); // revert if quoteBalance