openzeppelin_monitor/models/core/monitor.rs
1use serde::{Deserialize, Serialize};
2
3use crate::models::blockchain::ContractSpec;
4
5/// Configuration for monitoring specific blockchain activity.
6///
7/// A Monitor defines what blockchain activity to watch for through a combination of:
8/// - Network targets (which chains to monitor)
9/// - Contract addresses to watch
10/// - Conditions to match (functions, events, transactions)
11/// - Triggers conditions refers to a custom filter script that being executed apply extra filters
12/// to the matched transactions before triggering the notifications
13/// - Triggers to execute when conditions are met
14#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
15#[serde(deny_unknown_fields)]
16pub struct Monitor {
17 /// Unique name identifying this monitor
18 pub name: String,
19
20 /// List of network slugs this monitor should watch
21 pub networks: Vec<String>,
22
23 /// Whether this monitor is currently paused
24 pub paused: bool,
25
26 /// Contract addresses to monitor, optionally with their contract specs
27 pub addresses: Vec<AddressWithSpec>,
28
29 /// Conditions that should trigger this monitor
30 pub match_conditions: MatchConditions,
31
32 /// Conditions that should be met prior to triggering notifications
33 pub trigger_conditions: Vec<TriggerConditions>,
34
35 /// IDs of triggers to execute when conditions match
36 pub triggers: Vec<String>,
37}
38
39/// Contract address with optional ABI for decoding transactions and events
40#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
41#[serde(deny_unknown_fields)]
42pub struct AddressWithSpec {
43 /// Contract address in the network's native format
44 pub address: String,
45
46 /// Optional contract spec for decoding contract interactions
47 pub contract_spec: Option<ContractSpec>,
48}
49
50/// Collection of conditions that can trigger a monitor
51#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
52#[serde(deny_unknown_fields)]
53pub struct MatchConditions {
54 /// Function calls to match
55 pub functions: Vec<FunctionCondition>,
56
57 /// Events to match
58 pub events: Vec<EventCondition>,
59
60 /// Transaction states to match
61 pub transactions: Vec<TransactionCondition>,
62}
63
64/// Condition for matching contract function calls
65#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
66#[serde(deny_unknown_fields)]
67pub struct FunctionCondition {
68 /// Function signature (e.g., "transfer(address,uint256)")
69 pub signature: String,
70
71 /// Optional expression to filter function parameters
72 pub expression: Option<String>,
73}
74
75/// Condition for matching contract events
76#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
77#[serde(deny_unknown_fields)]
78pub struct EventCondition {
79 /// Event signature (e.g., "Transfer(address,address,uint256)")
80 pub signature: String,
81
82 /// Optional expression to filter event parameters
83 pub expression: Option<String>,
84}
85
86/// Condition for matching transaction states
87#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
88#[serde(deny_unknown_fields)]
89pub struct TransactionCondition {
90 /// Required transaction status
91 pub status: TransactionStatus,
92
93 /// Optional expression to filter transaction properties
94 pub expression: Option<String>,
95}
96
97/// Possible transaction execution states
98#[derive(Debug, Copy, Clone, Deserialize, Serialize, PartialEq)]
99#[serde(deny_unknown_fields)]
100pub enum TransactionStatus {
101 /// Match any transaction status
102 Any,
103 /// Match only successful transactions
104 Success,
105 /// Match only failed transactions
106 Failure,
107}
108
109/// Conditions that should be met prior to triggering notifications
110#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
111#[serde(deny_unknown_fields)]
112pub struct TriggerConditions {
113 /// The path to the script
114 pub script_path: String,
115
116 /// The arguments of the script
117 #[serde(default)]
118 pub arguments: Option<Vec<String>>,
119
120 /// The language of the script
121 pub language: ScriptLanguage,
122
123 /// The timeout of the script
124 pub timeout_ms: u32,
125}
126/// The possible languages of the script
127#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Hash, Eq)]
128pub enum ScriptLanguage {
129 JavaScript,
130 Python,
131 Bash,
132}