feat: create buy script for solana tokens

This commit is contained in:
Filip Dunder
2024-01-03 20:56:45 +01:00
parent eaf37c456d
commit d22b1dc261
17 changed files with 1771 additions and 0 deletions

41
market/market.ts Normal file
View 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,
},
);
}