mirror of
https://github.com/status-im/codex-contracts-eth.git
synced 2025-02-19 11:56:43 +00:00
- changes balance from uint256 -> uint128 so that entire Balance can be read or written with a single operation - moves Lock to library - simplifies lock checks
43 lines
1.1 KiB
Solidity
43 lines
1.1 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity 0.8.28;
|
|
|
|
type Timestamp is uint64;
|
|
|
|
using {_timestampEquals as ==} for Timestamp global;
|
|
using {_timestampNotEqual as !=} for Timestamp global;
|
|
using {_timestampLessThan as <} for Timestamp global;
|
|
using {_timestampAtMost as <=} for Timestamp global;
|
|
|
|
function _timestampEquals(Timestamp a, Timestamp b) pure returns (bool) {
|
|
return Timestamp.unwrap(a) == Timestamp.unwrap(b);
|
|
}
|
|
|
|
function _timestampNotEqual(Timestamp a, Timestamp b) pure returns (bool) {
|
|
return Timestamp.unwrap(a) != Timestamp.unwrap(b);
|
|
}
|
|
|
|
function _timestampLessThan(Timestamp a, Timestamp b) pure returns (bool) {
|
|
return Timestamp.unwrap(a) < Timestamp.unwrap(b);
|
|
}
|
|
|
|
function _timestampAtMost(Timestamp a, Timestamp b) pure returns (bool) {
|
|
return Timestamp.unwrap(a) <= Timestamp.unwrap(b);
|
|
}
|
|
|
|
library Timestamps {
|
|
function currentTime() internal view returns (Timestamp) {
|
|
return Timestamp.wrap(uint64(block.timestamp));
|
|
}
|
|
|
|
function earliest(
|
|
Timestamp a,
|
|
Timestamp b
|
|
) internal pure returns (Timestamp) {
|
|
if (a <= b) {
|
|
return a;
|
|
} else {
|
|
return b;
|
|
}
|
|
}
|
|
}
|