-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into fix/autoswap
- Loading branch information
Showing
59 changed files
with
5,075 additions
and
236 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package v500 | ||
|
||
import ( | ||
storetypes "cosmossdk.io/store/types" | ||
|
||
"github.com/neutron-org/neutron/v5/app/upgrades" | ||
ibcratelimittypes "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/types" | ||
) | ||
|
||
const ( | ||
// UpgradeName defines the on-chain upgrade name. | ||
UpgradeName = "v5.0.0" | ||
|
||
MarketMapAuthorityMultisig = "neutron1anjpluecd0tdc0n8xzc3l5hua4h93wyq0x7v56" | ||
// RateLimitContract defines the RL contract addr which we set as a contract address in ibc-rate-limit middleware | ||
// https://neutron.celat.one/neutron-1/contracts/neutron15aqgplxcavqhurr0g5wwtdw6025dknkqwkfh0n46gp2qjl6236cs2yd3nl | ||
RateLimitContract = "neutron15aqgplxcavqhurr0g5wwtdw6025dknkqwkfh0n46gp2qjl6236cs2yd3nl" | ||
) | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
CreateUpgradeHandler: CreateUpgradeHandler, | ||
StoreUpgrades: storetypes.StoreUpgrades{ | ||
Added: []string{ibcratelimittypes.ModuleName}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package v500 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
adminmoduletypes "github.com/cosmos/admin-module/v2/x/adminmodule/types" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
marketmapkeeper "github.com/skip-mev/slinky/x/marketmap/keeper" | ||
marketmaptypes "github.com/skip-mev/slinky/x/marketmap/types" | ||
|
||
"github.com/neutron-org/neutron/v5/app/upgrades" | ||
dexkeeper "github.com/neutron-org/neutron/v5/x/dex/keeper" | ||
ibcratelimitkeeper "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/keeper" | ||
ibcratelimittypes "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/types" | ||
) | ||
|
||
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 | ||
} | ||
} | ||
|
||
err = setMarketMapParams(ctx, keepers.MarketmapKeeper) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ctx.Logger().Info("Running ibc-rate-limit upgrades...") | ||
// Only set rate limit contract for mainnet | ||
if ctx.ChainID() == "neutron-1" { | ||
err = upgradeIbcRateLimitSetContract(ctx, *keepers.IbcRateLimitKeeper) | ||
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 | ||
} | ||
|
||
func upgradeIbcRateLimitSetContract(ctx sdk.Context, k ibcratelimitkeeper.Keeper) error { | ||
// Set the dex to paused | ||
ctx.Logger().Info("Setting ibc rate limiting contract...") | ||
|
||
if err := k.SetParams(ctx, ibcratelimittypes.Params{ContractAddress: RateLimitContract}); err != nil { | ||
return err | ||
} | ||
|
||
ctx.Logger().Info("Rate limit contract is set") | ||
|
||
return nil | ||
} | ||
|
||
func setMarketMapParams(ctx sdk.Context, marketmapKeeper *marketmapkeeper.Keeper) error { | ||
marketmapParams := marketmaptypes.Params{ | ||
MarketAuthorities: []string{authtypes.NewModuleAddress(adminmoduletypes.ModuleName).String(), MarketMapAuthorityMultisig}, | ||
Admin: authtypes.NewModuleAddress(adminmoduletypes.ModuleName).String(), | ||
} | ||
return marketmapKeeper.SetParams(ctx, marketmapParams) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package v500_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"cosmossdk.io/math" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
"github.com/stretchr/testify/require" | ||
"github.com/stretchr/testify/suite" | ||
|
||
v500 "github.com/neutron-org/neutron/v5/app/upgrades/v5.0.0" | ||
"github.com/neutron-org/neutron/v5/testutil/common/sample" | ||
|
||
"github.com/neutron-org/neutron/v5/testutil" | ||
dexkeeper "github.com/neutron-org/neutron/v5/x/dex/keeper" | ||
dextypes "github.com/neutron-org/neutron/v5/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) TestOracleUpgrade() { | ||
app := suite.GetNeutronZoneApp(suite.ChainA) | ||
ctx := suite.ChainA.GetContext() | ||
t := suite.T() | ||
|
||
upgrade := upgradetypes.Plan{ | ||
Name: v500.UpgradeName, | ||
Info: "some text here", | ||
Height: 100, | ||
} | ||
require.NoError(t, app.UpgradeKeeper.ApplyUpgrade(ctx, upgrade)) | ||
|
||
params, err := app.MarketMapKeeper.GetParams(ctx) | ||
suite.Require().NoError(err) | ||
suite.Require().Equal(params.MarketAuthorities[0], "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z") | ||
suite.Require().Equal(params.MarketAuthorities[1], v500.MarketMapAuthorityMultisig) | ||
suite.Require().Equal(params.Admin, "neutron1hxskfdxpp5hqgtjj6am6nkjefhfzj359x0ar3z") | ||
} | ||
|
||
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) | ||
} | ||
|
||
func (suite *UpgradeTestSuite) TestUpgradeSetRateLimitContract() { | ||
var ( | ||
app = suite.GetNeutronZoneApp(suite.ChainA) | ||
ctx = suite.ChainA.GetContext().WithChainID("neutron-1") | ||
) | ||
|
||
params := app.RateLimitingICS4Wrapper.IbcratelimitKeeper.GetParams(ctx) | ||
|
||
suite.Equal(params.ContractAddress, "") | ||
|
||
upgrade := upgradetypes.Plan{ | ||
Name: v500.UpgradeName, | ||
Info: "some text here", | ||
Height: 100, | ||
} | ||
suite.NoError(app.UpgradeKeeper.ApplyUpgrade(ctx, upgrade)) | ||
|
||
params = app.RateLimitingICS4Wrapper.IbcratelimitKeeper.GetParams(ctx) | ||
|
||
suite.Equal(params.ContractAddress, v500.RateLimitContract) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
syntax = "proto3"; | ||
package neutron.ibcratelimit.v1beta1; | ||
|
||
import "cosmos_proto/cosmos.proto"; | ||
import "gogoproto/gogo.proto"; | ||
import "google/protobuf/any.proto"; | ||
import "neutron/ibcratelimit/v1beta1/params.proto"; | ||
|
||
option go_package = "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/types"; | ||
|
||
// GenesisState defines the ibc-rate-limit module's genesis state. | ||
message GenesisState { | ||
// params are all the parameters of the module | ||
Params params = 1 [(gogoproto.nullable) = false]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
syntax = "proto3"; | ||
package neutron.ibcratelimit.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/types"; | ||
|
||
// Params defines the parameters for the ibc-rate-limit module. | ||
message Params { | ||
string contract_address = 1 [ | ||
(gogoproto.moretags) = "yaml:\"contract_address\"", | ||
(gogoproto.nullable) = true | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
syntax = "proto3"; | ||
package neutron.ibcratelimit.v1beta1; | ||
|
||
import "cosmos/base/query/v1beta1/pagination.proto"; | ||
import "gogoproto/gogo.proto"; | ||
import "google/api/annotations.proto"; | ||
import "neutron/ibcratelimit/v1beta1/params.proto"; | ||
|
||
option go_package = "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/types"; | ||
|
||
// Query defines the gRPC querier service. | ||
service Query { | ||
// Params defines a gRPC query method that returns the ibc-rate-limit module's | ||
// parameters. | ||
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { | ||
option (google.api.http).get = "/neutron/ibc-rate-limit/v1beta1/params"; | ||
} | ||
} | ||
|
||
// ParamsRequest is the request type for the Query/Params RPC method. | ||
message QueryParamsRequest {} | ||
|
||
// aramsResponse is the response type for the Query/Params RPC method. | ||
message QueryParamsResponse { | ||
// params defines the parameters of the module. | ||
Params params = 1 [(gogoproto.nullable) = false]; | ||
} |
Oops, something went wrong.