@kamino-finance/klend-sdk 5.10.35-beta.1 → 5.11.0
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/classes/action.d.ts +24 -26
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +501 -270
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/lut_utils.d.ts +29 -0
- package/dist/classes/lut_utils.d.ts.map +1 -0
- package/dist/classes/lut_utils.js +62 -0
- package/dist/classes/lut_utils.js.map +1 -0
- package/dist/classes/manager.js +1 -1
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligation.d.ts +1 -1
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +1 -1
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/vault.js +6 -6
- package/dist/classes/vault.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +5 -9
- package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +3 -7
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +7 -27
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +5 -0
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +4 -2
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/operations.d.ts +8 -8
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +27 -24
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +4 -1
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/utils/lookupTable.d.ts +0 -27
- package/dist/utils/lookupTable.d.ts.map +1 -1
- package/dist/utils/lookupTable.js +0 -58
- package/dist/utils/lookupTable.js.map +1 -1
- package/dist/utils/seeds.d.ts +3 -9
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +5 -11
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/userMetadata.js +6 -6
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +4 -1
- package/src/classes/action.ts +643 -404
- package/src/classes/lut_utils.ts +63 -0
- package/src/classes/manager.ts +1 -1
- package/src/classes/obligation.ts +1 -1
- package/src/classes/vault.ts +1 -1
- package/src/client.ts +7 -3
- package/src/lending_operations/repay_with_collateral_calcs.ts +5 -14
- package/src/lending_operations/repay_with_collateral_operations.ts +14 -30
- package/src/lending_operations/swap_collateral_operations.ts +11 -0
- package/src/leverage/operations.ts +38 -11
- package/src/leverage/types.ts +4 -1
- package/src/utils/lookupTable.ts +0 -62
- package/src/utils/seeds.ts +7 -12
- package/src/utils/userMetadata.ts +14 -14
package/src/utils/lookupTable.ts
CHANGED
|
@@ -53,65 +53,3 @@ 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
|
-
}
|
package/src/utils/seeds.ts
CHANGED
|
@@ -38,10 +38,11 @@ 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
|
+
|
|
41
42
|
/**
|
|
42
|
-
*
|
|
43
|
+
* User farm state seed
|
|
43
44
|
*/
|
|
44
|
-
export const
|
|
45
|
+
export const BASE_SEED_FARM_USER_STATE = Buffer.from('user');
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
48
|
* Encapsulates all the PDAs for a given reserve
|
|
@@ -187,15 +188,9 @@ export function shortUrlPda(shortUrl: string, programId: PublicKey = PROGRAM_ID)
|
|
|
187
188
|
return PublicKey.findProgramAddressSync([Buffer.from(BASE_SEED_SHORT_URL), Buffer.from(shortUrl)], programId);
|
|
188
189
|
}
|
|
189
190
|
|
|
190
|
-
|
|
191
|
-
* Returns the PDA for the obligation farm state
|
|
192
|
-
* @param farm
|
|
193
|
-
* @param obligation
|
|
194
|
-
* @returns pda
|
|
195
|
-
*/
|
|
196
|
-
export function obligationFarmStatePda(farm: PublicKey, obligation: PublicKey) {
|
|
191
|
+
export function obligationFarmStatePda(obligation: PublicKey, farm: PublicKey, programId: PublicKey = farmsId) {
|
|
197
192
|
return PublicKey.findProgramAddressSync(
|
|
198
|
-
[Buffer.from(
|
|
199
|
-
|
|
200
|
-
)
|
|
193
|
+
[Buffer.from(BASE_SEED_FARM_USER_STATE), farm.toBuffer(), obligation.toBuffer()],
|
|
194
|
+
programId
|
|
195
|
+
);
|
|
201
196
|
}
|
|
@@ -267,18 +267,18 @@ function getMultiplyObligationAndObligationFarmStateAddresses(
|
|
|
267
267
|
if (!collReserve.state.farmCollateral.equals(PublicKey.default)) {
|
|
268
268
|
farmUserStates.push({
|
|
269
269
|
address: obligationFarmStatePda(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
),
|
|
270
|
+
multiplyObligation.toPda(kaminoMarket.getAddress(), user),
|
|
271
|
+
collReserve.state.farmCollateral!
|
|
272
|
+
)[0],
|
|
273
273
|
log: 'collReserve farmState for multiply obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
274
274
|
});
|
|
275
275
|
}
|
|
276
276
|
if (!debtReserve.state.farmDebt.equals(PublicKey.default)) {
|
|
277
277
|
farmUserStates.push({
|
|
278
278
|
address: obligationFarmStatePda(
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
),
|
|
279
|
+
multiplyObligation.toPda(kaminoMarket.getAddress(), user),
|
|
280
|
+
debtReserve.state.farmDebt!
|
|
281
|
+
)[0],
|
|
282
282
|
log: 'debtReserve farmState for multiply obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
283
283
|
});
|
|
284
284
|
}
|
|
@@ -310,18 +310,18 @@ function getLeverageObligationAndObligationFarmStateAddresses(
|
|
|
310
310
|
if (!collReserve.state.farmCollateral.equals(PublicKey.default)) {
|
|
311
311
|
farmUserStates.push({
|
|
312
312
|
address: obligationFarmStatePda(
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
),
|
|
313
|
+
leverageObligation.toPda(kaminoMarket.getAddress(), user),
|
|
314
|
+
collReserve.state.farmCollateral!
|
|
315
|
+
)[0],
|
|
316
316
|
log: 'collReserve farmState for leverage obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
317
317
|
});
|
|
318
318
|
}
|
|
319
319
|
if (!debtReserve.state.farmDebt.equals(PublicKey.default)) {
|
|
320
320
|
farmUserStates.push({
|
|
321
321
|
address: obligationFarmStatePda(
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
),
|
|
322
|
+
leverageObligation.toPda(kaminoMarket.getAddress(), user),
|
|
323
|
+
debtReserve.state.farmDebt!
|
|
324
|
+
)[0],
|
|
325
325
|
log: 'debtReserve farmState for leverage obligation coll: ' + collMintString + ' debt: ' + debtMintString,
|
|
326
326
|
});
|
|
327
327
|
}
|
|
@@ -342,7 +342,7 @@ function getRepayWithCollObligationFarmStateAddresses(
|
|
|
342
342
|
const borrowReserve = kaminoMarket.getReserveByMint(borrow.mintAddress)!;
|
|
343
343
|
if (!borrowReserve.state.farmDebt.equals(PublicKey.default)) {
|
|
344
344
|
farmUserStates.push({
|
|
345
|
-
address: obligationFarmStatePda(borrowReserve.state.farmDebt
|
|
345
|
+
address: obligationFarmStatePda(obligation.obligationAddress, borrowReserve.state.farmDebt!)[0],
|
|
346
346
|
log: 'debtReserve farmState for vanilla obligation: ' + obligationString,
|
|
347
347
|
});
|
|
348
348
|
}
|
|
@@ -352,7 +352,7 @@ function getRepayWithCollObligationFarmStateAddresses(
|
|
|
352
352
|
const depositReserve = kaminoMarket.getReserveByMint(deposit.mintAddress)!;
|
|
353
353
|
if (!depositReserve.state.farmCollateral.equals(PublicKey.default)) {
|
|
354
354
|
farmUserStates.push({
|
|
355
|
-
address: obligationFarmStatePda(depositReserve.state.farmCollateral
|
|
355
|
+
address: obligationFarmStatePda(obligation.obligationAddress, depositReserve.state.farmCollateral!)[0],
|
|
356
356
|
log: 'collReserve farmState for vanilla obligation' + obligationString,
|
|
357
357
|
});
|
|
358
358
|
}
|