fix_: l1 fees at 0 and fix base fees sepolia

This commit is contained in:
Anthony Laibe 2024-07-04 13:30:22 +02:00 committed by Anthony Laibe
parent fc401bc8a7
commit abb570dd3f
3 changed files with 17 additions and 22 deletions

View File

@ -148,7 +148,6 @@ func (f *FeeManager) SuggestedFees(ctx context.Context, chainID uint64) (*Sugges
EIP1559Enabled: false, EIP1559Enabled: false,
}, nil }, nil
} }
baseFee, err := f.getBaseFee(ctx, backend) baseFee, err := f.getBaseFee(ctx, backend)
if err != nil { if err != nil {
return nil, err return nil, err
@ -190,19 +189,17 @@ func (f *FeeManager) getBaseFee(ctx context.Context, client chain.ClientInterfac
} }
chainID := client.NetworkID() chainID := client.NetworkID()
config := params.MainnetChainConfig config := params.MainnetChainConfig
switch chainID { switch chainID {
case common.EthereumSepolia: case common.EthereumSepolia,
case common.OptimismSepolia: common.OptimismSepolia,
case common.ArbitrumSepolia: common.ArbitrumSepolia:
config = params.SepoliaChainConfig config = params.SepoliaChainConfig
case common.EthereumGoerli: case common.EthereumGoerli,
case common.OptimismGoerli: common.OptimismGoerli,
case common.ArbitrumGoerli: common.ArbitrumGoerli:
config = params.GoerliChainConfig config = params.GoerliChainConfig
} }
baseFee := misc.CalcBaseFee(config, header) baseFee := misc.CalcBaseFee(config, header)
return baseFee, nil return baseFee, nil
} }

View File

