Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
divine-comedian opened this issue Oct 6, 2023 · 29 comments
Closed
Assignees

Comments

@divine-comedian
Copy link
Collaborator

divine-comedian commented Oct 6, 2023

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

@divine-comedian
Copy link
Collaborator Author

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

@divine-comedian
Copy link
Collaborator Author

divine-comedian commented Jan 16, 2024

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

@divine-comedian divine-comedian changed the title Periodically fetch stream end dates Periodically fetch stream end dates and donation data Jan 16, 2024
@jainkrati
Copy link
Collaborator

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

@divine-comedian
Copy link
Collaborator Author

divine-comedian commented Jan 16, 2024

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

@jainkrati
Copy link
Collaborator

jainkrati commented Jan 29, 2024

@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

@jainkrati
Copy link
Collaborator

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

@mohammadranjbarz
Copy link
Collaborator

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

@divine-comedian
Copy link
Collaborator Author

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

@jainkrati
Copy link
Collaborator

@CarlosQ96 to begin on this today.

@divine-comedian
Copy link
Collaborator Author

divine-comedian commented Feb 13, 2024

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 
    }
  }
}

@jainkrati
Copy link
Collaborator

Date of Completion 22st feb

@jainkrati jainkrati changed the title Periodically fetch stream end dates and donation data [22FEB]Periodically fetch stream end dates and donation data Feb 21, 2024
@CarlosQ96
Copy link
Collaborator

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.

@CarlosQ96
Copy link
Collaborator

Related to #1148

@CarlosQ96
Copy link
Collaborator

Finishing Donation Creation Logic, will push tomorrow.

@jainkrati jainkrati changed the title [22FEB]Periodically fetch stream end dates and donation data [23FEB]Periodically fetch stream end dates and donation data Feb 22, 2024
@jainkrati
Copy link
Collaborator

jainkrati commented Feb 22, 2024

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

@CarlosQ96
Copy link
Collaborator

CarlosQ96 commented Feb 26, 2024

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.

@CarlosQ96
Copy link
Collaborator

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

@jainkrati
Copy link
Collaborator

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

@jainkrati jainkrati changed the title [23FEB]Periodically fetch stream end dates and donation data [7 MARCH] Periodically fetch stream end dates and donation data Mar 7, 2024
@jainkrati jainkrati assigned maryjaf and unassigned CarlosQ96 Mar 11, 2024
@maryjaf
Copy link
Collaborator

maryjaf commented Mar 12, 2024

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

@divine-comedian
Copy link
Collaborator Author

divine-comedian commented Mar 12, 2024

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.

@maryjaf
Copy link
Collaborator

maryjaf commented Mar 13, 2024

  • 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

@divine-comedian
Copy link
Collaborator Author

@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?

@maryjaf
Copy link
Collaborator

maryjaf commented Apr 2, 2024

  • 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

@maryjaf maryjaf removed their assignment Apr 2, 2024
@jainkrati
Copy link
Collaborator

@CarlosQ96 pls take this up

@CarlosQ96
Copy link
Collaborator

related to: #1431 merged

@maryjaf
Copy link
Collaborator

maryjaf commented Apr 3, 2024

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

@jainkrati jainkrati assigned MohammadPCh and unassigned CarlosQ96 Apr 3, 2024
@maryjaf
Copy link
Collaborator

maryjaf commented Apr 7, 2024

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

@MoeNick
Copy link
Member

MoeNick commented Apr 7, 2024

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

@MoeNick
Copy link
Member

MoeNick commented Apr 7, 2024

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

@MoeNick MoeNick assigned RamRamez and unassigned MohammadPCh Apr 7, 2024
@maryjaf maryjaf closed this as completed Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants