yield_basis.metrics

Documentation for eth_defi.yield_basis.metrics Python module.

YieldBasis fundamental, redemption and conversion calculations.

The primary share price uses the USD value returned by preview_withdraw; fundamental pricePerShare remains available for comparison. Inputs stay as raw onchain integers until these pure functions derive display values.

Stablecoin conversion is an endpoint cost, exposed separately through estimate_usd_stablecoin_swap_cost() and never embedded in the historical equity curve.

Module Attributes

PPS_SCALE

Fixed-point scale used by LT pricePerShare().

ORACLE_SCALE

Fixed-point scale used by Curve price_oracle().

LT_SHARE_SCALE

Decimal scale used by LT share balances.

YIELD_BASIS_USD_STABLECOIN_SWAP_COST

Assumed one-way conversion cost between a generic USD stablecoin and the YieldBasis underlying asset: 10 basis points, or 0.10%.

MAX_ASSET_DECIMALS

Largest sensible ERC-20 decimal precision for a uint256 raw value.

Functions

asset_price_per_share(raw_price_per_share, *)

Convert raw LT pricePerShare to native asset units.

asset_usd_price(raw_price, *[, oracle_scale])

Convert the Curve pool oracle to assumed USD per native asset.

estimate_usd_stablecoin_swap_cost(...)

Estimate one generic USD-stablecoin/underlying conversion cost.

redemption_asset_per_share(...[, share_scale])

Convert a protocol redemption preview to native asset per LT share.

redemption_usd_price_per_share(...[, ...])

Convert a marginal redemption preview to USD per LT share.

round_trip_usd_stablecoin_swap_cost(...)

Return the assumed loss from an otherwise flat round trip.

staked_ratio(raw_effective_supply, ...)

Return staked LT units divided by effective LT supply.

temporary_redemption_discount(...[, ...])

Return temporary redemption discount relative to fundamental PPS.

underlying_return(start_raw_price_per_share, ...)

Return the native-asset endpoint return for one LT share.

usd_stablecoin_investor_return(...)

Calculate mint-to-redemption USD return after endpoint conversions.

PPS_SCALE: int = 1000000000000000000

Fixed-point scale used by LT pricePerShare().

ORACLE_SCALE: int = 1000000000000000000

Fixed-point scale used by Curve price_oracle().

LT_SHARE_SCALE: int = 1000000000000000000

Decimal scale used by LT share balances.

YIELD_BASIS_USD_STABLECOIN_SWAP_COST: float = 0.001

Assumed one-way conversion cost between a generic USD stablecoin and the YieldBasis underlying asset: 10 basis points, or 0.10%.

MAX_ASSET_DECIMALS: int = 78

Largest sensible ERC-20 decimal precision for a uint256 raw value. Ethereum’s uint256 decimal display has at most 78 decimal places.

estimate_usd_stablecoin_swap_cost(underlying_token)

Estimate one generic USD-stablecoin/underlying conversion cost.

The current baseline is deliberately simple: every reviewed WBTC, cbBTC, tBTC and WETH market uses the same fixed 10-basis-point assumption. The underlying-token argument keeps the accounting boundary explicit and allows later token-specific estimates without changing the VaultBase fee interface or historical schema. This estimate excludes price impact, gas and MEV.

Parameters

underlying_token (eth_typing.evm.HexAddress) – YieldBasis LT underlying ERC-20 address.

Returns

One-way cost as a fraction, currently 0.001 for every token.

Return type

float

usd_stablecoin_investor_return(fundamental_entry_share_price, redemption_exit_share_price, underlying_token)

Calculate mint-to-redemption USD return after endpoint conversions.

YieldBasis mints new shares at fundamental PPS and redeems them at the current preview_withdraw value. The entry value must therefore exclude TRD, while the exit value includes it. Each stablecoin conversion retains 1 - cost of value. The fixed cost is applied once at entry and once at exit, never at intermediate historical observations.

Parameters
  • fundamental_entry_share_price (decimal.Decimal) – Positive fundamental USD PPS used to mint at entry.

  • redemption_exit_share_price (decimal.Decimal) – Positive TRD-inclusive USD redemption value at exit.

  • underlying_token (eth_typing.evm.HexAddress) – YieldBasis LT underlying ERC-20 address.

Returns

Net endpoint return where 0.1 means 10%.

Return type

decimal.Decimal

round_trip_usd_stablecoin_swap_cost(underlying_token)

Return the assumed loss from an otherwise flat round trip.

Parameters

underlying_token (eth_typing.evm.HexAddress) – YieldBasis LT underlying ERC-20 address.

Returns

Positive loss fraction, currently 0.001999 for two 10-bps legs.

Return type

decimal.Decimal

asset_price_per_share(raw_price_per_share, *, pps_scale=1000000000000000000)

Convert raw LT pricePerShare to native asset units.

