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

Add base and priority fee to gas oracle response #9202

Merged
merged 2 commits into from Feb 9, 2024

Conversation

sl1depengwyn
Copy link
Collaborator

@sl1depengwyn sl1depengwyn commented Jan 19, 2024

Closes #9201

Changelog

  • Calculate the base fee of the next block by ourselves instead of query the node

  • Added EIP_1559_BASE_FEE_MAX_CHANGE_DENOMINATOR env variable with default value of 8 to accomplish the task above (Add EIP_1559_BASE_FEE_MAX_CHANGE_DENOMINATOR docs#235)

  • Added base and proirity fee

Response example:

{
    "average_block_time": 15030.0,
    "coin_price": null,
    "coin_price_change_percentage": null,
    "gas_price_updated_at": "2024-01-19T21:06:35.462186Z",
    "gas_prices": {
        "average": {
            "base_fee": 23.6,
            "fiat_price": null,
            "price": 23.85,
            "priority_fee": 0.26,
            "time": 15030.0
        },
        "fast": {
            "base_fee": 23.6,
            "fiat_price": null,
            "price": 25.18,
            "priority_fee": 1.59,
            "time": 15030.0
        },
        "slow": {
            "base_fee": 23.6,
            "fiat_price": null,
            "price": 23.64,
            "priority_fee": 0.05,
            "time": 15030.0
        }
    },
    "gas_prices_update_in": 32000,
    "gas_used_today": "0",
    "market_cap": "0",
    "network_utilization_percentage": 33.13972293333333,
    "static_gas_price": null,
    "total_addresses": "177985",
    "total_blocks": "4405",
    "total_gas_used": "0",
    "total_transactions": "300805",
    "transactions_today": "0",
    "tvl": null
}

Checklist for your Pull Request (PR)

@sl1depengwyn sl1depengwyn force-pushed the mf-gas-price-oracle-base-priority branch from 4358e07 to be6077e Compare January 19, 2024 21:10
@sl1depengwyn sl1depengwyn marked this pull request as ready for review January 20, 2024 10:52
apps/explorer/lib/explorer/chain/cache/gas_price_oracle.ex Outdated Show resolved Hide resolved
fiat_price: fiat_fee(fee, exchange_rate_from_db)
fiat_price: fiat_fee(fee, exchange_rate_from_db),
base_fee: base_fee |> format_wei(),
priority_fee: base_fee && priority_fee && priority_fee |> Decimal.new() |> Wei.from(:wei) |> format_wei()
Copy link
Member

Choose a reason for hiding this comment

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

Why should we check non-nil base_fee here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we have no base fee, priority fee may be misleading to the user since the price would be calculated without base fee knowledge and there may be strange relations between the price and priority fee, so I decided that it's better not to give priority fee if we do not have base fee by some reason (that is much less probable with manual calculation of the next block base fee)

@sl1depengwyn sl1depengwyn force-pushed the mf-gas-price-oracle-base-priority branch 2 times, most recently from 2163ae6 to 89705e9 Compare January 29, 2024 16:47
@sl1depengwyn sl1depengwyn force-pushed the mf-gas-price-oracle-base-priority branch from 89705e9 to fc85954 Compare January 30, 2024 17:11
@sl1depengwyn sl1depengwyn removed the wip label Jan 30, 2024
@sl1depengwyn
Copy link
Collaborator Author

I suggest to fix dialyzer errors in this PR: #8851

end

@spec next_block_base_fee(t()) :: Decimal.t() | nil
def next_block_base_fee(block) do
Copy link
Member

Choose a reason for hiding this comment

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

Let's rename base_fee to base_fee_per_gas here and above

@sl1depengwyn sl1depengwyn force-pushed the mf-gas-price-oracle-base-priority branch from fc85954 to e1871b0 Compare February 9, 2024 13:36
@vbaranov vbaranov merged commit 536ccb2 into master Feb 9, 2024
37 of 41 checks passed
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.

Gas Tracker API (v2). Base and priority method
3 participants