@drift-labs/sdk 2.37.1-beta.3 → 2.37.1-beta.5

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.37.1-beta.3
1
+ 2.37.1-beta.5
@@ -144,6 +144,16 @@ exports.DevnetPerpMarkets = [
144
144
  launchTs: 1689270550000,
145
145
  oracleSource: __1.OracleSource.PYTH,
146
146
  },
147
+ {
148
+ fullName: 'HNT',
149
+ category: ['IoT'],
150
+ symbol: 'HNT-PERP',
151
+ baseAssetSymbol: 'HNT',
152
+ marketIndex: 14,
153
+ oracle: new web3_js_1.PublicKey('6Eg8YdfFJQF2HHonzPUBSCCmyUEhrStg9VBLK957sBe6'),
154
+ launchTs: 16922949550000,
155
+ oracleSource: __1.OracleSource.PYTH,
156
+ },
147
157
  ];
148
158
  exports.MainnetPerpMarkets = [
149
159
  {
@@ -286,6 +296,16 @@ exports.MainnetPerpMarkets = [
286
296
  launchTs: 1689270550000,
287
297
  oracleSource: __1.OracleSource.PYTH,
288
298
  },
299
+ {
300
+ fullName: 'HNT',
301
+ category: ['IoT'],
302
+ symbol: 'HNT-PERP',
303
+ baseAssetSymbol: 'HNT',
304
+ marketIndex: 14,
305
+ oracle: new web3_js_1.PublicKey('7moA1i5vQUpfDwSpK6Pw9s56ahB7WFGidtbL2ujWrVvm'),
306
+ launchTs: 16922949550000,
307
+ oracleSource: __1.OracleSource.PYTH,
308
+ },
289
309
  ];
290
310
  exports.PerpMarkets = {
291
311
  devnet: exports.DevnetPerpMarkets,
@@ -64,7 +64,7 @@ function getAuctionPriceForOracleOffsetAuction(order, slot, oraclePrice) {
64
64
  const deltaDenominator = new _1.BN(order.auctionDuration);
65
65
  const deltaNumerator = _1.BN.min(slotsElapsed, deltaDenominator);
66
66
  if (deltaDenominator.eq(_1.ZERO)) {
67
- return order.auctionEndPrice.add(order.auctionEndPrice);
67
+ return oraclePrice.add(order.auctionEndPrice);
68
68
  }
69
69
  let priceOffsetDelta;
70
70
  if ((0, types_1.isVariant)(order.direction, 'long')) {
package/lib/types.d.ts CHANGED
@@ -50,6 +50,9 @@ export declare class UserStatus {
50
50
  static readonly BANKRUPT: {
51
51
  bankrupt: {};
52
52
  };
53
+ static readonly REDUCE_ONLY: {
54
+ reduceOnly: {};
55
+ };
53
56
  }
54
57
  export declare class ContractType {
55
58
  static readonly PERPETUAL: {
package/lib/types.js CHANGED
@@ -33,6 +33,7 @@ exports.UserStatus = UserStatus;
33
33
  UserStatus.ACTIVE = { active: {} };
34
34
  UserStatus.BEING_LIQUIDATED = { beingLiquidated: {} };
35
35
  UserStatus.BANKRUPT = { bankrupt: {} };
36
+ UserStatus.REDUCE_ONLY = { reduceOnly: {} };
36
37
  class ContractType {
37
38
  }
38
39
  exports.ContractType = ContractType;
package/lib/user.js CHANGED
@@ -1606,12 +1606,15 @@ class User {
1606
1606
  if (canBypass) {
1607
1607
  withdrawLimit = _1.BN.max(withdrawLimit, userDepositAmount);
1608
1608
  }
1609
- const amountWithdrawable = freeCollateral
1610
- .mul(numericConstants_1.MARGIN_PRECISION)
1611
- .div(new _1.BN(spotMarket.initialAssetWeight))
1612
- .mul(numericConstants_1.PRICE_PRECISION)
1613
- .div(oracleData.price)
1614
- .mul(precisionIncrease);
1609
+ const assetWeight = (0, spotBalance_1.calculateAssetWeight)(userDepositAmount, spotMarket, 'Initial');
1610
+ const amountWithdrawable = assetWeight.eq(numericConstants_1.ZERO)
1611
+ ? userDepositAmount
1612
+ : freeCollateral
1613
+ .mul(numericConstants_1.MARGIN_PRECISION)
1614
+ .div(assetWeight)
1615
+ .mul(numericConstants_1.PRICE_PRECISION)
1616
+ .div(oracleData.price)
1617
+ .mul(precisionIncrease);
1615
1618
  const maxWithdrawValue = _1.BN.min(_1.BN.min(amountWithdrawable, userDepositAmount), withdrawLimit.abs());
1616
1619
  if (reduceOnly) {
1617
1620
  return _1.BN.max(maxWithdrawValue, numericConstants_1.ZERO);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.37.1-beta.3",
3
+ "version": "2.37.1-beta.5",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -154,6 +154,16 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
154
154
  launchTs: 1689270550000,
155
155
  oracleSource: OracleSource.PYTH,
156
156
  },
157
+ {
158
+ fullName: 'HNT',
159
+ category: ['IoT'],
160
+ symbol: 'HNT-PERP',
161
+ baseAssetSymbol: 'HNT',
162
+ marketIndex: 14,
163
+ oracle: new PublicKey('6Eg8YdfFJQF2HHonzPUBSCCmyUEhrStg9VBLK957sBe6'),
164
+ launchTs: 16922949550000,
165
+ oracleSource: OracleSource.PYTH,
166
+ },
157
167
  ];
158
168
 
159
169
  export const MainnetPerpMarkets: PerpMarketConfig[] = [
@@ -297,6 +307,16 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
297
307
  launchTs: 1689270550000,
298
308
  oracleSource: OracleSource.PYTH,
299
309
  },
310
+ {
311
+ fullName: 'HNT',
312
+ category: ['IoT'],
313
+ symbol: 'HNT-PERP',
314
+ baseAssetSymbol: 'HNT',
315
+ marketIndex: 14,
316
+ oracle: new PublicKey('7moA1i5vQUpfDwSpK6Pw9s56ahB7WFGidtbL2ujWrVvm'),
317
+ launchTs: 16922949550000,
318
+ oracleSource: OracleSource.PYTH,
319
+ },
300
320
  ];
301
321
 
302
322
  export const PerpMarkets: { [key in DriftEnv]: PerpMarketConfig[] } = {
@@ -79,7 +79,7 @@ export function getAuctionPriceForOracleOffsetAuction(
79
79
  const deltaNumerator = BN.min(slotsElapsed, deltaDenominator);
80
80
 
81
81
  if (deltaDenominator.eq(ZERO)) {
82
- return order.auctionEndPrice.add(order.auctionEndPrice);
82
+ return oraclePrice.add(order.auctionEndPrice);
83
83
  }
84
84
 
85
85
  let priceOffsetDelta;
package/src/types.ts CHANGED
@@ -31,6 +31,7 @@ export class UserStatus {
31
31
  static readonly ACTIVE = { active: {} };
32
32
  static readonly BEING_LIQUIDATED = { beingLiquidated: {} };
33
33
  static readonly BANKRUPT = { bankrupt: {} };
34
+ static readonly REDUCE_ONLY = { reduceOnly: {} };
34
35
  }
35
36
 
36
37
  export class ContractType {
package/src/user.ts CHANGED
@@ -2937,12 +2937,20 @@ export class User {
2937
2937
  withdrawLimit = BN.max(withdrawLimit, userDepositAmount);
2938
2938
  }
2939
2939
 
2940
- const amountWithdrawable = freeCollateral
2941
- .mul(MARGIN_PRECISION)
2942
- .div(new BN(spotMarket.initialAssetWeight))
2943
- .mul(PRICE_PRECISION)
2944
- .div(oracleData.price)
2945
- .mul(precisionIncrease);
2940
+ const assetWeight = calculateAssetWeight(
2941
+ userDepositAmount,
2942
+ spotMarket,
2943
+ 'Initial'
2944
+ );
2945
+
2946
+ const amountWithdrawable = assetWeight.eq(ZERO)
2947
+ ? userDepositAmount
2948
+ : freeCollateral
2949
+ .mul(MARGIN_PRECISION)
2950
+ .div(assetWeight)
2951
+ .mul(PRICE_PRECISION)
2952
+ .div(oracleData.price)
2953
+ .mul(precisionIncrease);
2946
2954
 
2947
2955
  const maxWithdrawValue = BN.min(
2948
2956
  BN.min(amountWithdrawable, userDepositAmount),