@ -260,7 +260,6 @@ func findBestV2(routes [][]*PathV2, tokenPrice float64, nativeChainTokenPrice fl
// ecaluate the cost of the path // ecaluate the cost of the path
pathCost := big.NewFloat(0) pathCost := big.NewFloat(0)
nativeTokenPrice := new(big.Float).SetFloat64(nativeChainTokenPrice) nativeTokenPrice := new(big.Float).SetFloat64(nativeChainTokenPrice)
if path.TxBaseFee != nil && path.TxPriorityFee != nil { if path.TxBaseFee != nil && path.TxPriorityFee != nil {
feePerGas := new(big.Int).Add(path.TxBaseFee.ToInt(), path.TxPriorityFee.ToInt()) feePerGas := new(big.Int).Add(path.TxBaseFee.ToInt(), path.TxPriorityFee.ToInt())
txFeeInWei := new(big.Int).Mul(feePerGas, big.NewInt(int64(path.TxGasAmount))) txFeeInWei := new(big.Int).Mul(feePerGas, big.NewInt(int64(path.TxGasAmount)))
@ -269,7 +268,6 @@ func findBestV2(routes [][]*PathV2, tokenPrice float64, nativeChainTokenPrice fl
path.requiredNativeBalance.Add(path.requiredNativeBalance, txFeeInWei) path.requiredNativeBalance.Add(path.requiredNativeBalance, txFeeInWei)
pathCost = new(big.Float).Mul(txFeeInEth, nativeTokenPrice) pathCost = new(big.Float).Mul(txFeeInEth, nativeTokenPrice)
} }
if path.TxBonderFees != nil && path.TxBonderFees.ToInt().Cmp(pathprocessor.ZeroBigIntValue) > 0 { if path.TxBonderFees != nil && path.TxBonderFees.ToInt().Cmp(pathprocessor.ZeroBigIntValue) > 0 {
if path.FromToken.IsNative() { if path.FromToken.IsNative() {
path.requiredNativeBalance.Add(path.requiredNativeBalance, path.TxBonderFees.ToInt()) path.requiredNativeBalance.Add(path.requiredNativeBalance, path.TxBonderFees.ToInt())
@ -281,7 +279,6 @@ func findBestV2(routes [][]*PathV2, tokenPrice float64, nativeChainTokenPrice fl
new(big.Float).SetFloat64(tokenPrice))) new(big.Float).SetFloat64(tokenPrice)))
} }
if path.TxL1Fee != nil && path.TxL1Fee.ToInt().Cmp(pathprocessor.ZeroBigIntValue) > 0 { if path.TxL1Fee != nil && path.TxL1Fee.ToInt().Cmp(pathprocessor.ZeroBigIntValue) > 0 {
l1FeeInWei := path.TxL1Fee.ToInt() l1FeeInWei := path.TxL1Fee.ToInt()
l1FeeInEth := gweiToEth(weiToGwei(l1FeeInWei)) l1FeeInEth := gweiToEth(weiToGwei(l1FeeInWei))
@ -289,7 +286,6 @@ func findBestV2(routes [][]*PathV2, tokenPrice float64, nativeChainTokenPrice fl
path.requiredNativeBalance.Add(path.requiredNativeBalance, l1FeeInWei) path.requiredNativeBalance.Add(path.requiredNativeBalance, l1FeeInWei)
pathCost.Add(pathCost, new(big.Float).Mul(l1FeeInEth, nativeTokenPrice)) pathCost.Add(pathCost, new(big.Float).Mul(l1FeeInEth, nativeTokenPrice))
} }
if path.TxTokenFees != nil && path.TxTokenFees.ToInt().Cmp(pathprocessor.ZeroBigIntValue) > 0 && path.FromToken != nil { if path.TxTokenFees != nil && path.TxTokenFees.ToInt().Cmp(pathprocessor.ZeroBigIntValue) > 0 && path.FromToken != nil {
if path.FromToken.IsNative() { if path.FromToken.IsNative() {
path.requiredNativeBalance.Add(path.requiredNativeBalance, path.TxTokenFees.ToInt()) path.requiredNativeBalance.Add(path.requiredNativeBalance, path.TxTokenFees.ToInt())
@ -300,7 +296,6 @@ func findBestV2(routes [][]*PathV2, tokenPrice float64, nativeChainTokenPrice fl
new(big.Float).Quo(new(big.Float).SetInt(path.TxTokenFees.ToInt()), tokenDenominator), new(big.Float).Quo(new(big.Float).SetInt(path.TxTokenFees.ToInt()), tokenDenominator),
new(big.Float).SetFloat64(tokenPrice))) new(big.Float).SetFloat64(tokenPrice)))
} }
if path.ApprovalRequired { if path.ApprovalRequired {
if path.ApprovalBaseFee != nil && path.ApprovalPriorityFee != nil { if path.ApprovalBaseFee != nil && path.ApprovalPriorityFee != nil {
feePerGas := new(big.Int).Add(path.ApprovalBaseFee.ToInt(), path.ApprovalPriorityFee.ToInt()) feePerGas := new(big.Int).Add(path.ApprovalBaseFee.ToInt(), path.ApprovalPriorityFee.ToInt())
@ -657,15 +652,16 @@ func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams)
continue continue
} }
var l1FeeWei uint64 // TODO: keep l1 fees at 0 until we have the correct algorithm, as we do base fee x 2 that should cover the l1 fees
if input.SendType.needL1Fee() { var l1FeeWei uint64 = 0
txInputData, err := pProcessor.PackTxInputData(processorInputParams) // if input.SendType.needL1Fee() {
if err != nil { // txInputData, err := pProcessor.PackTxInputData(processorInputParams)
continue // if err != nil {
} // continue
// }
l1FeeWei, _ = r.feesManager.GetL1Fee(ctx, network.ChainID, txInputData) // l1FeeWei, _ = r.feesManager.GetL1Fee(ctx, network.ChainID, txInputData)
} // }
amountOut, err := pProcessor.CalculateAmountOut(processorInputParams) amountOut, err := pProcessor.CalculateAmountOut(processorInputParams)
if err != nil { if err != nil {

View File

@ -2455,6 +2455,8 @@ func TestNoBalanceForTheBestRouteRouterV2(t *testing.T) {
suggestedFees: testSuggestedFees, suggestedFees: testSuggestedFees,
balanceMap: map[string]*big.Int{ balanceMap: map[string]*big.Int{
makeTestBalanceKey(walletCommon.ArbitrumMainnet, pathprocessor.UsdcSymbol): big.NewInt(testAmount100USDC + testAmount100USDC), makeTestBalanceKey(walletCommon.ArbitrumMainnet, pathprocessor.UsdcSymbol): big.NewInt(testAmount100USDC + testAmount100USDC),
makeTestBalanceKey(walletCommon.EthereumMainnet, pathprocessor.UsdcSymbol): big.NewInt(testAmount100USDC + testAmount100USDC),
makeTestBalanceKey(walletCommon.OptimismMainnet, pathprocessor.UsdcSymbol): big.NewInt(testAmount100USDC + testAmount100USDC),
}, },
estimationMap: testEstimationMap, estimationMap: testEstimationMap,
bonderFeeMap: testBbonderFeeMap, bonderFeeMap: testBbonderFeeMap,