@carrot-protocol/clend-rpc 0.1.45-fl-signer1-dev-9b2343b → 0.1.46-support-sol-dev-a4e5ebf

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/dist/rpc.js CHANGED
@@ -110,7 +110,7 @@ class ClendClient {
110
110
  microLamports: this.cuFeeInMicroLamports,
111
111
  });
112
112
  const cuLimitIx = anchor_1.web3.ComputeBudgetProgram.setComputeUnitLimit({
113
- units: 500000,
113
+ units: 800000,
114
114
  });
115
115
  const { blockhash, lastValidBlockHeight } = await this.connection.getLatestBlockhash({
116
116
  commitment: "confirmed",
@@ -528,8 +528,8 @@ class ClendClient {
528
528
  const tokenProgram = (0, utils_1.getTokenProgramForMint)(bankData.mint);
529
529
  // Derive the associated token account for the signer
530
530
  const signerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, this.address(), true, tokenProgram);
531
- const ix = await this.instructions.deposit(group, clendAccount, this.address(), bank, bankData.mint, bankData.defaultOracle, signerTokenAccount, tokenProgram, amount, false);
532
- return this.send([ix]);
531
+ const ixns = await this.instructions.deposit(group, clendAccount, this.address(), bank, bankData.mint, bankData.defaultOracle, signerTokenAccount, tokenProgram, amount, false);
532
+ return this.send(ixns);
533
533
  }
534
534
  async withdraw(clendAccount, mint, amount, withdrawAll = null) {
535
535
  const clendAccountData = await this.getClendAccount(clendAccount);
@@ -551,8 +551,8 @@ class ClendClient {
551
551
  activeBankData.push(bankData);
552
552
  }
553
553
  const remainingAccounts = (0, utils_1.getClendAccountRemainingAccounts)(activeBankData);
554
- const ix = await this.instructions.withdraw(group, clendAccount, this.address(), bank, mint, destinationTokenAccount, tokenProgram, amount, withdrawAll, remainingAccounts);
555
- return this.send([ix]);
554
+ const ixns = await this.instructions.withdraw(group, clendAccount, this.address(), bank, mint, destinationTokenAccount, tokenProgram, amount, withdrawAll, remainingAccounts);
555
+ return this.send(ixns);
556
556
  }
557
557
  async borrow(clendAccount, mint, amount) {
558
558
  const clendAccountData = await this.getClendAccount(clendAccount);
@@ -579,8 +579,8 @@ class ClendClient {
579
579
  activeBankData.push(bankData);
580
580
  }
581
581
  const remainingAccounts = (0, utils_1.getClendAccountRemainingAccounts)(activeBankData);
582
- const ix = await this.instructions.borrow(clendAccountData.group, clendAccount, this.address(), bank, bankData.mint, destinationTokenAccount, tokenProgram, amount, remainingAccounts);
583
- return this.send([createDestinationTokenAccountIx, ix]);
582
+ const ixns = await this.instructions.borrow(clendAccountData.group, clendAccount, this.address(), bank, bankData.mint, destinationTokenAccount, tokenProgram, amount, remainingAccounts);
583
+ return this.send([createDestinationTokenAccountIx, ...ixns]);
584
584
  }
585
585
  async repay(clendAccount, mint, amount, repayAll, repayUpToAmount) {
586
586
  const clendAccountData = await this.getClendAccount(clendAccount);
@@ -601,8 +601,8 @@ class ClendClient {
601
601
  activeBankData.push(bankData);
602
602
  }
603
603
  const remainingAccounts = (0, utils_1.getClendAccountRemainingAccounts)(activeBankData);
604
- const ix = await this.instructions.repay(clendAccountData.group, clendAccount, this.address(), bank, bankData.mint, userTokenAccount, tokenProgram, amount, repayAll, repayUpToAmount, remainingAccounts);
605
- return this.send([ix]);
604
+ const ixns = await this.instructions.repay(clendAccountData.group, clendAccount, this.address(), bank, bankData.mint, userTokenAccount, tokenProgram, amount, repayAll, repayUpToAmount, remainingAccounts);
605
+ return this.send(ixns);
606
606
  }
607
607
  async editGlobalFeeState(groups, newGlobalFeeWallet, newBankInitFlatSolFee, newProgramFeeFixed, newProgramFeeRate) {
608
608
  const currentFeeState = await this.getFeeState();
@@ -655,7 +655,7 @@ class ClendClient {
655
655
  return this.send([ix]);
656
656
  }
657
657
  async liquidateClendAccountWithFlashLoan(liquidatorClendAccount, liquidateeClendAccount, assetBankData, liabBankData, targetOnChainMaintenanceHealthValue, slippageBps, marginfiLiabFlashLoanBank, liquidatorMarginfiAccount, additionalIxnCount, // used to calculate the end flash loan index
658
- swapperOverride) {
658
+ swapperOverride, additionalLuts = []) {
659
659
  // create instructions
660
660
  const result = await this.getLiquidateClendAccountIxns(liquidatorClendAccount, liquidateeClendAccount, assetBankData, liabBankData, targetOnChainMaintenanceHealthValue, slippageBps, swapperOverride);
661
661
  if (!result) {
@@ -688,15 +688,15 @@ class ClendClient {
688
688
  repayIx,
689
689
  endFlashLoanIx,
690
690
  ];
691
- return this.send(ixns, [], luts);
691
+ return this.send(ixns, [], [...luts, ...additionalLuts]);
692
692
  }
693
- async liquidateClendAccount(liquidatorClendAccount, liquidateeClendAccount, assetBankData, liabBankData, targetOnChainMaintenanceHealthValue, slippageBps, swapperOverride) {
693
+ async liquidateClendAccount(liquidatorClendAccount, liquidateeClendAccount, assetBankData, liabBankData, targetOnChainMaintenanceHealthValue, slippageBps, swapperOverride, additionalLuts = []) {
694
694
  const result = await this.getLiquidateClendAccountIxns(liquidatorClendAccount, liquidateeClendAccount, assetBankData, liabBankData, targetOnChainMaintenanceHealthValue, slippageBps, swapperOverride);
695
695
  if (!result) {
696
696
  return;
697
697
  }
698
698
  const { ixns, luts, depositAmount: _depositAmount } = result;
699
- return this.send(ixns, [], luts);
699
+ return this.send(ixns, [], [...luts, ...additionalLuts]);
700
700
  }
701
701
  /**
702
702
  * Creates instructions to liquidate an unhealthy Clend account.
@@ -820,10 +820,6 @@ class ClendClient {
820
820
  });
821
821
  const liabilityMintTokenProgram = (0, utils_1.getTokenProgramForMint)(liabBankData.mint);
822
822
  const assetTokenProgram = (0, utils_1.getTokenProgramForMint)(assetBankData.mint);
823
- const remainingAccounts = (0, utils_1.getClendAccountRemainingAccounts)([
824
- liabBankData,
825
- assetBankData,
826
- ]);
827
823
  const liquidatorLiabilityAta = (0, spl_token_1.getAssociatedTokenAddressSync)(liabBankData.mint, liquidatorClendAccount.authority, true, liabilityMintTokenProgram);
828
824
  // calcualte amount of liability tokens to deposit into the liquidator clend account
829
825
  const calculatedAssetAmountValue = (0, clend_common_1.calculateWeightedValue)(calculatedAssetAmountUi, assetPrice, 1);
@@ -831,15 +827,19 @@ class ClendClient {
831
827
  utils_1.logger.info(`liability token deposit amount calculated`, {
832
828
  depositAmount: depositAmount.toString(10),
833
829
  });
834
- const depositIx = await this.instructions.deposit(liabBankData.group, liquidatorClendAccount.key, liquidatorClendAccount.authority, liabBankData.key, liabBankData.mint, liabBankData.defaultOracle, liquidatorLiabilityAta, liabilityMintTokenProgram, depositAmount, true);
835
- const liquidationRemainingAccounts = (0, utils_1.getLiquidateClendAccountRemainingAccounts)(liquidateeClendAccount, liquidatorClendAccount, liabBankData.mint, liabilityMintTokenProgram, assetBankData.mint, this.mintOracleMapping);
830
+ const depositIxns = await this.instructions.deposit(liabBankData.group, liquidatorClendAccount.key, liquidatorClendAccount.authority, liabBankData.key, liabBankData.mint, liabBankData.defaultOracle, liquidatorLiabilityAta, liabilityMintTokenProgram, depositAmount, true);
831
+ const liquidationRemainingAccounts = (0, utils_1.getLiquidateClendAccountRemainingAccounts)(liquidateeClendAccount, liquidatorClendAccount, liabBankData.mint, liabilityMintTokenProgram, assetBankData.mint, this.mintOracleMapping, liabBankData.key);
836
832
  // create liquidation instruction
837
833
  const liquidationIx = await this.instructions.liquidateClendAccount(assetBankData.group, liquidatorClendAccount.authority, assetBankData.key, liabBankData.key, liquidatorClendAccount.key, liquidateeClendAccount.key, liabilityMintTokenProgram, liquidationRemainingAccounts, finalAssetAmount);
838
834
  const liquidatorAssetAta = (0, spl_token_1.getAssociatedTokenAddressSync)(assetBankData.mint, liquidatorClendAccount.authority, true, assetTokenProgram);
835
+ const withdrawRemainingAccounts = (0, utils_1.getClendAccountRemainingAccounts)([
836
+ assetBankData,
837
+ liabBankData,
838
+ ]);
839
839
  // careful not to withdraw everything we need to keep an "active"
840
840
  // just withdraw the liquidated amount
841
841
  // balance for the asset
842
- const withdrawAssetIx = await this.instructions.withdraw(assetBankData.group, liquidatorClendAccount.key, liquidatorClendAccount.authority, assetBankData.key, assetBankData.mint, liquidatorAssetAta, assetTokenProgram, finalAssetAmount, false, remainingAccounts);
842
+ const withdrawAssetIxns = await this.instructions.withdraw(assetBankData.group, liquidatorClendAccount.key, liquidatorClendAccount.authority, assetBankData.key, assetBankData.mint, liquidatorAssetAta, assetTokenProgram, finalAssetAmount, false, withdrawRemainingAccounts);
843
843
  // get a swap quote
844
844
  const swapQuote = await activeSwapper.getQuote({
845
845
  payer: liquidatorClendAccount.authority,
@@ -860,9 +860,9 @@ class ClendClient {
860
860
  // 5. Get Swap Instructions from Jupiter
861
861
  const swapIxns = await activeSwapper.getSwapIxns(swapQuote);
862
862
  const ixns = [
863
- depositIx, // deposit liability mint into liquidator clend account
863
+ ...depositIxns, // deposit liability mint into liquidator clend account
864
864
  liquidationIx, // liquidate liquidatee clend account
865
- withdrawAssetIx, // withdraw liquidated asset from liquidator clend account
865
+ ...withdrawAssetIxns, // withdraw liquidated asset from liquidator clend account
866
866
  ...swapIxns.ixns, // swap liquidated asset for liability mint
867
867
  ];
868
868
  return { ixns, luts: swapIxns.luts, depositAmount };
@@ -936,7 +936,7 @@ class ClendClient {
936
936
  return this.send(ixns, additionalSigners, luts);
937
937
  }
938
938
  async getDepositLeverageFromDebtIxns(clendGroup, user, clendAccount, collateralMint, debtMint, debtMintDecimals, collateralMintDecimals, initialUserDebtContributionForSwap, finalLoopBorrowAmount, slippageBps, additionalIxnCount, // For JIT liquidity, etc.
939
- swapperOverride, flashLoanSignerOverride) {
939
+ swapperOverride) {
940
940
  // override swapper if provided
941
941
  let activeSwapper = this.swapper;
942
942
  if (swapperOverride) {
@@ -1009,7 +1009,7 @@ class ClendClient {
1009
1009
  // 5. Get Swap Instructions from Jupiter
1010
1010
  const swapIxns = await activeSwapper.getSwapIxns(swapQuote);
1011
1011
  // 6. Create Clend Protocol Instructions
1012
- const borrowIx = await this.instructions.borrow(clendGroup, clendAccount, // clendAccount is guaranteed to be non-null here
1012
+ const borrowIxns = await this.instructions.borrow(clendGroup, clendAccount, // clendAccount is guaranteed to be non-null here
1013
1013
  user, debtBank, debtMint, userDebtAta, // Borrow into user's ATA
1014
1014
  debtTokenProgram, finalLoopBorrowAmount, // Borrow only the protocol's contribution
1015
1015
  remainingAccounts);
@@ -1023,15 +1023,15 @@ class ClendClient {
1023
1023
  if (!collateralBankData) {
1024
1024
  throw new Error(`Collateral bank not found: ${collateralBank.toString()}`);
1025
1025
  }
1026
- const depositIx = await this.instructions.deposit(clendGroup, clendAccount, user, collateralBank, collateralMint, collateralBankData.defaultOracle, userCollateralAta, // Deposit from user's JLP ATA (which received swap output)
1026
+ const depositIxns = await this.instructions.deposit(clendGroup, clendAccount, user, collateralBank, collateralMint, collateralBankData.defaultOracle, userCollateralAta, // Deposit from user's JLP ATA (which received swap output)
1027
1027
  collateralTokenProgram, optimisticCollateralFromQuote, // Deposit the optimistic amount from the quote
1028
1028
  true);
1029
1029
  // 7. Assemble instructions for the flash loan
1030
1030
  // Order: Borrow additional debt, then swap combined debt, then deposit resulting collateral
1031
1031
  const ixnsWithoutFlashLoan = [
1032
- borrowIx,
1032
+ ...borrowIxns,
1033
1033
  ...swapIxns.ixns,
1034
- depositIx,
1034
+ ...depositIxns,
1035
1035
  ];
1036
1036
  // 8. Wrap in Flash Loan
1037
1037
  const { addInitClendAccountIncrement, initClendAccountIxns } = initClendAccountIx
@@ -1048,9 +1048,7 @@ class ClendClient {
1048
1048
  startFlashLoanIncrement +
1049
1049
  additionalIxnCount);
1050
1050
  const remainingAccountsForFlashLoan = (0, utils_1.getClendAccountRemainingAccounts)(activeBankData);
1051
- // used for clend accounts which are owned by PDAs
1052
- const flashLoanSigner = flashLoanSignerOverride || user;
1053
- const { beginFlashLoanIx, endFlashLoanIx } = await this.instructions.createFlashLoanInstructions(clendAccount, flashLoanSigner, endIndex, remainingAccountsForFlashLoan);
1051
+ const { beginFlashLoanIx, endFlashLoanIx } = await this.instructions.createFlashLoanInstructions(clendAccount, user, endIndex, remainingAccountsForFlashLoan);
1054
1052
  // Final instruction sequence
1055
1053
  const ixns = [
1056
1054
  ...initClendAccountIxns,
@@ -1066,7 +1064,7 @@ class ClendClient {
1066
1064
  };
1067
1065
  }
1068
1066
  async getDepositLeverageFromCollateralIxns(clendGroup, user, clendAccount, collateralMint, debtMint, debtMintDecimals, collateralMintDecimals, borrowAmount, depositAmount, slippageBps, additionalIxnCount, // used to correctly offset the flash loan index
1069
- swapperOverride, flashLoanSignerOverride) {
1067
+ swapperOverride) {
1070
1068
  // override swapper if provided
1071
1069
  let activeSwapper = this.swapper;
1072
1070
  if (swapperOverride) {
@@ -1139,18 +1137,18 @@ class ClendClient {
1139
1137
  const userDebtAta = (0, spl_token_1.getAssociatedTokenAddressSync)(debtMint, user, true, debtTokenProgram);
1140
1138
  const userCollateralAta = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralMint, user, true, collateralTokenProgram);
1141
1139
  // Create transaction instructions in correct order
1142
- const borrowIx = await this.instructions.borrow(clendGroup, clendAccount, user, debtBank, debtMint, userDebtAta, debtTokenProgram, borrowAmount, remainingAccounts);
1140
+ const borrowIxns = await this.instructions.borrow(clendGroup, clendAccount, user, debtBank, debtMint, userDebtAta, debtTokenProgram, borrowAmount, remainingAccounts);
1143
1141
  const collateralBankData = activeBankData.find((bank) => bank.key.equals(collateralBank));
1144
1142
  if (!collateralBankData) {
1145
1143
  throw new Error(`Collateral bank not found: ${collateralBank.toString()}`);
1146
1144
  }
1147
- const depositIx = await this.instructions.deposit(clendGroup, clendAccount, user, collateralBank, collateralMint, collateralBankData.defaultOracle, userCollateralAta, collateralTokenProgram, totalCollateralAmount, // this is optimistic amount from the quote
1145
+ const depositIxns = await this.instructions.deposit(clendGroup, clendAccount, user, collateralBank, collateralMint, collateralBankData.defaultOracle, userCollateralAta, collateralTokenProgram, totalCollateralAmount, // this is optimistic amount from the quote
1148
1146
  true);
1149
1147
  // add lending and swap instructions
1150
1148
  const ixnsWithoutFlashLoan = [
1151
- borrowIx,
1149
+ ...borrowIxns,
1152
1150
  ...swapIxns.ixns,
1153
- depositIx,
1151
+ ...depositIxns,
1154
1152
  ];
1155
1153
  // If the clend account is being created, we need to add 1 to the endIndex
1156
1154
  const { addInitClendAccountIncrement, initClendAccountIxns } = initClendAccountIx
@@ -1167,8 +1165,6 @@ class ClendClient {
1167
1165
  startFlashLoanIncrement +
1168
1166
  additionalIxnCount);
1169
1167
  const remainingAccountsForFlashLoan = (0, utils_1.getClendAccountRemainingAccounts)(activeBankData);
1170
- // used for clend accounts which are owned by PDAs
1171
- const flashLoanSigner = flashLoanSignerOverride || user;
1172
1168
  const { beginFlashLoanIx, endFlashLoanIx } = await this.instructions.createFlashLoanInstructions(clendAccount, user, endIndex, remainingAccountsForFlashLoan);
1173
1169
  const ixns = [
1174
1170
  ...initClendAccountIxns,
@@ -1373,7 +1369,7 @@ class ClendClient {
1373
1369
  // Send transaction
1374
1370
  return this.send(ixns, [], luts);
1375
1371
  }
1376
- async getWithdrawLeverageDebtIxns(clendGroup, clendAccount, collateralMint, debtMint, collateralDecimals, debtDecimals, withdrawAll, debtToRepay, collateralToWithdraw, slippageBps, additionalIxnCount, swapperOverride, flashLoanSignerOverride) {
1372
+ async getWithdrawLeverageDebtIxns(clendGroup, clendAccount, collateralMint, debtMint, collateralDecimals, debtDecimals, withdrawAll, debtToRepay, collateralToWithdraw, slippageBps, additionalIxnCount, swapperOverride) {
1377
1373
  // override swapper if provided
1378
1374
  let activeSwapper = this.swapper;
1379
1375
  if (swapperOverride) {
@@ -1418,7 +1414,7 @@ class ClendClient {
1418
1414
  const userCollateralAta = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralMint, clendAccountData.authority, true, collateralTokenProgram);
1419
1415
  const userDebtAta = (0, spl_token_1.getAssociatedTokenAddressSync)(debtMint, clendAccountData.authority, true, debtTokenProgram);
1420
1416
  // Create withdraw instruction: Withdraw the total collateral calculated by the params function
1421
- const withdrawIx = await this.instructions.withdraw(clendGroup, clendAccount, clendAccountData.authority, collateralBank, collateralMint, userCollateralAta, collateralTokenProgram, collateralToWithdraw, withdrawAll, remainingAccounts);
1417
+ const withdrawIxns = await this.instructions.withdraw(clendGroup, clendAccount, clendAccountData.authority, collateralBank, collateralMint, userCollateralAta, collateralTokenProgram, collateralToWithdraw, withdrawAll, remainingAccounts);
1422
1418
  // if withdrawAll == true we need to make sure we withdraw emissions from both banks before withdrawing all the bank tokens
1423
1419
  const emissionsIxns = [];
1424
1420
  if (withdrawAll) {
@@ -1452,22 +1448,20 @@ class ClendClient {
1452
1448
  }
1453
1449
  }
1454
1450
  // Create repay instruction: Repay the debt portion using the guaranteed swap output
1455
- const repayIx = await this.instructions.repay(clendGroup, clendAccount, clendAccountData.authority, debtBank, debtMint, userDebtAta, debtTokenProgram, finalDebtToRepay, // Use the slippage-protected amount from the final quote
1451
+ const repayIxns = await this.instructions.repay(clendGroup, clendAccount, clendAccountData.authority, debtBank, debtMint, userDebtAta, debtTokenProgram, finalDebtToRepay, // Use the slippage-protected amount from the final quote
1456
1452
  withdrawAll, true, remainingAccounts);
1457
1453
  // Assemble instructions
1458
1454
  const ixnsWithoutFlashLoan = [
1459
1455
  ...emissionsIxns,
1460
- withdrawIx,
1456
+ ...withdrawIxns,
1461
1457
  ...swapIxns.ixns,
1462
- repayIx,
1458
+ ...repayIxns,
1463
1459
  ];
1464
1460
  // Flash Loan Wrapping
1465
1461
  const cuIxns = 2;
1466
1462
  const endIndex = new anchor_1.BN(cuIxns + ixnsWithoutFlashLoan.length + 1 + additionalIxnCount);
1467
1463
  const remainingAccountsForFlashLoan = (0, utils_1.getClendAccountRemainingAccounts)(activeBankData);
1468
- // used for clend accounts which are owned by PDAs
1469
- const flashLoanSigner = flashLoanSignerOverride || clendAccountData.authority;
1470
- const { beginFlashLoanIx, endFlashLoanIx } = await this.instructions.createFlashLoanInstructions(clendAccount, flashLoanSigner, endIndex, remainingAccountsForFlashLoan);
1464
+ const { beginFlashLoanIx, endFlashLoanIx } = await this.instructions.createFlashLoanInstructions(clendAccount, clendAccountData.authority, endIndex, remainingAccountsForFlashLoan);
1471
1465
  const instructions = [
1472
1466
  beginFlashLoanIx,
1473
1467
  ...ixnsWithoutFlashLoan,
@@ -1548,7 +1542,7 @@ class ClendClient {
1548
1542
  debtBankData,
1549
1543
  };
1550
1544
  }
1551
- async getWithdrawLeverageCollateralIxns(clendGroup, clendAccount, collateralMint, debtMint, collateralDecimals, debtDecimals, withdrawAll, collateralToWithdraw, desiredNetCollateralToReceive, debtToRepay, slippageBps, additionalIxnCount, swapperOverride, flashLoanSignerOverride) {
1545
+ async getWithdrawLeverageCollateralIxns(clendGroup, clendAccount, collateralMint, debtMint, collateralDecimals, debtDecimals, withdrawAll, collateralToWithdraw, desiredNetCollateralToReceive, debtToRepay, slippageBps, additionalIxnCount, swapperOverride) {
1552
1546
  // override swapper if provided
1553
1547
  let activeSwapper = this.swapper;
1554
1548
  if (swapperOverride) {
@@ -1630,7 +1624,7 @@ class ClendClient {
1630
1624
  const userCollateralAta = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralMint, clendAccountData.authority, true, collateralTokenProgram);
1631
1625
  const userDebtAta = (0, spl_token_1.getAssociatedTokenAddressSync)(debtMint, clendAccountData.authority, true, debtTokenProgram);
1632
1626
  utils_1.logger.info(`begin crafting ixns`);
1633
- const withdrawIx = await this.instructions.withdraw(clendGroup, clendAccount, clendAccountData.authority, collateralBank, collateralMint, userCollateralAta, collateralTokenProgram, collateralToWithdraw, withdrawAll, remainingAccounts);
1627
+ const withdrawIxns = await this.instructions.withdraw(clendGroup, clendAccount, clendAccountData.authority, collateralBank, collateralMint, userCollateralAta, collateralTokenProgram, collateralToWithdraw, withdrawAll, remainingAccounts);
1634
1628
  utils_1.logger.info(`withdrawIx set`);
1635
1629
  // if withdrawAll == true we need to make sure we withdraw emissions from both banks before withdrawing all the bank tokens
1636
1630
  const emissionsIxns = [];
@@ -1665,21 +1659,19 @@ class ClendClient {
1665
1659
  }
1666
1660
  }
1667
1661
  // Create repay instruction with the amount from the 'ExactIn' swap
1668
- const repayIx = await this.instructions.repay(clendGroup, clendAccount, clendAccountData.authority, debtBank, debtMint, userDebtAta, debtTokenProgram, finalDebtToRepay, withdrawAll, true, remainingAccounts);
1662
+ const repayIxns = await this.instructions.repay(clendGroup, clendAccount, clendAccountData.authority, debtBank, debtMint, userDebtAta, debtTokenProgram, finalDebtToRepay, withdrawAll, true, remainingAccounts);
1669
1663
  utils_1.logger.info(`repayIx set`);
1670
1664
  const ixnsWithoutFlashLoan = [
1671
1665
  ...emissionsIxns,
1672
- withdrawIx,
1666
+ ...withdrawIxns,
1673
1667
  ...swapIxns.ixns,
1674
- repayIx,
1668
+ ...repayIxns,
1675
1669
  ];
1676
1670
  utils_1.logger.info(`ixnsWithoutFlashLoan set`);
1677
1671
  const cuIxns = 2;
1678
1672
  const endIndex = new anchor_1.BN(cuIxns + ixnsWithoutFlashLoan.length + 1 + additionalIxnCount);
1679
1673
  const remainingAccountsForFlashLoan = (0, utils_1.getClendAccountRemainingAccounts)(activeBankData);
1680
- // used for clend accounts which are owned by PDAs
1681
- const flashLoanSigner = flashLoanSignerOverride || clendAccountData.authority;
1682
- const { beginFlashLoanIx, endFlashLoanIx } = await this.instructions.createFlashLoanInstructions(clendAccount, flashLoanSigner, endIndex, remainingAccountsForFlashLoan);
1674
+ const { beginFlashLoanIx, endFlashLoanIx } = await this.instructions.createFlashLoanInstructions(clendAccount, clendAccountData.authority, endIndex, remainingAccountsForFlashLoan);
1683
1675
  const instructions = [
1684
1676
  beginFlashLoanIx,
1685
1677
  ...ixnsWithoutFlashLoan,
@@ -1984,7 +1976,7 @@ class ClendClient {
1984
1976
  */
1985
1977
  async getAdjustLeverageIxns(clendGroup, clendAccount, user, debtBankData, collateralBankData, isIncrease, finalDebtDeltaUi, // Use the final adjusted value from getAdjustLeverageParams
1986
1978
  finalCollateralDeltaUi, // Use the final adjusted value from getAdjustLeverageParams
1987
- slippageBps, additionalIxnCount, swapperOverride, flashLoanSignerOverride) {
1979
+ slippageBps, additionalIxnCount, swapperOverride) {
1988
1980
  // override swapper if provided
1989
1981
  let activeSwapper = this.swapper;
1990
1982
  if (swapperOverride) {
@@ -2031,10 +2023,10 @@ class ClendClient {
2031
2023
  swapMode: "ExactIn",
2032
2024
  });
2033
2025
  const swapIxns = await activeSwapper.getSwapIxns(swapQuote);
2034
- const borrowIx = await this.instructions.borrow(clendGroup, clendAccount, user, debtBankData.key, debtBankData.mint, userDebtAta, debtTokenProgram, additionalDebtAmount, remainingAccounts);
2026
+ const borrowIxns = await this.instructions.borrow(clendGroup, clendAccount, user, debtBankData.key, debtBankData.mint, userDebtAta, debtTokenProgram, additionalDebtAmount, remainingAccounts);
2035
2027
  const additionalCollateralAmount = swapQuote.outAmount;
2036
- const depositIx = await this.instructions.deposit(clendGroup, clendAccount, user, collateralBankData.key, collateralBankData.mint, collateralBankData.defaultOracle, userCollateralAta, collateralTokenProgram, additionalCollateralAmount, true);
2037
- instructions.push(borrowIx, ...swapIxns.ixns, depositIx);
2028
+ const depositIxns = await this.instructions.deposit(clendGroup, clendAccount, user, collateralBankData.key, collateralBankData.mint, collateralBankData.defaultOracle, userCollateralAta, collateralTokenProgram, additionalCollateralAmount, true);
2029
+ instructions.push(...borrowIxns, ...swapIxns.ixns, ...depositIxns);
2038
2030
  swapLookupTables = swapIxns.luts;
2039
2031
  }
2040
2032
  else {
@@ -2058,23 +2050,21 @@ class ClendClient {
2058
2050
  const finalDebtToRepay = swapQuote.outAmount;
2059
2051
  const swapIxns = await activeSwapper.getSwapIxns(swapQuote);
2060
2052
  // Withdraw the calculated collateral needed for the swap
2061
- const withdrawIx = await this.instructions.withdraw(clendGroup, clendAccount, user, collateralBankData.key, collateralBankData.mint, userCollateralAta, collateralTokenProgram, collateralToWithdrawBN, false, // Not withdrawing all
2053
+ const withdrawIxns = await this.instructions.withdraw(clendGroup, clendAccount, user, collateralBankData.key, collateralBankData.mint, userCollateralAta, collateralTokenProgram, collateralToWithdrawBN, false, // Not withdrawing all
2062
2054
  remainingAccounts);
2063
2055
  // Repay the debt with the swap output
2064
- const repayIx = await this.instructions.repay(clendGroup, clendAccount, user, debtBankData.key, debtBankData.mint, userDebtAta, debtTokenProgram, finalDebtToRepay, // Use optimistic amount
2056
+ const repayIxns = await this.instructions.repay(clendGroup, clendAccount, user, debtBankData.key, debtBankData.mint, userDebtAta, debtTokenProgram, finalDebtToRepay, // Use optimistic amount
2065
2057
  false, // Not repaying all
2066
2058
  true, // Use the new repay_up_to_amount flag
2067
2059
  remainingAccounts);
2068
- instructions.push(withdrawIx, ...swapIxns.ixns, repayIx);
2060
+ instructions.push(...withdrawIxns, ...swapIxns.ixns, ...repayIxns);
2069
2061
  swapLookupTables = swapIxns.luts;
2070
2062
  }
2071
2063
  // --- Flash Loan Wrapping ---
2072
2064
  const cuIxns = 2;
2073
2065
  const endIndex = new anchor_1.BN(cuIxns + instructions.length + 1 + additionalIxnCount);
2074
2066
  const remainingAccountsForFlashLoan = (0, utils_1.getClendAccountRemainingAccounts)(activeBankData);
2075
- // used for clend accounts which are owned by PDAs
2076
- const flashLoanSigner = flashLoanSignerOverride || clendAccountData.authority;
2077
- const { beginFlashLoanIx, endFlashLoanIx } = await this.instructions.createFlashLoanInstructions(clendAccount, flashLoanSigner, endIndex, remainingAccountsForFlashLoan);
2067
+ const { beginFlashLoanIx, endFlashLoanIx } = await this.instructions.createFlashLoanInstructions(clendAccount, user, endIndex, remainingAccountsForFlashLoan);
2078
2068
  const finalInstructions = [
2079
2069
  beginFlashLoanIx,
2080
2070
  ...instructions,