Documentation ¶
Index ¶
- Constants
- Variables
- func BigPow(a, b int64) *big.Int
- func ComputeAMMAmountWithPrice(p *model.LiquidityPoolStorage, perpetualIndex int64, isTraderBuy bool, ...) decimal.Decimal
- func ComputeAMMMaxTradeAmount(p *model.LiquidityPoolStorage, perpetualIndex int64, ...) decimal.Decimal
- func ComputeAMMPrice(p *model.LiquidityPoolStorage, perpetualIndex int64, amount decimal.Decimal) (deltaAMMMargin, deltaAMMAmount, tradingPrice decimal.Decimal, err error)
- func ComputeAMMTrade(p *model.LiquidityPoolStorage, perpetualIndex int64, ...) (*model.AccountComputed, bool, decimal.Decimal, error)
- func ComputeAccount(p *model.LiquidityPoolStorage, perpetualIndex int64, a *model.AccountStorage) (*model.AccountComputed, error)
- func ComputeBestAskBidPrice(p *model.LiquidityPoolStorage, perpetualIndex int64, isAMMBuy bool) decimal.Decimal
- func ComputeDecreasePosition(p *model.LiquidityPoolStorage, perpetualIndex int64, a *model.AccountStorage, ...) error
- func ComputeFee(hasOpened bool, price, amount, feeRate decimal.Decimal, ...) (decimal.Decimal, error)
- func ComputeIncreasePosition(p *model.LiquidityPoolStorage, perpetualIndex int64, a *model.AccountStorage, ...) error
- func ComputeTradeWithPrice(p *model.LiquidityPoolStorage, perpetualIndex int64, a *model.AccountStorage, ...) (*model.AccountComputed, bool, decimal.Decimal, error)
- func CopyAccountStorage(a *model.AccountStorage) *model.AccountStorage
- func CopyLiquidityPoolStorage(p *model.LiquidityPoolStorage) *model.LiquidityPoolStorage
- func CopyPerpetualStorage(perp *model.PerpetualStorage) *model.PerpetualStorage
- func GenerateOrderData(...) string
- func GenerateOrderFlags(orderType model.OrderType, isCloseOnly bool) int
- func GetGasFeeLimit(perpetualCount int, isCloseOnly bool) int64
- func GetOrderHash(...) ([]byte, error)
- func Gss(f func(float64) float64, a, b, tol float64, maxIter int) float64
- func IsValidSignature(address string, message string, signature string, method string) (bool, error)
- func Sqrt(d decimal.Decimal) decimal.Decimal
- type MaiProtocolVersion
Constants ¶
const ( // arbitrum MaiV3BaseGas int64 = 4800000 MaiV3GasForEachPerp int64 = 7300 MaiV3BaseGasCloseOnly int64 = 1129722 MaiV3GasForEachPerpCloseOnly int64 = 22330 )
const ( EthSign = "ethSign" EIP712 = "eip712" )
const DECIMALS = 18
Variables ¶
var EIP712_DOMAIN_TYPEHASH []byte
var EIP712_MAI3_ORDER_TYPE []byte
Functions ¶
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 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 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 CopyLiquidityPoolStorage ¶
func CopyLiquidityPoolStorage(p *model.LiquidityPoolStorage) *model.LiquidityPoolStorage
func CopyPerpetualStorage ¶
func CopyPerpetualStorage(perp *model.PerpetualStorage) *model.PerpetualStorage
func GenerateOrderData ¶
func GetGasFeeLimit ¶
func GetOrderHash ¶
func Gss ¶
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 ¶
Types ¶
type MaiProtocolVersion ¶
type MaiProtocolVersion int64
const ( ProtocolV1 MaiProtocolVersion = 1 ProtocolV2 MaiProtocolVersion = 2 ProtocolV3 MaiProtocolVersion = 3 )