@kamino-finance/klend-sdk 5.2.14 → 5.4.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 (142) hide show
  1. package/dist/classes/action.d.ts.map +1 -1
  2. package/dist/classes/action.js +1 -2
  3. package/dist/classes/action.js.map +1 -1
  4. package/dist/classes/manager.d.ts +2 -4
  5. package/dist/classes/manager.d.ts.map +1 -1
  6. package/dist/classes/manager.js +29 -20
  7. package/dist/classes/manager.js.map +1 -1
  8. package/dist/classes/market.d.ts +1 -2
  9. package/dist/classes/market.d.ts.map +1 -1
  10. package/dist/classes/market.js +7 -20
  11. package/dist/classes/market.js.map +1 -1
  12. package/dist/classes/reserve.js +14 -14
  13. package/dist/classes/reserve.js.map +1 -1
  14. package/dist/classes/shared.d.ts +2 -2
  15. package/dist/classes/shared.d.ts.map +1 -1
  16. package/dist/classes/vault.d.ts +2 -4
  17. package/dist/classes/vault.d.ts.map +1 -1
  18. package/dist/classes/vault.js +7 -15
  19. package/dist/classes/vault.js.map +1 -1
  20. package/dist/client_kamino_manager.js +7 -3
  21. package/dist/client_kamino_manager.js.map +1 -1
  22. package/dist/idl.json +310 -48
  23. package/dist/idl_codegen/accounts/LendingMarket.d.ts +48 -3
  24. package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
  25. package/dist/idl_codegen/accounts/LendingMarket.js +35 -8
  26. package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
  27. package/dist/idl_codegen/accounts/Obligation.d.ts +30 -0
  28. package/dist/idl_codegen/accounts/Obligation.d.ts.map +1 -1
  29. package/dist/idl_codegen/accounts/Obligation.js +23 -2
  30. package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
  31. package/dist/idl_codegen/accounts/Reserve.js +1 -1
  32. package/dist/idl_codegen/errors/custom.d.ts +33 -1
  33. package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
  34. package/dist/idl_codegen/errors/custom.js +57 -1
  35. package/dist/idl_codegen/errors/custom.js.map +1 -1
  36. package/dist/idl_codegen/instructions/index.d.ts +7 -3
  37. package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
  38. package/dist/idl_codegen/instructions/index.js +7 -3
  39. package/dist/idl_codegen/instructions/index.js.map +1 -1
  40. package/dist/idl_codegen/instructions/initReferrerTokenState.d.ts +2 -5
  41. package/dist/idl_codegen/instructions/initReferrerTokenState.d.ts.map +1 -1
  42. package/dist/idl_codegen/instructions/initReferrerTokenState.js +3 -32
  43. package/dist/idl_codegen/instructions/initReferrerTokenState.js.map +1 -1
  44. package/dist/idl_codegen/instructions/markObligationForDeleveraging.d.ts +12 -0
  45. package/dist/idl_codegen/instructions/markObligationForDeleveraging.d.ts.map +1 -0
  46. package/dist/idl_codegen/instructions/markObligationForDeleveraging.js +47 -0
  47. package/dist/idl_codegen/instructions/markObligationForDeleveraging.js.map +1 -0
  48. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts +38 -0
  49. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts.map +1 -0
  50. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js +159 -0
  51. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js.map +1 -0
  52. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +1 -1
  53. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
  54. package/dist/idl_codegen/types/ReserveConfig.d.ts +78 -20
  55. package/dist/idl_codegen/types/ReserveConfig.d.ts.map +1 -1
  56. package/dist/idl_codegen/types/ReserveConfig.js +45 -14
  57. package/dist/idl_codegen/types/ReserveConfig.js.map +1 -1
  58. package/dist/idl_codegen/types/ReserveLiquidity.d.ts +16 -16
  59. package/dist/idl_codegen/types/ReserveLiquidity.d.ts.map +1 -1
  60. package/dist/idl_codegen/types/ReserveLiquidity.js +16 -16
  61. package/dist/idl_codegen/types/ReserveLiquidity.js.map +1 -1
  62. package/dist/idl_codegen/types/UpdateConfigMode.d.ts +40 -14
  63. package/dist/idl_codegen/types/UpdateConfigMode.d.ts.map +1 -1
  64. package/dist/idl_codegen/types/UpdateConfigMode.js +71 -23
  65. package/dist/idl_codegen/types/UpdateConfigMode.js.map +1 -1
  66. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +37 -11
  67. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
  68. package/dist/idl_codegen/types/UpdateLendingMarketMode.js +64 -16
  69. package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
  70. package/dist/idl_codegen/types/index.d.ts +4 -4
  71. package/dist/idl_codegen/types/index.d.ts.map +1 -1
  72. package/dist/idl_codegen/types/index.js.map +1 -1
  73. package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +4 -0
  74. package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -1
  75. package/dist/idl_codegen/zero_padding/ObligationZP.js +10 -0
  76. package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
  77. package/dist/pyth/accounts/PriceUpdateV2.d.ts +30 -0
  78. package/dist/pyth/accounts/PriceUpdateV2.d.ts.map +1 -0
  79. package/dist/pyth/accounts/PriceUpdateV2.js +104 -0
  80. package/dist/pyth/accounts/PriceUpdateV2.js.map +1 -0
  81. package/dist/pyth/accounts/index.d.ts +3 -0
  82. package/dist/pyth/accounts/index.d.ts.map +1 -0
  83. package/dist/pyth/accounts/index.js +6 -0
  84. package/dist/pyth/accounts/index.js.map +1 -0
  85. package/dist/pyth/types/PriceFeedMessage.d.ts +58 -0
  86. package/dist/pyth/types/PriceFeedMessage.d.ts.map +1 -0
  87. package/dist/pyth/types/PriceFeedMessage.js +118 -0
  88. package/dist/pyth/types/PriceFeedMessage.js.map +1 -0
  89. package/dist/pyth/types/VerificationLevel.d.ts +45 -0
  90. package/dist/pyth/types/VerificationLevel.d.ts.map +1 -0
  91. package/dist/pyth/types/VerificationLevel.js +105 -0
  92. package/dist/pyth/types/VerificationLevel.js.map +1 -0
  93. package/dist/pyth/types/index.d.ts +7 -0
  94. package/dist/pyth/types/index.d.ts.map +1 -0
  95. package/dist/pyth/types/index.js +31 -0
  96. package/dist/pyth/types/index.js.map +1 -0
  97. package/dist/referrals/instructions.d.ts.map +1 -1
  98. package/dist/referrals/instructions.js +1 -2
  99. package/dist/referrals/instructions.js.map +1 -1
  100. package/dist/utils/managerTypes.d.ts.map +1 -1
  101. package/dist/utils/managerTypes.js +5 -4
  102. package/dist/utils/managerTypes.js.map +1 -1
  103. package/dist/utils/oracle.d.ts.map +1 -1
  104. package/dist/utils/oracle.js +9 -14
  105. package/dist/utils/oracle.js.map +1 -1
  106. package/dist/utils/rpc.d.ts +2 -1
  107. package/dist/utils/rpc.d.ts.map +1 -1
  108. package/dist/utils/rpc.js +8 -6
  109. package/dist/utils/rpc.js.map +1 -1
  110. package/package.json +5 -6
  111. package/src/classes/action.ts +1 -3
  112. package/src/classes/manager.ts +39 -19
  113. package/src/classes/market.ts +8 -21
  114. package/src/classes/reserve.ts +16 -16
  115. package/src/classes/shared.ts +2 -2
  116. package/src/classes/vault.ts +10 -14
  117. package/src/client_kamino_manager.ts +7 -3
  118. package/src/idl_codegen/accounts/LendingMarket.ts +76 -13
  119. package/src/idl_codegen/accounts/Obligation.ts +47 -2
  120. package/src/idl_codegen/accounts/Reserve.ts +1 -1
  121. package/src/idl_codegen/errors/custom.ts +56 -0
  122. package/src/idl_codegen/instructions/index.ts +13 -6
  123. package/src/idl_codegen/instructions/initReferrerTokenState.ts +3 -15
  124. package/src/idl_codegen/instructions/markObligationForDeleveraging.ts +40 -0
  125. package/src/idl_codegen/instructions/repayAndWithdrawAndRedeem.ts +177 -0
  126. package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +1 -1
  127. package/src/idl_codegen/programId.ts +1 -1
  128. package/src/idl_codegen/types/ReserveConfig.ts +100 -28
  129. package/src/idl_codegen/types/ReserveLiquidity.ts +25 -24
  130. package/src/idl_codegen/types/UpdateConfigMode.ts +86 -26
  131. package/src/idl_codegen/types/UpdateLendingMarketMode.ts +77 -17
  132. package/src/idl_codegen/types/index.ts +14 -6
  133. package/src/idl_codegen/zero_padding/ObligationZP.ts +10 -0
  134. package/src/pyth/accounts/PriceUpdateV2.ts +110 -0
  135. package/src/pyth/accounts/index.ts +2 -0
  136. package/src/pyth/types/PriceFeedMessage.ts +120 -0
  137. package/src/pyth/types/VerificationLevel.ts +98 -0
  138. package/src/pyth/types/index.ts +9 -0
  139. package/src/referrals/instructions.ts +1 -3
  140. package/src/utils/managerTypes.ts +5 -5
  141. package/src/utils/oracle.ts +9 -15
  142. package/src/utils/rpc.ts +8 -5
