github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/order/types/params.go (about) 1 package types 2 3 import ( 4 "fmt" 5 6 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 7 "github.com/fibonacci-chain/fbc/x/common" 8 "github.com/fibonacci-chain/fbc/x/params" 9 ) 10 11 // nolint 12 const ( 13 // System param 14 DefaultOrderExpireBlocks = 259200 // order will be expired after 86400 blocks. 15 DefaultMaxDealsPerBlock = 1000 // deals limit per block 16 17 // Fee param 18 DefaultFeeAmountPerBlock = "0" // fibo 19 DefaultFeeDenomPerBlock = common.NativeToken 20 DefaultFeeRateTrade = "0.001" // percentage 21 DefaultNewOrderMsgGasUnit = 40000 22 DefaultCancelOrderMsgGasUnit = 30000 23 ) 24 25 // nolint : Parameter keys 26 var ( 27 KeyOrderExpireBlocks = []byte("OrderExpireBlocks") 28 KeyMaxDealsPerBlock = []byte("MaxDealsPerBlock") 29 KeyFeePerBlock = []byte("FeePerBlock") 30 KeyTradeFeeRate = []byte("TradeFeeRate") 31 KeyNewOrderMsgGasUnit = []byte("NewOrderMsgGasUnit") 32 KeyCancelOrderMsgGasUnit = []byte("CancelOrderMsgGasUnit") 33 DefaultFeePerBlock = sdk.NewDecCoinFromDec(DefaultFeeDenomPerBlock, sdk.MustNewDecFromStr(DefaultFeeAmountPerBlock)) 34 ) 35 36 // nolint 37 var _ params.ParamSet = &Params{} 38 39 // nolint : order parameters 40 type Params struct { 41 OrderExpireBlocks int64 `json:"order_expire_blocks"` 42 MaxDealsPerBlock int64 `json:"max_deals_per_block"` 43 FeePerBlock sdk.SysCoin `json:"fee_per_block"` 44 TradeFeeRate sdk.Dec `json:"trade_fee_rate"` 45 NewOrderMsgGasUnit uint64 `json:"new_order_msg_gas_unit"` 46 CancelOrderMsgGasUnit uint64 `json:"cancel_order_msg_gas_unit"` 47 } 48 49 // ParamKeyTable for auth module 50 func ParamKeyTable() params.KeyTable { 51 return params.NewKeyTable().RegisterParamSet(&Params{}) 52 } 53 54 // TODO: to supplement the validate function for every pair of param 55 func validateParams(value interface{}) error { 56 return nil 57 } 58 59 // ParamSetPairs implements the ParamSet interface and returns all the key/value pairs 60 // pairs of auth module's parameters. 61 // nolint 62 func (p *Params) ParamSetPairs() params.ParamSetPairs { 63 return params.ParamSetPairs{ 64 {KeyOrderExpireBlocks, &p.OrderExpireBlocks, common.ValidateInt64Positive("order expire blocks")}, 65 {KeyMaxDealsPerBlock, &p.MaxDealsPerBlock, common.ValidateInt64Positive("max deals per block")}, 66 {KeyFeePerBlock, &p.FeePerBlock, common.ValidateSysCoin("fee per block")}, 67 {KeyTradeFeeRate, &p.TradeFeeRate, common.ValidateRateNotNeg("trade fee rate")}, 68 {KeyNewOrderMsgGasUnit, &p.NewOrderMsgGasUnit, common.ValidateUint64Positive("new order msg gas unit")}, 69 {KeyCancelOrderMsgGasUnit, &p.CancelOrderMsgGasUnit, common.ValidateUint64Positive("cancel order msg gas unit")}, 70 } 71 } 72 73 // DefaultParams returns a default set of parameters. 74 func DefaultParams() Params { 75 return Params{ 76 OrderExpireBlocks: DefaultOrderExpireBlocks, 77 MaxDealsPerBlock: DefaultMaxDealsPerBlock, 78 FeePerBlock: DefaultFeePerBlock, 79 TradeFeeRate: sdk.MustNewDecFromStr(DefaultFeeRateTrade), 80 NewOrderMsgGasUnit: DefaultNewOrderMsgGasUnit, 81 CancelOrderMsgGasUnit: DefaultCancelOrderMsgGasUnit, 82 } 83 } 84 85 // String implements the stringer interface. 86 func (p Params) String() string { 87 return fmt.Sprintf(`Order Params: 88 OrderExpireBlocks: %d 89 MaxDealsPerBlock: %d 90 FeePerBlock: %s 91 TradeFeeRate: %s 92 NewOrderMsgGasUnit: %d 93 CancelOrderMsgGasUnit: %d`, p.OrderExpireBlocks, 94 p.MaxDealsPerBlock, p.FeePerBlock, 95 p.TradeFeeRate, p.NewOrderMsgGasUnit, p.CancelOrderMsgGasUnit) 96 }