sdxx

package
v0.0.0-...-7037f4e Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2021 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolName       = "sdxx"
	ProtocolVersion    = uint64(1)
	ProtocolVersionStr = "1.0"

	MaximumTxMatchSize = 1000
)
View Source
const (
	LimitThresholdOrderNonceInQueue = 100
)

Variables

View Source
var (
	ErrNoTopics          = errors.New("missing topic(s)")
	ErrOrderNonceTooLow  = errors.New("OrderNonce too low")
	ErrOrderNonceTooHigh = errors.New("OrderNonce too high")
)

List of errors

View Source
var (
	ErrNonceTooHigh = errors.New("nonce too high")
	ErrNonceTooLow  = errors.New("nonce too low")
)
View Source
var DefaultConfig = Config{
	DataDir: "",
}

DefaultConfig represents (shocker!) the default configuration.

Functions

func DoSettleBalance

func DoSettleBalance(coinbase common.Address, takerOrder, makerOrder *tradingstate.OrderItem, settleBalance *tradingstate.SettleBalance, statedb *state.StateDB) error

func GetTokenAbi

func GetTokenAbi() (*abi.ABI, error)

GetTokenAbi return token abi

func GetTradeQuantity

func GetTradeQuantity(takerSide string, takerFeeRate *big.Int, takerBalance *big.Int, makerPrice *big.Int, makerFeeRate *big.Int, makerBalance *big.Int, baseTokenDecimal *big.Int, quantityToTrade *big.Int) (*big.Int, bool)

func NewLDBEngine

func NewLDBEngine(cfg *Config) *sdxxDAO.BatchDatabase

func NewMongoDBEngine

func NewMongoDBEngine(cfg *Config) *sdxxDAO.MongoDatabase

func RunContract

func RunContract(chain consensus.ChainContext, statedb *state.StateDB, contractAddr common.Address, abi *abi.ABI, method string, args ...interface{}) (interface{}, error)

RunContract run smart contract

Types

type Config

type Config struct {
	DataDir        string `toml:",omitempty"`
	DBEngine       string `toml:",omitempty"`
	DBName         string `toml:",omitempty"`
	ConnectionUrl  string `toml:",omitempty"`
	ReplicaSetName string `toml:",omitempty"`
}

type PublicSdxXAPI

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

PublicSdxXAPI provides the sdxX RPC service that can be use publicly without security implications.

func NewPublicSdxXAPI

func NewPublicSdxXAPI(t *SdxX) *PublicSdxXAPI

NewPublicSdxXAPI create a new RPC sdxX service.

func (*PublicSdxXAPI) Version

func (api *PublicSdxXAPI) Version(ctx context.Context) string

Version returns the SdxX sub-protocol version.

type SdxX

type SdxX struct {
	Triegc     *prque.Prque          // Priority queue mapping block numbers to tries to gc
	StateCache tradingstate.Database // State database to reuse between imports (contains state cache)    *sdxx_state.TradingStateDB
	// contains filtered or unexported fields
}

func New

func New(cfg *Config) *SdxX

func (*SdxX) APIs

func (sdxx *SdxX) APIs() []rpc.API

APIs returns the RPC descriptors the SdxX implementation offers

func (*SdxX) ApplyOrder

func (sdxx *SdxX) ApplyOrder(header *types.Header, coinbase common.Address, chain consensus.ChainContext, statedb *state.StateDB, tradingStateDB *tradingstate.TradingStateDB, orderBook common.Hash, order *tradingstate.OrderItem) ([]map[string]string, []*tradingstate.OrderItem, error)

func (*SdxX) CommitOrder

func (sdxx *SdxX) CommitOrder(header *types.Header, coinbase common.Address, chain consensus.ChainContext, statedb *state.StateDB, tradingStateDB *tradingstate.TradingStateDB, orderBook common.Hash, order *tradingstate.OrderItem) ([]map[string]string, []*tradingstate.OrderItem, error)

func (*SdxX) ConvertSDXToToken

func (sdxx *SdxX) ConvertSDXToToken(chain consensus.ChainContext, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, token common.Address, quantity *big.Int) (*big.Int, *big.Int, error)

return tokenQuantity (after convert from SDX to token), tokenPriceInSDX, error

func (*SdxX) GetAveragePriceLastEpoch

func (sdxx *SdxX) GetAveragePriceLastEpoch(chain consensus.ChainContext, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, baseToken common.Address, quoteToken common.Address) (*big.Int, error)

return average price of the given pair in the last epoch

func (*SdxX) GetLevelDB

func (sdxx *SdxX) GetLevelDB() sdxxDAO.SdxXDAO

