Skip to content

Commit

Permalink
Merge branch 'master' into releases/v0.16.x
Browse files Browse the repository at this point in the history
  • Loading branch information
NibiruHeisenberg committed Dec 11, 2022
2 parents bc40fee + db63480 commit 4a3f0c9
Show file tree
Hide file tree
Showing 31 changed files with 1,334 additions and 513 deletions.
25 changes: 17 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### State Machine Breaking

* [#1102](https://github.com/NibiruChain/nibiru/pull/1102) - refactor(perp)!: replace CumulativePremiumFractions array with single value
## Unreleased

### Bug Fixes
* [#1113](https://github.com/NibiruChain/nibiru/pull/1113) - fix: fix quick simulation issue
* [#1114](https://github.com/NibiruChain/nibiru/pull/1114) - fix(dex): fix single asset join

* [#1100](https://github.com/NibiruChain/nibiru/pull/1100) - fix(oracle): fix flaky oracle test

## [v0.16.0](https://github.com/NibiruChain/nibiru/releases/tag/v0.16.0) - 2022-11-23
## [v0.16.0](https://github.com/NibiruChain/nibiru/releases/tag/v0.16.0) - Unreleased

### Features

Expand All @@ -60,13 +56,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1082](https://github.com/NibiruChain/nibiru/pull/1082) - feat(vpool): Add gov proposal for editing the sswap invariant of a vpool..
* [#1092](https://github.com/NibiruChain/nibiru/pull/1092) - refactor(dex)!: revive dex module using intermediate test app
* [#1097](https://github.com/NibiruChain/nibiru/pull/1097) - feat(perp): Track and expose the net size of a pair with a query
* [#1105](https://github.com/NibiruChain/nibiru/pull/1105) - feat(perp): Add (notional) volume to metrics state

### State Machine Breaking

* [#1102](https://github.com/NibiruChain/nibiru/pull/1102) - refactor(perp)!: replace CumulativePremiumFractions array with single value

### Breaking Changes

* [#1074](https://github.com/NibiruChain/nibiru/pull/1074) - feat(vpool): Add gov proposal for editing the vpool config without changing the reserves.

### Improvements

* [#1111](https://github.com/NibiruChain/nibiru/pull/1111) - feat(vpool)!: Use flags and certain default values instead of unnamed args for add-genesis-vpool to improve ease of use
* [#1046](https://github.com/NibiruChain/nibiru/pull/1046) - remove: feeder. The price feeder was moved to an external repo.
* [#1015](https://github.com/NibiruChain/nibiru/pull/1015) - feat(dex): throw error when swap output amount is less than 1
* [#1018](https://github.com/NibiruChain/nibiru/pull/1018) - chore(dex): refactor to match best practice
Expand All @@ -85,7 +87,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1080](https://github.com/NibiruChain/nibiru/pull/1080) - feat(perp): Add exchanged notional to the position changed event #1080
* [#1082](https://github.com/NibiruChain/nibiru/pull/1082) - feat(localnet.sh): Set genesis prices based on real BTC and ETH prices
* [#1086](https://github.com/NibiruChain/nibiru/pull/1086) - refactor(perp)!: Removed unused field, `LiquidationPenalty`, from `PositionChangedEvent`
* [#1093](https://github.com/NibiruChain/nibiru/pull/1093) - simulation(dex): add simulation tests for stableswap pools
* [#1091](https://github.com/NibiruChain/nibiru/pull/1091) - refactor: Use common.Precision instead of 1_000_000 in the codebase
* [#1109](https://github.com/NibiruChain/nibiru/pull/1109) - refactor(vpool)!: Condense swap SwapXForY and SwapYForX events into SwapOnVpoolEvent

### Bug Fixes

* [#1100](https://github.com/NibiruChain/nibiru/pull/1100) - fix(oracle): fix flaky oracle test
* [#1110](https://github.com/NibiruChain/nibiru/pull/1110) - fix(dex): fix dex issue on unsorted join pool

### CI

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/CosmWasm/wasmd v0.29.1
github.com/NibiruChain/collections v0.1.0
github.com/NibiruChain/collections v0.1.1
github.com/cosmos/cosmos-sdk v0.45.10
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-go/v3 v3.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA=
github.com/NibiruChain/collections v0.1.0 h1:Y+S9IBID5g8tQonVtIhHxIFYgE4EnMs9PZh0y4AlBp0=
github.com/NibiruChain/collections v0.1.0/go.mod h1:ejC9eAI5B6/56mKYagW5T5aIw0yh1yI0ID+/SnqbCYo=
github.com/NibiruChain/collections v0.1.1 h1:6urGw4ephXwNKZ/cg6I5SGBBlIf9UPvRn6mFiAoX8Vk=
github.com/NibiruChain/collections v0.1.1/go.mod h1:uWw2HTT4NxQaqC6Wmwyqbz8Fg7bGShMjZUx5unWRLNk=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
Expand Down
16 changes: 14 additions & 2 deletions proto/perp/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,21 @@ message MetricsEvent {
(gogoproto.nullable) = false
];

// Total notional volume for the pair.
string volumeQuote = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// Total size volume for the pair.
string volumeBase = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// The block number at which metrics were generated.
int64 block_height = 3;
int64 block_height = 5;

// The block time in unix milliseconds at which metrics were generated.
int64 block_time_ms = 4;
int64 block_time_ms = 6;
}
12 changes: 12 additions & 0 deletions proto/perp/v1/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,16 @@ message Metrics {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// Total notional volume for the pair.
string volumeQuote = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// Total size volume for the pair.
string volumeBase = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
76 changes: 33 additions & 43 deletions proto/vpool/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,67 @@ syntax = "proto3";

package nibiru.vpool.v1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/NibiruChain/nibiru/x/vpool/types";

message ReserveSnapshotSavedEvent {
string pair = 1;

string quote_reserve = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

string base_reserve = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// MarkPrice at the end of the block.
// (instantaneous) markPrice := quoteReserve / baseReserve
string mark_price = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

int64 block_height = 5;
string pair = 1;
string quote_reserve = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

string base_reserve = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// MarkPrice at the end of the block.
// (instantaneous) markPrice := quoteReserve / baseReserve
string mark_price = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

int64 block_height = 5;

google.protobuf.Timestamp block_timestamp = 6 [
google.protobuf.Timestamp block_timestamp = 6 [
(gogoproto.stdtime) = true,
(gogoproto.nullable) = false
];
}

message SwapQuoteForBaseEvent {
string pair = 1;

string quote_amount = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

string base_amount = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message SwapBaseForQuoteEvent {
string pair = 1;
// A swap on the vpool represented by 'pair'.
// Amounts are negative or positive base on the perspective of the pool, i.e.
// a negative quote means the trader has gained quote and the vpool lost quote.
message SwapOnVpoolEvent {
string pair = 1;

string quote_amount = 2 [
// delta in the quote reserves of the vpool
string quote_amount = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

string base_amount = 3 [
// delta in the base reserves of the vpool
string base_amount = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message MarkPriceChangedEvent {
string pair = 1;
string price = 2 [
string pair = 1;
string price = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

google.protobuf.Timestamp block_timestamp = 3 [
google.protobuf.Timestamp block_timestamp = 3 [
(gogoproto.stdtime) = true,
(gogoproto.nullable) = false
];
Expand Down
55 changes: 30 additions & 25 deletions scripts/localnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,26 @@ console_log_text_color() {
reset=$(tput sgr0)
}

if [ console_log_text_color ]; then echo "succesfully toggled console coloring"
if [ console_log_text_color ]; then
echo "succesfully toggled console coloring"
else
# For Ubuntu and Debian. MacOS has tput by default.
apt-get install libncurses5-dbg -y
fi

echo_info () {
echo_info() {
echo "${blue}"
echo "$1"
echo "${reset}"
}

echo_error () {
echo_error() {
echo "${red}"
echo "$1"
echo "${reset}"
}

echo_success () {
echo_success() {
echo "${green}"
echo "$1"
echo "${reset}"
Expand All @@ -47,18 +48,20 @@ CHAIN_ID="nibiru-localnet-0"
RPC_PORT="26657"
GRPC_PORT="9090"
MNEMONIC="guard cream sadness conduct invite crumble clock pudding hole grit liar hotel maid produce squeeze return argue turtle know drive eight casino maze host"
GENESIS_COINS="1000000000unibi,10000000000000unusd"
GENESIS_COINS="10000000000000unibi,10000000000000unusd,10000000000000uusdt"
CHAIN_DIR="$HOME/.nibid"
echo "CHAIN_DIR: $CHAIN_DIR"
echo "CHAIN_ID: $CHAIN_ID"

SEDOPTION=""
if [[ "$OSTYPE" == "darwin"* ]]; then
SEDOPTION="''"
fi

# Stop nibid if it is already running
if pgrep -x "$BINARY" > /dev/null; then
echo_error "Terminating $BINARY..."
killall nibid
if pgrep -x "$BINARY" >/dev/null; then
echo_error "Terminating $BINARY..."
killall nibid
fi

# Remove previous data
Expand All @@ -79,7 +82,6 @@ else
echo_error "Failed to initialize $CHAIN_ID"
fi


# Configure keyring-backend to "test"
echo_info "Configuring keyring-backend..."
if $BINARY config keyring-backend test; then
Expand All @@ -88,7 +90,6 @@ else
echo_error "Failed to configure keyring-backend"
fi


# Configure chain-id
echo_info "Configuring chain-id..."
if $BINARY config chain-id $CHAIN_ID; then
Expand Down Expand Up @@ -170,7 +171,7 @@ fi
add_genesis_param() {
echo "jq input $1"
# copy param ($1) to tmp_genesis.json
cat $CHAIN_DIR/config/genesis.json | jq "$1" > $CHAIN_DIR/config/tmp_genesis.json
cat $CHAIN_DIR/config/genesis.json | jq "$1" >$CHAIN_DIR/config/tmp_genesis.json
# rewrite genesis.json with the contents of tmp_genesis.json
mv $CHAIN_DIR/config/tmp_genesis.json $CHAIN_DIR/config/genesis.json
}
Expand All @@ -182,13 +183,13 @@ add_genesis_vpools_with_coingecko_prices() {
curl -X 'GET' \
'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin%2Cethereum&vs_currencies=usd' \
-H 'accept: application/json' \
> $temp_json_fname
>$temp_json_fname

local M=1000000

local num_users=24000
local faucet_nusd_amt=100
local quote_amt=$(($num_users * $faucet_nusd_amt * $M))
local faucet_nusd_amt=100
local quote_amt=$(($num_users * $faucet_nusd_amt * $M))

price_btc=$(cat tmp_vpool_prices.json | jq -r '.bitcoin.usd')
price_btc=${price_btc%.*}
Expand All @@ -198,10 +199,10 @@ add_genesis_vpools_with_coingecko_prices() {
price_eth=${price_eth%.*}
base_amt_eth=$(($quote_amt / $price_eth))

nibid add-genesis-vpool ubtc:unusd $base_amt_btc $quote_amt 0.1 0.1 0.1 0.0625 12
nibid add-genesis-vpool ueth:unusd $base_amt_eth $quote_amt 0.1 0.1 0.1 0.04 20
nibid add-genesis-vpool --pair=ubtc:unusd --base-amt=$base_amt_btc --quote-amt=$quote_amt --max-leverage=12
nibid add-genesis-vpool --pair=ueth:unusd --base-amt=$base_amt_eth --quote-amt=$quote_amt --max-leverage=20 --mmr=0.04

echo 'tmp_vpool_prices: '
echo 'tmp_vpool_prices: '
cat $temp_json_fname | jq .
rm -f $temp_json_fname
}
Expand All @@ -213,16 +214,16 @@ add_genesis_vpools_default() {
local quote_amt=10$KILO$MEGA
local base_amt_btc=$(($quote_amt / 16500))
local base_amt_eth=$(($quote_amt / 1200))
nibid add-genesis-vpool ubtc:unusd $base_amt_btc $quote_amt 0.1 0.1 0.1 0.0625 12
nibid add-genesis-vpool ueth:unusd $base_amt_eth $quote_amt 0.1 0.1 0.1 0.0625 10
nibid add-genesis-vpool --pair=ubtc:unusd --base-amt=$base_amt_btc --quote-amt=$quote_amt --max-leverage=12
nibid add-genesis-vpool --pair=ueth:unusd --base-amt=$base_amt_eth --quote-amt=$quote_amt --max-leverage=20 --mmr=0.04
}

# x/vpool
if add_genesis_vpools_with_coingecko_prices; then
if add_genesis_vpools_with_coingecko_prices; then
echo_success "set vpools with coingecko prices"
elif add_genesis_vpools_default; then
echo_success "set vpools with defaults"
else
elif add_genesis_vpools_default; then
echo_success "set vpools with defaults"
else
echo_error "failed to set genesis vpools"
fi

Expand All @@ -240,9 +241,13 @@ add_genesis_param '.app_state.perp.pair_metadata[1].pair = {token0:"ueth",token1
add_genesis_param '.app_state.perp.pair_metadata[1].latest_cumulative_premium_fraction = "0"'

# x/pricefeed
add_genesis_param '.app_state.pricefeed.params.pairs[0] = {token0:"ubtc",token1:"unusd"}'
add_genesis_param '.app_state.pricefeed.params.pairs[0] = {token0:"ueth",token1:"unusd"}'
add_genesis_param '.app_state.pricefeed.params.pairs[0] = {token0:"ueth",token1:"unusd"}'
add_genesis_param '.app_state.pricefeed.params.twap_lookback_window = "900s"'
nibid add-genesis-oracle nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl

cat $HOME/.nibid/config/genesis.json | jq '.app_state.pricefeed.params.twap_lookback_window = "900s"' > $HOME/.nibid/config/tmp_genesis.json && mv $HOME/.nibid/config/tmp_genesis.json $HOME/.nibid/config/genesis.json
nibid add-genesis-oracle nibi1lptpc0e3upq2n7e4zmqtr0yxyrldp6jzz8z8xm
nibid add-genesis-oracle nibi15cdcxznuwpuk5hw7t678wpyesy78kwy00qcesa

# Start the network
echo_info "Starting $CHAIN_ID in $CHAIN_DIR..."
Expand Down
1 change: 1 addition & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ func NewNibiruTestApp(
epochsModule,
perpModule,
vpoolModule,
dexModule,
// ibc
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
Expand Down
2 changes: 1 addition & 1 deletion x/dex/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func (k Keeper) JoinPool(
) (pool types.Pool, numSharesOut sdk.Coin, remCoins sdk.Coins, err error) {
pool, _ = k.FetchPool(ctx, poolId)

if len(tokensIn) != len(pool.PoolAssets) {
if len(tokensIn) != len(pool.PoolAssets) && !shouldSwap {
return pool, numSharesOut, remCoins, errors.New("too few assets to join this pool")
}

Expand Down
Loading

0 comments on commit 4a3f0c9

Please sign in to comment.