osmosis
osmosis copied to clipboard
Create SuperfluidDelegationsByValidator and SuperfluidDelegationsByAsset GRPC Queries
Background
ATM, the SFS module has ABCI queries for the total amount of Osmos SFS staked & some more granular queries. Specifically, there are queries for SFSDelegationsByDelegator and SuperFluidDelegationsByValidatorDenom.
I run an analytics dashboard for tracking SFS usage. To get the total number of Osmos SFS delegated by a pool or validator, I have to make V*A ABCI Queries where V is the number of Validators and A is the number of SFS Assets. Even if I limit my searches to the active set, that is 135 * 15 = 2025 ABCI Queries ATM.
If either number grows, which is a reasonable expectation, then this number increases dramatically. I can't use SFSDelegationsByDelegators as there's no ABCI Query for the entire list of delegators using SFS. I'd have to get a state export and then make an ABCI query for every user w/ a 14 day lock to see if they have any SFS Delegations. The number of users w/ 14 day locks far exceeds V*A, ~156k 14 Day Locks when I last checked.
Suggested Design
Implement SFSDelegationsByValidator and SFSDelegationsByDenom ABCI Queries. They don't have to return the estimation of Osmos delegated. Simply returning the delegations for a Validator/Asset. This would reduce the number of queries to V + A and remove any scalability concerns.
An alternative would an ABCI Query that lists all SFSDelegations. I can't think of a similar query in the CosmosSDK so that may break from the usual convention. There also may be bandwidth/spam concerns (i.e. someone spam requesting a large ABCI Query from a node to increase its bandwidth out significantly) with this solution.
Listing all SFS delegations is going to be a bit hard, because then you have to paginate it. Right now pagination in the SDK is too naive, and means you have to literally read pages 0 through N, in order to return page N+1...
Sounds like we just need one of the two queries supported right?
If I understand correctly, we could make a single query TotalDelegationByValidatorForAsset( asset: string ) [](validator addr, amount of asset SFS'd, equivalent osmo amount) right?
That works! Users can aggregate from there if needed and it reduces the number of queries needed too.