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

Add query support for Distribution module #1154

Closed
JakeHartnell opened this issue Oct 30, 2021 · 5 comments · Fixed by #1788
Closed

Add query support for Distribution module #1154

JakeHartnell opened this issue Oct 30, 2021 · 5 comments · Fixed by #1788
Milestone

Comments

@JakeHartnell
Copy link

Was talking with @sgoya about a contract and it would be really nice to be able to query the distribution module like we can query the staking or bank module. Something like query_all_rewards or query_rewards similar to query_all_balances and query_balances in QuerierWrapper would be really useful.

Have some folks that would be willing to contribute to this if you could provide some pointers.

@webmaster128
Copy link
Member

Is this still relevant? A contract querying the distribution module is interesting for a contract that stakes, right? Maybe you could explain more about the use case to help understanding the motivation and figure out which queries matter the most.

@JakeHartnell
Copy link
Author

Is this still relevant? A contract querying the distribution module is interesting for a contract that stakes, right? Maybe you could explain more about the use case to help understanding the motivation and figure out which queries matter the most.

I think it is still relevant. Staking contracts are a very interesting design space. Here are couple examples of thing's I've discussed with folks:

  • Use case 1: a "self-repaying loan" protocol where the user deposits tokens, the contract stakes them, and the loan gradually repays itself. Users would want to know how much remains to be paid, and thus the contract would need to query_rewards.

  • Use case 2: a staking contract that equally delegates stake equally between a number of validators. Users would want to know the staking rewards available to claim, and for that the contract would need to query_all_rewards.

  • Use case 3: a contract calculates voting power in a Validator DAO. This would require querying how much a user has staked to a particular validator.

@ethanfrey
Copy link
Member

I agree with this. We support a number of StakingQueries, we should expose some one rewards.

Not sure if to extend StakingQuery or add a new QueryRequest::Distribution variant.

Let's define the exact queries we want.

@webmaster128
Copy link
Member

Thank you for opening the discussion. I'm tracking this in #1521 now to make sure we are talking about the same queries and we have an efficient backend for them.

Use case 1: a "self-repaying loan" protocol where the user deposits tokens, the contract stakes them, and the loan gradually repays itself. Users would want to know how much remains to be paid, and thus the contract would need to query_rewards.

This would be distribution/DelegationRewards "queries the total rewards accrued by a delegation [= delegator, validator pair)].".

I guess this is what wallets show as pending rewards and the value get zeroed on MsgWithdrawDelegatorReward. Those pending rewards will hardly match exactly what is withdrawn due to all the rounding in place. So I assume this is only useful for queries between the withdrawals.

Use case 2: a staking contract that equally delegates stake equally between a number of validators. Users would want to know the staking rewards available to claim, and for that the contract would need to query_all_rewards.

This would be distribution/DelegationTotalRewards "queries the total rewards accrued by a each validator". I don't understand this doc string but seems to be everything that can be claimed by a delegator across multiple validators.

Use case 3: a contract calculates voting power in a Validator DAO. This would require querying how much a user has staked to a particular validator.

This is staking/Delegation which should be available.

@webmaster128 webmaster128 modified the milestones: 1.2.0, 1.3.0 Nov 29, 2022
@webmaster128
Copy link
Member

webmaster128 commented Jul 17, 2023

Let's start with those:

  • DelegationRewards
  • DelegationTotalRewards
  • DelegatorValidators
  • DelegatorWithdrawAddress (done in 1.3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants