Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: l1 gas price estimation when placing l2 transaction #4923

Merged
merged 1 commit into from
Mar 27, 2024

Conversation

saledjenic
Copy link
Contributor

@saledjenic saledjenic commented Mar 14, 2024

No description provided.

@status-im-auto
Copy link
Member

status-im-auto commented Mar 14, 2024

Jenkins Builds

Click to see older builds (24)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ d4dc656 #1 2024-03-14 13:42:53 ~3 min linux 📦zip
✔️ d4dc656 #1 2024-03-14 13:44:07 ~4 min ios 📦zip
✔️ d4dc656 #1 2024-03-14 13:44:24 ~5 min android 📦aar
✔️ 4067f22 #2 2024-03-18 08:34:04 ~2 min ios 📦zip
✔️ 4067f22 #2 2024-03-18 08:34:16 ~2 min linux 📦zip
✔️ 4067f22 #2 2024-03-18 08:36:37 ~5 min android 📦aar
✔️ 4067f22 #2 2024-03-18 09:10:10 ~38 min tests 📄log
✔️ d9bd863 #3 2024-03-25 12:45:20 ~3 min linux 📦zip
✔️ d9bd863 #3 2024-03-25 12:47:35 ~5 min android 📦aar
✔️ a2383ca #4 2024-03-25 16:01:14 ~2 min linux 📦zip
✔️ a2383ca #4 2024-03-25 16:02:49 ~4 min android 📦aar
✔️ a2383ca #4 2024-03-25 16:06:14 ~7 min ios 📦zip
✔️ 48d0dd3 #5 2024-03-26 10:50:33 ~2 min android 📦aar
✔️ 48d0dd3 #5 2024-03-26 10:51:51 ~3 min linux 📦zip
✔️ 48d0dd3 #5 2024-03-26 10:51:57 ~3 min ios 📦zip
✔️ 48d0dd3 #5 2024-03-26 11:27:39 ~39 min tests 📄log
✔️ 6e30e1c #6 2024-03-26 11:56:43 ~2 min linux 📦zip
✔️ 6e30e1c #6 2024-03-26 11:57:10 ~2 min android 📦aar
✔️ 6e30e1c #6 2024-03-26 11:58:24 ~3 min ios 📦zip
✔️ 6e30e1c #6 2024-03-26 12:34:35 ~39 min tests 📄log
✔️ 46955b1 #7 2024-03-26 12:56:18 ~1 min linux 📦zip
✔️ 46955b1 #7 2024-03-26 12:56:40 ~2 min android 📦aar
✔️ 46955b1 #7 2024-03-26 12:57:50 ~3 min ios 📦zip
✔️ 46955b1 #8 2024-03-26 14:29:39 ~39 min tests 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
daed981 #8 2024-03-26 14:11:11 ~15 sec linux 📄log
daed981 #8 2024-03-26 14:11:17 ~20 sec ios 📄log
daed981 #8 2024-03-26 14:11:20 ~21 sec android 📄log
✔️ 1c59e85 #9 2024-03-26 14:17:16 ~1 min linux 📦zip
✔️ 1c59e85 #9 2024-03-26 14:17:41 ~2 min android 📦aar
✔️ 1c59e85 #9 2024-03-26 14:18:47 ~3 min ios 📦zip
✔️ 1c59e85 #9 2024-03-26 15:09:17 ~39 min tests 📄log

@saledjenic saledjenic force-pushed the l1-gas-price branch 2 times, most recently from d9bd863 to a2383ca Compare March 25, 2024 15:57
@saledjenic saledjenic marked this pull request as ready for review March 25, 2024 15:58
@saledjenic saledjenic requested review from IvanBelyakoff, Khushboo-dev-cpp and alaibe and removed request for IvanBelyakoff March 25, 2024 15:58
@saledjenic saledjenic changed the title init feat: l1 gas price estimation when placing l2 transaction Mar 25, 2024
@@ -547,6 +549,48 @@ func (r *Router) getERC1155Balance(ctx context.Context, network *params.Network,
return balances[0].Int, nil
}

func (r *Router) getL1Fee(ctx context.Context, network *params.Network, fromAddress common.Address, toAddress common.Address, amountIn *big.Int) (uint64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested sending erc20 and sending eth from metamask and there is differences in l1 fees.

I beleve this logic is only valid for the case of sending eth, there should be logic for all types of tx:
Bridge / buy ENS, send ERC20, sendERC71.

This logic should be encapsulated by bridge

services/wallet/router.go Outdated Show resolved Hide resolved
@@ -737,6 +792,7 @@ func (r *Router) suggestedRoutes(
AmountIn: (*hexutil.Big)(zero),
AmountOut: (*hexutil.Big)(zero),
GasAmount: gasLimit,
L1GasAmount: l1Fee,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as said above, this should directly be attached to the gasfees

// Removed the required fees from maxAMount in case of native token tx
if token.IsNative() {
maxAmountIn = (*hexutil.Big)(new(big.Int).Sub(maxAmountIn.ToInt(), requiredNativeBalance))
approvalRequired, approvalAmountRequired, approvalGasLimit, approvalContractAddress, err := r.requireApproval(ctx, sendType, bridge, addrFrom, network, token, amountIn)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require approval should also have a l1 fees dedicated value

@saledjenic saledjenic force-pushed the l1-gas-price branch 2 times, most recently from 48d0dd3 to 6e30e1c Compare March 26, 2024 11:54
@saledjenic saledjenic requested a review from alaibe March 26, 2024 11:54
Copy link
Contributor

@alaibe alaibe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General question: what happens when the chain is not optimism, can we have a guard and stop early?

}

return true, amountIn, estimate, bridgeAddress, nil
l1Fee, _ := r.getL1Fee(ctx, network, token.Address, account, amountIn)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Require approval is not a eth transaction, here we are calling get L1 fee assuming it is, isn't possible to call getL1Fees witht the data above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alaibe if we call it on other than the optimism chain we will get an error like L1 fee not supported on this chain and the value will be 0, so we continue the block execution, doesn't need to skip the loop.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for answering and good for me, but this comment is about this specific call which need to buil getL1Fee for require approval not for eth tx

},
}

tx, err := s.BuildTransaction(sendArgs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: all the belows seems repeated accross all bridge, maybe move this into fees.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, thanks


l1GasFeeWei, _ := bridge.GetL1Fee(ctx, network, addrTo, addrFrom, token, amountIn)
l1GasFeeWei += l1ApprovalFee
gasFees.L1GasFee = weiToGwei(big.NewInt(int64(l1GasFeeWei)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be build directly instead of added?

I am not sure how @endulab has been doing it for communities but I believe they call directly:

func (api *API) GetSuggestedFees(ctx context.Context, chainID uint64) (*SuggestedFees, error) {
log.Debug("call to GetSuggestedFees")
return api.s.feesManager.suggestedFees(ctx, chainID)
}

if this is the case he will need to update this api endpoint but also consider this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I use this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be build directly instead of added?

@alaibe if we have the following params network, addrTo, addrFrom, token, amountIn on the client side, we can add a new endpoint and call it directly from the client, if that's what you meant?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sync up with @endulab offline, will create a follow up issue

Copy link
Member

@briansztamfater briansztamfater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for addressing this!

@saledjenic saledjenic merged commit 98c3be5 into develop Mar 27, 2024
7 checks passed
@saledjenic saledjenic deleted the l1-gas-price branch March 27, 2024 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants