From fe061aad4f43f93c488a7b0545c449c7932fe998 Mon Sep 17 00:00:00 2001 From: Samuel Tinnerholm Date: Fri, 5 Jun 2026 15:04:40 +0000 Subject: [PATCH] fix: name hardcoded chain IDs --- core/src/exchanges/limitless/client.ts | 6 +++--- core/src/exchanges/limitless/config.ts | 2 ++ core/src/exchanges/limitless/index.ts | 4 ++-- core/src/exchanges/polymarket/auth.ts | 6 +++--- core/src/exchanges/polymarket/config.ts | 1 + core/src/exchanges/polymarket/index.ts | 3 ++- core/src/exchanges/probable/auth.ts | 9 +++++---- core/src/exchanges/probable/config.ts | 2 ++ core/src/exchanges/probable/websocket.ts | 3 ++- 9 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 core/src/exchanges/polymarket/config.ts create mode 100644 core/src/exchanges/probable/config.ts diff --git a/core/src/exchanges/limitless/client.ts b/core/src/exchanges/limitless/client.ts index 0ba431af..970ebd79 100644 --- a/core/src/exchanges/limitless/client.ts +++ b/core/src/exchanges/limitless/client.ts @@ -1,6 +1,6 @@ import { HttpClient, OrderClient, OrderBuilder, OrderSigner, MarketFetcher, Side, OrderType } from '@limitless-exchange/sdk'; import { Wallet, providers, Contract } from 'ethers'; -import { LIMITLESS_RPC_URL } from './config'; +import { LIMITLESS_CHAIN_ID, LIMITLESS_RPC_URL } from './config'; import { scaledIntegerToNumber } from './utils'; const DEFAULT_LIMITLESS_API_URL = process.env.LIMITLESS_BASE_URL || 'https://api.limitless.exchange'; @@ -204,7 +204,7 @@ export class LimitlessClient { // Sign with the EOA private key. const orderSigner = new OrderSigner(wallet); const signature = await orderSigner.signOrder(unsignedOrder, { - chainId: 8453, + chainId: LIMITLESS_CHAIN_ID, contractAddress: market.venue.exchange, }); @@ -387,7 +387,7 @@ export class LimitlessClient { const ABI = ["function balanceOf(address) view returns (uint256)", "function decimals() view returns (uint8)"]; const provider = new providers.StaticJsonRpcProvider(LIMITLESS_RPC_URL, { - chainId: 8453, + chainId: LIMITLESS_CHAIN_ID, name: 'base', }); const contract = new Contract(USDC_ADDRESS, ABI, provider); diff --git a/core/src/exchanges/limitless/config.ts b/core/src/exchanges/limitless/config.ts index bed2d5fd..85695435 100644 --- a/core/src/exchanges/limitless/config.ts +++ b/core/src/exchanges/limitless/config.ts @@ -1 +1,3 @@ +export const LIMITLESS_BASE_URL = process.env.LIMITLESS_BASE_URL || 'https://api.limitless.exchange'; export const LIMITLESS_RPC_URL = process.env.LIMITLESS_RPC_URL || 'https://mainnet.base.org'; +export const LIMITLESS_CHAIN_ID = 8453; // Base mainnet diff --git a/core/src/exchanges/limitless/index.ts b/core/src/exchanges/limitless/index.ts index 79008d78..840e6df2 100644 --- a/core/src/exchanges/limitless/index.ts +++ b/core/src/exchanges/limitless/index.ts @@ -32,7 +32,7 @@ import { FetcherContext } from '../interfaces'; import { limitlessApiSpec } from './api'; import { LimitlessAuth } from './auth'; import { LimitlessClient } from './client'; -import { LIMITLESS_RPC_URL } from './config'; +import { LIMITLESS_CHAIN_ID, LIMITLESS_RPC_URL } from './config'; import { limitlessErrorMapper } from './errors'; import { LimitlessFetcher } from './fetcher'; import { LimitlessNormalizer } from './normalizer'; @@ -572,7 +572,7 @@ export class LimitlessExchange extends PredictionMarketExchange { // Static network avoids ethers v5 auto-detect (eth_chainId), which can throw // noNetwork / NETWORK_ERROR on flaky public RPCs (#92). const provider = new providers.StaticJsonRpcProvider(LIMITLESS_RPC_URL, { - chainId: 8453, + chainId: LIMITLESS_CHAIN_ID, name: 'base', }); diff --git a/core/src/exchanges/polymarket/auth.ts b/core/src/exchanges/polymarket/auth.ts index 5aa2e3fb..51c9041f 100644 --- a/core/src/exchanges/polymarket/auth.ts +++ b/core/src/exchanges/polymarket/auth.ts @@ -7,10 +7,10 @@ import { polygon } from 'viem/chains'; import axios from 'axios'; import { ExchangeCredentials } from '../../BaseExchange'; import { logger } from '../../utils/logger'; +import { POLYMARKET_CHAIN_ID } from './config'; import { polymarketErrorMapper } from './errors'; const DEFAULT_POLYMARKET_HOST = process.env.POLYMARKET_CLOB_URL || 'https://clob.polymarket.com'; -const POLYGON_CHAIN_ID = 137; // Polymarket CLOB signature types — determines how the CLOB API // resolves the on-chain address holding the user's funds. @@ -93,7 +93,7 @@ export class PolymarketAuth { // Otherwise, derive/create them using L1 auth const l1Client = new ClobClient({ host: this.host, - chain: POLYGON_CHAIN_ID, + chain: POLYMARKET_CHAIN_ID, signer: this.signer, }); @@ -278,7 +278,7 @@ export class PolymarketAuth { this.clobClient = new ClobClient({ host: this.host, - chain: POLYGON_CHAIN_ID, + chain: POLYMARKET_CHAIN_ID, signer: this.signer, creds: apiCreds, signatureType: finalSignatureType, diff --git a/core/src/exchanges/polymarket/config.ts b/core/src/exchanges/polymarket/config.ts new file mode 100644 index 00000000..11eb8877 --- /dev/null +++ b/core/src/exchanges/polymarket/config.ts @@ -0,0 +1 @@ +export const POLYMARKET_CHAIN_ID = 137; // Polygon mainnet diff --git a/core/src/exchanges/polymarket/index.ts b/core/src/exchanges/polymarket/index.ts index fa62caf6..fd695784 100644 --- a/core/src/exchanges/polymarket/index.ts +++ b/core/src/exchanges/polymarket/index.ts @@ -37,6 +37,7 @@ import { polymarketClobSpec } from './api-clob'; import { polymarketDataSpec } from './api-data'; import { polymarketGammaSpec } from './api-gamma'; import { PolymarketAuth } from './auth'; +import { POLYMARKET_CHAIN_ID } from './config'; import { logger } from '../../utils/logger'; import { polymarketErrorMapper } from './errors'; import { PolymarketFetcher } from './fetcher'; @@ -752,7 +753,7 @@ export class PolymarketExchange extends PredictionMarketExchange { // Static network avoids ethers v5 auto-detect (eth_chainId), which can throw // noNetwork / NETWORK_ERROR on flaky public RPCs (#92). const provider = new ethers.providers.StaticJsonRpcProvider('https://polygon-rpc.com', { - chainId: 137, + chainId: POLYMARKET_CHAIN_ID, name: 'matic', }); const pusdAddress = '0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB'; // pUSD (Polymarket USD) diff --git a/core/src/exchanges/probable/auth.ts b/core/src/exchanges/probable/auth.ts index 0d126f57..92d1f652 100644 --- a/core/src/exchanges/probable/auth.ts +++ b/core/src/exchanges/probable/auth.ts @@ -3,6 +3,7 @@ import { privateKeyToAccount } from 'viem/accounts'; import { createWalletClient, http } from 'viem'; import { bsc, bscTestnet } from 'viem/chains'; import { ExchangeCredentials } from '../../BaseExchange'; +import { PROBABLE_CHAIN_ID, PROBABLE_TESTNET_CHAIN_ID } from './config'; /** * Manages Probable authentication and CLOB client initialization. @@ -36,8 +37,8 @@ export class ProbableAuth { return this.clobClient; } - const chainId = parseInt(process.env.PROBABLE_CHAIN_ID || '56', 10); - const chain = chainId === 97 ? bscTestnet : bsc; + const chainId = parseInt(process.env.PROBABLE_CHAIN_ID || String(PROBABLE_CHAIN_ID), 10); + const chain = chainId === PROBABLE_TESTNET_CHAIN_ID ? bscTestnet : bsc; const account = privateKeyToAccount(this.credentials.privateKey as `0x${string}`); const wallet = createWalletClient({ @@ -56,9 +57,9 @@ export class ProbableAuth { // disagree on WalletClient. Runtime shape is identical. const walletForClob = wallet as any; - if (chainId === 56) { + if (chainId === PROBABLE_CHAIN_ID) { this.clobClient = createClobClient({ - chainId: 56, + chainId: PROBABLE_CHAIN_ID, wallet: walletForClob, credential, }); diff --git a/core/src/exchanges/probable/config.ts b/core/src/exchanges/probable/config.ts new file mode 100644 index 00000000..0234301c --- /dev/null +++ b/core/src/exchanges/probable/config.ts @@ -0,0 +1,2 @@ +export const PROBABLE_CHAIN_ID = 56; // BSC mainnet +export const PROBABLE_TESTNET_CHAIN_ID = 97; // BSC testnet diff --git a/core/src/exchanges/probable/websocket.ts b/core/src/exchanges/probable/websocket.ts index cfaf48c8..79e5dded 100644 --- a/core/src/exchanges/probable/websocket.ts +++ b/core/src/exchanges/probable/websocket.ts @@ -1,6 +1,7 @@ import type { createClobClient } from '@prob/clob'; import { OrderBook, OrderLevel } from '../../types'; import { DEFAULT_WATCH_TIMEOUT_MS, withWatchTimeout } from '../../utils/watch-timeout'; +import { PROBABLE_CHAIN_ID } from './config'; interface QueuedPromise { resolve: (value: T | PromiseLike) => void; @@ -37,7 +38,7 @@ export class ProbableWebSocket { private async ensureClient(): Promise> { if (this.client) return this.client; - const chainId = this.config.chainId || parseInt(process.env.PROBABLE_CHAIN_ID || '56', 10); + const chainId = this.config.chainId || parseInt(process.env.PROBABLE_CHAIN_ID || String(PROBABLE_CHAIN_ID), 10); const wsUrl = this.config.wsUrl || process.env.PROBABLE_WS_URL || 'wss://ws.probable.markets/public/api/v1'; const baseUrl = this.config.baseUrl || process.env.PROBABLE_BASE_URL || 'https://api.probable.markets/public/api/v1';