@kamino-finance/klend-sdk 5.14.4 → 5.15.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.
Files changed (124) hide show
  1. package/dist/classes/farm_utils.d.ts.map +1 -1
  2. package/dist/classes/farm_utils.js +1 -0
  3. package/dist/classes/farm_utils.js.map +1 -1
  4. package/dist/classes/manager.d.ts.map +1 -1
  5. package/dist/classes/manager.js +3 -1
  6. package/dist/classes/manager.js.map +1 -1
  7. package/dist/classes/market.d.ts.map +1 -1
  8. package/dist/classes/market.js.map +1 -1
  9. package/dist/classes/reserve.d.ts +1 -1
  10. package/dist/classes/reserve.d.ts.map +1 -1
  11. package/dist/classes/reserve.js +11 -8
  12. package/dist/classes/reserve.js.map +1 -1
  13. package/dist/classes/vault.d.ts +1 -1
  14. package/dist/classes/vault.d.ts.map +1 -1
  15. package/dist/classes/vault.js +89 -15
  16. package/dist/classes/vault.js.map +1 -1
  17. package/dist/client_kamino_manager.d.ts.map +1 -1
  18. package/dist/client_kamino_manager.js +20 -10
  19. package/dist/client_kamino_manager.js.map +1 -1
  20. package/dist/idl.json +193 -16
  21. package/dist/idl_codegen/accounts/GlobalConfig.d.ts +40 -0
  22. package/dist/idl_codegen/accounts/GlobalConfig.d.ts.map +1 -0
  23. package/dist/idl_codegen/accounts/GlobalConfig.js +116 -0
  24. package/dist/idl_codegen/accounts/GlobalConfig.js.map +1 -0
  25. package/dist/idl_codegen/accounts/LendingMarket.d.ts +24 -3
  26. package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
  27. package/dist/idl_codegen/accounts/LendingMarket.js +25 -7
  28. package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
  29. package/dist/idl_codegen/accounts/index.d.ts +2 -0
  30. package/dist/idl_codegen/accounts/index.d.ts.map +1 -1
  31. package/dist/idl_codegen/accounts/index.js +3 -1
  32. package/dist/idl_codegen/accounts/index.js.map +1 -1
  33. package/dist/idl_codegen/errors/custom.d.ts +35 -11
  34. package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
  35. package/dist/idl_codegen/errors/custom.js +64 -22
  36. package/dist/idl_codegen/errors/custom.js.map +1 -1
  37. package/dist/idl_codegen/instructions/idlMissingTypes.d.ts +2 -1
  38. package/dist/idl_codegen/instructions/idlMissingTypes.d.ts.map +1 -1
  39. package/dist/idl_codegen/instructions/idlMissingTypes.js +2 -1
  40. package/dist/idl_codegen/instructions/idlMissingTypes.js.map +1 -1
  41. package/dist/idl_codegen/instructions/index.d.ts +6 -0
  42. package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
  43. package/dist/idl_codegen/instructions/index.js +7 -1
  44. package/dist/idl_codegen/instructions/index.js.map +1 -1
  45. package/dist/idl_codegen/instructions/initGlobalConfig.d.ts +10 -0
  46. package/dist/idl_codegen/instructions/initGlobalConfig.d.ts.map +1 -0
  47. package/dist/idl_codegen/instructions/initGlobalConfig.js +19 -0
  48. package/dist/idl_codegen/instructions/initGlobalConfig.js.map +1 -0
  49. package/dist/idl_codegen/instructions/updateGlobalConfig.d.ts +13 -0
  50. package/dist/idl_codegen/instructions/updateGlobalConfig.d.ts.map +1 -0
  51. package/dist/idl_codegen/instructions/updateGlobalConfig.js +61 -0
  52. package/dist/idl_codegen/instructions/updateGlobalConfig.js.map +1 -0
  53. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.d.ts +7 -0
  54. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.d.ts.map +1 -0
  55. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.js +16 -0
  56. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.js.map +1 -0
  57. package/dist/idl_codegen/instructions/updateReserveConfig.d.ts +5 -4
  58. package/dist/idl_codegen/instructions/updateReserveConfig.d.ts.map +1 -1
  59. package/dist/idl_codegen/instructions/updateReserveConfig.js +7 -5
  60. package/dist/idl_codegen/instructions/updateReserveConfig.js.map +1 -1
  61. package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts +2 -2
  62. package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts.map +1 -1
  63. package/dist/idl_codegen/instructions/withdrawProtocolFee.js +2 -6
  64. package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
  65. package/dist/idl_codegen/types/UpdateGlobalConfigMode.d.ts +32 -0
  66. package/dist/idl_codegen/types/UpdateGlobalConfigMode.d.ts.map +1 -0
  67. package/dist/idl_codegen/types/UpdateGlobalConfigMode.js +108 -0
  68. package/dist/idl_codegen/types/UpdateGlobalConfigMode.js.map +1 -0
  69. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +33 -7
  70. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
  71. package/dist/idl_codegen/types/UpdateLendingMarketMode.js +60 -12
  72. package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
  73. package/dist/idl_codegen/types/index.d.ts +6 -2
  74. package/dist/idl_codegen/types/index.d.ts.map +1 -1
  75. package/dist/idl_codegen/types/index.js +3 -1
  76. package/dist/idl_codegen/types/index.js.map +1 -1
  77. package/dist/utils/api.d.ts +7 -1
  78. package/dist/utils/api.d.ts.map +1 -1
  79. package/dist/utils/api.js +3 -2
  80. package/dist/utils/api.js.map +1 -1
  81. package/dist/utils/constants.d.ts +1 -1
  82. package/dist/utils/constants.d.ts.map +1 -1
  83. package/dist/utils/constants.js +3 -3
  84. package/dist/utils/constants.js.map +1 -1
  85. package/dist/utils/instruction.d.ts.map +1 -1
  86. package/dist/utils/instruction.js.map +1 -1
  87. package/dist/utils/lookupTable.d.ts.map +1 -1
  88. package/dist/utils/lookupTable.js +1 -6
  89. package/dist/utils/lookupTable.js.map +1 -1
  90. package/dist/utils/managerTypes.js +1 -1
  91. package/dist/utils/managerTypes.js.map +1 -1
  92. package/dist/utils/seeds.d.ts +16 -0
  93. package/dist/utils/seeds.d.ts.map +1 -1
  94. package/dist/utils/seeds.js +23 -1
  95. package/dist/utils/seeds.js.map +1 -1
  96. package/package.json +1 -1
  97. package/src/classes/farm_utils.ts +1 -0
  98. package/src/classes/manager.ts +3 -1
  99. package/src/classes/market.ts +2 -6
  100. package/src/classes/reserve.ts +12 -8
  101. package/src/classes/vault.ts +118 -14
  102. package/src/classes/vault_types.ts +1 -1
  103. package/src/client_kamino_manager.ts +35 -13
  104. package/src/idl.json +193 -16
  105. package/src/idl_codegen/accounts/GlobalConfig.ts +125 -0
  106. package/src/idl_codegen/accounts/LendingMarket.ts +41 -9
  107. package/src/idl_codegen/accounts/index.ts +2 -0
  108. package/src/idl_codegen/errors/custom.ts +65 -20
  109. package/src/idl_codegen/instructions/idlMissingTypes.ts +4 -2
  110. package/src/idl_codegen/instructions/index.ts +9 -0
  111. package/src/idl_codegen/instructions/initGlobalConfig.ts +30 -0
  112. package/src/idl_codegen/instructions/updateGlobalConfig.ts +47 -0
  113. package/src/idl_codegen/instructions/updateGlobalConfigAdmin.ts +24 -0
  114. package/src/idl_codegen/instructions/updateReserveConfig.ts +10 -8
  115. package/src/idl_codegen/instructions/withdrawProtocolFee.ts +4 -8
  116. package/src/idl_codegen/types/UpdateGlobalConfigMode.ts +90 -0
  117. package/src/idl_codegen/types/UpdateLendingMarketMode.ts +73 -13
  118. package/src/idl_codegen/types/index.ts +16 -2
  119. package/src/utils/api.ts +9 -3
  120. package/src/utils/constants.ts +3 -3
  121. package/src/utils/instruction.ts +2 -2
  122. package/src/utils/lookupTable.ts +1 -7
  123. package/src/utils/managerTypes.ts +1 -1
  124. package/src/utils/seeds.ts +25 -0
