spot

package
v1.67.4 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuySellAsset

func BuySellAsset(op int32, left, right *et.ZkAsset) (*et.ZkAsset, *et.ZkAsset)

func CalcActualCost

func CalcActualCost(op int32, amount int64, price, coinPrecision int64) int64

CalcActualCost Calculate actual cost

func CreateNftOrder

func CreateNftOrder(payload *et.SpotNftOrder, ty int32) *et.SpotOrder

func CreateNftTakerOrder

func CreateNftTakerOrder(payload *et.SpotNftTakerOrder, ty int32, order2 *Order) *et.SpotOrder

func Direction

func Direction(op int32) int32

Direction Buying depth is in reverse order by price, from high to low

func FindOrderByOrderID

func FindOrderByOrderID(statedb dbm.KV, localdb dbm.KV, dbprefix et.DBprefix, orderID int64) (*et.SpotOrder, error)

func FindOrderByOrderNftID

func FindOrderByOrderNftID(statedb dbm.KV, localdb dbm.KV, dbprefix et.DBprefix, orderID int64) (*et.SpotOrder, error)

func GetCoinPrecision

func GetCoinPrecision(ty int32) int64

func LoadSpotFeeAccountConfig

func LoadSpotFeeAccountConfig(db dbm.KV) (*et.DexAccount, error)

func NewEvmNftAsset

func NewEvmNftAsset(left uint64) *et.ZkAsset

func NewHistoryOrderTable

func NewHistoryOrderTable(kvdb dbm.KV, p et.DBprefix) *table.Table

NewHistoryOrderTable ...

func NewMarketDepthTable

func NewMarketDepthTable(kvdb dbm.KV, p et.DBprefix) *table.Table

NewMarketDepthTable 新建表

func NewMarketOrderTable

func NewMarketOrderTable(kvdb dbm.KV, p et.DBprefix) *table.Table

NewMarketOrderTable ...

func NewZkAsset

func NewZkAsset(left uint64) *et.ZkAsset

func NewZkNftAsset

func NewZkNftAsset(left uint64) *et.ZkAsset

func OpSwap

func OpSwap(op int32) int32

OpSwap reverse

func ParseCoins

func ParseCoins(cfg *types.Chain33Config, tradeKey string, height int64) (coins []et.CoinCfg, err error)

func ParseConfig

func ParseConfig(cfg *types.Chain33Config, height int64) (*et.Econfig, error)

func ParseStrings

func ParseStrings(cfg *types.Chain33Config, tradeKey string, height int64) (ret []string, err error)

func ParseSymbols

func ParseSymbols(cfg *types.Chain33Config, tradeKey string, height int64) (symbols map[string]*et.Trade, err error)

func QueryHistoryOrderList

func QueryHistoryOrderList(localdb dbm.KV, dbprefix et.DBprefix, in *et.SpotQueryHistoryOrderList) (types.Message, error)

QueryHistoryOrderList Only the order information is returned

func QueryMarketDepth

func QueryMarketDepth(localdb dbm.KV, dbprefix et.DBprefix, in *et.SpotQueryMarketDepth) (*et.SpotMarketDepthList, error)

QueryMarketDepth 这里primaryKey当作主键索引来用, The first query does not need to fill in the value, pay according to the price from high to low, selling orders according to the price from low to high query

func QueryOrderList

func QueryOrderList(localdb dbm.KV, dbprefix et.DBprefix, in *et.SpotQueryOrderList) (types.Message, error)

QueryOrderList Displays the latest by default

func SafeAdd

func SafeAdd(x, y int64) int64

SafeAdd Safe add

func SafeMul

func SafeMul(x, y, coinPrecision int64) int64

SafeMul Safe multiplication of large numbers, prevent overflow

func SymbolStr

func SymbolStr(a *et.ZkAsset) string

func SymbolStrL1

func SymbolStrL1(i uint64) string

Types

type AccountInfo

type AccountInfo struct {
	// contains filtered or unexported fields
}

type AssetAccount

type AssetAccount interface {
	Transfer(to AssetAccount, amountt int64) (*types.Receipt, error)
	TransferFrozen(to AssetAccount, amountt int64) (*types.Receipt, error)

	Frozen(amount int64) (*types.Receipt, error)
	UnFrozen(amount int64) (*types.Receipt, error)
	CheckBalance(amount int64) error

	GetCoinPrecision() int64
	GetAccountInfo() AccountInfo
}

support kinds of asset

type AssetAccounts

type AssetAccounts struct {
	// contains filtered or unexported fields
}

type DexAccount

