@kamino-finance/klend-sdk 5.13.9 → 5.13.10
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.map +1 -1
- package/dist/classes/action.js +0 -1
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +1 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +2 -2
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/reserve.d.ts +4 -0
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +8 -2
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/vault.d.ts +1 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +1 -1
- package/dist/classes/vault.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +5 -5
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +9 -9
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +8 -8
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +25 -25
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/instructions.d.ts +5 -5
- package/dist/leverage/instructions.d.ts.map +1 -1
- package/dist/leverage/instructions.js +6 -6
- package/dist/leverage/instructions.js.map +1 -1
- package/dist/leverage/operations.d.ts +5 -0
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +131 -304
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +35 -57
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/leverage/utils.d.ts +1 -1
- package/dist/leverage/utils.js +5 -5
- package/dist/leverage/utils.js.map +1 -1
- package/dist/utils/ata.d.ts +0 -1
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +0 -14
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/instruction.d.ts +1 -0
- package/dist/utils/instruction.d.ts.map +1 -1
- package/dist/utils/instruction.js +10 -0
- package/dist/utils/instruction.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/action.ts +0 -1
- package/src/classes/manager.ts +2 -2
- package/src/classes/reserve.ts +9 -2
- package/src/classes/vault.ts +1 -1
- package/src/lending_operations/repay_with_collateral_operations.ts +6 -6
- package/src/lending_operations/swap_collateral_operations.ts +22 -24
- package/src/leverage/calcs.ts +26 -26
- package/src/leverage/instructions.ts +8 -8
- package/src/leverage/operations.ts +232 -325
- package/src/leverage/types.ts +38 -67
- package/src/leverage/utils.ts +5 -5
- package/src/utils/ata.ts +1 -26
- package/src/utils/instruction.ts +12 -0
package/src/leverage/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AddressLookupTableAccount, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
3
|
import { KaminoMarket, KaminoObligation } from '../classes';
|
|
4
|
-
import {
|
|
4
|
+
import { Kamino, StrategyWithAddress } from '@kamino-finance/kliquidity-sdk';
|
|
5
5
|
import { ObligationType, ObligationTypeTag, ScopePriceRefreshConfig } from '../utils';
|
|
6
6
|
|
|
7
7
|
export type SwapQuoteProvider<QuoteResponse> = (
|
|
@@ -48,27 +48,15 @@ export type SwapInputs = {
|
|
|
48
48
|
amountDebtAtaBalance: Decimal | undefined;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
export type
|
|
52
|
-
kaminoMarket: KaminoMarket,
|
|
53
|
-
kamino: Kamino,
|
|
54
|
-
depositor: PublicKey,
|
|
55
|
-
amountInMint: PublicKey,
|
|
56
|
-
amountOutMint: PublicKey,
|
|
57
|
-
amountIn: Decimal,
|
|
58
|
-
slippageFactor: Decimal,
|
|
59
|
-
amountDebtAtaBalance: Decimal
|
|
60
|
-
) => Promise<InstructionsWithLookupTables>;
|
|
61
|
-
|
|
62
|
-
export type DepositLeverageIxsResponse<QuoteResponse> = {
|
|
51
|
+
export type BaseLeverageIxsResponse = {
|
|
63
52
|
ixs: TransactionInstruction[];
|
|
64
53
|
lookupTables: AddressLookupTableAccount[];
|
|
65
54
|
swapInputs: SwapInputs;
|
|
66
55
|
flashLoanInfo: FlashLoanInfo;
|
|
67
|
-
initialInputs: DepositLeverageInitialInputs<QuoteResponse>;
|
|
68
56
|
};
|
|
69
57
|
|
|
70
|
-
export type
|
|
71
|
-
calcs:
|
|
58
|
+
export type LeverageInitialInputs<LeverageCalcsResult, QuoteResponse> = {
|
|
59
|
+
calcs: LeverageCalcsResult;
|
|
72
60
|
swapQuote: SwapQuote<QuoteResponse>;
|
|
73
61
|
currentSlot: number;
|
|
74
62
|
klendAccounts: Array<PublicKey>;
|
|
@@ -77,31 +65,48 @@ export type DepositLeverageInitialInputs<QuoteResponse> = {
|
|
|
77
65
|
strategy: StrategyWithAddress | undefined;
|
|
78
66
|
};
|
|
79
67
|
|
|
80
|
-
export interface
|
|
68
|
+
export interface BaseLeverageSwapInputsProps<QuoteResponse> {
|
|
81
69
|
owner: PublicKey;
|
|
82
70
|
kaminoMarket: KaminoMarket;
|
|
83
71
|
debtTokenMint: PublicKey;
|
|
84
72
|
collTokenMint: PublicKey;
|
|
85
|
-
obligation: KaminoObligation | null;
|
|
86
|
-
obligationTypeTagOverride: ObligationTypeTag;
|
|
87
73
|
referrer: PublicKey;
|
|
88
74
|
currentSlot: number;
|
|
89
|
-
depositAmount: Decimal;
|
|
90
|
-
priceDebtToColl: Decimal;
|
|
91
75
|
slippagePct: Decimal;
|
|
92
|
-
targetLeverage: Decimal;
|
|
93
|
-
selectedTokenMint: PublicKey;
|
|
94
76
|
budgetAndPriorityFeeIxs?: TransactionInstruction[];
|
|
95
77
|
kamino: Kamino | undefined;
|
|
96
78
|
scopeRefreshConfig?: ScopePriceRefreshConfig;
|
|
97
79
|
quoteBufferBps: Decimal;
|
|
98
|
-
priceAinB: PriceAinBProvider;
|
|
99
80
|
isKtoken: IsKtokenProvider;
|
|
100
81
|
quoter: SwapQuoteProvider<QuoteResponse>;
|
|
82
|
+
useV2Ixs: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type DepositLeverageIxsResponse<QuoteResponse> = BaseLeverageIxsResponse & {
|
|
86
|
+
initialInputs: LeverageInitialInputs<DepositLeverageCalcsResult, QuoteResponse>;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type DepositLeverageInitialInputs<QuoteResponse> = {
|
|
90
|
+
calcs: DepositLeverageCalcsResult;
|
|
91
|
+
swapQuote: SwapQuote<QuoteResponse>;
|
|
92
|
+
currentSlot: number;
|
|
93
|
+
klendAccounts: Array<PublicKey>;
|
|
94
|
+
collIsKtoken: boolean;
|
|
95
|
+
obligation: KaminoObligation | ObligationType | undefined;
|
|
96
|
+
strategy: StrategyWithAddress | undefined;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export interface DepositWithLeverageSwapInputsProps<QuoteResponse> extends BaseLeverageSwapInputsProps<QuoteResponse> {
|
|
100
|
+
obligation: KaminoObligation | null;
|
|
101
|
+
obligationTypeTagOverride: ObligationTypeTag;
|
|
102
|
+
depositAmount: Decimal;
|
|
103
|
+
priceDebtToColl: Decimal;
|
|
104
|
+
targetLeverage: Decimal;
|
|
105
|
+
selectedTokenMint: PublicKey;
|
|
106
|
+
priceAinB: PriceAinBProvider;
|
|
101
107
|
// currently only used to disable requesting elevation group when this value is 0
|
|
102
108
|
// to be implemented properly in the future
|
|
103
109
|
elevationGroupOverride?: number;
|
|
104
|
-
useV2Ixs: boolean;
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
export interface DepositWithLeverageProps<QuoteResponse> extends DepositWithLeverageSwapInputsProps<QuoteResponse> {
|
|
@@ -120,12 +125,8 @@ export type DepositLeverageCalcsResult = {
|
|
|
120
125
|
requiredCollateralKtokenOnly: Decimal;
|
|
121
126
|
};
|
|
122
127
|
|
|
123
|
-
export type WithdrawLeverageIxsResponse<QuoteResponse> = {
|
|
124
|
-
|
|
125
|
-
lookupTables: AddressLookupTableAccount[];
|
|
126
|
-
swapInputs: SwapInputs;
|
|
127
|
-
flashLoanInfo: FlashLoanInfo;
|
|
128
|
-
initialInputs: WithdrawLeverageInitialInputs<QuoteResponse>;
|
|
128
|
+
export type WithdrawLeverageIxsResponse<QuoteResponse> = BaseLeverageIxsResponse & {
|
|
129
|
+
initialInputs: LeverageInitialInputs<WithdrawLeverageCalcsResult, QuoteResponse>;
|
|
129
130
|
};
|
|
130
131
|
|
|
131
132
|
export type WithdrawLeverageInitialInputs<QuoteResponse> = {
|
|
@@ -138,28 +139,14 @@ export type WithdrawLeverageInitialInputs<QuoteResponse> = {
|
|
|
138
139
|
strategy: StrategyWithAddress | undefined;
|
|
139
140
|
};
|
|
140
141
|
|
|
141
|
-
export interface WithdrawWithLeverageSwapInputsProps<QuoteResponse> {
|
|
142
|
-
owner: PublicKey;
|
|
143
|
-
kaminoMarket: KaminoMarket;
|
|
144
|
-
debtTokenMint: PublicKey;
|
|
145
|
-
collTokenMint: PublicKey;
|
|
142
|
+
export interface WithdrawWithLeverageSwapInputsProps<QuoteResponse> extends BaseLeverageSwapInputsProps<QuoteResponse> {
|
|
146
143
|
obligation: KaminoObligation;
|
|
147
144
|
deposited: Decimal;
|
|
148
145
|
borrowed: Decimal;
|
|
149
|
-
referrer: PublicKey;
|
|
150
|
-
currentSlot: number;
|
|
151
146
|
withdrawAmount: Decimal;
|
|
152
147
|
priceCollToDebt: Decimal;
|
|
153
|
-
slippagePct: Decimal;
|
|
154
148
|
isClosingPosition: boolean;
|
|
155
149
|
selectedTokenMint: PublicKey;
|
|
156
|
-
budgetAndPriorityFeeIxs?: TransactionInstruction[];
|
|
157
|
-
kamino: Kamino | undefined;
|
|
158
|
-
scopeRefreshConfig?: ScopePriceRefreshConfig;
|
|
159
|
-
quoteBufferBps: Decimal;
|
|
160
|
-
isKtoken: IsKtokenProvider;
|
|
161
|
-
quoter: SwapQuoteProvider<QuoteResponse>;
|
|
162
|
-
useV2Ixs: boolean;
|
|
163
150
|
}
|
|
164
151
|
|
|
165
152
|
export interface WithdrawWithLeverageProps<QuoteResponse> extends WithdrawWithLeverageSwapInputsProps<QuoteResponse> {
|
|
@@ -174,12 +161,10 @@ export type WithdrawLeverageCalcsResult = {
|
|
|
174
161
|
debtTokenExpectedSwapOut: Decimal;
|
|
175
162
|
};
|
|
176
163
|
|
|
177
|
-
export type AdjustLeverageIxsResponse<QuoteResponse> = {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
flashLoanInfo: FlashLoanInfo;
|
|
182
|
-
initialInputs: AdjustLeverageInitialInputs<QuoteResponse>;
|
|
164
|
+
export type AdjustLeverageIxsResponse<QuoteResponse> = BaseLeverageIxsResponse & {
|
|
165
|
+
initialInputs: LeverageInitialInputs<AdjustLeverageCalcsResult, QuoteResponse> & {
|
|
166
|
+
isDeposit: boolean;
|
|
167
|
+
};
|
|
183
168
|
};
|
|
184
169
|
|
|
185
170
|
export type AdjustLeverageInitialInputs<QuoteResponse> = {
|
|
@@ -193,28 +178,14 @@ export type AdjustLeverageInitialInputs<QuoteResponse> = {
|
|
|
193
178
|
strategy: StrategyWithAddress | undefined;
|
|
194
179
|
};
|
|
195
180
|
|
|
196
|
-
export interface AdjustLeverageSwapInputsProps<QuoteResponse> {
|
|
197
|
-
owner: PublicKey;
|
|
198
|
-
kaminoMarket: KaminoMarket;
|
|
199
|
-
debtTokenMint: PublicKey;
|
|
200
|
-
collTokenMint: PublicKey;
|
|
181
|
+
export interface AdjustLeverageSwapInputsProps<QuoteResponse> extends BaseLeverageSwapInputsProps<QuoteResponse> {
|
|
201
182
|
obligation: KaminoObligation;
|
|
202
183
|
depositedLamports: Decimal;
|
|
203
184
|
borrowedLamports: Decimal;
|
|
204
|
-
referrer: PublicKey;
|
|
205
|
-
currentSlot: number;
|
|
206
185
|
targetLeverage: Decimal;
|
|
207
186
|
priceCollToDebt: Decimal;
|
|
208
187
|
priceDebtToColl: Decimal;
|
|
209
|
-
slippagePct: Decimal;
|
|
210
|
-
budgetAndPriorityFeeIxs?: TransactionInstruction[];
|
|
211
|
-
kamino: Kamino | undefined;
|
|
212
|
-
scopeRefreshConfig?: ScopePriceRefreshConfig;
|
|
213
|
-
quoteBufferBps: Decimal;
|
|
214
188
|
priceAinB: PriceAinBProvider;
|
|
215
|
-
isKtoken: IsKtokenProvider;
|
|
216
|
-
quoter: SwapQuoteProvider<QuoteResponse>;
|
|
217
|
-
useV2Ixs: boolean;
|
|
218
189
|
}
|
|
219
190
|
|
|
220
191
|
export interface AdjustLeverageProps<QuoteResponse> extends AdjustLeverageSwapInputsProps<QuoteResponse> {
|
package/src/leverage/utils.ts
CHANGED
|
@@ -40,7 +40,7 @@ export async function getTokenToKtokenSwapper<QuoteResponse>(
|
|
|
40
40
|
quote: SwapQuote<QuoteResponse>
|
|
41
41
|
): Promise<SwapIxs> => {
|
|
42
42
|
const slippageBps = new Decimal(slippagePct).mul('100');
|
|
43
|
-
const mintInDecimals = kaminoMarket.
|
|
43
|
+
const mintInDecimals = kaminoMarket.getExistingReserveByMint(inputs.inputMint).getMintDecimals();
|
|
44
44
|
const amountIn = lamportsToNumberDecimal(inputs.inputAmountLamports, mintInDecimals);
|
|
45
45
|
console.debug('Depositing token', inputs.inputMint.toString(), ' for ', inputs.outputMint.toString(), 'ktoken');
|
|
46
46
|
if (inputs.amountDebtAtaBalance === undefined) {
|
|
@@ -134,7 +134,7 @@ export async function getKtokenToTokenSwapper<QuoteResponse>(
|
|
|
134
134
|
swapper: SwapIxsProvider<QuoteResponse>
|
|
135
135
|
): Promise<SwapIxsProvider<QuoteResponse>> {
|
|
136
136
|
return async (inputs: SwapInputs, klendAccounts: Array<PublicKey>, quote: SwapQuote<QuoteResponse>) => {
|
|
137
|
-
const amountInDecimals = kaminoMarket.
|
|
137
|
+
const amountInDecimals = kaminoMarket.getExistingReserveByMint(inputs.inputMint).getMintDecimals();
|
|
138
138
|
const amountToWithdraw = lamportsToNumberDecimal(inputs.inputAmountLamports, amountInDecimals);
|
|
139
139
|
const kaminoStrategy = await kamino.getStrategyByKTokenMint(inputs.inputMint);
|
|
140
140
|
|
|
@@ -298,13 +298,13 @@ export const getExpectedTokenBalanceAfterBorrow = async (
|
|
|
298
298
|
mint: PublicKey,
|
|
299
299
|
owner: PublicKey,
|
|
300
300
|
amountToBorrowLamports: Decimal,
|
|
301
|
-
|
|
301
|
+
amountToBorrowMintDecimals: number
|
|
302
302
|
) => {
|
|
303
303
|
const initialUserTokenABalance = await getTokenAccountBalanceDecimal(connection, mint, owner);
|
|
304
304
|
|
|
305
305
|
return initialUserTokenABalance
|
|
306
|
-
.add(lamportsToNumberDecimal(amountToBorrowLamports,
|
|
307
|
-
.toDecimalPlaces(
|
|
306
|
+
.add(lamportsToNumberDecimal(amountToBorrowLamports, amountToBorrowMintDecimals))
|
|
307
|
+
.toDecimalPlaces(amountToBorrowMintDecimals);
|
|
308
308
|
};
|
|
309
309
|
|
|
310
310
|
export const isBorrowingEnabled = (reserve: KaminoReserve) => {
|
package/src/utils/ata.ts
CHANGED
|
@@ -7,14 +7,7 @@ import {
|
|
|
7
7
|
createCloseAccountInstruction,
|
|
8
8
|
getAssociatedTokenAddressSync,
|
|
9
9
|
} from '@solana/spl-token';
|
|
10
|
-
import {
|
|
11
|
-
AccountInfo,
|
|
12
|
-
ComputeBudgetProgram,
|
|
13
|
-
Connection,
|
|
14
|
-
PublicKey,
|
|
15
|
-
SystemProgram,
|
|
16
|
-
TransactionInstruction,
|
|
17
|
-
} from '@solana/web3.js';
|
|
10
|
+
import { AccountInfo, Connection, PublicKey, SystemProgram, TransactionInstruction } from '@solana/web3.js';
|
|
18
11
|
import Decimal from 'decimal.js';
|
|
19
12
|
import { collToLamportsDecimal, DECIMALS_SOL } from '@kamino-finance/kliquidity-sdk/dist';
|
|
20
13
|
|
|
@@ -137,24 +130,6 @@ export function getTransferWsolIxs(owner: PublicKey, ata: PublicKey, amountLampo
|
|
|
137
130
|
return ixs;
|
|
138
131
|
}
|
|
139
132
|
|
|
140
|
-
export function removeBudgetAndAtaIxs(ixs: TransactionInstruction[], mints: string[]): TransactionInstruction[] {
|
|
141
|
-
return ixs.filter((ix) => {
|
|
142
|
-
const { programId, keys } = ix;
|
|
143
|
-
|
|
144
|
-
if (programId.equals(ComputeBudgetProgram.programId)) {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (programId.equals(ASSOCIATED_TOKEN_PROGRAM_ID)) {
|
|
149
|
-
const mint = keys[3];
|
|
150
|
-
|
|
151
|
-
return !mints.includes(mint.pubkey.toString());
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return true;
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
133
|
export async function getTokenAccountBalance(connection: Connection, tokenAccount: PublicKey): Promise<number> {
|
|
159
134
|
const tokenAccountBalance = await connection.getTokenAccountBalance(tokenAccount);
|
|
160
135
|
|
package/src/utils/instruction.ts
CHANGED
|
@@ -281,3 +281,15 @@ export function uniqueAccountsWithProgramIds(
|
|
|
281
281
|
|
|
282
282
|
return uniqueAccounts.toArray();
|
|
283
283
|
}
|
|
284
|
+
|
|
285
|
+
export function removeBudgetIxs(ixs: TransactionInstruction[]): TransactionInstruction[] {
|
|
286
|
+
return ixs.filter((ix) => {
|
|
287
|
+
const { programId } = ix;
|
|
288
|
+
|
|
289
|
+
if (programId.equals(ComputeBudgetProgram.programId)) {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return true;
|
|
294
|
+
});
|
|
295
|
+
}
|