XDCxlending

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	ErrNonceTooHigh = errors.New("nonce too high")
	ErrNonceTooLow  = errors.New("nonce too low")
)
View Source
var (
	ErrOrderNonceTooLow  = errors.New("OrderNonce too low")
	ErrOrderNonceTooHigh = errors.New("OrderNonce too high")
)

List of errors

Functions

func DoSettleBalance

func DoSettleBalance(coinbase common.Address, takerOrder, makerOrder *lendingstate.LendingItem, settleBalance *lendingstate.LendingSettleBalance, statedb *state.StateDB) error

func GetLendQuantity

func GetLendQuantity(takerSide string, collateralTokenDecimal *big.Int, depositRate *big.Int, collateralPrice *big.Int, takerBalance *big.Int, makerBalance *big.Int, quantityToLend *big.Int) (*big.Int, bool)

Types

type Lending

type Lending struct {
	Triegc     *prque.Prque          // Priority queue mapping block numbers to tries to gc
	StateCache lendingstate.Database // State database to reuse between imports (contains state cache)    *lendingstate.TradingStateDB

	XDCx *XDCx.XDCX
	// contains filtered or unexported fields
}

func New

func New(XDCx *XDCx.XDCX) *Lending

func (*Lending) APIs

func (l *Lending) APIs() []rpc.API

APIs returns the RPC descriptors the Lending implementation offers

func (*Lending) ApplyOrder

func (l *Lending) ApplyOrder(header *types.Header, coinbase common.Address, chain consensus.ChainContext, statedb *state.StateDB, lendingStateDB *lendingstate.LendingStateDB, tradingStateDb *tradingstate.TradingStateDB, lendingOrderBook common.Hash, order *lendingstate.LendingItem) ([]*lendingstate.LendingTrade, []*lendingstate.LendingItem, error)

func (*Lending) AutoTopUp

func (l *Lending) AutoTopUp(statedb *state.StateDB, tradingState *tradingstate.TradingStateDB, lendingState *lendingstate.LendingStateDB, lendingBook, lendingTradeId common.Hash, currentPrice *big.Int) (*lendingstate.LendingTrade, error)

func (*Lending) CommitOrder

func (l *Lending) CommitOrder(header *types.Header, coinbase common.Address, chain consensus.ChainContext, statedb *state.StateDB, lendingStateDB *lendingstate.LendingStateDB, tradingStateDb *tradingstate.TradingStateDB, lendingOrderBook common.Hash, order *lendingstate.LendingItem) ([]*lendingstate.LendingTrade, []*lendingstate.LendingItem, error)

func (*Lending) GetCollateralPrices

func (l *Lending) GetCollateralPrices(header *types.Header, chain consensus.ChainContext, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, collateralToken common.Address, lendingToken common.Address) (*big.Int, *big.Int, error)

LendToken and CollateralToken must meet at least one of following conditions - Have direct pair in XDCX: lendToken/CollateralToken or CollateralToken/LendToken - Have pairs with XDC: - lendToken/XDC and CollateralToken/XDC - XDC/lendToken and XDC/CollateralToken

func (*Lending) GetLendingState

func (l *Lending) GetLendingState(block *types.Block, author common.Address) (*lendingstate.LendingStateDB, error)

func (*Lending) GetLendingStateRoot

func (l *Lending) GetLendingStateRoot(block *types.Block, author common.Address) (common.Hash, error)

func (*Lending) GetLevelDB

func (l *Lending) GetLevelDB() XDCxDAO.XDCXDAO

func (*Lending) GetMediumTradePriceBeforeEpoch

func (l *Lending) GetMediumTradePriceBeforeEpoch(chain consensus.ChainContext, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, baseToken common.Address, quoteToken common.Address) (*big.Int, error)

func (*Lending) GetMongoDB

func (l *Lending) GetMongoDB() XDCxDAO.XDCXDAO

func (*Lending) GetStateCache

func (l *Lending) GetStateCache() lendingstate.Database

func (*Lending) GetTriegc

func (l *Lending) GetTriegc() *prque.Prque

func (*Lending) GetXDCBasePrices

func (l *Lending) GetXDCBasePrices(header *types.Header, chain consensus.ChainContext, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, token common.Address) (*big.Int, error)

func (*Lending) HasLendingState

func (l *Lending) HasLendingState(block *types.Block, author common.Address) bool

func (*Lending) LiquidationExpiredTrade

func (l *Lending) LiquidationExpiredTrade(header *types.Header, chain consensus.ChainContext, lendingStateDB *lendingstate.LendingStateDB, statedb *state.StateDB, tradingstateDB *tradingstate.TradingStateDB, lendingBook common.Hash, lendingTradeId uint64) (*lendingstate.LendingTrade, error)

return liquidatedTrade

func (*Lending) LiquidationTrade

func (l *Lending) LiquidationTrade(lendingStateDB *lendingstate.LendingStateDB, statedb *state.StateDB, tradingstateDB *tradingstate.TradingStateDB, lendingBook common.Hash, lendingTradeId uint64) (*lendingstate.LendingTrade, error)

return liquidatedTrade

func (*Lending) ProcessCancelOrder

