@anywalletkit/protocol-lending-kamino-solana 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -7
- package/dist/index.cjs +151 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +130 -78
- package/dist/index.d.ts +130 -78
- package/dist/index.js +151 -39
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -20,6 +20,85 @@ declare const divWadUp: (a: bigint, wad: bigint) => bigint;
|
|
|
20
20
|
/** `amount × (10_000 − bps) / 10_000`, rounded down. */
|
|
21
21
|
declare const lessBps: (amount: bigint, bps: number) => bigint;
|
|
22
22
|
|
|
23
|
+
/** An account as the wallet's RPC returns it. */
|
|
24
|
+
interface ChainAccount {
|
|
25
|
+
owner: string;
|
|
26
|
+
lamports: bigint;
|
|
27
|
+
data: Uint8Array;
|
|
28
|
+
}
|
|
29
|
+
/** How far the API's figures may sit from the chain's before the operation is refused, in basis points. */
|
|
30
|
+
declare const CHAIN_TOLERANCE_BPS = 100n;
|
|
31
|
+
interface VaultChain {
|
|
32
|
+
tokenMint: string;
|
|
33
|
+
tokenDecimals: number;
|
|
34
|
+
tokenProgram: string;
|
|
35
|
+
sharesMint: string;
|
|
36
|
+
sharesDecimals: number;
|
|
37
|
+
tokenAvailable: bigint;
|
|
38
|
+
sharesIssued: bigint;
|
|
39
|
+
pendingFeesSf: bigint;
|
|
40
|
+
/** Reserves the vault has invested in and the collateral (cTokens) it holds in each. */
|
|
41
|
+
allocations: Array<{
|
|
42
|
+
reserve: string;
|
|
43
|
+
ctokens: bigint;
|
|
44
|
+
}>;
|
|
45
|
+
minDeposit: bigint;
|
|
46
|
+
minWithdraw: bigint;
|
|
47
|
+
farm: string | null;
|
|
48
|
+
}
|
|
49
|
+
/** A kVault's `VaultState`. */
|
|
50
|
+
declare function decodeVault(address: string, acc: ChainAccount | null): VaultChain;
|
|
51
|
+
interface ReserveChain {
|
|
52
|
+
lendingMarket: string;
|
|
53
|
+
mint: string;
|
|
54
|
+
decimals: number;
|
|
55
|
+
tokenProgram: string;
|
|
56
|
+
/** Liquidity the reserve owes its depositors (available + borrowed − fees), scaled by {@link SF}. */
|
|
57
|
+
totalLiquiditySf: bigint;
|
|
58
|
+
/** cTokens issued against it. */
|
|
59
|
+
collateralSupply: bigint;
|
|
60
|
+
/** Cumulative borrow rate (scaled by {@link SF}) at the reserve's last refresh. */
|
|
61
|
+
cumulativeBorrowRate: bigint;
|
|
62
|
+
}
|
|
63
|
+
/** A klend `Reserve`. */
|
|
64
|
+
declare function decodeReserve(address: string, acc: ChainAccount | null): ReserveChain;
|
|
65
|
+
interface ObligationChain {
|
|
66
|
+
lendingMarket: string;
|
|
67
|
+
owner: string;
|
|
68
|
+
deposits: Array<{
|
|
69
|
+
reserve: string;
|
|
70
|
+
ctokens: bigint;
|
|
71
|
+
}>;
|
|
72
|
+
borrows: Array<{
|
|
73
|
+
reserve: string;
|
|
74
|
+
borrowedSf: bigint;
|
|
75
|
+
cumulativeBorrowRate: bigint;
|
|
76
|
+
}>;
|
|
77
|
+
}
|
|
78
|
+
/** A klend `Obligation`. */
|
|
79
|
+
declare function decodeObligation(address: string, acc: ChainAccount | null): ObligationChain;
|
|
80
|
+
/** The legs of an obligation, wherever they were read from (the chain, or the API's raw `state`). */
|
|
81
|
+
type ObligationLegs = Pick<ObligationChain, 'deposits' | 'borrows'>;
|
|
82
|
+
/** One deposit leg in base units of the reserve's token, rounded down. */
|
|
83
|
+
declare function depositLegLiquidity(r: ReserveChain, ctokens: bigint): bigint;
|
|
84
|
+
/** One debt leg in base units of the reserve's token, with the interest the reserve has accrued since, rounded up. */
|
|
85
|
+
declare function debtLegNow(r: ReserveChain, leg: ObligationChain['borrows'][number]): bigint;
|
|
86
|
+
/** What an obligation leg is worth in base units of the reserve's token: deposits rounded down, debt (with the interest the reserve has accrued since) up. */
|
|
87
|
+
declare function depositedLiquidity(o: ObligationLegs, r: ReserveChain, reserve: string): bigint;
|
|
88
|
+
declare function debtNow(o: ObligationLegs, r: ReserveChain, reserve: string): bigint;
|
|
89
|
+
/** A farm `UserState`: whose it is, which farm, and the shares staked (base units). */
|
|
90
|
+
declare function decodeFarmUser(address: string, acc: ChainAccount | null): {
|
|
91
|
+
farm: string;
|
|
92
|
+
owner: string;
|
|
93
|
+
staked: bigint;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Assets per share in token units, as a WAD (what the API's `tokensPerShare` means): the vault's idle
|
|
97
|
+
* tokens plus what its cTokens redeem for at each reserve's rate, less pending fees, over the shares
|
|
98
|
+
* issued. An empty vault prices a share at one token.
|
|
99
|
+
*/
|
|
100
|
+
declare function vaultTokensPerShareWad(v: VaultChain, reserves: ReadonlyMap<string, ReserveChain>): bigint;
|
|
101
|
+
|
|
23
102
|
declare const KAMINO_API = "https://api.kamino.finance";
|
|
24
103
|
/** Kamino's Main Market. */
|
|
25
104
|
declare const MAIN_MARKET = "7u3HeHxYDLhnCoErrtycNokbQYbWGzLs6JSDqGAv5PfF";
|
|
@@ -104,16 +183,32 @@ interface ApiVaultPosition {
|
|
|
104
183
|
interface ApiLoanLeg {
|
|
105
184
|
mint: string;
|
|
106
185
|
symbol: string;
|
|
186
|
+
/** Decimal string in token units. */
|
|
107
187
|
amount: string;
|
|
188
|
+
/** Decimal string; '' when nothing reports one. */
|
|
108
189
|
valueUsd: string;
|
|
190
|
+
/** The reserve the leg sits in, when known (always on legs read from the chain). */
|
|
191
|
+
reserve?: string;
|
|
192
|
+
}
|
|
193
|
+
/** An obligation's legs as the account stores them: cTokens per deposit reserve, debt × 2^60 with the borrow rate it was last charged at. */
|
|
194
|
+
interface ApiObligationState extends ObligationLegs {
|
|
195
|
+
owner: string;
|
|
196
|
+
lendingMarket: string;
|
|
109
197
|
}
|
|
110
198
|
interface ApiObligation {
|
|
111
199
|
obligation: string;
|
|
112
200
|
market: string;
|
|
113
201
|
user: string;
|
|
114
202
|
elevationGroup: number;
|
|
203
|
+
/**
|
|
204
|
+
* Per-token legs. From `getUserObligations` they are the API's decorated legs, which the live API
|
|
205
|
+
* leaves empty (`{}`) since 2026-10-28; from `KaminoMarketProtocolSolana.getPosition` they are the
|
|
206
|
+
* obligation's legs read from the chain.
|
|
207
|
+
*/
|
|
115
208
|
deposits: ApiLoanLeg[];
|
|
116
209
|
borrows: ApiLoanLeg[];
|
|
210
|
+
/** The row's raw `state` decoded (where the live API keeps the legs now); null when it has none. */
|
|
211
|
+
state: ApiObligationState | null;
|
|
117
212
|
/** Fractions. */
|
|
118
213
|
currentLtv: number;
|
|
119
214
|
maxLtv: number | null;
|
|
@@ -174,79 +269,6 @@ declare class KaminoApi {
|
|
|
174
269
|
buildLendRepay(p: KtxLend): Promise<string>;
|
|
175
270
|
}
|
|
176
271
|
|
|
177
|
-
/** An account as the wallet's RPC returns it. */
|
|
178
|
-
interface ChainAccount {
|
|
179
|
-
owner: string;
|
|
180
|
-
lamports: bigint;
|
|
181
|
-
data: Uint8Array;
|
|
182
|
-
}
|
|
183
|
-
/** How far the API's figures may sit from the chain's before the operation is refused, in basis points. */
|
|
184
|
-
declare const CHAIN_TOLERANCE_BPS = 100n;
|
|
185
|
-
interface VaultChain {
|
|
186
|
-
tokenMint: string;
|
|
187
|
-
tokenDecimals: number;
|
|
188
|
-
tokenProgram: string;
|
|
189
|
-
sharesMint: string;
|
|
190
|
-
sharesDecimals: number;
|
|
191
|
-
tokenAvailable: bigint;
|
|
192
|
-
sharesIssued: bigint;
|
|
193
|
-
pendingFeesSf: bigint;
|
|
194
|
-
/** Reserves the vault has invested in and the collateral (cTokens) it holds in each. */
|
|
195
|
-
allocations: Array<{
|
|
196
|
-
reserve: string;
|
|
197
|
-
ctokens: bigint;
|
|
198
|
-
}>;
|
|
199
|
-
minDeposit: bigint;
|
|
200
|
-
minWithdraw: bigint;
|
|
201
|
-
farm: string | null;
|
|
202
|
-
}
|
|
203
|
-
/** A kVault's `VaultState`. */
|
|
204
|
-
declare function decodeVault(address: string, acc: ChainAccount | null): VaultChain;
|
|
205
|
-
interface ReserveChain {
|
|
206
|
-
lendingMarket: string;
|
|
207
|
-
mint: string;
|
|
208
|
-
decimals: number;
|
|
209
|
-
tokenProgram: string;
|
|
210
|
-
/** Liquidity the reserve owes its depositors (available + borrowed − fees), scaled by {@link SF}. */
|
|
211
|
-
totalLiquiditySf: bigint;
|
|
212
|
-
/** cTokens issued against it. */
|
|
213
|
-
collateralSupply: bigint;
|
|
214
|
-
/** Cumulative borrow rate (scaled by {@link SF}) at the reserve's last refresh. */
|
|
215
|
-
cumulativeBorrowRate: bigint;
|
|
216
|
-
}
|
|
217
|
-
/** A klend `Reserve`. */
|
|
218
|
-
declare function decodeReserve(address: string, acc: ChainAccount | null): ReserveChain;
|
|
219
|
-
interface ObligationChain {
|
|
220
|
-
lendingMarket: string;
|
|
221
|
-
owner: string;
|
|
222
|
-
deposits: Array<{
|
|
223
|
-
reserve: string;
|
|
224
|
-
ctokens: bigint;
|
|
225
|
-
}>;
|
|
226
|
-
borrows: Array<{
|
|
227
|
-
reserve: string;
|
|
228
|
-
borrowedSf: bigint;
|
|
229
|
-
cumulativeBorrowRate: bigint;
|
|
230
|
-
}>;
|
|
231
|
-
}
|
|
232
|
-
/** A klend `Obligation`. */
|
|
233
|
-
declare function decodeObligation(address: string, acc: ChainAccount | null): ObligationChain;
|
|
234
|
-
/** What an obligation leg is worth in base units of the reserve's token: deposits rounded down, debt (with the interest the reserve has accrued since) up. */
|
|
235
|
-
declare function depositedLiquidity(o: ObligationChain, r: ReserveChain, reserve: string): bigint;
|
|
236
|
-
declare function debtNow(o: ObligationChain, r: ReserveChain, reserve: string): bigint;
|
|
237
|
-
/** A farm `UserState`: whose it is, which farm, and the shares staked (base units). */
|
|
238
|
-
declare function decodeFarmUser(address: string, acc: ChainAccount | null): {
|
|
239
|
-
farm: string;
|
|
240
|
-
owner: string;
|
|
241
|
-
staked: bigint;
|
|
242
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* Assets per share in token units, as a WAD (what the API's `tokensPerShare` means): the vault's idle
|
|
245
|
-
* tokens plus what its cTokens redeem for at each reserve's rate, less pending fees, over the shares
|
|
246
|
-
* issued. An empty vault prices a share at one token.
|
|
247
|
-
*/
|
|
248
|
-
declare function vaultTokensPerShareWad(v: VaultChain, reserves: ReadonlyMap<string, ReserveChain>): bigint;
|
|
249
|
-
|
|
250
272
|
/** Mirrors wallet-solana's `SerializedInstructionRule`. */
|
|
251
273
|
interface InstructionRule {
|
|
252
274
|
program: string;
|
|
@@ -575,9 +597,13 @@ interface MarketInfo extends ApiMarket {
|
|
|
575
597
|
reserves: ReserveInfo[];
|
|
576
598
|
}
|
|
577
599
|
interface MarketPosition {
|
|
578
|
-
/**
|
|
600
|
+
/**
|
|
601
|
+
* The obligations (loans) the wallet has in this market, as they stand on chain; an empty list means
|
|
602
|
+
* no position. Their `deposits` / `borrows` legs are the chain's, each naming its reserve; LTVs and
|
|
603
|
+
* USD values stay the API's.
|
|
604
|
+
*/
|
|
579
605
|
obligations: ApiObligation[];
|
|
580
|
-
/** Base units per mint, summed over obligations. */
|
|
606
|
+
/** Base units per mint, summed over obligations, from the chain (debt with the interest the reserve has accrued). */
|
|
581
607
|
supplied: Record<string, bigint>;
|
|
582
608
|
borrowed: Record<string, bigint>;
|
|
583
609
|
}
|
|
@@ -609,8 +635,20 @@ declare class KaminoMarketProtocolSolana extends KaminoBase<KaminoMarketConfig>
|
|
|
609
635
|
getMarket(): Promise<MarketInfo>;
|
|
610
636
|
/** The reserve a mint maps to: the pinned one, else the deepest by supplied value. */
|
|
611
637
|
resolveReserve(mint: string): Promise<ReserveInfo>;
|
|
612
|
-
/**
|
|
638
|
+
/**
|
|
639
|
+
* Obligations and per-mint totals, read from the chain (watch 2026-11-04: the live API now answers
|
|
640
|
+
* `deposits: {}` / `borrows: {}` and keeps the legs in its raw `state`, so its figures said "no
|
|
641
|
+
* position" for wallets with millions supplied). The API only names the wallet's obligations; each
|
|
642
|
+
* is read from the chain and must be the wallet's on this market, and the wallet's vanilla obligation
|
|
643
|
+
* is read even when the API leaves it out. A listed obligation that no longer exists is closed.
|
|
644
|
+
* Amounts are what each leg redeems for, or owes, at its reserve's on-chain rate.
|
|
645
|
+
*/
|
|
613
646
|
getPosition(): Promise<MarketPosition>;
|
|
647
|
+
/**
|
|
648
|
+
* Reserves of this market from the chain, keyed by address: each must be a klend Reserve on this
|
|
649
|
+
* market. `known` (already read) is reused and filled in.
|
|
650
|
+
*/
|
|
651
|
+
private chainReserves;
|
|
614
652
|
/**
|
|
615
653
|
* The reserve and the wallet's vanilla obligation from the chain (scan 2026-10-27 modules, F1/F6/F10):
|
|
616
654
|
* the reserve must be this market's and lend the token, 'max' comes from the obligation, and the
|
|
@@ -626,10 +664,24 @@ declare class KaminoMarketProtocolSolana extends KaminoBase<KaminoMarketConfig>
|
|
|
626
664
|
* within 1%: an inflated debt or a negative deposit is refused (scan 2026-10-27 modules, F6/F10).
|
|
627
665
|
*/
|
|
628
666
|
private resolveMax;
|
|
629
|
-
/**
|
|
667
|
+
/** What the legs hold in, or owe of, `mint` across every reserve they name, at the reserves' on-chain rates. */
|
|
668
|
+
private perMint;
|
|
669
|
+
/**
|
|
670
|
+
* The API's figure for one leg of the wallet's vanilla obligation; undefined when it reports none. Its
|
|
671
|
+
* decorated per-token legs count when it gives them; the live API (2026-10-28 on) leaves them empty and
|
|
672
|
+
* keeps the account's legs in the row's raw `state` (cTokens, scaled debt), which are valued at the
|
|
673
|
+
* reserves' on-chain rates, so a `state` that is not the chain's obligation is refused all the same.
|
|
674
|
+
*/
|
|
630
675
|
private reported;
|
|
631
676
|
quoteSupply(o: SupplyOptions): Promise<MarketQuote>;
|
|
632
677
|
supply(o: SupplyOptions): Promise<LendingResult>;
|
|
678
|
+
/**
|
|
679
|
+
* A withdrawal pays out about what was asked: at least the amount less the slippage tolerance, at
|
|
680
|
+
* most the amount plus that tolerance (interest accrued before the block, on a 'max'), one cToken's
|
|
681
|
+
* worth at the reserve's on-chain rate (klend redeems whole cTokens) and a unit of rounding. A bigger
|
|
682
|
+
* payout is collateral the user did not choose to take out of the obligation.
|
|
683
|
+
*/
|
|
684
|
+
private withdrawExpectation;
|
|
633
685
|
quoteWithdraw(o: KaminoMarketWithdrawOptions): Promise<MarketQuote>;
|
|
634
686
|
withdraw(o: KaminoMarketWithdrawOptions): Promise<LendingResult>;
|
|
635
687
|
/** A borrow pays out at most what was asked: a bigger one is debt the user did not choose. */
|
|
@@ -676,4 +728,4 @@ declare function associatedTokenAddress(owner: string, mint: string, tokenProgra
|
|
|
676
728
|
/** A farm's state for one staker: `["user", farm, owner]` under the farms program (checked against mainnet user states, 2026-10-28). */
|
|
677
729
|
declare function farmUserState(farm: string, owner: string, farmsProgram?: string): string;
|
|
678
730
|
|
|
679
|
-
export { ADDRESS_LOOKUP_TABLE_PROGRAM, type AmountOption, type ApiLoanLeg, type ApiMarket, type ApiObligation, type ApiReserve, type ApiVault, type ApiVaultAllocation, type ApiVaultMetrics, type ApiVaultPosition, CHAIN_TOLERANCE_BPS, type ChainAccount, DEFAULT_FIRST_DEPOSIT_ALLOWANCE, DEFAULT_RENT_ALLOWANCE, type Expectation, FARMS_PROGRAM, INSTRUCTION_NAMES, IX, type InstructionRule, KAMINO_API, KAMINO_PROGRAM_ALLOWLIST, KLEND_PROGRAM, KNOWN_DECIMALS, KVAULT_PROGRAM, KaminoApi, KaminoBase, type KaminoBaseConfig, KaminoError, type KaminoMarketConfig, KaminoMarketProtocolSolana, type KaminoMarketRepayOptions, type KaminoMarketWithdrawOptions, type KaminoVaultConfig, KaminoVaultProtocolSolana, type KaminoVaultSupplyOptions, type KaminoVaultWithdrawOptions, type KtxLend, type KtxVaultDeposit, type KtxVaultWithdraw, MAIN_MARKET, MEMO_PROGRAM, type MarketInfo, type MarketPosition, type MarketQuote, type MarketRuleAccounts, type ObligationChain, type ReserveChain, type ReserveInfo, SOLANA_MAINNET, type SerializedGuard, type SolanaAccountSurface, type VaultChain, type VaultInfo, type VaultPosition, type VaultRuleAccounts, type VaultSupplyQuote, type VaultWithdrawQuote, WAD, WITHDRAW_ALL, WSOL_MINT, associatedTokenAddress, debtNow, decodeFarmUser, decodeObligation, decodeReserve, decodeVault, KaminoVaultProtocolSolana as default, depositedLiquidity, divWadUp, farmUserState, findProgramAddress, fromDecimalString, instructionName, lessBps, marketRules, mulWad, plumbing, toAmount, toDecimalString, toWad, vanillaObligation, vaultRules, vaultSharesMint, vaultTokensPerShareWad };
|
|
731
|
+
export { ADDRESS_LOOKUP_TABLE_PROGRAM, type AmountOption, type ApiLoanLeg, type ApiMarket, type ApiObligation, type ApiObligationState, type ApiReserve, type ApiVault, type ApiVaultAllocation, type ApiVaultMetrics, type ApiVaultPosition, CHAIN_TOLERANCE_BPS, type ChainAccount, DEFAULT_FIRST_DEPOSIT_ALLOWANCE, DEFAULT_RENT_ALLOWANCE, type Expectation, FARMS_PROGRAM, INSTRUCTION_NAMES, IX, type InstructionRule, KAMINO_API, KAMINO_PROGRAM_ALLOWLIST, KLEND_PROGRAM, KNOWN_DECIMALS, KVAULT_PROGRAM, KaminoApi, KaminoBase, type KaminoBaseConfig, KaminoError, type KaminoMarketConfig, KaminoMarketProtocolSolana, type KaminoMarketRepayOptions, type KaminoMarketWithdrawOptions, type KaminoVaultConfig, KaminoVaultProtocolSolana, type KaminoVaultSupplyOptions, type KaminoVaultWithdrawOptions, type KtxLend, type KtxVaultDeposit, type KtxVaultWithdraw, MAIN_MARKET, MEMO_PROGRAM, type MarketInfo, type MarketPosition, type MarketQuote, type MarketRuleAccounts, type ObligationChain, type ObligationLegs, type ReserveChain, type ReserveInfo, SOLANA_MAINNET, type SerializedGuard, type SolanaAccountSurface, type VaultChain, type VaultInfo, type VaultPosition, type VaultRuleAccounts, type VaultSupplyQuote, type VaultWithdrawQuote, WAD, WITHDRAW_ALL, WSOL_MINT, associatedTokenAddress, debtLegNow, debtNow, decodeFarmUser, decodeObligation, decodeReserve, decodeVault, KaminoVaultProtocolSolana as default, depositLegLiquidity, depositedLiquidity, divWadUp, farmUserState, findProgramAddress, fromDecimalString, instructionName, lessBps, marketRules, mulWad, plumbing, toAmount, toDecimalString, toWad, vanillaObligation, vaultRules, vaultSharesMint, vaultTokensPerShareWad };
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,85 @@ declare const divWadUp: (a: bigint, wad: bigint) => bigint;
|
|
|
20
20
|
/** `amount × (10_000 − bps) / 10_000`, rounded down. */
|
|
21
21
|
declare const lessBps: (amount: bigint, bps: number) => bigint;
|
|
22
22
|
|
|
23
|
+
/** An account as the wallet's RPC returns it. */
|
|
24
|
+
interface ChainAccount {
|
|
25
|
+
owner: string;
|
|
26
|
+
lamports: bigint;
|
|
27
|
+
data: Uint8Array;
|
|
28
|
+
}
|
|
29
|
+
/** How far the API's figures may sit from the chain's before the operation is refused, in basis points. */
|
|
30
|
+
declare const CHAIN_TOLERANCE_BPS = 100n;
|
|
31
|
+
interface VaultChain {
|
|
32
|
+
tokenMint: string;
|
|
33
|
+
tokenDecimals: number;
|
|
34
|
+
tokenProgram: string;
|
|
35
|
+
sharesMint: string;
|
|
36
|
+
sharesDecimals: number;
|
|
37
|
+
tokenAvailable: bigint;
|
|
38
|
+
sharesIssued: bigint;
|
|
39
|
+
pendingFeesSf: bigint;
|
|
40
|
+
/** Reserves the vault has invested in and the collateral (cTokens) it holds in each. */
|
|
41
|
+
allocations: Array<{
|
|
42
|
+
reserve: string;
|
|
43
|
+
ctokens: bigint;
|
|
44
|
+
}>;
|
|
45
|
+
minDeposit: bigint;
|
|
46
|
+
minWithdraw: bigint;
|
|
47
|
+
farm: string | null;
|
|
48
|
+
}
|
|
49
|
+
/** A kVault's `VaultState`. */
|
|
50
|
+
declare function decodeVault(address: string, acc: ChainAccount | null): VaultChain;
|
|
51
|
+
interface ReserveChain {
|
|
52
|
+
lendingMarket: string;
|
|
53
|
+
mint: string;
|
|
54
|
+
decimals: number;
|
|
55
|
+
tokenProgram: string;
|
|
56
|
+
/** Liquidity the reserve owes its depositors (available + borrowed − fees), scaled by {@link SF}. */
|
|
57
|
+
totalLiquiditySf: bigint;
|
|
58
|
+
/** cTokens issued against it. */
|
|
59
|
+
collateralSupply: bigint;
|
|
60
|
+
/** Cumulative borrow rate (scaled by {@link SF}) at the reserve's last refresh. */
|
|
61
|
+
cumulativeBorrowRate: bigint;
|
|
62
|
+
}
|
|
63
|
+
/** A klend `Reserve`. */
|
|
64
|
+
declare function decodeReserve(address: string, acc: ChainAccount | null): ReserveChain;
|
|
65
|
+
interface ObligationChain {
|
|
66
|
+
lendingMarket: string;
|
|
67
|
+
owner: string;
|
|
68
|
+
deposits: Array<{
|
|
69
|
+
reserve: string;
|
|
70
|
+
ctokens: bigint;
|
|
71
|
+
}>;
|
|
72
|
+
borrows: Array<{
|
|
73
|
+
reserve: string;
|
|
74
|
+
borrowedSf: bigint;
|
|
75
|
+
cumulativeBorrowRate: bigint;
|
|
76
|
+
}>;
|
|
77
|
+
}
|
|
78
|
+
/** A klend `Obligation`. */
|
|
79
|
+
declare function decodeObligation(address: string, acc: ChainAccount | null): ObligationChain;
|
|
80
|
+
/** The legs of an obligation, wherever they were read from (the chain, or the API's raw `state`). */
|
|
81
|
+
type ObligationLegs = Pick<ObligationChain, 'deposits' | 'borrows'>;
|
|
82
|
+
/** One deposit leg in base units of the reserve's token, rounded down. */
|
|
83
|
+
declare function depositLegLiquidity(r: ReserveChain, ctokens: bigint): bigint;
|
|
84
|
+
/** One debt leg in base units of the reserve's token, with the interest the reserve has accrued since, rounded up. */
|
|
85
|
+
declare function debtLegNow(r: ReserveChain, leg: ObligationChain['borrows'][number]): bigint;
|
|
86
|
+
/** What an obligation leg is worth in base units of the reserve's token: deposits rounded down, debt (with the interest the reserve has accrued since) up. */
|
|
87
|
+
declare function depositedLiquidity(o: ObligationLegs, r: ReserveChain, reserve: string): bigint;
|
|
88
|
+
declare function debtNow(o: ObligationLegs, r: ReserveChain, reserve: string): bigint;
|
|
89
|
+
/** A farm `UserState`: whose it is, which farm, and the shares staked (base units). */
|
|
90
|
+
declare function decodeFarmUser(address: string, acc: ChainAccount | null): {
|
|
91
|
+
farm: string;
|
|
92
|
+
owner: string;
|
|
93
|
+
staked: bigint;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Assets per share in token units, as a WAD (what the API's `tokensPerShare` means): the vault's idle
|
|
97
|
+
* tokens plus what its cTokens redeem for at each reserve's rate, less pending fees, over the shares
|
|
98
|
+
* issued. An empty vault prices a share at one token.
|
|
99
|
+
*/
|
|
100
|
+
declare function vaultTokensPerShareWad(v: VaultChain, reserves: ReadonlyMap<string, ReserveChain>): bigint;
|
|
101
|
+
|
|
23
102
|
declare const KAMINO_API = "https://api.kamino.finance";
|
|
24
103
|
/** Kamino's Main Market. */
|
|
25
104
|
declare const MAIN_MARKET = "7u3HeHxYDLhnCoErrtycNokbQYbWGzLs6JSDqGAv5PfF";
|
|
@@ -104,16 +183,32 @@ interface ApiVaultPosition {
|
|
|
104
183
|
interface ApiLoanLeg {
|
|
105
184
|
mint: string;
|
|
106
185
|
symbol: string;
|
|
186
|
+
/** Decimal string in token units. */
|
|
107
187
|
amount: string;
|
|
188
|
+
/** Decimal string; '' when nothing reports one. */
|
|
108
189
|
valueUsd: string;
|
|
190
|
+
/** The reserve the leg sits in, when known (always on legs read from the chain). */
|
|
191
|
+
reserve?: string;
|
|
192
|
+
}
|
|
193
|
+
/** An obligation's legs as the account stores them: cTokens per deposit reserve, debt × 2^60 with the borrow rate it was last charged at. */
|
|
194
|
+
interface ApiObligationState extends ObligationLegs {
|
|
195
|
+
owner: string;
|
|
196
|
+
lendingMarket: string;
|
|
109
197
|
}
|
|
110
198
|
interface ApiObligation {
|
|
111
199
|
obligation: string;
|
|
112
200
|
market: string;
|
|
113
201
|
user: string;
|
|
114
202
|
elevationGroup: number;
|
|
203
|
+
/**
|
|
204
|
+
* Per-token legs. From `getUserObligations` they are the API's decorated legs, which the live API
|
|
205
|
+
* leaves empty (`{}`) since 2026-10-28; from `KaminoMarketProtocolSolana.getPosition` they are the
|
|
206
|
+
* obligation's legs read from the chain.
|
|
207
|
+
*/
|
|
115
208
|
deposits: ApiLoanLeg[];
|
|
116
209
|
borrows: ApiLoanLeg[];
|
|
210
|
+
/** The row's raw `state` decoded (where the live API keeps the legs now); null when it has none. */
|
|
211
|
+
state: ApiObligationState | null;
|
|
117
212
|
/** Fractions. */
|
|
118
213
|
currentLtv: number;
|
|
119
214
|
maxLtv: number | null;
|
|
@@ -174,79 +269,6 @@ declare class KaminoApi {
|
|
|
174
269
|
buildLendRepay(p: KtxLend): Promise<string>;
|
|
175
270
|
}
|
|
176
271
|
|
|
177
|
-
/** An account as the wallet's RPC returns it. */
|
|
178
|
-
interface ChainAccount {
|
|
179
|
-
owner: string;
|
|
180
|
-
lamports: bigint;
|
|
181
|
-
data: Uint8Array;
|
|
182
|
-
}
|
|
183
|
-
/** How far the API's figures may sit from the chain's before the operation is refused, in basis points. */
|
|
184
|
-
declare const CHAIN_TOLERANCE_BPS = 100n;
|
|
185
|
-
interface VaultChain {
|
|
186
|
-
tokenMint: string;
|
|
187
|
-
tokenDecimals: number;
|
|
188
|
-
tokenProgram: string;
|
|
189
|
-
sharesMint: string;
|
|
190
|
-
sharesDecimals: number;
|
|
191
|
-
tokenAvailable: bigint;
|
|
192
|
-
sharesIssued: bigint;
|
|
193
|
-
pendingFeesSf: bigint;
|
|
194
|
-
/** Reserves the vault has invested in and the collateral (cTokens) it holds in each. */
|
|
195
|
-
allocations: Array<{
|
|
196
|
-
reserve: string;
|
|
197
|
-
ctokens: bigint;
|
|
198
|
-
}>;
|
|
199
|
-
minDeposit: bigint;
|
|
200
|
-
minWithdraw: bigint;
|
|
201
|
-
farm: string | null;
|
|
202
|
-
}
|
|
203
|
-
/** A kVault's `VaultState`. */
|
|
204
|
-
declare function decodeVault(address: string, acc: ChainAccount | null): VaultChain;
|
|
205
|
-
interface ReserveChain {
|
|
206
|
-
lendingMarket: string;
|
|
207
|
-
mint: string;
|
|
208
|
-
decimals: number;
|
|
209
|
-
tokenProgram: string;
|
|
210
|
-
/** Liquidity the reserve owes its depositors (available + borrowed − fees), scaled by {@link SF}. */
|
|
211
|
-
totalLiquiditySf: bigint;
|
|
212
|
-
/** cTokens issued against it. */
|
|
213
|
-
collateralSupply: bigint;
|
|
214
|
-
/** Cumulative borrow rate (scaled by {@link SF}) at the reserve's last refresh. */
|
|
215
|
-
cumulativeBorrowRate: bigint;
|
|
216
|
-
}
|
|
217
|
-
/** A klend `Reserve`. */
|
|
218
|
-
declare function decodeReserve(address: string, acc: ChainAccount | null): ReserveChain;
|
|
219
|
-
interface ObligationChain {
|
|
220
|
-
lendingMarket: string;
|
|
221
|
-
owner: string;
|
|
222
|
-
deposits: Array<{
|
|
223
|
-
reserve: string;
|
|
224
|
-
ctokens: bigint;
|
|
225
|
-
}>;
|
|
226
|
-
borrows: Array<{
|
|
227
|
-
reserve: string;
|
|
228
|
-
borrowedSf: bigint;
|
|
229
|
-
cumulativeBorrowRate: bigint;
|
|
230
|
-
}>;
|
|
231
|
-
}
|
|
232
|
-
/** A klend `Obligation`. */
|
|
233
|
-
declare function decodeObligation(address: string, acc: ChainAccount | null): ObligationChain;
|
|
234
|
-
/** What an obligation leg is worth in base units of the reserve's token: deposits rounded down, debt (with the interest the reserve has accrued since) up. */
|
|
235
|
-
declare function depositedLiquidity(o: ObligationChain, r: ReserveChain, reserve: string): bigint;
|
|
236
|
-
declare function debtNow(o: ObligationChain, r: ReserveChain, reserve: string): bigint;
|
|
237
|
-
/** A farm `UserState`: whose it is, which farm, and the shares staked (base units). */
|
|
238
|
-
declare function decodeFarmUser(address: string, acc: ChainAccount | null): {
|
|
239
|
-
farm: string;
|
|
240
|
-
owner: string;
|
|
241
|
-
staked: bigint;
|
|
242
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* Assets per share in token units, as a WAD (what the API's `tokensPerShare` means): the vault's idle
|
|
245
|
-
* tokens plus what its cTokens redeem for at each reserve's rate, less pending fees, over the shares
|
|
246
|
-
* issued. An empty vault prices a share at one token.
|
|
247
|
-
*/
|
|
248
|
-
declare function vaultTokensPerShareWad(v: VaultChain, reserves: ReadonlyMap<string, ReserveChain>): bigint;
|
|
249
|
-
|
|
250
272
|
/** Mirrors wallet-solana's `SerializedInstructionRule`. */
|
|
251
273
|
interface InstructionRule {
|
|
252
274
|
program: string;
|
|
@@ -575,9 +597,13 @@ interface MarketInfo extends ApiMarket {
|
|
|
575
597
|
reserves: ReserveInfo[];
|
|
576
598
|
}
|
|
577
599
|
interface MarketPosition {
|
|
578
|
-
/**
|
|
600
|
+
/**
|
|
601
|
+
* The obligations (loans) the wallet has in this market, as they stand on chain; an empty list means
|
|
602
|
+
* no position. Their `deposits` / `borrows` legs are the chain's, each naming its reserve; LTVs and
|
|
603
|
+
* USD values stay the API's.
|
|
604
|
+
*/
|
|
579
605
|
obligations: ApiObligation[];
|
|
580
|
-
/** Base units per mint, summed over obligations. */
|
|
606
|
+
/** Base units per mint, summed over obligations, from the chain (debt with the interest the reserve has accrued). */
|
|
581
607
|
supplied: Record<string, bigint>;
|
|
582
608
|
borrowed: Record<string, bigint>;
|
|
583
609
|
}
|
|
@@ -609,8 +635,20 @@ declare class KaminoMarketProtocolSolana extends KaminoBase<KaminoMarketConfig>
|
|
|
609
635
|
getMarket(): Promise<MarketInfo>;
|
|
610
636
|
/** The reserve a mint maps to: the pinned one, else the deepest by supplied value. */
|
|
611
637
|
resolveReserve(mint: string): Promise<ReserveInfo>;
|
|
612
|
-
/**
|
|
638
|
+
/**
|
|
639
|
+
* Obligations and per-mint totals, read from the chain (watch 2026-11-04: the live API now answers
|
|
640
|
+
* `deposits: {}` / `borrows: {}` and keeps the legs in its raw `state`, so its figures said "no
|
|
641
|
+
* position" for wallets with millions supplied). The API only names the wallet's obligations; each
|
|
642
|
+
* is read from the chain and must be the wallet's on this market, and the wallet's vanilla obligation
|
|
643
|
+
* is read even when the API leaves it out. A listed obligation that no longer exists is closed.
|
|
644
|
+
* Amounts are what each leg redeems for, or owes, at its reserve's on-chain rate.
|
|
645
|
+
*/
|
|
613
646
|
getPosition(): Promise<MarketPosition>;
|
|
647
|
+
/**
|
|
648
|
+
* Reserves of this market from the chain, keyed by address: each must be a klend Reserve on this
|
|
649
|
+
* market. `known` (already read) is reused and filled in.
|
|
650
|
+
*/
|
|
651
|
+
private chainReserves;
|
|
614
652
|
/**
|
|
615
653
|
* The reserve and the wallet's vanilla obligation from the chain (scan 2026-10-27 modules, F1/F6/F10):
|
|
616
654
|
* the reserve must be this market's and lend the token, 'max' comes from the obligation, and the
|
|
@@ -626,10 +664,24 @@ declare class KaminoMarketProtocolSolana extends KaminoBase<KaminoMarketConfig>
|
|
|
626
664
|
* within 1%: an inflated debt or a negative deposit is refused (scan 2026-10-27 modules, F6/F10).
|
|
627
665
|
*/
|
|
628
666
|
private resolveMax;
|
|
629
|
-
/**
|
|
667
|
+
/** What the legs hold in, or owe of, `mint` across every reserve they name, at the reserves' on-chain rates. */
|
|
668
|
+
private perMint;
|
|
669
|
+
/**
|
|
670
|
+
* The API's figure for one leg of the wallet's vanilla obligation; undefined when it reports none. Its
|
|
671
|
+
* decorated per-token legs count when it gives them; the live API (2026-10-28 on) leaves them empty and
|
|
672
|
+
* keeps the account's legs in the row's raw `state` (cTokens, scaled debt), which are valued at the
|
|
673
|
+
* reserves' on-chain rates, so a `state` that is not the chain's obligation is refused all the same.
|
|
674
|
+
*/
|
|
630
675
|
private reported;
|
|
631
676
|
quoteSupply(o: SupplyOptions): Promise<MarketQuote>;
|
|
632
677
|
supply(o: SupplyOptions): Promise<LendingResult>;
|
|
678
|
+
/**
|
|
679
|
+
* A withdrawal pays out about what was asked: at least the amount less the slippage tolerance, at
|
|
680
|
+
* most the amount plus that tolerance (interest accrued before the block, on a 'max'), one cToken's
|
|
681
|
+
* worth at the reserve's on-chain rate (klend redeems whole cTokens) and a unit of rounding. A bigger
|
|
682
|
+
* payout is collateral the user did not choose to take out of the obligation.
|
|
683
|
+
*/
|
|
684
|
+
private withdrawExpectation;
|
|
633
685
|
quoteWithdraw(o: KaminoMarketWithdrawOptions): Promise<MarketQuote>;
|
|
634
686
|
withdraw(o: KaminoMarketWithdrawOptions): Promise<LendingResult>;
|
|
635
687
|
/** A borrow pays out at most what was asked: a bigger one is debt the user did not choose. */
|
|
@@ -676,4 +728,4 @@ declare function associatedTokenAddress(owner: string, mint: string, tokenProgra
|
|
|
676
728
|
/** A farm's state for one staker: `["user", farm, owner]` under the farms program (checked against mainnet user states, 2026-10-28). */
|
|
677
729
|
declare function farmUserState(farm: string, owner: string, farmsProgram?: string): string;
|
|
678
730
|
|
|
679
|
-
export { ADDRESS_LOOKUP_TABLE_PROGRAM, type AmountOption, type ApiLoanLeg, type ApiMarket, type ApiObligation, type ApiReserve, type ApiVault, type ApiVaultAllocation, type ApiVaultMetrics, type ApiVaultPosition, CHAIN_TOLERANCE_BPS, type ChainAccount, DEFAULT_FIRST_DEPOSIT_ALLOWANCE, DEFAULT_RENT_ALLOWANCE, type Expectation, FARMS_PROGRAM, INSTRUCTION_NAMES, IX, type InstructionRule, KAMINO_API, KAMINO_PROGRAM_ALLOWLIST, KLEND_PROGRAM, KNOWN_DECIMALS, KVAULT_PROGRAM, KaminoApi, KaminoBase, type KaminoBaseConfig, KaminoError, type KaminoMarketConfig, KaminoMarketProtocolSolana, type KaminoMarketRepayOptions, type KaminoMarketWithdrawOptions, type KaminoVaultConfig, KaminoVaultProtocolSolana, type KaminoVaultSupplyOptions, type KaminoVaultWithdrawOptions, type KtxLend, type KtxVaultDeposit, type KtxVaultWithdraw, MAIN_MARKET, MEMO_PROGRAM, type MarketInfo, type MarketPosition, type MarketQuote, type MarketRuleAccounts, type ObligationChain, type ReserveChain, type ReserveInfo, SOLANA_MAINNET, type SerializedGuard, type SolanaAccountSurface, type VaultChain, type VaultInfo, type VaultPosition, type VaultRuleAccounts, type VaultSupplyQuote, type VaultWithdrawQuote, WAD, WITHDRAW_ALL, WSOL_MINT, associatedTokenAddress, debtNow, decodeFarmUser, decodeObligation, decodeReserve, decodeVault, KaminoVaultProtocolSolana as default, depositedLiquidity, divWadUp, farmUserState, findProgramAddress, fromDecimalString, instructionName, lessBps, marketRules, mulWad, plumbing, toAmount, toDecimalString, toWad, vanillaObligation, vaultRules, vaultSharesMint, vaultTokensPerShareWad };
|
|
731
|
+
export { ADDRESS_LOOKUP_TABLE_PROGRAM, type AmountOption, type ApiLoanLeg, type ApiMarket, type ApiObligation, type ApiObligationState, type ApiReserve, type ApiVault, type ApiVaultAllocation, type ApiVaultMetrics, type ApiVaultPosition, CHAIN_TOLERANCE_BPS, type ChainAccount, DEFAULT_FIRST_DEPOSIT_ALLOWANCE, DEFAULT_RENT_ALLOWANCE, type Expectation, FARMS_PROGRAM, INSTRUCTION_NAMES, IX, type InstructionRule, KAMINO_API, KAMINO_PROGRAM_ALLOWLIST, KLEND_PROGRAM, KNOWN_DECIMALS, KVAULT_PROGRAM, KaminoApi, KaminoBase, type KaminoBaseConfig, KaminoError, type KaminoMarketConfig, KaminoMarketProtocolSolana, type KaminoMarketRepayOptions, type KaminoMarketWithdrawOptions, type KaminoVaultConfig, KaminoVaultProtocolSolana, type KaminoVaultSupplyOptions, type KaminoVaultWithdrawOptions, type KtxLend, type KtxVaultDeposit, type KtxVaultWithdraw, MAIN_MARKET, MEMO_PROGRAM, type MarketInfo, type MarketPosition, type MarketQuote, type MarketRuleAccounts, type ObligationChain, type ObligationLegs, type ReserveChain, type ReserveInfo, SOLANA_MAINNET, type SerializedGuard, type SolanaAccountSurface, type VaultChain, type VaultInfo, type VaultPosition, type VaultRuleAccounts, type VaultSupplyQuote, type VaultWithdrawQuote, WAD, WITHDRAW_ALL, WSOL_MINT, associatedTokenAddress, debtLegNow, debtNow, decodeFarmUser, decodeObligation, decodeReserve, decodeVault, KaminoVaultProtocolSolana as default, depositLegLiquidity, depositedLiquidity, divWadUp, farmUserState, findProgramAddress, fromDecimalString, instructionName, lessBps, marketRules, mulWad, plumbing, toAmount, toDecimalString, toWad, vanillaObligation, vaultRules, vaultSharesMint, vaultTokensPerShareWad };
|