From a70d7856066489ee60cee4b5c19dbc0f5245dd0a Mon Sep 17 00:00:00 2001 From: JairusSW Date: Fri, 19 Jan 2024 16:54:44 -0800 Subject: [PATCH] add janky no-log tick calculation --- assembly/index.ts | 13 ++++++++++++- test.ts | 0 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test.ts diff --git a/assembly/index.ts b/assembly/index.ts index bb044f7..23c36de 100644 --- a/assembly/index.ts +++ b/assembly/index.ts @@ -31,7 +31,6 @@ let configObj: Config = new Config(); export function initialize(config: string): void { configObj = JSON.parse(config); - if (!configObj.isValid()) throw new Error("Invalid configuration"); } @@ -46,6 +45,18 @@ function getTickFromPrice(price: f64): i32 { return i32(tick); } +function getTickFromPriceNoLog(price: u64): i32 { + let tick = 1.0001; + let result = -1; + + while (u64(tick) < price) { + tick /= 1.0001; + result++; + } + + return result; +} + export function execute(_prices: string): string { const prices = parseCandles(_prices); if (prices.length == 0) throw new Error("Expected to find candles, but found none!"); diff --git a/test.ts b/test.ts new file mode 100644 index 0000000..e69de29