Skip to content

Commit

Permalink
feat(eibc): store json object as the group and policy metadata (#1153)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Dec 5, 2024
1 parent 2ff5e50 commit 2a99f2c
Show file tree
Hide file tree
Showing 12 changed files with 829 additions and 337 deletions.
2 changes: 0 additions & 2 deletions cmd/consts/dymension.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package consts

const DefaultIndexer = "http://44.206.211.230:3000/"

var MainnetHubData = HubData{
Environment: "mainnet",
ApiUrl: "https://dymension-mainnet-rest.public.blastapi.io",
Expand Down
6 changes: 6 additions & 0 deletions cmd/consts/eibc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package consts

const (
DefaultIndexer = "http://44.206.211.230:3000/"
DefaultEibcOperatorFeeShare = 0.1
)
69 changes: 69 additions & 0 deletions cmd/eibc/fulfill/feeshare/feeshare.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package feeshare

import (
"os"
"path/filepath"
"strconv"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/utils/config/yamlconfig"
eibcutils "github.com/dymensionxyz/roller/utils/eibc"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "fee-share [fee-share]",
Short: "Set",
Example: "roller eibc fulfill fee-share 0.1",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
home, err := os.UserHomeDir()
if err != nil {
pterm.Error.Println("failed to get user home dir", err)
return
}

if err != nil {
pterm.Error.Println("failed to expand home directory")
return
}

eibcHome := filepath.Join(home, consts.ConfigDirName.Eibc)
eibcConfigPath := filepath.Join(eibcHome, "config.yaml")

fee := args[0]
ff, err := strconv.ParseFloat(fee, 64)
if err != nil {
pterm.Error.Printf("fee must be a valid number, got %s\n", fee)
return
}

updates := map[string]interface{}{
"operator.min_fee_share": ff,
}
err = yamlconfig.UpdateNestedYAML(eibcConfigPath, updates)
if err != nil {
pterm.Error.Println("failed to update config", err)
return
}

var cfg eibcutils.Config
err = cfg.LoadConfig(eibcConfigPath)
if err != nil {
pterm.Error.Println("failed to load eibc config: ", err)
return
}

err = eibcutils.UpdateGroupOperatorMinFee(eibcConfigPath, ff, cfg, home)
if err != nil {
pterm.Error.Println("failed to update eibc operator metadata: ", err)
return
}
},
}

return cmd
}
2 changes: 2 additions & 0 deletions cmd/eibc/fulfill/fulfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fulfill
import (
"github.com/spf13/cobra"

"github.com/dymensionxyz/roller/cmd/eibc/fulfill/feeshare"
"github.com/dymensionxyz/roller/cmd/eibc/fulfill/order"
"github.com/dymensionxyz/roller/cmd/eibc/fulfill/rollapps"
)
Expand All @@ -14,6 +15,7 @@ func Cmd() *cobra.Command {
}

cmd.AddCommand(order.Cmd())
cmd.AddCommand(feeshare.Cmd())
cmd.AddCommand(rollapps.Cmd())

return cmd
Expand Down
16 changes: 16 additions & 0 deletions cmd/eibc/fulfill/rollapps/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/utils/eibc"
eibcutils "github.com/dymensionxyz/roller/utils/eibc"
"github.com/dymensionxyz/roller/utils/filesystem"
)

Expand Down Expand Up @@ -54,6 +55,7 @@ func Cmd() *cobra.Command {
return
}

lspn, _ := pterm.DefaultSpinner.Start("removing rollapp to eibc config")
config.RemoveChain(rollAppID)
updatedData, err := yaml.Marshal(&config)
if err != nil {
Expand All @@ -66,6 +68,20 @@ func Cmd() *cobra.Command {
pterm.Error.Printf("Error reading file: %v\n", err)
return
}
lspn.Success("rollapp removed from eibc config")

var cfg eibcutils.Config
err = cfg.LoadConfig(eibcConfigPath)
if err != nil {
pterm.Error.Println("failed to load eibc config: ", err)
return
}

err = eibcutils.UpdateGroupSupportedRollapps(eibcConfigPath, cfg, home)
if err != nil {
pterm.Error.Println("failed to update eibc operator metadata: ", err)
return
}
},
}

Expand Down
19 changes: 18 additions & 1 deletion cmd/eibc/fulfill/rollapps/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/utils/eibc"
eibcutils "github.com/dymensionxyz/roller/utils/eibc"
"github.com/dymensionxyz/roller/utils/filesystem"
)

Expand All @@ -34,6 +35,7 @@ instance.
}

eibcHome := filepath.Join(home, consts.ConfigDirName.Eibc)
eibcConfigPath := filepath.Join(eibcHome, "config.yaml")
isEibcClientInitialized, err := filesystem.DirNotEmpty(eibcHome)
if err != nil {
pterm.Error.Println("failed to check eibc client initialized", err)
Expand All @@ -54,10 +56,25 @@ instance.

fNodes := strings.Split(fullNodes, ",")

err = eibc.AddRollappToEibc(rollAppID, eibcHome, fNodes)
lspn, _ := pterm.DefaultSpinner.Start("adding rollapp to eibc config")
err = eibc.AddRollappToEibcConfig(rollAppID, eibcHome, fNodes)
if err != nil {
return
}
lspn.Success("rollapp added to eibc config")

var cfg eibcutils.Config
err = cfg.LoadConfig(eibcConfigPath)
if err != nil {
pterm.Error.Println("failed to load eibc config: ", err)
return
}

err = eibcutils.UpdateGroupSupportedRollapps(eibcConfigPath, cfg, home)
if err != nil {
pterm.Error.Println("failed to update eibc operator metadata: ", err)
return
}
},
}

Expand Down
Loading

0 comments on commit 2a99f2c

Please sign in to comment.