@drift-labs/sdk 2.96.0-beta.2 → 2.96.0-beta.4

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.
Files changed (55) hide show
  1. package/VERSION +1 -1
  2. package/lib/accounts/types.d.ts +0 -8
  3. package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -1
  4. package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +3 -3
  5. package/lib/accounts/webSocketProgramAccountSubscriber.d.ts +1 -1
  6. package/lib/constants/spotMarkets.js +1 -1
  7. package/lib/driftClient.js +14 -35
  8. package/lib/driftClientConfig.d.ts +0 -6
  9. package/lib/orderSubscriber/OrderSubscriber.d.ts +1 -2
  10. package/lib/orderSubscriber/OrderSubscriber.js +4 -19
  11. package/lib/orderSubscriber/types.d.ts +0 -9
  12. package/lib/user.js +4 -11
  13. package/lib/userConfig.d.ts +1 -6
  14. package/lib/userMap/userMap.js +0 -14
  15. package/lib/userMap/userMapConfig.d.ts +0 -7
  16. package/lib/userStatsConfig.d.ts +0 -6
  17. package/package.json +1 -3
  18. package/src/accounts/types.ts +0 -9
  19. package/src/accounts/webSocketAccountSubscriber.ts +1 -1
  20. package/src/accounts/webSocketDriftClientAccountSubscriber.ts +3 -3
  21. package/src/accounts/webSocketProgramAccountSubscriber.ts +1 -1
  22. package/src/constants/spotMarkets.ts +1 -1
  23. package/src/driftClient.ts +0 -28
  24. package/src/driftClientConfig.ts +0 -7
  25. package/src/orderSubscriber/OrderSubscriber.ts +1 -15
  26. package/src/orderSubscriber/types.ts +0 -10
  27. package/src/user.ts +0 -11
  28. package/src/userConfig.ts +1 -7
  29. package/src/userMap/userMap.ts +1 -17
  30. package/src/userMap/userMapConfig.ts +0 -8
  31. package/src/userStatsConfig.ts +0 -7
  32. package/lib/accounts/grpcAccountSubscriber.d.ts +0 -16
  33. package/lib/accounts/grpcAccountSubscriber.js +0 -155
  34. package/lib/accounts/grpcDriftClientAccountSubscriber.d.ts +0 -13
  35. package/lib/accounts/grpcDriftClientAccountSubscriber.js +0 -96
  36. package/lib/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +0 -10
  37. package/lib/accounts/grpcInsuranceFundStakeAccountSubscriber.js +0 -30
  38. package/lib/accounts/grpcProgramAccountSubscriber.d.ts +0 -19
  39. package/lib/accounts/grpcProgramAccountSubscriber.js +0 -161
  40. package/lib/accounts/grpcUserAccountSubscriber.d.ts +0 -10
  41. package/lib/accounts/grpcUserAccountSubscriber.js +0 -28
  42. package/lib/accounts/grpcUserStatsAccountSubscriber.d.ts +0 -10
  43. package/lib/accounts/grpcUserStatsAccountSubscriber.js +0 -28
  44. package/lib/orderSubscriber/grpcSubscription.d.ts +0 -25
  45. package/lib/orderSubscriber/grpcSubscription.js +0 -68
  46. package/lib/userMap/grpcSubscription.d.ts +0 -26
  47. package/lib/userMap/grpcSubscription.js +0 -42
  48. package/src/accounts/grpcAccountSubscriber.ts +0 -158
  49. package/src/accounts/grpcDriftClientAccountSubscriber.ts +0 -196
  50. package/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +0 -62
  51. package/src/accounts/grpcProgramAccountSubscriber.ts +0 -181
  52. package/src/accounts/grpcUserAccountSubscriber.ts +0 -48
  53. package/src/accounts/grpcUserStatsAccountSubscriber.ts +0 -51
  54. package/src/orderSubscriber/grpcSubscription.ts +0 -126
  55. package/src/userMap/grpcSubscription.ts +0 -83
package/src/userConfig.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DriftClient } from './driftClient';
2
2
  import { Commitment, PublicKey } from '@solana/web3.js';
