Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unwire spot module for main branch #1831

Merged
merged 10 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .hypothesis/unicode_data/13.0.0/charmap.json.gz
Binary file not shown.
15 changes: 0 additions & 15 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ import (
oraclekeeper "github.com/NibiruChain/nibiru/x/oracle/keeper"
oracletypes "github.com/NibiruChain/nibiru/x/oracle/types"

"github.com/NibiruChain/nibiru/x/spot"
spotkeeper "github.com/NibiruChain/nibiru/x/spot/keeper"
spottypes "github.com/NibiruChain/nibiru/x/spot/types"

"github.com/NibiruChain/nibiru/x/sudo"
"github.com/NibiruChain/nibiru/x/sudo/keeper"
sudotypes "github.com/NibiruChain/nibiru/x/sudo/types"
Expand Down Expand Up @@ -169,7 +165,6 @@ type AppKeepers struct {
// Nibiru keepers
// ---------------
EpochsKeeper epochskeeper.Keeper
SpotKeeper spotkeeper.Keeper
OracleKeeper oraclekeeper.Keeper
InflationKeeper inflationkeeper.Keeper
SudoKeeper keeper.Keeper
Expand Down Expand Up @@ -208,7 +203,6 @@ func initStoreKeys() (
ibcexported.StoreKey,

// nibiru x/ keys
spottypes.StoreKey,
oracletypes.StoreKey,
epochstypes.StoreKey,
inflationtypes.StoreKey,
Expand Down Expand Up @@ -348,10 +342,6 @@ func (app *NibiruApp) InitKeepers(

// ---------------------------------- Nibiru Chain x/ keepers

app.SpotKeeper = spotkeeper.NewKeeper(
appCodec, keys[spottypes.StoreKey], app.GetSubspace(spottypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.DistrKeeper)

app.SudoKeeper = keeper.NewKeeper(
appCodec, keys[sudotypes.StoreKey],
)
Expand Down Expand Up @@ -578,7 +568,6 @@ func (app *NibiruApp) initAppModules(
authzmodule.NewAppModule(appCodec, app.authzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),

// Nibiru modules
spot.NewAppModule(appCodec, app.SpotKeeper, app.AccountKeeper, app.BankKeeper),
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
epochs.NewAppModule(appCodec, app.EpochsKeeper),
inflation.NewAppModule(app.InflationKeeper, app.AccountKeeper, *app.stakingKeeper),
Expand Down Expand Up @@ -649,7 +638,6 @@ func orderedModuleNames() []string {
// --------------------------------------------------------------------
// Native x/ Modules
epochstypes.ModuleName,
spottypes.ModuleName,
oracletypes.ModuleName,
inflationtypes.ModuleName,
sudotypes.ModuleName,
Expand Down Expand Up @@ -762,7 +750,6 @@ func ModuleBasicManager() module.BasicManager {
ibctransfer.AppModuleBasic{},
ibctm.AppModuleBasic{},
// native x/
spot.AppModuleBasic{},
oracle.AppModuleBasic{},
epochs.AppModuleBasic{},
inflation.AppModuleBasic{},
Expand All @@ -783,7 +770,6 @@ func ModuleAccPerms() map[string][]string {
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
spottypes.ModuleName: {authtypes.Minter, authtypes.Burner},
oracletypes.ModuleName: {},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: {},
Expand All @@ -810,7 +796,6 @@ func initParamsKeeper(
paramsKeeper.Subspace(govtypes.ModuleName)
paramsKeeper.Subspace(crisistypes.ModuleName)
// Nibiru core params keepers | x/
paramsKeeper.Subspace(spottypes.ModuleName)
paramsKeeper.Subspace(epochstypes.ModuleName)
paramsKeeper.Subspace(inflationtypes.ModuleName)
// ibc params keepers
Expand Down
118 changes: 71 additions & 47 deletions contrib/scripts/localnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ console_log_text_color() {
}

if [ console_log_text_color ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the conditional check to correctly execute the console_log_text_color function.

- if [ console_log_text_color ]; then
+ if console_log_text_color; then

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if [ console_log_text_color ]; then
if console_log_text_color; then

echo "successfully toggled console coloring"
echo "succesfully toggled console coloring"
else
# For Ubuntu and Debian. MacOS has tput by default.
apt-get install libncurses5-dbg -y
Expand Down Expand Up @@ -58,8 +58,6 @@ echo_info "Parsing flags for the script..."
# behavior of the script is to run make install if the flag --no-build is not present.
FLAG_NO_BUILD=false

# $FLAG_SPOT: Feature flag for x/spot. Enabled with `--features spot`.
FLAG_SPOT=false

build_from_source() {
echo_info "Building from source..."
Expand Down Expand Up @@ -97,14 +95,14 @@ while [[ $# -gt 0 ]]; do
esac
done


# Check if FLAG_NO_BUILD was set to true
if ! $FLAG_NO_BUILD; then
build_from_source
fi

echo_info "Features flags:"
echo "FLAG_NO_BUILD: $FLAG_NO_BUILD"
echo "FLAG_SPOT: $FLAG_SPOT"

SEDOPTION=""
if [[ "$OSTYPE" == "darwin"* ]]; then
Expand Down Expand Up @@ -139,37 +137,90 @@ else
echo_error "Failed to initialize $CHAIN_ID"
fi

# nibid config
echo_info "Updating nibid config..."
$BINARY config keyring-backend test
$BINARY config chain-id $CHAIN_ID
$BINARY config broadcast-mode sync
$BINARY config output json
$BINARY config # Prints config.
# Configure keyring-backend to "test"
echo_info "Configuring keyring-backend..."
if $BINARY config keyring-backend test; then
echo_success "Successfully configured keyring-backend"
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
echo_success "Successfully configured chain-id"
else
echo_error "Failed to configure chain-id"
fi

# Configure broadcast mode
echo_info "Configuring broadcast mode..."
if $BINARY config broadcast-mode sync; then
echo_success "Successfully configured broadcast-mode"
else
echo_error "Failed to configure broadcast mode"
fi

# Configure output mode
echo_info "Configuring output mode..."
if $BINARY config output json; then
echo_success "Successfully configured output mode"
else
echo_error "Failed to configure output mode"
fi

# Enable API Server
echo_info "config/app.toml: Enabling API server"
sed -i $SEDOPTION '/\[api\]/,+3 s/enable = false/enable = true/' $CHAIN_DIR/config/app.toml
echo_info "Enabling API server"
if sed -i $SEDOPTION '/\[api\]/,+3 s/enable = false/enable = true/' $CHAIN_DIR/config/app.toml; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that variables and paths in shell commands are properly quoted to prevent globbing and word splitting. This is particularly important for the sed command modifications in the script.

- if sed -i $SEDOPTION '/\[api\]/,+3 s/enable = false/enable = true/' $CHAIN_DIR/config/app.toml; then
+ if sed -i "$SEDOPTION" '/\[api\]/,+3 s/enable = false/enable = true/' "$CHAIN_DIR/config/app.toml"; then

- if sed -i $SEDOPTION 's/swagger = false/swagger = true/' $CHAIN_DIR/config/app.toml; then
+ if sed -i "$SEDOPTION" 's/swagger = false/swagger = true/' "$CHAIN_DIR/config/app.toml"; then

- if sed -i $SEDOPTION 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/' $CHAIN_DIR/config/app.toml; then
+ if sed -i "$SEDOPTION" 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/' "$CHAIN_DIR/config/app.toml"; then

Also applies to: 182-182, 190-190


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if sed -i $SEDOPTION '/\[api\]/,+3 s/enable = false/enable = true/' $CHAIN_DIR/config/app.toml; then
if sed -i "$SEDOPTION" '/\[api\]/,+3 s/enable = false/enable = true/' "$CHAIN_DIR/config/app.toml"; then

echo_success "Successfully enabled API server"
else
echo_error "Failed to enable API server"
fi

# Enable Swagger Docs
echo_info "config/app.toml: Enabling Swagger Docs"
sed -i $SEDOPTION 's/swagger = false/swagger = true/' $CHAIN_DIR/config/app.toml
echo_info "Enabling Swagger Docs"
if sed -i $SEDOPTION 's/swagger = false/swagger = true/' $CHAIN_DIR/config/app.toml; then
echo_success "Successfully enabled Swagger Docs"
else
echo_error "Failed to enable Swagger Docs"
fi

# Enable CORS for localnet
echo_info "config/app.toml: Enabling CORS"
sed -i $SEDOPTION 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/' $CHAIN_DIR/config/app.toml
echo_info "Enabling CORS"
if sed -i $SEDOPTION 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/' $CHAIN_DIR/config/app.toml; then
echo_success "Successfully enabled CORS"
else
echo_error "Failed to enable CORS"
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure variables in sed commands are properly quoted to prevent globbing and word splitting.

- if sed -i $SEDOPTION '/\[api\]/,+3 s/enable = false/enable = true/' $CHAIN_DIR/config/app.toml; then
+ if sed -i "$SEDOPTION" '/\[api\]/,+3 s/enable = false/enable = true/' "$CHAIN_DIR/config/app.toml"; then

- if sed -i $SEDOPTION 's/swagger = false/swagger = true/' $CHAIN_DIR/config/app.toml; then
+ if sed -i "$SEDOPTION" 's/swagger = false/swagger = true/' "$CHAIN_DIR/config/app.toml"; then

- if sed -i $SEDOPTION 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/' $CHAIN_DIR/config/app.toml; then
+ if sed -i "$SEDOPTION" 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/' "$CHAIN_DIR/config/app.toml"; then

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if sed -i $SEDOPTION '/\[api\]/,+3 s/enable = false/enable = true/' $CHAIN_DIR/config/app.toml; then
echo_success "Successfully enabled API server"
else
echo_error "Failed to enable API server"
fi
# Enable Swagger Docs
echo_info "config/app.toml: Enabling Swagger Docs"
sed -i $SEDOPTION 's/swagger = false/swagger = true/' $CHAIN_DIR/config/app.toml
echo_info "Enabling Swagger Docs"
if sed -i $SEDOPTION 's/swagger = false/swagger = true/' $CHAIN_DIR/config/app.toml; then
echo_success "Successfully enabled Swagger Docs"
else
echo_error "Failed to enable Swagger Docs"
fi
# Enable CORS for localnet
echo_info "config/app.toml: Enabling CORS"
sed -i $SEDOPTION 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/' $CHAIN_DIR/config/app.toml
echo_info "Enabling CORS"
if sed -i $SEDOPTION 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/' $CHAIN_DIR/config/app.toml; then
echo_success "Successfully enabled CORS"
else
echo_error "Failed to enable CORS"
fi
if sed -i "$SEDOPTION" '/\[api\]/,+3 s/enable = false/enable = true/' "$CHAIN_DIR/config/app.toml"; then
echo_success "Successfully enabled API server"
else
echo_error "Failed to enable API server"
fi
# Enable Swagger Docs
echo_info "Enabling Swagger Docs"
if sed -i "$SEDOPTION" 's/swagger = false/swagger = true/' "$CHAIN_DIR/config/app.toml"; then
echo_success "Successfully enabled Swagger Docs"
else
echo_error "Failed to enable Swagger Docs"
fi
# Enable CORS for localnet
echo_info "Enabling CORS"
if sed -i "$SEDOPTION" 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/' "$CHAIN_DIR/config/app.toml"; then
echo_success "Successfully enabled CORS"
else
echo_error "Failed to enable CORS"
fi


echo_info "Adding genesis accounts..."

val_key_name="validator"

echo "$MNEMONIC" | $BINARY keys add $val_key_name --recover
$BINARY add-genesis-account $($BINARY keys show $val_key_name -a) $GENESIS_COINS
echo_success "Successfully added genesis account: $val_key_name"
if $BINARY add-genesis-account $($BINARY keys show $val_key_name -a) $GENESIS_COINS; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quote the subshell command to prevent word splitting when adding a genesis account.

- if $BINARY add-genesis-account $($BINARY keys show $val_key_name -a) $GENESIS_COINS; then
+ if $BINARY add-genesis-account "$($BINARY keys show $val_key_name -a)" $GENESIS_COINS; then

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if $BINARY add-genesis-account $($BINARY keys show $val_key_name -a) $GENESIS_COINS; then
if $BINARY add-genesis-account "$($BINARY keys show $val_key_name -a)" $GENESIS_COINS; then

echo_success "Successfully added genesis account: $val_key_name"
else
echo_error "Failed to add genesis account: $val_key_name"
fi

val_address=$($BINARY keys list | jq -r '.[] | select(.name == "validator") | .address')
val_address=${val_address:-"nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl"}

echo_info "Adding gentx validator..."
if $BINARY genesis gentx $val_key_name 900000000unibi --chain-id $CHAIN_ID; then
echo_success "Successfully added gentx"
else
echo_error "Failed to add gentx"
fi

echo_info "Collecting gentx..."
if $BINARY genesis collect-gentxs; then
echo_success "Successfully collected genesis txs into genesis.json"
else
echo_error "Failed to collect genesis txs"
fi

# ------------------------------------------------------------------------
# Configure genesis params
# ------------------------------------------------------------------------
Expand All @@ -188,10 +239,6 @@ add_genesis_param() {

echo_info "Configuring genesis params"

# if $FLAG_SPOT; then
# # Perform any actions specific to the x/spot feature
# fi

# set validator as sudoer
add_genesis_param '.app_state.sudo.sudoers.root = "'"$val_address"'"'

Expand All @@ -200,32 +247,9 @@ price_btc="50000"
price_eth="2000"
add_genesis_param '.app_state.oracle.exchange_rates[0].pair = "ubtc:uuusd"'
add_genesis_param '.app_state.oracle.exchange_rates[0].exchange_rate = "'"$price_btc"'"'
add_genesis_param '.app_state.oracle.exchange_rates[1].pair = "ueth:uuusd"'
add_genesis_param '.app_state.oracle.exchange_rates[1].pair = "ueth:unusd"'
add_genesis_param '.app_state.oracle.exchange_rates[1].exchange_rate = "'"$price_eth"'"'

add_genesis_param '.app_state.inflation.params.inflation_enabled = false'

# ------------------------------------------------------------------------
# Gentx
# ------------------------------------------------------------------------

echo_info "Adding gentx validator..."
if $BINARY genesis gentx $val_key_name 900000000unibi --chain-id $CHAIN_ID; then
echo_success "Successfully added gentx"
else
echo_error "Failed to add gentx"
fi

echo_info "Collecting gentx..."
if $BINARY genesis collect-gentxs; then
echo_success "Successfully collected genesis txs into genesis.json"
else
echo_error "Failed to collect genesis txs"
fi

# ------------------------------------------------------------------------
# Start the network
# ------------------------------------------------------------------------

echo_info "Starting $CHAIN_ID in $CHAIN_DIR..."
$BINARY start --home "$CHAIN_DIR" --pruning nothing
Loading
Loading