@kamino-finance/klend-sdk 7.2.3 → 7.2.5

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.
@@ -1,4 +1,4 @@
1
- import { Address, Instruction } from '@solana/kit';
1
+ import { Address, Instruction, TransactionSigner } from '@solana/kit';
2
2
  import Decimal from 'decimal.js/decimal';
3
3
 
4
4
  /** the populateLUTIxs should be executed in a separate transaction as we cannot create and populate a lookup table in the same tx */
@@ -9,6 +9,8 @@ export type InitVaultIxs = {
9
9
  populateLUTIxs: Instruction[];
10
10
  cleanupIxs: Instruction[];
11
11
  initSharesMetadataIx: Instruction;
12
+ createVaultFarm: CreateVaultFarm;
13
+ setFarmToVaultIx: Instruction;
12
14
  };
13
15
 
14
16
  export type AcceptVaultOwnershipIxs = {
@@ -78,3 +80,9 @@ export type APYs = {
78
80
  grossAPY: Decimal;
79
81
  netAPY: Decimal;
80
82
  };
83
+
84
+ export type CreateVaultFarm = {
85
+ farm: TransactionSigner;
86
+ setupFarmIxs: Instruction[];
87
+ updateFarmIxs: Instruction[];
88
+ };
@@ -352,6 +352,22 @@ async function main() {
352
352
  ...instructions.createAtaIfNeededIxs,
353
353
  ...instructions.initVaultIxs,
354
354
  instructions.createLUTIx,
355
+ instructions.setFarmToVaultIx,
356
+ ...getPriorityFeeAndCuIxs({
357
+ priorityFeeMultiplier: 2500,
358
+ }),
359
+ ],
360
+ mode,
361
+ []
362
+ );
363
+ await sleep(2000);
364
+ // create the farm
365
+ await processTx(
366
+ env.c,
367
+ admin,
368
+ [
369
+ ...instructions.createVaultFarm.setupFarmIxs,
370
+ ...instructions.createVaultFarm.updateFarmIxs,
355
371
  ...getPriorityFeeAndCuIxs({
356
372
  priorityFeeMultiplier: 2500,
357
373
  }),
@@ -1,5 +1,6 @@
1
1
  import Decimal from 'decimal.js';
2
2
  import { Address } from '@solana/kit';
3
+ import { lamportsToCollDecimal } from '@kamino-finance/farms-sdk';
3
4
 
4
5
  export interface ReserveAllocationOverview {
5
6
  targetWeight: Decimal;
@@ -13,21 +14,22 @@ export interface VaultAllocationResult {
13
14
  }
14
15
 
15
16
  const ZERO = new Decimal(0);
16
- const ONE = new Decimal(1);
17
17
 
18
18
  /**
19
19
  * Computes the allocation of vault funds across reserves based on weights and caps
20
- * @param vaultAUM - Total AUM of the vault
20
+ * @param vaultAUM - Total AUM of the vault, in tokens
21
21
  * @param vaultUnallocatedWeight - Weight for unallocated funds
22
22
  * @param vaultUnallocatedCap - Maximum amount that can remain unallocated
23
23
  * @param initialVaultAllocations - Map of reserve addresses to their allocation configurations
24
- * @returns Object containing target unallocated amount and target allocations per reserve
24
+ * @param vaultTokenDecimals - The number of decimals of the vault token, needed to compute the min amount
25
+ * @returns Object containing target unallocated amount and target allocations per reserve, in tokens
25
26
  */
26
27
  export function computeReservesAllocation(
27
28
  vaultAUM: Decimal,
28
29
  vaultUnallocatedWeight: Decimal,
29
30
  vaultUnallocatedCap: Decimal,
30
- initialVaultAllocations: Map<Address, ReserveAllocationOverview>
31
+ initialVaultAllocations: Map<Address, ReserveAllocationOverview>,
32
+ vaultTokenDecimals: number
31
33
  ): VaultAllocationResult {
32
34
  let totalAllocation = new Decimal(0);
33
35
  const allReserves = Array.from(initialVaultAllocations.keys());
@@ -51,8 +53,10 @@ export function computeReservesAllocation(
51
53
 
52
54
  let currentAllocationSum = totalAllocation;
53
55
 
56
+ const reservesCount = allReserves.length;
57
+ const maxRemainedUninvestedLamports = lamportsToCollDecimal(new Decimal(reservesCount), vaultTokenDecimals); // invest only if the AUM has more lamports than the number of reserves
54
58
  // Iteratively allocate funds to reserves based on weights and caps
55
- while (totalLeftToInvest.gt(ONE) && currentAllocationSum.gt(ZERO)) {
59
+ while (totalLeftToInvest.gt(maxRemainedUninvestedLamports) && currentAllocationSum.gt(ZERO)) {
56
60
  const totalLeftover = totalLeftToInvest;
57
61
 
58
62
  for (const reserve of allReserves) {