@kamino-finance/klend-sdk 5.13.1 → 5.13.4
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/dist/classes/action.d.ts +32 -31
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +126 -95
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/index.d.ts +3 -2
- package/dist/classes/index.d.ts.map +1 -1
- package/dist/classes/index.js +3 -2
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/manager.d.ts +15 -7
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +57 -46
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligationOrder.d.ts +1 -1
- package/dist/classes/obligationOrder.d.ts.map +1 -1
- package/dist/classes/reserve.d.ts +2 -2
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +70 -70
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +13 -0
- package/dist/classes/shared.d.ts.map +1 -1
- package/dist/classes/utils.d.ts +1 -9
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +4 -51
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +22 -4
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +78 -43
- package/dist/classes/vault.js.map +1 -1
- package/dist/classes/{types.d.ts → vault_types.d.ts} +3 -15
- package/dist/classes/vault_types.d.ts.map +1 -0
- package/dist/classes/{types.js → vault_types.js} +1 -1
- package/dist/classes/vault_types.js.map +1 -0
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +44 -28
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +6 -6
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +6 -6
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +61 -61
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +0 -1
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +5 -8
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/operations.d.ts +5 -5
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +73 -73
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +1 -1
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/leverage/utils.d.ts +2 -2
- package/dist/leverage/utils.d.ts.map +1 -1
- package/dist/leverage/utils.js +5 -5
- package/dist/leverage/utils.js.map +1 -1
- package/dist/referrals/instructions.d.ts +3 -3
- package/dist/referrals/instructions.d.ts.map +1 -1
- package/dist/referrals/instructions.js +10 -10
- package/dist/referrals/instructions.js.map +1 -1
- package/dist/referrals/operations.js +6 -6
- package/dist/referrals/operations.js.map +1 -1
- package/dist/utils/ata.d.ts +3 -3
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +22 -22
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/instruction.d.ts +2 -2
- package/dist/utils/instruction.d.ts.map +1 -1
- package/dist/utils/instruction.js +12 -12
- package/dist/utils/instruction.js.map +1 -1
- package/dist/utils/lookupTable.js +6 -6
- package/dist/utils/lookupTable.js.map +1 -1
- package/dist/utils/metadata.d.ts +14 -0
- package/dist/utils/metadata.d.ts.map +1 -0
- package/dist/utils/metadata.js +78 -0
- package/dist/utils/metadata.js.map +1 -0
- package/dist/utils/seeds.d.ts +6 -0
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +10 -0
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/userMetadata.d.ts +1 -1
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +3 -3
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/action.ts +143 -102
- package/src/classes/index.ts +5 -2
- package/src/classes/manager.ts +74 -51
- package/src/classes/obligationOrder.ts +1 -1
- package/src/classes/reserve.ts +126 -132
- package/src/classes/shared.ts +15 -0
- package/src/classes/utils.ts +3 -52
- package/src/classes/vault.ts +125 -44
- package/src/classes/{types.ts → vault_types.ts} +2 -16
- package/src/client.ts +16 -16
- package/src/client_kamino_manager.ts +59 -27
- package/src/lending_operations/repay_with_collateral_operations.ts +13 -13
- package/src/lending_operations/swap_collateral_operations.ts +85 -85
- package/src/leverage/calcs.ts +2 -6
- package/src/leverage/operations.ts +84 -84
- package/src/leverage/types.ts +1 -1
- package/src/leverage/utils.ts +5 -5
- package/src/referrals/instructions.ts +6 -6
- package/src/referrals/operations.ts +9 -9
- package/src/utils/ata.ts +18 -18
- package/src/utils/instruction.ts +10 -10
- package/src/utils/lookupTable.ts +6 -6
- package/src/utils/metadata.ts +115 -0
- package/src/utils/seeds.ts +13 -0
- package/src/utils/userMetadata.ts +1 -1
- package/dist/classes/types.d.ts.map +0 -1
- package/dist/classes/types.js.map +0 -1
- package/dist/classes/types_utils.d.ts +0 -14
- package/dist/classes/types_utils.d.ts.map +0 -1
- package/dist/classes/types_utils.js +0 -50
- package/dist/classes/types_utils.js.map +0 -1
- package/src/classes/types_utils.ts +0 -49
package/src/classes/utils.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { PubkeyHashMap, SLOTS_PER_SECOND, SLOTS_PER_YEAR } from '../utils';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
3
|
import { AccountInfo, PublicKey } from '@solana/web3.js';
|
|
4
|
-
import { MarketOverview, ReserveOverview } from '../lib';
|
|
5
4
|
import { AccountLayout, NATIVE_MINT } from '@solana/spl-token';
|
|
6
|
-
import { ReserveAllocationOverview } from './types';
|
|
7
5
|
import axios from 'axios';
|
|
8
6
|
|
|
9
7
|
type ObligationFarmScoreType = {
|
|
@@ -276,56 +274,9 @@ export function pubkeyHashMapToJson(map: PubkeyHashMap<PublicKey, any>): { [key:
|
|
|
276
274
|
return obj;
|
|
277
275
|
}
|
|
278
276
|
|
|
279
|
-
export function
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
export function printReservesOverviewMap(map: PubkeyHashMap<PublicKey, ReserveOverview>) {
|
|
284
|
-
map.forEach((value, key) => {
|
|
285
|
-
console.log('Reserve:', key.toString());
|
|
286
|
-
printReserveOverview(value);
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
export function printReserveOverview(reserveOverview: ReserveOverview) {
|
|
291
|
-
console.log('Total borrowed from reserve:', reserveOverview.totalBorrowedAmount.toString());
|
|
292
|
-
console.log('Borrowed from the supplied amount:', reserveOverview.amountBorrowedFromSupplied.toString());
|
|
293
|
-
console.log('Supplied:', reserveOverview.suppliedAmount.toString());
|
|
294
|
-
console.log('Utilization ratio:', reserveOverview.utilizationRatio.toString());
|
|
295
|
-
console.log('Liquidation Threshold Pct:', reserveOverview.liquidationThresholdPct.toString());
|
|
296
|
-
console.log('Supply APY:', reserveOverview.supplyAPY.toString());
|
|
297
|
-
console.log('Lending market:', reserveOverview.market.toString());
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
export function printMarketsOverviewMap(map: PubkeyHashMap<PublicKey, MarketOverview>) {
|
|
301
|
-
map.forEach((value, key) => {
|
|
302
|
-
console.log('Reserve:', key.toString());
|
|
303
|
-
printMarketOverview(value);
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export function printMarketOverview(marketOverview: MarketOverview) {
|
|
308
|
-
console.log('Market overview:');
|
|
309
|
-
console.log(' Address:', marketOverview.address.toString());
|
|
310
|
-
console.log(' Min LTV percentage:', marketOverview.minLTVPct.toString());
|
|
311
|
-
console.log(' Max LTV percentage:', marketOverview.maxLTVPct.toString());
|
|
312
|
-
marketOverview.reservesAsCollateral.forEach((reserve, _) => {
|
|
313
|
-
console.log(' Liquidation LTV percentage:', reserve.liquidationLTVPct.toString());
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
export function printReservesAllocationOverviewMap(map: PubkeyHashMap<PublicKey, ReserveAllocationOverview>) {
|
|
318
|
-
map.forEach((value, key) => {
|
|
319
|
-
console.log('Reserve:', key.toString());
|
|
320
|
-
printReserveAllocationOverview(value);
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
export function printReserveAllocationOverview(reserveAllocationOverview: ReserveAllocationOverview) {
|
|
325
|
-
console.log('Reserve allocation overview:');
|
|
326
|
-
console.log(' Target weight:', reserveAllocationOverview.targetWeight.toString());
|
|
327
|
-
console.log(' Token allocation cap:', reserveAllocationOverview.tokenAllocationCap.toString());
|
|
328
|
-
console.log(' Ctoken allocation:', reserveAllocationOverview.ctokenAllocation.toString());
|
|
277
|
+
export function toJson(object: any, inline: boolean = false): string {
|
|
278
|
+
const replacer = (key: any, value: any) => (typeof value === 'bigint' ? value.toString() : value);
|
|
279
|
+
return inline ? JSON.stringify(object, replacer) : JSON.stringify(object, replacer, 2);
|
|
329
280
|
}
|
|
330
281
|
|
|
331
282
|
export function assertNever(x: never): never {
|
package/src/classes/vault.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
import { getAssociatedTokenAddressSync, NATIVE_MINT, TOKEN_PROGRAM_ID, unpackAccount } from '@solana/spl-token';
|
|
15
15
|
import {
|
|
16
16
|
getAssociatedTokenAddress,
|
|
17
|
-
|
|
17
|
+
getTransferWsolIxs,
|
|
18
18
|
getTokenOracleData,
|
|
19
19
|
KaminoMarket,
|
|
20
20
|
KaminoReserve,
|
|
@@ -60,6 +60,7 @@ import {
|
|
|
60
60
|
getTokenBalanceFromAccountInfoLamports,
|
|
61
61
|
numberToLamportsDecimal,
|
|
62
62
|
parseTokenSymbol,
|
|
63
|
+
pubkeyHashMapToJson,
|
|
63
64
|
} from './utils';
|
|
64
65
|
import { deposit } from '../idl_codegen_kamino_vault/instructions';
|
|
65
66
|
import { withdraw } from '../idl_codegen_kamino_vault/instructions';
|
|
@@ -69,6 +70,7 @@ import { Fraction } from './fraction';
|
|
|
69
70
|
import {
|
|
70
71
|
createAtasIdempotent,
|
|
71
72
|
createWsolAtaIfMissing,
|
|
73
|
+
getKVaultSharesMetadataPda,
|
|
72
74
|
lendingMarketAuthPda,
|
|
73
75
|
PublicKeySet,
|
|
74
76
|
SECONDS_PER_YEAR,
|
|
@@ -88,7 +90,7 @@ import {
|
|
|
88
90
|
UpdateVaultConfigIxs,
|
|
89
91
|
UserSharesForVault,
|
|
90
92
|
WithdrawIxs,
|
|
91
|
-
} from './
|
|
93
|
+
} from './vault_types';
|
|
92
94
|
import { batchFetch, collToLamportsDecimal, ZERO } from '@kamino-finance/kliquidity-sdk';
|
|
93
95
|
import { FullBPSDecimal } from '@kamino-finance/kliquidity-sdk/dist/utils/CreationParameters';
|
|
94
96
|
import { FarmState } from '@kamino-finance/farms-sdk/dist';
|
|
@@ -100,7 +102,7 @@ import {
|
|
|
100
102
|
getSharesInFarmUserPosition,
|
|
101
103
|
getUserSharesInFarm,
|
|
102
104
|
} from './farm_utils';
|
|
103
|
-
import {
|
|
105
|
+
import { getInitializeKVaultSharesMetadataIx, getUpdateSharesMetadataIx, resolveMetadata } from '../utils/metadata';
|
|
104
106
|
|
|
105
107
|
export const kaminoVaultId = new PublicKey('KvauGMspG5k6rtzrqqn7WNn3oZdyKqLKwK2XWQ8FLjd');
|
|
106
108
|
export const kaminoVaultStagingId = new PublicKey('stKvQfwRsQiKnLtMNVLHKS3exFJmZFsgfzBPWHECUYK');
|
|
@@ -110,6 +112,10 @@ const CTOKEN_VAULT_SEED = 'ctoken_vault';
|
|
|
110
112
|
const BASE_VAULT_AUTHORITY_SEED = 'authority';
|
|
111
113
|
const SHARES_SEED = 'shares';
|
|
112
114
|
const EVENT_AUTHORITY_SEED = '__event_authority';
|
|
115
|
+
export const METADATA_SEED = 'metadata';
|
|
116
|
+
|
|
117
|
+
export const METADATA_PROGRAM_ID: PublicKey = new PublicKey('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s');
|
|
118
|
+
|
|
113
119
|
export const INITIAL_DEPOSIT_LAMPORTS = 1000;
|
|
114
120
|
|
|
115
121
|
/**
|
|
@@ -270,7 +276,7 @@ export class KaminoVaultClient {
|
|
|
270
276
|
lut.toString()
|
|
271
277
|
);
|
|
272
278
|
|
|
273
|
-
const
|
|
279
|
+
const ixs = [createVaultIx, initVaultIx, setLUTIx];
|
|
274
280
|
|
|
275
281
|
if (vaultConfig.getPerformanceFeeBps() > 0) {
|
|
276
282
|
const setPerformanceFeeIx = this.updateUninitialisedVaultConfigIx(
|
|
@@ -279,7 +285,7 @@ export class KaminoVaultClient {
|
|
|
279
285
|
new VaultConfigField.PerformanceFeeBps(),
|
|
280
286
|
vaultConfig.getPerformanceFeeBps().toString()
|
|
281
287
|
);
|
|
282
|
-
|
|
288
|
+
ixs.push(setPerformanceFeeIx);
|
|
283
289
|
}
|
|
284
290
|
if (vaultConfig.getManagementFeeBps() > 0) {
|
|
285
291
|
const setManagementFeeIx = this.updateUninitialisedVaultConfigIx(
|
|
@@ -288,7 +294,7 @@ export class KaminoVaultClient {
|
|
|
288
294
|
new VaultConfigField.ManagementFeeBps(),
|
|
289
295
|
vaultConfig.getManagementFeeBps().toString()
|
|
290
296
|
);
|
|
291
|
-
|
|
297
|
+
ixs.push(setManagementFeeIx);
|
|
292
298
|
}
|
|
293
299
|
if (vaultConfig.name && vaultConfig.name.length > 0) {
|
|
294
300
|
const setNameIx = this.updateUninitialisedVaultConfigIx(
|
|
@@ -297,21 +303,78 @@ export class KaminoVaultClient {
|
|
|
297
303
|
new VaultConfigField.Name(),
|
|
298
304
|
vaultConfig.name
|
|
299
305
|
);
|
|
300
|
-
|
|
306
|
+
ixs.push(setNameIx);
|
|
301
307
|
}
|
|
302
308
|
|
|
309
|
+
const metadataIx = await this.getSetSharesMetadataIx(
|
|
310
|
+
this.getConnection(),
|
|
311
|
+
vaultConfig.admin,
|
|
312
|
+
vaultState.publicKey,
|
|
313
|
+
sharesMint,
|
|
314
|
+
baseVaultAuthority,
|
|
315
|
+
vaultConfig.vaultTokenSymbol,
|
|
316
|
+
vaultConfig.vaultTokenName
|
|
317
|
+
);
|
|
318
|
+
|
|
303
319
|
return {
|
|
304
320
|
vault: vaultState,
|
|
305
321
|
initVaultIxs: {
|
|
306
322
|
createAtaIfNeededIxs: prerequisiteIxs,
|
|
307
|
-
initVaultIxs:
|
|
323
|
+
initVaultIxs: ixs,
|
|
308
324
|
createLUTIx,
|
|
309
325
|
populateLUTIxs: insertIntoLUTIxs,
|
|
310
326
|
cleanupIxs,
|
|
327
|
+
initSharesMetadataIx: metadataIx,
|
|
311
328
|
},
|
|
312
329
|
};
|
|
313
330
|
}
|
|
314
331
|
|
|
332
|
+
/**
|
|
333
|
+
* This method creates an instruction to set the shares metadata for a vault
|
|
334
|
+
* @param vault - the vault to set the shares metadata for
|
|
335
|
+
* @param tokenName - the name of the token in the vault (symbol; e.g. "USDC" which becomes "kVUSDC")
|
|
336
|
+
* @param extraName - the extra string appended to the prefix("Kamino Vault USDC <extraName>")
|
|
337
|
+
* @returns - an instruction to set the shares metadata for the vault
|
|
338
|
+
*/
|
|
339
|
+
async getSetSharesMetadataIx(
|
|
340
|
+
connection: Connection,
|
|
341
|
+
vaultAdmin: PublicKey,
|
|
342
|
+
vault: PublicKey,
|
|
343
|
+
sharesMint: PublicKey,
|
|
344
|
+
baseVaultAuthority: PublicKey,
|
|
345
|
+
tokenName: string,
|
|
346
|
+
extraName: string
|
|
347
|
+
) {
|
|
348
|
+
const [sharesMintMetadata] = getKVaultSharesMetadataPda(sharesMint);
|
|
349
|
+
|
|
350
|
+
const { name, symbol, uri } = resolveMetadata(sharesMint, extraName, tokenName);
|
|
351
|
+
|
|
352
|
+
const ix =
|
|
353
|
+
(await connection.getAccountInfo(sharesMintMetadata)) === null
|
|
354
|
+
? await getInitializeKVaultSharesMetadataIx(
|
|
355
|
+
connection,
|
|
356
|
+
vaultAdmin,
|
|
357
|
+
vault,
|
|
358
|
+
sharesMint,
|
|
359
|
+
baseVaultAuthority,
|
|
360
|
+
name,
|
|
361
|
+
symbol,
|
|
362
|
+
uri
|
|
363
|
+
)
|
|
364
|
+
: await getUpdateSharesMetadataIx(
|
|
365
|
+
connection,
|
|
366
|
+
vaultAdmin,
|
|
367
|
+
vault,
|
|
368
|
+
sharesMint,
|
|
369
|
+
baseVaultAuthority,
|
|
370
|
+
name,
|
|
371
|
+
symbol,
|
|
372
|
+
uri
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
return ix;
|
|
376
|
+
}
|
|
377
|
+
|
|
315
378
|
/**
|
|
316
379
|
* 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.
|
|
317
380
|
* @param vault - vault to be updated
|
|
@@ -715,7 +778,7 @@ export class KaminoVaultClient {
|
|
|
715
778
|
reservesToWithdraw,
|
|
716
779
|
this._kaminoLendProgramId
|
|
717
780
|
);
|
|
718
|
-
const
|
|
781
|
+
const withdrawIxs: TransactionInstruction[] = await Promise.all(
|
|
719
782
|
reservesToWithdraw.map(async (reserve, index) => {
|
|
720
783
|
if (reserveStates[index] === null) {
|
|
721
784
|
throw new Error(`Reserve ${reserve.toBase58()} not found`);
|
|
@@ -734,7 +797,7 @@ export class KaminoVaultClient {
|
|
|
734
797
|
})
|
|
735
798
|
);
|
|
736
799
|
|
|
737
|
-
return [createAtaIx, ...
|
|
800
|
+
return [createAtaIx, ...withdrawIxs];
|
|
738
801
|
}
|
|
739
802
|
|
|
740
803
|
// async closeVaultIx(vault: KaminoVault): Promise<TransactionInstruction> {
|
|
@@ -768,8 +831,8 @@ export class KaminoVaultClient {
|
|
|
768
831
|
|
|
769
832
|
const tokenProgramID = vaultState.tokenProgram;
|
|
770
833
|
const userTokenAta = getAssociatedTokenAddress(vaultState.tokenMint, user, true, tokenProgramID);
|
|
771
|
-
const
|
|
772
|
-
const
|
|
834
|
+
const createAtasIxs: TransactionInstruction[] = [];
|
|
835
|
+
const closeAtasIxs: TransactionInstruction[] = [];
|
|
773
836
|
if (vaultState.tokenMint.equals(NATIVE_MINT)) {
|
|
774
837
|
const [{ ata: wsolAta, createAtaIx: createWsolAtaIxn }] = createAtasIdempotent(user, [
|
|
775
838
|
{
|
|
@@ -777,22 +840,22 @@ export class KaminoVaultClient {
|
|
|
777
840
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
778
841
|
},
|
|
779
842
|
]);
|
|
780
|
-
|
|
781
|
-
const
|
|
843
|
+
createAtasIxs.push(createWsolAtaIxn);
|
|
844
|
+
const transferWsolIxs = getTransferWsolIxs(
|
|
782
845
|
user,
|
|
783
846
|
wsolAta,
|
|
784
847
|
numberToLamportsDecimal(tokenAmount, vaultState.tokenMintDecimals.toNumber()).ceil()
|
|
785
848
|
);
|
|
786
|
-
|
|
849
|
+
createAtasIxs.push(...transferWsolIxs);
|
|
787
850
|
}
|
|
788
851
|
|
|
789
|
-
const [{ ata: userSharesAta, createAtaIx:
|
|
852
|
+
const [{ ata: userSharesAta, createAtaIx: createSharesAtaIxs }] = createAtasIdempotent(user, [
|
|
790
853
|
{
|
|
791
854
|
mint: vaultState.sharesMint,
|
|
792
855
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
793
856
|
},
|
|
794
857
|
]);
|
|
795
|
-
|
|
858
|
+
createAtasIxs.push(createSharesAtaIxs);
|
|
796
859
|
|
|
797
860
|
const eventAuthority = getEventAuthorityPda(this._kaminoVaultProgramId);
|
|
798
861
|
const depoistAccounts: DepositAccounts = {
|
|
@@ -839,7 +902,7 @@ export class KaminoVaultClient {
|
|
|
839
902
|
depositIx.keys = depositIx.keys.concat(vaultReservesLendingMarkets);
|
|
840
903
|
|
|
841
904
|
const depositIxs: DepositIxs = {
|
|
842
|
-
depositIxs: [...
|
|
905
|
+
depositIxs: [...createAtasIxs, depositIx, ...closeAtasIxs],
|
|
843
906
|
stakeInFarmIfNeededIxs: [],
|
|
844
907
|
};
|
|
845
908
|
|
|
@@ -930,7 +993,7 @@ export class KaminoVaultClient {
|
|
|
930
993
|
);
|
|
931
994
|
|
|
932
995
|
if (vaultAllocation) {
|
|
933
|
-
const withdrawFromVaultIxs = await this.
|
|
996
|
+
const withdrawFromVaultIxs = await this.wihdrdrawWithReserveIxs(
|
|
934
997
|
user,
|
|
935
998
|
kaminoVault,
|
|
936
999
|
shareAmount,
|
|
@@ -939,14 +1002,14 @@ export class KaminoVaultClient {
|
|
|
939
1002
|
);
|
|
940
1003
|
withdrawIxs.withdrawIxs = withdrawFromVaultIxs;
|
|
941
1004
|
} else {
|
|
942
|
-
const withdrawFromVaultIxs = await this.
|
|
1005
|
+
const withdrawFromVaultIxs = await this.withdrawFromAvailableIxs(user, kaminoVault, shareAmount);
|
|
943
1006
|
withdrawIxs.withdrawIxs = withdrawFromVaultIxs;
|
|
944
1007
|
}
|
|
945
1008
|
|
|
946
1009
|
return withdrawIxs;
|
|
947
1010
|
}
|
|
948
1011
|
|
|
949
|
-
private async
|
|
1012
|
+
private async withdrawFromAvailableIxs(
|
|
950
1013
|
user: PublicKey,
|
|
951
1014
|
vault: KaminoVault,
|
|
952
1015
|
shareAmount: Decimal
|
|
@@ -975,7 +1038,7 @@ export class KaminoVaultClient {
|
|
|
975
1038
|
return [createAtaIx, withdrawFromAvailableIxn];
|
|
976
1039
|
}
|
|
977
1040
|
|
|
978
|
-
private async
|
|
1041
|
+
private async wihdrdrawWithReserveIxs(
|
|
979
1042
|
user: PublicKey,
|
|
980
1043
|
vault: KaminoVault,
|
|
981
1044
|
shareAmount: Decimal,
|
|
@@ -1041,8 +1104,8 @@ export class KaminoVaultClient {
|
|
|
1041
1104
|
});
|
|
1042
1105
|
}
|
|
1043
1106
|
|
|
1044
|
-
const
|
|
1045
|
-
|
|
1107
|
+
const withdrawIxs: TransactionInstruction[] = [];
|
|
1108
|
+
withdrawIxs.push(createAtaIx);
|
|
1046
1109
|
|
|
1047
1110
|
for (let reserveIndex = 0; reserveIndex < reserveWithSharesAmountToWithdraw.length; reserveIndex++) {
|
|
1048
1111
|
const reserveWithTokens = reserveWithSharesAmountToWithdraw[reserveIndex];
|
|
@@ -1070,10 +1133,10 @@ export class KaminoVaultClient {
|
|
|
1070
1133
|
sharesToWithdraw,
|
|
1071
1134
|
vaultReservesState
|
|
1072
1135
|
);
|
|
1073
|
-
|
|
1136
|
+
withdrawIxs.push(withdrawFromReserveIx);
|
|
1074
1137
|
}
|
|
1075
1138
|
|
|
1076
|
-
return
|
|
1139
|
+
return withdrawIxs;
|
|
1077
1140
|
}
|
|
1078
1141
|
|
|
1079
1142
|
/**
|
|
@@ -1132,7 +1195,7 @@ export class KaminoVaultClient {
|
|
|
1132
1195
|
}
|
|
1133
1196
|
}
|
|
1134
1197
|
|
|
1135
|
-
const
|
|
1198
|
+
const investIxsPromises: Promise<TransactionInstruction[]>[] = [];
|
|
1136
1199
|
// invest first the reserves from which we disinvest, then the other ones
|
|
1137
1200
|
for (const reserve of reservesToDisinvestFrom) {
|
|
1138
1201
|
const reserveState = allReservesStateMap.get(reserve);
|
|
@@ -1149,7 +1212,7 @@ export class KaminoVaultClient {
|
|
|
1149
1212
|
allReservesStateMap,
|
|
1150
1213
|
false
|
|
1151
1214
|
);
|
|
1152
|
-
|
|
1215
|
+
investIxsPromises.push(investIxsPromise);
|
|
1153
1216
|
}
|
|
1154
1217
|
|
|
1155
1218
|
for (const reserve of reservesToInvestInto) {
|
|
@@ -1167,14 +1230,14 @@ export class KaminoVaultClient {
|
|
|
1167
1230
|
allReservesStateMap,
|
|
1168
1231
|
false
|
|
1169
1232
|
);
|
|
1170
|
-
|
|
1233
|
+
investIxsPromises.push(investIxsPromise);
|
|
1171
1234
|
}
|
|
1172
1235
|
|
|
1173
|
-
let
|
|
1174
|
-
|
|
1175
|
-
|
|
1236
|
+
let investIxs: TransactionInstruction[] = [];
|
|
1237
|
+
investIxs.push(createAtaIx);
|
|
1238
|
+
investIxs = await Promise.all(investIxsPromises).then((ixs) => ixs.flat());
|
|
1176
1239
|
|
|
1177
|
-
return
|
|
1240
|
+
return investIxs;
|
|
1178
1241
|
}
|
|
1179
1242
|
|
|
1180
1243
|
// todo: make sure we also check the ata of the investor for the vault token exists
|
|
@@ -1488,8 +1551,8 @@ export class KaminoVaultClient {
|
|
|
1488
1551
|
let lut = vaultState.vaultLookupTable;
|
|
1489
1552
|
if (lut.equals(PublicKey.default)) {
|
|
1490
1553
|
const recentSlot = await this.getConnection().getSlot();
|
|
1491
|
-
const [
|
|
1492
|
-
setupLUTIfNeededIxs.push(
|
|
1554
|
+
const [ix, address] = initLookupTableIx(vaultState.vaultAdminAuthority, recentSlot);
|
|
1555
|
+
setupLUTIfNeededIxs.push(ix);
|
|
1493
1556
|
lut = address;
|
|
1494
1557
|
|
|
1495
1558
|
// set the new LUT for the vault
|
|
@@ -1501,12 +1564,12 @@ export class KaminoVaultClient {
|
|
|
1501
1564
|
setupLUTIfNeededIxs.push(updateVaultConfigIxs.updateVaultConfigIx);
|
|
1502
1565
|
}
|
|
1503
1566
|
|
|
1504
|
-
const
|
|
1567
|
+
const ixs: TransactionInstruction[] = [];
|
|
1505
1568
|
let overridenExistentAccounts: PublicKey[] | undefined = undefined;
|
|
1506
1569
|
if (vaultState.vaultLookupTable.equals(PublicKey.default)) {
|
|
1507
1570
|
overridenExistentAccounts = [];
|
|
1508
1571
|
}
|
|
1509
|
-
|
|
1572
|
+
ixs.push(
|
|
1510
1573
|
...(await this.insertIntoLookupTableIxs(
|
|
1511
1574
|
vaultState.vaultAdminAuthority,
|
|
1512
1575
|
lut,
|
|
@@ -1517,7 +1580,7 @@ export class KaminoVaultClient {
|
|
|
1517
1580
|
|
|
1518
1581
|
return {
|
|
1519
1582
|
setupLUTIfNeededIxs,
|
|
1520
|
-
syncLUTIxs:
|
|
1583
|
+
syncLUTIxs: ixs,
|
|
1521
1584
|
};
|
|
1522
1585
|
}
|
|
1523
1586
|
|
|
@@ -1562,20 +1625,20 @@ export class KaminoVaultClient {
|
|
|
1562
1625
|
const missingAccountsList = new PublicKeySet(missingAccounts).toArray();
|
|
1563
1626
|
|
|
1564
1627
|
const chunkSize = 20;
|
|
1565
|
-
const
|
|
1628
|
+
const ixs: TransactionInstruction[] = [];
|
|
1566
1629
|
|
|
1567
1630
|
for (let i = 0; i < missingAccountsList.length; i += chunkSize) {
|
|
1568
1631
|
const chunk = missingAccountsList.slice(i, i + chunkSize);
|
|
1569
|
-
const
|
|
1632
|
+
const ix = AddressLookupTableProgram.extendLookupTable({
|
|
1570
1633
|
lookupTable,
|
|
1571
1634
|
authority: payer,
|
|
1572
1635
|
payer,
|
|
1573
1636
|
addresses: chunk,
|
|
1574
1637
|
});
|
|
1575
|
-
|
|
1638
|
+
ixs.push(ix);
|
|
1576
1639
|
}
|
|
1577
1640
|
|
|
1578
|
-
return
|
|
1641
|
+
return ixs;
|
|
1579
1642
|
}
|
|
1580
1643
|
|
|
1581
1644
|
/** 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.
|
|
@@ -2138,6 +2201,7 @@ export class KaminoVaultClient {
|
|
|
2138
2201
|
.map((filteredReserve) => {
|
|
2139
2202
|
const reserveAsCollateral: ReserveAsCollateral = {
|
|
2140
2203
|
mint: filteredReserve.getLiquidityMint(),
|
|
2204
|
+
address: filteredReserve.address,
|
|
2141
2205
|
liquidationLTVPct: new Decimal(filteredReserve.state.config.liquidationThresholdPct),
|
|
2142
2206
|
};
|
|
2143
2207
|
marketOverview.reservesAsCollateral.push(reserveAsCollateral);
|
|
@@ -2643,9 +2707,12 @@ export class KaminoVaultConfig {
|
|
|
2643
2707
|
readonly performanceFeeRatePercentage: Decimal;
|
|
2644
2708
|
/** The management fee rate of the vault, as percents, expressed as a decimal */
|
|
2645
2709
|
readonly managementFeeRatePercentage: Decimal;
|
|
2646
|
-
/** The name to be stored on
|
|
2710
|
+
/** The name to be stored on chain for the vault (max 40 characters). */
|
|
2647
2711
|
readonly name: string;
|
|
2648
|
-
|
|
2712
|
+
/** The symbol of the vault token to be stored (max 5 characters). E.g. USDC for a vault using USDC as token. */
|
|
2713
|
+
readonly vaultTokenSymbol: string;
|
|
2714
|
+
/** The name of the vault token to be stored (max 10 characters), after the prefix `Kamino Vault <vaultTokenSymbol>`. E.g. USDC Vault for a vault using USDC as token. */
|
|
2715
|
+
readonly vaultTokenName: string;
|
|
2649
2716
|
constructor(args: {
|
|
2650
2717
|
admin: PublicKey;
|
|
2651
2718
|
tokenMint: PublicKey;
|
|
@@ -2653,6 +2720,8 @@ export class KaminoVaultConfig {
|
|
|
2653
2720
|
performanceFeeRatePercentage: Decimal;
|
|
2654
2721
|
managementFeeRatePercentage: Decimal;
|
|
2655
2722
|
name: string;
|
|
2723
|
+
vaultTokenSymbol: string;
|
|
2724
|
+
vaultTokenName: string;
|
|
2656
2725
|
}) {
|
|
2657
2726
|
this.admin = args.admin;
|
|
2658
2727
|
this.tokenMint = args.tokenMint;
|
|
@@ -2660,6 +2729,8 @@ export class KaminoVaultConfig {
|
|
|
2660
2729
|
this.managementFeeRatePercentage = args.managementFeeRatePercentage;
|
|
2661
2730
|
this.tokenMintProgramId = args.tokenMintProgramId;
|
|
2662
2731
|
this.name = args.name;
|
|
2732
|
+
this.vaultTokenSymbol = args.vaultTokenSymbol;
|
|
2733
|
+
this.vaultTokenName = args.vaultTokenName;
|
|
2663
2734
|
}
|
|
2664
2735
|
|
|
2665
2736
|
getPerformanceFeeBps(): number {
|
|
@@ -2762,6 +2833,7 @@ export type MarketOverview = {
|
|
|
2762
2833
|
export type ReserveAsCollateral = {
|
|
2763
2834
|
mint: PublicKey;
|
|
2764
2835
|
liquidationLTVPct: Decimal;
|
|
2836
|
+
address: PublicKey;
|
|
2765
2837
|
};
|
|
2766
2838
|
|
|
2767
2839
|
export type VaultOverview = {
|
|
@@ -2788,3 +2860,12 @@ export type VaultCumulativeInterestWithTimestamp = {
|
|
|
2788
2860
|
cumulativeInterest: Decimal;
|
|
2789
2861
|
timestamp: number;
|
|
2790
2862
|
};
|
|
2863
|
+
|
|
2864
|
+
export function printHoldings(holdings: VaultHoldings) {
|
|
2865
|
+
console.log('Holdings:');
|
|
2866
|
+
console.log(' Available:', holdings.available.toString());
|
|
2867
|
+
console.log(' Invested:', holdings.invested.toString());
|
|
2868
|
+
console.log(' Total AUM including fees:', holdings.totalAUMIncludingFees.toString());
|
|
2869
|
+
console.log(' Pending fees:', holdings.pendingFees.toString());
|
|
2870
|
+
console.log(' Invested in reserves:', pubkeyHashMapToJson(holdings.investedInReserves));
|
|
2871
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TransactionInstruction } from '@solana/web3.js';
|
|
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 */
|
|
@@ -8,6 +8,7 @@ export type InitVaultIxs = {
|
|
|
8
8
|
createLUTIx: TransactionInstruction;
|
|
9
9
|
populateLUTIxs: TransactionInstruction[];
|
|
10
10
|
cleanupIxs: TransactionInstruction[];
|
|
11
|
+
initSharesMetadataIx: TransactionInstruction;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
export type AcceptVaultOwnershipIxs = {
|
|
@@ -61,18 +62,3 @@ export type APYs = {
|
|
|
61
62
|
grossAPY: Decimal;
|
|
62
63
|
netAPY: Decimal;
|
|
63
64
|
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Some amount of a specific token type.
|
|
67
|
-
*/
|
|
68
|
-
export type TokenAmount = {
|
|
69
|
-
/**
|
|
70
|
-
* Token's mint key.
|
|
71
|
-
*/
|
|
72
|
-
mint: PublicKey;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Amount, in lamports.
|
|
76
|
-
*/
|
|
77
|
-
amount: Decimal;
|
|
78
|
-
};
|
package/src/client.ts
CHANGED
|
@@ -364,13 +364,13 @@ async function deposit(connection: Connection, wallet: Keypair, token: string, d
|
|
|
364
364
|
true,
|
|
365
365
|
{ scope: new Scope('mainnet-beta', connection), scopeFeed: 'hubble' }
|
|
366
366
|
);
|
|
367
|
-
console.log('User obligation', kaminoAction.
|
|
367
|
+
console.log('User obligation', kaminoAction.getObligationPda().toString());
|
|
368
368
|
|
|
369
369
|
const tx = await buildVersionedTransaction(connection, wallet.publicKey, KaminoAction.actionToIxs(kaminoAction));
|
|
370
370
|
|
|
371
|
-
console.log('Deposit
|
|
372
|
-
console.log('Deposit
|
|
373
|
-
console.log('Deposit
|
|
371
|
+
console.log('Deposit SetupIxs:', kaminoAction.setupIxsLabels);
|
|
372
|
+
console.log('Deposit LendingIxs:', kaminoAction.lendingIxsLabels);
|
|
373
|
+
console.log('Deposit CleanupIxs:', kaminoAction.cleanupIxsLabels);
|
|
374
374
|
await buildAndSendTxnWithLogs(connection, tx, wallet, []);
|
|
375
375
|
}
|
|
376
376
|
|
|
@@ -386,13 +386,13 @@ async function withdraw(connection: Connection, wallet: Keypair, token: string,
|
|
|
386
386
|
true,
|
|
387
387
|
{ scope: new Scope('mainnet-beta', connection), scopeFeed: 'hubble' }
|
|
388
388
|
);
|
|
389
|
-
console.log('User obligation', kaminoAction.
|
|
389
|
+
console.log('User obligation', kaminoAction.getObligationPda().toString());
|
|
390
390
|
|
|
391
391
|
const tx = await buildVersionedTransaction(connection, wallet.publicKey, KaminoAction.actionToIxs(kaminoAction));
|
|
392
392
|
|
|
393
|
-
console.log('Withdraw
|
|
394
|
-
console.log('Withdraw
|
|
395
|
-
console.log('Withdraw
|
|
393
|
+
console.log('Withdraw SetupIxs:', kaminoAction.setupIxsLabels);
|
|
394
|
+
console.log('Withdraw LendingIxs:', kaminoAction.lendingIxsLabels);
|
|
395
|
+
console.log('Withdraw CleanupIxs:', kaminoAction.cleanupIxsLabels);
|
|
396
396
|
await buildAndSendTxnWithLogs(connection, tx, wallet, []);
|
|
397
397
|
}
|
|
398
398
|
|
|
@@ -408,13 +408,13 @@ async function borrow(connection: Connection, wallet: Keypair, token: string, bo
|
|
|
408
408
|
true,
|
|
409
409
|
{ scope: new Scope('mainnet-beta', connection), scopeFeed: 'hubble' }
|
|
410
410
|
);
|
|
411
|
-
console.log('User obligation', kaminoAction.
|
|
411
|
+
console.log('User obligation', kaminoAction.getObligationPda().toString());
|
|
412
412
|
|
|
413
413
|
const tx = await buildVersionedTransaction(connection, wallet.publicKey, KaminoAction.actionToIxs(kaminoAction));
|
|
414
414
|
|
|
415
|
-
console.log('Borrow
|
|
416
|
-
console.log('Borrow
|
|
417
|
-
console.log('Borrow
|
|
415
|
+
console.log('Borrow SetupIxs:', kaminoAction.setupIxsLabels);
|
|
416
|
+
console.log('Borrow LendingIxs:', kaminoAction.lendingIxsLabels);
|
|
417
|
+
console.log('Borrow CleanupIxs:', kaminoAction.cleanupIxsLabels);
|
|
418
418
|
await buildAndSendTxnWithLogs(connection, tx, wallet, []);
|
|
419
419
|
}
|
|
420
420
|
|
|
@@ -431,13 +431,13 @@ async function repay(connection: Connection, wallet: Keypair, token: string, bor
|
|
|
431
431
|
{ scope: new Scope('mainnet-beta', connection), scopeFeed: 'hubble' },
|
|
432
432
|
await connection.getSlot()
|
|
433
433
|
);
|
|
434
|
-
console.log('User obligation', kaminoAction.
|
|
434
|
+
console.log('User obligation', kaminoAction.getObligationPda().toString());
|
|
435
435
|
|
|
436
436
|
const tx = await buildVersionedTransaction(connection, wallet.publicKey, KaminoAction.actionToIxs(kaminoAction));
|
|
437
437
|
|
|
438
|
-
console.log('Repay
|
|
439
|
-
console.log('Repay
|
|
440
|
-
console.log('Repay
|
|
438
|
+
console.log('Repay SetupIxs:', kaminoAction.setupIxsLabels);
|
|
439
|
+
console.log('Repay LendingIxs:', kaminoAction.lendingIxsLabels);
|
|
440
|
+
console.log('Repay CleanupIxs:', kaminoAction.cleanupIxsLabels);
|
|
441
441
|
await buildAndSendTxnWithLogs(connection, tx, wallet, []);
|
|
442
442
|
}
|
|
443
443
|
|