1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct Transaction {
6 pub to: String,
8 pub data: String,
10 pub value: String,
12}
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21#[repr(u8)]
22pub enum RelayerTxType {
23 Eoa = 0,
25 Proxy = 1,
27 Safe = 2,
29}
30
31impl RelayerTxType {
32 pub fn as_str(&self) -> &'static str {
33 match self {
34 RelayerTxType::Eoa => "EOA",
35 RelayerTxType::Proxy => "PROXY",
36 RelayerTxType::Safe => "SAFE",
37 }
38 }
39
40 pub fn signature_type(&self) -> u8 {
42 *self as u8
43 }
44
45 pub fn from_signature_type(sig_type: u8) -> Option<Self> {
47 match sig_type {
48 0 => Some(RelayerTxType::Eoa),
49 1 => Some(RelayerTxType::Proxy),
50 2 => Some(RelayerTxType::Safe),
51 _ => None,
52 }
53 }
54}
55
56#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
58#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
59pub enum TxState {
60 New,
61 Executed,
62 Mined,
63 Confirmed,
64 Failed,
65 Invalid,
66}
67
68impl TxState {
69 pub fn is_terminal(&self) -> bool {
70 matches!(self, TxState::Confirmed | TxState::Failed | TxState::Invalid)
71 }
72
73 pub fn is_success(&self) -> bool {
74 matches!(self, TxState::Mined | TxState::Confirmed)
75 }
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(rename_all = "camelCase")]
81pub struct RelayerTransactionResponse {
82 #[serde(rename = "transactionID", alias = "transactionId")]
83 pub transaction_id: String,
84 pub state: String,
85 #[serde(default)]
86 pub hash: Option<String>,
87 #[serde(default, rename = "transactionHash")]
88 pub transaction_hash: Option<String>,
89}
90
91#[derive(Debug, Clone)]
93pub struct TxResult {
94 pub state: TxState,
95 pub tx_hash: Option<String>,
96 pub proxy_address: Option<String>,
97 pub error: Option<String>,
98}
99
100#[derive(Debug, Clone, Serialize)]
102#[serde(rename_all = "camelCase")]
103pub struct SafeSignatureParams {
104 pub gas_price: String,
105 pub operation: String,
106 pub safe_txn_gas: String,
107 pub base_gas: String,
108 pub gas_token: String,
109 pub refund_receiver: String,
110}
111
112impl Default for SafeSignatureParams {
113 fn default() -> Self {
114 Self {
115 gas_price: "0".to_string(),
116 operation: "0".to_string(),
117 safe_txn_gas: "0".to_string(),
118 base_gas: "0".to_string(),
119 gas_token: "0x0000000000000000000000000000000000000000".to_string(),
120 refund_receiver: "0x0000000000000000000000000000000000000000".to_string(),
121 }
122 }
123}
124
125#[derive(Debug, Clone, Serialize)]
127#[serde(rename_all = "camelCase")]
128pub struct ProxySignatureParams {
129 pub gas_price: String,
130 pub gas_limit: String,
131 pub relayer_fee: String,
132 pub relay_hub: String,
133 pub relay: String,
134}
135
136#[derive(Debug, Clone, Serialize)]
138#[serde(rename_all = "camelCase")]
139pub struct CreateSignatureParams {
140 pub payment_token: String,
141 pub payment: String,
142 pub payment_receiver: String,
143}
144
145impl Default for CreateSignatureParams {
146 fn default() -> Self {
147 Self {
148 payment_token: "0x0000000000000000000000000000000000000000".to_string(),
149 payment: "0".to_string(),
150 payment_receiver: "0x0000000000000000000000000000000000000000".to_string(),
151 }
152 }
153}
154
155#[derive(Debug, Clone, Serialize)]
164#[serde(rename_all = "camelCase")]
165pub struct TransactionRequest {
166 #[serde(rename = "type")]
167 pub tx_type: String,
168 pub from: String,
169 pub to: String,
170 #[serde(skip_serializing_if = "Option::is_none")]
171 pub proxy_wallet: Option<String>,
172 #[serde(skip_serializing_if = "Option::is_none")]
173 pub data: Option<String>,
174 #[serde(skip_serializing_if = "Option::is_none")]
175 pub signature: Option<String>,
176 #[serde(skip_serializing_if = "Option::is_none")]
177 pub nonce: Option<String>,
178 #[serde(skip_serializing_if = "Option::is_none")]
179 pub signature_params: Option<serde_json::Value>,
180 #[serde(skip_serializing_if = "Option::is_none")]
181 pub metadata: Option<String>,
182 #[serde(skip_serializing_if = "Option::is_none")]
183 pub value: Option<String>,
184 #[serde(skip_serializing_if = "Option::is_none")]
185 pub deposit_wallet_params: Option<DepositWalletParams>,
186}
187
188#[derive(Debug, Clone, Serialize, Deserialize)]
193pub struct DepositWalletCall {
194 pub target: String,
195 pub value: String,
196 pub data: String,
197}
198
199impl DepositWalletCall {
200 pub fn new(target: impl Into<String>, data: impl Into<String>) -> Self {
202 Self {
203 target: target.into(),
204 value: "0".to_string(),
205 data: data.into(),
206 }
207 }
208}
209
210impl From<Transaction> for DepositWalletCall {
211 fn from(tx: Transaction) -> Self {
214 Self {
215 target: tx.to,
216 value: tx.value,
217 data: tx.data,
218 }
219 }
220}
221
222#[derive(Debug, Clone, Serialize, Deserialize)]
224#[serde(rename_all = "camelCase")]
225pub struct DepositWalletParams {
226 pub deposit_wallet: String,
227 pub deadline: String,
228 pub calls: Vec<DepositWalletCall>,
229}
230
231#[derive(Debug, Clone, Deserialize)]
233pub struct RelayPayload {
234 pub address: String,
235 pub nonce: String,
236}