@drift-labs/sdk 2.0.13 → 2.0.15
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/README.md +3 -3
- package/lib/accounts/pollingDriftClientAccountSubscriber.js +0 -3
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +0 -3
- package/lib/adminClient.d.ts +2 -0
- package/lib/adminClient.js +16 -0
- package/lib/constants/numericConstants.d.ts +2 -0
- package/lib/constants/numericConstants.js +3 -1
- package/lib/dlob/DLOB.d.ts +8 -8
- package/lib/dlob/DLOB.js +227 -246
- package/lib/driftClient.d.ts +19 -0
- package/lib/driftClient.js +32 -0
- package/lib/idl/drift.json +65 -7
- package/lib/math/amm.d.ts +3 -2
- package/lib/math/amm.js +61 -27
- package/lib/math/oracles.d.ts +2 -0
- package/lib/math/oracles.js +23 -1
- package/lib/math/orders.d.ts +1 -2
- package/lib/math/orders.js +4 -20
- package/lib/math/utils.d.ts +1 -0
- package/lib/math/utils.js +5 -1
- package/lib/types.d.ts +6 -2
- package/lib/user.js +10 -6
- package/package.json +1 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +0 -4
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +0 -4
- package/src/adminClient.ts +28 -0
- package/src/constants/numericConstants.ts +3 -0
- package/src/dlob/DLOB.ts +444 -345
- package/src/driftClient.ts +41 -0
- package/src/idl/drift.json +65 -7
- package/src/math/amm.ts +126 -42
- package/src/math/oracles.ts +52 -0
- package/src/math/orders.ts +5 -22
- package/src/math/utils.ts +4 -0
- package/src/types.ts +6 -2
- package/src/user.ts +17 -6
- package/tests/dlob/helpers.ts +4 -2
- package/tests/dlob/test.ts +547 -63
package/src/user.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
SPOT_MARKET_WEIGHT_PRECISION,
|
|
26
26
|
QUOTE_SPOT_MARKET_INDEX,
|
|
27
27
|
TEN,
|
|
28
|
+
OPEN_ORDER_MARGIN_REQUIREMENT,
|
|
28
29
|
} from './constants/numericConstants';
|
|
29
30
|
import {
|
|
30
31
|
UserAccountSubscriber,
|
|
@@ -163,8 +164,8 @@ export class User {
|
|
|
163
164
|
openAsks: ZERO,
|
|
164
165
|
settledPnl: ZERO,
|
|
165
166
|
lpShares: ZERO,
|
|
166
|
-
|
|
167
|
-
|
|
167
|
+
lastBaseAssetAmountPerLp: ZERO,
|
|
168
|
+
lastQuoteAssetAmountPerLp: ZERO,
|
|
168
169
|
};
|
|
169
170
|
}
|
|
170
171
|
|
|
@@ -267,11 +268,11 @@ export class User {
|
|
|
267
268
|
const nShares = position.lpShares;
|
|
268
269
|
|
|
269
270
|
const deltaBaa = market.amm.baseAssetAmountPerLp
|
|
270
|
-
.sub(position.
|
|
271
|
+
.sub(position.lastBaseAssetAmountPerLp)
|
|
271
272
|
.mul(nShares)
|
|
272
273
|
.div(AMM_RESERVE_PRECISION);
|
|
273
274
|
const deltaQaa = market.amm.quoteAssetAmountPerLp
|
|
274
|
-
.sub(position.
|
|
275
|
+
.sub(position.lastQuoteAssetAmountPerLp)
|
|
275
276
|
.mul(nShares)
|
|
276
277
|
.div(AMM_RESERVE_PRECISION);
|
|
277
278
|
|
|
@@ -593,6 +594,10 @@ export class User {
|
|
|
593
594
|
newTotalLiabilityValue.add(weightedTokenValue);
|
|
594
595
|
}
|
|
595
596
|
|
|
597
|
+
newTotalLiabilityValue = newTotalLiabilityValue.add(
|
|
598
|
+
new BN(spotPosition.openOrders).mul(OPEN_ORDER_MARGIN_REQUIREMENT)
|
|
599
|
+
);
|
|
600
|
+
|
|
596
601
|
return newTotalLiabilityValue;
|
|
597
602
|
},
|
|
598
603
|
ZERO
|
|
@@ -893,6 +898,12 @@ export class User {
|
|
|
893
898
|
baseAssetValue = baseAssetValue
|
|
894
899
|
.mul(marginRatio)
|
|
895
900
|
.div(MARGIN_PRECISION);
|
|
901
|
+
|
|
902
|
+
if (includeOpenOrders) {
|
|
903
|
+
baseAssetValue = baseAssetValue.add(
|
|
904
|
+
new BN(perpPosition.openOrders).mul(OPEN_ORDER_MARGIN_REQUIREMENT)
|
|
905
|
+
);
|
|
906
|
+
}
|
|
896
907
|
}
|
|
897
908
|
|
|
898
909
|
return totalPerpValue.add(baseAssetValue);
|
|
@@ -1251,8 +1262,8 @@ export class User {
|
|
|
1251
1262
|
openAsks: new BN(0),
|
|
1252
1263
|
settledPnl: ZERO,
|
|
1253
1264
|
lpShares: ZERO,
|
|
1254
|
-
|
|
1255
|
-
|
|
1265
|
+
lastBaseAssetAmountPerLp: ZERO,
|
|
1266
|
+
lastQuoteAssetAmountPerLp: ZERO,
|
|
1256
1267
|
};
|
|
1257
1268
|
|
|
1258
1269
|
if (proposedBaseAssetAmount.eq(ZERO)) return new BN(-1);
|
package/tests/dlob/helpers.ts
CHANGED
|
@@ -37,8 +37,8 @@ export const mockPerpPosition: PerpPosition = {
|
|
|
37
37
|
settledPnl: new BN(0),
|
|
38
38
|
lpShares: new BN(0),
|
|
39
39
|
remainderBaseAssetAmount: 0,
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
lastBaseAssetAmountPerLp: new BN(0),
|
|
41
|
+
lastQuoteAssetAmountPerLp: new BN(0),
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
export const mockAMM: AMM = {
|
|
@@ -486,6 +486,8 @@ export const mockStateAccount: StateAccount = {
|
|
|
486
486
|
numberOfSpotMarkets: 0,
|
|
487
487
|
numberOfSubAccounts: new BN(0),
|
|
488
488
|
numberOfAuthorities: new BN(0),
|
|
489
|
+
initialPctToLiquidate: 0,
|
|
490
|
+
liquidationDuration: 0,
|
|
489
491
|
oracleGuardRails: {
|
|
490
492
|
priceDivergence: {
|
|
491
493
|
markOracleDivergenceNumerator: new BN(0),
|