interlay / interbtc-squid

Subquid GraphQL schema and indexer for the Interlay and Kintsugi networks
Apache License 2.0
4 stars 7 forks source link

Add query to fetch amount of non-vested staked INTR #59

Open alexeiZamyatin opened 1 year ago

alexeiZamyatin commented 1 year ago

Is your feature request related to a problem? Please describe. Currently, we only query how much INTR was staked in total. However, it is possible to stake both liquid and unvested INTR. This makes it impossible to check how much of the actual liquid supply has been staked. This metric is important to understand the attractivity of staking as a product and user behavior (unvested tokens "mess" this up because there is nothing else users can do with these unvested tokens).

Describe the solution you'd like Add a query to compute how much vested (i.e., liquid) INTR has been staked. Note: unvested = cannot be claimed. The query should exclude tokens that are theoretically vested but have not yet been claimed yet (users must manually call vesting.claim() to actually make the vested share of tokens transferable in their account).

Describe alternatives you've considered None

Additional context Note that storage keys for user accounts are different for each pallet. This is probably a non-issue for squid but adding just in case - this is how to convert storage keys to actual accounts in JS:

   const vestingSchedules = await api.query.vesting.vestingSchedules.entries();
    const vestingAccounts = vestingSchedules.map(([key, _]) => key.args[0].toHuman());
    const escrowLocked = await api.query.escrow.locked.entries();
    const escrowAccounts = escrowLocked.map(([key, _]) => key.args[0].toHuman());

storage key (in this case) is basically [pallet, itemName, mapKey] hence key.args[0] to get the mapKey - the account