func (*SdxX) GetMongoDB

func (sdxx *SdxX) GetMongoDB() sdxxDAO.SdxXDAO

func (*SdxX) GetStateCache

func (sdxx *SdxX) GetStateCache() tradingstate.Database

func (*SdxX) GetTokenDecimal

func (sdxx *SdxX) GetTokenDecimal(chain consensus.ChainContext, statedb *state.StateDB, tokenAddr common.Address) (*big.Int, error)

func (*SdxX) GetTradingState

func (sdxx *SdxX) GetTradingState(block *types.Block, author common.Address) (*tradingstate.TradingStateDB, error)

func (*SdxX) GetTradingStateRoot

func (sdxx *SdxX) GetTradingStateRoot(block *types.Block, author common.Address) (common.Hash, error)

func (*SdxX) GetTriegc

func (sdxx *SdxX) GetTriegc() *prque.Prque

func (*SdxX) HasTradingState

func (sdxx *SdxX) HasTradingState(block *types.Block, author common.Address) bool

func (*SdxX) IsSDKNode

func (sdxx *SdxX) IsSDKNode() bool

func (*SdxX) LogEpochPrice

func (sdxx *SdxX) LogEpochPrice(epochNumber uint64, epochPriceResult map[common.Hash]*big.Int) error

put average price of epoch to mongodb for tracking liquidation trades epochPriceResult: a map of epoch average price, key is orderbook hash , value is epoch average price orderbook hash genereted from baseToken, quoteToken at sdxchain/sdxx/tradingstate/common.go:214

func (*SdxX) Overflow

func (sdxx *SdxX) Overflow() bool

Overflow returns an indication if the message queue is full.

func (*SdxX) ProcessCancelOrder

func (sdxx *SdxX) ProcessCancelOrder(header *types.Header, tradingStateDB *tradingstate.TradingStateDB, statedb *state.StateDB, chain consensus.ChainContext, coinbase common.Address, orderBook common.Hash, order *tradingstate.OrderItem) (error, bool)

func (*SdxX) ProcessOrderPending

func (sdxx *SdxX) ProcessOrderPending(header *types.Header, coinbase common.Address, chain consensus.ChainContext, pending map[common.Address]types.OrderTransactions, statedb *state.StateDB, sdxXstatedb *tradingstate.TradingStateDB) ([]tradingstate.TxDataMatch, map[common.Hash]tradingstate.MatchingResult)

func (*SdxX) Protocols

func (sdxx *SdxX) Protocols() []p2p.Protocol

func (*SdxX) RollbackReorgTxMatch

func (sdxx *SdxX) RollbackReorgTxMatch(txhash common.Hash) error

func (*SdxX) SaveData

func (sdxx *SdxX) SaveData()

func (*SdxX) SetTokenDecimal

func (sdxx *SdxX) SetTokenDecimal(token common.Address, decimal *big.Int)

FIXME: using in unit tests only

func (*SdxX) Start

func (sdxx *SdxX) Start(server *p2p.Server) error

func (*SdxX) Stop

func (sdxx *SdxX) Stop() error

func (*SdxX) SyncDataToSDKNode

func (sdxx *SdxX) SyncDataToSDKNode(takerOrderInTx *tradingstate.OrderItem, txHash common.Hash, txMatchTime time.Time, statedb *state.StateDB, trades []map[string]string, rejectedOrders []*tradingstate.OrderItem, dirtyOrderCount *uint64) error

there are 3 tasks need to complete to update data in SDK nodes after matching

  1. txMatchData.Order: order has been processed. This order should be put to `orders` collection with status sdktypes.OrderStatusOpen
  2. txMatchData.Trades: includes information of matched orders. a. PutObject them to `trades` collection b. Update status of regrading orders to sdktypes.OrderStatusFilled

func (*SdxX) UpdateMediumPriceBeforeEpoch

func (sdxx *SdxX) UpdateMediumPriceBeforeEpoch(epochNumber uint64, tradingStateDB *tradingstate.TradingStateDB, statedb *state.StateDB) error

func (*SdxX) UpdateOrderCache

func (sdxx *SdxX) UpdateOrderCache(baseToken, quoteToken common.Address, orderHash common.Hash, txhash common.Hash, lastState tradingstate.OrderHistoryItem)

func (*SdxX) Version

func (sdxx *SdxX) Version() uint64

Version returns the SdxX sub-protocols version number.

Directories

Path Synopsis
Package state provides a caching layer atop the Ethereum state trie.
Package state provides a caching layer atop the Ethereum state trie.

Jump to

Keyboard shortcuts

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