Documentation Index
Fetch the complete documentation index at: https://mintlify.com/reserve-protocol/reserve-index-dtf/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Reserve Folio uses three primary utility libraries that implement core protocol logic. These libraries are used viadelegatecall from Folio contracts to reduce deployment size and improve code reusability.
Library Overview
- FolioLib: Fee calculations and governance operations
- RebalancingLib: Auction mechanics and rebalancing logic
- MathLib: Fixed-point math operations
FolioLib
Handles fee calculations and fee recipient management.Set Fee Recipients
Configure the fee recipient table for a Folio.FolioLib.sol
Fee recipients must be provided in ascending address order with no duplicates. Portions must sum to exactly 1e18 (100%). An empty table results in all fees going to the DAO.
Compute Fee Shares
Calculate TVL fee shares owed to DAO and fee recipients.FolioLib.sol
currentDaoPending: Existing DAO pending sharescurrentFeeRecipientsPending: Existing recipient pending sharestvlFee: Per-second TVL fee rate (D18)folioFeeForSelf: Fraction of recipient shares to burn (D18)supply: Current total supplyelapsed: Time elapsed since last fee calculation
Set TVL Fee
Convert annual TVL fee to per-second rate.FolioLib.sol
Converts annual percentage to per-second using formula:
1 - (1 - feeAnnually)^(1/31536000). This ensures accurate compounding over time.Compute Mint Fees
Calculate fee shares for minting operations.FolioLib.sol
shares: Total shares being minted (before fees)mintFee: Mint fee percentage (D18)folioFeeForSelf: Fraction of recipient fees to burn (D18)minSharesOut: Minimum shares caller must receive
RebalancingLib
Implements auction mechanics and rebalancing operations.Start Rebalance
Initiate a new rebalancing operation.RebalancingLib.sol
Open Auction
Open a new auction within an ongoing rebalance.RebalancingLib.sol
Auctions begin after a 30-second warmup period (
AUCTION_WARMUP). Atomic swaps (constant price) start and end at the same timestamp.Get Bid
Calculate bid parameters for a token pair at current timestamp.RebalancingLib.sol
sellAmount: Amount of sell token to transfer (in sellTok)bidAmount: Amount of buy token required (in buyTok)price: Current Dutch auction price (D27 format)
Bid
Execute a bid in an ongoing auction.RebalancingLib.sol
If
withCallback is true, the caller must implement IBidderCallee.bidCallback(). Otherwise, the caller must have pre-approved the buy token.Price Calculation
Internal function for Dutch auction pricing using exponential decay:P_0: Starting price (sellPriceHigh / buyPriceLow)P_t: Ending price (sellPriceLow / buyPriceHigh)k: Decay constant =ln(P_0 / P_t) / auctionLengtht: Time elapsed since auction start
MathLib
Fixed-point mathematical operations using PRBMath.Power
Raise a number to a fractional power.MathLib.sol
Base (D18 fixed point)
Exponent (D18 fixed point)
Used for compound interest calculations:
(1 - fee)^timePower (Unsigned)
Raise a number to an integer power.MathLib.sol
Base (D18 fixed point)
Exponent (whole number, not fixed point)
Natural Logarithm
Compute the natural logarithm of a number.MathLib.sol
Input (D18 fixed point)
Used in Dutch auction price decay calculations.
Exponential
Compute e raised to a power.MathLib.sol
Exponent (D18 fixed point, can be negative)
Used for exponential decay in auction pricing:
P_0 * e^(-kt)Constants
Key constants used across libraries:Fixed Point Scaling
18-decimal fixed point (standard for fees and ratios)
27-decimal fixed point (high precision for weights and prices)
Fee Limits
Maximum annual TVL fee: 10%
Minimum mint fee: 3 bps
Maximum number of fee recipients
Rebalancing Limits
Maximum token weight (D27 * 1e27)
Maximum BU limit per share
Maximum token price (D27 * 1e18)
Maximum ratio between high and low price
Maximum single token purchase amount
Auction Settings
Warmup period before auction bidding opens (seconds)
Maximum rebalance time-to-live
Time Constants
1/31536000 in D18 format (for annual to per-second conversion)
Usage in Contracts
Libraries are typically used withusing directives: