@kamino-finance/klend-sdk 5.11.2-beta.0 → 5.11.2
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 +2 -12
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +29 -245
- 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/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 +18 -18
- package/dist/classes/vault.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +3 -3
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +6 -6
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.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 +0 -5
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +1 -26
- package/dist/lending_operations/repay_with_collateral_operations.js.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 +1 -11
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +3 -13
- 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 +1 -1
- package/src/classes/action.ts +49 -378
- package/src/classes/lut_utils.ts +63 -0
- package/src/classes/obligation.ts +1 -1
- package/src/classes/vault.ts +15 -15
- package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +8 -8
- package/src/idl_codegen_kamino_vault/instructions/giveUpPendingFees.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/updateSharesMetadata.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/updateVaultConfig.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/withdrawPendingFees.ts +2 -2
- package/src/idl_kamino_vault.json +7 -7
- package/src/lending_operations/repay_with_collateral_calcs.ts +5 -14
- package/src/lending_operations/repay_with_collateral_operations.ts +20 -63
- package/src/utils/lookupTable.ts +0 -62
- package/src/utils/seeds.ts +4 -14
- package/src/utils/userMetadata.ts +14 -14
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
}
|
|
@@ -266,7 +266,7 @@ export class KaminoObligation {
|
|
|
266
266
|
/**
|
|
267
267
|
* @returns total borrow power of the obligation, relative to max LTV of each asset's reserve
|
|
268
268
|
*/
|
|
269
|
-
|
|
269
|
+
getAllowedBorrowValue(): Decimal {
|
|
270
270
|
return new Fraction(this.state.allowedBorrowValueSf).toDecimal();
|
|
271
271
|
}
|
|
272
272
|
|
package/src/classes/vault.ts
CHANGED
|
@@ -82,7 +82,7 @@ import {
|
|
|
82
82
|
import { batchFetch, collToLamportsDecimal, ZERO } from '@kamino-finance/kliquidity-sdk';
|
|
83
83
|
import { FullBPSDecimal } from '@kamino-finance/kliquidity-sdk/dist/utils/CreationParameters';
|
|
84
84
|
import { FarmState } from '@kamino-finance/farms-sdk/dist';
|
|
85
|
-
import { getAccountsInLUT, initLookupTableIx } from '
|
|
85
|
+
import { getAccountsInLUT, initLookupTableIx } from './lut_utils';
|
|
86
86
|
import {
|
|
87
87
|
getFarmStakeIxs,
|
|
88
88
|
getFarmUnstakeAndWithdrawIxs,
|
|
@@ -293,7 +293,7 @@ export class KaminoVaultClient {
|
|
|
293
293
|
);
|
|
294
294
|
|
|
295
295
|
const updateReserveAllocationAccounts: UpdateReserveAllocationAccounts = {
|
|
296
|
-
signer: vaultState.
|
|
296
|
+
signer: vaultState.vaultAdminAuthority,
|
|
297
297
|
vaultState: vault.address,
|
|
298
298
|
baseVaultAuthority: vaultState.baseVaultAuthority,
|
|
299
299
|
reserveCollateralMint: reserveState.collateral.mintPubkey,
|
|
@@ -325,7 +325,7 @@ export class KaminoVaultClient {
|
|
|
325
325
|
accountsToAddToLUT.push(lendingMarketAuth);
|
|
326
326
|
|
|
327
327
|
const insertIntoLUTIxs = await this.insertIntoLookupTableIxs(
|
|
328
|
-
vaultState.
|
|
328
|
+
vaultState.vaultAdminAuthority,
|
|
329
329
|
vaultState.vaultLookupTable,
|
|
330
330
|
accountsToAddToLUT
|
|
331
331
|
);
|
|
@@ -355,12 +355,12 @@ export class KaminoVaultClient {
|
|
|
355
355
|
const vaultState: VaultState = await vault.getState(this.getConnection());
|
|
356
356
|
|
|
357
357
|
const updateVaultConfigAccs: UpdateVaultConfigAccounts = {
|
|
358
|
-
|
|
358
|
+
vaultAdminAuthority: vaultState.vaultAdminAuthority,
|
|
359
359
|
vaultState: vault.address,
|
|
360
360
|
klendProgram: this._kaminoLendProgramId,
|
|
361
361
|
};
|
|
362
362
|
if (signer) {
|
|
363
|
-
updateVaultConfigAccs.
|
|
363
|
+
updateVaultConfigAccs.vaultAdminAuthority = signer;
|
|
364
364
|
}
|
|
365
365
|
|
|
366
366
|
const updateVaultConfigArgs: UpdateVaultConfigArgs = {
|
|
@@ -414,7 +414,7 @@ export class KaminoVaultClient {
|
|
|
414
414
|
if (mode.kind === new VaultConfigField.PendingVaultAdmin().kind) {
|
|
415
415
|
const newPubkey = new PublicKey(value);
|
|
416
416
|
const insertIntoLutIxs = await this.insertIntoLookupTableIxs(
|
|
417
|
-
vaultState.
|
|
417
|
+
vaultState.vaultAdminAuthority,
|
|
418
418
|
vaultState.vaultLookupTable,
|
|
419
419
|
[newPubkey]
|
|
420
420
|
);
|
|
@@ -432,7 +432,7 @@ export class KaminoVaultClient {
|
|
|
432
432
|
farmState!.globalConfig
|
|
433
433
|
);
|
|
434
434
|
const insertIntoLutIxs = await this.insertIntoLookupTableIxs(
|
|
435
|
-
vaultState.
|
|
435
|
+
vaultState.vaultAdminAuthority,
|
|
436
436
|
vaultState.vaultLookupTable,
|
|
437
437
|
keysToAddToLUT
|
|
438
438
|
);
|
|
@@ -481,7 +481,7 @@ export class KaminoVaultClient {
|
|
|
481
481
|
value: string
|
|
482
482
|
): TransactionInstruction {
|
|
483
483
|
const updateVaultConfigAccs: UpdateVaultConfigAccounts = {
|
|
484
|
-
|
|
484
|
+
vaultAdminAuthority: admin,
|
|
485
485
|
vaultState: vault,
|
|
486
486
|
klendProgram: this._kaminoLendProgramId,
|
|
487
487
|
};
|
|
@@ -531,7 +531,7 @@ export class KaminoVaultClient {
|
|
|
531
531
|
|
|
532
532
|
// read the current LUT and create a new one for the new admin and backfill it
|
|
533
533
|
const accountsInExistentLUT = (await getAccountsInLUT(this.getConnection(), vaultState.vaultLookupTable)).filter(
|
|
534
|
-
(account) => !account.equals(vaultState.
|
|
534
|
+
(account) => !account.equals(vaultState.vaultAdminAuthority)
|
|
535
535
|
);
|
|
536
536
|
|
|
537
537
|
const LUTIxs: TransactionInstruction[] = [];
|
|
@@ -574,7 +574,7 @@ export class KaminoVaultClient {
|
|
|
574
574
|
const vaultState: VaultState = await vault.getState(this.getConnection());
|
|
575
575
|
|
|
576
576
|
const giveUpPendingFeesAccounts: GiveUpPendingFeesAccounts = {
|
|
577
|
-
|
|
577
|
+
vaultAdminAuthority: vaultState.vaultAdminAuthority,
|
|
578
578
|
vaultState: vault.address,
|
|
579
579
|
klendProgram: this._kaminoLendProgramId,
|
|
580
580
|
};
|
|
@@ -604,7 +604,7 @@ export class KaminoVaultClient {
|
|
|
604
604
|
): Promise<TransactionInstruction[]> {
|
|
605
605
|
const vaultState: VaultState = await vault.getState(this.getConnection());
|
|
606
606
|
const vaultReservesState = vaultReservesMap ? vaultReservesMap : await this.loadVaultReserves(vaultState);
|
|
607
|
-
const [{ ata: adminTokenAta, createAtaIx }] = createAtasIdempotent(vaultState.
|
|
607
|
+
const [{ ata: adminTokenAta, createAtaIx }] = createAtasIdempotent(vaultState.vaultAdminAuthority, [
|
|
608
608
|
{
|
|
609
609
|
mint: vaultState.tokenMint,
|
|
610
610
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
@@ -1295,7 +1295,7 @@ export class KaminoVaultClient {
|
|
|
1295
1295
|
const lendingMarketAuth = lendingMarketAuthPda(marketAddress, this._kaminoLendProgramId)[0];
|
|
1296
1296
|
|
|
1297
1297
|
const withdrawPendingFeesAccounts: WithdrawPendingFeesAccounts = {
|
|
1298
|
-
|
|
1298
|
+
vaultAdminAuthority: vaultState.vaultAdminAuthority,
|
|
1299
1299
|
vaultState: vault.address,
|
|
1300
1300
|
reserve: reserve.address,
|
|
1301
1301
|
tokenVault: vaultState.tokenVault,
|
|
@@ -1355,7 +1355,7 @@ export class KaminoVaultClient {
|
|
|
1355
1355
|
const vaultState = await vault.getState(this.getConnection());
|
|
1356
1356
|
const allAccountsToBeInserted = [
|
|
1357
1357
|
vault.address,
|
|
1358
|
-
vaultState.
|
|
1358
|
+
vaultState.vaultAdminAuthority,
|
|
1359
1359
|
vaultState.baseVaultAuthority,
|
|
1360
1360
|
vaultState.tokenMint,
|
|
1361
1361
|
vaultState.tokenVault,
|
|
@@ -1400,7 +1400,7 @@ export class KaminoVaultClient {
|
|
|
1400
1400
|
let lut = vaultState.vaultLookupTable;
|
|
1401
1401
|
if (lut.equals(PublicKey.default)) {
|
|
1402
1402
|
const recentSlot = await this.getConnection().getSlot();
|
|
1403
|
-
const [ixn, address] = initLookupTableIx(vaultState.
|
|
1403
|
+
const [ixn, address] = initLookupTableIx(vaultState.vaultAdminAuthority, recentSlot);
|
|
1404
1404
|
setupLUTIfNeededIxs.push(ixn);
|
|
1405
1405
|
lut = address;
|
|
1406
1406
|
|
|
@@ -1420,7 +1420,7 @@ export class KaminoVaultClient {
|
|
|
1420
1420
|
}
|
|
1421
1421
|
ixns.push(
|
|
1422
1422
|
...(await this.insertIntoLookupTableIxs(
|
|
1423
|
-
vaultState.
|
|
1423
|
+
vaultState.vaultAdminAuthority,
|
|
1424
1424
|
lut,
|
|
1425
1425
|
allAccountsToBeInserted,
|
|
1426
1426
|
overridenExistentAccounts
|
|
@@ -5,7 +5,7 @@ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-u
|
|
|
5
5
|
import { PROGRAM_ID } from "../programId"
|
|
6
6
|
|
|
7
7
|
export interface VaultStateFields {
|
|
8
|
-
|
|
8
|
+
vaultAdminAuthority: PublicKey
|
|
9
9
|
baseVaultAuthority: PublicKey
|
|
10
10
|
baseVaultAuthorityBump: BN
|
|
11
11
|
tokenMint: PublicKey
|
|
@@ -43,7 +43,7 @@ export interface VaultStateFields {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export interface VaultStateJSON {
|
|
46
|
-
|
|
46
|
+
vaultAdminAuthority: string
|
|
47
47
|
baseVaultAuthority: string
|
|
48
48
|
baseVaultAuthorityBump: string
|
|
49
49
|
tokenMint: string
|
|
@@ -81,7 +81,7 @@ export interface VaultStateJSON {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
export class VaultState {
|
|
84
|
-
readonly
|
|
84
|
+
readonly vaultAdminAuthority: PublicKey
|
|
85
85
|
readonly baseVaultAuthority: PublicKey
|
|
86
86
|
readonly baseVaultAuthorityBump: BN
|
|
87
87
|
readonly tokenMint: PublicKey
|
|
@@ -122,7 +122,7 @@ export class VaultState {
|
|
|
122
122
|
])
|
|
123
123
|
|
|
124
124
|
static readonly layout = borsh.struct([
|
|
125
|
-
borsh.publicKey("
|
|
125
|
+
borsh.publicKey("vaultAdminAuthority"),
|
|
126
126
|
borsh.publicKey("baseVaultAuthority"),
|
|
127
127
|
borsh.u64("baseVaultAuthorityBump"),
|
|
128
128
|
borsh.publicKey("tokenMint"),
|
|
@@ -160,7 +160,7 @@ export class VaultState {
|
|
|
160
160
|
])
|
|
161
161
|
|
|
162
162
|
constructor(fields: VaultStateFields) {
|
|
163
|
-
this.
|
|
163
|
+
this.vaultAdminAuthority = fields.vaultAdminAuthority
|
|
164
164
|
this.baseVaultAuthority = fields.baseVaultAuthority
|
|
165
165
|
this.baseVaultAuthorityBump = fields.baseVaultAuthorityBump
|
|
166
166
|
this.tokenMint = fields.tokenMint
|
|
@@ -243,7 +243,7 @@ export class VaultState {
|
|
|
243
243
|
const dec = VaultState.layout.decode(data.slice(8))
|
|
244
244
|
|
|
245
245
|
return new VaultState({
|
|
246
|
-
|
|
246
|
+
vaultAdminAuthority: dec.vaultAdminAuthority,
|
|
247
247
|
baseVaultAuthority: dec.baseVaultAuthority,
|
|
248
248
|
baseVaultAuthorityBump: dec.baseVaultAuthorityBump,
|
|
249
249
|
tokenMint: dec.tokenMint,
|
|
@@ -287,7 +287,7 @@ export class VaultState {
|
|
|
287
287
|
|
|
288
288
|
toJSON(): VaultStateJSON {
|
|
289
289
|
return {
|
|
290
|
-
|
|
290
|
+
vaultAdminAuthority: this.vaultAdminAuthority.toString(),
|
|
291
291
|
baseVaultAuthority: this.baseVaultAuthority.toString(),
|
|
292
292
|
baseVaultAuthorityBump: this.baseVaultAuthorityBump.toString(),
|
|
293
293
|
tokenMint: this.tokenMint.toString(),
|
|
@@ -329,7 +329,7 @@ export class VaultState {
|
|
|
329
329
|
|
|
330
330
|
static fromJSON(obj: VaultStateJSON): VaultState {
|
|
331
331
|
return new VaultState({
|
|
332
|
-
|
|
332
|
+
vaultAdminAuthority: new PublicKey(obj.vaultAdminAuthority),
|
|
333
333
|
baseVaultAuthority: new PublicKey(obj.baseVaultAuthority),
|
|
334
334
|
baseVaultAuthorityBump: new BN(obj.baseVaultAuthorityBump),
|
|
335
335
|
tokenMint: new PublicKey(obj.tokenMint),
|
|
@@ -9,7 +9,7 @@ export interface GiveUpPendingFeesArgs {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface GiveUpPendingFeesAccounts {
|
|
12
|
-
|
|
12
|
+
vaultAdminAuthority: PublicKey
|
|
13
13
|
vaultState: PublicKey
|
|
14
14
|
klendProgram: PublicKey
|
|
15
15
|
}
|
|
@@ -22,7 +22,7 @@ export function giveUpPendingFees(
|
|
|
22
22
|
programId: PublicKey = PROGRAM_ID
|
|
23
23
|
) {
|
|
24
24
|
const keys: Array<AccountMeta> = [
|
|
25
|
-
{ pubkey: accounts.
|
|
25
|
+
{ pubkey: accounts.vaultAdminAuthority, isSigner: true, isWritable: true },
|
|
26
26
|
{ pubkey: accounts.vaultState, isSigner: false, isWritable: true },
|
|
27
27
|
{ pubkey: accounts.klendProgram, isSigner: false, isWritable: false },
|
|
28
28
|
]
|
|
@@ -11,7 +11,7 @@ export interface InitializeSharesMetadataArgs {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface InitializeSharesMetadataAccounts {
|
|
14
|
-
|
|
14
|
+
vaultAdminAuthority: PublicKey
|
|
15
15
|
vaultState: PublicKey
|
|
16
16
|
sharesMint: PublicKey
|
|
17
17
|
baseVaultAuthority: PublicKey
|
|
@@ -33,7 +33,7 @@ export function initializeSharesMetadata(
|
|
|
33
33
|
programId: PublicKey = PROGRAM_ID
|
|
34
34
|
) {
|
|
35
35
|
const keys: Array<AccountMeta> = [
|
|
36
|
-
{ pubkey: accounts.
|
|
36
|
+
{ pubkey: accounts.vaultAdminAuthority, isSigner: true, isWritable: true },
|
|
37
37
|
{ pubkey: accounts.vaultState, isSigner: false, isWritable: false },
|
|
38
38
|
{ pubkey: accounts.sharesMint, isSigner: false, isWritable: false },
|
|
39
39
|
{ pubkey: accounts.baseVaultAuthority, isSigner: false, isWritable: false },
|
|
@@ -11,7 +11,7 @@ export interface UpdateSharesMetadataArgs {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface UpdateSharesMetadataAccounts {
|
|
14
|
-
|
|
14
|
+
vaultAdminAuthority: PublicKey
|
|
15
15
|
vaultState: PublicKey
|
|
16
16
|
baseVaultAuthority: PublicKey
|
|
17
17
|
sharesMetadata: PublicKey
|
|
@@ -30,7 +30,7 @@ export function updateSharesMetadata(
|
|
|
30
30
|
programId: PublicKey = PROGRAM_ID
|
|
31
31
|
) {
|
|
32
32
|
const keys: Array<AccountMeta> = [
|
|
33
|
-
{ pubkey: accounts.
|
|
33
|
+
{ pubkey: accounts.vaultAdminAuthority, isSigner: true, isWritable: true },
|
|
34
34
|
{ pubkey: accounts.vaultState, isSigner: false, isWritable: false },
|
|
35
35
|
{ pubkey: accounts.baseVaultAuthority, isSigner: false, isWritable: false },
|
|
36
36
|
{ pubkey: accounts.sharesMetadata, isSigner: false, isWritable: true },
|
|
@@ -10,7 +10,7 @@ export interface UpdateVaultConfigArgs {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface UpdateVaultConfigAccounts {
|
|
13
|
-
|
|
13
|
+
vaultAdminAuthority: PublicKey
|
|
14
14
|
vaultState: PublicKey
|
|
15
15
|
klendProgram: PublicKey
|
|
16
16
|
}
|
|
@@ -26,7 +26,7 @@ export function updateVaultConfig(
|
|
|
26
26
|
programId: PublicKey = PROGRAM_ID
|
|
27
27
|
) {
|
|
28
28
|
const keys: Array<AccountMeta> = [
|
|
29
|
-
{ pubkey: accounts.
|
|
29
|
+
{ pubkey: accounts.vaultAdminAuthority, isSigner: true, isWritable: false },
|
|
30
30
|
{ pubkey: accounts.vaultState, isSigner: false, isWritable: true },
|
|
31
31
|
{ pubkey: accounts.klendProgram, isSigner: false, isWritable: false },
|
|
32
32
|
]
|
|
@@ -5,7 +5,7 @@ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-u
|
|
|
5
5
|
import { PROGRAM_ID } from "../programId"
|
|
6
6
|
|
|
7
7
|
export interface WithdrawPendingFeesAccounts {
|
|
8
|
-
|
|
8
|
+
vaultAdminAuthority: PublicKey
|
|
9
9
|
vaultState: PublicKey
|
|
10
10
|
reserve: PublicKey
|
|
11
11
|
tokenVault: PublicKey
|
|
@@ -29,7 +29,7 @@ export function withdrawPendingFees(
|
|
|
29
29
|
programId: PublicKey = PROGRAM_ID
|
|
30
30
|
) {
|
|
31
31
|
const keys: Array<AccountMeta> = [
|
|
32
|
-
{ pubkey: accounts.
|
|
32
|
+
{ pubkey: accounts.vaultAdminAuthority, isSigner: true, isWritable: true },
|
|
33
33
|
{ pubkey: accounts.vaultState, isSigner: false, isWritable: true },
|
|
34
34
|
{ pubkey: accounts.reserve, isSigner: false, isWritable: true },
|
|
35
35
|
{ pubkey: accounts.tokenVault, isSigner: false, isWritable: true },
|
|
@@ -403,7 +403,7 @@
|
|
|
403
403
|
"name": "updateVaultConfig",
|
|
404
404
|
"accounts": [
|
|
405
405
|
{
|
|
406
|
-
"name": "
|
|
406
|
+
"name": "vaultAdminAuthority",
|
|
407
407
|
"isMut": false,
|
|
408
408
|
"isSigner": true
|
|
409
409
|
},
|
|
@@ -435,7 +435,7 @@
|
|
|
435
435
|
"name": "withdrawPendingFees",
|
|
436
436
|
"accounts": [
|
|
437
437
|
{
|
|
438
|
-
"name": "
|
|
438
|
+
"name": "vaultAdminAuthority",
|
|
439
439
|
"isMut": true,
|
|
440
440
|
"isSigner": true
|
|
441
441
|
},
|
|
@@ -540,7 +540,7 @@
|
|
|
540
540
|
"name": "giveUpPendingFees",
|
|
541
541
|
"accounts": [
|
|
542
542
|
{
|
|
543
|
-
"name": "
|
|
543
|
+
"name": "vaultAdminAuthority",
|
|
544
544
|
"isMut": true,
|
|
545
545
|
"isSigner": true
|
|
546
546
|
},
|
|
@@ -566,7 +566,7 @@
|
|
|
566
566
|
"name": "initializeSharesMetadata",
|
|
567
567
|
"accounts": [
|
|
568
568
|
{
|
|
569
|
-
"name": "
|
|
569
|
+
"name": "vaultAdminAuthority",
|
|
570
570
|
"isMut": true,
|
|
571
571
|
"isSigner": true
|
|
572
572
|
},
|
|
@@ -625,7 +625,7 @@
|
|
|
625
625
|
"name": "updateSharesMetadata",
|
|
626
626
|
"accounts": [
|
|
627
627
|
{
|
|
628
|
-
"name": "
|
|
628
|
+
"name": "vaultAdminAuthority",
|
|
629
629
|
"isMut": true,
|
|
630
630
|
"isSigner": true
|
|
631
631
|
},
|
|
@@ -858,7 +858,7 @@
|
|
|
858
858
|
"kind": "struct",
|
|
859
859
|
"fields": [
|
|
860
860
|
{
|
|
861
|
-
"name": "
|
|
861
|
+
"name": "vaultAdminAuthority",
|
|
862
862
|
"type": "publicKey"
|
|
863
863
|
},
|
|
864
864
|
{
|
|
@@ -2189,4 +2189,4 @@
|
|
|
2189
2189
|
"msg": "Wrong admin or allocation admin"
|
|
2190
2190
|
}
|
|
2191
2191
|
]
|
|
2192
|
-
}
|
|
2192
|
+
}
|
|
@@ -2,7 +2,6 @@ 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';
|
|
6
5
|
|
|
7
6
|
export function calcRepayAmountWithSlippage(
|
|
8
7
|
kaminoMarket: KaminoMarket,
|
|
@@ -103,7 +102,6 @@ export function calcMaxWithdrawCollateral(
|
|
|
103
102
|
.filter((p) => !p.reserveAddress.equals(borrow.reserveAddress))
|
|
104
103
|
.reduce((acc, b) => acc.add(b.marketValueRefreshed), new Decimal('0'));
|
|
105
104
|
}
|
|
106
|
-
const maxWithdrawLtvCheck = getMaxWithdrawLtvCheck(obligation);
|
|
107
105
|
|
|
108
106
|
let remainingDepositsValueWithLtv = new Decimal('0');
|
|
109
107
|
if (obligation.getDeposits().length > 1) {
|
|
@@ -111,13 +109,8 @@ export function calcMaxWithdrawCollateral(
|
|
|
111
109
|
.getDeposits()
|
|
112
110
|
.filter((p) => !p.reserveAddress.equals(deposit.reserveAddress))
|
|
113
111
|
.reduce((acc, d) => {
|
|
114
|
-
const { maxLtv
|
|
115
|
-
|
|
116
|
-
market.getReserveByAddress(d.reserveAddress)!
|
|
117
|
-
);
|
|
118
|
-
const maxWithdrawLtv =
|
|
119
|
-
maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? liquidationLtv : maxLtv;
|
|
120
|
-
return acc.add(d.marketValueRefreshed.mul(maxWithdrawLtv));
|
|
112
|
+
const { maxLtv } = obligation.getLtvForReserve(market, market.getReserveByAddress(d.reserveAddress)!);
|
|
113
|
+
return acc.add(d.marketValueRefreshed.mul(maxLtv));
|
|
121
114
|
}, new Decimal('0'));
|
|
122
115
|
}
|
|
123
116
|
|
|
@@ -130,18 +123,16 @@ export function calcMaxWithdrawCollateral(
|
|
|
130
123
|
repayingAllDebt: repayAmountLamports.gte(borrow.amount),
|
|
131
124
|
};
|
|
132
125
|
} else {
|
|
133
|
-
const { maxLtv: collMaxLtv
|
|
126
|
+
const { maxLtv: collMaxLtv } = obligation.getLtvForReserve(
|
|
134
127
|
market,
|
|
135
128
|
market.getReserveByAddress(depositReserve.address)!
|
|
136
129
|
);
|
|
137
|
-
const maxWithdrawLtv =
|
|
138
|
-
maxWithdrawLtvCheck === MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD ? collLiquidationLtv : collMaxLtv;
|
|
139
130
|
const numerator = deposit.marketValueRefreshed
|
|
140
|
-
.mul(
|
|
131
|
+
.mul(collMaxLtv)
|
|
141
132
|
.add(remainingDepositsValueWithLtv)
|
|
142
133
|
.sub(remainingBorrowsValue);
|
|
143
134
|
|
|
144
|
-
const denominator = depositReserve.getOracleMarketPrice().mul(
|
|
135
|
+
const denominator = depositReserve.getOracleMarketPrice().mul(collMaxLtv);
|
|
145
136
|
const maxCollWithdrawAmount = numerator.div(denominator);
|
|
146
137
|
const withdrawableCollLamports = maxCollWithdrawAmount.mul(depositReserve.getMintFactor()).floor();
|
|
147
138
|
|
|
@@ -56,11 +56,6 @@ interface RepayWithCollSwapInputsProps<QuoteResponse> {
|
|
|
56
56
|
quoter: SwapQuoteProvider<QuoteResponse>;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
export enum MaxWithdrawLtvCheck {
|
|
60
|
-
MAX_LTV,
|
|
61
|
-
LIQUIDATION_THRESHOLD,
|
|
62
|
-
}
|
|
63
|
-
|
|
64
59
|
export async function getRepayWithCollSwapInputs<QuoteResponse>({
|
|
65
60
|
collTokenMint,
|
|
66
61
|
currentSlot,
|
|
@@ -217,17 +212,8 @@ export async function getRepayWithCollIxs<QuoteResponse>({
|
|
|
217
212
|
const { debtRepayAmountLamports, flashRepayAmountLamports, maxCollateralWithdrawLamports, swapQuote } = initialInputs;
|
|
218
213
|
const { inputAmountLamports: collSwapInLamports } = swapInputs;
|
|
219
214
|
|
|
220
|
-
const collReserve = kaminoMarket.getReserveByMint(collTokenMint)
|
|
221
|
-
|
|
222
|
-
if (!collReserve) {
|
|
223
|
-
throw new Error(`Collateral reserve with mint ${collTokenMint} not found in market ${kaminoMarket.getAddress()}`);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
227
|
-
|
|
228
|
-
if (!debtReserve) {
|
|
229
|
-
throw new Error(`Debt reserve with mint ${debtTokenMint} not found in market ${kaminoMarket.getAddress()}`);
|
|
230
|
-
}
|
|
215
|
+
const collReserve = kaminoMarket.getReserveByMint(collTokenMint)!;
|
|
216
|
+
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint)!;
|
|
231
217
|
|
|
232
218
|
// the client should use these values to prevent this input, but the tx may succeed, so we don't want to fail
|
|
233
219
|
// there is also a chance that the tx will consume debt token from the user's ata which they would not expect
|
|
@@ -317,48 +303,25 @@ async function buildRepayWithCollateralIxs(
|
|
|
317
303
|
|
|
318
304
|
const requestElevationGroup = !isClosingPosition && obligation.state.elevationGroup !== 0;
|
|
319
305
|
|
|
320
|
-
const maxWithdrawLtvCheck = getMaxWithdrawLtvCheck(obligation);
|
|
321
|
-
|
|
322
306
|
// 3. Repay using the flash borrowed funds & withdraw collateral to swap and pay the flash loan
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
scopeRefresh
|
|
342
|
-
);
|
|
343
|
-
} else {
|
|
344
|
-
repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawV2Txns(
|
|
345
|
-
market,
|
|
346
|
-
isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
|
|
347
|
-
debtReserve.getLiquidityMint(),
|
|
348
|
-
isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
|
|
349
|
-
collReserve.getLiquidityMint(),
|
|
350
|
-
obligation.state.owner,
|
|
351
|
-
currentSlot,
|
|
352
|
-
obligation,
|
|
353
|
-
0,
|
|
354
|
-
false,
|
|
355
|
-
requestElevationGroup,
|
|
356
|
-
undefined,
|
|
357
|
-
undefined,
|
|
358
|
-
referrer,
|
|
359
|
-
scopeRefresh
|
|
360
|
-
);
|
|
361
|
-
}
|
|
307
|
+
const repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns(
|
|
308
|
+
market,
|
|
309
|
+
isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
|
|
310
|
+
debtReserve.getLiquidityMint(),
|
|
311
|
+
isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
|
|
312
|
+
collReserve.getLiquidityMint(),
|
|
313
|
+
obligation.state.owner,
|
|
314
|
+
currentSlot,
|
|
315
|
+
obligation,
|
|
316
|
+
useV2Ixs,
|
|
317
|
+
0,
|
|
318
|
+
false,
|
|
319
|
+
requestElevationGroup,
|
|
320
|
+
undefined,
|
|
321
|
+
undefined,
|
|
322
|
+
referrer,
|
|
323
|
+
scopeRefresh
|
|
324
|
+
);
|
|
362
325
|
|
|
363
326
|
// 4. Swap collateral to debt to repay flash loan
|
|
364
327
|
const { preActionIxs, swapIxs } = swapQuoteIxs;
|
|
@@ -374,9 +337,3 @@ async function buildRepayWithCollateralIxs(
|
|
|
374
337
|
flashRepayIxn,
|
|
375
338
|
];
|
|
376
339
|
}
|
|
377
|
-
|
|
378
|
-
export const getMaxWithdrawLtvCheck = (obligation: KaminoObligation) => {
|
|
379
|
-
return obligation.refreshedStats.userTotalBorrowBorrowFactorAdjusted.gte(obligation.refreshedStats.borrowLimit)
|
|
380
|
-
? MaxWithdrawLtvCheck.LIQUIDATION_THRESHOLD
|
|
381
|
-
: MaxWithdrawLtvCheck.MAX_LTV;
|
|
382
|
-
};
|
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
|
-
}
|