monitor

package
v0.0.0-...-9003b37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2025 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AVALANCHE_NETWORK  = "avalanche"
	AVALANCHE_CHAIN_ID = 43114
)
View Source
const (
	COINGECKO_AVALANCHE_ID = "avalanche-2"
	COINGECKO_OSMOSIS_ID   = "osmosis"
	COINGECKO_ETHEREUM_ID  = "ethereum"
)
View Source
const (
	ARBITRUM_NETWORK  = "arbitrum"
	ARBITRUM_CHAIN_ID = 42161

	ETHEREUM_NETWORK  = "ethereum"
	ETHEREUM_CHAIN_ID = 1

	BASE_NETWORK  = "base"
	BASE_CHAIN_ID = 8453
)
View Source
const BLOCK_QUERY string = "/cosmos/base/tendermint/v1beta1/blocks"

Variables

View Source
var ChainIdToNetwork = map[string]string{
	"42161":     "arbitrum",
	"43114":     "avalanche",
	"8453":      "base",
	"56":        "bnb",
	"1":         "ethereum",
	"137":       "polygon",
	"osmosis-1": "osmosis",
}
View Source
var NetworkToChainId = map[string]string{
	"arbitrum":  "42161",
	"avalanche": "43114",
	"base":      "8453",
	"bnb":       "56",
	"ethereum":  "1",
	"polygon":   "137",
	"osmosis":   "osmosis-1",
}
View Source
var NotAvailableError = errors.New("server not available error")
View Source
var RateLimitErr = errors.New("rate limit error")

Functions

func HttpCodeCheck

func HttpCodeCheck(httpCode int) string

func InitDB

func InitDB(db *sql.DB)

func MustInitDecoder

func MustInitDecoder() *decode.Decoder

Types

type AvaxAddressesResponse

type AvaxAddressesResponse struct {
	Address               string    `json:"address"`
	Balance               string    `json:"balance"` // 18 decimals
	FirstActivity         time.Time `json:"firstActivity"`
	TransactionsCount     int       `json:"transactionsCount"`
	ERC20TransfersCount   int       `json:"erc20TransfersCount"`
	ERC721TransfersCount  int       `json:"erc721TransfersCount"`
	ERC1155TransfersCount int       `json:"erc1155TransfersCount"`
}

type AvaxEVMTxDetails

type AvaxEVMTxDetails struct {
	Type        string `json:"type"`
	ID          string `json:"id"`
	ChainID     string `json:"chainId"`
	Timestamp   string `json:"timestamp"`
	BlockNumber int64  `json:"blockNumber"`
	BlockHash   string `json:"blockHash"`
	From        string `json:"from"`
	To          string `json:"to"`
	Value       string `json:"value"`
	Index       int64  `json:"index"`
	Status      bool   `json:"status"`
	GasUsed     string `json:"gasUsed"`
	GasPrice    string `json:"gasPrice"`
	GasLimit    string `json:"gasLimit"`
	BurnedFees  string `json:"burnedFees"`

	Network    string `json:"network,omitempty"` // not in the response -- injected by us
	GasUsedUsd string `json:"gasUsedUsd"`        // not in the response -- calculated by us
}

func (*AvaxEVMTxDetails) ToEthTxDetails

func (td *AvaxEVMTxDetails) ToEthTxDetails() EthTxDetails

type AvaxErc20

type AvaxErc20 struct {
	ChainId         string `json:"chainId"`
	TokenAddress    string `json:"tokenAddress"`
	TokenName       string `json:"tokenName"`
	TokenSymbol     string `json:"tokenSymbol"`
	TokenDecimals   int    `json:"tokenDecimals"`
	TokenQuantity   string `json:"tokenQuantity"`
	TokenPrice      string `json:"tokenPrice"`
	TokenValueInUsd string `json:"tokenValueInUsd"`
	UpdatedAtBlock  int64  `json:"updatedAtBlock"`
}

type AvaxErc20HoldingResponse

type AvaxErc20HoldingResponse struct {
	Items []AvaxErc20 `json:"items"`
}

type AvaxTxsResponse

type AvaxTxsResponse struct {
	// not exactly the same as the Etherscan response but works for gas calculations
	Items []AvaxEVMTxDetails `json:"items"`
}

type BalancesByNetworkResponse

type BalancesByNetworkResponse map[string][]DbBalance

type BlockTime

