-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
sudoswap improved price calculations #1437
Conversation
@andrewhong5297 give this a look if you can. I want to gather some example transactions covering all the different trade cases and write a test for them. |
Awesome!!! I'll take a look tonight, agree on having tests for different trade types. Probably need to have pool type checks with trade types, and add in the total protocol fee check as a sanity check. Likely also need an aggregator check (I saw Vasa tweet that gem was integrating next week). |
0xRob's Main
|
, SUM( | |
CASE WHEN sb.trade_category = 'Buy' -- caller buys, AMM sells | |
THEN ( | |
CASE WHEN tr.from = sb.call_from THEN value -- amount of ETH payed | |
WHEN (tr.to = sb.call_from AND sb.call_from != sb.asset_recip) THEN -value --refunds unless the caller is also the asset recipient, no way to discriminate there. | |
ELSE 0 END) | |
ELSE ( -- caller sells, AMM buys | |
CASE WHEN tr.from = sb.pair_address THEN value -- all ETH leaving the pool, nothing should be coming in on a sell. | |
ELSE 0 END) | |
END ) as trade_price -- what the buyer paid (incl all fees) | |
, SUM( | |
CASE WHEN (tr.to = sb.protocolfee_recipient) THEN value | |
ELSE 0 END | |
) as protocol_fee_amount -- what the buyer paid |
What we are not seeing here is the so-called swap fee
set by a trade pool owner (owner fee).
I would say the swap fee has no influence in the value exchanged, it only influences the spread when setting both ask and bid prices on the same moving price curve. When you are listing NFTs at 10% above the current floor price, you are not collecting a 10% fee when that ask gets filled.
You should look at it as a spread setting instead of a fee setting where it results in profit if (and only if) spread from both the ask and bid sides are captured.
Now that I have thought about it more, I believe we should remove the owner fee fields from this base table as it will probably lead to a lot of misinformation about pool profits.
It's still interesting to calculate the 'virtual swap fees' that were used in all the pool trades, but more thought is needed to present it correctly to the public then just a flat fee collected on each swap.
I hope this gives a good/better understanding at the thought framework I'm currently employing. 😄
wait we still need owner fees in there! I thought we agreed to keep all fees in prices and those columns too. I can't accept deleting those columns completely. |
if you take those out there's no way for us to back into real spot price either if we're doing slippage analysis later |
You can still calculate internal spot price as |
lol fair, but I am still against taking it out since I think it's useful data to have. |
will revert then, no harm in including it. 👍 |
@jeff-dude this is now ready for review :) |
This reverts commit e581845.
@0xRobin i pushed a few minor commits. the model runs as expected. i did compile the code and grab the test query on new seed file, it appears rows are returned: |
outer join examples ex | ||
join examples ex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually want to do outer join here because we want the the union of the two sets.
To validate that we are
- not missing any entries
- not returning excess entries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, i think syntax needs to be 'full outer join' or it fails, i can push a commit if so
@jeff-dude thanks for this! |
rebuilding now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you @0xRobin and @andrewhong5297
fyi @soispoke this model will need a full refresh in prod
following the discussion we had after the merge of: #1397
This PR includes:
For Dune Engine V2
I've checked that:
lowercase_snake_cased
When you are ready for a review, tag duneanalytics/data-experience. We will re-open your forked pull request as an internal pull request. Then your spells will run in dbt and the logs will be avaiable in Github Actions DBT Slim CI. This job will only run the models and tests changed by your PR compared to the production project.