func (l *Lending) ProcessCancelOrder(header *types.Header, lendingStateDB *lendingstate.LendingStateDB, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, chain consensus.ChainContext, coinbase common.Address, lendingOrderBook common.Hash, order *lendingstate.LendingItem) (error, bool)

func (*Lending) ProcessLiquidationData

func (l *Lending) ProcessLiquidationData(header *types.Header, chain consensus.ChainContext, statedb *state.StateDB, tradingState *tradingstate.TradingStateDB, lendingState *lendingstate.LendingStateDB) (updatedTrades map[common.Hash]*lendingstate.LendingTrade, liquidatedTrades, autoRepayTrades, autoTopUpTrades, autoRecallTrades []*lendingstate.LendingTrade, err error)

func (*Lending) ProcessOrderPending

func (l *Lending) ProcessOrderPending(header *types.Header, coinbase common.Address, chain consensus.ChainContext, pending map[common.Address]types.LendingTransactions, statedb *state.StateDB, lendingStatedb *lendingstate.LendingStateDB, tradingStateDb *tradingstate.TradingStateDB) ([]*lendingstate.LendingItem, map[common.Hash]lendingstate.MatchingResult)

func (*Lending) ProcessRecallLendingTrade

func (l *Lending) ProcessRecallLendingTrade(lendingStateDB *lendingstate.LendingStateDB, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, lendingBook common.Hash, lendingTradeId common.Hash, newLiquidationPrice *big.Int) (error, bool, *lendingstate.LendingTrade)

func (*Lending) ProcessRepay

func (l *Lending) ProcessRepay(header *types.Header, chain consensus.ChainContext, lendingStateDB *lendingstate.LendingStateDB, statedb *state.StateDB, tradingstateDB *tradingstate.TradingStateDB, lendingBook common.Hash, order *lendingstate.LendingItem) (trade *lendingstate.LendingTrade, err error)

return hash: hash of lendingTrade

func (*Lending) ProcessRepayLendingTrade

func (l *Lending) ProcessRepayLendingTrade(header *types.Header, chain consensus.ChainContext, lendingStateDB *lendingstate.LendingStateDB, statedb *state.StateDB, tradingstateDB *tradingstate.TradingStateDB, lendingBook common.Hash, lendingTradeId uint64) (trade *lendingstate.LendingTrade, err error)

func (*Lending) ProcessTopUp

func (l *Lending) ProcessTopUp(lendingStateDB *lendingstate.LendingStateDB, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, order *lendingstate.LendingItem) (error, bool, *lendingstate.LendingTrade)

func (*Lending) ProcessTopUpLendingTrade

func (l *Lending) ProcessTopUpLendingTrade(lendingStateDB *lendingstate.LendingStateDB, statedb *state.StateDB, tradingStateDb *tradingstate.TradingStateDB, lendingTradeId common.Hash, lendingBook common.Hash, quantity *big.Int) (error, bool, *lendingstate.LendingTrade)

func (*Lending) Protocols

func (l *Lending) Protocols() []p2p.Protocol

func (*Lending) RollbackLendingData

func (l *Lending) RollbackLendingData(txhash common.Hash) error

func (*Lending) SaveData

func (l *Lending) SaveData()

func (*Lending) Start

func (l *Lending) Start(server *p2p.Server) error

func (*Lending) Stop

func (l *Lending) Stop() error

func (*Lending) SyncDataToSDKNode

func (l *Lending) SyncDataToSDKNode(chain consensus.ChainContext, statedb *state.StateDB, block *types.Block, takerLendingItem *lendingstate.LendingItem, txHash common.Hash, txMatchTime time.Time, trades []*lendingstate.LendingTrade, rejectedItems []*lendingstate.LendingItem, dirtyOrderCount *uint64) error

there are 3 tasks need to complete (for SDK nodes) after matching 1. Put takerLendingItem to database 2.a Update status, filledAmount of makerLendingItem 2.b. Put lendingTrade to database 3. Update status of rejected items

func (*Lending) UpdateLendingItemCache

func (l *Lending) UpdateLendingItemCache(LendingToken, CollateralToken common.Address, hash common.Hash, txhash common.Hash, lastState lendingstate.LendingItemHistoryItem)

func (*Lending) UpdateLendingTrade

func (l *Lending) UpdateLendingTrade(trades map[common.Hash]*lendingstate.LendingTrade, txhash common.Hash, txTime time.Time) error

func (*Lending) UpdateLendingTradeCache

func (l *Lending) UpdateLendingTradeCache(hash common.Hash, txhash common.Hash, lastState lendingstate.LendingTradeHistoryItem)

func (*Lending) UpdateLiquidatedTrade

func (l *Lending) UpdateLiquidatedTrade(blockTime uint64, result lendingstate.FinalizedResult, trades map[common.Hash]*lendingstate.LendingTrade) error

func (*Lending) Version

func (l *Lending) Version() uint64

Version returns the Lending sub-protocols version number.

type PublicXDCXLendingAPI

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

PublicXDCXLendingAPI provides the XDCX RPC service that can be use publicly without security implications.

func NewPublicXDCXLendingAPI

func NewPublicXDCXLendingAPI(t *Lending) *PublicXDCXLendingAPI

NewPublicXDCXLendingAPI create a new RPC XDCX service.

func (*PublicXDCXLendingAPI) Version

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

Version returns the Lending sub-protocol version.

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