@kamino-finance/klend-sdk 5.2.14 → 5.3.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 (125) 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.js +22 -5
  5. package/dist/classes/manager.js.map +1 -1
  6. package/dist/classes/reserve.js +14 -14
  7. package/dist/classes/reserve.js.map +1 -1
  8. package/dist/classes/shared.d.ts +2 -2
  9. package/dist/classes/shared.d.ts.map +1 -1
  10. package/dist/client_kamino_manager.js +6 -2
  11. package/dist/client_kamino_manager.js.map +1 -1
  12. package/dist/idl.json +310 -48
  13. package/dist/idl_codegen/accounts/LendingMarket.d.ts +48 -3
  14. package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
  15. package/dist/idl_codegen/accounts/LendingMarket.js +35 -8
  16. package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
  17. package/dist/idl_codegen/accounts/Obligation.d.ts +30 -0
  18. package/dist/idl_codegen/accounts/Obligation.d.ts.map +1 -1
  19. package/dist/idl_codegen/accounts/Obligation.js +23 -2
  20. package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
  21. package/dist/idl_codegen/accounts/Reserve.js +1 -1
  22. package/dist/idl_codegen/errors/custom.d.ts +33 -1
  23. package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
  24. package/dist/idl_codegen/errors/custom.js +57 -1
  25. package/dist/idl_codegen/errors/custom.js.map +1 -1
  26. package/dist/idl_codegen/instructions/index.d.ts +7 -3
  27. package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
  28. package/dist/idl_codegen/instructions/index.js +7 -3
  29. package/dist/idl_codegen/instructions/index.js.map +1 -1
  30. package/dist/idl_codegen/instructions/initReferrerTokenState.d.ts +2 -5
  31. package/dist/idl_codegen/instructions/initReferrerTokenState.d.ts.map +1 -1
  32. package/dist/idl_codegen/instructions/initReferrerTokenState.js +3 -32
  33. package/dist/idl_codegen/instructions/initReferrerTokenState.js.map +1 -1
  34. package/dist/idl_codegen/instructions/markObligationForDeleveraging.d.ts +12 -0
  35. package/dist/idl_codegen/instructions/markObligationForDeleveraging.d.ts.map +1 -0
  36. package/dist/idl_codegen/instructions/markObligationForDeleveraging.js +47 -0
  37. package/dist/idl_codegen/instructions/markObligationForDeleveraging.js.map +1 -0
  38. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts +38 -0
  39. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts.map +1 -0
  40. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js +159 -0
  41. package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js.map +1 -0
  42. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +1 -1
  43. package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
  44. package/dist/idl_codegen/types/ReserveConfig.d.ts +78 -20
  45. package/dist/idl_codegen/types/ReserveConfig.d.ts.map +1 -1
  46. package/dist/idl_codegen/types/ReserveConfig.js +45 -14
  47. package/dist/idl_codegen/types/ReserveConfig.js.map +1 -1
  48. package/dist/idl_codegen/types/ReserveLiquidity.d.ts +16 -16
  49. package/dist/idl_codegen/types/ReserveLiquidity.d.ts.map +1 -1
  50. package/dist/idl_codegen/types/ReserveLiquidity.js +16 -16
  51. package/dist/idl_codegen/types/ReserveLiquidity.js.map +1 -1
  52. package/dist/idl_codegen/types/UpdateConfigMode.d.ts +40 -14
  53. package/dist/idl_codegen/types/UpdateConfigMode.d.ts.map +1 -1
  54. package/dist/idl_codegen/types/UpdateConfigMode.js +71 -23
  55. package/dist/idl_codegen/types/UpdateConfigMode.js.map +1 -1
  56. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +37 -11
  57. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
  58. package/dist/idl_codegen/types/UpdateLendingMarketMode.js +64 -16
  59. package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
  60. package/dist/idl_codegen/types/index.d.ts +4 -4
  61. package/dist/idl_codegen/types/index.d.ts.map +1 -1
  62. package/dist/idl_codegen/types/index.js.map +1 -1
  63. package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +4 -0
  64. package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -1
  65. package/dist/idl_codegen/zero_padding/ObligationZP.js +10 -0
  66. package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
  67. package/dist/pyth/accounts/PriceUpdateV2.d.ts +30 -0
  68. package/dist/pyth/accounts/PriceUpdateV2.d.ts.map +1 -0
  69. package/dist/pyth/accounts/PriceUpdateV2.js +104 -0
  70. package/dist/pyth/accounts/PriceUpdateV2.js.map +1 -0
  71. package/dist/pyth/accounts/index.d.ts +3 -0
  72. package/dist/pyth/accounts/index.d.ts.map +1 -0
  73. package/dist/pyth/accounts/index.js +6 -0
  74. package/dist/pyth/accounts/index.js.map +1 -0
  75. package/dist/pyth/types/PriceFeedMessage.d.ts +58 -0
  76. package/dist/pyth/types/PriceFeedMessage.d.ts.map +1 -0
  77. package/dist/pyth/types/PriceFeedMessage.js +118 -0
  78. package/dist/pyth/types/PriceFeedMessage.js.map +1 -0
  79. package/dist/pyth/types/VerificationLevel.d.ts +45 -0
  80. package/dist/pyth/types/VerificationLevel.d.ts.map +1 -0
  81. package/dist/pyth/types/VerificationLevel.js +105 -0
  82. package/dist/pyth/types/VerificationLevel.js.map +1 -0
  83. package/dist/pyth/types/index.d.ts +7 -0
  84. package/dist/pyth/types/index.d.ts.map +1 -0
  85. package/dist/pyth/types/index.js +31 -0
  86. package/dist/pyth/types/index.js.map +1 -0
  87. package/dist/referrals/instructions.d.ts.map +1 -1
  88. package/dist/referrals/instructions.js +1 -2
  89. package/dist/referrals/instructions.js.map +1 -1
  90. package/dist/utils/managerTypes.d.ts.map +1 -1
  91. package/dist/utils/managerTypes.js +5 -4
  92. package/dist/utils/managerTypes.js.map +1 -1
  93. package/dist/utils/oracle.d.ts.map +1 -1
  94. package/dist/utils/oracle.js +9 -14
  95. package/dist/utils/oracle.js.map +1 -1
  96. package/package.json +3 -4
  97. package/src/classes/action.ts +1 -3
  98. package/src/classes/manager.ts +29 -6
  99. package/src/classes/reserve.ts +16 -16
  100. package/src/classes/shared.ts +2 -2
  101. package/src/client_kamino_manager.ts +6 -2
  102. package/src/idl_codegen/accounts/LendingMarket.ts +76 -13
  103. package/src/idl_codegen/accounts/Obligation.ts +47 -2
  104. package/src/idl_codegen/accounts/Reserve.ts +1 -1
  105. package/src/idl_codegen/errors/custom.ts +56 -0
  106. package/src/idl_codegen/instructions/index.ts +13 -6
  107. package/src/idl_codegen/instructions/initReferrerTokenState.ts +3 -15
  108. package/src/idl_codegen/instructions/markObligationForDeleveraging.ts +40 -0
  109. package/src/idl_codegen/instructions/repayAndWithdrawAndRedeem.ts +177 -0
  110. package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +1 -1
  111. package/src/idl_codegen/programId.ts +1 -1
  112. package/src/idl_codegen/types/ReserveConfig.ts +100 -28
  113. package/src/idl_codegen/types/ReserveLiquidity.ts +25 -24
  114. package/src/idl_codegen/types/UpdateConfigMode.ts +86 -26
  115. package/src/idl_codegen/types/UpdateLendingMarketMode.ts +77 -17
  116. package/src/idl_codegen/types/index.ts +14 -6
  117. package/src/idl_codegen/zero_padding/ObligationZP.ts +10 -0
  118. package/src/pyth/accounts/PriceUpdateV2.ts +110 -0
  119. package/src/pyth/accounts/index.ts +2 -0
  120. package/src/pyth/types/PriceFeedMessage.ts +120 -0
  121. package/src/pyth/types/VerificationLevel.ts +98 -0
  122. package/src/pyth/types/index.ts +9 -0
  123. package/src/referrals/instructions.ts +1 -3
  124. package/src/utils/managerTypes.ts +5 -5
  125. package/src/utils/oracle.ts +9 -15
