Skip to content

Commit

Permalink
feat(sequencer): add fee denom to sequencer metadata (#1662)
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 authored Dec 17, 2024
1 parent d0166dd commit c955648
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 38 deletions.
1 change: 1 addition & 0 deletions app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ func ConvertOldSequencerToNew(old sequencertypes.Sequencer) sequencertypes.Seque
ExtraData: nil,
Snapshots: []*sequencertypes.SnapshotInfo{},
GasPrice: &defaultGasPrice,
FeeDenom: nil,
},
}
}
8 changes: 8 additions & 0 deletions proto/dymensionxyz/dymension/sequencer/metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ message SequencerMetadata {
repeated SnapshotInfo snapshots = 14;
// gas_price defines the value for each gas unit
string gas_price = 15 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"];
// fee_denom is the base denom for fees
DenomMetadata fee_denom = 16;
}

message ContactDetails {
Expand All @@ -52,3 +54,9 @@ message SnapshotInfo {
// sha-256 checksum value for the snapshot file
string checksum=3;
}

message DenomMetadata {
string display = 1;
string base = 2;
uint32 exponent = 3;
}
1 change: 1 addition & 0 deletions x/sequencer/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ var (
ErrInvalidAddr = gerrc.ErrInvalidArgument.Wrap("address")
ErrInvalidPubKey = gerrc.ErrInvalidArgument.Wrap("pubkey")
ErrUnknownRequest = gerrc.ErrInvalidArgument.Wrap("unknown request")
ErrInvalidFeeDenom = gerrc.ErrInvalidArgument.Wrap("invalid fee denom")
)
34 changes: 34 additions & 0 deletions x/sequencer/types/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

errorsmod "cosmossdk.io/errors"
"github.com/cockroachdb/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
)

Expand All @@ -19,6 +20,12 @@ const (
maxListLength = 5
)

type AllowedDecimals uint32

const (
Decimals18 AllowedDecimals = 18
)

func (d SequencerMetadata) Validate() error {
_, err := d.EnsureLength()
if err != nil {
Expand All @@ -33,13 +40,40 @@ func (d SequencerMetadata) Validate() error {
return errorsmod.Wrap(err, "invalid rest api URLs")
}

if d.FeeDenom != nil {
if err := d.FeeDenom.Validate(); err != nil {
return errors.Join(ErrInvalidFeeDenom, err)
}
}

if d.ContactDetails == nil {
return nil
}

return d.ContactDetails.Validate()
}

func (dm DenomMetadata) IsSet() bool {
return dm != DenomMetadata{}
}

func (dm DenomMetadata) Validate() error {
if err := sdk.ValidateDenom(dm.Base); err != nil {
return fmt.Errorf("invalid metadata base denom: %w", err)
}

if err := sdk.ValidateDenom(dm.Display); err != nil {
return fmt.Errorf("invalid metadata display denom: %w", err)
}

// validate exponent
if AllowedDecimals(dm.Exponent) != Decimals18 {
return fmt.Errorf("invalid exponent")
}

return nil
}

func (cd ContactDetails) Validate() error {
if cd.Website != "" {
if err := validateURL(cd.Website); err != nil {
Expand Down
Loading

0 comments on commit c955648

Please sign in to comment.