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

fix: fix fees calculation and add support for L1 fees for Optimism transactions #19603

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

briansztamfater
Copy link
Member

@briansztamfater briansztamfater commented Apr 10, 2024

fixes #18780
fixes #19431

Summary

This PR fixes fees calculation and adds support for Optimism L1 fees.

cc @FFFra

Testing notes

Platforms

  • Android
  • iOS

Areas that maybe impacted

Functional
  • wallet / transactions

Steps to test

General fees fix testing

  • Open Status
  • Login
  • Go to wallet
  • Go to an account with funds on any chain
  • Tap on Send button
  • Select an account to send funds to
  • Select token
  • Input an amount
  • Wait for routes to be loaded
  • Check that fee is correctly displayed

For Optimism specific L1 fees

  • Open Status
  • Login
  • Go to wallet
  • Go to an account with funds on Optimism
  • Tap on Send button
  • Select an account to send funds to
  • Select token
  • Input an amount
  • Wait for routes to be loaded
  • Check that fee is correctly displayed

status: ready

@status-im-auto
Copy link
Member

status-im-auto commented Apr 10, 2024

Jenkins Builds

Click to see older builds (27)
Commit #️⃣ Finished (UTC) Duration Platform Result
60647da #1 2024-04-10 21:13:18 ~2 min tests 📄log
✔️ 60647da #1 2024-04-10 21:16:10 ~5 min android 🤖apk 📲
✔️ 60647da #1 2024-04-10 21:17:26 ~7 min android-e2e 🤖apk 📲
✔️ 60647da #1 2024-04-10 21:18:53 ~8 min ios 📱ipa 📲
cff1d84 #2 2024-04-10 22:25:17 ~2 min tests 📄log
✔️ cff1d84 #2 2024-04-10 22:28:37 ~5 min android-e2e 🤖apk 📲
✔️ cff1d84 #2 2024-04-10 22:28:44 ~5 min android 🤖apk 📲
✔️ cff1d84 #2 2024-04-10 22:31:04 ~8 min ios 📱ipa 📲
ea4b351 #3 2024-04-10 22:41:12 ~2 min tests 📄log
48ad7c7 #4 2024-04-10 22:46:36 ~2 min tests 📄log
✔️ cb56042 #5 2024-04-10 22:52:10 ~4 min tests 📄log
✔️ cb56042 #5 2024-04-10 22:53:44 ~5 min android 🤖apk 📲
✔️ cb56042 #5 2024-04-10 22:53:49 ~5 min android-e2e 🤖apk 📲
✔️ cb56042 #5 2024-04-10 22:56:03 ~8 min ios 📱ipa 📲
✔️ 53d6a55 #6 2024-04-16 09:27:18 ~3 min tests 📄log
✔️ b767983 #7 2024-04-16 09:32:48 ~4 min tests 📄log
✔️ b767983 #7 2024-04-16 09:35:19 ~6 min android-e2e 🤖apk 📲
✔️ b767983 #7 2024-04-16 09:35:34 ~6 min android 🤖apk 📲
✔️ b767983 #7 2024-04-16 09:37:10 ~8 min ios 📱ipa 📲
✔️ b7fa37a #8 2024-04-17 09:15:05 ~3 min tests 📄log
✔️ b7fa37a #8 2024-04-17 09:17:33 ~6 min android 🤖apk 📲
✔️ b7fa37a #8 2024-04-17 09:17:54 ~6 min android-e2e 🤖apk 📲
✔️ b7fa37a #8 2024-04-17 09:19:43 ~8 min ios 📱ipa 📲
✔️ 11a0ebd #9 2024-04-17 10:35:25 ~5 min tests 📄log
✔️ 11a0ebd #9 2024-04-17 10:36:36 ~7 min android-e2e 🤖apk 📲
✔️ 11a0ebd #9 2024-04-17 10:36:41 ~7 min android 🤖apk 📲
✔️ 11a0ebd #9 2024-04-17 10:39:45 ~10 min ios 📱ipa 📲
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 44ad8dc #10 2024-04-18 11:50:28 ~4 min tests 📄log
✔️ 44ad8dc #10 2024-04-18 11:54:17 ~8 min android 🤖apk 📲
✔️ 44ad8dc #10 2024-04-18 11:54:17 ~8 min android-e2e 🤖apk 📲
✔️ 44ad8dc #10 2024-04-18 11:55:01 ~8 min ios 📱ipa 📲
✔️ ae90df0 #11 2024-04-18 13:22:35 ~3 min tests 📄log
✔️ ae90df0 #11 2024-04-18 13:24:59 ~6 min android 🤖apk 📲
✔️ ae90df0 #11 2024-04-18 13:25:23 ~6 min android-e2e 🤖apk 📲
✔️ ae90df0 #11 2024-04-18 13:29:21 ~10 min ios 📱ipa 📲

