Verified contractPartialMIT
Time
Address0x5dcd2315a462f0046641b2118e106fbb47d133d3
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.27
- Same code
Only this contract
Details
- Compiler
- solc 0.8.27+commit.40a35a09
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- shanghai
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 21,752,761
- Creation transaction
- 0xf8002535d0…3569dd2c9e
- Libraries
- src/utils/Time.sol:Time0x5dcd…d133d3
src/utils/Time.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.27;
library Time {
///@notice The cut-off time in seconds from the start of the day for a day turnover, equivalent to 18 hours (64,800 seconds).
uint32 constant TURN_OVER_TIME = 64800;
///@notice The total number of seconds in a day.
uint32 constant SECONDS_PER_DAY = 86400;
/**
* @notice Returns the current block timestamp.
* @dev This function retrieves the timestamp using assembly for gas efficiency.
* @return ts The current block timestamp.
*/
function blockTs() internal view returns (uint32 ts) {
assembly {
ts := timestamp()
}
}
/**
* @notice Calculates the number of weeks passed since a given timestamp.
* @dev Uses assembly to retrieve the current timestamp and calculates the number of turnover time periods passed.
* @param t The starting timestamp.
* @return weeksPassed The number of weeks that have passed since the provided timestamp.
*/
function weekSince(uint32 t) internal view returns (uint32 weeksPassed) {
assembly {
let currentTime := timestamp()
let timeElapsed := sub(currentTime, t)
weeksPassed := div(timeElapsed, TURN_OVER_TIME)
}
}
/**
* @notice Calculates the number of full days between two timestamps.
* @dev Subtracts the start time from the end time and divides by the seconds per day.
* @param start The starting timestamp.
* @param end The ending timestamp.
* @return daysPassed The number of full days between the two timestamps.
*/
function dayGap(uint32 start, uint256 end) public pure returns (uint32 daysPassed) {
assembly {
daysPassed := div(sub(end, start), SECONDS_PER_DAY)
}
}
/**
* @notice Get the day count for a timestamp
* @param t The timestamp from which to get the timestamp
*/
function dayCountByT(uint32 t) public pure returns (uint32) {
// Adjust the timestamp to the cut-off time
uint32 adjustedTime = t - TURN_OVER_TIME;
// Calculate the number of days since Unix epoch
return adjustedTime / SECONDS_PER_DAY;
}
function weekDayByT(uint32 t) public pure returns (uint8 weekDay) {
assembly {
// Subtract 14 hours from the timestamp
let adjustedTimestamp := sub(t, TURN_OVER_TIME)
// Divide by the number of seconds in a day (86400)
let days := div(adjustedTimestamp, SECONDS_PER_DAY)
// Add 4 to align with weekday and calculate mod 7
let result := mod(add(days, 4), 7)
// Store result as uint8
weekDay := result
}
}
/**
* @notice Calculates the end of the day at 2 PM UTC based on a given timestamp.
* @dev Adjusts the provided timestamp by subtracting the turnover time, calculates the next day's timestamp at 2 PM UTC.
* @param t The starting timestamp.
* @return nextDayStartAt2PM The timestamp for the next day ending at 2 PM UTC.
*/
function getDayEnd(uint32 t) public pure returns (uint32 nextDayStartAt2PM) {
// Adjust the timestamp to the cutoff time (2 PM UTC)
uint32 adjustedTime = t - TURN_OVER_TIME;
// Calculate the number of days since Unix epoch
uint32 daysSinceEpoch = adjustedTime / SECONDS_PER_DAY;
// Calculate the start of the next day at 2 PM UTC
nextDayStartAt2PM = (daysSinceEpoch + 1) * SECONDS_PER_DAY + TURN_OVER_TIME;
}
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {
"src/utils/Time.sol": {
"Time": "0x5dcd2315a462f0046641b2118e106fbb47d133d3"
}
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "shanghai",
"remappings": [
":@actions/=src/actions/",
":@chainlink/=lib/chainlink/",
":@const/=src/const/",
":@core/=src/",
":@interfaces/=src/interfaces/",
":@layerzerolabs/lz-evm-protocol-v2/=lib/layerzero-v2/packages/layerzero-v2/evm/protocol/",
":@layerzerolabs/oapp-evm/=lib/devtools/packages/oapp-evm/",
":@layerzerolabs/oft-evm/=lib/devtools/packages/oft-evm/",
":@libs/=src/libs/",
":@murky/=lib/murky/src/",
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":@script/=script/",
":@uniswap/v2-core/=lib/v2-core/",
":@uniswap/v2-periphery/=lib/v2-periphery/",
":@uniswap/v3-core/=lib/v3-core/",
":@uniswap/v3-periphery/=lib/v3-periphery/",
":@utils/=src/utils/",
":chainlink/=lib/chainlink/",
":devtools/=lib/devtools/packages/toolbox-foundry/src/",
":ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
":layerzero-v2/=lib/layerzero-v2/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":v3-core/=lib/v3-core/contracts/",
":v3-periphery/=lib/v3-periphery/contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.