@kamino-finance/klend-sdk 5.11.6 → 5.11.8

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 (55) hide show
  1. package/dist/classes/action.d.ts +12 -2
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +225 -30
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/manager.js +1 -1
  6. package/dist/classes/manager.js.map +1 -1
  7. package/dist/classes/obligation.d.ts +1 -1
  8. package/dist/classes/obligation.d.ts.map +1 -1
  9. package/dist/classes/obligation.js +1 -1
  10. package/dist/classes/obligation.js.map +1 -1
  11. package/dist/classes/vault.d.ts.map +1 -1
  12. package/dist/classes/vault.js +11 -8
  13. package/dist/classes/vault.js.map +1 -1
  14. package/dist/client_kamino_manager.d.ts.map +1 -1
  15. package/dist/client_kamino_manager.js +11 -0
  16. package/dist/client_kamino_manager.js.map +1 -1
  17. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  18. package/dist/lending_operations/repay_with_collateral_calcs.js +9 -5
  19. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  20. package/dist/lending_operations/repay_with_collateral_operations.d.ts +5 -0
  21. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  22. package/dist/lending_operations/repay_with_collateral_operations.js +26 -1
  23. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  24. package/dist/utils/accountListing.d.ts +4 -4
  25. package/dist/utils/accountListing.d.ts.map +1 -1
  26. package/dist/utils/accountListing.js +3 -3
  27. package/dist/utils/accountListing.js.map +1 -1
  28. package/dist/utils/lookupTable.d.ts +27 -0
  29. package/dist/utils/lookupTable.d.ts.map +1 -1
  30. package/dist/utils/lookupTable.js +58 -0
  31. package/dist/utils/lookupTable.js.map +1 -1
  32. package/dist/utils/seeds.d.ts +11 -1
  33. package/dist/utils/seeds.d.ts.map +1 -1
  34. package/dist/utils/seeds.js +13 -3
  35. package/dist/utils/seeds.js.map +1 -1
  36. package/dist/utils/userMetadata.js +6 -6
  37. package/dist/utils/userMetadata.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/classes/action.ts +358 -50
  40. package/src/classes/manager.ts +1 -1
  41. package/src/classes/obligation.ts +1 -1
  42. package/src/classes/vault.ts +6 -3
  43. package/src/client.ts +32 -6
  44. package/src/client_kamino_manager.ts +15 -0
  45. package/src/lending_operations/repay_with_collateral_calcs.ts +14 -5
  46. package/src/lending_operations/repay_with_collateral_operations.ts +63 -20
  47. package/src/utils/accountListing.ts +11 -7
  48. package/src/utils/lookupTable.ts +62 -0
  49. package/src/utils/seeds.ts +14 -4
  50. package/src/utils/userMetadata.ts +14 -14
  51. package/dist/classes/lut_utils.d.ts +0 -29
  52. package/dist/classes/lut_utils.d.ts.map +0 -1
  53. package/dist/classes/lut_utils.js +0 -62
  54. package/dist/classes/lut_utils.js.map +0 -1
  55. package/src/classes/lut_utils.ts +0 -63
