diff --git a/contracts/DODOStablePool/impl/DSPVault.sol b/contracts/DODOStablePool/impl/DSPVault.sol index 32cac39..112591c 100644 --- a/contracts/DODOStablePool/impl/DSPVault.sol +++ b/contracts/DODOStablePool/impl/DSPVault.sol @@ -11,6 +11,7 @@ pragma experimental ABIEncoderV2; import {IERC20} from "../../intf/IERC20.sol"; import {SafeMath} from "../../lib/SafeMath.sol"; import {DecimalMath} from "../../lib/DecimalMath.sol"; +import {PMMPricing} from "../../lib/PMMPricing.sol"; import {SafeERC20} from "../../lib/SafeERC20.sol"; import {DSPStorage} from "./DSPStorage.sol"; @@ -93,6 +94,19 @@ contract DSPVault is DSPStorage { _sync(); } + function correctRState() public { + if (_RState_ == uint32(PMMPricing.RState.BELOW_ONE) && _BASE_RESERVE_<_BASE_TARGET_) { + _RState_ = uint32(PMMPricing.RState.ONE); + _BASE_TARGET_ = _BASE_RESERVE_; + _QUOTE_TARGET_ = _QUOTE_RESERVE_; + } + if (_RState_ == uint32(PMMPricing.RState.ABOVE_ONE) && _QUOTE_RESERVE_<_QUOTE_TARGET_) { + _RState_ = uint32(PMMPricing.RState.ONE); + _BASE_TARGET_ = _BASE_RESERVE_; + _QUOTE_TARGET_ = _QUOTE_RESERVE_; + } + } + // ============ Asset Out ============ function _transferBaseOut(address to, uint256 amount) internal {