@drift-labs/sdk 2.90.0-beta.2 → 2.90.0-beta.4

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.2
1
+ 2.90.0-beta.4
@@ -446,15 +446,14 @@ class AdminClient extends driftClient_1.DriftClient {
446
446
  const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket);
447
447
  return await this.program.instruction.depositIntoSpotMarketVault(amount, {
448
448
  accounts: {
449
- admin: this.isSubscribed
450
- ? this.getStateAccount().admin
451
- : this.wallet.publicKey,
449
+ admin: this.wallet.publicKey,
452
450
  state: await this.getStatePublicKey(),
453
451
  sourceVault,
454
452
  spotMarket: spotMarket.pubkey,
455
453
  spotMarketVault: spotMarket.vault,
456
454
  tokenProgram,
457
455
  },
456
+ remainingAccounts,
458
457
  });
459
458
  }
460
459
  async updateAdmin(admin) {
@@ -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.2",
3
+ "version": "2.90.0-beta.4",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -1030,15 +1030,14 @@ export class AdminClient extends DriftClient {
1030
1030
  const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket);
1031
1031
  return await this.program.instruction.depositIntoSpotMarketVault(amount, {
1032
1032
  accounts: {
1033
- admin: this.isSubscribed
1034
- ? this.getStateAccount().admin
1035
- : this.wallet.publicKey,
1033
+ admin: this.wallet.publicKey,
1036
1034
  state: await this.getStatePublicKey(),
1037
1035
  sourceVault,
1038
1036
  spotMarket: spotMarket.pubkey,
1039
1037
  spotMarketVault: spotMarket.vault,
1040
1038
  tokenProgram,
1041
1039
  },
1040
+ remainingAccounts,
1042
1041
  });
1043
1042
  }
1044
1043
 
@@ -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
  }