From f4e78474fa9d348a01dc0a4e8f8f6cdbec873ff4 Mon Sep 17 00:00:00 2001 From: 0xgnek <0xgnek@gmail.com> Date: Fri, 13 Dec 2024 12:20:53 +0000 Subject: [PATCH] add restrictemode --- helpers/env.ts | 1 + helpers/flipsidecrypto.ts | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/helpers/env.ts b/helpers/env.ts index c7dde6736c..696683b8cd 100644 --- a/helpers/env.ts +++ b/helpers/env.ts @@ -32,6 +32,7 @@ export const ENV_KEYS = new Set([ 'OKX_API_KEY', 'ALCHEMIX_KEY', 'ALCHEMIX_SECRET', + 'FLIPSIDE_RESTRICTED_MODE', ]) // This is done to support both ZEROx_API_KEY and ZEROX_API_KEY diff --git a/helpers/flipsidecrypto.ts b/helpers/flipsidecrypto.ts index 47f1c4d6d0..a3eaf33994 100644 --- a/helpers/flipsidecrypto.ts +++ b/helpers/flipsidecrypto.ts @@ -4,6 +4,7 @@ import { httpPost } from "../utils/fetchURL"; import { getEnv } from "./env"; const token = {} as IJSON +const isRestrictedMode = getEnv('FLIPSIDE_RESTRICTED_MODE') === 'true' const FLIPSIDE_API_KEYS = getEnv('FLIPSIDE_API_KEY')?.split(',') ?? ["f3b65679-a179-4983-b794-e41cf40103ed"] let API_KEY_INDEX = 0; const MAX_RETRIES = 20; @@ -19,6 +20,7 @@ async function randomDelay() { } export async function queryFlipside(sqlQuery: string, maxAgeMinutes: number = 90) { + checkCanFlipSideQuery(); if (!query[sqlQuery]) { query[sqlQuery] = _queryFlipside(sqlQuery, maxAgeMinutes) } @@ -178,3 +180,10 @@ async function _queryFlipside(sqlQuery: string, maxAgeMinutes: number = 90) { } ); } + +export function checkCanFlipSideQuery() { + if (!isRestrictedMode) return; + const currentHour = new Date().getUTCHours(); + if (currentHour >= 1 && currentHour <= 3) return; // 1am - 3am - any time other than this, throw error + throw new Error(`Current hour is ${currentHour}. In restricted mode, can run flipsside queries only between 1am - 3am UTC`); +}