add denoms to config

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2023-09-05 11:03:42 +02:00
parent 05a484c8b9
commit c58dda2034
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A
3 changed files with 24 additions and 7 deletions

View File

@ -14,6 +14,9 @@ const DefaultConfigTemplate = `
osc-service-port = {{ .PlmntConfig.OSCServicePort }}
watchmen-endpoint = "{{ .PlmntConfig.WatchmenEndpoint }}"
watchmen-port = {{ .PlmntConfig.WatchmenPort }}
token-denom = {{ .PlmntConfig.TokenDenom }}
stake-denom = {{ .PlmntConfig.StakeDenom }}
fee-denom = {{ .PlmntConfig.FeeDenom }}
`
// Config defines Planetmint's top level configuration
@ -21,6 +24,9 @@ type Config struct {
OSCServicePort int `mapstructure:"osc-service-port" json:"osc-service-port"`
WatchmenEndpoint string `mapstructure:"watchmen-endpoint" json:"watchmen-endpoint"`
WatchmenPort int `mapstructure:"watchmen-port" json:"watchmen-port"`
TokenDenom string `mapstructure:"token-denom" json:"token-denom"`
StakeDenom string `mapstructure:"stake-denom" json:"stake-denom"`
FeeDenom string `mapstructure:"fee-denom" json:"fee-denom"`
}
// cosmos-sdk wide global singleton
@ -35,6 +41,9 @@ func DefaultConfig() *Config {
OSCServicePort: 8766,
WatchmenEndpoint: "lab.r3c.network",
WatchmenPort: 7401,
TokenDenom: "plmnt",
StakeDenom: "plmntstake",
FeeDenom: "plmnt",
}
}

View File

@ -2,6 +2,7 @@ package dao
import (
"fmt"
"planetmint-go/config"
"planetmint-go/testutil/network"
"planetmint-go/testutil/sample"
@ -37,6 +38,10 @@ func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
// SetupSuite initializes dao E2ETestSuite
func (s *E2ETestSuite) SetupSuite() {
conf := config.GetConfig()
conf.FeeDenom = "node0token"
conf.SetPlanetmintConfig(conf)
s.T().Log("setting up e2e test suite")
// set accounts for alice and bob in genesis state
@ -60,11 +65,13 @@ func (s *E2ETestSuite) SetupSuite() {
s.cfg.Codec.MustUnmarshalJSON(s.cfg.GenesisState[banktypes.ModuleName], &bankGenState)
bbalances := sdk.NewCoins(
sdk.NewCoin("rddl", math.NewInt(10000)),
sdk.NewCoin(conf.TokenDenom, math.NewInt(10000)),
sdk.NewCoin(conf.StakeDenom, math.NewInt(10000)),
)
abalances := sdk.NewCoins(
sdk.NewCoin("rddl", math.NewInt(5000)),
sdk.NewCoin(conf.TokenDenom, math.NewInt(10000)),
sdk.NewCoin(conf.StakeDenom, math.NewInt(5000)),
)
accountBalances := []banktypes.Balance{
@ -74,7 +81,7 @@ func (s *E2ETestSuite) SetupSuite() {
bankGenState.Balances = append(bankGenState.Balances, accountBalances...)
s.cfg.GenesisState[banktypes.ModuleName] = s.cfg.Codec.MustMarshalJSON(&bankGenState)
s.cfg.MinGasPrices = fmt.Sprintf("0.000006%s", "node0token")
s.cfg.MinGasPrices = fmt.Sprintf("0.000006%s", conf.FeeDenom)
s.network = network.New(s.T(), s.cfg)
}

View File

@ -12,6 +12,7 @@ import (
disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"planetmint-go/config"
"planetmint-go/x/dao/types"
)
@ -58,13 +59,14 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
func (k Keeper) DistributeCollectedFees(ctx sdk.Context) {
ctx = sdk.UnwrapSDKContext(ctx)
conf := config.GetConfig()
balances := make(map[string]math.Int)
totalStake := math.ZeroInt()
k.accountKeeper.IterateAccounts(ctx, func(acc authtypes.AccountI) bool {
addr := acc.GetAddress()
balance := k.bankKeeper.SpendableCoins(ctx, addr)
found, stake := balance.Find("rddl")
found, stake := balance.Find(conf.StakeDenom)
if found {
totalStake = totalStake.Add(stake.Amount)
balances[addr.String()] = stake.Amount
@ -74,8 +76,7 @@ func (k Keeper) DistributeCollectedFees(ctx sdk.Context) {
distAddr := k.accountKeeper.GetModuleAddress(disttypes.ModuleName)
distSpendableCoins := k.bankKeeper.SpendableCoins(ctx, distAddr)
// found, coinToDistribute := distSpendableCoins.Find("stake")
found, coinToDistribute := distSpendableCoins.Find("node0token")
found, coinToDistribute := distSpendableCoins.Find(conf.FeeDenom)
if found {
decTotalAmountToDistribute := sdk.NewDecFromInt(coinToDistribute.Amount)
@ -86,7 +87,7 @@ func (k Keeper) DistributeCollectedFees(ctx sdk.Context) {
claim := decTotalAmountToDistribute.Mul(share)
if claim.GTE(sdk.OneDec()) {
intClaim := claim.TruncateInt()
coinClaim := sdk.NewCoin("node0token", intClaim)
coinClaim := sdk.NewCoin(conf.FeeDenom, intClaim)
accAddress, err := sdk.AccAddressFromBech32(addr)
if err != nil {
panic(err)