@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 +1 -1
- package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.js +3 -3
- package/lib/browser/math/amm.js +1 -1
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.js +3 -3
- package/lib/node/math/amm.js +1 -1
- package/package.json +1 -1
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +3 -3
- package/src/math/amm.ts +2 -2
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.128.0-beta.
|
|
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(
|
|
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(
|
|
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(
|
|
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);
|
package/lib/browser/math/amm.js
CHANGED
|
@@ -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),
|
|
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(
|
|
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(
|
|
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(
|
|
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);
|
package/lib/node/math/amm.js
CHANGED
|
@@ -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),
|
|
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
|
@@ -293,7 +293,7 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
293
293
|
marketIndex
|
|
294
294
|
);
|
|
295
295
|
const accountSubscriber = new WebSocketAccountSubscriber<PerpMarketAccount>(
|
|
296
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
479
|
-
|
|
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
|