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— LLP account index
No authentication required.
For more information about Lighter:
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. |
- class LighterPoolDetail
Bases:
objectDetailed pool information from the
/api/v1/accountendpoint.Includes share price history and daily returns from
pool_info.- __init__(account_index, name, description, total_asset_value, operator_fee, annual_percentage_yield, sharpe_ratio, share_prices, daily_returns, total_shares, operator_shares)
- class LighterPoolSummary
Bases:
objectSummary information for a Lighter pool from the bulk listing.
From
/api/v1/publicPoolsMetadata.- __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
- fetch_all_pools(session, timeout=30.0, page_size=100)
Fetch all Lighter public pools.
Uses
/api/v1/publicPoolsMetadatawith pagination. Also fetches system config to identify the LLP pool.- 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
- fetch_system_config(session, timeout=30.0)
Fetch Lighter system configuration.
Returns system config including the LLP account index.
- Parameters
session (eth_defi.lighter.session.LighterSession) – HTTP session.
timeout (float) – HTTP request timeout.
- Returns
System config dict with key field
liquidity_pool_index.- 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