mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-06 19:06:42 +01:00
Add minPriceUSD in L2DB, check maxTxs atomically
- Add config parameter `Coordinator.L2DB.MinPriceUSD` which allows rejecting txs to the pool that have a fee lower than the minimum. - In pool tx insertion, checking the number of pending txs atomically with the insertion to avoid data races leading to more than MaxTxs pending txs in the pool.
This commit is contained in:
@@ -62,3 +62,17 @@ func RmEndingZeroes(siblings []*merkletree.Hash) []*merkletree.Hash {
|
||||
}
|
||||
return siblings[:pos]
|
||||
}
|
||||
|
||||
// TokensToUSD is a helper function to calculate the USD value of a certain
|
||||
// amount of tokens considering the normalized token price (which is the price
|
||||
// commonly reported by exhanges)
|
||||
func TokensToUSD(amount *big.Int, decimals uint64, valueUSD float64) float64 {
|
||||
amountF := new(big.Float).SetInt(amount)
|
||||
// Divide by 10^decimals to normalize the amount
|
||||
baseF := new(big.Float).SetInt(new(big.Int).Exp(
|
||||
big.NewInt(10), big.NewInt(int64(decimals)), nil)) //nolint:gomnd
|
||||
amountF.Mul(amountF, big.NewFloat(valueUSD))
|
||||
amountF.Quo(amountF, baseF)
|
||||
amountUSD, _ := amountF.Float64()
|
||||
return amountUSD
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user