Help on a Reward sharing smart contract

What is the best way to implement a contract that calculates a user trading volume over a 6400 blocks and a reward sharing smart contract that divides user volume by total volume

Is every trade recored in a smart contract in the first place? Is it a new smart contract for an existing token that has already been traded?

Is a prediction smart contract, and reward is given by a user total volume in the prediction over 24 hours or 6400 blocks.

Yes every trade is recorded

It sounds very much like the methodology adopted by the uniswap V3 oracle. The exact details may be different.

Can you please explain more

What I really need is just an idea of how to create the smart contract or the smart contract of a reward Sharing contract interacting with let me say a lottery smart contract which stores the total volume a user has betted through out a 6400 blocks or 24 hours, so I can show it on a leaderboard

Why does it have to be stored on chain? Can't it be calculated off-chain?

Am looking at the security impact... If it's created offchain anyone can send fake data to the Blockchain.
Explain your idea to me

The quantity of target can be calculated by Dune Analytics. That is totally off-chain, however, there is still trust in it.

Dune analytics, I need to make a research about that