@kamino-finance/klend-sdk 5.11.0-beta.0 → 5.11.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 +16 -17
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +61 -102
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +16 -4
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +28 -3
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligation.d.ts +6 -1
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +4 -2
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts +2 -2
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +15 -11
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/types.d.ts +4 -0
- package/dist/classes/types.d.ts.map +1 -1
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +1 -2
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +18 -4
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +87 -30
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +8 -3
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl.json +199 -152
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +15 -0
- package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/LendingMarket.js +11 -1
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/errors/custom.d.ts +18 -2
- package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen/errors/custom.js +31 -3
- package/dist/idl_codegen/errors/custom.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js.map +1 -1
- package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts +52 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.js +219 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.js.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/index.d.ts +2 -2
- package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/index.js +3 -3
- package/dist/idl_codegen/instructions/index.js.map +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReserve.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.js +5 -0
- package/dist/idl_codegen/instructions/initReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js +2 -2
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js +2 -2
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemFees.js +1 -1
- package/dist/idl_codegen/instructions/redeemFees.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js +2 -2
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +13 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +25 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/idl_codegen/types/index.d.ts +2 -2
- package/dist/idl_codegen/types/index.d.ts.map +1 -1
- package/dist/idl_codegen/types/index.js.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +10 -4
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.js +9 -7
- package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +3 -0
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +7 -1
- 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/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/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/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.js +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +5 -3
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +1 -1
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +12 -10
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/instructions.d.ts +1 -2
- package/dist/leverage/instructions.d.ts.map +1 -1
- package/dist/leverage/instructions.js +2 -6
- package/dist/leverage/instructions.js.map +1 -1
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +19 -13
- package/dist/leverage/operations.js.map +1 -1
- package/dist/utils/ata.d.ts +1 -1
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +2 -2
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/constants.d.ts +5 -9
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +6 -10
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/instruction.d.ts.map +1 -1
- package/dist/utils/instruction.js +1 -3
- package/dist/utils/instruction.js.map +1 -1
- package/dist/utils/managerTypes.d.ts +1 -0
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +2 -1
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +7 -7
- package/src/classes/action.ts +77 -105
- package/src/classes/manager.ts +35 -3
- package/src/classes/obligation.ts +8 -4
- package/src/classes/reserve.ts +16 -13
- package/src/classes/types.ts +5 -0
- package/src/classes/utils.ts +3 -3
- package/src/classes/vault.ts +103 -45
- package/src/client_kamino_manager.ts +10 -3
- package/src/idl.json +199 -152
- package/src/idl_codegen/accounts/LendingMarket.ts +21 -1
- package/src/idl_codegen/errors/custom.ts +39 -2
- package/src/idl_codegen/instructions/borrowObligationLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/borrowObligationLiquidityV2.ts +1 -1
- package/src/idl_codegen/instructions/depositAndWithdraw.ts +241 -0
- package/src/idl_codegen/instructions/depositReserveLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.ts +1 -1
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.ts +1 -1
- package/src/idl_codegen/instructions/index.ts +4 -4
- package/src/idl_codegen/instructions/initFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/initObligationFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/initReserve.ts +6 -0
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.ts +2 -2
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.ts +2 -2
- package/src/idl_codegen/instructions/redeemFees.ts +1 -1
- package/src/idl_codegen/instructions/redeemReserveCollateral.ts +1 -1
- package/src/idl_codegen/instructions/refreshObligationFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/repayAndWithdrawAndRedeem.ts +2 -2
- package/src/idl_codegen/instructions/repayObligationLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/repayObligationLiquidityV2.ts +1 -1
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +1 -1
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts +1 -1
- package/src/idl_codegen/instructions/withdrawProtocolFee.ts +1 -1
- package/src/idl_codegen/instructions/withdrawReferrerFees.ts +1 -1
- package/src/idl_codegen/types/UpdateLendingMarketMode.ts +30 -0
- package/src/idl_codegen/types/index.ts +2 -0
- package/src/idl_codegen/zero_padding/ObligationZP.ts +12 -6
- package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +9 -1
- package/src/idl_codegen_kamino_vault/errors/custom.ts +42 -0
- package/src/idl_codegen_kamino_vault/instructions/initVault.ts +2 -0
- package/src/idl_codegen_kamino_vault/instructions/updateReserveAllocation.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 +30 -3
- package/src/lending_operations/repay_with_collateral_operations.ts +1 -0
- package/src/lending_operations/swap_collateral_operations.ts +6 -5
- package/src/leverage/calcs.ts +16 -13
- package/src/leverage/instructions.ts +1 -6
- package/src/leverage/operations.ts +28 -18
- package/src/utils/ata.ts +1 -1
- package/src/utils/constants.ts +6 -11
- package/src/utils/instruction.ts +1 -3
- package/src/utils/managerTypes.ts +1 -0
- package/src/utils/userMetadata.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kamino-finance/klend-sdk",
|
|
3
|
-
"version": "5.11.
|
|
3
|
+
"version": "5.11.1",
|
|
4
4
|
"description": "Typescript SDK for interacting with the Kamino Lending (klend) protocol",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"build": "rm -rf dist/; tsc",
|
|
32
32
|
"build:test": "yarn tsc --project ./tests/tsconfig.json",
|
|
33
33
|
"build:watch": "yarn tsc --watch",
|
|
34
|
-
"test": "
|
|
35
|
-
"test-v2": "USE_V2=true
|
|
34
|
+
"test": "yarn ts-mocha ./tests/**/*.test.ts ./tests/*.test.ts --parallel --exit",
|
|
35
|
+
"test-v2": "USE_V2=true yarn ts-mocha ./tests/**/*.test.ts ./tests/*.test.ts --parallel --exit",
|
|
36
36
|
"watch": "tsc --watch",
|
|
37
37
|
"coverage": "jest --coverage",
|
|
38
38
|
"clean": "rm -rf dist/",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@coral-xyz/anchor": "^0.28.0",
|
|
58
58
|
"@coral-xyz/borsh": "^0.28.0",
|
|
59
|
-
"@kamino-finance/farms-sdk": "2.
|
|
60
|
-
"@kamino-finance/kliquidity-sdk": "^7.0.
|
|
59
|
+
"@kamino-finance/farms-sdk": "2.4.2",
|
|
60
|
+
"@kamino-finance/kliquidity-sdk": "^7.0.13",
|
|
61
61
|
"@kamino-finance/scope-sdk": "^8.0.3",
|
|
62
62
|
"@solana/buffer-layout": "^4.0.0",
|
|
63
63
|
"@solana/spl-token": "^0.4.8",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@orca-so/sdk": "^1.2.25",
|
|
79
79
|
"@orca-so/whirlpool-sdk": "^0.4.2",
|
|
80
|
-
"@raydium-io/raydium-sdk": "
|
|
80
|
+
"@raydium-io/raydium-sdk-v2": "=0.1.111-alpha",
|
|
81
81
|
"@types/bn.js": "^5.1.1",
|
|
82
82
|
"@types/bs58": "^4.0.1",
|
|
83
83
|
"@types/chai": "^4.3.5",
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"ts-node": "^10.9.2",
|
|
108
108
|
"tsx": "^4.19.1",
|
|
109
109
|
"typedoc": "^0.22.10",
|
|
110
|
-
"typescript": "^5.7.
|
|
110
|
+
"typescript": "^5.7.3",
|
|
111
111
|
"typescript-eslint": "^0.0.1-alpha.0"
|
|
112
112
|
}
|
|
113
113
|
}
|
package/src/classes/action.ts
CHANGED
|
@@ -60,11 +60,9 @@ import {
|
|
|
60
60
|
createLookupTableIx,
|
|
61
61
|
isNotNullPubkey,
|
|
62
62
|
PublicKeySet,
|
|
63
|
-
WRAPPED_SOL_MINT,
|
|
64
63
|
getAssociatedTokenAddress,
|
|
65
64
|
ScopeRefresh,
|
|
66
65
|
createAtasIdempotent,
|
|
67
|
-
POSITION_LIMIT,
|
|
68
66
|
obligationFarmStatePda,
|
|
69
67
|
} from '../utils';
|
|
70
68
|
import { KaminoMarket } from './market';
|
|
@@ -329,10 +327,6 @@ export class KaminoAction {
|
|
|
329
327
|
...(action === 'depositAndBorrow' ? [outflowReserve!] : []),
|
|
330
328
|
]).toArray().length;
|
|
331
329
|
|
|
332
|
-
if (distinctReserveCount > POSITION_LIMIT) {
|
|
333
|
-
throw Error(`Obligation already has max number of positions: ${POSITION_LIMIT}`);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
330
|
return {
|
|
337
331
|
kaminoObligation,
|
|
338
332
|
depositReserves,
|
|
@@ -421,6 +415,7 @@ export class KaminoAction {
|
|
|
421
415
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
422
416
|
requestElevationGroup: boolean = false, // to be requested *before* the deposit
|
|
423
417
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
418
|
+
createLookupTable: boolean = true,
|
|
424
419
|
referrer: PublicKey = PublicKey.default,
|
|
425
420
|
currentSlot: number = 0,
|
|
426
421
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' },
|
|
@@ -459,6 +454,7 @@ export class KaminoAction {
|
|
|
459
454
|
includeUserMetadata,
|
|
460
455
|
addInitObligationForFarm,
|
|
461
456
|
useV2Ixs,
|
|
457
|
+
createLookupTable,
|
|
462
458
|
undefined,
|
|
463
459
|
overrideElevationGroupRequest
|
|
464
460
|
);
|
|
@@ -521,6 +517,7 @@ export class KaminoAction {
|
|
|
521
517
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
522
518
|
requestElevationGroup: boolean = false,
|
|
523
519
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
520
|
+
createLookupTable: boolean = true,
|
|
524
521
|
referrer: PublicKey = PublicKey.default,
|
|
525
522
|
currentSlot: number = 0,
|
|
526
523
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' },
|
|
@@ -559,6 +556,7 @@ export class KaminoAction {
|
|
|
559
556
|
includeUserMetadata,
|
|
560
557
|
addInitObligationForFarm,
|
|
561
558
|
useV2Ixs,
|
|
559
|
+
createLookupTable,
|
|
562
560
|
undefined,
|
|
563
561
|
overrideElevationGroupRequest
|
|
564
562
|
);
|
|
@@ -581,7 +579,6 @@ export class KaminoAction {
|
|
|
581
579
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
582
580
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
|
|
583
581
|
requestElevationGroup: boolean = false,
|
|
584
|
-
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
585
582
|
referrer: PublicKey = PublicKey.default,
|
|
586
583
|
currentSlot: number = 0,
|
|
587
584
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
@@ -617,8 +614,9 @@ export class KaminoAction {
|
|
|
617
614
|
'mint',
|
|
618
615
|
includeAtaIxns,
|
|
619
616
|
requestElevationGroup,
|
|
620
|
-
|
|
617
|
+
false,
|
|
621
618
|
addInitObligationForFarm,
|
|
619
|
+
false,
|
|
622
620
|
false
|
|
623
621
|
);
|
|
624
622
|
axn.addDepositReserveLiquidityIx();
|
|
@@ -635,7 +633,6 @@ export class KaminoAction {
|
|
|
635
633
|
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ixn
|
|
636
634
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
|
|
637
635
|
requestElevationGroup: boolean = false,
|
|
638
|
-
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
639
636
|
referrer: PublicKey = PublicKey.default,
|
|
640
637
|
currentSlot: number = 0,
|
|
641
638
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
@@ -671,8 +668,9 @@ export class KaminoAction {
|
|
|
671
668
|
'redeem',
|
|
672
669
|
includeAtaIxns,
|
|
673
670
|
requestElevationGroup,
|
|
674
|
-
|
|
671
|
+
false,
|
|
675
672
|
addInitObligationForFarm,
|
|
673
|
+
false,
|
|
676
674
|
false
|
|
677
675
|
);
|
|
678
676
|
axn.addRedeemReserveCollateralIx();
|
|
@@ -691,6 +689,7 @@ export class KaminoAction {
|
|
|
691
689
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas
|
|
692
690
|
requestElevationGroup: boolean = false,
|
|
693
691
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
692
|
+
createLookupTable: boolean = true,
|
|
694
693
|
referrer: PublicKey = PublicKey.default,
|
|
695
694
|
currentSlot: number = 0,
|
|
696
695
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
@@ -728,7 +727,8 @@ export class KaminoAction {
|
|
|
728
727
|
requestElevationGroup,
|
|
729
728
|
includeUserMetadata,
|
|
730
729
|
addInitObligationForFarm,
|
|
731
|
-
useV2Ixs
|
|
730
|
+
useV2Ixs,
|
|
731
|
+
createLookupTable
|
|
732
732
|
);
|
|
733
733
|
if (useV2Ixs) {
|
|
734
734
|
axn.addDepositObligationCollateralIxV2();
|
|
@@ -752,6 +752,7 @@ export class KaminoAction {
|
|
|
752
752
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
753
753
|
requestElevationGroup: boolean = false,
|
|
754
754
|
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
755
|
+
createLookupTable: boolean = true,
|
|
755
756
|
referrer: PublicKey = PublicKey.default,
|
|
756
757
|
currentSlot: number = 0,
|
|
757
758
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
@@ -796,6 +797,7 @@ export class KaminoAction {
|
|
|
796
797
|
includeUserMetadata,
|
|
797
798
|
addInitObligationForFarmForDeposit,
|
|
798
799
|
useV2Ixs,
|
|
800
|
+
createLookupTable,
|
|
799
801
|
twoTokenAction
|
|
800
802
|
);
|
|
801
803
|
|
|
@@ -829,6 +831,7 @@ export class KaminoAction {
|
|
|
829
831
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
830
832
|
requestElevationGroup: boolean = false,
|
|
831
833
|
includeUserMetadata: boolean = true, // if true it includes user metadata,
|
|
834
|
+
createLookupTable: boolean = true,
|
|
832
835
|
referrer: PublicKey = PublicKey.default,
|
|
833
836
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
834
837
|
) {
|
|
@@ -871,13 +874,17 @@ export class KaminoAction {
|
|
|
871
874
|
includeUserMetadata,
|
|
872
875
|
addInitObligationForFarmForRepay,
|
|
873
876
|
useV2Ixs,
|
|
877
|
+
createLookupTable,
|
|
874
878
|
twoTokenAction
|
|
875
879
|
);
|
|
880
|
+
|
|
881
|
+
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve!, axn.outflowAmount!);
|
|
876
882
|
if (useV2Ixs) {
|
|
877
|
-
await axn.addRepayAndWithdrawIxsV2();
|
|
883
|
+
await axn.addRepayAndWithdrawIxsV2(withdrawCollateralAmount);
|
|
878
884
|
} else {
|
|
879
|
-
await axn.addRepayAndWithdrawIxs();
|
|
885
|
+
await axn.addRepayAndWithdrawIxs(withdrawCollateralAmount);
|
|
880
886
|
}
|
|
887
|
+
|
|
881
888
|
await axn.addInBetweenIxs(
|
|
882
889
|
'repayAndWithdraw',
|
|
883
890
|
includeAtaIxns,
|
|
@@ -900,6 +907,7 @@ export class KaminoAction {
|
|
|
900
907
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas,
|
|
901
908
|
requestElevationGroup: boolean = false, // to be requested *after* the withdraw
|
|
902
909
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
910
|
+
createLookupTable: boolean = true,
|
|
903
911
|
referrer: PublicKey = PublicKey.default,
|
|
904
912
|
currentSlot: number = 0,
|
|
905
913
|
scopeRefresh: ScopeRefresh | undefined = undefined,
|
|
@@ -946,14 +954,18 @@ export class KaminoAction {
|
|
|
946
954
|
includeUserMetadata,
|
|
947
955
|
addInitObligationForFarm,
|
|
948
956
|
useV2Ixs,
|
|
957
|
+
createLookupTable,
|
|
949
958
|
false,
|
|
950
959
|
overrideElevationGroupRequest
|
|
951
960
|
);
|
|
961
|
+
|
|
962
|
+
const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
|
|
952
963
|
if (useV2Ixs) {
|
|
953
|
-
await axn.addWithdrawIxV2();
|
|
964
|
+
await axn.addWithdrawIxV2(collateralAmount);
|
|
954
965
|
} else {
|
|
955
|
-
await axn.addWithdrawIx();
|
|
966
|
+
await axn.addWithdrawIx(collateralAmount);
|
|
956
967
|
}
|
|
968
|
+
|
|
957
969
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
958
970
|
|
|
959
971
|
return axn;
|
|
@@ -987,6 +999,7 @@ export class KaminoAction {
|
|
|
987
999
|
includeAtaIxns: boolean = true,
|
|
988
1000
|
requestElevationGroup: boolean = false,
|
|
989
1001
|
includeUserMetadata: boolean = true,
|
|
1002
|
+
createLookupTable: boolean = true,
|
|
990
1003
|
referrer: PublicKey = PublicKey.default,
|
|
991
1004
|
scopeRefresh: ScopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }
|
|
992
1005
|
) {
|
|
@@ -1024,7 +1037,8 @@ export class KaminoAction {
|
|
|
1024
1037
|
requestElevationGroup,
|
|
1025
1038
|
includeUserMetadata,
|
|
1026
1039
|
addInitObligationForFarm,
|
|
1027
|
-
useV2Ixs
|
|
1040
|
+
useV2Ixs,
|
|
1041
|
+
createLookupTable
|
|
1028
1042
|
);
|
|
1029
1043
|
if (useV2Ixs) {
|
|
1030
1044
|
await axn.addRepayIxV2();
|
|
@@ -1050,6 +1064,7 @@ export class KaminoAction {
|
|
|
1050
1064
|
includeAtaIxns: boolean = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
|
|
1051
1065
|
requestElevationGroup: boolean = false,
|
|
1052
1066
|
includeUserMetadata: boolean = true, // if true it includes user metadata
|
|
1067
|
+
createLookupTable: boolean = true,
|
|
1053
1068
|
referrer: PublicKey = PublicKey.default,
|
|
1054
1069
|
maxAllowedLtvOverridePercent: number = 0,
|
|
1055
1070
|
currentSlot: number = 0,
|
|
@@ -1092,7 +1107,8 @@ export class KaminoAction {
|
|
|
1092
1107
|
requestElevationGroup,
|
|
1093
1108
|
includeUserMetadata,
|
|
1094
1109
|
addInitObligationForFarm,
|
|
1095
|
-
useV2Ixs
|
|
1110
|
+
useV2Ixs,
|
|
1111
|
+
createLookupTable
|
|
1096
1112
|
);
|
|
1097
1113
|
if (useV2Ixs) {
|
|
1098
1114
|
await axn.addLiquidateIxV2(maxAllowedLtvOverridePercent);
|
|
@@ -1505,16 +1521,7 @@ export class KaminoAction {
|
|
|
1505
1521
|
}
|
|
1506
1522
|
|
|
1507
1523
|
/// @deprecated -- use addWithdrawIxV2 instead
|
|
1508
|
-
async addWithdrawIx() {
|
|
1509
|
-
const collateralExchangeRate = this.reserve.getEstimatedCollateralExchangeRate(
|
|
1510
|
-
this.currentSlot,
|
|
1511
|
-
this.kaminoMarket.state.referralFeeBps
|
|
1512
|
-
);
|
|
1513
|
-
|
|
1514
|
-
const collateralAmount = this.amount.eq(new BN(U64_MAX))
|
|
1515
|
-
? this.amount
|
|
1516
|
-
: new BN(new Decimal(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
|
|
1517
|
-
|
|
1524
|
+
async addWithdrawIx(collateralAmount: BN) {
|
|
1518
1525
|
this.lendingIxsLabels.push(`withdrawObligationCollateralAndRedeemReserveCollateral`);
|
|
1519
1526
|
this.lendingIxs.push(
|
|
1520
1527
|
withdrawObligationCollateralAndRedeemReserveCollateral(
|
|
@@ -1542,17 +1549,7 @@ export class KaminoAction {
|
|
|
1542
1549
|
);
|
|
1543
1550
|
}
|
|
1544
1551
|
|
|
1545
|
-
async addWithdrawIxV2() {
|
|
1546
|
-
const collateralExchangeRate = this.reserve.getEstimatedCollateralExchangeRate(
|
|
1547
|
-
this.currentSlot,
|
|
1548
|
-
this.kaminoMarket.state.referralFeeBps
|
|
1549
|
-
);
|
|
1550
|
-
|
|
1551
|
-
// TODO: Move this side effect from here...
|
|
1552
|
-
const collateralAmount = this.amount.eq(new BN(U64_MAX))
|
|
1553
|
-
? this.amount
|
|
1554
|
-
: new BN(new Decimal(this.amount.toString()).mul(collateralExchangeRate).ceil().toString());
|
|
1555
|
-
|
|
1552
|
+
async addWithdrawIxV2(collateralAmount: BN) {
|
|
1556
1553
|
const farmsAccounts = this.reserve.state.farmCollateral.equals(PublicKey.default)
|
|
1557
1554
|
? {
|
|
1558
1555
|
obligationFarmUserState: PROGRAM_ID,
|
|
@@ -1872,7 +1869,7 @@ export class KaminoAction {
|
|
|
1872
1869
|
this.lendingIxs.push(borrowIx);
|
|
1873
1870
|
}
|
|
1874
1871
|
|
|
1875
|
-
async addRepayAndWithdrawIxs() {
|
|
1872
|
+
async addRepayAndWithdrawIxs(withdrawCollateralAmount: BN) {
|
|
1876
1873
|
this.lendingIxsLabels.push(
|
|
1877
1874
|
`repayObligationLiquidity(reserve=${this.reserve!.address})(obligation=${this.getObligationPda()})`
|
|
1878
1875
|
);
|
|
@@ -1916,17 +1913,10 @@ export class KaminoAction {
|
|
|
1916
1913
|
throw new Error(`outflowAmount not set`);
|
|
1917
1914
|
}
|
|
1918
1915
|
|
|
1919
|
-
const collateralExchangeRate = this.outflowReserve.getEstimatedCollateralExchangeRate(
|
|
1920
|
-
this.currentSlot,
|
|
1921
|
-
this.kaminoMarket.state.referralFeeBps
|
|
1922
|
-
);
|
|
1923
|
-
|
|
1924
1916
|
this.lendingIxs.push(
|
|
1925
1917
|
withdrawObligationCollateralAndRedeemReserveCollateral(
|
|
1926
1918
|
{
|
|
1927
|
-
collateralAmount:
|
|
1928
|
-
? this.outflowAmount
|
|
1929
|
-
: new BN(new Decimal(this.outflowAmount.toString()).mul(collateralExchangeRate).ceil().toString()),
|
|
1919
|
+
collateralAmount: withdrawCollateralAmount,
|
|
1930
1920
|
},
|
|
1931
1921
|
{
|
|
1932
1922
|
owner: this.owner,
|
|
@@ -1949,7 +1939,7 @@ export class KaminoAction {
|
|
|
1949
1939
|
);
|
|
1950
1940
|
}
|
|
1951
1941
|
|
|
1952
|
-
async addRepayAndWithdrawIxsV2() {
|
|
1942
|
+
async addRepayAndWithdrawIxsV2(withdrawCollateralAmount: BN) {
|
|
1953
1943
|
this.lendingIxsLabels.push(
|
|
1954
1944
|
`repayObligationLiquidityV2(reserve=${this.reserve!.address})(obligation=${this.getObligationPda()})`
|
|
1955
1945
|
);
|
|
@@ -2009,11 +1999,6 @@ export class KaminoAction {
|
|
|
2009
1999
|
throw new Error(`outflowAmount not set`);
|
|
2010
2000
|
}
|
|
2011
2001
|
|
|
2012
|
-
const collateralExchangeRate = this.outflowReserve.getEstimatedCollateralExchangeRate(
|
|
2013
|
-
this.currentSlot,
|
|
2014
|
-
this.kaminoMarket.state.referralFeeBps
|
|
2015
|
-
);
|
|
2016
|
-
|
|
2017
2002
|
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(PublicKey.default)
|
|
2018
2003
|
? {
|
|
2019
2004
|
obligationFarmUserState: PROGRAM_ID,
|
|
@@ -2030,9 +2015,7 @@ export class KaminoAction {
|
|
|
2030
2015
|
this.lendingIxs.push(
|
|
2031
2016
|
withdrawObligationCollateralAndRedeemReserveCollateralV2(
|
|
2032
2017
|
{
|
|
2033
|
-
collateralAmount:
|
|
2034
|
-
? this.outflowAmount
|
|
2035
|
-
: new BN(new Decimal(this.outflowAmount.toString()).mul(collateralExchangeRate).ceil().toString()),
|
|
2018
|
+
collateralAmount: withdrawCollateralAmount,
|
|
2036
2019
|
},
|
|
2037
2020
|
{
|
|
2038
2021
|
withdrawAccounts: {
|
|
@@ -2517,13 +2500,24 @@ export class KaminoAction {
|
|
|
2517
2500
|
includeUserMetadata: boolean,
|
|
2518
2501
|
addInitObligationForFarm: boolean,
|
|
2519
2502
|
useV2Ixs: boolean,
|
|
2503
|
+
createLookupTable: boolean,
|
|
2520
2504
|
twoTokenAction: boolean = false,
|
|
2521
2505
|
overrideElevationGroupRequest?: number
|
|
2522
2506
|
) {
|
|
2523
2507
|
if (!['mint', 'redeem'].includes(action)) {
|
|
2524
2508
|
const [, ownerUserMetadata] = await this.kaminoMarket.getUserMetadata(this.owner);
|
|
2525
2509
|
if (!ownerUserMetadata && includeUserMetadata) {
|
|
2526
|
-
|
|
2510
|
+
let lookupTable: PublicKey = PublicKey.default;
|
|
2511
|
+
if (createLookupTable) {
|
|
2512
|
+
const [createLutIx, lookupTableAddress] = await createLookupTableIx(
|
|
2513
|
+
this.kaminoMarket.getConnection(),
|
|
2514
|
+
this.owner
|
|
2515
|
+
);
|
|
2516
|
+
lookupTable = lookupTableAddress;
|
|
2517
|
+
this.setupIxs.push(createLutIx);
|
|
2518
|
+
this.setupIxsLabels.push(`createUserLutIx[${lookupTableAddress.toString()}]`);
|
|
2519
|
+
}
|
|
2520
|
+
this.addInitUserMetadataIxs(lookupTable);
|
|
2527
2521
|
}
|
|
2528
2522
|
|
|
2529
2523
|
if (['borrow', 'withdrawReferrerFees'].includes(action)) {
|
|
@@ -2931,10 +2925,7 @@ export class KaminoAction {
|
|
|
2931
2925
|
}
|
|
2932
2926
|
}
|
|
2933
2927
|
|
|
2934
|
-
private
|
|
2935
|
-
const [createLutIx, lookupTableAddress] = await createLookupTableIx(this.kaminoMarket.getConnection(), this.owner);
|
|
2936
|
-
this.setupIxs.push(createLutIx);
|
|
2937
|
-
this.setupIxsLabels.push(`createUserLutIx[${lookupTableAddress.toString()}]`);
|
|
2928
|
+
private addInitUserMetadataIxs(lookupTableAddress: PublicKey) {
|
|
2938
2929
|
const [userMetadataAddress, _bump] = userMetadataPda(this.owner, this.kaminoMarket.programId);
|
|
2939
2930
|
const referrerUserMetadataAddress = this.referrer.equals(PublicKey.default)
|
|
2940
2931
|
? this.kaminoMarket.programId
|
|
@@ -3014,11 +3005,11 @@ export class KaminoAction {
|
|
|
3014
3005
|
}
|
|
3015
3006
|
|
|
3016
3007
|
private async addAtaIxs(action: ActionType) {
|
|
3017
|
-
if (this.mint.equals(
|
|
3008
|
+
if (this.mint.equals(NATIVE_MINT) || this.secondaryMint?.equals(NATIVE_MINT)) {
|
|
3018
3009
|
await this.updateWSOLAccount(action);
|
|
3019
3010
|
}
|
|
3020
3011
|
|
|
3021
|
-
if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(
|
|
3012
|
+
if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(NATIVE_MINT)) {
|
|
3022
3013
|
const [, createUserTokenAccountIx] = createAssociatedTokenAccountIdempotentInstruction(
|
|
3023
3014
|
this.owner,
|
|
3024
3015
|
this.reserve.getLiquidityMint(),
|
|
@@ -3027,13 +3018,8 @@ export class KaminoAction {
|
|
|
3027
3018
|
this.userTokenAccountAddress
|
|
3028
3019
|
);
|
|
3029
3020
|
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
this.preTxnIxsLabels.push(`CreateLiquidityUserAta[${this.owner}]`);
|
|
3033
|
-
} else {
|
|
3034
|
-
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
3035
|
-
this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
|
|
3036
|
-
}
|
|
3021
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
3022
|
+
this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
|
|
3037
3023
|
}
|
|
3038
3024
|
|
|
3039
3025
|
if (action === 'liquidate') {
|
|
@@ -3048,13 +3034,9 @@ export class KaminoAction {
|
|
|
3048
3034
|
this.outflowReserve.getLiquidityTokenProgram(),
|
|
3049
3035
|
this.userTokenAccountAddress
|
|
3050
3036
|
);
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
} else {
|
|
3055
|
-
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
3056
|
-
this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
3057
|
-
}
|
|
3037
|
+
|
|
3038
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
3039
|
+
this.setupIxsLabels.unshift(`CreateUserAta[${this.userTokenAccountAddress.toBase58()}]`);
|
|
3058
3040
|
|
|
3059
3041
|
const [, createUserCollateralAccountIx] = createAssociatedTokenAccountIdempotentInstruction(
|
|
3060
3042
|
this.owner,
|
|
@@ -3064,23 +3046,15 @@ export class KaminoAction {
|
|
|
3064
3046
|
this.userCollateralAccountAddress
|
|
3065
3047
|
);
|
|
3066
3048
|
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
3070
|
-
} else {
|
|
3071
|
-
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
3072
|
-
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
3073
|
-
}
|
|
3049
|
+
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
3050
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
3074
3051
|
|
|
3075
3052
|
if (!this.additionalTokenAccountAddress) {
|
|
3076
3053
|
throw new Error(`Additional token account address not found ${this.mint}`);
|
|
3077
3054
|
}
|
|
3078
3055
|
}
|
|
3079
3056
|
|
|
3080
|
-
if (
|
|
3081
|
-
action === 'depositAndBorrow' ||
|
|
3082
|
-
(action === 'repayAndWithdraw' && !this.secondaryMint?.equals(WRAPPED_SOL_MINT))
|
|
3083
|
-
) {
|
|
3057
|
+
if (action === 'depositAndBorrow' || (action === 'repayAndWithdraw' && !this.secondaryMint?.equals(NATIVE_MINT))) {
|
|
3084
3058
|
if (!this.additionalTokenAccountAddress) {
|
|
3085
3059
|
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
3086
3060
|
}
|
|
@@ -3128,13 +3102,8 @@ export class KaminoAction {
|
|
|
3128
3102
|
this.userCollateralAccountAddress
|
|
3129
3103
|
);
|
|
3130
3104
|
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
this.preTxnIxsLabels.push(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
3134
|
-
} else {
|
|
3135
|
-
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
3136
|
-
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
3137
|
-
}
|
|
3105
|
+
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
3106
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.userCollateralAccountAddress.toString()}]`);
|
|
3138
3107
|
}
|
|
3139
3108
|
}
|
|
3140
3109
|
|
|
@@ -3177,7 +3146,7 @@ export class KaminoAction {
|
|
|
3177
3146
|
}
|
|
3178
3147
|
|
|
3179
3148
|
let userTokenAccountAddress = this.userTokenAccountAddress;
|
|
3180
|
-
if (this.secondaryMint?.equals(
|
|
3149
|
+
if (this.secondaryMint?.equals(NATIVE_MINT)) {
|
|
3181
3150
|
if (!this.additionalTokenAccountAddress) {
|
|
3182
3151
|
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
3183
3152
|
}
|
|
@@ -3193,7 +3162,7 @@ export class KaminoAction {
|
|
|
3193
3162
|
action === 'deposit' ||
|
|
3194
3163
|
action === 'repay' ||
|
|
3195
3164
|
action === 'mint' ||
|
|
3196
|
-
(action === 'liquidate' && this.secondaryMint?.equals(
|
|
3165
|
+
(action === 'liquidate' && this.secondaryMint?.equals(NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
|
|
3197
3166
|
|
|
3198
3167
|
const transferLamportsIx = SystemProgram.transfer({
|
|
3199
3168
|
fromPubkey: this.owner,
|
|
@@ -3236,14 +3205,6 @@ export class KaminoAction {
|
|
|
3236
3205
|
postIxsLabels.push(`CloseUserAtaSOL[${userTokenAccountAddress}]`);
|
|
3237
3206
|
}
|
|
3238
3207
|
|
|
3239
|
-
// TODO: Consider for liquidations and other types of actions if we have to split up some ixs in 2-3 txs
|
|
3240
|
-
// if (this.positions && this.positions >= POSITION_LIMIT) {
|
|
3241
|
-
// this.preTxnIxs.push(...preIxs);
|
|
3242
|
-
// this.preTxnIxsLabels.push(...preIxsLabels);
|
|
3243
|
-
// this.postTxnIxs.push(...postIxs);
|
|
3244
|
-
// this.postTxnIxsLabels.push(...postIxsLabels);
|
|
3245
|
-
// } else {
|
|
3246
|
-
// }
|
|
3247
3208
|
this.setupIxs.unshift(...preIxs);
|
|
3248
3209
|
this.setupIxsLabels.unshift(...preIxsLabels);
|
|
3249
3210
|
this.cleanupIxs.push(...postIxs);
|
|
@@ -3384,6 +3345,17 @@ export class KaminoAction {
|
|
|
3384
3345
|
};
|
|
3385
3346
|
}
|
|
3386
3347
|
|
|
3348
|
+
getWithdrawCollateralAmount(reserve: KaminoReserve, amount: BN): BN {
|
|
3349
|
+
const collateralExchangeRate = reserve.getEstimatedCollateralExchangeRate(
|
|
3350
|
+
this.currentSlot,
|
|
3351
|
+
this.kaminoMarket.state.referralFeeBps
|
|
3352
|
+
);
|
|
3353
|
+
|
|
3354
|
+
return amount.eq(new BN(U64_MAX))
|
|
3355
|
+
? amount
|
|
3356
|
+
: new BN(new Decimal(amount.toString()).mul(collateralExchangeRate).ceil().toString());
|
|
3357
|
+
}
|
|
3358
|
+
|
|
3387
3359
|
getObligationPda(): PublicKey {
|
|
3388
3360
|
return this.obligation
|
|
3389
3361
|
? this.obligation.obligationAddress
|
package/src/classes/manager.ts
CHANGED
|
@@ -76,6 +76,7 @@ import { getProgramAccounts } from '../utils/rpc';
|
|
|
76
76
|
import { VaultConfigField, VaultConfigFieldKind } from '../idl_codegen_kamino_vault/types';
|
|
77
77
|
import {
|
|
78
78
|
AcceptVaultOwnershipIxs,
|
|
79
|
+
APYs,
|
|
79
80
|
DepositIxs,
|
|
80
81
|
InitVaultIxs,
|
|
81
82
|
ReserveAllocationOverview,
|
|
@@ -186,6 +187,7 @@ export class KaminoManager {
|
|
|
186
187
|
const createReserveInstructions = await createReserveIxs(
|
|
187
188
|
this._connection,
|
|
188
189
|
params.admin,
|
|
190
|
+
params.adminLiquiditySource,
|
|
189
191
|
params.marketAddress,
|
|
190
192
|
params.assetConfig.mint,
|
|
191
193
|
reserveAccount.publicKey,
|
|
@@ -621,6 +623,15 @@ export class KaminoManager {
|
|
|
621
623
|
});
|
|
622
624
|
}
|
|
623
625
|
|
|
626
|
+
/**
|
|
627
|
+
* Get a list of kaminoVaults
|
|
628
|
+
* @param vaults - a list of vaults to get the states for; if not provided, all vaults will be fetched
|
|
629
|
+
* @returns a list of KaminoVaults
|
|
630
|
+
*/
|
|
631
|
+
async getVaults(vaults?: Array<PublicKey>): Promise<Array<KaminoVault | null>> {
|
|
632
|
+
return this._vaultClient.getVaults(vaults);
|
|
633
|
+
}
|
|
634
|
+
|
|
624
635
|
/**
|
|
625
636
|
* Get all token accounts that hold shares for a specific share mint
|
|
626
637
|
* @param shareMint
|
|
@@ -769,14 +780,14 @@ export class KaminoManager {
|
|
|
769
780
|
* This will return the APY of the vault under the assumption that all the available tokens in the vault are all the time invested in the reserves as ratio; for percentage it needs multiplication by 100
|
|
770
781
|
* @param vault - the kamino vault to get APY for
|
|
771
782
|
* @param slot - current slot
|
|
772
|
-
* @param
|
|
773
|
-
* @returns APY for the vault
|
|
783
|
+
* @param [vaultReservesMap] - hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
|
|
784
|
+
* @returns a struct containing estimated gross APY and net APY (gross - vault fees) for the vault
|
|
774
785
|
*/
|
|
775
786
|
async getVaultTheoreticalAPY(
|
|
776
787
|
vault: VaultState,
|
|
777
788
|
slot: number,
|
|
778
789
|
vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>
|
|
779
|
-
): Promise<
|
|
790
|
+
): Promise<APYs> {
|
|
780
791
|
return this._vaultClient.getVaultTheoreticalAPY(vault, slot, vaultReserves);
|
|
781
792
|
}
|
|
782
793
|
|
|
@@ -854,6 +865,15 @@ export class KaminoManager {
|
|
|
854
865
|
return this._vaultClient.loadVaultReserves(vaultState);
|
|
855
866
|
}
|
|
856
867
|
|
|
868
|
+
/**
|
|
869
|
+
* This will load the onchain state for all the reserves that the vaults have allocations for, deduplicating the reserves
|
|
870
|
+
* @param vaults - the vault states to load reserves for
|
|
871
|
+
* @returns a hashmap from each reserve pubkey to the reserve state
|
|
872
|
+
*/
|
|
873
|
+
async loadVaultsReserves(vaults: VaultState[]): Promise<PubkeyHashMap<PublicKey, KaminoReserve>> {
|
|
874
|
+
return this._vaultClient.loadVaultsReserves(vaults);
|
|
875
|
+
}
|
|
876
|
+
|
|
857
877
|
/**
|
|
858
878
|
* This will load the onchain state for all the reserves that the vault has allocations for
|
|
859
879
|
* @param vaultState - the vault state to load reserves for
|
|
@@ -1248,6 +1268,17 @@ const updateLendingMarketConfig = (
|
|
|
1248
1268
|
});
|
|
1249
1269
|
}
|
|
1250
1270
|
break;
|
|
1271
|
+
case 'minInitialDepositAmount':
|
|
1272
|
+
if (!market.minInitialDepositAmount.eq(newMarket.minInitialDepositAmount)) {
|
|
1273
|
+
updateLendingMarketIxnsArgs.push({
|
|
1274
|
+
mode: UpdateLendingMarketMode.UpdateInitialDepositAmount.discriminator,
|
|
1275
|
+
value: updateMarketConfigEncodedValue(
|
|
1276
|
+
UpdateLendingMarketMode.UpdateInitialDepositAmount.discriminator,
|
|
1277
|
+
newMarket.minInitialDepositAmount.toNumber()
|
|
1278
|
+
),
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
break;
|
|
1251
1282
|
default:
|
|
1252
1283
|
assertNever(key);
|
|
1253
1284
|
}
|
|
@@ -1312,6 +1343,7 @@ function updateMarketConfigEncodedValue(
|
|
|
1312
1343
|
case UpdateLendingMarketMode.UpdateMinValueBfSkipPriorityLiqCheck.discriminator:
|
|
1313
1344
|
case UpdateLendingMarketMode.UpdateMinValueLtvSkipPriorityLiqCheck.discriminator:
|
|
1314
1345
|
case UpdateLendingMarketMode.UpdateIndividualAutodeleverageMarginCallPeriodSecs.discriminator:
|
|
1346
|
+
case UpdateLendingMarketMode.UpdateInitialDepositAmount.discriminator:
|
|
1315
1347
|
value = value as number;
|
|
1316
1348
|
buffer.writeBigUint64LE(BigInt(value), 0);
|
|
1317
1349
|
break;
|
|
@@ -105,6 +105,7 @@ export class KaminoObligation {
|
|
|
105
105
|
) {
|
|
106
106
|
this.obligationAddress = obligationAddress;
|
|
107
107
|
this.state = obligation;
|
|
108
|
+
|
|
108
109
|
const { borrows, deposits, refreshedStats } = this.calculatePositions(
|
|
109
110
|
market,
|
|
110
111
|
obligation.deposits,
|
|
@@ -784,20 +785,23 @@ export class KaminoObligation {
|
|
|
784
785
|
return new Decimal(0);
|
|
785
786
|
};
|
|
786
787
|
|
|
787
|
-
|
|
788
|
+
static getOraclePx = (reserve: KaminoReserve) => {
|
|
789
|
+
return reserve.getOracleMarketPrice();
|
|
790
|
+
};
|
|
791
|
+
|
|
792
|
+
calculatePositions(
|
|
788
793
|
market: KaminoMarket,
|
|
789
794
|
obligationDeposits: ObligationCollateral[],
|
|
790
795
|
obligationBorrows: ObligationLiquidity[],
|
|
791
796
|
elevationGroup: number,
|
|
792
797
|
collateralExchangeRates: Map<PublicKey, Decimal>,
|
|
793
|
-
cumulativeBorrowRates: Map<PublicKey, Decimal> | null
|
|
798
|
+
cumulativeBorrowRates: Map<PublicKey, Decimal> | null,
|
|
799
|
+
getOraclePx: (reserve: KaminoReserve) => Decimal = KaminoObligation.getOraclePx
|
|
794
800
|
): {
|
|
795
801
|
borrows: Map<PublicKey, Position>;
|
|
796
802
|
deposits: Map<PublicKey, Position>;
|
|
797
803
|
refreshedStats: ObligationStats;
|
|
798
804
|
} {
|
|
799
|
-
const getOraclePx = (reserve: KaminoReserve) => reserve.getOracleMarketPrice();
|
|
800
|
-
|
|
801
805
|
const depositStatsOraclePrice = KaminoObligation.calculateObligationDeposits(
|
|
802
806
|
market,
|
|
803
807
|
obligationDeposits,
|