0xSplits / splits-contracts

Core smart contracts of 0xSplits
GNU General Public License v3.0
158 stars 34 forks source link

Programmatically Query Distributed Balances Ready for Withdrawal & Percent Splits #2

Closed codesport closed 2 years ago

codesport commented 2 years ago

Hi Guys,

How would you recommend that we query the percentage splits and balances distributed, but not withdrawn for each split recipient from with our dApp?

This info is available from the UI (via the navbar) on your site. But we'd like for our users to see this from within our dApp.

Thanks!

wminshew commented 2 years ago

have you checked out the subgraph? for active balances I believe you need to query SplitMain

codesport commented 2 years ago

Thanks @wminshew

Will check it out. Haven't looked into that yet but wanted to get advice before diving down a potentially misdirected rabbit hole.

We went through SplitMain.sol and its Nat spec with a fine tooth.

You guys did an impressive job!

Speaking of, it seems those balances are emitted as events, but wanted to ask you guys if there was another way to grab.

The answer is yes. So will dig into your subgraph repo.

wminshew commented 2 years ago

the subgraph is good for a lot of split metadata (current recipients in particular) but I don't think it's actually the right place to look for balances atm (technically events are emitted on receives so it /could/ track eth balances but there's no way for it to track erc20 balances from transfer events based on how subgraphs work so we kept them at parity)

@mihoward21 can weigh in more here

might also be easier / more fluid to have this conversation in our discord

codesport commented 2 years ago

Thanks for the tip.

Glad I left the issue open for you to provide the add'l datapoints.

Just wondering how much developer time and resources are needed to integrate with subgraph. Will head over to Discord.

mihoward21 commented 2 years ago

yes, as @wminshew mentioned subgraph has basically all the info about each split except the current balances. That's how we build our frontend, grab everything from subgraph and then getEthBalance and getERC20Balance for the balances.

Hopefully it's not too much work to integrate with the subgraph, especially if you are familiar with graphql. Happy to help answer any questions or provide sample queries or anything.

mihoward21 commented 2 years ago

We are planning to work on an sdk over the coming weeks/months to make this kind of development simpler. So would definitely love to hear any specifics on what exactly would be most helpful for you all.

codesport commented 2 years ago

yes, as @wminshew mentioned subgraph has basically all the info about each split except the current balances. That's how we build our frontend, grab everything from subgraph and then getEthBalance and getERC20Balance for the balances.

Hopefully it's not too much work to integrate with the subgraph, especially if you are familiar with graphql. Happy to help answer any questions or provide sample queries or anything.

Thank you @mihoward21. We are a small Blockchain team and will have to allocate a developer resource to focus on subgraph.

So, if you feel comfortable sharing any starter code in querying subgraph for 0xSplits accounts we would be grateful.

Our original thinking was to capture past events via Event Filter's contract.queryFilter method and store results in a DB. But, subgraph is more efficient way of doing things.

Feel free to close out this "issue" as it was more of a request for direction and guidance. And, you've provided us a clear path to move forward.

Thanks again for launching this great project and for your help!

mihoward21 commented 2 years ago

So there's a bunch of libraries then can help manage graphql requests from the client. Apollo is the most popular, but there's a bunch of other options too you can check out here. Not sure we can help out a ton for setting that up, depends on the app you have, framework you're using, etc.

But the actual queries to fetch data from the subgraph we are happy to help with. There's a couple samples already in the playground section on the subgraph page.

If you are looking for data on the users, that is all available in the subgraph. Withdrawn amounts and active balances waiting to be withdrawn are both there for users. It's only if you need to fetch the active balances for any splits that you'll need to make requests to split main.

If there are other questions or anything else we can help out with just let us know!

codesport commented 2 years ago

@mihoward21

Thanks again for the assist!

Your subgraph repo definitely has what we need: https://github.com/0xSplits/splits-subgraph