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: wrap eibc version with min fee percentage support #874

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 25 additions & 3 deletions cmd/eibc/eibc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
package eibc

import (
"github.com/dymensionxyz/roller/cmd/eibc/fulfill"
"github.com/dymensionxyz/roller/cmd/eibc/funds"
eibcinit "github.com/dymensionxyz/roller/cmd/eibc/init"
"github.com/dymensionxyz/roller/cmd/eibc/scale"
"github.com/dymensionxyz/roller/cmd/eibc/start"
"github.com/dymensionxyz/roller/cmd/services"
loadservices "github.com/dymensionxyz/roller/cmd/services/load"
restartservices "github.com/dymensionxyz/roller/cmd/services/restart"
startservices "github.com/dymensionxyz/roller/cmd/services/start"
stopservices "github.com/dymensionxyz/roller/cmd/services/stop"
"github.com/spf13/cobra"
)

Expand All @@ -10,9 +20,21 @@ func Cmd() *cobra.Command {
Short: "Commands for running and managing eibc client",
}

cmd.AddCommand(initCmd())
cmd.AddCommand(startCmd())
cmd.AddCommand(scaleCmd())
cmd.AddCommand(eibcinit.Cmd())
cmd.AddCommand(start.Cmd())
cmd.AddCommand(scale.Cmd())
cmd.AddCommand(funds.Cmd())
cmd.AddCommand(fulfill.Cmd())

sl := []string{"eibc"}
cmd.AddCommand(
services.Cmd(
loadservices.Cmd(sl, cmd.Use),
startservices.EibcCmd(),
restartservices.Cmd(sl),
stopservices.Cmd(sl),
),
)

return cmd
}
22 changes: 22 additions & 0 deletions cmd/eibc/fulfill/denoms/denoms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package denoms

import (
"github.com/dymensionxyz/roller/cmd/eibc/fulfill/denoms/list"
"github.com/dymensionxyz/roller/cmd/eibc/fulfill/denoms/remove"
"github.com/dymensionxyz/roller/cmd/eibc/fulfill/denoms/set"
"github.com/spf13/cobra"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "denoms",
Short: "Commands to manage the whitelist of Denoms to fulfill eibc orders for",
Args: cobra.MaximumNArgs(1),
}

cmd.AddCommand(list.Cmd())
cmd.AddCommand(remove.Cmd())
cmd.AddCommand(set.Cmd())

return cmd
}
61 changes: 61 additions & 0 deletions cmd/eibc/fulfill/denoms/list/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package list

import (
"fmt"
"os"
"path/filepath"

"github.com/dymensionxyz/roller/cmd/consts"
globalutils "github.com/dymensionxyz/roller/utils"
eibcutils "github.com/dymensionxyz/roller/utils/eibc"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "Commands to manage the whitelist of RollApps to fulfill eibc orders for",
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
}

eibcHome := filepath.Join(home, consts.ConfigDirName.Eibc)
isEibcClientInitialized, err := globalutils.DirNotEmpty(eibcHome)
if err != nil {
pterm.Error.Println("failed to check eibc client initialized", err)
return
}

if !isEibcClientInitialized {
pterm.Error.Println("eibc client not initialized")
return
}

eibcConfigPath := filepath.Join(eibcHome, "config.yaml")
data, err := os.ReadFile(eibcConfigPath)
if err != nil {
pterm.Error.Printf("Error reading file: %v\n", err)
return
}

// Parse the YAML
var config eibcutils.Config
err = yaml.Unmarshal(data, &config)
if err != nil {
pterm.Error.Printf("Error reading file: %v\n", err)
return
}

for asset, percentage := range config.FulfillCriteria.MinFeePercentage.Asset {
fmt.Printf("%s: %.6f\n", asset, percentage)
}
},
}

return cmd
}
74 changes: 74 additions & 0 deletions cmd/eibc/fulfill/denoms/remove/remove.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package remove

