1- import dotenv from ' dotenv'
2- dotenv . config ( )
3- import { GfxCpmmClient } from ' ../src/gfx/index'
4- import fs from 'fs'
5- import BN from "bn.js"
1+ import dotenv from " dotenv" ;
2+ dotenv . config ( ) ;
3+ import { GfxCpmmClient } from " ../src/gfx/index" ;
4+ import fs from "fs" ;
5+ import BN from "bn.js" ;
66
7- import { Connection , Keypair , PublicKey , VersionedTransaction } from ' @solana/web3.js'
8- import { fetchMultipleMintInfos , TxVersion } from "@/common"
7+ import { Connection , Keypair , PublicKey , VersionedTransaction } from " @solana/web3.js" ;
8+ import { fetchMultipleMintInfos , TxVersion } from "@/common" ;
99
10- const RPC_URL = process . env . RPC_URL !
11- const SEND_RPC_URL = process . env . SEND_RPC_URL ?? RPC_URL
12- const KEYPAIR_PATH = process . env . KEYPAIR_PATH !
13- const MINT1 = process . env . MINT1 !
14- const MINT2 = process . env . MINT2 !
15- const MINT1_AMOUNT = parseInt ( process . env . MINT1_AMOUNT ! )
16- const MINT2_AMOUNT = parseInt ( process . env . MINT2_AMOUNT ! )
17- const GAMMA_CONFIG = new PublicKey ( process . env . GAMMA_CONFIG ! )
18- const GAMMA_PROGRAM = new PublicKey ( process . env . GAMMA_PROGRAM ! )
19- const GAMMA_POOL_FEE_ACCOUNT = new PublicKey ( process . env . GAMMA_POOL_FEE_ACCOUNT ! )
20- const MICRO_LAMPORTS = parseInt ( process . env . DEFAULT_CU_LAMPORTS ?? ' 1200000' )
10+ const RPC_URL = process . env . RPC_URL ! ;
11+ const SEND_RPC_URL = process . env . SEND_RPC_URL ?? RPC_URL ;
12+ const KEYPAIR_PATH = process . env . KEYPAIR_PATH ! ;
13+ const MINT1 = process . env . MINT1 ! ;
14+ const MINT2 = process . env . MINT2 ! ;
15+ const MINT1_AMOUNT = parseInt ( process . env . MINT1_AMOUNT ! ) ;
16+ const MINT2_AMOUNT = parseInt ( process . env . MINT2_AMOUNT ! ) ;
17+ const GAMMA_CONFIG = new PublicKey ( process . env . GAMMA_CONFIG ! ) ;
18+ const GAMMA_PROGRAM = new PublicKey ( process . env . GAMMA_PROGRAM ! ) ;
19+ const GAMMA_POOL_FEE_ACCOUNT = new PublicKey ( process . env . GAMMA_POOL_FEE_ACCOUNT ! ) ;
20+ const MICRO_LAMPORTS = parseInt ( process . env . DEFAULT_CU_LAMPORTS ?? " 1200000" ) ;
2121
2222async function mainFn ( ) : Promise < void > {
23- const keypair = createKeypairFromFile ( KEYPAIR_PATH )
24- console . log ( "Pubkey: " , keypair . publicKey . toBase58 ( ) )
25- const client = await GfxCpmmClient . load (
26- {
27- connection : new Connection ( RPC_URL ) ,
28- disableFeatureCheck : true ,
29- disableLoadToken : true ,
30- urlConfigs : {
31- BASE_HOST : '' ,
32- } ,
33- owner : keypair
34- }
35- )
23+ const keypair = createKeypairFromFile ( KEYPAIR_PATH ) ;
24+ console . log ( "Pubkey: " , keypair . publicKey . toBase58 ( ) ) ;
25+ const client = await GfxCpmmClient . load ( {
26+ connection : new Connection ( RPC_URL ) ,
27+ disableFeatureCheck : true ,
28+ disableLoadToken : true ,
29+ urlConfigs : {
30+ BASE_HOST : "" ,
31+ } ,
32+ owner : keypair ,
33+ } ) ;
3634
3735 const mints = await fetchMultipleMintInfos ( {
3836 connection : client . connection ,
3937 mints : [ MINT1 , MINT2 ] . map ( ( mint ) => new PublicKey ( mint ) ) ,
4038 config : {
41- batchRequest : true
42- }
43- } )
44- const mint1 = mints [ MINT1 ]
45- const mint2 = mints [ MINT2 ]
46- const feeConfig = await client . api . getConfig ( GAMMA_CONFIG . toBase58 ( ) )
39+ batchRequest : true ,
40+ } ,
41+ } ) ;
42+ const mint1 = mints [ MINT1 ] ;
43+ const mint2 = mints [ MINT2 ] ;
44+ const feeConfig = await client . api . getConfig ( GAMMA_CONFIG . toBase58 ( ) ) ;
4745
4846 let { transaction } = await client . cpmm . createPool ( {
4947 programId : GAMMA_PROGRAM ,
5048 poolFeeAccount : GAMMA_POOL_FEE_ACCOUNT ,
5149 mintA : {
5250 ...mint1 ,
5351 address : mint1 . address . toBase58 ( ) ,
54- programId : mint1 . programId . toBase58 ( )
52+ programId : mint1 . programId . toBase58 ( ) ,
5553 } ,
5654 mintB : {
5755 ...mint2 ,
5856 address : mint2 . address . toBase58 ( ) ,
59- programId : mint2 . programId . toBase58 ( )
57+ programId : mint2 . programId . toBase58 ( ) ,
6058 } ,
6159 mintAAmount : new BN ( MINT1_AMOUNT ) ,
6260 mintBAmount : new BN ( MINT2_AMOUNT ) ,
@@ -67,49 +65,49 @@ async function mainFn(): Promise<void> {
6765 associatedOnly : true ,
6866 checkCreateATAOwner : false ,
6967 ownerInfo : {
70- useSOLBalance : true
68+ useSOLBalance : true ,
7169 } ,
7270 computeBudgetConfig : {
7371 units : 200000 ,
74- microLamports : MICRO_LAMPORTS
72+ microLamports : MICRO_LAMPORTS ,
7573 } ,
76- txVersion : TxVersion . V0
77- } )
78-
79- const latestBlockhash = await client . connection . getLatestBlockhash ( )
80- transaction . message . recentBlockhash = latestBlockhash . blockhash
81- transaction . sign ( [ {
82- publicKey : keypair . publicKey ,
83- secretKey : keypair . secretKey
84- } ] )
74+ txVersion : TxVersion . V0 ,
75+ } ) ;
8576
86- console . log ( "Sending createPool transaction" )
87- const signature = await new Connection ( SEND_RPC_URL ) . sendTransaction (
88- transaction as unknown as VersionedTransaction ,
77+ const latestBlockhash = await client . connection . getLatestBlockhash ( ) ;
78+ transaction . message . recentBlockhash = latestBlockhash . blockhash ;
79+ transaction . sign ( [
8980 {
90- skipPreflight : true ,
91- preflightCommitment : 'confirmed' ,
92- maxRetries : 0 ,
93- }
94- )
95- console . log ( `Waiting to confirm transaction ${ signature } ` )
81+ publicKey : keypair . publicKey ,
82+ secretKey : keypair . secretKey ,
83+ } ,
84+ ] ) ;
85+
86+ console . log ( "Sending createPool transaction" ) ;
87+ const signature = await new Connection ( SEND_RPC_URL ) . sendTransaction ( transaction as unknown as VersionedTransaction , {
88+ skipPreflight : true ,
89+ preflightCommitment : "confirmed" ,
90+ maxRetries : 0 ,
91+ } ) ;
92+ console . log ( `Waiting to confirm transaction ${ signature } ` ) ;
9693
97- await client . connection . confirmTransaction ( {
98- signature,
99- blockhash : latestBlockhash . blockhash ,
100- lastValidBlockHeight : latestBlockhash . lastValidBlockHeight
101- } , 'confirmed' )
102- console . log ( `createPool txn confirmed. View at https://solscan.io/tx/${ signature } ` )
94+ await client . connection . confirmTransaction (
95+ {
96+ signature,
97+ blockhash : latestBlockhash . blockhash ,
98+ lastValidBlockHeight : latestBlockhash . lastValidBlockHeight ,
99+ } ,
100+ "confirmed" ,
101+ ) ;
102+ console . log ( `createPool txn confirmed. View at https://solscan.io/tx/${ signature } ` ) ;
103103}
104104
105- export function createKeypairFromFile (
106- filePath : string
107- ) : Keypair {
108- const secretKeyString = fs . readFileSync ( filePath , { encoding : 'utf8' } ) ;
105+ export function createKeypairFromFile ( filePath : string ) : Keypair {
106+ const secretKeyString = fs . readFileSync ( filePath , { encoding : "utf8" } ) ;
109107 const secretKey = Uint8Array . from ( JSON . parse ( secretKeyString ) ) ;
110108 return Keypair . fromSecretKey ( secretKey ) ;
111109}
112110
113111if ( require . main === module ) {
114- mainFn ( ) . catch ( console . error )
112+ mainFn ( ) . catch ( console . error ) ;
115113}
0 commit comments