Giveth / impact-graph

MIT License
49 stars 18 forks source link

[3rd April] Save & Retrieve recurring donation data for projects #1142

Closed divine-comedian closed 6 months ago

divine-comedian commented 1 year ago

We'll need to save & fetch certain information to show user's & project owners data regarding a given donation stream. In order to query the information we need to check the stream between the donor & recipient address (or anchor address (allo protocol))

When a superfluid stream is created through the Giveth UI we should save the following information to our back-end:

We identify the stream on the subgraph or other superfluid service by the sender, receiver & token and we can alias it to Giveth by the saved projectId in our DB.

When we need to fetch the data in the case of showing recurring donations for donors & project owners (public & private view) this will allow us to know exactly what to query.

Optimism

https://console.superfluid.finance/subgraph?_network=optimism-mainnet

OP Goerli

https://console.superfluid.finance/subgraph?_network=optimism-goerli

Private Zenhub Image

related to https://github.com/Giveth/giveth-dapps-v2/issues/3093 , https://github.com/Giveth/giveth-dapps-v2/issues/3092

divine-comedian commented 11 months ago

@jainkrati - I'm second guessing myself on this one - Do we need back-end services on this one or can we handle it all from the front-end with the subgraph to get recurring donation (stream) data?

mohammadranjbarz commented 11 months ago

@divine-comedian Good question, if frontend can communicate with subgraph directly, in the backend side we just need to fetch donation data fro superfluid and insert new record in our DB?

divine-comedian commented 11 months ago

@divine-comedian Good question, if frontend can communicate with subgraph directly, in the backend side we just need to fetch donation data fro superfluid and insert new record in our DB?

I guess the subgraph can fetch most of the relevant data for a given stream - For each stream made we should save it (defined by sender & receiver) so we can know all of the streams that are associated with Giveth and then we don't have to sort the subgraph data to know which ones are related to Giveth and which ones are not.

This would be relevant when we show data on the public & private view of user recurring donations and also projects receiving recurring donations from users.

divine-comedian commented 11 months ago

When the user makes a recurring donation we save the 4 following pieces of info to our DB:

When we need to retrieve stream data we can use this to query the subgraph

mohammadranjbarz commented 10 months ago

@divine-comedian @MohammadPCh @alireza-sharifpour Do we have some test TXs for creating anchor contract and create recurring donation?

MohammadPCh commented 10 months ago

@mohammadranjbarz This is a batchCall tx: https://goerli-optimism.etherscan.io/tx/0xb68fb77e70a34efbcc19448a6f5b638b5cf2ecabf5a97f13981dceadea44cd74

mohammadranjbarz commented 10 months ago

@mohammadranjbarz This is a batchCall tx: https://goerli-optimism.etherscan.io/tx/0xb68fb77e70a34efbcc19448a6f5b638b5cf2ecabf5a97f13981dceadea44cd74

Thanks, @MohammadPCh but don't you have any non-batch transaction?

MohammadPCh commented 10 months ago

@mohammadranjbarz We batch most of our transactions, we have 4 types of transactions:

  1. only wrap (this is not a donation transaction)
  2. Batch: Wrap + Create Donation to Project + Create Donation to giveth
  3. Batch: Create Donation to Project + Create Donation to giveth
  4. Modify Donataion to a Project
divine-comedian commented 9 months ago

@mohammadranjbarz - I just added another piece of info - saving the txHash of when the recurring donation is created - we'll need this to show on the project donation table.

Also we'll need to know when a recurring donation stream has ended and then update it in the DB - so you might need to add a boolean field to indicate if the stream is active or not

As for knowing if its active or not we might need to follow it in this issue: https://github.com/Giveth/impact-graph/issues/1148

mohammadranjbarz commented 9 months ago

I suggest we add two tables for this feature

Entities

  1. AnchorContractAddress
name type required description
networkId integer yes
txHash string yes
chainType string yes SOLANA | EVM
address string yes
project Project yes
anchorContractAddress AnchorContractAddress yes
creator User yes
owner User yes
  1. RecurringDonation
name type required description
networkId integer yes
txHash string yes
chainType string yes SOLANA | EVM
project Project yes
anchorContractAddress AnchorContractAddress yes
donor User yes
  1. RecurringDonationStream For it doesn't need to create new table, we can add few fields to current donation table to show it's a recurring donation stream

Flow

We should follow https://github.com/Giveth/giveth-dapps-v2/issues/3477#issuecomment-1850182341 that @divine-comedian designed it.

These are the steps based on that diagram:

  1. Create anchor contract for project if not exists
  2. Create a recurring donation for a project with needed params
  3. Every day we get recurring donation info from network and create a stream donation related to that recurring donation, in this way we would know how much of a recurring donation is related to this round, and filling price, givback params, ...
  4. If recurring donation has been stopped we mark that as finished in our DB

@divine-comedian @jainkrati If you have comments on it please let us know @mateodaza I has implemented some of them in https://github.com/Giveth/impact-graph/pull/1194 so you can read it and continue on that PR ( I will focus on that as well) but I think first step for you can be have get stream info of a recurring donation from network (I think we use all protocol or something like that) I can continue other parts then integrate them, WDYT?

jainkrati commented 8 months ago

Date of Completion : 21st Feb to unblock FE

CarlosQ96 commented 8 months ago

I checked the logic done by Mohammad that was merged, and validated the flow with Mitch, I think what is implemented is enough. To finish the flow. @mohammadranjbarz right?

Aside from maybe getting the final amount, which im almost done, but thats part of the https://github.com/Giveth/impact-graph/issues/1148 issue.

jainkrati commented 8 months ago

@MohammadPCh this is ready to integrate

maryjaf commented 7 months ago

I'm not aware about this issue could you please help me on this @mohammadranjbarz @MohammadPCh is it ready for testing? it's on inprogress and assigned to me

MohammadPCh commented 7 months ago

@maryjaf As I know, @mohammadranjbarz is working on it. there is a problem with some batchCall that he talked about on the call, he is trying to figure it out.

jainkrati commented 7 months ago

Mohammad to take a look at the telegram and follow up on batch call issues

maryjaf commented 7 months ago

The problem related to batch call donation also has been resolved