Skip to content

Prime lens

PrimeLens is a read-only helper contract for off-chain APR queries against PrimeV2. It is kept separate from PrimeV2 to stay within the EVM contract-size limit. It holds an immutable reference to a PrimeV2 instance and derives values from PrimeV2 and PrimeLiquidityProvider state.

The PrimeV2 instance this lens reads from (set in the constructor)

contract IPrimeV2WithStorage primeV2

constructor(address primeV2_)
NameTypeDescription
primeV2_addressAddress of the PrimeV2 contract
  • Throw InvalidAddress if primeV2_ is the zero address

Returns supply and borrow APR for a user in a given market, based on current state.

function calculateAPR(address market, address user) external view returns (struct IPrimeV2.APRInfo aprInfo)
NameTypeDescription
marketaddressThe market for which to fetch the APR
useraddressThe account for which to get the APR
NameTypeDescription
aprInfostruct IPrimeV2.APRInfoAPR information for the user in the given market

The APRInfo struct contains:

struct APRInfo {
uint256 supplyAPR; // supply APR of the user in BPS
uint256 borrowAPR; // borrow APR of the user in BPS
uint256 totalScore; // total score of the market
uint256 userScore; // score of the user
uint256 xvsBalanceForScore; // XVS balance of the user used for score
uint256 capital; // capital of the user
uint256 cappedSupply; // capped supply of the user
uint256 cappedBorrow; // capped borrow of the user
uint256 supplyCapUSD; // supply cap of the user in USD
uint256 borrowCapUSD; // borrow cap of the user in USD
}

Returns supply and borrow APR for a user in a given market based on hypothetical supply, borrow and XVS staked amounts. The user’s score is recomputed from the supplied inputs (subtracting their existing market score and re-adding the estimated one), so the result reflects what the APR would be under the provided position.

function estimateAPR(address market, address user, uint256 borrow, uint256 supply, uint256 xvsStaked) external view returns (struct IPrimeV2.APRInfo aprInfo)
NameTypeDescription
marketaddressThe market for which to fetch the APR
useraddressThe account for which to get the APR
borrowuint256Hypothetical borrow amount
supplyuint256Hypothetical supply amount
xvsStakeduint256Hypothetical staked XVS amount
NameTypeDescription
aprInfostruct IPrimeV2.APRInfoAPR information for the user in the given market (same APRInfo struct as calculateAPR)

The total income that will be distributed to Prime token holders for a market over a year. Computed as the PrimeLiquidityProvider effective distribution speed for the market’s underlying multiplied by blocksOrSecondsPerYear.

function incomeDistributionYearly(address vToken) public view returns (uint256 amount)
NameTypeDescription
vTokenaddressThe market for which to fetch the total income
NameTypeDescription
amountuint256The annualized distribution income