Giveth / impact-graph

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[7 MARCH] Periodically fetch stream end dates and donation data

divine-comedian opened this issue · comments

For users to be notified when their super token balances are about to run out we'll have to check periodically their balance & net flowrate (max one time daily) for each token, for each chain and trigger an email & notification if conditions are met.

  • stream balance has < 1 month left at current flowrate
  • stream balance has < 1 week left at current flowrate
  • their recurring donations were ended because their stream balance ran out

each notification should only trigger once and they all should be reset when the user has modified their stream balance (withdrawn or deposited tokens). Related to Giveth/notification-center#62

In the subgraph we do have many options to experiment with to find the most efficient way of getting data
https://docs.superfluid.finance/superfluid/developers/subgraph

Can also see the accounting API:
https://superfluidhq.notion.site/Using-the-Stream-Accounting-API-3d161745acfe4750acf43c546f84c724
https://accounting.superfluid.dev/v1/swagger

@jainkrati to do more research on https://powerpool.finance/ to see if it can handle this computation job

We'll do background cronJobs to query the status of recurring donations and update their status in the Giveth DB

We need to update the amount of tokens donated and the USD value on a daily basis.

we'll need some way to know the amount of tokens donated and usd value between two dates for calculating QF and GIVbacks

related to #1483 and Giveth/giveth-dapps-v2#3284

Since powerpool will charge us per use, as of now we are dropping powerpool integration. Instead, we will continue the normal way we automate blockchain calls - using cron job.

In order to calculate the amount of tokens donated by each person, we will need to create a new table in database for recurring donation per person (including the equivalent $ or fiat value donated in this interval) where we add a donation record every 6 hours or 10 hours or N hours depending on token price fluctuation (the duration for which token price is stable). This duration could be different for different tokens. Example: For token A, we can calculate donation dollar equivalent every X hours and for Token B every Y hours and so on. Then we will write an API which simply queries the sum of all such donations in a specific interval for a person or everyone etc

Just adding this here, I would definitely check out the accounting API I mentioned above
https://accounting.superfluid.dev/v1/swagger

This allows us to track multiple tokens streamed between two periods of time and its USD value for a specific address

This takes in a couple parameters:

  • account addresses (our project recipient address/anchor contract address - it can take in an array of addresses into a single query)
  • start date to query
  • end date to query until
  • virtualization period (at what time intervals should we separate the data into e.g. days/weeks/months/years)
  • price granularity (take an average of the price over how long of a period e.g. days/weeks/months/years)
  • currency (USD/EURO etc...) fiat value to show
  • counterParties (if you want to query for a specific other address such as sender/receiver related to account(s) your looking up)

the response gives you the total amount of tokens and its usd value split up into the virtualization periods you specified for the timestamp range you gave. it will split up the responses if the flowrate was changed during the timestamp ranges (donor increased or decreased their flowrate)

So for the cronjob service it might be as easy as querying this API, making some calculations (to get the total) with the returned info and saving it somewhere.

You can see a detailed example in their documentation:
https://superfluidhq.notion.site/Using-the-Stream-Accounting-API-3d161745acfe4750acf43c546f84c724

@mohammadranjbarz please take this up. @aminlatifi can also weigh in on the high level plan.

@divine-comedian could you setup 20 min thursday sometime to set context and invite me, mohammad and @aminlatifi

Is this same as #1243 @divine-comedian ? if yes can we keep only one?

@CarlosQ96 This is another issue related to get recurring donation info from blockchain

Is this same as Giveth/giveth-dapps-v2#1243 @divine-comedian ? if yes can we keep only one?

I had to look at both issue to double check what I wrote :P I will close Giveth/giveth-dapps-v2#1243 as I think this issue has more context inside of it

@CarlosQ96 to begin on this today.

Mohammad left a cronjob to put the logic for this there. Carlos needs to fill in the logic

Everyday we check the donation and create a stream donation for it

How do we show the total donated amount

when we check everyday we need to update the totalDonated field and totalDonatedUSD

call the accounting API everyday and save it as a new donation each day but we hide it on the front-end
use the recurring donation table with all the total but there is also all the small donations associated with it - the mini donations will be flagged

won't be an issue for database size since we include it from most queries

run cronjob everyday to check the status - add the new donations and see if the recurring donation is still active if it isn't (user ran out of funds or they ended the stream themselves we mark it as finalized)

We need to also run this subgraph query on each donor to know when their super token balances will run out (and their recurring donaitons will end from insufficient funds

query MyQuery {
  account(id: "") {
    accountTokenSnapshots {
      token {
        id
        name
      }
      maybeCriticalAtTimestamp 
    }
  }
}

Date of Completion 22st feb

Ok I added the logic for knowing which super tokens are almost running out.
@divine-comedian if we can meet tomorrow to check the notification logic that was done with Ramin, so we can send the notification would be good.

Related to #1148

Finishing Donation Creation Logic, will push tomorrow.

Carlos needs test Anchor Contract with recurring donations.. can @alireza-sharifpour or @MohammadPCh help

Regarding the help Alireza provided, the api of superfluid is blocked by this.
Optimism Goerli was deprecated.
I cannot test with said Data. For now using Mock adapters for the tests.

I requested from superfluid to add optimism sepolia. They will do it this week and that it shouldnt take a lot of time.

We should in the mean time also add optimism sepolia to our networks and contract, in a separate issue related to this too.

So I'm currently blocked by not having real tests at the moment.

@CarlosQ96 pls create another issue for tests and merge this PR to unblock FE.

This issue is on in progress in zenhub board, is the status correct in zenhub ? or It should be in UAT status and is ready for testing? @CarlosQ96

and I couldn't understand the acceptance criteria of this issue could you please tell me more about this? @divine-comedian

In order for this to pass we should ensure the following:

  • When an already active recurring donation enters into having less than one MONTh left of it's stream balance you should receive a notification.
  • When an already active recurring donation enters into having less than one WEEK left of it's stream balance you should receive a notification.
  • USD values of total donated and total donated token amounts should show up correctly after a recurring donation has been running for a while

@CarlosQ96 - maybe we should find some test values when you make this cronJob so testing can be done faster than one month 😂

We could try 30 mins / 1 hour

The USD values might be off since they are tricky/not available for some tokens on OP Sepolia but we need to make sure they work properly with production values.

  • When an already active recurring donation enters into having less than one MONTh left of it's stream balance you should receive a notification.

If I set a recurring donation for only 1 month , should I receive a donation?
for example I set 1 month and now rounds out is <1 , I didn't receive any notification for this

image

@maryjaf - it could be that this isn't hooked up to the notification center or it isn't finished yet @CarlosQ96 is there a way to test this right now?

  • When an already active recurring donation enters into having less than one MONTh left of it's stream balance you should receive a notification.

If I set a recurring donation for only 1 month , should I receive a donation? for example I set 1 month and now rounds out is <1 , I didn't receive any notification for this

image

I've tested this and it should be assigned to the developers again to completing implementation because the tests were failed
@jainkrati @divine-comedian

@CarlosQ96 pls take this up

related to: #1431 merged

I didn't receive any notification and email for recurring donation (more than 1 $) @CarlosQ96 @RamRamez

This is my last recurring donation and it was more than 1 $

https://optimism-sepolia.blockscout.com/tx/0x38dbe9bcda631031a9feac355f54420c6d016234d2a779bcd504df0c27b22187
image
image

It seems it's related to this
#1416 (comment)
the tests haven't been passed

@MohammadPCh I put it back into in-progress, needs your attention! thanks

I put it to done and we continue testing on notif issue #1416 AND
Giveth/notification-center#62