@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,166 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import type { SolanaConnection } from "../common/connection";
|
|
3
|
+
export type CustodyName = "SOL" | "ETH" | "WBTC" | "USDC" | "USDT";
|
|
4
|
+
export interface JlpCustody {
|
|
5
|
+
name: CustodyName;
|
|
6
|
+
aumUsd: number;
|
|
7
|
+
weightBps: number;
|
|
8
|
+
priceUsd: number;
|
|
9
|
+
}
|
|
10
|
+
export interface JlpData {
|
|
11
|
+
timestamp: string;
|
|
12
|
+
totalAumUsd: number;
|
|
13
|
+
custodies: JlpCustody[];
|
|
14
|
+
}
|
|
15
|
+
/** Jupiter Perps Pool fee parameters (from on-chain Pool account) */
|
|
16
|
+
export interface JlpPoolFees {
|
|
17
|
+
addRemoveLiquidityBps: number;
|
|
18
|
+
swapBps: number;
|
|
19
|
+
taxBps: number;
|
|
20
|
+
stableSwapBps: number;
|
|
21
|
+
stableSwapTaxBps: number;
|
|
22
|
+
}
|
|
23
|
+
/** Per-custody info including target weight and current weight */
|
|
24
|
+
export interface JlpCustodyInfo {
|
|
25
|
+
mint: PublicKey;
|
|
26
|
+
name: CustodyName;
|
|
27
|
+
targetRatioBps: number;
|
|
28
|
+
currentRatioBps: number;
|
|
29
|
+
aumUsd: number;
|
|
30
|
+
isStable: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** Full pool details: fees, custody weights, AUM, JLP price */
|
|
33
|
+
export interface JlpPoolDetails {
|
|
34
|
+
fees: JlpPoolFees | null;
|
|
35
|
+
custodies: JlpCustodyInfo[];
|
|
36
|
+
poolAumUsd: number;
|
|
37
|
+
jlpPrice: number;
|
|
38
|
+
jlpSupply: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Reset the price memo. Intended for unit tests that mock global fetch with
|
|
42
|
+
* scenario-specific prices — module-level cache pollutes across tests when
|
|
43
|
+
* TTL has not expired, leading to assertion failures that depend on test
|
|
44
|
+
* ordering.
|
|
45
|
+
*
|
|
46
|
+
* Not part of the public surface for application code; cache TTL handles
|
|
47
|
+
* production. Exported under `__test__*` namespace convention so consumers
|
|
48
|
+
* tree-shake it out and never accidentally rely on cache invalidation.
|
|
49
|
+
*/
|
|
50
|
+
export declare function __test__resetPricesCache(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Fetch full JLP pool details: fee parameters, per-custody target/current
|
|
53
|
+
* weights, pool AUM, and JLP price.
|
|
54
|
+
*
|
|
55
|
+
* Reads the Pool account for fees and aumUsd, Custody accounts for per-asset
|
|
56
|
+
* data including target weights, and the JLP mint for total supply.
|
|
57
|
+
*/
|
|
58
|
+
export declare function fetchJlpPoolDetails(connection: SolanaConnection): Promise<JlpPoolDetails>;
|
|
59
|
+
/**
|
|
60
|
+
* Estimate the addLiquidity fee for depositing into a specific JLP custody.
|
|
61
|
+
*
|
|
62
|
+
* Implements the Jupiter Perps fee formula:
|
|
63
|
+
* - If deposit moves custody weight TOWARD target: rebate (fee < baseFee)
|
|
64
|
+
* - If deposit moves custody weight AWAY from target: tax (fee > baseFee)
|
|
65
|
+
*
|
|
66
|
+
* Formula:
|
|
67
|
+
* initDiff = |currentRatio - targetRatio|
|
|
68
|
+
* finalDiff = |newRatio - targetRatio|
|
|
69
|
+
* avgDiff = (initDiff + finalDiff) / 2
|
|
70
|
+
* if improving: fee = max(baseFee - taxBps * avgDiff / 10000, 0)
|
|
71
|
+
* if worsening: fee = baseFee + taxBps * avgDiff / 10000
|
|
72
|
+
*/
|
|
73
|
+
export declare function computeAddLiquidityFee(args: {
|
|
74
|
+
custodyAumUsd: number;
|
|
75
|
+
poolAumUsd: number;
|
|
76
|
+
targetRatioBps: number;
|
|
77
|
+
depositUsd: number;
|
|
78
|
+
fees: JlpPoolFees;
|
|
79
|
+
isStable: boolean;
|
|
80
|
+
}): {
|
|
81
|
+
feeBps: number;
|
|
82
|
+
isDiscount: boolean;
|
|
83
|
+
};
|
|
84
|
+
export declare function fetchJlpCustodyData(connection: SolanaConnection): Promise<JlpData>;
|
|
85
|
+
/** Public symbol used by the effective-weights API.
|
|
86
|
+
*
|
|
87
|
+
* Note: JLP custody is internally named "WBTC" but represents BTC exposure
|
|
88
|
+
* for sensitivity purposes — surfaced as `'BTC'` here per spec. */
|
|
89
|
+
export type EffectiveWeightSymbol = "BTC" | "ETH" | "SOL" | "USDC" | "USDT";
|
|
90
|
+
export interface AssetEffectiveWeight {
|
|
91
|
+
mint: PublicKey;
|
|
92
|
+
symbol: EffectiveWeightSymbol;
|
|
93
|
+
/** Effective USD contribution, normalized to 8 decimals. */
|
|
94
|
+
effUsd: bigint;
|
|
95
|
+
/** Share of total effective USD, in basis points (0–10000). */
|
|
96
|
+
effShareBps: number;
|
|
97
|
+
/** True if `(owned − locked) < 0`. Spot term clamped to 0 in `effUsd`. */
|
|
98
|
+
spotClamped: boolean;
|
|
99
|
+
}
|
|
100
|
+
export interface JlpEffectiveWeights {
|
|
101
|
+
assets: AssetEffectiveWeight[];
|
|
102
|
+
/** Sum of all `effUsd` values, 8 decimals. */
|
|
103
|
+
totalEffUsd: bigint;
|
|
104
|
+
/** Total pool aumUsd (including `guaranteed_usd`), 8 decimals — context only. */
|
|
105
|
+
totalAumUsd: bigint;
|
|
106
|
+
}
|
|
107
|
+
/** Inputs needed to compute effective USD for one custody.
|
|
108
|
+
*
|
|
109
|
+
* Decoupled from on-chain fetching so unit tests can drive the math directly. */
|
|
110
|
+
export interface EffectiveWeightInput {
|
|
111
|
+
owned: bigint;
|
|
112
|
+
locked: bigint;
|
|
113
|
+
/** Raw debt u128 (DEBT_MULTIPLIER-scaled by 1e9 internally, then by 10^decimals). */
|
|
114
|
+
debt: bigint;
|
|
115
|
+
/** Raw borrow-lend interests accrued u128 (same scale as `debt`). */
|
|
116
|
+
borrowLendInterestsAccrued: bigint;
|
|
117
|
+
shortSizeUsd: bigint;
|
|
118
|
+
avgShortPriceUsd: bigint;
|
|
119
|
+
guaranteedUsd: bigint;
|
|
120
|
+
decimals: number;
|
|
121
|
+
/** Price scaled to 8 decimals (float price × 10^8, as bigint). */
|
|
122
|
+
priceScaled8: bigint;
|
|
123
|
+
}
|
|
124
|
+
export interface EffectiveWeightOutput {
|
|
125
|
+
/** (owned + netDebt − locked) × price, normalized to 8-decimal USD. Clamped to 0 if negative. */
|
|
126
|
+
spotEffUsd: bigint;
|
|
127
|
+
/** shortSize × price / avgShortPrice, normalized to 8-decimal USD. 0 if no shorts. */
|
|
128
|
+
shortEffUsd: bigint;
|
|
129
|
+
/** spotEffUsd + shortEffUsd. */
|
|
130
|
+
effUsd: bigint;
|
|
131
|
+
/** True if (owned + netDebt − locked) < 0 — spot term was clamped. */
|
|
132
|
+
spotClamped: boolean;
|
|
133
|
+
/** netDebt tokens applied to spot term (already converted to token-base units). */
|
|
134
|
+
netDebtTokens: bigint;
|
|
135
|
+
}
|
|
136
|
+
/** Compute effective USD (price-sensitivity-weighted) for a single custody.
|
|
137
|
+
*
|
|
138
|
+
* Formula (in 8-decimal USD):
|
|
139
|
+
* netDebtTokens = max(debt − borrowLendInterestsAccrued, 0) / DEBT_MULTIPLIER
|
|
140
|
+
* spot = (owned + netDebtTokens − locked) × price_8dec / 10^decimals
|
|
141
|
+
* short = shortSize_6dec × price_8dec / avgShortPrice_6dec (zeroed if either operand is 0)
|
|
142
|
+
* effUsd = max(spot, 0) + short
|
|
143
|
+
*
|
|
144
|
+
* Algebra for unit normalization:
|
|
145
|
+
* - owned/locked/netDebt is in 10^decimals base units; price is 10^8 USD.
|
|
146
|
+
* spot = (owned + netDebt − locked) × price_8dec / 10^decimals → 10^8 USD ✓
|
|
147
|
+
* - debt is stored as u128 scaled by DEBT_MULTIPLIER (1e9) on top of 10^decimals.
|
|
148
|
+
* netDebtTokens = (debt − borrowLendInterestsAccrued) / DEBT_MULTIPLIER
|
|
149
|
+
* (integer division — small rounding under one base unit, acceptable).
|
|
150
|
+
* - shortSize and avgShortPrice are both 10^6; ratio is dimensionless.
|
|
151
|
+
* short = shortSize × price_8dec / avgShortPrice → 10^8 USD ✓
|
|
152
|
+
*/
|
|
153
|
+
export declare function computeEffectiveUsd(input: EffectiveWeightInput): EffectiveWeightOutput;
|
|
154
|
+
/**
|
|
155
|
+
* Fetch JLP pool effective-weight composition.
|
|
156
|
+
*
|
|
157
|
+
* Returns price-sensitivity-weighted shares per asset, dropping `guaranteed_usd`
|
|
158
|
+
* from the per-asset weight calculation. Suitable for rebalance planners that
|
|
159
|
+
* want to track the pool's true delta-1 composition rather than reported aumUsd.
|
|
160
|
+
*
|
|
161
|
+
* Reuses the same on-chain custody parser and Jupiter Price API source as
|
|
162
|
+
* `fetchJlpCustodyData` to keep numbers consistent across callers.
|
|
163
|
+
*
|
|
164
|
+
* @returns assets in fixed order: BTC, ETH, SOL, USDC, USDT.
|
|
165
|
+
*/
|
|
166
|
+
export declare function fetchJlpEffectiveWeights(connection: SolanaConnection): Promise<JlpEffectiveWeights>;
|