Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent mapping multiple denoms to same ERC20 #1346

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions x/skyway/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,15 @@ func (k *msgServer) SetERC20ToTokenDenom(ctx context.Context, msg *types.MsgSetE
return nil, sdkerrors.Wrap(types.ErrUnauthorized, "missing token admin permission")
}

d, err := k.GetDenomOfERC20(ctx, ci.ChainReferenceID, *erc20)
if err != nil && err != types.ErrDenomNotFound {
return nil, sdkerrors.Wrap(types.ErrInternal, "duplicate binding lookup failed")
}

if len(d) > 0 {
return nil, sdkerrors.Wrap(types.ErrDuplicateBinding, "token already bridged")
}

if err := k.setDenomToERC20(ctx, ci.ChainReferenceID, msg.Denom, *erc20); err != nil {
return nil, sdkerrors.Wrap(types.ErrInternal, err.Error())
}
Expand Down
1 change: 1 addition & 0 deletions x/skyway/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ var (
ErrDenomNotFound = sdkerrors.Register(ModuleName, 21, "denom not found")
ErrERC20NotFound = sdkerrors.Register(ModuleName, 22, "erc20 not found")
ErrUnauthorized = sdkerrors.Register(ModuleName, 23, "unauthorized")
ErrDuplicateBinding = sdkerrors.Register(ModuleName, 24, "erc20 already bound to denom")
)