@kamino-finance/klend-sdk 5.10.9 → 5.10.11
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.
- package/README.md +26 -2
- package/dist/classes/manager.d.ts +9 -3
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +10 -2
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +4 -1
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/types.d.ts +7 -0
- package/dist/classes/types.d.ts.map +1 -1
- package/dist/classes/vault.d.ts +23 -11
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +141 -29
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +5 -5
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +17 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.js +29 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/deposit.d.ts +0 -1
- package/dist/idl_codegen_kamino_vault/instructions/deposit.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/deposit.js +0 -5
- package/dist/idl_codegen_kamino_vault/instructions/deposit.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js +5 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.d.ts +8 -5
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.js +9 -8
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.js.map +1 -1
- package/dist/utils/accountListing.d.ts +4 -0
- package/dist/utils/accountListing.d.ts.map +1 -0
- package/dist/utils/accountListing.js +37 -0
- package/dist/utils/accountListing.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +2 -1
- package/src/classes/manager.ts +12 -2
- package/src/classes/market.ts +7 -1
- package/src/classes/types.ts +9 -1
- package/src/classes/vault.ts +182 -32
- package/src/client.ts +11 -0
- package/src/client_kamino_manager.ts +12 -5
- package/src/idl_codegen_kamino_vault/errors/custom.ts +28 -0
- package/src/idl_codegen_kamino_vault/instructions/deposit.ts +0 -6
- package/src/idl_codegen_kamino_vault/instructions/updateReserveAllocation.ts +6 -2
- package/src/idl_codegen_kamino_vault/types/ReserveConfig.ts +17 -14
- package/src/idl_kamino_vault.json +17 -9
- package/src/utils/accountListing.ts +32 -0
- package/src/utils/index.ts +1 -0
package/dist/classes/vault.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { VaultConfigFieldKind } from '../idl_codegen_kamino_vault/types';
|
|
|
4
4
|
import { VaultState } from '../idl_codegen_kamino_vault/accounts';
|
|
5
5
|
import Decimal from 'decimal.js';
|
|
6
6
|
import { ReserveWithAddress } from './reserve';
|
|
7
|
-
import { AcceptVaultOwnershipIxs, DepositIxs, InitVaultIxs, SyncVaultLUTIxs, UpdateReserveAllocationIxs, UpdateVaultConfigIxs, UserSharesForVault, WithdrawIxs } from './types';
|
|
7
|
+
import { AcceptVaultOwnershipIxs, DepositIxs, InitVaultIxs, ReserveAllocationOverview, SyncVaultLUTIxs, UpdateReserveAllocationIxs, UpdateVaultConfigIxs, UserSharesForVault, WithdrawIxs } from './types';
|
|
8
8
|
import { FarmState } from '@kamino-finance/farms-sdk/dist';
|
|
9
9
|
export declare const kaminoVaultId: PublicKey;
|
|
10
10
|
export declare const kaminoVaultStagingId: PublicKey;
|
|
@@ -48,9 +48,10 @@ export declare class KaminoVaultClient {
|
|
|
48
48
|
* @param vault the vault to update
|
|
49
49
|
* @param mode the field to update (based on VaultConfigFieldKind enum)
|
|
50
50
|
* @param value the value to update the field with
|
|
51
|
+
* @param [signer] the signer of the transaction. Optional. If not provided the admin of the vault will be used. It should be used when changing the admin of the vault if we want to batch multiple ixs in the same tx
|
|
51
52
|
* @returns a struct that contains the instruction to update the field and an optional list of instructions to update the lookup table
|
|
52
53
|
*/
|
|
53
|
-
updateVaultConfigIxs(vault: KaminoVault, mode: VaultConfigFieldKind, value: string): Promise<UpdateVaultConfigIxs>;
|
|
54
|
+
updateVaultConfigIxs(vault: KaminoVault, mode: VaultConfigFieldKind, value: string, signer?: PublicKey): Promise<UpdateVaultConfigIxs>;
|
|
54
55
|
/** Sets the farm where the shares can be staked. This is store in vault state and a vault can only have one farm, so the new farm will ovveride the old farm
|
|
55
56
|
* @param vault - vault to set the farm for
|
|
56
57
|
* @param farm - the farm where the vault shares can be staked
|
|
@@ -109,7 +110,7 @@ export declare class KaminoVaultClient {
|
|
|
109
110
|
* This function will return a struct with the instructions to unstake from the farm if necessary and the instructions for the missing ATA creation instructions, as well as one or multiple withdraw instructions, based on how many reserves it's needed to withdraw from. This might have to be split in multiple transactions
|
|
110
111
|
* @param user - user to withdraw
|
|
111
112
|
* @param vault - vault to withdraw from
|
|
112
|
-
* @param shareAmount - share amount to withdraw, in order to withdraw everything, any value > user share amount
|
|
113
|
+
* @param shareAmount - share amount to withdraw (in tokens, not lamports), in order to withdraw everything, any value > user share amount
|
|
113
114
|
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
|
|
114
115
|
* @param [vaultReservesMap] - optional parameter; a hashmap from each reserve pubkey to the reserve state. If provided the function will be significantly faster as it will not have to fetch the reserves
|
|
115
116
|
* @param [farmState] - the state of the vault farm, if the vault has a farm. Optional. If not provided, it will be fetched
|
|
@@ -133,7 +134,7 @@ export declare class KaminoVaultClient {
|
|
|
133
134
|
* @param [vaultReservesMap] - optional parameter; a hashmap from each reserve pubkey to the reserve state. If provided the function will be significantly faster as it will not have to fetch the reserves
|
|
134
135
|
* @returns - an array of invest instructions for each invest action required for the vault reserves
|
|
135
136
|
*/
|
|
136
|
-
investSingleReserveIxs(payer: PublicKey, vault: KaminoVault, reserve: ReserveWithAddress, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve
|
|
137
|
+
investSingleReserveIxs(payer: PublicKey, vault: KaminoVault, reserve: ReserveWithAddress, vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>, createAtaIfNeeded?: boolean): Promise<TransactionInstruction[]>;
|
|
137
138
|
/** Convert a string to a u8 representation to be stored on chain */
|
|
138
139
|
encodeVaultName(token: string): Uint8Array;
|
|
139
140
|
/**Convert an u8 array to a string */
|
|
@@ -159,6 +160,11 @@ export declare class KaminoVaultClient {
|
|
|
159
160
|
* @returns - an array of instructions to insert the missing keys into the lookup table
|
|
160
161
|
*/
|
|
161
162
|
insertIntoLookupTableIxs(payer: PublicKey, lookupTable: PublicKey, keys: PublicKey[], accountsInLUT?: PublicKey[]): Promise<TransactionInstruction[]>;
|
|
163
|
+
/** Read the total holdings of a vault and the reserve weights and returns a map from each reserve to how many tokens should be deposited.
|
|
164
|
+
* @param vaultState - the vault state to calculate the allocation for
|
|
165
|
+
* @returns - a map from each reserve to how many tokens should be invested into
|
|
166
|
+
*/
|
|
167
|
+
getVaultComputedReservesAllocation(vaultState: VaultState): Promise<PubkeyHashMap<PublicKey, Decimal>>;
|
|
162
168
|
/**
|
|
163
169
|
* This method returns the user shares balance for a given vault
|
|
164
170
|
* @param user - user to calculate the shares balance for
|
|
@@ -211,9 +217,15 @@ export declare class KaminoVaultClient {
|
|
|
211
217
|
/**
|
|
212
218
|
* This will return the a map between reserve pubkey and the pct of the vault invested amount in each reserve
|
|
213
219
|
* @param vaultState - the kamino vault to get reserves distribution for
|
|
214
|
-
* @returns a
|
|
220
|
+
* @returns a map between reserve pubkey and the allocation pct for the reserve
|
|
215
221
|
*/
|
|
216
222
|
getAllocationsDistribuionPct(vaultState: VaultState): PubkeyHashMap<PublicKey, Decimal>;
|
|
223
|
+
/**
|
|
224
|
+
* This will return the a map between reserve pubkey and the allocation overview for the reserve
|
|
225
|
+
* @param vaultState - the kamino vault to get reserves allocation overview for
|
|
226
|
+
* @returns a map between reserve pubkey and the allocation overview for the reserve
|
|
227
|
+
*/
|
|
228
|
+
getVaultAllocations(vaultState: VaultState): PubkeyHashMap<PublicKey, ReserveAllocationOverview>;
|
|
217
229
|
/**
|
|
218
230
|
* This will return an unsorted hash map of all reserves that the given vault has allocations for, toghether with the amount that can be withdrawn from each of the reserves
|
|
219
231
|
* @param vault - the kamino vault to get available liquidity to withdraw for
|
|
@@ -344,18 +356,18 @@ export declare class KaminoVaultConfig {
|
|
|
344
356
|
readonly tokenMint: PublicKey;
|
|
345
357
|
/** The token mint program id */
|
|
346
358
|
readonly tokenMintProgramId: PublicKey;
|
|
347
|
-
/** The performance fee rate of the vault, expressed as a decimal */
|
|
348
|
-
readonly
|
|
349
|
-
/** The management fee rate of the vault, expressed as a decimal */
|
|
350
|
-
readonly
|
|
359
|
+
/** The performance fee rate of the vault, as percents, expressed as a decimal */
|
|
360
|
+
readonly performanceFeeRatePercentage: Decimal;
|
|
361
|
+
/** The management fee rate of the vault, as percents, expressed as a decimal */
|
|
362
|
+
readonly managementFeeRatePercentage: Decimal;
|
|
351
363
|
/** The name to be stored on cain for the vault (max 40 characters). */
|
|
352
364
|
readonly name: string;
|
|
353
365
|
constructor(args: {
|
|
354
366
|
admin: PublicKey;
|
|
355
367
|
tokenMint: PublicKey;
|
|
356
368
|
tokenMintProgramId: PublicKey;
|
|
357
|
-
|
|
358
|
-
|
|
369
|
+
performanceFeeRatePercentage: Decimal;
|
|
370
|
+
managementFeeRatePercentage: Decimal;
|
|
359
371
|
name: string;
|
|
360
372
|
});
|
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,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG;IACjD,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,SAAS,CAAC;IACnB,oBAAoB,EAAE,mBAAmB,EAAE,CAAC;IAC5C,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,SAAS,CAAC;IAChB,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,yBAAyB,CAAC;IACvC,gBAAgB,EAAE,aAAa,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;IAC5D,gBAAgB,EAAE,aAAa,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAC3D,oBAAoB,EAAE,OAAO,CAAC;IAC9B,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC"}
|
package/dist/classes/vault.js
CHANGED
|
@@ -129,7 +129,7 @@ class KaminoVaultClient {
|
|
|
129
129
|
];
|
|
130
130
|
const insertIntoLUTIxs = await this.insertIntoLookupTableIxs(vaultConfig.admin, lut, accountsToBeInserted, []);
|
|
131
131
|
const setLUTIx = this.updateUninitialisedVaultConfigIx(vaultConfig.admin, vaultState.publicKey, new types_1.VaultConfigField.LookupTable(), lut.toString());
|
|
132
|
-
const ixns = [createVaultIx, initVaultIx,
|
|
132
|
+
const ixns = [createVaultIx, initVaultIx, setLUTIx];
|
|
133
133
|
if (vaultConfig.getPerformanceFeeBps() > 0) {
|
|
134
134
|
const setPerformanceFeeIx = this.updateUninitialisedVaultConfigIx(vaultConfig.admin, vaultState.publicKey, new types_1.VaultConfigField.PerformanceFeeBps(), vaultConfig.getPerformanceFeeBps().toString());
|
|
135
135
|
ixns.push(setPerformanceFeeIx);
|
|
@@ -142,7 +142,7 @@ class KaminoVaultClient {
|
|
|
142
142
|
const setNameIx = this.updateUninitialisedVaultConfigIx(vaultConfig.admin, vaultState.publicKey, new types_1.VaultConfigField.Name(), vaultConfig.name);
|
|
143
143
|
ixns.push(setNameIx);
|
|
144
144
|
}
|
|
145
|
-
return { vault: vaultState, initVaultIxs: { initVaultIxs: ixns, populateLUTIxs: insertIntoLUTIxs } };
|
|
145
|
+
return { vault: vaultState, initVaultIxs: { initVaultIxs: ixns, createLUTIx, populateLUTIxs: insertIntoLUTIxs } };
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* This method updates the vault reserve allocation cofnig for an exiting vault reserve, or adds a new reserve to the vault if it does not exist.
|
|
@@ -163,7 +163,7 @@ class KaminoVaultClient {
|
|
|
163
163
|
ctokenVault: cTokenVault,
|
|
164
164
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
165
165
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
166
|
-
|
|
166
|
+
reserveCollateralTokenProgram: vaultState.tokenProgram,
|
|
167
167
|
};
|
|
168
168
|
const updateReserveAllocationArgs = {
|
|
169
169
|
weight: new anchor_1.BN(reserveAllocationConfig.targetAllocationWeight),
|
|
@@ -189,15 +189,19 @@ class KaminoVaultClient {
|
|
|
189
189
|
* @param vault the vault to update
|
|
190
190
|
* @param mode the field to update (based on VaultConfigFieldKind enum)
|
|
191
191
|
* @param value the value to update the field with
|
|
192
|
+
* @param [signer] the signer of the transaction. Optional. If not provided the admin of the vault will be used. It should be used when changing the admin of the vault if we want to batch multiple ixs in the same tx
|
|
192
193
|
* @returns a struct that contains the instruction to update the field and an optional list of instructions to update the lookup table
|
|
193
194
|
*/
|
|
194
|
-
async updateVaultConfigIxs(vault, mode, value) {
|
|
195
|
+
async updateVaultConfigIxs(vault, mode, value, signer) {
|
|
195
196
|
const vaultState = await vault.getState(this.getConnection());
|
|
196
197
|
const updateVaultConfigAccs = {
|
|
197
198
|
adminAuthority: vaultState.adminAuthority,
|
|
198
199
|
vaultState: vault.address,
|
|
199
200
|
klendProgram: this._kaminoLendProgramId,
|
|
200
201
|
};
|
|
202
|
+
if (signer) {
|
|
203
|
+
updateVaultConfigAccs.adminAuthority = signer;
|
|
204
|
+
}
|
|
201
205
|
const updateVaultConfigArgs = {
|
|
202
206
|
entry: mode,
|
|
203
207
|
data: Buffer.from([0]),
|
|
@@ -324,14 +328,14 @@ class KaminoVaultClient {
|
|
|
324
328
|
const accountsInExistentLUT = (await (0, lut_utils_1.getAccountsInLUT)(this.getConnection(), vaultState.vaultLookupTable)).filter((account) => !account.equals(vaultState.adminAuthority));
|
|
325
329
|
const LUTIxs = [];
|
|
326
330
|
const [initNewLUTIx, newLUT] = (0, lut_utils_1.initLookupTableIx)(vaultState.pendingAdmin, await this.getConnection().getSlot());
|
|
327
|
-
|
|
328
|
-
const insertIntoLUTIxs = await this.insertIntoLookupTableIxs(vaultState.pendingAdmin, newLUT, accountsInExistentLUT);
|
|
331
|
+
const insertIntoLUTIxs = await this.insertIntoLookupTableIxs(vaultState.pendingAdmin, newLUT, accountsInExistentLUT, []);
|
|
329
332
|
LUTIxs.push(...insertIntoLUTIxs);
|
|
330
|
-
const updateVaultConfigIxs = await this.updateVaultConfigIxs(vault, new types_1.VaultConfigField.LookupTable(), newLUT.toString());
|
|
333
|
+
const updateVaultConfigIxs = await this.updateVaultConfigIxs(vault, new types_1.VaultConfigField.LookupTable(), newLUT.toString(), vaultState.pendingAdmin);
|
|
331
334
|
LUTIxs.push(updateVaultConfigIxs.updateVaultConfigIx);
|
|
332
335
|
LUTIxs.push(...updateVaultConfigIxs.updateLUTIxs);
|
|
333
336
|
const acceptVaultOwnershipIxs = {
|
|
334
337
|
acceptVaultOwnershipIx,
|
|
338
|
+
initNewLUTIx,
|
|
335
339
|
updateLUTIxs: LUTIxs,
|
|
336
340
|
};
|
|
337
341
|
return acceptVaultOwnershipIxs;
|
|
@@ -453,7 +457,6 @@ class KaminoVaultClient {
|
|
|
453
457
|
userTokenAta: userTokenAta,
|
|
454
458
|
userSharesAta: userSharesAta,
|
|
455
459
|
tokenProgram: tokenProgramID,
|
|
456
|
-
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
457
460
|
klendProgram: this._kaminoLendProgramId,
|
|
458
461
|
sharesTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
459
462
|
};
|
|
@@ -517,7 +520,7 @@ class KaminoVaultClient {
|
|
|
517
520
|
* This function will return a struct with the instructions to unstake from the farm if necessary and the instructions for the missing ATA creation instructions, as well as one or multiple withdraw instructions, based on how many reserves it's needed to withdraw from. This might have to be split in multiple transactions
|
|
518
521
|
* @param user - user to withdraw
|
|
519
522
|
* @param vault - vault to withdraw from
|
|
520
|
-
* @param shareAmount - share amount to withdraw, in order to withdraw everything, any value > user share amount
|
|
523
|
+
* @param shareAmount - share amount to withdraw (in tokens, not lamports), in order to withdraw everything, any value > user share amount
|
|
521
524
|
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
|
|
522
525
|
* @param [vaultReservesMap] - optional parameter; a hashmap from each reserve pubkey to the reserve state. If provided the function will be significantly faster as it will not have to fetch the reserves
|
|
523
526
|
* @param [farmState] - the state of the vault farm, if the vault has a farm. Optional. If not provided, it will be fetched
|
|
@@ -538,7 +541,7 @@ class KaminoVaultClient {
|
|
|
538
541
|
withdrawIxs.unstakeFromFarmIfNeededIxs.push(unstakeAndWithdrawFromFarmIxs.withdrawIx);
|
|
539
542
|
}
|
|
540
543
|
// if the vault has allocations withdraw otherwise wtihdraw from available ix
|
|
541
|
-
const vaultAllocation = vaultState.vaultAllocationStrategy.find((allocation) => allocation.reserve.equals(web3_js_1.PublicKey.default));
|
|
544
|
+
const vaultAllocation = vaultState.vaultAllocationStrategy.find((allocation) => !allocation.reserve.equals(web3_js_1.PublicKey.default));
|
|
542
545
|
if (vaultAllocation) {
|
|
543
546
|
const withdrawFromVaultIxs = await this.wihdrdrawWithReserveIxns(user, kaminoVault, shareAmount, slot, vaultReservesMap);
|
|
544
547
|
withdrawIxs.withdrawIxs = withdrawFromVaultIxs;
|
|
@@ -630,7 +633,6 @@ class KaminoVaultClient {
|
|
|
630
633
|
}
|
|
631
634
|
return withdrawIxns;
|
|
632
635
|
}
|
|
633
|
-
// todo: make sure we also check the ata of the investor for the vault token exists
|
|
634
636
|
/**
|
|
635
637
|
* This will trigger invest by balancing, based on weights, the reserve allocations of the vault. It can either withdraw or deposit into reserves to balance them. This is a function that should be cranked
|
|
636
638
|
* @param payer wallet that pays the tx
|
|
@@ -638,19 +640,62 @@ class KaminoVaultClient {
|
|
|
638
640
|
* @returns - an array of invest instructions for each invest action required for the vault reserves
|
|
639
641
|
*/
|
|
640
642
|
async investAllReservesIxs(payer, vault) {
|
|
641
|
-
//TODO: Order invest ixns by - invest that removes first, then invest that adds
|
|
642
643
|
const vaultState = await vault.getState(this.getConnection());
|
|
643
|
-
const
|
|
644
|
+
const allReserves = this.getAllVaultReserves(vaultState);
|
|
645
|
+
if (allReserves.length === 0) {
|
|
646
|
+
throw new Error('No reserves found for the vault, please select at least one reserve for the vault');
|
|
647
|
+
}
|
|
648
|
+
const [allReservesStateMap, computedReservesAllocation] = await Promise.all([
|
|
649
|
+
this.loadVaultReserves(vaultState),
|
|
650
|
+
this.getVaultComputedReservesAllocation(vaultState),
|
|
651
|
+
]);
|
|
652
|
+
const tokenProgram = await (0, rpc_1.getAccountOwner)(this.getConnection(), vaultState.tokenMint);
|
|
653
|
+
const [{ ata: _payerTokenAta, createAtaIx }] = (0, utils_2.createAtasIdempotent)(payer, [
|
|
654
|
+
{ mint: vaultState.tokenMint, tokenProgram },
|
|
655
|
+
]);
|
|
656
|
+
// compute total vault holdings and expected distribution based on weights
|
|
657
|
+
const curentVaultAllocations = this.getVaultAllocations(vaultState);
|
|
658
|
+
const reservesToDisinvestFrom = [];
|
|
659
|
+
for (let index = 0; index < allReserves.length; index++) {
|
|
660
|
+
const reservePubkey = allReserves[index];
|
|
661
|
+
const reserveState = allReservesStateMap.get(reservePubkey);
|
|
662
|
+
const computedAllocation = computedReservesAllocation.get(reservePubkey);
|
|
663
|
+
const currentCTokenAllocation = curentVaultAllocations.get(reservePubkey).ctokenAllocation;
|
|
664
|
+
const reserveCollExchangeRate = reserveState.getCollateralExchangeRate();
|
|
665
|
+
const reserveAllocationLiquidityAmount = (0, lib_1.lamportsToDecimal)(currentCTokenAllocation.div(reserveCollExchangeRate), vaultState.tokenMintDecimals.toNumber());
|
|
666
|
+
if (computedAllocation.lt(reserveAllocationLiquidityAmount)) {
|
|
667
|
+
reservesToDisinvestFrom.push(reservePubkey);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
644
670
|
const investIxnsPromises = [];
|
|
645
|
-
|
|
646
|
-
|
|
671
|
+
// invest first the reserves from which we disinvest, then the other ones
|
|
672
|
+
for (const reserve of reservesToDisinvestFrom) {
|
|
673
|
+
const reserveState = allReservesStateMap.get(reserve);
|
|
647
674
|
if (reserveState === null) {
|
|
648
675
|
throw new Error(`Reserve ${reserve.toBase58()} not found`);
|
|
649
676
|
}
|
|
650
|
-
const investIxsPromise = this.investSingleReserveIxs(payer, vault, {
|
|
677
|
+
const investIxsPromise = this.investSingleReserveIxs(payer, vault, {
|
|
678
|
+
address: reserve,
|
|
679
|
+
state: reserveState.state,
|
|
680
|
+
}, allReservesStateMap, false);
|
|
651
681
|
investIxnsPromises.push(investIxsPromise);
|
|
652
682
|
}
|
|
653
|
-
const
|
|
683
|
+
for (const reserve of allReserves) {
|
|
684
|
+
if (!reservesToDisinvestFrom.includes(reserve)) {
|
|
685
|
+
const reserveState = allReservesStateMap.get(reserve);
|
|
686
|
+
if (reserveState === null) {
|
|
687
|
+
throw new Error(`Reserve ${reserve.toBase58()} not found`);
|
|
688
|
+
}
|
|
689
|
+
const investIxsPromise = this.investSingleReserveIxs(payer, vault, {
|
|
690
|
+
address: reserve,
|
|
691
|
+
state: reserveState.state,
|
|
692
|
+
}, allReservesStateMap, false);
|
|
693
|
+
investIxnsPromises.push(investIxsPromise);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
let investIxns = [];
|
|
697
|
+
investIxns.push(createAtaIx);
|
|
698
|
+
investIxns = await Promise.all(investIxnsPromises).then((ixns) => ixns.flat());
|
|
654
699
|
return investIxns;
|
|
655
700
|
}
|
|
656
701
|
// todo: make sure we also check the ata of the investor for the vault token exists
|
|
@@ -662,14 +707,19 @@ class KaminoVaultClient {
|
|
|
662
707
|
* @param [vaultReservesMap] - optional parameter; a hashmap from each reserve pubkey to the reserve state. If provided the function will be significantly faster as it will not have to fetch the reserves
|
|
663
708
|
* @returns - an array of invest instructions for each invest action required for the vault reserves
|
|
664
709
|
*/
|
|
665
|
-
async investSingleReserveIxs(payer, vault, reserve, vaultReservesMap) {
|
|
710
|
+
async investSingleReserveIxs(payer, vault, reserve, vaultReservesMap, createAtaIfNeeded = true) {
|
|
711
|
+
console.log('create invest ix for reserve', reserve.address.toBase58());
|
|
666
712
|
const vaultState = await vault.getState(this.getConnection());
|
|
667
713
|
const cTokenVault = getCTokenVaultPda(vault.address, reserve.address, this._kaminoVaultProgramId);
|
|
668
714
|
const lendingMarketAuth = (0, utils_2.lendingMarketAuthPda)(reserve.state.lendingMarket, this._kaminoLendProgramId)[0];
|
|
715
|
+
const ixs = [];
|
|
669
716
|
const tokenProgram = await (0, rpc_1.getAccountOwner)(this.getConnection(), vaultState.tokenMint);
|
|
670
717
|
const [{ ata: payerTokenAta, createAtaIx }] = (0, utils_2.createAtasIdempotent)(payer, [
|
|
671
718
|
{ mint: vaultState.tokenMint, tokenProgram },
|
|
672
719
|
]);
|
|
720
|
+
if (createAtaIfNeeded) {
|
|
721
|
+
ixs.push(createAtaIx);
|
|
722
|
+
}
|
|
673
723
|
const investAccounts = {
|
|
674
724
|
payer,
|
|
675
725
|
vaultState: vault.address,
|
|
@@ -949,6 +999,45 @@ class KaminoVaultClient {
|
|
|
949
999
|
}
|
|
950
1000
|
return ixns;
|
|
951
1001
|
}
|
|
1002
|
+
/** Read the total holdings of a vault and the reserve weights and returns a map from each reserve to how many tokens should be deposited.
|
|
1003
|
+
* @param vaultState - the vault state to calculate the allocation for
|
|
1004
|
+
* @returns - a map from each reserve to how many tokens should be invested into
|
|
1005
|
+
*/
|
|
1006
|
+
async getVaultComputedReservesAllocation(vaultState) {
|
|
1007
|
+
const holdings = await this.getVaultHoldings(vaultState);
|
|
1008
|
+
const initialVaultAllocations = this.getVaultAllocations(vaultState);
|
|
1009
|
+
const allReserves = this.getAllVaultReserves(vaultState);
|
|
1010
|
+
let totalAllocation = new decimal_js_1.default(0);
|
|
1011
|
+
initialVaultAllocations.forEach((allocation) => {
|
|
1012
|
+
totalAllocation = totalAllocation.add(allocation.targetWeight);
|
|
1013
|
+
});
|
|
1014
|
+
const expectedHoldingsDistribution = new lib_1.PubkeyHashMap();
|
|
1015
|
+
let totalLeftToInvest = holdings.total;
|
|
1016
|
+
let currentAllocationSum = totalAllocation;
|
|
1017
|
+
const ZERO = new decimal_js_1.default(0);
|
|
1018
|
+
while (totalLeftToInvest.gt(ZERO)) {
|
|
1019
|
+
const totalLeftover = totalLeftToInvest;
|
|
1020
|
+
for (const reserve of allReserves) {
|
|
1021
|
+
const reserveWithWeight = initialVaultAllocations.get(reserve);
|
|
1022
|
+
const targetAllocation = reserveWithWeight.targetWeight.mul(totalLeftover).div(currentAllocationSum);
|
|
1023
|
+
const reserveCap = reserveWithWeight.tokenAllocationCap;
|
|
1024
|
+
// todo: check if both target and reserveCap
|
|
1025
|
+
const amountToInvest = decimal_js_1.default.min(targetAllocation, reserveCap, totalLeftToInvest);
|
|
1026
|
+
totalLeftToInvest = totalLeftToInvest.sub(amountToInvest);
|
|
1027
|
+
if (amountToInvest.eq(reserveCap)) {
|
|
1028
|
+
currentAllocationSum = currentAllocationSum.sub(reserveWithWeight.targetWeight);
|
|
1029
|
+
}
|
|
1030
|
+
const reserveHasPreallocation = expectedHoldingsDistribution.has(reserve);
|
|
1031
|
+
if (reserveHasPreallocation) {
|
|
1032
|
+
expectedHoldingsDistribution.set(reserve, expectedHoldingsDistribution.get(reserve).add(amountToInvest));
|
|
1033
|
+
}
|
|
1034
|
+
else {
|
|
1035
|
+
expectedHoldingsDistribution.set(reserve, amountToInvest);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
return expectedHoldingsDistribution;
|
|
1040
|
+
}
|
|
952
1041
|
/**
|
|
953
1042
|
* This method returns the user shares balance for a given vault
|
|
954
1043
|
* @param user - user to calculate the shares balance for
|
|
@@ -1134,13 +1223,12 @@ class KaminoVaultClient {
|
|
|
1134
1223
|
/**
|
|
1135
1224
|
* This will return the a map between reserve pubkey and the pct of the vault invested amount in each reserve
|
|
1136
1225
|
* @param vaultState - the kamino vault to get reserves distribution for
|
|
1137
|
-
* @returns a
|
|
1226
|
+
* @returns a map between reserve pubkey and the allocation pct for the reserve
|
|
1138
1227
|
*/
|
|
1139
1228
|
getAllocationsDistribuionPct(vaultState) {
|
|
1140
1229
|
const allocationsDistributionPct = new lib_1.PubkeyHashMap();
|
|
1141
1230
|
let totalAllocation = new decimal_js_1.default(0);
|
|
1142
1231
|
const filteredAllocations = vaultState.vaultAllocationStrategy.filter((allocation) => !allocation.reserve.equals(web3_js_1.PublicKey.default));
|
|
1143
|
-
console.log('filteredAllocations length', filteredAllocations.length);
|
|
1144
1232
|
filteredAllocations.forEach((allocation) => {
|
|
1145
1233
|
totalAllocation = totalAllocation.add(new decimal_js_1.default(allocation.targetAllocationWeight.toString()));
|
|
1146
1234
|
});
|
|
@@ -1149,6 +1237,26 @@ class KaminoVaultClient {
|
|
|
1149
1237
|
});
|
|
1150
1238
|
return allocationsDistributionPct;
|
|
1151
1239
|
}
|
|
1240
|
+
/**
|
|
1241
|
+
* This will return the a map between reserve pubkey and the allocation overview for the reserve
|
|
1242
|
+
* @param vaultState - the kamino vault to get reserves allocation overview for
|
|
1243
|
+
* @returns a map between reserve pubkey and the allocation overview for the reserve
|
|
1244
|
+
*/
|
|
1245
|
+
getVaultAllocations(vaultState) {
|
|
1246
|
+
const vaultAllocations = new lib_1.PubkeyHashMap();
|
|
1247
|
+
vaultState.vaultAllocationStrategy.map((allocation) => {
|
|
1248
|
+
if (allocation.reserve.equals(web3_js_1.PublicKey.default)) {
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
const allocationOverview = {
|
|
1252
|
+
targetWeight: new decimal_js_1.default(allocation.targetAllocationWeight.toString()),
|
|
1253
|
+
tokenAllocationCap: new decimal_js_1.default(allocation.tokenAllocationCap.toString()),
|
|
1254
|
+
ctokenAllocation: new decimal_js_1.default(allocation.ctokenAllocation.toString()),
|
|
1255
|
+
};
|
|
1256
|
+
vaultAllocations.set(allocation.reserve, allocationOverview);
|
|
1257
|
+
});
|
|
1258
|
+
return vaultAllocations;
|
|
1259
|
+
}
|
|
1152
1260
|
/**
|
|
1153
1261
|
* This will return an unsorted hash map of all reserves that the given vault has allocations for, toghether with the amount that can be withdrawn from each of the reserves
|
|
1154
1262
|
* @param vault - the kamino vault to get available liquidity to withdraw for
|
|
@@ -1189,7 +1297,11 @@ class KaminoVaultClient {
|
|
|
1189
1297
|
* @returns a hashmap from each reserve pubkey to the reserve state
|
|
1190
1298
|
*/
|
|
1191
1299
|
getAllVaultReserves(vault) {
|
|
1192
|
-
return vault.vaultAllocationStrategy
|
|
1300
|
+
return vault.vaultAllocationStrategy
|
|
1301
|
+
.map((vaultAllocation) => vaultAllocation.reserve)
|
|
1302
|
+
.filter((reserve) => {
|
|
1303
|
+
return !reserve.equals(web3_js_1.PublicKey.default);
|
|
1304
|
+
});
|
|
1193
1305
|
}
|
|
1194
1306
|
/**
|
|
1195
1307
|
* This will get the list of all reserve pubkeys that the vault has allocations for ex
|
|
@@ -1595,25 +1707,25 @@ class KaminoVaultConfig {
|
|
|
1595
1707
|
tokenMint;
|
|
1596
1708
|
/** The token mint program id */
|
|
1597
1709
|
tokenMintProgramId;
|
|
1598
|
-
/** The performance fee rate of the vault, expressed as a decimal */
|
|
1599
|
-
|
|
1600
|
-
/** The management fee rate of the vault, expressed as a decimal */
|
|
1601
|
-
|
|
1710
|
+
/** The performance fee rate of the vault, as percents, expressed as a decimal */
|
|
1711
|
+
performanceFeeRatePercentage;
|
|
1712
|
+
/** The management fee rate of the vault, as percents, expressed as a decimal */
|
|
1713
|
+
managementFeeRatePercentage;
|
|
1602
1714
|
/** The name to be stored on cain for the vault (max 40 characters). */
|
|
1603
1715
|
name;
|
|
1604
1716
|
constructor(args) {
|
|
1605
1717
|
this.admin = args.admin;
|
|
1606
1718
|
this.tokenMint = args.tokenMint;
|
|
1607
|
-
this.
|
|
1608
|
-
this.
|
|
1719
|
+
this.performanceFeeRatePercentage = args.performanceFeeRatePercentage;
|
|
1720
|
+
this.managementFeeRatePercentage = args.managementFeeRatePercentage;
|
|
1609
1721
|
this.tokenMintProgramId = args.tokenMintProgramId;
|
|
1610
1722
|
this.name = args.name;
|
|
1611
1723
|
}
|
|
1612
1724
|
getPerformanceFeeBps() {
|
|
1613
|
-
return this.
|
|
1725
|
+
return this.performanceFeeRatePercentage.mul(100).toNumber();
|
|
1614
1726
|
}
|
|
1615
1727
|
getManagementFeeBps() {
|
|
1616
|
-
return this.
|
|
1728
|
+
return this.managementFeeRatePercentage.mul(100).toNumber();
|
|
1617
1729
|
}
|
|
1618
1730
|
}
|
|
1619
1731
|
exports.KaminoVaultConfig = KaminoVaultConfig;
|