@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.
Files changed (56) hide show
  1. package/dist/classes/action.d.ts +7 -3
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +28 -13
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/market.d.ts +11 -0
  6. package/dist/classes/market.d.ts.map +1 -1
  7. package/dist/classes/market.js +26 -0
  8. package/dist/classes/market.js.map +1 -1
  9. package/dist/classes/obligation.d.ts +14 -0
  10. package/dist/classes/obligation.d.ts.map +1 -1
  11. package/dist/classes/obligation.js +25 -0
  12. package/dist/classes/obligation.js.map +1 -1
  13. package/dist/lending_operations/index.d.ts +1 -0
  14. package/dist/lending_operations/index.d.ts.map +1 -1
  15. package/dist/lending_operations/index.js +1 -0
  16. package/dist/lending_operations/index.js.map +1 -1
  17. package/dist/lending_operations/repay_with_collateral_operations.d.ts +5 -5
  18. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  19. package/dist/lending_operations/repay_with_collateral_operations.js +3 -2
  20. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  21. package/dist/lending_operations/swap_collateral_operations.d.ts +102 -0
  22. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -0
  23. package/dist/lending_operations/swap_collateral_operations.js +306 -0
  24. package/dist/lending_operations/swap_collateral_operations.js.map +1 -0
  25. package/dist/leverage/operations.d.ts +2 -2
  26. package/dist/leverage/operations.d.ts.map +1 -1
  27. package/dist/leverage/operations.js +4 -0
  28. package/dist/leverage/operations.js.map +1 -1
  29. package/dist/leverage/types.d.ts +5 -5
  30. package/dist/leverage/types.d.ts.map +1 -1
  31. package/dist/leverage/utils.d.ts +5 -5
  32. package/dist/leverage/utils.d.ts.map +1 -1
  33. package/dist/leverage/utils.js.map +1 -1
  34. package/dist/utils/constants.d.ts +1 -0
  35. package/dist/utils/constants.d.ts.map +1 -1
  36. package/dist/utils/constants.js +2 -1
  37. package/dist/utils/constants.js.map +1 -1
  38. package/dist/utils/pubkey.d.ts +3 -0
  39. package/dist/utils/pubkey.d.ts.map +1 -1
  40. package/dist/utils/pubkey.js +16 -2
  41. package/dist/utils/pubkey.js.map +1 -1
  42. package/dist/utils/seeds.d.ts +1 -1
  43. package/dist/utils/seeds.js +1 -1
  44. package/package.json +4 -4
  45. package/src/classes/action.ts +37 -19
  46. package/src/classes/market.ts +35 -1
  47. package/src/classes/obligation.ts +75 -0
  48. package/src/lending_operations/index.ts +1 -0
  49. package/src/lending_operations/repay_with_collateral_operations.ts +10 -9
  50. package/src/lending_operations/swap_collateral_operations.ts +586 -0
  51. package/src/leverage/operations.ts +14 -10
  52. package/src/leverage/types.ts +6 -6
  53. package/src/leverage/utils.ts +8 -8
  54. package/src/utils/constants.ts +2 -0
  55. package/src/utils/pubkey.ts +19 -2
  56. package/src/utils/seeds.ts +1 -1
@@ -9,18 +9,18 @@ export type SwapQuoteProvider<QuoteResponse> = (
9
9
  klendAccounts: Array<PublicKey>
10
10
  ) => Promise<SwapQuote<QuoteResponse>>;
11
11
 
12
- export type SwapQuoteIxsProvider<QuoteResponse> = (
12
+ export type SwapIxsProvider<QuoteResponse> = (
13
13
  inputs: SwapInputs,
14
14
  klendAccounts: Array<PublicKey>,
15
15
  quote: SwapQuote<QuoteResponse>
16
- ) => Promise<SwapQuoteIxs>;
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 SwapQuoteIxs = {
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: SwapQuoteIxsProvider<QuoteResponse>;
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: SwapQuoteIxsProvider<QuoteResponse>;
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: SwapQuoteIxsProvider<QuoteResponse>;
205
+ swapper: SwapIxsProvider<QuoteResponse>;
206
206
  }
207
207
 
208
208
  export type AdjustLeverageCalcsResult = {
@@ -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, SwapQuoteIxs, SwapQuoteIxsProvider } from './types';
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: SwapQuoteIxsProvider<QuoteResponse>,
33
+ swapper: SwapIxsProvider<QuoteResponse>,
34
34
  priceAinB: PriceAinBProvider,
35
35
  includeAtaIxns: boolean = true
36
- ): Promise<SwapQuoteIxsProvider<QuoteResponse>> {
36
+ ): Promise<SwapIxsProvider<QuoteResponse>> {
37
37
  return async (
38
38
  inputs: SwapInputs,
39
39
  klendAccounts: Array<PublicKey>,
40
40
  quote: SwapQuote<QuoteResponse>
41
- ): Promise<SwapQuoteIxs> => {
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: SwapQuoteIxsProvider<QuoteResponse>,
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: SwapQuoteIxsProvider<QuoteResponse>
135
- ): Promise<SwapQuoteIxsProvider<QuoteResponse>> {
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: SwapQuoteIxsProvider<QuoteResponse>,
254
+ swapper: SwapIxsProvider<QuoteResponse>,
255
255
  klendAccounts: Array<PublicKey>,
256
256
  swapQuote: SwapQuote<QuoteResponse>
257
257
  ): KaminoSwapperIxBuilder {
@@ -87,3 +87,5 @@ export const MAINNET_BETA_CHAIN_ID = 101;
87
87
  export const POSITION_LIMIT = 10;
88
88
  export const BORROWS_LIMIT = 5;
89
89
  export const DEPOSITS_LIMIT = 8;
90
+
91
+ export const DEFAULT_MAX_COMPUTE_UNITS = 1_400_000;
@@ -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.items.some((existingItem) => this.equals(existingItem, item));
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.items.length === 0;
55
+ return this.size() === 0;
56
+ }
57
+
58
+ size(): number {
59
+ return this.items.length;
43
60
  }
44
61
 
45
62
  toArray(): T[] {
@@ -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 mint
150
+ * @param reserve
151
151
  * @param programId
152
152
  * @returns [pda, bump]
153
153
  */