@@ -0,0 +1,120 @@
1
+ import BN from 'bn.js';
2
+ import * as borsh from '@coral-xyz/borsh';
3
+
4
+ export interface PriceFeedMessageFields {
5
+ feedId: number[];
6
+ price: BN;
7
+ conf: BN;
8
+ exponent: number;
9
+ publishTime: BN;
10
+ prevPublishTime: BN;
11
+ emaPrice: BN;
12
+ emaConf: BN;
13
+ }
14
+
15
+ export interface PriceFeedMessageJSON {
16
+ feedId: number[];
17
+ price: string;
18
+ conf: string;
19
+ exponent: number;
20
+ publishTime: string;
21
+ prevPublishTime: string;
22
+ emaPrice: string;
23
+ emaConf: string;
24
+ }
25
+
26
+ /** Reserve Withdrawal Caps State */
27
+ export class PriceFeedMessage {
28
+ readonly feedId: number[];
29
+ readonly price: BN;
30
+ readonly conf: BN;
31
+ readonly exponent: number;
32
+ readonly publishTime: BN;
33
+ readonly prevPublishTime: BN;
34
+ readonly emaPrice: BN;
35
+ readonly emaConf: BN;
36
+
37
+ constructor(fields: PriceFeedMessageFields) {
38
+ this.feedId = fields.feedId;
39
+ this.price = fields.price;
40
+ this.conf = fields.conf;
41
+ this.exponent = fields.exponent;
42
+ this.publishTime = fields.publishTime;
43
+ this.prevPublishTime = fields.prevPublishTime;
44
+ this.emaPrice = fields.emaPrice;
45
+ this.emaConf = fields.emaConf;
46
+ }
47
+
48
+ static layout(property?: string) {
49
+ return borsh.struct(
50
+ [
51
+ borsh.array(borsh.u8(), 32, 'feedId'),
52
+ borsh.i64('price'),
53
+ borsh.u64('conf'),
54
+ borsh.i32('exponent'),
55
+ borsh.i64('publishTime'),
56
+ borsh.i64('prevPublishTime'),
57
+ borsh.i64('emaPrice'),
58
+ borsh.u64('emaConf'),
59
+ ],
60
+ property
61
+ );
62
+ }
63
+
64
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
+ static fromDecoded(obj: any) {
66
+ return new PriceFeedMessage({
67
+ feedId: obj.feedId,
68
+ price: obj.price,
69
+ conf: obj.conf,
70
+ exponent: obj.exponent,
71
+ publishTime: obj.publishTime,
72
+ prevPublishTime: obj.prevPublishTime,
73
+ emaPrice: obj.emaPrice,
74
+ emaConf: obj.emaConf,
75
+ });
76
+ }
77
+
78
+ static toEncodable(fields: PriceFeedMessageFields) {
79
+ return {
80
+ feedId: fields.feedId,
81
+ price: fields.price,
82
+ conf: fields.conf,
83
+ exponent: fields.exponent,
84
+ publishTime: fields.publishTime,
85
+ prevPublishTime: fields.prevPublishTime,
86
+ emaPrice: fields.emaPrice,
87
+ emaConf: fields.emaConf,
88
+ };
89
+ }
90
+
91
+ toJSON(): PriceFeedMessageJSON {
92
+ return {
93
+ feedId: this.feedId,
94
+ price: this.price.toString(),
95
+ conf: this.conf.toString(),
96
+ exponent: this.exponent,
97
+ publishTime: this.publishTime.toString(),
98
+ prevPublishTime: this.prevPublishTime.toString(),
99
+ emaPrice: this.emaPrice.toString(),
100
+ emaConf: this.emaConf.toString(),
101
+ };
102
+ }
103
+
104
+ static fromJSON(obj: PriceFeedMessageJSON): PriceFeedMessage {
105
+ return new PriceFeedMessage({
106
+ feedId: obj.feedId,
107
+ price: new BN(obj.price),
108
+ conf: new BN(obj.conf),
109
+ exponent: obj.exponent,
110
+ publishTime: new BN(obj.publishTime),
111
+ prevPublishTime: new BN(obj.prevPublishTime),
112
+ emaPrice: new BN(obj.emaPrice),
113
+ emaConf: new BN(obj.emaConf),
114
+ });
115
+ }
116
+
117
+ toEncodable() {
118
+ return PriceFeedMessage.toEncodable(this);
119
+ }
120
+ }
@@ -0,0 +1,98 @@
1
+ import * as types from '../types';
2
+ import * as borsh from '@coral-xyz/borsh';
3
+
4
+ export type PartialFields = { numSignatures: number };
5
+ export type PartialValue = { numSignatures: number };
6
+
7
+ export interface PartialJSON {
8
+ kind: 'Partial';
9
+ value: { numSignatures: number };
10
+ }
11
+
12
+ export class Partial {
13
+ static readonly discriminator = 1;
14
+ static readonly kind = 'Partial';
15
+ readonly discriminator = 1;
16
+ readonly kind = 'Partial';
17
+ readonly value: PartialValue;
18
+
19
+ constructor(value: PartialFields) {
20
+ this.value = { numSignatures: value.numSignatures };
21
+ }
22
+
23
+ toJSON(): PartialJSON {
24
+ return {
25
+ kind: 'Partial',
26
+ value: {
27
+ numSignatures: this.value.numSignatures,
28
+ },
29
+ };
30
+ }
31
+
32
+ toEncodable() {
33
+ return {
34
+ Partial: {
35
+ numSignatures: this.value.numSignatures,
36
+ },
37
+ };
38
+ }
39
+ }
40
+
41
+ export interface FullJSON {
42
+ kind: 'Full';
43
+ }
44
+
45
+ export class Full {
46
+ static readonly discriminator = 1;
47
+ static readonly kind = 'Full';
48
+ readonly discriminator = 1;
49
+ readonly kind = 'Full';
50
+
51
+ toJSON(): FullJSON {
52
+ return {
53
+ kind: 'Full',
54
+ };
55
+ }
56
+
57
+ toEncodable() {
58
+ return {
59
+ Full: {},
60
+ };
61
+ }
62
+ }
63
+
64
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
+ export function fromDecoded(obj: any): types.VerificationLevelKind {
66
+ if (typeof obj !== 'object') {
67
+ throw new Error('Invalid enum object');
68
+ }
69
+
70
+ if ('Partial' in obj) {
71
+ return new Partial({ numSignatures: obj.Partial.numSignatures });
72
+ }
73
+ if ('Full' in obj) {
74
+ return new Full();
75
+ }
76
+
77
+ throw new Error('Invalid enum object');
78
+ }
79
+
80
+ export function fromJSON(obj: types.VerificationLevelJSON): types.VerificationLevelKind {
81
+ switch (obj.kind) {
82
+ case 'Partial': {
83
+ return new Partial({ numSignatures: obj.value.numSignatures });
84
+ }
85
+ case 'Full': {
86
+ return new Full();
87
+ }
88
+ }
89
+ throw new Error('Invalid enum object');
90
+ }
91
+
92
+ export function layout(property?: string) {
93
+ const ret = borsh.rustEnum([borsh.struct([borsh.u8('numSignatures')], 'Partial'), borsh.struct([], 'Full')]);
94
+ if (property !== undefined) {
95
+ return ret.replicate(property);
96
+ }
97
+ return ret;
98
+ }
@@ -0,0 +1,9 @@
1
+ export { PriceFeedMessage } from './PriceFeedMessage';
2
+ export type { PriceFeedMessageFields, PriceFeedMessageJSON } from './PriceFeedMessage';
3
+
4
+ import * as VerificationLevel from './VerificationLevel';
5
+
6
+ export { VerificationLevel };
7
+
8
+ export type VerificationLevelKind = VerificationLevel.Partial | VerificationLevel.Full;
9
+ export type VerificationLevelJSON = VerificationLevel.PartialJSON | VerificationLevel.FullJSON;
@@ -41,13 +41,11 @@ export const getInitAllReferrerTokenStateIxns = async ({
41
41
 
42
42
  tokenStatesToCreate.forEach(([referrerTokenStateAddress, reserveAddress]) => {
43
43
  const initReferrerTokenStateIx = initReferrerTokenState(
44
- {
45
- referrer,
46
- },
47
44
  {
48
45
  lendingMarket: kaminoMarket.getAddress(),
49
46
  payer,
50
47
  reserve: reserveAddress,
48
+ referrer,
51
49
  referrerTokenState: referrerTokenStateAddress,
52
50
  rent: SYSVAR_RENT_PUBKEY,
53
51
  systemProgram: SystemProgram.programId,
@@ -277,9 +277,7 @@ export const encodeTokenName = (tokenName: string): number[] => {
277
277
  for (let i = 0; i < tokenNameEncoded.length; i++) {
278
278
  buffer[i] = tokenNameEncoded[i];
279
279
  }
280
-
281
- const result = [...buffer];
282
- return result;
280
+ return [...buffer];
283
281
  };
284
282
 
285
283
  function buildReserveConfig(fields: {
@@ -337,13 +335,15 @@ function buildReserveConfig(fields: {
337
335
  deleveragingMarginCallPeriodSecs: new BN(0),
338
336
  borrowFactorPct: new BN(100),
339
337
  elevationGroups: fields.configParams.elevationGroups,
340
- deleveragingThresholdSlotsPerBps: new BN(7200),
338
+ deleveragingThresholdSecsPerBps: new BN(3600),
341
339
  disableUsageAsCollOutsideEmode: 0,
342
340
  utilizationLimitBlockBorrowingAbove: 0,
343
341
  hostFixedInterestRateBps: 0,
342
+ autodeleverageEnabled: 0,
344
343
  borrowLimitOutsideElevationGroup: new BN(0),
345
344
  borrowLimitAgainstThisCollateralInElevationGroup: Array(32).fill(new BN(0)),
346
- reserved1: Array(2).fill(0),
345
+ deleveragingBonusIncreaseBpsPerDay: new BN(100),
346
+ reserved1: Array(1).fill(0),
347
347
  reserved2: Array(2).fill(0),
348
348
  reserved3: Array(8).fill(0),
349
349
  };
@@ -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
  }