@drift-labs/sdk 2.95.0-beta.8 → 2.96.0-beta.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/VERSION +1 -1
- package/lib/accounts/pollingDriftClientAccountSubscriber.d.ts +3 -1
- package/lib/accounts/pollingDriftClientAccountSubscriber.js +14 -4
- package/lib/accounts/types.d.ts +1 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +8 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.js +70 -8
- package/lib/addresses/pda.d.ts +2 -0
- package/lib/addresses/pda.js +15 -1
- package/lib/config.d.ts +3 -0
- package/lib/config.js +2 -0
- package/lib/constants/spotMarkets.js +10 -0
- package/lib/driftClient.js +6 -2
- package/lib/events/parse.d.ts +4 -0
- package/lib/events/parse.js +10 -3
- package/lib/idl/drift.json +9 -4
- package/lib/math/insurance.d.ts +3 -1
- package/lib/math/insurance.js +31 -1
- package/lib/math/spotBalance.d.ts +3 -3
- package/lib/math/spotBalance.js +7 -7
- package/package.json +1 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +17 -5
- package/src/accounts/types.ts +1 -1
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +132 -14
- package/src/addresses/pda.ts +26 -0
- package/src/config.ts +8 -0
- package/src/constants/spotMarkets.ts +11 -0
- package/src/driftClient.ts +11 -2
- package/src/events/parse.ts +12 -1
- package/src/idl/drift.json +9 -4
- package/src/math/insurance.ts +48 -2
- package/src/math/spotBalance.ts +13 -7
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(
|