@drift-labs/sdk 2.90.0-beta.1 → 2.90.0-beta.3

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 CHANGED
@@ -1 +1 @@
1
- 2.90.0-beta.1
1
+ 2.90.0-beta.3
@@ -346,10 +346,18 @@ function calculateWithdrawLimit(spotMarket, now) {
346
346
  const minDepositTokensTwap = depositTokenTwapLive.sub(anchor_1.BN.max(depositTokenTwapLive.div(new anchor_1.BN(4)), anchor_1.BN.min(spotMarket.withdrawGuardThreshold, depositTokenTwapLive)));
347
347
  const { minDepositTokensForUtilization, maxBorrowTokensForUtilization } = calculateTokenUtilizationLimits(marketDepositTokenAmount, marketBorrowTokenAmount, spotMarket);
348
348
  const minDepositTokens = anchor_1.BN.max(minDepositTokensForUtilization, minDepositTokensTwap);
349
- const maxBorrowTokens = anchor_1.BN.min(maxBorrowTokensForUtilization, maxBorrowTokensTwap);
349
+ let maxBorrowTokens = anchor_1.BN.min(maxBorrowTokensForUtilization, maxBorrowTokensTwap);
350
350
  const withdrawLimit = anchor_1.BN.max(marketDepositTokenAmount.sub(minDepositTokens), numericConstants_1.ZERO);
351
351
  let borrowLimit = maxBorrowTokens.sub(marketBorrowTokenAmount);
352
352
  borrowLimit = anchor_1.BN.min(borrowLimit, marketDepositTokenAmount.sub(marketBorrowTokenAmount));
353
+ if (spotMarket.maxTokenBorrowsFraction > 0) {
354
+ const maxTokenBorrowsByFraction = spotMarket.maxTokenDeposits
355
+ .mul(new anchor_1.BN(spotMarket.maxTokenBorrowsFraction))
356
+ .divn(10000);
357
+ const trueMaxBorrowTokensAvailable = maxTokenBorrowsByFraction.sub(marketBorrowTokenAmount);
358
+ maxBorrowTokens = anchor_1.BN.min(maxBorrowTokens, trueMaxBorrowTokensAvailable);
359
+ borrowLimit = anchor_1.BN.min(borrowLimit, maxBorrowTokens);
360
+ }
353
361
  if (withdrawLimit.eq(numericConstants_1.ZERO)) {
354
362
  borrowLimit = numericConstants_1.ZERO;
355
363
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.90.0-beta.1",
3
+ "version": "2.90.0-beta.3",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -44,7 +44,7 @@
44
44
  "@pythnetwork/pyth-solana-receiver": "^0.7.0",
45
45
  "@solana/spl-token": "0.3.7",
46
46
  "@solana/web3.js": "1.92.3",
47
- "@switchboard-xyz/on-demand": "^1.2.1",
47
+ "@switchboard-xyz/on-demand": "1.2.1",
48
48
  "anchor-bankrun": "^0.3.0",
49
49
  "rpc-websockets": "7.5.1",
50
50
  "solana-bankrun": "^0.3.0",
@@ -578,7 +578,7 @@ export function calculateWithdrawLimit(
578
578
  minDepositTokensTwap
579
579
  );
580
580
 
581
- const maxBorrowTokens = BN.min(
581
+ let maxBorrowTokens = BN.min(
582
582
  maxBorrowTokensForUtilization,
583
583
  maxBorrowTokensTwap
584
584
  );
@@ -589,11 +589,26 @@ export function calculateWithdrawLimit(
589
589
  );
590
590
 
591
591
  let borrowLimit = maxBorrowTokens.sub(marketBorrowTokenAmount);
592
+
592
593
  borrowLimit = BN.min(
593
594
  borrowLimit,
594
595
  marketDepositTokenAmount.sub(marketBorrowTokenAmount)
595
596
  );
596
597
 
598
+ if (spotMarket.maxTokenBorrowsFraction > 0) {
599
+ const maxTokenBorrowsByFraction = spotMarket.maxTokenDeposits
600
+ .mul(new BN(spotMarket.maxTokenBorrowsFraction))
601
+ .divn(10000);
602
+
603
+ const trueMaxBorrowTokensAvailable = maxTokenBorrowsByFraction.sub(
604
+ marketBorrowTokenAmount
605
+ );
606
+
607
+ maxBorrowTokens = BN.min(maxBorrowTokens, trueMaxBorrowTokensAvailable);
608
+
609
+ borrowLimit = BN.min(borrowLimit, maxBorrowTokens);
610
+ }
611
+
597
612
  if (withdrawLimit.eq(ZERO)) {
598
613
  borrowLimit = ZERO;
599
614
  }