type BlockTime struct {
	Height    int64  `json:"height"`
	Timestamp int64  `json:"timestamp"`
	Datetime  string `json:"datetime"`
}

type ChainEntry

type ChainEntry struct {
	Key         string `json:"key,omitempty" yaml:"key,omitempty" toml:"key,omitempty"`
	ApiUrl      string `json:"api_url,omitempty" yaml:"api_url,omitempty" toml:"api_url,omitempty"`
	UsdcAddress string `json:"usdc_address,omitempty" yaml:"usdc_address,omitempty" toml:"usdc_address,omitempty"`
	Address     string `json:"address,omitempty" yaml:"address,omitempty" toml:"address,omitempty"`
}

type Config

type Config struct {
	Arbitrum  ChainEntry    `json:"arbitrum,omitempty" yaml:"arbitrum,omitempty" toml:"arbitrum,omitempty"`
	Ethereum  ChainEntry    `json:"ethereum,omitempty" yaml:"ethereum,omitempty" toml:"ethereum,omitempty"`
	Base      ChainEntry    `json:"base,omitempty" yaml:"base,omitempty" toml:"base,omitempty"`
	Osmosis   OsmosisConfig `json:"osmosis,omitempty" yaml:"osmosis,omitempty" toml:"osmosis,omitempty"`
	Avalanche ChainEntry    `json:"avalanche,omitempty" yaml:"avalanche,omitempty" toml:"avalanche,omitempty"`
}

func MustLoadConfig

func MustLoadConfig(path string) *Config

type CosmosBalances

type CosmosBalances []sdktypes.Coin

type DbBalance

type DbBalance struct {
	Timestamp int64  `json:"timestamp"`
	Balance   string `json:"balance"`
	Address   string `json:"address,omitempty"`
	Exponent  int64  `json:"exponent,omitempty"`
	Token     string `json:"token"`
	Network   string `json:"network,omitempty"`
}

type DbEthTxResponse

type DbEthTxResponse struct {
	TxHash     string `json:"tx_hash"`
	Height     int64  `json:"height"`
	Timestamp  int64  `json:"timestamp"`
	GasUsedWei int64  `json:"gas_used_wei"` // value in wei -> gasUsed * gasPrice
	Valid      bool   `json:"valid"`
	Network    string `json:"network"`
	TxResponse []byte `json:"tx_response"` // raw response so we can fallback to local stores if we need to recover or sth
}

type DbOrderFilled

type DbOrderFilled struct {
	TxHash             string    `json:"tx_hash"`
	Sender             string    `json:"sender"`
	AmountIn           string    `json:"amount_in"`
	AmountOut          string    `json:"amount_out"`
	SourceDomain       string    `json:"source_domain"`
	SolverRevenue      int64     `json:"solver_revenue"`
	Height             int64     `json:"height"`
	Code               int64     `json:"code"`
	IngestionTimestamp time.Time `json:"ingestion_timestamp"`
	Filler             string    `json:"filler"`
}

func ReadOrdersByFiller

func ReadOrdersByFiller(db *sql.DB, filler string) []DbOrderFilled

func ReadOrdersFilled

func ReadOrdersFilled(db *sql.DB) []DbOrderFilled

type DbTxResponse

type DbTxResponse struct {
	TxHash     string `json:"tx_hash"`
	Height     int64  `json:"height"`
	Valid      bool   `json:"valid"`
	TxResponse []byte `json:"tx_response"`
}

type EncodingConfig

type EncodingConfig struct {
	InterfaceRegistry types.InterfaceRegistry
	Marshaler         codec.Codec
	TxConfig          client.TxConfig
	Amino             *codec.LegacyAmino
}

EncodingConfig specifies the concrete encoding types to use for a given app. This is provided for compatibility between protobuf and amino implementations.

func MakeEncodingConfig

func MakeEncodingConfig() EncodingConfig

MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.

type EthBalanceResponse

type EthBalanceResponse struct {
	Status  string `json:"status"`
	Message string `json:"message"`
	Result  string `json:"result"` // token balance -> 18 decimals for ETH, 6 decimals for USDC
}

type EthScanTxListResponse

type EthScanTxListResponse struct {
	Status  string         `json:"status"`
	Message string         `json:"message"`
	Result  []EthTxDetails `json:"result"`
}

type EthTxDetails

