A Uniswap v4 hook that reverts when markets are closed in New York.
isCoreTradingHours
: Returntrue
between 9:30 AM and 4:00 PM ET.isTradingDay
: Returntrue
Mon-Fri, if it's not a NYSE holiday.isHoliday
: Returntrue
if it's a NYSE holiday.getHoliday
: Get the current holiday (see theHoliday
enum).isDST
: Returntrue
if it's Daylight Savings Time in New York.time
: Adjustblock.timestamp
so that UTC date calculations are localized to US Eastern Time. Subtracts either 4 or 5 hours, depending on whether it's DST.marketIsOpen
: Returntrue
if the market is currently open.state
: Get the current state of the market, one of:HOLIDAY
WEEKEND
AFTER_HOURS
OPEN
ClosedForHoliday(Holiday holiday)
: Markets are closed for a NYSE holiday. Error data includes a Holiday enum, one of:NEW_YEARS_DAY
MARTIN_LUTHER_KING_JR_DAY
WASHINGTONS_BIRTHDAY
GOOD_FRIDAY
MEMORIAL_DAY
JUNETEENTH_NATIONAL_INDEPENDENCE_DAY
INDEPENDENCE_DAY
LABOR_DAY
THANKSGIVING_DAY
CHRISTMAS_DAY
NEW_YEARS_DAY_OBSERVED
ClosedForWeekend
: Markets are closed for the weekend.AfterHours
: Markets are closed on weekdays before 9:30 AM and after 4:00 PM ET.
DingDingDing
: If you perform the first swap of the day, you get to ring the opening bell!
Network | TradingView |
---|---|
Goerli | 0x000000006016c17169c289346015b3c9d42a1218 |
Mainnet | 0x000000006016c17169c289346015b3c9d42a1218 |
The NYSE holiday calendar and Daylight Savings start/end timestamps are stored as data contracts.
NYSE holidays were precalculated through 2123 using the Python holidays package. Each 13-byte sequence encodes one year, which includes up to 11 holidays. Each holiday is encoded as 9 bits, 4 for the month and 5 for the day. A year may have 9, 10, or 11 holidays, depending on whether New Year's Day of the next year falls on a Saturday.
The start and end timestamps for Daylight Savings were precalculated through 2123 using the calculate_dst.py
script in this repo. The data contract stores each start/end pair as an 8-byte sequence, encoding two 32-bit values representing seconds since Jan 1, 2023. These represent the exact start and end timestamp of Daylight Savings Time in New York, according to current DST rules. (That is, DST starts at 2am local time on the second Sunday of March and ends 2am local time on the first Sunday of November).
Inspired by Mariano's legendary "office hours" modifier:
Thanks to:
- saucepoint for their v4 hooks template
- BokkyPooBah for BokkyPooBahsDateTimeLibrary