Skip to content

Commit

Permalink
Allow NAVs to have a greater volume than the marker's supply. (#1883)
Browse files Browse the repository at this point in the history
* Remove the NAV restriction that volume is at most the supply.

* Fix an exchange unit test that started to fail because the NAV is now being recorded, which takes more gas.

* Add changelog entry.
  • Loading branch information
SpicyLemon committed Mar 19, 2024
1 parent 72c333c commit b15d914
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Add a `tourmaline-rc3` upgrade handler to set some new exchange module params related to payments [#1703](https://github.com/provenance-io/provenance/issues/1703).
* Remove the startup warning issued when disable-iavl-fastnode is true (we recommend keeping it as true if you already have it that way) [#1874](https://github.com/provenance-io/provenance/pull/1874).
* Switch to `github.com/cometbft/cometbft-db` `v0.7.0` (from `github.com/tendermint/tm-db` `v0.6.7`) [#1874](https://github.com/provenance-io/provenance/pull/1874).
* Allow NAV volume to exceed a marker's supply [#1883](https://github.com/provenance-io/provenance/pull/1883).

### Bug Fixes

Expand Down
9 changes: 8 additions & 1 deletion x/exchange/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,8 @@ type txCmdTestCase struct {
args []string
// addedFees is any fees to add to the default 10<bond> amount.
addedFees sdk.Coins
// gas is the amount of gas to include. Default is 250,000.
gas int
// expInErr are strings to expect in an error from the cmd.
// Errors that come from the endpoint will not be here; use expInRawLog for those.
expInErr []string
Expand Down Expand Up @@ -563,9 +565,14 @@ func (s *CmdTestSuite) runTxCmdTestCase(tc txCmdTestCase) {
fees = fees.Add(tc.addedFees...)
}

gas := "250000"
if tc.gas > 0 {
gas = fmt.Sprintf("%d", tc.gas)
}

args := append(tc.args, extraArgs...)
args = append(args,
"--"+flags.FlagGas, "250000",
"--"+flags.FlagGas, gas,
"--"+flags.FlagFees, fees.String(),
"--"+flags.FlagBroadcastMode, flags.BroadcastBlock,
"--"+flags.FlagSkipConfirmation,
Expand Down
1 change: 1 addition & 0 deletions x/exchange/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ func (s *CmdTestSuite) TestCmdTxMarketSettle() {
return args, s.assertBalancesFollowup(expBals)
},
args: []string{"settle", "--from", s.addr1.String(), "--market", "5"},
gas: 300_000,
expectedCode: 0,
},
}
Expand Down
8 changes: 1 addition & 7 deletions x/marker/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (

"github.com/tendermint/tendermint/libs/log"

"cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -310,15 +308,11 @@ func (k Keeper) SetNetAssetValue(ctx sdk.Context, marker types.MarkerAccountI, n
}

key := types.NetAssetValueKey(marker.GetAddress(), netAssetValue.Price.Denom)
store := ctx.KVStore(k.storeKey)
if math.NewIntFromUint64(netAssetValue.Volume).GT(marker.GetSupply().Amount) {
return fmt.Errorf("volume (%v) cannot exceed %q marker supply (%v)", netAssetValue.Volume, marker.GetDenom(), marker.GetSupply())
}

bz, err := k.cdc.Marshal(&netAssetValue)
if err != nil {
return err
}
store := ctx.KVStore(k.storeKey)
store.Set(key, bz)

return nil
Expand Down
26 changes: 6 additions & 20 deletions x/marker/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2562,8 +2562,8 @@ func TestAddSetNetAssetValues(t *testing.T) {
marker: redMarker,
navs: []types.NetAssetValue{newNav("3blue", 1001)},
source: "val",
expErr: "cannot set net asset value: volume (1001) cannot exceed \"red\" marker supply (1000red)",
expEvents: sdk.Events{navEvent("red", "3blue", 1001, "val")},
expNavs: []types.NetAssetValue{newNav("3blue", 1001)},
},
{
name: "one nav: success",
Expand All @@ -2581,12 +2581,12 @@ func TestAddSetNetAssetValues(t *testing.T) {
expErr: "cannot set net asset value: marker net asset value volume must be positive value",
},
{
name: "usd nav: too much volume",
name: "usd nav: volume greater than supply",
marker: blueMarker,
navs: []types.NetAssetValue{newNav("55"+types.UsdDenom, 1005)},
source: "wynne",
expEvents: sdk.Events{navEvent("blue", "55"+types.UsdDenom, 1005, "wynne")},
expErr: "cannot set net asset value: volume (1005) cannot exceed \"blue\" marker supply (1000blue)",
expNavs: []types.NetAssetValue{newNav("55"+types.UsdDenom, 1005)},
},
{
name: "usd nav: success",
Expand All @@ -2611,11 +2611,11 @@ func TestAddSetNetAssetValues(t *testing.T) {
{
name: "three navs: error on first",
marker: whiteMarker,
navs: []types.NetAssetValue{newNav("7blue", 1001), newNav("167red", 66), newNav("377yellow", 89)},
navs: []types.NetAssetValue{newNav("7blue", 0), newNav("167red", 66), newNav("377yellow", 89)},
source: "knox",
expErr: "cannot set net asset value: volume (1001) cannot exceed \"white\" marker supply (1000white)",
expErr: "cannot set net asset value: marker net asset value volume must be positive value",
expEvents: sdk.Events{
navEvent("white", "7blue", 1001, "knox"),
// no blue event because the nav is invalid.
navEvent("white", "167red", 66, "knox"),
navEvent("white", "377yellow", 89, "knox"),
},
Expand Down Expand Up @@ -2647,20 +2647,6 @@ func TestAddSetNetAssetValues(t *testing.T) {
},
expNavs: []types.NetAssetValue{newNav("788blue", 14), newNav("215red", 3)},
},
{
name: "three navs: error on all",
marker: whiteMarker,
navs: []types.NetAssetValue{newNav("44blue", 1001), newNav("55red", 0), newNav("66yellow", 1002)},
source: "lynn",
expErr: "cannot set net asset value: volume (1001) cannot exceed \"white\" marker supply (1000white)" + "\n" +
"cannot set net asset value: marker net asset value volume must be positive value" + "\n" +
"cannot set net asset value: volume (1002) cannot exceed \"white\" marker supply (1000white)",
expEvents: sdk.Events{
navEvent("white", "44blue", 1001, "lynn"),
// nav 2 is invalid, so no event from it.
navEvent("white", "66yellow", 1002, "lynn"),
},
},
}

for _, tc := range tests {
Expand Down

0 comments on commit b15d914

Please sign in to comment.