From 212046f2b83e8109a95a49fd7bcf1ba5880d69b9 Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:31:40 +0800 Subject: [PATCH] fix: crosschain with origin token (#884) Co-authored-by: nulnut <151493716+nulnut@users.noreply.github.com> --- x/crosschain/keeper/bridge_token.go | 2 +- x/crosschain/keeper/many_to_one.go | 4 +++- x/erc20/keeper/bridge_token.go | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/x/crosschain/keeper/bridge_token.go b/x/crosschain/keeper/bridge_token.go index 00be5168..aeee9a56 100644 --- a/x/crosschain/keeper/bridge_token.go +++ b/x/crosschain/keeper/bridge_token.go @@ -20,7 +20,7 @@ func (k Keeper) AddBridgeTokenExecuted(ctx sdk.Context, claim *types.MsgBridgeTo 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) + return k.erc20Keeper.AddBridgeToken(ctx, claim.Symbol, k.moduleName, claim.TokenContract, false) } return k.erc20Keeper.AddBridgeToken(ctx, strings.ToLower(claim.Symbol), k.moduleName, claim.TokenContract, false) diff --git a/x/crosschain/keeper/many_to_one.go b/x/crosschain/keeper/many_to_one.go index 108007ed..c432b419 100644 --- a/x/crosschain/keeper/many_to_one.go +++ b/x/crosschain/keeper/many_to_one.go @@ -40,7 +40,9 @@ func (k Keeper) BaseCoinToBridgeToken(ctx context.Context, holder sdk.AccAddress if err != nil { return bridgeToken, err } - + if bridgeToken.IsOrigin() { + return bridgeToken, nil + } baseCoins := sdk.NewCoins(baseCoin) if err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, holder, types.ModuleName, baseCoins); err != nil { return bridgeToken, err diff --git a/x/erc20/keeper/bridge_token.go b/x/erc20/keeper/bridge_token.go index cdd1ccc0..d07474aa 100644 --- a/x/erc20/keeper/bridge_token.go +++ b/x/erc20/keeper/bridge_token.go @@ -8,12 +8,12 @@ import ( "github.com/pundiai/fx-core/v8/x/erc20/types" ) -func (k Keeper) HasToken(ctx context.Context, denom string) (bool, error) { - return k.DenomIndex.Has(ctx, denom) +func (k Keeper) HasToken(ctx context.Context, index string) (bool, error) { + return k.DenomIndex.Has(ctx, index) } -func (k Keeper) GetBaseDenom(ctx context.Context, token string) (string, error) { - return k.DenomIndex.Get(ctx, token) +func (k Keeper) GetBaseDenom(ctx context.Context, index string) (string, error) { + return k.DenomIndex.Get(ctx, index) } func (k Keeper) GetBridgeToken(ctx context.Context, chainName, baseDenom string) (types.BridgeToken, error) { @@ -58,5 +58,5 @@ func (k Keeper) AddBridgeToken(ctx context.Context, baseDenom, chainName, contra if err = k.BridgeToken.Set(ctx, key, bridgeToken); err != nil { return err } - return k.DenomIndex.Set(ctx, bridgeToken.BridgeDenom(), baseDenom) + return k.DenomIndex.Set(ctx, types.NewBridgeDenom(chainName, contract), baseDenom) }