@kamino-finance/klend-sdk 5.0.4 → 5.0.5
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/fraction.d.ts.map +1 -1
- package/dist/classes/fraction.js.map +1 -1
- package/dist/classes/manager.d.ts +38 -4
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +112 -5
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +4 -0
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +17 -25
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +2 -1
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts +1 -0
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +22 -27
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/utils.d.ts +3 -0
- package/dist/classes/utils.d.ts.map +1 -1
- package/dist/classes/utils.js +30 -0
- package/dist/classes/utils.js.map +1 -1
- package/dist/classes/vault.d.ts +12 -8
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +94 -66
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +15 -1
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl.json +27 -2
- package/dist/idl_codegen/accounts/LendingMarket.d.ts +6 -0
- package/dist/idl_codegen/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/LendingMarket.js +8 -1
- package/dist/idl_codegen/accounts/LendingMarket.js.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.d.ts +3 -12
- package/dist/idl_codegen/accounts/Obligation.d.ts.map +1 -1
- package/dist/idl_codegen/accounts/Obligation.js +1 -4
- package/dist/idl_codegen/accounts/Obligation.js.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts +20 -0
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.d.ts.map +1 -1
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.js +33 -1
- package/dist/idl_codegen/types/UpdateLendingMarketConfigValue.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 +4 -4
- 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_kamino_vault/accounts/Reserve.d.ts +3 -3
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.js +22 -18
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +45 -15
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +101 -39
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/index.d.ts +4 -4
- package/dist/idl_codegen_kamino_vault/accounts/index.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/anchor.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/anchor.js +162 -162
- package/dist/idl_codegen_kamino_vault/errors/anchor.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +144 -32
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.js +305 -109
- package/dist/idl_codegen_kamino_vault/errors/custom.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/index.d.ts +3 -3
- package/dist/idl_codegen_kamino_vault/errors/index.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/index.js +7 -2
- package/dist/idl_codegen_kamino_vault/errors/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/deposit.d.ts +4 -2
- package/dist/idl_codegen_kamino_vault/instructions/deposit.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/deposit.js +3 -1
- package/dist/idl_codegen_kamino_vault/instructions/deposit.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts +13 -0
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js +47 -0
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/index.d.ts +18 -10
- package/dist/idl_codegen_kamino_vault/instructions/index.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/index.js +9 -1
- package/dist/idl_codegen_kamino_vault/instructions/index.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts +2 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/invest.d.ts +6 -2
- package/dist/idl_codegen_kamino_vault/instructions/invest.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/invest.js +9 -1
- package/dist/idl_codegen_kamino_vault/instructions/invest.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateAdmin.d.ts +7 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateAdmin.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateAdmin.js +16 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateAdmin.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts +2 -2
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts +14 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js +52 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.d.ts +4 -2
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.js +8 -2
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts +23 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js +51 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/programId.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/programId.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/programId.js +1 -1
- package/dist/idl_codegen_kamino_vault/programId.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.d.ts +2 -2
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.js +4 -1
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.js +1 -1
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.js +1 -1
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.d.ts +2 -2
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.js +6 -1
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.d.ts +2 -2
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.js +1 -1
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.d.ts +2 -2
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.js +1 -1
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.d.ts +3 -3
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.js +5 -5
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.d.ts +27 -24
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.js +59 -53
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.d.ts +2 -2
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.js +5 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.d.ts +11 -3
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.js +25 -17
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.d.ts +2 -2
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.js +3 -3
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.d.ts +2 -2
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.js +1 -1
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.d.ts +3 -3
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.js +11 -11
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.d.ts +18 -8
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.js +27 -13
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts +110 -0
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js +242 -0
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/index.d.ts +34 -30
- package/dist/idl_codegen_kamino_vault/types/index.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/index.js +26 -1
- package/dist/idl_codegen_kamino_vault/types/index.js.map +1 -1
- package/dist/utils/ObligationType.d.ts.map +1 -1
- package/dist/utils/ObligationType.js.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/pubkey.d.ts.map +1 -1
- package/dist/utils/pubkey.js.map +1 -1
- package/dist/utils/rpc.d.ts.map +1 -1
- package/dist/utils/rpc.js +2 -1
- package/dist/utils/rpc.js.map +1 -1
- package/package.json +2 -1
- package/src/classes/fraction.ts +5 -0
- package/src/classes/manager.ts +136 -5
- package/src/classes/market.ts +19 -2
- package/src/classes/obligation.ts +2 -1
- package/src/classes/reserve.ts +55 -39
- package/src/classes/utils.ts +30 -0
- package/src/classes/vault.ts +123 -49
- package/src/client_kamino_manager.ts +19 -1
- package/src/idl_codegen/accounts/LendingMarket.ts +12 -1
- package/src/idl_codegen/accounts/Obligation.ts +3 -12
- package/src/idl_codegen/types/UpdateLendingMarketConfigValue.ts +43 -0
- package/src/idl_codegen/types/UpdateLendingMarketMode.ts +30 -0
- package/src/idl_codegen/types/index.ts +4 -0
- package/src/idl_codegen_kamino_vault/accounts/Reserve.ts +132 -105
- package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +217 -124
- package/src/idl_codegen_kamino_vault/accounts/index.ts +4 -4
- package/src/idl_codegen_kamino_vault/errors/anchor.ts +335 -326
- package/src/idl_codegen_kamino_vault/errors/custom.ts +353 -157
- package/src/idl_codegen_kamino_vault/errors/index.ts +35 -22
- package/src/idl_codegen_kamino_vault/instructions/deposit.ts +33 -25
- package/src/idl_codegen_kamino_vault/instructions/giveUpPendingFees.ts +40 -0
- package/src/idl_codegen_kamino_vault/instructions/index.ts +27 -10
- package/src/idl_codegen_kamino_vault/instructions/initVault.ts +25 -20
- package/src/idl_codegen_kamino_vault/instructions/invest.ts +40 -25
- package/src/idl_codegen_kamino_vault/instructions/updateAdmin.ts +24 -0
- package/src/idl_codegen_kamino_vault/instructions/updateReserveAllocation.ts +24 -24
- package/src/idl_codegen_kamino_vault/instructions/updateVaultConfig.ts +49 -0
- package/src/idl_codegen_kamino_vault/instructions/withdraw.ts +45 -33
- package/src/idl_codegen_kamino_vault/instructions/withdrawPendingFees.ts +75 -0
- package/src/idl_codegen_kamino_vault/programId.ts +5 -3
- package/src/idl_codegen_kamino_vault/types/BigFractionBytes.ts +24 -18
- package/src/idl_codegen_kamino_vault/types/BorrowRateCurve.ts +21 -16
- package/src/idl_codegen_kamino_vault/types/CurvePoint.ts +21 -18
- package/src/idl_codegen_kamino_vault/types/LastUpdate.ts +32 -27
- package/src/idl_codegen_kamino_vault/types/PriceHeuristic.ts +25 -22
- package/src/idl_codegen_kamino_vault/types/PythConfiguration.ts +14 -14
- package/src/idl_codegen_kamino_vault/types/ReserveCollateral.ts +35 -35
- package/src/idl_codegen_kamino_vault/types/ReserveConfig.ts +232 -191
- package/src/idl_codegen_kamino_vault/types/ReserveFees.ts +27 -23
- package/src/idl_codegen_kamino_vault/types/ReserveLiquidity.ts +116 -98
- package/src/idl_codegen_kamino_vault/types/ScopeConfiguration.ts +25 -25
- package/src/idl_codegen_kamino_vault/types/SwitchboardConfiguration.ts +21 -18
- package/src/idl_codegen_kamino_vault/types/TokenInfo.ts +92 -74
- package/src/idl_codegen_kamino_vault/types/VaultAllocation.ts +67 -49
- package/src/idl_codegen_kamino_vault/types/VaultConfigField.ts +270 -0
- package/src/idl_codegen_kamino_vault/types/index.ts +77 -30
- package/src/utils/ObligationType.ts +6 -0
- package/src/utils/managerTypes.ts +1 -0
- package/src/utils/pubkey.ts +2 -0
- package/src/utils/rpc.ts +3 -1
package/src/classes/market.ts
CHANGED
|
@@ -31,9 +31,11 @@ import bs58 from 'bs58';
|
|
|
31
31
|
import { OraclePrices, Scope } from '@kamino-finance/scope-sdk';
|
|
32
32
|
import { Fraction } from './fraction';
|
|
33
33
|
import { chunks, KaminoPrices, MintToPriceMap } from '@kamino-finance/kliquidity-sdk';
|
|
34
|
-
import { parseTokenSymbol } from './utils';
|
|
34
|
+
import { parseTokenSymbol, parseZeroPaddedUtf8 } from './utils';
|
|
35
35
|
import SwitchboardProgram from '@switchboard-xyz/sbv2-lite';
|
|
36
36
|
import { ObligationZP } from '../idl_codegen/zero_padding';
|
|
37
|
+
import { ReserveStatus } from '../idl_codegen/types';
|
|
38
|
+
import { getProgramAccounts } from '../utils/rpc';
|
|
37
39
|
|
|
38
40
|
export interface ReserveRewardInfo {
|
|
39
41
|
rewardsPerSecond: Decimal; // not lamport
|
|
@@ -84,8 +86,11 @@ export class KaminoMarket {
|
|
|
84
86
|
* Load a new market with all of its associated reserves
|
|
85
87
|
* @param connection
|
|
86
88
|
* @param marketAddress
|
|
89
|
+
* @param recentSlotDurationMs
|
|
87
90
|
* @param programId
|
|
91
|
+
* @param withReserves
|
|
88
92
|
* @param setupLocalTest
|
|
93
|
+
* @param withReserves
|
|
89
94
|
*/
|
|
90
95
|
static async load(
|
|
91
96
|
connection: Connection,
|
|
@@ -175,6 +180,10 @@ export class KaminoMarket {
|
|
|
175
180
|
return lendingMarketAuthPda(this.getAddress(), this.programId)[0];
|
|
176
181
|
}
|
|
177
182
|
|
|
183
|
+
getName(): string {
|
|
184
|
+
return parseZeroPaddedUtf8(this.state.name);
|
|
185
|
+
}
|
|
186
|
+
|
|
178
187
|
async getObligationDepositByWallet(
|
|
179
188
|
owner: PublicKey,
|
|
180
189
|
mint: PublicKey,
|
|
@@ -524,7 +533,6 @@ export class KaminoMarket {
|
|
|
524
533
|
* @param tag
|
|
525
534
|
*/
|
|
526
535
|
async getAllObligationsForMarket(tag?: number): Promise<KaminoObligation[]> {
|
|
527
|
-
const { getProgramAccounts } = await import('../utils/rpc');
|
|
528
536
|
const filters = [
|
|
529
537
|
{
|
|
530
538
|
dataSize: Obligation.layout.span + 8,
|
|
@@ -1082,6 +1090,10 @@ export class KaminoMarket {
|
|
|
1082
1090
|
const spot: MintToPriceMap = {};
|
|
1083
1091
|
const twaps: MintToPriceMap = {};
|
|
1084
1092
|
for (const reserve of this.reserves.values()) {
|
|
1093
|
+
if (reserve.state.config.status === ReserveStatus.Obsolete.discriminator) {
|
|
1094
|
+
// skip obsolete reserves
|
|
1095
|
+
continue;
|
|
1096
|
+
}
|
|
1085
1097
|
const tokenMint = reserve.getLiquidityMint().toString();
|
|
1086
1098
|
const tokenName = reserve.getTokenSymbol();
|
|
1087
1099
|
const oracle = reserve.state.config.tokenInfo.scopeConfiguration.priceFeed;
|
|
@@ -1119,6 +1131,11 @@ export class KaminoMarket {
|
|
|
1119
1131
|
const switchboardV2 = await SwitchboardProgram.loadMainnet(this.connection);
|
|
1120
1132
|
|
|
1121
1133
|
for (const reserve of this.reserves.values()) {
|
|
1134
|
+
if (reserve.state.config.status === ReserveStatus.Obsolete.discriminator) {
|
|
1135
|
+
// skip obsolete reserves
|
|
1136
|
+
continue;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1122
1139
|
const tokenMint = reserve.getLiquidityMint().toString();
|
|
1123
1140
|
const tokenName = reserve.getTokenSymbol();
|
|
1124
1141
|
const scopeOracle = reserve.state.config.tokenInfo.scopeConfiguration.priceFeed;
|
|
@@ -366,7 +366,7 @@ export class KaminoObligation {
|
|
|
366
366
|
if (obligationDeposits[i].depositReserve.equals(changeReserve)) {
|
|
367
367
|
const coll: ObligationCollateralFields = { ...obligationDeposits[i] };
|
|
368
368
|
const exchangeRate = collateralExchangeRates.get(changeReserve)!;
|
|
369
|
-
const changeInCollateral = new Decimal(changeInLamports).mul(exchangeRate);
|
|
369
|
+
const changeInCollateral = new Decimal(changeInLamports).mul(exchangeRate).toFixed(0);
|
|
370
370
|
const updatedDeposit = new Decimal(obligationDeposits[i].depositedAmount.toNumber()).add(changeInCollateral);
|
|
371
371
|
coll.depositedAmount = new BN(positiveOrZero(updatedDeposit).toString());
|
|
372
372
|
newDeposits.push(new ObligationCollateral(coll));
|
|
@@ -927,6 +927,7 @@ export class KaminoObligation {
|
|
|
927
927
|
if (elevationGroup === this.state.elevationGroup) {
|
|
928
928
|
return Decimal.min(maxBorrowAmount, liquidityAvailable);
|
|
929
929
|
} else {
|
|
930
|
+
// TODO: this is wrong, most liquidity caps are global, we should add up only the ones that are specific to this mode
|
|
930
931
|
const { amount: debtThisReserve } = this.borrows.get(reserve.address) || { amount: new Decimal(0) };
|
|
931
932
|
const liquidityAvailablePostMigration = Decimal.max(0, liquidityAvailable.minus(debtThisReserve));
|
|
932
933
|
return Decimal.min(maxBorrowAmount, liquidityAvailablePostMigration);
|
package/src/classes/reserve.ts
CHANGED
|
@@ -23,7 +23,14 @@ import {
|
|
|
23
23
|
import { FeeCalculation, Fees, ReserveDataType, ReserveFarmInfo, ReserveRewardYield, ReserveStatus } from './shared';
|
|
24
24
|
import { Reserve, ReserveFields } from '../idl_codegen/accounts';
|
|
25
25
|
import { BorrowRateCurve, CurvePointFields, ReserveConfig, UpdateConfigMode } from '../idl_codegen/types';
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
calculateAPYFromAPR,
|
|
28
|
+
getBorrowRate,
|
|
29
|
+
lamportsToNumberDecimal,
|
|
30
|
+
parseTokenSymbol,
|
|
31
|
+
positiveOrZero,
|
|
32
|
+
sameLengthArrayEquals,
|
|
33
|
+
} from './utils';
|
|
27
34
|
import { Fraction } from './fraction';
|
|
28
35
|
import BN from 'bn.js';
|
|
29
36
|
import { ActionType } from './action';
|
|
@@ -570,7 +577,7 @@ export class KaminoReserve {
|
|
|
570
577
|
return Decimal.max(new Decimal(0), maxBorrowAmount);
|
|
571
578
|
}
|
|
572
579
|
|
|
573
|
-
|
|
580
|
+
calcSimulatedBorrowRate(
|
|
574
581
|
amount: Decimal,
|
|
575
582
|
action: ActionType,
|
|
576
583
|
slot: number,
|
|
@@ -580,7 +587,20 @@ export class KaminoReserve {
|
|
|
580
587
|
const slotAdjustmentFactor = this.slotAdjustmentFactor();
|
|
581
588
|
const newUtilization = this.calcSimulatedUtilizationRatio(amount, action, slot, referralFeeBps, outflowAmount);
|
|
582
589
|
const curve = truncateBorrowCurve(this.state.config.borrowRateCurve.points);
|
|
583
|
-
return getBorrowRate(newUtilization, curve) * slotAdjustmentFactor
|
|
590
|
+
return getBorrowRate(newUtilization, curve) * slotAdjustmentFactor;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
calcSimulatedBorrowAPR(
|
|
594
|
+
amount: Decimal,
|
|
595
|
+
action: ActionType,
|
|
596
|
+
slot: number,
|
|
597
|
+
referralFeeBps: number,
|
|
598
|
+
outflowAmount?: Decimal
|
|
599
|
+
) {
|
|
600
|
+
return (
|
|
601
|
+
this.calcSimulatedBorrowRate(amount, action, slot, referralFeeBps, outflowAmount) +
|
|
602
|
+
this.getFixedHostInterestRate().toNumber()
|
|
603
|
+
);
|
|
584
604
|
}
|
|
585
605
|
|
|
586
606
|
calcSimulatedSupplyAPR(
|
|
@@ -591,7 +611,7 @@ export class KaminoReserve {
|
|
|
591
611
|
outflowAmount?: Decimal
|
|
592
612
|
) {
|
|
593
613
|
const newUtilization = this.calcSimulatedUtilizationRatio(amount, action, slot, referralFeeBps, outflowAmount);
|
|
594
|
-
const simulatedBorrowAPR = this.
|
|
614
|
+
const simulatedBorrowAPR = this.calcSimulatedBorrowRate(amount, action, slot, referralFeeBps, outflowAmount);
|
|
595
615
|
const protocolTakeRatePct = 1 - this.state.config.protocolTakeRatePct / 100;
|
|
596
616
|
|
|
597
617
|
return newUtilization * simulatedBorrowAPR * protocolTakeRatePct;
|
|
@@ -1746,17 +1766,11 @@ export function parseForChangesReserveConfigAndGetIxs(
|
|
|
1746
1766
|
),
|
|
1747
1767
|
});
|
|
1748
1768
|
} else {
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
UpdateConfigMode.UpdateTokenInfoName.discriminator,
|
|
1755
|
-
tokenInfo.name
|
|
1756
|
-
),
|
|
1757
|
-
});
|
|
1758
|
-
break;
|
|
1759
|
-
}
|
|
1769
|
+
if (!sameLengthArrayEquals(reserve.config.tokenInfo.name, tokenInfo.name)) {
|
|
1770
|
+
updateReserveIxnsArgs.push({
|
|
1771
|
+
mode: UpdateConfigMode.UpdateTokenInfoName.discriminator,
|
|
1772
|
+
value: updateReserveConfigEncodedValue(UpdateConfigMode.UpdateTokenInfoName.discriminator, tokenInfo.name),
|
|
1773
|
+
});
|
|
1760
1774
|
}
|
|
1761
1775
|
if (!reserve.config.tokenInfo.heuristic.lower.eq(tokenInfo.heuristic.lower)) {
|
|
1762
1776
|
updateReserveIxnsArgs.push({
|
|
@@ -1812,31 +1826,33 @@ export function parseForChangesReserveConfigAndGetIxs(
|
|
|
1812
1826
|
),
|
|
1813
1827
|
});
|
|
1814
1828
|
}
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
reserve.config.tokenInfo.scopeConfiguration.priceChain
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
}
|
|
1829
|
+
if (
|
|
1830
|
+
!sameLengthArrayEquals(
|
|
1831
|
+
reserve.config.tokenInfo.scopeConfiguration.priceChain,
|
|
1832
|
+
tokenInfo.scopeConfiguration.priceChain
|
|
1833
|
+
)
|
|
1834
|
+
) {
|
|
1835
|
+
updateReserveIxnsArgs.push({
|
|
1836
|
+
mode: UpdateConfigMode.UpdateTokenInfoScopeChain.discriminator,
|
|
1837
|
+
value: updateReserveConfigEncodedValue(
|
|
1838
|
+
UpdateConfigMode.UpdateTokenInfoScopeChain.discriminator,
|
|
1839
|
+
tokenInfo.scopeConfiguration.priceChain
|
|
1840
|
+
),
|
|
1841
|
+
});
|
|
1828
1842
|
}
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1843
|
+
if (
|
|
1844
|
+
!sameLengthArrayEquals(
|
|
1845
|
+
reserve.config.tokenInfo.scopeConfiguration.twapChain,
|
|
1846
|
+
tokenInfo.scopeConfiguration.twapChain
|
|
1847
|
+
)
|
|
1848
|
+
) {
|
|
1849
|
+
updateReserveIxnsArgs.push({
|
|
1850
|
+
mode: UpdateConfigMode.UpdateTokenInfoScopeTwap.discriminator,
|
|
1851
|
+
value: updateReserveConfigEncodedValue(
|
|
1852
|
+
UpdateConfigMode.UpdateTokenInfoScopeTwap.discriminator,
|
|
1853
|
+
tokenInfo.scopeConfiguration.twapChain
|
|
1854
|
+
),
|
|
1855
|
+
});
|
|
1840
1856
|
}
|
|
1841
1857
|
if (
|
|
1842
1858
|
!reserve.config.tokenInfo.switchboardConfiguration.priceAggregator.equals(
|
package/src/classes/utils.ts
CHANGED
|
@@ -142,6 +142,29 @@ export const parseTokenSymbol = (tokenSymbol: number[]): string => {
|
|
|
142
142
|
return String.fromCharCode(...tokenSymbol.filter((x) => x > 0));
|
|
143
143
|
};
|
|
144
144
|
|
|
145
|
+
export function parseZeroPaddedUtf8(utf8Array: number[]): string {
|
|
146
|
+
for (let last = utf8Array.length - 1; last >= 0; last--) {
|
|
147
|
+
const trailing_zero = utf8Array[last];
|
|
148
|
+
if (trailing_zero != 0) {
|
|
149
|
+
const encoding = new Uint8Array(last + 1);
|
|
150
|
+
for (let i = 0; i <= last; i++) {
|
|
151
|
+
encoding[i] = utf8Array[i];
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return new TextDecoder().decode();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function renderZeroPaddedUtf8(str: string, utf8ArrayLength: number): number[] {
|
|
160
|
+
const encoding = new TextEncoder().encode(str);
|
|
161
|
+
const result = new Array<number>(utf8ArrayLength);
|
|
162
|
+
for (let i = 0; i < result.length; i++) {
|
|
163
|
+
result[i] = i < encoding.length ? encoding[i] : 0;
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
|
|
145
168
|
export function sleep(ms: number) {
|
|
146
169
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
147
170
|
}
|
|
@@ -190,3 +213,10 @@ export function calculateAPRFromAPY(apy: Decimal.Value) {
|
|
|
190
213
|
.minus(1)
|
|
191
214
|
.times(SLOTS_PER_YEAR);
|
|
192
215
|
}
|
|
216
|
+
|
|
217
|
+
export function sameLengthArrayEquals(left: Array<number>, right: Array<number>): boolean {
|
|
218
|
+
if (left.length != right.length) {
|
|
219
|
+
throw new Error(`Not same length: ${left.length} != ${left.length}`);
|
|
220
|
+
}
|
|
221
|
+
return left.every((value, index) => value === right[index]);
|
|
222
|
+
}
|
package/src/classes/vault.ts
CHANGED
|
@@ -23,6 +23,8 @@ import {
|
|
|
23
23
|
WRAPPED_SOL_MINT,
|
|
24
24
|
} from '../lib';
|
|
25
25
|
import {
|
|
26
|
+
// closeVault,
|
|
27
|
+
// CloseVaultAccounts,
|
|
26
28
|
DepositAccounts,
|
|
27
29
|
DepositArgs,
|
|
28
30
|
initVault,
|
|
@@ -44,6 +46,8 @@ import { PROGRAM_ID } from '../idl_codegen/programId';
|
|
|
44
46
|
import { DEFAULT_RECENT_SLOT_DURATION_MS, ReserveWithAddress } from './reserve';
|
|
45
47
|
import { Fraction } from './fraction';
|
|
46
48
|
import { lendingMarketAuthPda } from '../utils/seeds';
|
|
49
|
+
import bs58 from 'bs58';
|
|
50
|
+
import { getProgramAccounts } from '../utils/rpc';
|
|
47
51
|
|
|
48
52
|
export const kaminoVaultId = new PublicKey('kvauTFR8qm1dhniz6pYuBZkuene3Hfrs1VQhVRgCNrr');
|
|
49
53
|
|
|
@@ -124,6 +128,7 @@ export class KaminoVaultClient {
|
|
|
124
128
|
systemProgram: SystemProgram.programId,
|
|
125
129
|
rent: SYSVAR_RENT_PUBKEY,
|
|
126
130
|
tokenProgram: vaultConfig.tokenMintProgramId,
|
|
131
|
+
sharesTokenProgram: TOKEN_PROGRAM_ID,
|
|
127
132
|
};
|
|
128
133
|
const initVaultIx = initVault(initVaultAccounts, this._kaminoVaultProgramId);
|
|
129
134
|
|
|
@@ -145,7 +150,11 @@ export class KaminoVaultClient {
|
|
|
145
150
|
const vaultState: VaultState = await vault.getState(this.getConnection());
|
|
146
151
|
const reserveState: Reserve = reserveAllocationConfig.getReserveState();
|
|
147
152
|
|
|
148
|
-
const cTokenVault = getCTokenVaultPda(
|
|
153
|
+
const cTokenVault = getCTokenVaultPda(
|
|
154
|
+
vault.address,
|
|
155
|
+
reserveAllocationConfig.getReserveAddress(),
|
|
156
|
+
this._kaminoVaultProgramId
|
|
157
|
+
);
|
|
149
158
|
|
|
150
159
|
const updateReserveAllocationAccounts: UpdateReserveAllocationAccounts = {
|
|
151
160
|
adminAuthority: vaultState.adminAuthority,
|
|
@@ -171,6 +180,17 @@ export class KaminoVaultClient {
|
|
|
171
180
|
);
|
|
172
181
|
}
|
|
173
182
|
|
|
183
|
+
// async closeVaultIx(vault: KaminoVault): Promise<TransactionInstruction> {
|
|
184
|
+
// const vaultState: VaultState = await vault.getState(this.getConnection());
|
|
185
|
+
|
|
186
|
+
// const closeVaultAccounts: CloseVaultAccounts = {
|
|
187
|
+
// adminAuthority: vaultState.adminAuthority,
|
|
188
|
+
// vaultState: vault.address,
|
|
189
|
+
// };
|
|
190
|
+
|
|
191
|
+
// return closeVault(closeVaultAccounts, this._kaminoVaultProgramId);
|
|
192
|
+
// }
|
|
193
|
+
|
|
174
194
|
/**
|
|
175
195
|
* This function creates instructions to deposit into a vault. It will also create ATA creation instructions for the vault shares that the user receives in return
|
|
176
196
|
* @param user - user to deposit
|
|
@@ -225,6 +245,8 @@ export class KaminoVaultClient {
|
|
|
225
245
|
userSharesAta: userSharesAta,
|
|
226
246
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
227
247
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
248
|
+
klendProgram: this._kaminoLendProgramId,
|
|
249
|
+
sharesTokenProgram: TOKEN_PROGRAM_ID,
|
|
228
250
|
};
|
|
229
251
|
|
|
230
252
|
const depositArgs: DepositArgs = {
|
|
@@ -235,10 +257,24 @@ export class KaminoVaultClient {
|
|
|
235
257
|
|
|
236
258
|
const vaultReserves = this.getVaultReserves(vaultState);
|
|
237
259
|
|
|
238
|
-
const
|
|
239
|
-
|
|
260
|
+
const vaultReservesState = await this.loadVaultReserves(vaultState);
|
|
261
|
+
|
|
262
|
+
let vaultReservesAccountMetas: AccountMeta[] = [];
|
|
263
|
+
let vaultReservesLendingMarkets: AccountMeta[] = [];
|
|
264
|
+
vaultReserves.forEach((reserve) => {
|
|
265
|
+
const reserveState = vaultReservesState.get(reserve);
|
|
266
|
+
if (reserveState === undefined) {
|
|
267
|
+
throw new Error(`Reserve ${reserve.toBase58()} not found`);
|
|
268
|
+
}
|
|
269
|
+
vaultReservesAccountMetas = vaultReservesAccountMetas.concat([
|
|
270
|
+
{ pubkey: reserve, isSigner: false, isWritable: true },
|
|
271
|
+
]);
|
|
272
|
+
vaultReservesLendingMarkets = vaultReservesLendingMarkets.concat([
|
|
273
|
+
{ pubkey: reserveState.state.lendingMarket, isSigner: false, isWritable: false },
|
|
274
|
+
]);
|
|
240
275
|
});
|
|
241
276
|
depositIx.keys = depositIx.keys.concat(vaultReservesAccountMetas);
|
|
277
|
+
depositIx.keys = depositIx.keys.concat(vaultReservesLendingMarkets);
|
|
242
278
|
|
|
243
279
|
return [...createAtasIxns, depositIx, ...closeAtasIxns];
|
|
244
280
|
}
|
|
@@ -341,7 +377,7 @@ export class KaminoVaultClient {
|
|
|
341
377
|
* @param kaminoVault - vault to invest from
|
|
342
378
|
* @returns - an array of invest instructions for each invest action required for the vault reserves
|
|
343
379
|
*/
|
|
344
|
-
async investAllReservesIxs(vault: KaminoVault): Promise<TransactionInstruction[]> {
|
|
380
|
+
async investAllReservesIxs(payer: PublicKey, vault: KaminoVault): Promise<TransactionInstruction[]> {
|
|
345
381
|
//TODO: Order invest ixns by - invest that removes first, then invest that adds
|
|
346
382
|
|
|
347
383
|
const vaultState = await vault.getState(this._connection);
|
|
@@ -352,7 +388,7 @@ export class KaminoVaultClient {
|
|
|
352
388
|
if (reserveState === null) {
|
|
353
389
|
throw new Error(`Reserve ${reserve.toBase58()} not found`);
|
|
354
390
|
}
|
|
355
|
-
investIxns.push(await this.investSingleReserveIxs(vault, { address: reserve, state: reserveState }));
|
|
391
|
+
investIxns.push(await this.investSingleReserveIxs(payer, vault, { address: reserve, state: reserveState }));
|
|
356
392
|
}
|
|
357
393
|
|
|
358
394
|
return investIxns;
|
|
@@ -364,14 +400,21 @@ export class KaminoVaultClient {
|
|
|
364
400
|
* @param reserve - reserve to invest into or disinvest from
|
|
365
401
|
* @returns - an array of invest instructions for each invest action required for the vault reserves
|
|
366
402
|
*/
|
|
367
|
-
async investSingleReserveIxs(
|
|
403
|
+
async investSingleReserveIxs(
|
|
404
|
+
payer: PublicKey,
|
|
405
|
+
vault: KaminoVault,
|
|
406
|
+
reserve: ReserveWithAddress
|
|
407
|
+
): Promise<TransactionInstruction> {
|
|
368
408
|
const vaultState = await vault.getState(this._connection);
|
|
369
409
|
|
|
370
|
-
const cTokenVault = getCTokenVaultPda(reserve.address, this._kaminoVaultProgramId);
|
|
410
|
+
const cTokenVault = getCTokenVaultPda(vault.address, reserve.address, this._kaminoVaultProgramId);
|
|
371
411
|
const lendingMarketAuth = lendingMarketAuthPda(reserve.state.lendingMarket, this._kaminoLendProgramId)[0];
|
|
372
412
|
|
|
413
|
+
// todo: create ata if needed here
|
|
414
|
+
const payerTokenAta = getAssociatedTokenAddress(vaultState.tokenMint, payer);
|
|
415
|
+
|
|
373
416
|
const investAccounts: InvestAccounts = {
|
|
374
|
-
|
|
417
|
+
payer,
|
|
375
418
|
vaultState: vault.address,
|
|
376
419
|
tokenVault: vaultState.tokenVault,
|
|
377
420
|
baseVaultAuthority: vaultState.baseVaultAuthority,
|
|
@@ -385,6 +428,10 @@ export class KaminoVaultClient {
|
|
|
385
428
|
klendProgram: this._kaminoLendProgramId,
|
|
386
429
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
387
430
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
431
|
+
payerTokenAccount: payerTokenAta,
|
|
432
|
+
tokenMint: vaultState.tokenMint,
|
|
433
|
+
reserveCollateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
434
|
+
sharesTokenProgram: TOKEN_PROGRAM_ID,
|
|
388
435
|
};
|
|
389
436
|
|
|
390
437
|
const investIx = invest(investAccounts, this._kaminoVaultProgramId);
|
|
@@ -398,7 +445,7 @@ export class KaminoVaultClient {
|
|
|
398
445
|
return investIx;
|
|
399
446
|
}
|
|
400
447
|
|
|
401
|
-
private withdrawIxn(
|
|
448
|
+
private async withdrawIxn(
|
|
402
449
|
user: PublicKey,
|
|
403
450
|
vault: KaminoVault,
|
|
404
451
|
vaultState: VaultState,
|
|
@@ -407,7 +454,7 @@ export class KaminoVaultClient {
|
|
|
407
454
|
userSharesAta: PublicKey,
|
|
408
455
|
userTokenAta: PublicKey,
|
|
409
456
|
shareAmountLamports: Decimal
|
|
410
|
-
): TransactionInstruction {
|
|
457
|
+
): Promise<TransactionInstruction> {
|
|
411
458
|
const lendingMarketAuth = lendingMarketAuthPda(marketWithAddress.address, this._kaminoLendProgramId)[0];
|
|
412
459
|
|
|
413
460
|
const withdrawAccounts: WithdrawAccounts = {
|
|
@@ -422,13 +469,15 @@ export class KaminoVaultClient {
|
|
|
422
469
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
423
470
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
424
471
|
reserve: reserve.address,
|
|
425
|
-
ctokenVault: getCTokenVaultPda(reserve.address, this._kaminoVaultProgramId),
|
|
472
|
+
ctokenVault: getCTokenVaultPda(vault.address, reserve.address, this._kaminoVaultProgramId),
|
|
426
473
|
/** CPI accounts */
|
|
427
474
|
lendingMarket: marketWithAddress.address,
|
|
428
475
|
lendingMarketAuthority: lendingMarketAuth,
|
|
429
476
|
reserveLiquiditySupply: reserve.state.liquidity.supplyVault,
|
|
430
477
|
reserveCollateralMint: reserve.state.collateral.mintPubkey,
|
|
431
478
|
klendProgram: this._kaminoLendProgramId,
|
|
479
|
+
reserveCollateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
480
|
+
sharesTokenProgram: TOKEN_PROGRAM_ID,
|
|
432
481
|
};
|
|
433
482
|
|
|
434
483
|
const withdrawArgs: WithdrawArgs = {
|
|
@@ -438,10 +487,26 @@ export class KaminoVaultClient {
|
|
|
438
487
|
const withdrawIxn = withdraw(withdrawArgs, withdrawAccounts, this._kaminoVaultProgramId);
|
|
439
488
|
|
|
440
489
|
const vaultReserves = this.getVaultReserves(vaultState);
|
|
441
|
-
const
|
|
442
|
-
|
|
490
|
+
const vaultReservesState = await this.loadVaultReserves(vaultState);
|
|
491
|
+
|
|
492
|
+
let vaultReservesAccountMetas: AccountMeta[] = [];
|
|
493
|
+
let vaultReservesLendingMarkets: AccountMeta[] = [];
|
|
494
|
+
|
|
495
|
+
vaultReserves.forEach((reserve) => {
|
|
496
|
+
const reserveState = vaultReservesState.get(reserve);
|
|
497
|
+
if (reserveState === undefined) {
|
|
498
|
+
throw new Error(`Reserve ${reserve.toBase58()} not found`);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
vaultReservesAccountMetas = vaultReservesAccountMetas.concat([
|
|
502
|
+
{ pubkey: reserve, isSigner: false, isWritable: true },
|
|
503
|
+
]);
|
|
504
|
+
vaultReservesLendingMarkets = vaultReservesLendingMarkets.concat([
|
|
505
|
+
{ pubkey: reserveState.state.lendingMarket, isSigner: false, isWritable: false },
|
|
506
|
+
]);
|
|
443
507
|
});
|
|
444
508
|
withdrawIxn.keys = withdrawIxn.keys.concat(vaultReservesAccountMetas);
|
|
509
|
+
withdrawIxn.keys = withdrawIxn.keys.concat(vaultReservesLendingMarkets);
|
|
445
510
|
|
|
446
511
|
return withdrawIxn;
|
|
447
512
|
}
|
|
@@ -590,6 +655,44 @@ export class KaminoVaultClient {
|
|
|
590
655
|
return vaultTokensPerShare;
|
|
591
656
|
}
|
|
592
657
|
|
|
658
|
+
/**
|
|
659
|
+
* Get all vaults
|
|
660
|
+
* @returns an array of all vaults
|
|
661
|
+
*/
|
|
662
|
+
async getAllVaults(): Promise<KaminoVault[]> {
|
|
663
|
+
const filters = [
|
|
664
|
+
{
|
|
665
|
+
dataSize: VaultState.layout.span + 8,
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
memcmp: {
|
|
669
|
+
offset: 0,
|
|
670
|
+
bytes: bs58.encode(VaultState.discriminator),
|
|
671
|
+
},
|
|
672
|
+
},
|
|
673
|
+
];
|
|
674
|
+
|
|
675
|
+
const [kaminoVaults] = await Promise.all([
|
|
676
|
+
getProgramAccounts(this._connection, this._kaminoVaultProgramId, {
|
|
677
|
+
commitment: this._connection.commitment ?? 'processed',
|
|
678
|
+
filters,
|
|
679
|
+
}),
|
|
680
|
+
]);
|
|
681
|
+
|
|
682
|
+
return kaminoVaults.map((kaminoVault) => {
|
|
683
|
+
if (kaminoVault.account === null) {
|
|
684
|
+
throw new Error(`kaminoVault with pubkey ${kaminoVault.pubkey.toString()} does not exist`);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
const kaminoVaultAccount = VaultState.decode(kaminoVault.account.data);
|
|
688
|
+
if (!kaminoVaultAccount) {
|
|
689
|
+
throw Error(`kaminoVault with pubkey ${kaminoVault.pubkey.toString()} could not be decoded`);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
return new KaminoVault(kaminoVault.pubkey, kaminoVaultAccount, this._kaminoVaultProgramId);
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
|
|
593
696
|
/**
|
|
594
697
|
* This will return an unsorted hash map of all reserves that the given vault has allocations for, toghether with the amount that can be withdrawn from each of the reserves
|
|
595
698
|
* @param vault - the kamino vault to get available liquidity to withdraw for
|
|
@@ -673,40 +776,6 @@ export class KaminoVaultClient {
|
|
|
673
776
|
|
|
674
777
|
return kaminoReserves;
|
|
675
778
|
}
|
|
676
|
-
|
|
677
|
-
/**
|
|
678
|
-
* Get all vaults
|
|
679
|
-
* @returns an array of all vaults
|
|
680
|
-
*/
|
|
681
|
-
async getAllVaults(): Promise<KaminoVault[]> {
|
|
682
|
-
const { getProgramAccounts } = await import('../utils/rpc');
|
|
683
|
-
const filters = [
|
|
684
|
-
{
|
|
685
|
-
dataSize: VaultState.layout.span + 8,
|
|
686
|
-
},
|
|
687
|
-
];
|
|
688
|
-
|
|
689
|
-
const [, kaminoVaults] = await Promise.all([
|
|
690
|
-
this._connection.getSlot(),
|
|
691
|
-
getProgramAccounts(this._connection, this._kaminoVaultProgramId, {
|
|
692
|
-
commitment: this._connection.commitment ?? 'processed',
|
|
693
|
-
filters,
|
|
694
|
-
}),
|
|
695
|
-
]);
|
|
696
|
-
|
|
697
|
-
return kaminoVaults.map((kaminoVault) => {
|
|
698
|
-
if (kaminoVault.account === null) {
|
|
699
|
-
throw new Error('Invalid account');
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
const kaminoVaultAccount = VaultState.decode(kaminoVault.account.data);
|
|
703
|
-
if (!kaminoVaultAccount) {
|
|
704
|
-
throw Error('Could not parse obligation.');
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
return new KaminoVault(kaminoVault.pubkey, kaminoVaultAccount, this._kaminoVaultProgramId);
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
779
|
} // KaminoVaultClient
|
|
711
780
|
|
|
712
781
|
export class KaminoVault {
|
|
@@ -804,9 +873,14 @@ export class ReserveAllocationConfig {
|
|
|
804
873
|
}
|
|
805
874
|
}
|
|
806
875
|
|
|
807
|
-
export function getCTokenVaultPda(reserveAddress: PublicKey, kaminoVaultProgramId: PublicKey) {
|
|
876
|
+
export function getCTokenVaultPda(vaultAddress: PublicKey, reserveAddress: PublicKey, kaminoVaultProgramId: PublicKey) {
|
|
808
877
|
return PublicKey.findProgramAddressSync(
|
|
809
|
-
[Buffer.from(CTOKEN_VAULT_SEED), reserveAddress.toBytes()],
|
|
878
|
+
[Buffer.from(CTOKEN_VAULT_SEED), vaultAddress.toBytes(), reserveAddress.toBytes()],
|
|
810
879
|
kaminoVaultProgramId
|
|
811
880
|
)[0];
|
|
812
881
|
}
|
|
882
|
+
|
|
883
|
+
export type VaultHolder = {
|
|
884
|
+
holderPubkey: PublicKey;
|
|
885
|
+
amount: Decimal;
|
|
886
|
+
};
|
|
@@ -87,7 +87,7 @@ async function main() {
|
|
|
87
87
|
|
|
88
88
|
commands
|
|
89
89
|
.command('add-asset-to-market')
|
|
90
|
-
.requiredOption('--market <string>', 'Market
|
|
90
|
+
.requiredOption('--market <string>', 'Market address to add asset to')
|
|
91
91
|
.requiredOption('--mint <string>', 'Reserve liquidity token mint')
|
|
92
92
|
.requiredOption('--mint-program-id <string>', 'Reserve liquidity token mint program id')
|
|
93
93
|
.requiredOption('--reserve-config-path <string>', 'Path for the reserve config')
|
|
@@ -296,6 +296,24 @@ async function main() {
|
|
|
296
296
|
mode === 'execute' && console.log('Vault allocation updated:', updateVaultAllocationSig);
|
|
297
297
|
});
|
|
298
298
|
|
|
299
|
+
// commands
|
|
300
|
+
// .command('close-vault')
|
|
301
|
+
// .requiredOption('--vault <string>', 'Vault address')
|
|
302
|
+
// .option(`--staging`, 'If true, will use the staging programs')
|
|
303
|
+
// .action(async ({vault, staging}) => {
|
|
304
|
+
// console.log("silviuuuu vault", vault);
|
|
305
|
+
// const env = initializeClient(false, staging);
|
|
306
|
+
// const vaultAddress = new PublicKey(vault);
|
|
307
|
+
|
|
308
|
+
// const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
|
|
309
|
+
|
|
310
|
+
// const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
|
|
311
|
+
// const instructions = await kaminoManager.closeVault(kaminoVault);
|
|
312
|
+
|
|
313
|
+
// const closeVaultSig = await processTxn(env.client, env.payer, [instructions], 'execute', 2500, []);
|
|
314
|
+
// console.log('Vault closed:', closeVaultSig);
|
|
315
|
+
// });
|
|
316
|
+
|
|
299
317
|
commands.command('get-oracle-mappings').action(async () => {
|
|
300
318
|
const env = initializeClient(false, false);
|
|
301
319
|
const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
|
|
@@ -51,6 +51,8 @@ export interface LendingMarketFields {
|
|
|
51
51
|
/** Min net value accepted to be found in a position after any lending action in an obligation (scaled by quote currency decimals) */
|
|
52
52
|
minNetValueInObligationSf: BN
|
|
53
53
|
minValueSkipLiquidationLtvBfChecks: BN
|
|
54
|
+
/** Market name, zero-padded. */
|
|
55
|
+
name: Array<number>
|
|
54
56
|
padding1: Array<BN>
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -101,6 +103,8 @@ export interface LendingMarketJSON {
|
|
|
101
103
|
/** Min net value accepted to be found in a position after any lending action in an obligation (scaled by quote currency decimals) */
|
|
102
104
|
minNetValueInObligationSf: string
|
|
103
105
|
minValueSkipLiquidationLtvBfChecks: string
|
|
106
|
+
/** Market name, zero-padded. */
|
|
107
|
+
name: Array<number>
|
|
104
108
|
padding1: Array<string>
|
|
105
109
|
}
|
|
106
110
|
|
|
@@ -151,6 +155,8 @@ export class LendingMarket {
|
|
|
151
155
|
/** Min net value accepted to be found in a position after any lending action in an obligation (scaled by quote currency decimals) */
|
|
152
156
|
readonly minNetValueInObligationSf: BN
|
|
153
157
|
readonly minValueSkipLiquidationLtvBfChecks: BN
|
|
158
|
+
/** Market name, zero-padded. */
|
|
159
|
+
readonly name: Array<number>
|
|
154
160
|
readonly padding1: Array<BN>
|
|
155
161
|
|
|
156
162
|
static readonly discriminator = Buffer.from([
|
|
@@ -180,7 +186,8 @@ export class LendingMarket {
|
|
|
180
186
|
borsh.array(borsh.u64(), 90, "elevationGroupPadding"),
|
|
181
187
|
borsh.u128("minNetValueInObligationSf"),
|
|
182
188
|
borsh.u64("minValueSkipLiquidationLtvBfChecks"),
|
|
183
|
-
borsh.array(borsh.
|
|
189
|
+
borsh.array(borsh.u8(), 32, "name"),
|
|
190
|
+
borsh.array(borsh.u64(), 173, "padding1"),
|
|
184
191
|
])
|
|
185
192
|
|
|
186
193
|
constructor(fields: LendingMarketFields) {
|
|
@@ -212,6 +219,7 @@ export class LendingMarket {
|
|
|
212
219
|
this.minNetValueInObligationSf = fields.minNetValueInObligationSf
|
|
213
220
|
this.minValueSkipLiquidationLtvBfChecks =
|
|
214
221
|
fields.minValueSkipLiquidationLtvBfChecks
|
|
222
|
+
this.name = fields.name
|
|
215
223
|
this.padding1 = fields.padding1
|
|
216
224
|
}
|
|
217
225
|
|
|
@@ -287,6 +295,7 @@ export class LendingMarket {
|
|
|
287
295
|
minNetValueInObligationSf: dec.minNetValueInObligationSf,
|
|
288
296
|
minValueSkipLiquidationLtvBfChecks:
|
|
289
297
|
dec.minValueSkipLiquidationLtvBfChecks,
|
|
298
|
+
name: dec.name,
|
|
290
299
|
padding1: dec.padding1,
|
|
291
300
|
})
|
|
292
301
|
}
|
|
@@ -320,6 +329,7 @@ export class LendingMarket {
|
|
|
320
329
|
minNetValueInObligationSf: this.minNetValueInObligationSf.toString(),
|
|
321
330
|
minValueSkipLiquidationLtvBfChecks:
|
|
322
331
|
this.minValueSkipLiquidationLtvBfChecks.toString(),
|
|
332
|
+
name: this.name,
|
|
323
333
|
padding1: this.padding1.map((item) => item.toString()),
|
|
324
334
|
}
|
|
325
335
|
}
|
|
@@ -358,6 +368,7 @@ export class LendingMarket {
|
|
|
358
368
|
minValueSkipLiquidationLtvBfChecks: new BN(
|
|
359
369
|
obj.minValueSkipLiquidationLtvBfChecks
|
|
360
370
|
),
|
|
371
|
+
name: obj.name,
|
|
361
372
|
padding1: obj.padding1.map((item) => new BN(item)),
|
|
362
373
|
})
|
|
363
374
|
}
|