Skip to content

Commit

Permalink
Merge branch 'master' into feature/market-version-query
Browse files Browse the repository at this point in the history
  • Loading branch information
Unique-Divine committed Sep 19, 2023
2 parents 004b616 + cdf86c5 commit c7e3d5e
Show file tree
Hide file tree
Showing 21 changed files with 801 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/changelog-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
# TODO: feat: try to use author of the commit(s) to see if it's dependabot
# ${{ any(contains(commit.author.username, 'dependabot') for commit in github.event.commits) }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
with:
token: ${{ secrets.NIBIRU_PM }}
# to avoid checking out the repo in a detached state
Expand Down
31 changes: 0 additions & 31 deletions .github/workflows/coverage.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3

- name: Get version
id: get_version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
get-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download release
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3

- uses: actions/setup-go@v4
with:
go-version: 1.19
cache: false # the golangci-lint action already caches for us (https://github.com/golangci/golangci-lint-action#performance)

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.52.1
version: v1.54.2

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- uses: actions/checkout@v4
- uses: actions/checkout@v3
with:
fetch-depth: 0

Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Integration tests

on:
workflow_dispatch: # Runs on manual calls
schedule:
- cron: "0 0 * * *" # Runs automatically every day
pull_request:
# paths makes the action run only when the given paths are changed
paths: ["**.go", "**.proto", "go.mod", "go.sum"]
Expand All @@ -15,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
Expand All @@ -24,4 +27,7 @@ jobs:
cache: true

- name: Run all integration tests.
run: make test-integration
run: make test-coverage-integration

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
4 changes: 2 additions & 2 deletions .github/workflows/proto-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
# runs-on: ubuntu-latest
# timeout-minutes: 5
# steps:
# - uses: actions/checkout@v4
# - uses: actions/checkout@v3
# - uses: bufbuild/[email protected]
# - uses: bufbuild/buf-lint-action@v1
# with:
Expand All @@ -30,7 +30,7 @@ jobs:
break-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- uses: bufbuild/[email protected]
- uses: bufbuild/buf-breaking-action@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
install-runsim:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: 1.19
Expand All @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
needs: [install-runsim]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
with:
SUFFIX_FILTER: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
Expand All @@ -22,12 +22,12 @@ jobs:
cache: true

- name: Run all unit tests.
run: make test-unit
run: make test-coverage

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1574](https://github.com/NibiruChain/nibiru/pull/1574) - chore(goreleaser): update wasmvm to v1.4.0

### Features

* [#1575](https://github.com/NibiruChain/nibiru/pull/1575) - feat(perp): Add trader volume tracking
* [#1463](https://github.com/NibiruChain/nibiru/pull/1463) - feat(oracle): add genesis pricefeeder delegation
* [#1479](https://github.com/NibiruChain/nibiru/pull/1479) - feat(perp): implement `PartialClose`
* [#1498](https://github.com/NibiruChain/nibiru/pull/1498) - feat: add cli to change root sudo command
Expand All @@ -81,6 +81,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1459](https://github.com/NibiruChain/nibiru/pull/1459) - fix(spot): wire `x/spot` msgService into app router
* [#1467](https://github.com/NibiruChain/nibiru/pull/1467) - fix(oracle): make `calcTwap` safer
* [#1464](https://github.com/NibiruChain/nibiru/pull/1464) - fix(gov): wire legacy proposal handlers
* [#1586](https://github.com/NibiruChain/nibiru/pull/1586) - fix(sudo): make messages compatible with `Amino`

### State Machine Breaking

Expand Down Expand Up @@ -649,4 +650,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Testing

* [#695](https://github.com/NibiruChain/nibiru/pull/695) Add `OpenPosition` integration tests.
* [#692](https://github.com/NibiruChain/nibiru/pull/692) Add test coverage for Perp MsgServer methods.
* [#692](https://github.com/NibiruChain/nibiru/pull/692) Add test coverage for Perp MsgServer methods.
12 changes: 2 additions & 10 deletions contrib/make/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@

PACKAGES_NOSIMULATION = ${shell go list ./... | grep -v simapp}

.PHONY: test-unit
test-unit:
go test -v $(PACKAGES_NOSIMULATION) -short -coverprofile=coverage.txt -covermode=count

.PHONY: test-integration
test-integration:
go test -v $(PACKAGES_NOSIMULATION) -coverprofile=coverage.txt -covermode=count

# Used for CI by Codecov
.PHONY: test-coverage
test-coverage:
go test ./... -short \
go test ./... -v $(PACKAGES_NOSIMULATION) -short \
-coverprofile=coverage.txt \
-covermode=atomic \
-race | grep -v "no test" | grep -v "no statement"

.PHONY: test-coverage-integration
test-coverage-integration:
go test ./... \
go test ./... -v $(PACKAGES_NOSIMULATION) \
-coverprofile=coverage.txt \
-covermode=atomic \
-race | grep -v "no test" | grep -v "no statement"
Expand Down
23 changes: 19 additions & 4 deletions proto/nibiru/perp/v2/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,32 @@ option go_package = "github.com/NibiruChain/nibiru/x/perp/v2/types";
message GenesisState {
repeated Market markets = 2 [ (gogoproto.nullable) = false ];

repeated GenesisMarketLastVersion market_last_versions = 6 [ (gogoproto.nullable) = false ];

repeated AMM amms = 3 [ (gogoproto.nullable) = false ];

repeated Position positions = 4 [ (gogoproto.nullable) = false ];

repeated ReserveSnapshot reserve_snapshots = 5
[ (gogoproto.nullable) = false ];

uint64 dnr_epoch = 6;

repeated TraderVolume trader_volumes = 7 [ (gogoproto.nullable) = false ];

message TraderVolume {
string trader = 1;
uint64 epoch = 2;
string volume = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

repeated GenesisMarketLastVersion market_last_versions = 8
[ (gogoproto.nullable) = false ];
}

// GenesisMarketLastVersion is the last version including pair only used for genesis
// GenesisMarketLastVersion is the last version including pair only used for
// genesis
message GenesisMarketLastVersion {
string pair = 1 [
(gogoproto.customtype) =
Expand All @@ -32,4 +47,4 @@ message GenesisMarketLastVersion {
];

uint64 version = 2;
}
}
94 changes: 94 additions & 0 deletions x/perp/v2/integration/action/dnr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package action

import (
"fmt"

"cosmossdk.io/math"
"github.com/NibiruChain/collections"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/NibiruChain/nibiru/app"
"github.com/NibiruChain/nibiru/x/common/testutil/action"
)

func DnREpochIs(epoch uint64) action.Action {
return &setEpochAction{
Epoch: epoch,
}
}

type setEpochAction struct {
Epoch uint64
}

func (s setEpochAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) {
app.PerpKeeperV2.DnREpoch.Set(ctx, s.Epoch)
return ctx, nil, true
}

func DnRCurrentVolumeIs(user sdk.AccAddress, wantVolume math.Int) action.Action {
return &expectVolumeAction{
User: user,
Volume: wantVolume,
}
}

type expectVolumeAction struct {
User sdk.AccAddress
Volume math.Int
}

func (e expectVolumeAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) {
currentEpoch, err := app.PerpKeeperV2.DnREpoch.Get(ctx)
if err != nil {
return ctx, err, true
}
volume, err := app.PerpKeeperV2.TraderVolumes.Get(ctx, collections.Join(e.User, currentEpoch))
if err != nil {
return ctx, err, true
}
if !volume.Equal(e.Volume) {
return ctx, fmt.Errorf("unexpected user dnr volume, wanted %s, got %s", e.Volume, volume), true
}
return ctx, nil, true
}

func DnRPreviousVolumeIs(user sdk.AccAddress, wantVolume math.Int) action.Action {
return &expectPreviousVolumeAction{
User: user,
Volume: wantVolume,
}
}

type expectPreviousVolumeAction struct {
User sdk.AccAddress
Volume math.Int
}

func (e expectPreviousVolumeAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) {
v := app.PerpKeeperV2.GetUserVolumeLastEpoch(ctx, e.User)
if !v.Equal(e.Volume) {
return ctx, fmt.Errorf("unexpected user dnr volume, wanted %s, got %s", e.Volume, v), true
}
return ctx, nil, true
}

func DnRVolumeNotExist(user sdk.AccAddress, epoch uint64) action.Action {
return &expectVolumeNotExistAction{
Epoch: epoch,
User: user,
}
}

type expectVolumeNotExistAction struct {
Epoch uint64
User sdk.AccAddress
}

func (e expectVolumeNotExistAction) Do(app *app.NibiruApp, ctx sdk.Context) (outCtx sdk.Context, err error, isMandatory bool) {
v, err := app.PerpKeeperV2.TraderVolumes.Get(ctx, collections.Join(e.User, e.Epoch))
if err == nil {
return ctx, fmt.Errorf("unexpected user dnr volume, got %s", v), true
}
return ctx, nil, true
}
7 changes: 7 additions & 0 deletions x/perp/v2/keeper/clearing_house.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,13 @@ func (k Keeper) afterPositionUpdate(
}
}

// update user volume
dnrEpoch, err := k.DnREpoch.Get(ctx)
if err != nil {
return err
}
k.IncreaseTraderVolume(ctx, dnrEpoch, traderAddr, positionResp.ExchangedNotionalValue.Abs().TruncateInt())

transferredFee, err := k.transferFee(ctx, market.Pair, traderAddr, positionResp.ExchangedNotionalValue,
market.ExchangeFeeRatio, market.EcosystemFundFeeRatio,
)
Expand Down
Loading

0 comments on commit c7e3d5e

Please sign in to comment.