Skip to content

Commit

Permalink
Add gnosis price (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrevuelta authored Dec 5, 2022
1 parent 65b8e0f commit 7c68142
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
9 changes: 7 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var ReleaseVersion = "custom-build"
// 16 Gnosis mainnet
var SlotsInEpoch = uint64(32)

var Network = ""

type Config struct {
PoolNames []string
Network string
Expand Down Expand Up @@ -80,6 +82,9 @@ func NewCliConfig() (*Config, error) {
if *network == "gnosis" {
SlotsInEpoch = uint64(16)
}

// Used for the price
Network = *network
/*
if *poolName == "required" {
log.Fatal("pool-name flag is required")
Expand All @@ -98,7 +103,7 @@ func NewCliConfig() (*Config, error) {
}*/

conf := &Config{
PoolNames: poolNames,
PoolNames: poolNames,
Network: *network,
BeaconRpcEndpoint: *beaconRpcEndpoint,
PrometheusPort: *prometheusPort,
Expand Down Expand Up @@ -127,6 +132,6 @@ func logConfig(cfg *Config) {
"Eth1Address": cfg.Eth1Address,
"Eth2Address": cfg.Eth2Address,
"EpochDebug": cfg.EpochDebug,
"SlotsInEpoch": SlotsInEpoch,
"SlotsInEpoch": SlotsInEpoch,
}).Info("Cli Config:")
}
15 changes: 12 additions & 3 deletions price/price.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package price
import (
"time"

"github.com/alrevuelta/eth-pools-metrics/config"
"github.com/alrevuelta/eth-pools-metrics/postgresql"
"github.com/alrevuelta/eth-pools-metrics/prometheus"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
gecko "github.com/superoo7/go-gecko/v3"
)

var ids = []string{"ethereum"}
var vc = []string{"usd", "eurr"}

type Price struct {
Expand Down Expand Up @@ -42,12 +42,21 @@ func NewPrice(postgresEndpoint string) (*Price, error) {
}

func (p *Price) GetEthPrice() {
sp, err := p.coingecko.SimplePrice(ids, vc)
id := ""
if config.Network == "mainnet" {
id = "ethereum"
} else if config.Network == "gnosis" {
id = "gnosis"
} else {
log.Fatal("Network not supported: ", config.Network)
}

sp, err := p.coingecko.SimplePrice([]string{id}, vc)
if err != nil {
log.Error(err)
}

eth := (*sp)["ethereum"]
eth := (*sp)[id]
ethPriceUsd := eth["usd"]

logPrice(ethPriceUsd)
Expand Down

0 comments on commit 7c68142

Please sign in to comment.