@drift-labs/sdk 2.18.0-beta.2 → 2.18.0

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.
@@ -1841,7 +1841,7 @@ class DriftClient {
1841
1841
  ? newTriggerCondition || openOrder.triggerCondition
1842
1842
  : undefined,
1843
1843
  oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
1844
- auctionDuration: auctionDuration || openOrder.auctionDuration,
1844
+ auctionDuration: auctionDuration !== null && auctionDuration !== void 0 ? auctionDuration : openOrder.auctionDuration,
1845
1845
  maxTs: openOrder.maxTs,
1846
1846
  auctionStartPrice: auctionStartPrice || openOrder.auctionStartPrice,
1847
1847
  auctionEndPrice: auctionEndPrice || openOrder.auctionEndPrice,
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.18.0-beta.2",
2
+ "version": "2.18.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -8596,6 +8596,11 @@
8596
8596
  "code": 6226,
8597
8597
  "name": "MarginOrdersOpen",
8598
8598
  "msg": "MarginOrdersOpen"
8599
+ },
8600
+ {
8601
+ "code": 6227,
8602
+ "name": "TierViolationLiquidatingPerpPnl",
8603
+ "msg": "TierViolationLiquidatingPerpPnl"
8599
8604
  }
8600
8605
  ]
8601
8606
  }
@@ -6,6 +6,7 @@ const anchor_1 = require("@project-serum/anchor");
6
6
  const numericConstants_1 = require("../constants/numericConstants");
7
7
  const margin_1 = require("./margin");
8
8
  const numericConstants_2 = require("../constants/numericConstants");
9
+ const utils_1 = require("./utils");
9
10
  function getBalance(tokenAmount, spotMarket, balanceType) {
10
11
  const precisionIncrease = numericConstants_1.TEN.pow(new anchor_1.BN(19 - spotMarket.decimals));
11
12
  const cumulativeInterest = types_1.isVariant(balanceType, 'deposit')
@@ -20,10 +21,14 @@ function getBalance(tokenAmount, spotMarket, balanceType) {
20
21
  exports.getBalance = getBalance;
21
22
  function getTokenAmount(balanceAmount, spotMarket, balanceType) {
22
23
  const precisionDecrease = numericConstants_1.TEN.pow(new anchor_1.BN(19 - spotMarket.decimals));
23
- const cumulativeInterest = types_1.isVariant(balanceType, 'deposit')
24
- ? spotMarket.cumulativeDepositInterest
25
- : spotMarket.cumulativeBorrowInterest;
26
- return balanceAmount.mul(cumulativeInterest).div(precisionDecrease);
24
+ if (types_1.isVariant(balanceType, 'deposit')) {
25
+ return balanceAmount
26
+ .mul(spotMarket.cumulativeDepositInterest)
27
+ .div(precisionDecrease);
28
+ }
29
+ else {
30
+ return utils_1.divCeil(balanceAmount.mul(spotMarket.cumulativeBorrowInterest), precisionDecrease);
31
+ }
27
32
  }
28
33
  exports.getTokenAmount = getTokenAmount;
29
34
  function getSignedTokenAmount(tokenAmount, balanceType) {
@@ -2,3 +2,4 @@
2
2
  import { BN } from '../';
3
3
  export declare function clampBN(x: BN, min: BN, max: BN): BN;
4
4
  export declare const squareRootBN: (n: BN) => BN;
5
+ export declare const divCeil: (a: BN, b: BN) => BN;
package/lib/math/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.squareRootBN = exports.clampBN = void 0;
3
+ exports.divCeil = exports.squareRootBN = exports.clampBN = void 0;
4
4
  const __1 = require("../");
5
5
  function clampBN(x, min, max) {
6
6
  return __1.BN.max(min, __1.BN.min(x, max));
@@ -23,3 +23,14 @@ const squareRootBN = (n) => {
23
23
  }
24
24
  };
25
25
  exports.squareRootBN = squareRootBN;
26
+ const divCeil = (a, b) => {
27
+ const quotient = a.div(b);
28
+ const remainder = a.mod(b);
29
+ if (remainder.gt(__1.ZERO)) {
30
+ return quotient.add(__1.ONE);
31
+ }
32
+ else {
33
+ return quotient;
34
+ }
35
+ };
36
+ exports.divCeil = divCeil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.18.0-beta.2",
3
+ "version": "2.18.0",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -3160,7 +3160,7 @@ export class DriftClient {
3160
3160
  ? newTriggerCondition || openOrder.triggerCondition
3161
3161
  : undefined,
3162
3162
  oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
3163
- auctionDuration: auctionDuration || openOrder.auctionDuration,
3163
+ auctionDuration: auctionDuration ?? openOrder.auctionDuration,
3164
3164
  maxTs: openOrder.maxTs,
3165
3165
  auctionStartPrice: auctionStartPrice || openOrder.auctionStartPrice,
3166
3166
  auctionEndPrice: auctionEndPrice || openOrder.auctionEndPrice,
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.18.0-beta.2",
2
+ "version": "2.18.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -8596,6 +8596,11 @@
8596
8596
  "code": 6226,
8597
8597
  "name": "MarginOrdersOpen",
8598
8598
  "msg": "MarginOrdersOpen"
8599
+ },
8600
+ {
8601
+ "code": 6227,
8602
+ "name": "TierViolationLiquidatingPerpPnl",
8603
+ "msg": "TierViolationLiquidatingPerpPnl"
8599
8604
  }
8600
8605
  ]
8601
8606
  }
@@ -21,6 +21,7 @@ import {
21
21
  } from './margin';
22
22
  import { OraclePriceData } from '../oracles/types';
23
23
  import { PERCENTAGE_PRECISION } from '../constants/numericConstants';
24
+ import { divCeil } from './utils';
24
25
 
25
26
  export function getBalance(
26
27
  tokenAmount: BN,
@@ -49,11 +50,16 @@ export function getTokenAmount(
49
50
  ): BN {
50
51
  const precisionDecrease = TEN.pow(new BN(19 - spotMarket.decimals));
51
52
 
52
- const cumulativeInterest = isVariant(balanceType, 'deposit')
53
- ? spotMarket.cumulativeDepositInterest
54
- : spotMarket.cumulativeBorrowInterest;
55
-
56
- return balanceAmount.mul(cumulativeInterest).div(precisionDecrease);
53
+ if (isVariant(balanceType, 'deposit')) {
54
+ return balanceAmount
55
+ .mul(spotMarket.cumulativeDepositInterest)
56
+ .div(precisionDecrease);
57
+ } else {
58
+ return divCeil(
59
+ balanceAmount.mul(spotMarket.cumulativeBorrowInterest),
60
+ precisionDecrease
61
+ );
62
+ }
57
63
  }
58
64
 
59
65
  export function getSignedTokenAmount(
package/src/math/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BN } from '../';
1
+ import { BN, ONE, ZERO } from '../';
2
2
 
3
3
  export function clampBN(x: BN, min: BN, max: BN): BN {
4
4
  return BN.max(min, BN.min(x, max));
@@ -21,3 +21,15 @@ export const squareRootBN = (n: BN): BN => {
21
21
  return largeCand;
22
22
  }
23
23
  };
24
+
25
+ export const divCeil = (a: BN, b: BN): BN => {
26
+ const quotient = a.div(b);
27
+
28
+ const remainder = a.mod(b);
29
+
30
+ if (remainder.gt(ZERO)) {
31
+ return quotient.add(ONE);
32
+ } else {
33
+ return quotient;
34
+ }
35
+ };