@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.
- package/lib/driftClient.js +1 -1
- package/lib/idl/drift.json +6 -1
- package/lib/math/spotBalance.js +9 -4
- package/lib/math/utils.d.ts +1 -0
- package/lib/math/utils.js +12 -1
- package/package.json +1 -1
- package/src/driftClient.ts +1 -1
- package/src/idl/drift.json +6 -1
- package/src/math/spotBalance.ts +11 -5
- package/src/math/utils.ts +13 -1
package/lib/driftClient.js
CHANGED
|
@@ -1841,7 +1841,7 @@ class DriftClient {
|
|
|
1841
1841
|
? newTriggerCondition || openOrder.triggerCondition
|
|
1842
1842
|
: undefined,
|
|
1843
1843
|
oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
|
|
1844
|
-
auctionDuration: 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,
|
package/lib/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.18.0
|
|
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
|
}
|
package/lib/math/spotBalance.js
CHANGED
|
@@ -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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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) {
|
package/lib/math/utils.d.ts
CHANGED
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
package/src/driftClient.ts
CHANGED
|
@@ -3160,7 +3160,7 @@ export class DriftClient {
|
|
|
3160
3160
|
? newTriggerCondition || openOrder.triggerCondition
|
|
3161
3161
|
: undefined,
|
|
3162
3162
|
oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
|
|
3163
|
-
auctionDuration: auctionDuration
|
|
3163
|
+
auctionDuration: auctionDuration ?? openOrder.auctionDuration,
|
|
3164
3164
|
maxTs: openOrder.maxTs,
|
|
3165
3165
|
auctionStartPrice: auctionStartPrice || openOrder.auctionStartPrice,
|
|
3166
3166
|
auctionEndPrice: auctionEndPrice || openOrder.auctionEndPrice,
|
package/src/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.18.0
|
|
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
|
}
|
package/src/math/spotBalance.ts
CHANGED
|
@@ -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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
+
};
|