@drift-labs/sdk 2.95.0-beta.15 → 2.95.0-beta.16
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/math/spotBalance.d.ts +3 -3
- package/lib/math/spotBalance.js +7 -7
- package/package.json +1 -1
- package/src/math/spotBalance.ts +13 -7
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.95.0-beta.
|
|
1
|
+
2.95.0-beta.16
|
|
@@ -62,9 +62,9 @@ export declare function calculateSpotMarketBorrowCapacity(spotMarketAccount: Spo
|
|
|
62
62
|
totalCapacity: BN;
|
|
63
63
|
remainingCapacity: BN;
|
|
64
64
|
};
|
|
65
|
-
export declare function calculateInterestRate(bank: SpotMarketAccount, delta?: BN): BN;
|
|
66
|
-
export declare function calculateDepositRate(bank: SpotMarketAccount, delta?: BN): BN;
|
|
67
|
-
export declare function calculateBorrowRate(bank: SpotMarketAccount, delta?: BN): BN;
|
|
65
|
+
export declare function calculateInterestRate(bank: SpotMarketAccount, delta?: BN, currentUtilization?: BN): BN;
|
|
66
|
+
export declare function calculateDepositRate(bank: SpotMarketAccount, delta?: BN, currentUtilization?: BN): BN;
|
|
67
|
+
export declare function calculateBorrowRate(bank: SpotMarketAccount, delta?: BN, currentUtilization?: BN): BN;
|
|
68
68
|
export declare function calculateInterestAccumulated(bank: SpotMarketAccount, now: BN): {
|
|
69
69
|
borrowInterest: BN;
|
|
70
70
|
depositInterest: BN;
|
package/lib/math/spotBalance.js
CHANGED
|
@@ -246,8 +246,8 @@ function calculateSpotMarketBorrowCapacity(spotMarketAccount, targetBorrowRate)
|
|
|
246
246
|
return { totalCapacity, remainingCapacity };
|
|
247
247
|
}
|
|
248
248
|
exports.calculateSpotMarketBorrowCapacity = calculateSpotMarketBorrowCapacity;
|
|
249
|
-
function calculateInterestRate(bank, delta = numericConstants_1.ZERO) {
|
|
250
|
-
const utilization = calculateUtilization(bank, delta);
|
|
249
|
+
function calculateInterestRate(bank, delta = numericConstants_1.ZERO, currentUtilization = null) {
|
|
250
|
+
const utilization = currentUtilization || calculateUtilization(bank, delta);
|
|
251
251
|
let interestRate;
|
|
252
252
|
if (utilization.gt(new anchor_1.BN(bank.optimalUtilization))) {
|
|
253
253
|
const surplusUtilization = utilization.sub(new anchor_1.BN(bank.optimalUtilization));
|
|
@@ -269,11 +269,11 @@ function calculateInterestRate(bank, delta = numericConstants_1.ZERO) {
|
|
|
269
269
|
return anchor_1.BN.max(interestRate, new anchor_1.BN(bank.minBorrowRate).mul(numericConstants_2.PERCENTAGE_PRECISION.divn(200)));
|
|
270
270
|
}
|
|
271
271
|
exports.calculateInterestRate = calculateInterestRate;
|
|
272
|
-
function calculateDepositRate(bank, delta = numericConstants_1.ZERO) {
|
|
272
|
+
function calculateDepositRate(bank, delta = numericConstants_1.ZERO, currentUtilization = null) {
|
|
273
273
|
// positive delta => adding to deposit
|
|
274
274
|
// negative delta => adding to borrow
|
|
275
|
-
const utilization = calculateUtilization(bank, delta);
|
|
276
|
-
const borrowRate = calculateBorrowRate(bank, delta);
|
|
275
|
+
const utilization = currentUtilization || calculateUtilization(bank, delta);
|
|
276
|
+
const borrowRate = calculateBorrowRate(bank, delta, utilization);
|
|
277
277
|
const depositRate = borrowRate
|
|
278
278
|
.mul(numericConstants_2.PERCENTAGE_PRECISION.sub(new anchor_1.BN(bank.insuranceFund.totalFactor)))
|
|
279
279
|
.mul(utilization)
|
|
@@ -282,8 +282,8 @@ function calculateDepositRate(bank, delta = numericConstants_1.ZERO) {
|
|
|
282
282
|
return depositRate;
|
|
283
283
|
}
|
|
284
284
|
exports.calculateDepositRate = calculateDepositRate;
|
|
285
|
-
function calculateBorrowRate(bank, delta = numericConstants_1.ZERO) {
|
|
286
|
-
return calculateInterestRate(bank, delta);
|
|
285
|
+
function calculateBorrowRate(bank, delta = numericConstants_1.ZERO, currentUtilization = null) {
|
|
286
|
+
return calculateInterestRate(bank, delta, currentUtilization);
|
|
287
287
|
}
|
|
288
288
|
exports.calculateBorrowRate = calculateBorrowRate;
|
|
289
289
|
function calculateInterestAccumulated(bank, now) {
|
package/package.json
CHANGED
package/src/math/spotBalance.ts
CHANGED
|
@@ -379,9 +379,10 @@ export function calculateSpotMarketBorrowCapacity(
|
|
|
379
379
|
|
|
380
380
|
export function calculateInterestRate(
|
|
381
381
|
bank: SpotMarketAccount,
|
|
382
|
-
delta = ZERO
|
|
382
|
+
delta = ZERO,
|
|
383
|
+
currentUtilization: BN = null
|
|
383
384
|
): BN {
|
|
384
|
-
const utilization = calculateUtilization(bank, delta);
|
|
385
|
+
const utilization = currentUtilization || calculateUtilization(bank, delta);
|
|
385
386
|
let interestRate: BN;
|
|
386
387
|
if (utilization.gt(new BN(bank.optimalUtilization))) {
|
|
387
388
|
const surplusUtilization = utilization.sub(new BN(bank.optimalUtilization));
|
|
@@ -414,13 +415,14 @@ export function calculateInterestRate(
|
|
|
414
415
|
|
|
415
416
|
export function calculateDepositRate(
|
|
416
417
|
bank: SpotMarketAccount,
|
|
417
|
-
delta = ZERO
|
|
418
|
+
delta = ZERO,
|
|
419
|
+
currentUtilization: BN = null
|
|
418
420
|
): BN {
|
|
419
421
|
// positive delta => adding to deposit
|
|
420
422
|
// negative delta => adding to borrow
|
|
421
423
|
|
|
422
|
-
const utilization = calculateUtilization(bank, delta);
|
|
423
|
-
const borrowRate = calculateBorrowRate(bank, delta);
|
|
424
|
+
const utilization = currentUtilization || calculateUtilization(bank, delta);
|
|
425
|
+
const borrowRate = calculateBorrowRate(bank, delta, utilization);
|
|
424
426
|
const depositRate = borrowRate
|
|
425
427
|
.mul(PERCENTAGE_PRECISION.sub(new BN(bank.insuranceFund.totalFactor)))
|
|
426
428
|
.mul(utilization)
|
|
@@ -429,8 +431,12 @@ export function calculateDepositRate(
|
|
|
429
431
|
return depositRate;
|
|
430
432
|
}
|
|
431
433
|
|
|
432
|
-
export function calculateBorrowRate(
|
|
433
|
-
|
|
434
|
+
export function calculateBorrowRate(
|
|
435
|
+
bank: SpotMarketAccount,
|
|
436
|
+
delta = ZERO,
|
|
437
|
+
currentUtilization: BN = null
|
|
438
|
+
): BN {
|
|
439
|
+
return calculateInterestRate(bank, delta, currentUtilization);
|
|
434
440
|
}
|
|
435
441
|
|
|
436
442
|
export function calculateInterestAccumulated(
|