mirror of
https://github.com/fdundjer/solana-sniper-bot.git
synced 2025-11-18 10:41:10 +10:00
feat: create buy script for solana tokens
This commit is contained in:
41
market/market.ts
Normal file
41
market/market.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { Connection, PublicKey } from '@solana/web3.js';
|
||||
import {
|
||||
MARKET_STATE_LAYOUT_V3,
|
||||
} from '@raydium-io/raydium-sdk';
|
||||
import { USDC_TOKEN_ID } from '../common';
|
||||
import {
|
||||
OPENBOOK_PROGRAM_ID,
|
||||
|
||||
} from '../liquidity';
|
||||
|
||||
export type MinimalOpenBookAccountData = {
|
||||
id: PublicKey;
|
||||
programId: PublicKey;
|
||||
};
|
||||
|
||||
export async function getAllMarketsV3(
|
||||
connection: Connection,
|
||||
): Promise<MinimalOpenBookAccountData[]> {
|
||||
const { span } = MARKET_STATE_LAYOUT_V3;
|
||||
const accounts = await connection.getProgramAccounts(OPENBOOK_PROGRAM_ID, {
|
||||
dataSlice: { offset: 0, length: 0 },
|
||||
commitment: 'processed',
|
||||
filters: [
|
||||
{ dataSize: span },
|
||||
{
|
||||
memcmp: {
|
||||
offset: MARKET_STATE_LAYOUT_V3.offsetOf('quoteMint'),
|
||||
bytes: USDC_TOKEN_ID.toBase58(),
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
return accounts.map(
|
||||
(info) =>
|
||||
<MinimalOpenBookAccountData>{
|
||||
id: info.pubkey,
|
||||
programId: OPENBOOK_PROGRAM_ID,
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user