@elmntl/jlpd-sdk 0.1.11 → 0.13.4
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/LICENSE +201 -0
- package/README.md +185 -404
- package/dist/common/ata.d.ts +26 -0
- package/dist/common/ata.js +48 -0
- package/dist/common/buffer.d.ts +15 -0
- package/dist/common/buffer.js +118 -0
- package/dist/common/connection.d.ts +13 -0
- package/dist/common/connection.js +2 -0
- package/dist/common/constants.d.ts +14 -0
- package/dist/common/constants.js +31 -0
- package/dist/common/index.d.ts +6 -0
- package/dist/common/index.js +28 -0
- package/dist/common/strategy-interface.d.ts +59 -0
- package/dist/common/strategy-interface.js +42 -0
- package/dist/elemental-lend/accounts.d.ts +103 -0
- package/dist/elemental-lend/accounts.js +354 -0
- package/dist/elemental-lend/constants.d.ts +25 -0
- package/dist/elemental-lend/constants.js +48 -0
- package/dist/elemental-lend/index.d.ts +8 -0
- package/dist/elemental-lend/index.js +24 -0
- package/dist/elemental-lend/instructions.d.ts +104 -0
- package/dist/elemental-lend/instructions.js +266 -0
- package/dist/elemental-lend/jupiter-lend.d.ts +91 -0
- package/dist/elemental-lend/jupiter-lend.js +189 -0
- package/dist/elemental-lend/kamino-vault.d.ts +173 -0
- package/dist/elemental-lend/kamino-vault.js +483 -0
- package/dist/elemental-lend/pda.d.ts +12 -0
- package/dist/elemental-lend/pda.js +24 -0
- package/dist/elemental-lend/protocol-actions.d.ts +56 -0
- package/dist/elemental-lend/protocol-actions.js +244 -0
- package/dist/elemental-lend/types.d.ts +113 -0
- package/dist/elemental-lend/types.js +2 -0
- package/dist/elemental-lend-v2/accounts.d.ts +14 -0
- package/dist/elemental-lend-v2/accounts.js +136 -0
- package/dist/elemental-lend-v2/adapters.d.ts +22 -0
- package/dist/elemental-lend-v2/adapters.js +50 -0
- package/dist/elemental-lend-v2/constants.d.ts +48 -0
- package/dist/elemental-lend-v2/constants.js +104 -0
- package/dist/elemental-lend-v2/index.d.ts +8 -0
- package/dist/elemental-lend-v2/index.js +24 -0
- package/dist/elemental-lend-v2/instructions.d.ts +96 -0
- package/dist/elemental-lend-v2/instructions.js +190 -0
- package/dist/elemental-lend-v2/lut.d.ts +20 -0
- package/dist/elemental-lend-v2/lut.js +65 -0
- package/dist/elemental-lend-v2/pda.d.ts +9 -0
- package/dist/elemental-lend-v2/pda.js +27 -0
- package/dist/elemental-lend-v2/types.d.ts +105 -0
- package/dist/elemental-lend-v2/types.js +2 -0
- package/dist/elemental-lend-v2/update-aum.d.ts +29 -0
- package/dist/elemental-lend-v2/update-aum.js +82 -0
- package/dist/index.d.ts +5 -3552
- package/dist/index.js +37 -4454
- package/dist/jlpd-strategy/accounts.d.ts +83 -0
- package/dist/jlpd-strategy/accounts.js +216 -0
- package/dist/jlpd-strategy/adapter.d.ts +81 -0
- package/dist/jlpd-strategy/adapter.js +118 -0
- package/dist/jlpd-strategy/base-to-base-swap.d.ts +74 -0
- package/dist/jlpd-strategy/base-to-base-swap.js +205 -0
- package/dist/jlpd-strategy/constants.d.ts +127 -0
- package/dist/jlpd-strategy/constants.js +174 -0
- package/dist/jlpd-strategy/fluid-view.d.ts +199 -0
- package/dist/jlpd-strategy/fluid-view.js +799 -0
- package/dist/jlpd-strategy/hedge-derived.d.ts +135 -0
- package/dist/jlpd-strategy/hedge-derived.js +231 -0
- package/dist/jlpd-strategy/hedge-instructions.d.ts +210 -0
- package/dist/jlpd-strategy/hedge-instructions.js +300 -0
- package/dist/jlpd-strategy/hedge-state.d.ts +88 -0
- package/dist/jlpd-strategy/hedge-state.js +110 -0
- package/dist/jlpd-strategy/index.d.ts +17 -0
- package/dist/jlpd-strategy/index.js +33 -0
- package/dist/jlpd-strategy/instructions.d.ts +159 -0
- package/dist/jlpd-strategy/instructions.js +234 -0
- package/dist/jlpd-strategy/jlp-borrow.d.ts +63 -0
- package/dist/jlpd-strategy/jlp-borrow.js +87 -0
- package/dist/jlpd-strategy/jlp-data.d.ts +166 -0
- package/dist/jlpd-strategy/jlp-data.js +611 -0
- package/dist/jlpd-strategy/jupusd-earn.d.ts +90 -0
- package/dist/jlpd-strategy/jupusd-earn.js +166 -0
- package/dist/jlpd-strategy/live-jlp-price.d.ts +46 -0
- package/dist/jlpd-strategy/live-jlp-price.js +267 -0
- package/dist/jlpd-strategy/pda.d.ts +13 -0
- package/dist/jlpd-strategy/pda.js +28 -0
- package/dist/jlpd-strategy/settle-yield.d.ts +45 -0
- package/dist/jlpd-strategy/settle-yield.js +113 -0
- package/dist/jlpd-strategy/swap-jlp.d.ts +198 -0
- package/dist/jlpd-strategy/swap-jlp.js +586 -0
- package/dist/jlpd-strategy/types.d.ts +101 -0
- package/dist/jlpd-strategy/types.js +29 -0
- package/dist/p-stv-core/accounts.d.ts +152 -0
- package/dist/p-stv-core/accounts.js +407 -0
- package/dist/p-stv-core/constants.d.ts +138 -0
- package/dist/p-stv-core/constants.js +181 -0
- package/dist/p-stv-core/events.d.ts +7 -0
- package/dist/p-stv-core/events.js +246 -0
- package/dist/p-stv-core/index.d.ts +11 -0
- package/dist/p-stv-core/index.js +27 -0
- package/dist/p-stv-core/instructions.d.ts +637 -0
- package/dist/p-stv-core/instructions.js +670 -0
- package/dist/p-stv-core/lut.d.ts +41 -0
- package/dist/p-stv-core/lut.js +81 -0
- package/dist/p-stv-core/pda.d.ts +30 -0
- package/dist/p-stv-core/pda.js +65 -0
- package/dist/p-stv-core/prices.d.ts +20 -0
- package/dist/p-stv-core/prices.js +77 -0
- package/dist/p-stv-core/remaining-accounts.d.ts +107 -0
- package/dist/p-stv-core/remaining-accounts.js +326 -0
- package/dist/p-stv-core/send-tx.d.ts +72 -0
- package/dist/p-stv-core/send-tx.js +290 -0
- package/dist/p-stv-core/sol-wrap.d.ts +34 -0
- package/dist/p-stv-core/sol-wrap.js +74 -0
- package/dist/p-stv-core/types.d.ts +361 -0
- package/dist/p-stv-core/types.js +2 -0
- package/package.json +56 -15
- package/dist/index.d.mts +0 -3552
- package/dist/index.mjs +0 -4363
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jupiter Lend (Fluid Vaults + Fluid Earn) read-only valuation helpers — TS mirror of
|
|
3
|
+
* `jlpd-strategy/programs/jlpd-strategy/src/utils/jup_lend_view.rs` (program
|
|
4
|
+
* `GXqt4ZH2UUBsLWwMNJiZMXza3q7xEGChfW8XjVRjLxr5`, mainnet).
|
|
5
|
+
*
|
|
6
|
+
* Pure decode + math, ALL-bigint (matching Rust's u128/i128 exactly — truncating division
|
|
7
|
+
* for the hop-rate math, ceil-division for debt). Answers the same question the on-chain
|
|
8
|
+
* `hedge_borrow`/`hedge_withdraw_collateral` guard answers: what LTV does a position imply,
|
|
9
|
+
* valued on the SAME Fluid oracle chain the vault itself liquidates on (never this program's
|
|
10
|
+
* own JLP NAV mark, `computeLiveJlpPriceUsd` — see `live-jlp-price.ts` — which is a DIFFERENT
|
|
11
|
+
* feed that can diverge from Fluid's exactly when liquidation risk is highest).
|
|
12
|
+
*
|
|
13
|
+
* Ported/derived from `github.com/Instadapp/fluid-solana-programs` the same way `oracle.rs`
|
|
14
|
+
* itself was ported (fixed-byte-offset decode, no new on-chain-format dependency). Every
|
|
15
|
+
* offset below is cross-checked against `jup_lend_view.rs`'s own named constants.
|
|
16
|
+
*/
|
|
17
|
+
import { PublicKey } from "@solana/web3.js";
|
|
18
|
+
import type { SolanaConnection } from "../common/connection";
|
|
19
|
+
import type { HedgePositionSlot } from "./hedge-state";
|
|
20
|
+
export declare const JUP_LEND_EARN_MIN_SANE_RATE = 1000000000000n;
|
|
21
|
+
export declare const JUP_LEND_EARN_MAX_SANE_RATE: bigint;
|
|
22
|
+
/** `ratio_x48` at tick 0 (`1 << 48`). */
|
|
23
|
+
export declare const FLUID_ZERO_TICK_SCALED_RATIO: bigint;
|
|
24
|
+
/** `ratio_x48 = 1.0015^tick * 2^48`. */
|
|
25
|
+
export declare function getRatioAtTick(tick: number): bigint;
|
|
26
|
+
/** Minimal identity of a fetched on-chain account, as returned by `connection.getAccountInfo`. */
|
|
27
|
+
export interface RawAccount {
|
|
28
|
+
pubkey: PublicKey;
|
|
29
|
+
owner: PublicKey;
|
|
30
|
+
data: Buffer;
|
|
31
|
+
}
|
|
32
|
+
/** Decoded essentials of a Fluid `Position` (Jupiter Lend Borrow position NFT account). */
|
|
33
|
+
export interface FluidPosition {
|
|
34
|
+
vaultId: number;
|
|
35
|
+
isSupplyOnly: boolean;
|
|
36
|
+
tick: number;
|
|
37
|
+
/** Tick GENERATION this position was placed at. Liquidation-current iff the canonical Tick has
|
|
38
|
+
* `!isLiquidated && totalIds === tickId` (see `requireFluidPositionLiquidationCurrent`). */
|
|
39
|
+
tickId: number;
|
|
40
|
+
/** Raw collateral (`Position.supply_amount`), Fluid's normalized 9-decimal basis. */
|
|
41
|
+
collateralRaw: bigint;
|
|
42
|
+
/** Raw dust debt (`Position.dust_debt_amount`), same basis. */
|
|
43
|
+
dustDebtRaw: bigint;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Decode + validate a Fluid `Position` account. `expected` pins it to the caller's canonical
|
|
47
|
+
* pubkey (e.g. one `HedgePositionSlot.borrowPosition`) — mirrors `decode_fluid_position`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function decodeFluidPosition(account: RawAccount, expected: PublicKey): FluidPosition;
|
|
50
|
+
/** Decoded essentials of a Fluid `Tick` account. */
|
|
51
|
+
export interface FluidTick {
|
|
52
|
+
vaultId: number;
|
|
53
|
+
tick: number;
|
|
54
|
+
isLiquidated: boolean;
|
|
55
|
+
/** Generation counter — increments when the tick is FULLY liquidated. */
|
|
56
|
+
totalIds: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Canonical Tick PDA `[b"tick", vault_id_le2, (tick − MIN_TICK)_i32_le4]` under the Fluid vault
|
|
60
|
+
* program — byte-identical to the on-chain `derive_fluid_tick_pda` (golden-vector tested).
|
|
61
|
+
*/
|
|
62
|
+
export declare function deriveFluidTickPda(vaultId: number, tick: number): PublicKey;
|
|
63
|
+
/**
|
|
64
|
+
* The Tick account settle_yield's per-slot triple must carry for `position`: the canonical
|
|
65
|
+
* `Tick(vaultId, position.tick)` for an ACTIVE debt position, or the `Tick(vaultId, MIN_TICK)`
|
|
66
|
+
* cold placeholder for a supply-only one (key-pinned by the program; the placeholder may not
|
|
67
|
+
* exist on chain — contents are ignored, only the key matters).
|
|
68
|
+
*/
|
|
69
|
+
export declare function settleTickPdaForPosition(position: FluidPosition): PublicKey;
|
|
70
|
+
/**
|
|
71
|
+
* Decode + fully validate a Fluid `Tick` against `expected` (the canonical PDA) — mirrors the
|
|
72
|
+
* on-chain `decode_fluid_tick`: key equality, Fluid ownership, discriminator, min length, and a
|
|
73
|
+
* CANONICAL `is_liquidated` byte (any value other than 0/1 rejects).
|
|
74
|
+
*/
|
|
75
|
+
export declare function decodeFluidTick(account: RawAccount, expected: PublicKey): FluidTick;
|
|
76
|
+
/**
|
|
77
|
+
* Mirror of the on-chain liquidation-staleness gate (`require_fluid_position_liquidation_current`):
|
|
78
|
+
* throws unless `position`'s stored bytes are proven liquidation-current by its canonical Tick.
|
|
79
|
+
* For a supply-only position only the placeholder KEY is checked (`tickAccount` may be null —
|
|
80
|
+
* the placeholder need not exist). For an active position the Tick must decode cleanly and pass
|
|
81
|
+
* `!isLiquidated && totalIds === tickId` (strict generation equality — `<` is not a valid Fluid
|
|
82
|
+
* transition and also rejects).
|
|
83
|
+
*/
|
|
84
|
+
export declare function requireFluidPositionLiquidationCurrent(position: FluidPosition, tickAccount: RawAccount | null): void;
|
|
85
|
+
/** Decoded exchange prices of a Fluid `VaultState`. */
|
|
86
|
+
export interface FluidVaultExchangePrices {
|
|
87
|
+
vaultId: number;
|
|
88
|
+
supplyExPrice: bigint;
|
|
89
|
+
borrowExPrice: bigint;
|
|
90
|
+
/** Unix seconds. Only ENFORCED as a freshness bound by `requireFluidVaultStateFresh`. */
|
|
91
|
+
lastUpdateTimestamp: bigint;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Decode + validate a Fluid `VaultState` account. `expected` pins it to the caller's canonical
|
|
95
|
+
* pubkey (e.g. one `HedgePositionSlot.vaultState`) — mirrors `decode_fluid_vault_state`.
|
|
96
|
+
*/
|
|
97
|
+
export declare function decodeFluidVaultState(account: RawAccount, expected: PublicKey): FluidVaultExchangePrices;
|
|
98
|
+
/**
|
|
99
|
+
* Require a Fluid `VaultState`'s `lastUpdateTimestamp` to be within
|
|
100
|
+
* `FLUID_VAULT_STATE_MAX_STALENESS_SECS` (24h) of `nowUnixSec` — mirrors
|
|
101
|
+
* `require_fluid_vault_state_fresh` — the check every risk-limit valuation applies:
|
|
102
|
+
* `settle_yield`'s NAV fold, the `hedge_supply_collateral` pledge cap, and the per-op LTV
|
|
103
|
+
* guards on `hedge_borrow`/`hedge_withdraw_collateral` (Fluid's `operate` CPI does not
|
|
104
|
+
* refresh `last_update_timestamp`, so a post-`operate` read is not automatically fresh).
|
|
105
|
+
*/
|
|
106
|
+
export declare function requireFluidVaultStateFresh(vaultState: Pick<FluidVaultExchangePrices, "lastUpdateTimestamp">, nowUnixSec: bigint): void;
|
|
107
|
+
/** Decoded essentials of a Fluid `VaultConfig`. */
|
|
108
|
+
export interface FluidVaultConfigInfo {
|
|
109
|
+
vaultId: number;
|
|
110
|
+
oracle: PublicKey;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Decode + validate a Fluid `VaultConfig` account. `expected` pins it to the caller's canonical
|
|
114
|
+
* pubkey (e.g. one `HedgePositionSlot.vaultConfig`) — mirrors the account-loading half of
|
|
115
|
+
* `read_fluid_price_1e15`.
|
|
116
|
+
*/
|
|
117
|
+
export declare function decodeFluidVaultConfig(account: RawAccount, expected: PublicKey): FluidVaultConfigInfo;
|
|
118
|
+
/**
|
|
119
|
+
* Bind a Fluid position's, vault state's, and vault config's `vaultId` together in one call —
|
|
120
|
+
* mirrors `require_fluid_vault_id_bind`.
|
|
121
|
+
*/
|
|
122
|
+
export declare function requireFluidVaultIdBind(positionVaultId: number, vaultStateVaultId: number, vaultConfigVaultId: number): void;
|
|
123
|
+
/**
|
|
124
|
+
* Collateral (always JLP, 6 decimals) held by `position`, interest-adjusted and FLOORED —
|
|
125
|
+
* mirrors `collateral_jlp_normal` exactly.
|
|
126
|
+
*/
|
|
127
|
+
export declare function collateralJlpNormal(position: FluidPosition, vaultState: FluidVaultExchangePrices): bigint;
|
|
128
|
+
/**
|
|
129
|
+
* TRUE debt owed by `position` in `mintDecimals`-decimal native units of the debt mint,
|
|
130
|
+
* interest-adjusted and CEILED at both conversion stages.
|
|
131
|
+
*
|
|
132
|
+
* Fluid stores a position as (tick, collateral, dust): `operate` rounds the debt/col ratio UP one
|
|
133
|
+
* tick (1.0015 steps) and books the excess as `dust_debt`, so the true owed amount is
|
|
134
|
+
* `tick_implied − dust` (Fluid's own `get_net_debt_raw` = `debt_raw.safe_sub(dust_debt_raw)`,
|
|
135
|
+
* structs.rs). Adding dust — the sign this function shipped with — overstates debt by 2×dust,
|
|
136
|
+
* a random ≤~30bps of total debt that re-rolls on every operate.
|
|
137
|
+
*/
|
|
138
|
+
export declare function debtNativeCeil(position: FluidPosition, vaultState: FluidVaultExchangePrices, mintDecimals: number): bigint;
|
|
139
|
+
/**
|
|
140
|
+
* The DEPLOYED jlpd-strategy program's debt view (`jup_lend_view.rs::debt_native_ceil`), which
|
|
141
|
+
* ADDS dust — overstating true debt by 2×dust. Wrong as economics, but the program's own LTV /
|
|
142
|
+
* repay guards are enforced against THIS number until the program-side sign fix ships, so any
|
|
143
|
+
* caller sizing an operation the PROGRAM must accept has to use this view, not the true one.
|
|
144
|
+
*/
|
|
145
|
+
export declare function debtNativeCeilProgramView(position: FluidPosition, vaultState: FluidVaultExchangePrices, mintDecimals: number): bigint;
|
|
146
|
+
/**
|
|
147
|
+
* `ltvBps = ceil(debtNative * 10_000 / colInDebtNative)`, mirrors `position_ltv_bps` exactly —
|
|
148
|
+
* `debtNative == 0` short-circuits to 0; a non-zero debt against zero-valued collateral
|
|
149
|
+
* saturates to `0xFFFF` (u16::MAX), matching the on-chain guard's "maximally unsafe" reading.
|
|
150
|
+
*/
|
|
151
|
+
export declare function positionLtvBps(debtNative: bigint, debtDecimals: number, collateralJlpNative: bigint, price1e15: bigint): number;
|
|
152
|
+
/** One decoded `Sources` element: which account to read, whether to invert, and its type tag. */
|
|
153
|
+
export interface OracleSourceMeta {
|
|
154
|
+
sourcePk: PublicKey;
|
|
155
|
+
invert: boolean;
|
|
156
|
+
sourceType: number;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Peek a Fluid oracle config account's own declared hop count (1 or 2) — mirrors
|
|
160
|
+
* `read_oracle_hop_count` (sizes how many feed accounts to fetch before decoding any price).
|
|
161
|
+
*/
|
|
162
|
+
export declare function readOracleHopCount(account: RawAccount, expected: PublicKey): number;
|
|
163
|
+
/**
|
|
164
|
+
* Read one Fluid vault's pair-native price (1e15 precision — collateral, always JLP, valued in
|
|
165
|
+
* that vault's OWN debt mint), off the SAME oracle chain Fluid itself liquidates on. Pure
|
|
166
|
+
* orchestrator over already-fetched accounts — mirrors `read_fluid_price_1e15` exactly.
|
|
167
|
+
* See `readFluidPrice1e15` for the async fetch-and-compute convenience wrapper.
|
|
168
|
+
*/
|
|
169
|
+
export declare function readFluidPrice1e15FromAccounts(args: {
|
|
170
|
+
vaultConfig: RawAccount;
|
|
171
|
+
expectedVaultConfig: PublicKey;
|
|
172
|
+
positionVaultId: number;
|
|
173
|
+
vaultStateVaultId: number;
|
|
174
|
+
oracleCfg: RawAccount;
|
|
175
|
+
expectedOracle: PublicKey;
|
|
176
|
+
feedAccounts: RawAccount[];
|
|
177
|
+
nowUnixSec: bigint;
|
|
178
|
+
currentSlot: bigint;
|
|
179
|
+
}): bigint;
|
|
180
|
+
/**
|
|
181
|
+
* Fetch + decode one `HedgePositionSlot`'s pair-native oracle price (1e15), then read that
|
|
182
|
+
* slot's Position/VaultState and compute its LTV — the async convenience wrapper matching
|
|
183
|
+
* `hedge_borrow`'s / `hedge_withdraw_collateral`'s guard basis exactly. `debtDecimals` must be
|
|
184
|
+
* the debt mint's own `Mint.decimals` (fetch separately; not re-derived here).
|
|
185
|
+
*/
|
|
186
|
+
export declare function fetchFluidSlotLtv(connection: SolanaConnection, slot: HedgePositionSlot, debtDecimals: number): Promise<{
|
|
187
|
+
ltvBps: number;
|
|
188
|
+
debtNative: bigint;
|
|
189
|
+
collateralJlpNative: bigint;
|
|
190
|
+
price1e15: bigint;
|
|
191
|
+
position: FluidPosition;
|
|
192
|
+
vaultState: FluidVaultExchangePrices;
|
|
193
|
+
}>;
|
|
194
|
+
/**
|
|
195
|
+
* Read the Jupiter Lend Earn `lending` account's stored exchange rate (1e12 precision) for one
|
|
196
|
+
* fToken — mirrors `earn_exchange_rate` exactly (uses the STORED rate directly, no forward
|
|
197
|
+
* accrual; `lending`'s identity must be pinned by the caller).
|
|
198
|
+
*/
|
|
199
|
+
export declare function earnExchangeRate(account: RawAccount): bigint;
|