agglayer_types/
settlement.rs1use std::time::SystemTime;
2
3use alloy::primitives::Bytes;
4
5use crate::{Address, SettlementTxHash, B256, U256};
6
7#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, derive_more::Display)]
8pub struct SettlementAttemptNumber(pub u64);
9
10#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, derive_more::Display)]
11pub struct Nonce(pub u64);
12
13impl Nonce {
14 pub fn previous(&self) -> Option<Nonce> {
15 self.0.checked_sub(1).map(Nonce)
16 }
17}
18
19#[derive(Clone, Debug, Eq, PartialEq)]
20pub struct SettlementJob {
21 pub contract_address: Address,
22 pub calldata: Bytes,
23 pub eth_value: U256,
24 pub gas_limit: u128,
25 pub max_fee_per_gas_ceiling: u128,
26 pub max_fee_per_gas_floor: u128,
27 pub max_fee_per_gas_increase_percents: u32,
28 pub max_priority_fee_per_gas_ceiling: u128,
29 pub max_priority_fee_per_gas_floor: u128,
30 pub max_priority_fee_per_gas_increase_percents: u32,
31}
32
33#[derive(Clone, Debug, Eq, PartialEq)]
34pub enum SettlementJobResult {
35 ContractCall(ContractCallResult),
36}
37
38#[derive(Clone, Debug, Eq, PartialEq)]
39pub enum SettlementAttemptResult {
40 ClientError(ClientError),
41 ContractCall(ContractCallResult),
42}
43
44#[derive(Clone, Debug, Eq, PartialEq)]
45pub struct ClientError {
46 pub kind: ClientErrorType,
47 pub message: String,
48}
49
50#[derive(Clone, Debug, Eq, PartialEq)]
51pub enum ClientErrorType {
52 Unknown,
53 NonceAlreadyUsed,
54}
55
56impl ClientError {
57 pub fn nonce_already_used(address: Address, nonce: Nonce, tx_hash: SettlementTxHash) -> Self {
58 Self {
59 kind: ClientErrorType::NonceAlreadyUsed,
60 message: format!(
61 "Nonce already used: for {address}/{nonce}, the settled tx is {tx_hash}"
62 ),
63 }
64 }
65
66 pub fn timeout_waiting_for_inclusion() -> Self {
67 Self {
68 kind: ClientErrorType::Unknown,
69 message: "Timeout waiting for inclusion on L1".to_string(),
70 }
71 }
72}
73
74#[derive(Clone, Debug, Eq, PartialEq)]
75pub struct ContractCallResult {
76 pub outcome: ContractCallOutcome,
77 pub metadata: Bytes,
78 pub block_hash: B256,
79 pub block_number: u64,
80 pub tx_hash: SettlementTxHash,
81}
82
83#[derive(Clone, Debug, Eq, PartialEq)]
84pub enum ContractCallOutcome {
85 Success,
86 Revert,
87}
88
89#[derive(Clone, Debug, Eq, PartialEq)]
90pub struct SettlementAttempt {
91 pub sender_wallet: Address,
92 pub nonce: Nonce,
93 pub max_fee_per_gas: u128,
94 pub max_priority_fee_per_gas: u128,
95 pub hash: SettlementTxHash,
96 pub submission_time: SystemTime,
97}