Files
dodo-contractV2/contracts/DODOVendingMachine/impl/DVMStorage.sol

102 lines
2.7 KiB
Solidity
Raw Normal View History

2020-10-23 01:16:52 +08:00
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol";
import {SafeMath} from "../../lib/SafeMath.sol";
import {DODOMath} from "../../lib/DODOMath.sol";
import {DecimalMath} from "../../lib/DecimalMath.sol";
2020-11-23 10:43:12 +08:00
import {IFeeRateModel} from "../../lib/FeeRateModel.sol";
2020-11-18 17:51:50 +08:00
import {IERC20} from "../../intf/IERC20.sol";
2021-01-19 17:10:46 +08:00
import {PMMPricing} from "../../lib/PMMPricing.sol";
2020-10-23 01:16:52 +08:00
2020-12-30 12:23:52 +08:00
contract DVMStorage is ReentrancyGuard {
2020-10-23 01:16:52 +08:00
using SafeMath for uint256;
2021-01-19 17:10:46 +08:00
bool public _IS_OPEN_TWAP_ = false;
2020-10-23 01:16:52 +08:00
// ============ Core Address ============
2020-11-29 17:38:13 +08:00
address public _MAINTAINER_;
2020-10-23 01:16:52 +08:00
2020-11-18 17:51:50 +08:00
IERC20 public _BASE_TOKEN_;
IERC20 public _QUOTE_TOKEN_;
2021-01-19 17:10:46 +08:00
uint112 public _BASE_RESERVE_;
uint112 public _QUOTE_RESERVE_;
uint32 public _BLOCK_TIMESTAMP_LAST_;
uint256 public _BASE_PRICE_CUMULATIVE_LAST_;
2020-11-18 17:51:50 +08:00
2020-11-29 17:38:13 +08:00
// ============ Shares (ERC20) ============
2020-11-18 17:51:50 +08:00
string public symbol;
2020-12-09 11:20:27 +08:00
uint8 public decimals;
2020-11-18 17:51:50 +08:00
string public name;
uint256 public totalSupply;
mapping(address => uint256) internal _SHARES_;
mapping(address => mapping(address => uint256)) internal _ALLOWED_;
2020-10-23 01:16:52 +08:00
2020-11-30 09:59:01 +08:00
// ================= Permit ======================
2020-11-29 23:40:19 +08:00
bytes32 public DOMAIN_SEPARATOR;
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
2020-12-30 12:23:52 +08:00
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
2020-11-29 23:40:19 +08:00
mapping(address => uint256) public nonces;
2020-10-23 01:16:52 +08:00
// ============ Variables for Pricing ============
2020-12-30 12:23:52 +08:00
uint256 public _LP_FEE_RATE_;
2020-11-23 10:43:12 +08:00
IFeeRateModel public _MT_FEE_RATE_MODEL_;
2020-10-23 01:16:52 +08:00
uint256 public _K_;
uint256 public _I_;
2021-01-19 17:10:46 +08:00
// ============ Helper Functions ============
function getPMMState() public view returns (PMMPricing.PMMState memory state) {
state.i = _I_;
state.K = _K_;
state.B = _BASE_RESERVE_;
state.Q = _QUOTE_RESERVE_;
state.B0 = 0; // will be calculated in adjustedTarget
state.Q0 = 0;
state.R = PMMPricing.RState.ABOVE_ONE;
PMMPricing.adjustedTarget(state);
}
function getPMMStateForCall()
external
view
returns (
uint256 i,
uint256 K,
uint256 B,
uint256 Q,
uint256 B0,
uint256 Q0,
uint256 R
)
{
PMMPricing.PMMState memory state = getPMMState();
i = state.i;
K = state.K;
B = state.B;
Q = state.Q;
B0 = state.B0;
Q0 = state.Q0;
R = uint256(state.R);
}
function getMidPrice() public view returns (uint256 midPrice) {
return PMMPricing.getMidPrice(getPMMState());
}
2020-10-23 01:16:52 +08:00
}