Skip to content
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
14 changes: 2 additions & 12 deletions e2e/app/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/omni-network/omni/lib/log"
"github.com/omni-network/omni/lib/netconf"
"github.com/omni-network/omni/lib/txmgr"
"github.com/omni-network/omni/lib/xchain"

"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
Expand All @@ -25,9 +26,7 @@ const drainRecipient = "0x79Ef4d1224a055Ad4Ee5e2226d0cb3720d929AE7"
const ethTransferGas uint64 = 21000

// DrainRelayerMonitor transfers all relayer and monitor ETH balances to the drain recipient on all chains.
func DrainRelayerMonitor(ctx context.Context, def Definition, dryRun bool) error {
network := networkFromDef(def)
endpoints := ExternalEndpoints(def)
func DrainRelayerMonitor(ctx context.Context, network netconf.Network, endpoints xchain.RPCEndpoints, dryRun bool) error {
roles := []eoa.Role{eoa.RoleRelayer, eoa.RoleMonitor}
recipient := common.HexToAddress(drainRecipient)

Expand Down Expand Up @@ -185,12 +184,3 @@ func transferNativeMax(

return nil, nil, errors.New("transfer failed after retries", "retries", maxDrainRetries)
}

// DrainAllowed returns an error if the drain command is not allowed for the given network.
func DrainAllowed(network netconf.ID) error {
if network == netconf.Simnet || network == netconf.Devnet {
return errors.New("cannot drain on simnet or devnet")
}

return nil
}
46 changes: 38 additions & 8 deletions e2e/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/omni-network/omni/lib/log"
"github.com/omni-network/omni/lib/netconf"
"github.com/omni-network/omni/lib/tokens"
"github.com/omni-network/omni/lib/xchain"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -51,7 +52,7 @@ func New() *cobra.Command {
}

// Some commands do not require a full definition.
if matchAny(cmd.Use, "hyperliquid-use-big-blocks") {
if matchAny(cmd.Use, "hyperliquid-use-big-blocks", "drain-relayer-monitor") {
return nil
}

Expand Down Expand Up @@ -105,7 +106,7 @@ func New() *cobra.Command {
fundAccounts(&def),
newFundOpsFromSolverCmd(&def),
newConvertOmniCmd(&def),
newDrainRelayerMonitorCmd(&def),
newDrainRelayerMonitorCmd(&defCfg),
)

return cmd
Expand Down Expand Up @@ -525,21 +526,50 @@ func newConvertOmniCmd(def *app.Definition) *cobra.Command {
return cmd
}

func newDrainRelayerMonitorCmd(def *app.Definition) *cobra.Command {
func newDrainRelayerMonitorCmd(defCfg *app.DefinitionConfig) *cobra.Command {
var dryRun bool

cmd := &cobra.Command{
Use: "drain-relayer-monitor",
Short: "Transfers relayer and monitor ETH balances to ops wallet on all chains",
RunE: func(cmd *cobra.Command, _ []string) error {
if err := app.DrainAllowed(def.Testnet.Network); err != nil {
return err
ctx := cmd.Context()

manifest, err := app.LoadManifest(defCfg.ManifestFile)
if err != nil {
return errors.Wrap(err, "load manifest")
}
if err := def.InitLazyNetwork(); err != nil {
return errors.Wrap(err, "init network")

networkID := manifest.Network

// Build network and endpoints.
// Partial & inline, because old utils rely on halted infra.
endpoints := make(xchain.RPCEndpoints)
var chains []netconf.Chain
for _, name := range manifest.PublicChains {
if rpc, ok := defCfg.RPCOverrides[name]; ok {
endpoints[name] = rpc
} else {
endpoints[name] = types.PublicRPCByName(name)
}

chain, err := types.PublicChainByName(name)
if err != nil {
return errors.Wrap(err, "public chain", "name", name)
}

chains = append(chains, netconf.Chain{
ID: chain.ChainID,
Name: chain.Name,
})
}

network := netconf.Network{
ID: networkID,
Chains: chains,
}

return app.DrainRelayerMonitor(cmd.Context(), *def, dryRun)
return app.DrainRelayerMonitor(ctx, network, endpoints, dryRun)
},
}

Expand Down
Loading