use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Transaction {
pub to: String,
pub data: String,
pub value: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum RelayerTxType {
Eoa = 0,
Proxy = 1,
Safe = 2,
}
impl RelayerTxType {
pub fn as_str(&self) -> &'static str {
match self {
RelayerTxType::Eoa => "EOA",
RelayerTxType::Proxy => "PROXY",
RelayerTxType::Safe => "SAFE",
}
}
pub fn signature_type(&self) -> u8 {
*self as u8
}
pub fn from_signature_type(sig_type: u8) -> Option<Self> {
match sig_type {
0 => Some(RelayerTxType::Eoa),
1 => Some(RelayerTxType::Proxy),
2 => Some(RelayerTxType::Safe),
_ => None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum TxState {
New,
Executed,
Mined,
Confirmed,
Failed,
Invalid,
}
impl TxState {
pub fn is_terminal(&self) -> bool {
matches!(self, TxState::Confirmed | TxState::Failed | TxState::Invalid)
}
pub fn is_success(&self) -> bool {
matches!(self, TxState::Mined | TxState::Confirmed)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RelayerTransactionResponse {
#[serde(rename = "transactionID", alias = "transactionId")]
pub transaction_id: String,
pub state: String,
#[serde(default)]
pub hash: Option<String>,
#[serde(default, rename = "transactionHash")]
pub transaction_hash: Option<String>,
}
#[derive(Debug, Clone)]
pub struct TxResult {
pub state: TxState,
pub tx_hash: Option<String>,
pub proxy_address: Option<String>,
pub error: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SafeSignatureParams {
pub gas_price: String,
pub operation: String,
pub safe_txn_gas: String,
pub base_gas: String,
pub gas_token: String,
pub refund_receiver: String,
}
impl Default for SafeSignatureParams {
fn default() -> Self {
Self {
gas_price: "0".to_string(),
operation: "0".to_string(),
safe_txn_gas: "0".to_string(),
base_gas: "0".to_string(),
gas_token: "0x0000000000000000000000000000000000000000".to_string(),
refund_receiver: "0x0000000000000000000000000000000000000000".to_string(),
}
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ProxySignatureParams {
pub gas_price: String,
pub gas_limit: String,
pub relayer_fee: String,
pub relay_hub: String,
pub relay: String,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateSignatureParams {
pub payment_token: String,
pub payment: String,
pub payment_receiver: String,
}
impl Default for CreateSignatureParams {
fn default() -> Self {
Self {
payment_token: "0x0000000000000000000000000000000000000000".to_string(),
payment: "0".to_string(),
payment_receiver: "0x0000000000000000000000000000000000000000".to_string(),
}
}
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TransactionRequest {
#[serde(rename = "type")]
pub tx_type: String,
pub from: String,
pub to: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub proxy_wallet: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub signature: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub nonce: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub signature_params: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub deposit_wallet_params: Option<DepositWalletParams>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DepositWalletCall {
pub target: String,
pub value: String,
pub data: String,
}
impl DepositWalletCall {
pub fn new(target: impl Into<String>, data: impl Into<String>) -> Self {
Self {
target: target.into(),
value: "0".to_string(),
data: data.into(),
}
}
}
impl From<Transaction> for DepositWalletCall {
fn from(tx: Transaction) -> Self {
Self {
target: tx.to,
value: tx.value,
data: tx.data,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DepositWalletParams {
pub deposit_wallet: String,
pub deadline: String,
pub calls: Vec<DepositWalletCall>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct RelayPayload {
pub address: String,
pub nonce: String,
}