Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into chore/better_lo_errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jcompagni10 committed Sep 24, 2024
2 parents 1c11522 + 0ff43e4 commit 741447c
Show file tree
Hide file tree
Showing 37 changed files with 7,908 additions and 3,350 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ test: test-unit
test-all: check test-race test-cover

test-unit:
@VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock' `go list ./... | grep -v dex`
@VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock' ./...

test-race:
@VERSION=$(VERSION) go test -mod=readonly -race -tags='ledger test_ledger_mock' ./...
Expand Down
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
servicemetrics "github.com/skip-mev/slinky/service/metrics"

v401 "github.com/neutron-org/neutron/v4/app/upgrades/v4.0.1"
v500 "github.com/neutron-org/neutron/v4/app/upgrades/v5.0.0"
"github.com/neutron-org/neutron/v4/x/globalfee"
globalfeetypes "github.com/neutron-org/neutron/v4/x/globalfee/types"

Expand Down Expand Up @@ -221,7 +222,7 @@ const (
)

var (
Upgrades = []upgrades.Upgrade{v401.Upgrade}
Upgrades = []upgrades.Upgrade{v401.Upgrade, v500.Upgrade}

// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string
Expand Down Expand Up @@ -1396,6 +1397,7 @@ func (app *App) setupUpgradeHandlers() {
MarketmapKeeper: app.MarketMapKeeper,
FeeMarketKeeper: app.FeeMarkerKeeper,
DynamicfeesKeeper: app.DynamicFeesKeeper,
DexKeeper: &app.DexKeeper,
GlobalFeeSubspace: app.GetSubspace(globalfee.ModuleName),
CcvConsumerSubspace: app.GetSubspace(ccvconsumertypes.ModuleName),
},
Expand Down
2 changes: 2 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

contractmanagerkeeper "github.com/neutron-org/neutron/v4/x/contractmanager/keeper"
cronkeeper "github.com/neutron-org/neutron/v4/x/cron/keeper"
dexkeeper "github.com/neutron-org/neutron/v4/x/dex/keeper"
feeburnerkeeper "github.com/neutron-org/neutron/v4/x/feeburner/keeper"
icqkeeper "github.com/neutron-org/neutron/v4/x/interchainqueries/keeper"
tokenfactorykeeper "github.com/neutron-org/neutron/v4/x/tokenfactory/keeper"
Expand Down Expand Up @@ -64,6 +65,7 @@ type UpgradeKeepers struct {
MarketmapKeeper *marketmapkeeper.Keeper
FeeMarketKeeper *feemarketkeeper.Keeper
DynamicfeesKeeper *dynamicfeeskeeper.Keeper
DexKeeper *dexkeeper.Keeper
// subspaces
GlobalFeeSubspace paramtypes.Subspace
CcvConsumerSubspace paramtypes.Subspace
Expand Down
20 changes: 20 additions & 0 deletions app/upgrades/v5.0.0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v400

import (
storetypes "cosmossdk.io/store/types"

"github.com/neutron-org/neutron/v4/app/upgrades"
)

const (
// UpgradeName defines the on-chain upgrade name.
UpgradeName = "v5.0.0"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: storetypes.StoreUpgrades{
Added: []string{},
},
}
60 changes: 60 additions & 0 deletions app/upgrades/v5.0.0/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package v400

import (
"context"
"fmt"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

"github.com/neutron-org/neutron/v4/app/upgrades"
dexkeeper "github.com/neutron-org/neutron/v4/x/dex/keeper"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
keepers *upgrades.UpgradeKeepers,
_ upgrades.StoreKeys,
_ codec.Codec,
) upgradetypes.UpgradeHandler {
return func(c context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx := sdk.UnwrapSDKContext(c)

ctx.Logger().Info("Starting module migrations...")
vm, err := mm.RunMigrations(ctx, configurator, vm)
if err != nil {
return vm, err
}

ctx.Logger().Info("Running dex upgrades...")
// Only pause dex for mainnet
if ctx.ChainID() == "neutron-1" {
err = upgradeDexPause(ctx, *keepers.DexKeeper)
if err != nil {
return nil, err
}
}

ctx.Logger().Info(fmt.Sprintf("Migration {%s} applied", UpgradeName))
return vm, nil
}
}

func upgradeDexPause(ctx sdk.Context, k dexkeeper.Keeper) error {
// Set the dex to paused
ctx.Logger().Info("Pausing dex...")

params := k.GetParams(ctx)
params.Paused = true

if err := k.SetParams(ctx, params); err != nil {
return err
}

ctx.Logger().Info("Dex is paused")

return nil
}
65 changes: 65 additions & 0 deletions app/upgrades/v5.0.0/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package v400_test

import (
"testing"

"cosmossdk.io/math"
upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/stretchr/testify/suite"

v500 "github.com/neutron-org/neutron/v4/app/upgrades/v5.0.0"
"github.com/neutron-org/neutron/v4/testutil/common/sample"

"github.com/neutron-org/neutron/v4/testutil"
dexkeeper "github.com/neutron-org/neutron/v4/x/dex/keeper"
dextypes "github.com/neutron-org/neutron/v4/x/dex/types"
)

type UpgradeTestSuite struct {
testutil.IBCConnectionTestSuite
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

func (suite *UpgradeTestSuite) SetupTest() {
suite.IBCConnectionTestSuite.SetupTest()
}

func (suite *UpgradeTestSuite) TestUpgradeDexPause() {
var (
app = suite.GetNeutronZoneApp(suite.ChainA)
ctx = suite.ChainA.GetContext().WithChainID("neutron-1")
msgServer = dexkeeper.NewMsgServerImpl(app.DexKeeper)
)

params := app.DexKeeper.GetParams(ctx)

suite.False(params.Paused)

upgrade := upgradetypes.Plan{
Name: v500.UpgradeName,
Info: "some text here",
Height: 100,
}
suite.NoError(app.UpgradeKeeper.ApplyUpgrade(ctx, upgrade))

params = app.DexKeeper.GetParams(ctx)

suite.True(params.Paused)

_, err := msgServer.Deposit(ctx, &dextypes.MsgDeposit{
Creator: sample.AccAddress(),
Receiver: sample.AccAddress(),
TokenA: "TokenA",
TokenB: "TokenB",
TickIndexesAToB: []int64{1},
Fees: []uint64{1},
AmountsA: []math.Int{math.OneInt()},
AmountsB: []math.Int{math.ZeroInt()},
Options: []*dextypes.DepositOptions{{}},
})

suite.ErrorIs(err, dextypes.ErrDexPaused)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
cosmossdk.io/x/tx v0.13.5
cosmossdk.io/x/upgrade v0.1.4
github.com/CosmWasm/wasmd v0.51.0
github.com/CosmWasm/wasmvm/v2 v2.1.2
github.com/CosmWasm/wasmvm/v2 v2.1.3
github.com/cometbft/cometbft v0.38.11
github.com/cosmos/admin-module/v2 v2.0.0-20240430142959-8b3328d1b1a2
github.com/cosmos/cosmos-db v1.0.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CosmWasm/wasmvm/v2 v2.1.2 h1:GkJ5bAsRlLHfIQVg/FY1VHwLyBwlCjAhDea0B8L+e20=
github.com/CosmWasm/wasmvm/v2 v2.1.2/go.mod h1:bMhLQL4Yp9CzJi9A83aR7VO9wockOsSlZbT4ztOl6bg=
github.com/CosmWasm/wasmvm/v2 v2.1.3 h1:CSJTauZqkHyb9yic6JVYCjiGUgxI2MJV2QzfSu8m49c=
github.com/CosmWasm/wasmvm/v2 v2.1.3/go.mod h1:bMhLQL4Yp9CzJi9A83aR7VO9wockOsSlZbT4ztOl6bg=
github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=
Expand Down
86 changes: 84 additions & 2 deletions proto/neutron/dex/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ service Query {
option (google.api.http).get = "/neutron/dex/pool_reserves/{pair_id}/{token_in}/{tick_index}/{fee}";
}

// Queries the simulated result of a multihop swap
// DEPRECATED Queries the simulated result of a multihop swap
rpc EstimateMultiHopSwap(QueryEstimateMultiHopSwapRequest) returns (QueryEstimateMultiHopSwapResponse) {
option (google.api.http).get = "/neutron/dex/estimate_multi_hop_swap";
option deprecated = true;
}

// Queries the simulated result of a PlaceLimit order
// DEPRECATED Queries the simulated result of a PlaceLimit order
rpc EstimatePlaceLimitOrder(QueryEstimatePlaceLimitOrderRequest) returns (QueryEstimatePlaceLimitOrderResponse) {
option (google.api.http).get = "/neutron/dex/estimate_place_limit_order";
option deprecated = true;
}

// Queries a pool by pair, tick and fee
Expand All @@ -126,6 +128,36 @@ service Query {
option (google.api.http).get = "/neutron/dex/pool_metadata";
}

// Simulates MsgDeposit
rpc SimulateDeposit(QuerySimulateDepositRequest) returns (QuerySimulateDepositResponse) {
option (google.api.http).get = "/neutron/dex/simulate_deposit";
}

// Simulates MsgWithdrawal
rpc SimulateWithdrawal(QuerySimulateWithdrawalRequest) returns (QuerySimulateWithdrawalResponse) {
option (google.api.http).get = "/neutron/dex/simulate_withdrawal";
}

// Simulates MsgPlaceLimitOrder
rpc SimulatePlaceLimitOrder(QuerySimulatePlaceLimitOrderRequest) returns (QuerySimulatePlaceLimitOrderResponse) {
option (google.api.http).get = "/neutron/dex/simulate_place_limit_order";
}

// Simulates MsgWithdrawFilledLimitOrder
rpc SimulateWithdrawFilledLimitOrder(QuerySimulateWithdrawFilledLimitOrderRequest) returns (QuerySimulateWithdrawFilledLimitOrderResponse) {
option (google.api.http).get = "/neutron/dex/simulate_withdraw_filled_limit_order";
}

// Simulates MsgCancelLimitOrder
rpc SimulateCancelLimitOrder(QuerySimulateCancelLimitOrderRequest) returns (QuerySimulateCancelLimitOrderResponse) {
option (google.api.http).get = "/neutron/dex/simulate_cancel_limit_order";
}

// Simulates MsgMultiHopSwap
rpc SimulateMultiHopSwap(QuerySimulateMultiHopSwapRequest) returns (QuerySimulateMultiHopSwapResponse) {
option (google.api.http).get = "/neutron/dex/pool_metadata";
}

// this line is used by starport scaffolding # 2
}

Expand Down Expand Up @@ -260,6 +292,7 @@ message QueryGetPoolReservesResponse {
}

message QueryEstimateMultiHopSwapRequest {
// DEPRECATED: Use QuerySimulateMultiHopSwap
string creator = 1;
string receiver = 2;
repeated MultiHopRoute routes = 3;
Expand Down Expand Up @@ -290,6 +323,7 @@ message QueryEstimateMultiHopSwapResponse {
}

message QueryEstimatePlaceLimitOrderRequest {
// DEPRECATED: Use QuerySimulatePlaceLimitOrder
string creator = 1;
string receiver = 2;
string token_in = 3;
Expand Down Expand Up @@ -378,4 +412,52 @@ message QueryAllPoolMetadataResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QuerySimulateDepositRequest {
MsgDeposit msg = 1;
}

message QuerySimulateDepositResponse {
MsgDepositResponse resp = 1;
}

message QuerySimulateWithdrawalRequest {
MsgWithdrawal msg = 1;
}

message QuerySimulateWithdrawalResponse {
MsgWithdrawalResponse resp = 1;
}

message QuerySimulatePlaceLimitOrderRequest {
MsgPlaceLimitOrder msg = 1;
}

message QuerySimulatePlaceLimitOrderResponse {
MsgPlaceLimitOrderResponse resp = 1;
}

message QuerySimulateWithdrawFilledLimitOrderRequest {
MsgWithdrawFilledLimitOrder msg = 1;
}

message QuerySimulateWithdrawFilledLimitOrderResponse {
MsgWithdrawFilledLimitOrderResponse resp = 1;
}

message QuerySimulateCancelLimitOrderRequest {
MsgCancelLimitOrder msg = 1;
}

message QuerySimulateCancelLimitOrderResponse {
MsgCancelLimitOrderResponse resp = 1;
}

message QuerySimulateMultiHopSwapRequest {
MsgMultiHopSwap msg = 1;
}

message QuerySimulateMultiHopSwapResponse {
MsgMultiHopSwapResponse resp = 1;
}

// this line is used by starport scaffolding # 3
Loading

0 comments on commit 741447c

Please sign in to comment.