Parameters
  • raw_price_per_share (int) – LT fixed-point pricePerShare value.

  • pps_scale (int) – Fixed-point scale verified for the deployed market.

Returns

Native-asset value of one LT share.

Return type

decimal.Decimal

asset_usd_price(raw_price, *, oracle_scale=1000000000000000000)

Convert the Curve pool oracle to assumed USD per native asset.

The reviewed pools quote coin 1, the BTC or ETH asset, in coin 0 crvUSD. The integration treats that stable-side quote as one USD for its generic USD comparison; crvUSD remains protocol plumbing, not the investor-facing denomination token.

Parameters
  • raw_price (int) – Raw Curve price_oracle() value.

  • oracle_scale (int) – Fixed-point scale verified for the deployed pools.

Returns

Assumed USD value of one whole native asset.

Return type

decimal.Decimal

underlying_return(start_raw_price_per_share, end_raw_price_per_share, *, pps_scale=1000000000000000000)

Return the native-asset endpoint return for one LT share.

This diagnostic isolates the change in YieldBasis fundamental PPS from the BTC or ETH price move included in the primary USD return.

Parameters
  • start_raw_price_per_share (int) – Raw LT PPS at the start observation.

  • end_raw_price_per_share (int) – Raw LT PPS at the end observation.

  • pps_scale (int) – LT fixed-point scale.

Returns

Decimal endpoint return, where 0.1 means 10%.

Return type

decimal.Decimal

redemption_asset_per_share(raw_preview_shares, raw_redemption_assets, *, asset_decimals, share_scale=1000000000000000000)

Convert a protocol redemption preview to native asset per LT share.

preview_withdraw returns raw units of the market’s volatile asset, whereas LT shares use the protocol’s 18-decimal fixed-point scale.

Parameters
  • raw_preview_shares (int) – Raw LT units supplied to preview_withdraw.

  • raw_redemption_assets (int) – Raw underlying units returned by the preview.

  • asset_decimals (int) – ERC-20 decimals of the underlying asset.

  • share_scale (int) – LT share fixed-point scale.

Returns

Native-asset redemption value per whole LT share.

Return type

decimal.Decimal

redemption_usd_price_per_share(raw_preview_shares, raw_redemption_assets, raw_asset_crvusd_price, *, asset_decimals, oracle_scale=1000000000000000000, share_scale=1000000000000000000)

Convert a marginal redemption preview to USD per LT share.

This is the primary gross YieldBasis share-price-equivalence formula used by the common vault pipeline. The first term incorporates the Temporary Redemption Discount (TRD); the second term incorporates BTC or ETH price volatility. Multiplying the two is equivalent to fundamental USD PPS multiplied by 1 + TRD, so callers must not subtract TRD a second time. Investor-specific conversion costs are not deducted here: use usd_stablecoin_investor_return() for a fee-adjusted investment period.

Parameters
  • raw_preview_shares (int) – Raw LT units supplied to preview_withdraw.

  • raw_redemption_assets (int) – Raw underlying units returned by the preview.

  • raw_asset_crvusd_price (int) – Raw Curve asset/crvUSD oracle value used as the USD proxy at the same block.

  • asset_decimals (int) – ERC-20 decimal precision of the underlying asset.

  • oracle_scale (int) – Curve oracle fixed-point scale.

  • share_scale (int) – LT share fixed-point scale.

Returns

Gross marginal redemption value of one whole LT share in USD.

Return type

decimal.Decimal

temporary_redemption_discount(raw_preview_shares, raw_redemption_assets, raw_price_per_share, *, asset_decimals, pps_scale=1000000000000000000, share_scale=1000000000000000000)

Return temporary redemption discount relative to fundamental PPS.

A negative value means the previewed exit is below fundamental value. The preview is required because the primary curve must not substitute fundamental value and mix two accounting bases.

Parameters
  • raw_preview_shares (int) – Raw LT units supplied to preview_withdraw.

  • raw_redemption_assets (int) – Raw underlying units returned by the preview.

  • raw_price_per_share (int) – Raw fundamental LT PPS from the same block.

  • asset_decimals (int) – ERC-20 decimals of the underlying asset.

  • pps_scale (int) – LT PPS fixed-point scale.

  • share_scale (int) – LT share fixed-point scale.

Returns

Redemption-to-fundamental relative difference.

Return type

decimal.Decimal

staked_ratio(raw_effective_supply, raw_staked_supply)

Return staked LT units divided by effective LT supply.

The ratio is contextual market information only; staked gauge returns and YB incentives are outside the base LT performance curve.

Parameters
  • raw_effective_supply (int) – Effective LT supply from updated_balances().

  • raw_staked_supply (int) – Effective LT units held in the staker.

Returns

Ratio from zero to one, or None for zero supply.

Return type

Optional[decimal.Decimal]