@kamino-finance/klend-sdk 5.14.0 → 5.14.1-beta.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 (140) hide show
  1. package/dist/classes/configItems.d.ts +166 -0
  2. package/dist/classes/configItems.d.ts.map +1 -0
  3. package/dist/classes/configItems.js +202 -0
  4. package/dist/classes/configItems.js.map +1 -0
  5. package/dist/classes/farm_utils.d.ts.map +1 -1
  6. package/dist/classes/farm_utils.js +3 -10
  7. package/dist/classes/farm_utils.js.map +1 -1
  8. package/dist/classes/manager.d.ts +6 -21
  9. package/dist/classes/manager.d.ts.map +1 -1
  10. package/dist/classes/manager.js +40 -311
  11. package/dist/classes/manager.js.map +1 -1
  12. package/dist/classes/obligation.d.ts.map +1 -1
  13. package/dist/classes/obligation.js +14 -0
  14. package/dist/classes/obligation.js.map +1 -1
  15. package/dist/classes/reserve.d.ts +5 -14
  16. package/dist/classes/reserve.d.ts.map +1 -1
  17. package/dist/classes/reserve.js +91 -463
  18. package/dist/classes/reserve.js.map +1 -1
  19. package/dist/classes/shared.d.ts +0 -1
  20. package/dist/classes/shared.d.ts.map +1 -1
  21. package/dist/classes/shared.js.map +1 -1
  22. package/dist/classes/utils.d.ts +1 -0
  23. package/dist/classes/utils.d.ts.map +1 -1
  24. package/dist/classes/utils.js +12 -0
  25. package/dist/classes/utils.js.map +1 -1
  26. package/dist/classes/vault.d.ts +1 -11
  27. package/dist/classes/vault.d.ts.map +1 -1
  28. package/dist/classes/vault.js +6 -54
  29. package/dist/classes/vault.js.map +1 -1
  30. package/dist/client_kamino_manager.d.ts.map +1 -1
  31. package/dist/client_kamino_manager.js +27 -26
  32. package/dist/client_kamino_manager.js.map +1 -1
  33. package/dist/idl.json +186 -9
  34. package/dist/idl_codegen/accounts/GlobalConfig.d.ts +40 -0
  35. package/dist/idl_codegen/accounts/GlobalConfig.d.ts.map +1 -0
  36. package/dist/idl_codegen/accounts/GlobalConfig.js +116 -0
  37. package/dist/idl_codegen/accounts/GlobalConfig.js.map +1 -0
  38. package/dist/idl_codegen/accounts/LendingMarket.d.ts +24 -3
  39. package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
  40. package/dist/idl_codegen/accounts/LendingMarket.js +25 -7
  41. package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
  42. package/dist/idl_codegen/accounts/index.d.ts +2 -0
  43. package/dist/idl_codegen/accounts/index.d.ts.map +1 -1
  44. package/dist/idl_codegen/accounts/index.js +3 -1
  45. package/dist/idl_codegen/accounts/index.js.map +1 -1
  46. package/dist/idl_codegen/errors/custom.d.ts +25 -1
  47. package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
  48. package/dist/idl_codegen/errors/custom.js +43 -1
  49. package/dist/idl_codegen/errors/custom.js.map +1 -1
  50. package/dist/idl_codegen/instructions/idlMissingTypes.d.ts +2 -1
  51. package/dist/idl_codegen/instructions/idlMissingTypes.d.ts.map +1 -1
  52. package/dist/idl_codegen/instructions/idlMissingTypes.js +2 -1
  53. package/dist/idl_codegen/instructions/idlMissingTypes.js.map +1 -1
  54. package/dist/idl_codegen/instructions/index.d.ts +6 -0
  55. package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
  56. package/dist/idl_codegen/instructions/index.js +7 -1
  57. package/dist/idl_codegen/instructions/index.js.map +1 -1
  58. package/dist/idl_codegen/instructions/initGlobalConfig.d.ts +10 -0
  59. package/dist/idl_codegen/instructions/initGlobalConfig.d.ts.map +1 -0
  60. package/dist/idl_codegen/instructions/initGlobalConfig.js +19 -0
  61. package/dist/idl_codegen/instructions/initGlobalConfig.js.map +1 -0
  62. package/dist/idl_codegen/instructions/updateGlobalConfig.d.ts +13 -0
  63. package/dist/idl_codegen/instructions/updateGlobalConfig.d.ts.map +1 -0
  64. package/dist/idl_codegen/instructions/updateGlobalConfig.js +61 -0
  65. package/dist/idl_codegen/instructions/updateGlobalConfig.js.map +1 -0
  66. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.d.ts +7 -0
  67. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.d.ts.map +1 -0
  68. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.js +16 -0
  69. package/dist/idl_codegen/instructions/updateGlobalConfigAdmin.js.map +1 -0
  70. package/dist/idl_codegen/instructions/updateReserveConfig.d.ts +4 -3
  71. package/dist/idl_codegen/instructions/updateReserveConfig.d.ts.map +1 -1
  72. package/dist/idl_codegen/instructions/updateReserveConfig.js +5 -3
  73. package/dist/idl_codegen/instructions/updateReserveConfig.js.map +1 -1
  74. package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts +2 -2
  75. package/dist/idl_codegen/instructions/withdrawProtocolFee.d.ts.map +1 -1
  76. package/dist/idl_codegen/instructions/withdrawProtocolFee.js +2 -6
  77. package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
  78. package/dist/idl_codegen/types/UpdateGlobalConfigMode.d.ts +32 -0
  79. package/dist/idl_codegen/types/UpdateGlobalConfigMode.d.ts.map +1 -0
  80. package/dist/idl_codegen/types/UpdateGlobalConfigMode.js +108 -0
  81. package/dist/idl_codegen/types/UpdateGlobalConfigMode.js.map +1 -0
  82. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +33 -7
  83. package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
  84. package/dist/idl_codegen/types/UpdateLendingMarketMode.js +60 -12
  85. package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
  86. package/dist/idl_codegen/types/index.d.ts +6 -2
  87. package/dist/idl_codegen/types/index.d.ts.map +1 -1
  88. package/dist/idl_codegen/types/index.js +3 -1
  89. package/dist/idl_codegen/types/index.js.map +1 -1
  90. package/dist/utils/accountListing.d.ts +1 -1
  91. package/dist/utils/accountListing.d.ts.map +1 -1
  92. package/dist/utils/accountListing.js +2 -2
  93. package/dist/utils/accountListing.js.map +1 -1
  94. package/dist/utils/api.d.ts +1 -5
  95. package/dist/utils/api.d.ts.map +1 -1
  96. package/dist/utils/api.js +6 -15
  97. package/dist/utils/api.js.map +1 -1
  98. package/dist/utils/constants.d.ts +1 -1
  99. package/dist/utils/constants.js +1 -1
  100. package/dist/utils/lookupTable.d.ts.map +1 -1
  101. package/dist/utils/lookupTable.js +1 -6
  102. package/dist/utils/lookupTable.js.map +1 -1
  103. package/dist/utils/managerTypes.d.ts.map +1 -1
  104. package/dist/utils/managerTypes.js +10 -4
  105. package/dist/utils/managerTypes.js.map +1 -1
  106. package/dist/utils/seeds.d.ts +16 -0
  107. package/dist/utils/seeds.d.ts.map +1 -1
  108. package/dist/utils/seeds.js +23 -1
  109. package/dist/utils/seeds.js.map +1 -1
  110. package/package.json +1 -1
  111. package/src/classes/configItems.ts +295 -0
  112. package/src/classes/farm_utils.ts +3 -11
  113. package/src/classes/manager.ts +52 -417
  114. package/src/classes/obligation.ts +16 -0
  115. package/src/classes/reserve.ts +119 -783
  116. package/src/classes/shared.ts +0 -1
  117. package/src/classes/utils.ts +12 -0
  118. package/src/classes/vault.ts +7 -75
  119. package/src/client_kamino_manager.ts +42 -34
  120. package/src/idl.json +186 -9
  121. package/src/idl_codegen/accounts/GlobalConfig.ts +125 -0
  122. package/src/idl_codegen/accounts/LendingMarket.ts +41 -9
  123. package/src/idl_codegen/accounts/index.ts +2 -0
  124. package/src/idl_codegen/errors/custom.ts +45 -0
  125. package/src/idl_codegen/instructions/idlMissingTypes.ts +4 -2
  126. package/src/idl_codegen/instructions/index.ts +9 -0
  127. package/src/idl_codegen/instructions/initGlobalConfig.ts +30 -0
  128. package/src/idl_codegen/instructions/updateGlobalConfig.ts +47 -0
  129. package/src/idl_codegen/instructions/updateGlobalConfigAdmin.ts +24 -0
  130. package/src/idl_codegen/instructions/updateReserveConfig.ts +7 -5
  131. package/src/idl_codegen/instructions/withdrawProtocolFee.ts +4 -8
  132. package/src/idl_codegen/types/UpdateGlobalConfigMode.ts +90 -0
  133. package/src/idl_codegen/types/UpdateLendingMarketMode.ts +73 -13
  134. package/src/idl_codegen/types/index.ts +16 -2
  135. package/src/utils/accountListing.ts +2 -3
  136. package/src/utils/api.ts +6 -20
  137. package/src/utils/constants.ts +1 -1
  138. package/src/utils/lookupTable.ts +1 -7
  139. package/src/utils/managerTypes.ts +10 -4
  140. package/src/utils/seeds.ts +25 -0
