slimplify dodo lp token constructor
This commit is contained in:
@@ -34,7 +34,7 @@ contract DODO is Admin, Trader, LiquidityProvider {
|
|||||||
uint256 k,
|
uint256 k,
|
||||||
uint256 gasPriceLimit
|
uint256 gasPriceLimit
|
||||||
) external onlyOwner preventReentrant {
|
) external onlyOwner preventReentrant {
|
||||||
require(!_INITIALIZED_, "DODO_ALREADY_INITIALIZED");
|
require(!_INITIALIZED_, "DODO_INITIALIZED");
|
||||||
_INITIALIZED_ = true;
|
_INITIALIZED_ = true;
|
||||||
|
|
||||||
_SUPERVISOR_ = supervisor;
|
_SUPERVISOR_ = supervisor;
|
||||||
@@ -53,19 +53,8 @@ contract DODO is Admin, Trader, LiquidityProvider {
|
|||||||
_K_ = k;
|
_K_ = k;
|
||||||
_R_STATUS_ = Types.RStatus.ONE;
|
_R_STATUS_ = Types.RStatus.ONE;
|
||||||
|
|
||||||
string memory lpTokenSuffix = "_DODO_LP_TOKEN_";
|
_BASE_CAPITAL_TOKEN_ = address(new DODOLpToken(_BASE_TOKEN_));
|
||||||
|
_QUOTE_CAPITAL_TOKEN_ = address(new DODOLpToken(_QUOTE_TOKEN_));
|
||||||
string memory baseName = string(
|
|
||||||
abi.encodePacked(IERC20(_BASE_TOKEN_).name(), lpTokenSuffix)
|
|
||||||
);
|
|
||||||
uint8 baseDecimals = IERC20(_BASE_TOKEN_).decimals();
|
|
||||||
_BASE_CAPITAL_TOKEN_ = address(new DODOLpToken(baseName, baseDecimals));
|
|
||||||
|
|
||||||
string memory quoteName = string(
|
|
||||||
abi.encodePacked(IERC20(_QUOTE_TOKEN_).name(), lpTokenSuffix)
|
|
||||||
);
|
|
||||||
uint8 quoteDecimals = IERC20(_QUOTE_TOKEN_).decimals();
|
|
||||||
_QUOTE_CAPITAL_TOKEN_ = address(new DODOLpToken(quoteName, quoteDecimals));
|
|
||||||
|
|
||||||
_checkDODOParameters();
|
_checkDODOParameters();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
pragma solidity 0.6.9;
|
pragma solidity 0.6.9;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import {IERC20} from "../intf/IERC20.sol";
|
||||||
import {SafeMath} from "../lib/SafeMath.sol";
|
import {SafeMath} from "../lib/SafeMath.sol";
|
||||||
import {Ownable} from "../lib/Ownable.sol";
|
import {Ownable} from "../lib/Ownable.sol";
|
||||||
|
|
||||||
@@ -21,8 +22,7 @@ contract DODOLpToken is Ownable {
|
|||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
|
|
||||||
string public symbol = "DLP";
|
string public symbol = "DLP";
|
||||||
string public name;
|
address public originToken;
|
||||||
uint8 public decimals;
|
|
||||||
|
|
||||||
uint256 public totalSupply;
|
uint256 public totalSupply;
|
||||||
mapping(address => uint256) internal balances;
|
mapping(address => uint256) internal balances;
|
||||||
@@ -40,9 +40,17 @@ contract DODOLpToken is Ownable {
|
|||||||
|
|
||||||
// ============ Functions ============
|
// ============ Functions ============
|
||||||
|
|
||||||
constructor(string memory _name, uint8 _decimals) public {
|
constructor(address _originToken) public {
|
||||||
name = _name;
|
originToken = _originToken;
|
||||||
decimals = _decimals;
|
}
|
||||||
|
|
||||||
|
function name() public view returns (string memory) {
|
||||||
|
string memory lpTokenSuffix = "_DODO_LP_TOKEN_";
|
||||||
|
return string(abi.encodePacked(IERC20(originToken).name(), lpTokenSuffix));
|
||||||
|
}
|
||||||
|
|
||||||
|
function decimals() public view returns (uint8) {
|
||||||
|
return IERC20(originToken).decimals();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,7 +59,6 @@ contract DODOLpToken is Ownable {
|
|||||||
* @param amount The amount to be transferred.
|
* @param amount The amount to be transferred.
|
||||||
*/
|
*/
|
||||||
function transfer(address to, uint256 amount) public returns (bool) {
|
function transfer(address to, uint256 amount) public returns (bool) {
|
||||||
require(to != address(0), "TO_ADDRESS_IS_EMPTY");
|
|
||||||
require(amount <= balances[msg.sender], "BALANCE_NOT_ENOUGH");
|
require(amount <= balances[msg.sender], "BALANCE_NOT_ENOUGH");
|
||||||
|
|
||||||
balances[msg.sender] = balances[msg.sender].sub(amount);
|
balances[msg.sender] = balances[msg.sender].sub(amount);
|
||||||
@@ -80,7 +87,6 @@ contract DODOLpToken is Ownable {
|
|||||||
address to,
|
address to,
|
||||||
uint256 amount
|
uint256 amount
|
||||||
) public returns (bool) {
|
) public returns (bool) {
|
||||||
require(to != address(0), "TO_ADDRESS_IS_EMPTY");
|
|
||||||
require(amount <= balances[from], "BALANCE_NOT_ENOUGH");
|
require(amount <= balances[from], "BALANCE_NOT_ENOUGH");
|
||||||
require(amount <= allowed[from][msg.sender], "ALLOWANCE_NOT_ENOUGH");
|
require(amount <= allowed[from][msg.sender], "ALLOWANCE_NOT_ENOUGH");
|
||||||
|
|
||||||
@@ -123,6 +129,5 @@ contract DODOLpToken is Ownable {
|
|||||||
balances[user] = balances[user].sub(value);
|
balances[user] = balances[user].sub(value);
|
||||||
totalSupply = totalSupply.sub(value);
|
totalSupply = totalSupply.sub(value);
|
||||||
emit Burn(user, value);
|
emit Burn(user, value);
|
||||||
emit Transfer(user, address(0), value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user