一个模块化工具,可跟踪 EVM 链上的任何内容,包括实时跟踪和警报。
A modular tool to track and process anything on an EVM chain, including events, transactions and blocks.
Logging events from specific contracts, transactions from specific addresses, and blocks mined, either in realtime or historically
Scanning for contracts deployed by deployment transactions, for specific bytecodes
Tracking the volume of uniswap v2 & v3 pools, alerting via Discord webhook when there is a significant percentage change
Monitoring for ownership transfers and proxy upgrades
Tracking the common exploit pattern of withdrawing from Tornado.Cash then deploying a contract
Graphing funding paths, for both native ETH and ERC20 tokens to visualize transfers of funds
Usage:
go run main.go track --config
List actions: go run main.go actions
go run main.go actions Whether to track events or blocks is automatically determined (based on what data the actions require), but you can also explicitly state what to track by putting blocks or events after historical/realtime.
events will use eth_subscribe to listen for logs, thus only events can be processedblocks will use eth_subscribe to listen for newHeads, thus new blocks and transactions in those blocks can be tracked. As for events, another eth_getFilterLogs query is used to fetch all events in that block.
Therefore, blocks is recommended as it allows events, txs and blocks to be tracked.There is also an option for requesting historical data across a block range, in which case:
events will use eth_getFilterLogs to fetch event logs across multiple blocks, stepping a set amount of blocks at once (default 10000)blocks will use eth_getBlockByNumber to fetch blocks and transactions in those blocks, then another call to eth_getFilterLogs for events in that block.
Therefore, events is recommended if only event logs are required, as it is much faster, being able to query a wide range of blocks in a single call.All events, txs and blocks will be sent to actions, which are specified in the config file.
Examples:
go run main.go track realtime blocks --config ./config.jsonconfig.json, the Logging action is used with the contract address in its settings (see Actions)go run main.go track historical blocks --config ./config.json --from-block 1337 --to-block 2000--from-block 2000 --to-block 1337The config file should contain what actions you want to run, and options for those actions. You should also specify the RPC URL there.
Basic structure:
{
"rpcurl": "wss://...",
"actions": {
"ActionName": {
"addresses": {
"0xAA...": { "name": "optional contract name 1" },
"0xBB...": { "name": "optional contract name 2" }
},
"options": {
"custom-option-1": "something"
}
},
"AnotherAction": {
"addresses": {
"0xCC...": { "name": "optional contract name 1" }
},
"options": {
"custom-option-2": "something"
}
}
}
}"rpcurl" must be Websocket (wss:// or ws://)"actions" contains multiple actions to run, each with their own addresses to track["0xAA...", "0xBB...", "0xCC..."]. The same applies for event signatures."options" are custom options specific for each action. To see custom options for each action, list all actions (that are documented) using go run main.go actionsThe example config below logs info for 0xA0b8... using the Logging action, and also records Tornado.Cash deposits/withdrawals for contract 0x910C... using the TornadoCash action:
…There are also options specific to events. You shouldn't need to use these, unless you need to filter by events and it has to be fast. Both of these are optional.
"event-signatures" - List of event signatures (unhashed) to filter by"event-signatures":["Stored(uint256)", Retrieved(uint256)]"event-topics" - Nested list of event topics to filter by. This explains it better. Event signatures provided from "event-signatures" are aggregated with this and placed in the first index as topic 0. [[],["0x0000000000000000000000000000000000000000000000000000000000000539"]]Actions are golang code that 'postprocesses' data received from the trackooor.
Every time there is an event, transaction or block mined, action functions will be called depending on if the data (e.g. event sig, address) is being tracked.
For example, if you want to track transactions from/to an address, you add the address to a transaction address -> action functions mapping.
There are already premade actions, such as Logging, which simply outputs the data received.
Run go run main.go actions to list all actions (that have descriptions written).
Run go run main.go actions to search for actions and list their custom options and example config.
However, you can write your own actions for your own purposes.
To make your own custom actions, create a file in actions/, such as actions/action_logging.go.
Each action has an initialization function, which will be called right before the trackooor starts. Registering what to listen for is usually done in this init function. The init function must start with Init and be a method of the action type. After the Init word should be your action name. This is important - your action name must be the same for other special functions (see action info and finished functions)
For example, func (p action) InitLogging() {} is the Init function with action name Logging.
The action type struct contains action options, which include addresses, event sigs and custom options:
type action struct {
o shared.ActionOptions
}type ActionOptions struct {
Addresses []common.Address // addresses specific to each action
EventSigs []common.Hash // event sigs specific to each action
CustomOptions map[string]interface{} // custom options specific to each action
}All of these options will be specified by the user in the config file. The reason Addresses and EventSigs are separate is because when running the trackooor, there are (usually) multiple actions ran at the same time, thus if using a filter log, the trackooor aggregates addresses and event sigs into a single filter log.
Custom options are JSON inputs by the user in the config file, actions should have their own info on what custom options they require.
Each action is responsible for registering what events/txs/blocks to listen for.
For example, if you wish to call logTx() when transactions are receieved from addresses in Addresses, you can loop through Addresses and call addTxAddressAction():
func (p action) InitLogging() {
...
for _, address := range p.o.Addresses {
addTxAddressAction(address, logTransaction)
}
...
}There are 5 functions to add tracking for events/txs/blocks:
addEventSigAction() adds event sig string to event sig -> action funcs map, tracking all events that match that event sigaddAddressEventSigAction() adds an event sig string and contract address to contract address -> event sig -> action funcs map, tracking a specific event from a specific contractaddAddressEventAction() adds contract address to contract address -> action funcs map, essentially calling action functions regardless of event signatureindexed bytes32 and put a keccak hash of a valid event signature, but not actually have the relevant topics/data. As such, when using addEventSigAction(), you should first check if the mapping (e.g p.DecodedTopics["from"]) exists.addTxAddressAction() adds an address to address -> action funcs map, tracking all transactions to and from an addressaddBlockAction() adds an action func to action funcs array, which will be called every time a new block is minedAction functions process the received data.
They can take either event, transaction or block data:
type ActionEventData struct {
EventLog types.Log
EventFields shared.EventFields
DecodedTopics map[string]interface{}
DecodedData map[string]interface{}
}
type ActionTxData struct {
Transaction *types.Transaction
From *common.Address
To *common.Address
Block *types.Block // block which the tx was in
}
type ActionBlockData struct {
Block *types.Block
}For example, checking a transaction calldata takes transaction data, thus ActionTxData:
func checkFunctionCall(p ActionTxData) {
// continue only if tx was contract interaction
txType := shared.DetermineTxType(p.Transaction, p.Block.Number())
if txType != shared.ContractTx {
return
}
// get tx To and From
to := p.To
from := p.From
// get tx calldata
txData := p.Transaction.Data()
// get tx func selector
txFuncSig := txData[:4]
...
}For ActionEventData:
EventFields contains event fields, where each field contains field name, type, and whether that field is indexedDecodedTopics and DecodedData are decoded according to their event ABI, and map the event field name to the value. Topics are indexed fields, while Data are unindexed.event Transfer(address indexed from, address indexed to, uint256 value); will have from and to in DecodedTopics and value in DecodedData. You will need to type assert them in the action function, such as to := p.DecodedTopics["to"].(common.Address).For example, processing a ERC20 transfer event:
func ProcessERC20Transfer(p ActionEventData) {
tokenAddress := p.EventLog.Address
from := p.DecodedTopics["from"].(common.Address)
to := p.DecodedTopics["to"].(common.Address)
value := p.DecodedData["value"].(*big.Int)
...
}"Finished" functions are called when the trackooor ends, which only happens in historical tracking.
This can be useful for things like saving data to a file after tracking across a certain block range.
Defining a finished function is similar to init functions, where it must be a method of the action type, and function name must start with Finished. After Finished should be the action name, identical to the init function's action name.
For example, the TornadoCash action will have finisher function func (p action) FinishedTornadoCash() {}.
Since action functions are run in async, you should ensure any time-consuming action funcs have finished before proceeding.
Example for the TornadoCash action:
// function called after historical processor is finished
func (p action) FinishedTornadoCash() {
// wait for async funcs to finish
RpcW暂无开放 Issues,或尚未同步最近议题。