type DexAccount struct {
	// contains filtered or unexported fields
}

func LoadSpotAccount

func LoadSpotAccount(addr string, id uint64, statedb dbm.KV, p et.DBprefix) (*DexAccount, error)

func NewDexAccount

func NewDexAccount(acc *et.DexAccount, db *accountRepo) *DexAccount

func (*DexAccount) Active

func (acc *DexAccount) Active(token uint64, amount uint64) (*types.Receipt, error)

func (*DexAccount) Burn

func (acc *DexAccount) Burn(token uint64, amount uint64) (*types.Receipt, error)

func (*DexAccount) Frozen

func (acc *DexAccount) Frozen(token uint64, amount uint64) (*types.Receipt, error)

func (*DexAccount) FrozenTranfer

func (acc *DexAccount) FrozenTranfer(accTo *DexAccount, token uint64, amount uint64) (*types.Receipt, error)

func (*DexAccount) GetBalance

func (acc *DexAccount) GetBalance(tid uint64) uint64

func (*DexAccount) GetFrozen

func (acc *DexAccount) GetFrozen(tid uint64) uint64

func (*DexAccount) GetKVSet

func (acc *DexAccount) GetKVSet() (kvset []*types.KeyValue)

GetKVSet account to statdb kv

func (*DexAccount) Mint

func (acc *DexAccount) Mint(token uint64, amount uint64) (*types.Receipt, error)

func (*DexAccount) Tranfer

func (acc *DexAccount) Tranfer(accTo *DexAccount, token uint64, amount uint64) (*types.Receipt, error)

type Entrust

type Entrust struct {
	// contains filtered or unexported fields
}

func NewEntrust

func NewEntrust(s string, h int64, d dbm.KV) *Entrust

func (*Entrust) Bind

func (a *Entrust) Bind(payload *et.SpotExchangeBind) (*types.Receipt, error)

func (*Entrust) CheckBind

func (a *Entrust) CheckBind(addr string) error

func (*Entrust) SetDB

func (a *Entrust) SetDB(d dbm.KV, prefix et.DBprefix)

type EvmxgoNftAccountRepo

type EvmxgoNftAccountRepo struct {
	// contains filtered or unexported fields
}

func (*EvmxgoNftAccountRepo) NewAccount

func (accdb *EvmxgoNftAccountRepo) NewAccount(addr string, accid uint64, asset *et.ZkAsset) (*NftAccount, error)

type GetFeeAccount

type GetFeeAccount func() (*SpotFee, error)

type HistoryOrderRow

type HistoryOrderRow struct {
	*et.SpotOrder
}

HistoryOrderRow table meta 结构

func NewHistoryOrderRow

func NewHistoryOrderRow() *HistoryOrderRow

NewHistoryOrderRow ...

func (*HistoryOrderRow) CreateRow

func (m *HistoryOrderRow) CreateRow() *table.Row

CreateRow ...

func (*HistoryOrderRow) Get

func (m *HistoryOrderRow) Get(key string) ([]byte, error)

Get 按照indexName 查询 indexValue

func (*HistoryOrderRow) SetPayload

func (m *HistoryOrderRow) SetPayload(data types.Message) error

SetPayload 设置数据

type MarketDepthRow

type MarketDepthRow struct {
	*et.SpotMarketDepth
}

MarketDepthRow table meta 结构

func NewMarketDepthRow

func NewMarketDepthRow() *MarketDepthRow

NewMarketDepthRow 新建一个meta 结构

func (*MarketDepthRow) CreateRow

func (m *MarketDepthRow) CreateRow() *table.Row

CreateRow 新建数据行(注意index 数据一定也要保存到数据中,不能就保存eventid)

func (*MarketDepthRow) Get

func (m *MarketDepthRow) Get(key string) ([]byte, error)

Get 按照indexName 查询 indexValue

func (*MarketDepthRow) SetPayload

func (m *MarketDepthRow) SetPayload(data types.Message) error

SetPayload 设置数据

type NftAccount

type NftAccount struct {
	AccountInfo
	// contains filtered or unexported fields
}

support nft asset from evm contract

func (*NftAccount) CheckBalance

func (acc *NftAccount) CheckBalance(amount int64) error

func (*NftAccount) Frozen

func (acc *NftAccount) Frozen(amount int64) (*types.Receipt, error)

func (*NftAccount) GetAccountInfo

func (acc *NftAccount) GetAccountInfo() AccountInfo

func (*NftAccount) GetCoinPrecision

func (acc *NftAccount) GetCoinPrecision() int64

func (*NftAccount) Transfer