package/src/client.ts CHANGED
@@ -62,9 +62,17 @@ async function main() {
62
62
  .option(`--rpc <string>`, 'The RPC URL')
63
63
  .action(async ({ rpc }) => {
64
64
  const connection = new Connection(rpc, {});
65
- for await (const lendingMarketAccount of getAllLendingMarketAccounts(connection)) {
66
- console.log(toJson(lendingMarketAccount.toJSON()));
65
+ let count = 0;
66
+ for await (const [address, lendingMarketAccount] of getAllLendingMarketAccounts(connection)) {
67
+ count++;
68
+ console.log(
69
+ address.toString(),
70
+ lendingMarketAccount.riskCouncil.toString(),
71
+ lendingMarketAccount.autodeleverageEnabled,
72
+ lendingMarketAccount.individualAutodeleverageMarginCallPeriodSecs.toString()
73
+ );
67
74
  }
75
+ console.log(`Total lending markets: ${count}`);
68
76
  });
69
77
 
70
78
  commands
@@ -84,9 +92,17 @@ async function main() {
84
92
  .option(`--rpc <string>`, 'The RPC URL')
85
93
  .action(async ({ rpc }) => {
86
94
  const connection = new Connection(rpc, {});
87
- for await (const obligationAccount of getAllObligationAccounts(connection)) {
88
- console.log(toJson(obligationAccount.toJSON()));
95
+ let count = 0;
96
+ for await (const [address, obligationAccount] of getAllObligationAccounts(connection)) {
97
+ count++;
98
+ if (
99
+ obligationAccount.autodeleverageTargetLtvPct > 0 ||
100
+ obligationAccount.autodeleverageMarginCallStartedTimestamp.toNumber() > 0
101
+ ) {
102
+ console.log(address.toString(), toJson(obligationAccount.toJSON()));
103
+ }
89
104
  }
105
+ console.log(`Total obligations: ${count}`);
90
106
  });
91
107
 
92
108
  commands
@@ -104,9 +120,19 @@ async function main() {
104
120
  .option(`--rpc <string>`, 'The RPC URL')
105
121
  .action(async ({ rpc }) => {
106
122
  const connection = new Connection(rpc, {});
107
- for await (const reserveAccount of getAllReserveAccounts(connection)) {
108
- console.log(toJson(reserveAccount.toJSON()));
123
+ let count = 0;
124
+ const logItems: { address: string; value: string; index: number }[] = [];
125
+ for await (const [address, reserveAccount] of getAllReserveAccounts(connection)) {
126
+ count++;
127
+ const logItem = {
128
+ address: address.toString(),
129
+ value: reserveAccount.config.autodeleverageEnabled.toString(),
130
+ index: count,
131
+ };
132
+ logItems.push(logItem);
109
133
  }
134
+ console.log(`Total reserves: ${count}`);
135
+ console.log(logItems);
110
136
  });
111
137
 
112
138
  commands
@@ -1019,6 +1019,21 @@ async function main() {
1019
1019
  );
1020
1020
  });
1021
1021
 
1022
+ commands
1023
+ .command('compute-alloc')
1024
+ .requiredOption('--vault <string>', 'Vault address')
1025
+ .action(async ({ vault }) => {
1026
+ const env = initializeClient(false, false);
1027
+
1028
+ const vaultAddress = new PublicKey(vault);
1029
+
1030
+ const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
1031
+ const vaultState = await new KaminoVault(vaultAddress, undefined, env.kVaultProgramId).getState(env.connection);
1032
+
1033
+ const computedAllocation = await kaminoManager.getVaultComputedReservesAllocation(vaultState);
1034
+ console.log('computedAllocation', computedAllocation);
1035
+ });
1036
+
1022
1037
  commands
1023
1038
  .command('download-lending-market-config-and-all-reserves-configs')
1024
1039
  .requiredOption('--lending-market <string>', 'Lending Market Address')
@@ -2,6 +2,7 @@ import Decimal from 'decimal.js';
2
2
  import { KaminoMarket, KaminoObligation, KaminoReserve, numberToLamportsDecimal } from '../classes';
3
3
  import { PublicKey } from '@solana/web3.js';
4
4
  import { lamportsToDecimal } from '../classes/utils';
5
+ import { MaxWithdrawLtvCheck, getMaxWithdrawLtvCheck } from './repay_with_collateral_operations';
5
6
 
6
7
  export function calcRepayAmountWithSlippage(
7
8
  kaminoMarket: KaminoMarket,
@@ -102,6 +103,7 @@ export function calcMaxWithdrawCollateral(
102
103
  .filter((p) => !p.reserveAddress.equals(borrow.reserveAddress))
103
104
  .reduce((acc, b) => acc.add(b.marketValueRefreshed), new Decimal('0'));
104
105
  }
106
+ const maxWithdrawLtvCheck = getMaxWithdrawLtvCheck(obligation);
105
107
 
106
108
  let remainingDepositsValueWithLtv = new Decimal('0');
107
109
  if (obligation.getDeposits().length > 1) {
@@ -109,8 +111,13 @@ export function calcMaxWithdrawCollateral(
109
111
  .getDeposits()
110
112
  .filter((p) => !p.reserveAddress.equals(deposit.reserveAddress))
111
113
  .reduce((acc, d) => {
112
- const { maxLtv } = obligation.getLtvForReserve(market, market.getReserveByAddress(d.reserveAddress)!);
113
- return acc.add(d.marketValueRefreshed.mul(maxLtv));
114
+ const { maxLtv, liquidationLtv } = obligation.getLtvForReserve(
115
+ market,
116
+ market.getReserveByAddress(d.reserveAddress)!
117
+ );
118
+ const maxWithdrawLtv =
119
+ maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? liquidationLtv : maxLtv;
120
+ return acc.add(d.marketValueRefreshed.mul(maxWithdrawLtv));
114
121
  }, new Decimal('0'));
115
122
  }
116
123
 
@@ -123,16 +130,18 @@ export function calcMaxWithdrawCollateral(
123
130
  repayingAllDebt: repayAmountLamports.gte(borrow.amount),
124
131
  };
125
132
  } else {
126
- const { maxLtv: collMaxLtv } = obligation.getLtvForReserve(
133
+ const { maxLtv: collMaxLtv, liquidationLtv: collLiquidationLtv } = obligation.getLtvForReserve(
127
134
  market,
128
135
  market.getReserveByAddress(depositReserve.address)!
129
136
  );
137
+ const maxWithdrawLtv =
138
+ maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? collLiquidationLtv : collMaxLtv;
130
139
  const numerator = deposit.marketValueRefreshed
131
- .mul(collMaxLtv)
140
+ .mul(maxWithdrawLtv)
132
141
  .add(remainingDepositsValueWithLtv)
133
142
  .sub(remainingBorrowsValue);
134
143
 
135
- const denominator = depositReserve.getOracleMarketPrice().mul(collMaxLtv);
144
+ const denominator = depositReserve.getOracleMarketPrice().mul(maxWithdrawLtv);
136
145
  const maxCollWithdrawAmount = numerator.div(denominator);
137
146
  const withdrawableCollLamports = maxCollWithdrawAmount.mul(depositReserve.getMintFactor()).floor();
138
147
 
@@ -57,6 +57,11 @@ interface RepayWithCollSwapInputsProps<QuoteResponse> {
57
57
  quoter: SwapQuoteProvider<QuoteResponse>;
58
58
  }
59
59
 
60
+ export enum MaxWithdrawLtvCheck {
61
+ MAX_LTV,
62
+ LIQUIDATION_THRESHOLD,
63
+ }
64
+
60
65
  export async function getRepayWithCollSwapInputs<QuoteResponse>({
61
66
  collTokenMint,
62
67
  currentSlot,
@@ -213,8 +218,17 @@ export async function getRepayWithCollIxs<QuoteResponse>({
213
218
  const { debtRepayAmountLamports, flashRepayAmountLamports, maxCollateralWithdrawLamports, swapQuote } = initialInputs;
214
219
  const { inputAmountLamports: collSwapInLamports } = swapInputs;
215
220
 
216
- const collReserve = kaminoMarket.getReserveByMint(collTokenMint)!;
217
- const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint)!;
221
+ const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
222
+
223
+ if (!collReserve) {
224
+ throw new Error(`Collateral reserve with mint ${collTokenMint} not found in market ${kaminoMarket.getAddress()}`);
225
+ }
226
+
227
+ const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
228
+
229
+ if (!debtReserve) {
230
+ throw new Error(`Debt reserve with mint ${debtTokenMint} not found in market ${kaminoMarket.getAddress()}`);
231
+ }
218
232
 
219
233
  // the client should use these values to prevent this input, but the tx may succeed, so we don't want to fail
220
234
  // there is also a chance that the tx will consume debt token from the user's ata which they would not expect
@@ -306,25 +320,48 @@ async function buildRepayWithCollateralIxs(
306
320
 
307
321
  const requestElevationGroup = !isClosingPosition && obligation.state.elevationGroup !== 0;
308
322
 
323
+ const maxWithdrawLtvCheck = getMaxWithdrawLtvCheck(obligation);
324
+
309
325
  // 3. Repay using the flash borrowed funds & withdraw collateral to swap and pay the flash loan
310
- const repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns(
311
- market,
312
- isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
313
- debtReserve.getLiquidityMint(),
314
- isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
315
- collReserve.getLiquidityMint(),
316
- obligation.state.owner,
317
- currentSlot,
318
- obligation,
319
- useV2Ixs,
320
- undefined,
321
- 0,
322
- false,
323
- requestElevationGroup,
324
- undefined,
325
- undefined,
326
- referrer
327
- );
326
+ let repayAndWithdrawAction;
327
+ if (maxWithdrawLtvCheck === MaxWithdrawLtvCheck.MAX_LTV) {
328
+ repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns(
329
+ market,
330
+ isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
331
+ debtReserve.getLiquidityMint(),
332
+ isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
333
+ collReserve.getLiquidityMint(),
334
+ obligation.state.owner,
335
+ currentSlot,
336
+ obligation,
337
+ useV2Ixs,
338
+ undefined,
339
+ 0,
340
+ false,
341
+ requestElevationGroup,
342
+ undefined,
343
+ undefined,
344
+ referrer
345
+ );
346
+ } else {
347
+ repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawV2Txns(
348
+ market,
349
+ isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
350
+ debtReserve.getLiquidityMint(),
351
+ isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
352
+ collReserve.getLiquidityMint(),
353
+ obligation.state.owner,
354
+ currentSlot,
355
+ obligation,
356
+ undefined,
357
+ 0,
358
+ false,
359
+ requestElevationGroup,
360
+ undefined,
361
+ undefined,
362
+ referrer
363
+ );
364
+ }
328
365
 
329
366
  // 4. Swap collateral to debt to repay flash loan
330
367
  const { preActionIxs, swapIxs } = swapQuoteIxs;
@@ -341,3 +378,9 @@ async function buildRepayWithCollateralIxs(
341
378
  flashRepayIxn,
342
379
  ];
343
380
  }
381
+
382
+ export const getMaxWithdrawLtvCheck = (obligation: KaminoObligation) => {
383
+ return obligation.refreshedStats.userTotalBorrowBorrowFactorAdjusted.gte(obligation.refreshedStats.borrowLimit)
384
+ ? MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD
385
+ : MaxWithdrawLtvCheck.MAX_LTV;
386
+ };
@@ -1,9 +1,11 @@
1
- import { Connection } from '@solana/web3.js';
1
+ import { Connection, PublicKey } from '@solana/web3.js';
2
2
  import { LendingMarket, Obligation, Reserve } from '../idl_codegen/accounts';
3
3
  import { PROGRAM_ID } from '../idl_codegen/programId';
4
4
  import bs58 from 'bs58';
5
5
 
6
- export async function* getAllObligationAccounts(connection: Connection): AsyncGenerator<Obligation, void, unknown> {
6
+ export async function* getAllObligationAccounts(
7
+ connection: Connection
8
+ ): AsyncGenerator<[PublicKey, Obligation], void, unknown> {
7
9
  // Poor-man's paging...
8
10
  for (let i = 0; i < 256; i++) {
9
11
  const obligations = await connection.getProgramAccounts(PROGRAM_ID, {
@@ -26,12 +28,14 @@ export async function* getAllObligationAccounts(connection: Connection): AsyncGe
26
28
  ],
27
29
  });
28
30
  for (const obligation of obligations) {
29
- yield Obligation.decode(obligation.account.data);
31
+ yield [obligation.pubkey, Obligation.decode(obligation.account.data)];
30
32
  }
31
33
  }
32
34
  }
33
35
 
34
- export async function* getAllReserveAccounts(connection: Connection): AsyncGenerator<Reserve, void, unknown> {
36
+ export async function* getAllReserveAccounts(
37
+ connection: Connection
38
+ ): AsyncGenerator<[PublicKey, Reserve], void, unknown> {
35
39
  // due to relatively low count of reserves, we technically don't really need a generator, but let's keep it consistent within this file
36
40
  const reserves = await connection.getProgramAccounts(PROGRAM_ID, {
37
41
  filters: [
@@ -47,13 +51,13 @@ export async function* getAllReserveAccounts(connection: Connection): AsyncGener
47
51
  ],
48
52
  });
49
53
  for (const reserve of reserves) {
50
- yield Reserve.decode(reserve.account.data);
54
+ yield [reserve.pubkey, Reserve.decode(reserve.account.data)];
51
55
  }
52
56
  }
53
57
 
54
58
  export async function* getAllLendingMarketAccounts(
55
59
  connection: Connection
56
- ): AsyncGenerator<LendingMarket, void, unknown> {
60
+ ): AsyncGenerator<[PublicKey, LendingMarket], void, unknown> {
57
61
  // due to relatively very low count of lending markets, we technically don't really need a generator, but let's keep it consistent within this file
58
62
  const lendingMarkets = await connection.getProgramAccounts(PROGRAM_ID, {
59
63
  filters: [
@@ -69,6 +73,6 @@ export async function* getAllLendingMarketAccounts(
69
73
  ],
70
74
  });
71
75
  for (const lendingMarket of lendingMarkets) {
72
- yield LendingMarket.decode(lendingMarket.account.data);
76
+ yield [lendingMarket.pubkey, LendingMarket.decode(lendingMarket.account.data)];
73
77
  }
74
78
  }
@@ -53,3 +53,65 @@ export const extendLookupTableIxs = (
53
53
 
54
54
  return extendLookupIxs;
55
55
  };
56
+
57
+ /**
58
+ * This method retuns an instruction that creates a lookup table, alongside the pubkey of the lookup table
59
+ * @param payer - the owner of the lookup table
60
+ * @param slot - the current slot
61
+ * @returns - the instruction to create the lookup table and its address
62
+ */
63
+ export function initLookupTableIx(payer: PublicKey, slot: number): [TransactionInstruction, PublicKey] {
64
+ const [ixn, address] = AddressLookupTableProgram.createLookupTable({
65
+ authority: payer,
66
+ payer,
67
+ recentSlot: slot,
68
+ });
69
+
70
+ return [ixn, address];
71
+ }
72
+
73
+ /**
74
+ * This method retuns an instruction that deactivates a lookup table, which is needed to close it
75
+ * @param payer - the owner of the lookup table
76
+ * @param lookupTable - the lookup table to deactivate
77
+ * @returns - the instruction to deactivate the lookup table
78
+ */
79
+ export function deactivateLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
80
+ const ixn = AddressLookupTableProgram.deactivateLookupTable({
81
+ authority: payer,
82
+ lookupTable: lookupTable,
83
+ });
84
+
85
+ return ixn;
86
+ }
87
+
88
+ /**
89
+ * This method returns an instruction that closes a lookup table. That lookup table needs to be disabled at least 500 blocks before closing it.
90
+ * @param payer - the owner of the lookup table
91
+ * @param lookupTable - the lookup table to close
92
+ * @returns - the instruction to close the lookup table
93
+ */
94
+ /// this require the LUT to be deactivated at least 500 blocks before
95
+ export function closeLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
96
+ const ixn = AddressLookupTableProgram.closeLookupTable({
97
+ authority: payer,
98
+ recipient: payer,
99
+ lookupTable: lookupTable,
100
+ });
101
+
102
+ return ixn;
103
+ }
104
+
105
+ /**
106
+ * Returns the accounts in a lookup table
107
+ * @param lookupTable - lookup table to get the accounts from
108
+ * @returns - an array of accounts in the lookup table
109
+ */
110
+ export async function getAccountsInLUT(connection: Connection, lookupTable: PublicKey): Promise<PublicKey[]> {
111
+ const lutState = await connection.getAddressLookupTable(lookupTable);
112
+ if (!lutState || !lutState.value) {
113
+ throw new Error(`Lookup table ${lookupTable} not found`);
114
+ }
115
+
116
+ return lutState.value.state.addresses;
117
+ }
@@ -38,6 +38,10 @@ export const BASE_SEED_REFERRER_STATE = 'ref_state';
38
38
  * Short url seed
39
39
  */
40
40
  export const BASE_SEED_SHORT_URL = 'short_url';
41
+ /**
42
+ * Farm user state seed
43
+ */
44
+ export const BASE_SEED_USER_STATE = 'user';
41
45
 
42
46
  /**
43
47
  * User farm state seed
@@ -188,9 +192,15 @@ export function shortUrlPda(shortUrl: string, programId: PublicKey = PROGRAM_ID)
188
192
  return PublicKey.findProgramAddressSync([Buffer.from(BASE_SEED_SHORT_URL), Buffer.from(shortUrl)], programId);
189
193
  }
190
194
 
191
- export function obligationFarmStatePda(obligation: PublicKey, farm: PublicKey, programId: PublicKey = farmsId) {
195
+ /**
196
+ * Returns the PDA for the obligation farm state
197
+ * @param farm
198
+ * @param obligation
199
+ * @returns pda
200
+ */
201
+ export function obligationFarmStatePda(farm: PublicKey, obligation: PublicKey) {
192
202
  return PublicKey.findProgramAddressSync(
193
- [Buffer.from(BASE_SEED_FARM_USER_STATE), farm.toBuffer(), obligation.toBuffer()],
194
- programId
195
- );
203
+ [Buffer.from(BASE_SEED_USER_STATE), farm.toBytes(), obligation.toBytes()],
204
+ farmsId
205
+ )[0];
196
206
  }
@@ -266,18 +266,18 @@ function getMultiplyObligationAndObligationFarmStateAddresses(
266
266
  if (!collReserve.state.farmCollateral.equals(PublicKey.default)) {
267
267
  farmUserStates.push({
268
268
  address: obligationFarmStatePda(
269
- multiplyObligation.toPda(kaminoMarket.getAddress(), user),
270
- collReserve.state.farmCollateral!
271
- )[0],
269
+ collReserve.state.farmCollateral!,
270
+ multiplyObligation.toPda(kaminoMarket.getAddress(), user)
271
+ ),
272
272
  log: 'collReserve farmState for multiply obligation coll: ' + collMintString + ' debt: ' + debtMintString,
273
273
  });
274
274
  }
275
275
  if (!debtReserve.state.farmDebt.equals(PublicKey.default)) {
276
276
  farmUserStates.push({
277
277
  address: obligationFarmStatePda(
278
- multiplyObligation.toPda(kaminoMarket.getAddress(), user),
279
- debtReserve.state.farmDebt!
280
- )[0],
278
+ debtReserve.state.farmDebt!,
279
+ multiplyObligation.toPda(kaminoMarket.getAddress(), user)
280
+ ),
281
281
  log: 'debtReserve farmState for multiply obligation coll: ' + collMintString + ' debt: ' + debtMintString,
282
282
  });
283
283
  }
@@ -309,18 +309,18 @@ function getLeverageObligationAndObligationFarmStateAddresses(
309
309
  if (!collReserve.state.farmCollateral.equals(PublicKey.default)) {
310
310
  farmUserStates.push({
311
311
  address: obligationFarmStatePda(
312
- leverageObligation.toPda(kaminoMarket.getAddress(), user),
313
- collReserve.state.farmCollateral!
314
- )[0],
312
+ collReserve.state.farmCollateral!,
313
+ leverageObligation.toPda(kaminoMarket.getAddress(), user)
314
+ ),
315
315
  log: 'collReserve farmState for leverage obligation coll: ' + collMintString + ' debt: ' + debtMintString,
316
316
  });
317
317
  }
318
318
  if (!debtReserve.state.farmDebt.equals(PublicKey.default)) {
319
319
  farmUserStates.push({
320
320
  address: obligationFarmStatePda(
321
- leverageObligation.toPda(kaminoMarket.getAddress(), user),
322
- debtReserve.state.farmDebt!
323
- )[0],
321
+ debtReserve.state.farmDebt!,
322
+ leverageObligation.toPda(kaminoMarket.getAddress(), user)
323
+ ),
324
324
  log: 'debtReserve farmState for leverage obligation coll: ' + collMintString + ' debt: ' + debtMintString,
325
325
  });
326
326
  }
@@ -341,7 +341,7 @@ function getRepayWithCollObligationFarmStateAddresses(
341
341
  const borrowReserve = kaminoMarket.getReserveByMint(borrow.mintAddress)!;
342
342
  if (!borrowReserve.state.farmDebt.equals(PublicKey.default)) {
343
343
  farmUserStates.push({
344
- address: obligationFarmStatePda(obligation.obligationAddress, borrowReserve.state.farmDebt!)[0],
344
+ address: obligationFarmStatePda(borrowReserve.state.farmDebt!, obligation.obligationAddress),
345
345
  log: 'debtReserve farmState for vanilla obligation: ' + obligationString,
346
346
  });
347
347
  }
@@ -351,7 +351,7 @@ function getRepayWithCollObligationFarmStateAddresses(
351
351
  const depositReserve = kaminoMarket.getReserveByMint(deposit.mintAddress)!;
352
352
  if (!depositReserve.state.farmCollateral.equals(PublicKey.default)) {
353
353
  farmUserStates.push({
354
- address: obligationFarmStatePda(obligation.obligationAddress, depositReserve.state.farmCollateral!)[0],
354
+ address: obligationFarmStatePda(depositReserve.state.farmCollateral!, obligation.obligationAddress),
355
355
  log: 'collReserve farmState for vanilla obligation' + obligationString,
356
356
  });
357
357
  }
@@ -1,29 +0,0 @@
1
- import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
2
- /**
3
- * This method retuns an instruction that creates a lookup table, alongside the pubkey of the lookup table
4
- * @param payer - the owner of the lookup table
5
- * @param slot - the current slot
6
- * @returns - the instruction to create the lookup table and its address
7
- */
8
- export declare function initLookupTableIx(payer: PublicKey, slot: number): [TransactionInstruction, PublicKey];
9
- /**
10
- * This method retuns an instruction that deactivates a lookup table, which is needed to close it
11
- * @param payer - the owner of the lookup table
12
- * @param lookupTable - the lookup table to deactivate
13
- * @returns - the instruction to deactivate the lookup table
14
- */
15
- export declare function deactivateLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction;
16
- /**
17
- * This method returns an instruction that closes a lookup table. That lookup table needs to be disabled at least 500 blocks before closing it.
18
- * @param payer - the owner of the lookup table
19
- * @param lookupTable - the lookup table to close
20
- * @returns - the instruction to close the lookup table
21
- */
22
- export declare function closeLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction;
23
- /**
24
- * Returns the accounts in a lookup table
25
- * @param lookupTable - lookup table to get the accounts from
26
- * @returns - an array of accounts in the lookup table
27
- */
28
- export declare function getAccountsInLUT(connection: Connection, lookupTable: PublicKey): Promise<PublicKey[]>;
29
- //# sourceMappingURL=lut_utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lut_utils.d.ts","sourceRoot":"","sources":["../../src/classes/lut_utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,UAAU,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAE3G;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,sBAAsB,EAAE,SAAS,CAAC,CAQrG;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,GAAG,sBAAsB,CAOxG;AAED;;;;;GAKG;AAEH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,GAAG,sBAAsB,CAQnG;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAO3G"}
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initLookupTableIx = initLookupTableIx;
4
- exports.deactivateLookupTableIx = deactivateLookupTableIx;
5
- exports.closeLookupTableIx = closeLookupTableIx;
6
- exports.getAccountsInLUT = getAccountsInLUT;
7
- const web3_js_1 = require("@solana/web3.js");
8
- /**
9
- * This method retuns an instruction that creates a lookup table, alongside the pubkey of the lookup table
10
- * @param payer - the owner of the lookup table
11
- * @param slot - the current slot
12
- * @returns - the instruction to create the lookup table and its address
13
- */
14
- function initLookupTableIx(payer, slot) {
15
- const [ixn, address] = web3_js_1.AddressLookupTableProgram.createLookupTable({
16
- authority: payer,
17
- payer,
18
- recentSlot: slot,
19
- });
20
- return [ixn, address];
21
- }
22
- /**
23
- * This method retuns an instruction that deactivates a lookup table, which is needed to close it
24
- * @param payer - the owner of the lookup table
25
- * @param lookupTable - the lookup table to deactivate
26
- * @returns - the instruction to deactivate the lookup table
27
- */
28
- function deactivateLookupTableIx(payer, lookupTable) {
29
- const ixn = web3_js_1.AddressLookupTableProgram.deactivateLookupTable({
30
- authority: payer,
31
- lookupTable: lookupTable,
32
- });
33
- return ixn;
34
- }
35
- /**
36
- * This method returns an instruction that closes a lookup table. That lookup table needs to be disabled at least 500 blocks before closing it.
37
- * @param payer - the owner of the lookup table
38
- * @param lookupTable - the lookup table to close
39
- * @returns - the instruction to close the lookup table
40
- */
41
- /// this require the LUT to be deactivated at least 500 blocks before
42
- function closeLookupTableIx(payer, lookupTable) {
43
- const ixn = web3_js_1.AddressLookupTableProgram.closeLookupTable({
44
- authority: payer,
45
- recipient: payer,
46
- lookupTable: lookupTable,
47
- });
48
- return ixn;
49
- }
50
- /**
51
- * Returns the accounts in a lookup table
52
- * @param lookupTable - lookup table to get the accounts from
53
- * @returns - an array of accounts in the lookup table
54
- */
55
- async function getAccountsInLUT(connection, lookupTable) {
56
- const lutState = await connection.getAddressLookupTable(lookupTable);
57
- if (!lutState || !lutState.value) {
58
- throw new Error(`Lookup table ${lookupTable} not found`);
59
- }
60
- return lutState.value.state.addresses;
61
- }
62
- //# sourceMappingURL=lut_utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lut_utils.js","sourceRoot":"","sources":["../../src/classes/lut_utils.ts"],"names":[],"mappings":";;AAQA,8CAQC;AAQD,0DAOC;AASD,gDAQC;AAOD,4CAOC;AA9DD,6CAA2G;AAE3G;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,KAAgB,EAAE,IAAY;IAC9D,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,mCAAyB,CAAC,iBAAiB,CAAC;QACjE,SAAS,EAAE,KAAK;QAChB,KAAK;QACL,UAAU,EAAE,IAAI;KACjB,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACxB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,KAAgB,EAAE,WAAsB;IAC9E,MAAM,GAAG,GAAG,mCAAyB,CAAC,qBAAqB,CAAC;QAC1D,SAAS,EAAE,KAAK;QAChB,WAAW,EAAE,WAAW;KACzB,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;GAKG;AACH,qEAAqE;AACrE,SAAgB,kBAAkB,CAAC,KAAgB,EAAE,WAAsB;IACzE,MAAM,GAAG,GAAG,mCAAyB,CAAC,gBAAgB,CAAC;QACrD,SAAS,EAAE,KAAK;QAChB,SAAS,EAAE,KAAK;QAChB,WAAW,EAAE,WAAW;KACzB,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,gBAAgB,CAAC,UAAsB,EAAE,WAAsB;IACnF,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;IACrE,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,gBAAgB,WAAW,YAAY,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC;AACxC,CAAC"}
@@ -1,63 +0,0 @@
1
- import { AddressLookupTableProgram, Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
2
-
3
- /**
4
- * This method retuns an instruction that creates a lookup table, alongside the pubkey of the lookup table
5
- * @param payer - the owner of the lookup table
6
- * @param slot - the current slot
7
- * @returns - the instruction to create the lookup table and its address
8
- */
9
- export function initLookupTableIx(payer: PublicKey, slot: number): [TransactionInstruction, PublicKey] {
10
- const [ixn, address] = AddressLookupTableProgram.createLookupTable({
11
- authority: payer,
12
- payer,
13
- recentSlot: slot,
14
- });
15
-
16
- return [ixn, address];
17
- }
18
-
19
- /**
20
- * This method retuns an instruction that deactivates a lookup table, which is needed to close it
21
- * @param payer - the owner of the lookup table
22
- * @param lookupTable - the lookup table to deactivate
23
- * @returns - the instruction to deactivate the lookup table
24
- */
25
- export function deactivateLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
26
- const ixn = AddressLookupTableProgram.deactivateLookupTable({
27
- authority: payer,
28
- lookupTable: lookupTable,
29
- });
30
-
31
- return ixn;
32
- }
33
-
34
- /**
35
- * This method returns an instruction that closes a lookup table. That lookup table needs to be disabled at least 500 blocks before closing it.
36
- * @param payer - the owner of the lookup table
37
- * @param lookupTable - the lookup table to close
38
- * @returns - the instruction to close the lookup table
39
- */
40
- /// this require the LUT to be deactivated at least 500 blocks before
41
- export function closeLookupTableIx(payer: PublicKey, lookupTable: PublicKey): TransactionInstruction {
42
- const ixn = AddressLookupTableProgram.closeLookupTable({
43
- authority: payer,
44
- recipient: payer,
45
- lookupTable: lookupTable,
46
- });
47
-
48
- return ixn;
49
- }
50
-
51
- /**
52
- * Returns the accounts in a lookup table
53
- * @param lookupTable - lookup table to get the accounts from
54
- * @returns - an array of accounts in the lookup table
55
- */
56
- export async function getAccountsInLUT(connection: Connection, lookupTable: PublicKey): Promise<PublicKey[]> {
57
- const lutState = await connection.getAddressLookupTable(lookupTable);
58
- if (!lutState || !lutState.value) {
59
- throw new Error(`Lookup table ${lookupTable} not found`);
60
- }
61
-
62
- return lutState.value.state.addresses;
63
- }