mirror of
https://github.com/fdundjer/solana-sniper-bot.git
synced 2025-11-14 00:31:23 +10:00
feat: add support for wsol swaps
This commit is contained in:
@ -12,7 +12,7 @@ import {
|
||||
LiquidityStateV4,
|
||||
} from '@raydium-io/raydium-sdk';
|
||||
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
||||
import { USDC_TOKEN_ID } from '../common';
|
||||
import { MinimalMarketLayoutV3 } from '../market';
|
||||
|
||||
export const RAYDIUM_LIQUIDITY_PROGRAM_ID_V4 = MAINNET_PROGRAM_ID.AmmV4;
|
||||
export const OPENBOOK_PROGRAM_ID = MAINNET_PROGRAM_ID.OPENBOOK_MARKET;
|
||||
@ -31,19 +31,21 @@ export type MinimalLiquidityAccountData = {
|
||||
|
||||
export async function getAllAccountsV4(
|
||||
connection: Connection,
|
||||
quoteMint: PublicKey,
|
||||
commitment?: Commitment,
|
||||
): Promise<MinimalLiquidityAccountData[]> {
|
||||
const { span } = LIQUIDITY_STATE_LAYOUT_V4;
|
||||
const accounts = await connection.getProgramAccounts(
|
||||
RAYDIUM_LIQUIDITY_PROGRAM_ID_V4,
|
||||
{
|
||||
dataSlice: { offset: 0, length: 0 },
|
||||
commitment: 'processed',
|
||||
commitment: commitment,
|
||||
filters: [
|
||||
{ dataSize: span },
|
||||
{
|
||||
memcmp: {
|
||||
offset: LIQUIDITY_STATE_LAYOUT_V4.offsetOf('quoteMint'),
|
||||
bytes: USDC_TOKEN_ID.toBase58(),
|
||||
bytes: quoteMint.toBase58(),
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -66,6 +68,46 @@ export async function getAllAccountsV4(
|
||||
);
|
||||
}
|
||||
|
||||
export function createPoolKeys(
|
||||
id: PublicKey,
|
||||
accountData: LiquidityStateV4,
|
||||
minimalMarketLayoutV3: MinimalMarketLayoutV3,
|
||||
): LiquidityPoolKeys {
|
||||
return {
|
||||
id,
|
||||
baseMint: accountData.baseMint,
|
||||
quoteMint: accountData.quoteMint,
|
||||
lpMint: accountData.lpMint,
|
||||
baseDecimals: accountData.baseDecimal.toNumber(),
|
||||
quoteDecimals: accountData.quoteDecimal.toNumber(),
|
||||
lpDecimals: 5,
|
||||
version: 4,
|
||||
programId: RAYDIUM_LIQUIDITY_PROGRAM_ID_V4,
|
||||
authority: Liquidity.getAssociatedAuthority({
|
||||
programId: RAYDIUM_LIQUIDITY_PROGRAM_ID_V4,
|
||||
}).publicKey,
|
||||
openOrders: accountData.openOrders,
|
||||
targetOrders: accountData.targetOrders,
|
||||
baseVault: accountData.baseVault,
|
||||
quoteVault: accountData.quoteVault,
|
||||
marketVersion: 3,
|
||||
marketProgramId: accountData.marketProgramId,
|
||||
marketId: accountData.marketId,
|
||||
marketAuthority: Market.getAssociatedAuthority({
|
||||
programId: accountData.marketProgramId,
|
||||
marketId: accountData.marketId,
|
||||
}).publicKey,
|
||||
marketBaseVault: accountData.baseVault,
|
||||
marketQuoteVault: accountData.quoteVault,
|
||||
marketBids: minimalMarketLayoutV3.bids,
|
||||
marketAsks: minimalMarketLayoutV3.asks,
|
||||
marketEventQueue: minimalMarketLayoutV3.eventQueue,
|
||||
withdrawQueue: accountData.withdrawQueue,
|
||||
lpVault: accountData.lpVault,
|
||||
lookupTableAccount: PublicKey.default,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getAccountPoolKeysFromAccountDataV4(
|
||||
connection: Connection,
|
||||
id: PublicKey,
|
||||
@ -73,7 +115,7 @@ export async function getAccountPoolKeysFromAccountDataV4(
|
||||
commitment?: Commitment,
|
||||
): Promise<LiquidityPoolKeys> {
|
||||
const marketInfo = await connection.getAccountInfo(accountData.marketId, {
|
||||
commitment: commitment ?? 'processed',
|
||||
commitment: commitment,
|
||||
dataSlice: {
|
||||
offset: 253, // eventQueue
|
||||
length: 32 * 3,
|
||||
@ -122,10 +164,15 @@ export async function getAccountPoolKeysFromAccountDataV4(
|
||||
export async function getTokenAccounts(
|
||||
connection: Connection,
|
||||
owner: PublicKey,
|
||||
commitment?: Commitment,
|
||||
) {
|
||||
const tokenResp = await connection.getTokenAccountsByOwner(owner, {
|
||||
programId: TOKEN_PROGRAM_ID,
|
||||
});
|
||||
const tokenResp = await connection.getTokenAccountsByOwner(
|
||||
owner,
|
||||
{
|
||||
programId: TOKEN_PROGRAM_ID,
|
||||
},
|
||||
commitment,
|
||||
);
|
||||
|
||||
const accounts: TokenAccount[] = [];
|
||||
for (const { pubkey, account } of tokenResp.value) {
|
||||
|
||||
Reference in New Issue
Block a user