espresso_types/v0/v0_3/
state.rs1use alloy::primitives::{Address, U256};
2use derive_more::{derive::AddAssign, Add, Display, From, Into, Mul, Sub};
3use jf_merkle_tree::{
4 prelude::{Sha3Digest, Sha3Node},
5 universal_merkle_tree::UniversalMerkleTree,
6 MerkleTreeScheme, UniversalMerkleTreeScheme,
7};
8use serde::{Deserialize, Serialize};
9
10pub const REWARD_MERKLE_TREE_V1_HEIGHT: usize = 20;
11const REWARD_MERKLE_TREE_V1_ARITY: usize = 256;
12
13pub type RewardMerkleTreeV1 = UniversalMerkleTree<
14 RewardAmount,
15 Sha3Digest,
16 RewardAccountV1,
17 REWARD_MERKLE_TREE_V1_ARITY,
18 Sha3Node,
19>;
20
21pub type RewardMerkleCommitmentV1 = <RewardMerkleTreeV1 as MerkleTreeScheme>::Commitment;
22
23#[derive(
28 Default,
29 Hash,
30 Copy,
31 Clone,
32 Debug,
33 Display,
34 Deserialize,
35 Serialize,
36 PartialEq,
37 Eq,
38 PartialOrd,
39 Ord,
40 From,
41 Into,
42)]
43#[display("{_0:x}")]
44pub struct RewardAccountV1(pub Address);
45
46#[derive(
49 Default,
50 Hash,
51 Copy,
52 Clone,
53 Debug,
54 Display,
55 PartialEq,
56 Eq,
57 PartialOrd,
58 Ord,
59 Add,
60 Sub,
61 Mul,
62 From,
63 Into,
64 AddAssign,
65)]
66#[display("{_0}")]
67pub struct RewardAmount(pub U256);
68
69pub(crate) const INFLATION_RATE: u128 = 300; pub(crate) const ASSUMED_BLOCK_TIME_SECONDS: u128 = 2;
71pub(crate) const SECONDS_PER_YEAR: u128 = 60 * 60 * 24 * 365;
72pub(crate) const MILLISECONDS_PER_YEAR: u128 = 86_400_000 * 365;
73pub(crate) const BLOCKS_PER_YEAR: u128 = SECONDS_PER_YEAR / ASSUMED_BLOCK_TIME_SECONDS;
74pub const COMMISSION_BASIS_POINTS: u16 = 10_000;
75
76#[derive(Clone, Debug, Serialize, Deserialize)]
77pub struct RewardAccountQueryDataV1 {
78 pub balance: U256,
79 pub proof: RewardAccountProofV1,
80}
81
82#[derive(Clone, Debug, Deserialize, Serialize)]
83pub struct RewardAccountProofV1 {
84 pub account: Address,
85 pub proof: RewardMerkleProofV1,
86}
87
88#[derive(Clone, Debug, Deserialize, Serialize)]
89pub enum RewardMerkleProofV1 {
90 Presence(<RewardMerkleTreeV1 as MerkleTreeScheme>::MembershipProof),
91 Absence(<RewardMerkleTreeV1 as UniversalMerkleTreeScheme>::NonMembershipProof),
92}