Help with a Leaderboard smart contract with a reward token

I need help in building a leaderboard smart contract which interacts with another smart contract let's say pancakeswap lottery smart contract.... Then it displays users in a leaderboard according to total amount spent on the lottery and rewards them with a reward token.
If you can help me with the smart contract or an idea