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

support client identifiers as channels in ics20 denom hops #7551

Merged
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
3 changes: 2 additions & 1 deletion modules/apps/transfer/types/denom.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
cmtbytes "github.com/cometbft/cometbft/libs/bytes"
cmttypes "github.com/cometbft/cometbft/types"

clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
)

Expand Down Expand Up @@ -167,7 +168,7 @@ func ExtractDenomFromPath(fullPath string) Denom {
// will be incorrectly parsed, but the token will continue to be treated correctly
// as an IBC denomination. The hash used to store the token internally on our chain
// will be the same value as the base denomination being correctly parsed.
if i < length-1 && length > 2 && channeltypes.IsValidChannelID(denomSplit[i+1]) {
if i < length-1 && length > 2 && (channeltypes.IsValidChannelID(denomSplit[i+1]) || clienttypes.IsValidClientID(denomSplit[i+1])) {
trace = append(trace, NewHop(denomSplit[i], denomSplit[i+1]))
} else {
baseDenomSlice = denomSplit[i:]
Expand Down
30 changes: 30 additions & 0 deletions modules/apps/transfer/types/denom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func (suite *TypesTestSuite) TestDenomsValidate() {
types.Denoms{},
nil,
},
{
"valid trace with client id",
types.Denoms{types.NewDenom("uatom", types.NewHop("transfer", "07-tendermint-0"))},
nil,
},
{
"valid multiple trace info",
types.Denoms{types.NewDenom("uatom", types.NewHop("transfer", "channel-1"), types.NewHop("transfer", "channel-2"))},
Expand Down Expand Up @@ -79,6 +84,16 @@ func (suite *TypesTestSuite) TestPath() {
types.NewDenom("uatom", types.NewHop("transfer", "channel-0")),
"transfer/channel-0/uatom",
},
{
"1 hop denom with client id",
types.NewDenom("uatom", types.NewHop("transfer", "07-tendermint-0")),
"transfer/07-tendermint-0/uatom",
},
{
"1 hop denom with client id and slashes",
types.NewDenom("gamm/pool/osmo", types.NewHop("transfer", "07-tendermint-0")),
"transfer/07-tendermint-0/gamm/pool/osmo",
},
{
"2 hop denom",
types.NewDenom("uatom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52")),
Expand Down Expand Up @@ -202,6 +217,13 @@ func (suite *TypesTestSuite) TestDenomChainSource() {
"channel-0",
false,
},
{
"sender chain is source: single trace with client id",
types.NewDenom("ubtc", types.NewHop("transfer", "07-tendermint-0")),
"transfer",
"channel-0",
false,
},
{
"sender chain is source: swapped portID and channelID",
types.NewDenom("uatom", types.NewHop("transfer", "channel-0")),
Expand All @@ -226,6 +248,13 @@ func (suite *TypesTestSuite) TestDenomChainSource() {
"channel-0",
true,
},
{
"receiver chain is source: single trace with client id",
types.NewDenom("ubtc", types.NewHop("transfer", "07-tendermint-0")),
"transfer",
"07-tendermint-0",
true,
},
{
"receiver chain is source: multi-trace",
types.NewDenom("uatom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-52")),
Expand Down Expand Up @@ -284,6 +313,7 @@ func TestExtractDenomFromPath(t *testing.T) {
{"base denom with trailing slash", "atom/", types.NewDenom("atom/")},
{"base denom multiple trailing slash", "foo///bar//baz/atom/", types.NewDenom("foo///bar//baz/atom/")},
{"ibc denom one hop", "transfer/channel-0/atom", types.NewDenom("atom", types.NewHop("transfer", "channel-0"))},
{"ibc denom one hop with client id", "transfer/07-tendermint-0/atom", types.NewDenom("atom", types.NewHop("transfer", "07-tendermint-0"))},
{"ibc denom one hop trailing slash", "transfer/channel-0/atom/", types.NewDenom("atom/", types.NewHop("transfer", "channel-0"))},
{"ibc denom one hop multiple slashes", "transfer/channel-0//at/om/", types.NewDenom("/at/om/", types.NewHop("transfer", "channel-0"))},
{"ibc denom two hops", "transfer/channel-0/transfer/channel-60/atom", types.NewDenom("atom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-60"))},
Expand Down
Loading