Add the PoPCycle concept (#208)

* added reissuance details, the concept of popepochs and popcycles

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2023-11-29 14:14:29 +01:00 committed by GitHub
parent 6a60b78b62
commit cefd22f448
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 7 deletions

View File

@ -1,19 +1,51 @@
package keeper package keeper
import ( import (
"math"
"math/big" "math/big"
"github.com/cosmos/cosmos-sdk/store/prefix" "github.com/cosmos/cosmos-sdk/store/prefix"
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/x/dao/types" "github.com/planetmint/planetmint-go/x/dao/types"
) )
func GetReissuanceCommand(assetID string, _ int64) string { func GetPopNumber(blockHeight int64) float64 {
return "reissueasset " + assetID + " 998.69000000" return float64(blockHeight) / float64(config.GetConfig().PoPEpochs)
} }
func IsValidReissuanceCommand(reissuanceStr string, assetID string, _ int64) bool { var PopsPerCycle float64
expected := "reissueasset " + assetID + " 998.69000000"
func init() {
PopsPerCycle = 1051200.0
}
func GetReissuanceAsStringValue(blockHeight int64) string {
PopNumber := GetPopNumber(blockHeight)
exactCycleID := PopNumber / PopsPerCycle
switch cycleID := math.Floor(exactCycleID); cycleID {
case 0:
return "998.69000000"
case 1:
return "499.34000000"
case 2:
return "249.67000000"
case 3:
return "124.83000000"
case 4:
return "62.42000000"
default:
return "0.0"
}
}
func GetReissuanceCommand(assetID string, blockHeight int64) string {
return "reissueasset " + assetID + " " + GetReissuanceAsStringValue(blockHeight)
}
func IsValidReissuanceCommand(reissuanceStr string, assetID string, blockHeight int64) bool {
expected := "reissueasset " + assetID + " " + GetReissuanceAsStringValue(blockHeight)
return reissuanceStr == expected return reissuanceStr == expected
} }

View File

@ -4,20 +4,21 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/planetmint/planetmint-go/config"
keepertest "github.com/planetmint/planetmint-go/testutil/keeper" keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/x/dao/keeper" daokeeper "github.com/planetmint/planetmint-go/x/dao/keeper"
"github.com/planetmint/planetmint-go/x/dao/types" "github.com/planetmint/planetmint-go/x/dao/types"
) )
func createNReissuances(k *keeper.Keeper, ctx sdk.Context, n int) []types.Reissuance { func createNReissuances(k *daokeeper.Keeper, ctx sdk.Context, n int) []types.Reissuance {
items := make([]types.Reissuance, n) items := make([]types.Reissuance, n)
for i := range items { for i := range items {
items[i].BlockHeight = int64(i) items[i].BlockHeight = int64(i)
items[i].Proposer = fmt.Sprintf("proposer_%v", i) items[i].Proposer = fmt.Sprintf("proposer_%v", i)
items[i].Rawtx = keeper.GetReissuanceCommand("asset_id", int64(i)) items[i].Rawtx = daokeeper.GetReissuanceCommand("asset_id", int64(i))
items[i].TxID = "" items[i].TxID = ""
k.StoreReissuance(ctx, items[i]) k.StoreReissuance(ctx, items[i])
} }
@ -34,3 +35,14 @@ func TestGetReissuances(t *testing.T) {
assert.Equal(t, item, reissuance) assert.Equal(t, item, reissuance)
} }
} }
func TestReissuanceValueComputation(t *testing.T) {
t.Parallel()
popsPerEpoch := float64(config.GetConfig().PoPEpochs)
assert.Equal(t, "998.69000000", daokeeper.GetReissuanceAsStringValue(1))
assert.Equal(t, "499.34000000", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*1+1)))
assert.Equal(t, "249.67000000", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*2+1)))
assert.Equal(t, "124.83000000", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*3+1)))
assert.Equal(t, "62.42000000", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*4+1)))
assert.Equal(t, "0.0", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*5+1)))
}