Skip to content

Commit

Permalink
remove increase/decrease supply legacy proposals, add decrease supply…
Browse files Browse the repository at this point in the history
… proposal msg, refactor proposal msgs
  • Loading branch information
nullpointer0x00 committed Apr 30, 2024
1 parent 1b84bce commit 18238ef
Show file tree
Hide file tree
Showing 9 changed files with 613 additions and 171 deletions.
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106875,6 +106875,11 @@ definitions:
provenance.marker.v1.MsgSetDenomMetadataResponse:
type: object
title: MsgSetDenomMetadataResponse defines the Msg/SetDenomMetadata response type
provenance.marker.v1.MsgSupplyDecreaseProposalResponse:
type: object
title: >-
MsgSupplyIncreaseProposalResponse defines the Msg/SupplyDecreaseProposal
response type
provenance.marker.v1.MsgSupplyIncreaseProposalResponse:
type: object
title: >-
Expand Down
15 changes: 15 additions & 0 deletions proto/provenance/marker/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ service Msg {
rpc AddFinalizeActivateMarker(MsgAddFinalizeActivateMarkerRequest) returns (MsgAddFinalizeActivateMarkerResponse);
// SupplyIncreaseProposal can only be called via gov proposal
rpc SupplyIncreaseProposal(MsgSupplyIncreaseProposalRequest) returns (MsgSupplyIncreaseProposalResponse);
// SupplyDecreaseProposal can only be called via gov proposal
rpc SupplyDecreaseProposal(MsgSupplyDecreaseProposalRequest) returns (MsgSupplyDecreaseProposalResponse);
// UpdateRequiredAttributes will only succeed if signer has transfer authority
rpc UpdateRequiredAttributes(MsgUpdateRequiredAttributesRequest) returns (MsgUpdateRequiredAttributesResponse);
// UpdateForcedTransfer updates the allow_forced_transfer field of a marker via governance proposal.
Expand Down Expand Up @@ -281,6 +283,19 @@ message MsgSupplyIncreaseProposalRequest {
// MsgSupplyIncreaseProposalResponse defines the Msg/SupplyIncreaseProposal response type
message MsgSupplyIncreaseProposalResponse {}

// MsgSupplyDecreaseProposalRequest defines a governance proposal to decrease total supply of the marker
message MsgSupplyDecreaseProposalRequest {
option (gogoproto.equal) = true;
option (cosmos.msg.v1.signer) = "authority";

cosmos.base.v1beta1.Coin amount = 1
[(gogoproto.nullable) = false, (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin"];
string authority = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // signer of the proposal
}

// MsgSupplyIncreaseProposalResponse defines the Msg/SupplyDecreaseProposal response type
message MsgSupplyDecreaseProposalResponse {}

// MsgUpdateRequiredAttributesRequest defines a msg to update/add/remove required attributes from a resticted marker
// signer must have transfer authority to change attributes, to update attribute add current to remove list and new to
// add list
Expand Down
17 changes: 16 additions & 1 deletion third_party/proto/cosmos_proto/cosmos.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import "google/protobuf/descriptor.proto";

option go_package = "github.com/cosmos/cosmos-proto;cosmos_proto";

extend google.protobuf.MethodOptions {

// method_added_in is used to indicate from which version the method was added.
string method_added_in = 93001;
}

extend google.protobuf.MessageOptions {

// implements_interface is used to indicate the type name of the interface
Expand All @@ -13,6 +19,9 @@ extend google.protobuf.MessageOptions {
// interfaces. Interfaces should be declared using a declare_interface
// file option.
repeated string implements_interface = 93001;

// message_added_in is used to indicate from which version the message was added.
string message_added_in = 93002;
}

extend google.protobuf.FieldOptions {
Expand All @@ -27,6 +36,9 @@ extend google.protobuf.FieldOptions {
// generators may choose to use this information to map this field to a
// language-specific type representing the scalar.
string scalar = 93002;

// field_added_in is used to indicate from which version the field was added.
string field_added_in = 93003;
}

extend google.protobuf.FileOptions {
Expand All @@ -46,6 +58,9 @@ extend google.protobuf.FileOptions {
// expected that the declaration will be found in a protobuf file named
// a/b/scalars.proto in the file descriptor set.
repeated ScalarDescriptor declare_scalar = 793022;

// file_added_in is used to indicate from which the version the file was added.
string file_added_in = 793023;
}

// InterfaceDescriptor describes an interface type to be used with
Expand Down Expand Up @@ -94,4 +109,4 @@ enum ScalarType {
SCALAR_TYPE_UNSPECIFIED = 0;
SCALAR_TYPE_STRING = 1;
SCALAR_TYPE_BYTES = 2;
}
}
4 changes: 0 additions & 4 deletions x/marker/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import (
func NewProposalHandler(k keeper.Keeper) govtypesv1beta1.Handler {
return func(ctx sdk.Context, content govtypesv1beta1.Content) error {
switch c := content.(type) {
case *types.SupplyIncreaseProposal:
return keeper.HandleSupplyIncreaseProposal(ctx, k, c)
case *types.SupplyDecreaseProposal:
return keeper.HandleSupplyDecreaseProposal(ctx, k, c)
case *types.SetAdministratorProposal:
return keeper.HandleSetAdministratorProposal(ctx, k, c)
case *types.RemoveAdministratorProposal:
Expand Down
23 changes: 17 additions & 6 deletions x/marker/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,17 +538,28 @@ func (k msgServer) SupplyIncreaseProposal(goCtx context.Context, msg *types.MsgS
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "expected %s got %s", k.GetAuthority(), msg.Authority)
}

proposal := types.SupplyIncreaseProposal{
Amount: msg.Amount,
TargetAddress: msg.TargetAddress,
err := k.Keeper.SupplyIncreaseProposal(ctx, msg.Amount, msg.TargetAddress)
if err != nil {
return nil, err
}

// HandleSupplyIncreaseProposal performs the basic validation
err := HandleSupplyIncreaseProposal(ctx, k.Keeper, &proposal)
return &types.MsgSupplyIncreaseProposalResponse{}, nil
}

// DecreaseIncreaseProposal can only be called via gov proposal
func (k msgServer) SupplyDecreaseProposal(goCtx context.Context, msg *types.MsgSupplyDecreaseProposalRequest) (*types.MsgSupplyDecreaseProposalResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

if k.GetAuthority() != msg.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "expected %s got %s", k.GetAuthority(), msg.Authority)
}

err := k.Keeper.HandleSupplyDecreaseProposal(ctx, msg.Amount)
if err != nil {
return nil, err
}
return &types.MsgSupplyIncreaseProposalResponse{}, nil

return &types.MsgSupplyDecreaseProposalResponse{}, nil
}

// UpdateRequiredAttributes will only succeed if signer has transfer authority
Expand Down
38 changes: 19 additions & 19 deletions x/marker/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"github.com/provenance-io/provenance/x/marker/types"
)

// HandleSupplyIncreaseProposal handles a SupplyIncrease governance proposal request
func HandleSupplyIncreaseProposal(ctx sdk.Context, k Keeper, c *types.SupplyIncreaseProposal) error {
// SupplyIncreaseProposal handles a SupplyIncrease governance proposal request
func (k Keeper) SupplyIncreaseProposal(ctx sdk.Context, amount sdk.Coin, targetAddress string) error {
logger := k.Logger(ctx)
addr, err := types.MarkerAddress(c.Amount.Denom)
addr, err := types.MarkerAddress(amount.Denom)
if err != nil {
return err
}
Expand All @@ -20,51 +20,51 @@ func HandleSupplyIncreaseProposal(ctx sdk.Context, k Keeper, c *types.SupplyIncr
return err
}
if m == nil {
return fmt.Errorf("%s marker does not exist", c.Amount.Denom)
return fmt.Errorf("%s marker does not exist", amount.Denom)
}
if !m.HasGovernanceEnabled() {
return fmt.Errorf("%s marker does not allow governance control", c.Amount.Denom)
return fmt.Errorf("%s marker does not allow governance control", amount.Denom)
}

if m.GetStatus() == types.StatusProposed || m.GetStatus() == types.StatusFinalized {
total := m.GetSupply().Add(c.Amount)
total := m.GetSupply().Add(amount)
if err = m.SetSupply(total); err != nil {
return err
}
if err := m.Validate(); err != nil {
return err
}
k.SetMarker(ctx, m)
logger.Info("marker configured supply increased", "marker", c.Amount.Denom, "amount", c.Amount.Amount.String())
logger.Info("marker configured supply increased", "marker", amount.Denom, "amount", amount.Amount.String())
return nil
} else if m.GetStatus() != types.StatusActive {
return fmt.Errorf("cannot mint coin for a marker that is not in Active status")
}

if err := k.IncreaseSupply(ctx, m, c.Amount); err != nil {
if err := k.IncreaseSupply(ctx, m, amount); err != nil {
return err
}

logger.Info("marker total supply increased", "marker", c.Amount.Denom, "amount", c.Amount.Amount.String())
logger.Info("marker total supply increased", "marker", amount.Denom, "amount", amount.Amount.String())

// If a target address for minted coins is given then send them there.
if len(c.TargetAddress) > 0 {
recipient, err := sdk.AccAddressFromBech32(c.TargetAddress)
if len(targetAddress) > 0 {
recipient, err := sdk.AccAddressFromBech32(targetAddress)
if err != nil {
return err
}
if err := k.bankKeeper.SendCoins(types.WithBypass(ctx), addr, recipient, sdk.NewCoins(c.Amount)); err != nil {
if err := k.bankKeeper.SendCoins(types.WithBypass(ctx), addr, recipient, sdk.NewCoins(amount)); err != nil {
return err
}
logger.Info("transferred escrowed coin from marker", "marker", c.Amount.Denom, "amount", c.Amount.String(), "recipient", c.TargetAddress)
logger.Info("transferred escrowed coin from marker", "marker", amount.Denom, "amount", amount.String(), "recipient", targetAddress)
}

return nil
}

// HandleSupplyDecreaseProposal handles a SupplyDecrease governance proposal request
func HandleSupplyDecreaseProposal(ctx sdk.Context, k Keeper, c *types.SupplyDecreaseProposal) error {
addr, err := types.MarkerAddress(c.Amount.Denom)
func (k Keeper) HandleSupplyDecreaseProposal(ctx sdk.Context, amount sdk.Coin) error {
addr, err := types.MarkerAddress(amount.Denom)
if err != nil {
return err
}
Expand All @@ -73,19 +73,19 @@ func HandleSupplyDecreaseProposal(ctx sdk.Context, k Keeper, c *types.SupplyDecr
return err
}
if m == nil {
return fmt.Errorf("%s marker does not exist", c.Amount.Denom)
return fmt.Errorf("%s marker does not exist", amount.Denom)
}

if !m.HasGovernanceEnabled() {
return fmt.Errorf("%s marker does not allow governance control", c.Amount.Denom)
return fmt.Errorf("%s marker does not allow governance control", amount.Denom)
}

if err := k.DecreaseSupply(ctx, m, c.Amount); err != nil {
if err := k.DecreaseSupply(ctx, m, amount); err != nil {
return err
}

logger := k.Logger(ctx)
logger.Info("marker total supply reduced", "marker", c.Amount.Denom, "amount", c.Amount.Amount.String())
logger.Info("marker total supply reduced", "marker", amount.Denom, "amount", amount.Amount.String())

return nil
}
Expand Down
4 changes: 0 additions & 4 deletions x/marker/keeper/proposal_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ func (s *IntegrationTestSuite) TestMarkerProposals() {

var err error
switch c := tc.prop.(type) {
case *markertypes.SupplyIncreaseProposal:
err = markerkeeper.HandleSupplyIncreaseProposal(s.ctx, s.k, c)
case *markertypes.SupplyDecreaseProposal:
err = markerkeeper.HandleSupplyDecreaseProposal(s.ctx, s.k, c)
case *markertypes.SetAdministratorProposal:
err = markerkeeper.HandleSetAdministratorProposal(s.ctx, s.k, c)
case *markertypes.RemoveAdministratorProposal:
Expand Down
Loading

0 comments on commit 18238ef

Please sign in to comment.