@drift-labs/sdk-browser 2.128.0-beta.5 → 2.128.0-beta.7

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.128.0-beta.5
1
+ 2.128.0-beta.7
@@ -138,7 +138,7 @@ class WebSocketDriftClientAccountSubscriber {
138
138
  }
139
139
  async subscribeToPerpMarketAccount(marketIndex) {
140
140
  const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
141
- const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('perpMarket', this.program, perpMarketPublicKey, undefined, this.resubOpts, this.commitment);
141
+ const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber(`perpMarket-${marketIndex}`, this.program, perpMarketPublicKey, undefined, this.resubOpts, this.commitment);
142
142
  accountSubscriber.setData(this.initialPerpMarketAccountData.get(marketIndex));
143
143
  await accountSubscriber.subscribe((data) => {
144
144
  this.eventEmitter.emit('perpMarketAccountUpdate', data);
@@ -153,7 +153,7 @@ class WebSocketDriftClientAccountSubscriber {
153
153
  }
154
154
  async subscribeToSpotMarketAccount(marketIndex) {
155
155
  const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
156
- const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('spotMarket', this.program, marketPublicKey, undefined, this.resubOpts, this.commitment);
156
+ const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber(`spotMarket-${marketIndex}`, this.program, marketPublicKey, undefined, this.resubOpts, this.commitment);
157
157
  accountSubscriber.setData(this.initialSpotMarketAccountData.get(marketIndex));
158
158
  await accountSubscriber.subscribe((data) => {
159
159
  this.eventEmitter.emit('spotMarketAccountUpdate', data);
@@ -171,7 +171,7 @@ class WebSocketDriftClientAccountSubscriber {
171
171
  async subscribeToOracle(oracleInfo) {
172
172
  const oracleId = (0, oracleId_1.getOracleId)(oracleInfo.publicKey, oracleInfo.source);
173
173
  const client = this.oracleClientCache.get(oracleInfo.source, this.program.provider.connection, this.program);
174
- const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('oracle', this.program, oracleInfo.publicKey, (buffer) => {
174
+ const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber(`oracle-${oracleId}`, this.program, oracleInfo.publicKey, (buffer) => {
175
175
  return client.getOraclePriceDataFromBuffer(buffer);
176
176
  }, this.resubOpts, this.commitment);
177
177
  const initialOraclePriceData = this.initialOraclePriceData.get(oracleId);
@@ -245,7 +245,7 @@ function calculateReferencePriceOffset(reservePrice, last24hAvgFundingRate, liqu
245
245
  const markPremiumAvgPct = markPremiumAvg
246
246
  .mul(numericConstants_1.PRICE_PRECISION)
247
247
  .div(reservePrice);
248
- const inventoryPct = (0, __1.clampBN)(liquidityFraction.mul(new anchor_1.BN(maxOffsetPct)).div(numericConstants_1.PERCENTAGE_PRECISION), maxOffsetInPrice.mul(new anchor_1.BN(-1)), maxOffsetInPrice);
248
+ const inventoryPct = (0, __1.clampBN)(liquidityFraction.mul(new anchor_1.BN(maxOffsetPct)).div(numericConstants_1.PERCENTAGE_PRECISION), new anchor_1.BN(maxOffsetPct).mul(new anchor_1.BN(-1)), new anchor_1.BN(maxOffsetPct));
249
249
  // Only apply when inventory is consistent with recent and 24h market premium
250
250
  let offsetPct = markPremiumAvgPct.add(inventoryPct);
251
251
  if (!(0, __1.sigNum)(inventoryPct).eq((0, __1.sigNum)(markPremiumAvgPct))) {
@@ -138,7 +138,7 @@ class WebSocketDriftClientAccountSubscriber {
138
138
  }
139
139
  async subscribeToPerpMarketAccount(marketIndex) {
140
140
  const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
141
- const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('perpMarket', this.program, perpMarketPublicKey, undefined, this.resubOpts, this.commitment);
141
+ const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber(`perpMarket-${marketIndex}`, this.program, perpMarketPublicKey, undefined, this.resubOpts, this.commitment);
142
142
  accountSubscriber.setData(this.initialPerpMarketAccountData.get(marketIndex));
143
143
  await accountSubscriber.subscribe((data) => {
144
144
  this.eventEmitter.emit('perpMarketAccountUpdate', data);
@@ -153,7 +153,7 @@ class WebSocketDriftClientAccountSubscriber {
153
153
  }
154
154
  async subscribeToSpotMarketAccount(marketIndex) {
155
155
  const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
156
- const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('spotMarket', this.program, marketPublicKey, undefined, this.resubOpts, this.commitment);
156
+ const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber(`spotMarket-${marketIndex}`, this.program, marketPublicKey, undefined, this.resubOpts, this.commitment);
157
157
  accountSubscriber.setData(this.initialSpotMarketAccountData.get(marketIndex));
158
158
  await accountSubscriber.subscribe((data) => {
159
159
  this.eventEmitter.emit('spotMarketAccountUpdate', data);
@@ -171,7 +171,7 @@ class WebSocketDriftClientAccountSubscriber {
171
171
  async subscribeToOracle(oracleInfo) {
172
172
  const oracleId = (0, oracleId_1.getOracleId)(oracleInfo.publicKey, oracleInfo.source);
173
173
  const client = this.oracleClientCache.get(oracleInfo.source, this.program.provider.connection, this.program);
174
- const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('oracle', this.program, oracleInfo.publicKey, (buffer) => {
174
+ const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber(`oracle-${oracleId}`, this.program, oracleInfo.publicKey, (buffer) => {
175
175
  return client.getOraclePriceDataFromBuffer(buffer);
176
176
  }, this.resubOpts, this.commitment);
177
177
  const initialOraclePriceData = this.initialOraclePriceData.get(oracleId);
@@ -245,7 +245,7 @@ function calculateReferencePriceOffset(reservePrice, last24hAvgFundingRate, liqu
245
245
  const markPremiumAvgPct = markPremiumAvg
246
246
  .mul(numericConstants_1.PRICE_PRECISION)
247
247
  .div(reservePrice);
248
- const inventoryPct = (0, __1.clampBN)(liquidityFraction.mul(new anchor_1.BN(maxOffsetPct)).div(numericConstants_1.PERCENTAGE_PRECISION), maxOffsetInPrice.mul(new anchor_1.BN(-1)), maxOffsetInPrice);
248
+ const inventoryPct = (0, __1.clampBN)(liquidityFraction.mul(new anchor_1.BN(maxOffsetPct)).div(numericConstants_1.PERCENTAGE_PRECISION), new anchor_1.BN(maxOffsetPct).mul(new anchor_1.BN(-1)), new anchor_1.BN(maxOffsetPct));
249
249
  // Only apply when inventory is consistent with recent and 24h market premium
250
250
  let offsetPct = markPremiumAvgPct.add(inventoryPct);
251
251
  if (!(0, __1.sigNum)(inventoryPct).eq((0, __1.sigNum)(markPremiumAvgPct))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk-browser",
3
- "version": "2.128.0-beta.5",
3
+ "version": "2.128.0-beta.7",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "browser": "./lib/browser/index.js",
@@ -293,7 +293,7 @@ export class WebSocketDriftClientAccountSubscriber
293
293
  marketIndex
294
294
  );
295
295
  const accountSubscriber = new WebSocketAccountSubscriber<PerpMarketAccount>(
296
- 'perpMarket',
296
+ `perpMarket-${marketIndex}`,
297
297
  this.program,
298
298
  perpMarketPublicKey,
299
299
  undefined,
@@ -326,7 +326,7 @@ export class WebSocketDriftClientAccountSubscriber
326
326
  marketIndex
327
327
  );
328
328
  const accountSubscriber = new WebSocketAccountSubscriber<SpotMarketAccount>(
329
- 'spotMarket',
329
+ `spotMarket-${marketIndex}`,
330
330
  this.program,
331
331
  marketPublicKey,
332
332
  undefined,
@@ -362,7 +362,7 @@ export class WebSocketDriftClientAccountSubscriber
362
362
  this.program
363
363
  );
364
364
  const accountSubscriber = new WebSocketAccountSubscriber<OraclePriceData>(
365
- 'oracle',
365
+ `oracle-${oracleId}`,
366
366
  this.program,
367
367
  oracleInfo.publicKey,
368
368
  (buffer: Buffer) => {
package/src/math/amm.ts CHANGED
@@ -475,8 +475,8 @@ export function calculateReferencePriceOffset(
475
475
 
476
476
  const inventoryPct = clampBN(
477
477
  liquidityFraction.mul(new BN(maxOffsetPct)).div(PERCENTAGE_PRECISION),
478
- maxOffsetInPrice.mul(new BN(-1)),
479
- maxOffsetInPrice
478
+ new BN(maxOffsetPct).mul(new BN(-1)),
479
+ new BN(maxOffsetPct)
480
480
  );
481
481
 
482
482
  // Only apply when inventory is consistent with recent and 24h market premium