type EthTxDetails struct {
	BlockNumber       string `json:"blockNumber"`
	BlockHash         string `json:"blockHash"`
	TimeStamp         string `json:"timeStamp"`
	Hash              string `json:"hash"`
	Nonce             string `json:"nonce"`
	TransactionIndex  string `json:"transactionIndex"`
	From              string `json:"from"`
	To                string `json:"to"`
	Value             string `json:"value"`
	Gas               string `json:"gas"`
	GasPrice          string `json:"gasPrice"`
	GasPriceBid       string `json:"gasPriceBid"`
	Input             string `json:"input"`
	MethodId          string `json:"methodId"`
	FunctionName      string `json:"functionName"`
	ContractAddress   string `json:"contractAddress"`
	CumulativeGasUsed string `json:"cumulativeGasUsed"`
	TxreceiptStatus   string `json:"txreceipt_status"`
	GasUsed           string `json:"gasUsed"`
	Confirmations     string `json:"confirmations"`
	IsError           string `json:"isError"`
	Network           string `json:"network,omitempty"` // not in the response -- injected by us
	GasUsedUsd        string `json:"gasUsedUsd"`        // not in the response -- calculated by us
}

type FastTransferOrder

type FastTransferOrder struct {
	Sender            string `json:"sender"`
	Recipient         string `json:"recipient"`
	AmountIn          string `json:"amount_in"`
	AmountOut         string `json:"amount_out"`
	Nonce             uint32 `json:"nonce"`
	SourceDomain      uint32 `json:"source_domain"`
	DestinationDomain uint32 `json:"destination_domain"`
	TimeoutTimestamp  uint64 `json:"timeout_timestamp"`
	Data              string `json:"data,omitempty"`
}

type FeeStatsSummary

type FeeStatsSummary struct {
	TotalGasUSD  string            `json:"total_gas_usd"`
	TotalGasETH  string            `json:"total_gas_eth"`
	TotalGasAVAX string            `json:"total_gas_avax"`
	TotalTxCount int64             `json:"total_tx_count"`
	NetworkStats []NetworkFeeStats `json:"network_stats"`
}

type FillOrderEnvelope

type FillOrderEnvelope struct {
	FillOrder *OrderEnvelope `json:"fill_order"`
}

type FillStatsResponse

type FillStatsResponse struct {
	AverageRevenue   string                 `json:"average_revenue"`
	AverageFill      string                 `json:"average_fill"`
	MaxFill          string                 `json:"max_fill"`
	MaxRevenue       string                 `json:"max_revenue"`
	MinFill          string                 `json:"min_fill"`
	MinRevenue       string                 `json:"min_revenue"`
	MaxFillOrders    []MaxFillOrderResponse `json:"max_fill_details"`
	MaxRevenueOrders []MaxFillOrderResponse `json:"max_revenue_details"`
}

type MaxFillOrderResponse

type MaxFillOrderResponse struct {
	TxHash             string    `json:"tx_hash"`
	AmountIn           string    `json:"amount_in"`
	AmountOut          string    `json:"amount_out"`
	Network            string    `json:"network"`
	SolverRevenue      string    `json:"solver_revenue"`
	Height             int64     `json:"height"`
	IngestionTimestamp time.Time `json:"ingestion_timestamp"`
}

type Monitor

type Monitor struct {
	Codec codec.Codec
	// contains filtered or unexported fields
}

func NewMonitor

func NewMonitor(db *sql.DB, cfg *Config, logger *zerolog.Logger, apiUrl string) *Monitor

func (*Monitor) DecodeTxResponse

func (m *Monitor) DecodeTxResponse(r *sdktypes.TxResponse) []FillOrderEnvelope

func (*Monitor) FetchAndSaveBlocktimes

func (m *Monitor) FetchAndSaveBlocktimes(intervalSeconds int) error

func (*Monitor) GetAllOsmosisOrders

func (m *Monitor) GetAllOsmosisOrders(contract_address string, apiUrl string, outputFile string)

func (*Monitor) GetCoingeckoPrices

func (m *Monitor) GetCoingeckoPrices() error

func (*Monitor) GetDbAverageFill

func (m *Monitor) GetDbAverageFill(filler string) (string, error)

func (*Monitor) GetDbAverageRevenue

func (m *Monitor) GetDbAverageRevenue(filler string) (string, error)

func (*Monitor) GetDbBalancesInTimeRange

func (m *Monitor) GetDbBalancesInTimeRange(network string, from, to time.Time) ([]DbBalance, error)

