diff --git a/common/constants.go b/common/constants.go index c0d9004c67..9566b4bf42 100644 --- a/common/constants.go +++ b/common/constants.go @@ -77,6 +77,7 @@ var BaseTopUp = big.NewInt(100) var BaseRecall = big.NewInt(100) var TIPTRC21Fee = big.NewInt(38383838) var TIPTRC21FeeTestnet = big.NewInt(38383838) +var BlockNumberGas50x = big.NewInt(TIPTRC21Fee.Int64() + 30000000) var LimitTimeFinality = uint64(30) // limit in 30 block var IgnoreSignerCheckBlockArray = map[uint64]bool{ diff --git a/common/gas.go b/common/gas.go new file mode 100644 index 0000000000..a5b5690a76 --- /dev/null +++ b/common/gas.go @@ -0,0 +1,34 @@ +package common + +import "math/big" + +var MinGasPrice50x = big.NewInt(12500000000) +var GasPrice50x = big.NewInt(12500000000) + +func GetGasFee(blockNumber, gas uint64) *big.Int { + fee := new(big.Int).SetUint64(gas) + + if blockNumber >= BlockNumberGas50x.Uint64() { + fee = fee.Mul(fee, GasPrice50x) + } else if blockNumber > TIPTRC21Fee.Uint64() { + fee = fee.Mul(fee, TRC21GasPrice) + } + + return fee +} + +func GetGasPrice(number *big.Int) *big.Int { + if number == nil || number.Cmp(BlockNumberGas50x) < 0 { + return new(big.Int).Set(TRC21GasPrice) + } else { + return new(big.Int).Set(GasPrice50x) + } +} + +func GetMinGasPrice(number *big.Int) *big.Int { + if number == nil || number.Cmp(BlockNumberGas50x) < 0 { + return new(big.Int).Set(MinGasPrice) + } else { + return new(big.Int).Set(MinGasPrice50x) + } +}