mirror of
https://github.com/AthanorLabs/atomic-swap.git
synced 2026-01-08 21:58:07 -05:00
made optimism endpoint configurable and changed default (#502)
This commit is contained in:
1
.github/workflows/unit-tests.yml
vendored
1
.github/workflows/unit-tests.yml
vendored
@@ -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
|
||||
|
||||
6
Makefile
6
Makefile
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user