mai3

package
v0.0.0-...-a287f25 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// arbitrum
	MaiV3BaseGas                 int64 = 4800000
	MaiV3GasForEachPerp          int64 = 7300
	MaiV3BaseGasCloseOnly        int64 = 1129722
	MaiV3GasForEachPerpCloseOnly int64 = 22330
)
View Source
const (
	EthSign = "ethSign"
	EIP712  = "eip712"
)
View Source
const DECIMALS = 18

Variables

View Source
var EIP712_DOMAIN_TYPEHASH []byte
View Source
var EIP712_MAI3_ORDER_TYPE []byte

Functions

func BigPow

func BigPow(a, b int64) *big.Int

BigPow returns a ** b as a big integer.

func ComputeAMMAmountWithPrice

func ComputeAMMAmountWithPrice(p *model.LiquidityPoolStorage, perpetualIndex int64, isTraderBuy bool, limitPrice decimal.Decimal) decimal.Decimal

func ComputeAMMMaxTradeAmount

func ComputeAMMMaxTradeAmount(p *model.LiquidityPoolStorage, perpetualIndex int64, trader *model.AccountStorage, amount decimal.Decimal, isTraderBuy bool) decimal.Decimal

just use for order, for using golden section search, the bounds is [0, order.amount]

func ComputeAMMPrice

func ComputeAMMPrice(p *model.LiquidityPoolStorage, perpetualIndex int64, amount decimal.Decimal) (deltaAMMMargin, deltaAMMAmount, tradingPrice decimal.Decimal, err error)

func ComputeAMMTrade

func ComputeAMMTrade(p *model.LiquidityPoolStorage, perpetualIndex int64, trader *model.AccountStorage, amount decimal.Decimal) (*model.AccountComputed, bool, decimal.Decimal, error)

func ComputeAccount

func ComputeAccount(p *model.LiquidityPoolStorage, perpetualIndex int64, a *model.AccountStorage) (*model.AccountComputed, error)

func ComputeBestAskBidPrice

func ComputeBestAskBidPrice(p *model.LiquidityPoolStorage, perpetualIndex int64, isAMMBuy bool) decimal.Decimal

get the price if ΔN -> 0. lim_(ΔN -> 0) (computeDeltaMargin / (ΔN)) this function implements all possible situations include: * limit by α. this is P_{best} in the paper * limit by δ when close * amm unsafe

func ComputeDecreasePosition

func ComputeDecreasePosition(p *model.LiquidityPoolStorage, perpetualIndex int64, a *model.AccountStorage, price, amount decimal.Decimal) error

func ComputeFee

func ComputeFee(hasOpened bool, price, amount, feeRate decimal.Decimal, afterTrade *model.AccountComputed) (decimal.Decimal, error)

func ComputeIncreasePosition

func ComputeIncreasePosition(p *model.LiquidityPoolStorage, perpetualIndex int64, a *model.AccountStorage, price, amount decimal.Decimal) error

func ComputeTradeWithPrice

func ComputeTradeWithPrice(p *model.LiquidityPoolStorage, perpetualIndex int64, a *model.AccountStorage, price, amount, feeRate decimal.Decimal) (*model.AccountComputed, bool, decimal.Decimal, error)

func CopyAccountStorage

func CopyAccountStorage(a *model.AccountStorage) *model.AccountStorage

func CopyPerpetualStorage

func CopyPerpetualStorage(perp *model.PerpetualStorage) *model.PerpetualStorage

func GenerateOrderData

func GenerateOrderData(traderAddress, brokerAddress, relayerAddress, referrerAddress, poolAddress string,
	minTradeAmount, amount, price, triggerPrice decimal.Decimal, chainID int64,
	expiredAt, perpetualIndex, brokerFeeLimit, flags, salt int64, signType, v, r, s string) string

func GenerateOrderFlags

func GenerateOrderFlags(orderType model.OrderType, isCloseOnly bool) int

func GetGasFeeLimit

func GetGasFeeLimit(perpetualCount int, isCloseOnly bool) int64

func GetOrderHash

func GetOrderHash(traderAddress, brokerAddress, relayerAddress, referrerAddress, poolAddress string,
	minTradeAmount, amount, price, triggerPrice decimal.Decimal, chainID int64,
	expiredAt, perpetualIndex, brokerFeeLimit, flags, salt int64) ([]byte, error)

func Gss

func Gss(f func(float64) float64, a, b, tol float64, maxIter int) float64

Gss golden section search (recursive version) https://en.wikipedia.org/wiki/Golden-section_search ”' Golden section search, recursive. Given a function f with a single local minimum in the interval [a,b], gss returns a subset interval [c,d] that contains the minimum with d-c <= tol.

example: >>> f = lambda x: (x-2)**2 >>> a = 1 >>> b = 5 >>> tol = 1e-5 >>> (c,d) = gssrec(f, a, b, tol) >>> print (c,d) (1.9999959837979107, 2.0000050911830893) ”'

func IsValidSignature

func IsValidSignature(address string, message string, signature string, method string) (bool, error)

func Sqrt

Sqrt returns the square root of d, accurate to DivisionPrecision decimal places.

Types

type MaiProtocolVersion

type MaiProtocolVersion int64
const (
	ProtocolV1 MaiProtocolVersion = 1
	ProtocolV2 MaiProtocolVersion = 2
	ProtocolV3 MaiProtocolVersion = 3
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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