@kamino-finance/klend-sdk 5.11.3-beta.0 → 5.11.3-beta.1
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 +23 -23
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +149 -69
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +1 -1
- package/dist/classes/manager.js +1 -1
- package/dist/classes/market.d.ts +3 -3
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +16 -30
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +0 -2
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +0 -5
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/vault.js +14 -14
- 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_operations.d.ts +4 -4
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +8 -10
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +2 -2
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +6 -11
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +10 -5
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +13 -6
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/operations.d.ts +7 -9
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +72 -78
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +4 -4
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/utils/ObligationType.d.ts +1 -1
- package/dist/utils/ObligationType.d.ts.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +52 -7
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/oracle.d.ts +3 -3
- package/dist/utils/oracle.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/classes/action.ts +162 -75
- package/src/classes/manager.ts +1 -1
- package/src/classes/market.ts +25 -34
- package/src/classes/obligation.ts +0 -6
- package/src/classes/vault.ts +14 -14
- package/src/client.ts +3 -8
- 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_operations.ts +11 -15
- package/src/lending_operations/swap_collateral_operations.ts +7 -19
- package/src/leverage/calcs.ts +18 -2
- package/src/leverage/operations.ts +72 -114
- package/src/leverage/types.ts +4 -4
- package/src/utils/ObligationType.ts +1 -1
- package/src/utils/managerTypes.ts +52 -10
- package/src/utils/oracle.ts +2 -2
package/src/classes/vault.ts
CHANGED
|
@@ -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
|
package/src/client.ts
CHANGED
|
@@ -22,7 +22,6 @@ import { VanillaObligation } from './utils/ObligationType';
|
|
|
22
22
|
import { parseTokenSymbol } from './classes/utils';
|
|
23
23
|
import { Env, initEnv } from '../tests/runner/setup_utils';
|
|
24
24
|
import { initializeFarmsForReserve } from '../tests/runner/farms/farms_operations';
|
|
25
|
-
import { Scope } from '@kamino-finance/scope-sdk';
|
|
26
25
|
|
|
27
26
|
const STAGING_LENDING_MARKET = new PublicKey('6WVSwDQXrBZeQVnu6hpnsRZhodaJTZBUaC334SiiBKdb');
|
|
28
27
|
const MAINNET_LENDING_MARKET = new PublicKey('7u3HeHxYDLhnCoErrtycNokbQYbWGzLs6JSDqGAv5PfF');
|
|
@@ -310,8 +309,7 @@ async function deposit(connection: Connection, wallet: Keypair, token: string, d
|
|
|
310
309
|
kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
|
|
311
310
|
wallet.publicKey,
|
|
312
311
|
new VanillaObligation(STAGING_LENDING_MARKET),
|
|
313
|
-
true
|
|
314
|
-
{ scope: new Scope('mainnet-beta', connection), scopeFeed: 'hubble' }
|
|
312
|
+
true
|
|
315
313
|
);
|
|
316
314
|
console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
|
|
317
315
|
|
|
@@ -332,8 +330,7 @@ async function withdraw(connection: Connection, wallet: Keypair, token: string,
|
|
|
332
330
|
kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
|
|
333
331
|
wallet.publicKey,
|
|
334
332
|
new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET)),
|
|
335
|
-
true
|
|
336
|
-
{ scope: new Scope('mainnet-beta', connection), scopeFeed: 'hubble' }
|
|
333
|
+
true
|
|
337
334
|
);
|
|
338
335
|
console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
|
|
339
336
|
|
|
@@ -354,8 +351,7 @@ async function borrow(connection: Connection, wallet: Keypair, token: string, bo
|
|
|
354
351
|
kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
|
|
355
352
|
wallet.publicKey,
|
|
356
353
|
new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET)),
|
|
357
|
-
true
|
|
358
|
-
{ scope: new Scope('mainnet-beta', connection), scopeFeed: 'hubble' }
|
|
354
|
+
true
|
|
359
355
|
);
|
|
360
356
|
console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
|
|
361
357
|
|
|
@@ -377,7 +373,6 @@ async function repay(connection: Connection, wallet: Keypair, token: string, bor
|
|
|
377
373
|
wallet.publicKey,
|
|
378
374
|
new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET)),
|
|
379
375
|
true,
|
|
380
|
-
{ scope: new Scope('mainnet-beta', connection), scopeFeed: 'hubble' },
|
|
381
376
|
await connection.getSlot()
|
|
382
377
|
);
|
|
383
378
|
console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
|
|
@@ -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
|
+
}
|
|
@@ -6,13 +6,12 @@ import {
|
|
|
6
6
|
SwapIxs,
|
|
7
7
|
SwapIxsProvider,
|
|
8
8
|
SwapQuoteProvider,
|
|
9
|
-
getScopeRefreshIx,
|
|
10
9
|
} from '../leverage';
|
|
11
10
|
import {
|
|
12
11
|
createAtasIdempotent,
|
|
13
12
|
getComputeBudgetAndPriorityFeeIxns,
|
|
14
13
|
removeBudgetAndAtaIxns,
|
|
15
|
-
|
|
14
|
+
ScopeRefresh,
|
|
16
15
|
U64_MAX,
|
|
17
16
|
uniqueAccounts,
|
|
18
17
|
} from '../utils';
|
|
@@ -52,7 +51,7 @@ interface RepayWithCollSwapInputsProps<QuoteResponse> {
|
|
|
52
51
|
repayAmount: Decimal;
|
|
53
52
|
isClosingPosition: boolean;
|
|
54
53
|
budgetAndPriorityFeeIxs?: TransactionInstruction[];
|
|
55
|
-
|
|
54
|
+
scopeRefresh?: ScopeRefresh;
|
|
56
55
|
useV2Ixs: boolean;
|
|
57
56
|
quoter: SwapQuoteProvider<QuoteResponse>;
|
|
58
57
|
}
|
|
@@ -68,7 +67,7 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
|
|
|
68
67
|
repayAmount,
|
|
69
68
|
isClosingPosition,
|
|
70
69
|
budgetAndPriorityFeeIxs,
|
|
71
|
-
|
|
70
|
+
scopeRefresh,
|
|
72
71
|
useV2Ixs,
|
|
73
72
|
}: RepayWithCollSwapInputsProps<QuoteResponse>): Promise<{
|
|
74
73
|
swapInputs: SwapInputs;
|
|
@@ -127,7 +126,7 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
|
|
|
127
126
|
referrer,
|
|
128
127
|
currentSlot,
|
|
129
128
|
budgetAndPriorityFeeIxs,
|
|
130
|
-
|
|
129
|
+
scopeRefresh,
|
|
131
130
|
{
|
|
132
131
|
preActionIxs: [],
|
|
133
132
|
swapIxs: [],
|
|
@@ -192,7 +191,7 @@ export async function getRepayWithCollIxs<QuoteResponse>({
|
|
|
192
191
|
quoter,
|
|
193
192
|
swapper,
|
|
194
193
|
referrer,
|
|
195
|
-
|
|
194
|
+
scopeRefresh,
|
|
196
195
|
useV2Ixs,
|
|
197
196
|
logger = console.log,
|
|
198
197
|
}: RepayWithCollIxsProps<QuoteResponse>): Promise<RepayWithCollIxsResponse<QuoteResponse>> {
|
|
@@ -207,7 +206,7 @@ export async function getRepayWithCollIxs<QuoteResponse>({
|
|
|
207
206
|
repayAmount,
|
|
208
207
|
isClosingPosition,
|
|
209
208
|
budgetAndPriorityFeeIxs,
|
|
210
|
-
|
|
209
|
+
scopeRefresh,
|
|
211
210
|
useV2Ixs,
|
|
212
211
|
});
|
|
213
212
|
const { debtRepayAmountLamports, flashRepayAmountLamports, maxCollateralWithdrawLamports, swapQuote } = initialInputs;
|
|
@@ -245,7 +244,7 @@ export async function getRepayWithCollIxs<QuoteResponse>({
|
|
|
245
244
|
referrer,
|
|
246
245
|
currentSlot,
|
|
247
246
|
budgetAndPriorityFeeIxs,
|
|
248
|
-
|
|
247
|
+
scopeRefresh,
|
|
249
248
|
swapResponse,
|
|
250
249
|
isClosingPosition,
|
|
251
250
|
debtRepayAmountLamports,
|
|
@@ -269,7 +268,7 @@ async function buildRepayWithCollateralIxs(
|
|
|
269
268
|
referrer: PublicKey,
|
|
270
269
|
currentSlot: number,
|
|
271
270
|
budgetAndPriorityFeeIxs: TransactionInstruction[] | undefined,
|
|
272
|
-
|
|
271
|
+
scopeRefresh: ScopeRefresh | undefined,
|
|
273
272
|
swapQuoteIxs: SwapIxs,
|
|
274
273
|
isClosingPosition: boolean,
|
|
275
274
|
debtRepayAmountLamports: Decimal,
|
|
@@ -287,11 +286,9 @@ async function buildRepayWithCollateralIxs(
|
|
|
287
286
|
const atasAndIxs = createAtasIdempotent(obligation.state.owner, atas);
|
|
288
287
|
const [, { ata: debtTokenAta }] = atasAndIxs;
|
|
289
288
|
|
|
290
|
-
const scopeRefreshIxn = await getScopeRefreshIx(market, collReserve, debtReserve, obligation, scopeRefreshConfig);
|
|
291
|
-
|
|
292
289
|
// 2. Flash borrow & repay the debt to repay amount needed
|
|
293
290
|
const { flashBorrowIxn, flashRepayIxn } = getFlashLoanInstructions({
|
|
294
|
-
borrowIxnIndex: budgetIxns.length + atasAndIxs.length
|
|
291
|
+
borrowIxnIndex: budgetIxns.length + atasAndIxs.length,
|
|
295
292
|
walletPublicKey: obligation.state.owner,
|
|
296
293
|
lendingMarketAuthority: market.getLendingMarketAuthority(),
|
|
297
294
|
lendingMarketAddress: market.getAddress(),
|
|
@@ -317,13 +314,13 @@ async function buildRepayWithCollateralIxs(
|
|
|
317
314
|
currentSlot,
|
|
318
315
|
obligation,
|
|
319
316
|
useV2Ixs,
|
|
320
|
-
undefined,
|
|
321
317
|
0,
|
|
322
318
|
false,
|
|
323
319
|
requestElevationGroup,
|
|
324
320
|
undefined,
|
|
325
321
|
undefined,
|
|
326
|
-
referrer
|
|
322
|
+
referrer,
|
|
323
|
+
scopeRefresh
|
|
327
324
|
);
|
|
328
325
|
|
|
329
326
|
// 4. Swap collateral to debt to repay flash loan
|
|
@@ -331,7 +328,6 @@ async function buildRepayWithCollateralIxs(
|
|
|
331
328
|
const swapInstructions = removeBudgetAndAtaIxns(swapIxs, []);
|
|
332
329
|
|
|
333
330
|
return [
|
|
334
|
-
...scopeRefreshIxn,
|
|
335
331
|
...budgetIxns,
|
|
336
332
|
...atasAndIxs.map((x) => x.createAtaIx),
|
|
337
333
|
flashBorrowIxn,
|
|
@@ -6,14 +6,14 @@ import {
|
|
|
6
6
|
KaminoObligation,
|
|
7
7
|
KaminoReserve,
|
|
8
8
|
} from '../classes';
|
|
9
|
-
import { getFlashLoanInstructions,
|
|
9
|
+
import { getFlashLoanInstructions, SwapIxsProvider, SwapQuoteProvider } from '../leverage';
|
|
10
10
|
import {
|
|
11
11
|
createAtasIdempotent,
|
|
12
12
|
DEFAULT_MAX_COMPUTE_UNITS,
|
|
13
13
|
getAssociatedTokenAddress,
|
|
14
14
|
getComputeBudgetAndPriorityFeeIxns,
|
|
15
15
|
PublicKeySet,
|
|
16
|
-
|
|
16
|
+
ScopeRefresh,
|
|
17
17
|
U64_MAX,
|
|
18
18
|
uniqueAccounts,
|
|
19
19
|
} from '../utils';
|
|
@@ -61,7 +61,7 @@ export interface SwapCollIxnsInputs<QuoteResponse> {
|
|
|
61
61
|
referrer: PublicKey;
|
|
62
62
|
currentSlot: number;
|
|
63
63
|
budgetAndPriorityFeeIxns?: TransactionInstruction[];
|
|
64
|
-
|
|
64
|
+
scopeRefresh?: ScopeRefresh;
|
|
65
65
|
useV2Ixs: boolean;
|
|
66
66
|
quoter: SwapQuoteProvider<QuoteResponse>;
|
|
67
67
|
swapper: SwapIxsProvider<QuoteResponse>;
|
|
@@ -205,7 +205,7 @@ type SwapCollContext<QuoteResponse> = {
|
|
|
205
205
|
referrer: PublicKey;
|
|
206
206
|
currentSlot: number;
|
|
207
207
|
useV2Ixs: boolean;
|
|
208
|
-
|
|
208
|
+
scopeRefresh: ScopeRefresh | undefined;
|
|
209
209
|
logger: (msg: string, ...extra: any[]) => void;
|
|
210
210
|
};
|
|
211
211
|
|
|
@@ -235,7 +235,7 @@ function extractArgsAndContext<QuoteResponse>(
|
|
|
235
235
|
quoter: inputs.quoter,
|
|
236
236
|
swapper: inputs.swapper,
|
|
237
237
|
referrer: inputs.referrer,
|
|
238
|
-
|
|
238
|
+
scopeRefresh: inputs.scopeRefresh,
|
|
239
239
|
currentSlot: inputs.currentSlot,
|
|
240
240
|
useV2Ixs: inputs.useV2Ixs,
|
|
241
241
|
},
|
|
@@ -264,18 +264,6 @@ async function getKlendIxns(
|
|
|
264
264
|
const { ataCreationIxns, targetCollAta } = getAtaCreationIxns(context);
|
|
265
265
|
const setupIxns = [...context.budgetAndPriorityFeeIxns, ...ataCreationIxns];
|
|
266
266
|
|
|
267
|
-
const scopeRefreshIxn = await getScopeRefreshIx(
|
|
268
|
-
context.market,
|
|
269
|
-
context.sourceCollReserve,
|
|
270
|
-
context.targetCollReserve,
|
|
271
|
-
context.obligation,
|
|
272
|
-
context.scopeRefreshConfig
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
if (scopeRefreshIxn) {
|
|
276
|
-
setupIxns.unshift(...scopeRefreshIxn);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
267
|
const targetCollFlashBorrowedAmount = calculateTargetCollFlashBorrowedAmount(targetCollSwapOutAmount, context);
|
|
280
268
|
const { targetCollFlashBorrowIxn, targetCollFlashRepayIxn } = getTargetCollFlashLoanIxns(
|
|
281
269
|
targetCollFlashBorrowedAmount,
|
|
@@ -392,7 +380,6 @@ async function getDepositTargetCollIxns(
|
|
|
392
380
|
context.obligation.state.owner,
|
|
393
381
|
context.obligation,
|
|
394
382
|
context.useV2Ixs,
|
|
395
|
-
undefined, // we create the scope refresh ixn outside of KaminoAction
|
|
396
383
|
0, // no extra compute budget
|
|
397
384
|
false, // we do not need ATA ixns here (we construct and close them ourselves)
|
|
398
385
|
removesElevationGroup, // we may need to (temporarily) remove the elevation group; the same or a different one will be set on withdraw, if requested
|
|
@@ -400,6 +387,7 @@ async function getDepositTargetCollIxns(
|
|
|
400
387
|
false, // we do not need to create a lookup table, dealing with an existing obligation
|
|
401
388
|
context.referrer,
|
|
402
389
|
context.currentSlot,
|
|
390
|
+
context.scopeRefresh,
|
|
403
391
|
removesElevationGroup ? 0 : undefined // only applicable when removing the group
|
|
404
392
|
);
|
|
405
393
|
return {
|
|
@@ -442,7 +430,6 @@ async function getWithdrawSourceCollIxns(
|
|
|
442
430
|
context.obligation.state.owner,
|
|
443
431
|
context.obligation,
|
|
444
432
|
context.useV2Ixs,
|
|
445
|
-
undefined, // we create the scope refresh ixn outside of KaminoAction
|
|
446
433
|
0, // no extra compute budget
|
|
447
434
|
false, // we do not need ATA ixns here (we construct and close them ourselves)
|
|
448
435
|
requestedElevationGroup !== undefined, // the `elevationGroupIdToRequestAfterWithdraw()` has already decided on this
|
|
@@ -450,6 +437,7 @@ async function getWithdrawSourceCollIxns(
|
|
|
450
437
|
false, // we do not need to create a lookup table, dealing with an existing obligation
|
|
451
438
|
context.referrer,
|
|
452
439
|
context.currentSlot,
|
|
440
|
+
undefined, // we have refreshed scope already, during depositing
|
|
453
441
|
requestedElevationGroup,
|
|
454
442
|
context.obligation.deposits.has(context.targetCollReserve.address) // if our obligation already had the target coll...
|
|
455
443
|
? undefined // ... then we need no customizations here, but otherwise...
|