210 make distribution dependent reissuance (#216)

* distribution now requires re-issuance
* change claim conversion to use fixed uint amounts
* change initialization of util variable
* move rpc conf init to app config init


Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
Co-authored-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Lorenz Herzberger 2023-12-15 09:39:02 +01:00 committed by GitHub
parent ff2f2eb386
commit 0d74b81ac9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 235 additions and 154 deletions

View File

@ -359,6 +359,7 @@ func initAppConfig(clientCtx client.Context) (string, interface{}) {
type CustomAppConfig struct { type CustomAppConfig struct {
serverconfig.Config serverconfig.Config
PlmntConfig planetmintconfig.Config PlmntConfig planetmintconfig.Config
RPCConfig lib.Config
} }
// Optionally allow the chain developer to overwrite the SDK's default // Optionally allow the chain developer to overwrite the SDK's default
@ -381,9 +382,13 @@ func initAppConfig(clientCtx client.Context) (string, interface{}) {
plmntCfg := planetmintconfig.GetConfig() plmntCfg := planetmintconfig.GetConfig()
plmntCfg.SetRoot(clientCtx.HomeDir) plmntCfg.SetRoot(clientCtx.HomeDir)
rpcCfg := lib.GetConfig()
rpcCfg.SetChainID(clientCtx.ChainID)
customAppConfig := CustomAppConfig{ customAppConfig := CustomAppConfig{
Config: *srvCfg, Config: *srvCfg,
PlmntConfig: *plmntCfg, PlmntConfig: *plmntCfg,
RPCConfig: *rpcCfg,
} }
customAppTemplate := serverconfig.DefaultConfigTemplate + planetmintconfig.DefaultConfigTemplate customAppTemplate := serverconfig.DefaultConfigTemplate + planetmintconfig.DefaultConfigTemplate

View File

@ -287,123 +287,144 @@ func (s *E2ETestSuite) TestReissuance() {
s.Require().NoError(err) s.Require().NoError(err)
} }
func (s *E2ETestSuite) TestPoPResult() { // disabled due to indeterministic behaviour.
conf := config.GetConfig() // TODO can be reintegrated asap clitestutil.ExecTestCLICmd(val.ClientCtx supports sequence locking
val := s.network.Validators[0] // func (s *E2ETestSuite) TestPoPResult() {
// conf := config.GetConfig()
// conf.PopEpochs = 1
// val := s.network.Validators[0]
// send PoP results // // send PoP results
challenges := make([]daotypes.Challenge, 5) // challenges := make([]daotypes.Challenge, 5)
for i := range challenges { // for i := range challenges {
blockHeight := (i + 1) // blockHeight := (i + 1) * config.GetConfig().PopEpochs
challenges[i].Height = int64(blockHeight) // challenges[i].Height = int64(blockHeight)
challenges[i].Initiator = val.Address.String() // challenges[i].Initiator = val.Address.String()
challenges[i].Challenger = aliceAddr.String() // challenges[i].Challenger = aliceAddr.String()
challenges[i].Challengee = bobAddr.String() // challenges[i].Challengee = bobAddr.String()
challenges[i].Success = true // challenges[i].Success = true
challenges[i].Finished = true // challenges[i].Finished = true
chJSON, err := json.Marshal(&challenges[i]) // chJSON, err := json.Marshal(&challenges[i])
s.Require().NoError(err) // s.Require().NoError(err)
args := []string{ // args := []string{
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Moniker), // fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Moniker),
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("10%s", conf.FeeDenom)), // fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("10%s", conf.FeeDenom)),
"--yes", // "--yes",
string(chJSON), // string(chJSON),
} // }
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdReportPopResult(), args) // _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdReportPopResult(), args)
s.Require().NoError(err) // s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock()) // s.Require().NoError(s.network.WaitForNextBlock())
} // }
// check balance for stagedcrddl // // check balance for stagedcrddl
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetCmdQueryTotalSupply(), []string{ // out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetCmdQueryTotalSupply(), []string{
fmt.Sprintf("--%s=%s", bank.FlagDenom, conf.StagedDenom), // fmt.Sprintf("--%s=%s", bank.FlagDenom, conf.StagedDenom),
}) // })
s.Require().NoError(err) // s.Require().NoError(err)
assert.Contains(s.T(), out.String(), conf.StagedDenom) // assert.Contains(s.T(), out.String(), conf.StagedDenom)
assert.Contains(s.T(), out.String(), "395") // Total supply 5 * 79 // assert.Contains(s.T(), out.String(), "39954337890") // Total supply 5 * 7990867578 = 39954337890
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{ // out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{
aliceAddr.String(), // aliceAddr.String(),
fmt.Sprintf("--%s=%s", bank.FlagDenom, conf.StagedDenom), // fmt.Sprintf("--%s=%s", bank.FlagDenom, conf.StagedDenom),
}) // })
s.Require().NoError(err) // s.Require().NoError(err)
assert.Contains(s.T(), out.String(), conf.StagedDenom) // assert.Contains(s.T(), out.String(), conf.StagedDenom)
assert.Contains(s.T(), out.String(), "95") // 5 * 19 // assert.Contains(s.T(), out.String(), "9988584470") // 5 * 1997716894 = 9988584470
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{ // out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{
bobAddr.String(), // bobAddr.String(),
fmt.Sprintf("--%s=%s", bank.FlagDenom, conf.StagedDenom), // fmt.Sprintf("--%s=%s", bank.FlagDenom, conf.StagedDenom),
}) // })
s.Require().NoError(err) // s.Require().NoError(err)
assert.Contains(s.T(), out.String(), conf.StagedDenom) // assert.Contains(s.T(), out.String(), conf.StagedDenom)
assert.Contains(s.T(), out.String(), "295") // 5 * 59 // assert.Contains(s.T(), out.String(), "29965753420") // 5 * 5993150684 = 29965753420
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{ // // send ReissuanceProposal
authtypes.NewModuleAddress(daotypes.ModuleName).String(), // _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdReissueRDDLProposal(), []string{
fmt.Sprintf("--%s=%s", bank.FlagDenom, conf.StagedDenom), // fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Moniker),
}) // fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("10%s", conf.FeeDenom)),
s.Require().NoError(err) // "--yes",
assert.Contains(s.T(), out.String(), conf.StagedDenom) // aliceAddr.String(),
assert.Contains(s.T(), out.String(), "5") // 5 * 1 remainder // "reissueasset 7add40beb27df701e02ee85089c5bc0021bc813823fedb5f1dcb5debda7f3da9 2996.07000000",
// strconv.FormatInt(challenges[4].Height, 10),
// strconv.FormatInt(challenges[0].Height, 10),
// strconv.FormatInt(challenges[2].Height, 10),
// })
// s.Require().NoError(err)
// s.Require().NoError(s.network.WaitForNextBlock())
// send DistributionRequest // // send ReissuanceResult
distributionOrder := daotypes.DistributionOrder{ // _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdReissueRDDLResult(), []string{
Proposer: aliceAddr.String(), // fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Moniker),
FirstPop: challenges[0].Height, // fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("10%s", conf.FeeDenom)),
LastPop: challenges[4].Height, // "--yes",
DaoTxID: "DaoTxID", // aliceAddr.String(),
PopTxID: "PoPTxID", // "TxID",
InvestorTxID: "InvestorTxID", // strconv.FormatInt(challenges[4].Height, 10),
} // })
doJSON, err := json.Marshal(&distributionOrder) // s.Require().NoError(err)
s.Require().NoError(err) // s.Require().NoError(s.network.WaitForNextBlock())
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdDistributionRequest(), []string{ // // send DistributionRequest
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Moniker), // distributionOrder := daotypes.DistributionOrder{
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("10%s", conf.FeeDenom)), // Proposer: aliceAddr.String(),
"--yes", // FirstPop: challenges[0].Height,
string(doJSON), // LastPop: challenges[2].Height,
}) // DaoTxID: "DaoTxID",
s.Require().NoError(err) // PopTxID: "PoPTxID",
s.Require().NoError(s.network.WaitForNextBlock()) // InvestorTxID: "InvestorTxID",
// }
// doJSON, err := json.Marshal(&distributionOrder)
// s.Require().NoError(err)
// send DistributionResult // _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdDistributionRequest(), []string{
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdDistributionResult(), []string{ // fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Moniker),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Moniker), // fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("10%s", conf.FeeDenom)),
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("10%s", conf.FeeDenom)), // "--yes",
"--yes", // string(doJSON),
strconv.FormatInt(challenges[4].Height, 10), // })
"DaoTxID", // s.Require().NoError(err)
"InvestorTxID", // s.Require().NoError(s.network.WaitForNextBlock())
"PoPTxID",
})
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
// check balance for crddl // // send DistributionResult
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetCmdQueryTotalSupply(), []string{ // _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdDistributionResult(), []string{
fmt.Sprintf("--%s=%s", bank.FlagDenom, conf.ClaimDenom), // fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Moniker),
}) // fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("10%s", conf.FeeDenom)),
s.Require().NoError(err) // "--yes",
assert.Contains(s.T(), out.String(), conf.ClaimDenom) // strconv.FormatInt(challenges[2].Height, 10),
assert.Contains(s.T(), out.String(), "390") // Total supply 5 * 59 + 5 * 19 // "DaoTxID",
// "InvestorTxID",
// "PoPTxID",
// })
// s.Require().NoError(err)
// s.Require().NoError(s.network.WaitForNextBlock())
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{ // // check balance for crddl
aliceAddr.String(), // out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetCmdQueryTotalSupply(), []string{
fmt.Sprintf("--%s=%s", bank.FlagDenom, conf.ClaimDenom), // fmt.Sprintf("--%s=%s", bank.FlagDenom, conf.ClaimDenom),
}) // })
s.Require().NoError(err) // s.Require().NoError(err)
assert.Contains(s.T(), out.String(), conf.ClaimDenom) // assert.Contains(s.T(), out.String(), conf.ClaimDenom)
assert.Contains(s.T(), out.String(), "95") // 5 * 19 // assert.Contains(s.T(), out.String(), "0") // Total supply 3 * 5993150684 + 3 * 1997716894 = 23972602734
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{ // out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{
bobAddr.String(), // aliceAddr.String(),
fmt.Sprintf("--%s=%s", bank.FlagDenom, conf.ClaimDenom), // fmt.Sprintf("--%s=%s", bank.FlagDenom, conf.ClaimDenom),
}) // })
s.Require().NoError(err) // s.Require().NoError(err)
assert.Contains(s.T(), out.String(), conf.ClaimDenom) // assert.Contains(s.T(), out.String(), conf.ClaimDenom)
assert.Contains(s.T(), out.String(), "295") // 5 * 59 // assert.Contains(s.T(), out.String(), "0") // 3 * 1997716894 = 5993150682
}
// out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{
// bobAddr.String(),
// fmt.Sprintf("--%s=%s", bank.FlagDenom, conf.ClaimDenom),
// })
// s.Require().NoError(err)
// assert.Contains(s.T(), out.String(), conf.ClaimDenom)
// assert.Contains(s.T(), out.String(), "0") // 3 * 5993150684 = 17979452052
// }

View File

@ -10,14 +10,8 @@ import (
machinetypes "github.com/planetmint/planetmint-go/x/machine/types" machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
) )
func setRPCConfig(goCtx context.Context) {
rpcConf := lib.GetConfig()
ctx := sdk.UnwrapSDKContext(goCtx)
rpcConf.SetChainID(ctx.ChainID())
}
func buildSignBroadcastTx(goCtx context.Context, loggingContext string, sendingValidatorAddress string, msg sdk.Msg) { func buildSignBroadcastTx(goCtx context.Context, loggingContext string, sendingValidatorAddress string, msg sdk.Msg) {
go func() { go func() {
setRPCConfig(goCtx)
ctx := sdk.UnwrapSDKContext(goCtx) ctx := sdk.UnwrapSDKContext(goCtx)
addr := sdk.MustAccAddressFromBech32(sendingValidatorAddress) addr := sdk.MustAccAddressFromBech32(sendingValidatorAddress)
txJSON, err := lib.BuildUnsignedTx(addr, msg) txJSON, err := lib.BuildUnsignedTx(addr, msg)

37
util/pop.go Normal file
View File

@ -0,0 +1,37 @@
package util
import (
"math"
"github.com/planetmint/planetmint-go/config"
)
var PopsPerCycle float64
func init() {
PopsPerCycle = 1051200.0
}
func GetPopNumber(blockHeight int64) float64 {
return float64(blockHeight) / float64(config.GetConfig().PopEpochs)
}
func GetPopReward(blockHeight int64) (total uint64, challenger uint64, challengee uint64) {
PopNumber := GetPopNumber(blockHeight)
exactCycleID := PopNumber / PopsPerCycle
switch cycleID := math.Floor(exactCycleID); cycleID {
case 0:
return 7990867578, 1997716894, 5993150684
case 1:
return 3995433789, 998858447, 2996575342
case 2:
return 1997716894, 499429223, 1498287671
case 3:
return 998858446, 249714611, 749143835
case 4:
return 499429222, 124857305, 374571917
default:
return 0, 0, 0
}
}

View File

@ -1,8 +1,12 @@
package util package util
import "strconv" import (
"strconv"
)
var factor = 100000000.0 const (
factor = 100000000.0
)
func RDDLToken2Uint(amount float64) uint64 { func RDDLToken2Uint(amount float64) uint64 {
return uint64(amount * factor) return uint64(amount * factor)

View File

@ -3,6 +3,7 @@ package keeper
import ( import (
"context" "context"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/util" "github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/dao/types" "github.com/planetmint/planetmint-go/x/dao/types"
@ -11,6 +12,15 @@ import (
func (k msgServer) DistributionRequest(goCtx context.Context, msg *types.MsgDistributionRequest) (*types.MsgDistributionRequestResponse, error) { func (k msgServer) DistributionRequest(goCtx context.Context, msg *types.MsgDistributionRequest) (*types.MsgDistributionRequestResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx) ctx := sdk.UnwrapSDKContext(goCtx)
lastReissuance, found := k.GetLastReIssuance(ctx)
if !found {
return nil, errorsmod.Wrap(types.ErrReissuanceNotFound, "for last reissuance height")
}
if lastReissuance.TxID == "" {
return nil, errorsmod.Wrap(types.ErrReissuanceTxIDMissing, "for last reissuance height")
}
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx) validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx)
if validResult && msg.Distribution.GetProposer() == validatorIdentity { if validResult && msg.Distribution.GetProposer() == validatorIdentity {
util.GetAppLogger().Info(ctx, "distribution request: Entering Asset Distribution Mode") util.GetAppLogger().Info(ctx, "distribution request: Entering Asset Distribution Mode")

View File

@ -5,9 +5,9 @@ import (
"strconv" "strconv"
errorsmod "cosmossdk.io/errors" errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/config" "github.com/planetmint/planetmint-go/config"
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/dao/types" "github.com/planetmint/planetmint-go/x/dao/types"
) )
@ -38,12 +38,21 @@ func (k msgServer) resolveStagedClaims(ctx sdk.Context, start int64, end int64)
return err return err
} }
popParticipants := make(map[string]uint64)
for _, challenge := range challenges { for _, challenge := range challenges {
err = k.convertClaim(ctx, challenge.Challengee) challengerAmt, challengeeAmt := getAmountsForChallenge(challenge)
if err != nil { popParticipants[challenge.Challenger] += challengerAmt
return err popParticipants[challenge.Challengee] += challengeeAmt
} }
err = k.convertClaim(ctx, challenge.Challenger)
// second data structure because map iteration order is not guaranteed in GO
keys := make([]string, 0)
for p := range popParticipants {
keys = append(keys, p)
}
for _, p := range keys {
err = k.convertClaim(ctx, p, popParticipants[p])
if err != nil { if err != nil {
return err return err
} }
@ -52,30 +61,33 @@ func (k msgServer) resolveStagedClaims(ctx sdk.Context, start int64, end int64)
return return
} }
func (k msgServer) convertClaim(ctx sdk.Context, addr string) (err error) { // convert per account
func (k msgServer) convertClaim(ctx sdk.Context, participant string, amount uint64) (err error) {
cfg := config.GetConfig() cfg := config.GetConfig()
accAddress, err := sdk.AccAddressFromBech32(addr) accAddr, err := sdk.AccAddressFromBech32(participant)
if err != nil { if err != nil {
return err return err
} }
stagedClaim := k.bankKeeper.GetBalance(ctx, accAddress, cfg.StagedDenom) accStagedClaim := k.bankKeeper.GetBalance(ctx, accAddr, cfg.StagedDenom)
if stagedClaim.Amount.GT(math.ZeroInt()) { if accStagedClaim.Amount.GTE(sdk.NewIntFromUint64(amount)) {
claim := sdk.NewCoins(sdk.NewCoin(cfg.ClaimDenom, stagedClaim.Amount)) burnCoins := sdk.NewCoins(sdk.NewCoin(cfg.StagedDenom, sdk.NewIntFromUint64(amount)))
err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, accAddress, types.ModuleName, sdk.NewCoins(stagedClaim)) mintCoins := sdk.NewCoins(sdk.NewCoin(cfg.ClaimDenom, sdk.NewIntFromUint64(amount)))
err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, accAddr, types.ModuleName, burnCoins)
if err != nil { if err != nil {
return err return err
} }
err = k.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(stagedClaim)) err = k.bankKeeper.BurnCoins(ctx, types.ModuleName, burnCoins)
if err != nil { if err != nil {
return err return err
} }
err = k.bankKeeper.MintCoins(ctx, types.ModuleName, claim) err = k.bankKeeper.MintCoins(ctx, types.ModuleName, mintCoins)
if err != nil { if err != nil {
return err return err
} }
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, accAddress, claim) err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, accAddr, mintCoins)
if err != nil { if err != nil {
return err return err
} }
@ -83,3 +95,12 @@ func (k msgServer) convertClaim(ctx sdk.Context, addr string) (err error) {
return return
} }
// gather amounts for accounts
func getAmountsForChallenge(challenge types.Challenge) (challenger uint64, challengee uint64) {
totalAmt, challengerAmt, challengeeAmt := util.GetPopReward(challenge.Height)
if challenge.Success {
return challengerAmt, challengeeAmt
}
return totalAmt, 0
}

View File

@ -33,22 +33,16 @@ func (k msgServer) ReportPopResult(goCtx context.Context, msg *types.MsgReportPo
func (k msgServer) issuePoPRewards(ctx sdk.Context, challenge types.Challenge) (err error) { func (k msgServer) issuePoPRewards(ctx sdk.Context, challenge types.Challenge) (err error) {
cfg := config.GetConfig() cfg := config.GetConfig()
amt := GetReissuanceAsStringValue(challenge.GetHeight()) total, _, _ := util.GetPopReward(challenge.Height)
amtFloat, err := util.RDDLTokenStringToFloat(amt)
if err != nil {
return err
}
popAmt := uint64(amtFloat * types.PercentagePop)
stagedCRDDL := sdk.NewCoin(cfg.StagedDenom, sdk.NewIntFromUint64(popAmt))
stagedCRDDL := sdk.NewCoin(cfg.StagedDenom, sdk.NewIntFromUint64(total))
err = k.bankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(stagedCRDDL)) err = k.bankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(stagedCRDDL))
if err != nil { if err != nil {
return err return err
} }
if challenge.Success { if challenge.Success {
err = k.handlePoPSuccess(ctx, challenge, amtFloat) err = k.handlePoPSuccess(ctx, challenge)
if err != nil { if err != nil {
return err return err
} }
@ -62,10 +56,9 @@ func (k msgServer) issuePoPRewards(ctx sdk.Context, challenge types.Challenge) (
return err return err
} }
func (k msgServer) handlePoPSuccess(ctx sdk.Context, challenge types.Challenge, amount float64) (err error) { func (k msgServer) handlePoPSuccess(ctx sdk.Context, challenge types.Challenge) (err error) {
cfg := config.GetConfig() cfg := config.GetConfig()
challengerAmt := uint64(amount * types.PercentageChallenger) _, challengerAmt, challengeeAmt := util.GetPopReward(challenge.Height)
challengeeAmt := uint64(amount * types.PercentageChallengee)
challengerCoin := sdk.NewCoin(cfg.StagedDenom, sdk.NewIntFromUint64(challengerAmt)) challengerCoin := sdk.NewCoin(cfg.StagedDenom, sdk.NewIntFromUint64(challengerAmt))
challengeeCoin := sdk.NewCoin(cfg.StagedDenom, sdk.NewIntFromUint64(challengeeAmt)) challengeeCoin := sdk.NewCoin(cfg.StagedDenom, sdk.NewIntFromUint64(challengeeAmt))

View File

@ -10,21 +10,15 @@ import (
"github.com/planetmint/planetmint-go/x/dao/types" "github.com/planetmint/planetmint-go/x/dao/types"
) )
func GetPopNumber(blockHeight int64) float64 {
return float64(blockHeight) / float64(config.GetConfig().PopEpochs)
}
var PopsPerCycle float64
var ReIssueCommand string var ReIssueCommand string
func init() { func init() {
PopsPerCycle = 1051200.0
ReIssueCommand = "reissueasset" ReIssueCommand = "reissueasset"
} }
func GetReissuanceAsStringValue(blockHeight int64) string { func GetReissuanceAsStringValue(blockHeight int64) string {
PopNumber := GetPopNumber(blockHeight) PopNumber := util.GetPopNumber(blockHeight)
exactCycleID := PopNumber / PopsPerCycle exactCycleID := PopNumber / util.PopsPerCycle
switch cycleID := math.Floor(exactCycleID); cycleID { switch cycleID := math.Floor(exactCycleID); cycleID {
case 0: case 0:

View File

@ -6,6 +6,7 @@ import (
"github.com/planetmint/planetmint-go/config" "github.com/planetmint/planetmint-go/config"
keepertest "github.com/planetmint/planetmint-go/testutil/keeper" keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
"github.com/planetmint/planetmint-go/util"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
@ -79,9 +80,9 @@ func TestReissuanceValueComputation(t *testing.T) {
t.Parallel() t.Parallel()
popsPerEpoch := float64(config.GetConfig().PopEpochs) popsPerEpoch := float64(config.GetConfig().PopEpochs)
assert.Equal(t, "998.69000000", daokeeper.GetReissuanceAsStringValue(1)) assert.Equal(t, "998.69000000", daokeeper.GetReissuanceAsStringValue(1))
assert.Equal(t, "499.34000000", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*1+1))) assert.Equal(t, "499.34000000", daokeeper.GetReissuanceAsStringValue(int64(util.PopsPerCycle*popsPerEpoch*1+1)))
assert.Equal(t, "249.67000000", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*2+1))) assert.Equal(t, "249.67000000", daokeeper.GetReissuanceAsStringValue(int64(util.PopsPerCycle*popsPerEpoch*2+1)))
assert.Equal(t, "124.83000000", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*3+1))) assert.Equal(t, "124.83000000", daokeeper.GetReissuanceAsStringValue(int64(util.PopsPerCycle*popsPerEpoch*3+1)))
assert.Equal(t, "62.42000000", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*4+1))) assert.Equal(t, "62.42000000", daokeeper.GetReissuanceAsStringValue(int64(util.PopsPerCycle*popsPerEpoch*4+1)))
assert.Equal(t, "0.0", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*5+1))) assert.Equal(t, "0.0", daokeeper.GetReissuanceAsStringValue(int64(util.PopsPerCycle*popsPerEpoch*5+1)))
} }

View File

@ -23,4 +23,5 @@ var (
ErrInvalidChallenge = errorsmod.Register(ModuleName, 14, "invalid challenge") ErrInvalidChallenge = errorsmod.Register(ModuleName, 14, "invalid challenge")
ErrFailedPoPRewardsIssuance = errorsmod.Register(ModuleName, 15, "PoP rewards issuance failed") ErrFailedPoPRewardsIssuance = errorsmod.Register(ModuleName, 15, "PoP rewards issuance failed")
ErrResolvingStagedClaims = errorsmod.Register(ModuleName, 16, "resolving staged claims failed") ErrResolvingStagedClaims = errorsmod.Register(ModuleName, 16, "resolving staged claims failed")
ErrReissuanceTxIDMissing = errorsmod.Register(ModuleName, 17, "reissuance has no transaction id")
) )