From 0690be72bd63e6d97f60c4aad535f51661cd9234 Mon Sep 17 00:00:00 2001 From: lowkeynicc <85139158+lowkeynicc@users.noreply.github.com> Date: Thu, 27 Mar 2025 12:22:54 -0400 Subject: [PATCH] Nick/fix topmakers error (#362) * add fallback account fetch to topMakers * remove accidental inclusion --- src/index.ts | 3 ++- src/utils/utils.ts | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9b8a137..37f3acb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -410,7 +410,8 @@ const main = async (): Promise => { if (accountFlag) { const topAccounts = await getRawAccountFromId( userMapClient, - topMakers + topMakers, + driftClient.connection ); res.end(JSON.stringify(topAccounts)); return; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 7aa2ab8..329a95c 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -18,6 +18,7 @@ import { RedisClient } from '@drift/common/clients'; import { logger } from './logger'; import { NextFunction, Request, Response } from 'express'; import FEATURE_FLAGS from './featureFlags'; +import { Connection } from '@solana/web3.js'; export const l2WithBNToStrings = (l2: L2OrderBook): any => { for (const key of Object.keys(l2)) { @@ -380,7 +381,8 @@ export const getAccountFromId = async ( export const getRawAccountFromId = async ( userMapClient: RedisClient, - topMakers: string[] + topMakers: string[], + connection: Connection ): Promise< { userAccountPubKey: string; @@ -395,7 +397,19 @@ export const getRawAccountFromId = async ( userAccountPubKey, accountBase64: userAccountEncoded.split('::')[1], }; + } else { + // user is not in the userMap, try to fetch from the connection + const account = await connection.getAccountInfo( + new PublicKey(userAccountPubKey) + ); + if (account) { + return { + userAccountPubKey, + accountBase64: account.data.toString('base64'), + }; + } } + return { userAccountPubKey, accountBase64: null,