all files / contracts/ TimeLockTransactions.sol

66.67% Statements 6/9
50% Branches 4/8
55.56% Functions 5/9
66.67% Lines 8/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                                      243×       245×       245× 243×                              
// SPDX-License-Identifier: NOLICENSE
 
pragma solidity ^0.8.9;
 
import "@openzeppelin/contracts/access/Ownable.sol";
 
contract TimeLockTransactions is Ownable {
    mapping (address => uint) private walletToTime;
 
    uint private constant MAX_ALLOWED_TIME = 1 days;
    uint private _lockTime = 5 minutes; // 5 minutes is the default
 
    // @dev unlock manually a wallet for one transaction
    // @note if you are inheriting this contract, you should expose this function and protect it via onlyowner or roles
    function _unlockWallet(address wallet) internal {
        walletToTime[wallet] = 0;
    }
 
    function getLockTime() external view returns(uint){
        return _lockTime;
    }
 
    function getLockTime(address wallet) public view returns (uint) {
        return walletToTime[wallet];
    }
 
    function lockToOperate(address addr) internal {
        walletToTime[addr] = block.timestamp + _lockTime;
    }
 
    function canOperate(address addr) public view returns (bool){
        return walletToTime[addr] <= block.timestamp;
    }
 
    function lockIfCanOperateAndRevertIfNotAllowed(address addr) internal {
        require(canOperate(addr), "TimeLock: the sender cannot operate yet");
        lockToOperate(addr);
    }
 
    function _setLockTime(uint timeBetweenTransactions) internal {
        Erequire(timeBetweenTransactions <= MAX_ALLOWED_TIME, "TimeLock: max temp ban greater than the allowed");
        _lockTime = timeBetweenTransactions;
        emit SetLockTimeEvent(timeBetweenTransactions);
    }
    event SetLockTimeEvent(uint timeBetweenPurchases);
 
    function setLockTime(uint timeBetweenTransactions) external EonlyOwner {
        _setLockTime(timeBetweenTransactions);
    }
 
    // @dev unlock a wallet for one transaction
    function unlockWallet(address wallet) public onlyOwner {
        _unlockWallet(wallet);
    }
}