sim_helpers

package
v0.0.0-...-baf6593 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Used to determine the % frequency that used genesis values are reasonable (e.g. similar to
	// to potential real-world conditions) in simulation tests. Value should be between 0 and 100.
	// For ex. if ReasonableGenesisWeight = 90, 90% of simulation tests will use reasonable values.
	ReasonableGenesisWeight = 90
)

Variables

View Source
var (
	MinValidClobPairs = MinNumPerpetuals.Valid
	MaxValidClobPairs = MaxNumPerpetuals.Valid * 2

	MinQuantumConversionExponent = GenesisParameters[int]{
		Reasonable: -9,
		Valid:      -25,
	}
	MaxQuantumConversionExponent = GenesisParameters[int]{
		Reasonable: 0,
		Valid:      25,
	}

	MinStepBaseQuantums = GenesisParameters[int]{
		Reasonable: 10,
		Valid:      1,
	}
	MaxStepBaseQuantums = GenesisParameters[int]{
		Reasonable: 100_000,
		Valid:      math.MaxUint32,
	}

	MaxOrderBaseQuantums = GenesisParameters[int]{
		Reasonable: 10_000_000,
		Valid:      math.MaxUint32,
	}

	MinSubticksPerTick = GenesisParameters[int]{
		Reasonable: 10,
		Valid:      1,
	}
	MaxSubticksPerTick = GenesisParameters[int]{
		Reasonable: 100_000,
		Valid:      math.MaxUint32,
	}

	MinPositionNotionalBuckets = []int{
		1,
		1_000_000,
		100_000_000,
		1_000_000_000_000,
	}
	SubaccountBlockLimitsBuckets = []int{
		1_000_000_000,
		10_000_000_000,
		100_000_000_000,
		1_000_000_000_000,
	}
	PpmSkewedTowardLowerBuckets = []int{
		1,
		1_000,
		10_000,
		100_000,
		1_000_000,
	}
	PpmSkewedTowardLargerBuckets = []int{
		1,
		500_000,
		750_000,
		900_000,
		1_000_000,
	}
)

Clob genesis parameters.

View Source
var (
	MinMarkets = GenesisParameters[int]{
		Reasonable: 10,
		Valid:      1,
	}
	MaxMarkets = GenesisParameters[int]{
		Reasonable: 200,
		Valid:      1000,
	}

	MinMinExchangesPerMarket = GenesisParameters[int]{
		Reasonable: 3,
		Valid:      1,
	}
	MaxMinExchangesPerMarket = GenesisParameters[int]{
		Reasonable: 5,
		Valid:      100,
	}

	MinMarketExponent = GenesisParameters[int]{
		Reasonable: -10,
		Valid:      -10,
	}
	MaxMarketExponent = GenesisParameters[int]{
		Reasonable: 0,
		Valid:      10,
	}
	MinMarketPrice = GenesisParameters[int]{
		Reasonable: 10_000,
		Valid:      1,
	}
	MaxMarketPrice = GenesisParameters[int]{
		Reasonable: 500_000_000_000,
		Valid:      math.MaxInt,
	}

	MinExchangesPerMarket = 1
)

Prices genesis parameters.

View Source
var (
	MinNumPerpetuals = GenesisParameters[int]{
		Reasonable: MinMarkets.Reasonable * 2,
		Valid:      MinMarkets.Valid * 2,
	}
	MaxNumPerpetuals = GenesisParameters[int]{
		Reasonable: MaxMarkets.Reasonable * 2,
		Valid:      MaxMarkets.Valid * 2,
	}

	MinNumLiquidityTiers = GenesisParameters[int]{
		Reasonable: 1,
		Valid:      2,
	}
	MaxNumLiquidityTiers = GenesisParameters[int]{
		Reasonable: 4,
		Valid:      MaxNumPerpetuals.Valid,
	}

	MinFundingRateClampFactorPpm = GenesisParameters[int]{
		Reasonable: 4_000_000,
		Valid:      1_000_000,
	}
	MaxFundingRateClampFactorPpm = GenesisParameters[int]{
		Reasonable: 8_000_000,
		Valid:      12_000_000,
	}

	MinPremiumVoteClampFactorPpm = GenesisParameters[int]{
		Reasonable: 40_000_000,
		Valid:      10_000_000,
	}
	MaxPremiumVoteClampFactorPpm = GenesisParameters[int]{
		Reasonable: 80_000_000,
		Valid:      120_000_000,
	}

	MinMinNumVotesPerSample = GenesisParameters[int]{
		Reasonable: 10,
		Valid:      0,
	}
	MaxMinNumVotesPerSample = GenesisParameters[int]{
		Reasonable: 25,
		Valid:      80,
	}

	MinAtomicResolution = GenesisParameters[int]{
		Reasonable: -10,
		Valid:      -10,
	}
	MaxAtomicResolution = GenesisParameters[int]{
		Reasonable: 0,
		Valid:      10,
	}

	DefaultFundingPpmAbsBuckets = []int{
		0,
		100,
		1_000,
		10_000,
		100_000,
		int(perptypes.MaxDefaultFundingPpmAbs),
	}

	InitialMarginBuckets = []int{
		0,
		100,
		1_000,
		10_000,
		100_000,
		int(perptypes.MaxInitialMarginPpm) + 1,
	}
)