if useDecimals is true, the balance is returned in decimals otherwise, the balance is returned as a string this means that for 10^18, the balance will be "1000000000000000000" with useDecimals = false and "1" with useDecimals = true

func (*Monitor) GetDbFeesStats

func (m *Monitor) GetDbFeesStats() (*FeeStatsSummary, error)

func (*Monitor) GetDbFillStats

func (m *Monitor) GetDbFillStats(filler string) (*FillStatsResponse, error)

func (*Monitor) GetDbFilledOrderStats

func (m *Monitor) GetDbFilledOrderStats(filler string) (*OrderStatsSummary, error)

func (*Monitor) GetDbLatestBalances

func (m *Monitor) GetDbLatestBalances(network string) ([]DbBalance, error)

if useDecimals is true, the balance is returned in decimals otherwise, the balance is returned as a string this means that for 10^18, the balance will be "1000000000000000000" with useDecimals = false and "1" with useDecimals = true

func (*Monitor) GetDbMinFill

func (m *Monitor) GetDbMinFill(filler string) (string, error)

func (*Monitor) GetDbMinRevenue

func (m *Monitor) GetDbMinRevenue(filler string) (string, error)

func (*Monitor) GetEthereumTxsFromFile

func (m *Monitor) GetEthereumTxsFromFile(path string, network string) ([]EthTxDetails, error)

func (*Monitor) GetLatestEthHeight

func (m *Monitor) GetLatestEthHeight(network string) (int64, error)

func (*Monitor) GetLatestHeight

func (m *Monitor) GetLatestHeight() int

func (*Monitor) GetLatestUsdTokenPrice

func (m *Monitor) GetLatestUsdTokenPrice(token string) (float64, error)

func (*Monitor) GetLatestUsdTokenPriceDecimal

func (m *Monitor) GetLatestUsdTokenPriceDecimal(token string) (decimal.Decimal, error)

func (*Monitor) GetNewOrders

func (m *Monitor) GetNewOrders(height int, contractAddress string) ([]DbOrderFilled, []*DbTxResponse, error)

func (*Monitor) GetOrderDetailsByRange

func (m *Monitor) GetOrderDetailsByRange(network string, startBlock uint64, filler string) ([]OrderDetailsInRange, error)

func (*Monitor) InsertBalance

func (m *Monitor) InsertBalance(balance DbBalance) error

func (*Monitor) InsertEthTxResponse

func (m *Monitor) InsertEthTxResponse(txResponse EthTxDetails, network string, storeRawResponse bool) error

func (*Monitor) InsertOrderFilled

func (m *Monitor) InsertOrderFilled(order DbOrderFilled) error

func (*Monitor) InsertRawTxResponse

func (m *Monitor) InsertRawTxResponse(txResponse DbTxResponse) error

func (*Monitor) InsertUsdPrice

func (m *Monitor) InsertUsdPrice(denom string, price float64) error

func (*Monitor) LoadFromFile

func (m *Monitor) LoadFromFile(path string, saveRawResponses bool)

func (*Monitor) LoadMissingOrderFromFile

func (m *Monitor) LoadMissingOrderFromFile(path string)

func (*Monitor) OrdersFromFile

func (m *Monitor) OrdersFromFile(filePath string) ([]DbOrderFilled, []*DbTxResponse, error)

func (*Monitor) ReadMaxAmountInOrdersByFiller

func (m *Monitor) ReadMaxAmountInOrdersByFiller(filler string) ([]DbOrderFilled, error)

func (*Monitor) ReadMaxSolverRevenueOrders

func (m *Monitor) ReadMaxSolverRevenueOrders(filler string) ([]DbOrderFilled, error)

func (*Monitor) RunAll

func (m *Monitor) RunAll(wg *sync.WaitGroup, saveRawResponses bool)

func (*Monitor) RunArbitrumBalances

func (m *Monitor) RunArbitrumBalances() int

func (*Monitor) RunArbitrumTxHistory

func (m *Monitor) RunArbitrumTxHistory(saveRawResponses bool)

func (*Monitor) RunAvalancheBalances

func (m *Monitor) RunAvalancheBalances()

func (*Monitor) RunAvalancheTxHistory

func (m *Monitor) RunAvalancheTxHistory(saveRawResponses bool)

func (*Monitor) RunBaseBalances

func (m *Monitor) RunBaseBalances() int

func (*Monitor) RunBaseTxHistory

func (m *Monitor) RunBaseTxHistory(saveRawResponses bool)

func (*Monitor) RunEthereumBalances

