27 lines
567 B
Go
27 lines
567 B
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
"math"
|
|
|
|
sdk "git.cw.tr/mukan-network/mukan-sdk/types"
|
|
)
|
|
|
|
// GetVotingPower calculates the quadratic voting power of an address.
|
|
// Voting Power = sqrt(MC Amount)
|
|
func (k Keeper) GetVotingPower(ctx context.Context, address string) float64 {
|
|
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
|
accAddr, err := k.addressCodec.StringToBytes(address)
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
|
|
balance := k.bankKeeper.GetBalance(sdkCtx, accAddr, "umc")
|
|
amount := balance.Amount.Int64()
|
|
|
|
if amount <= 0 {
|
|
return 0
|
|
}
|
|
|
|
return math.Sqrt(float64(amount))
|
|
}
|