Documentation ¶
Index ¶
- Constants
- Variables
- func CalculateShareAmount(token0Amount, token1Amount, amount0, amount1, poolPairShareAmount uint64) uint64
- func CombineReward(reward1 map[common.Hash]uint64, reward2 map[common.Hash]uint64) map[common.Hash]uint64
- func GetInscriptionTokenID(index uint64) common.Hash
- func GetPdexInstructions(instructions [][]string) map[uint][][]string
- func InitFullPoolPairStatesFromDB(stateDB *statedb.StateDB) (map[string]*PoolPairState, error)
- func InitIntermediatePoolPairStatesFromDB(stateDB *statedb.StateDB) (map[string]*PoolPairState, error)
- func InitLiquidityPoolPairStatesFromDB(stateDB *statedb.StateDB) (map[string]*PoolPairState, error)
- func InitNftIDsFromDB(stateDB *statedb.StateDB) (map[string]uint64, error)
- func InitPoolPairIDsFromDB(stateDB *statedb.StateDB) ([]string, error)
- func InitPoolPairOrderRewards(stateDB *statedb.StateDB, poolPairID string) (map[string]*OrderReward, error)
- func InitPoolPairShares(stateDB *statedb.StateDB, poolPairID string) (map[string]*Share, error)
- func InitStakingPoolsFromDB(stateDB *statedb.StateDB) (map[string]*StakingPoolState, error)
- func InitStateV2FromDBWithoutNftIDs(stateDB *statedb.StateDB, beaconHeight uint64) (*stateV2, error)
- func InitStatesFromDB(stateDB *statedb.StateDB, beaconHeight uint64) (map[uint]State, error)
- func InitWaitingContributionsFromDB(stateDB *statedb.StateDB) (map[string]rawdbv2.Pdexv3Contribution, error)
- func NewContributionWithMetaData(metaData metadataPdexv3.AddLiquidityRequest, txReqID common.Hash, shardID byte) *rawdbv2.Pdexv3Contribution
- func NewStatev2() *stateV2
- func TradePathFromState(sellToken common.Hash, tradePath []string, pairs map[string]*PoolPairState) ([]*rawdbv2.Pdexv3PoolPair, []map[common.Hash]*big.Int, ...)
- type MakingVolume
- type Order
- type OrderReward
- func (orderReward *OrderReward) AddReward(tokenID common.Hash, amount uint64)
- func (orderReward *OrderReward) Clone() *OrderReward
- func (orderReward *OrderReward) MarshalJSON() ([]byte, error)
- func (orderReward *OrderReward) UncollectedRewards() Reward
- func (orderReward *OrderReward) UnmarshalJSON(data []byte) error
- type Orderbook
- func (ob *Orderbook) Clone() Orderbook
- func (ob *Orderbook) InsertOrder(ord *Order)
- func (ob Orderbook) MarshalJSON() ([]byte, error)
- func (ob *Orderbook) NextOrder(tradeDirection byte) (*v2.MatchingOrder, string, error)
- func (ob *Orderbook) NftIDs() map[string]string
- func (ob *Orderbook) RemoveOrder(index int) error
- func (ob *Orderbook) UnmarshalJSON(data []byte) error
- type PDEXLogger
- type Params
- type PoolPairState
- func (p *PoolPairState) Clone() *PoolPairState
- func (poolPairState *PoolPairState) LmLockedShare() map[string]map[uint64]uint64
- func (poolPairState *PoolPairState) LmRewardsPerShare() map[common.Hash]*big.Int
- func (poolPairState *PoolPairState) LpFeesPerShare() map[common.Hash]*big.Int
- func (poolPairState *PoolPairState) MarshalJSON() ([]byte, error)
- func (poolPairState *PoolPairState) OrderRewards() map[string]*OrderReward
- func (poolPairState *PoolPairState) ProtocolFees() map[common.Hash]uint64
- func (p *PoolPairState) RecomputeLPRewards(nftID common.Hash) (map[common.Hash]uint64, error)
- func (poolPairState *PoolPairState) Shares() map[string]*Share
- func (poolPairState *PoolPairState) StakingPoolFees() map[common.Hash]uint64
- func (poolPairState *PoolPairState) State() rawdbv2.Pdexv3PoolPair
- func (poolPairState *PoolPairState) UnmarshalJSON(data []byte) error
- type Reward
- type Share
- func (share *Share) Amount() uint64
- func (share *Share) Clone() *Share
- func (share *Share) LastLPFeesPerShare() map[common.Hash]*big.Int
- func (share *Share) LastLmRewardsPerShare() map[common.Hash]*big.Int
- func (share *Share) LmLockedShareAmount() uint64
- func (share *Share) MarshalJSON() ([]byte, error)
- func (share *Share) TradingFees() map[common.Hash]uint64
- func (share *Share) UnmarshalJSON(data []byte) error
- type Staker
- func (staker *Staker) Clone() *Staker
- func (staker *Staker) LastRewardsPerShare() map[common.Hash]*big.Int
- func (staker *Staker) Liquidity() uint64
- func (staker *Staker) MarshalJSON() ([]byte, error)
- func (staker *Staker) Rewards() map[common.Hash]uint64
- func (staker *Staker) UnmarshalJSON(data []byte) error
- type StakingPoolState
- func (s *StakingPoolState) AddReward(tokenID common.Hash, amount uint64)
- func (s *StakingPoolState) Clone() *StakingPoolState
- func (stakingPoolState *StakingPoolState) Liquidity() uint64
- func (stakingPoolState *StakingPoolState) MarshalJSON() ([]byte, error)
- func (s *StakingPoolState) RecomputeStakingRewards(nftID common.Hash) (map[common.Hash]uint64, error)
- func (stakingPoolState *StakingPoolState) RewardsPerShare() map[common.Hash]*big.Int
- func (stakingPoolState *StakingPoolState) SetRewardsPerShare(rewardsPerShare map[common.Hash]*big.Int)
- func (stakingPoolState *StakingPoolState) Stakers() map[string]*Staker
- func (stakingPoolState *StakingPoolState) UnmarshalJSON(data []byte) error
- type State
- type StateChange
- type StateEnvBuilder
- type StateEnvironment
- type StateReader
- type StateValidator
- type TxBuilderV1
- type TxBuilderV2
Constants ¶
View Source
const ( BasicVersion = iota + 1 AmplifierVersion )
View Source
const ( MaxFeeRateBPS = 200 MaxPRVDiscountPercent = 75 )
params
View Source
const ( MintingBlockReward = 45000000 // without multiply with denominating rate MintingBlocks = 3600 * 24 * 30 * 60 / 40 // 60 months DecayIntervals = 30 DecayRateBPS = 500 // 5% )
PDEX token
View Source
const (
BPS = 10000
)
common
Variables ¶
View Source
var ( INSCRIPTIONS_FEATURE = "inscriptions" TotalPDEXReward = MintingBlockReward * math.Pow(10, common.PDEXDenominatingDecimal) DecayRate = float64(DecayRateBPS) / float64(BPS) PDEXRewardFirstInterval = uint64(TotalPDEXReward * DecayRate / (1 - math.Pow(1-DecayRate, DecayIntervals))) )
nft hash prefix
View Source
var Logger = PDEXLogger{}
Global instant to use
Functions ¶
func CalculateShareAmount ¶
func CombineReward ¶
func GetInscriptionTokenID ¶
func GetPdexInstructions ¶
func InitFullPoolPairStatesFromDB ¶
func InitFullPoolPairStatesFromDB(stateDB *statedb.StateDB) (map[string]*PoolPairState, error)
func InitIntermediatePoolPairStatesFromDB ¶
func InitIntermediatePoolPairStatesFromDB(stateDB *statedb.StateDB) (map[string]*PoolPairState, error)
func InitLiquidityPoolPairStatesFromDB ¶
func InitLiquidityPoolPairStatesFromDB(stateDB *statedb.StateDB) (map[string]*PoolPairState, error)
func InitPoolPairShares ¶
func InitStakingPoolsFromDB ¶
func InitStakingPoolsFromDB(stateDB *statedb.StateDB) (map[string]*StakingPoolState, error)
func InitStatesFromDB ¶
func NewContributionWithMetaData ¶
func NewContributionWithMetaData( metaData metadataPdexv3.AddLiquidityRequest, txReqID common.Hash, shardID byte, ) *rawdbv2.Pdexv3Contribution
func NewStatev2 ¶
func NewStatev2() *stateV2
func TradePathFromState ¶
func TradePathFromState( sellToken common.Hash, tradePath []string, pairs map[string]*PoolPairState, ) ( []*rawdbv2.Pdexv3PoolPair, []map[common.Hash]*big.Int, []map[common.Hash]uint64, []map[common.Hash]uint64, []v2.OrderBookIterator, []byte, common.Hash, error, )
TradePathFromState() prepares a trade path with reserves, orderbooks & directions. It returns cloned data only. State changes (if any) must be applied separately.
Types ¶
type MakingVolume ¶
type MakingVolume struct {
// contains filtered or unexported fields
}
func NewMakingVolume ¶
func NewMakingVolume() *MakingVolume
func (*MakingVolume) AddVolume ¶
func (makingVolume *MakingVolume) AddVolume(nftID string, amount *big.Int)
func (*MakingVolume) Clone ¶
func (makingVolume *MakingVolume) Clone() *MakingVolume
func (*MakingVolume) MarshalJSON ¶
func (makingVolume *MakingVolume) MarshalJSON() ([]byte, error)
func (*MakingVolume) UnmarshalJSON ¶
func (makingVolume *MakingVolume) UnmarshalJSON(data []byte) error
type Order ¶
type Order = rawdbv2.Pdexv3Order
type OrderReward ¶
type OrderReward struct {
// contains filtered or unexported fields
}
func NewOrderReward ¶
func NewOrderReward() *OrderReward
func (*OrderReward) AddReward ¶
func (orderReward *OrderReward) AddReward(tokenID common.Hash, amount uint64)
func (*OrderReward) Clone ¶
func (orderReward *OrderReward) Clone() *OrderReward
func (*OrderReward) MarshalJSON ¶
func (orderReward *OrderReward) MarshalJSON() ([]byte, error)
func (*OrderReward) UncollectedRewards ¶
func (orderReward *OrderReward) UncollectedRewards() Reward
func (*OrderReward) UnmarshalJSON ¶
func (orderReward *OrderReward) UnmarshalJSON(data []byte) error
type Orderbook ¶
type Orderbook struct {
// contains filtered or unexported fields
}
func InitPoolPairOrders ¶
func (*Orderbook) InsertOrder ¶
InsertOrder() appends a new order while keeping the list sorted (ascending by Token1Rate / Token0Rate)
func (Orderbook) MarshalJSON ¶
func (*Orderbook) NextOrder ¶
NextOrder() returns the matchable order with the best rate that has any outstanding balance to sell
func (*Orderbook) RemoveOrder ¶
RemoveOrder() removes one order by its index
func (*Orderbook) UnmarshalJSON ¶
type PDEXLogger ¶
type PDEXLogger struct {
// contains filtered or unexported fields
}
func (*PDEXLogger) Init ¶
func (pDEXLogger *PDEXLogger) Init(logger common.Logger)
type Params ¶
type Params struct { DefaultFeeRateBPS uint // the default value if fee rate is not specific in FeeRateBPS (default 0.3% ~ 30 BPS) FeeRateBPS map[string]uint // map: pool ID -> fee rate (0.1% ~ 10 BPS) PRVDiscountPercent uint // percent of fee that will be discounted if using PRV as the trading token fee (default: 25%) TradingProtocolFeePercent uint // percent of fees that is rewarded for the core team (default: 0%) TradingStakingPoolRewardPercent uint // percent of fees that is distributed for staking pools (PRV, PDEX, ..., default: 10%) StakingRewardTokens []common.Hash // list of staking reward tokens MintNftRequireAmount uint64 // amount prv for depositing to pdex MaxOrdersPerNft uint // max orders per nft AutoWithdrawOrderLimitAmount uint // max orders will be auto withdraw each shard for each blocks MinPRVReserveTradingRate uint64 // min prv reserve for checking price of trading fee paid by PRV DefaultOrderTradingRewardRatioBPS uint // default order trading reward ratio BPS OrderTradingRewardRatioBPS map[string]uint // map: pool ID -> the weight of LOP rewards compared with LP rewards (0.1% ~ 10 BPS) OrderLiquidityMiningBPS map[string]uint // map: pool ID -> order liquidity mining BPS (1500 BPS -> the percent of reward for AMM : buy orders : sell orders will be 70% : 15% : 15%) DAOContributingPercent uint // percent of DAO reward that is using for liquidity mining (default: 0%) MiningRewardPendingBlocks uint64 // liquidity mining reward of each contribution will be pending for this number of blocks (default: 0) OrderMiningRewardRatioBPS map[string]uint // not used yet }
func NewParamsWithValue ¶
func NewParamsWithValue(paramsState *statedb.Pdexv3Params) *Params
func (*Params) IsZeroValue ¶
type PoolPairState ¶
type PoolPairState struct {
// contains filtered or unexported fields
}
func InitPoolPair ¶
func InitPoolPair(stateDB *statedb.StateDB, poolPairID string) (*PoolPairState, error)
func NewPoolPairState ¶
func NewPoolPairState() *PoolPairState
func NewPoolPairStateWithValue ¶
func NewPoolPairStateWithValue( state rawdbv2.Pdexv3PoolPair, shares map[string]*Share, orderbook Orderbook, lpFeesPerShare, lmRewardsPerShare map[common.Hash]*big.Int, protocolFees, stakingPoolFees map[common.Hash]uint64, makingVolume map[common.Hash]*MakingVolume, orderRewards map[string]*OrderReward, lmLockedShare map[string]map[uint64]uint64, ) *PoolPairState
func (*PoolPairState) Clone ¶
func (p *PoolPairState) Clone() *PoolPairState
func (*PoolPairState) LmLockedShare ¶
func (poolPairState *PoolPairState) LmLockedShare() map[string]map[uint64]uint64
func (*PoolPairState) LmRewardsPerShare ¶
func (poolPairState *PoolPairState) LmRewardsPerShare() map[common.Hash]*big.Int
func (*PoolPairState) LpFeesPerShare ¶
func (poolPairState *PoolPairState) LpFeesPerShare() map[common.Hash]*big.Int
func (*PoolPairState) MarshalJSON ¶
func (poolPairState *PoolPairState) MarshalJSON() ([]byte, error)
func (*PoolPairState) OrderRewards ¶
func (poolPairState *PoolPairState) OrderRewards() map[string]*OrderReward
func (*PoolPairState) ProtocolFees ¶
func (poolPairState *PoolPairState) ProtocolFees() map[common.Hash]uint64
func (*PoolPairState) RecomputeLPRewards ¶
func (*PoolPairState) Shares ¶
func (poolPairState *PoolPairState) Shares() map[string]*Share
func (*PoolPairState) StakingPoolFees ¶
func (poolPairState *PoolPairState) StakingPoolFees() map[common.Hash]uint64
func (*PoolPairState) State ¶
func (poolPairState *PoolPairState) State() rawdbv2.Pdexv3PoolPair
func (*PoolPairState) UnmarshalJSON ¶
func (poolPairState *PoolPairState) UnmarshalJSON(data []byte) error
type Share ¶
type Share struct {
// contains filtered or unexported fields
}
func NewShareWithValue ¶
func (*Share) LastLPFeesPerShare ¶
func (*Share) LastLmRewardsPerShare ¶
func (*Share) LmLockedShareAmount ¶
func (*Share) MarshalJSON ¶
func (*Share) UnmarshalJSON ¶
type Staker ¶
type Staker struct {
// contains filtered or unexported fields
}
func NewStakerWithValue ¶
func (*Staker) LastRewardsPerShare ¶
func (*Staker) MarshalJSON ¶
func (*Staker) UnmarshalJSON ¶
type StakingPoolState ¶
type StakingPoolState struct {
// contains filtered or unexported fields
}
func InitStakingPoolFromDB ¶
func InitStakingPoolFromDB(stateDB *statedb.StateDB, stakingPoolID string) (*StakingPoolState, error)
func NewStakingPoolState ¶
func NewStakingPoolState() *StakingPoolState
func (*StakingPoolState) AddReward ¶
func (s *StakingPoolState) AddReward( tokenID common.Hash, amount uint64, )
func (*StakingPoolState) Clone ¶
func (s *StakingPoolState) Clone() *StakingPoolState
func (*StakingPoolState) Liquidity ¶
func (stakingPoolState *StakingPoolState) Liquidity() uint64
func (*StakingPoolState) MarshalJSON ¶
func (stakingPoolState *StakingPoolState) MarshalJSON() ([]byte, error)
func (*StakingPoolState) RecomputeStakingRewards ¶
func (*StakingPoolState) RewardsPerShare ¶
func (stakingPoolState *StakingPoolState) RewardsPerShare() map[common.Hash]*big.Int
func (*StakingPoolState) SetRewardsPerShare ¶
func (stakingPoolState *StakingPoolState) SetRewardsPerShare(rewardsPerShare map[common.Hash]*big.Int)
func (*StakingPoolState) Stakers ¶
func (stakingPoolState *StakingPoolState) Stakers() map[string]*Staker
func (*StakingPoolState) UnmarshalJSON ¶
func (stakingPoolState *StakingPoolState) UnmarshalJSON(data []byte) error
type State ¶
type State interface { Version() uint Clone() State Process(StateEnvironment) error StoreToDB(StateEnvironment, *StateChange) error BuildInstructions(StateEnvironment) ([][]string, error) TransformKeyWithNewBeaconHeight(beaconHeight uint64) ClearCache() GetDiff(State, *StateChange) (State, *StateChange, error) Reader() StateReader Validator() StateValidator }
func InitStateFromDB ¶
type StateChange ¶
type StateChange = v2.StateChange
func NewStateChange ¶
func NewStateChange() *StateChange
type StateEnvBuilder ¶
type StateEnvBuilder interface { BuildContributionActions([][]string) StateEnvBuilder BuildPRVRequiredContributionActions([][]string) StateEnvBuilder BuildTradeActions([][]string) StateEnvBuilder BuildCrossPoolTradeActions([][]string) StateEnvBuilder BuildWithdrawalActions([][]string) StateEnvBuilder BuildFeeWithdrawalActions([][]string) StateEnvBuilder BuildPrevBeaconHeight(uint64) StateEnvBuilder BuildListTxs(map[byte][]metadata.Transaction) StateEnvBuilder BuildBeaconInstructions([][]string) StateEnvBuilder BuildStateDB(*statedb.StateDB) StateEnvBuilder BuildBCHeightBreakPointPrivacyV2(uint64) StateEnvBuilder BuildPdexv3BreakPoint(uint64) StateEnvBuilder BuildReward(uint64) StateEnvBuilder BuildIsInscriptionFeatureEnabled(bool) StateEnvBuilder Build() StateEnvironment }
func NewStateEnvBuilder ¶
func NewStateEnvBuilder() StateEnvBuilder
type StateEnvironment ¶
type StateEnvironment interface { ContributionActions() [][]string PRVRequiredContributionActions() [][]string TradeActions() [][]string CrossPoolTradeActions() [][]string WithdrawalActions() [][]string FeeWithdrawalActions() [][]string PrevBeaconHeight() uint64 BeaconInstructions() [][]string ListTxs() map[byte][]metadata.Transaction StateDB() *statedb.StateDB BCHeightBreakPointPrivacyV2() uint64 Pdexv3BreakPoint() uint64 Reward() uint64 IsInscriptionFeatureEnabled() bool }
type StateReader ¶
type StateValidator ¶
type TxBuilderV1 ¶
type TxBuilderV1 struct { }
func (*TxBuilderV1) Build ¶
func (txBuilder *TxBuilderV1) Build( metaType int, inst []string, producerPrivateKey *privacy.PrivateKey, shardID byte, transactionStateDB *statedb.StateDB, ) (metadata.Transaction, error)
type TxBuilderV2 ¶
type TxBuilderV2 struct { }
func (*TxBuilderV2) Build ¶
func (txBuilder *TxBuilderV2) Build( metaType int, inst []string, producerPrivateKey *privacy.PrivateKey, shardID byte, transactionStateDB *statedb.StateDB, beaconHeight uint64, ) (metadata.Transaction, error)
Source Files ¶
- constants.go
- env.go
- interface.go
- log.go
- order_book.go
- params.go
- pool_pair_state.go
- staking_pool_state.go
- state_base.go
- state_processor_base.go
- state_processor_v1.go
- state_processor_v2.go
- state_producer_base.go
- state_producer_v1.go
- state_producer_v2.go
- state_v1.go
- state_v2.go
- state_v2_utils.go
- statedb.go
- tx_builder_v1.go
- tx_builder_v2.go
- utils.go
Click to show internal directories.
Click to hide internal directories.