Skip to content

Instantly share code, notes, and snippets.

@dapplion
Last active January 4, 2024 14:48
Show Gist options
  • Save dapplion/5426316f3cad4bc638596527ec16f440 to your computer and use it in GitHub Desktop.
Save dapplion/5426316f3cad4bc638596527ec16f440 to your computer and use it in GitHub Desktop.
Find fork slot and timestamp for a network with Gnosis preset and some time conditions
// Usage
// node slot_finder.mjs chiado
const genesisTimestamp = getGenesis();
const interval = 8192 * 5;
const now = Math.floor(Date.now() / 1000);
const futureDate = new Date();
futureDate.setMonth(futureDate.getMonth() + 2);
const futureTimestamp = Math.floor(futureDate.getTime() / 1000);
const elapsedIntervals = Math.floor((now - genesisTimestamp) / interval);
const firstFutureInterval = elapsedIntervals + 1;
const intervalsToFuture = Math.floor((futureTimestamp - now) / interval);
function isWeekday(date) {
const day = date.getUTCDay();
return day >= 1 && day <= 5;
}
function isWithinTimeRange(date) {
const hours = date.getUTCHours();
return hours >= 11 && hours < 19;
}
function getGenesis() {
const network = process.argv[2]
switch (network) {
case "gnosis":
return 1638993340
case "chiado":
return 1665396300
default:
throw Error(`unknown network ${network}`)
}
}
for (let i = firstFutureInterval; i <= firstFutureInterval + intervalsToFuture; i++) {
const timestamp = genesisTimestamp + (i * interval);
const date = new Date(timestamp * 1000);
if (isWeekday(date) && isWithinTimeRange(date)) {
console.log(
`Slot ${i * interval / 5}`,
`ts ${timestamp}`,
'UTC',
date.toLocaleString('en-GB', { weekday: 'short', timeZone: 'UTC' }),
date.toLocaleString('en-GB', { timeZone: 'UTC' })
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment