diff --git a/x/dao/keeper/reissuance.go b/x/dao/keeper/reissuance.go index e5d045b..1373510 100644 --- a/x/dao/keeper/reissuance.go +++ b/x/dao/keeper/reissuance.go @@ -1,19 +1,51 @@ package keeper import ( + "math" "math/big" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/planetmint/planetmint-go/config" "github.com/planetmint/planetmint-go/x/dao/types" ) -func GetReissuanceCommand(assetID string, _ int64) string { - return "reissueasset " + assetID + " 998.69000000" +func GetPopNumber(blockHeight int64) float64 { + return float64(blockHeight) / float64(config.GetConfig().PoPEpochs) } -func IsValidReissuanceCommand(reissuanceStr string, assetID string, _ int64) bool { - expected := "reissueasset " + assetID + " 998.69000000" +var PopsPerCycle float64 + +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 } diff --git a/x/dao/keeper/reissuance_test.go b/x/dao/keeper/reissuance_test.go index 0eebbe6..ca84f8e 100644 --- a/x/dao/keeper/reissuance_test.go +++ b/x/dao/keeper/reissuance_test.go @@ -4,20 +4,21 @@ import ( "fmt" "testing" + "github.com/planetmint/planetmint-go/config" keepertest "github.com/planetmint/planetmint-go/testutil/keeper" "github.com/stretchr/testify/assert" 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" ) -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) for i := range items { items[i].BlockHeight = int64(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 = "" k.StoreReissuance(ctx, items[i]) } @@ -34,3 +35,14 @@ func TestGetReissuances(t *testing.T) { 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))) +}