Angle Protocol Fees


I am a core member of Angle protocol - a decentralized, capital efficient and over-collateralized stablecoin. The first stablecoin made is the agEUR (pegged to the EURO), the largest decentralised EURO stablecoin, with currently 50m agEUR in circulation and a total volume of 6b.

Angle generates fees from different sources:

  • Core module: Marketplace between long/short on collateral, along with single sided LPs. Fees: mint/burn from stablecoin issuance, open/close from perpetuals and interest on invested reserves.
  • Borrow module: Borrow agEUR against collateral. Earning fees via borrow,repay, interest and liquidation surcharge.


Source : Angle built a graph via The Graph Protocol.


Thank you for reviewing it :slight_smile:


A quick sanity test I send query for the 29th and I get a negative number for fees paid. I have not looked deeper for the cause but wanted to let you know:

Hi, thank you, this wad off when querying for the current date, because it looked at tomorrow revenues. I fixed it in this one Angle Labs Adapter - CryptoStats

Thank you so much for your review :+1:

Hey @gs8nrv, it appears that there’s still negative numbers getting returned

Overall, I’m a bit worried about the complexity of this adapter. There’s quite a lot of logic in the adapter, some of which should probably be moved to the subgraph level. There shouldn’t really be “aggregation” being done in the adapter itself, that’s a task that’s better to be handled in the subgraph itself.

One other small optimization: Whenever doing a gt/lt comparison (such as timestamp_lt: $timestamp), it’s important to bound that search (such as timestamp_lt: ${timestamp}, timestamp_gt: ${timestamp - 100}.

Overall, I’d suggest we chat a bit more on Discord about the direction of this adapter. You’ve clearly done a lot of work building a powerful adapter! But I don’t feel very comfortable with the current state of it.

Uploaded a new one (Angle Labs Adapter - CryptoStats), I made a poor choice to use different exchange rates between 2 dates → making negative values by looking at the differences).

Yes let’s chat on Discord, but the adapter itself has nothing fancy I can walk you through it will make more sense I guess.

Thank your for your time @David

Hi @David, I have simplified the code a lot, I think we are ready for your review.

Here is the new hash: QmVFDWB3a8WRSMbfuiYttZgP7mQa4GvbiiwfXV2Bj5seW6

Thank you a lot

Thanks for the update! Just looked over the newest adapter, and it looks a lot better!

One issue is that I believe the date calculations are wrong: when provided a date, it subtracts one day to set the date bounds, instead it should be adding one date. For example, if I’m querying data on October 1, i’m looking for all fees between October 1 and October 2.

Furthermore, if you query for the current day, it will return the partial fees for that day, instead it should throw an error or return null. This can be addressed by throwing an error if the tomorrow query returns null.

Thank you for the answer, I fixed the first issue but the second one is harder in my case as the tomorrow query will never return null - it will return the last datapoint available. Is there a way to just fetch the current date from the sdk library?

Hi David, I updated it with your comments: QmT9Lmp3qU95KhL7pYP3qjaMVYNrFA9WQc3GyNi7xpu3L7.

Thank you :+1: