@kamino-finance/klend-sdk 5.0.3 → 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/manager.d.ts +38 -4
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +98 -4
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +2 -25
- package/dist/classes/market.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 +14 -0
- package/dist/client_kamino_manager.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/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +6 -0
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/leverage/calcs.d.ts +28 -1
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +204 -8
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/index.d.ts +1 -0
- package/dist/leverage/index.d.ts.map +1 -1
- package/dist/leverage/index.js +1 -0
- package/dist/leverage/index.js.map +1 -1
- package/dist/leverage/operations.d.ts +14 -241
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +508 -776
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +173 -0
- package/dist/leverage/types.d.ts.map +1 -0
- package/dist/leverage/types.js +3 -0
- package/dist/leverage/types.js.map +1 -0
- package/dist/leverage/utils.d.ts +5 -5
- package/dist/leverage/utils.d.ts.map +1 -1
- package/dist/leverage/utils.js +68 -33
- package/dist/leverage/utils.js.map +1 -1
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +2 -1
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/fuzz.d.ts +3 -0
- package/dist/utils/fuzz.d.ts.map +1 -0
- package/dist/utils/fuzz.js +11 -0
- package/dist/utils/fuzz.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.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/manager.ts +122 -4
- package/src/classes/market.ts +1 -1
- package/src/classes/vault.ts +123 -49
- package/src/client_kamino_manager.ts +18 -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/lending_operations/repay_with_collateral_operations.ts +2 -0
- package/src/leverage/calcs.ts +315 -8
- package/src/leverage/index.ts +1 -0
- package/src/leverage/operations.ts +1079 -1331
- package/src/leverage/types.ts +211 -0
- package/src/leverage/utils.ts +103 -64
- package/src/utils/constants.ts +2 -0
- package/src/utils/fuzz.ts +5 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/rpc.ts +2 -1
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
|
+
};
|
|
@@ -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);
|
|
@@ -1,136 +1,148 @@
|
|
|
1
|
-
import { PublicKey, Connection } from
|
|
2
|
-
import BN from
|
|
3
|
-
import * as borsh from
|
|
4
|
-
import * as types from
|
|
5
|
-
import { PROGRAM_ID } from
|
|
1
|
+
import { PublicKey, Connection } from "@solana/web3.js"
|
|
2
|
+
import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
3
|
+
import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
4
|
+
import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
5
|
+
import { PROGRAM_ID } from "../programId"
|
|
6
6
|
|
|
7
7
|
export interface ReserveFields {
|
|
8
8
|
/** Version of the reserve */
|
|
9
|
-
version: BN
|
|
9
|
+
version: BN
|
|
10
10
|
/** Last slot when supply and rates updated */
|
|
11
|
-
lastUpdate: types.LastUpdateFields
|
|
11
|
+
lastUpdate: types.LastUpdateFields
|
|
12
12
|
/** Lending market address */
|
|
13
|
-
lendingMarket: PublicKey
|
|
14
|
-
farmCollateral: PublicKey
|
|
15
|
-
farmDebt: PublicKey
|
|
13
|
+
lendingMarket: PublicKey
|
|
14
|
+
farmCollateral: PublicKey
|
|
15
|
+
farmDebt: PublicKey
|
|
16
16
|
/** Reserve liquidity */
|
|
17
|
-
liquidity: types.ReserveLiquidityFields
|
|
18
|
-
reserveLiquidityPadding: Array<BN
|
|
17
|
+
liquidity: types.ReserveLiquidityFields
|
|
18
|
+
reserveLiquidityPadding: Array<BN>
|
|
19
19
|
/** Reserve collateral */
|
|
20
|
-
collateral: types.ReserveCollateralFields
|
|
21
|
-
reserveCollateralPadding: Array<BN
|
|
20
|
+
collateral: types.ReserveCollateralFields
|
|
21
|
+
reserveCollateralPadding: Array<BN>
|
|
22
22
|
/** Reserve configuration values */
|
|
23
|
-
config: types.ReserveConfigFields
|
|
24
|
-
configPadding: Array<BN
|
|
25
|
-
borrowedAmountOutsideElevationGroup: BN
|
|
23
|
+
config: types.ReserveConfigFields
|
|
24
|
+
configPadding: Array<BN>
|
|
25
|
+
borrowedAmountOutsideElevationGroup: BN
|
|
26
26
|
/**
|
|
27
27
|
* Amount of token borrowed in lamport of debt asset in the given
|
|
28
28
|
* elevation group when this reserve is part of the collaterals.
|
|
29
29
|
*/
|
|
30
|
-
borrowedAmountsAgainstThisReserveInElevationGroups: Array<BN
|
|
31
|
-
padding: Array<BN
|
|
30
|
+
borrowedAmountsAgainstThisReserveInElevationGroups: Array<BN>
|
|
31
|
+
padding: Array<BN>
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export interface ReserveJSON {
|
|
35
35
|
/** Version of the reserve */
|
|
36
|
-
version: string
|
|
36
|
+
version: string
|
|
37
37
|
/** Last slot when supply and rates updated */
|
|
38
|
-
lastUpdate: types.LastUpdateJSON
|
|
38
|
+
lastUpdate: types.LastUpdateJSON
|
|
39
39
|
/** Lending market address */
|
|
40
|
-
lendingMarket: string
|
|
41
|
-
farmCollateral: string
|
|
42
|
-
farmDebt: string
|
|
40
|
+
lendingMarket: string
|
|
41
|
+
farmCollateral: string
|
|
42
|
+
farmDebt: string
|
|
43
43
|
/** Reserve liquidity */
|
|
44
|
-
liquidity: types.ReserveLiquidityJSON
|
|
45
|
-
reserveLiquidityPadding: Array<string
|
|
44
|
+
liquidity: types.ReserveLiquidityJSON
|
|
45
|
+
reserveLiquidityPadding: Array<string>
|
|
46
46
|
/** Reserve collateral */
|
|
47
|
-
collateral: types.ReserveCollateralJSON
|
|
48
|
-
reserveCollateralPadding: Array<string
|
|
47
|
+
collateral: types.ReserveCollateralJSON
|
|
48
|
+
reserveCollateralPadding: Array<string>
|
|
49
49
|
/** Reserve configuration values */
|
|
50
|
-
config: types.ReserveConfigJSON
|
|
51
|
-
configPadding: Array<string
|
|
52
|
-
borrowedAmountOutsideElevationGroup: string
|
|
50
|
+
config: types.ReserveConfigJSON
|
|
51
|
+
configPadding: Array<string>
|
|
52
|
+
borrowedAmountOutsideElevationGroup: string
|
|
53
53
|
/**
|
|
54
54
|
* Amount of token borrowed in lamport of debt asset in the given
|
|
55
55
|
* elevation group when this reserve is part of the collaterals.
|
|
56
56
|
*/
|
|
57
|
-
borrowedAmountsAgainstThisReserveInElevationGroups: Array<string
|
|
58
|
-
padding: Array<string
|
|
57
|
+
borrowedAmountsAgainstThisReserveInElevationGroups: Array<string>
|
|
58
|
+
padding: Array<string>
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export class Reserve {
|
|
62
62
|
/** Version of the reserve */
|
|
63
|
-
readonly version: BN
|
|
63
|
+
readonly version: BN
|
|
64
64
|
/** Last slot when supply and rates updated */
|
|
65
|
-
readonly lastUpdate: types.LastUpdate
|
|
65
|
+
readonly lastUpdate: types.LastUpdate
|
|
66
66
|
/** Lending market address */
|
|
67
|
-
readonly lendingMarket: PublicKey
|
|
68
|
-
readonly farmCollateral: PublicKey
|
|
69
|
-
readonly farmDebt: PublicKey
|
|
67
|
+
readonly lendingMarket: PublicKey
|
|
68
|
+
readonly farmCollateral: PublicKey
|
|
69
|
+
readonly farmDebt: PublicKey
|
|
70
70
|
/** Reserve liquidity */
|
|
71
|
-
readonly liquidity: types.ReserveLiquidity
|
|
72
|
-
readonly reserveLiquidityPadding: Array<BN
|
|
71
|
+
readonly liquidity: types.ReserveLiquidity
|
|
72
|
+
readonly reserveLiquidityPadding: Array<BN>
|
|
73
73
|
/** Reserve collateral */
|
|
74
|
-
readonly collateral: types.ReserveCollateral
|
|
75
|
-
readonly reserveCollateralPadding: Array<BN
|
|
74
|
+
readonly collateral: types.ReserveCollateral
|
|
75
|
+
readonly reserveCollateralPadding: Array<BN>
|
|
76
76
|
/** Reserve configuration values */
|
|
77
|
-
readonly config: types.ReserveConfig
|
|
78
|
-
readonly configPadding: Array<BN
|
|
79
|
-
readonly borrowedAmountOutsideElevationGroup: BN
|
|
77
|
+
readonly config: types.ReserveConfig
|
|
78
|
+
readonly configPadding: Array<BN>
|
|
79
|
+
readonly borrowedAmountOutsideElevationGroup: BN
|
|
80
80
|
/**
|
|
81
81
|
* Amount of token borrowed in lamport of debt asset in the given
|
|
82
82
|
* elevation group when this reserve is part of the collaterals.
|
|
83
83
|
*/
|
|
84
|
-
readonly borrowedAmountsAgainstThisReserveInElevationGroups: Array<BN
|
|
85
|
-
readonly padding: Array<BN
|
|
84
|
+
readonly borrowedAmountsAgainstThisReserveInElevationGroups: Array<BN>
|
|
85
|
+
readonly padding: Array<BN>
|
|
86
86
|
|
|
87
|
-
static readonly discriminator = Buffer.from([
|
|
87
|
+
static readonly discriminator = Buffer.from([
|
|
88
|
+
43, 242, 204, 202, 26, 247, 59, 127,
|
|
89
|
+
])
|
|
88
90
|
|
|
89
91
|
static readonly layout = borsh.struct([
|
|
90
|
-
borsh.u64(
|
|
91
|
-
types.LastUpdate.layout(
|
|
92
|
-
borsh.publicKey(
|
|
93
|
-
borsh.publicKey(
|
|
94
|
-
borsh.publicKey(
|
|
95
|
-
types.ReserveLiquidity.layout(
|
|
96
|
-
borsh.array(borsh.u64(), 150,
|
|
97
|
-
types.ReserveCollateral.layout(
|
|
98
|
-
borsh.array(borsh.u64(), 150,
|
|
99
|
-
types.ReserveConfig.layout(
|
|
100
|
-
borsh.array(borsh.u64(), 117,
|
|
101
|
-
borsh.u64(
|
|
102
|
-
borsh.array(
|
|
103
|
-
|
|
104
|
-
|
|
92
|
+
borsh.u64("version"),
|
|
93
|
+
types.LastUpdate.layout("lastUpdate"),
|
|
94
|
+
borsh.publicKey("lendingMarket"),
|
|
95
|
+
borsh.publicKey("farmCollateral"),
|
|
96
|
+
borsh.publicKey("farmDebt"),
|
|
97
|
+
types.ReserveLiquidity.layout("liquidity"),
|
|
98
|
+
borsh.array(borsh.u64(), 150, "reserveLiquidityPadding"),
|
|
99
|
+
types.ReserveCollateral.layout("collateral"),
|
|
100
|
+
borsh.array(borsh.u64(), 150, "reserveCollateralPadding"),
|
|
101
|
+
types.ReserveConfig.layout("config"),
|
|
102
|
+
borsh.array(borsh.u64(), 117, "configPadding"),
|
|
103
|
+
borsh.u64("borrowedAmountOutsideElevationGroup"),
|
|
104
|
+
borsh.array(
|
|
105
|
+
borsh.u64(),
|
|
106
|
+
32,
|
|
107
|
+
"borrowedAmountsAgainstThisReserveInElevationGroups"
|
|
108
|
+
),
|
|
109
|
+
borsh.array(borsh.u64(), 207, "padding"),
|
|
110
|
+
])
|
|
105
111
|
|
|
106
112
|
constructor(fields: ReserveFields) {
|
|
107
|
-
this.version = fields.version
|
|
108
|
-
this.lastUpdate = new types.LastUpdate({ ...fields.lastUpdate })
|
|
109
|
-
this.lendingMarket = fields.lendingMarket
|
|
110
|
-
this.farmCollateral = fields.farmCollateral
|
|
111
|
-
this.farmDebt = fields.farmDebt
|
|
112
|
-
this.liquidity = new types.ReserveLiquidity({ ...fields.liquidity })
|
|
113
|
-
this.reserveLiquidityPadding = fields.reserveLiquidityPadding
|
|
114
|
-
this.collateral = new types.ReserveCollateral({ ...fields.collateral })
|
|
115
|
-
this.reserveCollateralPadding = fields.reserveCollateralPadding
|
|
116
|
-
this.config = new types.ReserveConfig({ ...fields.config })
|
|
117
|
-
this.configPadding = fields.configPadding
|
|
118
|
-
this.borrowedAmountOutsideElevationGroup =
|
|
119
|
-
|
|
120
|
-
this.
|
|
113
|
+
this.version = fields.version
|
|
114
|
+
this.lastUpdate = new types.LastUpdate({ ...fields.lastUpdate })
|
|
115
|
+
this.lendingMarket = fields.lendingMarket
|
|
116
|
+
this.farmCollateral = fields.farmCollateral
|
|
117
|
+
this.farmDebt = fields.farmDebt
|
|
118
|
+
this.liquidity = new types.ReserveLiquidity({ ...fields.liquidity })
|
|
119
|
+
this.reserveLiquidityPadding = fields.reserveLiquidityPadding
|
|
120
|
+
this.collateral = new types.ReserveCollateral({ ...fields.collateral })
|
|
121
|
+
this.reserveCollateralPadding = fields.reserveCollateralPadding
|
|
122
|
+
this.config = new types.ReserveConfig({ ...fields.config })
|
|
123
|
+
this.configPadding = fields.configPadding
|
|
124
|
+
this.borrowedAmountOutsideElevationGroup =
|
|
125
|
+
fields.borrowedAmountOutsideElevationGroup
|
|
126
|
+
this.borrowedAmountsAgainstThisReserveInElevationGroups =
|
|
127
|
+
fields.borrowedAmountsAgainstThisReserveInElevationGroups
|
|
128
|
+
this.padding = fields.padding
|
|
121
129
|
}
|
|
122
130
|
|
|
123
|
-
static async fetch(
|
|
124
|
-
|
|
131
|
+
static async fetch(
|
|
132
|
+
c: Connection,
|
|
133
|
+
address: PublicKey,
|
|
134
|
+
programId: PublicKey = PROGRAM_ID
|
|
135
|
+
): Promise<Reserve | null> {
|
|
136
|
+
const info = await c.getAccountInfo(address)
|
|
125
137
|
|
|
126
138
|
if (info === null) {
|
|
127
|
-
return null
|
|
139
|
+
return null
|
|
128
140
|
}
|
|
129
141
|
if (!info.owner.equals(programId)) {
|
|
130
|
-
throw new Error("account doesn't belong to this program")
|
|
142
|
+
throw new Error("account doesn't belong to this program")
|
|
131
143
|
}
|
|
132
144
|
|
|
133
|
-
return this.decode(info.data)
|
|
145
|
+
return this.decode(info.data)
|
|
134
146
|
}
|
|
135
147
|
|
|
136
148
|
static async fetchMultiple(
|
|
@@ -138,26 +150,26 @@ export class Reserve {
|
|
|
138
150
|
addresses: PublicKey[],
|
|
139
151
|
programId: PublicKey = PROGRAM_ID
|
|
140
152
|
): Promise<Array<Reserve | null>> {
|
|
141
|
-
const infos = await c.getMultipleAccountsInfo(addresses)
|
|
153
|
+
const infos = await c.getMultipleAccountsInfo(addresses)
|
|
142
154
|
|
|
143
155
|
return infos.map((info) => {
|
|
144
156
|
if (info === null) {
|
|
145
|
-
return null
|
|
157
|
+
return null
|
|
146
158
|
}
|
|
147
159
|
if (!info.owner.equals(programId)) {
|
|
148
|
-
throw new Error("account doesn't belong to this program")
|
|
160
|
+
throw new Error("account doesn't belong to this program")
|
|
149
161
|
}
|
|
150
162
|
|
|
151
|
-
return this.decode(info.data)
|
|
152
|
-
})
|
|
163
|
+
return this.decode(info.data)
|
|
164
|
+
})
|
|
153
165
|
}
|
|
154
166
|
|
|
155
167
|
static decode(data: Buffer): Reserve {
|
|
156
168
|
if (!data.slice(0, 8).equals(Reserve.discriminator)) {
|
|
157
|
-
throw new Error(
|
|
169
|
+
throw new Error("invalid account discriminator")
|
|
158
170
|
}
|
|
159
171
|
|
|
160
|
-
const dec = Reserve.layout.decode(data.slice(8))
|
|
172
|
+
const dec = Reserve.layout.decode(data.slice(8))
|
|
161
173
|
|
|
162
174
|
return new Reserve({
|
|
163
175
|
version: dec.version,
|
|
@@ -171,10 +183,12 @@ export class Reserve {
|
|
|
171
183
|
reserveCollateralPadding: dec.reserveCollateralPadding,
|
|
172
184
|
config: types.ReserveConfig.fromDecoded(dec.config),
|
|
173
185
|
configPadding: dec.configPadding,
|
|
174
|
-
borrowedAmountOutsideElevationGroup:
|
|
175
|
-
|
|
186
|
+
borrowedAmountOutsideElevationGroup:
|
|
187
|
+
dec.borrowedAmountOutsideElevationGroup,
|
|
188
|
+
borrowedAmountsAgainstThisReserveInElevationGroups:
|
|
189
|
+
dec.borrowedAmountsAgainstThisReserveInElevationGroups,
|
|
176
190
|
padding: dec.padding,
|
|
177
|
-
})
|
|
191
|
+
})
|
|
178
192
|
}
|
|
179
193
|
|
|
180
194
|
toJSON(): ReserveJSON {
|
|
@@ -185,17 +199,23 @@ export class Reserve {
|
|
|
185
199
|
farmCollateral: this.farmCollateral.toString(),
|
|
186
200
|
farmDebt: this.farmDebt.toString(),
|
|
187
201
|
liquidity: this.liquidity.toJSON(),
|
|
188
|
-
reserveLiquidityPadding: this.reserveLiquidityPadding.map((item) =>
|
|
202
|
+
reserveLiquidityPadding: this.reserveLiquidityPadding.map((item) =>
|
|
203
|
+
item.toString()
|
|
204
|
+
),
|
|
189
205
|
collateral: this.collateral.toJSON(),
|
|
190
|
-
reserveCollateralPadding: this.reserveCollateralPadding.map((item) =>
|
|
206
|
+
reserveCollateralPadding: this.reserveCollateralPadding.map((item) =>
|
|
207
|
+
item.toString()
|
|
208
|
+
),
|
|
191
209
|
config: this.config.toJSON(),
|
|
192
210
|
configPadding: this.configPadding.map((item) => item.toString()),
|
|
193
|
-
borrowedAmountOutsideElevationGroup:
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
211
|
+
borrowedAmountOutsideElevationGroup:
|
|
212
|
+
this.borrowedAmountOutsideElevationGroup.toString(),
|
|
213
|
+
borrowedAmountsAgainstThisReserveInElevationGroups:
|
|
214
|
+
this.borrowedAmountsAgainstThisReserveInElevationGroups.map((item) =>
|
|
215
|
+
item.toString()
|
|
216
|
+
),
|
|
197
217
|
padding: this.padding.map((item) => item.toString()),
|
|
198
|
-
}
|
|
218
|
+
}
|
|
199
219
|
}
|
|
200
220
|
|
|
201
221
|
static fromJSON(obj: ReserveJSON): Reserve {
|
|
@@ -206,16 +226,23 @@ export class Reserve {
|
|
|
206
226
|
farmCollateral: new PublicKey(obj.farmCollateral),
|
|
207
227
|
farmDebt: new PublicKey(obj.farmDebt),
|
|
208
228
|
liquidity: types.ReserveLiquidity.fromJSON(obj.liquidity),
|
|
209
|
-
reserveLiquidityPadding: obj.reserveLiquidityPadding.map(
|
|
229
|
+
reserveLiquidityPadding: obj.reserveLiquidityPadding.map(
|
|
230
|
+
(item) => new BN(item)
|
|
231
|
+
),
|
|
210
232
|
collateral: types.ReserveCollateral.fromJSON(obj.collateral),
|
|
211
|
-
reserveCollateralPadding: obj.reserveCollateralPadding.map(
|
|
233
|
+
reserveCollateralPadding: obj.reserveCollateralPadding.map(
|
|
234
|
+
(item) => new BN(item)
|
|
235
|
+
),
|
|
212
236
|
config: types.ReserveConfig.fromJSON(obj.config),
|
|
213
237
|
configPadding: obj.configPadding.map((item) => new BN(item)),
|
|
214
|
-
borrowedAmountOutsideElevationGroup: new BN(
|
|
215
|
-
|
|
216
|
-
(item) => new BN(item)
|
|
238
|
+
borrowedAmountOutsideElevationGroup: new BN(
|
|
239
|
+
obj.borrowedAmountOutsideElevationGroup
|
|
217
240
|
),
|
|
241
|
+
borrowedAmountsAgainstThisReserveInElevationGroups:
|
|
242
|
+
obj.borrowedAmountsAgainstThisReserveInElevationGroups.map(
|
|
243
|
+
(item) => new BN(item)
|
|
244
|
+
),
|
|
218
245
|
padding: obj.padding.map((item) => new BN(item)),
|
|
219
|
-
})
|
|
246
|
+
})
|
|
220
247
|
}
|
|
221
248
|
}
|