func (m *Monitor) RunEthereumBalances() int

ethereum balances are handled as strings and stored as strings in the db sqlite cannot store 256 bit integers, so we use strings to get around that

func (*Monitor) RunEthereumTxHistory

func (m *Monitor) RunEthereumTxHistory(saveRawResponses bool)

func (*Monitor) RunOrders

func (m *Monitor) RunOrders(saveRawResponses bool)

func (*Monitor) RunOsmosisBalances

func (m *Monitor) RunOsmosisBalances()

type NetworkFeeStats

type NetworkFeeStats struct {
	TotalGasUSD  string `json:"total_gas_usd"`
	TotalGasETH  string `json:"total_gas_eth"`
	TotalGasAVAX string `json:"total_gas_avax"`
	TxCount      int64  `json:"tx_count"`
	Network      string `json:"network"`
}

type NetworkOrderStats

type NetworkOrderStats struct {
	TotalSolverRevenue int64  `json:"total_solver_revenue"`
	OrderCount         int64  `json:"order_count"`
	Network            string `json:"network"`
}

type NetworkStatsResponse

type NetworkStatsResponse struct {
	TotalSolverRevenue string `json:"total_solver_revenue"`
	OrderCount         string `json:"order_count"`
	Network            string `json:"network"`
}

type OrderDetailsInRange

type OrderDetailsInRange struct {
	AmountRange           string  `json:"amount_range"`
	TotalOrdersInRange    int     `json:"total_orders_in_range"`
	ExecutedOrdersInRange int     `json:"executed_orders_in_range"`
	Filler                string  `json:"filler"`
	TotalVolume           float64 `json:"total_volume"`
	AvgTransfer           float64 `json:"avg_transfer"`
	MinTransfer           float64 `json:"min_transfer"`
	MaxTransfer           float64 `json:"max_transfer"`
	SourceDomain          uint32  `json:"source_domain"`
}

type OrderEnvelope

type OrderEnvelope struct {
	Order  *FastTransferOrder `json:"order"`
	Filler string             `json:"filler"`
}

type OrderStatsSummary

type OrderStatsSummary struct {
	TotalSolverRevenue int64               `json:"total_solver_revenue"`
	TotalOrderCount    int64               `json:"total_order_count"`
	NetworkOrderStats  []NetworkOrderStats `json:"networks"`
}

type OrderWithMeta

type OrderWithMeta struct {
	FastTransferOrder
	Code               int       `json:"code"`
	TxHash             string    `json:"tx_hash"`
	Height             int       `json:"height"`
	SolverRevenue      int       `json:"solver_revenue"`
	IngestionTimestamp time.Time `json:"ingestion_timestamp"`
}

enrich with db fields

type OrdersFilledStatsResponse

type OrdersFilledStatsResponse struct {
	TotalSolverRevenue string                 `json:"total_solver_revenue"`
	TotalOrderCount    string                 `json:"total_order_count"`
	NetworkStats       []NetworkStatsResponse `json:"networks"`
}

type OsmosisConfig

type OsmosisConfig struct {
	ChainEntry
	SolverConfig
}

type PriceResponse

type PriceResponse map[string]UsdPrice

Response example from API:

{
    "ethereum": {
        "usd": 3265.89
    },
    "osmosis": {
        "usd": 0.40659
    }
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(monitor *Monitor) *Server

func (*Server) RunWithContext

func (s *Server) RunWithContext(ctx context.Context, addr string) error

type ShortBlockResp

type ShortBlockResp struct {
	Block struct {
		Header struct {
			Version struct {
				Block string `json:"block"`
				App   string `json:"app"`
			} `json:"version"`
			ChainID string    `json:"chain_id"`
			Height  string    `json:"height"`
			Time    time.Time `json:"time"`
		} `json:"header"`
	} `json:"block"`
}

don't want to mess widh cosmos/comet encoders again...

type SolverConfig

type SolverConfig struct {
	SolverAddress   string `json:"solver_address,omitempty" yaml:"solver_address,omitempty" toml:"solver_address,omitempty"`
	ContractAddress string `json:"contract_address,omitempty" yaml:"contract_address,omitempty" toml:"contract_address,omitempty"`
}

type TxsFile

type TxsFile struct {
	TxResponses []interface{} `json:"tx_responses"`
	Txs         []interface{} `json:"txs"`
}

type UsdPrice

type UsdPrice struct {
	USD float64 `json:"usd"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL