-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathTimestampEnforcer.sol
35 lines (33 loc) · 1.22 KB
/
TimestampEnforcer.sol
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
//SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import "../CaveatEnforcer.sol";
import {BytesLib} from "../libraries/BytesLib.sol";
contract TimestampEnforcer is CaveatEnforcer {
/**
* @notice Allows the delegator to specify the latest timestamp the delegation will be valid.
* @param terms - The latest timestamp this delegation is valid.
* @param transaction - The transaction the delegate might try to perform.
* @param delegationHash - The hash of the delegation being operated on.
**/
function enforceCaveat(
bytes calldata terms,
Transaction calldata transaction,
bytes32 delegationHash
) public override returns (bool) {
uint128 logicOperator = BytesLib.toUint128(terms, 0);
uint128 blockExpiration = BytesLib.toUint128(terms, 16);
if (logicOperator == 0) {
if (blockExpiration < block.timestamp) {
return true;
} else {
revert("TimestampEnforcer:expired-delegation");
}
} else {
if (blockExpiration > block.timestamp) {
return true;
} else {
revert("TimestampEnforcer:early-delegation");
}
}
}
}