Update gasprice.go

fix the percentile for price result in slice
This commit is contained in:
Matt Wang 2025-04-13 13:52:26 +08:00 committed by GitHub
parent 80753ba147
commit 6254333cc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -219,7 +219,12 @@ func (oracle *Oracle) SuggestTipCap(ctx context.Context) (*big.Int, error) {
price := lastPrice price := lastPrice
if len(results) > 0 { if len(results) > 0 {
slices.SortFunc(results, func(a, b *big.Int) int { return a.Cmp(b) }) slices.SortFunc(results, func(a, b *big.Int) int { return a.Cmp(b) })
price = results[(len(results)-1)*oracle.percentile/100] percentile := big.NewRat(int64(oracle.percentile), 100)
priceRat := new(big.Rat).Mul(
new(big.Rat).SetInt(results[(len(results)-1)]),
percentile,
)
price = new(big.Int).Div(priceRat.Num(), priceRat.Denom())
} }
if price.Cmp(oracle.maxPrice) > 0 { if price.Cmp(oracle.maxPrice) > 0 {
price = new(big.Int).Set(oracle.maxPrice) price = new(big.Int).Set(oracle.maxPrice)