Skip to content

Commit

Permalink
add padding to 1hr and 7day reset periods
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Oct 21, 2024
1 parent 803f73b commit 455cb64
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/lib/IdLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ library IdLib {
}
}

// TODO: add a bit of extra time to pad 1 hour and 1 day values
// NOTE: one hour is padded by five minutes & seven days is padded by one hour
function toSeconds(ResetPeriod resetPeriod) internal pure returns (uint256 duration) {
// note: no bounds check performed; ensure that the enum is in range
assembly ("memory-safe") {
// 278d00 093a80 015180 000e10 000258 00003c 00000f 000001
// 278d00 094890 015180 000f3c 000258 00003c 00000f 000001
// 30 days 7 days 1 day 1 hour 10 min 1 min 15 sec 1 sec
let bitpacked := 0x278d00093a80015180000e1000025800003c00000f000001
let bitpacked := 0x278d00094890015180000f3c00025800003c00000f000001

// shift right by period * 24 bits & mask the least significant 24 bits
duration := and(shr(mul(resetPeriod, 24), bitpacked), 0xFFFFFF)
duration := and(shr(mul(resetPeriod, 24), bitpacked), 0xffffff)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/types/ResetPeriod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ enum ResetPeriod {
FifteenSeconds,
OneMinute,
TenMinutes,
OneHour,
OneHourAndFiveMinutes,
OneDay,
SevenDays,
SevenDaysAndOneHour,
ThirtyDays
}

0 comments on commit 455cb64

Please sign in to comment.