@drift-labs/sdk-browser 2.137.0-beta.0 → 2.137.0-beta.2
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/webSocketAccountSubscriberV2.d.ts +1 -1
- package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.d.ts +1 -1
- package/lib/browser/decode/user.js +3 -2
- package/lib/browser/driftClient.d.ts +2 -0
- package/lib/browser/driftClient.js +17 -0
- package/lib/browser/idl/drift.json +28 -175
- package/lib/browser/math/bankruptcy.js +1 -2
- package/lib/browser/types.d.ts +2 -0
- package/lib/browser/user.d.ts +2 -15
- package/lib/browser/user.js +29 -225
- package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts +1 -1
- package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts +1 -1
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts.map +1 -1
- package/lib/node/decode/user.d.ts.map +1 -1
- package/lib/node/decode/user.js +3 -2
- package/lib/node/driftClient.d.ts +2 -0
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +17 -0
- package/lib/node/idl/drift.json +28 -175
- package/lib/node/math/bankruptcy.d.ts.map +1 -1
- package/lib/node/math/bankruptcy.js +1 -2
- package/lib/node/types.d.ts +2 -0
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/user.d.ts +2 -15
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +29 -225
- package/package.json +1 -1
- package/src/accounts/webSocketAccountSubscriberV2.ts +2 -2
- package/src/accounts/webSocketProgramAccountsSubscriberV2.ts +2 -2
- package/src/decode/user.ts +3 -2
- package/src/driftClient.ts +44 -0
- package/src/idl/drift.json +29 -176
- package/src/math/bankruptcy.ts +1 -2
- package/src/types.ts +2 -0
- package/src/user.ts +47 -343
package/lib/browser/user.js
CHANGED
|
@@ -17,7 +17,6 @@ const types_2 = require("./types");
|
|
|
17
17
|
const orders_1 = require("./math/orders");
|
|
18
18
|
const websocketProgramUserAccountSubscriber_1 = require("./accounts/websocketProgramUserAccountSubscriber");
|
|
19
19
|
const spotBalance_2 = require("./math/spotBalance");
|
|
20
|
-
const amm_1 = require("./math/amm");
|
|
21
20
|
const margin_2 = require("./math/margin");
|
|
22
21
|
const pollingUserAccountSubscriber_1 = require("./accounts/pollingUserAccountSubscriber");
|
|
23
22
|
const webSocketUserAccountSubscriber_1 = require("./accounts/webSocketUserAccountSubscriber");
|
|
@@ -105,6 +104,11 @@ class User {
|
|
|
105
104
|
const userAccount = this.getUserAccount();
|
|
106
105
|
return this.getPerpPositionForUserAccount(userAccount, marketIndex);
|
|
107
106
|
}
|
|
107
|
+
getPerpPositionOrEmpty(marketIndex) {
|
|
108
|
+
var _a;
|
|
109
|
+
const userAccount = this.getUserAccount();
|
|
110
|
+
return ((_a = this.getPerpPositionForUserAccount(userAccount, marketIndex)) !== null && _a !== void 0 ? _a : this.getEmptyPosition(marketIndex));
|
|
111
|
+
}
|
|
108
112
|
getPerpPositionAndSlot(marketIndex) {
|
|
109
113
|
const userAccount = this.getUserAccountAndSlot();
|
|
110
114
|
const perpPosition = this.getPerpPositionForUserAccount(userAccount.data, marketIndex);
|
|
@@ -175,6 +179,7 @@ class User {
|
|
|
175
179
|
lastBaseAssetAmountPerLp: numericConstants_1.ZERO,
|
|
176
180
|
lastQuoteAssetAmountPerLp: numericConstants_1.ZERO,
|
|
177
181
|
perLpBase: 0,
|
|
182
|
+
maxMarginRatio: 0,
|
|
178
183
|
};
|
|
179
184
|
}
|
|
180
185
|
getClonedPosition(position) {
|
|
@@ -248,203 +253,28 @@ class User {
|
|
|
248
253
|
*/
|
|
249
254
|
getPerpBidAsks(marketIndex) {
|
|
250
255
|
const position = this.getPerpPosition(marketIndex);
|
|
251
|
-
const
|
|
252
|
-
const
|
|
253
|
-
const totalOpenAsks = lpOpenAsks.add(position.openAsks);
|
|
256
|
+
const totalOpenBids = position.openBids;
|
|
257
|
+
const totalOpenAsks = position.openAsks;
|
|
254
258
|
return [totalOpenBids, totalOpenAsks];
|
|
255
259
|
}
|
|
256
|
-
/**
|
|
257
|
-
* calculates the open bids and asks for an lp
|
|
258
|
-
* optionally pass in lpShares to see what bid/asks a user *would* take on
|
|
259
|
-
* @returns : lp open bids
|
|
260
|
-
* @returns : lp open asks
|
|
261
|
-
*/
|
|
262
|
-
getLPBidAsks(marketIndex, lpShares) {
|
|
263
|
-
const position = this.getPerpPosition(marketIndex);
|
|
264
|
-
const lpSharesToCalc = lpShares !== null && lpShares !== void 0 ? lpShares : position === null || position === void 0 ? void 0 : position.lpShares;
|
|
265
|
-
if (!lpSharesToCalc || lpSharesToCalc.eq(numericConstants_1.ZERO)) {
|
|
266
|
-
return [numericConstants_1.ZERO, numericConstants_1.ZERO];
|
|
267
|
-
}
|
|
268
|
-
const market = this.driftClient.getPerpMarketAccount(marketIndex);
|
|
269
|
-
const [marketOpenBids, marketOpenAsks] = (0, amm_1.calculateMarketOpenBidAsk)(market.amm.baseAssetReserve, market.amm.minBaseAssetReserve, market.amm.maxBaseAssetReserve, market.amm.orderStepSize);
|
|
270
|
-
const lpOpenBids = marketOpenBids.mul(lpSharesToCalc).div(market.amm.sqrtK);
|
|
271
|
-
const lpOpenAsks = marketOpenAsks.mul(lpSharesToCalc).div(market.amm.sqrtK);
|
|
272
|
-
return [lpOpenBids, lpOpenAsks];
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* calculates the market position if the lp position was settled
|
|
276
|
-
* @returns : the settled userPosition
|
|
277
|
-
* @returns : the dust base asset amount (ie, < stepsize)
|
|
278
|
-
* @returns : pnl from settle
|
|
279
|
-
*/
|
|
280
|
-
getPerpPositionWithLPSettle(marketIndex, originalPosition, burnLpShares = false, includeRemainderInBaseAmount = false) {
|
|
281
|
-
var _a;
|
|
282
|
-
originalPosition =
|
|
283
|
-
(_a = originalPosition !== null && originalPosition !== void 0 ? originalPosition : this.getPerpPosition(marketIndex)) !== null && _a !== void 0 ? _a : this.getEmptyPosition(marketIndex);
|
|
284
|
-
if (originalPosition.lpShares.eq(numericConstants_1.ZERO)) {
|
|
285
|
-
return [originalPosition, numericConstants_1.ZERO, numericConstants_1.ZERO];
|
|
286
|
-
}
|
|
287
|
-
const position = this.getClonedPosition(originalPosition);
|
|
288
|
-
const market = this.driftClient.getPerpMarketAccount(position.marketIndex);
|
|
289
|
-
if (market.amm.perLpBase != position.perLpBase) {
|
|
290
|
-
// perLpBase = 1 => per 10 LP shares, perLpBase = -1 => per 0.1 LP shares
|
|
291
|
-
const expoDiff = market.amm.perLpBase - position.perLpBase;
|
|
292
|
-
const marketPerLpRebaseScalar = new anchor_1.BN(10 ** Math.abs(expoDiff));
|
|
293
|
-
if (expoDiff > 0) {
|
|
294
|
-
position.lastBaseAssetAmountPerLp =
|
|
295
|
-
position.lastBaseAssetAmountPerLp.mul(marketPerLpRebaseScalar);
|
|
296
|
-
position.lastQuoteAssetAmountPerLp =
|
|
297
|
-
position.lastQuoteAssetAmountPerLp.mul(marketPerLpRebaseScalar);
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
position.lastBaseAssetAmountPerLp =
|
|
301
|
-
position.lastBaseAssetAmountPerLp.div(marketPerLpRebaseScalar);
|
|
302
|
-
position.lastQuoteAssetAmountPerLp =
|
|
303
|
-
position.lastQuoteAssetAmountPerLp.div(marketPerLpRebaseScalar);
|
|
304
|
-
}
|
|
305
|
-
position.perLpBase = position.perLpBase + expoDiff;
|
|
306
|
-
}
|
|
307
|
-
const nShares = position.lpShares;
|
|
308
|
-
// incorp unsettled funding on pre settled position
|
|
309
|
-
const quoteFundingPnl = (0, position_1.calculateUnsettledFundingPnl)(market, position);
|
|
310
|
-
let baseUnit = numericConstants_1.AMM_RESERVE_PRECISION;
|
|
311
|
-
if (market.amm.perLpBase == position.perLpBase) {
|
|
312
|
-
if (position.perLpBase >= 0 &&
|
|
313
|
-
position.perLpBase <= numericConstants_1.AMM_RESERVE_PRECISION_EXP.toNumber()) {
|
|
314
|
-
const marketPerLpRebase = new anchor_1.BN(10 ** market.amm.perLpBase);
|
|
315
|
-
baseUnit = baseUnit.mul(marketPerLpRebase);
|
|
316
|
-
}
|
|
317
|
-
else if (position.perLpBase < 0 &&
|
|
318
|
-
position.perLpBase >= -numericConstants_1.AMM_RESERVE_PRECISION_EXP.toNumber()) {
|
|
319
|
-
const marketPerLpRebase = new anchor_1.BN(10 ** Math.abs(market.amm.perLpBase));
|
|
320
|
-
baseUnit = baseUnit.div(marketPerLpRebase);
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
throw 'cannot calc';
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
throw 'market.amm.perLpBase != position.perLpBase';
|
|
328
|
-
}
|
|
329
|
-
const deltaBaa = market.amm.baseAssetAmountPerLp
|
|
330
|
-
.sub(position.lastBaseAssetAmountPerLp)
|
|
331
|
-
.mul(nShares)
|
|
332
|
-
.div(baseUnit);
|
|
333
|
-
const deltaQaa = market.amm.quoteAssetAmountPerLp
|
|
334
|
-
.sub(position.lastQuoteAssetAmountPerLp)
|
|
335
|
-
.mul(nShares)
|
|
336
|
-
.div(baseUnit);
|
|
337
|
-
function sign(v) {
|
|
338
|
-
return v.isNeg() ? new anchor_1.BN(-1) : new anchor_1.BN(1);
|
|
339
|
-
}
|
|
340
|
-
function standardize(amount, stepSize) {
|
|
341
|
-
const remainder = amount.abs().mod(stepSize).mul(sign(amount));
|
|
342
|
-
const standardizedAmount = amount.sub(remainder);
|
|
343
|
-
return [standardizedAmount, remainder];
|
|
344
|
-
}
|
|
345
|
-
const [standardizedBaa, remainderBaa] = standardize(deltaBaa, market.amm.orderStepSize);
|
|
346
|
-
position.remainderBaseAssetAmount += remainderBaa.toNumber();
|
|
347
|
-
if (Math.abs(position.remainderBaseAssetAmount) >
|
|
348
|
-
market.amm.orderStepSize.toNumber()) {
|
|
349
|
-
const [newStandardizedBaa, newRemainderBaa] = standardize(new anchor_1.BN(position.remainderBaseAssetAmount), market.amm.orderStepSize);
|
|
350
|
-
position.baseAssetAmount =
|
|
351
|
-
position.baseAssetAmount.add(newStandardizedBaa);
|
|
352
|
-
position.remainderBaseAssetAmount = newRemainderBaa.toNumber();
|
|
353
|
-
}
|
|
354
|
-
let dustBaseAssetValue = numericConstants_1.ZERO;
|
|
355
|
-
if (burnLpShares && position.remainderBaseAssetAmount != 0) {
|
|
356
|
-
const oraclePriceData = this.driftClient.getOracleDataForPerpMarket(position.marketIndex);
|
|
357
|
-
dustBaseAssetValue = new anchor_1.BN(Math.abs(position.remainderBaseAssetAmount))
|
|
358
|
-
.mul(oraclePriceData.price)
|
|
359
|
-
.div(numericConstants_1.AMM_RESERVE_PRECISION)
|
|
360
|
-
.add(numericConstants_1.ONE);
|
|
361
|
-
}
|
|
362
|
-
let updateType;
|
|
363
|
-
if (position.baseAssetAmount.eq(numericConstants_1.ZERO)) {
|
|
364
|
-
updateType = 'open';
|
|
365
|
-
}
|
|
366
|
-
else if (sign(position.baseAssetAmount).eq(sign(deltaBaa))) {
|
|
367
|
-
updateType = 'increase';
|
|
368
|
-
}
|
|
369
|
-
else if (position.baseAssetAmount.abs().gt(deltaBaa.abs())) {
|
|
370
|
-
updateType = 'reduce';
|
|
371
|
-
}
|
|
372
|
-
else if (position.baseAssetAmount.abs().eq(deltaBaa.abs())) {
|
|
373
|
-
updateType = 'close';
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
updateType = 'flip';
|
|
377
|
-
}
|
|
378
|
-
let newQuoteEntry;
|
|
379
|
-
let pnl;
|
|
380
|
-
if (updateType == 'open' || updateType == 'increase') {
|
|
381
|
-
newQuoteEntry = position.quoteEntryAmount.add(deltaQaa);
|
|
382
|
-
pnl = numericConstants_1.ZERO;
|
|
383
|
-
}
|
|
384
|
-
else if (updateType == 'reduce' || updateType == 'close') {
|
|
385
|
-
newQuoteEntry = position.quoteEntryAmount.sub(position.quoteEntryAmount
|
|
386
|
-
.mul(deltaBaa.abs())
|
|
387
|
-
.div(position.baseAssetAmount.abs()));
|
|
388
|
-
pnl = position.quoteEntryAmount.sub(newQuoteEntry).add(deltaQaa);
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
newQuoteEntry = deltaQaa.sub(deltaQaa.mul(position.baseAssetAmount.abs()).div(deltaBaa.abs()));
|
|
392
|
-
pnl = position.quoteEntryAmount.add(deltaQaa.sub(newQuoteEntry));
|
|
393
|
-
}
|
|
394
|
-
position.quoteEntryAmount = newQuoteEntry;
|
|
395
|
-
position.baseAssetAmount = position.baseAssetAmount.add(standardizedBaa);
|
|
396
|
-
position.quoteAssetAmount = position.quoteAssetAmount
|
|
397
|
-
.add(deltaQaa)
|
|
398
|
-
.add(quoteFundingPnl)
|
|
399
|
-
.sub(dustBaseAssetValue);
|
|
400
|
-
position.quoteBreakEvenAmount = position.quoteBreakEvenAmount
|
|
401
|
-
.add(deltaQaa)
|
|
402
|
-
.add(quoteFundingPnl)
|
|
403
|
-
.sub(dustBaseAssetValue);
|
|
404
|
-
// update open bids/asks
|
|
405
|
-
const [marketOpenBids, marketOpenAsks] = (0, amm_1.calculateMarketOpenBidAsk)(market.amm.baseAssetReserve, market.amm.minBaseAssetReserve, market.amm.maxBaseAssetReserve, market.amm.orderStepSize);
|
|
406
|
-
const lpOpenBids = marketOpenBids
|
|
407
|
-
.mul(position.lpShares)
|
|
408
|
-
.div(market.amm.sqrtK);
|
|
409
|
-
const lpOpenAsks = marketOpenAsks
|
|
410
|
-
.mul(position.lpShares)
|
|
411
|
-
.div(market.amm.sqrtK);
|
|
412
|
-
position.openBids = lpOpenBids.add(position.openBids);
|
|
413
|
-
position.openAsks = lpOpenAsks.add(position.openAsks);
|
|
414
|
-
// eliminate counting funding on settled position
|
|
415
|
-
if (position.baseAssetAmount.gt(numericConstants_1.ZERO)) {
|
|
416
|
-
position.lastCumulativeFundingRate = market.amm.cumulativeFundingRateLong;
|
|
417
|
-
}
|
|
418
|
-
else if (position.baseAssetAmount.lt(numericConstants_1.ZERO)) {
|
|
419
|
-
position.lastCumulativeFundingRate =
|
|
420
|
-
market.amm.cumulativeFundingRateShort;
|
|
421
|
-
}
|
|
422
|
-
else {
|
|
423
|
-
position.lastCumulativeFundingRate = numericConstants_1.ZERO;
|
|
424
|
-
}
|
|
425
|
-
const remainderBeforeRemoval = new anchor_1.BN(position.remainderBaseAssetAmount);
|
|
426
|
-
if (includeRemainderInBaseAmount) {
|
|
427
|
-
position.baseAssetAmount = position.baseAssetAmount.add(remainderBeforeRemoval);
|
|
428
|
-
position.remainderBaseAssetAmount = 0;
|
|
429
|
-
}
|
|
430
|
-
return [position, remainderBeforeRemoval, pnl];
|
|
431
|
-
}
|
|
432
260
|
/**
|
|
433
261
|
* calculates Buying Power = free collateral / initial margin ratio
|
|
434
262
|
* @returns : Precision QUOTE_PRECISION
|
|
435
263
|
*/
|
|
436
264
|
getPerpBuyingPower(marketIndex, collateralBuffer = numericConstants_1.ZERO, enterHighLeverageMode = undefined) {
|
|
437
|
-
const perpPosition = this.
|
|
265
|
+
const perpPosition = this.getPerpPositionOrEmpty(marketIndex);
|
|
438
266
|
const perpMarket = this.driftClient.getPerpMarketAccount(marketIndex);
|
|
439
267
|
const oraclePriceData = this.getOracleDataForPerpMarket(marketIndex);
|
|
440
268
|
const worstCaseBaseAssetAmount = perpPosition
|
|
441
269
|
? (0, margin_2.calculateWorstCaseBaseAssetAmount)(perpPosition, perpMarket, oraclePriceData.price)
|
|
442
270
|
: numericConstants_1.ZERO;
|
|
443
271
|
const freeCollateral = this.getFreeCollateral('Initial', enterHighLeverageMode).sub(collateralBuffer);
|
|
444
|
-
return this.getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, worstCaseBaseAssetAmount, enterHighLeverageMode);
|
|
272
|
+
return this.getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, worstCaseBaseAssetAmount, enterHighLeverageMode, perpPosition);
|
|
445
273
|
}
|
|
446
|
-
getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, baseAssetAmount, enterHighLeverageMode = undefined) {
|
|
447
|
-
|
|
274
|
+
getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, baseAssetAmount, enterHighLeverageMode = undefined, perpPosition) {
|
|
275
|
+
var _a;
|
|
276
|
+
const userCustomMargin = Math.max((_a = perpPosition === null || perpPosition === void 0 ? void 0 : perpPosition.maxMarginRatio) !== null && _a !== void 0 ? _a : 0, this.getUserAccount().maxMarginRatio);
|
|
277
|
+
const marginRatio = (0, market_1.calculateMarketMarginRatio)(this.driftClient.getPerpMarketAccount(marketIndex), baseAssetAmount, 'Initial', userCustomMargin, enterHighLeverageMode || this.isHighLeverageMode('Initial'));
|
|
448
278
|
return freeCollateral.mul(numericConstants_1.MARGIN_PRECISION).div(new anchor_1.BN(marginRatio));
|
|
449
279
|
}
|
|
450
280
|
/**
|
|
@@ -480,8 +310,7 @@ class User {
|
|
|
480
310
|
getActivePerpPositionsForUserAccount(userAccount) {
|
|
481
311
|
return userAccount.perpPositions.filter((pos) => !pos.baseAssetAmount.eq(numericConstants_1.ZERO) ||
|
|
482
312
|
!pos.quoteAssetAmount.eq(numericConstants_1.ZERO) ||
|
|
483
|
-
!(pos.openOrders == 0)
|
|
484
|
-
!pos.lpShares.eq(numericConstants_1.ZERO));
|
|
313
|
+
!(pos.openOrders == 0));
|
|
485
314
|
}
|
|
486
315
|
getActivePerpPositions() {
|
|
487
316
|
const userAccount = this.getUserAccount();
|
|
@@ -522,9 +351,6 @@ class User {
|
|
|
522
351
|
const oraclePriceData = this.getMMOracleDataForPerpMarket(market.marketIndex);
|
|
523
352
|
const quoteSpotMarket = this.driftClient.getSpotMarketAccount(market.quoteSpotMarketIndex);
|
|
524
353
|
const quoteOraclePriceData = this.getOracleDataForSpotMarket(market.quoteSpotMarketIndex);
|
|
525
|
-
if (perpPosition.lpShares.gt(numericConstants_1.ZERO)) {
|
|
526
|
-
perpPosition = this.getPerpPositionWithLPSettle(perpPosition.marketIndex, undefined, !!withWeightMarginCategory)[0];
|
|
527
|
-
}
|
|
528
354
|
let positionUnrealizedPnl = (0, position_2.calculatePositionPNL)(market, perpPosition, withFunding, oraclePriceData);
|
|
529
355
|
let quotePrice;
|
|
530
356
|
if (strict && positionUnrealizedPnl.gt(numericConstants_1.ZERO)) {
|
|
@@ -758,10 +584,6 @@ class User {
|
|
|
758
584
|
}
|
|
759
585
|
calculateWeightedPerpPositionLiability(perpPosition, marginCategory, liquidationBuffer, includeOpenOrders, strict = false, enteringHighLeverage = undefined) {
|
|
760
586
|
const market = this.driftClient.getPerpMarketAccount(perpPosition.marketIndex);
|
|
761
|
-
if (perpPosition.lpShares.gt(numericConstants_1.ZERO)) {
|
|
762
|
-
// is an lp, clone so we dont mutate the position
|
|
763
|
-
perpPosition = this.getPerpPositionWithLPSettle(market.marketIndex, this.getClonedPosition(perpPosition), !!marginCategory)[0];
|
|
764
|
-
}
|
|
765
587
|
let valuationPrice = this.getOracleDataForPerpMarket(market.marketIndex).price;
|
|
766
588
|
if ((0, types_1.isVariant)(market.status, 'settlement')) {
|
|
767
589
|
valuationPrice = market.expiryPrice;
|
|
@@ -805,13 +627,6 @@ class User {
|
|
|
805
627
|
.div(numericConstants_1.MARGIN_PRECISION);
|
|
806
628
|
if (includeOpenOrders) {
|
|
807
629
|
liabilityValue = liabilityValue.add(new anchor_1.BN(perpPosition.openOrders).mul(numericConstants_1.OPEN_ORDER_MARGIN_REQUIREMENT));
|
|
808
|
-
if (perpPosition.lpShares.gt(numericConstants_1.ZERO)) {
|
|
809
|
-
liabilityValue = liabilityValue.add(anchor_1.BN.max(numericConstants_1.QUOTE_PRECISION, valuationPrice
|
|
810
|
-
.mul(market.amm.orderStepSize)
|
|
811
|
-
.mul(numericConstants_1.QUOTE_PRECISION)
|
|
812
|
-
.div(numericConstants_1.AMM_RESERVE_PRECISION)
|
|
813
|
-
.div(numericConstants_1.PRICE_PRECISION)));
|
|
814
|
-
}
|
|
815
630
|
}
|
|
816
631
|
}
|
|
817
632
|
return liabilityValue;
|
|
@@ -839,7 +654,7 @@ class User {
|
|
|
839
654
|
* @returns : Precision QUOTE_PRECISION
|
|
840
655
|
*/
|
|
841
656
|
getPerpPositionValue(marketIndex, oraclePriceData, includeOpenOrders = false) {
|
|
842
|
-
const userPosition = this.
|
|
657
|
+
const userPosition = this.getPerpPositionOrEmpty(marketIndex);
|
|
843
658
|
const market = this.driftClient.getPerpMarketAccount(userPosition.marketIndex);
|
|
844
659
|
return (0, margin_2.calculateBaseAssetValueWithOracle)(market, userPosition, oraclePriceData, includeOpenOrders);
|
|
845
660
|
}
|
|
@@ -848,7 +663,7 @@ class User {
|
|
|
848
663
|
* @returns : Precision QUOTE_PRECISION
|
|
849
664
|
*/
|
|
850
665
|
getPerpLiabilityValue(marketIndex, oraclePriceData, includeOpenOrders = false) {
|
|
851
|
-
const userPosition = this.
|
|
666
|
+
const userPosition = this.getPerpPositionOrEmpty(marketIndex);
|
|
852
667
|
const market = this.driftClient.getPerpMarketAccount(userPosition.marketIndex);
|
|
853
668
|
if (includeOpenOrders) {
|
|
854
669
|
return (0, margin_1.calculateWorstCasePerpLiabilityValue)(userPosition, market, oraclePriceData.price).worstCaseLiabilityValue;
|
|
@@ -1143,7 +958,7 @@ class User {
|
|
|
1143
958
|
.find((market) => market.amm.oracle.equals(oracle));
|
|
1144
959
|
const oraclePrice = this.driftClient.getOracleDataForSpotMarket(marketIndex).price;
|
|
1145
960
|
if (perpMarketWithSameOracle) {
|
|
1146
|
-
const perpPosition = this.
|
|
961
|
+
const perpPosition = this.getPerpPositionOrEmpty(perpMarketWithSameOracle.marketIndex);
|
|
1147
962
|
if (perpPosition) {
|
|
1148
963
|
let freeCollateralDeltaForPerp = this.calculateFreeCollateralDeltaForPerp(perpMarketWithSameOracle, perpPosition, numericConstants_1.ZERO, oraclePrice);
|
|
1149
964
|
if (freeCollateralDeltaForPerp) {
|
|
@@ -1184,8 +999,7 @@ class User {
|
|
|
1184
999
|
const oracle = this.driftClient.getPerpMarketAccount(marketIndex).amm.oracle;
|
|
1185
1000
|
const oraclePrice = this.driftClient.getOracleDataForPerpMarket(marketIndex).price;
|
|
1186
1001
|
const market = this.driftClient.getPerpMarketAccount(marketIndex);
|
|
1187
|
-
const currentPerpPosition = this.
|
|
1188
|
-
this.getEmptyPosition(marketIndex);
|
|
1002
|
+
const currentPerpPosition = this.getPerpPositionOrEmpty(marketIndex);
|
|
1189
1003
|
positionBaseSizeChange = (0, orders_1.standardizeBaseAssetAmount)(positionBaseSizeChange, market.amm.orderStepSize);
|
|
1190
1004
|
const freeCollateralChangeFromNewPosition = this.calculateEntriesEffectOnFreeCollateral(market, oraclePrice, currentPerpPosition, positionBaseSizeChange, estimatedEntryPrice, includeOpenOrders, enteringHighLeverage);
|
|
1191
1005
|
freeCollateral = freeCollateral.add(freeCollateralChangeFromNewPosition);
|
|
@@ -1259,7 +1073,7 @@ class User {
|
|
|
1259
1073
|
baseAssetAmount = perpPosition.baseAssetAmount;
|
|
1260
1074
|
liabilityValue = (0, margin_1.calculatePerpLiabilityValue)(baseAssetAmount, oraclePrice, (0, types_1.isVariant)(market.contractType, 'prediction'));
|
|
1261
1075
|
}
|
|
1262
|
-
const userCustomMargin = this.getUserAccount().maxMarginRatio;
|
|
1076
|
+
const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
|
|
1263
1077
|
const marginRatio = (0, market_1.calculateMarketMarginRatio)(market, baseAssetAmount.abs(), marginCategory, enteringHighLeverage === false
|
|
1264
1078
|
? Math.max(market.marginRatioInitial, userCustomMargin)
|
|
1265
1079
|
: userCustomMargin, this.isHighLeverageMode(marginCategory) || enteringHighLeverage === true);
|
|
@@ -1278,7 +1092,7 @@ class User {
|
|
|
1278
1092
|
// zero if include orders == false
|
|
1279
1093
|
const orderBaseAssetAmount = baseAssetAmount.sub(perpPosition.baseAssetAmount);
|
|
1280
1094
|
const proposedBaseAssetAmount = baseAssetAmount.add(positionBaseSizeChange);
|
|
1281
|
-
const userCustomMargin = this.getUserAccount().maxMarginRatio;
|
|
1095
|
+
const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
|
|
1282
1096
|
const marginRatio = (0, market_1.calculateMarketMarginRatio)(market, proposedBaseAssetAmount.abs(), marginCategory, enteringHighLeverage === false
|
|
1283
1097
|
? Math.max(market.marginRatioInitial, userCustomMargin)
|
|
1284
1098
|
: userCustomMargin, this.isHighLeverageMode(marginCategory) || enteringHighLeverage === true);
|
|
@@ -1344,7 +1158,7 @@ class User {
|
|
|
1344
1158
|
* @returns : Precision PRICE_PRECISION
|
|
1345
1159
|
*/
|
|
1346
1160
|
liquidationPriceAfterClose(positionMarketIndex, closeQuoteAmount, estimatedEntryPrice = numericConstants_1.ZERO) {
|
|
1347
|
-
const currentPosition = this.
|
|
1161
|
+
const currentPosition = this.getPerpPositionOrEmpty(positionMarketIndex);
|
|
1348
1162
|
const closeBaseAmount = currentPosition.baseAssetAmount
|
|
1349
1163
|
.mul(closeQuoteAmount)
|
|
1350
1164
|
.div(currentPosition.quoteAssetAmount.abs())
|
|
@@ -1373,8 +1187,7 @@ class User {
|
|
|
1373
1187
|
getMaxTradeSizeUSDCForPerp(targetMarketIndex, tradeSide, isLp = false, enterHighLeverageMode = undefined) {
|
|
1374
1188
|
let tradeSize = numericConstants_1.ZERO;
|
|
1375
1189
|
let oppositeSideTradeSize = numericConstants_1.ZERO;
|
|
1376
|
-
const currentPosition = this.
|
|
1377
|
-
this.getEmptyPosition(targetMarketIndex);
|
|
1190
|
+
const currentPosition = this.getPerpPositionOrEmpty(targetMarketIndex);
|
|
1378
1191
|
const targetSide = (0, types_1.isVariant)(tradeSide, 'short') ? 'short' : 'long';
|
|
1379
1192
|
const currentPositionSide = (currentPosition === null || currentPosition === void 0 ? void 0 : currentPosition.baseAssetAmount.isNeg())
|
|
1380
1193
|
? 'short'
|
|
@@ -1752,8 +1565,7 @@ class User {
|
|
|
1752
1565
|
.div(netAssetValueAfterTrade);
|
|
1753
1566
|
return newLeverage;
|
|
1754
1567
|
}
|
|
1755
|
-
const currentPosition = this.
|
|
1756
|
-
this.getEmptyPosition(targetMarketIndex);
|
|
1568
|
+
const currentPosition = this.getPerpPositionOrEmpty(targetMarketIndex);
|
|
1757
1569
|
const perpMarket = this.driftClient.getPerpMarketAccount(targetMarketIndex);
|
|
1758
1570
|
const oracleData = this.getOracleDataForPerpMarket(targetMarketIndex);
|
|
1759
1571
|
let {
|
|
@@ -2016,13 +1828,13 @@ class User {
|
|
|
2016
1828
|
};
|
|
2017
1829
|
}
|
|
2018
1830
|
getPerpPositionHealth({ marginCategory, perpPosition, oraclePriceData, quoteOraclePriceData, }) {
|
|
2019
|
-
const settledLpPosition = this.getPerpPositionWithLPSettle(perpPosition.marketIndex, perpPosition)[0];
|
|
2020
1831
|
const perpMarket = this.driftClient.getPerpMarketAccount(perpPosition.marketIndex);
|
|
2021
1832
|
const _oraclePriceData = oraclePriceData ||
|
|
2022
1833
|
this.driftClient.getOracleDataForPerpMarket(perpMarket.marketIndex);
|
|
2023
1834
|
const oraclePrice = _oraclePriceData.price;
|
|
2024
|
-
const { worstCaseBaseAssetAmount: worstCaseBaseAmount, worstCaseLiabilityValue, } = (0, margin_1.calculateWorstCasePerpLiabilityValue)(
|
|
2025
|
-
const
|
|
1835
|
+
const { worstCaseBaseAssetAmount: worstCaseBaseAmount, worstCaseLiabilityValue, } = (0, margin_1.calculateWorstCasePerpLiabilityValue)(perpPosition, perpMarket, oraclePrice);
|
|
1836
|
+
const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
|
|
1837
|
+
const marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(perpMarket, worstCaseBaseAmount.abs(), marginCategory, userCustomMargin, this.isHighLeverageMode(marginCategory)));
|
|
2026
1838
|
const _quoteOraclePriceData = quoteOraclePriceData ||
|
|
2027
1839
|
this.driftClient.getOracleDataForSpotMarket(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
2028
1840
|
let marginRequirement = worstCaseLiabilityValue
|
|
@@ -2031,13 +1843,6 @@ class User {
|
|
|
2031
1843
|
.mul(marginRatio)
|
|
2032
1844
|
.div(numericConstants_1.MARGIN_PRECISION);
|
|
2033
1845
|
marginRequirement = marginRequirement.add(new anchor_1.BN(perpPosition.openOrders).mul(numericConstants_1.OPEN_ORDER_MARGIN_REQUIREMENT));
|
|
2034
|
-
if (perpPosition.lpShares.gt(numericConstants_1.ZERO)) {
|
|
2035
|
-
marginRequirement = marginRequirement.add(anchor_1.BN.max(numericConstants_1.QUOTE_PRECISION, oraclePrice
|
|
2036
|
-
.mul(perpMarket.amm.orderStepSize)
|
|
2037
|
-
.mul(numericConstants_1.QUOTE_PRECISION)
|
|
2038
|
-
.div(numericConstants_1.AMM_RESERVE_PRECISION)
|
|
2039
|
-
.div(numericConstants_1.PRICE_PRECISION)));
|
|
2040
|
-
}
|
|
2041
1846
|
return {
|
|
2042
1847
|
marketIndex: perpMarket.marketIndex,
|
|
2043
1848
|
size: worstCaseBaseAmount,
|
|
@@ -2064,8 +1869,7 @@ class User {
|
|
|
2064
1869
|
quoteOraclePriceData,
|
|
2065
1870
|
}));
|
|
2066
1871
|
const quoteSpotMarket = this.driftClient.getSpotMarketAccount(perpMarket.quoteSpotMarketIndex);
|
|
2067
|
-
const
|
|
2068
|
-
const positionUnrealizedPnl = (0, position_2.calculatePositionPNL)(perpMarket, settledPerpPosition, true, oraclePriceData);
|
|
1872
|
+
const positionUnrealizedPnl = (0, position_2.calculatePositionPNL)(perpMarket, perpPosition, true, oraclePriceData);
|
|
2069
1873
|
let pnlWeight;
|
|
2070
1874
|
if (positionUnrealizedPnl.gt(numericConstants_1.ZERO)) {
|
|
2071
1875
|
pnlWeight = (0, market_1.calculateUnrealizedAssetWeight)(perpMarket, quoteSpotMarket, positionUnrealizedPnl, marginCategory, oraclePriceData);
|
|
@@ -2152,7 +1956,7 @@ class User {
|
|
|
2152
1956
|
* @returns positionValue : Precision QUOTE_PRECISION
|
|
2153
1957
|
*/
|
|
2154
1958
|
getTotalPerpPositionValueExcludingMarket(marketToIgnore, marginCategory, liquidationBuffer, includeOpenOrders) {
|
|
2155
|
-
const currentPerpPosition = this.
|
|
1959
|
+
const currentPerpPosition = this.getPerpPositionOrEmpty(marketToIgnore);
|
|
2156
1960
|
const oracleData = this.getOracleDataForPerpMarket(marketToIgnore);
|
|
2157
1961
|
let currentPerpPositionValueUSDC = numericConstants_1.ZERO;
|
|
2158
1962
|
if (currentPerpPosition) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { DataAndSlot, AccountSubscriber, ResubOpts, BufferAndSlot } from './types';
|
|
4
4
|
import { Program } from '@coral-xyz/anchor';
|
|
5
|
-
import { AccountInfoBase, AccountInfoWithBase64EncodedData, AccountInfoWithBase58EncodedData, Rpc, RpcSubscriptions, SolanaRpcSubscriptionsApi,
|
|
5
|
+
import { AccountInfoBase, AccountInfoWithBase64EncodedData, AccountInfoWithBase58EncodedData, Rpc, RpcSubscriptions, SolanaRpcSubscriptionsApi, Commitment } from 'gill';
|
|
6
6
|
import { PublicKey } from '@solana/web3.js';
|
|
7
7
|
/**
|
|
8
8
|
* WebSocketAccountSubscriberV2
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webSocketAccountSubscriberV2.d.ts","sourceRoot":"","sources":["../../../src/accounts/webSocketAccountSubscriberV2.ts"],"names":[],"mappings":";;AAAA,OAAO,EACN,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,aAAa,EACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAkB,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EACN,eAAe,EACf,gCAAgC,EAChC,gCAAgC,EAGhC,GAAG,EACH,gBAAgB,EAChB,yBAAyB,EAEzB,
|
|
1
|
+
{"version":3,"file":"webSocketAccountSubscriberV2.d.ts","sourceRoot":"","sources":["../../../src/accounts/webSocketAccountSubscriberV2.ts"],"names":[],"mappings":";;AAAA,OAAO,EACN,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,aAAa,EACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAkB,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EACN,eAAe,EACf,gCAAgC,EAChC,gCAAgC,EAGhC,GAAG,EACH,gBAAgB,EAChB,yBAAyB,EAEzB,UAAU,EACV,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,qBAAa,4BAA4B,CAAC,CAAC,CAAE,YAAW,iBAAiB,CAAC,CAAC,CAAC;IAC3E,WAAW,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC7B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,EAAE,SAAS,CAAC;IAC5B,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,CAAC;IACtC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,SAAS,EAAE,SAAS,CAAC;IAErB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,eAAe,UAAS;IAExB,SAAS,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;IAC1C,gBAAgB,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;IAEjD,aAAa,EAAE,OAAO,CAAC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PublicKey } from '@solana/web3.js';
|
|
6
|
-
import { AccountInfoBase, AccountInfoWithBase58EncodedData, AccountInfoWithBase64EncodedData,
|
|
6
|
+
import { AccountInfoBase, AccountInfoWithBase58EncodedData, AccountInfoWithBase64EncodedData, Address } from 'gill';
|
|
7
7
|
/**
|
|
8
8
|
* WebSocketProgramAccountsSubscriberV2
|
|
9
9
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webSocketProgramAccountsSubscriberV2.d.ts","sourceRoot":"","sources":["../../../src/accounts/webSocketProgramAccountsSubscriberV2.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAkB,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EACN,eAAe,EACf,gCAAgC,EAChC,gCAAgC,EAKhC,
|
|
1
|
+
{"version":3,"file":"webSocketProgramAccountsSubscriberV2.d.ts","sourceRoot":"","sources":["../../../src/accounts/webSocketProgramAccountsSubscriberV2.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAkB,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EACN,eAAe,EACf,gCAAgC,EAChC,gCAAgC,EAKhC,OAAO,EAEP,MAAM,MAAM,CAAC;AAqBd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,qBAAa,oCAAoC,CAAC,CAAC,CAClD,YAAW,wBAAwB,CAAC,CAAC,CAA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|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/decode/user.ts"],"names":[],"mappings":";;AACA,OAAO,EAWN,WAAW,EACX,MAAM,UAAU,CAAC;AAkBlB,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/decode/user.ts"],"names":[],"mappings":";;AACA,OAAO,EAWN,WAAW,EACX,MAAM,UAAU,CAAC;AAkBlB,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CA+VtD"}
|
package/lib/node/decode/user.js
CHANGED
|
@@ -94,7 +94,7 @@ function decodeUser(buffer) {
|
|
|
94
94
|
offset += 8;
|
|
95
95
|
const lastQuoteAssetAmountPerLp = readSignedBigInt64LE(buffer, offset);
|
|
96
96
|
offset += 8;
|
|
97
|
-
const
|
|
97
|
+
const maxMarginRatio = buffer.readUInt16LE(offset);
|
|
98
98
|
offset += 4;
|
|
99
99
|
const marketIndex = buffer.readUInt16LE(offset);
|
|
100
100
|
offset += 3;
|
|
@@ -110,12 +110,13 @@ function decodeUser(buffer) {
|
|
|
110
110
|
openAsks,
|
|
111
111
|
settledPnl,
|
|
112
112
|
lpShares,
|
|
113
|
+
remainderBaseAssetAmount: 0,
|
|
113
114
|
lastBaseAssetAmountPerLp,
|
|
114
115
|
lastQuoteAssetAmountPerLp,
|
|
115
|
-
remainderBaseAssetAmount,
|
|
116
116
|
marketIndex,
|
|
117
117
|
openOrders,
|
|
118
118
|
perLpBase,
|
|
119
|
+
maxMarginRatio,
|
|
119
120
|
});
|
|
120
121
|
}
|
|
121
122
|
const orders = [];
|
|
@@ -188,6 +188,8 @@ export declare class DriftClient {
|
|
|
188
188
|
subAccountId: number;
|
|
189
189
|
}[], txParams?: TxParams): Promise<TransactionSignature>;
|
|
190
190
|
getUpdateUserCustomMarginRatioIx(marginRatio: number, subAccountId?: number): Promise<TransactionInstruction>;
|
|
191
|
+
getUpdateUserPerpPositionCustomMarginRatioIx(perpMarketIndex: number, marginRatio: number, subAccountId?: number): Promise<TransactionInstruction>;
|
|
192
|
+
updateUserPerpPositionCustomMarginRatio(perpMarketIndex: number, marginRatio: number, subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
191
193
|
getUpdateUserMarginTradingEnabledIx(marginTradingEnabled: boolean, subAccountId?: number, userAccountPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
192
194
|
updateUserMarginTradingEnabled(updates: {
|
|
193
195
|
marginTradingEnabled: boolean;
|