diff --git a/src/experimental-bots/filler-common/utils.ts b/src/experimental-bots/filler-common/utils.ts index 44bb99ab..eb10996b 100644 --- a/src/experimental-bots/filler-common/utils.ts +++ b/src/experimental-bots/filler-common/utils.ts @@ -472,3 +472,13 @@ export const getPriorityFeeInstruction = (priorityFeeMicroLamports: number) => { microLamports, }); }; + +export const isTsRuntime = (): boolean => { + // @ts-ignore - This is how to check for tsx unfortunately https://github.com/privatenumber/tsx/issues/49 + const isTsx: boolean = process._preload_modules.some((m: string) => + m.includes('tsx') + ); + const isTsNode = process.argv.some((arg) => arg.includes('ts-node')); + const isBun = process.versions.bun !== undefined; + return isTsNode || isTsx || isBun; +}; diff --git a/src/experimental-bots/filler/fillerMultithreaded.ts b/src/experimental-bots/filler/fillerMultithreaded.ts index 95eae72b..064963f5 100644 --- a/src/experimental-bots/filler/fillerMultithreaded.ts +++ b/src/experimental-bots/filler/fillerMultithreaded.ts @@ -75,6 +75,7 @@ import { deserializeNodeToFill, deserializeOrder, getPriorityFeeInstruction, + isTsRuntime, } from '../filler-common/utils'; import { CounterValue, @@ -109,6 +110,8 @@ import { bs58 } from '@project-serum/anchor/dist/cjs/utils/bytes'; import { ChildProcess } from 'child_process'; import { PythPriceFeedSubscriber } from 'src/pythPriceFeedSubscriber'; import { PythLazerClient } from '@pythnetwork/pyth-lazer-sdk'; +import path from 'path'; + const logPrefix = '[Filler]'; export type MakerNodeMap = Map; @@ -504,8 +507,9 @@ export class FillerMultithreaded { `--market-type=${this.config.marketType}`, `--market-indexes=${marketIndexes.map(String)}`, ]; + const dlobBuilderFileName = 'dlobBuilder' + isTsRuntime() ? '.ts' : '.js'; const dlobBuilderProcess = spawnChild( - './src/experimental-bots/filler-common/dlobBuilder.ts', + path.join(__dirname, '../filler-common', dlobBuilderFileName), dlobBuilderArgs, 'dlobBuilder', (msg: any) => { @@ -596,8 +600,10 @@ export class FillerMultithreaded { } }; + const orderSubscriberFileName = + 'orderSubscriberFiltered' + isTsRuntime() ? '.ts' : '.js'; const orderSubscriberProcess = spawnChild( - './src/experimental-bots/filler-common/orderSubscriberFiltered.ts', + path.join(__dirname, '../filler-common', orderSubscriberFileName), orderSubscriberArgs, 'orderSubscriber', (msg: any) => { @@ -623,8 +629,10 @@ export class FillerMultithreaded { ); // Swift Subscriber process + const swiftOrderSubscriberFileName = + 'swiftOrderSubscriber' + isTsRuntime() ? '.ts' : '.js'; const swiftOrderSubscriberProcess = spawnChild( - './src/experimental-bots/filler-common/swiftOrderSubscriber.ts', + path.join(__dirname, '../filler-common', swiftOrderSubscriberFileName), orderSubscriberArgs, 'swiftOrderSubscriber', (msg: any) => { diff --git a/src/experimental-bots/spotFiller/spotFillerMultithreaded.ts b/src/experimental-bots/spotFiller/spotFillerMultithreaded.ts index 54ea7dd0..0fdd6c2a 100644 --- a/src/experimental-bots/spotFiller/spotFillerMultithreaded.ts +++ b/src/experimental-bots/spotFiller/spotFillerMultithreaded.ts @@ -73,6 +73,7 @@ import { deserializeOrder, serializeNodeToFill, spawnChild, + isTsRuntime, } from '../filler-common/utils'; import { CACHED_BLOCKHASH_OFFSET, @@ -98,6 +99,7 @@ import { getErrorCode } from '../../error'; import { webhookMessage } from '../../webhook'; import { selectMakers } from '../../makerSelection'; import { PythPriceFeedSubscriber } from 'src/pythPriceFeedSubscriber'; +import path from 'path'; enum METRIC_TYPES { try_fill_duration_histogram = 'try_fill_duration_histogram', @@ -457,8 +459,10 @@ export class SpotFillerMultithreaded { `--market-type=${this.config.marketType}`, `--market-indexes=${marketIndexes.map(String)}`, ]; + + const dlobBuilderFileName = 'dlobBuilder' + isTsRuntime() ? '.ts' : '.js'; const dlobBuilderProcess = spawnChild( - './src/experimental-bots/filler-common/dlobBuilder.ts', + path.join(__dirname, '../filler-common', dlobBuilderFileName), dlobBuilderArgs, 'dlobBuilder', (msg: any) => { @@ -549,8 +553,10 @@ export class SpotFillerMultithreaded { } }; + const orderSubscriberFileName = + 'orderSubscriberFiltered' + isTsRuntime() ? '.ts' : '.js'; const orderSubscriberProcess = spawnChild( - './src/experimental-bots/filler-common/orderSubscriberFiltered.ts', + path.join(__dirname, '../filler-common', orderSubscriberFileName), orderSubscriberArgs, 'orderSubscriber', (msg: any) => { diff --git a/yarn.lock b/yarn.lock index 622a640f..916a10ed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3137,7 +3137,7 @@ es6-promisify@^5.0.0: dependencies: es6-promise "^4.0.3" -esbuild@^0.24.0: +esbuild@0.24.0: version "0.24.0" resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.24.0.tgz#f2d470596885fcb2e91c21eb3da3b3c89c0b55e7" integrity sha512-FuLPevChGDshgSicjisSooU0cemp/sGXR841D5LHMB7mTVOmsEHcAxaH3irL53+8YDIeVNQEySh4DaYU/iuPqQ== @@ -5150,7 +5150,7 @@ thread-stream@^0.15.1: resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" integrity sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg== -tiny-glob@^0.2.9: +tiny-glob@0.2.9: version "0.2.9" resolved "https://registry.yarnpkg.com/tiny-glob/-/tiny-glob-0.2.9.tgz#2212d441ac17928033b110f8b3640683129d31e2" integrity sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg==