@drift-labs/sdk 2.52.0-beta.12 → 2.52.0-beta.14

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.52.0-beta.12
1
+ 2.52.0-beta.14
@@ -1,38 +1,57 @@
1
1
  import { Connection, PublicKey } from '@solana/web3.js';
2
- import { BASE_PRECISION, PRICE_PRECISION, PhoenixSubscriber } from '../src';
2
+ import {
3
+ BASE_PRECISION,
4
+ L2Level,
5
+ PRICE_PRECISION,
6
+ PhoenixSubscriber,
7
+ } from '../src';
3
8
  import { PROGRAM_ID } from '@ellipsis-labs/phoenix-sdk';
4
9
 
5
10
  export async function listenToBook(): Promise<void> {
6
11
  const connection = new Connection('https://api.mainnet-beta.solana.com');
7
12
 
8
- const phoenixSubscriber = new PhoenixSubscriber({
9
- connection,
10
- programId: PROGRAM_ID,
11
- marketAddress: new PublicKey(
12
- '4DoNfFBfF7UokCC2FQzriy7yHK6DY6NVdYpuekQ5pRgg'
13
- ),
14
- accountSubscription: {
15
- type: 'websocket',
16
- },
17
- });
18
-
19
- await phoenixSubscriber.subscribe();
20
-
21
- for (let i = 0; i < 10; i++) {
22
- const bids = phoenixSubscriber.getL2Levels("bids");
23
- const asks = phoenixSubscriber.getL2Levels("asks");
24
- console.log("bids");
25
- for (const bid of bids) {
26
- console.log(bid.price.toNumber() / PRICE_PRECISION.toNumber(), bid.size.toNumber() / BASE_PRECISION.toNumber());
13
+ for (const market of [
14
+ '4DoNfFBfF7UokCC2FQzriy7yHK6DY6NVdYpuekQ5pRgg', // SOL/USDC
15
+ 'Ew3vFDdtdGrknJAVVfraxCA37uNJtimXYPY4QjnfhFHH', // ETH/USDC
16
+ '2sTMN9A1D1qeZLF95XQgJCUPiKe5DiV52jLfZGqMP46m', // PYTH/USDC
17
+ 'BRLLmdtPGuuFn3BU6orYw4KHaohAEptBToi3dwRUnHQZ', // JTO/USDC
18
+ ]) {
19
+ const phoenixSubscriber = new PhoenixSubscriber({
20
+ connection,
21
+ programId: PROGRAM_ID,
22
+ marketAddress: new PublicKey(market),
23
+ accountSubscription: {
24
+ type: 'websocket',
25
+ },
26
+ });
27
+
28
+ await phoenixSubscriber.subscribe();
29
+
30
+ const bids = phoenixSubscriber.getL2Levels('bids');
31
+ const asks = phoenixSubscriber.getL2Levels('asks');
32
+ let bid: L2Level | null = null;
33
+ for (const b of bids) {
34
+ bid = b;
35
+ break;
27
36
  }
28
- console.log("asks");
29
- for (const ask of asks) {
30
- console.log(ask.price.toNumber() / PRICE_PRECISION.toNumber(), ask.size.toNumber() / BASE_PRECISION.toNumber());
37
+ let ask: L2Level | null = null;
38
+ for (const a of asks) {
39
+ ask = a;
40
+ break;
31
41
  }
32
- await new Promise((r) => setTimeout(r, 2000));
33
- }
34
42
 
35
- await phoenixSubscriber.unsubscribe();
43
+ console.log('market', market);
44
+ console.log(
45
+ (bid?.size.toNumber() || 0) / BASE_PRECISION.toNumber(),
46
+ (bid?.price.toNumber() || 0) / PRICE_PRECISION.toNumber(),
47
+ '@',
48
+ (ask?.price.toNumber() || (1 << 53) - 1) / PRICE_PRECISION.toNumber(),
49
+ (ask?.size.toNumber() || 0) / BASE_PRECISION.toNumber()
50
+ );
51
+ console.log();
52
+
53
+ await phoenixSubscriber.unsubscribe();
54
+ }
36
55
  }
37
56
 
38
57
  (async function () {
@@ -214,6 +214,16 @@ exports.DevnetPerpMarkets = [
214
214
  launchTs: 1701967240000,
215
215
  oracleSource: __1.OracleSource.PYTH,
216
216
  },
217
+ {
218
+ fullName: 'SEI',
219
+ category: ['L1'],
220
+ symbol: 'SEI-PERP',
221
+ baseAssetSymbol: 'SEI',
222
+ marketIndex: 21,
223
+ oracle: new web3_js_1.PublicKey('B6KVbgqTRY33yDgjAnc1mWw4ATS4W5544xghayQscdt7'),
224
+ launchTs: 1703173331000,
225
+ oracleSource: __1.OracleSource.PYTH,
226
+ },
217
227
  ];
218
228
  exports.MainnetPerpMarkets = [
219
229
  {
@@ -426,6 +436,16 @@ exports.MainnetPerpMarkets = [
426
436
  launchTs: 1701967240000,
427
437
  oracleSource: __1.OracleSource.PYTH,
428
438
  },
439
+ {
440
+ fullName: 'SEI',
441
+ category: ['L1'],
442
+ symbol: 'SEI-PERP',
443
+ baseAssetSymbol: 'SEI',
444
+ marketIndex: 21,
445
+ oracle: new web3_js_1.PublicKey('6cUuAyAX3eXoiWkjFF77RQBEUF15AAMQ7d1hm4EPd3tv'),
446
+ launchTs: 1703173331000,
447
+ oracleSource: __1.OracleSource.PYTH,
448
+ },
429
449
  ];
430
450
  exports.PerpMarkets = {
431
451
  devnet: exports.DevnetPerpMarkets,
@@ -99,23 +99,25 @@ class PhoenixSubscriber {
99
99
  return this.getL2Levels('asks');
100
100
  }
101
101
  *getL2Levels(side) {
102
- const tickSize = this.market.data.header
103
- .tickSizeInQuoteAtomsPerBaseUnit;
104
- const baseLotsToRawBaseUnits = this.market.baseLotsToRawBaseUnits(1);
105
- const basePrecision = new anchor_1.BN(Math.pow(10, this.market.data.header.baseParams.decimals) *
106
- baseLotsToRawBaseUnits);
107
- const pricePrecision = numericConstants_1.PRICE_PRECISION.div(tickSize);
108
- const ladder = (0, phoenix_sdk_1.getMarketLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 20);
102
+ const basePrecision = Math.pow(10, this.market.data.header.baseParams.decimals);
103
+ const pricePrecision = numericConstants_1.PRICE_PRECISION.toNumber();
104
+ const ladder = (0, phoenix_sdk_1.getMarketUiLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 20);
109
105
  for (let i = 0; i < ladder[side].length; i++) {
110
- const { priceInTicks, sizeInBaseLots } = ladder[side][i];
111
- const size = sizeInBaseLots.mul(basePrecision);
112
- yield {
113
- price: priceInTicks.mul(new anchor_1.BN(pricePrecision)),
114
- size,
115
- sources: {
116
- phoenix: size,
117
- },
118
- };
106
+ const { price, quantity } = ladder[side][i];
107
+ try {
108
+ const size = new anchor_1.BN(quantity * basePrecision);
109
+ const updatedPrice = new anchor_1.BN(price * pricePrecision);
110
+ yield {
111
+ price: updatedPrice,
112
+ size,
113
+ sources: {
114
+ phoenix: size,
115
+ },
116
+ };
117
+ }
118
+ catch {
119
+ continue;
120
+ }
119
121
  }
120
122
  }
121
123
  async unsubscribe() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.52.0-beta.12",
3
+ "version": "2.52.0-beta.14",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -224,6 +224,16 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
224
224
  launchTs: 1701967240000,
225
225
  oracleSource: OracleSource.PYTH,
226
226
  },
227
+ {
228
+ fullName: 'SEI',
229
+ category: ['L1'],
230
+ symbol: 'SEI-PERP',
231
+ baseAssetSymbol: 'SEI',
232
+ marketIndex: 21,
233
+ oracle: new PublicKey('B6KVbgqTRY33yDgjAnc1mWw4ATS4W5544xghayQscdt7'),
234
+ launchTs: 1703173331000,
235
+ oracleSource: OracleSource.PYTH,
236
+ },
227
237
  ];
228
238
 
229
239
  export const MainnetPerpMarkets: PerpMarketConfig[] = [
@@ -437,6 +447,16 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
437
447
  launchTs: 1701967240000,
438
448
  oracleSource: OracleSource.PYTH,
439
449
  },
450
+ {
451
+ fullName: 'SEI',
452
+ category: ['L1'],
453
+ symbol: 'SEI-PERP',
454
+ baseAssetSymbol: 'SEI',
455
+ marketIndex: 21,
456
+ oracle: new PublicKey('6cUuAyAX3eXoiWkjFF77RQBEUF15AAMQ7d1hm4EPd3tv'),
457
+ launchTs: 1703173331000,
458
+ oracleSource: OracleSource.PYTH,
459
+ },
440
460
  ];
441
461
 
442
462
  export const PerpMarkets: { [key in DriftEnv]: PerpMarketConfig[] } = {
@@ -6,7 +6,6 @@ import {
6
6
  toNum,
7
7
  getMarketUiLadder,
8
8
  Market,
9
- getMarketLadder,
10
9
  } from '@ellipsis-labs/phoenix-sdk';
11
10
  import { PRICE_PRECISION } from '../constants/numericConstants';
12
11
  import { BN } from '@coral-xyz/anchor';
@@ -164,18 +163,14 @@ export class PhoenixSubscriber implements L2OrderBookGenerator {
164
163
  }
165
164
 
166
165
  *getL2Levels(side: 'bids' | 'asks'): Generator<L2Level> {
167
- const tickSize = this.market.data.header
168
- .tickSizeInQuoteAtomsPerBaseUnit as BN;
169
- const baseLotsToRawBaseUnits = this.market.baseLotsToRawBaseUnits(1);
170
-
171
- const basePrecision = new BN(
172
- Math.pow(10, this.market.data.header.baseParams.decimals) *
173
- baseLotsToRawBaseUnits
166
+ const basePrecision = Math.pow(
167
+ 10,
168
+ this.market.data.header.baseParams.decimals
174
169
  );
175
170
 
176
- const pricePrecision = PRICE_PRECISION.div(tickSize as BN);
171
+ const pricePrecision = PRICE_PRECISION.toNumber();
177
172
 
178
- const ladder = getMarketLadder(
173
+ const ladder = getMarketUiLadder(
179
174
  this.market,
180
175
  this.lastSlot,
181
176
  this.lastUnixTimestamp,
@@ -183,18 +178,22 @@ export class PhoenixSubscriber implements L2OrderBookGenerator {
183
178
  );
184
179
 
185
180
  for (let i = 0; i < ladder[side].length; i++) {
186
- const { priceInTicks, sizeInBaseLots } = ladder[side][i];
187
- const size = sizeInBaseLots.mul(basePrecision);
188
- yield {
189
- price: priceInTicks.mul(new BN(pricePrecision)),
190
- size,
191
- sources: {
192
- phoenix: size,
193
- },
194
- };
181
+ const { price, quantity } = ladder[side][i];
182
+ try {
183
+ const size = new BN(quantity * basePrecision);
184
+ const updatedPrice = new BN(price * pricePrecision);
185
+ yield {
186
+ price: updatedPrice,
187
+ size,
188
+ sources: {
189
+ phoenix: size,
190
+ },
191
+ };
192
+ } catch {
193
+ continue;
194
+ }
195
195
  }
196
196
  }
197
-
198
197
  public async unsubscribe(): Promise<void> {
199
198
  if (!this.subscribed) {
200
199
  return;