Skip to content

Commit ccddc9b

Browse files
radik878MatusKyseldavidtaikocha
authored
fix(relayer): correct recommended processing fees layers (#21252)
Co-authored-by: Matus Kysel <MatusKysel@users.noreply.github.com> Co-authored-by: David <david@taiko.xyz>
1 parent 620ee91 commit ccddc9b

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

packages/relayer/pkg/http/get_recommended_processing_fees.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ func (srv *Server) GetRecommendedProcessingFees(c echo.Context) error {
115115
for _, f := range feeTypes {
116116
fees = append(fees, fee{
117117
Type: f.String(),
118-
Amount: srv.getCost(uint64(f), destGasTipCap, destBaseFee, Layer1).String(),
119-
DestChainID: srcChainID.Uint64(),
118+
Amount: srv.getCost(uint64(f), destGasTipCap, destBaseFee, Layer2).String(),
119+
DestChainID: destChainID.Uint64(),
120120
GasLimit: strconv.Itoa(int(f)),
121121
})
122122

123123
fees = append(fees, fee{
124124
Type: f.String(),
125-
Amount: srv.getCost(uint64(f), srcGasTipCap, srcBaseFee, Layer2).String(),
126-
DestChainID: destChainID.Uint64(),
125+
Amount: srv.getCost(uint64(f), srcGasTipCap, srcBaseFee, Layer1).String(),
126+
DestChainID: srcChainID.Uint64(),
127127
GasLimit: strconv.Itoa(int(f)),
128128
})
129129
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package http
2+
3+
import (
4+
"math/big"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestGetCost_LayerBehaviour(t *testing.T) {
11+
srv := &Server{processingFeeMultiplier: 2.5}
12+
13+
gasLimit := uint64(10)
14+
gasTipCap := big.NewInt(1)
15+
baseFee := big.NewInt(2)
16+
17+
// Calculate base cost used by both branches: gasLimit * (gasTipCap + baseFee*2).
18+
baseCost := new(big.Int).Mul(
19+
new(big.Int).SetUint64(gasLimit),
20+
new(big.Int).Add(gasTipCap, new(big.Int).Mul(baseFee, big.NewInt(2))),
21+
)
22+
23+
gotLayer2 := srv.getCost(gasLimit, gasTipCap, baseFee, Layer2)
24+
gotLayer1 := srv.getCost(gasLimit, gasTipCap, baseFee, Layer1)
25+
26+
// For Layer2 we expect raw base cost without processingFeeMultiplier.
27+
assert.Equal(t, baseCost, gotLayer2)
28+
29+
// For Layer1 we expect base cost multiplied by processingFeeMultiplier.
30+
costRat := new(big.Rat).SetInt(baseCost)
31+
multiplierRat := new(big.Rat).SetFloat64(srv.processingFeeMultiplier)
32+
costRat.Mul(costRat, multiplierRat)
33+
expectedLayer1 := new(big.Int).Div(costRat.Num(), costRat.Denom())
34+
35+
assert.Equal(t, expectedLayer1, gotLayer1)
36+
}

0 commit comments

Comments
 (0)