@kamino-finance/klend-sdk 5.13.7 → 5.13.9

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.
Files changed (38) hide show
  1. package/dist/classes/manager.d.ts +17 -1
  2. package/dist/classes/manager.d.ts.map +1 -1
  3. package/dist/classes/manager.js +20 -0
  4. package/dist/classes/manager.js.map +1 -1
  5. package/dist/classes/obligation.d.ts +1 -0
  6. package/dist/classes/obligation.d.ts.map +1 -1
  7. package/dist/classes/obligation.js +7 -0
  8. package/dist/classes/obligation.js.map +1 -1
  9. package/dist/classes/vault.d.ts +17 -1
  10. package/dist/classes/vault.d.ts.map +1 -1
  11. package/dist/classes/vault.js +66 -0
  12. package/dist/classes/vault.js.map +1 -1
  13. package/dist/classes/vault_types.d.ts +4 -0
  14. package/dist/classes/vault_types.d.ts.map +1 -1
  15. package/dist/client_kamino_manager.d.ts.map +1 -1
  16. package/dist/client_kamino_manager.js +8 -0
  17. package/dist/client_kamino_manager.js.map +1 -1
  18. package/dist/lending_operations/repay_with_collateral_calcs.d.ts +3 -4
  19. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  20. package/dist/lending_operations/repay_with_collateral_calcs.js +36 -34
  21. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  22. package/dist/lending_operations/repay_with_collateral_operations.d.ts +3 -2
  23. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  24. package/dist/lending_operations/repay_with_collateral_operations.js +40 -30
  25. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  26. package/dist/utils/multisig.d.ts +11 -1
  27. package/dist/utils/multisig.d.ts.map +1 -1
  28. package/dist/utils/multisig.js +8 -5
  29. package/dist/utils/multisig.js.map +1 -1
  30. package/package.json +1 -1
  31. package/src/classes/manager.ts +31 -0
  32. package/src/classes/obligation.ts +10 -0
  33. package/src/classes/vault.ts +91 -0
  34. package/src/classes/vault_types.ts +5 -0
  35. package/src/client_kamino_manager.ts +9 -0
  36. package/src/lending_operations/repay_with_collateral_calcs.ts +56 -39
  37. package/src/lending_operations/repay_with_collateral_operations.ts +84 -33
  38. package/src/utils/multisig.ts +19 -5
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getMaxWithdrawLtvCheck = exports.MaxWithdrawLtvCheck = void 0;
7
7
  exports.getRepayWithCollSwapInputs = getRepayWithCollSwapInputs;
8
8
  exports.getRepayWithCollIxs = getRepayWithCollIxs;
9
+ exports.getMaxCollateralFromRepayAmount = getMaxCollateralFromRepayAmount;
9
10
  const classes_1 = require("../classes");
10
11
  const leverage_1 = require("../leverage");
11
12
  const utils_1 = require("../utils");
@@ -17,14 +18,8 @@ var MaxWithdrawLtvCheck;
17
18
  MaxWithdrawLtvCheck[MaxWithdrawLtvCheck["LIQUIDATION_THRESHOLD"] = 1] = "LIQUIDATION_THRESHOLD";
18
19
  })(MaxWithdrawLtvCheck || (exports.MaxWithdrawLtvCheck = MaxWithdrawLtvCheck = {}));
