@drift-labs/sdk 2.161.0-beta.0 → 2.161.0-beta.1

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 CHANGED
@@ -1 +1 @@
1
- 2.161.0-beta.0
1
+ 2.161.0-beta.1
@@ -2,13 +2,18 @@
2
2
  import { Keypair } from '@solana/web3.js';
3
3
  import { BN } from '@coral-xyz/anchor';
4
4
  type Quote = {
5
- bidPrice: BN;
6
- askPrice: BN;
7
- bidBaseAssetAmount: BN;
8
- askBaseAssetAmount: BN;
5
+ bidPrice: BN | null;
6
+ askPrice: BN | null;
7
+ bidBaseAssetAmount: BN | null;
8
+ askBaseAssetAmount: BN | null;
9
9
  marketIndex: number;
10
10
  isOracleOffset?: boolean;
11
11
  };
12
+ type WsMessage = {
13
+ channel: string;
14
+ nonce?: string;
15
+ message?: string;
16
+ };
12
17
  export declare class IndicativeQuotesSender {
13
18
  private endpoint;
14
19
  private keypair;
@@ -21,7 +26,7 @@ export declare class IndicativeQuotesSender {
21
26
  private quotes;
22
27
  constructor(endpoint: string, keypair: Keypair);
23
28
  generateChallengeResponse(nonce: string): string;
24
- handleAuthMessage(message: any): void;
29
+ handleAuthMessage(message: WsMessage): void;
25
30
  connect(): Promise<void>;
26
31
  private startHeartbeatTimer;
27
32
  setQuote(newQuotes: Quote | Quote[]): void;
@@ -72,10 +72,18 @@ class IndicativeQuotesSender {
72
72
  market_type: 'perp',
73
73
  quotes: quotes.map((quote) => {
74
74
  return {
75
- bid_price: quote.bidPrice.toString(),
76
- ask_price: quote.askPrice.toString(),
77
- bid_size: quote.bidBaseAssetAmount.toString(),
78
- ask_size: quote.askBaseAssetAmount.toString(),
75
+ bid_price: quote.bidPrice
76
+ ? quote.bidPrice.toString()
77
+ : null,
78
+ ask_price: quote.askPrice
79
+ ? quote.askPrice.toString()
80
+ : null,
81
+ bid_size: quote.bidBaseAssetAmount
82
+ ? quote.bidBaseAssetAmount.toString()
83
+ : null,
84
+ ask_size: quote.askBaseAssetAmount
85
+ ? quote.askBaseAssetAmount.toString()
86
+ : null,
79
87
  is_oracle_offset: quote.isOracleOffset,
80
88
  };
81
89
  }),
@@ -113,8 +121,8 @@ class IndicativeQuotesSender {
113
121
  this.reconnect();
114
122
  }, 5000);
115
123
  });
116
- ws.on('error', async (request, response) => {
117
- console.error('WS closed from error, reconnecting in 1s:', response);
124
+ ws.on('error', async (error) => {
125
+ console.error('WS closed from error, reconnecting in 1s:', error);
118
126
  setTimeout(() => {
119
127
  if (this.heartbeatTimeout)
120
128
  clearTimeout(this.heartbeatTimeout);
@@ -157,9 +165,9 @@ class IndicativeQuotesSender {
157
165
  }
158
166
  (_a = newQuoteMap.get(quote.marketIndex)) === null || _a === void 0 ? void 0 : _a.push(quote);
159
167
  }
160
- for (const marketIndex of newQuoteMap.keys()) {
161
- this.quotes.set(marketIndex, newQuoteMap.get(marketIndex));
162
- }
168
+ newQuoteMap.forEach((quotes, marketIndex) => {
169
+ this.quotes.set(marketIndex, quotes);
170
+ });
163
171
  }
164
172
  reconnect() {
165
173
  if (this.ws) {
@@ -2,13 +2,18 @@
2
2
  import { Keypair } from '@solana/web3.js';
3
3
  import { BN } from '@coral-xyz/anchor';
4
4
  type Quote = {
5
- bidPrice: BN;
6
- askPrice: BN;
7
- bidBaseAssetAmount: BN;
8
- askBaseAssetAmount: BN;
5
+ bidPrice: BN | null;
6
+ askPrice: BN | null;
7
+ bidBaseAssetAmount: BN | null;
8
+ askBaseAssetAmount: BN | null;
9
9
  marketIndex: number;
10
10
  isOracleOffset?: boolean;
11
11
  };
12
+ type WsMessage = {
13
+ channel: string;
14
+ nonce?: string;
15
+ message?: string;
16
+ };
12
17
  export declare class IndicativeQuotesSender {
13
18
  private endpoint;
14
19
  private keypair;
@@ -21,7 +26,7 @@ export declare class IndicativeQuotesSender {
21
26
  private quotes;
22
27
  constructor(endpoint: string, keypair: Keypair);
23
28
  generateChallengeResponse(nonce: string): string;
24
- handleAuthMessage(message: any): void;
29
+ handleAuthMessage(message: WsMessage): void;
25
30
  connect(): Promise<void>;
26
31
  private startHeartbeatTimer;
27
32
  setQuote(newQuotes: Quote | Quote[]): void;
@@ -1 +1 @@
1
- {"version":3,"file":"indicativeQuotesSender.d.ts","sourceRoot":"","sources":["../../../src/indicative-quotes/indicativeQuotesSender.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAQvC,KAAK,KAAK,GAAG;IACZ,QAAQ,EAAE,EAAE,CAAC;IACb,QAAQ,EAAE,EAAE,CAAC;IACb,kBAAkB,EAAE,EAAE,CAAC;IACvB,kBAAkB,EAAE,EAAE,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,qBAAa,sBAAsB;IAYjC,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,OAAO;IAZhB,OAAO,CAAC,gBAAgB,CAA8C;IACtE,OAAO,CAAC,kBAAkB,CAA8C;IAExE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAC7C,OAAO,CAAC,cAAc,CAAQ;IAC9B,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,SAAS,CAAS;IAE1B,OAAO,CAAC,MAAM,CAAmC;gBAGxC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,OAAO;IAGzB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAOhD,iBAAiB,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI;IAmB/B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA4F9B,OAAO,CAAC,mBAAmB;IAU3B,QAAQ,CAAC,SAAS,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,IAAI;IAiC1C,OAAO,CAAC,SAAS;CAuBjB"}
1
+ {"version":3,"file":"indicativeQuotes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AuBjB"}
@@ -72,10 +72,18 @@ class IndicativeQuotesSender {
72
72
  market_type: 'perp',
73
73
  quotes: quotes.map((quote) => {
74
74
  return {
75
- bid_price: quote.bidPrice.toString(),
76
- ask_price: quote.askPrice.toString(),
77
- bid_size: quote.bidBaseAssetAmount.toString(),
78
- ask_size: quote.askBaseAssetAmount.toString(),
75
+ bid_price: quote.bidPrice
76
+ ? quote.bidPrice.toString()
77
+ : null,
78
+ ask_price: quote.askPrice
79
+ ? quote.askPrice.toString()
80
+ : null,
81
+ bid_size: quote.bidBaseAssetAmount
82
+ ? quote.bidBaseAssetAmount.toString()
83
+ : null,
84
+ ask_size: quote.askBaseAssetAmount
85
+ ? quote.askBaseAssetAmount.toString()
86
+ : null,
79
87
  is_oracle_offset: quote.isOracleOffset,
80
88
  };
81
89
  }),
@@ -113,8 +121,8 @@ class IndicativeQuotesSender {
113
121
  this.reconnect();
114
122
  }, 5000);
115
123
  });
116
- ws.on('error', async (request, response) => {
117
- console.error('WS closed from error, reconnecting in 1s:', response);
124
+ ws.on('error', async (error) => {
125
+ console.error('WS closed from error, reconnecting in 1s:', error);
118
126
  setTimeout(() => {
119
127
  if (this.heartbeatTimeout)
120
128
  clearTimeout(this.heartbeatTimeout);
@@ -157,9 +165,9 @@ class IndicativeQuotesSender {
157
165
  }
158
166
  (_a = newQuoteMap.get(quote.marketIndex)) === null || _a === void 0 ? void 0 : _a.push(quote);
159
167
  }
160
- for (const marketIndex of newQuoteMap.keys()) {
161
- this.quotes.set(marketIndex, newQuoteMap.get(marketIndex));
162
- }
168
+ newQuoteMap.forEach((quotes, marketIndex) => {
169
+ this.quotes.set(marketIndex, quotes);
170
+ });
163
171
  }
164
172
  reconnect() {
165
173
  if (this.ws) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.161.0-beta.0",
3
+ "version": "2.161.0-beta.1",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "module": "./lib/browser/index.js",
@@ -8,14 +8,20 @@ const SEND_INTERVAL = 500;
8
8
  const MAX_BUFFERED_AMOUNT = 20 * 1024; // 20 KB as worst case scenario
9
9
 
10
10
  type Quote = {
11
- bidPrice: BN;
12
- askPrice: BN;
13
- bidBaseAssetAmount: BN;
14
- askBaseAssetAmount: BN;
11
+ bidPrice: BN | null;
12
+ askPrice: BN | null;
13
+ bidBaseAssetAmount: BN | null;
14
+ askBaseAssetAmount: BN | null;
15
15
  marketIndex: number;
16
16
  isOracleOffset?: boolean;
17
17
  };
18
18
 
19
+ type WsMessage = {
20
+ channel: string;
21
+ nonce?: string;
22
+ message?: string;
23
+ };
24
+
19
25
  export class IndicativeQuotesSender {
20
26
  private heartbeatTimeout: ReturnType<typeof setTimeout> | null = null;
21
27
  private sendQuotesInterval: ReturnType<typeof setTimeout> | null = null;
@@ -39,7 +45,7 @@ export class IndicativeQuotesSender {
39
45
  return signatureBase64;
40
46
  }
41
47
 
42
- handleAuthMessage(message: any): void {
48
+ handleAuthMessage(message: WsMessage): void {
43
49
  if (message['channel'] === 'auth' && message['nonce'] != null) {
44
50
  const signatureBase64 = this.generateChallengeResponse(message['nonce']);
45
51
  this.ws?.send(
@@ -68,7 +74,7 @@ export class IndicativeQuotesSender {
68
74
  this.reconnectDelay = 1000;
69
75
 
70
76
  ws.on('message', async (data: WebSocket.Data) => {
71
- let message: string;
77
+ let message: WsMessage;
72
78
  try {
73
79
  message = JSON.parse(data.toString());
74
80
  } catch (e) {
@@ -93,10 +99,18 @@ export class IndicativeQuotesSender {
93
99
  market_type: 'perp',
94
100
  quotes: quotes.map((quote) => {
95
101
  return {
96
- bid_price: quote.bidPrice.toString(),
97
- ask_price: quote.askPrice.toString(),
98
- bid_size: quote.bidBaseAssetAmount.toString(),
99
- ask_size: quote.askBaseAssetAmount.toString(),
102
+ bid_price: quote.bidPrice
103
+ ? quote.bidPrice.toString()
104
+ : null,
105
+ ask_price: quote.askPrice
106
+ ? quote.askPrice.toString()
107
+ : null,
108
+ bid_size: quote.bidBaseAssetAmount
109
+ ? quote.bidBaseAssetAmount.toString()
110
+ : null,
111
+ ask_size: quote.askBaseAssetAmount
112
+ ? quote.askBaseAssetAmount.toString()
113
+ : null,
100
114
  is_oracle_offset: quote.isOracleOffset,
101
115
  };
102
116
  }),
@@ -140,8 +154,8 @@ export class IndicativeQuotesSender {
140
154
  }, 5000);
141
155
  });
142
156
 
143
- ws.on('error', async (request, response) => {
144
- console.error('WS closed from error, reconnecting in 1s:', response);
157
+ ws.on('error', async (error: Error) => {
158
+ console.error('WS closed from error, reconnecting in 1s:', error);
145
159
  setTimeout(() => {
146
160
  if (this.heartbeatTimeout) clearTimeout(this.heartbeatTimeout);
147
161
  if (this.sendQuotesInterval) clearInterval(this.sendQuotesInterval);
@@ -188,9 +202,9 @@ export class IndicativeQuotesSender {
188
202
  }
189
203
  newQuoteMap.get(quote.marketIndex)?.push(quote);
190
204
  }
191
- for (const marketIndex of newQuoteMap.keys()) {
192
- this.quotes.set(marketIndex, newQuoteMap.get(marketIndex));
193
- }
205
+ newQuoteMap.forEach((quotes, marketIndex) => {
206
+ this.quotes.set(marketIndex, quotes);
207
+ });
194
208
  }
195
209
 
196
210
  private reconnect() {