Skip to content

Commit

Permalink
fix link to etherscan/eigenlayer on telemetry (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
v9n authored Jul 16, 2024
1 parent b72a666 commit fa6335b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 3 deletions.
28 changes: 28 additions & 0 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package aggregator
import (
"context"
"fmt"
"math/big"
"os"
"os/signal"
"sync"
"syscall"
"time"

"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/ethereum/go-ethereum/ethclient"

"github.com/AvaProtocol/ap-avs/aggregator/types"
"github.com/AvaProtocol/ap-avs/core"
Expand Down Expand Up @@ -63,6 +65,9 @@ type Aggregator struct {
config *config.Config
db storage.Storage

ethRpcClient *ethclient.Client
chainID *big.Int

operatorPool *OperatorPool
}

Expand Down Expand Up @@ -136,9 +141,32 @@ func (agg *Aggregator) initDB(ctx context.Context) error {
return agg.db.Setup()
}

// initialize agg config and state
func (agg *Aggregator) init() {
var err error

agg.ethRpcClient, err = ethclient.Dial(agg.config.EthHttpRpcUrl)
if err != nil {
panic(err)
}

agg.chainID, err = agg.ethRpcClient.ChainID(context.Background())
if err != nil {
panic(err)
}

if agg.chainID.Cmp(config.MainnetChainID) == 0 {
config.CurrentChainEnv = config.EthereumEnv
} else {
config.CurrentChainEnv = config.HoleskyEnv
}
}

func (agg *Aggregator) Start(ctx context.Context) error {
agg.logger.Infof("Starting aggregator")

agg.init()

agg.logger.Infof("Initialize Storagre")
agg.initDB(ctx)

Expand Down
9 changes: 9 additions & 0 deletions aggregator/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

timestamppb "google.golang.org/protobuf/types/known/timestamppb"

"github.com/AvaProtocol/ap-avs/core/config"
avsproto "github.com/AvaProtocol/ap-avs/protobuf"
"github.com/AvaProtocol/ap-avs/storage"
)
Expand Down Expand Up @@ -37,6 +38,14 @@ func (o *OperatorNode) LastSeen() string {
}
}

func (o *OperatorNode) EtherscanURL() string {
return fmt.Sprintf("%s/address/%s", config.EtherscanURL(), o.Address)
}

func (o *OperatorNode) EigenlayerURL() string {
return fmt.Sprintf("%s/operator/%s", config.EigenlayerAppURL(), o.Address)
}

var (
operatorPrefix = []byte("operator:")
)
Expand Down
5 changes: 2 additions & 3 deletions aggregator/resources/index.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
alt="">*/}}
<div class="min-w-0 flex-auto">
<p class="text-sm font-semibold leading-6 text-white">
<a href="https://holesky.etherscan.io/address/{{ .Address}}">
<a href="{{ .EtherscanURL }}">
{{ .Address }}
</a>
</p>
<p class="mt-1 truncate text-xs leading-5 text-gray-400">
<a href="https://holesky.eigenlayer.xyz/operator/{{ .Address
}}">View on EigenLayer</a>
<a href="{{ .EigenlayerURL }}">View on EigenLayer</a>
</p>
</div>
</div>
Expand Down
41 changes: 41 additions & 0 deletions core/config/envs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package config

import "math/big"

type ChainEnv string

const (
HoleskyEnv = ChainEnv("holesky")
EthereumEnv = ChainEnv("ethereum")
)

var (
MainnetChainID = big.NewInt(1)
CurrentChainEnv = ChainEnv("ethereum")

etherscanURLs = map[ChainEnv]string{
EthereumEnv: "https://etherscan.io",
HoleskyEnv: "https://holesky.etherscan.io",
}

eigenlayerAppURLs = map[ChainEnv]string{
EthereumEnv: "https://app.eigenlayer.xyz",
HoleskyEnv: "https://holesky.eigenlayer.xyz",
}
)

func EtherscanURL() string {
if url, ok := etherscanURLs[CurrentChainEnv]; ok {
return url
}

return "https://etherscan.io"
}

func EigenlayerAppURL() string {
if url, ok := eigenlayerAppURLs[CurrentChainEnv]; ok {
return url
}

return "https://eigenlayer.xyz"
}

0 comments on commit fa6335b

Please sign in to comment.