@@ -10,7 +10,6 @@ export type MarketConfigType = {
10
10
  description: string;
11
11
  lendingMarket: string;
12
12
  lookupTable: string;
13
- isCurated: boolean;
14
13
  };
15
14
 
16
15
  export type ReserveConfigResponse = {
@@ -287,6 +287,18 @@ export function orThrow(message: string): never {
287
287
  throw new Error(message);
288
288
  }
289
289
 
290
+ export function blobEquals(left: Uint8Array, right: Uint8Array): boolean {
291
+ if (left.length !== right.length) {
292
+ return false;
293
+ }
294
+ for (let i = 0; i < left.length; ++i) {
295
+ if (left[i] !== right[i]) {
296
+ return false;
297
+ }
298
+ }
299
+ return true;
300
+ }
301
+
290
302
  /**
291
303
  * Returns an integer {@link Decimal} nearest to the given one.
292
304
  *
@@ -966,9 +966,7 @@ export class KaminoVaultClient {
966
966
  };
967
967
 
968
968
  const depositArgs: DepositArgs = {
969
- maxAmount: new BN(
970
- numberToLamportsDecimal(tokenAmount, vaultState.tokenMintDecimals.toNumber()).floor().toString()
971
- ),
969
+ maxAmount: new BN(numberToLamportsDecimal(tokenAmount, vaultState.tokenMintDecimals.toNumber()).toString()),
972
970
  };
973
971
 
974
972
  const depositIx = deposit(depositArgs, depoistAccounts, this._kaminoVaultProgramId);
@@ -1086,7 +1084,7 @@ export class KaminoVaultClient {
1086
1084
  );
1087
1085
 
1088
1086
  if (vaultAllocation) {
1089
- const withdrawFromVaultIxs = await this.withdrawWithReserveIxs(
1087
+ const withdrawFromVaultIxs = await this.wihdrdrawWithReserveIxs(
1090
1088
  user,
1091
1089
  kaminoVault,
1092
1090
  shareAmount,
@@ -1131,7 +1129,7 @@ export class KaminoVaultClient {
1131
1129
  return [createAtaIx, withdrawFromAvailableIxn];
1132
1130
  }
1133
1131
 
1134
- private async withdrawWithReserveIxs(
1132
+ private async wihdrdrawWithReserveIxs(
1135
1133
  user: PublicKey,
1136
1134
  vault: KaminoVault,
1137
1135
  shareAmount: Decimal,
@@ -1141,6 +1139,7 @@ export class KaminoVaultClient {
1141
1139
  const vaultState = await vault.getState(this.getConnection());
1142
1140
 
1143
1141
  const vaultReservesState = vaultReservesMap ? vaultReservesMap : await this.loadVaultReserves(vaultState);
1142
+
1144
1143
  const userSharesAta = getAssociatedTokenAddress(vaultState.sharesMint, user);
1145
1144
  const [{ ata: userTokenAta, createAtaIx }] = createAtasIdempotent(user, [
1146
1145
  {
@@ -1163,12 +1162,9 @@ export class KaminoVaultClient {
1163
1162
  let isFirstWithdraw = true;
1164
1163
 
1165
1164
  if (tokenLeftToWithdraw.lte(0)) {
1166
- // Availabe enough to withdraw all - using the first existent reserve
1167
- const firstReserve = vaultState.vaultAllocationStrategy.find(
1168
- (reserve) => !reserve.reserve.equals(PublicKey.default)
1169
- );
1165
+ // Availabe enough to withdraw all - using first reserve as it does not matter
1170
1166
  reserveWithSharesAmountToWithdraw.push({
1171
- reserve: firstReserve!.reserve,
1167
+ reserve: vaultState.vaultAllocationStrategy[0].reserve,
1172
1168
  shares: shareLamportsToWithdraw,
1173
1169
  });
1174
1170
  } else {
@@ -1201,6 +1197,7 @@ export class KaminoVaultClient {
1201
1197
 
1202
1198
  const withdrawIxs: TransactionInstruction[] = [];
1203
1199
  withdrawIxs.push(createAtaIx);
1200
+
1204
1201
  for (let reserveIndex = 0; reserveIndex < reserveWithSharesAmountToWithdraw.length; reserveIndex++) {
1205
1202
  const reserveWithTokens = reserveWithSharesAmountToWithdraw[reserveIndex];
1206
1203
  const reserveState = vaultReservesState.get(reserveWithTokens.reserve);
@@ -2507,7 +2504,6 @@ export class KaminoVaultClient {
2507
2504
  const slotForOverview = slot ? slot : await this.getConnection().getSlot();
2508
2505
 
2509
2506
  const vaultTheoreticalAPYPromise = await this.getVaultTheoreticalAPY(vault, slotForOverview, vaultReservesState);
2510
- const vaultActualAPYPromise = await this.getVaultActualAPY(vault, slotForOverview, vaultReservesState);
2511
2507
  const totalInvestedAndBorrowedPromise = await this.getTotalBorrowedAndInvested(
2512
2508
  vault,
2513
2509
  slotForOverview,
@@ -2525,14 +2521,12 @@ export class KaminoVaultClient {
2525
2521
  const [
2526
2522
  vaultHoldingsWithUSDValue,
2527
2523
  vaultTheoreticalAPYs,
2528
- vaultActualAPYs,
2529
2524
  totalInvestedAndBorrowed,
2530
2525
  vaultCollaterals,
2531
2526
  reservesOverview,
2532
2527
  ] = await Promise.all([
2533
2528
  vaultHoldingsWithUSDValuePromise,
2534
2529
  vaultTheoreticalAPYPromise,
2535
- vaultActualAPYPromise,
2536
2530
  totalInvestedAndBorrowedPromise,
2537
2531
  vaultCollateralsPromise,
2538
2532
  reservesOverviewPromise,
@@ -2542,7 +2536,6 @@ export class KaminoVaultClient {
2542
2536
  holdingsUSD: vaultHoldingsWithUSDValue,
2543
2537
  reservesOverview: reservesOverview,
2544
2538
  vaultCollaterals: vaultCollaterals,
2545
- actualSupplyAPY: vaultActualAPYs,
2546
2539
  theoreticalSupplyAPY: vaultTheoreticalAPYs,
2547
2540
  totalBorrowed: totalInvestedAndBorrowed.totalBorrowed,
2548
2541
  totalBorrowedUSD: totalInvestedAndBorrowed.totalBorrowed.mul(price),
@@ -2700,57 +2693,6 @@ export class KaminoVaultClient {
2700
2693
  };
2701
2694
  }
2702
2695
 
2703
- /**
2704
- * This will return the APY of the vault based on the current invested amounts; for percentage it needs multiplication by 100
2705
- * @param vault - the kamino vault to get APY for
2706
- * @param slot - current slot
2707
- * @param [vaultReservesMap] - hashmap from each reserve pubkey to the reserve state. Optional. If provided the function will be significantly faster as it will not have to fetch the reserves
2708
- * @returns a struct containing estimated gross APY and net APY (gross - vault fees) for the vault
2709
- */
2710
- async getVaultActualAPY(
2711
- vault: VaultState,
2712
- slot: number,
2713
- vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>
2714
- ): Promise<APYs> {
2715
- const vaultReservesState = vaultReservesMap ? vaultReservesMap : await this.loadVaultReserves(vault);
2716
-
2717
- let totalAUM = new Decimal(vault.tokenAvailable.toString());
2718
- let totalAPY = new Decimal(0);
2719
- vault.vaultAllocationStrategy.forEach((allocationStrategy) => {
2720
- if (allocationStrategy.reserve.equals(PublicKey.default)) {
2721
- return;
2722
- }
2723
-
2724
- const reserve = vaultReservesState.get(allocationStrategy.reserve);
2725
- if (reserve === undefined) {
2726
- throw new Error(`Reserve ${allocationStrategy.reserve.toBase58()} not found`);
2727
- }
2728
-
2729
- const reserveAPY = new Decimal(reserve.totalSupplyAPY(slot));
2730
- const exchangeRate = reserve.getEstimatedCollateralExchangeRate(slot, 0);
2731
- const investedInReserve = exchangeRate.mul(new Decimal(allocationStrategy.ctokenAllocation.toString()));
2732
-
2733
- const weightedAPY = reserveAPY.mul(investedInReserve);
2734
- totalAPY = totalAPY.add(weightedAPY);
2735
- totalAUM = totalAUM.add(investedInReserve);
2736
- });
2737
- if (totalAUM.isZero()) {
2738
- return {
2739
- grossAPY: new Decimal(0),
2740
- netAPY: new Decimal(0),
2741
- };
2742
- }
2743
-
2744
- const grossAPY = totalAPY.div(totalAUM);
2745
- const netAPY = grossAPY
2746
- .mul(new Decimal(1).sub(new Decimal(vault.performanceFeeBps.toString()).div(FullBPSDecimal)))
2747
- .mul(new Decimal(1).sub(new Decimal(vault.managementFeeBps.toString()).div(FullBPSDecimal)));
2748
- return {
2749
- grossAPY,
2750
- netAPY,
2751
- };
2752
- }
2753
-
2754
2696
  /**
2755
2697
  * Retrive the total amount of interest earned by the vault since its inception, up to the last interaction with the vault on chain, including what was charged as fees
2756
2698
  * @param vaultState the kamino vault state to get total net yield for
@@ -2842,15 +2784,6 @@ export class KaminoVaultClient {
2842
2784
  performanceFee: performanceFee,
2843
2785
  };
2844
2786
  }
2845
-
2846
- computeUserFarmStateDelegateePDAForUserInVault(
2847
- farmProgramID: PublicKey,
2848
- vault: PublicKey,
2849
- reserve: PublicKey,
2850
- user: PublicKey
2851
- ): [PublicKey, number] {
2852
- return PublicKey.findProgramAddressSync([vault.toBuffer(), reserve.toBuffer(), user.toBuffer()], farmProgramID);
2853
- }
2854
2787
  } // KaminoVaultClient
2855
2788
 
2856
2789
  export class KaminoVault {
@@ -3039,7 +2972,6 @@ export type VaultOverview = {
3039
2972
  reservesOverview: PubkeyHashMap<PublicKey, ReserveOverview>;
3040
2973
  vaultCollaterals: PubkeyHashMap<PublicKey, MarketOverview>;
3041
2974
  theoreticalSupplyAPY: APYs;
3042
- actualSupplyAPY: APYs;
3043
2975
  totalBorrowed: Decimal;
3044
2976
  totalBorrowedUSD: Decimal;
3045
2977
  totalSupplied: Decimal;
@@ -8,15 +8,20 @@ import {
8
8
  Signer,
9
9
  Transaction,
10
10
  TransactionInstruction,
11
+ TransactionMessage,
11
12
  TransactionSignature,
12
13
  VersionedTransaction,
13
14
  } from '@solana/web3.js';
14
15
  import {
15
16
  AssetReserveConfigCli,
16
17
  Chain,
18
+ createLookupTableIx,
17
19
  DEFAULT_RECENT_SLOT_DURATION_MS,
18
20
  encodeTokenName,
21
+ extendLookupTableIxs,
22
+ getLookupTableAccounts,
19
23
  getMedianSlotDurationInMsFromLastEpochs,
24
+ globalConfigPda,
20
25
  initLookupTableIx,
21
26
  KaminoManager,
22
27
  KaminoMarket,
@@ -27,6 +32,7 @@ import {
27
32
  MAINNET_BETA_CHAIN_ID,
28
33
  parseZeroPaddedUtf8,
29
34
  printHoldings,
35
+ PROGRAM_ID,
30
36
  Reserve,
31
37
  ReserveAllocationConfig,
32
38
  ReserveWithAddress,
@@ -153,7 +159,10 @@ async function main() {
153
159
 
154
160
  const _createReserveSig = await processTxn(env.client, env.payer, txnIxs[0], mode, 2500, [reserve]);
155
161
 
156
- const _updateReserveSig = await processTxn(env.client, env.payer, txnIxs[1], mode, 2500, [], 400_000);
162
+ const [lut, createLutIxs] = await createUpdateReserveConfigLutIxs(env, marketAddress, reserve.publicKey);
163
+ await processTxn(env.client, env.payer, createLutIxs, mode, 2500, []);
164
+
165
+ const _updateSig = await processTxn(env.client, env.payer, txnIxs[1], mode, 2500, [], 400_000, 1000, [lut]);
157
166
 
158
167
  mode === 'execute' &&
159
168
  console.log(
@@ -609,21 +618,13 @@ async function main() {
609
618
  const acceptVaultOwnershipSig = await processTxn(
610
619
  env.client,
611
620
  env.payer,
612
- [instructions.acceptVaultOwnershipIx],
621
+ [instructions.acceptVaultOwnershipIx, ...instructions.updateLUTIxs],
613
622
  mode,
614
623
  2500,
615
624
  []
616
625
  );
617
626
 
618
627
  mode === 'execute' && console.log('Vault ownership accepted:', acceptVaultOwnershipSig);
619
-
620
- // send the LUT mgmt ixs one by one
621
- const lutIxs = [...instructions.updateLUTIxs];
622
- for (let i = 0; i < lutIxs.length; i++) {
623
- const lutIxsGroup = lutIxs.slice(i, i + 1);
624
- const lutIxsSig = await processTxn(env.client, env.payer, lutIxsGroup, mode, 2500, []);
625
- mode === 'execute' && console.log('LUT updated:', lutIxsSig);
626
- }
627
628
  });
628
629
 
629
630
  commands
@@ -1076,11 +1077,7 @@ async function main() {
1076
1077
  const walletAddress = new PublicKey(wallet);
1077
1078
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
1078
1079
  const userShares = await kaminoManager.getUserSharesBalanceSingleVault(walletAddress, kaminoVault);
1079
- console.log(
1080
- `User shares for vault ${vaultAddress.toBase58()}: unstaked shares: ${
1081
- userShares.unstakedShares
1082
- } staked shares: ${userShares.stakedShares} total shares: ${userShares.totalShares}`
1083
- );
1080
+ console.log(`User shares for vault ${vaultAddress.toBase58()}: ${userShares}`);
1084
1081
  });
1085
1082
 
1086
1083
  commands
@@ -1604,45 +1601,46 @@ async function processTxn(
1604
1601
  priorityFeeMultiplier: number = 2500,
1605
1602
  extraSigners: Signer[],
1606
1603
  computeUnits: number = 200_000,
1607
- priorityFeeLamports: number = 1000
1604
+ priorityFeeLamports: number = 1000,
1605
+ luts: PublicKey[] = []
1608
1606
  ): Promise<TransactionSignature> {
1609
1607
  if (mode !== 'inspect' && mode !== 'simulate' && mode !== 'execute' && mode !== 'multisig') {
1610
1608
  throw new Error('Invalid mode: ' + mode + '. Must be one of: inspect/simulate/execute/multisig');
1611
1609
  }
1612
1610
  if (mode === 'multisig') {
1613
1611
  const { blockhash } = await web3Client.connection.getLatestBlockhash();
1614
- for (const ix of ixs) {
1615
- const txn = new Transaction();
1616
- txn.add(ix);
1617
- txn.recentBlockhash = blockhash;
1618
- txn.feePayer = admin.publicKey;
1612
+ const txn = new Transaction();
1613
+ txn.add(...ixs);
1614
+ txn.recentBlockhash = blockhash;
1615
+ txn.feePayer = admin.publicKey;
1619
1616
 
1620
- console.log(`${binary_to_base58(txn.serializeMessage())} \n`);
1621
- }
1617
+ console.log(binary_to_base58(txn.serializeMessage()));
1622
1618
 
1623
1619
  return '';
1624
1620
  } else {
1625
1621
  const microLamport = priorityFeeLamports * 10 ** 6; // 1000 lamports
1626
1622
  const microLamportsPrioritizationFee = microLamport / computeUnits;
1627
-
1628
- const tx = new Transaction();
1629
1623
  const { blockhash } = await web3Client.connection.getLatestBlockhash();
1624
+
1630
1625
  if (priorityFeeMultiplier) {
1631
1626
  const priorityFeeIxn = createAddExtraComputeUnitFeeTransaction(
1632
1627
  computeUnits,
1633
1628
  microLamportsPrioritizationFee * priorityFeeMultiplier
1634
1629
  );
1635
- tx.add(...priorityFeeIxn);
1630
+ ixs.push(...priorityFeeIxn);
1636
1631
  }
1637
- tx.recentBlockhash = blockhash;
1638
- tx.feePayer = admin.publicKey;
1639
- tx.add(...ixs);
1632
+
1633
+ const tx = new TransactionMessage({
1634
+ payerKey: admin.publicKey,
1635
+ recentBlockhash: blockhash,
1636
+ instructions: ixs,
1637
+ }).compileToV0Message(await getLookupTableAccounts(web3Client.connection, luts));
1640
1638
 
1641
1639
  if (mode === 'execute') {
1642
1640
  return await signSendAndConfirmRawTransactionWithRetry({
1643
1641
  mainConnection: web3Client.sendConnection,
1644
1642
  extraConnections: [],
1645
- tx: new VersionedTransaction(tx.compileMessage()),
1643
+ tx: new VersionedTransaction(tx),
1646
1644
  signers: [admin, ...extraSigners],
1647
1645
  commitment: 'confirmed',
1648
1646
  sendTransactionOptions: {
@@ -1651,9 +1649,7 @@ async function processTxn(
1651
1649
  },
1652
1650
  });
1653
1651
  } else if (mode === 'simulate') {
1654
- const simulation = await web3Client.sendConnection.simulateTransaction(
1655
- new VersionedTransaction(tx.compileMessage())
1656
- );
1652
+ const simulation = await web3Client.sendConnection.simulateTransaction(new VersionedTransaction(tx));
1657
1653
  if (simulation.value.logs && simulation.value.logs.length > 0) {
1658
1654
  console.log('Simulation: \n' + simulation.value.logs);
1659
1655
  } else {
@@ -1663,7 +1659,7 @@ async function processTxn(
1663
1659
  console.log(
1664
1660
  'Tx in B64',
1665
1661
  `https://explorer.solana.com/tx/inspector?message=${encodeURIComponent(
1666
- tx.serializeMessage().toString('base64')
1662
+ Buffer.from(tx.serialize()).toString('base64')
1667
1663
  )}`
1668
1664
  );
1669
1665
  }
@@ -1861,3 +1857,15 @@ function parseReserveConfigToFile(reserveConfig: ReserveConfig) {
1861
1857
  reserved2: Array(9).fill(0),
1862
1858
  };
1863
1859
  }
1860
+
1861
+ async function createUpdateReserveConfigLutIxs(
1862
+ env: Env,
1863
+ lendingMarketAddress: PublicKey,
1864
+ reserveAddress: PublicKey
1865
+ ): Promise<[PublicKey, TransactionInstruction[]]> {
1866
+ const [globalConfigAddress] = globalConfigPda(PROGRAM_ID);
1867
+ const contents = [globalConfigAddress, lendingMarketAddress, reserveAddress];
1868
+ const [createIx, lut] = await createLookupTableIx(env.connection, env.payer.publicKey);
1869
+ const extendIxs = extendLookupTableIxs(env.payer.publicKey, lut, contents);
1870
+ return [lut, [createIx, ...extendIxs]];
1871
+ }
package/src/idl.json CHANGED
@@ -230,10 +230,15 @@
230
230
  "name": "updateReserveConfig",
231
231
  "accounts": [
232
232
  {
233
- "name": "lendingMarketOwner",
233
+ "name": "signer",
234
234
  "isMut": false,
235
235
  "isSigner": true
236
236
  },
237
+ {
238
+ "name": "globalConfig",
239
+ "isMut": false,
240
+ "isSigner": false
241
+ },
237
242
  {
238
243
  "name": "lendingMarket",
239
244
  "isMut": false,
@@ -248,7 +253,9 @@
248
253
  "args": [
249
254
  {
250
255
  "name": "mode",
251
- "type": "u64"
256
+ "type": {
257
+ "defined": "UpdateConfigMode"
258
+ }
252
259
  },
253
260
  {
254
261
  "name": "value",
@@ -305,9 +312,9 @@
305
312
  "name": "withdrawProtocolFee",
306
313
  "accounts": [
307
314
  {
308
- "name": "lendingMarketOwner",
315
+ "name": "globalConfig",
309
316
  "isMut": false,
310
- "isSigner": true
317
+ "isSigner": false
311
318
  },
312
319
  {
313
320
  "name": "lendingMarket",
@@ -335,7 +342,7 @@
335
342
  "isSigner": false
336
343
  },
337
344
  {
338
- "name": "lendingMarketOwnerAta",
345
+ "name": "feeCollectorAta",
339
346
  "isMut": true,
340
347
  "isSigner": false
341
348
  },
@@ -2932,14 +2939,93 @@
2932
2939
  }
2933
2940
  ]
2934
2941
  },
2942
+ {
2943
+ "name": "initGlobalConfig",
2944
+ "accounts": [
2945
+ {
2946
+ "name": "payer",
2947
+ "isMut": true,
2948
+ "isSigner": true
2949
+ },
2950
+ {
2951
+ "name": "globalConfig",
2952
+ "isMut": true,
2953
+ "isSigner": false
2954
+ },
2955
+ {
2956
+ "name": "programData",
2957
+ "isMut": false,
2958
+ "isSigner": false
2959
+ },
2960
+ {
2961
+ "name": "systemProgram",
2962
+ "isMut": false,
2963
+ "isSigner": false
2964
+ },
2965
+ {
2966
+ "name": "rent",
2967
+ "isMut": false,
2968
+ "isSigner": false
2969
+ }
2970
+ ],
2971
+ "args": []
2972
+ },
2973
+ {
2974
+ "name": "updateGlobalConfig",
2975
+ "accounts": [
2976
+ {
2977
+ "name": "globalAdmin",
2978
+ "isMut": false,
2979
+ "isSigner": true
2980
+ },
2981
+ {
2982
+ "name": "globalConfig",
2983
+ "isMut": true,
2984
+ "isSigner": false
2985
+ }
2986
+ ],
2987
+ "args": [
2988
+ {
2989
+ "name": "mode",
2990
+ "type": {
2991
+ "defined": "UpdateGlobalConfigMode"
2992
+ }
2993
+ },
2994
+ {
2995
+ "name": "value",
2996
+ "type": "bytes"
2997
+ }
2998
+ ]
2999
+ },
3000
+ {
3001
+ "name": "updateGlobalConfigAdmin",
3002
+ "accounts": [
3003
+ {
3004
+ "name": "pendingAdmin",
3005
+ "isMut": false,
3006
+ "isSigner": true
3007
+ },
3008
+ {
3009
+ "name": "globalConfig",
3010
+ "isMut": true,
3011
+ "isSigner": false
3012
+ }
3013
+ ],
3014
+ "args": []
3015
+ },
2935
3016
  {
2936
3017
  "name": "idlMissingTypes",
2937
3018
  "accounts": [
2938
3019
  {
2939
- "name": "lendingMarketOwner",
3020
+ "name": "signer",
2940
3021
  "isMut": false,
2941
3022
  "isSigner": true
2942
3023
  },
3024
+ {
3025
+ "name": "globalConfig",
3026
+ "isMut": false,
3027
+ "isSigner": false
3028
+ },
2943
3029
  {
2944
3030
  "name": "lendingMarket",
2945
3031
  "isMut": false,
@@ -3134,6 +3220,47 @@
3134
3220
  ]
3135
3221
  }
3136
3222
  },
3223
+ {
3224
+ "name": "GlobalConfig",
3225
+ "type": {
3226
+ "kind": "struct",
3227
+ "fields": [
3228
+ {
3229
+ "name": "globalAdmin",
3230
+ "docs": [
3231
+ "Global admin of the program"
3232
+ ],
3233
+ "type": "publicKey"
3234
+ },
3235
+ {
3236
+ "name": "pendingAdmin",
3237
+ "docs": [
3238
+ "Pending admin must sign a specific transaction to become the global admin"
3239
+ ],
3240
+ "type": "publicKey"
3241
+ },
3242
+ {
3243
+ "name": "feeCollector",
3244
+ "docs": [
3245
+ "Fee collector is the only allowed owner of token accounts receiving protocol fees"
3246
+ ],
3247
+ "type": "publicKey"
3248
+ },
3249
+ {
3250
+ "name": "padding",
3251
+ "docs": [
3252
+ "Padding to make the struct size 1024 bytes"
3253
+ ],
3254
+ "type": {
3255
+ "array": [
3256
+ "u8",
3257
+ 928
3258
+ ]
3259
+ }
3260
+ }
3261
+ ]
3262
+ }
3263
+ },
3137
3264
  {
3138
3265
  "name": "LendingMarket",
3139
3266
  "type": {
@@ -3353,18 +3480,33 @@
3353
3480
  "type": "u64"
3354
3481
  },
3355
3482
  {
3356
- "name": "obligationOrdersEnabled",
3483
+ "name": "obligationOrderExecutionEnabled",
3357
3484
  "docs": [
3358
3485
  "Whether the obligation orders should be evaluated during liquidations."
3359
3486
  ],
3360
3487
  "type": "u8"
3361
3488
  },
3489
+ {
3490
+ "name": "immutable",
3491
+ "docs": [
3492
+ "Whether the lending market is set as immutable."
3493
+ ],
3494
+ "type": "u8"
3495
+ },
3496
+ {
3497
+ "name": "obligationOrderCreationEnabled",
3498
+ "docs": [
3499
+ "Whether new obligation orders can be created.",
3500
+ "Note: updating or cancelling existing orders is *not* affected by this flag."
3501
+ ],
3502
+ "type": "u8"
3503
+ },
3362
3504
  {
3363
3505
  "name": "padding2",
3364
3506
  "type": {
3365
3507
  "array": [
3366
3508
  "u8",
3367
- 7
3509
+ 5
3368
3510
  ]
3369
3511
  }
3370
3512
  },
@@ -4186,7 +4328,27 @@
4186
4328
  "name": "UpdateInitialDepositAmount"
4187
4329
  },
4188
4330
  {
4189
- "name": "UpdateObligationOrdersEnabled"
4331
+ "name": "UpdateObligationOrderExecutionEnabled"
4332
+ },
4333
+ {
4334
+ "name": "UpdateImmutableFlag"
4335
+ },
4336
+ {
4337
+ "name": "UpdateObligationOrderCreationEnabled"
4338
+ }
4339
+ ]
4340
+ }
4341
+ },
4342
+ {
4343
+ "name": "UpdateGlobalConfigMode",
4344
+ "type": {
4345
+ "kind": "enum",
4346
+ "variants": [
4347
+ {
4348
+ "name": "PendingAdmin"
4349
+ },
4350
+ {
4351
+ "name": "FeeCollector"
4190
4352
  }
4191
4353
  ]
4192
4354
  }
@@ -6032,6 +6194,21 @@
6032
6194
  "code": 6126,
6033
6195
  "name": "OperationNotPermittedWithCurrentObligationOrders",
6034
6196
  "msg": "Single debt, single collateral obligation orders have to be cancelled before changing the deposit/borrow count"
6197
+ },
6198
+ {
6199
+ "code": 6127,
6200
+ "name": "OperationNotPermittedMarketImmutable",
6201
+ "msg": "Cannot update lending market because it is set as immutable"
6202
+ },
6203
+ {
6204
+ "code": 6128,
6205
+ "name": "OrderCreationDisabled",
6206
+ "msg": "Creation of new orders is disabled"
6207
+ },
6208
+ {
6209
+ "code": 6129,
6210
+ "name": "NoUpgradeAuthority",
6211
+ "msg": "Cannot initialize global config because there is no upgrade authority to the program"
6035
6212
  }
6036
6213
  ]
6037
6214
  }