@kamino-finance/klend-sdk 5.0.5 → 5.0.7
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/README_KAMINO_MANAGER.md +154 -17
- package/dist/classes/manager.d.ts +22 -0
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +29 -0
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/obligation.d.ts +3 -4
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +94 -26
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts +1 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +10 -2
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/vault.d.ts +30 -0
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +177 -0
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +113 -1
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts +10 -10
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js +52 -51
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/manager.ts +34 -0
- package/src/classes/obligation.ts +139 -29
- package/src/classes/reserve.ts +15 -2
- package/src/classes/vault.ts +250 -0
- package/src/client_kamino_manager.ts +174 -1
- package/src/idl_codegen_kamino_vault/types/VaultConfigField.ts +116 -117
|
@@ -30,12 +30,12 @@ exports.layout = layout;
|
|
|
30
30
|
const borsh = __importStar(require("@coral-xyz/borsh"));
|
|
31
31
|
class PerformanceFeeBps {
|
|
32
32
|
static discriminator = 0;
|
|
33
|
-
static kind =
|
|
33
|
+
static kind = 'PerformanceFeeBps';
|
|
34
34
|
discriminator = 0;
|
|
35
|
-
kind =
|
|
35
|
+
kind = 'PerformanceFeeBps';
|
|
36
36
|
toJSON() {
|
|
37
37
|
return {
|
|
38
|
-
kind:
|
|
38
|
+
kind: 'PerformanceFeeBps',
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
toEncodable() {
|
|
@@ -47,12 +47,12 @@ class PerformanceFeeBps {
|
|
|
47
47
|
exports.PerformanceFeeBps = PerformanceFeeBps;
|
|
48
48
|
class ManagementFeeBps {
|
|
49
49
|
static discriminator = 1;
|
|
50
|
-
static kind =
|
|
50
|
+
static kind = 'ManagementFeeBps';
|
|
51
51
|
discriminator = 1;
|
|
52
|
-
kind =
|
|
52
|
+
kind = 'ManagementFeeBps';
|
|
53
53
|
toJSON() {
|
|
54
54
|
return {
|
|
55
|
-
kind:
|
|
55
|
+
kind: 'ManagementFeeBps',
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
toEncodable() {
|
|
@@ -64,12 +64,12 @@ class ManagementFeeBps {
|
|
|
64
64
|
exports.ManagementFeeBps = ManagementFeeBps;
|
|
65
65
|
class MinDepositAmount {
|
|
66
66
|
static discriminator = 2;
|
|
67
|
-
static kind =
|
|
67
|
+
static kind = 'MinDepositAmount';
|
|
68
68
|
discriminator = 2;
|
|
69
|
-
kind =
|
|
69
|
+
kind = 'MinDepositAmount';
|
|
70
70
|
toJSON() {
|
|
71
71
|
return {
|
|
72
|
-
kind:
|
|
72
|
+
kind: 'MinDepositAmount',
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
toEncodable() {
|
|
@@ -81,12 +81,12 @@ class MinDepositAmount {
|
|
|
81
81
|
exports.MinDepositAmount = MinDepositAmount;
|
|
82
82
|
class MinWithdrawAmount {
|
|
83
83
|
static discriminator = 3;
|
|
84
|
-
static kind =
|
|
84
|
+
static kind = 'MinWithdrawAmount';
|
|
85
85
|
discriminator = 3;
|
|
86
|
-
kind =
|
|
86
|
+
kind = 'MinWithdrawAmount';
|
|
87
87
|
toJSON() {
|
|
88
88
|
return {
|
|
89
|
-
kind:
|
|
89
|
+
kind: 'MinWithdrawAmount',
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
toEncodable() {
|
|
@@ -98,12 +98,12 @@ class MinWithdrawAmount {
|
|
|
98
98
|
exports.MinWithdrawAmount = MinWithdrawAmount;
|
|
99
99
|
class MintInvestAmount {
|
|
100
100
|
static discriminator = 4;
|
|
101
|
-
static kind =
|
|
101
|
+
static kind = 'MintInvestAmount';
|
|
102
102
|
discriminator = 4;
|
|
103
|
-
kind =
|
|
103
|
+
kind = 'MintInvestAmount';
|
|
104
104
|
toJSON() {
|
|
105
105
|
return {
|
|
106
|
-
kind:
|
|
106
|
+
kind: 'MintInvestAmount',
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
toEncodable() {
|
|
@@ -115,12 +115,12 @@ class MintInvestAmount {
|
|
|
115
115
|
exports.MintInvestAmount = MintInvestAmount;
|
|
116
116
|
class MinInvestDelaySlots {
|
|
117
117
|
static discriminator = 5;
|
|
118
|
-
static kind =
|
|
118
|
+
static kind = 'MinInvestDelaySlots';
|
|
119
119
|
discriminator = 5;
|
|
120
|
-
kind =
|
|
120
|
+
kind = 'MinInvestDelaySlots';
|
|
121
121
|
toJSON() {
|
|
122
122
|
return {
|
|
123
|
-
kind:
|
|
123
|
+
kind: 'MinInvestDelaySlots',
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
126
|
toEncodable() {
|
|
@@ -132,12 +132,12 @@ class MinInvestDelaySlots {
|
|
|
132
132
|
exports.MinInvestDelaySlots = MinInvestDelaySlots;
|
|
133
133
|
class CrankFundFeePerReserve {
|
|
134
134
|
static discriminator = 6;
|
|
135
|
-
static kind =
|
|
135
|
+
static kind = 'CrankFundFeePerReserve';
|
|
136
136
|
discriminator = 6;
|
|
137
|
-
kind =
|
|
137
|
+
kind = 'CrankFundFeePerReserve';
|
|
138
138
|
toJSON() {
|
|
139
139
|
return {
|
|
140
|
-
kind:
|
|
140
|
+
kind: 'CrankFundFeePerReserve',
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
143
|
toEncodable() {
|
|
@@ -149,12 +149,12 @@ class CrankFundFeePerReserve {
|
|
|
149
149
|
exports.CrankFundFeePerReserve = CrankFundFeePerReserve;
|
|
150
150
|
class PendingVaultAdmin {
|
|
151
151
|
static discriminator = 7;
|
|
152
|
-
static kind =
|
|
152
|
+
static kind = 'PendingVaultAdmin';
|
|
153
153
|
discriminator = 7;
|
|
154
|
-
kind =
|
|
154
|
+
kind = 'PendingVaultAdmin';
|
|
155
155
|
toJSON() {
|
|
156
156
|
return {
|
|
157
|
-
kind:
|
|
157
|
+
kind: 'PendingVaultAdmin',
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
160
|
toEncodable() {
|
|
@@ -166,73 +166,74 @@ class PendingVaultAdmin {
|
|
|
166
166
|
exports.PendingVaultAdmin = PendingVaultAdmin;
|
|
167
167
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
168
|
function fromDecoded(obj) {
|
|
169
|
-
if (typeof obj !==
|
|
170
|
-
throw new Error(
|
|
169
|
+
if (typeof obj !== 'object') {
|
|
170
|
+
throw new Error('Invalid enum object');
|
|
171
171
|
}
|
|
172
|
-
|
|
172
|
+
console.log('');
|
|
173
|
+
if ('PerformanceFeeBps' in obj) {
|
|
173
174
|
return new PerformanceFeeBps();
|
|
174
175
|
}
|
|
175
|
-
if (
|
|
176
|
+
if ('ManagementFeeBps' in obj) {
|
|
176
177
|
return new ManagementFeeBps();
|
|
177
178
|
}
|
|
178
|
-
if (
|
|
179
|
+
if ('MinDepositAmount' in obj) {
|
|
179
180
|
return new MinDepositAmount();
|
|
180
181
|
}
|
|
181
|
-
if (
|
|
182
|
+
if ('MinWithdrawAmount' in obj) {
|
|
182
183
|
return new MinWithdrawAmount();
|
|
183
184
|
}
|
|
184
|
-
if (
|
|
185
|
+
if ('MintInvestAmount' in obj) {
|
|
185
186
|
return new MintInvestAmount();
|
|
186
187
|
}
|
|
187
|
-
if (
|
|
188
|
+
if ('MinInvestDelaySlots' in obj) {
|
|
188
189
|
return new MinInvestDelaySlots();
|
|
189
190
|
}
|
|
190
|
-
if (
|
|
191
|
+
if ('CrankFundFeePerReserve' in obj) {
|
|
191
192
|
return new CrankFundFeePerReserve();
|
|
192
193
|
}
|
|
193
|
-
if (
|
|
194
|
+
if ('PendingVaultAdmin' in obj) {
|
|
194
195
|
return new PendingVaultAdmin();
|
|
195
196
|
}
|
|
196
|
-
throw new Error(
|
|
197
|
+
throw new Error('Invalid enum object');
|
|
197
198
|
}
|
|
198
199
|
function fromJSON(obj) {
|
|
199
200
|
switch (obj.kind) {
|
|
200
|
-
case
|
|
201
|
+
case 'PerformanceFeeBps': {
|
|
201
202
|
return new PerformanceFeeBps();
|
|
202
203
|
}
|
|
203
|
-
case
|
|
204
|
+
case 'ManagementFeeBps': {
|
|
204
205
|
return new ManagementFeeBps();
|
|
205
206
|
}
|
|
206
|
-
case
|
|
207
|
+
case 'MinDepositAmount': {
|
|
207
208
|
return new MinDepositAmount();
|
|
208
209
|
}
|
|
209
|
-
case
|
|
210
|
+
case 'MinWithdrawAmount': {
|
|
210
211
|
return new MinWithdrawAmount();
|
|
211
212
|
}
|
|
212
|
-
case
|
|
213
|
+
case 'MintInvestAmount': {
|
|
213
214
|
return new MintInvestAmount();
|
|
214
215
|
}
|
|
215
|
-
case
|
|
216
|
+
case 'MinInvestDelaySlots': {
|
|
216
217
|
return new MinInvestDelaySlots();
|
|
217
218
|
}
|
|
218
|
-
case
|
|
219
|
+
case 'CrankFundFeePerReserve': {
|
|
219
220
|
return new CrankFundFeePerReserve();
|
|
220
221
|
}
|
|
221
|
-
case
|
|
222
|
+
case 'PendingVaultAdmin': {
|
|
222
223
|
return new PendingVaultAdmin();
|
|
223
224
|
}
|
|
224
225
|
}
|
|
225
226
|
}
|
|
226
227
|
function layout(property) {
|
|
227
228
|
const ret = borsh.rustEnum([
|
|
228
|
-
borsh.struct([],
|
|
229
|
-
borsh.struct([],
|
|
230
|
-
borsh.struct([],
|
|
231
|
-
borsh.struct([],
|
|
232
|
-
borsh.struct([],
|
|
233
|
-
borsh.struct([],
|
|
234
|
-
borsh.struct([],
|
|
235
|
-
borsh.struct([],
|
|
229
|
+
borsh.struct([], 'PerformanceFeeBps'),
|
|
230
|
+
borsh.struct([], 'ManagementFeeBps'),
|
|
231
|
+
borsh.struct([], 'MinDepositAmount'),
|
|
232
|
+
borsh.struct([], 'MinWithdrawAmount'),
|
|
233
|
+
borsh.struct([], 'MintInvestAmount'),
|
|
234
|
+
borsh.struct([], 'MinInvestDelaySlots'),
|
|
235
|
+
borsh.struct([], 'CrankFundFeePerReserve'),
|
|
236
|
+
borsh.struct([], 'PendingVaultAdmin'),
|
|
236
237
|
]);
|
|
237
238
|
if (property !== undefined) {
|
|
238
239
|
return ret.replicate(property);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VaultConfigField.js","sourceRoot":"","sources":["../../../src/idl_codegen_kamino_vault/types/VaultConfigField.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8LA,
|
|
1
|
+
{"version":3,"file":"VaultConfigField.js","sourceRoot":"","sources":["../../../src/idl_codegen_kamino_vault/types/VaultConfigField.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8LA,kCAgCC;AAED,4BA2BC;AAED,wBAeC;AAzQD,wDAA0C;AAM1C,MAAa,iBAAiB;IAC5B,MAAM,CAAU,aAAa,GAAG,CAAC,CAAC;IAClC,MAAM,CAAU,IAAI,GAAG,mBAAmB,CAAC;IAClC,aAAa,GAAG,CAAC,CAAC;IAClB,IAAI,GAAG,mBAAmB,CAAC;IAEpC,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,mBAAmB;SAC1B,CAAC;IACJ,CAAC;IAED,WAAW;QACT,OAAO;YACL,iBAAiB,EAAE,EAAE;SACtB,CAAC;IACJ,CAAC;;AAhBH,8CAiBC;A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import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
|
54
54
|
import { Data } from '@kamino-finance/kliquidity-sdk';
|
|
55
55
|
import bs58 from 'bs58';
|
|
56
56
|
import { getProgramAccounts } from '../utils/rpc';
|
|
57
|
+
import { VaultConfigFieldKind } from '../idl_codegen_kamino_vault/types';
|
|
57
58
|
|
|
58
59
|
/**
|
|
59
60
|
* KaminoManager is a class that provides a high-level interface to interact with the Kamino Lend and Kamino Vault programs, in order to create and manage a market, as well as vaults
|
|
@@ -317,6 +318,29 @@ export class KaminoManager {
|
|
|
317
318
|
return this._vaultClient.depositIxs(user, vault, tokenAmount);
|
|
318
319
|
}
|
|
319
320
|
|
|
321
|
+
async updateVaultConfigIx(vault: KaminoVault, mode: VaultConfigFieldKind, value: string): Promise<TransactionInstruction> {
|
|
322
|
+
return this._vaultClient.updateVaultConfigIx(vault, mode, value);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* This function creates the instruction for the `pendingAdmin` of the vault to accept to become the owner of the vault (step 2/2 of the ownership transfer)
|
|
327
|
+
* @param vault - vault to change the ownership for
|
|
328
|
+
* @returns - an instruction to be used to be executed
|
|
329
|
+
*/
|
|
330
|
+
async acceptVaultOwnershipIx(vault: KaminoVault): Promise<TransactionInstruction> {
|
|
331
|
+
return this._vaultClient.acceptVaultOwnershipIx(vault);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* This function creates the instruction for the admin to give up a part of the pending fees (which will be accounted as part of the vault)
|
|
336
|
+
* @param vault - vault to give up pending fees for
|
|
337
|
+
* @param maxAmountToGiveUp - the maximum amount of fees to give up, in tokens
|
|
338
|
+
* @returns - an instruction to be used to be executed
|
|
339
|
+
*/
|
|
340
|
+
async giveUpPendingFeesIx(vault: KaminoVault, maxAmountToGiveUp: Decimal): Promise<TransactionInstruction> {
|
|
341
|
+
return this._vaultClient.giveUpPendingFeesIx(vault, maxAmountToGiveUp);
|
|
342
|
+
}
|
|
343
|
+
|
|
320
344
|
/**
|
|
321
345
|
* This function will return the missing ATA creation instructions, as well as one or multiple withdraw instructions, based on how many reserves it's needed to withdraw from. This might have to be split in multiple transactions
|
|
322
346
|
* @param user - user to withdraw
|
|
@@ -334,6 +358,16 @@ export class KaminoManager {
|
|
|
334
358
|
return this._vaultClient.withdrawIxs(user, vault, shareAmount, slot);
|
|
335
359
|
}
|
|
336
360
|
|
|
361
|
+
/**
|
|
362
|
+
* This method withdraws all the pending fees from the vault to the owner's token ATA
|
|
363
|
+
* @param vault - vault for which the admin withdraws the pending fees
|
|
364
|
+
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
|
|
365
|
+
* @returns - list of instructions to withdraw all pending fees
|
|
366
|
+
*/
|
|
367
|
+
async withdrawPendingFeesIxs(vault: KaminoVault, slot: number): Promise<TransactionInstruction[]> {
|
|
368
|
+
return this._vaultClient.withdrawPendingFeesIxs(vault, slot);
|
|
369
|
+
}
|
|
370
|
+
|
|
337
371
|
/**
|
|
338
372
|
* This method calculates the token per share value. This will always change based on interest earned from the vault, but calculating it requires a bunch of rpc requests. Caching this for a short duration would be optimal
|
|
339
373
|
* @param vault - vault to calculate tokensPerShare for
|
|
@@ -362,6 +362,9 @@ export class KaminoObligation {
|
|
|
362
362
|
collateralExchangeRates: Map<PublicKey, Decimal>
|
|
363
363
|
): ObligationCollateral[] {
|
|
364
364
|
const newDeposits: ObligationCollateral[] = [];
|
|
365
|
+
const depositIndex = obligationDeposits.findIndex((deposit) => deposit.depositReserve.equals(changeReserve));
|
|
366
|
+
|
|
367
|
+
// Always copy the previous deposits and modify the changeReserve one if it exists
|
|
365
368
|
for (let i = 0; i < obligationDeposits.length; i++) {
|
|
366
369
|
if (obligationDeposits[i].depositReserve.equals(changeReserve)) {
|
|
367
370
|
const coll: ObligationCollateralFields = { ...obligationDeposits[i] };
|
|
@@ -375,6 +378,25 @@ export class KaminoObligation {
|
|
|
375
378
|
}
|
|
376
379
|
}
|
|
377
380
|
|
|
381
|
+
if (depositIndex === -1) {
|
|
382
|
+
// If the reserve is not in the obligation, we add it
|
|
383
|
+
const firstBorrowIndexAvailable = obligationDeposits.findIndex((deposit) =>
|
|
384
|
+
deposit.depositReserve.equals(PublicKey.default)
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
if (firstBorrowIndexAvailable === -1) {
|
|
388
|
+
throw new Error('No available borrows to modify');
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const coll: ObligationCollateralFields = { ...obligationDeposits[firstBorrowIndexAvailable] };
|
|
392
|
+
const exchangeRate = collateralExchangeRates.get(changeReserve)!;
|
|
393
|
+
const changeInCollateral = new Decimal(changeInLamports).mul(exchangeRate).toFixed(0);
|
|
394
|
+
coll.depositedAmount = new BN(positiveOrZero(new Decimal(changeInCollateral)).toString());
|
|
395
|
+
coll.depositReserve = changeReserve;
|
|
396
|
+
|
|
397
|
+
newDeposits[firstBorrowIndexAvailable] = new ObligationCollateral(coll);
|
|
398
|
+
}
|
|
399
|
+
|
|
378
400
|
return newDeposits;
|
|
379
401
|
}
|
|
380
402
|
|
|
@@ -387,17 +409,30 @@ export class KaminoObligation {
|
|
|
387
409
|
const newBorrows: ObligationLiquidity[] = [];
|
|
388
410
|
const borrowIndex = obligationBorrows.findIndex((borrow) => borrow.borrowReserve.equals(changeReserve));
|
|
389
411
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
412
|
+
// Always copy the previous borrows and modify the changeReserve one if it exists
|
|
413
|
+
for (let i = 0; i < obligationBorrows.length; i++) {
|
|
414
|
+
if (obligationBorrows[i].borrowReserve.equals(changeReserve)) {
|
|
415
|
+
const borrow: ObligationLiquidityFields = { ...obligationBorrows[borrowIndex] };
|
|
416
|
+
const newBorrowedAmount: Decimal = new Fraction(borrow.borrowedAmountSf).toDecimal().add(changeInLamports);
|
|
417
|
+
const newBorrowedAmountSf = Fraction.fromDecimal(positiveOrZero(newBorrowedAmount)).getValue();
|
|
418
|
+
borrow.borrowedAmountSf = newBorrowedAmountSf;
|
|
419
|
+
|
|
420
|
+
newBorrows.push(new ObligationLiquidity(borrow));
|
|
421
|
+
} else {
|
|
422
|
+
newBorrows.push(obligationBorrows[i]);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (borrowIndex === -1) {
|
|
427
|
+
// If the reserve is not in the obligation, we add it
|
|
397
428
|
const firstBorrowIndexAvailable = obligationBorrows.findIndex((borrow) =>
|
|
398
429
|
borrow.borrowReserve.equals(PublicKey.default)
|
|
399
430
|
);
|
|
400
431
|
|
|
432
|
+
if (firstBorrowIndexAvailable === -1) {
|
|
433
|
+
throw new Error('No available borrows to modify');
|
|
434
|
+
}
|
|
435
|
+
|
|
401
436
|
const borrow: ObligationLiquidityFields = { ...obligationBorrows[firstBorrowIndexAvailable] };
|
|
402
437
|
borrow.borrowedAmountSf = Fraction.fromDecimal(new Decimal(changeInLamports)).getValue();
|
|
403
438
|
borrow.borrowReserve = changeReserve;
|
|
@@ -405,7 +440,7 @@ export class KaminoObligation {
|
|
|
405
440
|
padding: [],
|
|
406
441
|
value: [Fraction.fromDecimal(cumulativeBorrowRate).getValue(), new BN(0), new BN(0), new BN(0)],
|
|
407
442
|
};
|
|
408
|
-
newBorrows
|
|
443
|
+
newBorrows[firstBorrowIndexAvailable] = new ObligationLiquidity(borrow);
|
|
409
444
|
}
|
|
410
445
|
|
|
411
446
|
return newBorrows;
|
|
@@ -433,7 +468,23 @@ export class KaminoObligation {
|
|
|
433
468
|
const { amountCollateral, amountDebt, action, mintCollateral, mintDebt, market } = params;
|
|
434
469
|
let newStats = { ...this.refreshedStats };
|
|
435
470
|
|
|
436
|
-
const
|
|
471
|
+
const collateralReservePk = mintCollateral ? market.getReserveByMint(mintCollateral)!.address : undefined;
|
|
472
|
+
const debtReservePk = mintDebt ? market.getReserveByMint(mintDebt)!.address : undefined;
|
|
473
|
+
|
|
474
|
+
const additionalReserves = [];
|
|
475
|
+
if (collateralReservePk !== undefined) {
|
|
476
|
+
additionalReserves.push(collateralReservePk);
|
|
477
|
+
}
|
|
478
|
+
if (debtReservePk !== undefined) {
|
|
479
|
+
additionalReserves.push(debtReservePk);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
const { collateralExchangeRates } = KaminoObligation.getRatesForObligation(
|
|
483
|
+
market,
|
|
484
|
+
this.state,
|
|
485
|
+
params.slot,
|
|
486
|
+
additionalReserves
|
|
487
|
+
);
|
|
437
488
|
|
|
438
489
|
const elevationGroup = params.elevationGroupOverride ?? this.state.elevationGroup;
|
|
439
490
|
|
|
@@ -444,8 +495,6 @@ export class KaminoObligation {
|
|
|
444
495
|
// so we have to recalculate the entire position, not just an updated deposit or borrow
|
|
445
496
|
// as both LTVs and borrow factors can change, affecting all calcs
|
|
446
497
|
|
|
447
|
-
const collateralReservePk = mintCollateral ? market.getReserveByMint(mintCollateral)!.address : undefined;
|
|
448
|
-
const debtReservePk = mintDebt ? market.getReserveByMint(mintDebt)!.address : undefined;
|
|
449
498
|
const debtReserveCumulativeBorrowRate = mintDebt
|
|
450
499
|
? market.getReserveByMint(mintDebt)!.getCumulativeBorrowRate()
|
|
451
500
|
: undefined;
|
|
@@ -453,6 +502,14 @@ export class KaminoObligation {
|
|
|
453
502
|
let newObligationDeposits = this.state.deposits;
|
|
454
503
|
let newObligationBorrows = this.state.borrows;
|
|
455
504
|
|
|
505
|
+
// Print deposits and borrows before
|
|
506
|
+
for (const deposit of this.state.deposits) {
|
|
507
|
+
console.log(`Before Deposit: ${deposit.depositReserve.toBase58()} - ${deposit.depositedAmount}`);
|
|
508
|
+
}
|
|
509
|
+
for (const borrow of this.state.borrows) {
|
|
510
|
+
console.log(`Before Borrow: ${borrow.borrowReserve.toBase58()} - ${borrow.borrowedAmountSf}`);
|
|
511
|
+
}
|
|
512
|
+
|
|
456
513
|
switch (action) {
|
|
457
514
|
case 'deposit': {
|
|
458
515
|
if (amountCollateral === undefined || mintCollateral === undefined) {
|
|
@@ -567,6 +624,14 @@ export class KaminoObligation {
|
|
|
567
624
|
null
|
|
568
625
|
);
|
|
569
626
|
|
|
627
|
+
// Print deposits and borrows after
|
|
628
|
+
for (const deposit of newObligationDeposits) {
|
|
629
|
+
console.log(`After Deposit: ${deposit.depositReserve.toBase58()} - ${deposit.depositedAmount}`);
|
|
630
|
+
}
|
|
631
|
+
for (const borrow of newObligationBorrows) {
|
|
632
|
+
console.log(`After Borrow: ${borrow.borrowReserve.toBase58()} - ${borrow.borrowedAmountSf}`);
|
|
633
|
+
}
|
|
634
|
+
|
|
570
635
|
newStats = refreshedStats;
|
|
571
636
|
newDeposits = deposits;
|
|
572
637
|
newBorrows = borrows;
|
|
@@ -921,7 +986,11 @@ export class KaminoObligation {
|
|
|
921
986
|
throw new Error('Reserve not found');
|
|
922
987
|
}
|
|
923
988
|
|
|
924
|
-
const liquidityAvailable = reserve.getLiquidityAvailableForDebtReserveGivenCaps(
|
|
989
|
+
const liquidityAvailable = reserve.getLiquidityAvailableForDebtReserveGivenCaps(
|
|
990
|
+
market,
|
|
991
|
+
[elevationGroup],
|
|
992
|
+
Array.from(this.deposits.keys())
|
|
993
|
+
)[0];
|
|
925
994
|
const maxBorrowAmount = this.getBorrowPower(market, liquidityMint, slot, elevationGroup);
|
|
926
995
|
|
|
927
996
|
if (elevationGroup === this.state.elevationGroup) {
|
|
@@ -1213,7 +1282,8 @@ export class KaminoObligation {
|
|
|
1213
1282
|
public static getRatesForObligation(
|
|
1214
1283
|
kaminoMarket: KaminoMarket,
|
|
1215
1284
|
obligation: Obligation,
|
|
1216
|
-
slot: number
|
|
1285
|
+
slot: number,
|
|
1286
|
+
additionalReserves: PublicKey[] = []
|
|
1217
1287
|
): {
|
|
1218
1288
|
collateralExchangeRates: Map<PublicKey, Decimal>;
|
|
1219
1289
|
cumulativeBorrowRates: Map<PublicKey, Decimal>;
|
|
@@ -1221,12 +1291,14 @@ export class KaminoObligation {
|
|
|
1221
1291
|
const collateralExchangeRates = KaminoObligation.getCollateralExchangeRatesForObligation(
|
|
1222
1292
|
kaminoMarket,
|
|
1223
1293
|
obligation,
|
|
1224
|
-
slot
|
|
1294
|
+
slot,
|
|
1295
|
+
additionalReserves
|
|
1225
1296
|
);
|
|
1226
1297
|
const cumulativeBorrowRates = KaminoObligation.getCumulativeBorrowRatesForObligation(
|
|
1227
1298
|
kaminoMarket,
|
|
1228
1299
|
obligation,
|
|
1229
|
-
slot
|
|
1300
|
+
slot,
|
|
1301
|
+
additionalReserves
|
|
1230
1302
|
);
|
|
1231
1303
|
|
|
1232
1304
|
return {
|
|
@@ -1249,20 +1321,35 @@ export class KaminoObligation {
|
|
|
1249
1321
|
static getCollateralExchangeRatesForObligation(
|
|
1250
1322
|
kaminoMarket: KaminoMarket,
|
|
1251
1323
|
obligation: Obligation,
|
|
1252
|
-
slot: number
|
|
1324
|
+
slot: number,
|
|
1325
|
+
additionalReserves: PublicKey[]
|
|
1253
1326
|
): Map<PublicKey, Decimal> {
|
|
1254
1327
|
const collateralExchangeRates = new PubkeyHashMap<PublicKey, Decimal>();
|
|
1328
|
+
|
|
1329
|
+
// Create a set of all reserves coming from deposit plus additional reserves
|
|
1330
|
+
const allReserves = new Set<PublicKey>();
|
|
1255
1331
|
for (let i = 0; i < obligation.deposits.length; i++) {
|
|
1256
1332
|
const deposit = obligation.deposits[i];
|
|
1257
|
-
if (isNotNullPubkey(deposit.depositReserve)
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1333
|
+
if (isNotNullPubkey(deposit.depositReserve)) {
|
|
1334
|
+
allReserves.add(deposit.depositReserve);
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
for (let i = 0; i < additionalReserves.length; i++) {
|
|
1338
|
+
if (isNotNullPubkey(additionalReserves[i])) {
|
|
1339
|
+
allReserves.add(additionalReserves[i]);
|
|
1264
1340
|
}
|
|
1265
1341
|
}
|
|
1342
|
+
|
|
1343
|
+
// Run through all reserves and get the exchange rate
|
|
1344
|
+
for (const reserve of allReserves) {
|
|
1345
|
+
const reserveInstance = kaminoMarket.getReserveByAddress(reserve)!;
|
|
1346
|
+
const collateralExchangeRate = reserveInstance.getEstimatedCollateralExchangeRate(
|
|
1347
|
+
slot,
|
|
1348
|
+
kaminoMarket.state.referralFeeBps
|
|
1349
|
+
);
|
|
1350
|
+
collateralExchangeRates.set(reserve, collateralExchangeRate);
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1266
1353
|
return collateralExchangeRates;
|
|
1267
1354
|
}
|
|
1268
1355
|
|
|
@@ -1285,16 +1372,39 @@ export class KaminoObligation {
|
|
|
1285
1372
|
}
|
|
1286
1373
|
}
|
|
1287
1374
|
|
|
1288
|
-
static getCumulativeBorrowRatesForObligation(
|
|
1289
|
-
|
|
1375
|
+
static getCumulativeBorrowRatesForObligation(
|
|
1376
|
+
kaminoMarket: KaminoMarket,
|
|
1377
|
+
obligation: Obligation,
|
|
1378
|
+
slot: number,
|
|
1379
|
+
additionalReserves: PublicKey[] = []
|
|
1380
|
+
): Map<PublicKey, Decimal> {
|
|
1381
|
+
const allReserves = new Set<PublicKey>();
|
|
1290
1382
|
for (let i = 0; i < obligation.borrows.length; i++) {
|
|
1291
1383
|
const borrow = obligation.borrows[i];
|
|
1292
|
-
if (isNotNullPubkey(borrow.borrowReserve)
|
|
1293
|
-
|
|
1294
|
-
const cumulativeBorrowRate = reserve.getEstimatedCumulativeBorrowRate(slot, kaminoMarket.state.referralFeeBps);
|
|
1295
|
-
cumulativeBorrowRates.set(reserve.address, cumulativeBorrowRate);
|
|
1384
|
+
if (isNotNullPubkey(borrow.borrowReserve)) {
|
|
1385
|
+
allReserves.add(borrow.borrowReserve);
|
|
1296
1386
|
}
|
|
1297
1387
|
}
|
|
1388
|
+
|
|
1389
|
+
// Add additional reserves
|
|
1390
|
+
for (let i = 0; i < additionalReserves.length; i++) {
|
|
1391
|
+
if (isNotNullPubkey(additionalReserves[i])) {
|
|
1392
|
+
allReserves.add(additionalReserves[i]);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
const cumulativeBorrowRates = new PubkeyHashMap<PublicKey, Decimal>();
|
|
1397
|
+
|
|
1398
|
+
// Run through all reserves and get the cumulative borrow rate
|
|
1399
|
+
for (const reserve of allReserves) {
|
|
1400
|
+
const reserveInstance = kaminoMarket.getReserveByAddress(reserve)!;
|
|
1401
|
+
const cumulativeBorrowRate = reserveInstance.getEstimatedCumulativeBorrowRate(
|
|
1402
|
+
slot,
|
|
1403
|
+
kaminoMarket.state.referralFeeBps
|
|
1404
|
+
);
|
|
1405
|
+
cumulativeBorrowRates.set(reserve, cumulativeBorrowRate);
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1298
1408
|
return cumulativeBorrowRates;
|
|
1299
1409
|
}
|
|
1300
1410
|
|
package/src/classes/reserve.ts
CHANGED
|
@@ -1053,7 +1053,11 @@ export class KaminoReserve {
|
|
|
1053
1053
|
}
|
|
1054
1054
|
|
|
1055
1055
|
/* This takes into account all the caps */
|
|
1056
|
-
getLiquidityAvailableForDebtReserveGivenCaps(
|
|
1056
|
+
getLiquidityAvailableForDebtReserveGivenCaps(
|
|
1057
|
+
market: KaminoMarket,
|
|
1058
|
+
elevationGroups: number[],
|
|
1059
|
+
collateralReserves: PublicKey[] = []
|
|
1060
|
+
): Decimal[] {
|
|
1057
1061
|
const caps = this.getBorrowCapForReserve(market);
|
|
1058
1062
|
|
|
1059
1063
|
const liquidityAvailable = this.getLiquidityAvailableAmount();
|
|
@@ -1089,7 +1093,16 @@ export class KaminoReserve {
|
|
|
1089
1093
|
(x) => x.elevationGroup === elevationGroup
|
|
1090
1094
|
);
|
|
1091
1095
|
if (capsGivenEgroup.length > 0) {
|
|
1092
|
-
remainingInsideEmodeCaps = Decimal.min(
|
|
1096
|
+
remainingInsideEmodeCaps = Decimal.min(
|
|
1097
|
+
...capsGivenEgroup.map((x) => {
|
|
1098
|
+
// check reserve is part of collReserves array
|
|
1099
|
+
if (collateralReserves.find((collateralReserve) => collateralReserve.equals(x.collateralReserve))) {
|
|
1100
|
+
return x.maxDebt.minus(x.currentValue);
|
|
1101
|
+
} else {
|
|
1102
|
+
return new Decimal(U64_MAX);
|
|
1103
|
+
}
|
|
1104
|
+
})
|
|
1105
|
+
);
|
|
1093
1106
|
}
|
|
1094
1107
|
return Decimal.min(
|
|
1095
1108
|
positiveOrZero(liquidityAvailable),
|