From 5741e845529900541245605ca7b7d5747bfb43ae Mon Sep 17 00:00:00 2001 From: openhands Date: Tue, 17 Mar 2026 12:50:58 +0000 Subject: [PATCH] fix: services/txnBot still has dead recenterAccess read infrastructure (#887) Remove recenterAccess.ts, recenterAccess.test.ts, the ABI entry, and getRecenterAccessReader() from BlockchainService. Simplify getRecenterAccessStatus in service.ts to return open access (hasAccess: true) since the on-chain recenterAccess() guard no longer exists. Co-Authored-By: Claude Sonnet 4.6 --- services/txnBot/package.json | 2 +- services/txnBot/src/recenterAccess.test.ts | 45 ------------------- services/txnBot/src/recenterAccess.ts | 40 ----------------- services/txnBot/src/service.ts | 30 ++----------- .../txnBot/src/services/BlockchainService.ts | 11 ----- 5 files changed, 5 insertions(+), 123 deletions(-) delete mode 100644 services/txnBot/src/recenterAccess.test.ts delete mode 100644 services/txnBot/src/recenterAccess.ts diff --git a/services/txnBot/package.json b/services/txnBot/package.json index b2c1856..9a89e9d 100644 --- a/services/txnBot/package.json +++ b/services/txnBot/package.json @@ -8,7 +8,7 @@ "build": "tsc -p tsconfig.build.json", "start": "node dist/service.js", "dev": "tsx watch src/service.ts", - "test": "node --test --import tsx src/recenterAccess.test.ts", + "test": "node --test --import tsx", "lint": "eslint src/**/*.ts", "lint:fix": "eslint --fix src/**/*.ts", "format": "prettier --write src/**/*.ts", diff --git a/services/txnBot/src/recenterAccess.test.ts b/services/txnBot/src/recenterAccess.test.ts deleted file mode 100644 index 69867d3..0000000 --- a/services/txnBot/src/recenterAccess.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -import assert from 'node:assert/strict'; -import test from 'node:test'; -import { ethers } from 'ethers'; -import { hasRecenterAccess, readRecenterAccess, type RecenterAccessReader } from './recenterAccess.js'; - -const ZERO_ADDRESS = ethers.ZeroAddress; - -class MockRecenterAccessReader implements RecenterAccessReader { - constructor( - private readonly value: string, - private readonly shouldThrow = false - ) {} - - async recenterAccess(): Promise { - if (this.shouldThrow) { - throw new Error('read failed'); - } - return this.value; - } -} - -test('readRecenterAccess returns zero address for empty or zero values', async () => { - const reader = new MockRecenterAccessReader('0x0000000000000000000000000000000000000000'); - assert.equal(await readRecenterAccess(reader, ZERO_ADDRESS), ZERO_ADDRESS); - - const emptyReader = new MockRecenterAccessReader(''); - assert.equal(await readRecenterAccess(emptyReader, ZERO_ADDRESS), ZERO_ADDRESS); -}); - -test('readRecenterAccess normalises checksum addresses', async () => { - const reader = new MockRecenterAccessReader('0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc'); - assert.equal(await readRecenterAccess(reader, ZERO_ADDRESS), '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC'); -}); - -test('readRecenterAccess throws when reader fails', async () => { - const reader = new MockRecenterAccessReader('0x0', true); - await assert.rejects(() => readRecenterAccess(reader, ZERO_ADDRESS), /read failed/); -}); - -test('hasRecenterAccess acknowledges zero or wallet matches', () => { - const wallet = '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC'; - assert.equal(hasRecenterAccess(ZERO_ADDRESS, wallet, ZERO_ADDRESS), true); - assert.equal(hasRecenterAccess(wallet, wallet, ZERO_ADDRESS), true); - assert.equal(hasRecenterAccess('0x5cFB5CDd3E8723ba98312c90a43a4d6Ac6121240', wallet, ZERO_ADDRESS), false); -}); diff --git a/services/txnBot/src/recenterAccess.ts b/services/txnBot/src/recenterAccess.ts deleted file mode 100644 index d45dba9..0000000 --- a/services/txnBot/src/recenterAccess.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { ethers } from 'ethers'; - -export interface RecenterAccessReader { - recenterAccess(): Promise; -} - -export async function readRecenterAccess(reader: RecenterAccessReader, zeroAddress: string): Promise { - let raw: string; - try { - raw = await reader.recenterAccess(); - } catch (error) { - throw new Error(`Failed to read recenterAccess: ${(error as Error).message}`); - } - - if (typeof raw !== 'string' || raw.length === 0) { - return zeroAddress; - } - - if (raw === zeroAddress) { - return zeroAddress; - } - - try { - return ethers.getAddress(raw); - } catch (error) { - throw new Error(`Invalid recenterAccess address: ${(error as Error).message}`); - } -} - -export function hasRecenterAccess(recenterAddress: string, walletAddress: string, zeroAddress: string): boolean { - if (recenterAddress === zeroAddress) { - return true; - } - - try { - return ethers.getAddress(recenterAddress) === ethers.getAddress(walletAddress); - } catch { - return false; - } -} diff --git a/services/txnBot/src/service.ts b/services/txnBot/src/service.ts index a644c0a..b5c401d 100644 --- a/services/txnBot/src/service.ts +++ b/services/txnBot/src/service.ts @@ -1,5 +1,4 @@ import express, { NextFunction, Request, Response } from 'express'; -import { ethers } from 'ethers'; import { decodePositionId } from 'kraiken-lib/ids'; import { isPositionDelinquent } from 'kraiken-lib/staking'; import { pathToFileURL } from 'url'; @@ -7,7 +6,6 @@ import { BotConfigService } from './services/BotConfigService.js'; import { BlockchainService } from './services/BlockchainService.js'; import { GraphQLService } from './services/GraphQLService.js'; import { logger } from './logger.js'; -import { hasRecenterAccess, readRecenterAccess } from './recenterAccess.js'; import { Position, RecenterAccessStatus, RecenterEligibility, RecenterResult } from './types.js'; const ACTIVE_POSITIONS_QUERY = ` @@ -24,8 +22,6 @@ const ACTIVE_POSITIONS_QUERY = ` } `; -const ZERO_ADDRESS = ethers.ZeroAddress; - export interface TxnBotDependencies { configService: BotConfigService; blockchainService: BlockchainService; @@ -91,8 +87,6 @@ function formatDuration(ms: number): string { export function createTxnBot(dependencies: TxnBotDependencies): TxnBotInstance { const { configService, blockchainService, graphQLService } = dependencies; const envConfig = configService.getConfig(); - const recenterAccessReader = blockchainService.getRecenterAccessReader(); - const walletAddress = blockchainService.getWalletAddress(); const startTime = new Date(); let lastRecenterTime: Date | null = null; @@ -125,28 +119,12 @@ export function createTxnBot(dependencies: TxnBotDependencies): TxnBotInstance { return lastRecenterAccessStatus; } - let recenterAddress: string | null = null; - let hasAccess: boolean | null = null; - let slotHex: string | null = null; - let errorMessage: string | null = null; - - try { - const address = await readRecenterAccess(recenterAccessReader, ZERO_ADDRESS); - recenterAddress = address; - hasAccess = hasRecenterAccess(address, walletAddress, ZERO_ADDRESS); - slotHex = 'recenterAccess()'; - } catch (error) { - const err = error as { shortMessage?: string; message?: string }; - errorMessage = err?.shortMessage || err?.message || 'unknown error'; - recenterAddress = null; - } - lastRecenterAccessStatus = { - hasAccess, - recenterAccessAddress: recenterAddress, - slot: slotHex, + hasAccess: true, + recenterAccessAddress: null, + slot: null, checkedAtMs: now, - error: errorMessage, + error: null, }; return lastRecenterAccessStatus; diff --git a/services/txnBot/src/services/BlockchainService.ts b/services/txnBot/src/services/BlockchainService.ts index ba13239..27ff84f 100644 --- a/services/txnBot/src/services/BlockchainService.ts +++ b/services/txnBot/src/services/BlockchainService.ts @@ -1,5 +1,4 @@ import { Contract, JsonRpcProvider, TransactionResponse, Wallet, ethers } from 'ethers'; -import { RecenterAccessReader } from '../recenterAccess.js'; export interface BlockchainConfig { providerUrl: string; @@ -11,7 +10,6 @@ export interface BlockchainConfig { const LM_ABI = [ { type: 'function', name: 'recenter', inputs: [], outputs: [], stateMutability: 'nonpayable' }, { type: 'function', name: 'feeDestination', inputs: [], outputs: [{ type: 'address' }], stateMutability: 'view' }, - { type: 'function', name: 'recenterAccess', inputs: [], outputs: [{ type: 'address' }], stateMutability: 'view' }, ]; const STAKE_ABI = [ @@ -41,15 +39,6 @@ export class BlockchainService { return ethers.getAddress(this.wallet.address); } - getRecenterAccessReader(): RecenterAccessReader { - return { - recenterAccess: async (): Promise => { - const method = this.liquidityManager.getFunction('recenterAccess'); - return (await method()) as string; - }, - }; - } - async checkFunds(): Promise { const balance = await this.provider.getBalance(this.wallet.address); return ethers.formatEther(balance);