Skip to content

Commit

Permalink
rename price_per_token to price
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpointer0x00 committed Aug 29, 2023
1 parent 70d3a16 commit 9227bfb
Show file tree
Hide file tree
Showing 18 changed files with 225 additions and 226 deletions.
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36163,7 +36163,7 @@ paths:
items:
type: object
properties:
price_per_token:
price:
type: object
properties:
denom:
Expand All @@ -36178,7 +36178,7 @@ paths:
custom method

signatures required by gogoproto.
title: price_per_token is the price per unit for given volume
title: price is the complete value of the asset's volume
volume:
type: string
format: uint64
Expand Down Expand Up @@ -83287,7 +83287,7 @@ definitions:
provenance.marker.v1.NetAssetValue:
type: object
properties:
price_per_token:
price:
type: object
properties:
denom:
Expand All @@ -83299,7 +83299,7 @@ definitions:

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
title: price_per_token is the price per unit for given volume
title: price is the complete value of the asset's volume
volume:
type: string
format: uint64
Expand Down Expand Up @@ -83905,7 +83905,7 @@ definitions:
items:
type: object
properties:
price_per_token:
price:
type: object
properties:
denom:
Expand All @@ -83920,7 +83920,7 @@ definitions:
method

signatures required by gogoproto.
title: price_per_token is the price per unit for given volume
title: price is the complete value of the asset's volume
volume:
type: string
format: uint64
Expand Down
4 changes: 2 additions & 2 deletions docs/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ EventSetNetAssetValue event emitted when Net Asset Value for marker is update or
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `denom` | [string](#string) | | |
| `price_per_token` | [string](#string) | | |
| `price` | [string](#string) | | |
| `volume` | [string](#string) | | |
| `source` | [string](#string) | | |

Expand Down Expand Up @@ -1708,7 +1708,7 @@ NetAssetValue defines a marker's net asset value

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `price_per_token` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | price_per_token is the price per unit for given volume |
| `price` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | price is the complete value of the asset's volume |
| `volume` | [uint64](#uint64) | | volume is the volume of the assets |
| `updated_block_height` | [uint64](#uint64) | | updated_block_height is the block height of last update |

Expand Down
12 changes: 6 additions & 6 deletions internal/handlers/bank_send_restriction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func TestBankSend(tt *testing.T) {
nrMarkerAcct := markertypes.NewMarkerAccount(nrMarkerBaseAcct, sdk.NewInt64Coin(nrMarkerDenom, 10_000), addr1, []markertypes.AccessGrant{{Address: acct1.Address,
Permissions: []markertypes.Access{markertypes.Access_Withdraw}}}, markertypes.StatusProposed, markertypes.MarkerType_Coin, true, true, false, []string{})
require.NoError(tt, app.MarkerKeeper.SetNetAssetValue(ctx, nrMarkerAcct, markertypes.NetAssetValue{
PricePerToken: sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, 1),
Volume: 1,
Price: sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, 1),
Volume: 1,
}, "test"), "SetNetAssetValue failed to create nav for marker")
require.NoError(tt, app.MarkerKeeper.AddFinalizeAndActivateMarker(ctx, nrMarkerAcct),
"AddFinalizeAndActivateMarker failed to create marker")
Expand All @@ -62,8 +62,8 @@ func TestBankSend(tt *testing.T) {
rMarkerAcct := markertypes.NewMarkerAccount(rMarkerBaseAcct, sdk.NewInt64Coin(restrictedMarkerDenom, 10_000), addr1, []markertypes.AccessGrant{{Address: acct1.Address,
Permissions: []markertypes.Access{markertypes.Access_Withdraw, markertypes.Access_Transfer}}}, markertypes.StatusProposed, markertypes.MarkerType_RestrictedCoin, true, true, false, []string{})
require.NoError(tt, app.MarkerKeeper.SetNetAssetValue(ctx, rMarkerAcct, markertypes.NetAssetValue{
PricePerToken: sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, 1),
Volume: 1,
Price: sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, 1),
Volume: 1,
}, "test"), "SetNetAssetValue failed to create nav for marker")
require.NoError(tt, app.MarkerKeeper.AddFinalizeAndActivateMarker(ctx, rMarkerAcct), "AddFinalizeAndActivateMarker failed to create marker")

Expand All @@ -72,8 +72,8 @@ func TestBankSend(tt *testing.T) {
raMarkerAcct := markertypes.NewMarkerAccount(raMarkerBaseAcct, sdk.NewInt64Coin(restrictedAttrMarkerDenom, 10_000), addr1, []markertypes.AccessGrant{{Address: acct1.Address,
Permissions: []markertypes.Access{markertypes.Access_Withdraw, markertypes.Access_Transfer}}}, markertypes.StatusProposed, markertypes.MarkerType_RestrictedCoin, true, true, false, []string{"some.kyc.provenance.io"})
require.NoError(tt, app.MarkerKeeper.SetNetAssetValue(ctx, raMarkerAcct, markertypes.NetAssetValue{
PricePerToken: sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, 1),
Volume: 1,
Price: sdk.NewInt64Coin(pioconfig.GetProvenanceConfig().BondDenom, 1),
Volume: 1,
}, "test"), "SetNetAssetValue failed to create nav for marker")
require.NoError(tt, app.MarkerKeeper.AddFinalizeAndActivateMarker(ctx, raMarkerAcct), "AddFinalizeAndActivateMarker failed to create marker")

Expand Down
12 changes: 6 additions & 6 deletions proto/provenance/marker/v1/marker.proto
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ enum MarkerStatus {

// NetAssetValue defines a marker's net asset value
message NetAssetValue {
// price_per_token is the price per unit for given volume
cosmos.base.v1beta1.Coin price_per_token = 1 [(gogoproto.nullable) = false];
// price is the complete value of the asset's volume
cosmos.base.v1beta1.Coin price = 1 [(gogoproto.nullable) = false];
// volume is the volume of the assets
uint64 volume = 2;
// updated_block_height is the block height of last update
Expand Down Expand Up @@ -208,8 +208,8 @@ message EventDenomUnit {

// EventSetNetAssetValue event emitted when Net Asset Value for marker is update or added
message EventSetNetAssetValue {
string denom = 1;
string price_per_token = 2;
string volume = 3;
string source = 4;
string denom = 1;
string price = 2;
string volume = 3;
string source = 4;
}
4 changes: 2 additions & 2 deletions x/marker/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1925,13 +1925,13 @@ func (s *IntegrationTestSuite) TestParseNetAssertValueString() {
name: "successfully parse single nav",
netAssetValues: "1hotdog,10",
expErr: "",
expResult: []types.NetAssetValue{{PricePerToken: sdk.NewInt64Coin("hotdog", 1), Volume: 10}},
expResult: []types.NetAssetValue{{Price: sdk.NewInt64Coin("hotdog", 1), Volume: 10}},
},
{
name: "successfully parse multi nav",
netAssetValues: "1hotdog,10;20jackthecat,40",
expErr: "",
expResult: []types.NetAssetValue{{PricePerToken: sdk.NewInt64Coin("hotdog", 1), Volume: 10}, {PricePerToken: sdk.NewInt64Coin("jackthecat", 20), Volume: 40}},
expResult: []types.NetAssetValue{{Price: sdk.NewInt64Coin("hotdog", 1), Volume: 10}, {Price: sdk.NewInt64Coin("jackthecat", 20), Volume: 40}},
},
}
for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion x/marker/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) {
panic(err)
}
address := sdk.MustAccAddressFromBech32(mNavs.Address)
store.Set(types.NetAssetValueKey(address, navCopy.PricePerToken.Denom), bz)
store.Set(types.NetAssetValueKey(address, navCopy.Price.Denom), bz)
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions x/marker/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ func (k Keeper) RemoveSendDeny(ctx sdk.Context, markerAddr, senderAddr sdk.AccAd
// AddSetNetAssetValues adds a set of net asset values to a marker
func (k Keeper) AddSetNetAssetValues(ctx sdk.Context, marker types.MarkerAccountI, netAssetValues []types.NetAssetValue, source string) error {
for _, nav := range netAssetValues {
if nav.PricePerToken.Denom == marker.GetDenom() {
if nav.Price.Denom == marker.GetDenom() {
return fmt.Errorf("net asset value denom cannot match marker denom %q", marker.GetDenom())
}
if nav.PricePerToken.Denom != types.UsdDenom {
_, err := k.GetMarkerByDenom(ctx, nav.PricePerToken.Denom)
if nav.Price.Denom != types.UsdDenom {
_, err := k.GetMarkerByDenom(ctx, nav.Price.Denom)
if err != nil {
return fmt.Errorf("net asset value denom does not exist: %v", err.Error())
}
Expand All @@ -249,12 +249,12 @@ func (k Keeper) SetNetAssetValue(ctx sdk.Context, marker types.MarkerAccountI, n
return err
}

setNetAssetValueEvent := types.NewEventSetNetAssetValue(marker.GetDenom(), netAssetValue.PricePerToken, netAssetValue.Volume, source)
setNetAssetValueEvent := types.NewEventSetNetAssetValue(marker.GetDenom(), netAssetValue.Price, netAssetValue.Volume, source)
if err := ctx.EventManager().EmitTypedEvent(setNetAssetValueEvent); err != nil {
return err
}

key := types.NetAssetValueKey(marker.GetAddress(), netAssetValue.PricePerToken.Denom)
key := types.NetAssetValueKey(marker.GetAddress(), netAssetValue.Price.Denom)
store := ctx.KVStore(k.storeKey)

value := store.Get(key)
Expand Down Expand Up @@ -287,17 +287,17 @@ func (k Keeper) SetNetAssetValue(ctx sdk.Context, marker types.MarkerAccountI, n

// CalculateRollingAverage returns an updated net asset value with an average price per token and summed volume
func (k Keeper) CalculateRollingAverage(prevNav types.NetAssetValue, netAssetValue types.NetAssetValue) (types.NetAssetValue, error) {
if prevNav.PricePerToken.Denom != netAssetValue.PricePerToken.Denom {
return types.NetAssetValue{}, fmt.Errorf("net asset value denom do not match %v:%v", prevNav.PricePerToken.Denom, netAssetValue.PricePerToken.Denom)
if prevNav.Price.Denom != netAssetValue.Price.Denom {
return types.NetAssetValue{}, fmt.Errorf("net asset value denom do not match %v:%v", prevNav.Price.Denom, netAssetValue.Price.Denom)
}
totalVolume := prevNav.Volume + netAssetValue.Volume
if totalVolume == 0 {
return netAssetValue, nil
}
prevTotalPrice := prevNav.PricePerToken.Amount.Mul(sdk.NewInt(int64(prevNav.Volume)))
currentTotalPrice := netAssetValue.PricePerToken.Amount.Mul(sdk.NewInt(int64(netAssetValue.Volume)))
prevTotalPrice := prevNav.Price.Amount.Mul(sdk.NewInt(int64(prevNav.Volume)))
currentTotalPrice := netAssetValue.Price.Amount.Mul(sdk.NewInt(int64(netAssetValue.Volume)))
average := prevTotalPrice.Add(currentTotalPrice).Quo(sdk.NewInt(int64(totalVolume)))
netAssetValue.PricePerToken = sdk.NewCoin(prevNav.PricePerToken.Denom, average)
netAssetValue.Price = sdk.NewCoin(prevNav.Price.Denom, average)
netAssetValue.Volume = totalVolume
return netAssetValue, nil
}
Expand Down
28 changes: 14 additions & 14 deletions x/marker/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1474,41 +1474,41 @@ func TestCalculateRollingAverage(t *testing.T) {
{
name: "denoms do not match",
prevNav: types.NetAssetValue{
PricePerToken: sdk.NewInt64Coin("denoma", 1),
Price: sdk.NewInt64Coin("denoma", 1),
},
newNav: types.NetAssetValue{
PricePerToken: sdk.NewInt64Coin("denomb", 1),
Price: sdk.NewInt64Coin("denomb", 1),
},
expErr: "net asset value denom do not match denoma:denomb",
},
{
name: "succesfully compute rolling average and new volume",
prevNav: types.NetAssetValue{
PricePerToken: sdk.NewInt64Coin("usd", 100),
Volume: 2,
Price: sdk.NewInt64Coin("usd", 100),
Volume: 2,
},
newNav: types.NetAssetValue{
PricePerToken: sdk.NewInt64Coin("usd", 50),
Volume: 2,
Price: sdk.NewInt64Coin("usd", 50),
Volume: 2,
},
expNav: types.NetAssetValue{
PricePerToken: sdk.NewInt64Coin("usd", 75),
Volume: 4,
Price: sdk.NewInt64Coin("usd", 75),
Volume: 4,
},
},
{
name: "succesfully compute rolling average with rounding and new volume",
prevNav: types.NetAssetValue{
PricePerToken: sdk.NewInt64Coin("usd", 99),
Volume: 2,
Price: sdk.NewInt64Coin("usd", 99),
Volume: 2,
},
newNav: types.NetAssetValue{
PricePerToken: sdk.NewInt64Coin("usd", 50),
Volume: 2,
Price: sdk.NewInt64Coin("usd", 50),
Volume: 2,
},
expNav: types.NetAssetValue{
PricePerToken: sdk.NewInt64Coin("usd", 74),
Volume: 4,
Price: sdk.NewInt64Coin("usd", 74),
Volume: 4,
},
},
}
Expand Down
46 changes: 23 additions & 23 deletions x/marker/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ func (s *MsgServerTestSuite) TestMsgAddMarkerRequest() {
MarkerType: types.MarkerType_Coin.String(),
},
&types.EventSetNetAssetValue{
Denom: denom,
PricePerToken: "0usd",
Volume: "0",
Source: types.ModuleName,
Denom: denom,
Price: "0usd",
Volume: "0",
Source: types.ModuleName,
},
},
},
Expand Down Expand Up @@ -169,10 +169,10 @@ func (s *MsgServerTestSuite) TestMsgAddMarkerRequest() {
MarkerType: types.MarkerType_Coin.String(),
},
&types.EventSetNetAssetValue{
Denom: navDenom,
PricePerToken: "1usd",
Volume: "10",
Source: types.ModuleName,
Denom: navDenom,
Price: "1usd",
Volume: "10",
Source: types.ModuleName,
},
},
},
Expand All @@ -198,10 +198,10 @@ func (s *MsgServerTestSuite) TestMsgAddMarkerRequest() {
MarkerType: types.MarkerType_Coin.String(),
},
&types.EventSetNetAssetValue{
Denom: denomWithDashPeriod,
PricePerToken: "0usd",
Volume: "0",
Source: types.ModuleName,
Denom: denomWithDashPeriod,
Price: "0usd",
Volume: "0",
Source: types.ModuleName,
},
},
},
Expand All @@ -228,10 +228,10 @@ func (s *MsgServerTestSuite) TestMsgAddMarkerRequest() {
MarkerType: types.MarkerType_RestrictedCoin.String(),
},
&types.EventSetNetAssetValue{
Denom: rdenom,
PricePerToken: "0usd",
Volume: "0",
Source: types.ModuleName,
Denom: rdenom,
Price: "0usd",
Volume: "0",
Source: types.ModuleName,
},
},
},
Expand Down Expand Up @@ -282,7 +282,7 @@ func (s *MsgServerTestSuite) TestMsgFinalizeMarkerRequest() {
)
validMarker.Supply = sdk.NewInt(1)
s.Require().NoError(s.app.MarkerKeeper.AddMarkerAccount(s.ctx, validMarker))
s.Require().NoError(s.app.MarkerKeeper.SetNetAssetValue(s.ctx, validMarker, types.NetAssetValue{PricePerToken: sdk.NewInt64Coin(types.UsdDenom, 1), Volume: 1}, "test"))
s.Require().NoError(s.app.MarkerKeeper.SetNetAssetValue(s.ctx, validMarker, types.NetAssetValue{Price: sdk.NewInt64Coin(types.UsdDenom, 1), Volume: 1}, "test"))

testCases := []struct {
name string
Expand Down Expand Up @@ -635,8 +635,8 @@ func (s *MsgServerTestSuite) TestAddNetAssetValue() {
Denom: "cantfindme",
NetAssetValues: []types.NetAssetValue{
{
PricePerToken: sdk.NewInt64Coin("navcoin", 1),
Volume: 1,
Price: sdk.NewInt64Coin("navcoin", 1),
Volume: 1,
}},
Administrator: authUser.String()},
expErr: "marker cantfindme not found for address: cosmos17l2yneua2mdfqaycgyhqag8t20asnjwf6adpmt: invalid request",
Expand All @@ -647,7 +647,7 @@ func (s *MsgServerTestSuite) TestAddNetAssetValue() {
Denom: markerDenom,
NetAssetValues: []types.NetAssetValue{
{
PricePerToken: sdk.NewInt64Coin(markerDenom, 100),
Price: sdk.NewInt64Coin(markerDenom, 100),
Volume: uint64(100),
UpdatedBlockHeight: 1,
},
Expand All @@ -662,7 +662,7 @@ func (s *MsgServerTestSuite) TestAddNetAssetValue() {
Denom: markerDenom,
NetAssetValues: []types.NetAssetValue{
{
PricePerToken: sdk.NewInt64Coin("hotdog", 100),
Price: sdk.NewInt64Coin("hotdog", 100),
Volume: uint64(100),
UpdatedBlockHeight: 1,
},
Expand All @@ -677,7 +677,7 @@ func (s *MsgServerTestSuite) TestAddNetAssetValue() {
Denom: markerDenom,
NetAssetValues: []types.NetAssetValue{
{
PricePerToken: sdk.NewInt64Coin(types.UsdDenom, 100),
Price: sdk.NewInt64Coin(types.UsdDenom, 100),
Volume: uint64(100),
UpdatedBlockHeight: 1,
},
Expand All @@ -692,7 +692,7 @@ func (s *MsgServerTestSuite) TestAddNetAssetValue() {
Denom: markerDenom,
NetAssetValues: []types.NetAssetValue{
{
PricePerToken: sdk.NewInt64Coin(types.UsdDenom, 100),
Price: sdk.NewInt64Coin(types.UsdDenom, 100),
Volume: uint64(100),
UpdatedBlockHeight: 1,
},
Expand Down
2 changes: 1 addition & 1 deletion x/marker/spec/01_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ iterator from the auth module.

### Marker Net Asset Value

A marker can support multiple distinct net asset values assigned to track settlement pricing information on-chain. The `price_per_token` attribute represents the coin value of the asset, such as `usd` or `nhash`, along with its corresponding `volume`. The `update_block_height` attribute captures the block height when the update occurred.
A marker can support multiple distinct net asset values assigned to track settlement pricing information on-chain. The `price` attribute denotes the value assigned to the marker for a specific asset's associated `volume`. For instance, when considering a scenario where 10 billion `nhash` holds a value of 15¢, the corresponding `volume` should reflect the quantity of 10,000,000,000. The `update_block_height` attribute captures the block height when the update occurred.

+++ https://github.com/provenance-io/provenance/blob/25070572cc898c476f5bb1a816c6c1c4d07e3d38/proto/provenance/marker/v1/marker.proto#L96-L104

Expand Down
Loading

0 comments on commit 9227bfb

Please sign in to comment.