@@ -1,4 +1,3 @@
1
- import { parsePriceData } from '@pythnetwork/client';
2
1
  import { AccountInfo, Connection, PublicKey } from '@solana/web3.js';
3
2
  import Decimal from 'decimal.js';
4
3
  import { OraclePrices, Scope } from '@kamino-finance/scope-sdk';
@@ -8,6 +7,7 @@ import SwitchboardProgram from '@switchboard-xyz/sbv2-lite';
8
7
  import { Reserve } from '../lib';
9
8
  import { batchFetch } from '@kamino-finance/kliquidity-sdk';
10
9
  import BN from 'bn.js';
10
+ import { PriceUpdateV2 } from '../pyth/accounts';
11
11
 
12
12
  const SWITCHBOARD_V2_PROGRAM_ID = new PublicKey('SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f');
13
13
 
@@ -166,27 +166,21 @@ export function cacheOrGetPythPrices(
166
166
  const result = oracleAccounts.get(oracle);
167
167
  if (result) {
168
168
  try {
169
- const { price, timestamp, emaPrice, previousPrice, previousTimestamp, confidence } = parsePriceData(
170
- result.data
171
- );
169
+ const { priceMessage } = PriceUpdateV2.decode(result.data);
170
+ const { price, exponent, conf: confidence, publishTime: timestamp, emaPrice } = priceMessage;
172
171
  if (price) {
173
- const px = new Decimal(price);
172
+ const px = new Decimal(price.toString()).div(10 ** Math.abs(exponent));
174
173
  prices.spot = {
175
174
  price: px,
176
- timestamp,
177
- valid: validatePythPx(px, confidence),
178
- };
179
- } else {
180
- prices.spot = {
181
- price: new Decimal(previousPrice),
182
- timestamp: previousTimestamp,
183
- valid: false,
175
+ timestamp: BigInt(timestamp.toString()),
176
+ valid: validatePythPx(px, confidence.toNumber()),
184
177
  };
185
178
  }
186
179
  if (emaPrice !== undefined && emaPrice !== null) {
180
+ const emaPx = new Decimal(emaPrice.toString()).div(10 ** Math.abs(exponent));
187
181
  prices.twap = {
188
- price: new Decimal(emaPrice.value),
189
- timestamp,
182
+ price: emaPx,
183
+ timestamp: BigInt(timestamp.toString()),
190
184
  valid: true,
191
185
  };
192
186
  }
package/src/utils/rpc.ts CHANGED
@@ -9,11 +9,12 @@ import {
9
9
  } from '@solana/web3.js';
10
10
  import { Buffer } from 'buffer';
11
11
  import axios from 'axios';
12
- import { init, decompress } from '@bokuweb/zstd-wasm';
13
12
  import { v4 as uuidv4 } from 'uuid';
13
+ import { ZSTDDecoder } from 'zstddec';
14
14
 
15
+ const decoder = new ZSTDDecoder();
15
16
  (async () => {
16
- await init();
17
+ await decoder.init();
17
18
  })();
18
19
 
19
20
  /**
@@ -21,11 +22,13 @@ import { v4 as uuidv4 } from 'uuid';
21
22
  * Uses axios instead of node-fetch to work around a bug in node-fetch that causes subsequent requests with different encoding to fail
22
23
  * @param connection
23
24
  * @param programId
25
+ * @param structSize - the size of the decompressed account data struct
24
26
  * @param configOrCommitment
25
27
  */
26
28
  export async function getProgramAccounts(
27
29
  connection: Connection,
28
30
  programId: PublicKey,
31
+ structSize: number,
29
32
  configOrCommitment?: GetProgramAccountsConfig | Commitment
30
33
  ): Promise<GetProgramAccountsResponse> {
31
34
  const programIdStr = programId.toBase58();
@@ -65,7 +68,7 @@ export async function getProgramAccounts(
65
68
 
66
69
  const res = unsafeRes as RpcResult;
67
70
  const deser = res.result.map(async (account) => ({
68
- account: await deserializeAccountInfo(account.account),
71
+ account: await deserializeAccountInfo(account.account, structSize),
69
72
  pubkey: new PublicKey(account.pubkey),
70
73
  }));
71
74
  const x = await Promise.all(deser);
@@ -80,8 +83,8 @@ export async function getAccountOwner(connection: Connection, address: PublicKey
80
83
  return acc.owner;
81
84
  }
82
85
 
83
- async function deserializeAccountInfo(accountInfo: AccountInfo<string[]>): Promise<AccountInfo<Buffer>> {
84
- const data = decompress(Buffer.from(accountInfo.data[0], 'base64'));
86
+ async function deserializeAccountInfo(accountInfo: AccountInfo<string[]>, size: number): Promise<AccountInfo<Buffer>> {
87
+ const data = decoder.decode(Buffer.from(accountInfo.data[0], 'base64'), size);
85
88
  return {
86
89
  owner: accountInfo.owner,
87
90
  lamports: accountInfo.lamports,