@drift-labs/sdk 2.142.0-beta.4 → 2.142.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/VERSION +1 -1
- package/lib/browser/accounts/grpcDriftClientAccountSubscriberV2.js +2 -1
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.js +2 -1
- package/package.json +1 -1
- package/scripts/client-test.ts +53 -4
- package/src/accounts/grpcDriftClientAccountSubscriberV2.ts +6 -5
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.142.0-beta.
|
|
1
|
+
2.142.0-beta.5
|
|
@@ -167,7 +167,8 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
167
167
|
}
|
|
168
168
|
});
|
|
169
169
|
for (const data of this.initialOraclePriceData.entries()) {
|
|
170
|
-
|
|
170
|
+
const { publicKey } = (0, oracleId_1.getPublicKeyAndSourceFromOracleId)(data[0]);
|
|
171
|
+
this.oracleMultiSubscriber.setAccountData(publicKey, data[1]);
|
|
171
172
|
}
|
|
172
173
|
await this.oracleMultiSubscriber.subscribe(oraclePubkeys, (accountId, data) => {
|
|
173
174
|
const source = pubkeyToSource.get(accountId.toBase58());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grpcDriftClientAccountSubscriberV2.d.ts","sourceRoot":"","sources":["../../../src/accounts/grpcDriftClientAccountSubscriberV2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qCAAqC,EAAE,MAAM,yCAAyC,CAAC;AAChG,OAAO,EAAE,UAAU,EAAmB,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAQ5C,OAAO,EACN,WAAW,EACX,qBAAqB,EACrB,WAAW,EACX,SAAS,EACT,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE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IA2DjD,6BAA6B,IAAI,OAAO,CAAC,OAAO,CAAC;IA2DjD,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC;IAyE/C,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAS9B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAO3C"}
|
|
@@ -167,7 +167,8 @@ class grpcDriftClientAccountSubscriberV2 extends webSocketDriftClientAccountSubs
|
|
|
167
167
|
}
|
|
168
168
|
});
|
|
169
169
|
for (const data of this.initialOraclePriceData.entries()) {
|
|
170
|
-
|
|
170
|
+
const { publicKey } = (0, oracleId_1.getPublicKeyAndSourceFromOracleId)(data[0]);
|
|
171
|
+
this.oracleMultiSubscriber.setAccountData(publicKey, data[1]);
|
|
171
172
|
}
|
|
172
173
|
await this.oracleMultiSubscriber.subscribe(oraclePubkeys, (accountId, data) => {
|
|
173
174
|
const source = pubkeyToSource.get(accountId.toBase58());
|
package/package.json
CHANGED
package/scripts/client-test.ts
CHANGED
|
@@ -2,9 +2,21 @@ import { DriftClient } from '../src/driftClient';
|
|
|
2
2
|
import { grpcDriftClientAccountSubscriberV2 } from '../src/accounts/grpcDriftClientAccountSubscriberV2';
|
|
3
3
|
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
4
4
|
import { DriftClientConfig } from '../src/driftClientConfig';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
decodeName,
|
|
7
|
+
DRIFT_PROGRAM_ID,
|
|
8
|
+
PerpMarketAccount,
|
|
9
|
+
Wallet,
|
|
10
|
+
} from '../src';
|
|
6
11
|
import { CommitmentLevel } from '@triton-one/yellowstone-grpc';
|
|
7
12
|
import 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';
|
|
8
20
|
|
|
9
21
|
const GRPC_ENDPOINT = process.env.GRPC_ENDPOINT;
|
|
10
22
|
const TOKEN = process.env.TOKEN;
|
|
@@ -13,6 +25,43 @@ async function initializeGrpcDriftClientV2() {
|
|
|
13
25
|
const connection = new Connection('https://api.mainnet-beta.solana.com');
|
|
14
26
|
const wallet = new Wallet(new Keypair());
|
|
15
27
|
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
|
+
|
|
16
65
|
const config: DriftClientConfig = {
|
|
17
66
|
connection,
|
|
18
67
|
wallet,
|
|
@@ -31,9 +80,9 @@ async function initializeGrpcDriftClientV2() {
|
|
|
31
80
|
},
|
|
32
81
|
driftClientAccountSubscriber: grpcDriftClientAccountSubscriberV2,
|
|
33
82
|
},
|
|
34
|
-
perpMarketIndexes: [0, 1, 2],
|
|
35
|
-
spotMarketIndexes: [0, 1, 2],
|
|
36
|
-
oracleInfos: [
|
|
83
|
+
perpMarketIndexes: [0, 1, 2],
|
|
84
|
+
spotMarketIndexes: [0, 1, 2],
|
|
85
|
+
oracleInfos: [solOracleInfo, ethOracleInfo, btcOracleInfo],
|
|
37
86
|
};
|
|
38
87
|
|
|
39
88
|
const driftClient = new DriftClient(config);
|
|
@@ -17,7 +17,10 @@ import {
|
|
|
17
17
|
import { grpcAccountSubscriber } from './grpcAccountSubscriber';
|
|
18
18
|
import { grpcMultiAccountSubscriber } from './grpcMultiAccountSubscriber';
|
|
19
19
|
import { PerpMarketAccount, SpotMarketAccount, StateAccount } from '../types';
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
getOracleId,
|
|
22
|
+
getPublicKeyAndSourceFromOracleId,
|
|
23
|
+
} from '../oracles/oracleId';
|
|
21
24
|
|
|
22
25
|
export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAccountSubscriber {
|
|
23
26
|
private grpcConfigs: GrpcConfigs;
|
|
@@ -321,10 +324,8 @@ export class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAcco
|
|
|
321
324
|
);
|
|
322
325
|
|
|
323
326
|
for (const data of this.initialOraclePriceData.entries()) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
data[1]
|
|
327
|
-
);
|
|
327
|
+
const { publicKey } = getPublicKeyAndSourceFromOracleId(data[0]);
|
|
328
|
+
this.oracleMultiSubscriber.setAccountData(publicKey, data[1]);
|
|
328
329
|
}
|
|
329
330
|
|
|
330
331
|
await this.oracleMultiSubscriber.subscribe(
|