refactor DPP & DVM
This commit is contained in:
@@ -12,27 +12,12 @@ import {IERC20} from "../../intf/IERC20.sol";
|
||||
import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
import {DecimalMath} from "../../lib/DecimalMath.sol";
|
||||
import {SafeERC20} from "../../lib/SafeERC20.sol";
|
||||
import {Ownable} from "../../lib/Ownable.sol";
|
||||
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
|
||||
import {DVMStorage} from "./DVMStorage.sol";
|
||||
|
||||
contract DVMVault is InitializableOwnable {
|
||||
contract DVMVault is DVMStorage {
|
||||
using SafeMath for uint256;
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
address public _BASE_TOKEN_;
|
||||
address public _QUOTE_TOKEN_;
|
||||
|
||||
uint256 public _BASE_RESERVE_;
|
||||
uint256 public _QUOTE_RESERVE_;
|
||||
|
||||
string public symbol;
|
||||
uint256 public decimals;
|
||||
string public name;
|
||||
|
||||
uint256 public totalSupply;
|
||||
mapping(address => uint256) internal _SHARES_;
|
||||
mapping(address => mapping(address => uint256)) internal _ALLOWED_;
|
||||
|
||||
// ============ Events ============
|
||||
|
||||
event Transfer(address indexed from, address indexed to, uint256 amount);
|
||||
@@ -43,40 +28,10 @@ contract DVMVault is InitializableOwnable {
|
||||
|
||||
event Burn(address indexed user, uint256 value);
|
||||
|
||||
// init functions
|
||||
function init(
|
||||
address owner,
|
||||
address _baseToken,
|
||||
address _quoteToken
|
||||
) public notInitialized {
|
||||
initOwner(owner);
|
||||
string memory connect = "_";
|
||||
string memory suffix = "DLP";
|
||||
string memory uid = string(abi.encodePacked(address(this)));
|
||||
name = string(
|
||||
abi.encodePacked(
|
||||
suffix,
|
||||
connect,
|
||||
IERC20(_baseToken).symbol(),
|
||||
connect,
|
||||
IERC20(_quoteToken).symbol(),
|
||||
connect,
|
||||
uid
|
||||
)
|
||||
);
|
||||
symbol = "DLP";
|
||||
decimals = IERC20(_baseToken).decimals();
|
||||
_BASE_TOKEN_ = _baseToken;
|
||||
_QUOTE_TOKEN_ = _quoteToken;
|
||||
}
|
||||
|
||||
// Vault related
|
||||
|
||||
function getVaultBalance() public view returns (uint256 baseBalance, uint256 quoteBalance) {
|
||||
return (
|
||||
IERC20(_BASE_TOKEN_).balanceOf(address(this)),
|
||||
IERC20(_QUOTE_TOKEN_).balanceOf(address(this))
|
||||
);
|
||||
return (_BASE_TOKEN_.balanceOf(address(this)), _QUOTE_TOKEN_.balanceOf(address(this)));
|
||||
}
|
||||
|
||||
function getVaultReserve() public view returns (uint256 baseReserve, uint256 quoteReserve) {
|
||||
@@ -84,22 +39,22 @@ contract DVMVault is InitializableOwnable {
|
||||
}
|
||||
|
||||
function getBaseBalance() public view returns (uint256 baseBalance) {
|
||||
return IERC20(_BASE_TOKEN_).balanceOf(address(this));
|
||||
return _BASE_TOKEN_.balanceOf(address(this));
|
||||
}
|
||||
|
||||
function getQuoteBalance() public view returns (uint256 quoteBalance) {
|
||||
return IERC20(_QUOTE_TOKEN_).balanceOf(address(this));
|
||||
return _QUOTE_TOKEN_.balanceOf(address(this));
|
||||
}
|
||||
|
||||
function getBaseInput() public view returns (uint256 input) {
|
||||
return IERC20(_BASE_TOKEN_).balanceOf(address(this)).sub(_BASE_RESERVE_);
|
||||
return _BASE_TOKEN_.balanceOf(address(this)).sub(_BASE_RESERVE_);
|
||||
}
|
||||
|
||||
function getQuoteInput() public view returns (uint256 input) {
|
||||
return IERC20(_QUOTE_TOKEN_).balanceOf(address(this)).sub(_QUOTE_RESERVE_);
|
||||
return _QUOTE_TOKEN_.balanceOf(address(this)).sub(_QUOTE_RESERVE_);
|
||||
}
|
||||
|
||||
function sync() public onlyOwner {
|
||||
function _sync() internal {
|
||||
(uint256 baseBalance, uint256 quoteBalance) = getVaultBalance();
|
||||
if (baseBalance != _BASE_RESERVE_) {
|
||||
_BASE_RESERVE_ = baseBalance;
|
||||
@@ -109,15 +64,15 @@ contract DVMVault is InitializableOwnable {
|
||||
}
|
||||
}
|
||||
|
||||
function transferBaseOut(address to, uint256 amount) public onlyOwner {
|
||||
function _transferBaseOut(address to, uint256 amount) internal {
|
||||
if (amount > 0) {
|
||||
IERC20(_BASE_TOKEN_).safeTransfer(to, amount);
|
||||
_BASE_TOKEN_.safeTransfer(to, amount);
|
||||
}
|
||||
}
|
||||
|
||||
function transferQuoteOut(address to, uint256 amount) public onlyOwner {
|
||||
function _transferQuoteOut(address to, uint256 amount) internal {
|
||||
if (amount > 0) {
|
||||
IERC20(_QUOTE_TOKEN_).safeTransfer(to, amount);
|
||||
_QUOTE_TOKEN_.safeTransfer(to, amount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,14 +146,14 @@ contract DVMVault is InitializableOwnable {
|
||||
return _ALLOWED_[owner][spender];
|
||||
}
|
||||
|
||||
function mint(address user, uint256 value) external onlyOwner {
|
||||
function _mint(address user, uint256 value) internal {
|
||||
_SHARES_[user] = _SHARES_[user].add(value);
|
||||
totalSupply = totalSupply.add(value);
|
||||
emit Mint(user, value);
|
||||
emit Transfer(address(0), user, value);
|
||||
}
|
||||
|
||||
function burn(address user, uint256 value) external onlyOwner {
|
||||
function _burn(address user, uint256 value) internal {
|
||||
_SHARES_[user] = _SHARES_[user].sub(value);
|
||||
totalSupply = totalSupply.sub(value);
|
||||
emit Burn(user, value);
|
||||
|
||||
Reference in New Issue
Block a user