@kamino-finance/klend-sdk 5.10.6 → 5.10.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/action.d.ts +7 -3
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +28 -13
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/market.d.ts +11 -0
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +26 -0
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +14 -0
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +25 -0
- package/dist/classes/obligation.js.map +1 -1
- 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 +5 -5
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +3 -2
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +102 -0
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -0
- package/dist/lending_operations/swap_collateral_operations.js +306 -0
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -0
- package/dist/leverage/operations.d.ts +2 -2
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +4 -0
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +5 -5
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/leverage/utils.d.ts +5 -5
- package/dist/leverage/utils.d.ts.map +1 -1
- package/dist/leverage/utils.js.map +1 -1
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +2 -1
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/pubkey.d.ts +3 -0
- package/dist/utils/pubkey.d.ts.map +1 -1
- package/dist/utils/pubkey.js +16 -2
- package/dist/utils/pubkey.js.map +1 -1
- package/dist/utils/seeds.d.ts +1 -1
- package/dist/utils/seeds.js +1 -1
- package/package.json +4 -4
- package/src/classes/action.ts +37 -19
- package/src/classes/market.ts +35 -1
- package/src/classes/obligation.ts +75 -0
- package/src/lending_operations/index.ts +1 -0
- package/src/lending_operations/repay_with_collateral_operations.ts +10 -9
- package/src/lending_operations/swap_collateral_operations.ts +586 -0
- package/src/leverage/operations.ts +14 -10
- package/src/leverage/types.ts +6 -6
- package/src/leverage/utils.ts +8 -8
- package/src/utils/constants.ts +2 -0
- package/src/utils/pubkey.ts +19 -2
- package/src/utils/seeds.ts +1 -1
package/src/leverage/types.ts
CHANGED
|
@@ -9,18 +9,18 @@ export type SwapQuoteProvider<QuoteResponse> = (
|
|
|
9
9
|
klendAccounts: Array<PublicKey>
|
|
10
10
|
) => Promise<SwapQuote<QuoteResponse>>;
|
|
11
11
|
|
|
12
|
-
export type
|
|
12
|
+
export type SwapIxsProvider<QuoteResponse> = (
|
|
13
13
|
inputs: SwapInputs,
|
|
14
14
|
klendAccounts: Array<PublicKey>,
|
|
15
15
|
quote: SwapQuote<QuoteResponse>
|
|
16
|
-
) => Promise<
|
|
16
|
+
) => Promise<SwapIxs>;
|
|
17
17
|
|
|
18
18
|
export type SwapQuote<QuoteResponse> = {
|
|
19
19
|
priceAInB: Decimal;
|
|
20
20
|
quoteResponse?: QuoteResponse;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
export type
|
|
23
|
+
export type SwapIxs = {
|
|
24
24
|
preActionIxs: TransactionInstruction[];
|
|
25
25
|
swapIxs: TransactionInstruction[];
|
|
26
26
|
lookupTables: AddressLookupTableAccount[];
|
|
@@ -93,7 +93,7 @@ export interface DepositWithLeverageSwapInputsProps<QuoteResponse> {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
export interface DepositWithLeverageProps<QuoteResponse> extends DepositWithLeverageSwapInputsProps<QuoteResponse> {
|
|
96
|
-
swapper:
|
|
96
|
+
swapper: SwapIxsProvider<QuoteResponse>;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
export type DepositLeverageCalcsResult = {
|
|
@@ -149,7 +149,7 @@ export interface WithdrawWithLeverageSwapInputsProps<QuoteResponse> {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
export interface WithdrawWithLeverageProps<QuoteResponse> extends WithdrawWithLeverageSwapInputsProps<QuoteResponse> {
|
|
152
|
-
swapper:
|
|
152
|
+
swapper: SwapIxsProvider<QuoteResponse>;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
export type WithdrawLeverageCalcsResult = {
|
|
@@ -202,7 +202,7 @@ export interface AdjustLeverageSwapInputsProps<QuoteResponse> {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
export interface AdjustLeverageProps<QuoteResponse> extends AdjustLeverageSwapInputsProps<QuoteResponse> {
|
|
205
|
-
swapper:
|
|
205
|
+
swapper: SwapIxsProvider<QuoteResponse>;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
export type AdjustLeverageCalcsResult = {
|
package/src/leverage/utils.ts
CHANGED
|
@@ -5,7 +5,7 @@ import Decimal from 'decimal.js';
|
|
|
5
5
|
import { getLookupTableAccounts, getTokenAccountBalanceDecimal } from '../utils';
|
|
6
6
|
import { numberToLamportsDecimal } from '../classes/utils';
|
|
7
7
|
import BN from 'bn.js';
|
|
8
|
-
import { PriceAinBProvider, SwapInputs, SwapQuote,
|
|
8
|
+
import { PriceAinBProvider, SwapInputs, SwapQuote, SwapIxs, SwapIxsProvider } from './types';
|
|
9
9
|
|
|
10
10
|
export interface KaminoSwapperIxBuilder {
|
|
11
11
|
(
|
|
@@ -30,15 +30,15 @@ export async function getTokenToKtokenSwapper<QuoteResponse>(
|
|
|
30
30
|
kamino: Kamino,
|
|
31
31
|
depositor: PublicKey,
|
|
32
32
|
slippagePct: Decimal,
|
|
33
|
-
swapper:
|
|
33
|
+
swapper: SwapIxsProvider<QuoteResponse>,
|
|
34
34
|
priceAinB: PriceAinBProvider,
|
|
35
35
|
includeAtaIxns: boolean = true
|
|
36
|
-
): Promise<
|
|
36
|
+
): Promise<SwapIxsProvider<QuoteResponse>> {
|
|
37
37
|
return async (
|
|
38
38
|
inputs: SwapInputs,
|
|
39
39
|
klendAccounts: Array<PublicKey>,
|
|
40
40
|
quote: SwapQuote<QuoteResponse>
|
|
41
|
-
): Promise<
|
|
41
|
+
): Promise<SwapIxs> => {
|
|
42
42
|
const slippageBps = new Decimal(slippagePct).mul('100');
|
|
43
43
|
const mintInDecimals = kaminoMarket.getReserveByMint(inputs.inputMint)!.state.liquidity.mintDecimals.toNumber();
|
|
44
44
|
const amountIn = lamportsToNumberDecimal(inputs.inputAmountLamports, mintInDecimals);
|
|
@@ -82,7 +82,7 @@ export async function getKtokenDepositIxs<QuoteResponse>(
|
|
|
82
82
|
amountToDeposit: Decimal,
|
|
83
83
|
slippageBps: Decimal,
|
|
84
84
|
amountExpectedDepositAtaBalance: Decimal,
|
|
85
|
-
swapper:
|
|
85
|
+
swapper: SwapIxsProvider<QuoteResponse>,
|
|
86
86
|
priceAinB: PriceAinBProvider,
|
|
87
87
|
includeAtaIxns: boolean = true,
|
|
88
88
|
klendAccounts: Array<PublicKey>,
|
|
@@ -131,8 +131,8 @@ export async function getKtokenToTokenSwapper<QuoteResponse>(
|
|
|
131
131
|
kaminoMarket: KaminoMarket,
|
|
132
132
|
kamino: Kamino,
|
|
133
133
|
depositor: PublicKey,
|
|
134
|
-
swapper:
|
|
135
|
-
): Promise<
|
|
134
|
+
swapper: SwapIxsProvider<QuoteResponse>
|
|
135
|
+
): Promise<SwapIxsProvider<QuoteResponse>> {
|
|
136
136
|
return async (inputs: SwapInputs, klendAccounts: Array<PublicKey>, quote: SwapQuote<QuoteResponse>) => {
|
|
137
137
|
const amountInDecimals = kaminoMarket.getReserveByMint(inputs.inputMint)!.state.liquidity.mintDecimals.toNumber();
|
|
138
138
|
const amountToWithdraw = lamportsToNumberDecimal(inputs.inputAmountLamports, amountInDecimals);
|
|
@@ -251,7 +251,7 @@ export async function getKtokenWithdrawEstimatesAndPrice(
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
export function swapProviderToKaminoSwapProvider<QuoteResponse>(
|
|
254
|
-
swapper:
|
|
254
|
+
swapper: SwapIxsProvider<QuoteResponse>,
|
|
255
255
|
klendAccounts: Array<PublicKey>,
|
|
256
256
|
swapQuote: SwapQuote<QuoteResponse>
|
|
257
257
|
): KaminoSwapperIxBuilder {
|
package/src/utils/constants.ts
CHANGED
package/src/utils/pubkey.ts
CHANGED
|
@@ -30,8 +30,21 @@ export class PublicKeySet<T extends PublicKey> {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
remove(item: T): boolean {
|
|
34
|
+
const index = this.indexOf(item);
|
|
35
|
+
if (index == -1) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
this.items.splice(index, 1);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
33
42
|
contains(item: T): boolean {
|
|
34
|
-
return this.
|
|
43
|
+
return this.indexOf(item) != -1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private indexOf(item: T): number {
|
|
47
|
+
return this.items.findIndex((existingItem) => this.equals(existingItem, item));
|
|
35
48
|
}
|
|
36
49
|
|
|
37
50
|
private equals(item1: T, item2: T): boolean {
|
|
@@ -39,7 +52,11 @@ export class PublicKeySet<T extends PublicKey> {
|
|
|
39
52
|
}
|
|
40
53
|
|
|
41
54
|
isEmpty(): boolean {
|
|
42
|
-
return this.
|
|
55
|
+
return this.size() === 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
size(): number {
|
|
59
|
+
return this.items.length;
|
|
43
60
|
}
|
|
44
61
|
|
|
45
62
|
toArray(): T[] {
|
package/src/utils/seeds.ts
CHANGED
|
@@ -147,7 +147,7 @@ export function userMetadataPda(user: PublicKey, programId: PublicKey = PROGRAM_
|
|
|
147
147
|
/**
|
|
148
148
|
* Returns the PDA and bump for the referrer account for a mint
|
|
149
149
|
* @param referrer
|
|
150
|
-
* @param
|
|
150
|
+
* @param reserve
|
|
151
151
|
* @param programId
|
|
152
152
|
* @returns [pda, bump]
|
|
153
153
|
*/
|