@kamino-finance/klend-sdk 6.0.5-beta.2 → 6.0.5-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/action.d.ts +1 -1
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +32 -16
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +29 -18
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +66 -49
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +12 -11
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +77 -37
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +32 -2
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +150 -24
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/vault.d.ts +5 -3
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +8 -6
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +30 -22
- package/dist/client_kamino_manager.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 +36 -32
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +4 -4
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/operations.d.ts +4 -3
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +186 -154
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +1 -0
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/utils/managerTypes.d.ts +1 -2
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +9 -9
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/obligations.d.ts +5 -0
- package/dist/utils/obligations.d.ts.map +1 -0
- package/dist/utils/obligations.js +53 -0
- package/dist/utils/obligations.js.map +1 -0
- package/dist/utils/oracle.d.ts +3 -3
- package/dist/utils/oracle.d.ts.map +1 -1
- package/dist/utils/oracle.js +2 -2
- package/dist/utils/oracle.js.map +1 -1
- package/dist/utils/pubkey.d.ts +1 -0
- package/dist/utils/pubkey.d.ts.map +1 -1
- package/dist/utils/pubkey.js +10 -0
- package/dist/utils/pubkey.js.map +1 -1
- package/package.json +3 -3
- package/src/classes/action.ts +32 -20
- package/src/classes/manager.ts +87 -54
- package/src/classes/market.ts +132 -52
- package/src/classes/obligation.ts +201 -36
- package/src/classes/vault.ts +17 -6
- package/src/client.ts +4 -4
- package/src/client_kamino_manager.ts +40 -35
- package/src/lending_operations/repay_with_collateral_operations.ts +76 -72
- package/src/lending_operations/swap_collateral_operations.ts +13 -11
- package/src/leverage/operations.ts +362 -328
- package/src/leverage/types.ts +1 -0
- package/src/utils/managerTypes.ts +1 -2
- package/src/utils/obligations.ts +69 -0
- package/src/utils/oracle.ts +5 -4
- package/src/utils/pubkey.ts +9 -0
package/src/leverage/types.ts
CHANGED
|
@@ -188,6 +188,7 @@ export interface AdjustLeverageSwapInputsProps<QuoteResponse> extends BaseLevera
|
|
|
188
188
|
priceCollToDebt: Decimal;
|
|
189
189
|
priceDebtToColl: Decimal;
|
|
190
190
|
priceAinB: PriceAinBProvider;
|
|
191
|
+
withdrawSlotOffset?: number;
|
|
191
192
|
}
|
|
192
193
|
|
|
193
194
|
export interface AdjustLeverageProps<QuoteResponse> extends AdjustLeverageSwapInputsProps<QuoteResponse> {
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
WithdrawalCaps,
|
|
14
14
|
} from '../idl_codegen/types';
|
|
15
15
|
import Decimal from 'decimal.js';
|
|
16
|
-
import { Fraction, ZERO_FRACTION } from '../classes
|
|
16
|
+
import { Fraction, ZERO_FRACTION } from '../classes';
|
|
17
17
|
import BN from 'bn.js';
|
|
18
18
|
import { numberToLamportsDecimal } from '../classes';
|
|
19
19
|
import { NULL_PUBKEY } from './pubkey';
|
|
@@ -21,7 +21,6 @@ import { OracleType, U16_MAX } from '@kamino-finance/scope-sdk';
|
|
|
21
21
|
import { LendingMarket } from '../lib';
|
|
22
22
|
|
|
23
23
|
export type ScopeOracleConfig = {
|
|
24
|
-
scopePriceConfigAddress: PublicKey;
|
|
25
24
|
name: string;
|
|
26
25
|
oracleType: string;
|
|
27
26
|
oracleId: number;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { KaminoMarket, KaminoObligation } from '../classes';
|
|
2
|
+
import Decimal from 'decimal.js';
|
|
3
|
+
import { Commitment, Connection, PublicKey } from '@solana/web3.js';
|
|
4
|
+
import { PubkeyHashMap } from './pubkey';
|
|
5
|
+
import bs58 from 'bs58';
|
|
6
|
+
import { PROGRAM_ID } from '../idl_codegen/programId';
|
|
7
|
+
import { Obligation } from '../idl_codegen/accounts';
|
|
8
|
+
|
|
9
|
+
export async function getUserObligationsInMarkets(
|
|
10
|
+
connection: Connection,
|
|
11
|
+
user: PublicKey,
|
|
12
|
+
markets: PubkeyHashMap<PublicKey, KaminoMarket>,
|
|
13
|
+
slot: number,
|
|
14
|
+
commitment: Commitment = 'processed',
|
|
15
|
+
programId: PublicKey = PROGRAM_ID
|
|
16
|
+
): Promise<KaminoObligation[]> {
|
|
17
|
+
const obligations = await connection.getProgramAccounts(programId, {
|
|
18
|
+
filters: [
|
|
19
|
+
{
|
|
20
|
+
dataSize: Obligation.layout.span + 8,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
memcmp: {
|
|
24
|
+
offset: 0,
|
|
25
|
+
bytes: bs58.encode(Obligation.discriminator),
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
memcmp: {
|
|
30
|
+
offset: 64,
|
|
31
|
+
bytes: user.toBase58(),
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
commitment,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const collateralExchangeRates = new PubkeyHashMap<PublicKey, Decimal>();
|
|
39
|
+
const cumulativeBorrowRates = new PubkeyHashMap<PublicKey, Decimal>();
|
|
40
|
+
const kaminoObligations: KaminoObligation[] = [];
|
|
41
|
+
for (const obligation of obligations) {
|
|
42
|
+
if (!obligation.account.owner.equals(programId)) {
|
|
43
|
+
throw new Error(`Account ${obligation.account.owner} doesn't belong to this program ${programId}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const obligationAccount = Obligation.decode(obligation.account.data);
|
|
47
|
+
|
|
48
|
+
if (!obligationAccount) {
|
|
49
|
+
throw Error('Could not parse obligation.');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const market = markets.get(obligationAccount.lendingMarket);
|
|
53
|
+
if (!market) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
KaminoObligation.addRatesForObligation(
|
|
58
|
+
market,
|
|
59
|
+
obligationAccount,
|
|
60
|
+
collateralExchangeRates,
|
|
61
|
+
cumulativeBorrowRates,
|
|
62
|
+
slot
|
|
63
|
+
);
|
|
64
|
+
kaminoObligations.push(
|
|
65
|
+
new KaminoObligation(market, obligation.pubkey, obligationAccount, collateralExchangeRates, cumulativeBorrowRates)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return kaminoObligations;
|
|
69
|
+
}
|
package/src/utils/oracle.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AccountInfo, Connection, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
|
-
import { OraclePrices, Scope } from '@kamino-finance/scope-sdk';
|
|
3
|
+
import { Configuration, OraclePrices, Scope } from '@kamino-finance/scope-sdk';
|
|
4
4
|
import { isNotNullPubkey, PubkeyHashMap, PublicKeySet } from './pubkey';
|
|
5
5
|
import { parseTokenSymbol } from '../classes';
|
|
6
6
|
import SwitchboardProgram from '@switchboard-xyz/sbv2-lite';
|
|
@@ -37,7 +37,7 @@ export type CandidatePrice = {
|
|
|
37
37
|
|
|
38
38
|
export type ScopePriceRefreshConfig = {
|
|
39
39
|
scope: Scope;
|
|
40
|
-
|
|
40
|
+
scopeConfigurations: [PublicKey, Configuration][];
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
export function getTokenOracleDataSync(
|
|
@@ -107,9 +107,10 @@ export function getTokenOracleDataSync(
|
|
|
107
107
|
// TODO: Add freshness of the latest price to match sc logic
|
|
108
108
|
export async function getTokenOracleData(
|
|
109
109
|
connection: Connection,
|
|
110
|
-
reserves: Reserve[]
|
|
110
|
+
reserves: Reserve[],
|
|
111
|
+
oracleAccounts?: AllOracleAccounts
|
|
111
112
|
): Promise<Array<[Reserve, TokenOracleData | undefined]>> {
|
|
112
|
-
const allOracleAccounts = await getAllOracleAccounts(connection, reserves);
|
|
113
|
+
const allOracleAccounts = oracleAccounts ?? (await getAllOracleAccounts(connection, reserves));
|
|
113
114
|
const switchboardV2 = await SwitchboardProgram.loadMainnet(connection);
|
|
114
115
|
return getTokenOracleDataSync(allOracleAccounts, switchboardV2, reserves);
|
|
115
116
|
}
|
package/src/utils/pubkey.ts
CHANGED
|
@@ -253,6 +253,15 @@ export class PubkeyHashMap<K extends PublicKey, V> implements Map<K, V> {
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
+
export function setOrAppend<K, V>(map: Map<K, V[]>, key: K, value: V): void {
|
|
257
|
+
const existing = map.get(key);
|
|
258
|
+
if (existing) {
|
|
259
|
+
existing.push(value);
|
|
260
|
+
} else {
|
|
261
|
+
map.set(key, [value]);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
256
265
|
export class HashablePublicKey extends PublicKey implements IEquality<HashablePublicKey> {
|
|
257
266
|
// We only use the last 32 bits of the public key for hashing
|
|
258
267
|
static MASK = new BN(1).shln(32).subn(1);
|