From 11eb3d710326480ce8e7c849ae69b0e910e6f3ad Mon Sep 17 00:00:00 2001 From: mingda Date: Wed, 8 Jul 2020 17:04:48 +0800 Subject: [PATCH] [audit]#1 add decimals and name to lptoken --- contracts/dodo.sol | 17 ++++++++++++++--- contracts/helper/TestERC20.sol | 9 ++++++++- contracts/impl/DODOLpToken.sol | 8 ++++++++ contracts/intf/IERC20.sol | 5 ++++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/contracts/dodo.sol b/contracts/dodo.sol index f62d664..08a60c2 100644 --- a/contracts/dodo.sol +++ b/contracts/dodo.sol @@ -9,13 +9,13 @@ pragma solidity 0.6.9; pragma experimental ABIEncoderV2; import {Types} from "./lib/Types.sol"; +import {IERC20} from "./intf/IERC20.sol"; import {Storage} from "./impl/Storage.sol"; import {Trader} from "./impl/Trader.sol"; import {LiquidityProvider} from "./impl/LiquidityProvider.sol"; import {Admin} from "./impl/Admin.sol"; import {DODOLpToken} from "./impl/DODOLpToken.sol"; - /** * @title DODO * @author DODO Breeder @@ -53,8 +53,19 @@ contract DODO is Admin, Trader, LiquidityProvider { _K_ = k; _R_STATUS_ = Types.RStatus.ONE; - _BASE_CAPITAL_TOKEN_ = address(new DODOLpToken()); - _QUOTE_CAPITAL_TOKEN_ = address(new DODOLpToken()); + string memory lpTokenSuffix = "_DODO_LP_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(); } diff --git a/contracts/helper/TestERC20.sol b/contracts/helper/TestERC20.sol index 85acc3b..5d02d72 100644 --- a/contracts/helper/TestERC20.sol +++ b/contracts/helper/TestERC20.sol @@ -9,16 +9,23 @@ pragma solidity 0.6.9; import {SafeMath} from "../lib/SafeMath.sol"; - contract TestERC20 { using SafeMath for uint256; + string public name; + uint8 public decimals; + mapping(address => uint256) balances; mapping(address => mapping(address => uint256)) internal allowed; event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); + constructor(string memory _name, uint8 _decimals) public { + name = _name; + decimals = _decimals; + } + 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"); diff --git a/contracts/impl/DODOLpToken.sol b/contracts/impl/DODOLpToken.sol index 6268b4f..34f2bb8 100644 --- a/contracts/impl/DODOLpToken.sol +++ b/contracts/impl/DODOLpToken.sol @@ -20,6 +20,9 @@ import {Ownable} from "../lib/Ownable.sol"; contract DODOLpToken is Ownable { using SafeMath for uint256; + string public name; + uint8 public decimals; + uint256 public totalSupply; mapping(address => uint256) internal balances; mapping(address => mapping(address => uint256)) internal allowed; @@ -36,6 +39,11 @@ contract DODOLpToken is Ownable { // ============ Functions ============ + constructor(string memory _name, uint8 _decimals) public { + name = _name; + decimals = _decimals; + } + /** * @dev transfer token for a specified address * @param to The address to transfer to. diff --git a/contracts/intf/IERC20.sol b/contracts/intf/IERC20.sol index e24f1ec..2f1810b 100644 --- a/contracts/intf/IERC20.sol +++ b/contracts/intf/IERC20.sol @@ -4,7 +4,6 @@ pragma solidity 0.6.9; pragma experimental ABIEncoderV2; - /** * @dev Interface of the ERC20 standard as defined in the EIP. */ @@ -14,6 +13,10 @@ interface IERC20 { */ function totalSupply() external view returns (uint256); + function decimals() external view returns (uint8); + + function name() external view returns (string memory); + /** * @dev Returns the amount of tokens owned by `account`. */