Skip to content

Commit

Permalink
Update protos, documentation, and naming for NAVs (#1814)
Browse files Browse the repository at this point in the history
* Update CHANGELOG.

* Update protos to use mills and update cli.

* Update links in spec.

* Update types and constructors to use UsdMills rather than UsdCents.

* Fix added header.

* Revert flag usage to previous example since it was correct.

* Fix typo in changelog.

* Move changelog entry to bugs.

* Add usd_cents and deprecate it.

* Update links in spec to include deprecated field.

* Additional renaming of cents to mills.
  • Loading branch information
Taztingo authored Jan 17, 2024
1 parent ec697ce commit f464053
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 161 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes

* Remove deleted marker send deny entries [#1666](https://github.com/provenance-io/provenance/issues/1666).
* Update protos, naming, and documentation to use mills [#1813](https://github.com/provenance-io/provenance/issues/1813).

### Dependencies

Expand Down
6 changes: 4 additions & 2 deletions docs/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4623,8 +4623,9 @@ MsgAddFinalizeActivateMarkerRequest defines the Msg/AddFinalizeActivateMarker re
| `allow_governance_control` | [bool](#bool) | | |
| `allow_forced_transfer` | [bool](#bool) | | |
| `required_attributes` | [string](#string) | repeated | |
| `usd_cents` | [uint64](#uint64) | | |
| `usd_cents` | [uint64](#uint64) | | **Deprecated.** |
| `volume` | [uint64](#uint64) | | |
| `usd_mills` | [uint64](#uint64) | | |



Expand Down Expand Up @@ -4660,8 +4661,9 @@ If being provided as a governance proposal, set the from_address to the gov modu
| `allow_governance_control` | [bool](#bool) | | |
| `allow_forced_transfer` | [bool](#bool) | | |
| `required_attributes` | [string](#string) | repeated | |
| `usd_cents` | [uint64](#uint64) | | |
| `usd_cents` | [uint64](#uint64) | | **Deprecated.** |
| `volume` | [uint64](#uint64) | | |
| `usd_mills` | [uint64](#uint64) | | |



Expand Down
6 changes: 4 additions & 2 deletions proto/provenance/marker/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ message MsgAddMarkerRequest {
bool allow_governance_control = 9;
bool allow_forced_transfer = 10;
repeated string required_attributes = 11;
uint64 usd_cents = 12;
uint64 usd_cents = 12 [deprecated = true];
uint64 volume = 13;
uint64 usd_mills = 14;
}

// MsgAddMarkerResponse defines the Msg/AddMarker response type
Expand Down Expand Up @@ -229,8 +230,9 @@ message MsgAddFinalizeActivateMarkerRequest {
bool allow_governance_control = 8;
bool allow_forced_transfer = 9;
repeated string required_attributes = 10;
uint64 usd_cents = 11;
uint64 usd_cents = 11 [deprecated = true];
uint64 volume = 12;
uint64 usd_mills = 13;
}

// MsgAddFinalizeActivateMarkerResponse defines the Msg/AddFinalizeActivateMarker response type
Expand Down
20 changes: 10 additions & 10 deletions x/marker/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1968,7 +1968,7 @@ func TestParseNewMarkerFlags(t *testing.T) {
argGov := "--" + markercli.FlagAllowGovernanceControl
argForce := "--" + markercli.FlagAllowForceTransfer
argRequiredAtt := "--" + markercli.FlagRequiredAttributes
argUsdCents := "--" + markercli.FlagUsdCents
argUsdMills := "--" + markercli.FlagUsdMills
argVolume := "--" + markercli.FlagVolume

tests := []struct {
Expand Down Expand Up @@ -2155,10 +2155,10 @@ func TestParseNewMarkerFlags(t *testing.T) {
},
},
{
name: "usd cents present without volume",
name: "usd mills present without volume",
cmd: getTestCmd(),
args: []string{argUsdCents + "=10"},
expErr: []string{"incorrect value for volume flag. Must be positive number if usd-cents flag has been set to positive value"},
args: []string{argUsdMills + "=10"},
expErr: []string{"incorrect value for volume flag. Must be positive number if usd-mills flag has been set to positive value"},
},
{
name: "volume present",
Expand All @@ -2170,35 +2170,35 @@ func TestParseNewMarkerFlags(t *testing.T) {
AllowGovControl: false,
AllowForceTransfer: false,
RequiredAttributes: []string{},
UsdCents: 0,
UsdMills: 0,
Volume: 11,
},
},
{
name: "usd-cents and volume present",
name: "usd-mills and volume present",
cmd: getTestCmd(),
args: []string{argVolume + "=11", argUsdCents + "=1"},
args: []string{argVolume + "=11", argUsdMills + "=1"},
exp: &markercli.NewMarkerFlagValues{
MarkerType: types.MarkerType_Coin,
SupplyFixed: false,
AllowGovControl: false,
AllowForceTransfer: false,
RequiredAttributes: []string{},
UsdCents: 1,
UsdMills: 1,
Volume: 11,
},
},
{
name: "everything",
cmd: getTestCmd(),
args: []string{argForce, argGov, argType, "RESTRICTED", argFixed, argRequiredAtt, "jack.the.cat.io,george.the.dog.io", argUsdCents, "10", argVolume, "12"},
args: []string{argForce, argGov, argType, "RESTRICTED", argFixed, argRequiredAtt, "jack.the.cat.io,george.the.dog.io", argUsdMills, "10", argVolume, "12"},
exp: &markercli.NewMarkerFlagValues{
MarkerType: types.MarkerType_RestrictedCoin,
SupplyFixed: true,
AllowGovControl: true,
AllowForceTransfer: true,
RequiredAttributes: []string{"jack.the.cat.io", "george.the.dog.io"},
UsdCents: 10,
UsdMills: 10,
Volume: 12,
},
},
Expand Down
18 changes: 9 additions & 9 deletions x/marker/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const (
FlagAdd = "add"
FlagRemove = "remove"
FlagGovProposal = "gov-proposal"
FlagUsdCents = "usd-cents"
FlagUsdMills = "usd-mills"
FlagVolume = "volume"
)

Expand Down Expand Up @@ -151,7 +151,7 @@ with the given supply amount and denomination provided in the coin argument
flagVals.AllowGovControl,
flagVals.AllowForceTransfer,
flagVals.RequiredAttributes,
flagVals.UsdCents,
flagVals.UsdMills,
flagVals.Volume,
)

Expand Down Expand Up @@ -870,7 +870,7 @@ with the given supply amount and denomination provided in the coin argument
msg := types.NewMsgAddFinalizeActivateMarkerRequest(
coin.Denom, coin.Amount, callerAddr, callerAddr, flagVals.MarkerType,
flagVals.SupplyFixed, flagVals.AllowGovControl,
flagVals.AllowForceTransfer, flagVals.RequiredAttributes, accessGrants, flagVals.UsdCents, flagVals.Volume,
flagVals.AllowForceTransfer, flagVals.RequiredAttributes, accessGrants, flagVals.UsdMills, flagVals.Volume,
)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
Expand Down Expand Up @@ -1146,7 +1146,7 @@ func AddNewMarkerFlags(cmd *cobra.Command) {
cmd.Flags().Bool(FlagAllowGovernanceControl, false, "Indicates that governance control is allowed")
cmd.Flags().Bool(FlagAllowForceTransfer, false, "Indicates that force transfer is allowed")
cmd.Flags().StringSlice(FlagRequiredAttributes, []string{}, "comma delimited list of required attributes needed for a restricted marker to have send authority")
cmd.Flags().Uint64(FlagUsdCents, 0, "Indicates the net asset value of marker in usd cents, i.e. 1234 = $1.234")
cmd.Flags().Uint64(FlagUsdMills, 0, "Indicates the net asset value of marker in usd mills, i.e. 1234 = $1.234")
cmd.Flags().Uint64(FlagVolume, 0, "Indicates the volume of the net asset value")
}

Expand All @@ -1157,7 +1157,7 @@ type NewMarkerFlagValues struct {
AllowGovControl bool
AllowForceTransfer bool
RequiredAttributes []string
UsdCents uint64
UsdMills uint64
Volume uint64
}

Expand Down Expand Up @@ -1198,18 +1198,18 @@ func ParseNewMarkerFlags(cmd *cobra.Command) (*NewMarkerFlagValues, error) {
return nil, fmt.Errorf("incorrect value for %s flag. Accepted: comma delimited list of attributes Error: %w", FlagRequiredAttributes, err)
}

rv.UsdCents, err = cmd.Flags().GetUint64(FlagUsdCents)
rv.UsdMills, err = cmd.Flags().GetUint64(FlagUsdMills)
if err != nil {
return nil, fmt.Errorf("incorrect value for %s flag. Accepted: 0 or greater value Error: %w", FlagUsdCents, err)
return nil, fmt.Errorf("incorrect value for %s flag. Accepted: 0 or greater value Error: %w", FlagUsdMills, err)
}

rv.Volume, err = cmd.Flags().GetUint64(FlagVolume)
if err != nil {
return nil, fmt.Errorf("incorrect value for %s flag. Accepted: 0 or greater value Error: %w", FlagVolume, err)
}

if rv.UsdCents > 0 && rv.Volume == 0 {
return nil, fmt.Errorf("incorrect value for %s flag. Must be positive number if %s flag has been set to positive value", FlagVolume, FlagUsdCents)
if rv.UsdMills > 0 && rv.Volume == 0 {
return nil, fmt.Errorf("incorrect value for %s flag. Must be positive number if %s flag has been set to positive value", FlagVolume, FlagUsdMills)
}

return rv, nil
Expand Down
4 changes: 2 additions & 2 deletions x/marker/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (k msgServer) AddMarker(goCtx context.Context, msg *types.MsgAddMarkerReque
return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}

nav := types.NewNetAssetValue(sdk.NewInt64Coin(types.UsdDenom, int64(msg.UsdCents)), msg.Volume)
nav := types.NewNetAssetValue(sdk.NewInt64Coin(types.UsdDenom, int64(msg.UsdMills)), msg.Volume)
err = k.AddSetNetAssetValues(ctx, ma, []types.NetAssetValue{nav}, types.ModuleName)
if err != nil {
return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error())
Expand Down Expand Up @@ -601,7 +601,7 @@ func (k msgServer) AddFinalizeActivateMarker(goCtx context.Context, msg *types.M
normalizedReqAttrs,
)

err = k.AddSetNetAssetValues(ctx, ma, []types.NetAssetValue{types.NewNetAssetValue(sdk.NewInt64Coin(types.UsdDenom, int64(msg.UsdCents)), msg.Volume)}, types.ModuleName)
err = k.AddSetNetAssetValues(ctx, ma, []types.NetAssetValue{types.NewNetAssetValue(sdk.NewInt64Coin(types.UsdDenom, int64(msg.UsdMills)), msg.Volume)}, types.ModuleName)
if err != nil {
return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions x/marker/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (s *MsgServerTestSuite) TestMsgAddMarkerRequest() {
SupplyFixed: true,
AllowGovernanceControl: true,
AllowForcedTransfer: false,
UsdCents: 1,
UsdMills: 1,
Volume: 0,
},
expErr: `cannot set net asset value : marker net asset value volume must be positive value: invalid request`,
Expand All @@ -156,7 +156,7 @@ func (s *MsgServerTestSuite) TestMsgAddMarkerRequest() {
SupplyFixed: true,
AllowGovernanceControl: true,
AllowForcedTransfer: false,
UsdCents: 1,
UsdMills: 1,
Volume: 10,
},
expEvent: []proto.Message{
Expand Down
8 changes: 4 additions & 4 deletions x/marker/spec/03_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ A marker is created using the Add Marker service message.
The created marker can not be directly added in an Active (or Cancelled/Destroyed) status. Markers
must have a valid supply and denomination value.

+++ https://github.com/provenance-io/provenance/blob/22740319ba4b3ba268b3720d4bee36d6c6b06b40/proto/provenance/marker/v1/tx.proto#L77-L93
+++ https://github.com/provenance-io/provenance/blob/d999e7acefea1d77e2d5ce86ea89524dbf2692f8/proto/provenance/marker/v1/tx.proto#L83-L102

+++ https://github.com/provenance-io/provenance/blob/22740319ba4b3ba268b3720d4bee36d6c6b06b40/proto/provenance/marker/v1/tx.proto#L95-96
+++ https://github.com/provenance-io/provenance/blob/d999e7acefea1d77e2d5ce86ea89524dbf2692f8/proto/provenance/marker/v1/tx.proto#L104-L105


This service message is expected to fail if:
Expand Down Expand Up @@ -297,9 +297,9 @@ This service message is expected to fail if:

AddFinalizeActivate requested is used for adding, finalizing, and activating a marker in a single request.

+++ https://github.com/provenance-io/provenance/blob/22740319ba4b3ba268b3720d4bee36d6c6b06b40/proto/provenance/marker/v1/tx.proto#L212-L224
+++ https://github.com/provenance-io/provenance/blob/d999e7acefea1d77e2d5ce86ea89524dbf2692f8/proto/provenance/marker/v1/tx.proto#L221-L236

+++ https://github.com/provenance-io/provenance/blob/22740319ba4b3ba268b3720d4bee36d6c6b06b40/proto/provenance/marker/v1/tx.proto#L226-L227
+++ https://github.com/provenance-io/provenance/blob/d999e7acefea1d77e2d5ce86ea89524dbf2692f8/proto/provenance/marker/v1/tx.proto#L238-L239

This service message is expected to fail if:

Expand Down
4 changes: 2 additions & 2 deletions x/marker/types/marker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,15 +440,15 @@ func TestNetAssetValueValidate(t *testing.T) {
{
name: "volume must be positive if value is greater than 1",
nav: NetAssetValue{
Price: sdk.NewInt64Coin("usdcents", 1),
Price: sdk.NewInt64Coin("usdmills", 1),
Volume: 0,
},
expErr: "marker net asset value volume must be positive value",
},
{
name: "successful with 0 volume and coin",
nav: NetAssetValue{
Price: sdk.NewInt64Coin("usdcents", 0),
Price: sdk.NewInt64Coin("usdmills", 0),
Volume: 0,
},
},
Expand Down
9 changes: 5 additions & 4 deletions x/marker/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewMsgAddMarkerRequest(
allowGovernanceControl bool,
allowForcedTransfer bool,
requiredAttributes []string,
usdCentValue uint64,
usdMills uint64,
volume uint64,
) *MsgAddMarkerRequest {
return &MsgAddMarkerRequest{
Expand All @@ -65,7 +65,7 @@ func NewMsgAddMarkerRequest(
AllowGovernanceControl: allowGovernanceControl,
AllowForcedTransfer: allowForcedTransfer,
RequiredAttributes: requiredAttributes,
UsdCents: usdCentValue,
UsdMills: usdMills,
Volume: volume,
}
}
Expand Down Expand Up @@ -478,6 +478,7 @@ func (msg MsgGrantAllowanceRequest) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sdk.MustAccAddressFromBech32(msg.Administrator)}
}

// NewMsgAddFinalizeActivateMarkerRequest creates a new MsgAddFinalizeActivateMarkerRequest.
func NewMsgAddFinalizeActivateMarkerRequest(
denom string,
totalSupply sdkmath.Int,
Expand All @@ -489,7 +490,7 @@ func NewMsgAddFinalizeActivateMarkerRequest(
allowForcedTransfer bool,
requiredAttributes []string,
accessGrants []AccessGrant,
usdCentsValue uint64,
usdMills uint64,
netAssetVolume uint64,
) *MsgAddFinalizeActivateMarkerRequest {
return &MsgAddFinalizeActivateMarkerRequest{
Expand All @@ -502,7 +503,7 @@ func NewMsgAddFinalizeActivateMarkerRequest(
AccessList: accessGrants,
AllowForcedTransfer: allowForcedTransfer,
RequiredAttributes: requiredAttributes,
UsdCents: usdCentsValue,
UsdMills: usdMills,
Volume: netAssetVolume,
}
}
Expand Down
Loading

0 comments on commit f464053

Please sign in to comment.