@kamino-finance/klend-sdk 5.10.33 → 5.10.35-beta.0
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 +33 -26
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +614 -202
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +4 -4
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +13 -4
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/reserve.d.ts +1 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +2 -1
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/types.d.ts +4 -0
- package/dist/classes/types.d.ts.map +1 -1
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +1 -2
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +4 -4
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +39 -26
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +8 -3
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl.json +269 -156
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +15 -0
- package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/LendingMarket.js +11 -1
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.d.ts +6 -0
- package/dist/idl_codegen/accounts/Obligation.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.js +8 -1
- package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
- package/dist/idl_codegen/errors/custom.d.ts +51 -3
- package/dist/idl_codegen/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen/errors/custom.js +89 -5
- package/dist/idl_codegen/errors/custom.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js +1 -1
- package/dist/idl_codegen/instructions/borrowObligationLiquidityV2.js.map +1 -1
- package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts +52 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.d.ts.map +1 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.js +219 -0
- package/dist/idl_codegen/instructions/depositAndWithdraw.js.map +1 -0
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js +1 -1
- package/dist/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/index.d.ts +2 -2
- package/dist/idl_codegen/instructions/index.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/index.js +3 -3
- package/dist/idl_codegen/instructions/index.js.map +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/initFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/initObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.d.ts +1 -0
- package/dist/idl_codegen/instructions/initReserve.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/initReserve.js +5 -0
- package/dist/idl_codegen/instructions/initReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js +2 -2
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js +2 -2
- package/dist/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemFees.js +1 -1
- package/dist/idl_codegen/instructions/redeemFees.js.map +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js +1 -1
- package/dist/idl_codegen/instructions/redeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js +1 -1
- package/dist/idl_codegen/instructions/refreshObligationFarmsForReserve.js.map +1 -1
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts +9 -0
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.d.ts.map +1 -1
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js +24 -3
- package/dist/idl_codegen/instructions/repayAndWithdrawAndRedeem.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidity.js.map +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js +1 -1
- package/dist/idl_codegen/instructions/repayObligationLiquidityV2.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js +2 -2
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js +2 -2
- package/dist/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js +1 -1
- package/dist/idl_codegen/instructions/withdrawProtocolFee.js.map +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js +1 -1
- package/dist/idl_codegen/instructions/withdrawReferrerFees.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts +13 -0
- package/dist/idl_codegen/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js +25 -1
- package/dist/idl_codegen/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/idl_codegen/types/index.d.ts +2 -2
- package/dist/idl_codegen/types/index.d.ts.map +1 -1
- package/dist/idl_codegen/types/index.js.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts +12 -4
- package/dist/idl_codegen/zero_padding/ObligationZP.d.ts.map +1 -1
- package/dist/idl_codegen/zero_padding/ObligationZP.js +15 -8
- package/dist/idl_codegen/zero_padding/ObligationZP.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +3 -2
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +7 -6
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +5 -0
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +9 -5
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/instructions.d.ts +1 -2
- package/dist/leverage/instructions.d.ts.map +1 -1
- package/dist/leverage/instructions.js +2 -6
- package/dist/leverage/instructions.js.map +1 -1
- package/dist/leverage/operations.d.ts +8 -8
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +46 -37
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +4 -1
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/utils/ata.d.ts +1 -1
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +2 -2
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/constants.d.ts +4 -9
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +5 -10
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/instruction.d.ts.map +1 -1
- package/dist/utils/instruction.js +1 -3
- package/dist/utils/instruction.js.map +1 -1
- package/dist/utils/managerTypes.d.ts +1 -0
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/seeds.d.ts +5 -0
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +10 -1
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +8 -10
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +6 -3
- package/src/classes/action.ts +789 -214
- package/src/classes/manager.ts +18 -4
- package/src/classes/reserve.ts +2 -0
- package/src/classes/types.ts +5 -0
- package/src/classes/utils.ts +3 -3
- package/src/classes/vault.ts +49 -37
- package/src/client.ts +7 -3
- package/src/client_kamino_manager.ts +10 -3
- package/src/idl.json +269 -156
- package/src/idl_codegen/accounts/LendingMarket.ts +21 -1
- package/src/idl_codegen/accounts/Obligation.ts +12 -1
- package/src/idl_codegen/errors/custom.ts +103 -4
- package/src/idl_codegen/instructions/borrowObligationLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/borrowObligationLiquidityV2.ts +1 -1
- package/src/idl_codegen/instructions/depositAndWithdraw.ts +241 -0
- package/src/idl_codegen/instructions/depositReserveLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateral.ts +1 -1
- package/src/idl_codegen/instructions/depositReserveLiquidityAndObligationCollateralV2.ts +1 -1
- package/src/idl_codegen/instructions/index.ts +4 -4
- package/src/idl_codegen/instructions/initFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/initObligationFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/initReserve.ts +6 -0
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateral.ts +2 -2
- package/src/idl_codegen/instructions/liquidateObligationAndRedeemReserveCollateralV2.ts +2 -2
- package/src/idl_codegen/instructions/redeemFees.ts +1 -1
- package/src/idl_codegen/instructions/redeemReserveCollateral.ts +1 -1
- package/src/idl_codegen/instructions/refreshObligationFarmsForReserve.ts +1 -1
- package/src/idl_codegen/instructions/repayAndWithdrawAndRedeem.ts +33 -3
- package/src/idl_codegen/instructions/repayObligationLiquidity.ts +1 -1
- package/src/idl_codegen/instructions/repayObligationLiquidityV2.ts +1 -1
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +2 -2
- package/src/idl_codegen/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts +2 -2
- package/src/idl_codegen/instructions/withdrawProtocolFee.ts +1 -1
- package/src/idl_codegen/instructions/withdrawReferrerFees.ts +1 -1
- package/src/idl_codegen/types/UpdateLendingMarketMode.ts +30 -0
- package/src/idl_codegen/types/index.ts +2 -0
- package/src/idl_codegen/zero_padding/ObligationZP.ts +18 -7
- package/src/lending_operations/repay_with_collateral_operations.ts +12 -3
- package/src/lending_operations/swap_collateral_operations.ts +17 -5
- package/src/leverage/instructions.ts +1 -6
- package/src/leverage/operations.ts +66 -29
- package/src/leverage/types.ts +4 -1
- package/src/utils/ata.ts +1 -1
- package/src/utils/constants.ts +5 -11
- package/src/utils/instruction.ts +1 -3
- package/src/utils/managerTypes.ts +1 -0
- package/src/utils/seeds.ts +13 -0
- package/src/utils/userMetadata.ts +21 -26
package/src/classes/manager.ts
CHANGED
|
@@ -76,6 +76,7 @@ import { getProgramAccounts } from '../utils/rpc';
|
|
|
76
76
|
import { VaultConfigField, VaultConfigFieldKind } from '../idl_codegen_kamino_vault/types';
|
|
77
77
|
import {
|
|
78
78
|
AcceptVaultOwnershipIxs,
|
|
79
|
+
APYs,
|
|
79
80
|
DepositIxs,
|
|
80
81
|
InitVaultIxs,
|
|
81
82
|
ReserveAllocationOverview,
|
|
@@ -186,6 +187,7 @@ export class KaminoManager {
|
|
|
186
187
|
const createReserveInstructions = await createReserveIxs(
|
|
187
188
|
this._connection,
|
|
188
189
|
params.admin,
|
|
190
|
+
params.adminLiquiditySource,
|
|
189
191
|
params.marketAddress,
|
|
190
192
|
params.assetConfig.mint,
|
|
191
193
|
reserveAccount.publicKey,
|
|
@@ -197,7 +199,7 @@ export class KaminoManager {
|
|
|
197
199
|
reserveAccount.publicKey,
|
|
198
200
|
params.assetConfig.getReserveConfig(),
|
|
199
201
|
undefined,
|
|
200
|
-
|
|
202
|
+
false
|
|
201
203
|
);
|
|
202
204
|
|
|
203
205
|
const txnIxns: TransactionInstruction[][] = [];
|
|
@@ -778,14 +780,14 @@ export class KaminoManager {
|
|
|
778
780
|
* This will return the APY of the vault under the assumption that all the available tokens in the vault are all the time invested in the reserves as ratio; for percentage it needs multiplication by 100
|
|
779
781
|
* @param vault - the kamino vault to get APY for
|
|
780
782
|
* @param slot - current slot
|
|
781
|
-
* @param
|
|
782
|
-
* @returns APY for the vault
|
|
783
|
+
* @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
|
|
784
|
+
* @returns a struct containing estimated gross APY and net APY (gross - vault fees) for the vault
|
|
783
785
|
*/
|
|
784
786
|
async getVaultTheoreticalAPY(
|
|
785
787
|
vault: VaultState,
|
|
786
788
|
slot: number,
|
|
787
789
|
vaultReserves?: PubkeyHashMap<PublicKey, KaminoReserve>
|
|
788
|
-
): Promise<
|
|
790
|
+
): Promise<APYs> {
|
|
789
791
|
return this._vaultClient.getVaultTheoreticalAPY(vault, slot, vaultReserves);
|
|
790
792
|
}
|
|
791
793
|
|
|
@@ -1266,6 +1268,17 @@ const updateLendingMarketConfig = (
|
|
|
1266
1268
|
});
|
|
1267
1269
|
}
|
|
1268
1270
|
break;
|
|
1271
|
+
case 'minInitialDepositAmount':
|
|
1272
|
+
if (!market.minInitialDepositAmount.eq(newMarket.minInitialDepositAmount)) {
|
|
1273
|
+
updateLendingMarketIxnsArgs.push({
|
|
1274
|
+
mode: UpdateLendingMarketMode.UpdateInitialDepositAmount.discriminator,
|
|
1275
|
+
value: updateMarketConfigEncodedValue(
|
|
1276
|
+
UpdateLendingMarketMode.UpdateInitialDepositAmount.discriminator,
|
|
1277
|
+
newMarket.minInitialDepositAmount.toNumber()
|
|
1278
|
+
),
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
break;
|
|
1269
1282
|
default:
|
|
1270
1283
|
assertNever(key);
|
|
1271
1284
|
}
|
|
@@ -1330,6 +1343,7 @@ function updateMarketConfigEncodedValue(
|
|
|
1330
1343
|
case UpdateLendingMarketMode.UpdateMinValueBfSkipPriorityLiqCheck.discriminator:
|
|
1331
1344
|
case UpdateLendingMarketMode.UpdateMinValueLtvSkipPriorityLiqCheck.discriminator:
|
|
1332
1345
|
case UpdateLendingMarketMode.UpdateIndividualAutodeleverageMarginCallPeriodSecs.discriminator:
|
|
1346
|
+
case UpdateLendingMarketMode.UpdateInitialDepositAmount.discriminator:
|
|
1333
1347
|
value = value as number;
|
|
1334
1348
|
buffer.writeBigUint64LE(BigInt(value), 0);
|
|
1335
1349
|
break;
|
package/src/classes/reserve.ts
CHANGED
|
@@ -1134,6 +1134,7 @@ const truncateBorrowCurve = (points: CurvePointFields[]): [number, number][] =>
|
|
|
1134
1134
|
export async function createReserveIxs(
|
|
1135
1135
|
connection: Connection,
|
|
1136
1136
|
owner: PublicKey,
|
|
1137
|
+
ownerLiquiditySource: PublicKey,
|
|
1137
1138
|
lendingMarket: PublicKey,
|
|
1138
1139
|
liquidityMint: PublicKey,
|
|
1139
1140
|
reserveAddress: PublicKey,
|
|
@@ -1166,6 +1167,7 @@ export async function createReserveIxs(
|
|
|
1166
1167
|
feeReceiver: feeVault,
|
|
1167
1168
|
reserveCollateralMint: collateralMint,
|
|
1168
1169
|
reserveCollateralSupply: collateralSupplyVault,
|
|
1170
|
+
initialLiquiditySource: ownerLiquiditySource,
|
|
1169
1171
|
liquidityTokenProgram: TOKEN_PROGRAM_ID,
|
|
1170
1172
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1171
1173
|
systemProgram: SystemProgram.programId,
|
package/src/classes/types.ts
CHANGED
package/src/classes/utils.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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
|
|
5
|
-
import { AccountLayout } from '@solana/spl-token';
|
|
4
|
+
import { MarketOverview, ReserveOverview } from '../lib';
|
|
5
|
+
import { AccountLayout, NATIVE_MINT } from '@solana/spl-token';
|
|
6
6
|
import { ReserveAllocationOverview } from './types';
|
|
7
7
|
import axios from 'axios';
|
|
8
8
|
|
|
@@ -188,7 +188,7 @@ export function lamportsToDecimal(amount: Decimal.Value, decimals: Decimal.Value
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
export const isSolMint = (mint: PublicKey): boolean => {
|
|
191
|
-
return
|
|
191
|
+
return NATIVE_MINT.equals(mint);
|
|
192
192
|
};
|
|
193
193
|
|
|
194
194
|
export const valueOrZero = (value: Decimal): Decimal => {
|
package/src/classes/vault.ts
CHANGED
|
@@ -11,10 +11,10 @@ import {
|
|
|
11
11
|
SYSVAR_RENT_PUBKEY,
|
|
12
12
|
TransactionInstruction,
|
|
13
13
|
} from '@solana/web3.js';
|
|
14
|
-
import { TOKEN_PROGRAM_ID, unpackAccount } from '@solana/spl-token';
|
|
14
|
+
import { NATIVE_MINT, TOKEN_PROGRAM_ID, unpackAccount } from '@solana/spl-token';
|
|
15
15
|
import {
|
|
16
16
|
getAssociatedTokenAddress,
|
|
17
|
-
|
|
17
|
+
getTransferWsolIxns,
|
|
18
18
|
getTokenOracleData,
|
|
19
19
|
KaminoMarket,
|
|
20
20
|
KaminoReserve,
|
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
PubkeyHashMap,
|
|
23
23
|
Reserve,
|
|
24
24
|
UserState,
|
|
25
|
-
WRAPPED_SOL_MINT,
|
|
26
25
|
} from '../lib';
|
|
27
26
|
import {
|
|
28
27
|
DepositAccounts,
|
|
@@ -70,6 +69,7 @@ import bs58 from 'bs58';
|
|
|
70
69
|
import { getAccountOwner, getProgramAccounts } from '../utils/rpc';
|
|
71
70
|
import {
|
|
72
71
|
AcceptVaultOwnershipIxs,
|
|
72
|
+
APYs,
|
|
73
73
|
DepositIxs,
|
|
74
74
|
InitVaultIxs,
|
|
75
75
|
ReserveAllocationOverview,
|
|
@@ -98,7 +98,7 @@ export const kaminoVaultStagingId = new PublicKey('STkvh7ostar39Fwr4uZKASs1RNNuY
|
|
|
98
98
|
const TOKEN_VAULT_SEED = 'token_vault';
|
|
99
99
|
const CTOKEN_VAULT_SEED = 'ctoken_vault';
|
|
100
100
|
const BASE_VAULT_AUTHORITY_SEED = 'authority';
|
|
101
|
-
const
|
|
101
|
+
const SHARES_SEED = 'shares';
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* KaminoVaultClient is a class that provides a high-level interface to interact with the Kamino Vault program.
|
|
@@ -191,7 +191,7 @@ export class KaminoVaultClient {
|
|
|
191
191
|
)[0];
|
|
192
192
|
|
|
193
193
|
const sharesMint = PublicKey.findProgramAddressSync(
|
|
194
|
-
[Buffer.from(
|
|
194
|
+
[Buffer.from(SHARES_SEED), vaultState.publicKey.toBytes()],
|
|
195
195
|
this._kaminoVaultProgramId
|
|
196
196
|
)[0];
|
|
197
197
|
|
|
@@ -694,20 +694,20 @@ export class KaminoVaultClient {
|
|
|
694
694
|
const userTokenAta = getAssociatedTokenAddress(vaultState.tokenMint, user, true, tokenProgramID);
|
|
695
695
|
const createAtasIxns: TransactionInstruction[] = [];
|
|
696
696
|
const closeAtasIxns: TransactionInstruction[] = [];
|
|
697
|
-
if (vaultState.tokenMint.equals(
|
|
697
|
+
if (vaultState.tokenMint.equals(NATIVE_MINT)) {
|
|
698
698
|
const [{ ata: wsolAta, createAtaIx: createWsolAtaIxn }] = createAtasIdempotent(user, [
|
|
699
699
|
{
|
|
700
|
-
mint:
|
|
700
|
+
mint: NATIVE_MINT,
|
|
701
701
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
702
702
|
},
|
|
703
703
|
]);
|
|
704
704
|
createAtasIxns.push(createWsolAtaIxn);
|
|
705
|
-
const
|
|
705
|
+
const transferWsolIxns = getTransferWsolIxns(
|
|
706
706
|
user,
|
|
707
707
|
wsolAta,
|
|
708
708
|
numberToLamportsDecimal(tokenAmount, vaultState.tokenMintDecimals.toNumber()).ceil()
|
|
709
709
|
);
|
|
710
|
-
createAtasIxns.push(...
|
|
710
|
+
createAtasIxns.push(...transferWsolIxns);
|
|
711
711
|
}
|
|
712
712
|
|
|
713
713
|
const [{ ata: userSharesAta, createAtaIx: createSharesAtaIxns }] = createAtasIdempotent(user, [
|
|
@@ -1005,6 +1005,7 @@ export class KaminoVaultClient {
|
|
|
1005
1005
|
*/
|
|
1006
1006
|
async investAllReservesIxs(payer: PublicKey, vault: KaminoVault): Promise<TransactionInstruction[]> {
|
|
1007
1007
|
const vaultState = await vault.getState(this.getConnection());
|
|
1008
|
+
const minInvestAmount = vaultState.minInvestAmount;
|
|
1008
1009
|
const allReserves = this.getVaultReserves(vaultState);
|
|
1009
1010
|
if (allReserves.length === 0) {
|
|
1010
1011
|
throw new Error('No reserves found for the vault, please select at least one reserve for the vault');
|
|
@@ -1024,6 +1025,7 @@ export class KaminoVaultClient {
|
|
|
1024
1025
|
const curentVaultAllocations = this.getVaultAllocations(vaultState);
|
|
1025
1026
|
|
|
1026
1027
|
const reservesToDisinvestFrom: PublicKey[] = [];
|
|
1028
|
+
const reservesToInvestInto: PublicKey[] = [];
|
|
1027
1029
|
|
|
1028
1030
|
for (let index = 0; index < allReserves.length; index++) {
|
|
1029
1031
|
const reservePubkey = allReserves[index];
|
|
@@ -1037,8 +1039,15 @@ export class KaminoVaultClient {
|
|
|
1037
1039
|
vaultState.tokenMintDecimals.toNumber()
|
|
1038
1040
|
);
|
|
1039
1041
|
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
+
const diffInReserveTokens = computedAllocation.sub(reserveAllocationLiquidityAmount);
|
|
1043
|
+
const diffInReserveLamports = collToLamportsDecimal(diffInReserveTokens, vaultState.tokenMintDecimals.toNumber());
|
|
1044
|
+
// if the diff for the reserve is smaller than the min invest amount, we do not need to invest or disinvest
|
|
1045
|
+
if (diffInReserveLamports.abs().gte(new Decimal(minInvestAmount.toString()))) {
|
|
1046
|
+
if (computedAllocation.lt(reserveAllocationLiquidityAmount)) {
|
|
1047
|
+
reservesToDisinvestFrom.push(reservePubkey);
|
|
1048
|
+
} else {
|
|
1049
|
+
reservesToInvestInto.push(reservePubkey);
|
|
1050
|
+
}
|
|
1042
1051
|
}
|
|
1043
1052
|
}
|
|
1044
1053
|
|
|
@@ -1062,24 +1071,22 @@ export class KaminoVaultClient {
|
|
|
1062
1071
|
investIxnsPromises.push(investIxsPromise);
|
|
1063
1072
|
}
|
|
1064
1073
|
|
|
1065
|
-
for (const reserve of
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
throw new Error(`Reserve ${reserve.toBase58()} not found`);
|
|
1070
|
-
}
|
|
1071
|
-
const investIxsPromise = this.investSingleReserveIxs(
|
|
1072
|
-
payer,
|
|
1073
|
-
vault,
|
|
1074
|
-
{
|
|
1075
|
-
address: reserve,
|
|
1076
|
-
state: reserveState!.state,
|
|
1077
|
-
},
|
|
1078
|
-
allReservesStateMap,
|
|
1079
|
-
false
|
|
1080
|
-
);
|
|
1081
|
-
investIxnsPromises.push(investIxsPromise);
|
|
1074
|
+
for (const reserve of reservesToInvestInto) {
|
|
1075
|
+
const reserveState = allReservesStateMap.get(reserve);
|
|
1076
|
+
if (reserveState === null) {
|
|
1077
|
+
throw new Error(`Reserve ${reserve.toBase58()} not found`);
|
|
1082
1078
|
}
|
|
1079
|
+
const investIxsPromise = this.investSingleReserveIxs(
|
|
1080
|
+
payer,
|
|
1081
|
+
vault,
|
|
1082
|
+
{
|
|
1083
|
+
address: reserve,
|
|
1084
|
+
state: reserveState!.state,
|
|
1085
|
+
},
|
|
1086
|
+
allReservesStateMap,
|
|
1087
|
+
false
|
|
1088
|
+
);
|
|
1089
|
+
investIxnsPromises.push(investIxsPromise);
|
|
1083
1090
|
}
|
|
1084
1091
|
|
|
1085
1092
|
let investIxns: TransactionInstruction[] = [];
|
|
@@ -1500,7 +1507,7 @@ export class KaminoVaultClient {
|
|
|
1500
1507
|
const allocation = reservesAllocations.get(reserve);
|
|
1501
1508
|
return allocation?.targetWeight.isZero();
|
|
1502
1509
|
});
|
|
1503
|
-
if (
|
|
1510
|
+
if (allReservesPubkeys.length === 0 || allReservesHaveWeight0) {
|
|
1504
1511
|
const computedHoldings = new PubkeyHashMap<PublicKey, Decimal>();
|
|
1505
1512
|
allReservesPubkeys.forEach((reserve) => {
|
|
1506
1513
|
computedHoldings.set(reserve, new Decimal(0));
|
|
@@ -1528,7 +1535,6 @@ export class KaminoVaultClient {
|
|
|
1528
1535
|
const reserveWithWeight = initialVaultAllocations.get(reserve);
|
|
1529
1536
|
const targetAllocation = reserveWithWeight!.targetWeight.mul(totalLeftover).div(currentAllocationSum);
|
|
1530
1537
|
const reserveCap = reserveWithWeight!.tokenAllocationCap;
|
|
1531
|
-
// todo: check if both target and reserveCap
|
|
1532
1538
|
const amountToInvest = Decimal.min(targetAllocation, reserveCap, totalLeftToInvest);
|
|
1533
1539
|
totalLeftToInvest = totalLeftToInvest.sub(amountToInvest);
|
|
1534
1540
|
if (amountToInvest.eq(reserveCap)) {
|
|
@@ -2224,7 +2230,7 @@ export class KaminoVaultClient {
|
|
|
2224
2230
|
// all the async part of the functions above just read the vaultReservesState which is read beforehand, so excepting vaultCollateralsPromise they should do no additional network calls
|
|
2225
2231
|
const [
|
|
2226
2232
|
vaultHoldingsWithUSDValue,
|
|
2227
|
-
|
|
2233
|
+
vaultTheoreticalAPYs,
|
|
2228
2234
|
totalInvestedAndBorrowed,
|
|
2229
2235
|
vaultCollaterals,
|
|
2230
2236
|
reservesOverview,
|
|
@@ -2240,7 +2246,7 @@ export class KaminoVaultClient {
|
|
|
2240
2246
|
holdingsUSD: vaultHoldingsWithUSDValue,
|
|
2241
2247
|
reservesOverview: reservesOverview,
|
|
2242
2248
|
vaultCollaterals: vaultCollaterals,
|
|
2243
|
-
theoreticalSupplyAPY:
|
|
2249
|
+
theoreticalSupplyAPY: vaultTheoreticalAPYs,
|
|
2244
2250
|
totalBorrowed: totalInvestedAndBorrowed.totalBorrowed,
|
|
2245
2251
|
utilizationRatio: totalInvestedAndBorrowed.utilizationRatio,
|
|
2246
2252
|
totalSupplied: totalInvestedAndBorrowed.totalInvested,
|
|
@@ -2351,13 +2357,13 @@ export class KaminoVaultClient {
|
|
|
2351
2357
|
* @param vault - the kamino vault to get APY for
|
|
2352
2358
|
* @param slot - current slot
|
|
2353
2359
|
* @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
|
|
2354
|
-
* @returns APY for the vault
|
|
2360
|
+
* @returns a struct containing estimated gross APY and net APY (gross - vault fees) for the vault
|
|
2355
2361
|
*/
|
|
2356
2362
|
async getVaultTheoreticalAPY(
|
|
2357
2363
|
vault: VaultState,
|
|
2358
2364
|
slot: number,
|
|
2359
2365
|
vaultReservesMap?: PubkeyHashMap<PublicKey, KaminoReserve>
|
|
2360
|
-
): Promise<
|
|
2366
|
+
): Promise<APYs> {
|
|
2361
2367
|
const vaultReservesState = vaultReservesMap ? vaultReservesMap : await this.loadVaultReserves(vault);
|
|
2362
2368
|
|
|
2363
2369
|
let totalWeights = new Decimal(0);
|
|
@@ -2379,14 +2385,20 @@ export class KaminoVaultClient {
|
|
|
2379
2385
|
totalWeights = totalWeights.add(weight);
|
|
2380
2386
|
});
|
|
2381
2387
|
if (totalWeights.isZero()) {
|
|
2382
|
-
return
|
|
2388
|
+
return {
|
|
2389
|
+
grossAPY: new Decimal(0),
|
|
2390
|
+
netAPY: new Decimal(0),
|
|
2391
|
+
};
|
|
2383
2392
|
}
|
|
2384
2393
|
|
|
2385
2394
|
const grossAPY = totalAPY.div(totalWeights);
|
|
2386
2395
|
const netAPY = grossAPY
|
|
2387
2396
|
.mul(new Decimal(1).sub(new Decimal(vault.performanceFeeBps.toString()).div(FullBPSDecimal)))
|
|
2388
2397
|
.mul(new Decimal(1).sub(new Decimal(vault.managementFeeBps.toString()).div(FullBPSDecimal)));
|
|
2389
|
-
return
|
|
2398
|
+
return {
|
|
2399
|
+
grossAPY,
|
|
2400
|
+
netAPY,
|
|
2401
|
+
};
|
|
2390
2402
|
}
|
|
2391
2403
|
|
|
2392
2404
|
/**
|
|
@@ -2655,7 +2667,7 @@ export type VaultOverview = {
|
|
|
2655
2667
|
holdingsUSD: VaultHoldingsWithUSDValue;
|
|
2656
2668
|
reservesOverview: PubkeyHashMap<PublicKey, ReserveOverview>;
|
|
2657
2669
|
vaultCollaterals: PubkeyHashMap<PublicKey, MarketOverview>;
|
|
2658
|
-
theoreticalSupplyAPY:
|
|
2670
|
+
theoreticalSupplyAPY: APYs;
|
|
2659
2671
|
totalBorrowed: Decimal;
|
|
2660
2672
|
totalSupplied: Decimal;
|
|
2661
2673
|
utilizationRatio: Decimal;
|
package/src/client.ts
CHANGED
|
@@ -308,7 +308,8 @@ async function deposit(connection: Connection, wallet: Keypair, token: string, d
|
|
|
308
308
|
depositAmount,
|
|
309
309
|
kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
|
|
310
310
|
wallet.publicKey,
|
|
311
|
-
new VanillaObligation(STAGING_LENDING_MARKET)
|
|
311
|
+
new VanillaObligation(STAGING_LENDING_MARKET),
|
|
312
|
+
true
|
|
312
313
|
);
|
|
313
314
|
console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
|
|
314
315
|
|
|
@@ -328,7 +329,8 @@ async function withdraw(connection: Connection, wallet: Keypair, token: string,
|
|
|
328
329
|
depositAmount,
|
|
329
330
|
kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
|
|
330
331
|
wallet.publicKey,
|
|
331
|
-
new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET))
|
|
332
|
+
new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET)),
|
|
333
|
+
true
|
|
332
334
|
);
|
|
333
335
|
console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
|
|
334
336
|
|
|
@@ -348,7 +350,8 @@ async function borrow(connection: Connection, wallet: Keypair, token: string, bo
|
|
|
348
350
|
borrowAmount,
|
|
349
351
|
kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
|
|
350
352
|
wallet.publicKey,
|
|
351
|
-
new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET))
|
|
353
|
+
new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET)),
|
|
354
|
+
true
|
|
352
355
|
);
|
|
353
356
|
console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
|
|
354
357
|
|
|
@@ -369,6 +372,7 @@ async function repay(connection: Connection, wallet: Keypair, token: string, bor
|
|
|
369
372
|
kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
|
|
370
373
|
wallet.publicKey,
|
|
371
374
|
new VanillaObligation(new PublicKey(STAGING_LENDING_MARKET)),
|
|
375
|
+
true,
|
|
372
376
|
await connection.getSlot()
|
|
373
377
|
);
|
|
374
378
|
console.log('User obligation', kaminoAction.obligation!.obligationAddress.toString());
|
|
@@ -54,6 +54,7 @@ import {
|
|
|
54
54
|
} from './idl_codegen_kamino_vault/types/VaultConfigField';
|
|
55
55
|
import { getAccountOwner } from './utils/rpc';
|
|
56
56
|
import { printHoldings } from './classes/types_utils';
|
|
57
|
+
import { getAssociatedTokenAddressSync } from '@solana/spl-token';
|
|
57
58
|
|
|
58
59
|
dotenv.config({
|
|
59
60
|
path: `.env${process.env.ENV ? '.' + process.env.ENV : ''}`,
|
|
@@ -87,7 +88,7 @@ async function main() {
|
|
|
87
88
|
admin: mode === 'multisig' ? multisigPk : env.payer.publicKey,
|
|
88
89
|
});
|
|
89
90
|
|
|
90
|
-
|
|
91
|
+
await processTxn(env.client, env.payer, createMarketIxns, mode, 2500, [marketKp]);
|
|
91
92
|
|
|
92
93
|
mode === 'execute' && console.log('Market created:', marketKp.publicKey.toBase58());
|
|
93
94
|
});
|
|
@@ -122,8 +123,14 @@ async function main() {
|
|
|
122
123
|
const reserveConfig = parseReserveConfigFromFile(reserveConfigFromFile);
|
|
123
124
|
const assetConfig = new AssetReserveConfigCli(tokenMint, tokenMintProgramId, reserveConfig);
|
|
124
125
|
|
|
126
|
+
const adminAta =
|
|
127
|
+
mode === 'multisig'
|
|
128
|
+
? getAssociatedTokenAddressSync(tokenMint, multisigPk)
|
|
129
|
+
: getAssociatedTokenAddressSync(tokenMint, env.payer.publicKey);
|
|
130
|
+
|
|
125
131
|
const { reserve, txnIxns } = await kaminoManager.addAssetToMarketIxs({
|
|
126
132
|
admin: mode === 'multisig' ? multisigPk : env.payer.publicKey,
|
|
133
|
+
adminLiquiditySource: adminAta,
|
|
127
134
|
marketAddress: marketAddress,
|
|
128
135
|
assetConfig: assetConfig,
|
|
129
136
|
});
|
|
@@ -260,7 +267,7 @@ async function main() {
|
|
|
260
267
|
2500,
|
|
261
268
|
[vaultKp]
|
|
262
269
|
);
|
|
263
|
-
await sleep(
|
|
270
|
+
await sleep(2000);
|
|
264
271
|
const _populateLUTSig = await processTxn(env.client, env.payer, instructions.populateLUTIxs, mode, 2500, []);
|
|
265
272
|
|
|
266
273
|
mode === 'execute' && console.log('Vault created:', vaultKp.publicKey.toBase58());
|
|
@@ -426,7 +433,7 @@ async function main() {
|
|
|
426
433
|
// if we need to create the LUT we have to do that in a separate tx and wait a little bit after
|
|
427
434
|
if (syncLUTIxs.setupLUTIfNeededIxs.length > 0) {
|
|
428
435
|
const setupLUTSig = await processTxn(env.client, env.payer, syncLUTIxs.setupLUTIfNeededIxs, mode, 2500, []);
|
|
429
|
-
await sleep(
|
|
436
|
+
await sleep(2000);
|
|
430
437
|
mode === 'execute' && console.log('LUT created and set to the vault:', setupLUTSig);
|
|
431
438
|
}
|
|
432
439
|
// if there are accounts to be added to the LUT we have to do that in a separate tx
|