Overview
The FolioLens contract provides convenient read-only functions for analyzing Folio state. It’s designed for off-chain use by frontends, analytics tools, and indexers. These functions are gas-intensive and should not be called on-chain.Key Features
- Spot Weight Calculation: Compute current token weights from balances
- Batch Bid Queries: Get all auction bids at once
- Surplus/Deficit Analysis: Calculate which tokens need buying or selling
- Off-Chain Optimized: Not intended for on-chain calls
Analysis Functions
Get Spot Weights
Calculate token weights based on current Folio balances.Folio
Folio contract to analyze
FolioLens.sol
tokens: Array of token addresses in the basketweights: Token weights in D27 format (tokens per share)
Weights are calculated as:
(D27 * tokenBalance) / totalSupply. This gives the actual composition by current holdings, which may differ from target weights during rebalancing.Get All Bids
Retrieve all possible bids for an auction in a single call.Folio
Folio contract with active auction
uint256
ID of the auction to query
FolioLens.sol
- Array of
SingleBidstructs for all valid token pairs
This function attempts to call
getBid() for all N² token pairs. Invalid pairs (those that would revert) are filtered out. Only returns bids with non-zero amounts.Surpluses and Deficits
Calculate which tokens are over/under the target limits.Folio
Folio contract to analyze
uint256
Upper BU limit for selling (D18 format)
uint256
Lower BU limit for buying (D18 format)
FolioLens.sol
tokens: Array of token addressessurpluses: Amount above sell limit for each token (0 if not surplus)deficits: Amount below buy limit for each token (0 if not deficit)
Data Structures
SingleBid
Represents a single auction bid for a token pair.address
Token being sold by the Folio
address
Token being bought by the Folio
uint256
Amount of sell token available
uint256
Amount of buy token required
uint256
Price in D27 format (buyTok/sellTok)
Usage Examples
Analyze Current Composition
Find Best Auction Bids
Calculate Rebalancing Needs
Constants
uint256
default:"1e18"
18-decimal fixed point scaling factor
uint256
default:"1e27"
27-decimal fixed point scaling factor (used for weights and prices)
Integration Notes
Frontend Integration: Use these functions via
eth_call (read-only RPC calls). Never send transactions to FolioLens.Indexing: These functions are useful for building subgraphs or analytics dashboards. Call them periodically to track Folio state changes.
Error Handling
Functions usetry/catch to gracefully handle invalid states: