Skip to main content
Use these helpers to determine how much Senior or Junior capacity remains and how LP shares are priced.

Usage

console.log("Senior LP price:", market.getSrLpPriceNetAsset());
console.log("Junior LP price:", market.getJrLpPriceNetAsset());
console.log("Senior LP capacity:", market.getSrLpCapacity());
console.log("Junior LP capacity:", market.getJrLpCapacity());
console.log("Senior remaining LP capacity:", market.getSrRemainingLpCapacity());
console.log("Junior remaining LP capacity:", market.getJrRemainingLpCapacity());
console.log("Senior remaining NAV capacity:", market.getSrRemainingCapacityNetAssetValue());
console.log("Junior remaining NAV capacity:", market.getJrRemainingCapacityNetAssetValue());
use exponent_tranching::ExponentTranchingMarket;
use precise_number::Number;

fn calculate_lp_price_net_asset(
    total_lp_supply: u64,
    effective_nav: Number,
) -> Option<Number> {
    let virtual_total_supply = (total_lp_supply as u128).checked_add(1)?;
    let virtual_total_assets = effective_nav.checked_add(&Number::ONE)?;

    virtual_total_assets.checked_div(&Number::from(virtual_total_supply))
}

fn read_capacity_inputs(market: &ExponentTranchingMarket) {
    let senior_lp_price = calculate_lp_price_net_asset(
        market.tranche_supply_state.total_senior_lp_supply,
        market.financials.sr_effective_net_asset,
    );
    let junior_lp_price = calculate_lp_price_net_asset(
        market.tranche_supply_state.total_junior_lp_supply,
        market.financials.jr_effective_net_asset,
    );

    let max_senior_lp_supply = market.tranche_supply_state.max_senior_lp_supply;
    let max_junior_lp_supply = market.tranche_supply_state.max_junior_lp_supply;
    let total_senior_lp_supply = market.tranche_supply_state.total_senior_lp_supply;
    let total_junior_lp_supply = market.tranche_supply_state.total_junior_lp_supply;

    let senior_remaining_by_configured_cap =
        max_senior_lp_supply.saturating_sub(total_senior_lp_supply);
    let junior_remaining_lp_capacity = if max_junior_lp_supply == 0 {
        None
    } else {
        Some(max_junior_lp_supply.saturating_sub(total_junior_lp_supply))
    };

    let min_coverage = market.risk_config.min_coverage;
    let beta = market.risk_config.beta;
    let utilization = market.financials.utilization;

    println!("Senior LP price: {:?}", senior_lp_price);
    println!("Junior LP price: {:?}", junior_lp_price);
    println!(
        "Senior remaining LP by configured cap: {}",
        senior_remaining_by_configured_cap
    );
    println!("Junior remaining LP capacity: {:?}", junior_remaining_lp_capacity);
    println!("Minimum coverage: {}", min_coverage);
    println!("Beta: {}", beta);
    println!("Utilization: {}", utilization);
}
In Rust, max_senior_lp_supply is only the configured Senior cap. Exact Senior capacity also depends on available Junior coverage. Use min_coverage, beta, raw NAV, effective NAV, and LP supply to mirror the capacity helper formulas below.

LP price helpers

FunctionReturnsDescription
getSrLpPriceNetAsset()bigintSenior LP price as raw fixed-point NAV per raw Senior LP unit
getJrLpPriceNetAsset()bigintJunior LP price as raw fixed-point NAV per raw Junior LP unit
LP price uses the virtual-share formula: lpPrice=effectiveNAV+1NAVtotalLpSupply+1\text{lpPrice} = \left\lfloor \frac{\text{effectiveNAV} + 1_{\text{NAV}}}{\text{totalLpSupply} + 1} \right\rfloor In SDK raw bigint values, 1_NAV is 1_000_000_000_000. This converts the fixed-point scale only. Apply token mint decimals separately when showing NAV or LP balances in a UI.

Capacity helpers

FunctionReturnsDescription
getSrLpCapacity()bigintSenior LP capacity constrained by configured max supply and Junior coverage
getJrLpCapacity()bigintConfigured Junior max LP supply. 0n means uncapped
getSrRemainingLpCapacity()bigintRemaining Senior LP capacity
getJrRemainingLpCapacity()bigint | nullRemaining Junior LP capacity, or null when uncapped
getSrMaxCapacityNetAssetValue()bigintMax Senior capacity as raw fixed-point NAV
getJrMaxCapacityNetAssetValue()bigint | nullMax Junior capacity as raw fixed-point NAV, or null when uncapped
getSrRemainingCapacityNetAssetValue()bigintRemaining Senior deposit room as raw fixed-point NAV
getJrRemainingCapacityNetAssetValue()bigint | nullRemaining Junior deposit room as raw fixed-point NAV, or null when uncapped
getSrCoverageRemainingNetAssetValue()bigintSenior deposit room allowed by current Junior coverage, as raw fixed-point NAV
Senior capacity can be lower than maxSeniorLpSupply because Senior deposits also depend on available Junior coverage.