@drift-labs/sdk 2.31.1-beta.17 → 2.31.1-beta.19
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 +1 -1
- package/lib/idl/drift.json +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/math/spotBalance.d.ts +2 -2
- package/lib/math/spotBalance.js +11 -5
- package/package.json +1 -1
- package/src/idl/drift.json +1 -1
- package/src/index.ts +1 -0
- package/src/math/spotBalance.ts +17 -6
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.31.1-beta.
|
|
1
|
+
2.31.1-beta.19
|
package/lib/idl/drift.json
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export * from './math/orders';
|
|
|
45
45
|
export * from './math/repeg';
|
|
46
46
|
export * from './math/margin';
|
|
47
47
|
export * from './math/insurance';
|
|
48
|
+
export * from './math/superStake';
|
|
48
49
|
export * from './marinade';
|
|
49
50
|
export * from './orderParams';
|
|
50
51
|
export * from './slot/SlotSubscriber';
|
package/lib/index.js
CHANGED
|
@@ -68,6 +68,7 @@ __exportStar(require("./math/orders"), exports);
|
|
|
68
68
|
__exportStar(require("./math/repeg"), exports);
|
|
69
69
|
__exportStar(require("./math/margin"), exports);
|
|
70
70
|
__exportStar(require("./math/insurance"), exports);
|
|
71
|
+
__exportStar(require("./math/superStake"), exports);
|
|
71
72
|
__exportStar(require("./marinade"), exports);
|
|
72
73
|
__exportStar(require("./orderParams"), exports);
|
|
73
74
|
__exportStar(require("./slot/SlotSubscriber"), exports);
|
|
@@ -49,7 +49,7 @@ export declare function getStrictTokenValue(tokenAmount: BN, spotDecimals: numbe
|
|
|
49
49
|
export declare function getTokenValue(tokenAmount: BN, spotDecimals: number, oraclePriceData: OraclePriceData): BN;
|
|
50
50
|
export declare function calculateAssetWeight(balanceAmount: BN, spotMarket: SpotMarketAccount, marginCategory: MarginCategory): BN;
|
|
51
51
|
export declare function calculateLiabilityWeight(size: BN, spotMarket: SpotMarketAccount, marginCategory: MarginCategory): BN;
|
|
52
|
-
export declare function calculateUtilization(bank: SpotMarketAccount): BN;
|
|
52
|
+
export declare function calculateUtilization(bank: SpotMarketAccount, delta?: any): BN;
|
|
53
53
|
/**
|
|
54
54
|
* calculates max borrow amount where rate would stay below targetBorrowRate
|
|
55
55
|
* @param spotMarketAccount
|
|
@@ -57,7 +57,7 @@ export declare function calculateUtilization(bank: SpotMarketAccount): BN;
|
|
|
57
57
|
* @returns : Precision: TOKEN DECIMALS
|
|
58
58
|
*/
|
|
59
59
|
export declare function calculateSpotMarketBorrowCapacity(spotMarketAccount: SpotMarketAccount, targetBorrowRate: BN): BN;
|
|
60
|
-
export declare function calculateInterestRate(bank: SpotMarketAccount): BN;
|
|
60
|
+
export declare function calculateInterestRate(bank: SpotMarketAccount, delta?: any): BN;
|
|
61
61
|
export declare function calculateDepositRate(bank: SpotMarketAccount): BN;
|
|
62
62
|
export declare function calculateBorrowRate(bank: SpotMarketAccount): BN;
|
|
63
63
|
export declare function calculateInterestAccumulated(bank: SpotMarketAccount, now: BN): {
|
package/lib/math/spotBalance.js
CHANGED
|
@@ -156,9 +156,15 @@ function calculateLiabilityWeight(size, spotMarket, marginCategory) {
|
|
|
156
156
|
return liabilityWeight;
|
|
157
157
|
}
|
|
158
158
|
exports.calculateLiabilityWeight = calculateLiabilityWeight;
|
|
159
|
-
function calculateUtilization(bank) {
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
function calculateUtilization(bank, delta = numericConstants_1.ZERO) {
|
|
160
|
+
let tokenDepositAmount = getTokenAmount(bank.depositBalance, bank, types_1.SpotBalanceType.DEPOSIT);
|
|
161
|
+
let tokenBorrowAmount = getTokenAmount(bank.borrowBalance, bank, types_1.SpotBalanceType.BORROW);
|
|
162
|
+
if (delta.gt(numericConstants_1.ZERO)) {
|
|
163
|
+
tokenDepositAmount = tokenDepositAmount.add(delta);
|
|
164
|
+
}
|
|
165
|
+
else if (delta.lt(numericConstants_1.ZERO)) {
|
|
166
|
+
tokenBorrowAmount = tokenBorrowAmount.add(delta.abs());
|
|
167
|
+
}
|
|
162
168
|
let utilization;
|
|
163
169
|
if (tokenBorrowAmount.eq(numericConstants_1.ZERO) && tokenDepositAmount.eq(numericConstants_1.ZERO)) {
|
|
164
170
|
utilization = numericConstants_1.ZERO;
|
|
@@ -216,8 +222,8 @@ function calculateSpotMarketBorrowCapacity(spotMarketAccount, targetBorrowRate)
|
|
|
216
222
|
}
|
|
217
223
|
}
|
|
218
224
|
exports.calculateSpotMarketBorrowCapacity = calculateSpotMarketBorrowCapacity;
|
|
219
|
-
function calculateInterestRate(bank) {
|
|
220
|
-
const utilization = calculateUtilization(bank);
|
|
225
|
+
function calculateInterestRate(bank, delta = numericConstants_1.ZERO) {
|
|
226
|
+
const utilization = calculateUtilization(bank, delta);
|
|
221
227
|
let interestRate;
|
|
222
228
|
if (utilization.gt(new anchor_1.BN(bank.optimalUtilization))) {
|
|
223
229
|
const surplusUtilization = utilization.sub(new anchor_1.BN(bank.optimalUtilization));
|
package/package.json
CHANGED
package/src/idl/drift.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -46,6 +46,7 @@ export * from './math/orders';
|
|
|
46
46
|
export * from './math/repeg';
|
|
47
47
|
export * from './math/margin';
|
|
48
48
|
export * from './math/insurance';
|
|
49
|
+
export * from './math/superStake';
|
|
49
50
|
export * from './marinade';
|
|
50
51
|
export * from './orderParams';
|
|
51
52
|
export * from './slot/SlotSubscriber';
|
package/src/math/spotBalance.ts
CHANGED
|
@@ -236,18 +236,27 @@ export function calculateLiabilityWeight(
|
|
|
236
236
|
return liabilityWeight;
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
export function calculateUtilization(
|
|
240
|
-
|
|
239
|
+
export function calculateUtilization(
|
|
240
|
+
bank: SpotMarketAccount,
|
|
241
|
+
delta = ZERO
|
|
242
|
+
): BN {
|
|
243
|
+
let tokenDepositAmount = getTokenAmount(
|
|
241
244
|
bank.depositBalance,
|
|
242
245
|
bank,
|
|
243
246
|
SpotBalanceType.DEPOSIT
|
|
244
247
|
);
|
|
245
|
-
|
|
248
|
+
let tokenBorrowAmount = getTokenAmount(
|
|
246
249
|
bank.borrowBalance,
|
|
247
250
|
bank,
|
|
248
251
|
SpotBalanceType.BORROW
|
|
249
252
|
);
|
|
250
253
|
|
|
254
|
+
if (delta.gt(ZERO)) {
|
|
255
|
+
tokenDepositAmount = tokenDepositAmount.add(delta);
|
|
256
|
+
} else if (delta.lt(ZERO)) {
|
|
257
|
+
tokenBorrowAmount = tokenBorrowAmount.add(delta.abs());
|
|
258
|
+
}
|
|
259
|
+
|
|
251
260
|
let utilization: BN;
|
|
252
261
|
if (tokenBorrowAmount.eq(ZERO) && tokenDepositAmount.eq(ZERO)) {
|
|
253
262
|
utilization = ZERO;
|
|
@@ -329,9 +338,11 @@ export function calculateSpotMarketBorrowCapacity(
|
|
|
329
338
|
}
|
|
330
339
|
}
|
|
331
340
|
|
|
332
|
-
export function calculateInterestRate(
|
|
333
|
-
|
|
334
|
-
|
|
341
|
+
export function calculateInterestRate(
|
|
342
|
+
bank: SpotMarketAccount,
|
|
343
|
+
delta = ZERO
|
|
344
|
+
): BN {
|
|
345
|
+
const utilization = calculateUtilization(bank, delta);
|
|
335
346
|
let interestRate: BN;
|
|
336
347
|
if (utilization.gt(new BN(bank.optimalUtilization))) {
|
|
337
348
|
const surplusUtilization = utilization.sub(new BN(bank.optimalUtilization));
|