market.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { Commitment, Connection, PublicKey } from '@solana/web3.js';
  2. import {
  3. GetStructureSchema,
  4. MARKET_STATE_LAYOUT_V3,
  5. } from '@raydium-io/raydium-sdk';
  6. import {
  7. MINIMAL_MARKET_STATE_LAYOUT_V3,
  8. OPENBOOK_PROGRAM_ID,
  9. } from '../liquidity';
  10. export type MinimalOpenBookAccountData = {
  11. id: PublicKey;
  12. programId: PublicKey;
  13. };
  14. export type MinimalMarketStateLayoutV3 = typeof MINIMAL_MARKET_STATE_LAYOUT_V3;
  15. export type MinimalMarketLayoutV3 =
  16. GetStructureSchema<MinimalMarketStateLayoutV3>;
  17. export async function getAllMarketsV3(
  18. connection: Connection,
  19. quoteMint: PublicKey,
  20. commitment?: Commitment,
  21. ): Promise<MinimalOpenBookAccountData[]> {
  22. const { span } = MARKET_STATE_LAYOUT_V3;
  23. const accounts = await connection.getProgramAccounts(OPENBOOK_PROGRAM_ID, {
  24. dataSlice: { offset: 0, length: 0 },
  25. commitment: commitment,
  26. filters: [
  27. { dataSize: span },
  28. {
  29. memcmp: {
  30. offset: MARKET_STATE_LAYOUT_V3.offsetOf('quoteMint'),
  31. bytes: quoteMint.toBase58(),
  32. },
  33. },
  34. ],
  35. });
  36. return accounts.map(
  37. (info) =>
  38. <MinimalOpenBookAccountData>{
  39. id: info.pubkey,
  40. programId: OPENBOOK_PROGRAM_ID,
  41. },
  42. );
  43. }