@kamino-finance/klend-sdk 5.13.1 → 5.13.2
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 +7 -7
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +46 -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 +5 -3
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +50 -41
- package/dist/classes/vault.js.map +1 -1
- package/dist/classes/{types.d.ts → vault_types.d.ts} +2 -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 +25 -26
- 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/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 +54 -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 +53 -42
- package/src/classes/{types.ts → vault_types.ts} +1 -16
- package/src/client.ts +16 -16
- package/src/client_kamino_manager.ts +25 -25
- 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/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';
|
|
@@ -88,7 +89,7 @@ import {
|
|
|
88
89
|
UpdateVaultConfigIxs,
|
|
89
90
|
UserSharesForVault,
|
|
90
91
|
WithdrawIxs,
|
|
91
|
-
} from './
|
|
92
|
+
} from './vault_types';
|
|
92
93
|
import { batchFetch, collToLamportsDecimal, ZERO } from '@kamino-finance/kliquidity-sdk';
|
|
93
94
|
import { FullBPSDecimal } from '@kamino-finance/kliquidity-sdk/dist/utils/CreationParameters';
|
|
94
95
|
import { FarmState } from '@kamino-finance/farms-sdk/dist';
|
|
@@ -100,7 +101,6 @@ import {
|
|
|
100
101
|
getSharesInFarmUserPosition,
|
|
101
102
|
getUserSharesInFarm,
|
|
102
103
|
} from './farm_utils';
|
|
103
|
-
import { printHoldings } from './types_utils';
|
|
104
104
|
|
|
105
105
|
export const kaminoVaultId = new PublicKey('KvauGMspG5k6rtzrqqn7WNn3oZdyKqLKwK2XWQ8FLjd');
|
|
106
106
|
export const kaminoVaultStagingId = new PublicKey('stKvQfwRsQiKnLtMNVLHKS3exFJmZFsgfzBPWHECUYK');
|
|
@@ -270,7 +270,7 @@ export class KaminoVaultClient {
|
|
|
270
270
|
lut.toString()
|
|
271
271
|
);
|
|
272
272
|
|
|
273
|
-
const
|
|
273
|
+
const ixs = [createVaultIx, initVaultIx, setLUTIx];
|
|
274
274
|
|
|
275
275
|
if (vaultConfig.getPerformanceFeeBps() > 0) {
|
|
276
276
|
const setPerformanceFeeIx = this.updateUninitialisedVaultConfigIx(
|
|
@@ -279,7 +279,7 @@ export class KaminoVaultClient {
|
|
|
279
279
|
new VaultConfigField.PerformanceFeeBps(),
|
|
280
280
|
vaultConfig.getPerformanceFeeBps().toString()
|
|
281
281
|
);
|
|
282
|
-
|
|
282
|
+
ixs.push(setPerformanceFeeIx);
|
|
283
283
|
}
|
|
284
284
|
if (vaultConfig.getManagementFeeBps() > 0) {
|
|
285
285
|
const setManagementFeeIx = this.updateUninitialisedVaultConfigIx(
|
|
@@ -288,7 +288,7 @@ export class KaminoVaultClient {
|
|
|
288
288
|
new VaultConfigField.ManagementFeeBps(),
|
|
289
289
|
vaultConfig.getManagementFeeBps().toString()
|
|
290
290
|
);
|
|
291
|
-
|
|
291
|
+
ixs.push(setManagementFeeIx);
|
|
292
292
|
}
|
|
293
293
|
if (vaultConfig.name && vaultConfig.name.length > 0) {
|
|
294
294
|
const setNameIx = this.updateUninitialisedVaultConfigIx(
|
|
@@ -297,14 +297,14 @@ export class KaminoVaultClient {
|
|
|
297
297
|
new VaultConfigField.Name(),
|
|
298
298
|
vaultConfig.name
|
|
299
299
|
);
|
|
300
|
-
|
|
300
|
+
ixs.push(setNameIx);
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
return {
|
|
304
304
|
vault: vaultState,
|
|
305
305
|
initVaultIxs: {
|
|
306
306
|
createAtaIfNeededIxs: prerequisiteIxs,
|
|
307
|
-
initVaultIxs:
|
|
307
|
+
initVaultIxs: ixs,
|
|
308
308
|
createLUTIx,
|
|
309
309
|
populateLUTIxs: insertIntoLUTIxs,
|
|
310
310
|
cleanupIxs,
|
|
@@ -715,7 +715,7 @@ export class KaminoVaultClient {
|
|
|
715
715
|
reservesToWithdraw,
|
|
716
716
|
this._kaminoLendProgramId
|
|
717
717
|
);
|
|
718
|
-
const
|
|
718
|
+
const withdrawIxs: TransactionInstruction[] = await Promise.all(
|
|
719
719
|
reservesToWithdraw.map(async (reserve, index) => {
|
|
720
720
|
if (reserveStates[index] === null) {
|
|
721
721
|
throw new Error(`Reserve ${reserve.toBase58()} not found`);
|
|
@@ -734,7 +734,7 @@ export class KaminoVaultClient {
|
|
|
734
734
|
})
|
|
735
735
|
);
|
|
736
736
|
|
|
737
|
-
return [createAtaIx, ...
|
|
737
|
+
return [createAtaIx, ...withdrawIxs];
|
|
738
738
|
}
|
|
739
739
|
|
|
740
740
|
// async closeVaultIx(vault: KaminoVault): Promise<TransactionInstruction> {
|
|
@@ -768,8 +768,8 @@ export class KaminoVaultClient {
|
|
|
768
768
|
|
|
769
769
|
const tokenProgramID = vaultState.tokenProgram;
|
|
770
770
|
const userTokenAta = getAssociatedTokenAddress(vaultState.tokenMint, user, true, tokenProgramID);
|
|
771
|
-
const
|
|
772
|
-
const
|
|
771
|
+
const createAtasIxs: TransactionInstruction[] = [];
|
|
772
|
+
const closeAtasIxs: TransactionInstruction[] = [];
|
|
773
773
|
if (vaultState.tokenMint.equals(NATIVE_MINT)) {
|
|
774
774
|
const [{ ata: wsolAta, createAtaIx: createWsolAtaIxn }] = createAtasIdempotent(user, [
|
|
775
775
|
{
|
|
@@ -777,22 +777,22 @@ export class KaminoVaultClient {
|
|
|
777
777
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
778
778
|
},
|
|
779
779
|
]);
|
|
780
|
-
|
|
781
|
-
const
|
|
780
|
+
createAtasIxs.push(createWsolAtaIxn);
|
|
781
|
+
const transferWsolIxs = getTransferWsolIxs(
|
|
782
782
|
user,
|
|
783
783
|
wsolAta,
|
|
784
784
|
numberToLamportsDecimal(tokenAmount, vaultState.tokenMintDecimals.toNumber()).ceil()
|
|
785
785
|
);
|
|
786
|
-
|
|
786
|
+
createAtasIxs.push(...transferWsolIxs);
|
|
787
787
|
}
|
|
788
788
|
|
|
789
|
-
const [{ ata: userSharesAta, createAtaIx:
|
|
789
|
+
const [{ ata: userSharesAta, createAtaIx: createSharesAtaIxs }] = createAtasIdempotent(user, [
|
|
790
790
|
{
|
|
791
791
|
mint: vaultState.sharesMint,
|
|
792
792
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
793
793
|
},
|
|
794
794
|
]);
|
|
795
|
-
|
|
795
|
+
createAtasIxs.push(createSharesAtaIxs);
|
|
796
796
|
|
|
797
797
|
const eventAuthority = getEventAuthorityPda(this._kaminoVaultProgramId);
|
|
798
798
|
const depoistAccounts: DepositAccounts = {
|
|
@@ -839,7 +839,7 @@ export class KaminoVaultClient {
|
|
|
839
839
|
depositIx.keys = depositIx.keys.concat(vaultReservesLendingMarkets);
|
|
840
840
|
|
|
841
841
|
const depositIxs: DepositIxs = {
|
|
842
|
-
depositIxs: [...
|
|
842
|
+
depositIxs: [...createAtasIxs, depositIx, ...closeAtasIxs],
|
|
843
843
|
stakeInFarmIfNeededIxs: [],
|
|
844
844
|
};
|
|
845
845
|
|
|
@@ -930,7 +930,7 @@ export class KaminoVaultClient {
|
|
|
930
930
|
);
|
|
931
931
|
|
|
932
932
|
if (vaultAllocation) {
|
|
933
|
-
const withdrawFromVaultIxs = await this.
|
|
933
|
+
const withdrawFromVaultIxs = await this.wihdrdrawWithReserveIxs(
|
|
934
934
|
user,
|
|
935
935
|
kaminoVault,
|
|
936
936
|
shareAmount,
|
|
@@ -939,14 +939,14 @@ export class KaminoVaultClient {
|
|
|
939
939
|
);
|
|
940
940
|
withdrawIxs.withdrawIxs = withdrawFromVaultIxs;
|
|
941
941
|
} else {
|
|
942
|
-
const withdrawFromVaultIxs = await this.
|
|
942
|
+
const withdrawFromVaultIxs = await this.withdrawFromAvailableIxs(user, kaminoVault, shareAmount);
|
|
943
943
|
withdrawIxs.withdrawIxs = withdrawFromVaultIxs;
|
|
944
944
|
}
|
|
945
945
|
|
|
946
946
|
return withdrawIxs;
|
|
947
947
|
}
|
|
948
948
|
|
|
949
|
-
private async
|
|
949
|
+
private async withdrawFromAvailableIxs(
|
|
950
950
|
user: PublicKey,
|
|
951
951
|
vault: KaminoVault,
|
|
952
952
|
shareAmount: Decimal
|
|
@@ -975,7 +975,7 @@ export class KaminoVaultClient {
|
|
|
975
975
|
return [createAtaIx, withdrawFromAvailableIxn];
|
|
976
976
|
}
|
|
977
977
|
|
|
978
|
-
private async
|
|
978
|
+
private async wihdrdrawWithReserveIxs(
|
|
979
979
|
user: PublicKey,
|
|
980
980
|
vault: KaminoVault,
|
|
981
981
|
shareAmount: Decimal,
|
|
@@ -1041,8 +1041,8 @@ export class KaminoVaultClient {
|
|
|
1041
1041
|
});
|
|
1042
1042
|
}
|
|
1043
1043
|
|
|
1044
|
-
const
|
|
1045
|
-
|
|
1044
|
+
const withdrawIxs: TransactionInstruction[] = [];
|
|
1045
|
+
withdrawIxs.push(createAtaIx);
|
|
1046
1046
|
|
|
1047
1047
|
for (let reserveIndex = 0; reserveIndex < reserveWithSharesAmountToWithdraw.length; reserveIndex++) {
|
|
1048
1048
|
const reserveWithTokens = reserveWithSharesAmountToWithdraw[reserveIndex];
|
|
@@ -1070,10 +1070,10 @@ export class KaminoVaultClient {
|
|
|
1070
1070
|
sharesToWithdraw,
|
|
1071
1071
|
vaultReservesState
|
|
1072
1072
|
);
|
|
1073
|
-
|
|
1073
|
+
withdrawIxs.push(withdrawFromReserveIx);
|
|
1074
1074
|
}
|
|
1075
1075
|
|
|
1076
|
-
return
|
|
1076
|
+
return withdrawIxs;
|
|
1077
1077
|
}
|
|
1078
1078
|
|
|
1079
1079
|
/**
|
|
@@ -1132,7 +1132,7 @@ export class KaminoVaultClient {
|
|
|
1132
1132
|
}
|
|
1133
1133
|
}
|
|
1134
1134
|
|
|
1135
|
-
const
|
|
1135
|
+
const investIxsPromises: Promise<TransactionInstruction[]>[] = [];
|
|
1136
1136
|
// invest first the reserves from which we disinvest, then the other ones
|
|
1137
1137
|
for (const reserve of reservesToDisinvestFrom) {
|
|
1138
1138
|
const reserveState = allReservesStateMap.get(reserve);
|
|
@@ -1149,7 +1149,7 @@ export class KaminoVaultClient {
|
|
|
1149
1149
|
allReservesStateMap,
|
|
1150
1150
|
false
|
|
1151
1151
|
);
|
|
1152
|
-
|
|
1152
|
+
investIxsPromises.push(investIxsPromise);
|
|
1153
1153
|
}
|
|
1154
1154
|
|
|
1155
1155
|
for (const reserve of reservesToInvestInto) {
|
|
@@ -1167,14 +1167,14 @@ export class KaminoVaultClient {
|
|
|
1167
1167
|
allReservesStateMap,
|
|
1168
1168
|
false
|
|
1169
1169
|
);
|
|
1170
|
-
|
|
1170
|
+
investIxsPromises.push(investIxsPromise);
|
|
1171
1171
|
}
|
|
1172
1172
|
|
|
1173
|
-
let
|
|
1174
|
-
|
|
1175
|
-
|
|
1173
|
+
let investIxs: TransactionInstruction[] = [];
|
|
1174
|
+
investIxs.push(createAtaIx);
|
|
1175
|
+
investIxs = await Promise.all(investIxsPromises).then((ixs) => ixs.flat());
|
|
1176
1176
|
|
|
1177
|
-
return
|
|
1177
|
+
return investIxs;
|
|
1178
1178
|
}
|
|
1179
1179
|
|
|
1180
1180
|
// todo: make sure we also check the ata of the investor for the vault token exists
|
|
@@ -1488,8 +1488,8 @@ export class KaminoVaultClient {
|
|
|
1488
1488
|
let lut = vaultState.vaultLookupTable;
|
|
1489
1489
|
if (lut.equals(PublicKey.default)) {
|
|
1490
1490
|
const recentSlot = await this.getConnection().getSlot();
|
|
1491
|
-
const [
|
|
1492
|
-
setupLUTIfNeededIxs.push(
|
|
1491
|
+
const [ix, address] = initLookupTableIx(vaultState.vaultAdminAuthority, recentSlot);
|
|
1492
|
+
setupLUTIfNeededIxs.push(ix);
|
|
1493
1493
|
lut = address;
|
|
1494
1494
|
|
|
1495
1495
|
// set the new LUT for the vault
|
|
@@ -1501,12 +1501,12 @@ export class KaminoVaultClient {
|
|
|
1501
1501
|
setupLUTIfNeededIxs.push(updateVaultConfigIxs.updateVaultConfigIx);
|
|
1502
1502
|
}
|
|
1503
1503
|
|
|
1504
|
-
const
|
|
1504
|
+
const ixs: TransactionInstruction[] = [];
|
|
1505
1505
|
let overridenExistentAccounts: PublicKey[] | undefined = undefined;
|
|
1506
1506
|
if (vaultState.vaultLookupTable.equals(PublicKey.default)) {
|
|
1507
1507
|
overridenExistentAccounts = [];
|
|
1508
1508
|
}
|
|
1509
|
-
|
|
1509
|
+
ixs.push(
|
|
1510
1510
|
...(await this.insertIntoLookupTableIxs(
|
|
1511
1511
|
vaultState.vaultAdminAuthority,
|
|
1512
1512
|
lut,
|
|
@@ -1517,7 +1517,7 @@ export class KaminoVaultClient {
|
|
|
1517
1517
|
|
|
1518
1518
|
return {
|
|
1519
1519
|
setupLUTIfNeededIxs,
|
|
1520
|
-
syncLUTIxs:
|
|
1520
|
+
syncLUTIxs: ixs,
|
|
1521
1521
|
};
|
|
1522
1522
|
}
|
|
1523
1523
|
|
|
@@ -1562,20 +1562,20 @@ export class KaminoVaultClient {
|
|
|
1562
1562
|
const missingAccountsList = new PublicKeySet(missingAccounts).toArray();
|
|
1563
1563
|
|
|
1564
1564
|
const chunkSize = 20;
|
|
1565
|
-
const
|
|
1565
|
+
const ixs: TransactionInstruction[] = [];
|
|
1566
1566
|
|
|
1567
1567
|
for (let i = 0; i < missingAccountsList.length; i += chunkSize) {
|
|
1568
1568
|
const chunk = missingAccountsList.slice(i, i + chunkSize);
|
|
1569
|
-
const
|
|
1569
|
+
const ix = AddressLookupTableProgram.extendLookupTable({
|
|
1570
1570
|
lookupTable,
|
|
1571
1571
|
authority: payer,
|
|
1572
1572
|
payer,
|
|
1573
1573
|
addresses: chunk,
|
|
1574
1574
|
});
|
|
1575
|
-
|
|
1575
|
+
ixs.push(ix);
|
|
1576
1576
|
}
|
|
1577
1577
|
|
|
1578
|
-
return
|
|
1578
|
+
return ixs;
|
|
1579
1579
|
}
|
|
1580
1580
|
|
|
1581
1581
|
/** 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 +2138,7 @@ export class KaminoVaultClient {
|
|
|
2138
2138
|
.map((filteredReserve) => {
|
|
2139
2139
|
const reserveAsCollateral: ReserveAsCollateral = {
|
|
2140
2140
|
mint: filteredReserve.getLiquidityMint(),
|
|
2141
|
+
address: filteredReserve.address,
|
|
2141
2142
|
liquidationLTVPct: new Decimal(filteredReserve.state.config.liquidationThresholdPct),
|
|
2142
2143
|
};
|
|
2143
2144
|
marketOverview.reservesAsCollateral.push(reserveAsCollateral);
|
|
@@ -2762,6 +2763,7 @@ export type MarketOverview = {
|
|
|
2762
2763
|
export type ReserveAsCollateral = {
|
|
2763
2764
|
mint: PublicKey;
|
|
2764
2765
|
liquidationLTVPct: Decimal;
|
|
2766
|
+
address: PublicKey;
|
|
2765
2767
|
};
|
|
2766
2768
|
|
|
2767
2769
|
export type VaultOverview = {
|
|
@@ -2788,3 +2790,12 @@ export type VaultCumulativeInterestWithTimestamp = {
|
|
|
2788
2790
|
cumulativeInterest: Decimal;
|
|
2789
2791
|
timestamp: number;
|
|
2790
2792
|
};
|
|
2793
|
+
|
|
2794
|
+
export function printHoldings(holdings: VaultHoldings) {
|
|
2795
|
+
console.log('Holdings:');
|
|
2796
|
+
console.log(' Available:', holdings.available.toString());
|
|
2797
|
+
console.log(' Invested:', holdings.invested.toString());
|
|
2798
|
+
console.log(' Total AUM including fees:', holdings.totalAUMIncludingFees.toString());
|
|
2799
|
+
console.log(' Pending fees:', holdings.pendingFees.toString());
|
|
2800
|
+
console.log(' Invested in reserves:', pubkeyHashMapToJson(holdings.investedInReserves));
|
|
2801
|
+
}
|
|
@@ -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 */
|
|
@@ -61,18 +61,3 @@ export type APYs = {
|
|
|
61
61
|
grossAPY: Decimal;
|
|
62
62
|
netAPY: Decimal;
|
|
63
63
|
};
|
|
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
|
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
LendingMarket,
|
|
27
27
|
MAINNET_BETA_CHAIN_ID,
|
|
28
28
|
parseZeroPaddedUtf8,
|
|
29
|
+
printHoldings,
|
|
29
30
|
Reserve,
|
|
30
31
|
ReserveAllocationConfig,
|
|
31
32
|
ReserveWithAddress,
|
|
@@ -57,7 +58,6 @@ import {
|
|
|
57
58
|
PerformanceFeeBps,
|
|
58
59
|
} from './idl_codegen_kamino_vault/types/VaultConfigField';
|
|
59
60
|
import { getAccountOwner } from './utils/rpc';
|
|
60
|
-
import { printHoldings } from './classes/types_utils';
|
|
61
61
|
import { getAssociatedTokenAddressSync } from '@solana/spl-token';
|
|
62
62
|
|
|
63
63
|
dotenv.config({
|
|
@@ -93,11 +93,11 @@ async function main() {
|
|
|
93
93
|
env.kVaultProgramId
|
|
94
94
|
);
|
|
95
95
|
|
|
96
|
-
const { market: marketKp,
|
|
96
|
+
const { market: marketKp, ixs: createMarketIxs } = await kaminoManager.createMarketIxs({
|
|
97
97
|
admin: mode === 'multisig' ? multisigPk : env.payer.publicKey,
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
await processTxn(env.client, env.payer,
|
|
100
|
+
await processTxn(env.client, env.payer, createMarketIxs, mode, 2500, [marketKp]);
|
|
101
101
|
|
|
102
102
|
mode === 'execute' && console.log('Market created:', marketKp.publicKey.toBase58());
|
|
103
103
|
});
|
|
@@ -142,7 +142,7 @@ async function main() {
|
|
|
142
142
|
? getAssociatedTokenAddressSync(tokenMint, multisigPk)
|
|
143
143
|
: getAssociatedTokenAddressSync(tokenMint, env.payer.publicKey);
|
|
144
144
|
|
|
145
|
-
const { reserve,
|
|
145
|
+
const { reserve, txnIxs } = await kaminoManager.addAssetToMarketIxs({
|
|
146
146
|
admin: mode === 'multisig' ? multisigPk : env.payer.publicKey,
|
|
147
147
|
adminLiquiditySource: adminAta,
|
|
148
148
|
marketAddress: marketAddress,
|
|
@@ -151,9 +151,9 @@ async function main() {
|
|
|
151
151
|
|
|
152
152
|
console.log('reserve: ', reserve.publicKey);
|
|
153
153
|
|
|
154
|
-
const _createReserveSig = await processTxn(env.client, env.payer,
|
|
154
|
+
const _createReserveSig = await processTxn(env.client, env.payer, txnIxs[0], mode, 2500, [reserve]);
|
|
155
155
|
|
|
156
|
-
const _updateReserveSig = await processTxn(env.client, env.payer,
|
|
156
|
+
const _updateReserveSig = await processTxn(env.client, env.payer, txnIxs[1], mode, 2500, [], 400_000);
|
|
157
157
|
|
|
158
158
|
mode === 'execute' &&
|
|
159
159
|
console.log(
|
|
@@ -207,7 +207,7 @@ async function main() {
|
|
|
207
207
|
|
|
208
208
|
const reserveConfig = parseReserveConfigFromFile(reserveConfigFromFile);
|
|
209
209
|
|
|
210
|
-
const
|
|
210
|
+
const ixs = await kaminoManager.updateReserveIxs(
|
|
211
211
|
marketWithAddress,
|
|
212
212
|
reserveAddress,
|
|
213
213
|
reserveConfig,
|
|
@@ -215,7 +215,7 @@ async function main() {
|
|
|
215
215
|
updateEntireConfig
|
|
216
216
|
);
|
|
217
217
|
|
|
218
|
-
const _updateReserveSig = await processTxn(env.client, env.payer,
|
|
218
|
+
const _updateReserveSig = await processTxn(env.client, env.payer, ixs, mode, 2500, [], 400_000);
|
|
219
219
|
|
|
220
220
|
mode === 'execute' && console.log('Reserve Updated with config -> ', JSON.parse(JSON.stringify(reserveConfig)));
|
|
221
221
|
});
|
|
@@ -1242,11 +1242,11 @@ async function main() {
|
|
|
1242
1242
|
|
|
1243
1243
|
const newLendingMarket = LendingMarket.fromJSON(JSON.parse(fs.readFileSync(lendingMarketConfigPath, 'utf8')));
|
|
1244
1244
|
|
|
1245
|
-
const
|
|
1245
|
+
const ixs = kaminoManager.updateLendingMarketIxs(marketWithAddress, newLendingMarket);
|
|
1246
1246
|
|
|
1247
|
-
// executing 6
|
|
1248
|
-
for (let ixnIndex = 0; ixnIndex <
|
|
1249
|
-
const ixnToExecute =
|
|
1247
|
+
// executing 6 ixs in a txn to make sure they fit
|
|
1248
|
+
for (let ixnIndex = 0; ixnIndex < ixs.length; ixnIndex += 6) {
|
|
1249
|
+
const ixnToExecute = ixs.slice(ixnIndex, ixnIndex + 6);
|
|
1250
1250
|
const _updateLendingMarketSig = await processTxn(env.client, env.payer, ixnToExecute, mode, 2500, [], 400_000);
|
|
1251
1251
|
}
|
|
1252
1252
|
|
|
@@ -1285,9 +1285,9 @@ async function main() {
|
|
|
1285
1285
|
env.kVaultProgramId
|
|
1286
1286
|
);
|
|
1287
1287
|
|
|
1288
|
-
const
|
|
1288
|
+
const ix = kaminoManager.updateLendingMarketOwnerIxs(marketWithAddress);
|
|
1289
1289
|
|
|
1290
|
-
const _updateLendingMarketSig = await processTxn(env.client, env.payer, [
|
|
1290
|
+
const _updateLendingMarketSig = await processTxn(env.client, env.payer, [ix], mode, 2500, [], 400_000);
|
|
1291
1291
|
|
|
1292
1292
|
mode === 'execute' &&
|
|
1293
1293
|
console.log(
|
|
@@ -1340,9 +1340,9 @@ async function main() {
|
|
|
1340
1340
|
name: newNameEncoded,
|
|
1341
1341
|
};
|
|
1342
1342
|
|
|
1343
|
-
const
|
|
1343
|
+
const ixs = kaminoManager.updateLendingMarketIxs(marketWithAddress, newLendingMarket);
|
|
1344
1344
|
|
|
1345
|
-
const _updateLendingMarketSig = await processTxn(env.client, env.payer,
|
|
1345
|
+
const _updateLendingMarketSig = await processTxn(env.client, env.payer, ixs, mode, 2500, [], 400_000);
|
|
1346
1346
|
|
|
1347
1347
|
mode === 'execute' &&
|
|
1348
1348
|
console.log(
|
|
@@ -1395,9 +1395,9 @@ async function main() {
|
|
|
1395
1395
|
};
|
|
1396
1396
|
const newReserveConfig: ReserveConfig = new ReserveConfig(newReserveConfigFields);
|
|
1397
1397
|
|
|
1398
|
-
const
|
|
1398
|
+
const ixs = await kaminoManager.updateReserveIxs(marketWithAddress, reserveAddress, newReserveConfig);
|
|
1399
1399
|
|
|
1400
|
-
const _updateLendingMarketSig = await processTxn(env.client, env.payer,
|
|
1400
|
+
const _updateLendingMarketSig = await processTxn(env.client, env.payer, ixs, mode, 2500, [], 400_000);
|
|
1401
1401
|
|
|
1402
1402
|
mode === 'execute' &&
|
|
1403
1403
|
console.log(
|
|
@@ -1486,7 +1486,7 @@ export type Env = {
|
|
|
1486
1486
|
async function processTxn(
|
|
1487
1487
|
web3Client: Web3Client,
|
|
1488
1488
|
admin: Keypair,
|
|
1489
|
-
|
|
1489
|
+
ixs: TransactionInstruction[],
|
|
1490
1490
|
mode: string,
|
|
1491
1491
|
priorityFeeMultiplier: number = 2500,
|
|
1492
1492
|
extraSigners: Signer[],
|
|
@@ -1499,7 +1499,7 @@ async function processTxn(
|
|
|
1499
1499
|
if (mode === 'multisig') {
|
|
1500
1500
|
const { blockhash } = await web3Client.connection.getLatestBlockhash();
|
|
1501
1501
|
const txn = new Transaction();
|
|
1502
|
-
txn.add(...
|
|
1502
|
+
txn.add(...ixs);
|
|
1503
1503
|
txn.recentBlockhash = blockhash;
|
|
1504
1504
|
txn.feePayer = admin.publicKey;
|
|
1505
1505
|
|
|
@@ -1521,7 +1521,7 @@ async function processTxn(
|
|
|
1521
1521
|
}
|
|
1522
1522
|
tx.recentBlockhash = blockhash;
|
|
1523
1523
|
tx.feePayer = admin.publicKey;
|
|
1524
|
-
tx.add(...
|
|
1524
|
+
tx.add(...ixs);
|
|
1525
1525
|
|
|
1526
1526
|
if (mode === 'execute') {
|
|
1527
1527
|
return await signSendAndConfirmRawTransactionWithRetry({
|
|
@@ -1557,10 +1557,10 @@ async function processTxn(
|
|
|
1557
1557
|
}
|
|
1558
1558
|
|
|
1559
1559
|
function createAddExtraComputeUnitFeeTransaction(units: number, microLamports: number): TransactionInstruction[] {
|
|
1560
|
-
const
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
return
|
|
1560
|
+
const ixs: TransactionInstruction[] = [];
|
|
1561
|
+
ixs.push(ComputeBudgetProgram.setComputeUnitLimit({ units }));
|
|
1562
|
+
ixs.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: new Decimal(microLamports).floor().toNumber() }));
|
|
1563
|
+
return ixs;
|
|
1564
1564
|
}
|
|
1565
1565
|
|
|
1566
1566
|
function parseReserveConfigFromFile(reserveConfigFromFile: any): ReserveConfig {
|