diff --git a/x/crosschain/keeper/bridge_token.go b/x/crosschain/keeper/bridge_token.go index 6cf0636e..00be5168 100644 --- a/x/crosschain/keeper/bridge_token.go +++ b/x/crosschain/keeper/bridge_token.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "strings" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" @@ -14,28 +15,15 @@ import ( func (k Keeper) AddBridgeTokenExecuted(ctx sdk.Context, claim *types.MsgBridgeTokenClaim) error { k.Logger(ctx).Info("add bridge token claim", "symbol", claim.Symbol, "token", claim.TokenContract) - // Check if it already exists - bridgeDenom := types.NewBridgeDenom(k.moduleName, claim.TokenContract) - has, err := k.erc20Keeper.HasToken(ctx, bridgeDenom) - if err != nil { - return err - } - if has { - return types.ErrInvalid.Wrapf("bridge token is exist %s", bridgeDenom) + if claim.Symbol == fxtypes.DefaultDenom { + if uint64(fxtypes.DenomUnit) != claim.Decimals { + return types.ErrInvalid.Wrapf("%s denom decimals not match %d, expect %d", + fxtypes.DefaultDenom, claim.Decimals, fxtypes.DenomUnit) + } + return k.erc20Keeper.AddBridgeToken(ctx, claim.Symbol, k.moduleName, claim.TokenContract, true) } - if claim.Symbol == fxtypes.DefaultDenom && uint64(fxtypes.DenomUnit) != claim.Decimals { - return types.ErrInvalid.Wrapf("%s denom decimals not match %d, expect %d", - fxtypes.DefaultDenom, claim.Decimals, fxtypes.DenomUnit) - } - bridgeToken, err := k.erc20Keeper.GetBridgeToken(ctx, k.moduleName, claim.Symbol) - if err != nil { - return err - } - if bridgeToken.Contract != claim.TokenContract { - return types.ErrInvalid.Wrapf("bridge token contract not match %s, expect %s", bridgeToken.Contract, claim.TokenContract) - } - return nil + return k.erc20Keeper.AddBridgeToken(ctx, strings.ToLower(claim.Symbol), k.moduleName, claim.TokenContract, false) } func (k Keeper) BridgeCoinSupply(ctx context.Context, token, target string) (sdk.Coin, error) { diff --git a/x/crosschain/mock/expected_keepers_mocks.go b/x/crosschain/mock/expected_keepers_mocks.go index 29290219..370c6a53 100644 --- a/x/crosschain/mock/expected_keepers_mocks.go +++ b/x/crosschain/mock/expected_keepers_mocks.go @@ -345,6 +345,20 @@ func (m *MockErc20Keeper) EXPECT() *MockErc20KeeperMockRecorder { return m.recorder } +// AddBridgeToken mocks base method. +func (m *MockErc20Keeper) AddBridgeToken(ctx context.Context, baseDenom, chainName, contract string, isNative bool) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddBridgeToken", ctx, baseDenom, chainName, contract, isNative) + ret0, _ := ret[0].(error) + return ret0 +} + +// AddBridgeToken indicates an expected call of AddBridgeToken. +func (mr *MockErc20KeeperMockRecorder) AddBridgeToken(ctx, baseDenom, chainName, contract, isNative any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddBridgeToken", reflect.TypeOf((*MockErc20Keeper)(nil).AddBridgeToken), ctx, baseDenom, chainName, contract, isNative) +} + // BaseCoinToEvm mocks base method. func (m *MockErc20Keeper) BaseCoinToEvm(ctx context.Context, holder common.Address, coin types.Coin) (string, error) { m.ctrl.T.Helper() @@ -479,21 +493,6 @@ func (mr *MockErc20KeeperMockRecorder) HasCache(ctx, key any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasCache", reflect.TypeOf((*MockErc20Keeper)(nil).HasCache), ctx, key) } -// HasToken mocks base method. -func (m *MockErc20Keeper) HasToken(ctx context.Context, token string) (bool, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "HasToken", ctx, token) - ret0, _ := ret[0].(bool) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// HasToken indicates an expected call of HasToken. -func (mr *MockErc20KeeperMockRecorder) HasToken(ctx, token any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasToken", reflect.TypeOf((*MockErc20Keeper)(nil).HasToken), ctx, token) -} - // ReSetCache mocks base method. func (m *MockErc20Keeper) ReSetCache(ctx context.Context, oldKey, newKey string) error { m.ctrl.T.Helper() diff --git a/x/crosschain/types/expected_keepers.go b/x/crosschain/types/expected_keepers.go index 357fff22..b8509435 100644 --- a/x/crosschain/types/expected_keepers.go +++ b/x/crosschain/types/expected_keepers.go @@ -53,13 +53,13 @@ type Erc20Keeper interface { GetCache(ctx context.Context, key string) (sdkmath.Int, error) ReSetCache(ctx context.Context, oldKey, newKey string) error - HasToken(ctx context.Context, token string) (bool, error) GetBaseDenom(ctx context.Context, token string) (string, error) GetERC20Token(ctx context.Context, baseDenom string) (erc20types.ERC20Token, error) GetBridgeToken(ctx context.Context, chainName, baseDenom string) (erc20types.BridgeToken, error) GetBridgeTokens(ctx context.Context, chainName string) ([]erc20types.BridgeToken, error) + AddBridgeToken(ctx context.Context, baseDenom, chainName, contract string, isNative bool) error GetIBCToken(ctx context.Context, channel, baseDenom string) (erc20types.IBCToken, error) }