Skip to content

Commit

Permalink
chore(ECO-2876): Use different type for arena and normal periods
Browse files Browse the repository at this point in the history
  • Loading branch information
CRBl69 committed Feb 28, 2025
1 parent a36f419 commit 2a24d18
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
37 changes: 35 additions & 2 deletions src/typescript/sdk/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,17 @@ export const INITIAL_REAL_RESERVES: Types["Reserves"] = {
quote: 0n,
};

/// As defined in the database, aka the enum string.
export enum Period {
Period1M = "period_1m",
Period5M = "period_5m",
Period15M = "period_15m",
Period30M = "period_30m",
Period1H = "period_1h",
Period4H = "period_4h",
Period1D = "period_1d",
}

export enum ArenaPeriod {
Period15S = "period_15s",
Period1M = "period_1m",
Period5M = "period_5m",
Expand All @@ -180,7 +189,6 @@ export enum Trigger {
export const toPeriod = (s: DatabaseStructType["PeriodicStateMetadata"]["period"]) =>
({
// From the database.
period_15s: Period.Period15S,
period_1m: Period.Period1M,
period_5m: Period.Period5M,
period_15m: Period.Period15M,
Expand All @@ -201,6 +209,31 @@ export const toPeriod = (s: DatabaseStructType["PeriodicStateMetadata"]["period"
throw new Error(`Unknown period: ${s}`);
})();

export const toArenaPeriod = (s: DatabaseStructType["ArenaCandlestick"]["period"]) =>
({
// From the database.
period_15s: ArenaPeriod.Period15S,
period_1m: ArenaPeriod.Period1M,
period_5m: ArenaPeriod.Period5M,
period_15m: ArenaPeriod.Period15M,
period_30m: ArenaPeriod.Period30M,
period_1h: ArenaPeriod.Period1H,
period_4h: ArenaPeriod.Period4H,
period_1d: ArenaPeriod.Period1D,
// From the broker.
FifteenSeconds: ArenaPeriod.Period15S,
OneMinute: ArenaPeriod.Period1M,
FiveMinutes: ArenaPeriod.Period5M,
FifteenMinutes: ArenaPeriod.Period15M,
ThirtyMinutes: ArenaPeriod.Period30M,
OneHour: ArenaPeriod.Period1H,
FourHours: ArenaPeriod.Period4H,
OneDay: ArenaPeriod.Period1D,
})[s as ValueOf<typeof Period>] ??
(() => {
throw new Error(`Unknown period: ${s}`);
})();

export const toTrigger = (s: DatabaseStructType["GlobalStateEventData"]["trigger"]) =>
({
// From the database.
Expand Down
2 changes: 1 addition & 1 deletion src/typescript/sdk/src/indexer-v2/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const toArenaCandlestickFromDatabase = (
): Types["ArenaCandlestick"] => ({
meleeID: BigInt(data.melee_id),
volume: BigInt(data.volume),
period: toPeriod(data.period),
period: toArenaPeriod(data.period),
startTime: safeParseBigIntOrPostgresTimestamp(data.start_time),
openPrice: data.open_price === null ? null : Number(data.open_price),
closePrice: data.close_price === null ? null : Number(data.close_price),
Expand Down
4 changes: 2 additions & 2 deletions src/typescript/sdk/src/types/arena-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Period } from "../const";
import type { ArenaPeriod, Period } from "../const";

Check failure on line 1 in src/typescript/sdk/src/types/arena-types.ts

View workflow job for this annotation

GitHub Actions / pre-commit

'Period' is defined but never used

Check warning on line 1 in src/typescript/sdk/src/types/arena-types.ts

View workflow job for this annotation

GitHub Actions / pre-commit

'Period' is defined but never used. Allowed unused vars must match /^_/u
import { type SymbolEmoji } from "../emoji_data";
import { type AccountAddressString } from "../emojicoin_dot_fun";
import {
Expand Down Expand Up @@ -158,7 +158,7 @@ export type ArenaTypes = {

ArenaCandlestick: {
meleeID: bigint;
period: Period;
period: ArenaPeriod;
startTime: Date;

openPrice: number | null;
Expand Down

0 comments on commit 2a24d18

Please sign in to comment.