Skip to content

Commit

Permalink
fix(axelarnet): replace native asset with bond denom for dust amount (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs47 authored Jul 16, 2024
1 parent b99e0db commit d38e40a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ func initMessageRouter(keepers *KeeperCache) nexusTypes.MessageRouter {
axelarbankkeeper.NewBankKeeper(GetKeeper[bankkeeper.BaseKeeper](keepers)),
GetKeeper[nexusKeeper.Keeper](keepers),
GetKeeper[authkeeper.AccountKeeper](keepers),
GetKeeper[stakingkeeper.Keeper](keepers),
))

if IsWasmEnabled() {
Expand Down
7 changes: 4 additions & 3 deletions x/axelarnet/keeper/message_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/axelarnetwork/axelar-core/x/axelarnet/exported"
"github.com/axelarnetwork/axelar-core/x/axelarnet/types"
nexus "github.com/axelarnetwork/axelar-core/x/nexus/exported"
)
Expand All @@ -23,6 +22,7 @@ func NewMessageRoute(
bankK types.BankKeeper,
nexusK types.Nexus,
accountK types.AccountKeeper,
stakingK types.StakingKeeper,
) nexus.MessageRoute {
return func(ctx sdk.Context, routingCtx nexus.RoutingContext, msg nexus.GeneralMessage) error {
if routingCtx.Payload == nil {
Expand All @@ -34,7 +34,7 @@ func NewMessageRoute(
return sdkerrors.Wrap(err, "invalid payload")
}

asset, err := escrowAssetToMessageSender(ctx, keeper, feegrantK, bankK, nexusK, accountK, routingCtx, msg)
asset, err := escrowAssetToMessageSender(ctx, keeper, feegrantK, bankK, nexusK, accountK, stakingK, routingCtx, msg)
if err != nil {
return err
}
Expand All @@ -54,13 +54,14 @@ func escrowAssetToMessageSender(
bankK types.BankKeeper,
nexusK types.Nexus,
accountK types.AccountKeeper,
stakingK types.StakingKeeper,
routingCtx nexus.RoutingContext,
msg nexus.GeneralMessage,
) (sdk.Coin, error) {
switch msg.Type() {
case nexus.TypeGeneralMessage:
// pure general message, take dust amount from sender to satisfy ibc transfer requirements
asset := sdk.NewCoin(exported.NativeAsset, sdk.OneInt())
asset := sdk.NewCoin(stakingK.BondDenom(ctx), sdk.OneInt())
sender := routingCtx.Sender

if !routingCtx.FeeGranter.Empty() {
Expand Down
7 changes: 6 additions & 1 deletion x/axelarnet/keeper/message_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestNewMessageRoute(t *testing.T) {
bankK *mock.BankKeeperMock
nexusK *mock.NexusMock
accountK *mock.AccountKeeperMock
stakingK *mock.StakingKeeperMock
)

givenMessageRoute := Given("the message route", func() {
Expand All @@ -93,8 +94,12 @@ func TestNewMessageRoute(t *testing.T) {
bankK = &mock.BankKeeperMock{}
nexusK = &mock.NexusMock{}
accountK = &mock.AccountKeeperMock{}
stakingK = &mock.StakingKeeperMock{}
stakingK.BondDenomFunc = func(ctx sdk.Context) string {
return exported.NativeAsset
}

route = keeper.NewMessageRoute(k, ibcK, feegrantK, bankK, nexusK, accountK)
route = keeper.NewMessageRoute(k, ibcK, feegrantK, bankK, nexusK, accountK, stakingK)
})

givenMessageRoute.
Expand Down
7 changes: 6 additions & 1 deletion x/axelarnet/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
nexus "github.com/axelarnetwork/axelar-core/x/nexus/exported"
)

//go:generate moq -out ./mock/expected_keepers.go -pkg mock . BaseKeeper Nexus BankKeeper IBCTransferKeeper ChannelKeeper AccountKeeper PortKeeper GovKeeper FeegrantKeeper IBCKeeper
//go:generate moq -out ./mock/expected_keepers.go -pkg mock . BaseKeeper Nexus BankKeeper IBCTransferKeeper ChannelKeeper AccountKeeper PortKeeper GovKeeper StakingKeeper FeegrantKeeper IBCKeeper

// BaseKeeper is implemented by this module's base keeper
type BaseKeeper interface {
Expand Down Expand Up @@ -124,6 +124,11 @@ type GovKeeper interface {
GetProposal(ctx sdk.Context, proposalID uint64) (govtypes.Proposal, bool)
}

// StakingKeeper provides functionality to the staking module
type StakingKeeper interface {
BondDenom(ctx sdk.Context) string
}

// FeegrantKeeper defines the expected feegrant keeper.
type FeegrantKeeper interface {
UseGrantedFees(ctx sdk.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, msgs []sdk.Msg) error
Expand Down
66 changes: 66 additions & 0 deletions x/axelarnet/types/mock/expected_keepers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d38e40a

Please sign in to comment.