utils

package
v1.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ShareScalar   = math.NewInt(1_000_000) // 1 asset = 1e6 shares (neutral precision target)
	VirtualAssets = math.NewInt(1)         // 1 base unit of underlying
	VirtualShares = ShareScalar
)

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

func ExpDec(x math.LegacyDec, terms int) math.LegacyDec

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 Filter

func Filter[S any](s []S, fn func(S) bool) iter.Seq[S]

func GenerateRandomBytes

func GenerateRandomBytes(n int) []byte

func Map

func Map[S any, T any](s []S, fn func(S) T) iter.Seq[T]

Types

type Address

type Address struct {
	Bytes  []byte
	Bech32 string
}

func TestAddress

func TestAddress() Address

func TestProvlabsAddress

func TestProvlabsAddress() Address

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL