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

Create MEVRouter #1189

Open
9 tasks done
joaobrunoah opened this issue Dec 18, 2024 · 0 comments · May be fixed by #1199
Open
9 tasks done

Create MEVRouter #1189

joaobrunoah opened this issue Dec 18, 2024 · 0 comments · May be fixed by #1199
Assignees

Comments

@joaobrunoah
Copy link
Contributor

joaobrunoah commented Dec 18, 2024

Description

Charges the MEV taxes in ETH and transfer to the MevTaxCollector.
It supports only single-hop swap (exact in and exact out).

Variables

  • mevTaxCollector : address.
  • mevTaxMultiplier: uint256 18 decimals. Multiplier of priority gas price.
  • priorityGasThreshold : uint256 18 decimals. Above this value, the transaction pays the mev tax to the router.
  • mevTaxEnabled : boolean. If true, charge MEV taxes.

Functions

All variables described above needs to have getters and setters, and all setters must be permissioned. (Only the priority fee admin is able to change it). Besides, the following functions must be implemented:

  • enableMevTax and disableMevTax: authenticated functions to enable/disable MEV charges.
  • swapSingleTokenExactIn : same signature as the single-hop Router.sol , and has most of the code in common. It should charge MEV taxes before calculating the swap logic.
  • swapSingleTokenExactOut : same signature as the single-hop Router.sol, and has most of the code in common. It should charge MEV taxes before calculating the swap logic.

Logic to charge priority fees

  • Check if mevTaxEnabled == true
    • If not, do not charge MEV tax and continue
  • Calculate priorityGasPrice: tx.gasprice - block.basefee
  • Check if priorityGasPrice > priorityGasThreshold
    • If not, do not charge MEV tax and continue
  • Calculate mevTax: priorityGasPrice * mevTaxMultiplier
  • Call mevTaxCollector.chargeMevTax{value: mevTax}(address pool) , which will collect and register the MEV tax (LPs + Protocol).
  • Emit MevTaxCharged(address pool, uint256 mevTax)

Tests

Swap ExactIn and ExactOut

  • Swaps with low priority fee should not pay anything
  • Swaps with priority fee above threshold should pay the application priority fee
    • Check if applicationPriorityFee = priorityGasPrice * multiplier
    • Make sure the function chargePriorityFees is called with the correct pool and applicationPriorityFee. Mock priorityFeeCollector
  • If priority fees are disabled, ignore threshold and do not pay priority fees
  • Revert if not enough ETH to pay for priority fees
  • Check if event is emitted

Getters and Setters

  • Make sure all setters are authenticated
  • Make sure all setters change the value when a user with proper permissions calls it
@joaobrunoah joaobrunoah self-assigned this Dec 18, 2024
@joaobrunoah joaobrunoah linked a pull request Dec 20, 2024 that will close this issue
12 tasks
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 a pull request may close this issue.

1 participant