@@ -2,9 +2,21 @@ import { DriftClient } from '../src/driftClient';
22import { grpcDriftClientAccountSubscriberV2 } from '../src/accounts/grpcDriftClientAccountSubscriberV2' ;
33import { Connection , Keypair , PublicKey } from '@solana/web3.js' ;
44import { DriftClientConfig } from '../src/driftClientConfig' ;
5- import { decodeName , DRIFT_PROGRAM_ID , Wallet } from '../src' ;
5+ import {
6+ decodeName ,
7+ DRIFT_PROGRAM_ID ,
8+ PerpMarketAccount ,
9+ Wallet ,
10+ } from '../src' ;
611import { CommitmentLevel } from '@triton-one/yellowstone-grpc' ;
712import dotenv from 'dotenv' ;
13+ import {
14+ AnchorProvider ,
15+ Idl ,
16+ Program ,
17+ ProgramAccount ,
18+ } from '@coral-xyz/anchor' ;
19+ import driftIDL from '../src/idl/drift.json' ;
820
921const GRPC_ENDPOINT = process . env . GRPC_ENDPOINT ;
1022const TOKEN = process . env . TOKEN ;
@@ -13,6 +25,43 @@ async function initializeGrpcDriftClientV2() {
1325 const connection = new Connection ( 'https://api.mainnet-beta.solana.com' ) ;
1426 const wallet = new Wallet ( new Keypair ( ) ) ;
1527 dotenv . config ( { path : '../' } ) ;
28+
29+ const programId = new PublicKey ( DRIFT_PROGRAM_ID ) ;
30+ const provider = new AnchorProvider (
31+ connection ,
32+ // @ts -ignore
33+ wallet ,
34+ {
35+ commitment : 'confirmed' ,
36+ }
37+ ) ;
38+
39+ const program = new Program ( driftIDL as Idl , programId , provider ) ;
40+
41+ const perpMarketProgramAccounts =
42+ ( await program . account . perpMarket . all ( ) ) as ProgramAccount < PerpMarketAccount > [ ] ;
43+ const solPerpMarket = perpMarketProgramAccounts . find (
44+ ( account ) => account . account . marketIndex === 0
45+ ) ;
46+ const solOracleInfo = {
47+ publicKey : solPerpMarket . account . amm . oracle ,
48+ source : solPerpMarket . account . amm . oracleSource ,
49+ } ;
50+ const ethPerpMarket = perpMarketProgramAccounts . find (
51+ ( account ) => account . account . marketIndex === 2
52+ ) ;
53+ const ethOracleInfo = {
54+ publicKey : ethPerpMarket . account . amm . oracle ,
55+ source : ethPerpMarket . account . amm . oracleSource ,
56+ } ;
57+ const btcPerpMarket = perpMarketProgramAccounts . find (
58+ ( account ) => account . account . marketIndex === 1
59+ ) ;
60+ const btcOracleInfo = {
61+ publicKey : btcPerpMarket . account . amm . oracle ,
62+ source : btcPerpMarket . account . amm . oracleSource ,
63+ } ;
64+
1665 const config : DriftClientConfig = {
1766 connection,
1867 wallet,
@@ -31,9 +80,9 @@ async function initializeGrpcDriftClientV2() {
3180 } ,
3281 driftClientAccountSubscriber : grpcDriftClientAccountSubscriberV2 ,
3382 } ,
34- perpMarketIndexes : [ 0 , 1 , 2 ] , // Example market indexes
35- spotMarketIndexes : [ 0 , 1 , 2 ] , // Example market indexes
36- oracleInfos : [ ] , // Add oracle information if needed
83+ perpMarketIndexes : [ 0 , 1 , 2 ] ,
84+ spotMarketIndexes : [ 0 , 1 , 2 ] ,
85+ oracleInfos : [ solOracleInfo , ethOracleInfo , btcOracleInfo ] ,
3786 } ;
3887
3988 const driftClient = new DriftClient ( config ) ;
0 commit comments