import (
"fmt"
"os"
"path/filepath"

"github.com/dymensionxyz/roller/cmd/consts"
globalutils "github.com/dymensionxyz/roller/utils"
"github.com/dymensionxyz/roller/utils/eibc"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "remove",
Short: "Commands to manage the whitelist of RollApps to fulfill eibc orders for",
Args: cobra.MaximumNArgs(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
}

eibcHome := filepath.Join(home, consts.ConfigDirName.Eibc)
isEibcClientInitialized, err := globalutils.DirNotEmpty(eibcHome)
if err != nil {
pterm.Error.Println("failed to check eibc client initialized", err)
return
}

if !isEibcClientInitialized {
pterm.Error.Println("eibc client not initialized")
return
}

eibcConfigPath := filepath.Join(eibcHome, "config.yaml")
data, err := os.ReadFile(eibcConfigPath)
if err != nil {
pterm.Error.Printf("Error reading file: %v\n", err)
return
}

// Parse the YAML
var config eibc.Config

asset := args[0]
err = yaml.Unmarshal(data, &config)
if err != nil {
pterm.Error.Printf("Error reading file: %v\n", err)
return
}

config.RemoveChain(asset)
updatedData, err := yaml.Marshal(&config)
fmt.Println(string(updatedData))
if err != nil {
pterm.Error.Printf("Error reading file: %v\n", err)
return
}

err = os.WriteFile(eibcConfigPath, updatedData, 0o644)
if err != nil {
pterm.Error.Printf("Error reading file: %v\n", err)
return
}
},
}

return cmd
}
102 changes: 102 additions & 0 deletions cmd/eibc/fulfill/denoms/set/set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package set

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

"github.com/dymensionxyz/roller/cmd/consts"
globalutils "github.com/dymensionxyz/roller/utils"
"github.com/dymensionxyz/roller/utils/config/yamlconfig"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "set <ibc-denom-id> <value>",
Short: "Commands to manage the whitelist of RollApps to fulfill eibc orders for",
Args: cobra.ExactArgs(2),
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
}

eibcHome := filepath.Join(home, consts.ConfigDirName.Eibc)
isEibcClientInitialized, err := globalutils.DirNotEmpty(eibcHome)
if err != nil {
pterm.Error.Println("failed to check eibc client initialized", err)
return
}

if !isEibcClientInitialized {
pterm.Error.Println("eibc client not initialized")
return
}

eibcConfigPath := filepath.Join(eibcHome, "config.yaml")
data, err := os.ReadFile(eibcConfigPath)
if err != nil {
pterm.Error.Printf("Error reading file: %v\n", err)
return
}

// Parse the YAML
var node yaml.Node
ibcDenom := args[0]
value := args[1]

if !strings.HasPrefix(ibcDenom, "ibc/") {
pterm.Error.Println("invalid ibc denom")
return
}

valueFloat, err := strconv.ParseFloat(value, 32)
if err != nil {
pterm.Error.Println("failed to convert value to float", err)
return
}
err = yaml.Unmarshal(data, &node)
if err != nil {
pterm.Error.Println("failed to unmarshal config.yaml")
return
}

// Get the actual content node (usually the first child of the document node)
contentNode := &node
if node.Kind == yaml.DocumentNode && len(node.Content) > 0 {
contentNode = node.Content[0]
}

err = yamlconfig.UpdateNestedYAML(
contentNode,
[]string{"fulfill_criteria", "min_fee_percentage", "asset", ibcDenom},
valueFloat,
)
if err != nil {
fmt.Printf("Error updating YAML: %v\n", err)
return
}

updatedData, err := yaml.Marshal(&node)
if err != nil {
fmt.Printf("Error marshaling YAML: %v\n", err)
return
}

// Write the updated YAML back to the original file
err = os.WriteFile(eibcConfigPath, updatedData, 0o644)
if err != nil {
fmt.Printf("Error writing file: %v\n", err)
return
}
},
}

return cmd
}
22 changes: 22 additions & 0 deletions cmd/eibc/fulfill/fulfill.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fulfill

import (
"github.com/spf13/cobra"

"github.com/dymensionxyz/roller/cmd/eibc/fulfill/denoms"
"github.com/dymensionxyz/roller/cmd/eibc/fulfill/order"
"github.com/dymensionxyz/roller/cmd/eibc/fulfill/rollapps"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "fulfill",
Short: "Commands related to fulfillment of eibc orders",
}

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

return cmd
}
Loading
Loading