market.ts 876 B

12345678910111213141516171819202122
  1. import { Commitment, Connection, PublicKey } from '@solana/web3.js';
  2. import { GetStructureSchema, MARKET_STATE_LAYOUT_V3, publicKey, struct } from '@raydium-io/raydium-sdk';
  3. export const MINIMAL_MARKET_STATE_LAYOUT_V3 = struct([publicKey('eventQueue'), publicKey('bids'), publicKey('asks')]);
  4. export type MinimalMarketStateLayoutV3 = typeof MINIMAL_MARKET_STATE_LAYOUT_V3;
  5. export type MinimalMarketLayoutV3 = GetStructureSchema<MinimalMarketStateLayoutV3>;
  6. export async function getMinimalMarketV3(
  7. connection: Connection,
  8. marketId: PublicKey,
  9. commitment?: Commitment,
  10. ): Promise<MinimalMarketLayoutV3> {
  11. const marketInfo = await connection.getAccountInfo(marketId, {
  12. commitment,
  13. dataSlice: {
  14. offset: MARKET_STATE_LAYOUT_V3.offsetOf('eventQueue'),
  15. length: 32 * 3,
  16. },
  17. });
  18. return MINIMAL_MARKET_STATE_LAYOUT_V3.decode(marketInfo!.data);
  19. }