Files

88 lines
2.2 KiB
Solidity
Raw Permalink Normal View History

2020-11-09 14:26:38 +08:00
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
import {IERC20} from "../intf/IERC20.sol";
import {SafeERC20} from "../lib/SafeERC20.sol";
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
2020-11-09 14:26:38 +08:00
2020-12-14 18:43:35 +08:00
/**
* @title DODOApprove
* @author DODO Breeder
*
* @notice Handle authorizations in DODO platform
*/
contract DODOApprove is InitializableOwnable {
2020-11-09 14:26:38 +08:00
using SafeERC20 for IERC20;
2020-12-14 10:55:29 +08:00
// ============ Storage ============
uint256 private constant _TIMELOCK_DURATION_ = 3 days;
2020-12-14 22:02:22 +08:00
uint256 private constant _TIMELOCK_EMERGENCY_DURATION_ = 24 hours;
2020-12-14 10:55:29 +08:00
uint256 public _TIMELOCK_;
address public _PENDING_DODO_PROXY_;
2020-12-01 01:47:22 +08:00
address public _DODO_PROXY_;
2020-11-09 14:26:38 +08:00
2020-11-30 16:08:11 +08:00
// ============ Events ============
event SetDODOProxy(address indexed oldProxy, address indexed newProxy);
2020-12-14 10:55:29 +08:00
// ============ Modifiers ============
modifier notLocked() {
require(
_TIMELOCK_ <= block.timestamp,
"SetProxy is timelocked"
);
_;
2020-11-09 14:26:38 +08:00
}
2020-12-14 18:43:35 +08:00
function init(address owner, address initProxyAddress) external {
initOwner(owner);
_DODO_PROXY_ = initProxyAddress;
}
2020-12-14 10:55:29 +08:00
function unlockSetProxy(address newDodoProxy) public onlyOwner {
2020-12-14 18:43:35 +08:00
if(_DODO_PROXY_ == address(0))
_TIMELOCK_ = block.timestamp + _TIMELOCK_EMERGENCY_DURATION_;
2020-12-14 10:55:29 +08:00
else
_TIMELOCK_ = block.timestamp + _TIMELOCK_DURATION_;
_PENDING_DODO_PROXY_ = newDodoProxy;
2020-11-22 18:20:09 +08:00
}
2020-12-14 10:55:29 +08:00
function lockSetProxy() public onlyOwner {
_PENDING_DODO_PROXY_ = address(0);
_TIMELOCK_ = 0;
}
function setDODOProxy() external onlyOwner notLocked() {
emit SetDODOProxy(_DODO_PROXY_, _PENDING_DODO_PROXY_);
_DODO_PROXY_ = _PENDING_DODO_PROXY_;
lockSetProxy();
}
2020-11-09 14:26:38 +08:00
function claimTokens(
2020-11-23 22:33:23 +08:00
address token,
2020-11-09 14:26:38 +08:00
address who,
address dest,
uint256 amount
) external {
2020-12-01 01:47:22 +08:00
require(msg.sender == _DODO_PROXY_, "DODOApprove:Access restricted");
2020-11-28 17:44:39 +08:00
if (amount > 0) {
IERC20(token).safeTransferFrom(who, dest, amount);
}
2020-11-09 14:26:38 +08:00
}
2020-12-14 10:55:29 +08:00
function getDODOProxy() public view returns (address) {
return _DODO_PROXY_;
}
2020-11-09 14:26:38 +08:00
}