Skip to main content

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
FolioLens functions are designed for off-chain analysis only. Do not call these functions from other smart contracts as they may consume excessive gas.

Analysis Functions

Get Spot Weights

Calculate token weights based on current Folio balances.
Folio
Folio contract to analyze
FolioLens.sol
Returns:
  • tokens: Array of token addresses in the basket
  • weights: 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
Returns:
  • Array of SingleBid structs 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
Returns:
  • tokens: Array of token addresses
  • surpluses: Amount above sell limit for each token (0 if not surplus)
  • deficits: Amount below buy limit for each token (0 if not deficit)
Requires sellLimit >= buyLimit. A token cannot have both a surplus and deficit - if one is non-zero, the other is always zero.

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.
The getAllBids() function may be expensive for Folios with many tokens (N² complexity). Consider using pagination or filtering for large baskets.

Error Handling

Functions use try/catch to gracefully handle invalid states:
This ensures functions don’t revert on temporary invalid states (e.g., ended auctions, removed tokens).