fix: remove open book cache, improve startup speed

This commit is contained in:
Filip Dunder
2024-02-09 17:19:57 +01:00
parent f6f1b1bbbd
commit ab16a326f0
2 changed files with 39 additions and 69 deletions

View File

@ -1,46 +1,23 @@
import { Commitment, Connection, PublicKey } from '@solana/web3.js';
import {
GetStructureSchema,
MARKET_STATE_LAYOUT_V3,
} from '@raydium-io/raydium-sdk';
import {
MINIMAL_MARKET_STATE_LAYOUT_V3,
OPENBOOK_PROGRAM_ID,
} from '../liquidity';
import { GetStructureSchema, MARKET_STATE_LAYOUT_V3 } from '@raydium-io/raydium-sdk';
import { MINIMAL_MARKET_STATE_LAYOUT_V3 } from '../liquidity';
export type MinimalOpenBookAccountData = {
id: PublicKey;
programId: PublicKey;
};
export type MinimalMarketStateLayoutV3 = typeof MINIMAL_MARKET_STATE_LAYOUT_V3;
export type MinimalMarketLayoutV3 =
GetStructureSchema<MinimalMarketStateLayoutV3>;
export async function getAllMarketsV3(
export async function getMinimalMarketV3(
connection: Connection,
quoteMint: PublicKey,
marketId: PublicKey,
commitment?: Commitment,
): Promise<MinimalOpenBookAccountData[]> {
const { span } = MARKET_STATE_LAYOUT_V3;
const accounts = await connection.getProgramAccounts(OPENBOOK_PROGRAM_ID, {
dataSlice: { offset: 0, length: 0 },
commitment: commitment,
filters: [
{ dataSize: span },
{
memcmp: {
offset: MARKET_STATE_LAYOUT_V3.offsetOf('quoteMint'),
bytes: quoteMint.toBase58(),
},
},
],
): Promise<MinimalMarketLayoutV3> {
const marketInfo = await connection.getAccountInfo(marketId, {
commitment,
dataSlice: {
offset: MARKET_STATE_LAYOUT_V3.offsetOf('eventQueue'),
length: 32 * 3,
},
});
return accounts.map(
(info) =>
<MinimalOpenBookAccountData>{
id: info.pubkey,
programId: OPENBOOK_PROGRAM_ID,
},
);
return MINIMAL_MARKET_STATE_LAYOUT_V3.decode(marketInfo!.data);
}