Skip to content

Commit

Permalink
fix: unwire perp module for main branch (#1830)
Browse files Browse the repository at this point in the history
* feat: rest in peace

* fix: fix e2e wasm test

* fix: fix justfile and deplyo-wasm

---------

Co-authored-by: Unique Divine <[email protected]>
  • Loading branch information
matthiasmatt and Unique-Divine authored Apr 2, 2024
1 parent b23ae71 commit 68f8f5b
Show file tree
Hide file tree
Showing 113 changed files with 63 additions and 41,813 deletions.
36 changes: 20 additions & 16 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# Install `nibid` binaries <!-- omit in toc -->
# Install `nibid` binaries <!-- omit in toc -->

This guide will explain how to install the Nibiru Chain binary, `nibid`, onto your system.

#### Table of Contents

- [1. Update the system](#1-update-the-system)
- [2. Install Golang](#2-install-golang)
- [3. Install build requirements](#3-install-build-requirements)
- [4. Clone the Nibiru Repository](#4-clone-the-nibiru-repository)
- [Upgrade](#upgrade)

- [Troubleshooting](#troubleshooting)
- [Contributing](#contributing)
- [Troubleshooting](#troubleshooting-1)
- [Error when running `make install` on MacOS](#error-when-running-make-install-on-macos)

## 1. Update the system

Expand All @@ -19,7 +23,7 @@ sudo apt update
sudo apt upgrade --yes
```

## 2. Install Golang
## 2. Install Golang

Steps described here: https://go.dev/doc/install

Expand All @@ -34,7 +38,6 @@ wget -q -O - https://git.io/vQhTU | bash -s -- --version 1.16

After installed, open new terminal to properly load go


## 4. Clone the Nibiru Repository

```sh
Expand All @@ -43,32 +46,33 @@ git clone https://github.com/NibiruChain/nibiru
cd nibiru
```

On this fresh clone of the repo, simply run
On this fresh clone of the repo, simply run

```sh
make build
make build
make install
make localnet
```
and open another terminal.

and open another terminal.

---

## Upgrade

The scheduled mainnet upgrade to `nibiru-2` is planned for
The scheduled mainnet upgrade to `nibiru-2` is planned for

```
cd nibiru
git fetch tags
git checkout v0.0.1
```


Testnet
Testnet

One the Nibiru binary has been installed, for further information on joining the testnet, head over to the [testnet repo](https://github.com/NibiruChain/Networks/tree/main/Testnet).

Mainnet
Mainnet

One the Nibiru binary has been installed, for further information on joining mainnet, head over to the [mainnet repo](https://github.com/NibiruChain/Networks/tree/main/Mainnet).

Expand All @@ -84,9 +88,9 @@ B. New commands you've made on the `nibid` don't show up. Your `nibid` probably

## Contributing

The code for `nibid` is located in the `/cmd/nibid` folder.
The code for `nibid` is located in the `/cmd/nibid` folder.

In addition to the commands available within that folder, `nibid` pulls in cli subcommands from the modules e.g. `/x/perps/cli`
In addition to the commands available within that folder, `nibid` pulls in cli subcommands from the modules e.g. `/x/oracle/cli`

After updating the code run

Expand All @@ -98,14 +102,14 @@ make install
To see all the commands available just add `--help` to the end.

Example:

```bash
nibid --help
nibid query --help
nibid tx --help
nibid query perp --help
nibid query oracle --help
```


## Troubleshooting

### Error when running `make install` on MacOS
Expand All @@ -120,4 +124,4 @@ You can fix it by installing `wget` with Homebrew:

```
brew install wget
```
```
55 changes: 24 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@

## ⚙️ — Documentation

- [Docs | Nibiru Chain](https://nibiru.fi/docs/): Conceptual and technical documentation can be found here.
- [Docs | Nibiru Chain](https://nibiru.fi/docs/): Conceptual and technical documentation can be found here.
- [Complete Golang reference docs](https://pkg.go.dev/github.com/NibiruChain/nibiru): (`pkg.go.dev`) For the blockchain implementation .
- ["X Module"](https://nibiru.fi/docs/dev/x/)-specific documentation

## 💬 — Community

If you have questions or concerns, feel free to connect with a developer or community member in the [Nibiru Discord][social-discord]. We also have active communities on [Twitter][social-twitter] and [Telegram][social-telegram].

<!-- Markdown versions of the social badges
[![description][discord-badge]][social-discord]
[![description][twitter-badge]][social-twitter]
<!-- Markdown versions of the social badges
[![description][discord-badge]][social-discord]
[![description][twitter-badge]][social-twitter]
[![description][telegram-badge]][social-telegram]
-->

Expand All @@ -44,33 +44,30 @@ If you have questions or concerns, feel free to connect with a developer or comm

## 🧱 — Components of Nibiru

- **CosmWasm Smart Contracts**: Rust-based, Wasm smart contracts built enhanced security, performance, and interoperability. See our [CosmWasm sandbox monorepo (cw-nibiru)](https://github.com/NibiruChain/cw-nibiru/tree/main) for the protocol's core smart contracts.
- **Nibi-Perps**: A perpetual futures exchange where users can take leveraged exposure and trade on a plethora of assets — completely on-chain, completely non-custodially, and with minimal gas fees.
- **CosmWasm Smart Contracts**: Rust-based, Wasm smart contracts built enhanced security, performance, and interoperability. See our [CosmWasm sandbox monorepo (cw-nibiru)](https://github.com/NibiruChain/cw-nibiru/tree/main) for the protocol's core smart contracts.
- **Nibi-Oracle**: Nibiru accurately prices assets using a native, system of decentralized oracles, and communicates with other Cosmos layer-1 chains using the Inter-Blockchain Communication (IBC) (opens new window)protocol.
- **Nibi-Swap**: An automated market maker protocol for multichain assets. This application gives users access to swaps, pools, and bonded liquidity gauges.

| Module | Description |
| --- | --- |
| [wasm][code-x-wasm] | Implements the execution environment for [WebAssembly (WASM) smart contracts](https://nibiru.fi/docs/wasm/). |
| [devgas][code-x-devgas] | The `devgas` module of Nibiru Chain shares contract execution fees with smart contract developers. This aims to increase the adoption of Nibiru by offering CosmWasm smart contract developers a direct source of income based on usage. |
| [epochs][code-x-epochs] | The `epochs` module allows other modules to set hooks to be called to execute code automatically on a period basis. For example, "once a week, starting at UTC-time = x". `epochs` creates a generalized epoch interface. |
| [inflation][code-x-inflation] | Implements the [tokenomics](https://nibiru.fi/docs/learn/tokenomics.html) for Nibiru. |
| [common][code-x-common] | Holds helper and utility functions to be utilized by other `x/` modules. |
| [oracle][code-x-oracle] | Handles the posting of an up-to-date and accurate feed of exchange rates from the validators. |
| [perp][code-x-perp] | Powers the Nibi-Perps exchange. This module enables traders to open long and short leveraged positions and houses all of the PnL calculation and liquidation logic. |
| [spot][code-x-spot] | Responsible for creating, joining, and exiting liquidity pools. It also allows users to swap between two assets in an existing pool. It's a fully functional AMM. |
| Module | Description |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [wasm][code-x-wasm] | Implements the execution environment for [WebAssembly (WASM) smart contracts](https://nibiru.fi/docs/wasm/). |
| [devgas][code-x-devgas] | The `devgas` module of Nibiru Chain shares contract execution fees with smart contract developers. This aims to increase the adoption of Nibiru by offering CosmWasm smart contract developers a direct source of income based on usage. |
| [epochs][code-x-epochs] | The `epochs` module allows other modules to set hooks to be called to execute code automatically on a period basis. For example, "once a week, starting at UTC-time = x". `epochs` creates a generalized epoch interface. |
| [inflation][code-x-inflation] | Implements the [tokenomics](https://nibiru.fi/docs/learn/tokenomics.html) for Nibiru. |
| [common][code-x-common] | Holds helper and utility functions to be utilized by other `x/` modules. |
| [oracle][code-x-oracle] | Handles the posting of an up-to-date and accurate feed of exchange rates from the validators. |
| [spot][code-x-spot] | Responsible for creating, joining, and exiting liquidity pools. It also allows users to swap between two assets in an existing pool. It's a fully functional AMM. |

[code-x-common]: https://github.com/NibiruChain/nibiru/tree/main/x/common
[code-x-devgas]: https://nibiru.fi/docs/dev/x/nibiru-chain/devgas.html
[code-x-epochs]: https://github.com/NibiruChain/nibiru/tree/main/x/epochs
[code-x-inflation]: https://github.com/NibiruChain/nibiru/tree/main/x/inflation
[code-x-oracle]: https://github.com/NibiruChain/nibiru/tree/main/x/oracle
[code-x-perp]: https://github.com/NibiruChain/nibiru/tree/main/x/perp
[code-x-spot]: https://github.com/NibiruChain/nibiru/tree/main/x/spot

Nibiru is built with the [Cosmos-SDK][cosmos-sdk-repo] on [Tendermint Core](https://tendermint.com/core/) consensus and communicates with other blockchain chains using the [Inter-Blockchain Communication (IBC)](https://github.com/cosmos/ibc) protocol.

----
---

## ⛓️ — Building: `make` commands

Expand All @@ -94,10 +91,12 @@ Usage instructions for the `nibid` CLI are available at [docs.nibiru.fi/dev/cli]
### Running a Local Node

On a fresh clone of the repo, simply run:

```bash
make localnet
```
and open another terminal.
```

and open another terminal.

### Generate the protobufs

Expand Down Expand Up @@ -131,19 +130,13 @@ Licensed under the [MIT License](./LICENSE.md).

[license-badge]: https://img.shields.io/badge/License-MIT-blue.svg
[cosmos-sdk-repo]: https://github.com/cosmos/cosmos-sdk
[badge-go-linter]:
https://github.com/NibiruChain/nibiru/actions/workflows/golangci-lint.yml/badge.svg?query=branch%3Amain
[workflow-go-linter]:
https://github.com/NibiruChain/nibiru/actions/workflows/golangci-lint.yml?query=branch%3Amain
[badge-go-releaser]:
https://github.com/NibiruChain/nibiru/actions/workflows/goreleaser.yml/badge.svg?query=branch%3Amain
[workflow-go-releaser]:
https://github.com/NibiruChain/nibiru/actions/workflows/goreleaser.yml?query=branch%3Amain

[badge-go-linter]: https://github.com/NibiruChain/nibiru/actions/workflows/golangci-lint.yml/badge.svg?query=branch%3Amain
[workflow-go-linter]: https://github.com/NibiruChain/nibiru/actions/workflows/golangci-lint.yml?query=branch%3Amain
[badge-go-releaser]: https://github.com/NibiruChain/nibiru/actions/workflows/goreleaser.yml/badge.svg?query=branch%3Amain
[workflow-go-releaser]: https://github.com/NibiruChain/nibiru/actions/workflows/goreleaser.yml?query=branch%3Amain
[social-twitter]: https://twitter.com/NibiruChain
[social-discord]: https://discord.gg/nibirufi
[social-telegram]: https://t.me/nibiruchain

[discord-badge]: https://img.shields.io/badge/Discord-7289DA?&logo=discord&logoColor=white
[twitter-badge]: https://img.shields.io/badge/Twitter-1DA1F2?&logo=twitter&logoColor=white
[telegram-badge]: https://img.shields.io/badge/Telegram-2CA5E0?&logo=telegram&logoColor=white
Expand All @@ -153,7 +146,7 @@ https://github.com/NibiruChain/nibiru/actions/workflows/goreleaser.yml?query=bra
[![version](https://img.shields.io/github/tag/nibiru-labs/nibiru.svg)](https://github.com/NibiruChain/nibiru/releases/latest)
[![Go Report Card](https://goreportcard.com/badge/github.com/NibiruChain/nibiru)](https://goreportcard.com/report/github.com/NibiruChain/nibiru)
[![Go Report Card](https://goreportcard.com/badge/github.com/NibiruChain/nibiru)](https://goreportcard.com/report/github.com/NibiruChain/nibiru)
[![API Reference](https://godoc.org/github.com/NibiruChain/nibiru?status.svg)](https://godoc.org/github.com/NibiruChain/nibiru)
Expand Down
27 changes: 2 additions & 25 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ import (
oracle "github.com/NibiruChain/nibiru/x/oracle"
oraclekeeper "github.com/NibiruChain/nibiru/x/oracle/keeper"
oracletypes "github.com/NibiruChain/nibiru/x/oracle/types"
perpkeeper "github.com/NibiruChain/nibiru/x/perp/v2/keeper"
perpmodule "github.com/NibiruChain/nibiru/x/perp/v2/module"
perptypes "github.com/NibiruChain/nibiru/x/perp/v2/types"

"github.com/NibiruChain/nibiru/x/spot"
spotkeeper "github.com/NibiruChain/nibiru/x/spot/keeper"
Expand Down Expand Up @@ -172,7 +169,6 @@ type AppKeepers struct {
// Nibiru keepers
// ---------------
EpochsKeeper epochskeeper.Keeper
PerpKeeperV2 perpkeeper.Keeper
SpotKeeper spotkeeper.Keeper
OracleKeeper oraclekeeper.Keeper
InflationKeeper inflationkeeper.Keeper
Expand Down Expand Up @@ -215,7 +211,6 @@ func initStoreKeys() (
spottypes.StoreKey,
oracletypes.StoreKey,
epochstypes.StoreKey,
perptypes.StoreKey,
inflationtypes.StoreKey,
sudotypes.StoreKey,
wasmtypes.StoreKey,
Expand Down Expand Up @@ -371,20 +366,13 @@ func (app *NibiruApp) InitKeepers(
appCodec, keys[epochstypes.StoreKey],
)

app.PerpKeeperV2 = perpkeeper.NewKeeper(
appCodec, keys[perptypes.StoreKey],
app.AccountKeeper, app.BankKeeper, app.OracleKeeper, app.EpochsKeeper,
app.SudoKeeper,
)

app.InflationKeeper = inflationkeeper.NewKeeper(
appCodec, keys[inflationtypes.StoreKey], app.GetSubspace(inflationtypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.stakingKeeper, app.SudoKeeper, authtypes.FeeCollectorName,
)

app.EpochsKeeper.SetHooks(
epochstypes.NewMultiEpochHooks(
app.PerpKeeperV2.Hooks(),
app.InflationKeeper.Hooks(),
app.OracleKeeper.Hooks(),
),
Expand Down Expand Up @@ -437,8 +425,8 @@ func (app *NibiruApp) InitKeepers(
// NOTE: This keeper depends on all of pointers to the the Keepers to which
// it binds. Thus, it must be instantiated after those keepers have been
// assigned.
// For example, if there are bindings for the x/perp module, then the app
// passed to GetWasmOpts must already have a non-nil PerpKeeper.
// For example, if there are bindings for the x/inflation module, then the app
// passed to GetWasmOpts must already have a non-nil InflationKeeper.
supportedFeatures := strings.Join(wasmdapp.AllCapabilities(), ",")
app.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -593,7 +581,6 @@ func (app *NibiruApp) initAppModules(
spot.NewAppModule(appCodec, app.SpotKeeper, app.AccountKeeper, app.BankKeeper),
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
epochs.NewAppModule(appCodec, app.EpochsKeeper),
perpmodule.NewAppModule(appCodec, app.PerpKeeperV2, app.AccountKeeper, app.BankKeeper, app.OracleKeeper),
inflation.NewAppModule(app.InflationKeeper, app.AccountKeeper, *app.stakingKeeper),
sudo.NewAppModule(appCodec, app.SudoKeeper),
genmsg.NewAppModule(app.MsgServiceRouter()),
Expand Down Expand Up @@ -664,7 +651,6 @@ func orderedModuleNames() []string {
epochstypes.ModuleName,
spottypes.ModuleName,
oracletypes.ModuleName,
perptypes.ModuleName,
inflationtypes.ModuleName,
sudotypes.ModuleName,

Expand Down Expand Up @@ -779,7 +765,6 @@ func ModuleBasicManager() module.BasicManager {
spot.AppModuleBasic{},
oracle.AppModuleBasic{},
epochs.AppModuleBasic{},
perpmodule.AppModuleBasic{},
inflation.AppModuleBasic{},
sudo.AppModuleBasic{},
wasm.AppModuleBasic{},
Expand All @@ -803,13 +788,6 @@ func ModuleAccPerms() map[string][]string {
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: {},

perptypes.ModuleName: {},
perptypes.VaultModuleAccount: {},
perptypes.PerpFundModuleAccount: {},
perptypes.FeePoolModuleAccount: {},
perptypes.DNRAllocationModuleAccount: {},
perptypes.DNREscrowModuleAccount: {},

epochstypes.ModuleName: {},
sudotypes.ModuleName: {},
common.TreasuryPoolModuleAccount: {},
Expand All @@ -818,7 +796,6 @@ func ModuleAccPerms() map[string][]string {
}
}

// initParamsKeeper init params perpammkeeper and its subspaces
func initParamsKeeper(
appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key,
tkey storetypes.StoreKey,
Expand Down
2 changes: 0 additions & 2 deletions cmd/nibid/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

"github.com/NibiruChain/nibiru/app"
oraclecli "github.com/NibiruChain/nibiru/x/oracle/client/cli"
perpv2cli "github.com/NibiruChain/nibiru/x/perp/v2/client/cli"
)

// NewRootCmd creates a new root command for nibid. It is called once in the
Expand Down Expand Up @@ -156,7 +155,6 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) {
genesisCommand(
encodingConfig,
oraclecli.AddGenesisPricefeederDelegationCmd(app.DefaultNodeHome),
perpv2cli.AddMarketGenesisCmd(app.DefaultNodeHome),
cli.AddSudoRootAccountCmd(app.DefaultNodeHome),
),
queryCommand(),
Expand Down
1 change: 0 additions & 1 deletion contrib/docker/chaosnet.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ RUN apk --no-cache add \
COPY --from=builder /nibiru/build/nibid /usr/local/bin/nibid

COPY ./contrib/scripts/chaosnet.sh ./
COPY ./contrib/scripts/feat-perp.sh ./
RUN chmod +x ./chaosnet.sh
ARG MNEMONIC
ARG CHAIN_ID
Expand Down
7 changes: 2 additions & 5 deletions contrib/scripts/chaosnet.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
#
# This script is used in tandem with `contrib/docker/chaosnet.Dockerfile` to
# run nodes for Nibiru Chain networks inside docker containers.
# run nodes for Nibiru Chain networks inside docker containers.
# - See CHAOSNET.md for usage instructions.
set -e

Expand All @@ -27,7 +27,6 @@ sed -i 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/' $HOME/.nibid/
sed -i "s/localhost:1317/0.0.0.0:$LCD_PORT/" $HOME/.nibid/config/app.toml
sed -i "s/localhost:9090/0.0.0.0:$GRPC_PORT/" $HOME/.nibid/config/app.toml


# ------------------------------------------------------------------------
# Configure genesis params
# ------------------------------------------------------------------------
Expand All @@ -44,9 +43,7 @@ add_genesis_param() {
mv $HOME/.nibid/config/tmp_genesis.json $HOME/.nibid/config/genesis.json
}

curr_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source "$curr_dir/feat-perp.sh"
add_genesis_perp_markets_offline
curr_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"

# recover mnemonic
echo "$MNEMONIC" | nibid keys add validator --recover
Expand Down
Loading

0 comments on commit 68f8f5b

Please sign in to comment.