Skip to content

[tg4-stake] TotalPoints query shouldn't return denom #147

Closed
@maurolacy

Description

In confio/tgrade-contracts#361 we added denom to the TotalPoints (then called TotalWeight) query response.

The idea was to provide a way for querying the total staked amount. But this is wrong, because of tokens_per_point, which is a conversion factor between tokens and points. If tokens_per_points is different than 1, this query reports an incorrect staked amount.

Alternatives are:

  • Multiply the total points by the tokens per point when building the response to this query. This will only give an approximate (inferior, due to rounding) value of the real staked amounts. It also does not differentiate between liquid and vesting stakes.
  • Implement a ListStakers query, which returns the list of staked amounts (both liquid and vesting) per member. This query can then be used to compute the total staked amount (liquid and / plus vesting) on the client when needed.

The second option is clearly the preferred one. It differentiates between points and tokens, and provides detailed (per member) and discriminated (liquid vs. vesting) results. It will also keep the TotalPoints query in tg4-stake compatible with the other tg4 contracts.

Additionally, implement a TotalStakes query, to return both liquid and vesting totals. For this to make sense, the running staked totals should be stored in contract state (similar to how the running TOTAL points are currently stored).

Update:

There's a Staked

// Show the number of tokens currently staked by this address.
Staked {
address: String,
},
query already in the staking contract, that can be used to get a member's staking amounts. So, ListMembers can be combined with calls to Staked to get total staked amounts from tgrade (if needed), or from a client.

So, a simple alternative would be to modify tgrade's QueryStakedAmount https://github.com/confio/tgrade/blob/1b5973372834bfc17a34edc685a92a2d0bba40df/x/poe/contract/tg4_stake.go#L146-L159

to use this query first, to get staked amounts per member. And then, use an iteration on it to get total stakes if needed.

Update 2:

tgrade-app does use the TotalPoints query (https://github.com/confio/tgrade-app/blob/3f7d271c6fa8537c3dfe2822fbd4e903fbd284c8/src/utils/staking.tsx#L21-L24). So, that will need to be modified / adjusted accordingly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions