forbole / big-dipper-2.0-cosmos

https://bigdipper.live
Apache License 2.0
142 stars 336 forks source link

Logic behind the voting power % calculation #614

Closed alexdonh closed 2 years ago

alexdonh commented 2 years ago

Hello folks,

Can someone help explain the logic of voting power % calculation below:

https://github.com/forbole/big-dipper-2.0-cosmos/blob/dd2523bc256a15f1af014d9af3350052c81108e3/src/screens/validator_details/components/voting_power/index.tsx#L24

in short:

votingPowerPercent = data.self / data.overall * 100 

where self is:

https://github.com/forbole/big-dipper-2.0-cosmos/blob/dd2523bc256a15f1af014d9af3350052c81108e3/src/screens/validator_details/hooks.ts#L283

(= the validator's voting power)

and overall is:

https://github.com/forbole/big-dipper-2.0-cosmos/blob/dd2523bc256a15f1af014d9af3350052c81108e3/src/screens/validator_details/hooks.ts#L303

(= total bonded tokens)

I understand that the formatToken will divide this total bonded tokens by bondDenom's exponent which is normally 6 but what if you have a different exponent set?

ryuash commented 2 years ago

Then you would have to manually change the following line to the denom you want:

https://github.com/forbole/big-dipper-2.0-cosmos/blob/dd2523bc256a15f1af014d9af3350052c81108e3/src/screens/validator_details/hooks.ts#L305

We had a similar case with likcoin where the default denom was nanolike with 9 exponent places but the voting power was actually 6 decimal places. What I ended up doing was creating a ulike with 6 decimal places in the config and instead of relying on stakingParams.bondDenom I manually replaced it with ulike

https://github.com/forbole/big-dipper-2.0-cosmos/blob/b62fde196aa16961db8e03ef5c60e6b6423d8b02/src/screens/validator_details/hooks.ts#L304

and here is the config file: https://github.com/forbole/big-dipper-2.0-cosmos/blob/chains/likecoin/src/configs/chain_config.mainnet.json

As these cases do not happen often I think a manual change is quite alright for the time being

alexdonh commented 2 years ago

Thanks @ryuash but still i don't get the part dividing voting power by total bonded tokens. those 2 are basically different units. I will do a workaround as your suggestion for now.

ryuash commented 2 years ago

A chain's bonded tokens represent the number of active voting power present.

Example 1: 1 VP in Cosmos Hub can be represented by 1 ATOM but since I am referencing bonded tokens, 1 ATOM will be represented as 1000000uatom hence the formatting in the code (converting uatom -> atom)

Example 2: 1 VP in Likecoin is 0.001000000LIKE so instead of formatting the bonded tokens by the default 9 decimal places i formatted it by 6 (nanolike -> ulike) for the purposes of calculating the voting power

ryuash commented 2 years ago

Closing. Feel free to open back up if there's more questions regarding this issue