From 06b06b881a4a0b766643fdb6309e3a1d823e0776 Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Wed, 1 May 2024 13:10:53 -0400 Subject: [PATCH] refactor(oracle): add oracle slashing events (#1859) * refactor(oracle): add oracle slashing events * Update CHANGELOG.md --- CHANGELOG.md | 129 ++++++++++++++++-------------- x/oracle/keeper/keeper.go | 18 +++-- x/oracle/keeper/slash.go | 9 +-- x/oracle/keeper/test_utils.go | 14 +++- x/oracle/types/expected_keeper.go | 5 ++ 5 files changed, 101 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 097de9bb4..42431eae2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,18 +40,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## [v1.0.0.post1](https://github.com/NibiruChain/nibiru/releases/tag/v1.0.0.post1) + +### Improvements + +* [#1859](https://github.com/NibiruChain/nibiru/pull/1859) - refactor(oracle): add oracle slashing events + ## [v1.0.0](https://github.com/NibiruChain/nibiru/releases/tag/v1.0.0) -### Features +### Features * [#1596](https://github.com/NibiruChain/nibiru/pull/1596) - epic(tokenfactory): State transitions, collections, genesis import and export, and app wiring -* [#1607](https://github.com/NibiruChain/nibiru/pull/1607) - Token factory transaction messages for CreateDenom, ChangeAdmin, and UpdateModuleParams +* [#1607](https://github.com/NibiruChain/nibiru/pull/1607) - Token factory transaction messages for CreateDenom, ChangeAdmin, and UpdateModuleParams * [#1620](https://github.com/NibiruChain/nibiru/pull/1620) - Token factory transaction messages for Mint and Burn * [#1573](https://github.com/NibiruChain/nibiru/pull/1573) - feat(perp): Close markets and compute settlement price * [#1632](https://github.com/NibiruChain/nibiru/pull/1632) - feat(perp): Add settle position transaction * [#1658](https://github.com/NibiruChain/nibiru/pull/1658) - feat(oracle): add `EditOracleParams` message -### State Machine Breaking +### State Machine Breaking * [#1609](https://github.com/NibiruChain/nibiru/pull/1609) - refactor(app)!: Remove x/stablecoin module. * [#1613](https://github.com/NibiruChain/nibiru/pull/1613) - feat(app)!: enforce min commission by changing default and genesis validation @@ -72,15 +78,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1659](https://github.com/NibiruChain/nibiru/pull/1659) - refactor(oracle): curate oracle default whitelist ### Dependencies -- Bump `github.com/prometheus/client_golang` from 1.16.0 to 1.17.0 ([#1605](https://github.com/NibiruChain/nibiru/pull/1605)) -- Bump `bufbuild/buf-setup-action` from 1.26.1 to 1.27.1 ([#1624](https://github.com/NibiruChain/nibiru/pull/1624), [#1641](https://github.com/NibiruChain/nibiru/pull/1641)) -- Bump `stefanzweifel/git-auto-commit-action` from 4 to 5 ([#1625](https://github.com/NibiruChain/nibiru/pull/1625)) -- Bump `github.com/CosmWasm/wasmvm` from 1.4.0 to 1.5.0 ([#1629](https://github.com/NibiruChain/nibiru/pull/1629), [#1657](https://github.com/NibiruChain/nibiru/pull/1657)) -- Bump `google.golang.org/grpc` from 1.58.2 to 1.59.0 ([#1633](https://github.com/NibiruChain/nibiru/pull/1633), [#1643](https://github.com/NibiruChain/nibiru/pull/1643)) -- Bump `golang.org/x/net` from 0.12.0 to 0.17.0 ([#1634](https://github.com/NibiruChain/nibiru/pull/1634)) -- Bump `github.com/cosmos/ibc-go/v7` from 7.3.0 to 7.3.1 ([#1647](https://github.com/NibiruChain/nibiru/pull/1647)) -- Bump `github.com/CosmWasm/wasmd` from 0.40.2 to 0.43.0 ([#1660](https://github.com/NibiruChain/nibiru/pull/1660)) -- Bump `github.com/CosmWasm/wasmd` from 0.43.0 to 0.44.0 ([#1666](https://github.com/NibiruChain/nibiru/pull/1666)) + +* Bump `github.com/prometheus/client_golang` from 1.16.0 to 1.17.0 ([#1605](https://github.com/NibiruChain/nibiru/pull/1605)) + +* Bump `bufbuild/buf-setup-action` from 1.26.1 to 1.27.1 ([#1624](https://github.com/NibiruChain/nibiru/pull/1624), [#1641](https://github.com/NibiruChain/nibiru/pull/1641)) +* Bump `stefanzweifel/git-auto-commit-action` from 4 to 5 ([#1625](https://github.com/NibiruChain/nibiru/pull/1625)) +* Bump `github.com/CosmWasm/wasmvm` from 1.4.0 to 1.5.0 ([#1629](https://github.com/NibiruChain/nibiru/pull/1629), [#1657](https://github.com/NibiruChain/nibiru/pull/1657)) +* Bump `google.golang.org/grpc` from 1.58.2 to 1.59.0 ([#1633](https://github.com/NibiruChain/nibiru/pull/1633), [#1643](https://github.com/NibiruChain/nibiru/pull/1643)) +* Bump `golang.org/x/net` from 0.12.0 to 0.17.0 ([#1634](https://github.com/NibiruChain/nibiru/pull/1634)) +* Bump `github.com/cosmos/ibc-go/v7` from 7.3.0 to 7.3.1 ([#1647](https://github.com/NibiruChain/nibiru/pull/1647)) +* Bump `github.com/CosmWasm/wasmd` from 0.40.2 to 0.43.0 ([#1660](https://github.com/NibiruChain/nibiru/pull/1660)) +* Bump `github.com/CosmWasm/wasmd` from 0.43.0 to 0.44.0 ([#1666](https://github.com/NibiruChain/nibiru/pull/1666)) ### Bug Fixes @@ -110,7 +118,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1501](https://github.com/NibiruChain/nibiru/pull/1501) - feat(proto): add Python buf generation logic for py-sdk * [#1503](https://github.com/NibiruChain/nibiru/pull/1503) - feat(wasm): add Oracle Exchange Rate query for wasm * [#1543](https://github.com/NibiruChain/nibiru/pull/1543) - epic(devgas): devgas module for incentivizing smart contract -* +* + ### Improvements * [#1466](https://github.com/NibiruChain/nibiru/pull/1466) - refactor(perp): `PositionLiquidatedEvent` @@ -148,25 +157,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Dependencies -- Bump `robinraju/release-downloader` from 1.6 to 1.8 (#1326) -- Bump `pozetroninc/github-action-get-latest-release` from 0.6.0 to 0.7.0 (#1325) -- Bump `technote-space/get-diff-action` from 4 to 6 (#1327) -- Bump `actions/setup-go` from 3 to 4 (#1324) -- Bump `github.com/docker/distribution` from 2.8.1+incompatible to 2.8.2+incompatible (#1339) -- Bump `github.com/CosmWasm/wasmvm` from 1.2.1 to 1.3.0 (#1354, #1507) -- Bump `github.com/spf13/cast` from 1.5.0 to 1.5.1 (#1358) -- Bump `github.com/stretchr/testify` from 1.8.2 to 1.8.4 (#1384, #1435) -- Bump `cosmossdk.io/math` from 1.0.0-beta.6 to 1.1.2 (#1394, [#1547](https://github.com/NibiruChain/nibiru/pull/1547)) -- Bump `google.golang.org/grpc` from 1.53.0 to 1.57.0 (#1395, #1437, #1443, #1497, [#1525](https://github.com/NibiruChain/nibiru/pull/1525)) -- Bump `github.com/gin-gonic/gin` from 1.8.1 to 1.9.1 (#1409) -- Bump `github.com/spf13/viper` from 1.15.0 to 1.16.0 (#1436) -- Bump `github.com/prometheus/client_golang` from 1.15.1 to 1.16.0 (#1431) -- Bump `github.com/cosmos/ibc-go/v7` from 7.1.0 to 7.3.0 (#1445, [#1562](https://github.com/NibiruChain/nibiru/pull/1562)) -- Bump `bufbuild/buf-setup-action` from 1.21.0 to 1.26.1 (#1449, #1469, #1505, #1510, [#1537](https://github.com/NibiruChain/nibiru/pull/1537), [#1540](https://github.com/NibiruChain/nibiru/pull/1540), [#1544](https://github.com/NibiruChain/nibiru/pull/1544)) -- Bump `google.golang.org/protobuf` from 1.30.0 to 1.31.0 (#1450) -- Bump `cosmossdk.io/errors` from 1.0.0-beta.7 to 1.0.0 (#1499) -- Bump `github.com/holiman/uint256` from 1.2.2 to 1.2.3 (#1504) -- Bump `actions/checkout` from 3 to 4 ([#1563](https://github.com/NibiruChain/nibiru/pull/1563)) +* Bump `robinraju/release-downloader` from 1.6 to 1.8 (#1326) +* Bump `pozetroninc/github-action-get-latest-release` from 0.6.0 to 0.7.0 (#1325) +* Bump `technote-space/get-diff-action` from 4 to 6 (#1327) +* Bump `actions/setup-go` from 3 to 4 (#1324) +* Bump `github.com/docker/distribution` from 2.8.1+incompatible to 2.8.2+incompatible (#1339) +* Bump `github.com/CosmWasm/wasmvm` from 1.2.1 to 1.3.0 (#1354, #1507) +* Bump `github.com/spf13/cast` from 1.5.0 to 1.5.1 (#1358) +* Bump `github.com/stretchr/testify` from 1.8.2 to 1.8.4 (#1384, #1435) +* Bump `cosmossdk.io/math` from 1.0.0-beta.6 to 1.1.2 (#1394, [#1547](https://github.com/NibiruChain/nibiru/pull/1547)) +* Bump `google.golang.org/grpc` from 1.53.0 to 1.57.0 (#1395, #1437, #1443, #1497, [#1525](https://github.com/NibiruChain/nibiru/pull/1525)) +* Bump `github.com/gin-gonic/gin` from 1.8.1 to 1.9.1 (#1409) +* Bump `github.com/spf13/viper` from 1.15.0 to 1.16.0 (#1436) +* Bump `github.com/prometheus/client_golang` from 1.15.1 to 1.16.0 (#1431) +* Bump `github.com/cosmos/ibc-go/v7` from 7.1.0 to 7.3.0 (#1445, [#1562](https://github.com/NibiruChain/nibiru/pull/1562)) +* Bump `bufbuild/buf-setup-action` from 1.21.0 to 1.26.1 (#1449, #1469, #1505, #1510, [#1537](https://github.com/NibiruChain/nibiru/pull/1537), [#1540](https://github.com/NibiruChain/nibiru/pull/1540), [#1544](https://github.com/NibiruChain/nibiru/pull/1544)) +* Bump `google.golang.org/protobuf` from 1.30.0 to 1.31.0 (#1450) +* Bump `cosmossdk.io/errors` from 1.0.0-beta.7 to 1.0.0 (#1499) +* Bump `github.com/holiman/uint256` from 1.2.2 to 1.2.3 (#1504) +* Bump `actions/checkout` from 3 to 4 ([#1563](https://github.com/NibiruChain/nibiru/pull/1563)) ### Breaking @@ -174,7 +183,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1359](https://github.com/NibiruChain/nibiru/pull/1359) - feat(perp): Add InsuranceFundWithdraw admin call with corresponding smart contract * [#1356](https://github.com/NibiruChain/nibiru/pull/1356) - build: Regress wasmvm (v1.1.1), tendermint (v0.34.24), and Cosmos-SDK (v0.45.14) dependencies * [#1346](https://github.com/NibiruChain/nibiru/pull/1346) - build: Upgrade wasmvm (v1.2.1), tendermint (v0.34.26), and Cosmos-SDK (v0.45.14) dependencies -* [#1317](https://github.com/NibiruChain/nibiru/pull/1317) - feat(sudo): Implement and test CLI commands for tx and queries. +* [#1317](https://github.com/NibiruChain/nibiru/pull/1317) - feat(sudo): Implement and test CLI commands for tx and queries. * [#1307](https://github.com/NibiruChain/nibiru/pull/1307) - feat(sudo): Create the x/sudo module + integration tests * [#1299](https://github.com/NibiruChain/nibiru/pull/1299) - feat(wasm): Add peg shift bindings * [#1292](https://github.com/NibiruChain/nibiru/pull/1292) - feat(wasm): Add module bindings for execute calls in x/perp: OpenPosition, ClosePosition, AddMargin, RemoveMargin. @@ -314,7 +323,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1359](https://github.com/NibiruChain/nibiru/pull/1359) - feat(perp): Add InsuranceFundWithdraw admin call with corresponding smart contract * [#1356](https://github.com/NibiruChain/nibiru/pull/1356) - build: Regress wasmvm (v1.1.1), tendermint (v0.34.24), and Cosmos-SDK (v0.45.14) dependencies * [#1346](https://github.com/NibiruChain/nibiru/pull/1346) - build: Upgrade wasmvm (v1.2.1), tendermint (v0.34.26), and Cosmos-SDK (v0.45.14) dependencies -* [#1317](https://github.com/NibiruChain/nibiru/pull/1317) - feat(sudo): Implement and test CLI commands for tx and queries. +* [#1317](https://github.com/NibiruChain/nibiru/pull/1317) - feat(sudo): Implement and test CLI commands for tx and queries. * [#1307](https://github.com/NibiruChain/nibiru/pull/1307) - feat(sudo): Create the x/sudo module + integration tests * [#1299](https://github.com/NibiruChain/nibiru/pull/1299) - feat(wasm): Add peg shift bindings * [#1292](https://github.com/NibiruChain/nibiru/pull/1292) - feat(wasm): Add module bindings for execute calls in x/perp: OpenPosition, ClosePosition, AddMargin, RemoveMargin. @@ -354,31 +363,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Dependencies -- Bump `robinraju/release-downloader` from 1.6 to 1.8 (#1326) -- Bump `pozetroninc/github-action-get-latest-release` from 0.6.0 to 0.7.0 (#1325) -- Bump `technote-space/get-diff-action` from 4 to 6 (#1327) -- Bump `actions/setup-go` from 3 to 4 (#1324) -- Bump `github.com/docker/distribution` from 2.8.1+incompatible to 2.8.2+incompatible (#1339) -- Bump `github.com/CosmWasm/wasmvm` from 1.2.1 to 1.4.0 (#1354, #1507, [#1564](https://github.com/NibiruChain/nibiru/pull/1564)) -- Bump `github.com/spf13/cast` from 1.5.0 to 1.5.1 (#1358) -- Bump `github.com/stretchr/testify` from 1.8.2 to 1.8.4 (#1384, #1435) -- Bump `cosmossdk.io/math` from 1.0.0-beta.6 to 1.1.2 (#1394, [#1547](https://github.com/NibiruChain/nibiru/pull/1547)) -- Bump `google.golang.org/grpc` from 1.53.0 to 1.58.2 (#1395, #1437, #1443, #1497, [#1525](https://github.com/NibiruChain/nibiru/pull/1525), [#1568](https://github.com/NibiruChain/nibiru/pull/1568), [#1582](https://github.com/NibiruChain/nibiru/pull/1582), [#1598](https://github.com/NibiruChain/nibiru/pull/1598)) -- Bump `github.com/gin-gonic/gin` from 1.8.1 to 1.9.1 (#1409) -- Bump `github.com/spf13/viper` from 1.15.0 to 1.16.0 (#1436) -- Bump `github.com/prometheus/client_golang` from 1.15.1 to 1.16.0 (#1431) -- Bump `github.com/cosmos/ibc-go/v7` from 7.1.0 to 7.3.0 (#1445, [#1562](https://github.com/NibiruChain/nibiru/pull/1562)) -- Bump `bufbuild/buf-setup-action` from 1.21.0 to 1.26.1 (#1449, #1469, #1505, #1510, [#1537](https://github.com/NibiruChain/nibiru/pull/1537), [#1540](https://github.com/NibiruChain/nibiru/pull/1540), [#1544](https://github.com/NibiruChain/nibiru/pull/1544)) -- Bump `google.golang.org/protobuf` from 1.30.0 to 1.31.0 (#1450) -- Bump `cosmossdk.io/errors` from 1.0.0-beta.7 to 1.0.0 (#1499) -- Bump `github.com/holiman/uint256` from 1.2.2 to 1.2.3 (#1504) -- Bump `docker/build-push-action` from 4 to 5 ([#1572](https://github.com/NibiruChain/nibiru/pull/1572)) -- Bump `docker/login-action` from 2 to 3 ([#1571](https://github.com/NibiruChain/nibiru/pull/1571)) -- Bump `docker/setup-buildx-action` from 2 to 3 ([#1570](https://github.com/NibiruChain/nibiru/pull/1570)) -- Bump `docker/setup-qemu-action` from 2 to 3 ([#1569](https://github.com/NibiruChain/nibiru/pull/1569)) -- Bump `github.com/cosmos/cosmos-sdk` from v0.47.4 to v0.47.5 ([#1578](https://github.com/NibiruChain/nibiru/pull/1578)) -- Bump `codecov/codecov-action` from 3 to 4 ([#1583](https://github.com/NibiruChain/nibiru/pull/1583)) -- Bump `actions/checkout` from 3 to 4 ([#1593](https://github.com/NibiruChain/nibiru/pull/1593)) +* Bump `robinraju/release-downloader` from 1.6 to 1.8 (#1326) +* Bump `pozetroninc/github-action-get-latest-release` from 0.6.0 to 0.7.0 (#1325) +* Bump `technote-space/get-diff-action` from 4 to 6 (#1327) +* Bump `actions/setup-go` from 3 to 4 (#1324) +* Bump `github.com/docker/distribution` from 2.8.1+incompatible to 2.8.2+incompatible (#1339) +* Bump `github.com/CosmWasm/wasmvm` from 1.2.1 to 1.4.0 (#1354, #1507, [#1564](https://github.com/NibiruChain/nibiru/pull/1564)) +* Bump `github.com/spf13/cast` from 1.5.0 to 1.5.1 (#1358) +* Bump `github.com/stretchr/testify` from 1.8.2 to 1.8.4 (#1384, #1435) +* Bump `cosmossdk.io/math` from 1.0.0-beta.6 to 1.1.2 (#1394, [#1547](https://github.com/NibiruChain/nibiru/pull/1547)) +* Bump `google.golang.org/grpc` from 1.53.0 to 1.58.2 (#1395, #1437, #1443, #1497, [#1525](https://github.com/NibiruChain/nibiru/pull/1525), [#1568](https://github.com/NibiruChain/nibiru/pull/1568), [#1582](https://github.com/NibiruChain/nibiru/pull/1582), [#1598](https://github.com/NibiruChain/nibiru/pull/1598)) +* Bump `github.com/gin-gonic/gin` from 1.8.1 to 1.9.1 (#1409) +* Bump `github.com/spf13/viper` from 1.15.0 to 1.16.0 (#1436) +* Bump `github.com/prometheus/client_golang` from 1.15.1 to 1.16.0 (#1431) +* Bump `github.com/cosmos/ibc-go/v7` from 7.1.0 to 7.3.0 (#1445, [#1562](https://github.com/NibiruChain/nibiru/pull/1562)) +* Bump `bufbuild/buf-setup-action` from 1.21.0 to 1.26.1 (#1449, #1469, #1505, #1510, [#1537](https://github.com/NibiruChain/nibiru/pull/1537), [#1540](https://github.com/NibiruChain/nibiru/pull/1540), [#1544](https://github.com/NibiruChain/nibiru/pull/1544)) +* Bump `google.golang.org/protobuf` from 1.30.0 to 1.31.0 (#1450) +* Bump `cosmossdk.io/errors` from 1.0.0-beta.7 to 1.0.0 (#1499) +* Bump `github.com/holiman/uint256` from 1.2.2 to 1.2.3 (#1504) +* Bump `docker/build-push-action` from 4 to 5 ([#1572](https://github.com/NibiruChain/nibiru/pull/1572)) +* Bump `docker/login-action` from 2 to 3 ([#1571](https://github.com/NibiruChain/nibiru/pull/1571)) +* Bump `docker/setup-buildx-action` from 2 to 3 ([#1570](https://github.com/NibiruChain/nibiru/pull/1570)) +* Bump `docker/setup-qemu-action` from 2 to 3 ([#1569](https://github.com/NibiruChain/nibiru/pull/1569)) +* Bump `github.com/cosmos/cosmos-sdk` from v0.47.4 to v0.47.5 ([#1578](https://github.com/NibiruChain/nibiru/pull/1578)) +* Bump `codecov/codecov-action` from 3 to 4 ([#1583](https://github.com/NibiruChain/nibiru/pull/1583)) +* Bump `actions/checkout` from 3 to 4 ([#1593](https://github.com/NibiruChain/nibiru/pull/1593)) ## [v0.19.2](https://github.com/NibiruChain/nibiru/releases/tag/v0.19.2) - 2023-02-24 @@ -785,4 +794,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. \ No newline at end of file +* [#692](https://github.com/NibiruChain/nibiru/pull/692) Add test coverage for Perp MsgServer methods. diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index c8031720e..6bc13bf8f 100644 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -23,10 +23,11 @@ type Keeper struct { cdc codec.BinaryCodec storeKey storetypes.StoreKey - AccountKeeper types.AccountKeeper - bankKeeper types.BankKeeper - distrKeeper types.DistributionKeeper - StakingKeeper types.StakingKeeper + AccountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + distrKeeper types.DistributionKeeper + StakingKeeper types.StakingKeeper + slashingKeeper types.SlashingKeeper distrModuleName string @@ -47,8 +48,12 @@ type Keeper struct { // NewKeeper constructs a new keeper for oracle func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, accountKeeper types.AccountKeeper, - bankKeeper types.BankKeeper, distrKeeper types.DistributionKeeper, - stakingKeeper types.StakingKeeper, distrName string, + bankKeeper types.BankKeeper, + distrKeeper types.DistributionKeeper, + stakingKeeper types.StakingKeeper, + slashingKeeper types.SlashingKeeper, + + distrName string, ) Keeper { // ensure oracle module account is set if addr := accountKeeper.GetModuleAddress(types.ModuleName); addr == nil { @@ -62,6 +67,7 @@ func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, bankKeeper: bankKeeper, distrKeeper: distrKeeper, StakingKeeper: stakingKeeper, + slashingKeeper: slashingKeeper, distrModuleName: distrName, Params: collections.NewItem(storeKey, 11, collections.ProtoValueEncoder[types.Params](cdc)), ExchangeRates: collections.NewMap(storeKey, 1, asset.PairKeyEncoder, collections.ProtoValueEncoder[types.DatedPrice](cdc)), diff --git a/x/oracle/keeper/slash.go b/x/oracle/keeper/slash.go index a006fb8e6..d3de144f9 100644 --- a/x/oracle/keeper/slash.go +++ b/x/oracle/keeper/slash.go @@ -39,12 +39,11 @@ func (k Keeper) SlashAndResetMissCounters(ctx sdk.Context) { continue } - k.StakingKeeper.Slash( - ctx, consAddr, - distributionHeight, validator.GetConsensusPower(powerReduction), slashFraction, + k.slashingKeeper.Slash( + ctx, consAddr, slashFraction, validator.GetConsensusPower(powerReduction), distributionHeight, ) - k.Logger(ctx).Info("slash", "validator", consAddr.String(), "fraction", slashFraction.String()) - k.StakingKeeper.Jail(ctx, consAddr) + k.Logger(ctx).Info("oracle slash", "validator", consAddr.String(), "fraction", slashFraction.String()) + k.slashingKeeper.Jail(ctx, consAddr) } } diff --git a/x/oracle/keeper/test_utils.go b/x/oracle/keeper/test_utils.go index b92068f37..cc0b71761 100644 --- a/x/oracle/keeper/test_utils.go +++ b/x/oracle/keeper/test_utils.go @@ -2,11 +2,12 @@ package keeper import ( - sudokeeper "github.com/NibiruChain/nibiru/x/sudo/keeper" - sudotypes "github.com/NibiruChain/nibiru/x/sudo/types" "testing" "time" + sudokeeper "github.com/NibiruChain/nibiru/x/sudo/keeper" + sudotypes "github.com/NibiruChain/nibiru/x/sudo/types" + "github.com/cosmos/cosmos-sdk/store" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -38,6 +39,8 @@ import ( distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/params" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -137,9 +140,12 @@ func CreateTestFixture(t *testing.T) TestFixture { tKeyParams := sdk.NewTransientStoreKey(paramstypes.TStoreKey) keyOracle := sdk.NewKVStoreKey(types.StoreKey) keyStaking := sdk.NewKVStoreKey(stakingtypes.StoreKey) + keySlashing := sdk.NewKVStoreKey(slashingtypes.StoreKey) keyDistr := sdk.NewKVStoreKey(distrtypes.StoreKey) keySudo := sdk.NewKVStoreKey(sudotypes.StoreKey) + govModuleAddr := authtypes.NewModuleAddress(govtypes.ModuleName).String() + db := dbm.NewMemDB() ms := store.NewCommitMultiStore(db) ctx := sdk.NewContext(ms, tmproto.Header{Time: time.Now().UTC(), Height: 1}, false, log.NewNopLogger()) @@ -200,11 +206,12 @@ func CreateTestFixture(t *testing.T) TestFixture { bankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - stakingParams := stakingtypes.DefaultParams() stakingParams.BondDenom = denoms.NIBI stakingKeeper.SetParams(ctx, stakingParams) + slashingKeeper := slashingkeeper.NewKeeper(appCodec, legacyAmino, keySlashing, stakingKeeper, govModuleAddr) + distrKeeper := distrkeeper.NewKeeper( appCodec, keyDistr, @@ -253,6 +260,7 @@ func CreateTestFixture(t *testing.T) TestFixture { bankKeeper, distrKeeper, stakingKeeper, + slashingKeeper, distrtypes.ModuleName, ) diff --git a/x/oracle/types/expected_keeper.go b/x/oracle/types/expected_keeper.go index 4c47f8bd5..98ea85cb1 100644 --- a/x/oracle/types/expected_keeper.go +++ b/x/oracle/types/expected_keeper.go @@ -18,6 +18,11 @@ type StakingKeeper interface { PowerReduction(ctx sdk.Context) (res sdkmath.Int) } +type SlashingKeeper interface { + Slash(ctx sdk.Context, consAddr sdk.ConsAddress, fraction sdk.Dec, power int64, height int64) + Jail(sdk.Context, sdk.ConsAddress) +} + // DistributionKeeper is expected keeper for distribution module type DistributionKeeper interface { AllocateTokensToValidator(ctx sdk.Context, val stakingtypes.ValidatorI, tokens sdk.DecCoins)