market.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {PublicKey } from '@solana/web3.js';
  2. import {
  3. GetStructureSchema,
  4. } from '@raydium-io/raydium-sdk';
  5. import {
  6. MINIMAL_MARKET_STATE_LAYOUT_V3,
  7. OPENBOOK_PROGRAM_ID,
  8. } from '../liquidity';
  9. import axios from 'axios';
  10. interface AccountData {
  11. data: string[];
  12. executable: boolean;
  13. lamports: number;
  14. owner: string;
  15. rentEpoch: number;
  16. space: number;
  17. }
  18. interface MarketAccount {
  19. account: AccountData;
  20. pubkey: string;
  21. }
  22. interface JsonResponse {
  23. jsonrpc: string;
  24. result: MarketAccount[];
  25. }
  26. export type MinimalOpenBookAccountData = {
  27. id: PublicKey;
  28. programId: PublicKey;
  29. };
  30. export type MinimalMarketStateLayoutV3 = typeof MINIMAL_MARKET_STATE_LAYOUT_V3;
  31. export type MinimalMarketLayoutV3 =
  32. GetStructureSchema<MinimalMarketStateLayoutV3>;
  33. export async function getAllMarketsV3(
  34. ): Promise<{ id: string; programId: PublicKey }[]> {
  35. const url = 'https://cache.prism.ag/openbook.json';
  36. try {
  37. const response = await axios.get<JsonResponse>(url);
  38. // @ts-ignore
  39. const json: JsonResponse = response.data;
  40. return json.result
  41. .map(account => ({
  42. id: account.pubkey,
  43. programId: OPENBOOK_PROGRAM_ID,
  44. }));
  45. } catch (error) {
  46. console.error('Error during data retrieval:', error);
  47. return [];
  48. }
  49. }