@kamino-finance/klend-sdk 5.11.6-beta.0 → 5.11.7
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 +27 -35
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +198 -344
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/index.d.ts +1 -0
- package/dist/classes/index.d.ts.map +1 -1
- package/dist/classes/index.js +1 -0
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/manager.d.ts +6 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +16 -1
- package/dist/classes/manager.js.map +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/types.d.ts.map +1 -1
- package/dist/classes/vault.d.ts +1 -0
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +26 -20
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +11 -0
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +6 -3
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +13 -7
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +25 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.js +43 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.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/initVault.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.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/updateReserveAllocation.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.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/idl_codegen_kamino_vault/types/VaultConfigField.d.ts +13 -0
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js +25 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/index.d.ts +2 -2
- package/dist/idl_codegen_kamino_vault/types/index.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/index.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/accountListing.d.ts +4 -4
- package/dist/utils/accountListing.d.ts.map +1 -1
- package/dist/utils/accountListing.js +3 -3
- package/dist/utils/accountListing.js.map +1 -1
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +7 -1
- package/dist/utils/constants.js.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/dist/utils/oracle.js +4 -3
- package/dist/utils/oracle.js.map +1 -1
- package/package.json +2 -2
- package/src/classes/action.ts +225 -400
- package/src/classes/index.ts +1 -0
- package/src/classes/manager.ts +27 -1
- package/src/classes/market.ts +34 -25
- package/src/classes/obligation.ts +6 -0
- package/src/classes/types.ts +1 -1
- package/src/classes/vault.ts +28 -24
- package/src/client.ts +40 -9
- package/src/client_kamino_manager.ts +15 -0
- package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +17 -9
- package/src/idl_codegen_kamino_vault/errors/custom.ts +42 -0
- package/src/idl_codegen_kamino_vault/instructions/giveUpPendingFees.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/initVault.ts +2 -0
- package/src/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/updateReserveAllocation.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_codegen_kamino_vault/types/VaultConfigField.ts +30 -0
- package/src/idl_codegen_kamino_vault/types/index.ts +2 -0
- package/src/idl_kamino_vault.json +35 -8
- 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/accountListing.ts +11 -7
- package/src/utils/constants.ts +7 -0
- package/src/utils/managerTypes.ts +10 -52
- package/src/utils/oracle.ts +7 -6
|
@@ -43,6 +43,9 @@ export type CustomError =
|
|
|
43
43
|
| ManagementFeeGreaterThanMaxAllowed
|
|
44
44
|
| VaultAUMZero
|
|
45
45
|
| MissingReserveForBatchRefresh
|
|
46
|
+
| MinWithdrawAmountTooBig
|
|
47
|
+
| InvestTooSoon
|
|
48
|
+
| WrongAdminOrAllocationAdmin
|
|
46
49
|
|
|
47
50
|
export class DepositAmountsZero extends Error {
|
|
48
51
|
static readonly code = 7000
|
|
@@ -528,6 +531,39 @@ export class MissingReserveForBatchRefresh extends Error {
|
|
|
528
531
|
}
|
|
529
532
|
}
|
|
530
533
|
|
|
534
|
+
export class MinWithdrawAmountTooBig extends Error {
|
|
535
|
+
static readonly code = 7044
|
|
536
|
+
readonly code = 7044
|
|
537
|
+
readonly name = "MinWithdrawAmountTooBig"
|
|
538
|
+
readonly msg = "Min withdraw amount is too big"
|
|
539
|
+
|
|
540
|
+
constructor(readonly logs?: string[]) {
|
|
541
|
+
super("7044: Min withdraw amount is too big")
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export class InvestTooSoon extends Error {
|
|
546
|
+
static readonly code = 7045
|
|
547
|
+
readonly code = 7045
|
|
548
|
+
readonly name = "InvestTooSoon"
|
|
549
|
+
readonly msg = "Invest is called too soon after last invest"
|
|
550
|
+
|
|
551
|
+
constructor(readonly logs?: string[]) {
|
|
552
|
+
super("7045: Invest is called too soon after last invest")
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
export class WrongAdminOrAllocationAdmin extends Error {
|
|
557
|
+
static readonly code = 7046
|
|
558
|
+
readonly code = 7046
|
|
559
|
+
readonly name = "WrongAdminOrAllocationAdmin"
|
|
560
|
+
readonly msg = "Wrong admin or allocation admin"
|
|
561
|
+
|
|
562
|
+
constructor(readonly logs?: string[]) {
|
|
563
|
+
super("7046: Wrong admin or allocation admin")
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
531
567
|
export function fromCode(code: number, logs?: string[]): CustomError | null {
|
|
532
568
|
switch (code) {
|
|
533
569
|
case 7000:
|
|
@@ -618,6 +654,12 @@ export function fromCode(code: number, logs?: string[]): CustomError | null {
|
|
|
618
654
|
return new VaultAUMZero(logs)
|
|
619
655
|
case 7043:
|
|
620
656
|
return new MissingReserveForBatchRefresh(logs)
|
|
657
|
+
case 7044:
|
|
658
|
+
return new MinWithdrawAmountTooBig(logs)
|
|
659
|
+
case 7045:
|
|
660
|
+
return new InvestTooSoon(logs)
|
|
661
|
+
case 7046:
|
|
662
|
+
return new WrongAdminOrAllocationAdmin(logs)
|
|
621
663
|
}
|
|
622
664
|
|
|
623
665
|
return null
|
|
@@ -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,6 +11,7 @@ export interface InitVaultAccounts {
|
|
|
11
11
|
tokenVault: PublicKey
|
|
12
12
|
baseTokenMint: PublicKey
|
|
13
13
|
sharesMint: PublicKey
|
|
14
|
+
adminTokenAccount: PublicKey
|
|
14
15
|
systemProgram: PublicKey
|
|
15
16
|
rent: PublicKey
|
|
16
17
|
tokenProgram: PublicKey
|
|
@@ -28,6 +29,7 @@ export function initVault(
|
|
|
28
29
|
{ pubkey: accounts.tokenVault, isSigner: false, isWritable: true },
|
|
29
30
|
{ pubkey: accounts.baseTokenMint, isSigner: false, isWritable: false },
|
|
30
31
|
{ pubkey: accounts.sharesMint, isSigner: false, isWritable: true },
|
|
32
|
+
{ pubkey: accounts.adminTokenAccount, isSigner: false, isWritable: true },
|
|
31
33
|
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
|
|
32
34
|
{ pubkey: accounts.rent, isSigner: false, isWritable: false },
|
|
33
35
|
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
@@ -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 },
|
|
@@ -10,7 +10,7 @@ export interface UpdateReserveAllocationArgs {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface UpdateReserveAllocationAccounts {
|
|
13
|
-
|
|
13
|
+
signer: PublicKey
|
|
14
14
|
vaultState: PublicKey
|
|
15
15
|
baseVaultAuthority: PublicKey
|
|
16
16
|
reserveCollateralMint: PublicKey
|
|
@@ -29,7 +29,7 @@ export function updateReserveAllocation(
|
|
|
29
29
|
programId: PublicKey = PROGRAM_ID
|
|
30
30
|
) {
|
|
31
31
|
const keys: Array<AccountMeta> = [
|
|
32
|
-
{ pubkey: accounts.
|
|
32
|
+
{ pubkey: accounts.signer, isSigner: true, isWritable: true },
|
|
33
33
|
{ pubkey: accounts.vaultState, isSigner: false, isWritable: true },
|
|
34
34
|
{ pubkey: accounts.baseVaultAuthority, isSigner: false, isWritable: false },
|
|
35
35
|
{
|
|
@@ -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 },
|
|
@@ -256,6 +256,29 @@ export class Farm {
|
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
+
export interface AllocationAdminJSON {
|
|
260
|
+
kind: "AllocationAdmin"
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export class AllocationAdmin {
|
|
264
|
+
static readonly discriminator = 11
|
|
265
|
+
static readonly kind = "AllocationAdmin"
|
|
266
|
+
readonly discriminator = 11
|
|
267
|
+
readonly kind = "AllocationAdmin"
|
|
268
|
+
|
|
269
|
+
toJSON(): AllocationAdminJSON {
|
|
270
|
+
return {
|
|
271
|
+
kind: "AllocationAdmin",
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
toEncodable() {
|
|
276
|
+
return {
|
|
277
|
+
AllocationAdmin: {},
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
259
282
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
260
283
|
export function fromDecoded(obj: any): types.VaultConfigFieldKind {
|
|
261
284
|
if (typeof obj !== "object") {
|
|
@@ -295,6 +318,9 @@ export function fromDecoded(obj: any): types.VaultConfigFieldKind {
|
|
|
295
318
|
if ("Farm" in obj) {
|
|
296
319
|
return new Farm()
|
|
297
320
|
}
|
|
321
|
+
if ("AllocationAdmin" in obj) {
|
|
322
|
+
return new AllocationAdmin()
|
|
323
|
+
}
|
|
298
324
|
|
|
299
325
|
throw new Error("Invalid enum object")
|
|
300
326
|
}
|
|
@@ -336,6 +362,9 @@ export function fromJSON(
|
|
|
336
362
|
case "Farm": {
|
|
337
363
|
return new Farm()
|
|
338
364
|
}
|
|
365
|
+
case "AllocationAdmin": {
|
|
366
|
+
return new AllocationAdmin()
|
|
367
|
+
}
|
|
339
368
|
}
|
|
340
369
|
}
|
|
341
370
|
|
|
@@ -352,6 +381,7 @@ export function layout(property?: string) {
|
|
|
352
381
|
borsh.struct([], "Name"),
|
|
353
382
|
borsh.struct([], "LookupTable"),
|
|
354
383
|
borsh.struct([], "Farm"),
|
|
384
|
+
borsh.struct([], "AllocationAdmin"),
|
|
355
385
|
])
|
|
356
386
|
if (property !== undefined) {
|
|
357
387
|
return ret.replicate(property)
|
|
@@ -63,6 +63,7 @@ export type VaultConfigFieldKind =
|
|
|
63
63
|
| VaultConfigField.Name
|
|
64
64
|
| VaultConfigField.LookupTable
|
|
65
65
|
| VaultConfigField.Farm
|
|
66
|
+
| VaultConfigField.AllocationAdmin
|
|
66
67
|
export type VaultConfigFieldJSON =
|
|
67
68
|
| VaultConfigField.PerformanceFeeBpsJSON
|
|
68
69
|
| VaultConfigField.ManagementFeeBpsJSON
|
|
@@ -75,6 +76,7 @@ export type VaultConfigFieldJSON =
|
|
|
75
76
|
| VaultConfigField.NameJSON
|
|
76
77
|
| VaultConfigField.LookupTableJSON
|
|
77
78
|
| VaultConfigField.FarmJSON
|
|
79
|
+
| VaultConfigField.AllocationAdminJSON
|
|
78
80
|
|
|
79
81
|
export { VaultAllocation } from "./VaultAllocation"
|
|
80
82
|
export type {
|
|
@@ -35,6 +35,11 @@
|
|
|
35
35
|
"isMut": true,
|
|
36
36
|
"isSigner": false
|
|
37
37
|
},
|
|
38
|
+
{
|
|
39
|
+
"name": "adminTokenAccount",
|
|
40
|
+
"isMut": true,
|
|
41
|
+
"isSigner": false
|
|
42
|
+
},
|
|
38
43
|
{
|
|
39
44
|
"name": "systemProgram",
|
|
40
45
|
"isMut": false,
|
|
@@ -62,7 +67,7 @@
|
|
|
62
67
|
"name": "updateReserveAllocation",
|
|
63
68
|
"accounts": [
|
|
64
69
|
{
|
|
65
|
-
"name": "
|
|
70
|
+
"name": "signer",
|
|
66
71
|
"isMut": true,
|
|
67
72
|
"isSigner": true
|
|
68
73
|
},
|
|
@@ -398,7 +403,7 @@
|
|
|
398
403
|
"name": "updateVaultConfig",
|
|
399
404
|
"accounts": [
|
|
400
405
|
{
|
|
401
|
-
"name": "
|
|
406
|
+
"name": "vaultAdminAuthority",
|
|
402
407
|
"isMut": false,
|
|
403
408
|
"isSigner": true
|
|
404
409
|
},
|
|
@@ -430,7 +435,7 @@
|
|
|
430
435
|
"name": "withdrawPendingFees",
|
|
431
436
|
"accounts": [
|
|
432
437
|
{
|
|
433
|
-
"name": "
|
|
438
|
+
"name": "vaultAdminAuthority",
|
|
434
439
|
"isMut": true,
|
|
435
440
|
"isSigner": true
|
|
436
441
|
},
|
|
@@ -535,7 +540,7 @@
|
|
|
535
540
|
"name": "giveUpPendingFees",
|
|
536
541
|
"accounts": [
|
|
537
542
|
{
|
|
538
|
-
"name": "
|
|
543
|
+
"name": "vaultAdminAuthority",
|
|
539
544
|
"isMut": true,
|
|
540
545
|
"isSigner": true
|
|
541
546
|
},
|
|
@@ -561,7 +566,7 @@
|
|
|
561
566
|
"name": "initializeSharesMetadata",
|
|
562
567
|
"accounts": [
|
|
563
568
|
{
|
|
564
|
-
"name": "
|
|
569
|
+
"name": "vaultAdminAuthority",
|
|
565
570
|
"isMut": true,
|
|
566
571
|
"isSigner": true
|
|
567
572
|
},
|
|
@@ -620,7 +625,7 @@
|
|
|
620
625
|
"name": "updateSharesMetadata",
|
|
621
626
|
"accounts": [
|
|
622
627
|
{
|
|
623
|
-
"name": "
|
|
628
|
+
"name": "vaultAdminAuthority",
|
|
624
629
|
"isMut": true,
|
|
625
630
|
"isSigner": true
|
|
626
631
|
},
|
|
@@ -853,7 +858,7 @@
|
|
|
853
858
|
"kind": "struct",
|
|
854
859
|
"fields": [
|
|
855
860
|
{
|
|
856
|
-
"name": "
|
|
861
|
+
"name": "vaultAdminAuthority",
|
|
857
862
|
"type": "publicKey"
|
|
858
863
|
},
|
|
859
864
|
{
|
|
@@ -996,12 +1001,16 @@
|
|
|
996
1001
|
"name": "padding1",
|
|
997
1002
|
"type": "u64"
|
|
998
1003
|
},
|
|
1004
|
+
{
|
|
1005
|
+
"name": "allocationAdmin",
|
|
1006
|
+
"type": "publicKey"
|
|
1007
|
+
},
|
|
999
1008
|
{
|
|
1000
1009
|
"name": "padding2",
|
|
1001
1010
|
"type": {
|
|
1002
1011
|
"array": [
|
|
1003
1012
|
"u128",
|
|
1004
|
-
|
|
1013
|
+
242
|
|
1005
1014
|
]
|
|
1006
1015
|
}
|
|
1007
1016
|
}
|
|
@@ -1874,6 +1883,9 @@
|
|
|
1874
1883
|
},
|
|
1875
1884
|
{
|
|
1876
1885
|
"name": "Farm"
|
|
1886
|
+
},
|
|
1887
|
+
{
|
|
1888
|
+
"name": "AllocationAdmin"
|
|
1877
1889
|
}
|
|
1878
1890
|
]
|
|
1879
1891
|
}
|
|
@@ -2160,6 +2172,21 @@
|
|
|
2160
2172
|
"code": 7043,
|
|
2161
2173
|
"name": "MissingReserveForBatchRefresh",
|
|
2162
2174
|
"msg": "Missing reserve for batch refresh"
|
|
2175
|
+
},
|
|
2176
|
+
{
|
|
2177
|
+
"code": 7044,
|
|
2178
|
+
"name": "MinWithdrawAmountTooBig",
|
|
2179
|
+
"msg": "Min withdraw amount is too big"
|
|
2180
|
+
},
|
|
2181
|
+
{
|
|
2182
|
+
"code": 7045,
|
|
2183
|
+
"name": "InvestTooSoon",
|
|
2184
|
+
"msg": "Invest is called too soon after last invest"
|
|
2185
|
+
},
|
|
2186
|
+
{
|
|
2187
|
+
"code": 7046,
|
|
2188
|
+
"name": "WrongAdminOrAllocationAdmin",
|
|
2189
|
+
"msg": "Wrong admin or allocation admin"
|
|
2163
2190
|
}
|
|
2164
2191
|
]
|
|
2165
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...
|