Perpetuals genesis parameters.

View Source
var (
	MinNumSubaccount = 1
	MaxNumSubaccount = 128
)

Subaccounts genesis parameters.

Functions

func GenerateAndCheckTx

func GenerateAndCheckTx(
	r *rand.Rand,
	app *baseapp.BaseApp,
	ctx sdk.Context,
	chainId string,
	cdc *codec.ProtoCodec,
	ak pricestypes.AccountKeeper,
	bk pricestypes.BankKeeper,
	account simtypes.Account,
	moduleName string,
	msg sdk.Msg,
	msgType string,
	withZeroFees bool,
) (simtypes.OperationMsg, error)

GenerateAndCheckTx generates a random fee (or with zero fees if set), then generates a signed mock tx and calls `CheckTx` for simulated operations. This heavily matches the cosmos sdk `util.go` GenAndDeliverTx method from the simulation module.

func GenerateAndDeliverTx

func GenerateAndDeliverTx(
	r *rand.Rand,
	app *baseapp.BaseApp,
	ctx sdk.Context,
	chainId string,
	cdc *codec.ProtoCodec,
	ak pricestypes.AccountKeeper,
	bk pricestypes.BankKeeper,
	account simtypes.Account,
	moduleName string,
	msg sdk.Msg,
	msgType string,
	withZeroFees bool,
) (simtypes.OperationMsg, error)

GenerateAndDeliverTx generates a random fee (or with zero fees if set), then generates a signed mock tx and delivers the tx to the app for simulated operations.

func GetMin

func GetMin(x, y int) int

GetMin returns minimum of the two inputs.

func GetRandomBucketValue

func GetRandomBucketValue(r *rand.Rand, bucketBoundaries []int) int

GetRandomBucketValue randomly selects a min/max based on the given bucket boundaries and returns a random value within the chosen min/max. Each bucket has an equal probability of getting selected.

func MakeRange

func MakeRange(n uint32) []uint32

MakeRange returns a slice of uint32 where the values are sequential.

func PickGenesisParameter

func PickGenesisParameter[T any](
	param GenesisParameters[T],
	shouldUseReasonable bool,
) T

PickGenesisParameter picks the Reasonable genesis parameter if `shouldUseReasonable = true`, and the Valid parameter otherwise.

func RandBool

func RandBool(r *rand.Rand) bool

RandBool randomly returns true or false where each return value has 50% chance.

func RandPositiveUint64

func RandPositiveUint64(r *rand.Rand) uint64

RandPositiveUint64 returns a randomized number between 1 and the maximum `uint64`, inclusive.

func RandSliceShuffle

func RandSliceShuffle[T any](r *rand.Rand, s []T) []T

RandSliceShuffle returns a shuffled version of the input slice.

func RandWithWeight

func RandWithWeight[T comparable](r *rand.Rand, optionsWithWeight map[T]int) T

RandWithWeight takes in a map of options, each with a weight and returns each element with a probability (weight/totalWeight). Panics if weight is negative.

func ShouldGenerateReasonableGenesis

func ShouldGenerateReasonableGenesis(r *rand.Rand, genesisTime time.Time) bool

ShouldGenerateReasonableGenesis determines whether or not the Genesis parameters should be reasonable based on the ReasonableGenesisWeight (0-100). Weight is deterministic on genisisTime, meaning all modules should generate the same result for a simulation run.

Types

type GenesisParameters

type GenesisParameters[T any] struct {
	// Reasonable indicates a value that is similar to real-world conditions.
	Reasonable T
	// Valid indicates a value that can be handled by the chain without panicking.
	Valid T
}

Jump to

Keyboard shortcuts

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