Merge branch 'feature/V2' of github.com:DODOEX/contractV2 into feature/V2
This commit is contained in:
@@ -122,7 +122,12 @@ contract DPPTrader is DPPVault {
|
|||||||
uint256 quoteAmount,
|
uint256 quoteAmount,
|
||||||
address assetTo,
|
address assetTo,
|
||||||
bytes calldata data
|
bytes calldata data
|
||||||
) external preventReentrant {
|
)
|
||||||
|
external
|
||||||
|
preventReentrant
|
||||||
|
isSellAllow(assetTo)
|
||||||
|
isBuyAllow(assetTo)
|
||||||
|
{
|
||||||
_transferBaseOut(assetTo, baseAmount);
|
_transferBaseOut(assetTo, baseAmount);
|
||||||
_transferQuoteOut(assetTo, quoteAmount);
|
_transferQuoteOut(assetTo, quoteAmount);
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ contract DVMFunding is DVMVault {
|
|||||||
// 在提币的时候向下取整。因此永远不会出现,balance为0但totalsupply不为0的情况
|
// 在提币的时候向下取整。因此永远不会出现,balance为0但totalsupply不为0的情况
|
||||||
// 但有可能出现,reserve>0但totalSupply=0的场景
|
// 但有可能出现,reserve>0但totalSupply=0的场景
|
||||||
if (totalSupply == 0) {
|
if (totalSupply == 0) {
|
||||||
shares = baseBalance; // 以免出现balance很大但shares很小的情况
|
shares = baseBalance.sub(10**3); // 以免出现balance很大但shares很小的情况
|
||||||
|
_mint(address(0), 10**3);
|
||||||
} else if (baseReserve > 0 && quoteReserve == 0) {
|
} else if (baseReserve > 0 && quoteReserve == 0) {
|
||||||
// case 2. supply when quote reserve is 0
|
// case 2. supply when quote reserve is 0
|
||||||
shares = baseInput.mul(totalSupply).div(baseReserve);
|
shares = baseInput.mul(totalSupply).div(baseReserve);
|
||||||
@@ -61,6 +62,7 @@ contract DVMFunding is DVMVault {
|
|||||||
uint256 mintRatio = quoteInputRatio < baseInputRatio ? quoteInputRatio : baseInputRatio;
|
uint256 mintRatio = quoteInputRatio < baseInputRatio ? quoteInputRatio : baseInputRatio;
|
||||||
shares = DecimalMath.mulFloor(totalSupply, mintRatio);
|
shares = DecimalMath.mulFloor(totalSupply, mintRatio);
|
||||||
}
|
}
|
||||||
|
require(shares > 0, 'INSUFFICIENT_LIQUIDITY_MINED');
|
||||||
_mint(to, shares);
|
_mint(to, shares);
|
||||||
_sync();
|
_sync();
|
||||||
emit BuyShares(to, shares, _SHARES_[to]);
|
emit BuyShares(to, shares, _SHARES_[to]);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ contract DVMStorage is InitializableOwnable, ReentrancyGuard {
|
|||||||
// ============ Shares (ERC20) ============
|
// ============ Shares (ERC20) ============
|
||||||
|
|
||||||
string public symbol;
|
string public symbol;
|
||||||
uint256 public decimals;
|
uint8 public decimals;
|
||||||
string public name;
|
string public name;
|
||||||
|
|
||||||
uint256 public totalSupply;
|
uint256 public totalSupply;
|
||||||
|
|||||||
@@ -103,7 +103,12 @@ contract DVMTrader is DVMVault {
|
|||||||
uint256 quoteAmount,
|
uint256 quoteAmount,
|
||||||
address assetTo,
|
address assetTo,
|
||||||
bytes calldata data
|
bytes calldata data
|
||||||
) external preventReentrant {
|
)
|
||||||
|
external
|
||||||
|
preventReentrant
|
||||||
|
isSellAllow(assetTo)
|
||||||
|
isBuyAllow(assetTo)
|
||||||
|
{
|
||||||
_transferBaseOut(assetTo, baseAmount);
|
_transferBaseOut(assetTo, baseAmount);
|
||||||
_transferQuoteOut(assetTo, quoteAmount);
|
_transferQuoteOut(assetTo, quoteAmount);
|
||||||
|
|
||||||
|
|||||||
@@ -159,4 +159,12 @@ contract DPPFactory is Ownable {
|
|||||||
{
|
{
|
||||||
return (_REGISTRY_[token0][token1], _REGISTRY_[token1][token0]);
|
return (_REGISTRY_[token0][token1], _REGISTRY_[token1][token0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPrivatePoolByUser(address user)
|
||||||
|
external
|
||||||
|
view
|
||||||
|
returns (address[] memory pools)
|
||||||
|
{
|
||||||
|
return _USER_REGISTRY_[user];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,4 +131,12 @@ contract DVMFactory is Ownable {
|
|||||||
{
|
{
|
||||||
return (_REGISTRY_[token0][token1], _REGISTRY_[token1][token0]);
|
return (_REGISTRY_[token0][token1], _REGISTRY_[token1][token0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getVendingMachineByUser(address user)
|
||||||
|
external
|
||||||
|
view
|
||||||
|
returns (address[] memory machines)
|
||||||
|
{
|
||||||
|
return _USER_REGISTRY_[user];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ contract DODOV1Proxy01 is IDODOV1Proxy01, ReentrancyGuard, Ownable {
|
|||||||
address public immutable _CHI_TOKEN_;
|
address public immutable _CHI_TOKEN_;
|
||||||
uint8 public _GAS_DODO_MAX_RETURN_ = 0;
|
uint8 public _GAS_DODO_MAX_RETURN_ = 0;
|
||||||
uint8 public _GAS_EXTERNAL_RETURN_ = 0;
|
uint8 public _GAS_EXTERNAL_RETURN_ = 0;
|
||||||
|
mapping (address => bool) public isWhiteListed;
|
||||||
|
|
||||||
// ============ Events ============
|
// ============ Events ============
|
||||||
|
|
||||||
@@ -71,6 +72,14 @@ contract DODOV1Proxy01 is IDODOV1Proxy01, ReentrancyGuard, Ownable {
|
|||||||
_GAS_EXTERNAL_RETURN_ = newExternalGasReturn;
|
_GAS_EXTERNAL_RETURN_ = newExternalGasReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addWhiteList (address contractAddr) public onlyOwner {
|
||||||
|
isWhiteListed[contractAddr] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeWhiteList (address contractAddr) public onlyOwner {
|
||||||
|
isWhiteListed[contractAddr] = false;
|
||||||
|
}
|
||||||
|
|
||||||
function dodoSwapV1(
|
function dodoSwapV1(
|
||||||
address fromToken,
|
address fromToken,
|
||||||
address toToken,
|
address toToken,
|
||||||
@@ -80,6 +89,7 @@ contract DODOV1Proxy01 is IDODOV1Proxy01, ReentrancyGuard, Ownable {
|
|||||||
uint8[] memory directions,
|
uint8[] memory directions,
|
||||||
uint256 deadLine
|
uint256 deadLine
|
||||||
) external override payable judgeExpired(deadLine) returns (uint256 returnAmount) {
|
) external override payable judgeExpired(deadLine) returns (uint256 returnAmount) {
|
||||||
|
require(dodoPairs.length == directions.length, "DODOV1Proxy01: PARAMS_LENGTH_NOT_MATCH");
|
||||||
uint256 originGas = gasleft();
|
uint256 originGas = gasleft();
|
||||||
|
|
||||||
if (fromToken != _ETH_ADDRESS_) {
|
if (fromToken != _ETH_ADDRESS_) {
|
||||||
@@ -159,6 +169,7 @@ contract DODOV1Proxy01 is IDODOV1Proxy01, ReentrancyGuard, Ownable {
|
|||||||
IERC20(_fromToken).universalApproveMax(approveTarget, fromTokenAmount);
|
IERC20(_fromToken).universalApproveMax(approveTarget, fromTokenAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require(isWhiteListed[to], "DODOV1Proxy01: Not Whitelist Contract");
|
||||||
(bool success, ) = to.call{value: _fromToken == _ETH_ADDRESS_ ? msg.value : 0}(callDataConcat);
|
(bool success, ) = to.call{value: _fromToken == _ETH_ADDRESS_ ? msg.value : 0}(callDataConcat);
|
||||||
|
|
||||||
require(success, "DODOV1Proxy01: Contract Swap execution Failed");
|
require(success, "DODOV1Proxy01: Contract Swap execution Failed");
|
||||||
|
|||||||
@@ -19,8 +19,9 @@ import {UniversalERC20} from "./lib/UniversalERC20.sol";
|
|||||||
import {SafeERC20} from "../lib/SafeERC20.sol";
|
import {SafeERC20} from "../lib/SafeERC20.sol";
|
||||||
import {DecimalMath} from "../lib/DecimalMath.sol";
|
import {DecimalMath} from "../lib/DecimalMath.sol";
|
||||||
import {ReentrancyGuard} from "../lib/ReentrancyGuard.sol";
|
import {ReentrancyGuard} from "../lib/ReentrancyGuard.sol";
|
||||||
|
import {Ownable} from "../lib/Ownable.sol";
|
||||||
|
|
||||||
contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard {
|
contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard, Ownable {
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
using UniversalERC20 for IERC20;
|
using UniversalERC20 for IERC20;
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard {
|
|||||||
address public immutable _DODO_SELL_HELPER_;
|
address public immutable _DODO_SELL_HELPER_;
|
||||||
address public immutable _DVM_FACTORY_;
|
address public immutable _DVM_FACTORY_;
|
||||||
address public immutable _DPP_FACTORY_;
|
address public immutable _DPP_FACTORY_;
|
||||||
|
mapping (address => bool) public isWhiteListed;
|
||||||
|
|
||||||
// ============ Events ============
|
// ============ Events ============
|
||||||
|
|
||||||
@@ -68,6 +70,14 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard {
|
|||||||
_DODO_SELL_HELPER_ = dodoSellHelper;
|
_DODO_SELL_HELPER_ = dodoSellHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addWhiteList (address contractAddr) public onlyOwner {
|
||||||
|
isWhiteListed[contractAddr] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeWhiteList (address contractAddr) public onlyOwner {
|
||||||
|
isWhiteListed[contractAddr] = false;
|
||||||
|
}
|
||||||
|
|
||||||
// ============ DVM Functions (create & add liquidity) ============
|
// ============ DVM Functions (create & add liquidity) ============
|
||||||
|
|
||||||
function createDODOVendingMachine(
|
function createDODOVendingMachine(
|
||||||
@@ -299,6 +309,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard {
|
|||||||
judgeExpired(deadLine)
|
judgeExpired(deadLine)
|
||||||
returns (uint256 returnAmount)
|
returns (uint256 returnAmount)
|
||||||
{
|
{
|
||||||
|
require(dodoPairs.length == directions.length, "DODOV2Proxy01: PARAMS_LENGTH_NOT_MATCH");
|
||||||
uint256 originToTokenBalance = IERC20(toToken).balanceOf(msg.sender);
|
uint256 originToTokenBalance = IERC20(toToken).balanceOf(msg.sender);
|
||||||
|
|
||||||
IWETH(_WETH_).deposit{value: msg.value}();
|
IWETH(_WETH_).deposit{value: msg.value}();
|
||||||
@@ -345,6 +356,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard {
|
|||||||
judgeExpired(deadLine)
|
judgeExpired(deadLine)
|
||||||
returns (uint256 returnAmount)
|
returns (uint256 returnAmount)
|
||||||
{
|
{
|
||||||
|
require(dodoPairs.length == directions.length, "DODOV2Proxy01: PARAMS_LENGTH_NOT_MATCH");
|
||||||
IDODOApprove(_DODO_APPROVE_).claimTokens(fromToken, msg.sender, dodoPairs[0], fromTokenAmount);
|
IDODOApprove(_DODO_APPROVE_).claimTokens(fromToken, msg.sender, dodoPairs[0], fromTokenAmount);
|
||||||
|
|
||||||
for (uint256 i = 0; i < dodoPairs.length; i++) {
|
for (uint256 i = 0; i < dodoPairs.length; i++) {
|
||||||
@@ -390,6 +402,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard {
|
|||||||
judgeExpired(deadLine)
|
judgeExpired(deadLine)
|
||||||
returns (uint256 returnAmount)
|
returns (uint256 returnAmount)
|
||||||
{
|
{
|
||||||
|
require(dodoPairs.length == directions.length, "DODOV2Proxy01: PARAMS_LENGTH_NOT_MATCH");
|
||||||
uint256 originToTokenBalance = IERC20(toToken).balanceOf(msg.sender);
|
uint256 originToTokenBalance = IERC20(toToken).balanceOf(msg.sender);
|
||||||
IDODOApprove(_DODO_APPROVE_).claimTokens(fromToken, msg.sender, dodoPairs[0], fromTokenAmount);
|
IDODOApprove(_DODO_APPROVE_).claimTokens(fromToken, msg.sender, dodoPairs[0], fromTokenAmount);
|
||||||
|
|
||||||
@@ -447,6 +460,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard {
|
|||||||
IERC20(fromToken).universalApproveMax(approveTarget, fromTokenAmount);
|
IERC20(fromToken).universalApproveMax(approveTarget, fromTokenAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require(isWhiteListed[to], "DODOV2Proxy01: Not Whitelist Contract");
|
||||||
(bool success, ) = to.call{value: fromToken == _ETH_ADDRESS_ ? msg.value : 0}(callDataConcat);
|
(bool success, ) = to.call{value: fromToken == _ETH_ADDRESS_ ? msg.value : 0}(callDataConcat);
|
||||||
|
|
||||||
require(success, "DODOV2Proxy01: Contract Swap execution Failed");
|
require(success, "DODOV2Proxy01: Contract Swap execution Failed");
|
||||||
@@ -488,6 +502,7 @@ contract DODOV2Proxy01 is IDODOV2Proxy01, ReentrancyGuard {
|
|||||||
judgeExpired(deadLine)
|
judgeExpired(deadLine)
|
||||||
returns (uint256 returnAmount)
|
returns (uint256 returnAmount)
|
||||||
{
|
{
|
||||||
|
require(dodoPairs.length == directions.length, "DODOV2Proxy01: PARAMS_LENGTH_NOT_MATCH");
|
||||||
_deposit(msg.sender, address(this), fromToken, fromTokenAmount, fromToken == _ETH_ADDRESS_);
|
_deposit(msg.sender, address(this), fromToken, fromTokenAmount, fromToken == _ETH_ADDRESS_);
|
||||||
|
|
||||||
for (uint256 i = 0; i < dodoPairs.length; i++) {
|
for (uint256 i = 0; i < dodoPairs.length; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user