func (acc *NftAccount) Transfer(to AssetAccount, amount int64) (*types.Receipt, error)

func (*NftAccount) TransferFrozen

func (acc *NftAccount) TransferFrozen(to AssetAccount, amountt int64) (*types.Receipt, error)

func (*NftAccount) UnFrozen

func (acc *NftAccount) UnFrozen(amount int64) (*types.Receipt, error)

type Order

type Order struct {
	// contains filtered or unexported fields
}

func NewOrder

func NewOrder(order *et.SpotOrder, orderdb *orderSRepo) *Order

func PreCreateAssetLimitOrder

func PreCreateAssetLimitOrder(payload *et.SpotAssetLimitOrder) *Order

func PreCreateLimitOrder

func PreCreateLimitOrder(payload *et.SpotLimitOrder) *Order

func PreCreateNftOrder

func PreCreateNftOrder(payload *et.SpotNftOrder, ty int32) *Order

func PreCreateNftTakerOrder

func PreCreateNftTakerOrder(payload *et.SpotNftTakerOrder, ty int, order2 *Order) *Order

func (*Order) GetAsset

func (o *Order) GetAsset() (*et.ZkAsset, *et.ZkAsset)

func (*Order) GetOp

func (o *Order) GetOp() int32

func (*Order) GetPrice

func (o *Order) GetPrice() int64

func (*Order) GetZkOrder

func (o *Order) GetZkOrder() *et.ZkOrder

func (*Order) NeedToken

func (o *Order) NeedToken(precision int64) (uint64, int64)

buy 按最大量判断余额是否够 因为在吃单时, 价格是变动的, 所以实际锁定的量是会浮动的 实现上, 按最大量判断余额是否够, 在成交时, 按实际需要量扣除. 最后变成挂单时, 进行锁定

func (*Order) Revoke

func (o *Order) Revoke(blockTime int64, txhash []byte, txindex int) (*types.Receipt, error)

func (*Order) Traded

func (o *Order) Traded(matchDetail *et.MatchInfo, blocktime int64) ([]*types.ReceiptLog, []*types.KeyValue, error)

type OrderRow

type OrderRow struct {
	*et.SpotOrder
}

OrderRow table meta 结构

func NewOrderRow

func NewOrderRow() *OrderRow

NewOrderRow 新建一个meta 结构

func (*OrderRow) CreateRow

func (r *OrderRow) CreateRow() *table.Row

CreateRow ...

func (*OrderRow) Get

func (r *OrderRow) Get(key string) ([]byte, error)

Get 按照indexName 查询 indexValue

func (*OrderRow) SetPayload

func (r *OrderRow) SetPayload(data types.Message) error

SetPayload 设置数据

type Spot

type Spot struct {
	// contains filtered or unexported fields
}

func NewSpot

func NewSpot(e *drivers.DriverBase, tx *et.TxInfo, dbprefix et.DBprefix) (*Spot, error)

func (*Spot) CreateEvmxgoNftOrder

func (a *Spot) CreateEvmxgoNftOrder(fromaddr string, trader *SpotTrader, payload *et.SpotNftOrder, entrustAddr string) (*et.SpotOrder, error)

func (*Spot) CreateEvmxgoNftTakerOrder

func (a *Spot) CreateEvmxgoNftTakerOrder(fromaddr string, acc *SpotTrader, payload *et.SpotNftTakerOrder, entrustAddr string) (*et.SpotOrder, error)

func (*Spot) CreateNftOrder

func (a *Spot) CreateNftOrder(fromaddr string, trader *SpotTrader, payload *et.SpotNftOrder, entrustAddr string) (*et.SpotOrder, error)

func (*Spot) CreateNftTakerOrder

func (a *Spot) CreateNftTakerOrder(fromaddr string, acc *SpotTrader, payload *et.SpotNftTakerOrder, entrustAddr string) (*et.SpotOrder, error)

func (*Spot) CreateOrder

func (a *Spot) CreateOrder(acc *SpotTrader,
	or *et.SpotOrder, left, right *et.ZkAsset, entrustAddr string) (*et.SpotOrder, error)

func (*Spot) CreateOrder2

func (a *Spot) CreateOrder2(acc *SpotTrader,
	or *Order, entrustAddr string) (*Order, error)

func (*Spot) ExecLocal

func (a *Spot) ExecLocal(tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error)

execLocal ...

func (*Spot) GetIndex

func (a *Spot) GetIndex() int64

GetIndex get index

func (*Spot) GetSpotFee

func (a *Spot) GetSpotFee(fromaddr string, left, right *et.ZkAsset) (*SpotFee, error)

