Skip to content

Commit

Permalink
feat: support token-less rollapps (#1196)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Dec 18, 2024
1 parent 03be144 commit fc453fe
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 74 deletions.
14 changes: 8 additions & 6 deletions cmd/config/init/rollapp.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package initconfig

import (
"errors"
"os/exec"
"path/filepath"
"strings"

"github.com/pterm/pterm"

Expand Down Expand Up @@ -64,12 +64,14 @@ func InitializeRollappConfig(
return err
}

if len(as.Bank.Supply) == 0 {
return errors.New("token supply is not defined in the genesis file")
}
rollappBaseDenom := as.Staking.Params.BondDenom
var rollappDenom string

rollappBaseDenom := as.Bank.Supply[0].Denom
rollappDenom := rollappBaseDenom[1:]
if strings.HasPrefix(as.Staking.Params.BondDenom, "ibc/") {
rollappDenom = as.Staking.Params.BondDenom
} else {
rollappDenom = rollappBaseDenom[1:]
}

initConfig.BaseDenom = rollappBaseDenom
initConfig.Denom = rollappDenom
Expand Down
83 changes: 73 additions & 10 deletions cmd/rollapp/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"strconv"
"strings"
"time"

cosmossdkmath "cosmossdk.io/math"
cosmossdktypes "github.com/cosmos/cosmos-sdk/types"
github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types"
dymensionseqtypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
Expand All @@ -30,6 +30,7 @@ import (
"github.com/dymensionxyz/roller/utils/config/tomlconfig"
"github.com/dymensionxyz/roller/utils/errorhandling"
"github.com/dymensionxyz/roller/utils/filesystem"
"github.com/dymensionxyz/roller/utils/genesis"
"github.com/dymensionxyz/roller/utils/keys"
"github.com/dymensionxyz/roller/utils/rollapp"
"github.com/dymensionxyz/roller/utils/roller"
Expand Down Expand Up @@ -768,6 +769,41 @@ RollApp's IRO time: %v`,
return cmd
}

func SupportedGasDenoms(
raCfg roller.RollappConfig,
) (map[string]dymensionseqtypes.DenomMetadata, error) {
raResponse, err := rollapp.GetMetadataFromChain(
raCfg.RollappID,
raCfg.HubData,
)
if err != nil {
pterm.Error.Println("failed to retrieve rollapp information from hub: ", err)
return nil, err
}
sd := map[string]dymensionseqtypes.DenomMetadata{
"ibc/FECACB927EB3102CCCB240FFB3B6FCCEEB8D944C6FEA8DFF079650FEFF59781D": {
Display: "dym",
Base: "ibc/FECACB927EB3102CCCB240FFB3B6FCCEEB8D944C6FEA8DFF079650FEFF59781D",
Exponent: 18,
},
"ibc/B3504E092456BA618CC28AC671A71FB08C6CA0FD0BE7C8A5B5A3E2DD933CC9E4": {
Display: "usdc",
Base: "ibc/B3504E092456BA618CC28AC671A71FB08C6CA0FD0BE7C8A5B5A3E2DD933CC9E4",
Exponent: 6,
},
}

if raResponse.Rollapp.GenesisInfo.NativeDenom != nil {
sd[raResponse.Rollapp.GenesisInfo.NativeDenom.Base] = dymensionseqtypes.DenomMetadata{
Display: raResponse.Rollapp.GenesisInfo.NativeDenom.Display,
Base: raResponse.Rollapp.GenesisInfo.NativeDenom.Base,
Exponent: raResponse.Rollapp.GenesisInfo.NativeDenom.Exponent,
}
}

return sd, nil
}

func populateSequencerMetadata(raCfg roller.RollappConfig) error {
cd := dymensionseqtypes.ContactDetails{
Website: "",
Expand All @@ -778,18 +814,44 @@ func populateSequencerMetadata(raCfg roller.RollappConfig) error {
var defaultGasPrice cosmossdkmath.Int
var ok bool

if raCfg.HubData.GasPrice != "" {
defaultGasPrice, ok = github_com_cosmos_cosmos_sdk_types.NewIntFromString(
raCfg.HubData.GasPrice,
)
as, err := genesis.GetAppStateFromGenesisFile(raCfg.Home)
if err != nil {
return err
}

if len(as.RollappParams.Params.MinGasPrices) == 0 {
return errors.New("rollappparams should contain at least one gas token")
}

var denom string
if len(as.RollappParams.Params.MinGasPrices) == 1 {
defaultGasPrice = as.RollappParams.Params.MinGasPrices[0].Amount.TruncateInt()
denom = as.RollappParams.Params.MinGasPrices[0].Denom
} else {
defaultGasPrice = cosmossdktypes.NewInt(2000000000)
ok = true
pterm.Info.Println("more then 1 gas token option found")
var options []string
for _, token := range as.RollappParams.Params.MinGasPrices {
options = append(options, token.Denom)
}

denom, _ := pterm.DefaultInteractiveSelect.WithOptions(options).WithDefaultText("select the token to use for the gas denom").Show()
selectedIndex := slices.IndexFunc(as.RollappParams.Params.MinGasPrices, func(t cosmossdktypes.DecCoin) bool {
return t.Denom == denom
})
defaultGasPrice = as.RollappParams.Params.MinGasPrices[selectedIndex].Amount.TruncateInt()
}
if !ok {
return errors.New("failed to parse gas price")

sgt, err := SupportedGasDenoms(raCfg)
if err != nil {
return err
}

if _, ok = sgt[denom]; !ok {
return errors.New("unsupported gas denom")
}

fd := sgt[denom]

var defaultSnapshots []*dymensionseqtypes.SnapshotInfo
sm := dymensionseqtypes.SequencerMetadata{
Moniker: "",
Expand All @@ -804,6 +866,7 @@ func populateSequencerMetadata(raCfg roller.RollappConfig) error {
ExtraData: []byte{},
Snapshots: defaultSnapshots,
GasPrice: &defaultGasPrice,
FeeDenom: &fd,
}

path := filepath.Join(
Expand Down Expand Up @@ -910,7 +973,7 @@ func populateSequencerMetadata(raCfg roller.RollappConfig) error {
sm.Moniker = displayName
}

err := WriteStructToJSONFile(&sm, path)
err = WriteStructToJSONFile(&sm, path)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/cosmos/go-bip39 v1.0.0
github.com/docker/docker v27.0.3+incompatible
github.com/docker/go-connections v0.5.0
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20241203120245-89d3abd36078
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20241217181721-d437db3e83fe
github.com/gogo/protobuf v1.3.3
github.com/ignite/cli v0.27.2
github.com/lib/pq v1.10.9
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20241130123033-f4b2029af117 h
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20241130123033-f4b2029af117/go.mod h1:0fjf73QSddz/55i6TNx47WebJHWQJoGC4kQzRN+RUD0=
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20241203120245-89d3abd36078 h1:obpxLKy5++CypmNW4+ROUCLboSI/FIlP+GUFeaqoYiM=
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20241203120245-89d3abd36078/go.mod h1:kBpPNqUu9QvfGZwK6RmeYyjmbgISvlS+tcX4YC7nem0=
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20241217181721-d437db3e83fe h1:cciSOsvR+WUfI8TPSsEn4Pp0cC4UE2MESZoOjNT/OZk=
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20241217181721-d437db3e83fe/go.mod h1:eLXc2vJfU8iltWK/8tpU5jhopZA5RDgryzL9PFgYbLs=
github.com/dymensionxyz/gerr-cosmos v1.1.0 h1:IW/P7HCB/iP9kgk3VXaWUoMoyx3vD76YO6p1fnubHVc=
github.com/dymensionxyz/gerr-cosmos v1.1.0/go.mod h1:n+0olxPogzWqFKba45mCpvrHLGmeS8W9UZjggHnWk6c=
github.com/dymensionxyz/osmosis/v15 v15.2.0-dymension-v1.1.2 h1:HvBvVm2SdhKn9RYEiW8IbrvoDL3SbQhYVFo+aj4ELUw=
Expand Down
26 changes: 0 additions & 26 deletions relayer/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
cosmossdkmath "cosmossdk.io/math"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/sequencer"
"github.com/dymensionxyz/roller/utils/keys"
"github.com/dymensionxyz/roller/utils/roller"
)
Expand Down Expand Up @@ -103,28 +102,3 @@ func getHubRlyAccData(home string, hd consts.HubData) (*keys.AccountData, error)
Balance: *HubRlyBalance,
}, nil
}

// nolint: unused
func getRolRlyAccData(home string, raData roller.RollappConfig) (*keys.AccountData, error) {
RollappRlyAddr, err := keys.GetRelayerAddress(home, raData.RollappID)
seq := sequencer.GetInstance(raData)
if err != nil {
return nil, err
}

RollappRlyBalance, err := keys.QueryBalance(
keys.ChainQueryConfig{
RPC: seq.GetRPCEndpoint(),
Denom: raData.Denom,
Binary: consts.Executables.RollappEVM,
}, RollappRlyAddr,
)
if err != nil {
return nil, err
}

return &keys.AccountData{
Address: RollappRlyAddr,
Balance: *RollappRlyBalance,
}, nil
}
23 changes: 0 additions & 23 deletions sequencer/commands.go

This file was deleted.

17 changes: 11 additions & 6 deletions sequencer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"strings"

cosmossdktypes "github.com/cosmos/cosmos-sdk/types"
toml "github.com/pelletier/go-toml"
"github.com/pterm/pterm"

Expand Down Expand Up @@ -108,18 +109,22 @@ func SetAppConfig(rlpCfg roller.RollappConfig) error {
}

var minimumGasPrice string
if as.FeeMarket != nil && as.FeeMarket.Params != nil && as.FeeMarket.Params.MinGasPrice != "" {
pterm.Info.Println("applying feemarket gas price")
minimumGasPrice = as.FeeMarket.Params.MinGasPrice
} else if len(as.RollappParams.Params.MinGasPrices) > 0 {
if len(as.RollappParams.Params.MinGasPrices) > 0 {
pterm.Info.Println("applying rollappparam gas price")
minimumGasPrice = as.RollappParams.Params.MinGasPrices[0].Amount.String()

minGasPricesStrs := make([]string, len(as.RollappParams.Params.MinGasPrices))
for i, minGasPrice := range as.RollappParams.Params.MinGasPrices {
tkn := cosmossdktypes.NewCoin(minGasPrice.Denom, minGasPrice.Amount.TruncateInt())
minGasPricesStrs[i] = tkn.String()
}
minimumGasPrice = strings.Join(minGasPricesStrs, ",")
appCfg.Set("minimum-gas-prices", minimumGasPrice)
} else {
pterm.Info.Println("applying default gas price")
minimumGasPrice = consts.DefaultMinGasPrice
appCfg.Set("minimum-gas-prices", fmt.Sprintf("%s%s", minimumGasPrice, rlpCfg.BaseDenom))
}

appCfg.Set("minimum-gas-prices", fmt.Sprintf("%s%s", minimumGasPrice, rlpCfg.BaseDenom))
appCfg.Set("gas-adjustment", 1.3)
appCfg.Set("api.enable", true)
appCfg.Set("api.enabled-unsafe-cors", true)
Expand Down
2 changes: 1 addition & 1 deletion utils/dependencies/dymd.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func DefaultDymdDependency() types.Dependency {
RepositoryOwner: "dymensionxyz",
RepositoryName: "dymension",
RepositoryUrl: "https://github.com/artemijspavlovs/dymension",
Release: "v3.1.0-mig11",
Release: "v3.1.0-mig23",
Binaries: []types.BinaryPathPair{
{
Binary: "dymd",
Expand Down
14 changes: 14 additions & 0 deletions utils/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ type AppState struct {
Bank Bank `json:"bank"`
RollappParams RollappParams `json:"rollappparams"`
FeeMarket *FeeMarket `json:"feemarket"`
Staking *Staking `json:"staking"`
}

type Staking struct {
Params *StakingParams `json:"params"`
}

type StakingParams struct {
BondDenom string `json:"bond_denom"`
HistoricalEntries uint64 `json:"historical_entries"`
MaxEntries uint32 `json:"max_entries"`
MaxValidators uint32 `json:"max_validators"`
MinCommissionRate string `json:"min_commission_rate"`
UnbondingTime string `json:"unbonding_time"`
}

type FeeMarket struct {
Expand Down
9 changes: 8 additions & 1 deletion utils/sequencer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Info struct {
// WhitelistedRelayers is an array of the whitelisted relayer addresses. Addresses are bech32-encoded strings.
WhitelistedRelayers []string `protobuf:"bytes,13,rep,name=whitelisted_relayers,json=whitelistedRelayers,proto3" json:"whitelisted_relayers,omitempty"`
// opted in defines whether the sequencer can be selected as proposer
OptedIn bool `protobuf:"varint,14,opt,name=opted_in,proto3" json:"opted_in,omitempty"`
OptedIn bool `protobuf:"varint,14,opt,name=opted_in,proto3" json:"opted_in,omitempty"`
}

type Metadata struct {
Expand Down Expand Up @@ -70,6 +70,13 @@ type Metadata struct {
// gas_price defines the value for each gas unit
// nolint:govet,staticcheck
GasPrice *cosmossdkmath.Int `json:"gas_price"`
FeeDenom DenomMetadata `json:"fee_denom"`
}

type DenomMetadata struct {
Display string `json:"display"`
Base string `json:"base"`
Exponent int `json:"exponent"`
}

type ContactDetails struct {
Expand Down

0 comments on commit fc453fe

Please sign in to comment.