pdr-backend
pdr-backend copied to clipboard
[Lake] Calculate df and stake revenues for silver predictions table
Target of this ticket is to discuss and determin how to calculate the data farming and stake revenues for a slot.
The requirement is found in #618 but because this could be a higher complexity task and might require other tables decided to get it out into a separate issue and write down all the requirement here:
- [x] make sure all the subscriptions related data is fetched
- [x] add a list of addresses used by df to purchase the subscriptions
- [x] create a method that can filter a table based on df/non df addresses and returns the specific table
- [x] create a method that calculates the revenue for each contract+user+slot. For this we also need to read from pdr_slots table to get all the stakes from the specific slot.
- As a first step we could filter out subscription based revenue from the stake revenue: This is easy to do and doesn't require any extra data, just subtract the staked amount from the revenue
- In the second step we could further split the subscription based revenue into data farming and user purchase: In this step we need to query the subscription purchases from the subgraph and filter them based on address so we know how much is coming from data farming and how much from other users.
After knowing how much OCEAN tokens are coming for each inflow, calculate the slot revenues
How payout is calculated:
` uint256 amt_perepoch_start = amount / numepoch_starts
uint256 swe = trueValues[epoch_start] ? roundSumStakesUp[epoch_start] : roundSumStakes[epoch_start] - roundSumStakesUp[epoch_start];
if(swe > 0) { uint256 revenue = amt_perepoch_start; payout_amt = predobj.stake * (roundSumStakes[epoch_start] + revenue) / swe; }else{ payout_amt=0 } `
This is performing slowly. Calculating revenue & updating needs to lookback to get info. Let's review and improve the query.