@drift-labs/sdk 2.142.0-beta.1 → 2.142.0-beta.10
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/bun.lock +25 -10
- package/lib/browser/accounts/grpcAccountSubscriber.d.ts +2 -1
- package/lib/browser/accounts/grpcAccountSubscriber.js +4 -2
- package/lib/browser/accounts/grpcDriftClientAccountSubscriber.d.ts +1 -1
- package/lib/browser/accounts/grpcDriftClientAccountSubscriber.js +3 -3
- package/lib/browser/accounts/grpcDriftClientAccountSubscriberV2.d.ts +24 -0
- package/lib/browser/accounts/grpcDriftClientAccountSubscriberV2.js +243 -0
- package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +34 -0
- package/lib/browser/accounts/grpcMultiAccountSubscriber.js +284 -0
- package/lib/browser/constants/spotMarkets.js +4 -4
- package/lib/browser/driftClient.js +11 -10
- package/lib/browser/driftClientConfig.d.ts +3 -0
- package/lib/browser/types.d.ts +3 -1
- package/lib/node/accounts/grpcAccountSubscriber.d.ts +2 -1
- package/lib/node/accounts/grpcAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcAccountSubscriber.js +4 -2
- package/lib/node/accounts/grpcDriftClientAccountSubscriber.d.ts +1 -1
- package/lib/node/accounts/grpcDriftClientAccountSubscriber.js +3 -3
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.d.ts +25 -0
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.d.ts.map +1 -0
- package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.js +243 -0
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +35 -0
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -0
- package/lib/node/accounts/grpcMultiAccountSubscriber.js +284 -0
- package/lib/node/constants/spotMarkets.js +4 -4
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +11 -10
- package/lib/node/driftClientConfig.d.ts +3 -0
- package/lib/node/driftClientConfig.d.ts.map +1 -1
- package/lib/node/isomorphic/grpc.d.ts +5 -3
- package/lib/node/isomorphic/grpc.js +1 -3
- package/lib/node/isomorphic/grpc.node.d.ts +5 -3
- package/lib/node/isomorphic/grpc.node.d.ts.map +1 -1
- package/lib/node/isomorphic/grpc.node.js +1 -3
- package/lib/node/types.d.ts +3 -1
- package/lib/node/types.d.ts.map +1 -1
- package/package.json +10 -4
- package/scripts/client-test.ts +214 -0
- package/src/accounts/grpcAccountSubscriber.ts +9 -6
- package/src/accounts/grpcDriftClientAccountSubscriber.ts +1 -1
- package/src/accounts/grpcDriftClientAccountSubscriberV2.ts +417 -0
- package/src/accounts/grpcMultiAccountSubscriber.ts +343 -0
- package/src/constants/spotMarkets.ts +4 -4
- package/src/driftClient.ts +5 -2
- package/src/driftClientConfig.ts +13 -0
- package/src/isomorphic/grpc.node.ts +11 -7
- package/src/types.ts +4 -2
|
@@ -0,0 +1,284 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.grpcMultiAccountSubscriber = void 0;
|
|
30
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
31
|
+
const Buffer = __importStar(require("buffer"));
|
|
32
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
33
|
+
const grpc_1 = require("../isomorphic/grpc");
|
|
34
|
+
class grpcMultiAccountSubscriber {
|
|
35
|
+
constructor(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe) {
|
|
36
|
+
this.isUnsubscribing = false;
|
|
37
|
+
this.receivingData = false;
|
|
38
|
+
this.subscribedAccounts = new Set();
|
|
39
|
+
this.onChangeMap = new Map();
|
|
40
|
+
this.dataMap = new Map();
|
|
41
|
+
this.client = client;
|
|
42
|
+
this.commitmentLevel = commitmentLevel;
|
|
43
|
+
this.accountName = accountName;
|
|
44
|
+
this.program = program;
|
|
45
|
+
this.decodeBufferFn = decodeBuffer;
|
|
46
|
+
this.resubOpts = resubOpts;
|
|
47
|
+
this.onUnsubscribe = onUnsubscribe;
|
|
48
|
+
}
|
|
49
|
+
static async create(grpcConfigs, accountName, program, decodeBuffer, resubOpts, clientProp, onUnsubscribe) {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
const client = clientProp
|
|
52
|
+
? clientProp
|
|
53
|
+
: await (0, grpc_1.createClient)(grpcConfigs.endpoint, grpcConfigs.token, (_a = grpcConfigs.channelOptions) !== null && _a !== void 0 ? _a : {});
|
|
54
|
+
const commitmentLevel =
|
|
55
|
+
// @ts-ignore :: isomorphic exported enum fails typescript but will work at runtime
|
|
56
|
+
(_b = grpcConfigs.commitmentLevel) !== null && _b !== void 0 ? _b : grpc_1.CommitmentLevel.CONFIRMED;
|
|
57
|
+
return new grpcMultiAccountSubscriber(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe);
|
|
58
|
+
}
|
|
59
|
+
setAccountData(accountPubkey, data, slot) {
|
|
60
|
+
this.dataMap.set(accountPubkey, { data, slot });
|
|
61
|
+
}
|
|
62
|
+
getAccountData(accountPubkey) {
|
|
63
|
+
return this.dataMap.get(accountPubkey);
|
|
64
|
+
}
|
|
65
|
+
getAccountDataMap() {
|
|
66
|
+
return this.dataMap;
|
|
67
|
+
}
|
|
68
|
+
async subscribe(accounts, onChange) {
|
|
69
|
+
if (this.listenerId != null || this.isUnsubscribing) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// Track accounts and single onChange for all
|
|
73
|
+
for (const pk of accounts) {
|
|
74
|
+
const key = pk.toBase58();
|
|
75
|
+
this.subscribedAccounts.add(key);
|
|
76
|
+
this.onChangeMap.set(key, (data, ctx, buffer) => {
|
|
77
|
+
this.setAccountData(key, data, ctx.slot);
|
|
78
|
+
onChange(new web3_js_1.PublicKey(key), data, ctx, buffer);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
this.stream =
|
|
82
|
+
(await this.client.subscribe());
|
|
83
|
+
const request = {
|
|
84
|
+
slots: {},
|
|
85
|
+
accounts: {
|
|
86
|
+
account: {
|
|
87
|
+
account: accounts.map((a) => a.toBase58()),
|
|
88
|
+
owner: [],
|
|
89
|
+
filters: [],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
transactions: {},
|
|
93
|
+
blocks: {},
|
|
94
|
+
blocksMeta: {},
|
|
95
|
+
accountsDataSlice: [],
|
|
96
|
+
commitment: this.commitmentLevel,
|
|
97
|
+
entry: {},
|
|
98
|
+
transactionsStatus: {},
|
|
99
|
+
};
|
|
100
|
+
this.stream.on('data', (chunk) => {
|
|
101
|
+
var _a;
|
|
102
|
+
if (!chunk.account) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const slot = Number(chunk.account.slot);
|
|
106
|
+
const accountPubkeyBytes = chunk.account.account.pubkey;
|
|
107
|
+
const accountPubkey = bs58_1.default.encode(accountPubkeyBytes);
|
|
108
|
+
if (!accountPubkey || !this.subscribedAccounts.has(accountPubkey)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const accountInfo = {
|
|
112
|
+
owner: new web3_js_1.PublicKey(chunk.account.account.owner),
|
|
113
|
+
lamports: Number(chunk.account.account.lamports),
|
|
114
|
+
data: Buffer.Buffer.from(chunk.account.account.data),
|
|
115
|
+
executable: chunk.account.account.executable,
|
|
116
|
+
rentEpoch: Number(chunk.account.account.rentEpoch),
|
|
117
|
+
};
|
|
118
|
+
const context = { slot };
|
|
119
|
+
const buffer = accountInfo.data;
|
|
120
|
+
const data = this.decodeBufferFn
|
|
121
|
+
? this.decodeBufferFn(buffer, accountPubkey)
|
|
122
|
+
: this.program.account[this.accountName].coder.accounts.decode(this.capitalize(this.accountName), buffer);
|
|
123
|
+
const handler = this.onChangeMap.get(accountPubkey);
|
|
124
|
+
if (handler) {
|
|
125
|
+
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
|
|
126
|
+
this.receivingData = true;
|
|
127
|
+
clearTimeout(this.timeoutId);
|
|
128
|
+
handler(data, context, buffer);
|
|
129
|
+
this.setTimeout();
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
handler(data, context, buffer);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
return new Promise((resolve, reject) => {
|
|
137
|
+
this.stream.write(request, (err) => {
|
|
138
|
+
var _a;
|
|
139
|
+
if (err === null || err === undefined) {
|
|
140
|
+
this.listenerId = 1;
|
|
141
|
+
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
|
|
142
|
+
this.receivingData = true;
|
|
143
|
+
this.setTimeout();
|
|
144
|
+
}
|
|
145
|
+
resolve();
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
reject(err);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}).catch((reason) => {
|
|
152
|
+
console.error(reason);
|
|
153
|
+
throw reason;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
async addAccounts(accounts) {
|
|
157
|
+
for (const pk of accounts) {
|
|
158
|
+
this.subscribedAccounts.add(pk.toBase58());
|
|
159
|
+
}
|
|
160
|
+
const request = {
|
|
161
|
+
slots: {},
|
|
162
|
+
accounts: {
|
|
163
|
+
account: {
|
|
164
|
+
account: Array.from(this.subscribedAccounts.values()),
|
|
165
|
+
owner: [],
|
|
166
|
+
filters: [],
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
transactions: {},
|
|
170
|
+
blocks: {},
|
|
171
|
+
blocksMeta: {},
|
|
172
|
+
accountsDataSlice: [],
|
|
173
|
+
commitment: this.commitmentLevel,
|
|
174
|
+
entry: {},
|
|
175
|
+
transactionsStatus: {},
|
|
176
|
+
};
|
|
177
|
+
await new Promise((resolve, reject) => {
|
|
178
|
+
this.stream.write(request, (err) => {
|
|
179
|
+
if (err === null || err === undefined) {
|
|
180
|
+
resolve();
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
reject(err);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
async removeAccounts(accounts) {
|
|
189
|
+
for (const pk of accounts) {
|
|
190
|
+
const k = pk.toBase58();
|
|
191
|
+
this.subscribedAccounts.delete(k);
|
|
192
|
+
this.onChangeMap.delete(k);
|
|
193
|
+
}
|
|
194
|
+
const request = {
|
|
195
|
+
slots: {},
|
|
196
|
+
accounts: {
|
|
197
|
+
account: {
|
|
198
|
+
account: Array.from(this.subscribedAccounts.values()),
|
|
199
|
+
owner: [],
|
|
200
|
+
filters: [],
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
transactions: {},
|
|
204
|
+
blocks: {},
|
|
205
|
+
blocksMeta: {},
|
|
206
|
+
accountsDataSlice: [],
|
|
207
|
+
commitment: this.commitmentLevel,
|
|
208
|
+
entry: {},
|
|
209
|
+
transactionsStatus: {},
|
|
210
|
+
};
|
|
211
|
+
await new Promise((resolve, reject) => {
|
|
212
|
+
this.stream.write(request, (err) => {
|
|
213
|
+
if (err === null || err === undefined) {
|
|
214
|
+
resolve();
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
reject(err);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
async unsubscribe() {
|
|
223
|
+
this.isUnsubscribing = true;
|
|
224
|
+
clearTimeout(this.timeoutId);
|
|
225
|
+
this.timeoutId = undefined;
|
|
226
|
+
if (this.listenerId != null) {
|
|
227
|
+
const promise = new Promise((resolve, reject) => {
|
|
228
|
+
const request = {
|
|
229
|
+
slots: {},
|
|
230
|
+
accounts: {},
|
|
231
|
+
transactions: {},
|
|
232
|
+
blocks: {},
|
|
233
|
+
blocksMeta: {},
|
|
234
|
+
accountsDataSlice: [],
|
|
235
|
+
entry: {},
|
|
236
|
+
transactionsStatus: {},
|
|
237
|
+
};
|
|
238
|
+
this.stream.write(request, (err) => {
|
|
239
|
+
if (err === null || err === undefined) {
|
|
240
|
+
this.listenerId = undefined;
|
|
241
|
+
this.isUnsubscribing = false;
|
|
242
|
+
resolve();
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
reject(err);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}).catch((reason) => {
|
|
249
|
+
console.error(reason);
|
|
250
|
+
throw reason;
|
|
251
|
+
});
|
|
252
|
+
return promise;
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
this.isUnsubscribing = false;
|
|
256
|
+
}
|
|
257
|
+
if (this.onUnsubscribe) {
|
|
258
|
+
try {
|
|
259
|
+
await this.onUnsubscribe();
|
|
260
|
+
}
|
|
261
|
+
catch (e) {
|
|
262
|
+
console.error(e);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
setTimeout() {
|
|
267
|
+
var _a;
|
|
268
|
+
this.timeoutId = setTimeout(async () => {
|
|
269
|
+
if (this.isUnsubscribing) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (this.receivingData) {
|
|
273
|
+
await this.unsubscribe();
|
|
274
|
+
this.receivingData = false;
|
|
275
|
+
}
|
|
276
|
+
}, (_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs);
|
|
277
|
+
}
|
|
278
|
+
capitalize(value) {
|
|
279
|
+
if (!value)
|
|
280
|
+
return value;
|
|
281
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
exports.grpcMultiAccountSubscriber = grpcMultiAccountSubscriber;
|
|
@@ -11,8 +11,8 @@ exports.DevnetSpotMarkets = [
|
|
|
11
11
|
symbol: 'USDC',
|
|
12
12
|
marketIndex: 0,
|
|
13
13
|
poolId: 0,
|
|
14
|
-
oracle: new web3_js_1.PublicKey('
|
|
15
|
-
oracleSource: types_1.OracleSource.
|
|
14
|
+
oracle: new web3_js_1.PublicKey('9VCioxmni2gDLv11qufWzT3RDERhQE4iY5Gf7NTfYyAV'),
|
|
15
|
+
oracleSource: types_1.OracleSource.PYTH_LAZER_STABLE_COIN,
|
|
16
16
|
mint: new web3_js_1.PublicKey('8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2'),
|
|
17
17
|
precision: new anchor_1.BN(10).pow(numericConstants_1.SIX),
|
|
18
18
|
precisionExp: numericConstants_1.SIX,
|
|
@@ -23,8 +23,8 @@ exports.DevnetSpotMarkets = [
|
|
|
23
23
|
symbol: 'SOL',
|
|
24
24
|
marketIndex: 1,
|
|
25
25
|
poolId: 0,
|
|
26
|
-
oracle: new web3_js_1.PublicKey('
|
|
27
|
-
oracleSource: types_1.OracleSource.
|
|
26
|
+
oracle: new web3_js_1.PublicKey('3m6i4RFWEDw2Ft4tFHPJtYgmpPe21k56M3FHeWYrgGBz'),
|
|
27
|
+
oracleSource: types_1.OracleSource.PYTH_LAZER,
|
|
28
28
|
mint: new web3_js_1.PublicKey(exports.WRAPPED_SOL_MINT),
|
|
29
29
|
precision: numericConstants_1.LAMPORTS_PRECISION,
|
|
30
30
|
precisionExp: numericConstants_1.LAMPORTS_EXP,
|
|
@@ -86,7 +86,7 @@ class DriftClient {
|
|
|
86
86
|
this._isSubscribed = val;
|
|
87
87
|
}
|
|
88
88
|
constructor(config) {
|
|
89
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23;
|
|
89
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25;
|
|
90
90
|
this.users = new Map();
|
|
91
91
|
this._isSubscribed = false;
|
|
92
92
|
this.perpMarketLastSlotCache = new Map();
|
|
@@ -208,17 +208,18 @@ class DriftClient {
|
|
|
208
208
|
this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_6 = config.perpMarketIndexes) !== null && _6 !== void 0 ? _6 : [], (_7 = config.spotMarketIndexes) !== null && _7 !== void 0 ? _7 : [], (_8 = config.oracleInfos) !== null && _8 !== void 0 ? _8 : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
|
|
209
209
|
}
|
|
210
210
|
else if (((_9 = config.accountSubscription) === null || _9 === void 0 ? void 0 : _9.type) === 'grpc') {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
211
|
+
const accountSubscriberClass = (_11 = (_10 = config.accountSubscription) === null || _10 === void 0 ? void 0 : _10.driftClientAccountSubscriber) !== null && _11 !== void 0 ? _11 : grpcDriftClientAccountSubscriber_1.grpcDriftClientAccountSubscriber;
|
|
212
|
+
this.accountSubscriber = new accountSubscriberClass(config.accountSubscription.grpcConfigs, this.program, (_12 = config.perpMarketIndexes) !== null && _12 !== void 0 ? _12 : [], (_13 = config.spotMarketIndexes) !== null && _13 !== void 0 ? _13 : [], (_14 = config.oracleInfos) !== null && _14 !== void 0 ? _14 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
|
|
213
|
+
resubTimeoutMs: (_15 = config.accountSubscription) === null || _15 === void 0 ? void 0 : _15.resubTimeoutMs,
|
|
214
|
+
logResubMessages: (_16 = config.accountSubscription) === null || _16 === void 0 ? void 0 : _16.logResubMessages,
|
|
214
215
|
});
|
|
215
216
|
}
|
|
216
217
|
else {
|
|
217
|
-
const accountSubscriberClass = (
|
|
218
|
-
this.accountSubscriber = new accountSubscriberClass(this.program, (
|
|
219
|
-
resubTimeoutMs: (
|
|
220
|
-
logResubMessages: (
|
|
221
|
-
}, (
|
|
218
|
+
const accountSubscriberClass = (_18 = (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.driftClientAccountSubscriber) !== null && _18 !== void 0 ? _18 : webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber;
|
|
219
|
+
this.accountSubscriber = new accountSubscriberClass(this.program, (_19 = config.perpMarketIndexes) !== null && _19 !== void 0 ? _19 : [], (_20 = config.spotMarketIndexes) !== null && _20 !== void 0 ? _20 : [], (_21 = config.oracleInfos) !== null && _21 !== void 0 ? _21 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
|
|
220
|
+
resubTimeoutMs: (_22 = config.accountSubscription) === null || _22 === void 0 ? void 0 : _22.resubTimeoutMs,
|
|
221
|
+
logResubMessages: (_23 = config.accountSubscription) === null || _23 === void 0 ? void 0 : _23.logResubMessages,
|
|
222
|
+
}, (_24 = config.accountSubscription) === null || _24 === void 0 ? void 0 : _24.commitment);
|
|
222
223
|
}
|
|
223
224
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
224
225
|
this.metricsEventEmitter = new events_1.EventEmitter();
|
|
@@ -226,7 +227,7 @@ class DriftClient {
|
|
|
226
227
|
this.enableMetricsEvents = true;
|
|
227
228
|
}
|
|
228
229
|
this.txSender =
|
|
229
|
-
(
|
|
230
|
+
(_25 = config.txSender) !== null && _25 !== void 0 ? _25 : new retryTxSender_1.RetryTxSender({
|
|
230
231
|
connection: this.connection,
|
|
231
232
|
wallet: this.wallet,
|
|
232
233
|
opts: this.opts,
|
|
@@ -14,6 +14,8 @@ import { WebSocketAccountSubscriberV2 } from './accounts/webSocketAccountSubscri
|
|
|
14
14
|
import { WebSocketProgramAccountSubscriber } from './accounts/webSocketProgramAccountSubscriber';
|
|
15
15
|
import { WebSocketDriftClientAccountSubscriberV2 } from './accounts/webSocketDriftClientAccountSubscriberV2';
|
|
16
16
|
import { WebSocketDriftClientAccountSubscriber } from './accounts/webSocketDriftClientAccountSubscriber';
|
|
17
|
+
import { grpcDriftClientAccountSubscriberV2 } from './accounts/grpcDriftClientAccountSubscriberV2';
|
|
18
|
+
import { grpcDriftClientAccountSubscriber } from './accounts/grpcDriftClientAccountSubscriber';
|
|
17
19
|
export type DriftClientConfig = {
|
|
18
20
|
connection: Connection;
|
|
19
21
|
wallet: IWallet;
|
|
@@ -49,6 +51,7 @@ export type DriftClientSubscriptionConfig = {
|
|
|
49
51
|
grpcConfigs: GrpcConfigs;
|
|
50
52
|
resubTimeoutMs?: number;
|
|
51
53
|
logResubMessages?: boolean;
|
|
54
|
+
driftClientAccountSubscriber?: new (grpcConfigs: GrpcConfigs, program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, delistedMarketSetting: DelistedMarketSetting) => grpcDriftClientAccountSubscriberV2 | grpcDriftClientAccountSubscriber;
|
|
52
55
|
} | {
|
|
53
56
|
type: 'websocket';
|
|
54
57
|
resubTimeoutMs?: number;
|
package/lib/browser/types.d.ts
CHANGED
|
@@ -1649,12 +1649,14 @@ export type RevenueShareEscrowAccount = {
|
|
|
1649
1649
|
approvedBuilders: BuilderInfo[];
|
|
1650
1650
|
};
|
|
1651
1651
|
export type RevenueShareOrder = {
|
|
1652
|
-
builderIdx: number;
|
|
1653
1652
|
feesAccrued: BN;
|
|
1654
1653
|
orderId: number;
|
|
1655
1654
|
feeTenthBps: number;
|
|
1656
1655
|
marketIndex: number;
|
|
1656
|
+
subAccountId: number;
|
|
1657
|
+
builderIdx: number;
|
|
1657
1658
|
bitFlags: number;
|
|
1659
|
+
userOrderIndex: number;
|
|
1658
1660
|
marketType: MarketType;
|
|
1659
1661
|
padding: number[];
|
|
1660
1662
|
};
|
|
@@ -4,13 +4,14 @@ import { ResubOpts, GrpcConfigs } from './types';
|
|
|
4
4
|
import { Program } from '@coral-xyz/anchor';
|
|
5
5
|
import { PublicKey } from '@solana/web3.js';
|
|
6
6
|
import { WebSocketAccountSubscriber } from './webSocketAccountSubscriber';
|
|
7
|
+
import { Client } from '../isomorphic/grpc';
|
|
7
8
|
export declare class grpcAccountSubscriber<T> extends WebSocketAccountSubscriber<T> {
|
|
8
9
|
private client;
|
|
9
10
|
private stream;
|
|
10
11
|
private commitmentLevel;
|
|
11
12
|
listenerId?: number;
|
|
12
13
|
private constructor();
|
|
13
|
-
static create<U>(grpcConfigs: GrpcConfigs, accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => U, resubOpts?: ResubOpts): Promise<grpcAccountSubscriber<U>>;
|
|
14
|
+
static create<U>(grpcConfigs: GrpcConfigs, accountName: string, program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => U, resubOpts?: ResubOpts, clientProp?: Client): Promise<grpcAccountSubscriber<U>>;
|
|
14
15
|
subscribe(onChange: (data: T) => void): Promise<void>;
|
|
15
16
|
unsubscribe(onResub?: boolean): Promise<void>;
|
|
16
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grpcAccountSubscriber.d.ts","sourceRoot":"","sources":["../../../src/accounts/grpcAccountSubscriber.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"grpcAccountSubscriber.d.ts","sourceRoot":"","sources":["../../../src/accounts/grpcAccountSubscriber.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EACN,MAAM,EAMN,MAAM,oBAAoB,CAAC;AAE5B,qBAAa,qBAAqB,CAAC,CAAC,CAAE,SAAQ,0BAA0B,CAAC,CAAC,CAAC;IAC1E,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAwD;IACtE,OAAO,CAAC,eAAe,CAAkB;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE3B,OAAO;WAca,MAAM,CAAC,CAAC,EAC3B,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,EAChB,gBAAgB,EAAE,SAAS,EAC3B,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,EACpC,SAAS,CAAC,EAAE,SAAS,EACrB,UAAU,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAuBrB,SAAS,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAkFrD,WAAW,CAAC,OAAO,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAsC1D"}
|
|
@@ -34,9 +34,11 @@ class grpcAccountSubscriber extends webSocketAccountSubscriber_1.WebSocketAccoun
|
|
|
34
34
|
this.client = client;
|
|
35
35
|
this.commitmentLevel = commitmentLevel;
|
|
36
36
|
}
|
|
37
|
-
static async create(grpcConfigs, accountName, program, accountPublicKey, decodeBuffer, resubOpts) {
|
|
37
|
+
static async create(grpcConfigs, accountName, program, accountPublicKey, decodeBuffer, resubOpts, clientProp) {
|
|
38
38
|
var _a, _b;
|
|
39
|
-
const client =
|
|
39
|
+
const client = clientProp
|
|
40
|
+
? clientProp
|
|
41
|
+
: await (0, grpc_1.createClient)(grpcConfigs.endpoint, grpcConfigs.token, (_a = grpcConfigs.channelOptions) !== null && _a !== void 0 ? _a : {});
|
|
40
42
|
const commitmentLevel =
|
|
41
43
|
// @ts-ignore :: isomorphic exported enum fails typescript but will work at runtime
|
|
42
44
|
(_b = grpcConfigs.commitmentLevel) !== null && _b !== void 0 ? _b : grpc_1.CommitmentLevel.CONFIRMED;
|
|
@@ -2,7 +2,7 @@ import { WebSocketDriftClientAccountSubscriber } from './webSocketDriftClientAcc
|
|
|
2
2
|
import { OracleInfo } from '../oracles/types';
|
|
3
3
|
import { Program } from '@coral-xyz/anchor';
|
|
4
4
|
import { DelistedMarketSetting, GrpcConfigs, ResubOpts } from './types';
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class grpcDriftClientAccountSubscriber extends WebSocketDriftClientAccountSubscriber {
|
|
6
6
|
private grpcConfigs;
|
|
7
7
|
constructor(grpcConfigs: GrpcConfigs, program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, delistedMarketSetting: DelistedMarketSetting, resubOpts?: ResubOpts);
|
|
8
8
|
subscribe(): Promise<boolean>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.grpcDriftClientAccountSubscriber = void 0;
|
|
4
4
|
const webSocketDriftClientAccountSubscriber_1 = require("./webSocketDriftClientAccountSubscriber");
|
|
5
5
|
const config_1 = require("../config");
|
|
6
6
|
const pda_1 = require("../addresses/pda");
|
|
7
7
|
const grpcAccountSubscriber_1 = require("./grpcAccountSubscriber");
|
|
8
8
|
const oracleId_1 = require("../oracles/oracleId");
|
|
9
|
-
class
|
|
9
|
+
class grpcDriftClientAccountSubscriber extends webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber {
|
|
10
10
|
constructor(grpcConfigs, program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, delistedMarketSetting, resubOpts) {
|
|
11
11
|
super(program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, delistedMarketSetting, resubOpts);
|
|
12
12
|
this.grpcConfigs = grpcConfigs;
|
|
@@ -96,4 +96,4 @@ class gprcDriftClientAccountSubscriber extends webSocketDriftClientAccountSubscr
|
|
|
96
96
|
return true;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
exports.
|
|
99
|
+
exports.grpcDriftClientAccountSubscriber = grpcDriftClientAccountSubscriber;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { WebSocketDriftClientAccountSubscriber } from './webSocketDriftClientAccountSubscriber';
|
|
2
|
+
import { OracleInfo } from '../oracles/types';
|
|
3
|
+
import { Program } from '@coral-xyz/anchor';
|
|
4
|
+
import { DataAndSlot, DelistedMarketSetting, GrpcConfigs, ResubOpts } from './types';
|
|
5
|
+
import { PerpMarketAccount, SpotMarketAccount } from '../types';
|
|
6
|
+
export declare class grpcDriftClientAccountSubscriberV2 extends WebSocketDriftClientAccountSubscriber {
|
|
7
|
+
private grpcConfigs;
|
|
8
|
+
private perpMarketsSubscriber?;
|
|
9
|
+
private spotMarketsSubscriber?;
|
|
10
|
+
private oracleMultiSubscriber?;
|
|
11
|
+
private perpMarketIndexToAccountPubkeyMap;
|
|
12
|
+
private spotMarketIndexToAccountPubkeyMap;
|
|
13
|
+
constructor(grpcConfigs: GrpcConfigs, program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, delistedMarketSetting: DelistedMarketSetting, resubOpts?: ResubOpts);
|
|
14
|
+
subscribe(): Promise<boolean>;
|
|
15
|
+
getMarketAccountAndSlot(marketIndex: number): DataAndSlot<PerpMarketAccount> | undefined;
|
|
16
|
+
getSpotMarketAccountAndSlot(marketIndex: number): DataAndSlot<SpotMarketAccount> | undefined;
|
|
17
|
+
setPerpOracleMap(): Promise<void>;
|
|
18
|
+
setSpotOracleMap(): Promise<void>;
|
|
19
|
+
subscribeToPerpMarketAccounts(): Promise<boolean>;
|
|
20
|
+
subscribeToSpotMarketAccounts(): Promise<boolean>;
|
|
21
|
+
subscribeToOracles(): Promise<boolean>;
|
|
22
|
+
unsubscribeFromOracles(): Promise<void>;
|
|
23
|
+
unsubscribe(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=grpcDriftClientAccountSubscriberV2.d.ts.map
|
|
@@ -0,0 +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,iBAAiB,EAAE,iBAAiB,EAAgB,MAAM,UAAU,CAAC;AAM9E,qBAAa,kCAAmC,SAAQ,qCAAqC;IAC5F,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,qBAAqB,CAAC,CAAgD;IAC9E,OAAO,CAAC,qBAAqB,CAAC,CAAgD;IAC9E,OAAO,CAAC,qBAAqB,CAAC,CAA8C;IAC5E,OAAO,CAAC,iCAAiC,CAA6B;IACtE,OAAO,CAAC,iCAAiC,CAA6B;gBAGrE,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,OAAO,EAChB,iBAAiB,EAAE,MAAM,EAAE,EAC3B,iBAAiB,EAAE,MAAM,EAAE,EAC3B,WAAW,EAAE,UAAU,EAAE,EACzB,8BAA8B,EAAE,OAAO,EACvC,qBAAqB,EAAE,qBAAqB,EAC5C,SAAS,CAAC,EAAE,SAAS;IAcT,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAiFjC,uBAAuB,CAC/B,WAAW,EAAE,MAAM,GACjB,WAAW,CAAC,iBAAiB,CAAC,GAAG,SAAS;IAMpC,2BAA2B,CACnC,WAAW,EAAE,MAAM,GACjB,WAAW,CAAC,iBAAiB,CAAC,GAAG,SAAS;IAM9B,gBAAgB;IA0BhB,gBAAgB;IA0BhB,6BAA6B,IAAI,OAAO,CAAC,OAAO,CAAC;IA8DjD,6BAA6B,IAAI,OAAO,CAAC,OAAO,CAAC;IA8DjD,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC;IAyE/C,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAS9B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAO3C"}
|