@kamino-finance/klend-sdk 7.1.2 → 7.1.4-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/@codegen/klend/accounts/LendingMarket.d.ts +144 -3
- package/dist/@codegen/klend/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/LendingMarket.js +105 -3
- package/dist/@codegen/klend/accounts/LendingMarket.js.map +1 -1
- package/dist/@codegen/klend/accounts/Obligation.d.ts +30 -15
- package/dist/@codegen/klend/accounts/Obligation.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/Obligation.js +31 -21
- package/dist/@codegen/klend/accounts/Obligation.js.map +1 -1
- package/dist/@codegen/klend/accounts/PoolState.d.ts +53 -0
- package/dist/@codegen/klend/accounts/PoolState.d.ts.map +1 -0
- package/dist/@codegen/klend/accounts/PoolState.js +167 -0
- package/dist/@codegen/klend/accounts/PoolState.js.map +1 -0
- package/dist/@codegen/klend/accounts/Reserve.d.ts +6 -0
- package/dist/@codegen/klend/accounts/Reserve.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/Reserve.js +9 -2
- package/dist/@codegen/klend/accounts/Reserve.js.map +1 -1
- package/dist/@codegen/klend/accounts/UnstakeTicket.d.ts +41 -0
- package/dist/@codegen/klend/accounts/UnstakeTicket.d.ts.map +1 -0
- package/dist/@codegen/klend/accounts/UnstakeTicket.js +143 -0
- package/dist/@codegen/klend/accounts/UnstakeTicket.js.map +1 -0
- package/dist/@codegen/klend/accounts/UserState.d.ts +0 -75
- package/dist/@codegen/klend/accounts/UserState.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/UserState.js +0 -25
- package/dist/@codegen/klend/accounts/UserState.js.map +1 -1
- package/dist/@codegen/klend/accounts/WithdrawTicket.d.ts +132 -0
- package/dist/@codegen/klend/accounts/WithdrawTicket.d.ts.map +1 -0
- package/dist/@codegen/klend/accounts/WithdrawTicket.js +191 -0
- package/dist/@codegen/klend/accounts/WithdrawTicket.js.map +1 -0
- package/dist/@codegen/klend/accounts/index.d.ts +6 -0
- package/dist/@codegen/klend/accounts/index.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/index.js +7 -1
- package/dist/@codegen/klend/accounts/index.js.map +1 -1
- package/dist/@codegen/klend/errors/custom.d.ts +226 -2
- package/dist/@codegen/klend/errors/custom.d.ts.map +1 -1
- package/dist/@codegen/klend/errors/custom.js +396 -3
- package/dist/@codegen/klend/errors/custom.js.map +1 -1
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.d.ts +39 -0
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.js +67 -0
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.js.map +1 -0
- package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts +36 -0
- package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/fillBorrowOrder.js +49 -0
- package/dist/@codegen/klend/instructions/fillBorrowOrder.js.map +1 -0
- package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts +1 -2
- package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/idlMissingTypes.js +6 -2
- package/dist/@codegen/klend/instructions/idlMissingTypes.js.map +1 -1
- package/dist/@codegen/klend/instructions/index.d.ts +16 -0
- package/dist/@codegen/klend/instructions/index.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/index.js +18 -1
- package/dist/@codegen/klend/instructions/index.js.map +1 -1
- package/dist/@codegen/klend/instructions/initReserve.d.ts +1 -1
- package/dist/@codegen/klend/instructions/initReserve.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/initReserve.js +1 -5
- package/dist/@codegen/klend/instructions/initReserve.js.map +1 -1
- package/dist/@codegen/klend/instructions/liquidateObligationAndRedeemReserveCollateral.js +1 -1
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.d.ts +47 -0
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.js +66 -0
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.js.map +1 -0
- package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts +31 -0
- package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/setBorrowOrder.js +64 -0
- package/dist/@codegen/klend/instructions/setBorrowOrder.js.map +1 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.d.ts +53 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.js +190 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.js.map +1 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.d.ts +70 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.js +261 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.js.map +1 -0
- package/dist/@codegen/klend/instructions/updateGlobalConfig.d.ts +1 -1
- package/dist/@codegen/klend/instructions/updateGlobalConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/updateGlobalConfig.js +1 -0
- package/dist/@codegen/klend/instructions/updateGlobalConfig.js.map +1 -1
- package/dist/@codegen/klend/instructions/updateReserveConfig.d.ts +1 -1
- package/dist/@codegen/klend/instructions/updateReserveConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/updateReserveConfig.js +1 -0
- package/dist/@codegen/klend/instructions/updateReserveConfig.js.map +1 -1
- package/dist/@codegen/klend/instructions/withdrawObligationCollateral.js +1 -1
- package/dist/@codegen/klend/instructions/withdrawObligationCollateralV2.js +1 -1
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.d.ts +41 -0
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.js +135 -0
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.js.map +1 -0
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.d.ts +51 -0
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.js +28 -0
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.js.map +1 -0
- package/dist/@codegen/klend/types/BorrowOrder.d.ts +192 -0
- package/dist/@codegen/klend/types/BorrowOrder.d.ts.map +1 -0
- package/dist/@codegen/klend/types/BorrowOrder.js +194 -0
- package/dist/@codegen/klend/types/BorrowOrder.js.map +1 -0
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts +39 -0
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts.map +1 -0
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js +100 -0
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js.map +1 -0
- package/dist/@codegen/klend/types/ObligationLiquidity.d.ts +35 -5
- package/dist/@codegen/klend/types/ObligationLiquidity.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ObligationLiquidity.js +17 -7
- package/dist/@codegen/klend/types/ObligationLiquidity.js.map +1 -1
- package/dist/@codegen/klend/types/ObligationOrder.d.ts +4 -4
- package/dist/@codegen/klend/types/ObligationOrder.js +2 -2
- package/dist/@codegen/klend/types/ReserveConfig.d.ts +141 -29
- package/dist/@codegen/klend/types/ReserveConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveConfig.js +89 -25
- package/dist/@codegen/klend/types/ReserveConfig.js.map +1 -1
- package/dist/@codegen/klend/types/ReserveFees.d.ts +8 -8
- package/dist/@codegen/klend/types/ReserveFees.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveFees.js +8 -8
- package/dist/@codegen/klend/types/ReserveFees.js.map +1 -1
- package/dist/@codegen/klend/types/ReserveLiquidity.d.ts +26 -8
- package/dist/@codegen/klend/types/ReserveLiquidity.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveLiquidity.js +14 -8
- package/dist/@codegen/klend/types/ReserveLiquidity.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateConfigMode.d.ts +92 -14
- package/dist/@codegen/klend/types/UpdateConfigMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateConfigMode.js +168 -23
- package/dist/@codegen/klend/types/UpdateConfigMode.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts +130 -0
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js +241 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/@codegen/klend/types/WithdrawQueue.d.ts +64 -0
- package/dist/@codegen/klend/types/WithdrawQueue.d.ts.map +1 -0
- package/dist/@codegen/klend/types/WithdrawQueue.js +104 -0
- package/dist/@codegen/klend/types/WithdrawQueue.js.map +1 -0
- package/dist/@codegen/klend/types/index.d.ts +10 -8
- package/dist/@codegen/klend/types/index.d.ts.map +1 -1
- package/dist/@codegen/klend/types/index.js +7 -3
- package/dist/@codegen/klend/types/index.js.map +1 -1
- package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts +9 -4
- package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts.map +1 -1
- package/dist/@codegen/klend/zero_padding/ObligationZP.js +22 -13
- package/dist/@codegen/klend/zero_padding/ObligationZP.js.map +1 -1
- package/dist/classes/action.d.ts +30 -3
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +364 -10
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +10 -0
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +6 -2
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +26 -6
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.js +1 -1
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +13 -7
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/unstakingPool.d.ts +20 -3
- package/dist/classes/unstakingPool.d.ts.map +1 -1
- package/dist/classes/unstakingPool.js +62 -8
- package/dist/classes/unstakingPool.js.map +1 -1
- package/dist/idl/klend.json +2125 -232
- package/dist/lending_operations/index.d.ts +1 -0
- package/dist/lending_operations/index.d.ts.map +1 -1
- package/dist/lending_operations/index.js +1 -0
- package/dist/lending_operations/index.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +0 -2
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +0 -1
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/lending_operations/unstake_lst_collateral.d.ts +12 -0
- package/dist/lending_operations/unstake_lst_collateral.d.ts.map +1 -0
- package/dist/lending_operations/unstake_lst_collateral.js +104 -0
- package/dist/lending_operations/unstake_lst_collateral.js.map +1 -0
- package/dist/leverage/calcs.d.ts +2 -27
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +6 -136
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/operations.d.ts +8 -9
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +72 -228
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +0 -19
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/leverage/utils.d.ts +2 -19
- package/dist/leverage/utils.d.ts.map +1 -1
- package/dist/leverage/utils.js +0 -164
- package/dist/leverage/utils.js.map +1 -1
- package/dist/manager/client_kamino_manager.js +11 -8
- package/dist/manager/client_kamino_manager.js.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +9 -4
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/seeds.d.ts +10 -14
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +25 -22
- package/dist/utils/seeds.js.map +1 -1
- package/package.json +2 -2
- package/src/@codegen/klend/accounts/LendingMarket.ts +210 -5
- package/src/@codegen/klend/accounts/Obligation.ts +53 -31
- package/src/@codegen/klend/accounts/PoolState.ts +192 -0
- package/src/@codegen/klend/accounts/Reserve.ts +13 -2
- package/src/@codegen/klend/accounts/UnstakeTicket.ts +160 -0
- package/src/@codegen/klend/accounts/UserState.ts +0 -75
- package/src/@codegen/klend/accounts/WithdrawTicket.ts +256 -0
- package/src/@codegen/klend/accounts/index.ts +6 -0
- package/src/@codegen/klend/errors/custom.ts +427 -2
- package/src/@codegen/klend/instructions/enqueueToWithdraw.ts +89 -0
- package/src/@codegen/klend/instructions/fillBorrowOrder.ts +96 -0
- package/src/@codegen/klend/instructions/idlMissingTypes.ts +7 -4
- package/src/@codegen/klend/instructions/index.ts +34 -0
- package/src/@codegen/klend/instructions/initReserve.ts +2 -6
- package/src/@codegen/klend/instructions/liquidateObligationAndRedeemReserveCollateral.ts +1 -1
- package/src/@codegen/klend/instructions/recoverInvalidTicketCollateral.ts +96 -0
- package/src/@codegen/klend/instructions/setBorrowOrder.ts +77 -0
- package/src/@codegen/klend/instructions/unstakeLstCollateralEnd.ts +251 -0
- package/src/@codegen/klend/instructions/unstakeLstCollateralStart.ts +353 -0
- package/src/@codegen/klend/instructions/updateGlobalConfig.ts +2 -1
- package/src/@codegen/klend/instructions/updateReserveConfig.ts +2 -1
- package/src/@codegen/klend/instructions/withdrawObligationCollateral.ts +1 -1
- package/src/@codegen/klend/instructions/withdrawObligationCollateralV2.ts +1 -1
- package/src/@codegen/klend/instructions/withdrawObligationUsol.ts +168 -0
- package/src/@codegen/klend/instructions/withdrawQueuedLiquidity.ts +92 -0
- package/src/@codegen/klend/types/BorrowOrder.ts +267 -0
- package/src/@codegen/klend/types/BorrowOrderConfigArgs.ts +87 -0
- package/src/@codegen/klend/types/ObligationLiquidity.ts +39 -9
- package/src/@codegen/klend/types/ObligationOrder.ts +4 -4
- package/src/@codegen/klend/types/ReserveConfig.ts +171 -39
- package/src/@codegen/klend/types/ReserveFees.ts +12 -12
- package/src/@codegen/klend/types/ReserveLiquidity.ts +30 -12
- package/src/@codegen/klend/types/UpdateConfigMode.ts +206 -26
- package/src/@codegen/klend/types/UpdateLendingMarketMode.ts +300 -0
- package/src/@codegen/klend/types/WithdrawQueue.ts +117 -0
- package/src/@codegen/klend/types/index.ts +45 -16
- package/src/@codegen/klend/zero_padding/ObligationZP.ts +22 -13
- package/src/classes/action.ts +577 -8
- package/src/classes/manager.ts +11 -0
- package/src/classes/market.ts +36 -5
- package/src/classes/obligation.ts +1 -1
- package/src/classes/reserve.ts +13 -8
- package/src/classes/unstakingPool.ts +83 -6
- package/src/idl/klend.json +2126 -233
- package/src/lending_operations/index.ts +1 -0
- package/src/lending_operations/repay_with_collateral_operations.ts +0 -2
- package/src/lending_operations/swap_collateral_operations.ts +0 -1
- package/src/lending_operations/unstake_lst_collateral.ts +174 -0
- package/src/leverage/calcs.ts +2 -201
- package/src/leverage/operations.ts +45 -377
- package/src/leverage/types.ts +0 -20
- package/src/leverage/utils.ts +3 -320
- package/src/manager/client_kamino_manager.ts +11 -8
- package/src/utils/managerTypes.ts +9 -4
- package/src/utils/seeds.ts +28 -26
- package/dist/@codegen/klend/types/AssetTier.d.ts +0 -45
- package/dist/@codegen/klend/types/AssetTier.d.ts.map +0 -1
- package/dist/@codegen/klend/types/AssetTier.js +0 -132
- package/dist/@codegen/klend/types/AssetTier.js.map +0 -1
- package/src/@codegen/klend/types/AssetTier.ts +0 -119
package/src/leverage/types.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Account, Address, Instruction, Option, Slot, TransactionSigner } from '@solana/kit';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
3
|
import { KaminoMarket, KaminoObligation } from '../classes';
|
|
4
|
-
import { Kamino, StrategyWithAddress } from '@kamino-finance/kliquidity-sdk';
|
|
5
4
|
import { ObligationType, ObligationTypeTag, ScopePriceRefreshConfig } from '../utils';
|
|
6
5
|
import { AddressLookupTable } from '@solana-program/address-lookup-table';
|
|
7
6
|
|
|
@@ -30,8 +29,6 @@ export type SwapIxs<QuoteResponse> = {
|
|
|
30
29
|
|
|
31
30
|
export type PriceAinBProvider = (mintA: Address, mintB: Address) => Promise<Decimal>;
|
|
32
31
|
|
|
33
|
-
export type IsKtokenProvider = (token: Address) => Promise<boolean>;
|
|
34
|
-
|
|
35
32
|
export type FlashLoanInfo = {
|
|
36
33
|
flashBorrowReserve: Address;
|
|
37
34
|
flashLoanFee: Decimal;
|
|
@@ -47,7 +44,6 @@ export type SwapInputs = {
|
|
|
47
44
|
minOutAmountLamports?: Decimal;
|
|
48
45
|
inputMint: Address;
|
|
49
46
|
outputMint: Address;
|
|
50
|
-
amountDebtAtaBalance: Decimal | undefined;
|
|
51
47
|
};
|
|
52
48
|
|
|
53
49
|
export type BaseLeverageIxsResponse<QuoteResponse> = {
|
|
@@ -63,9 +59,7 @@ export type LeverageInitialInputs<LeverageCalcsResult, QuoteResponse> = {
|
|
|
63
59
|
swapQuote: SwapQuote<QuoteResponse>;
|
|
64
60
|
currentSlot: Slot;
|
|
65
61
|
klendAccounts: Array<Address>;
|
|
66
|
-
collIsKtoken: boolean;
|
|
67
62
|
obligation: KaminoObligation | ObligationType | undefined;
|
|
68
|
-
strategy: StrategyWithAddress | undefined;
|
|
69
63
|
};
|
|
70
64
|
|
|
71
65
|
export interface BaseLeverageSwapInputsProps<QuoteResponse> {
|
|
@@ -77,10 +71,8 @@ export interface BaseLeverageSwapInputsProps<QuoteResponse> {
|
|
|
77
71
|
currentSlot: Slot;
|
|
78
72
|
slippagePct: Decimal;
|
|
79
73
|
budgetAndPriorityFeeIxs?: Instruction[];
|
|
80
|
-
kamino: Kamino | undefined;
|
|
81
74
|
scopeRefreshConfig?: ScopePriceRefreshConfig;
|
|
82
75
|
quoteBufferBps: Decimal;
|
|
83
|
-
isKtoken: IsKtokenProvider;
|
|
84
76
|
quoter: SwapQuoteProvider<QuoteResponse>;
|
|
85
77
|
useV2Ixs: boolean;
|
|
86
78
|
}
|
|
@@ -94,9 +86,7 @@ export type DepositLeverageInitialInputs<QuoteResponse> = {
|
|
|
94
86
|
swapQuote: SwapQuote<QuoteResponse>;
|
|
95
87
|
currentSlot: Slot;
|
|
96
88
|
klendAccounts: Array<Address>;
|
|
97
|
-
collIsKtoken: boolean;
|
|
98
89
|
obligation: KaminoObligation | ObligationType | undefined;
|
|
99
|
-
strategy: StrategyWithAddress | undefined;
|
|
100
90
|
};
|
|
101
91
|
|
|
102
92
|
export interface DepositWithLeverageSwapInputsProps<QuoteResponse> extends BaseLeverageSwapInputsProps<QuoteResponse> {
|
|
@@ -106,7 +96,6 @@ export interface DepositWithLeverageSwapInputsProps<QuoteResponse> extends BaseL
|
|
|
106
96
|
priceDebtToColl: Decimal;
|
|
107
97
|
targetLeverage: Decimal;
|
|
108
98
|
selectedTokenMint: Address;
|
|
109
|
-
priceAinB: PriceAinBProvider;
|
|
110
99
|
// currently only used to disable requesting elevation group when this value is 0
|
|
111
100
|
// to be implemented properly in the future
|
|
112
101
|
elevationGroupOverride?: number;
|
|
@@ -123,9 +112,6 @@ export type DepositLeverageCalcsResult = {
|
|
|
123
112
|
collTokenToDeposit: Decimal;
|
|
124
113
|
swapDebtTokenIn: Decimal;
|
|
125
114
|
swapCollTokenExpectedOut: Decimal;
|
|
126
|
-
flashBorrowInDebtTokenKtokenOnly: Decimal;
|
|
127
|
-
singleSidedDepositKtokenOnly: Decimal;
|
|
128
|
-
requiredCollateralKtokenOnly: Decimal;
|
|
129
115
|
};
|
|
130
116
|
|
|
131
117
|
export type WithdrawLeverageIxsResponse<QuoteResponse> = BaseLeverageIxsResponse<QuoteResponse> & {
|
|
@@ -137,9 +123,7 @@ export type WithdrawLeverageInitialInputs<QuoteResponse> = {
|
|
|
137
123
|
swapQuote: SwapQuote<QuoteResponse>;
|
|
138
124
|
currentSlot: Slot;
|
|
139
125
|
klendAccounts: Array<Address>;
|
|
140
|
-
collIsKtoken: boolean;
|
|
141
126
|
obligation: KaminoObligation | ObligationType | undefined;
|
|
142
|
-
strategy: StrategyWithAddress | undefined;
|
|
143
127
|
};
|
|
144
128
|
|
|
145
129
|
export interface WithdrawWithLeverageSwapInputsProps<QuoteResponse> extends BaseLeverageSwapInputsProps<QuoteResponse> {
|
|
@@ -176,9 +160,7 @@ export type AdjustLeverageInitialInputs<QuoteResponse> = {
|
|
|
176
160
|
currentSlot: Slot;
|
|
177
161
|
klendAccounts: Array<Address>;
|
|
178
162
|
isDeposit: boolean;
|
|
179
|
-
collIsKtoken: boolean;
|
|
180
163
|
obligation: KaminoObligation | ObligationType | undefined;
|
|
181
|
-
strategy: StrategyWithAddress | undefined;
|
|
182
164
|
};
|
|
183
165
|
|
|
184
166
|
export interface AdjustLeverageSwapInputsProps<QuoteResponse> extends BaseLeverageSwapInputsProps<QuoteResponse> {
|
|
@@ -188,7 +170,6 @@ export interface AdjustLeverageSwapInputsProps<QuoteResponse> extends BaseLevera
|
|
|
188
170
|
targetLeverage: Decimal;
|
|
189
171
|
priceCollToDebt: Decimal;
|
|
190
172
|
priceDebtToColl: Decimal;
|
|
191
|
-
priceAinB: PriceAinBProvider;
|
|
192
173
|
withdrawSlotOffset?: number;
|
|
193
174
|
}
|
|
194
175
|
|
|
@@ -201,6 +182,5 @@ export type AdjustLeverageCalcsResult = {
|
|
|
201
182
|
adjustBorrowPosition: Decimal;
|
|
202
183
|
amountToFlashBorrowDebt: Decimal;
|
|
203
184
|
borrowAmount: Decimal;
|
|
204
|
-
expectedDebtTokenAtaBalance: Decimal;
|
|
205
185
|
withdrawAmountWithSlippageAndFlashLoanFee: Decimal;
|
|
206
186
|
};
|
package/src/leverage/utils.ts
CHANGED
|
@@ -1,325 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
Address,
|
|
5
|
-
Instruction,
|
|
6
|
-
GetAccountInfoApi,
|
|
7
|
-
Rpc,
|
|
8
|
-
GetTokenAccountBalanceApi,
|
|
9
|
-
TransactionSigner,
|
|
10
|
-
} from '@solana/kit';
|
|
1
|
+
import { KaminoReserve, lamportsToNumberDecimal } from '../classes';
|
|
2
|
+
import { Address, GetAccountInfoApi, Rpc, GetTokenAccountBalanceApi } from '@solana/kit';
|
|
11
3
|
import Decimal from 'decimal.js';
|
|
12
|
-
import {
|
|
13
|
-
import { numberToLamportsDecimal } from '../classes/utils';
|
|
4
|
+
import { getTokenAccountBalanceDecimal } from '../utils';
|
|
14
5
|
import BN from 'bn.js';
|
|
15
|
-
import { PriceAinBProvider, SwapInputs, SwapQuote, SwapIxs, SwapIxsProvider } from './types';
|
|
16
|
-
|
|
17
|
-
export interface KaminoSwapperIxBuilder {
|
|
18
|
-
(
|
|
19
|
-
input: DepositAmountsForSwap,
|
|
20
|
-
tokenAMint: Address,
|
|
21
|
-
tokenBMint: Address,
|
|
22
|
-
owner: TransactionSigner,
|
|
23
|
-
slippage: Decimal,
|
|
24
|
-
allKeys: Address[]
|
|
25
|
-
): Promise<[Instruction[], Address[]]>;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface DepositAmountsForSwap {
|
|
29
|
-
requiredAAmountToDeposit: Decimal;
|
|
30
|
-
requiredBAmountToDeposit: Decimal;
|
|
31
|
-
tokenAToSwapAmount: Decimal;
|
|
32
|
-
tokenBToSwapAmount: Decimal;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export async function getTokenToKtokenSwapper<QuoteResponse>(
|
|
36
|
-
kaminoMarket: KaminoMarket,
|
|
37
|
-
kamino: Kamino,
|
|
38
|
-
depositor: TransactionSigner,
|
|
39
|
-
slippagePct: Decimal,
|
|
40
|
-
swapper: SwapIxsProvider<QuoteResponse>,
|
|
41
|
-
priceAinB: PriceAinBProvider,
|
|
42
|
-
includeAtaIxs: boolean = true
|
|
43
|
-
): Promise<SwapIxsProvider<QuoteResponse>> {
|
|
44
|
-
return async (
|
|
45
|
-
inputs: SwapInputs,
|
|
46
|
-
klendAccounts: Array<Address>,
|
|
47
|
-
quote: SwapQuote<QuoteResponse>
|
|
48
|
-
): Promise<Array<SwapIxs<QuoteResponse>>> => {
|
|
49
|
-
const slippageBps = new Decimal(slippagePct).mul('100');
|
|
50
|
-
const mintInDecimals = kaminoMarket.getExistingReserveByMint(inputs.inputMint).getMintDecimals();
|
|
51
|
-
const amountIn = lamportsToNumberDecimal(inputs.inputAmountLamports, mintInDecimals);
|
|
52
|
-
console.debug('Depositing token', inputs.inputMint, ' for ', inputs.outputMint, 'ktoken');
|
|
53
|
-
if (inputs.amountDebtAtaBalance === undefined) {
|
|
54
|
-
throw Error('Amount in debt ATA balance is undefined for leverage ktoken deposit');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const ixWithLookup = (await getKtokenDepositIxs(
|
|
58
|
-
kaminoMarket.getRpc(),
|
|
59
|
-
kamino,
|
|
60
|
-
depositor,
|
|
61
|
-
inputs.inputMint,
|
|
62
|
-
inputs.outputMint,
|
|
63
|
-
amountIn,
|
|
64
|
-
slippageBps,
|
|
65
|
-
inputs.amountDebtAtaBalance,
|
|
66
|
-
swapper,
|
|
67
|
-
priceAinB,
|
|
68
|
-
includeAtaIxs,
|
|
69
|
-
klendAccounts,
|
|
70
|
-
quote
|
|
71
|
-
))!;
|
|
72
|
-
|
|
73
|
-
const luts = await getLookupTableAccounts(kaminoMarket.getRpc(), ixWithLookup.lookupTablesAddresses);
|
|
74
|
-
|
|
75
|
-
return [
|
|
76
|
-
{
|
|
77
|
-
preActionIxs: [],
|
|
78
|
-
swapIxs: ixWithLookup.instructions,
|
|
79
|
-
lookupTables: luts,
|
|
80
|
-
// TODO: Ktoken only supports one swap at a time for now (to be updated if we enable ktokens)
|
|
81
|
-
quote: {
|
|
82
|
-
priceAInB: new Decimal(0),
|
|
83
|
-
quoteResponse: undefined,
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
];
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export async function getKtokenDepositIxs<QuoteResponse>(
|
|
91
|
-
rpc: Rpc<GetAccountInfoApi & GetTokenAccountBalanceApi>,
|
|
92
|
-
kamino: Kamino,
|
|
93
|
-
depositor: TransactionSigner,
|
|
94
|
-
depositTokenMint: Address,
|
|
95
|
-
ktokenMint: Address,
|
|
96
|
-
amountToDeposit: Decimal,
|
|
97
|
-
slippageBps: Decimal,
|
|
98
|
-
amountExpectedDepositAtaBalance: Decimal,
|
|
99
|
-
swapper: SwapIxsProvider<QuoteResponse>,
|
|
100
|
-
priceAinB: PriceAinBProvider,
|
|
101
|
-
includeAtaIxs: boolean = true,
|
|
102
|
-
klendAccounts: Array<Address>,
|
|
103
|
-
quote: SwapQuote<QuoteResponse>
|
|
104
|
-
) {
|
|
105
|
-
const kaminoStrategy = await kamino.getStrategyByKTokenMint(ktokenMint);
|
|
106
|
-
const tokenAMint = kaminoStrategy?.strategy.tokenAMint!;
|
|
107
|
-
const tokenBMint = kaminoStrategy?.strategy.tokenBMint!;
|
|
108
|
-
const priceAinBDecimal = await priceAinB(tokenAMint, tokenBMint);
|
|
109
|
-
|
|
110
|
-
if (tokenAMint === depositTokenMint) {
|
|
111
|
-
const bBalance = await getTokenAccountBalanceDecimal(rpc, tokenBMint, depositor.address);
|
|
112
|
-
const tokensBalances = { a: amountExpectedDepositAtaBalance, b: bBalance };
|
|
113
|
-
console.log('amountToDeposit', amountToDeposit);
|
|
114
|
-
return await kamino.singleSidedDepositTokenA(
|
|
115
|
-
kaminoStrategy!,
|
|
116
|
-
amountToDeposit,
|
|
117
|
-
depositor,
|
|
118
|
-
slippageBps,
|
|
119
|
-
undefined,
|
|
120
|
-
swapProviderToKaminoSwapProvider(swapper, klendAccounts, quote),
|
|
121
|
-
tokensBalances,
|
|
122
|
-
priceAinBDecimal,
|
|
123
|
-
includeAtaIxs
|
|
124
|
-
);
|
|
125
|
-
} else if (tokenBMint === depositTokenMint) {
|
|
126
|
-
const aBalance = await getTokenAccountBalanceDecimal(rpc, tokenAMint, depositor.address);
|
|
127
|
-
const tokensBalances = { a: aBalance, b: amountExpectedDepositAtaBalance };
|
|
128
|
-
return await kamino.singleSidedDepositTokenB(
|
|
129
|
-
kaminoStrategy!,
|
|
130
|
-
amountToDeposit,
|
|
131
|
-
depositor,
|
|
132
|
-
slippageBps,
|
|
133
|
-
undefined,
|
|
134
|
-
swapProviderToKaminoSwapProvider(swapper, klendAccounts, quote),
|
|
135
|
-
tokensBalances,
|
|
136
|
-
priceAinBDecimal,
|
|
137
|
-
includeAtaIxs
|
|
138
|
-
);
|
|
139
|
-
} else {
|
|
140
|
-
throw Error('Deposit token is neither A nor B in the strategy');
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export async function getKtokenToTokenSwapper<QuoteResponse>(
|
|
145
|
-
kaminoMarket: KaminoMarket,
|
|
146
|
-
kamino: Kamino,
|
|
147
|
-
depositor: TransactionSigner,
|
|
148
|
-
swapper: SwapIxsProvider<QuoteResponse>
|
|
149
|
-
): Promise<SwapIxsProvider<QuoteResponse>> {
|
|
150
|
-
return async (inputs: SwapInputs, klendAccounts: Array<Address>, quote: SwapQuote<QuoteResponse>) => {
|
|
151
|
-
const amountInDecimals = kaminoMarket.getExistingReserveByMint(inputs.inputMint).getMintDecimals();
|
|
152
|
-
const amountToWithdraw = lamportsToNumberDecimal(inputs.inputAmountLamports, amountInDecimals);
|
|
153
|
-
const kaminoStrategy = await kamino.getStrategyByKTokenMint(inputs.inputMint);
|
|
154
|
-
|
|
155
|
-
console.log('Withdrawing ktoken', inputs.inputMint.toString(), ' for ', inputs.outputMint.toString(), 'token');
|
|
156
|
-
|
|
157
|
-
const ixWithdraw = (await getKtokenWithdrawIxs(kamino, depositor, kaminoStrategy!, amountToWithdraw))!;
|
|
158
|
-
|
|
159
|
-
const [estimatedAOut, estimatedBOut] = await getKtokenWithdrawEstimatesAndPrice(
|
|
160
|
-
kamino,
|
|
161
|
-
kaminoStrategy!,
|
|
162
|
-
amountToWithdraw
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
if (inputs.outputMint === kaminoStrategy!.strategy.tokenAMint!) {
|
|
166
|
-
const swapArray = await swapper(
|
|
167
|
-
{
|
|
168
|
-
inputAmountLamports: estimatedBOut,
|
|
169
|
-
inputMint: kaminoStrategy!.strategy.tokenBMint!,
|
|
170
|
-
outputMint: kaminoStrategy!.strategy.tokenAMint!,
|
|
171
|
-
amountDebtAtaBalance: new Decimal(0),
|
|
172
|
-
},
|
|
173
|
-
klendAccounts,
|
|
174
|
-
quote
|
|
175
|
-
);
|
|
176
|
-
// TODO: Ktoken only supports one swap at a time for now (to be updated if we enable ktokens)
|
|
177
|
-
const swap = swapArray[0];
|
|
178
|
-
|
|
179
|
-
return [
|
|
180
|
-
{
|
|
181
|
-
preActionIxs: [],
|
|
182
|
-
swapIxs: [...ixWithdraw.prerequisiteIxs, ixWithdraw.withdrawIx, ...swap.swapIxs],
|
|
183
|
-
lookupTables: swap.lookupTables,
|
|
184
|
-
quote: swap.quote,
|
|
185
|
-
},
|
|
186
|
-
];
|
|
187
|
-
} else if (inputs.outputMint === kaminoStrategy!.strategy.tokenBMint) {
|
|
188
|
-
const swapArray = await swapper(
|
|
189
|
-
{
|
|
190
|
-
inputAmountLamports: estimatedAOut,
|
|
191
|
-
inputMint: kaminoStrategy!.strategy.tokenAMint!,
|
|
192
|
-
outputMint: kaminoStrategy!.strategy.tokenBMint!,
|
|
193
|
-
amountDebtAtaBalance: new Decimal(0),
|
|
194
|
-
},
|
|
195
|
-
klendAccounts,
|
|
196
|
-
quote
|
|
197
|
-
);
|
|
198
|
-
// TODO: Ktoken only supports one swap at a time for now (to be updated if we enable ktokens)
|
|
199
|
-
const swap = swapArray[0];
|
|
200
|
-
|
|
201
|
-
return [
|
|
202
|
-
{
|
|
203
|
-
preActionIxs: [],
|
|
204
|
-
swapIxs: [...ixWithdraw.prerequisiteIxs, ixWithdraw.withdrawIx, ...swap.swapIxs],
|
|
205
|
-
lookupTables: swap.lookupTables,
|
|
206
|
-
quote: swap.quote,
|
|
207
|
-
},
|
|
208
|
-
];
|
|
209
|
-
} else {
|
|
210
|
-
throw Error('Deposit token is neither A nor B in the strategy');
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
export async function getKtokenWithdrawIxs(
|
|
216
|
-
kamino: Kamino,
|
|
217
|
-
withdrawer: TransactionSigner,
|
|
218
|
-
kaminoStrategy: StrategyWithAddress,
|
|
219
|
-
amountToWithdraw: Decimal
|
|
220
|
-
) {
|
|
221
|
-
return await kamino.withdrawShares(kaminoStrategy!, amountToWithdraw, withdrawer);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
export async function getKtokenWithdrawEstimatesAndPrice(
|
|
225
|
-
kamino: Kamino,
|
|
226
|
-
kaminoStrategy: StrategyWithAddress,
|
|
227
|
-
amountToWithdraw: Decimal
|
|
228
|
-
) {
|
|
229
|
-
const sharesData = await kamino.getStrategyShareData(kaminoStrategy);
|
|
230
|
-
const withdrawPct = amountToWithdraw
|
|
231
|
-
.div(
|
|
232
|
-
lamportsToNumberDecimal(
|
|
233
|
-
new Decimal(kaminoStrategy.strategy.sharesIssued.toString()),
|
|
234
|
-
kaminoStrategy.strategy.sharesMintDecimals.toNumber()
|
|
235
|
-
)
|
|
236
|
-
)
|
|
237
|
-
.toDecimalPlaces(18);
|
|
238
|
-
|
|
239
|
-
const withdrawFee = new Decimal(10_000).sub(new Decimal(kaminoStrategy.strategy.withdrawFee.toString()));
|
|
240
|
-
|
|
241
|
-
// TODO: Mihai/Marius improve - currently subtracting due to decimal accuracy issues compared to yvaults SC
|
|
242
|
-
// for both A and B op: .sub(0.000002)
|
|
243
|
-
|
|
244
|
-
const estimatedAOut = sharesData.balance.computedHoldings.invested.a
|
|
245
|
-
.add(sharesData.balance.computedHoldings.available.a)
|
|
246
|
-
.mul(withdrawPct)
|
|
247
|
-
.toDecimalPlaces(kaminoStrategy.strategy.tokenAMintDecimals.toNumber(), 1)
|
|
248
|
-
.sub(0.000002)
|
|
249
|
-
.mul(withdrawFee)
|
|
250
|
-
.div(10_000)
|
|
251
|
-
.toDecimalPlaces(kaminoStrategy.strategy.tokenAMintDecimals.toNumber());
|
|
252
|
-
|
|
253
|
-
const estimatedAOutDecimal = numberToLamportsDecimal(
|
|
254
|
-
estimatedAOut,
|
|
255
|
-
kaminoStrategy.strategy.tokenAMintDecimals.toNumber()
|
|
256
|
-
).floor();
|
|
257
|
-
|
|
258
|
-
const estimatedBOut = sharesData.balance.computedHoldings.invested.b
|
|
259
|
-
.add(sharesData.balance.computedHoldings.available.b)
|
|
260
|
-
.mul(withdrawPct)
|
|
261
|
-
.toDecimalPlaces(kaminoStrategy.strategy.tokenBMintDecimals.toNumber(), 1)
|
|
262
|
-
.sub(0.000002)
|
|
263
|
-
.mul(withdrawFee)
|
|
264
|
-
.div(10_000)
|
|
265
|
-
.toDecimalPlaces(kaminoStrategy.strategy.tokenAMintDecimals.toNumber());
|
|
266
|
-
|
|
267
|
-
const estimatedBOutDecimal = numberToLamportsDecimal(
|
|
268
|
-
estimatedBOut,
|
|
269
|
-
kaminoStrategy.strategy.tokenBMintDecimals.toNumber()
|
|
270
|
-
).floor();
|
|
271
|
-
|
|
272
|
-
console.log('a-out', estimatedAOutDecimal.toString());
|
|
273
|
-
console.log('b-out', estimatedBOut.toString());
|
|
274
|
-
return [estimatedAOutDecimal, estimatedBOutDecimal];
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
export function swapProviderToKaminoSwapProvider<QuoteResponse>(
|
|
278
|
-
swapper: SwapIxsProvider<QuoteResponse>,
|
|
279
|
-
klendAccounts: Array<Address>,
|
|
280
|
-
swapQuote: SwapQuote<QuoteResponse>
|
|
281
|
-
): KaminoSwapperIxBuilder {
|
|
282
|
-
return async (
|
|
283
|
-
input: DepositAmountsForSwap,
|
|
284
|
-
tokenAMint: Address,
|
|
285
|
-
tokenBMint: Address,
|
|
286
|
-
_owner: TransactionSigner,
|
|
287
|
-
_slippage: Decimal,
|
|
288
|
-
_allKeys: Address[]
|
|
289
|
-
): Promise<[Instruction[], Address[]]> => {
|
|
290
|
-
if (input.tokenBToSwapAmount.lt(0)) {
|
|
291
|
-
const swapperIxsArray = await swapper(
|
|
292
|
-
{
|
|
293
|
-
inputAmountLamports: input.tokenBToSwapAmount.abs(),
|
|
294
|
-
inputMint: tokenBMint,
|
|
295
|
-
outputMint: tokenAMint,
|
|
296
|
-
amountDebtAtaBalance: undefined,
|
|
297
|
-
},
|
|
298
|
-
klendAccounts,
|
|
299
|
-
swapQuote
|
|
300
|
-
);
|
|
301
|
-
// TODO: Ktoken only supports one swap at a time for now (to be updated if we enable ktokens)
|
|
302
|
-
const swapperIxs = swapperIxsArray[0];
|
|
303
|
-
return [swapperIxs.swapIxs, swapperIxs.lookupTables.map((lt) => lt.address)];
|
|
304
|
-
} else if (input.tokenAToSwapAmount.lt(0)) {
|
|
305
|
-
const swapperIxsArray = await swapper(
|
|
306
|
-
{
|
|
307
|
-
inputAmountLamports: input.tokenAToSwapAmount.abs(),
|
|
308
|
-
inputMint: tokenAMint,
|
|
309
|
-
outputMint: tokenBMint,
|
|
310
|
-
amountDebtAtaBalance: undefined,
|
|
311
|
-
},
|
|
312
|
-
klendAccounts,
|
|
313
|
-
swapQuote
|
|
314
|
-
);
|
|
315
|
-
// TODO: Ktoken only supports one swap at a time for now (to be updated if we enable ktokens)
|
|
316
|
-
const swapperIxs = swapperIxsArray[0];
|
|
317
|
-
return [swapperIxs.swapIxs, swapperIxs.lookupTables.map((lt) => lt.address)];
|
|
318
|
-
} else {
|
|
319
|
-
throw Error('Nothing to swap');
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
6
|
|
|
324
7
|
export const getExpectedTokenBalanceAfterBorrow = async (
|
|
325
8
|
rpc: Rpc<GetAccountInfoApi & GetTokenAccountBalanceApi>,
|
|
@@ -1991,11 +1991,10 @@ function parseReserveConfigFromFile(reserveConfigFromFile: any): ReserveConfig {
|
|
|
1991
1991
|
protocolLiquidationFeePct: reserveConfigFromFile.protocolLiquidationFeePct,
|
|
1992
1992
|
protocolOrderExecutionFeePct: reserveConfigFromFile.protocolOrderExecutionFeePct,
|
|
1993
1993
|
protocolTakeRatePct: reserveConfigFromFile.protocolTakeRatePct,
|
|
1994
|
-
assetTier: reserveConfigFromFile.assetTier,
|
|
1995
1994
|
maxLiquidationBonusBps: reserveConfigFromFile.maxLiquidationBonusBps,
|
|
1996
1995
|
badDebtLiquidationBonusBps: reserveConfigFromFile.badDebtLiquidationBonusBps,
|
|
1997
1996
|
fees: {
|
|
1998
|
-
|
|
1997
|
+
originationFeeSf: Fraction.fromDecimal(new Decimal(reserveConfigFromFile.fees.borrowFee)).valueSf,
|
|
1999
1998
|
flashLoanFeeSf: Fraction.fromDecimal(new Decimal(reserveConfigFromFile.fees.flashLoanFee)).valueSf,
|
|
2000
1999
|
padding: Array(8).fill(0),
|
|
2001
2000
|
},
|
|
@@ -2040,8 +2039,14 @@ function parseReserveConfigFromFile(reserveConfigFromFile: any): ReserveConfig {
|
|
|
2040
2039
|
borrowLimitOutsideElevationGroup: new BN(reserveConfigFromFile.borrowLimitOutsideElevationGroup),
|
|
2041
2040
|
borrowLimitAgainstThisCollateralInElevationGroup: parseReserveBorrowLimitAgainstCollInEmode(reserveConfigFromFile),
|
|
2042
2041
|
deleveragingBonusIncreaseBpsPerDay: new BN(reserveConfigFromFile.deleveragingBonusIncreaseBpsPerDay),
|
|
2043
|
-
|
|
2044
|
-
|
|
2042
|
+
canUnstakeLstCollateral: reserveConfigFromFile.canUnstakeLstCollateral,
|
|
2043
|
+
debtMaturityTimestamp: new BN(reserveConfigFromFile.debtMaturityTimestamp),
|
|
2044
|
+
debtTermSeconds: new BN(reserveConfigFromFile.debtTermSeconds),
|
|
2045
|
+
minDeleveragingBonusBps: reserveConfigFromFile.minDeleveragingBonusBps,
|
|
2046
|
+
proposerAuthorityLocked: reserveConfigFromFile.proposerAuthorityLocked,
|
|
2047
|
+
reserved1: Array(6).fill(0),
|
|
2048
|
+
paddingDeprecatedAssetTier: 0,
|
|
2049
|
+
ltvLamportsMargin: new BN(0),
|
|
2045
2050
|
};
|
|
2046
2051
|
|
|
2047
2052
|
return new ReserveConfig(reserveConfigFields);
|
|
@@ -2121,11 +2126,10 @@ function parseReserveConfigToFile(reserveConfig: ReserveConfig) {
|
|
|
2121
2126
|
protocolLiquidationFeePct: reserveConfig.protocolLiquidationFeePct,
|
|
2122
2127
|
protocolOrderExecutionFeePct: reserveConfig.protocolOrderExecutionFeePct,
|
|
2123
2128
|
protocolTakeRatePct: reserveConfig.protocolTakeRatePct,
|
|
2124
|
-
assetTier: reserveConfig.assetTier,
|
|
2125
2129
|
maxLiquidationBonusBps: reserveConfig.maxLiquidationBonusBps,
|
|
2126
2130
|
badDebtLiquidationBonusBps: reserveConfig.badDebtLiquidationBonusBps,
|
|
2127
2131
|
fees: {
|
|
2128
|
-
borrowFee: new Fraction(reserveConfig.fees.
|
|
2132
|
+
borrowFee: new Fraction(reserveConfig.fees.originationFeeSf).toDecimal().toString(),
|
|
2129
2133
|
flashLoanFee: new Fraction(reserveConfig.fees.flashLoanFeeSf).toDecimal().toString(),
|
|
2130
2134
|
padding: Array(8).fill(0),
|
|
2131
2135
|
},
|
|
@@ -2161,8 +2165,7 @@ function parseReserveConfigToFile(reserveConfig: ReserveConfig) {
|
|
|
2161
2165
|
borrowLimitAgainstThisCollateralInElevationGroup:
|
|
2162
2166
|
reserveConfig.borrowLimitAgainstThisCollateralInElevationGroup.map((entry) => entry.toString()),
|
|
2163
2167
|
deleveragingBonusIncreaseBpsPerDay: reserveConfig.deleveragingBonusIncreaseBpsPerDay.toString(),
|
|
2164
|
-
reserved1: Array(
|
|
2165
|
-
reserved2: Array(9).fill(0),
|
|
2168
|
+
reserved1: Array(6).fill(0),
|
|
2166
2169
|
};
|
|
2167
2170
|
}
|
|
2168
2171
|
|
|
@@ -306,11 +306,10 @@ function buildReserveConfig(fields: {
|
|
|
306
306
|
protocolLiquidationFeePct: 0,
|
|
307
307
|
protocolOrderExecutionFeePct: 0,
|
|
308
308
|
protocolTakeRatePct: fields.configParams.protocolTakeRate,
|
|
309
|
-
assetTier: 0,
|
|
310
309
|
maxLiquidationBonusBps: fields.configParams.maxLiquidationBonusBps,
|
|
311
310
|
badDebtLiquidationBonusBps: fields.configParams.badDebtLiquidationBonusBps,
|
|
312
311
|
fees: {
|
|
313
|
-
|
|
312
|
+
originationFeeSf: fields.configParams.borrowFeeSf.getValue(),
|
|
314
313
|
flashLoanFeeSf: fields.configParams.flashLoanFeeSf.getValue(),
|
|
315
314
|
padding: Array(6).fill(0),
|
|
316
315
|
},
|
|
@@ -369,8 +368,14 @@ function buildReserveConfig(fields: {
|
|
|
369
368
|
),
|
|
370
369
|
borrowLimitAgainstThisCollateralInElevationGroup: Array(32).fill(new BN(0)),
|
|
371
370
|
deleveragingBonusIncreaseBpsPerDay: new BN(100),
|
|
372
|
-
|
|
373
|
-
|
|
371
|
+
canUnstakeLstCollateral: 0,
|
|
372
|
+
debtMaturityTimestamp: new BN(0),
|
|
373
|
+
debtTermSeconds: new BN(0),
|
|
374
|
+
minDeleveragingBonusBps: 0,
|
|
375
|
+
proposerAuthorityLocked: 0,
|
|
376
|
+
ltvLamportsMargin: new BN(0),
|
|
377
|
+
reserved1: Array(6).fill(0),
|
|
378
|
+
paddingDeprecatedAssetTier: 0,
|
|
374
379
|
};
|
|
375
380
|
|
|
376
381
|
return new ReserveConfig(reserveConfigFields);
|
package/src/utils/seeds.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { PROGRAM_ID } from '../@codegen/klend/programId';
|
|
|
3
3
|
import { PROGRAM_ID as FARMS_PROGRAM_ID } from '@kamino-finance/farms-sdk/dist/@codegen/farms/programId';
|
|
4
4
|
import { METADATA_PROGRAM_ID, METADATA_SEED } from '../classes/vault';
|
|
5
5
|
import { Buffer } from 'buffer';
|
|
6
|
+
import { UNSTAKING_POOL_AUTHORITY_SEED } from '../classes/unstakingPool';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Lending market authority seed
|
|
@@ -69,16 +70,15 @@ export interface ReservePdas {
|
|
|
69
70
|
/**
|
|
70
71
|
* Returns all the PDAs for the given reserve
|
|
71
72
|
* @param programId
|
|
72
|
-
* @param
|
|
73
|
-
* @param mint
|
|
73
|
+
* @param reserve
|
|
74
74
|
* @returns ReservePdas
|
|
75
75
|
*/
|
|
76
|
-
export async function reservePdas(programId: Address,
|
|
76
|
+
export async function reservePdas(programId: Address, reserve: Address): Promise<ReservePdas> {
|
|
77
77
|
const [[liquiditySupplyVault], [collateralMint], [collateralSupplyVault], [feeVault]] = await Promise.all([
|
|
78
|
-
reserveLiqSupplyPda(
|
|
79
|
-
reserveCollateralMintPda(
|
|
80
|
-
reserveCollateralSupplyPda(
|
|
81
|
-
reserveFeeVaultPda(
|
|
78
|
+
reserveLiqSupplyPda(reserve, programId),
|
|
79
|
+
reserveCollateralMintPda(reserve, programId),
|
|
80
|
+
reserveCollateralSupplyPda(reserve, programId),
|
|
81
|
+
reserveFeeVaultPda(reserve, programId),
|
|
82
82
|
]);
|
|
83
83
|
return {
|
|
84
84
|
liquiditySupplyVault,
|
|
@@ -107,71 +107,63 @@ export function lendingMarketAuthPda(
|
|
|
107
107
|
/**
|
|
108
108
|
* Returns the PDA and bump for the reserve liquidity supply
|
|
109
109
|
* @param lendingMarket
|
|
110
|
-
* @param mint
|
|
111
110
|
* @param programId
|
|
112
111
|
* @returns [pda, bump]
|
|
113
112
|
*/
|
|
114
113
|
export async function reserveLiqSupplyPda(
|
|
115
|
-
|
|
116
|
-
mint: Address,
|
|
114
|
+
reserve: Address,
|
|
117
115
|
programId: Address = PROGRAM_ID
|
|
118
116
|
): Promise<ProgramDerivedAddress> {
|
|
119
117
|
return getProgramDerivedAddress({
|
|
120
|
-
seeds: [Buffer.from(RESERVE_LIQ_SUPPLY_SEED), addressEncoder.encode(
|
|
118
|
+
seeds: [Buffer.from(RESERVE_LIQ_SUPPLY_SEED), addressEncoder.encode(reserve)],
|
|
121
119
|
programAddress: programId,
|
|
122
120
|
});
|
|
123
121
|
}
|
|
124
122
|
|
|
125
123
|
/**
|
|
126
124
|
* Returns the PDA and bump for the reserve fee vault
|
|
127
|
-
* @param
|
|
128
|
-
* @param mint
|
|
125
|
+
* @param reserve
|
|
129
126
|
* @param programId
|
|
130
127
|
* @returns [vaultPda, bump]
|
|
131
128
|
*/
|
|
132
129
|
export async function reserveFeeVaultPda(
|
|
133
|
-
|
|
134
|
-
mint: Address,
|
|
130
|
+
reserve: Address,
|
|
135
131
|
programId: Address = PROGRAM_ID
|
|
136
132
|
): Promise<ProgramDerivedAddress> {
|
|
137
133
|
return getProgramDerivedAddress({
|
|
138
|
-
seeds: [Buffer.from(FEE_RECEIVER_SEED), addressEncoder.encode(
|
|
134
|
+
seeds: [Buffer.from(FEE_RECEIVER_SEED), addressEncoder.encode(reserve)],
|
|
139
135
|
programAddress: programId,
|
|
140
136
|
});
|
|
141
137
|
}
|
|
142
138
|
|
|
143
139
|
/**
|
|
144
140
|
* Returns the PDA and bump for the reserve collateral mint
|
|
145
|
-
* @param
|
|
146
|
-
* @param mint
|
|
141
|
+
* @param reserve
|
|
147
142
|
* @param programId
|
|
148
143
|
* @returns [mintPda, bump]
|
|
149
144
|
*/
|
|
150
145
|
export async function reserveCollateralMintPda(
|
|
151
|
-
|
|
152
|
-
mint: Address,
|
|
146
|
+
reserve: Address,
|
|
153
147
|
programId: Address = PROGRAM_ID
|
|
154
148
|
): Promise<ProgramDerivedAddress> {
|
|
155
149
|
return getProgramDerivedAddress({
|
|
156
|
-
seeds: [Buffer.from(RESERVE_COLL_MINT_SEED), addressEncoder.encode(
|
|
150
|
+
seeds: [Buffer.from(RESERVE_COLL_MINT_SEED), addressEncoder.encode(reserve)],
|
|
157
151
|
programAddress: programId,
|
|
158
152
|
});
|
|
159
153
|
}
|
|
160
154
|
|
|
161
155
|
/**
|
|
162
156
|
* Returns the PDA and bump for the reserve collateral supply
|
|
163
|
-
* @param
|
|
164
|
-
* @param mint
|
|
157
|
+
* @param reserve
|
|
165
158
|
* @param programId
|
|
166
159
|
* @returns [pda, bump]
|
|
167
160
|
*/
|
|
168
161
|
export function reserveCollateralSupplyPda(
|
|
169
|
-
|
|
170
|
-
mint: Address,
|
|
162
|
+
reserve: Address,
|
|
171
163
|
programId: Address = PROGRAM_ID
|
|
172
164
|
): Promise<ProgramDerivedAddress> {
|
|
173
165
|
return getProgramDerivedAddress({
|
|
174
|
-
seeds: [Buffer.from(RESERVE_COLL_SUPPLY_SEED), addressEncoder.encode(
|
|
166
|
+
seeds: [Buffer.from(RESERVE_COLL_SUPPLY_SEED), addressEncoder.encode(reserve)],
|
|
175
167
|
programAddress: programId,
|
|
176
168
|
});
|
|
177
169
|
}
|
|
@@ -290,3 +282,13 @@ export async function getKVaultSharesMetadataPda(mint: Address): Promise<Program
|
|
|
290
282
|
programAddress: METADATA_PROGRAM_ID,
|
|
291
283
|
});
|
|
292
284
|
}
|
|
285
|
+
|
|
286
|
+
export function unstakingPoolMarketAuthorityPda(
|
|
287
|
+
lendingMarket: Address,
|
|
288
|
+
programId: Address = PROGRAM_ID
|
|
289
|
+
): Promise<ProgramDerivedAddress> {
|
|
290
|
+
return getProgramDerivedAddress({
|
|
291
|
+
seeds: [UNSTAKING_POOL_AUTHORITY_SEED, addressEncoder.encode(lendingMarket)],
|
|
292
|
+
programAddress: programId,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import * as types from "../types";
|
|
2
|
-
import * as borsh from "@coral-xyz/borsh";
|
|
3
|
-
export interface RegularJSON {
|
|
4
|
-
kind: "Regular";
|
|
5
|
-
}
|
|
6
|
-
export declare class Regular {
|
|
7
|
-
static readonly discriminator = 0;
|
|
8
|
-
static readonly kind = "Regular";
|
|
9
|
-
readonly discriminator = 0;
|
|
10
|
-
readonly kind = "Regular";
|
|
11
|
-
toJSON(): RegularJSON;
|
|
12
|
-
toEncodable(): {
|
|
13
|
-
Regular: {};
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export interface IsolatedCollateralJSON {
|
|
17
|
-
kind: "IsolatedCollateral";
|
|
18
|
-
}
|
|
19
|
-
export declare class IsolatedCollateral {
|
|
20
|
-
static readonly discriminator = 1;
|
|
21
|
-
static readonly kind = "IsolatedCollateral";
|
|
22
|
-
readonly discriminator = 1;
|
|
23
|
-
readonly kind = "IsolatedCollateral";
|
|
24
|
-
toJSON(): IsolatedCollateralJSON;
|
|
25
|
-
toEncodable(): {
|
|
26
|
-
IsolatedCollateral: {};
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
export interface IsolatedDebtJSON {
|
|
30
|
-
kind: "IsolatedDebt";
|
|
31
|
-
}
|
|
32
|
-
export declare class IsolatedDebt {
|
|
33
|
-
static readonly discriminator = 2;
|
|
34
|
-
static readonly kind = "IsolatedDebt";
|
|
35
|
-
readonly discriminator = 2;
|
|
36
|
-
readonly kind = "IsolatedDebt";
|
|
37
|
-
toJSON(): IsolatedDebtJSON;
|
|
38
|
-
toEncodable(): {
|
|
39
|
-
IsolatedDebt: {};
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
export declare function fromDecoded(obj: any): types.AssetTierKind;
|
|
43
|
-
export declare function fromJSON(obj: types.AssetTierJSON): types.AssetTierKind;
|
|
44
|
-
export declare function layout(property?: string): borsh.EnumLayout<unknown>;
|
|
45
|
-
//# sourceMappingURL=AssetTier.d.ts.map
|