1
+ import { PublicKey } from "@solana/web3.js" ;
2
+ import { SYSTEM_PROGRAM_ID } from "@coral-xyz/anchor/dist/cjs/native/system" ;
3
+
4
+ import { TxnHelpers } from "./utils/transaction" ;
5
+ import { IntentPda , intentProgram , wallet , connection } from "./setup" ;
6
+
7
+ const txnHelpers = new TxnHelpers ( connection , wallet . payer ) ;
8
+
9
+ const args = process . argv . slice ( 2 ) ;
10
+ if ( args . length != 2 ) throw new Error ( "Invalid arguments" ) ;
11
+
12
+ const networkId = args [ 0 ] ;
13
+ const feeHandler = new PublicKey ( args [ 1 ] ) ;
14
+
15
+ const initializeContract = async ( ) => {
16
+ let config = await intentProgram . account . config . fetchNullable (
17
+ IntentPda . config ( ) . pda
18
+ ) ;
19
+ if ( ! config ) {
20
+ const initializeIx = await intentProgram . methods
21
+ . initialize ( networkId , feeHandler )
22
+ . signers ( [ wallet . payer ] )
23
+ . accountsStrict ( {
24
+ signer : wallet . publicKey ,
25
+ systemProgram : SYSTEM_PROGRAM_ID ,
26
+ config : IntentPda . config ( ) . pda ,
27
+ nativeVaultAccount : IntentPda . vaultNative ( ) . pda ,
28
+ } )
29
+ . instruction ( ) ;
30
+
31
+ const tx = await txnHelpers . buildV0Txn ( [ initializeIx ] , [ wallet . payer ] ) ;
32
+ const txSig = await connection . sendTransaction ( tx ) ;
33
+ return txSig ;
34
+ }
35
+ } ;
36
+
37
+ initializeContract ( )
38
+ . then ( async ( res ) => {
39
+ console . log ( "Contract initializing" ) ;
40
+ if ( res ) await txnHelpers . logParsedTx ( res ) ;
41
+ console . log ( "Contract initialized successfully" ) ;
42
+ } )
43
+ . catch ( ( err ) => {
44
+ console . log ( err ) ;
45
+ } ) ;
0 commit comments