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