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

feat: add metadata for IBC tokens #3104

Merged
merged 43 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b1359b2
add metadata after mint
0xmuralik Feb 2, 2023
4070c24
set base denom as ibc hash denom
0xmuralik Feb 2, 2023
d0c2b83
comment
0xmuralik Feb 2, 2023
d0662a4
remove unsed funcs from keeper
0xmuralik Feb 3, 2023
ef8310a
Merge branch 'main' into murali/ibc-denom
0xmuralik Feb 6, 2023
e460e35
genesis setmetadata
0xmuralik Feb 6, 2023
850ded9
set metadata in migration
0xmuralik Feb 10, 2023
9e7924a
Merge branch 'main' into murali/ibc-denom
0xmuralik Feb 10, 2023
e257dcb
Merge branch 'main' into murali/ibc-denom
0xmuralik Feb 14, 2023
21c81e5
new migration
0xmuralik Feb 16, 2023
dafd5f1
test new migration
0xmuralik Feb 16, 2023
7763f74
Merge branch 'main' into murali/ibc-denom
0xmuralik Feb 17, 2023
a2b159f
Update modules/apps/transfer/keeper/migrations.go
0xmuralik May 3, 2023
663a0fd
import seperation
0xmuralik May 3, 2023
737cba5
replace MetaData with Metadata
0xmuralik May 3, 2023
c30d23d
Merge branch 'main' of https://github.com/0xmuralik/ibc-go into mural…
0xmuralik May 3, 2023
d894142
Merge branch 'murali/ibc-denom' of https://github.com/0xmuralik/ibc-g…
0xmuralik May 3, 2023
1640753
Merge branch 'main' into murali/ibc-denom
Jun 3, 2023
9501c78
fix typo
Jun 5, 2023
de08338
add initial migration documentation
Jun 5, 2023
324986c
fixed tests
Jun 5, 2023
e4e24d2
add logging message
Jul 4, 2023
8001ff5
Merge branch 'main' into murali/ibc-denom
Jul 8, 2023
ff7e7ff
Merge branch 'main' into murali/ibc-denom
DimitrisJim Aug 28, 2023
dac13bb
Bump consensus version.
DimitrisJim Aug 28, 2023
d16383b
Nits:
DimitrisJim Aug 28, 2023
c29568a
Merge branch 'main' into murali/ibc-denom
Aug 29, 2023
17f23ae
Merge branch 'main' into murali/ibc-denom
DimitrisJim Aug 29, 2023
771dd3c
addressing some of the feedback
Aug 31, 2023
e94f138
add more test cases
Aug 31, 2023
2794a64
rename variables
Sep 4, 2023
b97b8ee
check metadata in onrecvpacket tests
Sep 4, 2023
bcfe839
fix: remove test assertion on errors, state will be reverted by basea…
colin-axner Sep 6, 2023
b8e0f63
Merge branch 'main' into murali/ibc-denom
Sep 6, 2023
7091998
address review comment
Sep 6, 2023
ab7c94f
lint, lint, lint
Sep 6, 2023
a433aad
Merge branch 'main' into murali/ibc-denom
Sep 7, 2023
ca1304b
Merge branch 'main' into murali/ibc-denom
colin-axner Sep 7, 2023
1c2626d
fix test
Sep 7, 2023
0e1c34e
Merge branch 'main' into murali/ibc-denom
Sep 10, 2023
b22484a
address review comments
Sep 11, 2023
ec3d294
Merge branch 'main' into murali/ibc-denom
Sep 11, 2023
aaa6786
Merge branch 'main' into murali/ibc-denom
Sep 11, 2023
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
23 changes: 23 additions & 0 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
Expand Down Expand Up @@ -282,6 +283,24 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
return err
}

if !k.bankKeeper.HasDenomMetaData(ctx, voucherDenom) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are running migrations such that all traces have metadata set, shouldn't we just make setting metadata a functionality of SetDenomTrace? This avoids accidental incidents where the trace is set but the metadata isn't. There should never be an instance when you want to set the denom trace without setting the metadata as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could do that, although SetDenomTrace is a setter function for a specific key in the store, so it would squeak to me a bit if we add SetDenomMetadata there as well. Maybe we could have a helper function that wraps both SetDenomTrace and SetDenomMetadata. Happy to hear other people's thoughts.

colin-axner marked this conversation as resolved.
Show resolved Hide resolved
metadata := banktypes.Metadata{
Description: getMetaDataDescription(denomTrace),
DenomUnits: []*banktypes.DenomUnit{
{
Denom: denomTrace.BaseDenom,
0xmuralik marked this conversation as resolved.
Show resolved Hide resolved
Exponent: 0,
},
},
// Setting base as IBChash Denom as SetDenomMetaData uses Base as storeKey
// and the bank keeper will only have the IBCHash to get the denom metadata
Base: voucherDenom,
Display: prefixedDenom,
0xmuralik marked this conversation as resolved.
Show resolved Hide resolved
}

k.bankKeeper.SetDenomMetaData(ctx, metadata)
}

// send to receiver
if err := k.bankKeeper.SendCoinsFromModuleToAccount(
ctx, types.ModuleName, receiver, sdk.NewCoins(voucher),
Expand Down Expand Up @@ -310,6 +329,10 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
return nil
}

func getMetaDataDescription(denomTrace types.DenomTrace) string {
return fmt.Sprintf("IBC Token from %s", denomTrace.Path)
0xmuralik marked this conversation as resolved.
Show resolved Hide resolved
}

// OnAcknowledgementPacket responds to the the success or failure of a packet
// acknowledgement written on the receiving chain. If the acknowledgement
// was a success then nothing occurs. If the acknowledgement failed, then
Expand Down
3 changes: 3 additions & 0 deletions modules/apps/transfer/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"

connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
Expand All @@ -25,6 +26,8 @@ type BankKeeper interface {
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
BlockedAddr(addr sdk.AccAddress) bool
IsSendEnabledCoin(ctx sdk.Context, coin sdk.Coin) bool
HasDenomMetaData(ctx sdk.Context, denom string) bool
SetDenomMetaData(ctx sdk.Context, denomMetaData banktypes.Metadata)
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
}

// ChannelKeeper defines the expected IBC channel keeper
Expand Down