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