refactor DPP & DVM

This commit is contained in:
mingda
2020-11-18 17:51:50 +08:00
parent 6a7b648753
commit d78de94b44
17 changed files with 627 additions and 339 deletions

View File

@@ -34,6 +34,7 @@ library DODOMath {
uint256 i,
uint256 k
) internal pure returns (uint256) {
require(V0 > 0, "TARGET_IS_ZERO");
uint256 fairAmount = DecimalMath.mul(i, V1.sub(V2)); // i*delta
uint256 V0V0V1V2 = DecimalMath.divCeil(V0.mul(V0).div(V1), V2);
uint256 penalty = DecimalMath.mul(k, V0V0V1V2); // k(V0^2/V1/V2)
@@ -62,6 +63,7 @@ library DODOMath {
bool deltaBSig,
uint256 k
) internal pure returns (uint256) {
require(Q0 > 0, "TARGET_IS_ZERO");
// calculate -b value and sig
// -b = (1-k)Q1-kQ0^2/Q1+i*deltaB
uint256 kQ02Q1 = DecimalMath.mul(k, Q0).mul(Q0).div(Q1); // kQ0^2/Q1

View File

@@ -0,0 +1,29 @@
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
import {Ownable} from "./Ownable.sol";
interface IExternalValue {
function set(uint256) external;
function get() external view returns (uint256);
}
contract ExternalValue is IExternalValue, Ownable {
uint256 public _VALUE_;
function set(uint256 value) external override {
_VALUE_ = value;
}
function get() external override view returns (uint256) {
return _VALUE_;
}
}

View File

@@ -1,29 +0,0 @@
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
import {Ownable} from "./Ownable.sol";
interface IGasPriceSource {
function setGasPrice(uint256) external;
function getGasPrice() external view returns (uint256);
}
contract GasPriceSource is IGasPriceSource, Ownable {
uint256 public _GAS_PRICE_;
function setGasPrice(uint256 gasPrice) external override {
_GAS_PRICE_ = gasPrice;
}
function getGasPrice() external override view returns (uint256) {
return _GAS_PRICE_;
}
}

View File

@@ -213,6 +213,7 @@ library PMMPricing {
// ============ Helper functions ============
// todo 我不确定这个函数是不是能改state的状态
function adjustedTarget(PMMState memory state) public pure {
if (state.R == RState.BELOW_ONE) {
uint256 fairAmount = DecimalMath.mulFloor(state.B.sub(state.B0), state.i);