Skip to content

Commit

Permalink
Record net value asset only when explicitly set
Browse files Browse the repository at this point in the history
by user when adding marker #2030
  • Loading branch information
iramiller committed Sep 24, 2024
1 parent 6666f50 commit e0621f4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 40 deletions.
1 change: 1 addition & 0 deletions .changelog/unreleased/improvements/2030-explicit-navs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Only set a NAV record when explicitly provided. [#2030](https://github.com/provenance-io/provenance/issues/2030).
3 changes: 0 additions & 3 deletions x/marker/keeper/marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,6 @@ func (k Keeper) FinalizeMarker(ctx sdk.Context, caller sdk.Address, denom string
if err != nil {
return err
}
if len(navs) == 0 {
return fmt.Errorf("marker %v does not have any net asset values assigned", denom)
}

// transition to finalized state ... then to active once mint is complete
if err = m.SetStatus(types.StatusFinalized); err != nil {
Expand Down
27 changes: 18 additions & 9 deletions x/marker/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,17 @@ func (k msgServer) AddMarker(goCtx context.Context, msg *types.MsgAddMarkerReque
return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}

usdMills := sdkmath.NewIntFromUint64(msg.UsdMills)
nav := types.NewNetAssetValue(sdk.NewCoin(types.UsdDenom, usdMills), msg.Volume)
err = k.AddSetNetAssetValues(ctx, ma, []types.NetAssetValue{nav}, types.ModuleName)
if err != nil {
return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error())
// Only create a NAV entry if an explicit value is given for a NAV. If a zero value is desired this can be set explicitly in a followup call.
// This check prevents a proliferation of incorrect NAV entries being recorded when setting up markers.
if msg.UsdMills > 0 {
usdMills := sdkmath.NewIntFromUint64(msg.UsdMills)
nav := types.NewNetAssetValue(sdk.NewCoin(types.UsdDenom, usdMills), msg.Volume)
err = k.AddSetNetAssetValues(ctx, ma, []types.NetAssetValue{nav}, types.ModuleName)
if err != nil {
return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}
}

// Note: The status can only be Active if this is being done via gov prop.
if ma.Status == types.StatusActive {
// Active markers should have supply set.
Expand Down Expand Up @@ -517,10 +522,14 @@ func (k msgServer) AddFinalizeActivateMarker(goCtx context.Context, msg *types.M
normalizedReqAttrs,
)

usdMills := sdkmath.NewIntFromUint64(msg.UsdMills)
err = k.AddSetNetAssetValues(ctx, ma, []types.NetAssetValue{types.NewNetAssetValue(sdk.NewCoin(types.UsdDenom, usdMills), msg.Volume)}, types.ModuleName)
if err != nil {
return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error())
// Only create a NAV entry if an explicit value is given for a NAV. If a zero value is desired this can be set explicitly in a followup call.
// This check prevents a proliferation of incorrect NAV entries being recorded when setting up markers.
if msg.UsdMills > 0 {
usdMills := sdkmath.NewIntFromUint64(msg.UsdMills)
err = k.AddSetNetAssetValues(ctx, ma, []types.NetAssetValue{types.NewNetAssetValue(sdk.NewCoin(types.UsdDenom, usdMills), msg.Volume)}, types.ModuleName)
if err != nil {
return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}
}

if err := k.Keeper.AddFinalizeAndActivateMarker(ctx, ma); err != nil {
Expand Down
23 changes: 0 additions & 23 deletions x/marker/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ func (s *MsgServerTestSuite) TestMsgAddMarkerRequest() {
Manager: s.owner1,
MarkerType: types.MarkerType_Coin.String(),
},
&types.EventSetNetAssetValue{
Denom: denom,
Price: "0usd",
Volume: "0",
Source: types.ModuleName,
},
},
},
{
Expand Down Expand Up @@ -212,12 +206,6 @@ func (s *MsgServerTestSuite) TestMsgAddMarkerRequest() {
Manager: s.owner1,
MarkerType: types.MarkerType_Coin.String(),
},
&types.EventSetNetAssetValue{
Denom: denomWithDashPeriod,
Price: "0usd",
Volume: "0",
Source: types.ModuleName,
},
},
},
{
Expand All @@ -242,12 +230,6 @@ func (s *MsgServerTestSuite) TestMsgAddMarkerRequest() {
Manager: s.owner1,
MarkerType: types.MarkerType_RestrictedCoin.String(),
},
&types.EventSetNetAssetValue{
Denom: rdenom,
Price: "0usd",
Volume: "0",
Source: types.ModuleName,
},
},
},
}
Expand Down Expand Up @@ -311,11 +293,6 @@ func (s *MsgServerTestSuite) TestMsgFinalizeMarkerRequest() {
msg types.MsgFinalizeRequest
expErr string
}{
{
name: "marker does not have net asset value",
msg: types.MsgFinalizeRequest{Denom: noNavMarker.Denom, Administrator: authUser.String()},
expErr: "marker nonav does not have any net asset values assigned: invalid request",
},
{
name: "successfully finalize",
msg: types.MsgFinalizeRequest{Denom: validMarker.Denom, Administrator: authUser.String()},
Expand Down
15 changes: 10 additions & 5 deletions x/metadata/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ func (k msgServer) WriteScope(
return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}

usdMills := sdkmath.NewIntFromUint64(msg.UsdMills)
nav := types.NewNetAssetValue(sdk.NewCoin(types.UsdDenom, usdMills), 1)
err := k.AddSetNetAssetValues(ctx, msg.Scope.ScopeId, []types.NetAssetValue{nav}, types.ModuleName)
if err != nil {
return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error())
// Do not set a NAV entry at this time unless a value greater than zero is specified. This avoids the common case of
// not having a NAV entry value at hand during a scope write request. A zero value can still be set explicitly with
// an add NAV call made separately.
if msg.UsdMills > 0 {
usdMills := sdkmath.NewIntFromUint64(msg.UsdMills)
nav := types.NewNetAssetValue(sdk.NewCoin(types.UsdDenom, usdMills), 1)
err := k.AddSetNetAssetValues(ctx, msg.Scope.ScopeId, []types.NetAssetValue{nav}, types.ModuleName)
if err != nil {
return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}
}

k.SetScope(ctx, msg.Scope)
Expand Down

0 comments on commit e0621f4

Please sign in to comment.