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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################## update dependencies ####################
ETHEREUM_SUBMODULE_COMMIT_OR_TAG := d085f8c79a53edbd45c4af09f8a8182f1b1d5401
ETHEREUM_TARGET_VERSION := v1.10.14-0.20251119080508-d085f8c79a53
ETHEREUM_SUBMODULE_COMMIT_OR_TAG := 49fa27bcab243c67f6489de504453637d6015ccf
ETHEREUM_TARGET_VERSION := v1.10.14-0.20251203083507-49fa27bcab24
TENDERMINT_TARGET_VERSION := v0.3.2

ETHEREUM_MODULE_NAME := github.com/morph-l2/go-ethereum
Expand Down
2 changes: 1 addition & 1 deletion bindings/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.24.0

replace github.com/tendermint/tendermint => github.com/morph-l2/tendermint v0.3.2

require github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53
require github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24

require (
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions bindings/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqky
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53 h1:8+qaUTn1/eyS8er4RkibhHMFC/L4IgqIXLtORakBDkI=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24 h1:r9eaQDNgjAxsuUchmoCFaAjL1TmUfjAmIlJjAtgUk8U=
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand Down
2 changes: 1 addition & 1 deletion contracts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ replace github.com/tendermint/tendermint => github.com/morph-l2/tendermint v0.3.

require (
github.com/iden3/go-iden3-crypto v0.0.16
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24
github.com/stretchr/testify v1.10.0
)

Expand Down
4 changes: 2 additions & 2 deletions contracts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqky
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53 h1:8+qaUTn1/eyS8er4RkibhHMFC/L4IgqIXLtORakBDkI=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24 h1:r9eaQDNgjAxsuUchmoCFaAjL1TmUfjAmIlJjAtgUk8U=
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
Expand Down
2 changes: 1 addition & 1 deletion node/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/hashicorp/golang-lru v1.0.2
github.com/holiman/uint256 v1.2.4
github.com/klauspost/compress v1.17.9
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24
github.com/prometheus/client_golang v1.17.0
github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions node/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqky
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53 h1:8+qaUTn1/eyS8er4RkibhHMFC/L4IgqIXLtORakBDkI=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24 h1:r9eaQDNgjAxsuUchmoCFaAjL1TmUfjAmIlJjAtgUk8U=
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/morph-l2/tendermint v0.3.2 h1:Gu6Uj2G6c3YP2NAKFi7A46JZaOCdD4zfZDKCjt0pDm8=
github.com/morph-l2/tendermint v0.3.2/go.mod h1:TtCzp9l6Z6yDUiwv3TbqKqw8Q8RKp3fSz5+adO1/Y8w=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
Expand Down
2 changes: 1 addition & 1 deletion ops/l2-genesis/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ replace github.com/tendermint/tendermint => github.com/morph-l2/tendermint v0.3.

require (
github.com/holiman/uint256 v1.2.4
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24
github.com/stretchr/testify v1.10.0
github.com/urfave/cli v1.22.17
)
Expand Down
4 changes: 2 additions & 2 deletions ops/l2-genesis/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqky
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53 h1:8+qaUTn1/eyS8er4RkibhHMFC/L4IgqIXLtORakBDkI=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24 h1:r9eaQDNgjAxsuUchmoCFaAjL1TmUfjAmIlJjAtgUk8U=
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
Expand Down
2 changes: 1 addition & 1 deletion ops/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.24.0
replace github.com/tendermint/tendermint => github.com/morph-l2/tendermint v0.3.2

require (
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24
github.com/tendermint/tendermint v0.35.9
)

Expand Down
4 changes: 2 additions & 2 deletions ops/tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqky
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53 h1:8+qaUTn1/eyS8er4RkibhHMFC/L4IgqIXLtORakBDkI=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24 h1:r9eaQDNgjAxsuUchmoCFaAjL1TmUfjAmIlJjAtgUk8U=
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/morph-l2/tendermint v0.3.2 h1:Gu6Uj2G6c3YP2NAKFi7A46JZaOCdD4zfZDKCjt0pDm8=
github.com/morph-l2/tendermint v0.3.2/go.mod h1:TtCzp9l6Z6yDUiwv3TbqKqw8Q8RKp3fSz5+adO1/Y8w=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
Expand Down
2 changes: 1 addition & 1 deletion oracle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ replace github.com/tendermint/tendermint => github.com/morph-l2/tendermint v0.3.
require (
github.com/go-kit/kit v0.12.0
github.com/morph-l2/externalsign v0.3.1
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24
github.com/prometheus/client_golang v1.17.0
github.com/stretchr/testify v1.10.0
github.com/tendermint/tendermint v0.35.9
Expand Down
4 changes: 2 additions & 2 deletions oracle/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/morph-l2/externalsign v0.3.1 h1:UYFDZFB0L85A4rDvuwLNBiGEi0kSmg9AZ2v8Q5O4dQo=
github.com/morph-l2/externalsign v0.3.1/go.mod h1:b6NJ4GUiiG/gcSJsp3p8ExsIs4ZdphlrVALASnVoGJE=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53 h1:8+qaUTn1/eyS8er4RkibhHMFC/L4IgqIXLtORakBDkI=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24 h1:r9eaQDNgjAxsuUchmoCFaAjL1TmUfjAmIlJjAtgUk8U=
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/morph-l2/tendermint v0.3.2 h1:Gu6Uj2G6c3YP2NAKFi7A46JZaOCdD4zfZDKCjt0pDm8=
github.com/morph-l2/tendermint v0.3.2/go.mod h1:TtCzp9l6Z6yDUiwv3TbqKqw8Q8RKp3fSz5+adO1/Y8w=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
Expand Down
56 changes: 44 additions & 12 deletions token-price-oracle/client/bitget_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"math/big"
"net/http"
"strconv"
"strings"
"sync"
"time"

Expand All @@ -16,6 +17,10 @@ import (

const (
bitgetTickerPath = "/api/v2/spot/market/tickers"

// StablecoinPrefix is used to mark stablecoins with fixed USD price
// Format: "$1.0" means the token is pegged to $1.0 USD
StablecoinPrefix = "$"
)

// BitgetSDKPriceFeed uses Bitget REST API to fetch prices
Expand Down Expand Up @@ -63,6 +68,10 @@ func NewBitgetSDKPriceFeed(tokenMap map[uint16]string, baseURL string) *BitgetSD

// GetTokenPrice returns token price in USD
// Note: Caller should ensure ETH price is updated via GetBatchTokenPrices for batch operations
//
// Stablecoin handling:
// - If the symbol starts with "$" (e.g., "$1.0"), it's treated as a stablecoin with fixed price
// - Example: "3:$1.0" means token ID 3 is a stablecoin pegged to $1.0 USD
func (b *BitgetSDKPriceFeed) GetTokenPrice(ctx context.Context, tokenID uint16) (*TokenPrice, error) {
b.mu.RLock()
symbol, exists := b.tokenMap[tokenID]
Expand All @@ -73,23 +82,46 @@ func (b *BitgetSDKPriceFeed) GetTokenPrice(ctx context.Context, tokenID uint16)
return nil, fmt.Errorf("token ID %d not mapped to trading pair", tokenID)
}

// Fetch token price
tokenPrice, err := b.fetchPrice(ctx, symbol)
if err != nil {
return nil, fmt.Errorf("failed to fetch price for %s: %w", symbol, err)
}

// Use cached ETH price (should be updated by GetBatchTokenPrices)
if ethPrice.Cmp(big.NewFloat(0)) == 0 {
return nil, fmt.Errorf("ETH price not initialized, please call GetBatchTokenPrices first")
}

b.log.Info("Fetched price from Bitget",
"source", "bitget",
"token_id", tokenID,
"symbol", symbol,
"token_price_usd", tokenPrice.String(),
"eth_price_usd", ethPrice.String())
var tokenPrice *big.Float

// Check if this is a stablecoin with fixed price (e.g., "$1.0")
if strings.HasPrefix(symbol, StablecoinPrefix) {
priceStr := strings.TrimPrefix(symbol, StablecoinPrefix)
fixedPrice, err := strconv.ParseFloat(priceStr, 64)
if err != nil {
return nil, fmt.Errorf("invalid stablecoin price format '%s': %w", symbol, err)
}
if fixedPrice <= 0 {
return nil, fmt.Errorf("stablecoin price must be positive, got '%s'", symbol)
}
tokenPrice = big.NewFloat(fixedPrice)

b.log.Info("Using fixed stablecoin price",
"source", "stablecoin",
"token_id", tokenID,
"symbol", symbol,
"token_price_usd", tokenPrice.String(),
"eth_price_usd", ethPrice.String())
} else {
// Fetch token price from exchange
var err error
tokenPrice, err = b.fetchPrice(ctx, symbol)
if err != nil {
return nil, fmt.Errorf("failed to fetch price for %s: %w", symbol, err)
}

b.log.Info("Fetched price from Bitget",
"source", "bitget",
"token_id", tokenID,
"symbol", symbol,
"token_price_usd", tokenPrice.String(),
"eth_price_usd", ethPrice.String())
}

return &TokenPrice{
TokenID: tokenID,
Expand Down
12 changes: 8 additions & 4 deletions token-price-oracle/env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ TOKEN_PRICE_ORACLE_PRICE_THRESHOLD=100 # basis points (bps), e.g. 100 means 1%
TOKEN_PRICE_ORACLE_PRICE_FEED_PRIORITY=bitget

# Token mapping for Bitget (tokenID:tradingPair,tokenID:tradingPair)
TOKEN_PRICE_ORACLE_TOKEN_MAPPING_BITGET=1:BGBUSDT,2:BTCUSDT

# Token mapping for Binance (optional)
# TOKEN_PRICE_ORACLE_TOKEN_MAPPING_BINANCE=1:BGBUSDT,2:BTCUSDT
# Format:
# - Regular tokens: tokenID:SYMBOL (e.g., 1:BGBUSDT, 2:BTCUSDT)
# - Stablecoins: tokenID:$PRICE (e.g., 3:$1.0 for USDT pegged to $1 USD)
# Example: 1:BGBUSDT,2:BTCUSDT,3:$1.0,4:$0.9999
TOKEN_PRICE_ORACLE_TOKEN_MAPPING_BITGET=1:BGBUSDT,2:BTCUSDT,3:$1.0

# Token mapping for Binance (optional, same format as Bitget)
# TOKEN_PRICE_ORACLE_TOKEN_MAPPING_BINANCE=1:BGBUSDT,2:BTCUSDT,3:$1.0

# API base URLs (optional, defaults provided)
TOKEN_PRICE_ORACLE_BITGET_API_BASE_URL=https://api.bitget.com
Expand Down
2 changes: 1 addition & 1 deletion token-price-oracle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ replace (
)

require (
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24
github.com/prometheus/client_golang v1.17.0
github.com/sirupsen/logrus v1.9.3
github.com/urfave/cli v1.22.17
Expand Down
4 changes: 2 additions & 2 deletions token-price-oracle/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqky
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53 h1:8+qaUTn1/eyS8er4RkibhHMFC/L4IgqIXLtORakBDkI=
github.com/morph-l2/go-ethereum v1.10.14-0.20251119080508-d085f8c79a53/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24 h1:r9eaQDNgjAxsuUchmoCFaAjL1TmUfjAmIlJjAtgUk8U=
github.com/morph-l2/go-ethereum v1.10.14-0.20251203083507-49fa27bcab24/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
Expand Down
7 changes: 6 additions & 1 deletion token-price-oracle/local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
--price-update-interval 30s \
--price-threshold 100 \
--price-feed-priority bitget \
--token-mapping-bitget "1:BGBUSDT,2:BTCUSDT" \
--token-mapping-bitget "1:BGBUSDT,2:BTCUSDT,3:\$1.0" \
--bitget-api-base-url https://api.bitget.com \
--log-level info \
--metrics-server-enable

# Price threshold examples (in basis points):
# 1 bps = 0.01%, 10 bps = 0.1%, 100 bps = 1%, 500 bps = 5%, 1000 bps = 10%

# Token mapping format:
# - Regular tokens: tokenID:SYMBOL (e.g., 1:BGBUSDT, 2:BTCUSDT)
# - Stablecoins: tokenID:$PRICE (e.g., 3:$1.0 for USDT pegged to $1 USD)
# Note: Use \$ in bash to escape the dollar sign

34 changes: 34 additions & 0 deletions token-price-oracle/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metrics

import (
"net/http"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand All @@ -25,12 +26,45 @@ var (
Help: "Account balance in ETH",
},
)

// LastSuccessfulUpdateTimestamp records the Unix timestamp of the last successful update cycle
// A successful update includes: prices updated on-chain OR prices skipped (below threshold)
// This helps monitor if the oracle is running normally
LastSuccessfulUpdateTimestamp = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "last_successful_update_timestamp",
Help: "Unix timestamp of the last successful price update cycle (includes both updates and skips)",
},
)

// UpdatesTotal counts total number of successful update cycles
UpdatesTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "updates_total",
Help: "Total number of successful update cycles",
},
[]string{"type"}, // type: "updated" or "skipped"
)
)

// init registers all metrics
func init() {
prometheus.MustRegister(UpdateErrors)
prometheus.MustRegister(AccountBalance)
prometheus.MustRegister(LastSuccessfulUpdateTimestamp)
prometheus.MustRegister(UpdatesTotal)

// Initialize metrics with default values to avoid nil pointer issues in alerting systems
// Set initial timestamp to current time (program start time)
LastSuccessfulUpdateTimestamp.Set(float64(time.Now().Unix()))
// Initialize counter labels to ensure they exist from the start
// Must call Add(0) to actually create the metric, WithLabelValues alone doesn't create it
UpdatesTotal.WithLabelValues("updated").Add(0)
UpdatesTotal.WithLabelValues("skipped").Add(0)
// Initialize error counter labels
UpdateErrors.WithLabelValues("price").Add(0)
// Note: AccountBalance is NOT initialized here to avoid triggering low balance alerts
// It will be set with the real value on the first update cycle
}

// StartMetricsServer starts metrics HTTP server
Expand Down
Loading
Loading