Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Add protocol fees to dune #64

Merged
merged 12 commits into from
Jan 22, 2024
Merged

Add protocol fees to dune #64

merged 12 commits into from
Jan 22, 2024

Conversation

fhenneke
Copy link
Contributor

@fhenneke fhenneke commented Jan 19, 2024

This PR adds protocol fees to dune.

It adds the changes which were also done to the solver rewards repo (here) to the dune sync repo.

The data uploaded to dune changes for batch_rewards and orders_rewards.

  • For batch rewards, we sync an additional entry protocol_fee which contains the ETH value of all protocol fees in a batch. Additionally, fees are reduced by network fees. We correct for the fact that the settlement_observations table calculates fees from surplus in the sell token while the protocol fee might be taken in the buy token.
  • For order rewards, we additionally sync the entries
    • protocol_fee: The protocol fee in the token it was charged in.
    • protocol_fee_token: The token in which the fee is charged, i.e., sell token for volume based fees and surplus token for surplus based fees. It is NULL when there was no protocol fee.
    • protocol_fee_native_price: The native price of the protocol fee token in the auction which was settled. It is 0.0 if there is no protocol fee.

@fhenneke
Copy link
Contributor Author

Tests affected by the changes in this repo pass locally. The test which fails is testing ipfs, which is unrelated. See #60

src/fetch/orderbook.py Outdated Show resolved Hide resolved
- fix small bug in sql query
- add comment for eth cap
uses one of the test batches on staging
-- Uncapped Reward = CLAMP_[-E, E + exec_cost](uncapped_payment_eth)
LEAST(GREATEST(-10000000000000000, surplus + fee - reference_score),
10000000000000000 + execution_cost) as capped_payment,
protocol_fee + fee - network_fee_correction as fee,-- total fee for ranking
Copy link
Contributor

@harisang harisang Jan 22, 2024

Choose a reason for hiding this comment

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

Should we call this something different? I am a bit confused as two lines later you use a fee term in the uncapped_payment_eth computation, and it is probably not referring to this total fee. What exactly are you trying to compute here?

Copy link
Contributor Author

@fhenneke fhenneke Jan 22, 2024

Choose a reason for hiding this comment

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

We could to corrected_fee and later select corrected_fee as fee for the uploading. Changing the name for what we upload might be breaking dune queries (but not the queries we use for payments, I guess, which only depend on capped_payment).

Another alternative is to repurpose the fee field to just be something like network fees. We do not use the field directly in the payment queries, so there it should be fine. Since protocol fees are synced explicitly, we can still recover the corrected quality on dune, quality = surplus + protocol_fee + fee.

With the implementation in this PR, we would still be able to do quality = surplus + fees.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The query now computes protocol_fee and network_fee separately. The payment is thus by quality = surplus + protocol_fee + network_fee.

On dune, the entry network_fee is still called just fee for now to not break existing queries.

@fhenneke
Copy link
Contributor Author

Comments have been addressed. This is ready to be merged now.

@fhenneke fhenneke merged commit 00410fe into main Jan 22, 2024
4 of 6 checks passed
@fhenneke fhenneke deleted the protocol_fee_sync branch January 22, 2024 11:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants