espresso_types/v0/v0_1/
fee_info.rs

1use alloy::primitives::{Address, U256};
2use alloy_compat::ethers_serde;
3use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
4use derive_more::{Add, Display, From, Into, Mul, Sub};
5use jf_merkle_tree::{MerkleTreeScheme, UniversalMerkleTreeScheme};
6use serde::{Deserialize, Serialize};
7
8use crate::FeeMerkleTree;
9
10// New Type for `U256` in order to implement `CanonicalSerialize` and
11// `CanonicalDeserialize`
12#[derive(
13    Default,
14    Hash,
15    Copy,
16    Clone,
17    Debug,
18    Display,
19    PartialEq,
20    Eq,
21    PartialOrd,
22    Ord,
23    Add,
24    Sub,
25    Mul,
26    From,
27    Into,
28)]
29#[display("{_0}")]
30pub struct FeeAmount(pub U256);
31
32// New Type for `Address` in order to implement `CanonicalSerialize` and
33// `CanonicalDeserialize`
34#[derive(
35    Default,
36    Hash,
37    Copy,
38    Clone,
39    Debug,
40    Display,
41    Deserialize,
42    Serialize,
43    PartialEq,
44    Eq,
45    PartialOrd,
46    Ord,
47    From,
48    Into,
49)]
50#[display("{_0:x}")]
51#[serde(transparent)]
52pub struct FeeAccount(#[serde(with = "ethers_serde::address")] pub Address);
53
54#[derive(
55    Hash,
56    Copy,
57    Clone,
58    Debug,
59    Deserialize,
60    Serialize,
61    PartialEq,
62    Eq,
63    CanonicalSerialize,
64    CanonicalDeserialize,
65)]
66/// `FeeInfo` holds data related to builder fees.
67pub struct FeeInfo {
68    pub account: FeeAccount,
69    pub amount: FeeAmount,
70}
71
72/// A proof of the balance of an account in the fee ledger.
73///
74/// If the account of interest does not exist in the fee state, this is a Merkle non-membership
75/// proof, and the balance is implicitly zero. Otherwise, this is a normal Merkle membership proof.
76#[derive(Clone, Debug, Deserialize, Serialize)]
77pub struct FeeAccountProof {
78    pub account: Address,
79    pub proof: FeeMerkleProof,
80}
81
82#[derive(Clone, Debug, Deserialize, Serialize)]
83pub enum FeeMerkleProof {
84    Presence(<FeeMerkleTree as MerkleTreeScheme>::MembershipProof),
85    Absence(<FeeMerkleTree as UniversalMerkleTreeScheme>::NonMembershipProof),
86}
87
88#[derive(Clone, Debug, Serialize, Deserialize)]
89pub struct AccountQueryData {
90    pub balance: U256,
91    pub proof: FeeAccountProof,
92}