lighter.vault
Documentation for eth_defi.lighter.vault Python module.
Lighter pool data extraction and analysis.
This module provides functionality for extracting Lighter pool data via public endpoints:
Pool listing via
/api/v1/publicPoolsMetadata— bulk fetch all pools with TVL, APY, Sharpe ratio, and operator feePool details (share price history, daily returns, positions) via
/api/v1/account— per-pool detailed dataSystem config via
/api/v1/systemConfig— reported LLP account index
No authentication required.
For more information about Lighter:
Module Attributes
Display-name fallback for the canonical protocol liquidity pool. |
|
Description fallback for the same protocol-operated insurance pool. |
Functions
|
Fetch all Lighter public pools. |
|
Fetch detailed pool data including share price history. |
|
Fetch historical total shares from the PnL endpoint. |
|
Fetch Lighter system configuration. |
|
Convert pool detail share prices into a daily DataFrame. |
Classes
Detailed pool information from the |
|
Summary information for a Lighter pool from the bulk listing. |
- LIGHTER_LLP_NAME = 'Lighter Liquidity Provider (LLP)'
Display-name fallback for the canonical protocol liquidity pool. The Robinhood deployment currently returns an empty API name for this account.
- LIGHTER_LLP_DESCRIPTION = 'Protocol-operated liquidity and insurance pool that provides market-making liquidity and handles liquidations on Lighter.'
Description fallback for the same protocol-operated insurance pool.
- class LighterPoolSummary
Bases:
objectSummary information for a Lighter pool from the bulk listing.
From
/api/v1/publicPoolsMetadata.Total shares outstanding
- created_at: Optional[datetime.datetime]
Creation timestamp
- __init__(account_index, name, l1_address, annual_percentage_yield, sharpe_ratio, operator_fee, total_asset_value, total_shares, status, account_type, master_account_index, created_at, is_llp=False)
- Parameters
- Return type
None
- class LighterPoolDetail
Bases:
objectDetailed pool information from the
/api/v1/accountendpoint.Includes share price history and daily returns from
pool_info.Historical share prices as (timestamp_seconds, share_price) tuples
- daily_returns: list[tuple[int, float]]
Historical daily returns as (timestamp_seconds, daily_return) tuples
Total shares outstanding
Operator’s shares
- __init__(account_index, name, description, total_asset_value, operator_fee, annual_percentage_yield, sharpe_ratio, share_prices, daily_returns, total_shares, operator_shares)
- fetch_system_config(session, timeout=30.0)
Fetch Lighter system configuration.
Returns system config including the deployment’s reported LLP account index. Deployment configuration may override a stale reported value.
- Parameters
session (eth_defi.lighter.session.LighterSession) – HTTP session.
timeout (float) – HTTP request timeout.
- Returns
System config dict with reported
liquidity_pool_indexfield.- Return type
- fetch_all_pools(session, timeout=30.0, page_size=100)
Fetch all Lighter public pools.
Uses
/api/v1/publicPoolsMetadatawith pagination. Also fetches system config and applies any deployment-specific LLP account override to identify the canonical pool exactly.- Parameters
session (eth_defi.lighter.session.LighterSession) – HTTP session.
timeout (float) – HTTP request timeout.
page_size (int) – Number of pools per page (max 100).
- Returns
List of
LighterPoolSummaryobjects.- Return type
- fetch_pool_detail(session, account_index, timeout=30.0)
Fetch detailed pool data including share price history.
Uses
/api/v1/account?by=index&value={account_index}. The response includespool_infowithshare_pricesanddaily_returnsarrays for pool accounts.- Parameters
session (eth_defi.lighter.session.LighterSession) – HTTP session.
account_index (int) – Pool account index.
timeout (float) – HTTP request timeout.
- Returns
LighterPoolDetailwith share price history.- Return type
Fetch historical total shares from the PnL endpoint.
Uses
/api/v1/pnlat daily resolution to getpool_total_sharesat each timestamp. This is the only endpoint that provides full history for all pool types (including user pools).The returned shares can be combined with share prices to compute historical TVL:
tvl = pool_total_shares * share_price.- Parameters
session (eth_defi.lighter.session.LighterSession) – HTTP session.
account_index (int) – Pool account index.
start_timestamp (Optional[int]) – Unix timestamp for the start of the range. Defaults to Jan 1 2025.
timeout (float) – HTTP request timeout.
- Returns
Mapping of
{date: pool_total_shares}.- Return type
- pool_detail_to_daily_dataframe(detail, total_shares_by_date=None)
Convert pool detail share prices into a daily DataFrame.
Takes the share price history from the
/api/v1/accountendpoint and produces a DataFrame indexed by date withshare_price,daily_return, andtvlcolumns.Historical TVL is computed as
pool_total_shares * share_pricewhentotal_shares_by_dateis provided (fromfetch_pool_total_shares_history()). Without it, TVL defaults to 0.The share price array from the API contains daily entries with unix timestamps. We convert to dates and compute daily returns via
pct_change().- Parameters
detail (eth_defi.lighter.vault.LighterPoolDetail) – Pool detail with share_prices array.
total_shares_by_date (Optional[dict[datetime.date, int]]) – Mapping of
{date: pool_total_shares}from the PnL endpoint. Used to compute historical TVL.
- Returns
DataFrame indexed by date with
share_price,daily_return, andtvlcolumns. Empty if insufficient data.- Return type