Documentation ¶
Index ¶
- Constants
- func BuildAcceptUnstakingInstructions(stakingPoolID, nftID common.Hash, unstakingAmount uint64, ...) ([][]string, error)
- func BuildAcceptWithdrawLiquidityInstructions(metaData metadataPdexv3.WithdrawLiquidityRequest, ...) ([][]string, error)
- func BuildDistributeMiningOrderRewardInsts(pairID string, makingTokenID common.Hash, mintingAmount uint64, ...) [][]string
- func BuildDistributeStakingRewardInst(stakingToken string, rewards map[common.Hash]uint64) [][]string
- func BuildMatchAddLiquidityInstructions(incomingContributionState statedb.Pdexv3ContributionState, poolPairID string, ...) ([][]string, error)
- func BuildMatchAndReturnAddLiquidityInstructions(...) ([][]string, error)
- func BuildMintBlockRewardInst(pairID string, mintingAmount uint64, mintingTokenID common.Hash) [][]string
- func BuildModifyParamsInst(params metadataPdexv3.Pdexv3Params, errorMsg string, shardID byte, ...) []string
- func BuildRefundAddLiquidityInstructions(...) ([][]string, error)
- func BuildRejectUnstakingInstructions(metaData metadataPdexv3.UnstakingRequest, txReqID common.Hash, shardID byte) ([][]string, error)
- func BuildRejectWithdrawLiquidityInstructions(metaData metadataPdexv3.WithdrawLiquidityRequest, txReqID common.Hash, ...) ([][]string, error)
- func BuildWithdrawLPFeeInsts(pairID string, nftID common.Hash, ...) [][]string
- func BuildWithdrawProtocolFeeInsts(pairID string, address string, amounts map[common.Hash]uint64, shardID byte, ...) [][]string
- func BuildWithdrawStakingRewardInsts(stakingPoolID string, nftID common.Hash, ...) [][]string
- func GetMakingVolumes(pairChange [2]*big.Int, orderChange map[string][2]*big.Int, ...) (*big.Int, map[string]*big.Int, byte)
- func GetPDEXRewardsForBlock(beaconHeight uint64, mintingBlocks int, decayIntervals int, ...) uint64
- func HasInsufficientLiquidity(poolPair rawdbv2.Pdexv3PoolPair) bool
- func MaybeAcceptTrade(amountIn, fee uint64, tradePath []string, receiver privacy.OTAReceiver, ...) (*metadataPdexv3.AcceptedTrade, []*rawdbv2.Pdexv3PoolPair, error)
- func MintPDEXGenesis(instStatus string, contentStr string, producerPrivateKey *privacy.PrivateKey, ...) (metadataCommon.Transaction, error)
- func OrderRefundTx(acn instructionPdexv3.Action, producerPrivateKey *privacy.PrivateKey, ...) (metadataCommon.Transaction, error)
- func SplitOrderRewardLiquidityMining(volume map[string]*big.Int, amount *big.Int, tokenID common.Hash) map[string]uint64
- func SplitTradingReward(reward *big.Int, ratio uint, bps uint, ammMakingAmt *big.Int, ...) (uint64, map[string]uint64)
- func TrackFee(fee uint64, feeInPRV bool, sellingTokenID common.Hash, baseLPPerShare *big.Int, ...) (*metadataPdexv3.AcceptedTrade, []map[string]map[common.Hash]uint64, ...)
- func TradeAcceptTx(acn instructionPdexv3.Action, producerPrivateKey *privacy.PrivateKey, ...) (metadataCommon.Transaction, error)
- func TradeRefundTx(acn instructionPdexv3.Action, producerPrivateKey *privacy.PrivateKey, ...) (metadataCommon.Transaction, error)
- func WithdrawLPFee(instStatus string, contentStr string, producerPrivateKey *privacy.PrivateKey, ...) (metadataCommon.Transaction, error)
- func WithdrawOrderAcceptTx(acn instructionPdexv3.Action, producerPrivateKey *privacy.PrivateKey, ...) (metadataCommon.Transaction, error)
- func WithdrawProtocolFee(instStatus string, contentStr string, producerPrivateKey *privacy.PrivateKey, ...) (metadataCommon.Transaction, error)
- func WithdrawStakingReward(instStatus string, contentStr string, producerPrivateKey *privacy.PrivateKey, ...) (metadataCommon.Transaction, error)
- type ContributionStatus
- type DifMapHashBigInt
- type DifMapHashUint64
- type DifMapStringBigInt
- type DifMapStringMapUint64Uint64
- type MakingVolumeChange
- type MatchingOrder
- func (order *MatchingOrder) ApplyBalanceChanges(change0, change1 *big.Int) error
- func (order MatchingOrder) BuyAmountFromOrder(incomingTradeSellAmount uint64, incomingTradeDirection byte) (uint64, error)
- func (order *MatchingOrder) CanMatch(incomingTradeDirection byte) (bool, error)
- func (order *MatchingOrder) Match(maxSellAmountAfterFee uint64, tradeDirection byte) (uint64, uint64, *big.Int, *big.Int, error)
- func (order *MatchingOrder) MatchPoolAmount(maxSellAmountAfterFee uint64, tradeDirection byte, pr TradingPair) (uint64, uint64, *big.Int, *big.Int, error)
- func (order MatchingOrder) SellAmountToOrder(incomingTradeBuyAmount uint64, incomingTradeDirection byte) (uint64, error)
- func (order *MatchingOrder) UnmarshalJSON(data []byte) error
- type MintNftStatus
- type OrderBookIterator
- type OrderRewardChange
- type PoolPairChange
- type ShareChange
- type StakerChange
- type StakingPoolChange
- type StakingStatus
- type StateChange
- type TradingPair
- func (tp *TradingPair) AddLMRewards(tokenID common.Hash, amount *big.Int, baseLPPerShare *big.Int, ...) map[common.Hash]*big.Int
- func (tp *TradingPair) AddLPFee(tokenID common.Hash, amount *big.Int, baseLPPerShare *big.Int, ...) map[common.Hash]*big.Int
- func (tp *TradingPair) AddStakingAndProtocolFee(tokenID common.Hash, amount *big.Int, ...) (map[common.Hash]uint64, map[common.Hash]uint64, *big.Int)
- func (tp TradingPair) AmountToSell(buyAmount uint64, tradeDirection byte) (uint64, error)
- func (tp *TradingPair) ApplyReserveChanges(change0, change1 *big.Int) error
- func (tp TradingPair) BuyAmount(sellAmount uint64, tradeDirection byte) (uint64, error)
- func (tp *TradingPair) SwapToReachOrderRate(maxSellAmountAfterFee uint64, tradeDirection byte, ord *MatchingOrder) (uint64, uint64, *big.Int, *big.Int, error)
- func (tp *TradingPair) UnmarshalJSON(data []byte) error
- type UnstakingStatus
- type WithdrawStatus
Constants ¶
const ( TradeDirectionSell0 = iota TradeDirectionSell1 )
Variables ¶
This section is empty.
Functions ¶
func BuildAcceptWithdrawLiquidityInstructions ¶
func BuildAcceptWithdrawLiquidityInstructions( metaData metadataPdexv3.WithdrawLiquidityRequest, token0ID, token1ID common.Hash, token0Amount, token1Amount, shareAmount uint64, txReqID common.Hash, shardID byte, ) ([][]string, error)
func BuildMatchAndReturnAddLiquidityInstructions ¶
func BuildMatchAndReturnAddLiquidityInstructions( token0ContributionState, token1ContributionState statedb.Pdexv3ContributionState, shareAmount, returnedToken0ContributionAmount, actualToken0ContributionAmount, returnedToken1ContributionAmount, actualToken1ContributionAmount uint64, nftID common.Hash, ) ([][]string, error)
func BuildModifyParamsInst ¶
func BuildModifyParamsInst( params metadataPdexv3.Pdexv3Params, errorMsg string, shardID byte, reqTxID common.Hash, status string, ) []string
func BuildRefundAddLiquidityInstructions ¶
func BuildRefundAddLiquidityInstructions( waitingContributionState, incomingContributionState statedb.Pdexv3ContributionState, ) ([][]string, error)
func BuildRejectUnstakingInstructions ¶
func BuildRejectUnstakingInstructions( metaData metadataPdexv3.UnstakingRequest, txReqID common.Hash, shardID byte, ) ([][]string, error)
func BuildRejectWithdrawLiquidityInstructions ¶
func BuildRejectWithdrawLiquidityInstructions( metaData metadataPdexv3.WithdrawLiquidityRequest, txReqID common.Hash, shardID byte, ) ([][]string, error)
func BuildWithdrawLPFeeInsts ¶
func GetMakingVolumes ¶
func GetPDEXRewardsForBlock ¶
func HasInsufficientLiquidity ¶
func HasInsufficientLiquidity(poolPair rawdbv2.Pdexv3PoolPair) bool
func MaybeAcceptTrade ¶
func MaybeAcceptTrade(amountIn, fee uint64, tradePath []string, receiver privacy.OTAReceiver, reserves []*rawdbv2.Pdexv3PoolPair, lpFeesPerShares []map[common.Hash]*big.Int, protocolFees, stakingPoolFees []map[common.Hash]uint64, tradeDirections []byte, tokenToBuy common.Hash, minAmount uint64, orderbooks []OrderBookIterator, ) (*metadataPdexv3.AcceptedTrade, []*rawdbv2.Pdexv3PoolPair, error)
MaybeAcceptTrade() performs a trade determined by input amount, path, directions & order book state. Upon success, state changes are applied in memory & collected in an instruction. A returned error means the trade is refunded
func MintPDEXGenesis ¶
func MintPDEXGenesis( instStatus string, contentStr string, producerPrivateKey *privacy.PrivateKey, shardID byte, transactionStateDB *statedb.StateDB, ) (metadataCommon.Transaction, error)
func OrderRefundTx ¶
func OrderRefundTx( acn instructionPdexv3.Action, producerPrivateKey *privacy.PrivateKey, shardID byte, transactionStateDB *statedb.StateDB, ) (metadataCommon.Transaction, error)
func SplitTradingReward ¶
func TrackFee ¶
func TrackFee( fee uint64, feeInPRV bool, sellingTokenID common.Hash, baseLPPerShare *big.Int, bps uint, tradePath []string, reserves []*rawdbv2.Pdexv3PoolPair, lpFeesPerShares []map[common.Hash]*big.Int, protocolFees, stakingPoolFees []map[common.Hash]uint64, tradeDirections []byte, orderbooks []OrderBookIterator, poolFees []uint, feeRateBPS uint, acceptedMeta *metadataPdexv3.AcceptedTrade, protocolFeePercent, stakingPoolRewardPercent uint, stakingRewardTokens []common.Hash, defaultOrderTradingRewardRatioBPS uint, orderTradingRewardRatioBPS map[string]uint, ) (*metadataPdexv3.AcceptedTrade, []map[string]map[common.Hash]uint64, []map[common.Hash]map[string]*big.Int, error)
func TradeAcceptTx ¶
func TradeAcceptTx( acn instructionPdexv3.Action, producerPrivateKey *privacy.PrivateKey, shardID byte, transactionStateDB *statedb.StateDB, ) (metadataCommon.Transaction, error)
func TradeRefundTx ¶
func TradeRefundTx( acn instructionPdexv3.Action, producerPrivateKey *privacy.PrivateKey, shardID byte, transactionStateDB *statedb.StateDB, ) (metadataCommon.Transaction, error)
func WithdrawLPFee ¶
func WithdrawLPFee( instStatus string, contentStr string, producerPrivateKey *privacy.PrivateKey, shardID byte, transactionStateDB *statedb.StateDB, ) (metadataCommon.Transaction, error)
func WithdrawOrderAcceptTx ¶
func WithdrawOrderAcceptTx( acn instructionPdexv3.Action, producerPrivateKey *privacy.PrivateKey, shardID byte, transactionStateDB *statedb.StateDB, ) (metadataCommon.Transaction, error)
func WithdrawProtocolFee ¶
func WithdrawProtocolFee( instStatus string, contentStr string, producerPrivateKey *privacy.PrivateKey, shardID byte, transactionStateDB *statedb.StateDB, ) (metadataCommon.Transaction, error)
func WithdrawStakingReward ¶
func WithdrawStakingReward( instStatus string, contentStr string, producerPrivateKey *privacy.PrivateKey, shardID byte, transactionStateDB *statedb.StateDB, ) (metadataCommon.Transaction, error)
Types ¶
type ContributionStatus ¶
type ContributionStatus struct { Status byte `json:"Status"` Token0ID string `json:"Token0ID"` Token0ContributedAmount uint64 `json:"Token0ContributedAmount"` Token0ReturnedAmount uint64 `json:"Token0ReturnedAmount"` Token1ID string `json:"Token1ID"` Token1ContributedAmount uint64 `json:"Token1ContributedAmount"` Token1ReturnedAmount uint64 `json:"Token1ReturnedAmount"` PoolPairID string `json:"PoolPairID"` }
type DifMapHashBigInt ¶
func (DifMapHashBigInt) GetDiff ¶
func (dm DifMapHashBigInt) GetDiff(compareWith DifMapHashBigInt) map[string]bool
type DifMapHashUint64 ¶
func (DifMapHashUint64) GetDiff ¶
func (dm DifMapHashUint64) GetDiff(compareWith DifMapHashUint64) map[string]bool
type DifMapStringBigInt ¶
func (DifMapStringBigInt) GetDiff ¶
func (dm DifMapStringBigInt) GetDiff(compareWith DifMapStringBigInt) map[string]bool
type DifMapStringMapUint64Uint64 ¶
func (DifMapStringMapUint64Uint64) GetDiff ¶
func (dm DifMapStringMapUint64Uint64) GetDiff(compareWith DifMapStringMapUint64Uint64) map[string]map[uint64]bool
type MakingVolumeChange ¶
func NewMakingVolumeChange ¶
func NewMakingVolumeChange() *MakingVolumeChange
type MatchingOrder ¶
type MatchingOrder struct {
*rawdbv2.Pdexv3Order
}
func (*MatchingOrder) ApplyBalanceChanges ¶
func (order *MatchingOrder) ApplyBalanceChanges(change0, change1 *big.Int) error
func (MatchingOrder) BuyAmountFromOrder ¶
func (order MatchingOrder) BuyAmountFromOrder(incomingTradeSellAmount uint64, incomingTradeDirection byte) (uint64, error)
BuyAmountFromOrder() computes the theoretical (by rate) output amount given incoming trade's sell amount. Order balance only needs to be non-zero since it can be partially matched
func (*MatchingOrder) CanMatch ¶
func (order *MatchingOrder) CanMatch(incomingTradeDirection byte) (bool, error)
CanMatch() returns true if - incoming trade is of opposite direction (sell0 vs sell1) - outstanding order balance is not too small (would exchange for at least 1 unit of TokenBuy using this order's own rate)
func (*MatchingOrder) Match ¶
func (order *MatchingOrder) Match(maxSellAmountAfterFee uint64, tradeDirection byte) (uint64, uint64, *big.Int, *big.Int, error)
Match() swaps this order's selling balance with token sold in a trade, following this order's rate
func (*MatchingOrder) MatchPoolAmount ¶
func (order *MatchingOrder) MatchPoolAmount(maxSellAmountAfterFee uint64, tradeDirection byte, pr TradingPair) (uint64, uint64, *big.Int, *big.Int, error)
MatchPoolAmount() uses pool values instead of this order's rate
func (MatchingOrder) SellAmountToOrder ¶
func (order MatchingOrder) SellAmountToOrder(incomingTradeBuyAmount uint64, incomingTradeDirection byte) (uint64, error)
func (*MatchingOrder) UnmarshalJSON ¶
func (order *MatchingOrder) UnmarshalJSON(data []byte) error
type MintNftStatus ¶
type OrderBookIterator ¶
type OrderRewardChange ¶
func NewOrderRewardChange ¶
func NewOrderRewardChange() *OrderRewardChange
type PoolPairChange ¶
type PoolPairChange struct { IsChanged bool OrderIDs map[string]bool ProtocolFees map[string]bool StakingPoolFees map[string]bool MakingVolume map[string]*MakingVolumeChange OrderRewards map[string]*OrderRewardChange }
func NewPoolPairChange ¶
func NewPoolPairChange() *PoolPairChange
type ShareChange ¶
type ShareChange struct {}
func NewShareChange ¶
func NewShareChange() *ShareChange
type StakerChange ¶
func NewStakerChange ¶
func NewStakerChange() *StakerChange
type StakingPoolChange ¶
type StakingPoolChange struct { Stakers map[string]*StakerChange }
func NewStakingChange ¶
func NewStakingChange() *StakingPoolChange
type StakingStatus ¶
type StateChange ¶
type StateChange struct { PoolPairs map[string]*PoolPairChange StakingPools map[string]*StakingPoolChange }
func NewStateChange ¶
func NewStateChange() *StateChange
type TradingPair ¶
type TradingPair struct {
*rawdbv2.Pdexv3PoolPair
}
func NewTradingPair ¶
func NewTradingPair() *TradingPair
func NewTradingPairWithValue ¶
func NewTradingPairWithValue( reserve *rawdbv2.Pdexv3PoolPair, ) *TradingPair
func (*TradingPair) AddLMRewards ¶
func (*TradingPair) AddStakingAndProtocolFee ¶
func (TradingPair) AmountToSell ¶
func (tp TradingPair) AmountToSell(buyAmount uint64, tradeDirection byte) (uint64, error)
BuyAmount() computes the input amount given output, based on reserve amounts
func (*TradingPair) ApplyReserveChanges ¶
func (tp *TradingPair) ApplyReserveChanges(change0, change1 *big.Int) error
func (TradingPair) BuyAmount ¶
func (tp TradingPair) BuyAmount(sellAmount uint64, tradeDirection byte) (uint64, error)
BuyAmount() computes the output amount given input, based on reserve amounts. Deduct fees before calling this
func (*TradingPair) SwapToReachOrderRate ¶
func (tp *TradingPair) SwapToReachOrderRate(maxSellAmountAfterFee uint64, tradeDirection byte, ord *MatchingOrder) (uint64, uint64, *big.Int, *big.Int, error)
SwapToReachOrderRate() does a *partial* swap using liquidity in the pool, such that the price afterwards does not exceed an order's rate It returns an error when the pool runs out of liquidity Upon success, it updates the reserve values and returns (buyAmount, sellAmountRemain, token0Change, token1Change)
func (*TradingPair) UnmarshalJSON ¶
func (tp *TradingPair) UnmarshalJSON(data []byte) error