19
20
  async function getRepayWithCollSwapInputs({ collTokenMint, currentSlot, debtTokenMint, kaminoMarket, obligation, quoter, referrer, repayAmount, isClosingPosition, budgetAndPriorityFeeIxs, scopeRefreshConfig, useV2Ixs, }) {
20
- const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
21
- const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
22
- if (!collReserve) {
23
- throw new Error(`Collateral reserve with mint ${collTokenMint} not found in market ${kaminoMarket.getAddress()}`);
24
- }
25
- if (!debtReserve) {
26
- throw new Error(`Debt reserve with mint ${debtTokenMint} not found in market ${kaminoMarket.getAddress()}`);
27
- }
21
+ const collReserve = kaminoMarket.getExistingReserveByMint(collTokenMint);
22
+ const debtReserve = kaminoMarket.getExistingReserveByMint(debtTokenMint);
28
23
  const { repayAmountLamports, flashRepayAmountLamports, repayAmount: finalRepayAmount, } = (0, repay_with_collateral_calcs_1.calcRepayAmountWithSlippage)(kaminoMarket, debtReserve, currentSlot, obligation, repayAmount, referrer);
29
24
  const debtPosition = obligation.getBorrowByReserve(debtReserve.address);
30
25
  const collPosition = obligation.getDepositByReserve(collReserve.address);
@@ -34,15 +29,9 @@ async function getRepayWithCollSwapInputs({ collTokenMint, currentSlot, debtToke
34
29
  if (!collPosition) {
35
30
  throw new Error(`Collateral position not found for ${collReserve.stats.symbol} reserve ${collReserve.address} in obligation ${obligation.obligationAddress}`);
36
31
  }
37
- const { withdrawableCollLamports } = (0, repay_with_collateral_calcs_1.calcMaxWithdrawCollateral)(kaminoMarket, obligation, collReserve.address, debtReserve.address, repayAmountLamports);
38
- // sanity check: we have extra collateral to swap, but we want to ensure we don't quote for way more than needed and get a bad px
39
- const maxCollNeededFromOracle = finalRepayAmount
40
- .mul(debtReserve.getOracleMarketPrice())
41
- .div(collReserve.getOracleMarketPrice())
42
- .mul('1.1')
43
- .mul(collReserve.getMintFactor())
44
- .ceil();
45
- const inputAmountLamports = decimal_js_1.default.min(withdrawableCollLamports, maxCollNeededFromOracle);
32
+ const { maxWithdrawableCollLamports } = (0, repay_with_collateral_calcs_1.calcMaxWithdrawCollateral)(kaminoMarket, obligation, collReserve.address, debtReserve.address, repayAmountLamports);
33
+ const maxCollNeededFromOracle = getMaxCollateralFromRepayAmount(finalRepayAmount, debtReserve, collReserve);
34
+ const inputAmountLamports = decimal_js_1.default.min(maxWithdrawableCollLamports, maxCollNeededFromOracle);
46
35
  // Build the repay & withdraw collateral tx to get the number of accounts
47
36
  const klendIxs = await buildRepayWithCollateralIxs(kaminoMarket, debtReserve, collReserve, obligation, referrer, currentSlot, budgetAndPriorityFeeIxs, scopeRefreshConfig, {
48
37
  preActionIxs: [],
@@ -54,7 +43,7 @@ async function getRepayWithCollSwapInputs({ collTokenMint, currentSlot, debtToke
54
43
  inputAmountLamports,
55
44
  inputMint: collTokenMint,
56
45
  outputMint: debtTokenMint,
57
- amountDebtAtaBalance: new decimal_js_1.default(0), // only used for kTokens
46
+ amountDebtAtaBalance: undefined, // only used for kTokens
58
47
  };
59
48
  const swapQuote = await quoter(swapQuoteInputs, uniqueKlendAccounts);
60
49
  const swapQuotePxDebtToColl = swapQuote.priceAInB;
@@ -69,13 +58,13 @@ async function getRepayWithCollSwapInputs({ collTokenMint, currentSlot, debtToke
69
58
  minOutAmountLamports: flashRepayAmountLamports,
70
59
  inputMint: collTokenMint,
71
60
  outputMint: debtTokenMint,
72
- amountDebtAtaBalance: new decimal_js_1.default(0), // only used for kTokens
61
+ amountDebtAtaBalance: undefined, // only used for kTokens
73
62
  },
74
63
  flashLoanInfo: klendIxs.flashLoanInfo,
75
64
  initialInputs: {
76
65
  debtRepayAmountLamports: repayAmountLamports,
77
66
  flashRepayAmountLamports,
78
- maxCollateralWithdrawLamports: withdrawableCollLamports,
67
+ maxCollateralWithdrawLamports: maxWithdrawableCollLamports,
79
68
  swapQuote,
80
69
  currentSlot,
81
70
  klendAccounts: uniqueKlendAccounts,
@@ -99,14 +88,8 @@ async function getRepayWithCollIxs({ repayAmount, isClosingPosition, budgetAndPr
99
88
  });
100
89
  const { debtRepayAmountLamports, flashRepayAmountLamports, maxCollateralWithdrawLamports, swapQuote } = initialInputs;
101
90
  const { inputAmountLamports: collSwapInLamports } = swapInputs;
102
- const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
103
- if (!collReserve) {
104
- throw new Error(`Collateral reserve with mint ${collTokenMint} not found in market ${kaminoMarket.getAddress()}`);
105
- }
106
- const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
107
- if (!debtReserve) {
108
- throw new Error(`Debt reserve with mint ${debtTokenMint} not found in market ${kaminoMarket.getAddress()}`);
109
- }
91
+ const collReserve = kaminoMarket.getExistingReserveByMint(collTokenMint);
92
+ const debtReserve = kaminoMarket.getExistingReserveByMint(debtTokenMint);
110
93
  // the client should use these values to prevent this input, but the tx may succeed, so we don't want to fail
111
94
  // there is also a chance that the tx will consume debt token from the user's ata which they would not expect
112
95
  if (collSwapInLamports.greaterThan(maxCollateralWithdrawLamports)) {
@@ -152,7 +135,7 @@ async function buildRepayWithCollateralIxs(market, debtReserve, collReserve, obl
152
135
  programId: market.programId,
153
136
  });
154
137
  const requestElevationGroup = !isClosingPosition && obligation.state.elevationGroup !== 0;
155
- const maxWithdrawLtvCheck = (0, exports.getMaxWithdrawLtvCheck)(obligation);
138
+ const maxWithdrawLtvCheck = (0, exports.getMaxWithdrawLtvCheck)(obligation, debtRepayAmountLamports, debtReserve, collWithdrawLamports, collReserve);
156
139
  // 3. Repay using the flash borrowed funds & withdraw collateral to swap and pay the flash loan
157
140
  let repayAndWithdrawAction;
158
141
  if (maxWithdrawLtvCheck === MaxWithdrawLtvCheck.MAX_LTV) {
@@ -183,10 +166,37 @@ async function buildRepayWithCollateralIxs(market, debtReserve, collReserve, obl
183
166
  };
184
167
  return res;
185
168
  }
186
- const getMaxWithdrawLtvCheck = (obligation) => {
169
+ const getMaxWithdrawLtvCheck = (obligation, repayAmountLamports, debtReserve, collWithdrawAmount, collReserve) => {
170
+ const [finalLtv, finalMaxLtv] = calculatePostOperationLtv(obligation, repayAmountLamports, debtReserve, collWithdrawAmount, collReserve);
171
+ if (finalLtv.lte(finalMaxLtv)) {
172
+ return MaxWithdrawLtvCheck.MAX_LTV;
173
+ }
187
174
  return obligation.refreshedStats.userTotalBorrowBorrowFactorAdjusted.gte(obligation.refreshedStats.borrowLimit)
188
175
  ? MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD
189
176
  : MaxWithdrawLtvCheck.MAX_LTV;
190
177
  };
191
178
  exports.getMaxWithdrawLtvCheck = getMaxWithdrawLtvCheck;
179
+ function calculatePostOperationLtv(obligation, repayAmountLamports, debtReserve, collWithdrawAmount, collReserve) {
180
+ const repayValue = repayAmountLamports
181
+ .div(debtReserve.getMintFactor())
182
+ .mul(debtReserve.getOracleMarketPrice())
183
+ .mul(debtReserve.getBorrowFactor());
184
+ const collWithdrawValue = collWithdrawAmount.div(collReserve.getMintFactor()).mul(collReserve.getOracleMarketPrice());
185
+ // Calculate new borrow value and deposit value
186
+ const newBorrowBfValue = decimal_js_1.default.max(new decimal_js_1.default(0), obligation.refreshedStats.userTotalBorrowBorrowFactorAdjusted.sub(repayValue));
187
+ const newDepositValue = decimal_js_1.default.max(new decimal_js_1.default(0), obligation.refreshedStats.userTotalDeposit.sub(collWithdrawValue));
188
+ const newMaxBorrowableValue = decimal_js_1.default.max(new decimal_js_1.default(0), obligation.refreshedStats.borrowLimit.sub(collWithdrawValue.mul(collReserve.stats.loanToValue)));
189
+ const newMaxLtv = newMaxBorrowableValue.div(newDepositValue);
190
+ // return final ltv and final max ltv
191
+ return [newBorrowBfValue.div(newDepositValue), newMaxLtv];
192
+ }
193
+ function getMaxCollateralFromRepayAmount(repayAmount, debtReserve, collReserve) {
194
+ // sanity check: we have extra collateral to swap, but we want to ensure we don't quote for way more than needed and get a bad px
195
+ return repayAmount
196
+ .mul(debtReserve.getOracleMarketPrice())
197
+ .div(collReserve.getOracleMarketPrice())
198
+ .mul('1.1')
199
+ .mul(collReserve.getMintFactor())
200
+ .ceil();
201
+ }
192
202
  //# sourceMappingURL=repay_with_collateral_operations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"repay_with_collateral_operations.js","sourceRoot":"","sources":["../../src/lending_operations/repay_with_collateral_operations.ts"],"names":[],"mappings":";;;;;;AAmEA,gEAsHC;AAOD,kDAyFC;AAzRD,wCAAyF;AACzF,0CAUqB;AACrB,oCAOkB;AAElB,4DAAiC;AACjC,+EAAuG;AAwCvG,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,mEAAO,CAAA;IACP,+FAAqB,CAAA;AACvB,CAAC,EAHW,mBAAmB,mCAAnB,mBAAmB,QAG9B;AAEM,KAAK,UAAU,0BAA0B,CAAgB,EAC9D,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,EACZ,UAAU,EACV,MAAM,EACN,QAAQ,EACR,WAAW,EACX,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,QAAQ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,WAAW,CAAC;QAC7G,CAAC,CAAC,mBAAmB,CAAC,qBAAqB;QAC3C,CAAC,CAAC,mBAAmB,CAAC,OAAO,CAAC;AAClC,CAAC,CAAC;AAJW,QAAA,sBAAsB,0BAIjC"}
1
+ {"version":3,"file":"repay_with_collateral_operations.js","sourceRoot":"","sources":["../../src/lending_operations/repay_with_collateral_operations.ts"],"names":[],"mappings":";;;;;;AAmEA,gEA0GC;AAOD,kDAgFC;AAkLD,0EAYC;AAlcD,wCAAyF;AACzF,0CAUqB;AACrB,oCAOkB;AAElB,4DAAiC;AACjC,+EAAuG;AAwCvG,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,mEAAO,CAAA;IACP,+FAAqB,CAAA;AACvB,CAAC,EAHW,mBAAmB,mCAAnB,mBAAmB,QAG9B;AAEM,KAAK,UAAU,0BAA0B,CAAgB,EAC9D,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,EACZ,UAAU,EACV,MAAM,EACN,QAAQ,EACR,WAAW,EACX,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,QAAQ,GACoC;IAK5C,MAAM,WAAW,GAAG,YAAY,CAAC,wBAAwB,CAAC,aAAa,CAAC,CAAC;IACzE,MAAM,WAAW,GAAG,YAAY,CAAC,wBAAwB,CAAC,aAAa,CAAC,CAAC;IAEzE,MAAM,EACJ,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EAAE,gBAAgB,GAC9B,GAAG,IAAA,yDAA2B,EAAC,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;IAE3G,MAAM,YAAY,GAAG,UAAU,CAAC,kBAAkB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACxE,MAAM,YAAY,GAAG,UAAU,CAAC,mBAAmB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACzE,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAC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CAAC,CAAC,EACd,UAAU,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAChG,CAAC;IAEF,MAAM,SAAS,GAAG,qBAAqB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAE7D,qCAAqC;IACrC,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,SAAS,CAAC,CAAC;AAC5D,CAAC;AAED,SAAgB,+BAA+B,CAC7C,WAAoB,EACpB,WAA0B,EAC1B,WAA0B;IAE1B,iIAAiI;IACjI,OAAO,WAAW;SACf,GAAG,CAAC,WAAW,CAAC,oBAAoB,EAAE,CAAC;SACvC,GAAG,CAAC,WAAW,CAAC,oBAAoB,EAAE,CAAC;SACvC,GAAG,CAAC,KAAK,CAAC;SACV,GAAG,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC;SAChC,IAAI,EAAE,CAAC;AACZ,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
2
  export declare function walletIsSquadsMultisig(wallet: PublicKey): Promise<boolean>;
3
- export declare function getSquadsMultisigAdminsAndThreshold(_wallet: PublicKey): Promise<{
3
+ export declare function getSquadsMultisigAdminsAndThreshold(wallet: PublicKey): Promise<{
4
4
  adminsNumber: number;
5
5
  threshold: number;
6
6
  }>;
@@ -13,4 +13,14 @@ export interface WalletType {
13
13
  walletAdminsNumber: number;
14
14
  walletThreshold: number;
15
15
  }
16
+ export type SquadsMultisigAccountResponse = {
17
+ allow_external_execute: boolean;
18
+ authority_index: number;
19
+ bump: number;
20
+ create_key: string;
21
+ keys: number[][];
22
+ ms_change_index: number;
23
+ threshold: number;
24
+ transaction_index: number;
25
+ };
16
26
  //# sourceMappingURL=multisig.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"multisig.d.ts","sourceRoot":"","sources":["../../src/utils/multisig.ts"],"names":[],"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IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC"}
@@ -2,18 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.walletIsSquadsMultisig = walletIsSquadsMultisig;
4
4
  exports.getSquadsMultisigAdminsAndThreshold = getSquadsMultisigAdminsAndThreshold;
5
- const SQUADS_API_BASE_URL = 'https://4fnetmviidiqkjzenwxe66vgoa0soerr.lambda-url.us-east-1.on.aws/';
5
+ const SQUADS_API_BASE_URL = 'https://4fnetmviidiqkjzenwxe66vgoa0soerr.lambda-url.us-east-1.on.aws';
6
6
  async function walletIsSquadsMultisig(wallet) {
7
- const response = await fetch(`${SQUADS_API_BASE_URL}/is-multisig?wallet=${wallet.toBase58()}`);
7
+ const response = await fetch(`${SQUADS_API_BASE_URL}/isSquad/${wallet.toBase58()}`);
8
8
  const data = await response.json();
9
9
  const squadsResponse = data;
10
10
  return squadsResponse.isSquad;
11
11
  }
12
12
  // todo: find a way to get the admins number and threshold
13
- async function getSquadsMultisigAdminsAndThreshold(_wallet) {
13
+ async function getSquadsMultisigAdminsAndThreshold(wallet) {
14
+ const response = await fetch(`${SQUADS_API_BASE_URL}/multisig/${wallet.toBase58()}`);
15
+ const data = await response.json();
16
+ const squadsResponse = data;
14
17
  return {
15
- adminsNumber: 1,
16
- threshold: 1,
18
+ adminsNumber: squadsResponse.keys.length,
19
+ threshold: squadsResponse.threshold,
17
20
  };
18
21
  }
19
22
  //# sourceMappingURL=multisig.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"multisig.js","sourceRoot":"","sources":["../../src/utils/multisig.ts"],"names":[],"mappings":";;AAIA,wDAKC;AAGD,kFAQC;AAlBD,MAAM,mBAAmB,GAAG,uEAAuE,CAAC;AAE7F,KAAK,UAAU,sBAAsB,CAAC,MAAiB;IAC5D,MAAM,QAAQ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
  {
2
2
  "name": "@kamino-finance/klend-sdk",
3
- "version": "5.13.7",
3
+ "version": "5.13.9",
4
4
  "description": "Typescript SDK for interacting with the Kamino Lending (klend) protocol",
5
5
  "repository": {
6
6
  "type": "git",
@@ -89,6 +89,7 @@ import {
89
89
  UpdateReserveAllocationIxs,
90
90
  UpdateVaultConfigIxs,
91
91
  UserSharesForVault,
92
+ WithdrawAndBlockReserveIxs,
92
93
  WithdrawIxs,
93
94
  } from './vault_types';
94
95
  import { FarmState } from '@kamino-finance/farms-sdk/dist';
@@ -271,6 +272,36 @@ export class KaminoManager {
271
272
  return this._vaultClient.removeReserveFromAllocationIx(vault, reserve);
272
273
  }
273
274
 
275
+ /**
276
+ * This method withdraws all the funds from a reserve and blocks it from being invested by setting its weight and ctoken allocation to 0
277
+ * @param vault - the vault to withdraw the funds from
278
+ * @param reserve - the reserve to withdraw the funds from
279
+ * @param payer - the payer of the transaction. If not provided, the admin of the vault will be used
280
+ * @returns - a struct with an instruction to update the reserve allocation and an optional list of instructions to update the lookup table for the allocation changes
281
+ */
282
+ async withdrawEverythingAndBLockReserve(
283
+ vault: KaminoVault,
284
+ reserve: PublicKey,
285
+ payer?: PublicKey
286
+ ): Promise<WithdrawAndBlockReserveIxs> {
287
+ return this._vaultClient.withdrawEverythingAndBLockReserve(vault, reserve, payer);
288
+ }
289
+
290
+ /**
291
+ * This method withdraws all the funds from all the reserves and blocks them from being invested by setting their weight and ctoken allocation to 0
292
+ * @param vault - the vault to withdraw the invested funds from
293
+ * @param [vaultReservesMap] - optional parameter to pass a map of the vault reserves. If not provided, the reserves will be loaded from the vault
294
+ * @param [payer] - optional parameter to pass a different payer for the transaction. If not provided, the admin of the vault will be used; this is the payer for the invest ixs and it should have an ATA and some lamports (2x no_of_reserves) of the token vault
295
+ * @returns - a struct with an instruction to update the reserve allocation and an optional list of instructions to update the lookup table for the allocation changes
296
+ */
297
+ async withdrawEverythingFromAllReservesAndBlockInvest(
298
+ vault: KaminoVault,
299
+ vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>,
300
+ payer?: PublicKey
301
+ ): Promise<WithdrawAndBlockReserveIxs> {
302
+ return this._vaultClient.withdrawEverythingFromAllReservesAndBlockInvest(vault, vaultReservesMap, payer);
303
+ }
304
+
274
305
  // async closeVault(vault: KaminoVault): Promise<TransactionInstruction> {
275
306
  // return this._vaultClient.closeVaultIx(vault);
276
307
  // }
@@ -1458,6 +1458,16 @@ export class KaminoObligation {
1458
1458
  );
1459
1459
  }
1460
1460
 
1461
+ getObligationLiquidityByReserve(reserveAddress: PublicKey): ObligationLiquidity {
1462
+ const obligationLiquidity = this.state.borrows.find((borrow) => borrow.borrowReserve.equals(reserveAddress));
1463
+
1464
+ if (!obligationLiquidity) {
1465
+ throw new Error(`Obligation liquidity not found given reserve ${reserveAddress.toString()}`);
1466
+ }
1467
+
1468
+ return obligationLiquidity;
1469
+ }
1470
+
1461
1471
  /**
1462
1472
  *
1463
1473
  * @returns Total borrowed amount for the specified obligation liquidity/borrow asset
@@ -89,6 +89,7 @@ import {
89
89
  UpdateReserveAllocationIxs,
90
90
  UpdateVaultConfigIxs,
91
91
  UserSharesForVault,
92
+ WithdrawAndBlockReserveIxs,
92
93
  WithdrawIxs,
93
94
  } from './vault_types';
94
95
  import { batchFetch, collToLamportsDecimal, ZERO } from '@kamino-finance/kliquidity-sdk';
@@ -443,6 +444,96 @@ export class KaminoVaultClient {
443
444
  return updateReserveAllocationIxs;
444
445
  }
445
446
 
447
+ /**
448
+ * This method withdraws all the funds from a reserve and blocks it from being invested by setting its weight and ctoken allocation to 0
449
+ * @param vault - the vault to withdraw the funds from
450
+ * @param reserve - the reserve to withdraw the funds from
451
+ * @param payer - the payer of the transaction. If not provided, the admin of the vault will be used
452
+ * @returns - a struct with an instruction to update the reserve allocation and an optional list of instructions to update the lookup table for the allocation changes
453
+ */
454
+ async withdrawEverythingAndBLockReserve(
455
+ vault: KaminoVault,
456
+ reserve: PublicKey,
457
+ payer?: PublicKey
458
+ ): Promise<WithdrawAndBlockReserveIxs> {
459
+ const vaultState = await vault.getState(this.getConnection());
460
+
461
+ const reserveIsPartOfAllocation = vaultState.vaultAllocationStrategy.some((allocation) =>
462
+ allocation.reserve.equals(reserve)
463
+ );
464
+
465
+ const withdrawAndBlockReserveIxs: WithdrawAndBlockReserveIxs = {
466
+ updateReserveAllocationIxs: [],
467
+ investIxs: [],
468
+ };
469
+ if (!reserveIsPartOfAllocation) {
470
+ return withdrawAndBlockReserveIxs;
471
+ }
472
+
473
+ const reserveState = await Reserve.fetch(this.getConnection(), reserve);
474
+ if (!reserveState) {
475
+ return withdrawAndBlockReserveIxs;
476
+ }
477
+ const reserveWithAddress: ReserveWithAddress = {
478
+ address: reserve,
479
+ state: reserveState,
480
+ };
481
+ const reserveAllocationConfig = new ReserveAllocationConfig(reserveWithAddress, 0, new Decimal(0));
482
+
483
+ // update allocation to have 0 weight and 0 cap
484
+ const updateAllocIxs = await this.updateReserveAllocationIxs(vault, reserveAllocationConfig);
485
+
486
+ const investPayer = payer ? payer : vaultState.vaultAdminAuthority;
487
+ const investIx = await this.investSingleReserveIxs(investPayer, vault, reserveWithAddress);
488
+ withdrawAndBlockReserveIxs.updateReserveAllocationIxs = [updateAllocIxs.updateReserveAllocationIx];
489
+ withdrawAndBlockReserveIxs.investIxs = investIx;
490
+
491
+ return withdrawAndBlockReserveIxs;
492
+ }
493
+
494
+ /**
495
+ * This method withdraws all the funds from all the reserves and blocks them from being invested by setting their weight and ctoken allocation to 0
496
+ * @param vault - the vault to withdraw the invested funds from
497
+ * @param [vaultReservesMap] - optional parameter to pass a map of the vault reserves. If not provided, the reserves will be loaded from the vault
498
+ * @param [payer] - optional parameter to pass a different payer for the transaction. If not provided, the admin of the vault will be used; this is the payer for the invest ixs and it should have an ATA and some lamports (2x no_of_reserves) of the token vault
499
+ * @returns - a struct with an instruction to update the reserve allocation and an optional list of instructions to update the lookup table for the allocation changes
500
+ */
501
+ async withdrawEverythingFromAllReservesAndBlockInvest(
502
+ vault: KaminoVault,
503
+ vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>,
504
+ payer?: PublicKey
505
+ ): Promise<WithdrawAndBlockReserveIxs> {
506
+ const vaultState = await vault.getState(this.getConnection());
507
+
508
+ const reserves = this.getVaultReserves(vaultState);
509
+ const withdrawAndBlockReserveIxs: WithdrawAndBlockReserveIxs = {
510
+ updateReserveAllocationIxs: [],
511
+ investIxs: [],
512
+ };
513
+
514
+ if (!vaultReservesMap) {
515
+ vaultReservesMap = await this.loadVaultReserves(vaultState);
516
+ }
517
+
518
+ for (const reserve of reserves) {
519
+ const reserveWithAddress: ReserveWithAddress = {
520
+ address: reserve,
521
+ state: vaultReservesMap.get(reserve)!.state,
522
+ };
523
+ const reserveAllocationConfig = new ReserveAllocationConfig(reserveWithAddress, 0, new Decimal(0));
524
+
525
+ // update allocation to have 0 weight and 0 cap
526
+ const updateAllocIxs = await this.updateReserveAllocationIxs(vault, reserveAllocationConfig);
527
+ withdrawAndBlockReserveIxs.updateReserveAllocationIxs.push(updateAllocIxs.updateReserveAllocationIx);
528
+ }
529
+
530
+ const investPayer = payer ? payer : vaultState.vaultAdminAuthority;
531
+ const investIxs = await this.investAllReservesIxs(investPayer, vault);
532
+ withdrawAndBlockReserveIxs.investIxs = investIxs;
533
+
534
+ return withdrawAndBlockReserveIxs;
535
+ }
536
+
446
537
  /**
447
538
  * This method removes a reserve from the vault allocation strategy if already part of the allocation strategy
448
539
  * @param vault - vault to remove the reserve from
@@ -22,6 +22,11 @@ export type UpdateReserveAllocationIxs = {
22
22
  updateLUTIxs: TransactionInstruction[];
23
23
  };
24
24
 
25
+ export type WithdrawAndBlockReserveIxs = {
26
+ updateReserveAllocationIxs: TransactionInstruction[];
27
+ investIxs: TransactionInstruction[];
28
+ };
29
+
25
30
  export type UpdateVaultConfigIxs = {
26
31
  updateVaultConfigIx: TransactionInstruction;
27
32
  updateLUTIxs: TransactionInstruction[];
@@ -1484,6 +1484,15 @@ async function main() {
1484
1484
  );
1485
1485
  });
1486
1486
 
1487
+ commands
1488
+ .command('get-market-or-vault-admin-info')
1489
+ .requiredOption('--address <string>', 'Address of the market or vault')
1490
+ .action(async ({ address }) => {
1491
+ const env = initializeClient(false, false);
1492
+ const adminInfo = await KaminoManager.getMarketOrVaultAdminInfo(env.connection, new PublicKey(address));
1493
+ console.log(adminInfo);
1494
+ });
1495
+
1487
1496
  await commands.parseAsync();
1488
1497
  }
1489
1498