@kamino-finance/klend-sdk 7.3.10-beta.0 → 7.3.10-beta.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.
Files changed (131) hide show
  1. package/dist/classes/action.d.ts +21 -91
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +152 -139
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/actionTypes.d.ts +310 -0
  6. package/dist/classes/actionTypes.d.ts.map +1 -0
  7. package/dist/classes/actionTypes.js +3 -0
  8. package/dist/classes/actionTypes.js.map +1 -0
  9. package/dist/classes/configItems.d.ts +1 -6
  10. package/dist/classes/configItems.d.ts.map +1 -1
  11. package/dist/classes/configItems.js +1 -93
  12. package/dist/classes/configItems.js.map +1 -1
  13. package/dist/classes/farm_utils.d.ts +1 -1
  14. package/dist/classes/farm_utils.d.ts.map +1 -1
  15. package/dist/classes/farm_utils.js +3 -1
  16. package/dist/classes/farm_utils.js.map +1 -1
  17. package/dist/classes/market.d.ts +15 -10
  18. package/dist/classes/market.d.ts.map +1 -1
  19. package/dist/classes/market.js +49 -26
  20. package/dist/classes/market.js.map +1 -1
  21. package/dist/classes/obligation.d.ts +9 -9
  22. package/dist/classes/obligation.d.ts.map +1 -1
  23. package/dist/classes/obligation.js +48 -50
  24. package/dist/classes/obligation.js.map +1 -1
  25. package/dist/classes/obligationOrder.d.ts.map +1 -1
  26. package/dist/classes/obligationOrder.js +6 -3
  27. package/dist/classes/obligationOrder.js.map +1 -1
  28. package/dist/classes/reserve.d.ts +7 -3
  29. package/dist/classes/reserve.d.ts.map +1 -1
  30. package/dist/classes/reserve.js +31 -43
  31. package/dist/classes/reserve.js.map +1 -1
  32. package/dist/classes/shared.d.ts +3 -2
  33. package/dist/classes/shared.d.ts.map +1 -1
  34. package/dist/classes/vault.d.ts +28 -1
  35. package/dist/classes/vault.d.ts.map +1 -1
  36. package/dist/classes/vault.js +103 -6
  37. package/dist/classes/vault.js.map +1 -1
  38. package/dist/classes/vault_types.d.ts +2 -1
  39. package/dist/classes/vault_types.d.ts.map +1 -1
  40. package/dist/client/commands/borrow.d.ts +1 -1
  41. package/dist/client/commands/borrow.d.ts.map +1 -1
  42. package/dist/client/commands/borrow.js +11 -2
  43. package/dist/client/commands/borrow.js.map +1 -1
  44. package/dist/client/commands/deposit.d.ts +1 -1
  45. package/dist/client/commands/deposit.d.ts.map +1 -1
  46. package/dist/client/commands/deposit.js +11 -2
  47. package/dist/client/commands/deposit.js.map +1 -1
  48. package/dist/client/commands/printReserve.d.ts +1 -1
  49. package/dist/client/commands/printReserve.d.ts.map +1 -1
  50. package/dist/client/commands/printReserve.js +2 -4
  51. package/dist/client/commands/printReserve.js.map +1 -1
  52. package/dist/client/commands/repay.d.ts +1 -1
  53. package/dist/client/commands/repay.d.ts.map +1 -1
  54. package/dist/client/commands/repay.js +12 -2
  55. package/dist/client/commands/repay.js.map +1 -1
  56. package/dist/client/commands/withdraw.d.ts +1 -1
  57. package/dist/client/commands/withdraw.d.ts.map +1 -1
  58. package/dist/client/commands/withdraw.js +11 -2
  59. package/dist/client/commands/withdraw.js.map +1 -1
  60. package/dist/lending_operations/repay_with_collateral_calcs.d.ts +1 -1
  61. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  62. package/dist/lending_operations/repay_with_collateral_calcs.js +2 -2
  63. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  64. package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -4
  65. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  66. package/dist/lending_operations/repay_with_collateral_operations.js +43 -10
  67. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  68. package/dist/lending_operations/swap_collateral_operations.d.ts +4 -4
  69. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  70. package/dist/lending_operations/swap_collateral_operations.js +40 -21
  71. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  72. package/dist/leverage/operations.d.ts +6 -6
  73. package/dist/leverage/operations.d.ts.map +1 -1
  74. package/dist/leverage/operations.js +167 -52
  75. package/dist/leverage/operations.js.map +1 -1
  76. package/dist/leverage/types.d.ts +2 -2
  77. package/dist/leverage/types.d.ts.map +1 -1
  78. package/dist/manager/client_kamino_manager.js +0 -2
  79. package/dist/manager/client_kamino_manager.js.map +1 -1
  80. package/dist/obligation_orders/price_based.js +5 -3
  81. package/dist/obligation_orders/price_based.js.map +1 -1
  82. package/dist/utils/Logger.d.ts +14 -0
  83. package/dist/utils/Logger.d.ts.map +1 -0
  84. package/dist/utils/Logger.js +12 -0
  85. package/dist/utils/Logger.js.map +1 -0
  86. package/dist/utils/ObligationType.d.ts +33 -1
  87. package/dist/utils/ObligationType.d.ts.map +1 -1
  88. package/dist/utils/ObligationType.js +81 -2
  89. package/dist/utils/ObligationType.js.map +1 -1
  90. package/dist/utils/api.d.ts +13 -4
  91. package/dist/utils/api.d.ts.map +1 -1
  92. package/dist/utils/api.js +33 -31
  93. package/dist/utils/api.js.map +1 -1
  94. package/dist/utils/userMetadata.d.ts +2 -2
  95. package/dist/utils/userMetadata.d.ts.map +1 -1
  96. package/dist/utils/userMetadata.js +49 -25
  97. package/dist/utils/userMetadata.js.map +1 -1
  98. package/dist/utils/validations.d.ts +1 -0
  99. package/dist/utils/validations.d.ts.map +1 -1
  100. package/dist/utils/validations.js +5 -0
  101. package/dist/utils/validations.js.map +1 -1
  102. package/package.json +1 -1
  103. package/src/classes/action.ts +346 -372
  104. package/src/classes/actionTypes.ts +295 -0
  105. package/src/classes/configItems.ts +1 -99
  106. package/src/classes/farm_utils.ts +5 -1
  107. package/src/classes/market.ts +74 -31
  108. package/src/classes/obligation.ts +54 -53
  109. package/src/classes/obligationOrder.ts +6 -3
  110. package/src/classes/reserve.ts +118 -122
  111. package/src/classes/shared.ts +4 -2
  112. package/src/classes/vault.ts +160 -7
  113. package/src/classes/vault_types.ts +2 -1
  114. package/src/client/client.ts +17 -18
  115. package/src/client/commands/borrow.ts +10 -9
  116. package/src/client/commands/deposit.ts +10 -9
  117. package/src/client/commands/printReserve.ts +2 -4
  118. package/src/client/commands/repay.ts +11 -10
  119. package/src/client/commands/withdraw.ts +15 -9
  120. package/src/lending_operations/repay_with_collateral_calcs.ts +3 -4
  121. package/src/lending_operations/repay_with_collateral_operations.ts +40 -38
  122. package/src/lending_operations/swap_collateral_operations.ts +47 -41
  123. package/src/leverage/operations.ts +168 -129
  124. package/src/leverage/types.ts +2 -2
  125. package/src/manager/client_kamino_manager.ts +0 -2
  126. package/src/obligation_orders/price_based.ts +7 -5
  127. package/src/utils/Logger.ts +14 -0
  128. package/src/utils/ObligationType.ts +92 -1
  129. package/src/utils/api.ts +56 -33
  130. package/src/utils/userMetadata.ts +64 -30
  131. package/src/utils/validations.ts +5 -0
