@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.
@@ -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(bank: SpotMarketAccount, delta = ZERO): BN {
433
- return calculateInterestRate(bank, delta);
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(