openzeppelin_monitor/models/core/
monitor.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use serde::{Deserialize, Serialize};

use crate::models::blockchain::ContractSpec;

/// Configuration for monitoring specific blockchain activity.
///
/// A Monitor defines what blockchain activity to watch for through a combination of:
/// - Network targets (which chains to monitor)
/// - Contract addresses to watch
/// - Conditions to match (functions, events, transactions)
/// - Triggers conditions refers to a custom filter script that being executed apply extra filters
///   to the matched transactions before triggering the notifications
/// - Triggers to execute when conditions are met
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
#[serde(deny_unknown_fields)]
pub struct Monitor {
	/// Unique name identifying this monitor
	pub name: String,

	/// List of network slugs this monitor should watch
	pub networks: Vec<String>,

	/// Whether this monitor is currently paused
	pub paused: bool,

	/// Contract addresses to monitor, optionally with their contract specs
	pub addresses: Vec<AddressWithSpec>,

	/// Conditions that should trigger this monitor
	pub match_conditions: MatchConditions,

	/// Conditions that should be met prior to triggering notifications
	pub trigger_conditions: Vec<TriggerConditions>,

	/// IDs of triggers to execute when conditions match
	pub triggers: Vec<String>,
}

/// Contract address with optional ABI for decoding transactions and events
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct AddressWithSpec {
	/// Contract address in the network's native format
	pub address: String,

	/// Optional contract spec for decoding contract interactions
	pub contract_spec: Option<ContractSpec>,
}

/// Collection of conditions that can trigger a monitor
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
#[serde(deny_unknown_fields)]
pub struct MatchConditions {
	/// Function calls to match
	pub functions: Vec<FunctionCondition>,

	/// Events to match
	pub events: Vec<EventCondition>,

	/// Transaction states to match
	pub transactions: Vec<TransactionCondition>,
}

/// Condition for matching contract function calls
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct FunctionCondition {
	/// Function signature (e.g., "transfer(address,uint256)")
	pub signature: String,

	/// Optional expression to filter function parameters
	pub expression: Option<String>,
}

/// Condition for matching contract events
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct EventCondition {
	/// Event signature (e.g., "Transfer(address,address,uint256)")
	pub signature: String,

	/// Optional expression to filter event parameters
	pub expression: Option<String>,
}

/// Condition for matching transaction states
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct TransactionCondition {
	/// Required transaction status
	pub status: TransactionStatus,

	/// Optional expression to filter transaction properties
	pub expression: Option<String>,
}

/// Possible transaction execution states
#[derive(Debug, Copy, Clone, Deserialize, Serialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub enum TransactionStatus {
	/// Match any transaction status
	Any,
	/// Match only successful transactions
	Success,
	/// Match only failed transactions
	Failure,
}

/// Conditions that should be met prior to triggering notifications
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct TriggerConditions {
	/// The path to the script
	pub script_path: String,

	/// The arguments of the script
	#[serde(default)]
	pub arguments: Option<Vec<String>>,

	/// The language of the script
	pub language: ScriptLanguage,

	/// The timeout of the script
	pub timeout_ms: u32,
}
/// The possible languages of the script
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub enum ScriptLanguage {
	JavaScript,
	Python,
	Bash,
}