@@ -243,8 +243,9 @@
(<= input-num-value 0)
(> input-num-value (current-limit)))
amount-text (str @input-value " " token-symbol)
first-route (first route)
Copy link
Member Author

@briansztamfater briansztamfater Apr 10, 2024

Choose a reason for hiding this comment

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

We use the first route to identify the native token symbol, which is the token used to pay the fees. This should always be the same token (ETH) across all routes as long as we're only supporting Layer 2s and the mainnet, and not including sidechains or alternative chains. Therefore, selecting the first element as the basis for this information should be entirely safe.

Comment on lines +6 to +15
(let [gas-amount (money/bignumber (get data :gas-amount))
gas-fees (get data :gas-fees)
eip1559-enabled? (get gas-fees :eip-1559-enabled)
optimal-price-gwei (money/bignumber (if eip1559-enabled?
(get gas-fees :max-fee-per-gas-medium)
(get gas-fees :gas-price)))
total-gas-fee-wei (money/mul (money/->wei :gwei optimal-price-gwei) gas-amount)
l1-fee-wei (money/->wei :gwei (get gas-fees :l-1-gas-fee))]
(money/add total-gas-fee-wei l1-fee-wei)))
Copy link
Member Author

@briansztamfater briansztamfater Apr 10, 2024

Choose a reason for hiding this comment

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

Used the same logic from status-desktop, values are received in gwei and we transform them to wei.


(defn calculate-full-route-gas-fee
[route]
(reduce money/add (map calculate-gas-fee route)))
(money/wei->ether (reduce money/add (map calculate-gas-fee route))))
Copy link
Member Author

@briansztamfater briansztamfater Apr 10, 2024

Choose a reason for hiding this comment

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

Sums all the routes fees in wei and then convert the total value to ether

Copy link
Member

@OmarBasem OmarBasem Apr 15, 2024

Choose a reason for hiding this comment

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

I think it maybe worth it adding that comment "Sums all the routes fees in wei and then convert the total value to ether" as a docstring to the function

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, done!

(get gas-fees :max-fee-per-gas-medium)
(get gas-fees :gas-price)))
total-gas-fee-wei (money/mul (money/->wei :gwei optimal-price-gwei) gas-amount)
l1-fee-wei (money/->wei :gwei (get gas-fees :l-1-gas-fee))]
Copy link
Member Author

@briansztamfater briansztamfater Apr 10, 2024

Choose a reason for hiding this comment

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

l-1-gas-fee should be 0 unless it is an Optimism (or Optimism Sepolia) transaction.

For more context: https://docs.optimism.io/stack/transactions/fees#l1-data-fee

@briansztamfater briansztamfater force-pushed the fix/fee-calculation branch 4 times, most recently from 48ad7c7 to cb56042 Compare April 10, 2024 22:47
@briansztamfater briansztamfater changed the title [WIP] fix: fix fees calculation and add support for L1 fees for Optimism transactions fix: fix fees calculation and add support for L1 fees for Optimism transactions Apr 10, 2024
@briansztamfater briansztamfater marked this pull request as ready for review April 10, 2024 22:48
@briansztamfater briansztamfater moved this from REVIEW to E2E Tests in Pipeline for QA Apr 11, 2024
@status-im-auto
Copy link
Member

88% of end-end tests have passed

Total executed tests: 52
Failed tests: 5
Expected to fail tests: 1
Passed tests: 46
IDs of failed tests: 704613,703495,702844,702730,702775 
IDs of expected to fail tests: 703503 

Failed tests (5)

Click to expand
  • Rerun failed tests

  • Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_mute_chat, id: 703495

    # STEP: Change device time so chat will be unmuted by timer
    Device 2: Long press on `ChatElement`

    critical/chats/test_group_chat.py:462: in test_group_chat_mute_chat
        self.errors.verify_no_errors()
    base_test_case.py:190: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Chat is still muted after timeout
    



    Device sessions

    Class TestDeepLinksOneDevice:

    1. test_links_open_universal_links_from_chat, id: 704613

    Device 1: Find Button by xpath: //*[@text="open community"]
    Device 1: Tap on found: Button

    critical/test_deep_and_universal_links.py:69: in test_links_open_universal_links_from_chat
        self.errors.verify_no_errors()
    base_test_case.py:190: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Community 'closed community' was not requested to join by the url https://status.app/c/G00AAGS9TbI9mSR-ZNmFrhRjNuEeXAAbcAIUaLLJyjMOG3ACJQ12oIHD78QhzO9s_T5bUeU7rnATWJg3mGgTUemrAg==#zQ3shspPKCZ1VPVQ9dLXGufUGvGphjxVwrcZ6rkZc7S39T4b3
    



    Device sessions

    2. test_links_deep_links, id: 702775

    Device 1: Find BrowserTab by accessibility id: browser-stack-tab
    Device 1: Tap on found: BrowserTab

    critical/test_deep_and_universal_links.py:112: in test_links_deep_links
        self.errors.verify_no_errors()
    base_test_case.py:190: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Community 'closed community' was not requested to join by the deep link status.app://c/G00AAGS9TbI9mSR-ZNmFrhRjNuEeXAAbcAIUaLLJyjMOG3ACJQ12oIHD78QhzO9s_T5bUeU7rnATWJg3mGgTUemrAg==#zQ3shspPKCZ1VPVQ9dLXGufUGvGphjxVwrcZ6rkZc7S39T4b3
    



    Device sessions

    Class TestCommunityMultipleDeviceMerged:

    1. test_community_links_with_previews_github_youtube_twitter_gif_send_enable, id: 702844

    Device 2: Tap on found: SendMessageButton
    Device 1: Getting preview message for link: #11707

    critical/chats/test_public_chat_browsing.py:586: in test_community_links_with_previews_github_youtube_twitter_gif_send_enable
        message.wait_for_element(60)
    ../views/base_element.py:129: in wait_for_element
        raise TimeoutException(
     Device `1`: `PreviewMessage` by` xpath`: `//*[starts-with(@text,'https://github.com/status-im/status-mobile/pull/11707')]/ancestor::android.view.ViewGroup[@content-desc='chat-item']` is not found on the screen after wait_for_element
    



    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_message_reaction, id: 702730

    Device 1: Find EmojisNumber by xpath: //*[starts-with(@text,'Message sender')]/ancestor::android.view.ViewGroup[@content-desc='chat-item']/../..//*[@content-desc='emoji-reaction-2']/android.widget.TextView[2]
    Device 1: Find EmojisNumber by xpath: //*[starts-with(@text,'Message sender')]/ancestor::android.view.ViewGroup[@content-desc='chat-item']/../..//*[@content-desc='emoji-reaction-2']/android.widget.TextView[2]

    critical/chats/test_1_1_public_chats.py:73: in test_1_1_chat_message_reaction
        message_sender.emojis_below_message(emoji="thumbs-up").wait_for_element_text(1, 90)
    ../views/base_element.py:190: in wait_for_element_text
        self.driver.fail(message if message else "`%s` is not equal to expected `%s` in %s sec" % (
    base_test_case.py:178: in fail
        pytest.fail('Device %s: %s' % (self.number, text))
     Device 1: `2` is not equal to expected `1` in 90 sec
    



    Device sessions

    Expected to fail tests (1)

    Click to expand

    Class TestCommunityOneDeviceMerged:

    1. test_community_discovery, id: 703503

    Test is not run, e2e blocker  
    

    [[reason: [NOTRUN] Curated communities not loading, https://github.com//issues/17852]]

    Passed tests (46)

    Click to expand

    Class TestActivityMultipleDevicePRTwo:

    1. test_activity_center_mentions, id: 702957
    Device sessions

    2. test_activity_center_admin_notification_accept_swipe, id: 702958
    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_emoji_send_reply_and_open_link, id: 702782
    Device sessions

    2. test_1_1_chat_text_message_delete_push_disappear, id: 702733
    Device sessions

    3. test_1_1_chat_push_emoji, id: 702813
    Device sessions

    4. test_1_1_chat_non_latin_messages_stack_update_profile_photo, id: 702745
    Device sessions

    5. test_1_1_chat_edit_message, id: 702855
    Device sessions

    6. test_1_1_chat_send_image_save_and_share, id: 703391
    Device sessions

    7. test_1_1_chat_pin_messages, id: 702731
    Device sessions

    Class TestActivityMultipleDevicePR:

    1. test_navigation_jump_to, id: 702936
    Device sessions

    2. test_activity_center_reply_read_unread_delete_filter_swipe, id: 702947
    Device sessions

    Class TestCommunityMultipleDeviceMerged:

    1. test_community_several_images_send_reply, id: 703194
    Device sessions

    2. test_community_one_image_send_reply, id: 702859
    Device sessions

    3. test_community_emoji_send_copy_paste_reply, id: 702840
    Device sessions

    4. test_community_mark_all_messages_as_read, id: 703086
    Device sessions

    5. test_community_contact_block_unblock_offline, id: 702894
    Device sessions

    6. test_community_edit_delete_message_when_offline, id: 704615
    Device sessions

    7. test_community_message_delete, id: 702839
    Device sessions

    8. test_community_message_send_check_timestamps_sender_username, id: 702838
    Device sessions

    9. test_community_message_edit, id: 702843
    Device sessions

    10. test_community_unread_messages_badge, id: 702841
    Device sessions

    Class TestCommunityMultipleDeviceMergedTwo:

    1. test_community_markdown_support, id: 702809
    Device sessions

    2. test_community_hashtag_links_to_community_channels, id: 702948
    Device sessions

    3. test_community_mentions_push_notification, id: 702786
    Device sessions

    4. test_community_leave, id: 702845
    Device sessions

    5. test_community_join_when_node_owner_offline, id: 703629
    Device sessions

    Class TestActivityCenterContactRequestMultipleDevicePR:

    1. test_add_contact_field_validation, id: 702777
    Device sessions

    2. test_activity_center_contact_request_accept_swipe_mark_all_as_read, id: 702851
    Device sessions

    3. test_activity_center_contact_request_decline, id: 702850
    Device sessions

    Class TestCommunityOneDeviceMerged:

    1. test_restore_multiaccount_with_waku_backup_remove_switch, id: 703133
    Device sessions

    2. test_community_copy_and_paste_message_in_chat_input, id: 702742
    Device sessions

    3. test_community_undo_delete_message, id: 702869
    Device sessions

    4. test_community_navigate_to_channel_when_relaunch, id: 702846
    Device sessions

    5. test_community_mute_community_and_channel, id: 703382
    Device sessions

    Class TestGroupChatMultipleDeviceMergedNewUI:

    1. test_group_chat_pin_messages, id: 702732
    Device sessions

    2. test_group_chat_send_image_save_and_share, id: 703297
    Device sessions

    3. test_group_chat_reactions, id: 703202
    Device sessions

    4. test_group_chat_join_send_text_messages_push, id: 702807
    Device sessions

    5. test_group_chat_offline_pn, id: 702808
    Device sessions

    Class TestWalletMultipleDevice:

    1. test_wallet_send_asset_from_drawer, id: 727230
    Device sessions

    2. test_wallet_send_eth, id: 727229
    Device sessions

    Class TestOneToOneChatMultipleSharedDevicesNewUiTwo:

    1. test_1_1_chat_delete_via_long_press_relogin, id: 702784
    Device sessions

    2. test_1_1_chat_is_shown_message_sent_delivered_from_offline, id: 702783
    Device sessions

    3. test_1_1_chat_mute_chat, id: 703496
    Device sessions

    Class TestWalletOneDevice:

    1. test_wallet_add_remove_regular_account, id: 727231
    Device sessions

    2. test_wallet_add_remove_watch_only_account, id: 727232
    Device sessions


    (defn calculate-full-route-gas-fee
    [route]
    (reduce money/add (map calculate-gas-fee route)))
    (money/wei->ether (reduce money/add (map calculate-gas-fee route))))
    Copy link
    Member

    @OmarBasem OmarBasem Apr 15, 2024

    Choose a reason for hiding this comment

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

    I think it maybe worth it adding that comment "Sums all the routes fees in wei and then convert the total value to ether" as a docstring to the function

    @briansztamfater briansztamfater force-pushed the fix/fee-calculation branch 2 times, most recently from 53d6a55 to b767983 Compare April 16, 2024 09:28
    @VolodLytvynenko VolodLytvynenko self-assigned this Apr 16, 2024
    @VolodLytvynenko VolodLytvynenko moved this from E2E Tests to IN TESTING in Pipeline for QA Apr 16, 2024
    @VolodLytvynenko
    Copy link
    Contributor

    VolodLytvynenko commented Apr 18, 2024

    Hi @briansztamfater thank you for PR. I think the PR can be merged since all information related to gas fees fetches is implemented in status go. However, please address any issues if you see that the problem is on your side.

    I have created a comparison table with gas fees using Metamask:

    1 Mainnet Mainnet eth 0.0001 0.83 usd 0.74 usd
    2 Mainnet Mainnet snt 1 5 usd 4.2 usd
    3 Mainnet Mainnet uni 0.01 2.33 usd 3.05 usd
    4 Mainnet Arbitrium eth 0.0001 0.3 usd <0.01 usd, but in fact 0.3 usd
    5 Mainnet Arbitrium wrapped bitcoin 0.00001 0.62 usd <0.01 usd
    6 Mainnet Optimism eth 0.0001 0,31 usd 1.17 usd, in fact 0.30 usd link in fact the fee is in 75% less
    7 Mainnet Optimism wrapped bitcoin 0.00001 0.62 usd 1.32 usd is shown

    In conclusion, regarding above the table:

    • For mainnet transactions (rows 1-3) I am not sure if this is expected behavior that all status app fees 15% less
    • It seems like Arbitrum is always shown as 0.01 USD (in row 4 and 5), but in fact, when the transaction is performed within the Status app, the gas fee is the same as within Metamask. So, the actual gas fee is 300-600% higher than estimated. Which is definitely that is not ok
    • In Optimism, the gas fee is usually higher than estimated. Status gas fee typically shows as 1.30 USD, but in fact 0.30 usd (in case when working with assets such as ETH) that is not ok
      How gas fee is estimated in Optimism in Metamask:
      image

    How gas fee is estimated in Optimism in Status:
    image

    @VolodLytvynenko
    Copy link
    Contributor

    Question

    Should the gas fee be fetched on the confirmation page which is shown when collectibles or tokens are going to be sent? Currently, it doesn't
    image

    @VolodLytvynenko VolodLytvynenko moved this from IN TESTING to MERGE in Pipeline for QA Apr 18, 2024
    @briansztamfater
    Copy link
    Member Author

    Hey @VolodLytvynenko, thanks for testing! We have an issue for that: #18408 👍

    @briansztamfater
    Copy link
    Member Author

    @VolodLytvynenko quick question, do you experience same fees values when trying those transactions in Status Desktop?

    @VolodLytvynenko
    Copy link
    Contributor

    @VolodLytvynenko quick question, do you experience same fees values when trying those transactions in Status Desktop?

    @briansztamfater hey. Unfortunately can't check it on a desktop. All transactions related to L2 just don't work there, routes are not fetched. In case of L1 the fees are the same as on mobile

    @briansztamfater
    Copy link
    Member Author

    @VolodLytvynenko quick question, do you experience same fees values when trying those transactions in Status Desktop?

    @briansztamfater hey. Unfortunately can't check it on a desktop. All transactions related to L2 just don't work there, routes are not fetched. In case of L1 the fees are the same as on mobile

    Ok, no problem, I will merge this so we can have at least some fees displayed, if there are some things to be adjusted, probably will be adjusted on status-go, we can fill another issue if necessary for mobile in the future.

    …ansactions
    
    Signed-off-by: Brian Sztamfater <brian@status.im>
    @briansztamfater briansztamfater merged commit 17afff2 into develop Apr 18, 2024
    6 checks passed
    Pipeline for QA automation moved this from MERGE to DONE Apr 18, 2024
    @briansztamfater briansztamfater deleted the fix/fee-calculation branch April 18, 2024 13:35
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    Archived in project
    Development

    Successfully merging this pull request may close these issues.

    Fees always displayed as 0 for all networks on the send assets page Incorrect Optimism Gas Fee display
    5 participants