Documentation
¶
Index ¶
- Variables
- func CalculateRedeemProRataFraction(shares math.Int, totalShares math.Int, totalAssets math.Int, ...) (sdk.Coin, error)
- func CalculateSharesProRataFraction(amountNumerator math.Int, amountDenominator math.Int, totalAssets math.Int, ...) (sdk.Coin, error)
- func ExpDec(x math.LegacyDec, terms int) math.LegacyDec
- func Filter[S any](s []S, fn func(S) bool) iter.Seq[S]
- func GenerateRandomBytes(n int) []byte
- func Map[S any, T any](s []S, fn func(S) T) iter.Seq[T]
- type Address
Constants ¶
This section is empty.
Variables ¶
var ( VirtualAssets = math.NewInt(1) // 1 base unit of underlying )
Fixed precision / virtual-offset parameters.
ShareScalar sets the "neutral" precision: 1 asset unit -> ShareScalar shares. VirtualAssets and VirtualShares are added to totals in all conversions to harden against first-depositor inflation/rounding attacks.
IMPORTANT: - VirtualAssets is ONE base unit of the underlying asset. - VirtualShares equals ShareScalar. - Do NOT divide by ShareScalar in redemption: the share supply is already scaled.
Functions ¶
func CalculateRedeemProRataFraction ¶
func CalculateRedeemProRataFraction(shares math.Int, totalShares math.Int, totalAssets math.Int, priceNumerator math.Int, priceDenominator math.Int, payoutDenom string) (sdk.Coin, error)
CalculateRedeemProRataFraction computes the payout amount for redeeming shares into an arbitrary payout denom using a single-floor, pro-rata formula with virtual offsets and an explicit price fraction.
Arguments:
- shares is the number of vault shares being redeemed.
- totalShares / totalAssets are the vault-wide totals prior to redemption.
- priceNumerator / priceDenominator encode the payout denom’s price in underlying units (1 payout = priceNum / priceDen underlying). For underlying payouts, pass (1, 1).
- payoutDenom is the target payout denom for the resulting coin.
Behavior:
- Applies virtual offsets: ta' = totalAssets + VirtualAssets, ts' = totalShares + VirtualShares.
- Computes: payout = floor( shares * ta' * priceDen / (ts' * priceNum) ).
- Returns sdk.Coin(payoutDenom, payout).
Errors if any input is negative or if priceNumerator == 0.
func CalculateSharesProRataFraction ¶
func CalculateSharesProRataFraction( amountNumerator math.Int, amountDenominator math.Int, totalAssets math.Int, totalShares math.Int, shareDenom string, ) (sdk.Coin, error)
CalculateSharesProRataFraction computes minted shares for a deposit using a single-floor, pro-rata formula with virtual offsets and an explicit price fraction.
Arguments:
- amountNumerator / amountDenominator represent the deposit value expressed in underlying units as a rational (e.g., amount * priceNum / priceDen). For underlying deposits, pass (amount, 1).
- totalAssets / totalShares are the vault-wide totals prior to the deposit.
- shareDenom is the vault share denom for the resulting coin.
Behavior:
- Applies virtual offsets: ta' = totalAssets + VirtualAssets, ts' = totalShares + VirtualShares.
- First deposit mints amount * ShareScalar / amountDenominator.
- Otherwise: shares = floor( amountNumerator * ts' / (amountDenominator * ta') ).
Errors if any input is negative or if amountDenominator == 0.
func ExpDec ¶
ExpDec calculates e^x using the Maclaurin series expansion up to `terms` terms. Safe for on-chain use (fully deterministic).
e^x = 1 + x + x^2/2! + x^3/3! + ... + x^n/n!
Note: x is cosmosmath.LegacyDec; higher `terms` -> greater accuracy.
func GenerateRandomBytes ¶
Types ¶
type Address ¶
func TestAddress ¶
func TestAddress() Address
func TestProvlabsAddress ¶
func TestProvlabsAddress() Address