mirror of
https://github.com/fdundjer/solana-sniper-bot.git
synced 2025-11-20 11:41:11 +10:00
feat: change getAllLiquidity and GetAllMarket
This commit is contained in:
committed by
ThomAill
parent
e5e20876eb
commit
f3c0cd5651
@ -1,12 +1,31 @@
|
||||
import { Commitment, Connection, PublicKey } from '@solana/web3.js';
|
||||
import {PublicKey } from '@solana/web3.js';
|
||||
import {
|
||||
GetStructureSchema,
|
||||
MARKET_STATE_LAYOUT_V3,
|
||||
} from '@raydium-io/raydium-sdk';
|
||||
import {
|
||||
MINIMAL_MARKET_STATE_LAYOUT_V3,
|
||||
OPENBOOK_PROGRAM_ID,
|
||||
} from '../liquidity';
|
||||
import axios from 'axios';
|
||||
|
||||
interface AccountData {
|
||||
data: string[];
|
||||
executable: boolean;
|
||||
lamports: number;
|
||||
owner: string;
|
||||
rentEpoch: number;
|
||||
space: number;
|
||||
}
|
||||
|
||||
interface MarketAccount {
|
||||
account: AccountData;
|
||||
pubkey: string;
|
||||
}
|
||||
|
||||
interface JsonResponse {
|
||||
jsonrpc: string;
|
||||
result: MarketAccount[];
|
||||
}
|
||||
|
||||
export type MinimalOpenBookAccountData = {
|
||||
id: PublicKey;
|
||||
@ -17,30 +36,21 @@ export type MinimalMarketLayoutV3 =
|
||||
GetStructureSchema<MinimalMarketStateLayoutV3>;
|
||||
|
||||
export async function getAllMarketsV3(
|
||||
connection: Connection,
|
||||
quoteMint: PublicKey,
|
||||
commitment?: Commitment,
|
||||
): Promise<MinimalOpenBookAccountData[]> {
|
||||
const { span } = MARKET_STATE_LAYOUT_V3;
|
||||
const accounts = await connection.getProgramAccounts(OPENBOOK_PROGRAM_ID, {
|
||||
dataSlice: { offset: 0, length: 0 },
|
||||
commitment: commitment,
|
||||
filters: [
|
||||
{ dataSize: span },
|
||||
{
|
||||
memcmp: {
|
||||
offset: MARKET_STATE_LAYOUT_V3.offsetOf('quoteMint'),
|
||||
bytes: quoteMint.toBase58(),
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
): Promise<{ id: string; programId: PublicKey }[]> {
|
||||
const url = 'https://cache.prism.ag/openbook.json';
|
||||
|
||||
return accounts.map(
|
||||
(info) =>
|
||||
<MinimalOpenBookAccountData>{
|
||||
id: info.pubkey,
|
||||
try {
|
||||
const response = await axios.get<JsonResponse>(url);
|
||||
// @ts-ignore
|
||||
const json: JsonResponse = response.data;
|
||||
|
||||
return json.result
|
||||
.map(account => ({
|
||||
id: account.pubkey,
|
||||
programId: OPENBOOK_PROGRAM_ID,
|
||||
},
|
||||
);
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('Error during data retrieval:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user