utils

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 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 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 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 negative.

func ExpDec

func ExpDec(x math.LegacyDec, terms int) (result math.LegacyDec, err error)

ExpDec calculates e^x using the Maclaurin series expansion up to `terms` terms. Fully deterministic and safe for on-chain use.

e^x = 1 + x + x^2/2! + x^3/3! + ... + x^n/n!

Note: x is cosmosmath.LegacyDec; higher `terms` -> greater accuracy.

A large |x| overflows the LegacyDec accumulator, which panics; that overflow is recovered and returned as an error instead. Callers should still bound x upstream (see types.MaxAbsInterestRate); this guard is defense-in-depth.

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