Skip to content

Commit

Permalink
register denom metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Feb 26, 2024
1 parent 5b46763 commit 07d2088
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 70 deletions.
5 changes: 4 additions & 1 deletion proto/opinit/opchild/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ message MsgFinalizeTokenDeposit {
// height is the height of l1 which is including the deposit message
uint64 height = 6;

// base_denom is the l1 denomination of the sent coin.
string base_denom = 7;

/// data is a extra bytes for hooks.
bytes data = 7 [(gogoproto.nullable) = true, (amino.dont_omitempty) = true];
bytes data = 8 [(gogoproto.nullable) = true, (amino.dont_omitempty) = true];
}

// MsgFinalizeTokenDepositResponse returns deposit result data
Expand Down
20 changes: 20 additions & 0 deletions x/opchild/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
cosmostypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/initia-labs/OPinit/x/opchild/types"
Expand Down Expand Up @@ -113,3 +114,22 @@ func (k Keeper) Logger(ctx context.Context) log.Logger {
func (keeper Keeper) Router() *baseapp.MsgServiceRouter {
return keeper.router
}

// setDenomMetadata sets an OPinit token's denomination metadata
func (k Keeper) setDenomMetadata(ctx context.Context, baseDenom, denom string) {
metadata := banktypes.Metadata{
Base: denom,
Display: baseDenom,
Symbol: baseDenom,
Name: fmt.Sprintf("%s OPinit token", baseDenom),
Description: fmt.Sprintf("OPinit token of %s", baseDenom),
DenomUnits: []*banktypes.DenomUnit{
{
Denom: baseDenom,
Exponent: 0,
},
},
}

k.bankKeeper.SetDenomMetaData(ctx, metadata)
}
5 changes: 5 additions & 0 deletions x/opchild/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ func (ms MsgServer) FinalizeTokenDeposit(ctx context.Context, req *types.MsgFina
return nil, err
}

// register denom metadata
if ok := ms.bankKeeper.HasDenomMetaData(ctx, coin.Denom); !ok {
ms.setDenomMetadata(ctx, req.BaseDenom, coin.Denom)
}

event := sdk.NewEvent(
types.EventTypeFinalizeTokenDeposit,
sdk.NewAttribute(types.AttributeKeyL1Sequence, strconv.FormatUint(req.Sequence, 10)),
Expand Down
4 changes: 4 additions & 0 deletions x/opchild/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"cosmossdk.io/core/address"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)

// AccountKeeper defines the expected account keeper (noalias)
Expand Down Expand Up @@ -41,6 +42,9 @@ type BankKeeper interface {

MintCoins(ctx context.Context, moduleName string, amounts sdk.Coins) error
BurnCoins(ctx context.Context, moduleName string, amounts sdk.Coins) error

HasDenomMetaData(ctx context.Context, denom string) bool
SetDenomMetaData(ctx context.Context, denomMetaData banktypes.Metadata)
}

// ValidatorSet expected properties for the set of all validators (noalias)
Expand Down
4 changes: 4 additions & 0 deletions x/opchild/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ func (msg MsgFinalizeTokenDeposit) Validate(ac address.Codec) error {
return ErrInvalidAmount
}

if err := sdk.ValidateDenom(msg.BaseDenom); err != nil {
return err
}

if msg.Sequence == 0 {
return ErrInvalidSequence
}
Expand Down
178 changes: 112 additions & 66 deletions x/opchild/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions x/ophost/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ func (ms MsgServer) CreateBridge(ctx context.Context, req *types.MsgCreateBridge
sdk.NewAttribute(types.AttributeKeyBridgeId, strconv.FormatUint(bridgeId, 10)),
))

// TODO in initia app
// permit to create bridge only when the ibc channel has
// GetNextL1SequenceSend == 1
if err := ms.bridgeHook.BridgeCreated(ctx, bridgeId, req.Config); err != nil {
return nil, err
}
Expand Down

0 comments on commit 07d2088

Please sign in to comment.