made optimism endpoint configurable and changed default (#502)

This commit is contained in:
Dmitry Holodov
2023-07-12 22:30:29 -05:00
committed by GitHub
parent 3b4870ed50
commit 13b7653249
4 changed files with 19 additions and 7 deletions

View File

@@ -64,6 +64,7 @@ jobs:
env:
ETH_MAINNET_ENDPOINT: ${{ secrets.ETH_MAINNET_ENDPOINT }}
ETH_SEPOLIA_ENDPOINT: ${{ secrets.ETH_SEPOLIA_ENDPOINT }}
ETH_OPTIMISM_ENDPOINT: ${{ secrets.ETH_OPTIMISM_ENDPOINT }}
run: ./scripts/run-unit-tests.sh
- name: Upload code coverage

View File

@@ -1,4 +1,5 @@
GOPATH ?= $(shell go env GOPATH)
NPM_DIR = $(shell npm config get prefix)
.PHONY: all
all: install
@@ -14,7 +15,7 @@ lint-shell:
.PHONY: lint-solidity
lint-solidity:
"$$(npm config get prefix)/bin/solhint" $$(find ethereum -name '*.sol' -not -path '**/@openzeppelin/**')
"$(NPM_DIR)/bin/solhint" $$(find ethereum -name '*.sol' -not -path '**/@openzeppelin/**')
.PHONY: lint
lint: lint-go lint-shell lint-solidity
@@ -30,7 +31,8 @@ format-shell:
.PHONY: format-solidity
format-solidity:
"$$(npm config get prefix)/bin/prettier" --print-width 100 --write \
"$(NPM_DIR)/bin/prettier" --print-width 100 --write \
--plugin="$(NPM_DIR)/lib/node_modules/prettier-plugin-solidity/src/index.js" \
$$(find ethereum -name '*.sol' -not -path '**/@openzeppelin/**')
.PHONY: format

View File

@@ -8,6 +8,7 @@ package pricefeed
import (
"context"
"errors"
"os"
"time"
"github.com/cockroachdb/apd/v3"
@@ -21,10 +22,10 @@ import (
)
const (
// optimismEndpoint is an RPC endpoint for optimism mainnet. Note that we
// fallbackOptimismEndpoint is an RPC endpoint for optimism mainnet. Note that we
// tried https://mainnet.optimism.io first, but it is severely rate limited
// to around 2 requests/second.
optimismEndpoint = "https://1rpc.io/op"
fallbackOptimismEndpoint = "https://optimism.blockpi.network/v1/rpc/public"
// https://data.chain.link/optimism/mainnet/crypto-usd/eth-usd
chainlinkETHToUSDProxy = "0x13e3ee699d1909e989722e753853ae30b17e08c5"
@@ -45,6 +46,14 @@ type PriceFeed struct {
UpdatedAt time.Time
}
func getOptimismEndpoint() string {
endpoint := os.Getenv("ETH_OPTIMISM_ENDPOINT")
if endpoint == "" {
endpoint = fallbackOptimismEndpoint
}
return endpoint
}
// GetETHUSDPrice returns the current ETH/USD price from the Chainlink oracle.
func GetETHUSDPrice(ctx context.Context, ec *ethclient.Client) (*PriceFeed, error) {
chainID, err := ec.ChainID(ctx)
@@ -56,7 +65,7 @@ func GetETHUSDPrice(ctx context.Context, ec *ethclient.Client) (*PriceFeed, erro
case common.OpMainnetChainID:
// No extra work to do
case common.MainnetChainID, common.SepoliaChainID:
ec, err = ethclient.Dial(optimismEndpoint)
ec, err = ethclient.Dial(getOptimismEndpoint())
if err != nil {
return nil, err
}
@@ -86,7 +95,7 @@ func GetXMRUSDPrice(ctx context.Context, ec *ethclient.Client) (*PriceFeed, erro
// No extra work to do
case common.MainnetChainID, common.SepoliaChainID:
// Push stagenet/sepolia users to a mainnet endpoint
ec, err = ethclient.Dial(optimismEndpoint)
ec, err = ethclient.Dial(getOptimismEndpoint())
if err != nil {
return nil, err
}

View File

@@ -20,7 +20,7 @@ func init() {
}
func newOptimismClient(t *testing.T) *ethclient.Client {
ec, err := ethclient.Dial(optimismEndpoint)
ec, err := ethclient.Dial(getOptimismEndpoint())
require.NoError(t, err)
t.Cleanup(func() {
ec.Close()