Documentation
¶
Index ¶
- Variables
- func CalculateRedeemProRata(shares math.Int, totalShares math.Int, totalAssets math.Int, ...) (sdk.Coin, error)
- func CalculateSharesProRata(amount math.Int, totalAssets math.Int, totalShares math.Int, shareDenom string) (sdk.Coin, error)
- func ExpDec(x math.LegacyDec, terms int) (result math.LegacyDec, err error)
- 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.
ErrZeroAssetsWithSharesOutstanding is returned by CalculateSharesProRata when zero assets back outstanding shares, collapsing the pro-rata divisor to VirtualAssets alone. Classify with errors.Is.
Functions ¶
func CalculateRedeemProRata ¶ added in v1.2.0
func CalculateRedeemProRata(shares math.Int, totalShares math.Int, totalAssets math.Int, payoutDenom string) (sdk.Coin, error)
CalculateRedeemProRata computes the payout amount for redeeming shares into the vault's underlying asset using a single-floor, pro-rata formula with virtual offsets. Vaults are single-denom, so the payout is always in underlying units and no price conversion applies.
Arguments:
- shares is the number of vault shares being redeemed.
- totalShares / totalAssets are the vault-wide totals prior to redemption.
- payoutDenom is the underlying asset denom for the resulting coin.
Behavior:
- Applies virtual offsets: ta' = totalAssets + VirtualAssets, ts' = totalShares + VirtualShares.
- Computes: payout = floor( shares * ta' / ts' ).
- Returns sdk.Coin(payoutDenom, payout).
Errors if any input is nil or negative.
func CalculateSharesProRata ¶ added in v1.2.0
func CalculateSharesProRata( amount math.Int, totalAssets math.Int, totalShares math.Int, shareDenom string, ) (sdk.Coin, error)
CalculateSharesProRata computes minted shares for a deposit of the vault's underlying asset using a single-floor, pro-rata formula with virtual offsets. Vaults are single-denom, so the deposit amount is already in underlying units and no price conversion applies.
Arguments:
- amount is the deposit amount in underlying units.
- 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.
- Otherwise: shares = floor( amount * ts' / ta' ).
Errors if any input is nil or negative, or with ErrZeroAssetsWithSharesOutstanding when zero assets back outstanding shares.
func ExpDec ¶
ExpDec calculates e^x using a Maclaurin series expansion of `terms` terms. Fully deterministic and safe for on-chain use.
e^x = 1 + x + x^2/2! + x^3/3! + ... + x^n/n!
The truncated series is only accurate for small |x|, so x is first range-reduced by repeated halving until |x| <= 1 and the series result is squared back up (e^x = (e^(x/2^k))^(2^k)). Without that reduction the series diverges for large positive x and sign-inverts to a negative e^x below x ~= -5.61.
Note: x is cosmosmath.LegacyDec; higher `terms` -> greater accuracy.
A large positive x overflows the LegacyDec accumulator, which panics; that overflow is recovered and returned as an error instead. A large negative x underflows to zero, which is the closest LegacyDec representation of e^x in that regime.
func GenerateRandomBytes ¶
Types ¶
type Address ¶
func TestAddress ¶
func TestAddress() Address
func TestProvlabsAddress ¶
func TestProvlabsAddress() Address