Skip to content

Commit

Permalink
refactor(nexus)!: refactor to move coin locking unlocking logic from …
Browse files Browse the repository at this point in the history
…axelarnet to nexus (#2186)

Co-authored-by: Haiyi Zhong <[email protected]>
  • Loading branch information
fish-sammy and haiyizxx authored Oct 4, 2024
1 parent 6271ef5 commit 2ee5604
Show file tree
Hide file tree
Showing 29 changed files with 3,072 additions and 962 deletions.
9 changes: 4 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ func NewAxelarApp(
*GetKeeper[axelarnetKeeper.IBCKeeper](keepers),
GetKeeper[nexusKeeper.Keeper](keepers),
axelarbankkeeper.NewBankKeeper(GetKeeper[bankkeeper.BaseKeeper](keepers)),
GetKeeper[authkeeper.AccountKeeper](keepers),
logger,
),
)
Expand Down Expand Up @@ -440,12 +439,10 @@ func initMessageRouter(keepers *KeeperCache) nexusTypes.MessageRouter {
messageRouter := nexusTypes.NewMessageRouter().
AddRoute(evmTypes.ModuleName, evmKeeper.NewMessageRoute()).
AddRoute(axelarnetTypes.ModuleName, axelarnetKeeper.NewMessageRoute(
*GetKeeper[axelarnetKeeper.Keeper](keepers),
GetKeeper[axelarnetKeeper.IBCKeeper](keepers),
GetKeeper[feegrantkeeper.Keeper](keepers),
axelarbankkeeper.NewBankKeeper(GetKeeper[bankkeeper.BaseKeeper](keepers)),
GetKeeper[nexusKeeper.Keeper](keepers),
GetKeeper[authkeeper.AccountKeeper](keepers),
GetKeeper[stakingkeeper.Keeper](keepers),
))

Expand Down Expand Up @@ -599,6 +596,8 @@ func initAppModules(keepers *KeeperCache, bApp *bam.BaseApp, encodingConfig axel
GetKeeper[stakingkeeper.Keeper](keepers),
GetKeeper[axelarnetKeeper.Keeper](keepers),
GetKeeper[rewardKeeper.Keeper](keepers),
GetKeeper[bankkeeper.BaseKeeper](keepers),
GetKeeper[authkeeper.AccountKeeper](keepers),
),
evm.NewAppModule(
GetKeeper[evmKeeper.BaseKeeper](keepers),
Expand Down Expand Up @@ -718,10 +717,10 @@ func InitModuleAccountPermissions() map[string][]string {
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
axelarnetTypes.ModuleName: {authtypes.Minter, authtypes.Burner},
axelarnetTypes.ModuleName: nil,
rewardTypes.ModuleName: {authtypes.Minter},
wasm.ModuleName: {authtypes.Burner},
nexusTypes.ModuleName: nil,
nexusTypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}
}

Expand Down
6 changes: 3 additions & 3 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,11 @@ func initBankKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, keepe
GetKeeper[authkeeper.AccountKeeper](keepers),
keepers.getSubspace(banktypes.ModuleName),
maps.Filter(moduleAccountAddrs(moduleAccPerms), func(addr string, _ bool) bool {
// we do not rely on internal balance tracking for invariance checks in the axelarnet module
// we do not rely on internal balance tracking for invariance checks in the nexus module
// (https://github.com/cosmos/cosmos-sdk/issues/12825 for more details on the purpose of the blocked list),
// but the module address must be able to use ibc transfers,
// but the nexus module account must be able to send or receive coins to mint/burn them for cross-chain transfers,
// so we exclude this address from the blocked list
return addr != authtypes.NewModuleAddress(axelarnetTypes.ModuleName).String()
return addr != authtypes.NewModuleAddress(nexusTypes.ModuleName).String()
}),
)
return &bankK
Expand Down
5 changes: 3 additions & 2 deletions x/ante/check_refund_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
evm "github.com/axelarnetwork/axelar-core/x/evm/types"
multisig "github.com/axelarnetwork/axelar-core/x/multisig/types"
"github.com/axelarnetwork/axelar-core/x/nexus/exported"
nexustypes "github.com/axelarnetwork/axelar-core/x/nexus/types"
rewardtypes "github.com/axelarnetwork/axelar-core/x/reward/types"
snapshotkeeper "github.com/axelarnetwork/axelar-core/x/snapshot/keeper"
snapshottypes "github.com/axelarnetwork/axelar-core/x/snapshot/types"
Expand Down Expand Up @@ -200,8 +201,8 @@ func prepareAnteHandler(ctx sdk.Context, sender sdk.AccAddress, encConfig params
bankKeeper := app.GetKeeper[bankkeeper.BaseKeeper](axelarApp.Keepers)
bankKeeper.SetParams(ctx, banktypes.DefaultParams())
balance := sdk.NewCoins(sdk.NewInt64Coin("stake", 1e10))
funcs.MustNoErr(bankKeeper.MintCoins(ctx, axelarnet.ModuleName, balance))
funcs.MustNoErr(bankKeeper.SendCoinsFromModuleToAccount(ctx, axelarnet.ModuleName, sender, balance))
funcs.MustNoErr(bankKeeper.MintCoins(ctx, nexustypes.ModuleName, balance))
funcs.MustNoErr(bankKeeper.SendCoinsFromModuleToAccount(ctx, nexustypes.ModuleName, sender, balance))

stakingKeeper := app.GetKeeper[stakingkeeper.Keeper](axelarApp.Keepers)
stakingKeeper.SetParams(ctx, stakingtypes.DefaultParams())
Expand Down
3 changes: 1 addition & 2 deletions x/axelarnet/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/axelarnetwork/axelar-core/x/axelarnet/keeper"
"github.com/axelarnetwork/axelar-core/x/axelarnet/types"
"github.com/axelarnetwork/axelar-core/x/axelarnet/types/mock"
"github.com/axelarnetwork/axelar-core/x/axelarnet/types/testutils"
axelartestutils "github.com/axelarnetwork/axelar-core/x/axelarnet/types/testutils"
nexus "github.com/axelarnetwork/axelar-core/x/nexus/exported"
"github.com/axelarnetwork/utils/math"
Expand Down Expand Up @@ -108,7 +107,7 @@ func TestEndBlocker(t *testing.T) {
return false
}

transfer := testutils.RandomIBCTransfer()
transfer := axelartestutils.RandomIBCTransfer()
bz, _ := transfer.Marshal()
if err := value.Unmarshal(bz); err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions x/axelarnet/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
)

// NewHandler returns the handler of the Cosmos module
func NewHandler(k keeper.Keeper, n types.Nexus, b types.BankKeeper, a types.AccountKeeper, ibcK keeper.IBCKeeper) sdk.Handler {
server := keeper.NewMsgServerImpl(k, n, b, a, ibcK)
func NewHandler(k keeper.Keeper, n types.Nexus, b types.BankKeeper, ibcK keeper.IBCKeeper) sdk.Handler {
server := keeper.NewMsgServerImpl(k, n, b, ibcK)
h := func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())
switch msg := msg.(type) {
Expand Down
185 changes: 0 additions & 185 deletions x/axelarnet/keeper/coin.go

This file was deleted.

Loading

0 comments on commit 2ee5604

Please sign in to comment.