@@ -11,6 +11,9 @@ export enum ObligationTypeTag {
11
11
  Multiply = 1,
12
12
  Lending = 2,
13
13
  Leverage = 3,
14
+ MultiplyFixedRate = 4,
15
+ LendingFixedRate = 5,
16
+ LeverageFixedRate = 6,
14
17
  }
15
18
 
16
19
  export type InitObligationArgsModel = {
@@ -76,6 +79,36 @@ export class MultiplyObligation {
76
79
  }
77
80
  }
78
81
 
82
+ export class MultiplyObligationFixedRate {
83
+ readonly collReserveAddress: Address;
84
+ readonly debtReserveAddress: Address;
85
+ readonly programId: Address;
86
+ readonly id: number;
87
+ static tag = 4;
88
+
89
+ constructor(collReserveAddress: Address, debtReserveAddress: Address, programId: Address, id?: number) {
90
+ this.collReserveAddress = collReserveAddress;
91
+ this.debtReserveAddress = debtReserveAddress;
92
+ this.programId = programId;
93
+ this.id = id ?? 0;
94
+ }
95
+
96
+ toArgs() {
97
+ const initObligationArgs: InitObligationArgsModel = {
98
+ tag: MultiplyObligationFixedRate.tag,
99
+ id: this.id,
100
+ seed1: this.collReserveAddress,
101
+ seed2: this.debtReserveAddress,
102
+ };
103
+
104
+ return initObligationArgs;
105
+ }
106
+
107
+ toPda(market: Address, user: Address) {
108
+ return getObligationPdaWithArgs(market, user, this.toArgs(), this.programId);
109
+ }
110
+ }
111
+
79
112
  export class LeverageObligation {
80
113
  readonly collToken: Address;
81
114
  readonly debtToken: Address;
@@ -106,6 +139,36 @@ export class LeverageObligation {
106
139
  }
107
140
  }