func (*Spot) LoadTrader

func (a *Spot) LoadTrader(fromaddr string, zkAccID uint64, buyAsset, sellAsset *et.ZkAsset) (*SpotTrader, error)

func (*Spot) MatchAssetLimitOrder

func (a *Spot) MatchAssetLimitOrder(taker *SpotTrader) (*types.Receipt, error)

func (*Spot) NftOrderMarked

func (a *Spot) NftOrderMarked(taker *SpotTrader) (*types.Receipt, error)

func (*Spot) NftOrderReceipt

func (a *Spot) NftOrderReceipt(order *Order, matches *et.ReceiptSpotMatch) (*types.Receipt, error)

func (*Spot) RevokeOrder

func (a *Spot) RevokeOrder(fromaddr string, payload *et.SpotRevokeOrder) (*types.Receipt, error)

func (*Spot) SetFeeAcc

func (a *Spot) SetFeeAcc(funcGetFeeAccount GetFeeAccount) error

func (*Spot) TradeNft

func (a *Spot) TradeNft(fromaddr string, payload *et.SpotNftTakerOrder, entrustAddr string, nftType int) (*types.Receipt, error)

type SpotFee

type SpotFee struct {
	Address string
	AccID   uint64
	// contains filtered or unexported fields
}

Spot Fee Account Fee Rate Fee Rate for trader(User)

type SpotTrader

type SpotTrader struct {
	AccID uint64
	// contains filtered or unexported fields
}

func (*SpotTrader) CheckTokenAmountForLimitOrder

func (s *SpotTrader) CheckTokenAmountForLimitOrder(tid uint64, total int64) error

func (*SpotTrader) FrozenForLimitOrder

func (s *SpotTrader) FrozenForLimitOrder(orderx *Order) (*types.Receipt, error)

func (*SpotTrader) GetAccout

func (s *SpotTrader) GetAccout() *AssetAccounts

func (*SpotTrader) GetOrder

func (s *SpotTrader) GetOrder() *Order

func (*SpotTrader) Trade

func (s *SpotTrader) Trade(maker *spotMaker) ([]*types.ReceiptLog, []*types.KeyValue, error)

type TokenAccount

type TokenAccount struct {
	AccountInfo
	// contains filtered or unexported fields
}

support go token from go contract

func (*TokenAccount) CheckBalance

func (acc *TokenAccount) CheckBalance(amount int64) error

func (*TokenAccount) Frozen

func (acc *TokenAccount) Frozen(amount int64) (*types.Receipt, error)

func (*TokenAccount) GetAccountInfo

func (acc *TokenAccount) GetAccountInfo() AccountInfo

func (*TokenAccount) GetCoinPrecision

func (acc *TokenAccount) GetCoinPrecision() int64

func (*TokenAccount) Transfer

func (acc *TokenAccount) Transfer(to AssetAccount, amount int64) (*types.Receipt, error)

func (*TokenAccount) TransferFrozen

func (acc *TokenAccount) TransferFrozen(to AssetAccount, amountt int64) (*types.Receipt, error)

func (*TokenAccount) UnFrozen

func (acc *TokenAccount) UnFrozen(amount int64) (*types.Receipt, error)

type TokenAccountRepo

type TokenAccountRepo struct {
	// contains filtered or unexported fields
}

func (*TokenAccountRepo) NewAccount

func (accdb *TokenAccountRepo) NewAccount(addr string, accid uint64, asset *et.ZkAsset) (*TokenAccount, error)

type ZkAccount

type ZkAccount struct {
	AccountInfo
	// contains filtered or unexported fields
}

func (*ZkAccount) CheckBalance

func (acc *ZkAccount) CheckBalance(amount int64) error

func (*ZkAccount) Frozen

func (acc *ZkAccount) Frozen(amount int64) (*types.Receipt, error)

func (*ZkAccount) GetAccountInfo

func (acc *ZkAccount) GetAccountInfo() AccountInfo

func (*ZkAccount) GetCoinPrecision

func (acc *ZkAccount) GetCoinPrecision() int64

func (*ZkAccount) Transfer

func (acc *ZkAccount) Transfer(to AssetAccount, amount int64) (*types.Receipt, error)

func (*ZkAccount) TransferFrozen

func (acc *ZkAccount) TransferFrozen(to AssetAccount, amount int64) (*types.Receipt, error)

func (*ZkAccount) UnFrozen

func (acc *ZkAccount) UnFrozen(amount int64) (*types.Receipt, error)

Jump to

Keyboard shortcuts

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