-
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 chore/better_dex_tx_a…
…ttrs
- Loading branch information
Showing
37 changed files
with
7,913 additions
and
3,355 deletions.
There are no files selected for viewing
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
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,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{}, | ||
}, | ||
} |
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,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 | ||
} |
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,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) | ||
} |
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
Oops, something went wrong.