33 */
44
55import { PublicKey } from '@solana/web3.js' ;
6- import { getAccountInfo , getProgramAccounts , base58Encode , base58Decode } from '../lib/solana-rpc' ;
6+ import {
7+ base58Decode ,
8+ base58Encode ,
9+ getAccountInfo ,
10+ getProgramAccounts ,
11+ } from '../lib/solana-rpc' ;
712
8- const RAYDIUM_AMM_PROGRAM_ID = new PublicKey ( '675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8' ) ;
13+ const RAYDIUM_AMM_PROGRAM_ID = new PublicKey (
14+ '675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8' ,
15+ ) ;
916const AUTHORITY_SEED = Buffer . from ( 'amm authority' ) ;
1017
1118// Test Raydium LP token
@@ -22,8 +29,10 @@ async function main() {
2229 }
2330 const buffer = Buffer . from ( mintAccount . data , 'base64' ) ;
2431 const hasAuthority = buffer . readUInt32LE ( 0 ) === 1 ;
25- const mintAuthority = hasAuthority ? base58Encode ( buffer . subarray ( 4 , 36 ) ) : null ;
26-
32+ const mintAuthority = hasAuthority
33+ ? base58Encode ( buffer . subarray ( 4 , 36 ) )
34+ : null ;
35+
2736 if ( ! mintAuthority ) {
2837 console . log ( 'No mint authority' ) ;
2938 return ;
@@ -33,13 +42,15 @@ async function main() {
3342 console . log ( '' ) ;
3443
3544 // Try to find the nonce that produces this authority
36- console . log ( 'Searching for matching PDA (v4 format: [amm authority, nonce])...' ) ;
45+ console . log (
46+ 'Searching for matching PDA (v4 format: [amm authority, nonce])...' ,
47+ ) ;
3748
3849 for ( let nonce = 255 ; nonce >= 0 ; nonce -- ) {
3950 try {
4051 const pda = PublicKey . createProgramAddressSync (
4152 [ AUTHORITY_SEED , Buffer . from ( [ nonce ] ) ] ,
42- RAYDIUM_AMM_PROGRAM_ID
53+ RAYDIUM_AMM_PROGRAM_ID ,
4354 ) ;
4455
4556 if ( pda . toBase58 ( ) === mintAuthority ) {
@@ -51,7 +62,7 @@ async function main() {
5162 if ( nonce >= 252 ) {
5263 console . log ( `Nonce ${ nonce } : ${ pda . toBase58 ( ) } ` ) ;
5364 }
54- } catch ( e ) {
65+ } catch ( _e ) {
5566 // Invalid PDA for this nonce (point is on curve)
5667 if ( nonce >= 252 ) {
5768 console . log ( `Nonce ${ nonce } : invalid (on curve)` ) ;
@@ -66,7 +77,7 @@ async function main() {
6677 // Let's also try find_program_address
6778 const [ standardPda , bump ] = PublicKey . findProgramAddressSync (
6879 [ AUTHORITY_SEED ] ,
69- RAYDIUM_AMM_PROGRAM_ID
80+ RAYDIUM_AMM_PROGRAM_ID ,
7081 ) ;
7182 console . log ( '' ) ;
7283 console . log ( 'Standard PDA (single seed):' ) ;
@@ -77,33 +88,30 @@ async function main() {
7788 // Try to find the pool account that has this LP mint
7889 console . log ( '' ) ;
7990 console . log ( 'Searching for pool account with this LP mint...' ) ;
80-
91+
8192 // LP mint is at offset 472 in the pool account
82- const lpMintBytes = base58Decode ( TEST_LP_MINT ) ;
83- const pools = await getProgramAccounts (
84- RAYDIUM_AMM_PROGRAM_ID . toBase58 ( ) ,
85- {
86- filters : [
87- {
88- memcmp : {
89- offset : 472 , // lpMint offset in AmmInfo struct
90- bytes : TEST_LP_MINT ,
91- } ,
93+ const _lpMintBytes = base58Decode ( TEST_LP_MINT ) ;
94+ const pools = await getProgramAccounts ( RAYDIUM_AMM_PROGRAM_ID . toBase58 ( ) , {
95+ filters : [
96+ {
97+ memcmp : {
98+ offset : 472 , // lpMint offset in AmmInfo struct
99+ bytes : TEST_LP_MINT ,
92100 } ,
93- ] ,
94- dataSlice : {
95- offset : 0 ,
96- length : 600 , // Get enough to see the nonce
97101 } ,
98- }
99- ) ;
100-
102+ ] ,
103+ dataSlice : {
104+ offset : 0 ,
105+ length : 600 , // Get enough to see the nonce
106+ } ,
107+ } ) ;
108+
101109 console . log ( 'Found pools:' , pools . length ) ;
102110 for ( const pool of pools ) {
103111 console . log ( 'Pool:' , pool . pubkey ) ;
104112 const data = Buffer . from ( pool . account . data , 'base64' ) ;
105113 console . log ( 'Data length:' , data . length ) ;
106-
114+
107115 // In Raydium V4 AmmInfo, the nonce is at a specific offset
108116 // Let's dump some key offsets
109117 // status: u64 at 0
@@ -112,16 +120,16 @@ async function main() {
112120 const nonce = data . readBigUInt64LE ( 8 ) ;
113121 console . log ( 'Status:' , status ) ;
114122 console . log ( 'Nonce:' , nonce ) ;
115-
123+
116124 // Try deriving with this nonce
117125 try {
118126 const poolPda = PublicKey . createProgramAddressSync (
119127 [ AUTHORITY_SEED , Buffer . from ( [ Number ( nonce ) ] ) ] ,
120- RAYDIUM_AMM_PROGRAM_ID
128+ RAYDIUM_AMM_PROGRAM_ID ,
121129 ) ;
122130 console . log ( 'PDA with pool nonce:' , poolPda . toBase58 ( ) ) ;
123131 console . log ( 'Match:' , poolPda . toBase58 ( ) === mintAuthority ) ;
124- } catch ( e ) {
132+ } catch ( _e ) {
125133 console . log ( 'PDA with pool nonce: invalid' ) ;
126134 }
127135 }
0 commit comments