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:
https://github.com/infu/sonic_contrib_volume
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