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(denommetadata): correct base denom format #1220

Merged
Merged
Changes from 2 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
20 changes: 18 additions & 2 deletions x/denommetadata/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,20 @@ func (m *ICS4Wrapper) SendPacket(
// At the first match, we assume that the rollapp already contains the metadata.
// It would be technically possible to have a race condition where the denom metadata is added to the rollapp
// from another packet before this packet is acknowledged.
if Contains(rollapp.RegisteredDenoms, packet.Denom) {
// The value of `packet.Denom` here can be one of two things:
// 1. Base denom (e.g. "adym") for the native token of the hub, and
// 2. IBC trace (e.g. "transfer/channel-1/arax") for a third party token.
// We need to handle both cases:
// 1. We use the value of `packet.Denom` as the baseDenom
// 2. We parse the IBC denom trace into IBC denom hash and prepend it with "ibc/" to get the baseDenom
baseDenom := getBaseDenomFromTrace(packet.Denom)
zale144 marked this conversation as resolved.
Show resolved Hide resolved

if Contains(rollapp.RegisteredDenoms, baseDenom) {
return m.ICS4Wrapper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data)
}

// get the denom metadata from the bank keeper, if it doesn't exist, move on to the next middleware in the chain
denomMetadata, ok := m.bankKeeper.GetDenomMetaData(ctx, packet.Denom)
denomMetadata, ok := m.bankKeeper.GetDenomMetaData(ctx, baseDenom)
if !ok {
return m.ICS4Wrapper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data)
}
Expand All @@ -239,3 +247,11 @@ func (m *ICS4Wrapper) SendPacket(

return m.ICS4Wrapper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data)
}

func getBaseDenomFromTrace(denomTrace string) string {
denomTraceObj := transfertypes.ParseDenomTrace(denomTrace)
if denomTraceObj.Path == "" {
return denomTraceObj.BaseDenom
}
return "ibc/" + denomTraceObj.Hash().String()
}
Loading