3
3
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
- import { GrpcConfigs, UserAccountSubscriber } from './accounts/types';
4
+ import { UserAccountSubscriber } from './accounts/types';
5
5
 
6
6
  export type UserConfig = {
7
7
  accountSubscription?: UserSubscriptionConfig;
@@ -23,10 +23,4 @@ export type UserSubscriptionConfig =
23
23
  | {
24
24
  type: 'custom';
25
25
  userAccountSubscriber: UserAccountSubscriber;
26
- }
27
- | {
28
- type: 'grpc';
29
- resubTimeoutMs?: number;
30
- logResubMessages?: boolean;
31
- configs: GrpcConfigs;
32
26
  };
@@ -36,7 +36,6 @@ import {
36
36
  import { WebsocketSubscription } from './WebsocketSubscription';
37
37
  import { PollingSubscription } from './PollingSubscription';
38
38
  import { decodeUser } from '../decode/user';
39
- import { grpcSubscription } from './grpcSubscription';
40
39
 
41
40
  const MAX_USER_ACCOUNT_SIZE_BYTES = 4376;
42
41
 
@@ -76,10 +75,7 @@ export class UserMap implements UserMapInterface {
76
75
  private includeIdle: boolean;
77
76
  private disableSyncOnTotalAccountsChange: boolean;
78
77
  private lastNumberOfSubAccounts: BN;
79
- private subscription:
80
- | PollingSubscription
81
- | WebsocketSubscription
82
- | grpcSubscription;
78
+ private subscription: PollingSubscription | WebsocketSubscription;
83
79
  private stateAccountUpdateCallback = async (state: StateAccount) => {
84
80
  if (!state.numberOfSubAccounts.eq(this.lastNumberOfSubAccounts)) {
85
81
  await this.sync();
@@ -126,18 +122,6 @@ export class UserMap implements UserMapInterface {
126
122
  frequency: config.subscriptionConfig.frequency,
127
123
  skipInitialLoad: config.skipInitialLoad,
128
124
  });
129
- } else if (config.subscriptionConfig.type === 'grpc') {
130
- this.subscription = new grpcSubscription({
131
- configs: config.subscriptionConfig.configs,
132
- userMap: this,
133
- commitment: this.commitment,
134
- resubOpts: {
135
- resubTimeoutMs: config.subscriptionConfig.resubTimeoutMs,
136
- logResubMessages: config.subscriptionConfig.logResubMessages,
137
- },
138
- skipInitialLoad: config.skipInitialLoad,
139
- decodeFn,
140
- });
141
125
  } else {
142
126
  this.subscription = new WebsocketSubscription({
143
127
  userMap: this,
@@ -1,6 +1,5 @@
1
1
  import { Commitment, Connection } from '@solana/web3.js';
2
2
  import { DriftClient } from '../driftClient';
3
- import { GrpcConfigs } from '../accounts/types';
4
3
 
5
4
  // passed into UserMap.getUniqueAuthorities to filter users
6
5
  export type UserAccountFilterCriteria = {
@@ -28,13 +27,6 @@ export type UserMapConfig = {
28
27
  frequency: number;
29
28
  commitment?: Commitment;
30
29
  }
31
- | {
32
- type: 'grpc';
33
- configs: GrpcConfigs;
34
- resubTimeoutMs?: number;
35
- logResubMessages?: boolean;
36
- commitment?: Commitment;
37
- }
38
30
  | {
39
31
  type: 'websocket';
40
32
  resubTimeoutMs?: number;
@@ -1,7 +1,6 @@
1
1
  import { DriftClient } from './driftClient';
2
2
  import { Commitment, PublicKey } from '@solana/web3.js';
3
3
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
- import { GrpcConfigs } from './accounts/types';
5
4
 
6
5
  export type UserStatsConfig = {
7
6
  accountSubscription?: UserStatsSubscriptionConfig;
@@ -22,10 +21,4 @@ export type UserStatsSubscriptionConfig =
22
21
  }
23
22
  | {
24
23
  type: 'custom';
25
- }
26
- | {
27
- type: 'grpc';
28
- resubTimeoutMs?: number;
29
- logResubMessages?: boolean;
30
- configs: GrpcConfigs;
31
24
  };
@@ -1,16 +0,0 @@
1
- /// <reference types="node" />
2
- import { ResubOpts, GrpcConfigs } from './types';
3
- import { Program } from '@coral-xyz/anchor';
4
- import { PublicKey } from '@solana/web3.js';
5
- import { ClientDuplexStream } from '@grpc/grpc-js';
6
- import Client, { CommitmentLevel, SubscribeRequest, SubscribeUpdate } from '@triton-one/yellowstone-grpc';
7
- import { WebSocketAccountSubscriber } from './webSocketAccountSubscriber';
8
- export declare class grpcAccountSubscriber<T> extends WebSocketAccountSubscriber<T> {
9
- client: Client;
10
- stream: ClientDuplexStream<SubscribeRequest, SubscribeUpdate>;
11
- commitmentLevel: CommitmentLevel;
12
- listenerId?: number;
13
- constructor(grpcConfigs: GrpcConfigs, accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => T, resubOpts?: ResubOpts);
14
- subscribe(onChange: (data: T) => void): Promise<void>;
15
- unsubscribe(onResub?: boolean): Promise<void>;
16
- }
@@ -1,155 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.grpcAccountSubscriber = void 0;
27
- const web3_js_1 = require("@solana/web3.js");
28
- const Buffer = __importStar(require("buffer"));
29
- const yellowstone_grpc_1 = __importStar(require("@triton-one/yellowstone-grpc"));
30
- const webSocketAccountSubscriber_1 = require("./webSocketAccountSubscriber");
31
- class grpcAccountSubscriber extends webSocketAccountSubscriber_1.WebSocketAccountSubscriber {
32
- constructor(grpcConfigs, accountName, program, accountPublicKey, decodeBuffer, resubOpts) {
33
- var _a, _b;
34
- super(accountName, program, accountPublicKey, decodeBuffer, resubOpts);
35
- this.client = new yellowstone_grpc_1.default(grpcConfigs.endpoint, grpcConfigs.token, (_a = grpcConfigs.channelOptions) !== null && _a !== void 0 ? _a : {});
36
- this.commitmentLevel =
37
- (_b = grpcConfigs.commitmentLevel) !== null && _b !== void 0 ? _b : yellowstone_grpc_1.CommitmentLevel.CONFIRMED;
38
- }
39
- async subscribe(onChange) {
40
- if (this.listenerId != null || this.isUnsubscribing) {
41
- return;
42
- }
43
- this.onChange = onChange;
44
- if (!this.dataAndSlot) {
45
- await this.fetch();
46
- }
47
- // Subscribe with grpc
48
- this.stream = await this.client.subscribe();
49
- const request = {
50
- slots: {
51
- slots: {},
52
- },
53
- accounts: {
54
- account: {
55
- account: [this.accountPublicKey.toString()],
56
- owner: [],
57
- filters: [],
58
- },
59
- },
60
- transactions: {},
61
- blocks: {},
62
- blocksMeta: {},
63
- accountsDataSlice: [],
64
- commitment: this.commitmentLevel,
65
- entry: {},
66
- transactionsStatus: {},
67
- };
68
- this.stream.on('data', (chunk) => {
69
- var _a;
70
- if (!chunk.account) {
71
- return;
72
- }
73
- const slot = Number(chunk.account.slot);
74
- const accountInfo = {
75
- owner: new web3_js_1.PublicKey(chunk.account.account.owner),
76
- lamports: Number(chunk.account.account.lamports),
77
- data: Buffer.Buffer.from(chunk.account.account.data),
78
- executable: chunk.account.account.executable,
79
- rentEpoch: Number(chunk.account.account.rentEpoch),
80
- };
81
- if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
82
- this.receivingData = true;
83
- clearTimeout(this.timeoutId);
84
- this.handleRpcResponse({
85
- slot,
86
- }, accountInfo);
87
- this.setTimeout();
88
- }
89
- else {
90
- this.handleRpcResponse({
91
- slot,
92
- }, accountInfo);
93
- }
94
- });
95
- return new Promise((resolve, reject) => {
96
- this.stream.write(request, (err) => {
97
- var _a;
98
- if (err === null || err === undefined) {
99
- this.listenerId = 1;
100
- if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
101
- this.receivingData = true;
102
- this.setTimeout();
103
- }
104
- resolve();
105
- }
106
- else {
107
- reject(err);
108
- }
109
- });
110
- }).catch((reason) => {
111
- console.error(reason);
112
- throw reason;
113
- });
114
- }
115
- async unsubscribe(onResub = false) {
116
- if (!onResub && this.resubOpts) {
117
- this.resubOpts.resubTimeoutMs = undefined;
118
- }
119
- this.isUnsubscribing = true;
120
- clearTimeout(this.timeoutId);
121
- this.timeoutId = undefined;
122
- if (this.listenerId != null) {
123
- const promise = new Promise((resolve, reject) => {
124
- const request = {
125
- slots: {},
126
- accounts: {},
127
- transactions: {},
128
- blocks: {},
129
- blocksMeta: {},
130
- accountsDataSlice: [],
131
- entry: {},
132
- transactionsStatus: {},
133
- };
134
- this.stream.write(request, (err) => {
135
- if (err === null || err === undefined) {
136
- this.listenerId = undefined;
137
- this.isUnsubscribing = false;
138
- resolve();
139
- }
140
- else {
141
- reject(err);
142
- }
143
- });
144
- }).catch((reason) => {
145
- console.error(reason);
146
- throw reason;
147
- });
148
- return promise;
149
- }
150
- else {
151
- this.isUnsubscribing = false;
152
- }
153
- }
154
- }
155
- exports.grpcAccountSubscriber = grpcAccountSubscriber;
@@ -1,13 +0,0 @@
1
- import { WebSocketDriftClientAccountSubscriber } from './webSocketDriftClientAccountSubscriber';
2
- import { OracleInfo } from '../oracles/types';
3
- import { Program } from '@coral-xyz/anchor';
4
- import { GrpcConfigs, ResubOpts } from './types';
5
- import { Commitment } from '@solana/web3.js';
6
- export declare class gprcDriftClientAccountSubscriber extends WebSocketDriftClientAccountSubscriber {
7
- private grpcConfigs;
8
- constructor(grpcConfigs: GrpcConfigs, program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, resubOpts?: ResubOpts, commitment?: Commitment);
9
- subscribe(): Promise<boolean>;
10
- subscribeToSpotMarketAccount(marketIndex: number): Promise<boolean>;
11
- subscribeToPerpMarketAccount(marketIndex: number): Promise<boolean>;
12
- subscribeToOracle(oracleInfo: OracleInfo): Promise<boolean>;
13
- }
@@ -1,96 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.gprcDriftClientAccountSubscriber = void 0;
4
- const webSocketDriftClientAccountSubscriber_1 = require("./webSocketDriftClientAccountSubscriber");
5
- const config_1 = require("../config");
6
- const pda_1 = require("../addresses/pda");
7
- const grpcAccountSubscriber_1 = require("./grpcAccountSubscriber");
8
- class gprcDriftClientAccountSubscriber extends webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber {
9
- constructor(grpcConfigs, program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, resubOpts, commitment) {
10
- super(program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, resubOpts, commitment);
11
- this.grpcConfigs = grpcConfigs;
12
- }
13
- async subscribe() {
14
- if (this.isSubscribed) {
15
- return true;
16
- }
17
- if (this.isSubscribing) {
18
- return await this.subscriptionPromise;
19
- }
20
- this.isSubscribing = true;
21
- this.subscriptionPromise = new Promise((res) => {
22
- this.subscriptionPromiseResolver = res;
23
- });
24
- if (this.shouldFindAllMarketsAndOracles) {
25
- const { perpMarketIndexes, perpMarketAccounts, spotMarketIndexes, spotMarketAccounts, oracleInfos, } = await (0, config_1.findAllMarketAndOracles)(this.program);
26
- this.perpMarketIndexes = perpMarketIndexes;
27
- this.spotMarketIndexes = spotMarketIndexes;
28
- this.oracleInfos = oracleInfos;
29
- // front run and set the initial data here to save extra gma call in set initial data
30
- this.initialPerpMarketAccountData = new Map(perpMarketAccounts.map((market) => [market.marketIndex, market]));
31
- this.initialSpotMarketAccountData = new Map(spotMarketAccounts.map((market) => [market.marketIndex, market]));
32
- }
33
- const statePublicKey = await (0, pda_1.getDriftStateAccountPublicKey)(this.program.programId);
34
- // create and activate main state account subscription
35
- this.stateAccountSubscriber = new grpcAccountSubscriber_1.grpcAccountSubscriber(this.grpcConfigs, 'state', this.program, statePublicKey, undefined, undefined);
36
- await this.stateAccountSubscriber.subscribe((data) => {
37
- this.eventEmitter.emit('stateAccountUpdate', data);
38
- this.eventEmitter.emit('update');
39
- });
40
- // set initial data to avoid spamming getAccountInfo calls in webSocketAccountSubscriber
41
- await this.setInitialData();
42
- await Promise.all([
43
- // subscribe to market accounts
44
- this.subscribeToPerpMarketAccounts(),
45
- // subscribe to spot market accounts
46
- this.subscribeToSpotMarketAccounts(),
47
- // subscribe to oracles
48
- this.subscribeToOracles(),
49
- ]);
50
- this.eventEmitter.emit('update');
51
- await Promise.all([this.setPerpOracleMap(), this.setSpotOracleMap()]);
52
- this.subscriptionPromiseResolver(true);
53
- this.isSubscribing = false;
54
- this.isSubscribed = true;
55
- // delete initial data
56
- this.removeInitialData();
57
- return true;
58
- }
59
- async subscribeToSpotMarketAccount(marketIndex) {
60
- const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
61
- const accountSubscriber = new grpcAccountSubscriber_1.grpcAccountSubscriber(this.grpcConfigs, 'spotMarket', this.program, marketPublicKey, undefined, this.resubOpts);
62
- accountSubscriber.setData(this.initialSpotMarketAccountData.get(marketIndex));
63
- await accountSubscriber.subscribe((data) => {
64
- this.eventEmitter.emit('spotMarketAccountUpdate', data);
65
- this.eventEmitter.emit('update');
66
- });
67
- this.spotMarketAccountSubscribers.set(marketIndex, accountSubscriber);
68
- return true;
69
- }
70
- async subscribeToPerpMarketAccount(marketIndex) {
71
- const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
72
- const accountSubscriber = new grpcAccountSubscriber_1.grpcAccountSubscriber(this.grpcConfigs, 'perpMarket', this.program, perpMarketPublicKey, undefined, this.resubOpts);
73
- accountSubscriber.setData(this.initialPerpMarketAccountData.get(marketIndex));
74
- await accountSubscriber.subscribe((data) => {
75
- this.eventEmitter.emit('perpMarketAccountUpdate', data);
76
- this.eventEmitter.emit('update');
77
- });
78
- this.perpMarketAccountSubscribers.set(marketIndex, accountSubscriber);
79
- return true;
80
- }
81
- async subscribeToOracle(oracleInfo) {
82
- const oracleString = oracleInfo.publicKey.toString();
83
- const client = this.oracleClientCache.get(oracleInfo.source, this.program.provider.connection, this.program);
84
- const accountSubscriber = new grpcAccountSubscriber_1.grpcAccountSubscriber(this.grpcConfigs, 'oracle', this.program, oracleInfo.publicKey, (buffer) => {
85
- return client.getOraclePriceDataFromBuffer(buffer);
86
- }, this.resubOpts);
87
- accountSubscriber.setData(this.initialOraclePriceData.get(oracleString));
88
- await accountSubscriber.subscribe((data) => {
89
- this.eventEmitter.emit('oraclePriceUpdate', oracleInfo.publicKey, data);
90
- this.eventEmitter.emit('update');
91
- });
92
- this.oracleSubscribers.set(oracleString, accountSubscriber);
93
- return true;
94
- }
95
- }
96
- exports.gprcDriftClientAccountSubscriber = gprcDriftClientAccountSubscriber;
@@ -1,10 +0,0 @@
1
- import { GrpcConfigs } from './types';
2
- import { Program } from '@coral-xyz/anchor';
3
- import { Commitment, PublicKey } from '@solana/web3.js';
4
- import { InsuranceFundStake } from '../types';
5
- import { WebSocketInsuranceFundStakeAccountSubscriber } from './webSocketInsuranceFundStakeAccountSubscriber';
6
- export declare class grpcInsuranceFundStakeAccountSubscriber extends WebSocketInsuranceFundStakeAccountSubscriber {
7
- private grpcConfigs;
8
- constructor(grpcConfigs: GrpcConfigs, program: Program, insuranceFundStakeAccountPublicKey: PublicKey, resubTimeoutMs?: number, commitment?: Commitment);
9
- subscribe(insuranceFundStakeAccount?: InsuranceFundStake): Promise<boolean>;
10
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.grpcInsuranceFundStakeAccountSubscriber = void 0;
4
- const webSocketInsuranceFundStakeAccountSubscriber_1 = require("./webSocketInsuranceFundStakeAccountSubscriber");
5
- const grpcAccountSubscriber_1 = require("./grpcAccountSubscriber");
6
- class grpcInsuranceFundStakeAccountSubscriber extends webSocketInsuranceFundStakeAccountSubscriber_1.WebSocketInsuranceFundStakeAccountSubscriber {
7
- constructor(grpcConfigs, program, insuranceFundStakeAccountPublicKey, resubTimeoutMs, commitment) {
8
- super(program, insuranceFundStakeAccountPublicKey, resubTimeoutMs, commitment);
9
- this.grpcConfigs = grpcConfigs;
10
- }
11
- async subscribe(insuranceFundStakeAccount) {
12
- if (this.isSubscribed) {
13
- return true;
14
- }
15
- this.insuranceFundStakeDataAccountSubscriber = new grpcAccountSubscriber_1.grpcAccountSubscriber(this.grpcConfigs, 'insuranceFundStake', this.program, this.insuranceFundStakeAccountPublicKey, undefined, {
16
- resubTimeoutMs: this.resubTimeoutMs,
17
- });
18
- if (insuranceFundStakeAccount) {
19
- this.insuranceFundStakeDataAccountSubscriber.setData(insuranceFundStakeAccount);
20
- }
21
- await this.insuranceFundStakeDataAccountSubscriber.subscribe((data) => {
22
- this.eventEmitter.emit('insuranceFundStakeAccountUpdate', data);
23
- this.eventEmitter.emit('update');
24
- });
25
- this.eventEmitter.emit('update');
26
- this.isSubscribed = true;
27
- return true;
28
- }
29
- }
30
- exports.grpcInsuranceFundStakeAccountSubscriber = grpcInsuranceFundStakeAccountSubscriber;
@@ -1,19 +0,0 @@
1
- /// <reference types="node" />
2
- import { ResubOpts, GrpcConfigs } from './types';
3
- import { Program } from '@coral-xyz/anchor';
4
- import { Commitment, Context, MemcmpFilter, PublicKey } from '@solana/web3.js';
5
- import { WebSocketProgramAccountSubscriber } from './webSocketProgramAccountSubscriber';
6
- import { ClientDuplexStream } from '@grpc/grpc-js';
7
- import Client, { SubscribeRequest, SubscribeUpdate, CommitmentLevel } from '@triton-one/yellowstone-grpc';
8
- export declare class grpcProgramAccountSubscriber<T> extends WebSocketProgramAccountSubscriber<T> {
9
- client: Client;
10
- stream: ClientDuplexStream<SubscribeRequest, SubscribeUpdate>;
11
- commitmentLevel: CommitmentLevel;
12
- listenerId?: number;
13
- constructor(grpcConfigs: GrpcConfigs, subscriptionName: string, accountDiscriminator: string, program: Program, decodeBufferFn: (accountName: string, ix: Buffer) => T, options?: {
14
- filters: MemcmpFilter[];
15
- commitment?: Commitment;
16
- }, resubOpts?: ResubOpts);
17
- subscribe(onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer) => void): Promise<void>;
18
- unsubscribe(onResub?: boolean): Promise<void>;
19
- }
@@ -1,161 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.grpcProgramAccountSubscriber = void 0;
27
- const web3_js_1 = require("@solana/web3.js");
28
- const Buffer = __importStar(require("buffer"));
29
- const webSocketProgramAccountSubscriber_1 = require("./webSocketProgramAccountSubscriber");
30
- const yellowstone_grpc_1 = __importStar(require("@triton-one/yellowstone-grpc"));
31
- class grpcProgramAccountSubscriber extends webSocketProgramAccountSubscriber_1.WebSocketProgramAccountSubscriber {
32
- constructor(grpcConfigs, subscriptionName, accountDiscriminator, program, decodeBufferFn, options = {
33
- filters: [],
34
- }, resubOpts) {
35
- var _a, _b;
36
- super(subscriptionName, accountDiscriminator, program, decodeBufferFn, options, resubOpts);
37
- this.client = new yellowstone_grpc_1.default(grpcConfigs.endpoint, grpcConfigs.token, (_a = grpcConfigs.channelOptions) !== null && _a !== void 0 ? _a : {});
38
- this.commitmentLevel =
39
- (_b = grpcConfigs.commitmentLevel) !== null && _b !== void 0 ? _b : yellowstone_grpc_1.CommitmentLevel.CONFIRMED;
40
- }
41
- async subscribe(onChange) {
42
- if (this.listenerId != null || this.isUnsubscribing) {
43
- return;
44
- }
45
- this.onChange = onChange;
46
- // Subscribe with grpc
47
- this.stream = await this.client.subscribe();
48
- const request = {
49
- slots: {
50
- slots: {},
51
- },
52
- accounts: {
53
- drift: {
54
- account: [],
55
- owner: [this.program.programId.toBase58()],
56
- // @ts-ignore
57
- filters: this.options.filters,
58
- },
59
- },
60
- transactions: {},
61
- blocks: {},
62
- blocksMeta: {},
63
- accountsDataSlice: [],
64
- commitment: this.commitmentLevel,
65
- entry: {},
66
- transactionsStatus: {},
67
- };
68
- this.stream.on('data', (chunk) => {
69
- var _a;
70
- if (!chunk.account) {
71
- return;
72
- }
73
- const slot = Number(chunk.account.slot);
74
- const accountInfo = {
75
- owner: new web3_js_1.PublicKey(chunk.account.account.owner),
76
- lamports: Number(chunk.account.account.lamports),
77
- data: Buffer.Buffer.from(chunk.account.account.data),
78
- executable: chunk.account.account.executable,
79
- rentEpoch: Number(chunk.account.account.rentEpoch),
80
- };
81
- if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
82
- this.receivingData = true;
83
- clearTimeout(this.timeoutId);
84
- this.handleRpcResponse({
85
- slot,
86
- }, {
87
- accountId: new web3_js_1.PublicKey(chunk.account.account.pubkey),
88
- accountInfo,
89
- });
90
- this.setTimeout();
91
- }
92
- else {
93
- this.handleRpcResponse({
94
- slot,
95
- }, {
96
- accountId: new web3_js_1.PublicKey(chunk.account.account.pubkey),
97
- accountInfo,
98
- });
99
- }
100
- });
101
- return new Promise((resolve, reject) => {
102
- this.stream.write(request, (err) => {
103
- var _a;
104
- if (err === null || err === undefined) {
105
- this.listenerId = 1;
106
- if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
107
- this.receivingData = true;
108
- this.setTimeout();
109
- }
110
- resolve();
111
- }
112
- else {
113
- reject(err);
114
- }
115
- });
116
- }).catch((reason) => {
117
- console.error(reason);
118
- throw reason;
119
- });
120
- }
121
- async unsubscribe(onResub = false) {
122
- if (!onResub && this.resubOpts) {
123
- this.resubOpts.resubTimeoutMs = undefined;
124
- }
125
- this.isUnsubscribing = true;
126
- clearTimeout(this.timeoutId);
127
- this.timeoutId = undefined;
128
- if (this.listenerId != null) {
129
- const promise = new Promise((resolve, reject) => {
130
- const request = {
131
- slots: {},
132
- accounts: {},
133
- transactions: {},
134
- blocks: {},
135
- blocksMeta: {},
136
- accountsDataSlice: [],
137
- entry: {},
138
- transactionsStatus: {},
139
- };
140
- this.stream.write(request, (err) => {
141
- if (err === null || err === undefined) {
142
- this.listenerId = undefined;
143
- this.isUnsubscribing = false;
144
- resolve();
145
- }
146
- else {
147
- reject(err);
148
- }
149
- });
150
- }).catch((reason) => {
151
- console.error(reason);
152
- throw reason;
153
- });
154
- return promise;
155
- }
156
- else {
157
- this.isUnsubscribing = false;
158
- }
159
- }
160
- }
161
- exports.grpcProgramAccountSubscriber = grpcProgramAccountSubscriber;
@@ -1,10 +0,0 @@
1
- import { ResubOpts, GrpcConfigs } from './types';
2
- import { Program } from '@coral-xyz/anchor';
3
- import { PublicKey } from '@solana/web3.js';
4
- import { UserAccount } from '../types';
5
- import { WebSocketUserAccountSubscriber } from './webSocketUserAccountSubscriber';
6
- export declare class grpcUserAccountSubscriber extends WebSocketUserAccountSubscriber {
7
- private grpcConfigs;
8
- constructor(grpcConfigs: GrpcConfigs, program: Program, userAccountPublicKey: PublicKey, resubOpts?: ResubOpts);
9
- subscribe(userAccount?: UserAccount): Promise<boolean>;
10
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.grpcUserAccountSubscriber = void 0;
4
- const webSocketUserAccountSubscriber_1 = require("./webSocketUserAccountSubscriber");
5
- const grpcAccountSubscriber_1 = require("./grpcAccountSubscriber");
6
- class grpcUserAccountSubscriber extends webSocketUserAccountSubscriber_1.WebSocketUserAccountSubscriber {
7
- constructor(grpcConfigs, program, userAccountPublicKey, resubOpts) {
8
- super(program, userAccountPublicKey, resubOpts);
9
- this.grpcConfigs = grpcConfigs;
10
- }
11
- async subscribe(userAccount) {
12
- if (this.isSubscribed) {
13
- return true;
14
- }
15
- this.userDataAccountSubscriber = new grpcAccountSubscriber_1.grpcAccountSubscriber(this.grpcConfigs, 'user', this.program, this.userAccountPublicKey, undefined, this.resubOpts);
16
- if (userAccount) {
17
- this.userDataAccountSubscriber.setData(userAccount);
18
- }
19
- await this.userDataAccountSubscriber.subscribe((data) => {
20
- this.eventEmitter.emit('userAccountUpdate', data);
21
- this.eventEmitter.emit('update');
22
- });
23
- this.eventEmitter.emit('update');
24
- this.isSubscribed = true;
25
- return true;
26
- }
27
- }
28
- exports.grpcUserAccountSubscriber = grpcUserAccountSubscriber;
@@ -1,10 +0,0 @@
1
- import { ResubOpts, GrpcConfigs } from './types';
2
- import { Program } from '@coral-xyz/anchor';
3
- import { Commitment, PublicKey } from '@solana/web3.js';
4
- import { UserStatsAccount } from '../types';
5
- import { WebSocketUserStatsAccountSubscriber } from './webSocketUserStatsAccountSubsriber';
6
- export declare class grpcUserStatsAccountSubscriber extends WebSocketUserStatsAccountSubscriber {
7
- private grpcConfigs;
8
- constructor(grpcConfigs: GrpcConfigs, program: Program, userStatsAccountPublicKey: PublicKey, resubOpts?: ResubOpts, commitment?: Commitment);
9
- subscribe(userStatsAccount?: UserStatsAccount): Promise<boolean>;
10
- }