BLens Contract Reference
The BLens contract provides read-only view functions for querying bToken state, prices, positions, and protocol parameters.
Contract: BLens.sol
Version: 4
License: AGPL-3.0-or-later
Overview
BLens is a view-only contract with ~50 functions for reading protocol state. Use BLens for:
- Querying prices (BLV, market, premium)
- Reading pool state (reserves, supply, fees)
- Checking user positions (staking, credit)
- Getting protocol configuration
Price Functions
getActivePrice
Get current market price.
function getActivePrice(BToken _bToken) external view returns (uint256)Returns: Market price in WAD (1e18 = 1.0)
getBLV
Get current Baseline Value (floor price).
function getBLV(BToken _bToken) external view returns (uint256)Returns: BLV in WAD
getPremium
Get premium above BLV.
function getPremium(BToken _bToken) external view returns (uint256)Returns: Premium in WAD (market price - BLV)
getBookPrice
Get book price (total reserves / circulating supply).
function getBookPrice(BToken _bToken) external view returns (uint256)Pool State Functions
totalReserves
Get total reserves in the pool.
function totalReserves(BToken _bToken) external view returns (uint256)totalBTokens
Get total bTokens held by the protocol.
function totalBTokens(BToken _bToken) external view returns (uint256)totalSupply
Get total token supply.
function totalSupply(BToken _bToken) external view returns (uint256)getCirculatingSupply
Get circulating supply (total - protocol holdings).
function getCirculatingSupply(BToken _bToken) external view returns (uint256)reserve
Get the reserve token address.
function reserve(BToken _bToken) external view returns (ERC20)Ratio Functions
getInventoryRatio
Get inventory ratio (pool inventory / circulating).
function getInventoryRatio(BToken _bToken) external view returns (uint256)getBufferRatio
Get buffer reserves ratio.
function getBufferRatio(BToken _bToken) external view returns (uint256)getLiquidityLeverage
Get liquidity leverage (buffer ratio × inventory ratio).
function getLiquidityLeverage(BToken _bToken) external view returns (uint256)Fee Functions
poolFeeShare
Get fee share going to pool (BLV growth).
function poolFeeShare(BToken _bToken) external view returns (uint256)creatorFeePct
Get creator fee percentage.
function creatorFeePct(BToken _bToken) external view returns (uint256)totalFeeShare
Get total fee share.
function totalFeeShare(BToken _bToken) external view returns (uint256)creatorClaimable
Get claimable fees for creator.
function creatorClaimable(BToken _bToken) external view returns (uint256)Position Functions
getCreditAccount
Get user's credit (borrow) position.
function getCreditAccount(BToken _bToken, address _user)
external view returns (State.CreditAccount memory)Returns: Struct with:
collateral: Locked bTokensdebt: Outstanding debt
getStakedAccount
Get user's staking position.
function getStakedAccount(BToken _bToken, address _user)
external view returns (State.StakedAccount memory)Returns: Struct with:
amount: Staked bTokensrewardDebt: Accumulated rewards claimed
getMaxBorrow
Get maximum borrowable amount for collateral.
function getMaxBorrow(BToken _bToken, uint256 _collateral)
external view returns (uint256)getLeverageResult
Preview leverage operation result.
function getLeverageResult(
BToken _bToken,
uint256 _collateral,
uint256 _leverageFactor
) external view returns (
uint256 collateralAdded_,
uint256 debtAdded_,
uint256 reservesNeeded_
)Protocol Configuration
protocolFeeRecipient
Get protocol fee recipient address.
function protocolFeeRecipient() external view returns (address)protocolFeePct
Get protocol fee percentage.
function protocolFeePct() external view returns (uint256)originationFee
Get loan origination fee.
function originationFee() external view returns (uint256)isPoolPaused
Check if a pool is paused.
function isPoolPaused(BToken _bToken) external view returns (bool)isProtocolPaused
Check if entire protocol is paused.
function isProtocolPaused() external view returns (bool)Hook Functions
hasHook
Check if bToken has Uniswap V4 hook.
function hasHook(BToken _bToken) external view returns (bool)poolKey
Get Uniswap V4 pool key.
function poolKey(BToken _bToken) external view returns (PoolKey memory)Component Functions
getComponents
Get all protocol components.
function getComponents() external view returns (address[] memory)Usage Example
// Get current prices
uint256 marketPrice = blens.getActivePrice(bToken);
uint256 blv = blens.getBLV(bToken);
uint256 premium = blens.getPremium(bToken);
// Check pool state
uint256 reserves = blens.totalReserves(bToken);
uint256 circulating = blens.getCirculatingSupply(bToken);
// Preview leverage
(uint256 collateral, uint256 debt, uint256 needed) = blens.getLeverageResult(
bToken,
1000e18, // initial collateral
2e18 // 2x leverage
);
// Check user position
State.CreditAccount memory credit = blens.getCreditAccount(bToken, user);
uint256 maxBorrow = blens.getMaxBorrow(bToken, credit.collateral);Related
- BSwap Contract : Trading functions
- BCredit Contract : Borrowing functions
- BStaking Contract : Staking functions