# Calculating desiredEgl

The initial value for `desiredEGL` at launch will equal the current gas limit at launch, e.g. 15M gas.

Each vote specifies the voter’s desired `gasTarget`, as well as an `eglAmount` and `lockupDuration`, and the weekly tally calculates the weighted average of all the votes’ `gasTarget` to determine the `desiredEGL`.

The votes are weighted based on `eglAmount` (the more EGLs you use, the stronger your vote) and `lockupDuration` (1 to 8 weeks; the longer you lockup your EGLs, the stronger your vote). Specifically, weight = `eglAmount` \* `lockupDuration` , and the weighted average is calculated as

$$
\frac{\sum\_i (targetGasLimit\_i \* weight\_i)}{ \sum\_i weight\_i}
$$

`desiredEGL`is calculated by storing and updating 2 variables:

1. sum of all voters’ `eglAmount` \* `lockupDuration`&#x20;
2. sum of all voters’ `eglAmount` \* `lockupDuration` \* `gasTarget`

{% hint style="info" %}
When `tallyVotes()` is called, the weighted average is calculated, and `desiredEGL` is adjusted towards it, but by no more than 1M gas.
{% endhint %}

To avoid manipulation of the weighted average by using very high / low values for `gasTarget`, the value of `gasTarget`must be close to the actual gas limit of the block in which the `vote()`/`revote()`Tx is mined.&#x20;

{% hint style="info" %}
If the `desiredEGL` is within 10,000 of the `tallyVotesGasLimit,`functionally the community is voting to keep the gas limit the same. For simplicity, the`desiredEGL` will be set to`tallyVotesGasLimit.`
{% endhint %}

Specifically, the delta between the two must be no greater than 4M gas. To protect honest users from having their Tx fail due to jitters in the gas limit, the UI provided at [egl.vote](https://docs.egl.vote/protocol-overview/voting/www.egl.vote) allows a delta of up to 3M gas between `gasTarget`and the current gas limit. Sophisticated users can of course bypass this limitation, and carry the risk of having their Tx fail.&#x20;

If your vote for a given epoch was within 4M of the gas at the time of the vote, but you've locked in your vote for several weeks and now it is outside of the 4M range, it will *still* be included in the `desiredEGL` calculation.  For example, if you voted for 7M gas when the current gas was 10M and now the current gas is 13M, your 7M vote will still be included as (7M \* your multiplier) in the calculation. However, remember that the `desiredEGL` cannot change by more than 1M each week.&#x20;

{% hint style="danger" %}
`desiredEGL` is calculated when `tallyvotes()` is called for the first time after the epoch has ended. Thus, someone needs to call `tallyvotes()` after an epoch has ended to ensure `desiredEGL` is calculated.&#x20;
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.egl.vote/protocol-overview/voting/calculating-desiredegl.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
