diff --git a/x/marker/client/cli/cli_test.go b/x/marker/client/cli/cli_test.go index 1a75e93e95..57e962db74 100644 --- a/x/marker/client/cli/cli_test.go +++ b/x/marker/client/cli/cli_test.go @@ -567,7 +567,7 @@ func (s *IntegrationTestSuite) TestMarkerQueryCommands() { name: "marker net asset value query", cmd: markercli.NetAssetValuesCmd(), args: []string{"testcoin"}, - expectedOutput: "net_asset_values:\n- price_per_token:\n amount: \"100\"\n denom: usd\n updated_block_height: \"0\"\n volume: \"100\"", + expectedOutput: "net_asset_values:\n- price:\n amount: \"100\"\n denom: usd\n updated_block_height: \"0\"\n volume: \"100\"", }, } for _, tc := range testCases { diff --git a/x/marker/keeper/keeper.go b/x/marker/keeper/keeper.go index 52b8e5af5d..4f2adc7141 100644 --- a/x/marker/keeper/keeper.go +++ b/x/marker/keeper/keeper.go @@ -242,7 +242,6 @@ func (k Keeper) AddSetNetAssetValues(ctx sdk.Context, marker types.MarkerAccount } // SetNetAssetValue adds/updates a net asset value to marker -// If multiple net asset values are set during same block height that rolling average will be stored func (k Keeper) SetNetAssetValue(ctx sdk.Context, marker types.MarkerAccountI, netAssetValue types.NetAssetValue, source string) error { netAssetValue.UpdatedBlockHeight = uint64(ctx.BlockHeight()) if err := netAssetValue.Validate(); err != nil { @@ -256,22 +255,6 @@ func (k Keeper) SetNetAssetValue(ctx sdk.Context, marker types.MarkerAccountI, n key := types.NetAssetValueKey(marker.GetAddress(), netAssetValue.Price.Denom) store := ctx.KVStore(k.storeKey) - - value := store.Get(key) - if value != nil { - var prevNav types.NetAssetValue - err := k.cdc.Unmarshal(value, &prevNav) - if err != nil { - return err - } - if prevNav.UpdatedBlockHeight == netAssetValue.UpdatedBlockHeight { - netAssetValue, err = k.CalculateRollingAverage(prevNav, netAssetValue) - if err != nil { - return err - } - } - } - if netAssetValue.Volume > marker.GetSupply().Amount.Uint64() { return fmt.Errorf("volume(%v) cannot exceed marker %q supply(%v) ", netAssetValue.Volume, marker.GetDenom(), marker.GetSupply()) } @@ -285,23 +268,6 @@ func (k Keeper) SetNetAssetValue(ctx sdk.Context, marker types.MarkerAccountI, n return nil } -// 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.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.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.Price = sdk.NewCoin(prevNav.Price.Denom, average) - netAssetValue.Volume = totalVolume - return netAssetValue, nil -} - // IterateNetAssetValues iterates net asset values for marker func (k Keeper) IterateNetAssetValues(ctx sdk.Context, markerAddr sdk.AccAddress, handler func(state types.NetAssetValue) (stop bool)) error { store := ctx.KVStore(k.storeKey) diff --git a/x/marker/keeper/keeper_test.go b/x/marker/keeper/keeper_test.go index d3f8783007..b004d6e6c3 100644 --- a/x/marker/keeper/keeper_test.go +++ b/x/marker/keeper/keeper_test.go @@ -1455,73 +1455,3 @@ func TestBypassAddrsLocked(t *testing.T) { act00 := kAddrs[0][0] assert.Equal(t, orig00, act00, "first byte of first address returned by GetReqAttrBypassAddrs") } - -func TestCalculateRollingAverage(t *testing.T) { - mk := markerkeeper.NewKeeper(nil, nil, paramtypes.NewSubspace(nil, nil, nil, nil, "test"), nil, &dummyBankKeeper{}, nil, nil, nil, nil, nil, nil) - testCases := []struct { - name string - prevNav types.NetAssetValue - newNav types.NetAssetValue - expNav types.NetAssetValue - expErr string - }{ - { - name: "volumes are zero", - prevNav: types.NetAssetValue{}, - newNav: types.NetAssetValue{}, - expNav: types.NetAssetValue{}, - }, - { - name: "denoms do not match", - prevNav: types.NetAssetValue{ - Price: sdk.NewInt64Coin("denoma", 1), - }, - newNav: types.NetAssetValue{ - 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{ - Price: sdk.NewInt64Coin("usd", 100), - Volume: 2, - }, - newNav: types.NetAssetValue{ - Price: sdk.NewInt64Coin("usd", 50), - Volume: 2, - }, - expNav: types.NetAssetValue{ - Price: sdk.NewInt64Coin("usd", 75), - Volume: 4, - }, - }, - { - name: "succesfully compute rolling average with rounding and new volume", - prevNav: types.NetAssetValue{ - Price: sdk.NewInt64Coin("usd", 99), - Volume: 2, - }, - newNav: types.NetAssetValue{ - Price: sdk.NewInt64Coin("usd", 50), - Volume: 2, - }, - expNav: types.NetAssetValue{ - Price: sdk.NewInt64Coin("usd", 74), - Volume: 4, - }, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - result, err := mk.CalculateRollingAverage(tc.prevNav, tc.newNav) - if len(tc.expErr) > 0 { - assert.EqualError(t, err, tc.expErr) - } else { - assert.NoError(t, err) - assert.Equal(t, tc.expNav, result) - } - }) - } -}