@drift-labs/jit-proxy 0.10.40 → 0.10.42

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.
@@ -23,6 +23,28 @@ class JitterSniper extends baseJitter_1.BaseJitter {
23
23
  const takerStats = await this.userStatsMap.mustGet(taker.authority.toString());
24
24
  const referrerInfo = takerStats.getReferrerInfo();
25
25
  const { slotsTilCross, willCross, bid, ask, auctionStartPrice, auctionEndPrice, stepSize, oraclePrice, } = this.getAuctionAndOrderDetails(order);
26
+ // don't increase risk if we're past max positions
27
+ if ((0, sdk_1.isVariant)(order.marketType, 'perp')) {
28
+ const currPerpPos = this.driftClient
29
+ .getUser()
30
+ .getPerpPosition(order.marketIndex);
31
+ if (currPerpPos.baseAssetAmount.lt(sdk_1.ZERO) &&
32
+ (0, sdk_1.isVariant)(order.direction, 'short')) {
33
+ if (currPerpPos.baseAssetAmount.lte(params.minPosition)) {
34
+ console.log(`Order would increase existing short (mkt ${(0, sdk_1.getVariant)(order.marketType)}-${order.marketIndex}) too much`);
35
+ this.onGoingAuctions.delete(orderSignature);
36
+ return;
37
+ }
38
+ }
39
+ else if (currPerpPos.baseAssetAmount.gt(sdk_1.ZERO) &&
40
+ (0, sdk_1.isVariant)(order.direction, 'long')) {
41
+ if (currPerpPos.baseAssetAmount.gte(params.maxPosition)) {
42
+ console.log(`Order would increase existing long (mkt ${(0, sdk_1.getVariant)(order.marketType)}-${order.marketIndex}) too much`);
43
+ this.onGoingAuctions.delete(orderSignature);
44
+ return;
45
+ }
46
+ }
47
+ }
26
48
  console.log(`
27
49
  Taker wants to ${JSON.stringify(order.direction)}, order slot is ${order.slot.toNumber()},
28
50
  My market: ${bid}@${ask},
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@drift-labs/jit-proxy",
3
- "version": "0.10.40",
3
+ "version": "0.10.42",
4
4
  "scripts": {
5
5
  "clean": "rm -rf lib",
6
6
  "build": "yarn clean && tsc"
7
7
  },
8
8
  "dependencies": {
9
9
  "@coral-xyz/anchor": "^0.26.0",
10
- "@drift-labs/sdk": "2.42.0-beta.8",
10
+ "@drift-labs/sdk": "2.42.0-beta.9",
11
11
  "@solana/web3.js": "1.73.2"
12
12
  },
13
13
  "engines": {
@@ -6,6 +6,7 @@ import {
6
6
  DriftClient,
7
7
  getAuctionPrice,
8
8
  getAuctionPriceForOracleOffsetAuction,
9
+ getVariant,
9
10
  isVariant,
10
11
  OraclePriceData,
11
12
  Order,
@@ -13,6 +14,7 @@ import {
13
14
  SlotSubscriber,
14
15
  UserAccount,
15
16
  UserStatsMap,
17
+ ZERO,
16
18
  } from '@drift-labs/sdk';
17
19
  import { BaseJitter } from './baseJitter';
18
20
 
@@ -83,6 +85,40 @@ export class JitterSniper extends BaseJitter {
83
85
  oraclePrice,
84
86
  } = this.getAuctionAndOrderDetails(order);
85
87
 
88
+ // don't increase risk if we're past max positions
89
+ if (isVariant(order.marketType, 'perp')) {
90
+ const currPerpPos = this.driftClient
91
+ .getUser()
92
+ .getPerpPosition(order.marketIndex);
93
+ if (
94
+ currPerpPos.baseAssetAmount.lt(ZERO) &&
95
+ isVariant(order.direction, 'short')
96
+ ) {
97
+ if (currPerpPos.baseAssetAmount.lte(params.minPosition)) {
98
+ console.log(
99
+ `Order would increase existing short (mkt ${getVariant(
100
+ order.marketType
101
+ )}-${order.marketIndex}) too much`
102
+ );
103
+ this.onGoingAuctions.delete(orderSignature);
104
+ return;
105
+ }
106
+ } else if (
107
+ currPerpPos.baseAssetAmount.gt(ZERO) &&
108
+ isVariant(order.direction, 'long')
109
+ ) {
110
+ if (currPerpPos.baseAssetAmount.gte(params.maxPosition)) {
111
+ console.log(
112
+ `Order would increase existing long (mkt ${getVariant(
113
+ order.marketType
114
+ )}-${order.marketIndex}) too much`
115
+ );
116
+ this.onGoingAuctions.delete(orderSignature);
117
+ return;
118
+ }
119
+ }
120
+ }
121
+
86
122
  console.log(`
87
123
  Taker wants to ${JSON.stringify(
88
124
  order.direction