package/src/utils/api.ts CHANGED
@@ -5,6 +5,12 @@ import { CDN_ENDPOINT, getApiEndpoint } from '../utils';
5
5
  import { IBackOffOptions, backOff } from 'exponential-backoff';
6
6
  import { PROGRAM_ID } from '../lib';
7
7
 
8
+ export type ApiRequestOptions = {
9
+ programId?: PublicKey;
10
+ source?: 'API' | 'CDN';
11
+ apiBaseUrl?: string;
12
+ };
13
+
8
14
  export type ApiFilterOptions = {
9
15
  isCurated?: boolean;
10
16
  };
@@ -15,11 +21,11 @@ export type ApiFilterOptions = {
15
21
  *
16
22
  * @param programId - The program id to retrieve config for
17
23
  * @param source - CDN is a json file hosted in the cloud, API is a webserver
24
+ * @param apiBaseUrl - Optional base URL for the API, if not provided, defaults to the standard API endpoint, not used for CDN
18
25
  * @param filterOptions - Config options to filter markets by
19
26
  */
20
27
  export async function getMarketsFromApi(
21
- programId: PublicKey = PROGRAM_ID,
22
- source: 'API' | 'CDN' = 'CDN',
28
+ { programId = PROGRAM_ID, source = 'CDN', apiBaseUrl }: ApiRequestOptions = {},
23
29
  filterOptions: ApiFilterOptions = {}
24
30
  ): Promise<ConfigType> {
25
31
  let unfilteredConfigs: ConfigType = {} as ConfigType;
@@ -30,7 +36,7 @@ export async function getMarketsFromApi(
30
36
  }
31
37
 
32
38
  if (!unfilteredConfigs || isEmptyObject(unfilteredConfigs)) {
33
- const API_ENDPOINT = getApiEndpoint(programId);
39
+ const API_ENDPOINT = getApiEndpoint(programId, apiBaseUrl);
34
40
  unfilteredConfigs = (await backOff(() => axios.get(API_ENDPOINT), KAMINO_API_RETRY)).data as ConfigType;
35
41
  }
36
42
 
@@ -19,11 +19,11 @@ export function isENV(value: any): value is ENV {
19
19
  return value === 'mainnet-beta' || value === 'devnet' || value === 'localnet';
20
20
  }
21
21
 
22
- export function getApiEndpoint(programId: PublicKey) {
22
+ export function getApiEndpoint(programId: PublicKey, apiBaseUrl: string = 'https://api.kamino.finance') {
23
23
  if (programId.equals(PROGRAM_ID)) {
24
- return 'https://api.hubbleprotocol.io/v2/kamino-market';
24
+ return `${apiBaseUrl}/v2/kamino-market`;
25
25
  } else {
26
- return `https://api.hubbleprotocol.io/v2/kamino-market/?programId=${programId.toString()}`;
26
+ return `${apiBaseUrl}/v2/kamino-market/?programId=${programId.toString()}`;
27
27
  }
28
28
  }
29
29
 
@@ -226,7 +226,7 @@ export const buildVersionedTransactionSync = (
226
226
  payer: PublicKey,
227
227
  instructions: TransactionInstruction[],
228
228
  blockhash: Blockhash,
229
- lookupTables: AddressLookupTableAccount[] = [],
229
+ lookupTables: AddressLookupTableAccount[] = []
230
230
  ): VersionedTransaction => {
231
231
  const messageV0 = new TransactionMessage({
232
232
  payerKey: payer,
@@ -235,7 +235,7 @@ export const buildVersionedTransactionSync = (
235
235
  }).compileToV0Message(lookupTables.filter(notEmpty));
236
236
 
237
237
  return new VersionedTransaction(messageV0);
238
- }
238
+ };
239
239
 
240
240
  export const getLookupTableAccount = async (connection: Connection, address: PublicKey) => {
241
241
  return connection.getAddressLookupTable(address).then((res) => res.value);
@@ -15,13 +15,7 @@ export async function createLookupTableIx(
15
15
  connection: Connection,
16
16
  wallet: PublicKey
17
17
  ): Promise<[TransactionInstruction, PublicKey]> {
18
- const [createLookupTableIxs, lookupTableAddress] = AddressLookupTableProgram.createLookupTable({
19
- authority: wallet,
20
- payer: wallet,
21
- recentSlot: await connection.getSlot('confirmed'),
22
- });
23
-
24
- return [createLookupTableIxs, lookupTableAddress];
18
+ return initLookupTableIx(wallet, await connection.getSlot('confirmed'));
25
19
  }
26
20
 
27
21
  export function extendLookupTableChunkIx(
@@ -262,7 +262,7 @@ export const DefaultConfigParams: AssetReserveConfigParams = {
262
262
  borrowFeeSf: ZERO_FRACTION,
263
263
  flashLoanFeeSf: ZERO_FRACTION,
264
264
  protocolTakeRate: 0,
265
- elevationGroups: [0, 0, 0, 0, 0],
265
+ elevationGroups: new Array(20).fill(0),
266
266
  priceFeed: null,
267
267
  borrowLimit: new Decimal(1000.0),
268
268
  depositLimit: new Decimal(1000.0),
@@ -39,6 +39,10 @@ export const BASE_SEED_REFERRER_STATE = 'ref_state';
39
39
  * Short url seed
40
40
  */
41
41
  export const BASE_SEED_SHORT_URL = 'short_url';
42
+ /**
43
+ * Short url seed
44
+ */
45
+ export const BASE_SEED_GLOBAL_CONFIG_STATE = 'global_config';
42
46
  /**
43
47
  * Farm user state seed
44
48
  */
@@ -193,6 +197,27 @@ export function shortUrlPda(shortUrl: string, programId: PublicKey = PROGRAM_ID)
193
197
  return PublicKey.findProgramAddressSync([Buffer.from(BASE_SEED_SHORT_URL), Buffer.from(shortUrl)], programId);
194
198
  }
195
199
 
200
+ /**
201
+ * Returns the PDA and bump for the global config state.
202
+ * @param programId
203
+ * @returns [pda, bump]
204
+ */
205
+ export function globalConfigPda(programId: PublicKey = PROGRAM_ID) {
206
+ return PublicKey.findProgramAddressSync([Buffer.from(BASE_SEED_GLOBAL_CONFIG_STATE)], programId);
207
+ }
208
+
209
+ /**
210
+ * Returns the PDA and bump for the program data.
211
+ * @param programId
212
+ * @returns [pda, bump]
213
+ */
214
+ export function programDataPda(programId: PublicKey = PROGRAM_ID) {
215
+ return PublicKey.findProgramAddressSync(
216
+ [programId.toBuffer()],
217
+ new PublicKey('BPFLoaderUpgradeab1e11111111111111111111111')
218
+ );
219
+ }
220
+
196
221
  /**
197
222
  * Returns the PDA for the obligation farm state
198
223
  * @param farm