Proposal to add Volume Tracking in SONIC v1 swap

We are proposing the addition of volume tracking in Sonic DAO V1 swap contract.
By: Anvil / ICPCoins

It will allow Sonic DAO to track the volume of different pairs over a rolling 24-hour window.
Why is it needed? Sonic DAO currently relies on off-chain graphQL for volume and charts. ICPCoins and other contracts on the IC can’t access that API on-chain.

Repo with the code we are proposing and details:

The code was made separately because we don’t have Sonic’s testing tools to try it out.
It’s easy to add. And once added Sonic developers can finish testing it and deploy it with a proposal.

Copy and paste inside the contract and insert one line in the ‘_swap’ function.
We have made it for the existing contract and that is why it doesn’t use any new libraries.
The repo also contains unit tests.

Security note:
The _swap function calls the function we propose to add. If it traps for some reason the whole swap will be reverted and nothing will change.
Memory - it takes a small & fixed amount of memory and doesn’t grow.
Performance - not a concern - two hashmap ops and recreation of 24-element Nat array



We should probably add that ICPSwap didn’t have such tracking a few weeks back and its charts looked like this ( resetting volume every 24 hours)
After an update, they started using a rolling window
Judging by ICDex charts
They are also using rolling windows or something similar.
Once Sonic adds it, all 3 dexes will report volume similarly.


I can’t stop being impressed by you Infu :star_struck:

Thanks for this effort and open contribution. I follow Sonic and I +1 that this effort is needed. Even for everyone to be more aware and compare the changing volumes on different coins (maybe important for liquidity pools).

Thanks again, hope Memecake and his team can use and implement it.


We have made a standalone canister that follows CAP history.
Next: Going to add Sonic volume to Icpcoins :sparkler:

1 Like