duneanalytics / spellbook

SQL views for Dune
Other
1.15k stars 1.06k forks source link

[BUG] wrong fee amount for phoenix_v1.base_trades #6642

Open 0xroll opened 2 weeks ago

0xroll commented 2 weeks ago

Description

The current fee_tier is overstated because the raw data is denominated in basis points (bps) but is being divided by 100 instead of 10000.

https://github.com/duneanalytics/spellbook/blob/main/dbt_subprojects/solana/models/_sector/dex/phoenix/phoenix_v1_base_trades.sql#L48

Current behavior

this is causing the inflated fees on solana_dex.trades

dune query to check :

https://dune.com/queries/4033552

Expected behavior

fee_tier to be /10000 instead of /100 to get the correct values

Impacted model(s)

https://github.com/duneanalytics/spellbook/blob/main/dbt_subprojects/solana/models/_sector/dex/phoenix/phoenix_v1_base_trades.sql

https://github.com/duneanalytics/spellbook/blob/main/dbt_subprojects/solana/models/_sector/dex/dex_solana_trades.sql

Possible solution

fix by changing from /100 to /10000

jeff-dude commented 1 week ago

@andrewhong5297 can you help validate the above issue on solana dex model?

GioZaarour commented 1 week ago

Hello, I came across this issue when writing a query here [https://dune.com/queries/4010725/6752431].

For certain markets on Phoenix, I have validated that the taker fee is in basis points. You can see this on the smart contracts on Solscan. For example, the "takerfeebps" for the SOL/USDC market is 2 bps, meaning 0.0002. See here [https://solscan.io/account/4DoNfFBfF7UokCC2FQzriy7yHK6DY6NVdYpuekQ5pRgg#data]

In the dex_solana.trades table, the fees are in percentages, for example 0.02 for the SOL/USDC market on Phoenix.

andrewhong5297 commented 1 week ago

Sounds right, lets push a fix

GioZaarour commented 3 days ago

Sounds right, lets push a fix

Hey Andrew! I'm not sure what happened, but from what I can see now on a new query, the amount sold/bought for the SOL token on Phoenix (not sure if this issue also occurred with other tokens on other markets), has been divided by many orders of magnitude. I'm not sure if this happened in an attempt to reduce the decimal form of the fee_tier and reduce the fee_amount, and accidentally reduced the amount of the token being swapped instead?

Regardless, you can see the error here [https://dune.com/queries/4050966]. Take a look at the amount being swapped for any trade, and then look at the amount on Solscan using the tx_id.