Skip to content

Commit

Permalink
Deprecate MaxTotalSupply and add MaxSupply as a BigInt to replace it.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Witkowski committed Sep 8, 2023
1 parent 183734e commit b9fd491
Show file tree
Hide file tree
Showing 17 changed files with 260 additions and 126 deletions.
3 changes: 2 additions & 1 deletion docs/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1968,9 +1968,10 @@ Params defines the set of params for the account module.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `max_total_supply` | [uint64](#uint64) | | maximum amount of supply to allow a marker to be created with |
| `max_total_supply` | [uint64](#uint64) | | **Deprecated.** Deprecated: Prefer to use `max_supply` instead. Maximum amount of supply to allow a marker to be created with |
| `enable_governance` | [bool](#bool) | | indicates if governance based controls of markers is allowed. |
| `unrestricted_denom_regex` | [string](#string) | | a regular expression used to validate marker denom values from normal create requests (governance requests are only subject to platform coin validation denom expression) |
| `max_supply` | [string](#string) | | maximum amount of supply to allow a marker to be created with |



Expand Down
10 changes: 8 additions & 2 deletions proto/provenance/marker/v1/marker.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ message Params {
option (gogoproto.equal) = false;
option (gogoproto.goproto_stringer) = false;

// maximum amount of supply to allow a marker to be created with
uint64 max_total_supply = 1 [(gogoproto.customtype) = "uint64", (gogoproto.nullable) = false];
// Deprecated: Prefer to use `max_supply` instead. Maximum amount of supply to allow a marker to be created with
uint64 max_total_supply = 1 [(gogoproto.customtype) = "uint64", (gogoproto.nullable) = false, deprecated = true];
// indicates if governance based controls of markers is allowed.
bool enable_governance = 2;
// a regular expression used to validate marker denom values from normal create requests (governance
// requests are only subject to platform coin validation denom expression)
string unrestricted_denom_regex = 3;
// maximum amount of supply to allow a marker to be created with
string max_supply = 4 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "json:\"max_supply\" yaml:\"max_supply\""
];
}

// MarkerAccount holds the marker configuration information in addition to a base account structure.
Expand Down
3 changes: 2 additions & 1 deletion x/marker/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
var markerData markertypes.GenesisState
markerData.Params.EnableGovernance = true
markerData.Params.MaxTotalSupply = 1000000
markerData.Params.MaxSupply = sdk.NewInt(1000000)
// Note: These account numbers get ignored.
markerData.Markers = []markertypes.MarkerAccount{
{
Expand Down Expand Up @@ -455,7 +456,7 @@ func (s *IntegrationTestSuite) TestMarkerQueryCommands() {
[]string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
`{"max_total_supply":"1000000","enable_governance":true,"unrestricted_denom_regex":""}`,
`{"max_total_supply":"1000000","enable_governance":true,"unrestricted_denom_regex":"","max_supply":"1000000"}`,
},
{
"get testcoin marker json",
Expand Down
2 changes: 1 addition & 1 deletion x/marker/keeper/marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (k Keeper) IncreaseSupply(ctx sdk.Context, marker types.MarkerAccountI, coi

inCirculation := sdk.NewCoin(marker.GetDenom(), k.bankKeeper.GetSupply(ctx, marker.GetDenom()).Amount)
total := inCirculation.Add(coin)
maxAllowed := sdk.NewCoin(marker.GetDenom(), sdk.NewIntFromUint64(k.GetParams(ctx).MaxTotalSupply))
maxAllowed := sdk.NewCoin(marker.GetDenom(), k.GetParams(ctx).MaxSupply)
if total.Amount.GT(maxAllowed.Amount) {
return fmt.Errorf(
"requested supply %d exceeds maximum allowed value %d", total.Amount, maxAllowed.Amount)
Expand Down
14 changes: 13 additions & 1 deletion x/marker/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"regexp"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/provenance-io/provenance/x/marker/types"
Expand All @@ -15,6 +16,7 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
MaxTotalSupply: k.GetMaxTotalSupply(ctx),
EnableGovernance: k.GetEnableGovernance(ctx),
UnrestrictedDenomRegex: k.GetUnrestrictedDenomRegex(ctx),
MaxSupply: k.GetMaxSupply(ctx),
}
}

Expand All @@ -23,7 +25,8 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
}

// GetMaxTotalSupply return the current parameter value for the max allowed total supply (or default if unset)
// GetMaxTotalSupply is deprecated.
// Deprecated: GetMaxTotalSupply is kept for backwards compability.
func (k Keeper) GetMaxTotalSupply(ctx sdk.Context) (max uint64) {
max = types.DefaultMaxTotalSupply
if k.paramSpace.Has(ctx, types.ParamStoreKeyMaxTotalSupply) {
Expand All @@ -32,6 +35,15 @@ func (k Keeper) GetMaxTotalSupply(ctx sdk.Context) (max uint64) {
return
}

// GetMaxSupply return the current parameter value for the max allowed supply (or default if unset)
func (k Keeper) GetMaxSupply(ctx sdk.Context) (max math.Int) {
max = math.NewIntFromUint64(types.DefaultMaxSupply)
if k.paramSpace.Has(ctx, types.ParamStoreKeyMaxSupply) {
k.paramSpace.Get(ctx, types.ParamStoreKeyMaxSupply, &max)
}
return
}

// GetEnableGovernance returns the current parameter value for enabling governance control (or default if unset)
func (k Keeper) GetEnableGovernance(ctx sdk.Context) (enabled bool) {
enabled = types.DefaultEnableGovernance
Expand Down
17 changes: 16 additions & 1 deletion x/marker/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"math/rand"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -17,15 +18,22 @@ import (
// Simulation parameter constants
const (
MaxTotalSupply = "max_total_supply"
MaxSupply = "max_supply"
EnableGovernance = "enable_governance"
UnrestrictedDenomRegex = "unresticted_denom_regex"
)

// GenMaxTotalSupply randomized Maximum amount of supply to allow for markers
// GenMaxTotalSupply is deprecated.
// Deprecated: GenMaxTotalSupply is kept for backwards compatability.
func GenMaxTotalSupply(r *rand.Rand) uint64 {
return r.Uint64()
}

// GenMaxSupply randomized Maximum amount of supply to allow for markers
func GenMaxSupply(r *rand.Rand) math.Int {
return math.NewIntFromUint64(r.Uint64())
}

// GenEnableGovernance returns a randomized EnableGovernance parameter.
func GenEnableGovernance(r *rand.Rand) bool {
return r.Int63n(100) < 50 // 50% chance of unrestricted names being enabled
Expand All @@ -46,6 +54,12 @@ func RandomizedGenState(simState *module.SimulationState) {
func(r *rand.Rand) { maxTotalSupply = GenMaxTotalSupply(r) },
)

var maxSupply math.Int
simState.AppParams.GetOrGenerate(
simState.Cdc, MaxSupply, &maxSupply, simState.Rand,
func(r *rand.Rand) { maxSupply = GenMaxSupply(r) },
)

var enableGovernance bool
simState.AppParams.GetOrGenerate(
simState.Cdc, EnableGovernance, &enableGovernance, simState.Rand,
Expand All @@ -61,6 +75,7 @@ func RandomizedGenState(simState *module.SimulationState) {
markerGenesis := types.GenesisState{
Params: types.Params{
MaxTotalSupply: maxTotalSupply,
MaxSupply: maxSupply,
EnableGovernance: enableGovernance,
UnrestrictedDenomRegex: unrestrictedDenomRegex,
},
Expand Down
3 changes: 2 additions & 1 deletion x/marker/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func TestRandomizedGenState(t *testing.T) {

require.Equal(t, true, markerGenesis.Params.EnableGovernance)
require.Equal(t, uint64(0x9408d2ac22c4d294), markerGenesis.Params.MaxTotalSupply)
require.Equal(t, `[a-zA-Z][a-zA-Z0-9\\-\\.]{7,60}`, markerGenesis.Params.UnrestrictedDenomRegex)
require.Equal(t, uint64(0xc697f48392907a0), markerGenesis.Params.MaxSupply.Uint64())
require.Equal(t, `[a-zA-Z][a-zA-Z0-9\\-\\.]{9,20}`, markerGenesis.Params.UnrestrictedDenomRegex)
}

// TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState.
Expand Down
6 changes: 3 additions & 3 deletions x/marker/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func SimulateMsgAddMarker(k keeper.Keeper, ak authkeeper.AccountKeeperI, bk bank
denom := randomUnrestrictedDenom(r, k.GetUnrestrictedDenomRegex(ctx))
msg := types.NewMsgAddMarkerRequest(
denom,
sdk.NewIntFromUint64(randomUint64(r, k.GetMaxTotalSupply(ctx))),
sdk.NewIntFromUint64(randomUint64(r, k.GetMaxSupply(ctx).Uint64())),
simAccount.Address,
mgrAccount.Address,
types.MarkerType(r.Intn(2)+1), // coin or restricted_coin
Expand Down Expand Up @@ -249,7 +249,7 @@ func SimulateMsgAddFinalizeActivateMarker(k keeper.Keeper, ak authkeeper.Account
grants := randomAccessGrants(r, accs, 100, markerType)
msg := types.NewMsgAddFinalizeActivateMarkerRequest(
denom,
sdk.NewIntFromUint64(randomUint64(r, k.GetMaxTotalSupply(ctx))),
sdk.NewIntFromUint64(randomUint64(r, k.GetMaxSupply(ctx).Uint64())),
simAccount.Address,
mgrAccount.Address,
markerType,
Expand Down Expand Up @@ -283,7 +283,7 @@ func SimulateMsgAddMarkerProposal(k keeper.Keeper, args *WeightedOpsArgs) simtyp
msg := &types.MsgAddMarkerRequest{
Amount: sdk.Coin{
Denom: denom,
Amount: sdk.NewIntFromUint64(randomUint64(r, k.GetMaxTotalSupply(ctx))),
Amount: sdk.NewIntFromUint64(randomUint64(r, k.GetMaxSupply(ctx).Uint64())),
},
Manager: simAccount.Address.String(),
FromAddress: k.GetAuthority(),
Expand Down
6 changes: 6 additions & 0 deletions x/marker/simulation/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

const (
keyMaxTotalSupply = "MaxTotalSupply"
keyMaxSupply = "MaxSupply"
keyEnableGovernance = "EnableGovernance"
keyUnrestrictedDenomRegex = "UnrestrictedDenomRegex"
)
Expand All @@ -27,6 +28,11 @@ func ParamChanges(_ *rand.Rand) []simtypes.ParamChange {
return fmt.Sprintf("\"%d\"", GenMaxTotalSupply(r))
},
),
simulation.NewSimParamChange(types.ModuleName, keyMaxSupply,
func(r *rand.Rand) string {
return fmt.Sprintf("\"%d\"", GenMaxSupply(r).Uint64())
},
),
simulation.NewSimParamChange(types.ModuleName, keyEnableGovernance,
func(r *rand.Rand) string {
return fmt.Sprintf("%v", GenEnableGovernance(r))
Expand Down
7 changes: 6 additions & 1 deletion x/marker/simulation/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func TestParamChanges(t *testing.T) {
key: "MaxTotalSupply",
subspace: markertypes.ModuleName,
},
{
composedKey: "marker/MaxSupply",
key: "MaxSupply",
subspace: markertypes.ModuleName,
},
{
composedKey: "marker/EnableGovernance",
key: "EnableGovernance",
Expand All @@ -38,7 +43,7 @@ func TestParamChanges(t *testing.T) {

paramChanges := simulation.ParamChanges(r)

require.Len(t, paramChanges, 3)
require.Len(t, paramChanges, 4)

for i, p := range paramChanges {
require.Equal(t, expected[i].composedKey, p.ComposedKey())
Expand Down
6 changes: 3 additions & 3 deletions x/marker/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ func SimulateCreateSupplyIncreaseProposalContent(k keeper.Keeper) simtypes.Conte
return nil
}

newSupply := randomUint64(r, k.GetMaxTotalSupply(ctx)-k.CurrentCirculation(ctx, m).Uint64())
newSupply := randomUint64(r, k.GetMaxSupply(ctx).Uint64()-k.CurrentCirculation(ctx, m).Uint64())

// TODO: When the simulation tests are fixed to stop breaking supply invariants through incorrect minting, the following check should be removed.
if newSupply > k.GetMaxTotalSupply(ctx) {
if newSupply > k.GetMaxSupply(ctx).Uint64() {
println("!!!! WARNING, TOKEN SUPPLY IS INVALID, ABORTING NEW PROPOSAL !!!!")
return nil
}

return types.NewSupplyIncreaseProposal(
simtypes.RandStringOfLength(r, 10),
simtypes.RandStringOfLength(r, 100),
// sdk.NewCoin(m.GetDenom(), sdk.NewIntFromUint64(randomUint64(r, k.GetMaxTotalSupply(ctx)-k.CurrentCirculation(ctx, m).Uint64()))),
// sdk.NewCoin(m.GetDenom(), sdk.NewIntFromUint64(randomUint64(r, k.GetMaxSupply(ctx).Uint64()-k.CurrentCirculation(ctx, m).Uint64()))),
sdk.NewCoin(m.GetDenom(), sdk.NewIntFromUint64(newSupply)),
dest,
)
Expand Down
3 changes: 2 additions & 1 deletion x/marker/spec/03_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All created/modified state objects specified by each message are defined within
[state](./02_state_transitions.md) section.

<!-- TOC 2 2 -->
- [Messages](#messages)
- [Msg/AddMarkerRequest](#msgaddmarkerrequest)
- [Msg/AddAccessRequest](#msgaddaccessrequest)
- [Msg/DeleteAccessRequest](#msgdeleteaccessrequest)
Expand Down Expand Up @@ -340,7 +341,7 @@ This service message is expected to fail if:

- The authority is not the address of the governance module's account.
- The governance proposal format (title, description, etc) is invalid
- The requested supply exceeds the configuration parameter for `MaxTotalSupply`
- The requested supply exceeds the configuration parameter for `MaxSupply`

See also: [Governance: Supply Increase Proposal](./10_governance.md#supply-increase-proposal)

Expand Down
3 changes: 2 additions & 1 deletion x/marker/spec/09_params.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ Param module and available for control via Governance proposal to change paramet
## Params

| Key | Type | Example |
|------------------------|----------|-----------------------------------|
| ---------------------- | -------- | --------------------------------- |
| MaxTotalSupply | `uint64` | `"259200000000000"` |
| MaxSupply | `BigInt` | `"259200000000000"` |
| EnableGovernance | `bool` | `true` |
| UnrestrictedDenomRegex | `string` | `"[a-zA-Z][a-zA-Z0-9\-\.]{7,83}"` |

Expand Down
3 changes: 2 additions & 1 deletion x/marker/spec/10_governance.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ marker to be defined where no single account is allowed to make modifications an
issue change requests through passing a governance proposal.

<!-- TOC 2 2 -->
- [Governance Proposal Control](#governance-proposal-control)
- [Add Marker Proposal](#add-marker-proposal)
- [Supply Increase Proposal](#supply-increase-proposal)
- [Supply Decrease Proposal](#supply-decrease-proposal)
Expand Down Expand Up @@ -48,7 +49,7 @@ through minting coin and placing it within the marker or assigning it directly t

This request is expected to fail if:
- The governance proposal format (title, description, etc) is invalid
- The requested supply exceeds the configuration parameter for `MaxTotalSupply`
- The requested supply exceeds the configuration parameter for `MaxSupply`

## Supply Decrease Proposal

Expand Down
Loading

0 comments on commit b9fd491

Please sign in to comment.