RubiconDeFi / rubi-subgraphs

Subgraphs for the Rubicon Protocol
MIT License
3 stars 0 forks source link

feat: tracking maker rebates #15

Open JossDuff opened 1 year ago

JossDuff commented 1 year ago

We can now track total, daily, and hourly rebates earned by makers. Initially this update was so we can display it on defi llama, but we can plug this in wherever we're using Metrics subgraphs.

Currently (July 12) the RubiconMetricsOptimism subgraph is 7 days into syncing with a few days left. RubiconMetricsArbitrum is fully synced. Neither of these are updated with these fee changes so we can't display fees on defi llama. If we wanted to re-sync with these changes, we would have (possibly) 12ish days of downtime on RubiconMetricsOptimism and only a few hours of downtime on RubiconMetricsArbitrum. Too much downtime for us to handle right now with all the new users from OP rewards and arb launch. Maybe wait until we have our own archival node (I assume syncing on our own archival is faster than hosted service).

Schema changes

New entities: HourMakerRebateVolume and DayMakerRebateVolume follow same pattern as HourVolume and DayVolume.

New field on Rubicon entity: total_maker_rebate_volume_usd tracks the total amount of fees paid to makers in USD.

Handler changes

All new fields and entities are updated in new event handler handleFee that handles the emitFee event.

First, the handleFee checks if the emitFee event is paid to a maker:

from Metrics/src/utils/entities/fee.ts

if (event.params.feeTo == rubiconMarket.getFeeTo()){
        // this emitFee event is NOT a maker rebate
}
else {
        // this emitFee event is a maker rebate
}

Then it follows the same pattern as handleLogTake to convert event.params.feeAmt into USD value of event.params.asset (asset that was paid to maker) and update Rubicon, HourMakerRebateVolume, and DayMakerRebateVolume.

Other changes

Added Metrics/src/utils/entities/fee.ts which contains function isFeeMakerRebate(event: emitFee). This function makes a call to a deployed RubiconMarket to check if the address the fee was sent to is the protocol's feeTo address.

Added RubiconMarket addresses to Metrics/src/prices/config/arbitrumOne.ts and optimism.ts

Notes

TODOs

Could easily update the schema to also track protocol revenue from fees if we want. Would need to update handleFee to not immediately return if fee is paid to the protocol and add logic inside that check.