108
141
 
142
+ export class LeverageObligationFixedRate {
143
+ readonly collReserveAddress: Address;
144
+ readonly debtReserveAddress: Address;
145
+ readonly programId: Address;
146
+ readonly id: number;
147
+ static tag = 6;
148
+
149
+ constructor(collReserveAddress: Address, debtReserveAddress: Address, programId: Address, id?: number) {
150
+ this.collReserveAddress = collReserveAddress;
151
+ this.debtReserveAddress = debtReserveAddress;
152
+ this.programId = programId;
153
+ this.id = id ?? 0;
154
+ }
155
+
156
+ toArgs() {
157
+ const initObligationArgs: InitObligationArgsModel = {
158
+ tag: LeverageObligationFixedRate.tag,
159
+ id: this.id,
160
+ seed1: this.collReserveAddress,
161
+ seed2: this.debtReserveAddress,
162
+ };
163
+
164
+ return initObligationArgs;
165
+ }
166
+
167
+ toPda(market: Address, user: Address) {
168
+ return getObligationPdaWithArgs(market, user, this.toArgs(), this.programId);
169
+ }
170
+ }
171
+
109
172
  export class LendingObligation {
110
173
  readonly token: Address;
111
174
  readonly programId: Address;
@@ -121,7 +184,7 @@ export class LendingObligation {
121
184
  toArgs() {
122
185
  const initObligationArgs: InitObligationArgsModel = {
123
186
  tag: LendingObligation.tag,
124
- id: 0,
187
+ id: this.id,
125
188
  seed1: this.token,
126
189
  seed2: this.token,
127
190
  };
@@ -134,6 +197,34 @@ export class LendingObligation {
134
197
  }
135
198
  }
136
199
 
200
+ export class LendingObligationFixedRate {
201
+ readonly reserveAddress: Address;
202
+ readonly programId: Address;
203
+ readonly id: number;
204
+ static tag = 5;
205
+
206
+ constructor(reserveAddress: Address, programId: Address, id?: number) {
207
+ this.reserveAddress = reserveAddress;
208
+ this.programId = programId;
209
+ this.id = id ?? 0;
210
+ }
211
+
212
+ toArgs() {
213
+ const initObligationArgs: InitObligationArgsModel = {
214
+ tag: LendingObligationFixedRate.tag,
215
+ id: this.id,
216
+ seed1: this.reserveAddress,
217
+ seed2: this.reserveAddress,
218
+ };
219
+
220
+ return initObligationArgs;
221
+ }
222
+
223
+ toPda(market: Address, user: Address) {
224
+ return getObligationPdaWithArgs(market, user, this.toArgs(), this.programId);
225
+ }
226
+ }
227
+
137
228
  export async function getObligationPdaWithArgs(
138
229
  market: Address,
139
230
  user: Address,
package/src/utils/api.ts CHANGED
@@ -4,6 +4,7 @@ import { ConfigType, isEmptyObject } from '../classes';
4
4
  import { CDN_ENDPOINT, getApiEndpoint } from '../utils';
5
5
  import { IBackOffOptions, backOff } from 'exponential-backoff';
6
6
  import { PROGRAM_ID } from '../lib';
7
+ import { Logger, LogLevel } from './Logger';
7
8
 
8
9
  export type ApiRequestOptions = {
9
10
  programId?: Address;
@@ -15,6 +16,17 @@ export type ApiFilterOptions = {
15
16
  isCurated?: boolean;
16
17
  };
17
18
 
19
+ export type ApiLoggerOptions = {
20
+ logger?: Logger;
21
+ errorLevel?: LogLevel;
22
+ };
23
+
24
+ export type MarketsApiRequest = {
25
+ api?: ApiRequestOptions;
26
+ filter?: ApiFilterOptions;
27
+ log?: ApiLoggerOptions;
28
+ };
29
+
18
30
  /**
19
31
  * Fetch config from the API
20
32
  * A good place to start to find active klend markets without expensive RPC calls
@@ -23,20 +35,29 @@ export type ApiFilterOptions = {
23
35
  * @param source - CDN is a json file hosted in the cloud, API is a webserver
24
36
  * @param apiBaseUrl - Optional base URL for the API, if not provided, defaults to the standard API endpoint, not used for CDN
25
37
  * @param filterOptions - Config options to filter markets by
38
+ * @param logger - pass a custom logger instance to log retries
39
+ * @param errorLevel - retry log level, NONE for no logs
26
40
  */
27
- export async function getMarketsFromApi(
28
- { programId = PROGRAM_ID, source = 'CDN', apiBaseUrl }: ApiRequestOptions = {},
29
- filterOptions: ApiFilterOptions = {}
30
- ): Promise<ConfigType> {
41
+ export async function getMarketsFromApi({
42
+ api: { programId = PROGRAM_ID, source = 'CDN', apiBaseUrl } = {},
43
+ filter: filterOptions = {},
44
+ log: { logger = console, errorLevel = LogLevel.WARN } = {},
45
+ }: MarketsApiRequest = {}): Promise<ConfigType> {
31
46
  let unfilteredConfigs: ConfigType = {} as ConfigType;
32
47
  if (source === 'CDN') {
33
- unfilteredConfigs = (await backOff(() => axios.get(`${CDN_ENDPOINT}/kamino_lend_config_v3.json`), KAMINO_CDN_RETRY))
34
- .data[programId.toString()] as ConfigType;
48
+ unfilteredConfigs = (
49
+ await backOff(
50
+ () => axios.get(`${CDN_ENDPOINT}/kamino_lend_config_v3.json`),
51
+ getKaminoCdnRetry(logger, errorLevel)
52
+ )
53
+ ).data[programId.toString()] as ConfigType;
35
54
  }
36
55
 
37
56
  if (!unfilteredConfigs || isEmptyObject(unfilteredConfigs)) {
38
57
  const API_ENDPOINT = getApiEndpoint(programId, apiBaseUrl);
39
- unfilteredConfigs = (await backOff(() => axios.get(API_ENDPOINT), KAMINO_API_RETRY)).data as ConfigType;
58
+ unfilteredConfigs = (
59
+ await backOff(() => axios.get(API_ENDPOINT), getKaminoApiRetry(logger, errorLevel, API_ENDPOINT))
60
+ ).data as ConfigType;
40
61
  }
41
62
 
42
63
  return unfilteredConfigs.filter((c) => {
@@ -47,30 +68,32 @@ export async function getMarketsFromApi(
47
68
  });
48
69
  }
49
70
 
50
- export const KAMINO_CDN_RETRY: Partial<IBackOffOptions> = {
51
- maxDelay: 1000,
52
- numOfAttempts: 3,
53
- startingDelay: 10,
54
- retry: (e: any, attemptNumber: number) => {
55
- console.warn(e);
56
- console.warn({
57
- attemptNumber,
58
- message: 'kamino CDN call failed, retrying with exponential backoff...',
59
- });
60
- return true;
61
- },
62
- };
71
+ function getKaminoCdnRetry(logger: Logger, errorLevel: LogLevel): Partial<IBackOffOptions> {
72
+ return {
73
+ maxDelay: 1000,
74
+ numOfAttempts: 3,
75
+ startingDelay: 10,
76
+ retry: (e: any, attemptNumber: number) => {
77
+ log(logger, errorLevel, `kamino CDN call #${attemptNumber} failed, retrying with exponential backoff...`, e);
78
+ return true;
79
+ },
80
+ };
81
+ }
63
82
 
64
- export const KAMINO_API_RETRY: Partial<IBackOffOptions> = {
65
- maxDelay: 1000,
66
- numOfAttempts: 3,
67
- startingDelay: 10,
68
- retry: (e: any, attemptNumber: number) => {
69
- console.warn(e);
70
- console.warn({
71
- attemptNumber,
72
- message: 'api.kamino.finance call failed, retrying with exponential backoff...',
73
- });
74
- return true;
75
- },
76
- };
83
+ function getKaminoApiRetry(logger: Logger, errorLevel: LogLevel, apiUrl: string): Partial<IBackOffOptions> {
84
+ return {
85
+ maxDelay: 1000,
86
+ numOfAttempts: 3,
87
+ startingDelay: 10,
88
+ retry: (e: any, attemptNumber: number) => {
89
+ log(logger, errorLevel, `${apiUrl} call #${attemptNumber} failed, retrying with exponential backoff...`, e);
90
+ return true;
91
+ },
92
+ };
93
+ }
94
+
95
+ function log(logger: Logger, errorLevel: LogLevel, msg: string, ...meta: any[]): void {
96
+ if (errorLevel !== LogLevel.NONE) {
97
+ logger[errorLevel](msg, ...meta);
98
+ }
99
+ }
@@ -25,6 +25,8 @@ import {
25
25
  UserMetadata,
26
26
  obligationFarmStatePda,
27
27
  DEFAULT_PUBLIC_KEY,
28
+ MultiplyObligationFixedRate,
29
+ LeverageObligationFixedRate,
28
30
  } from '../lib';
29
31
  import { KaminoReserve } from '../classes/reserve';
30
32
  import { Buffer } from 'buffer';
@@ -42,8 +44,8 @@ export const getUserLutAddressAndSetupIxs = async (
42
44
  user: TransactionSigner,
43
45
  referrer: Option<Address> = none(),
44
46
  withExtendLut: boolean = true,
45
- multiplyMints: { coll: Address; debt: Address }[] = [],
46
- leverageMints: { coll: Address; debt: Address }[] = [],
47
+ multiplyReserveAddresses: { coll: Address; debt: Address }[] = [],
48
+ leverageReserveAddresses: { coll: Address; debt: Address }[] = [],
47
49
  repayWithCollObligation: KaminoObligation | undefined = undefined,
48
50
  payer: TransactionSigner = user
49
51
  ): Promise<[Address, Instruction[][]]> => {
@@ -89,8 +91,8 @@ export const getUserLutAddressAndSetupIxs = async (
89
91
  userLookupTableAddress,
90
92
  user.address,
91
93
  referrer,
92
- multiplyMints,
93
- leverageMints,
94
+ multiplyReserveAddresses,
95
+ leverageReserveAddresses,
94
96
  userMetadataState !== null,
95
97
  repayWithCollObligation
96
98
  );
@@ -110,8 +112,8 @@ const getDedupUserLookupTableAddresses = async (
110
112
  tableAddress: Address,
111
113
  user: Address,
112
114
  referrer: Option<Address>,
113
- multiplyMints: { coll: Address; debt: Address }[] = [],
114
- leverageMints: { coll: Address; debt: Address }[] = [],
115
+ multiplyReserveAddresses: { coll: Address; debt: Address }[] = [],
116
+ leverageReserveAddresses: { coll: Address; debt: Address }[] = [],
115
117
  tableExists: boolean,
116
118
  repayWithCollObligation: KaminoObligation | undefined = undefined
117
119
  ): Promise<Address[]> => {
@@ -119,8 +121,8 @@ const getDedupUserLookupTableAddresses = async (
119
121
  kaminoMarket,
120
122
  user,
121
123
  referrer,
122
- multiplyMints,
123
- leverageMints,
124
+ multiplyReserveAddresses,
125
+ leverageReserveAddresses,
124
126
  repayWithCollObligation
125
127
  );
126
128
 
@@ -148,8 +150,8 @@ const getUserLookupTableAddresses = async (
148
150
  kaminoMarket: KaminoMarket,
149
151
  user: Address,
150
152
  referrer: Option<Address>,
151
- multiplyMints: { coll: Address; debt: Address }[] = [],
152
- leverageMints: { coll: Address; debt: Address }[] = [],
153
+ multiplyReserveAddresses: { coll: Address; debt: Address }[] = [],
154
+ leverageReserveAddresses: { coll: Address; debt: Address }[] = [],
153
155
  repayWithCollObligation: KaminoObligation | undefined = undefined
154
156
  ): Promise<{ address: Address; log: string }[]> => {
155
157
  const addresses: { address: Address; log: string }[] = [];
@@ -158,13 +160,22 @@ const getUserLookupTableAddresses = async (
158
160
  addresses.push({ address: userMetadataAddress, log: 'userMetadata address' });
159
161
 
160
162
  const allMints: Address[] = [];
161
- multiplyMints.forEach(({ coll: collMint, debt: debtMint }) => {
162
- allMints.push(collMint);
163
- allMints.push(debtMint);
163
+ const allReserves: Address[] = [];
164
+ multiplyReserveAddresses.forEach(({ coll: collReserveAddress, debt: debtReserveAddress }) => {
165
+ const collReserveMint = kaminoMarket.getExistingReserveByAddress(collReserveAddress)!.getLiquidityMint();
166
+ const debtReserveMint = kaminoMarket.getExistingReserveByAddress(debtReserveAddress)!.getLiquidityMint();
167
+ allMints.push(collReserveMint);
168
+ allMints.push(debtReserveMint);
169
+ allReserves.push(collReserveAddress);
170
+ allReserves.push(debtReserveAddress);
164
171
  });
165
- leverageMints.forEach(({ coll: collMint, debt: debtMint }) => {
166
- allMints.push(collMint);
167
- allMints.push(debtMint);
172
+ leverageReserveAddresses.forEach(({ coll: collReserveAddress, debt: debtReserveAddress }) => {
173
+ const collReserveMint = kaminoMarket.getExistingReserveByAddress(collReserveAddress)!.getLiquidityMint();
174
+ const debtReserveMint = kaminoMarket.getExistingReserveByAddress(debtReserveAddress)!.getLiquidityMint();
175
+ allMints.push(collReserveMint);
176
+ allMints.push(debtReserveMint);
177
+ allReserves.push(collReserveAddress);
178
+ allReserves.push(debtReserveAddress);
168
179
  });
169
180
 
170
181
  if (repayWithCollObligation) {
@@ -178,9 +189,10 @@ const getUserLookupTableAddresses = async (
178
189
  }
179
190
 
180
191
  const dedupMints = [...new Set(allMints)];
192
+ const dedupReserveAddresses = [...new Set(allReserves)];
181
193
  const reserves: KaminoReserve[] = [];
182
- dedupMints.forEach((mint) => {
183
- const kaminoReserve = kaminoMarket.getReserveByMint(mint);
194
+ dedupReserveAddresses.forEach((reserveAddress) => {
195
+ const kaminoReserve = kaminoMarket.getReserveByAddress(reserveAddress);
184
196
  if (kaminoReserve) {
185
197
  reserves.push(kaminoReserve);
186
198
  }
@@ -226,13 +238,13 @@ const getUserLookupTableAddresses = async (
226
238
  }
227
239
 
228
240
  const [multiplyObligations, multiplyObligationsFarmUserStates] =
229
- await getMultiplyObligationAndObligationFarmStateAddresses(kaminoMarket, user, multiplyMints);
241
+ await getMultiplyObligationAndObligationFarmStateAddresses(kaminoMarket, user, multiplyReserveAddresses);
230
242
 
231
243
  addresses.push(...multiplyObligations);
232
244
  addresses.push(...multiplyObligationsFarmUserStates);
233
245
 
234
246
  const [leverageObligations, leverageObligationsFarmUserStates] =
235
- await getLeverageObligationAndObligationFarmStateAddresses(kaminoMarket, user, leverageMints);
247
+ await getLeverageObligationAndObligationFarmStateAddresses(kaminoMarket, user, leverageReserveAddresses);
236
248
 
237
249
  addresses.push(...leverageObligations);
238
250
  addresses.push(...leverageObligationsFarmUserStates);
@@ -252,14 +264,16 @@ const getUserLookupTableAddresses = async (
252
264
  async function getMultiplyObligationAndObligationFarmStateAddresses(
253
265
  kaminoMarket: KaminoMarket,
254
266
  user: Address,
255
- mints: { coll: Address; debt: Address }[]
267
+ reserveAddresses: { coll: Address; debt: Address }[]
256
268
  ): Promise<[{ address: Address; log: string }[], { address: Address; log: string }[]]> {
257
269
  const obligationPdas: { address: Address; log: string }[] = [];
258
270
  const farmUserStates: { address: Address; log: string }[] = [];
259
271
 
260
- for (const { coll: collMint, debt: debtMint } of mints) {
261
- const collReserve = kaminoMarket.getReserveByMint(collMint);
262
- const debtReserve = kaminoMarket.getReserveByMint(debtMint);
272
+ for (const { coll: collReserveAddress, debt: debtReserveAddress } of reserveAddresses) {
273
+ const collReserve = kaminoMarket.getReserveByAddress(collReserveAddress);
274
+ const debtReserve = kaminoMarket.getReserveByAddress(debtReserveAddress);
275
+ const collMint = collReserve!.getLiquidityMint();
276
+ const debtMint = debtReserve!.getLiquidityMint();
263
277
  const collMintString = collMint.toString();
264
278
  const debtMintString = debtMint.toString();
265
279
  if (collReserve && debtReserve) {
@@ -268,6 +282,15 @@ async function getMultiplyObligationAndObligationFarmStateAddresses(
268
282
  address: await multiplyObligation.toPda(kaminoMarket.getAddress(), user),
269
283
  log: 'multiply obligation coll: ' + collMintString + ' debt: ' + debtMintString,
270
284
  });
285
+ const multiplyObligationFixedRate = new MultiplyObligationFixedRate(
286
+ collReserveAddress,
287
+ debtReserveAddress,
288
+ kaminoMarket.programId
289
+ );
290
+ obligationPdas.push({
291
+ address: await multiplyObligationFixedRate.toPda(kaminoMarket.getAddress(), user),
292
+ log: 'multiply obligation fixed rate coll: ' + collReserveAddress + ' debt: ' + debtReserveAddress,
293
+ });
271
294
  if (collReserve.state.farmCollateral !== DEFAULT_PUBLIC_KEY) {
272
295
  farmUserStates.push({
273
296
  address: await obligationFarmStatePda(
@@ -295,14 +318,16 @@ async function getMultiplyObligationAndObligationFarmStateAddresses(
295
318
  async function getLeverageObligationAndObligationFarmStateAddresses(
296
319
  kaminoMarket: KaminoMarket,
297
320
  user: Address,
298
- mints: { coll: Address; debt: Address }[]
321
+ reserveAddresses: { coll: Address; debt: Address }[]
299
322
  ): Promise<[{ address: Address; log: string }[], { address: Address; log: string }[]]> {
300
323
  const obligationPdas: { address: Address; log: string }[] = [];
301
324
  const farmUserStates: { address: Address; log: string }[] = [];
302
325
 
303
- for (const { coll: collMint, debt: debtMint } of mints) {
304
- const collReserve = kaminoMarket.getReserveByMint(collMint);
305
- const debtReserve = kaminoMarket.getReserveByMint(debtMint);
326
+ for (const { coll: collReserveAddress, debt: debtReserveAddress } of reserveAddresses) {
327
+ const collReserve = kaminoMarket.getReserveByAddress(collReserveAddress);
328
+ const debtReserve = kaminoMarket.getReserveByAddress(debtReserveAddress);
329
+ const collMint = collReserve!.getLiquidityMint();
330
+ const debtMint = debtReserve!.getLiquidityMint();
306
331
  const collMintString = collMint.toString();
307
332
  const debtMintString = debtMint.toString();
308
333
  if (collReserve && debtReserve) {
@@ -311,6 +336,15 @@ async function getLeverageObligationAndObligationFarmStateAddresses(
311
336
  address: await leverageObligation.toPda(kaminoMarket.getAddress(), user),
312
337
  log: 'leverage obligation coll: ' + collMintString + ' debt: ' + debtMintString,
313
338
  });
339
+ const leverageObligationFixedRate = new LeverageObligationFixedRate(
340
+ collReserveAddress,
341
+ debtReserveAddress,
342
+ kaminoMarket.programId
343
+ );
344
+ obligationPdas.push({
345
+ address: await leverageObligationFixedRate.toPda(kaminoMarket.getAddress(), user),
346
+ log: 'leverage obligation fixed rate coll: ' + collReserveAddress + ' debt: ' + debtReserveAddress,
347
+ });
314
348
  if (collReserve.state.farmCollateral !== DEFAULT_PUBLIC_KEY) {
315
349
  farmUserStates.push({
316
350
  address: await obligationFarmStatePda(
@@ -343,7 +377,7 @@ async function getRepayWithCollObligationFarmStateAddresses(
343
377
  const obligationString = obligation.obligationAddress.toString();
344
378
 
345
379
  for (const borrow of obligation.getBorrows()) {
346
- const borrowReserve = kaminoMarket.getReserveByMint(borrow.mintAddress)!;
380
+ const borrowReserve = kaminoMarket.getReserveByAddress(borrow.reserveAddress)!;
347
381
  if (borrowReserve.state.farmDebt !== DEFAULT_PUBLIC_KEY) {
348
382
  farmUserStates.push({
349
383
  address: await obligationFarmStatePda(borrowReserve.state.farmDebt!, obligation.obligationAddress),
@@ -353,7 +387,7 @@ async function getRepayWithCollObligationFarmStateAddresses(
353
387
  }
354
388
 
355
389
  for (const deposit of obligation.getDeposits()) {
356
- const depositReserve = kaminoMarket.getReserveByMint(deposit.mintAddress)!;
390
+ const depositReserve = kaminoMarket.getReserveByAddress(deposit.reserveAddress)!;
357
391
  if (depositReserve.state.farmCollateral !== DEFAULT_PUBLIC_KEY) {
358
392
  farmUserStates.push({
359
393
  address: await obligationFarmStatePda(depositReserve.state.farmCollateral!, obligation.obligationAddress),
@@ -14,6 +14,11 @@ export function checkNotNull<T>(value: T | null, message: string = 'value null')
14
14
  return value as T;
15
15
  }
16
16
 
17
+ export function checkArrayNotEmpty<T>(array: T[], message: string = 'array is empty'): T[] {
18
+ checkThat(array.length > 0, message);
19
+ return array;
20
+ }
21
+
17
22
  export function getSingleElement<T>(iterable: Iterable<T>, nameWithinMessage: string = 'element'): T {
18
23
  const nothingReturnedMarker = {};
19
24
  let single: T | {} = nothingReturnedMarker;