From 5e26f41df2907a59e8248fff33efc9fdef952617 Mon Sep 17 00:00:00 2001 From: shubhamessier Date: Sun, 7 Jun 2026 01:57:59 +0530 Subject: [PATCH] fix(sdk): honor nullable return type in `getSpotMarketAccount` `driftClient.getSpotMarketAccount()` and `forceGetSpotMarketAccount()` are declared to return `SpotMarketAccount | undefined`, but currently dereference `.data` on the underlying `DataAndSlot<...> | undefined` returned by `accountSubscriber`. This causes a `TypeError` when the requested `marketIndex` is not present in the subscriber cache. Use optional chaining when accessing `.data` so the implementation matches the declared return type and correctly returns `undefined` when the account is unavailable. This ensures external consumers can safely handle the nullable return path without encountering runtime exceptions. Closes #2137. --- sdk/src/driftClient.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/src/driftClient.ts b/sdk/src/driftClient.ts index 54a6c636b7..df21797bb4 100644 --- a/sdk/src/driftClient.ts +++ b/sdk/src/driftClient.ts @@ -696,7 +696,7 @@ export class DriftClient { public getSpotMarketAccount( marketIndex: number ): SpotMarketAccount | undefined { - return this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex).data; + return this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex)?.data; } /** @@ -707,7 +707,7 @@ export class DriftClient { marketIndex: number ): Promise { await this.accountSubscriber.fetch(); - return this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex).data; + return this.accountSubscriber.getSpotMarketAccountAndSlot(marketIndex)?.data; } public getSpotMarketAccounts(): SpotMarketAccount[] {