market.ts 975 B

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