hotshot_contract_adapter/
sol_types.rs

1//! Solidity types for interacting with contracts
2//! Re-export types that are used, sometimes renamed to avoid collision.
3//!
4//! TODO: (alex) Due to <https://github.com/foundry-rs/foundry/issues/10153>,
5//! try to re-export the same type from the "youngest" child contract since that is the contract whose functions are being called,
6//! thus from whom the rust bindings are expected.
7//! E.g. Both PlonkVerifier and LightClient, and LightClientV2 depends on BN254. The inheritance relationship is:
8//!   BN254 <- PlonkVerifier <- LIghtClient <- LightClientV2
9//! Most of the time, we interact with PlonkVerifier's function via LightClientV2, thus import BN254.G1Point from `bindings::plonkverifierv2`.
10//! When we need to directly interact with PlonkVerifier's method, implement stupid plain `From<lc2::BN254::G1Point> for pv::BN254::G1Point`.
11//! If you are lazy, you can even use unsafe memory transmute since they are literally the same representation, duplicated in different modules,
12//! thus treated by the rust type systems as distinct types.
13//!
14//! Another usage is in the differential testing in Solidity tests. In those cases, the actual types don't matter, since they will all `abi_encode()`
15//! into the exact same bytes before being communicated over to contract via FFI. Thus using any one of them is fine.
16
17use alloy::sol;
18
19use crate::bindings::stake_table_v2::{
20    EdOnBN254,
21    BN254::{self, BaseField},
22};
23/// # What to re-export, what to hide?
24/// - export contract struct itself, but try to avoid export instance type (instead, use ::new() to get a handle)
25/// - avoid exporting `xxCall` and `xxReturn` types, they usually can be converted/transmuted from existing struct
26/// - Event types should be exported
27/// - structs should be exported and renamed with `xxSol` suffix to avoid confusion with other rust types
28///   - see module doc for more explanation on types duplication issue in alloy
29pub use crate::bindings::{
30    erc1967_proxy::ERC1967Proxy,
31    esp_token::EspToken,
32    esp_token_v2::EspTokenV2,
33    fee_contract::FeeContract::{self, Deposit},
34    light_client::{
35        IPlonkVerifier::{PlonkProof as PlonkProofSol, VerifyingKey as VerifyingKeySol},
36        LightClient::{
37            self, LightClientErrors, LightClientInstance, LightClientState as LightClientStateSol,
38            StakeTableState as StakeTableStateSol,
39        },
40        BN254::G1Point as G1PointSol,
41    },
42    light_client_mock::{self, LightClientMock},
43    light_client_v2::{self, LightClientV2},
44    light_client_v2_mock::{self, LightClientV2Mock},
45    light_client_v3::{self, LightClientV3},
46    light_client_v3_mock::{self, LightClientV3Mock},
47    ops_timelock::OpsTimelock,
48    ownable_upgradeable::OwnableUpgradeable,
49    plonk_verifier::PlonkVerifier,
50    plonk_verifier_v2::PlonkVerifierV2,
51    plonk_verifier_v3::PlonkVerifierV3,
52    reward_claim::RewardClaim,
53    safe_exit_timelock::SafeExitTimelock,
54    stake_table::StakeTable,
55    stake_table_v2::{
56        self, EdOnBN254::EdOnBN254Point as EdOnBN254PointSol, StakeTableV2,
57        BN254::G2Point as G2PointSol,
58    },
59};
60
61// For types that we need to interact with some functions but their bindings are not generated
62// we manually declare them there. It's possible that they get included in the future commits,
63// at which point, the rust type system will complain and we simply remove the manual declaration
64// and re-export the type from bindings instead.
65sol! {
66    /// types in src/legacy/Transcript.sol
67    struct TranscriptDataSol {
68        bytes32 state;
69        bytes transcript;
70    }
71
72    /// types in src/libraries/PlonkVerifierV2.sol
73    struct ChallengesSol {
74        uint256 alpha;
75        uint256 alpha2;
76        uint256 alpha3;
77        uint256 beta;
78        uint256 gamma;
79        uint256 zeta;
80        uint256 v;
81        uint256 u;
82    }
83}
84
85// Due to <https://github.com/foundry-rs/foundry/issues/10153> the rust bindings contain duplicate types for our solidity types.
86// In order to avoid writing a lot of boilerplate code we use transmute to convert between these duplicated types.
87// Since all the types we transmute between are generated by foundry from the same underlying solidity type
88// we expect that the order of fields and types of fields are always the same.
89impl From<LightClient::genesisStateReturn> for LightClientStateSol {
90    fn from(v: LightClient::genesisStateReturn) -> Self {
91        unsafe { std::mem::transmute(v) }
92    }
93}
94
95impl From<light_client_mock::LightClient::LightClientState> for LightClientStateSol {
96    fn from(v: light_client_mock::LightClient::LightClientState) -> Self {
97        unsafe { std::mem::transmute(v) }
98    }
99}
100impl From<light_client_mock::LightClientMock::finalizedStateReturn> for LightClientStateSol {
101    fn from(v: light_client_mock::LightClientMock::finalizedStateReturn) -> Self {
102        unsafe { std::mem::transmute(v) }
103    }
104}
105
106impl From<LightClientStateSol> for light_client_mock::LightClient::LightClientState {
107    fn from(v: LightClientStateSol) -> Self {
108        unsafe { std::mem::transmute(v) }
109    }
110}
111
112impl From<PlonkProofSol> for light_client_mock::IPlonkVerifier::PlonkProof {
113    fn from(v: PlonkProofSol) -> Self {
114        unsafe { std::mem::transmute(v) }
115    }
116}
117
118impl From<light_client_mock::LightClientMock::genesisStateReturn> for LightClientStateSol {
119    fn from(v: light_client_mock::LightClientMock::genesisStateReturn) -> Self {
120        unsafe { std::mem::transmute(v) }
121    }
122}
123
124impl From<LightClientV2::finalizedStateReturn> for LightClientStateSol {
125    fn from(v: LightClientV2::finalizedStateReturn) -> Self {
126        unsafe { std::mem::transmute(v) }
127    }
128}
129
130impl From<LightClientV2::votingStakeTableStateReturn> for StakeTableStateSol {
131    fn from(v: LightClientV2::votingStakeTableStateReturn) -> Self {
132        unsafe { std::mem::transmute(v) }
133    }
134}
135
136impl From<light_client_v2_mock::LightClient::LightClientState> for LightClientStateSol {
137    fn from(v: light_client_v2_mock::LightClient::LightClientState) -> Self {
138        unsafe { std::mem::transmute(v) }
139    }
140}
141impl From<LightClientStateSol> for light_client_v2_mock::LightClient::LightClientState {
142    fn from(v: LightClientStateSol) -> Self {
143        unsafe { std::mem::transmute(v) }
144    }
145}
146impl From<LightClientStateSol> for light_client_v2::LightClient::LightClientState {
147    fn from(v: LightClientStateSol) -> Self {
148        unsafe { std::mem::transmute(v) }
149    }
150}
151
152impl From<StakeTableStateSol> for light_client_v2::LightClient::StakeTableState {
153    fn from(v: StakeTableStateSol) -> Self {
154        unsafe { std::mem::transmute(v) }
155    }
156}
157impl From<StakeTableStateSol> for light_client_v2_mock::LightClient::StakeTableState {
158    fn from(v: StakeTableStateSol) -> Self {
159        unsafe { std::mem::transmute(v) }
160    }
161}
162
163impl From<LightClientV2Mock::genesisStateReturn> for LightClientStateSol {
164    fn from(v: LightClientV2Mock::genesisStateReturn) -> Self {
165        unsafe { std::mem::transmute(v) }
166    }
167}
168
169impl From<LightClientV2Mock::finalizedStateReturn> for LightClientStateSol {
170    fn from(v: LightClientV2Mock::finalizedStateReturn) -> Self {
171        unsafe { std::mem::transmute(v) }
172    }
173}
174
175impl From<PlonkProofSol> for light_client_v2::IPlonkVerifier::PlonkProof {
176    fn from(v: PlonkProofSol) -> Self {
177        unsafe { std::mem::transmute(v) }
178    }
179}
180
181impl From<LightClientV2Mock::votingStakeTableStateReturn> for StakeTableStateSol {
182    fn from(v: LightClientV2Mock::votingStakeTableStateReturn) -> Self {
183        unsafe { std::mem::transmute(v) }
184    }
185}
186
187impl From<G1PointSol> for stake_table_v2::BN254::G1Point {
188    fn from(v: G1PointSol) -> Self {
189        unsafe { std::mem::transmute(v) }
190    }
191}
192
193impl From<stake_table_v2::BN254::G1Point> for G1PointSol {
194    fn from(v: stake_table_v2::BN254::G1Point) -> Self {
195        unsafe { std::mem::transmute(v) }
196    }
197}
198
199// Transmute conversion functions for LightClientV3
200impl From<LightClientV3::finalizedStateReturn> for LightClientStateSol {
201    fn from(v: LightClientV3::finalizedStateReturn) -> Self {
202        unsafe { std::mem::transmute(v) }
203    }
204}
205
206impl From<LightClientV3::votingStakeTableStateReturn> for StakeTableStateSol {
207    fn from(v: LightClientV3::votingStakeTableStateReturn) -> Self {
208        unsafe { std::mem::transmute(v) }
209    }
210}
211
212impl From<LightClientStateSol> for light_client_v3::LightClient::LightClientState {
213    fn from(v: LightClientStateSol) -> Self {
214        unsafe { std::mem::transmute(v) }
215    }
216}
217
218impl From<StakeTableStateSol> for light_client_v3::LightClient::StakeTableState {
219    fn from(v: StakeTableStateSol) -> Self {
220        unsafe { std::mem::transmute(v) }
221    }
222}
223
224impl From<PlonkProofSol> for light_client_v3::IPlonkVerifier::PlonkProof {
225    fn from(v: PlonkProofSol) -> Self {
226        unsafe { std::mem::transmute(v) }
227    }
228}
229
230// Transmute conversion functions for LightClientV3Mock
231impl From<light_client_v3_mock::LightClient::LightClientState> for LightClientStateSol {
232    fn from(v: light_client_v3_mock::LightClient::LightClientState) -> Self {
233        unsafe { std::mem::transmute(v) }
234    }
235}
236
237impl From<LightClientStateSol> for light_client_v3_mock::LightClient::LightClientState {
238    fn from(v: LightClientStateSol) -> Self {
239        unsafe { std::mem::transmute(v) }
240    }
241}
242
243impl From<StakeTableStateSol> for light_client_v3_mock::LightClient::StakeTableState {
244    fn from(v: StakeTableStateSol) -> Self {
245        unsafe { std::mem::transmute(v) }
246    }
247}
248
249impl From<LightClientV3Mock::genesisStateReturn> for LightClientStateSol {
250    fn from(v: LightClientV3Mock::genesisStateReturn) -> Self {
251        unsafe { std::mem::transmute(v) }
252    }
253}
254
255impl From<LightClientV3Mock::finalizedStateReturn> for LightClientStateSol {
256    fn from(v: LightClientV3Mock::finalizedStateReturn) -> Self {
257        unsafe { std::mem::transmute(v) }
258    }
259}
260
261impl From<LightClientV3Mock::votingStakeTableStateReturn> for StakeTableStateSol {
262    fn from(v: LightClientV3Mock::votingStakeTableStateReturn) -> Self {
263        unsafe { std::mem::transmute(v) }
264    }
265}
266
267use serde::{Deserialize, Serialize};
268
269use self::StakeTableV2::{
270    ConsensusKeysUpdated, ConsensusKeysUpdatedV2, Delegated, Undelegated, ValidatorExit,
271    ValidatorRegistered, ValidatorRegisteredV2,
272};
273
274impl PartialEq for ValidatorRegistered {
275    fn eq(&self, other: &Self) -> bool {
276        self.account == other.account
277            && self.blsVk == other.blsVk
278            && self.schnorrVk == other.schnorrVk
279            && self.commission == other.commission
280    }
281}
282
283impl PartialEq for ValidatorRegisteredV2 {
284    fn eq(&self, other: &Self) -> bool {
285        self.account == other.account
286            && self.blsVK == other.blsVK
287            && self.schnorrVK == other.schnorrVK
288            && self.commission == other.commission
289            && self.blsSig == other.blsSig
290            && self.schnorrSig == other.schnorrSig
291    }
292}
293
294impl PartialEq for ConsensusKeysUpdated {
295    fn eq(&self, other: &Self) -> bool {
296        self.account == other.account
297            && self.blsVK == other.blsVK
298            && self.schnorrVK == other.schnorrVK
299    }
300}
301
302impl PartialEq for ConsensusKeysUpdatedV2 {
303    fn eq(&self, other: &Self) -> bool {
304        self.account == other.account
305            && self.blsVK == other.blsVK
306            && self.schnorrVK == other.schnorrVK
307            && self.blsSig == other.blsSig
308            && self.schnorrSig == other.schnorrSig
309    }
310}
311
312#[derive()]
313/**Event with signature `ValidatorRegistered(address,(uint256,uint256,uint256,uint256),(uint256,uint256),uint16)` and selector `0xf6e8359c57520b469634736bfc3bb7ec5cbd1a0bd28b10a8275793bb730b797f`.
314```solidity
315event ValidatorRegistered(address indexed account, BN254.G2Point blsVk, EdOnBN254.EdOnBN254Point schnorrVk, uint16 commission);
316```*/
317#[allow(
318    non_camel_case_types,
319    non_snake_case,
320    clippy::pub_underscore_fields,
321    clippy::style
322)]
323#[derive(Clone, Serialize, Deserialize)]
324pub struct ValidatorRegisteredLegacy {
325    #[allow(missing_docs)]
326    pub account: alloy::sol_types::private::Address,
327    #[allow(missing_docs)]
328    pub blsVk: G2PointLegacy,
329    #[allow(missing_docs)]
330    pub schnorrVk: EdOnBN254PointLegacy,
331    #[allow(missing_docs)]
332    pub commission: u16,
333}
334
335#[allow(
336    non_camel_case_types,
337    non_snake_case,
338    clippy::pub_underscore_fields,
339    clippy::style
340)]
341#[derive(Clone, Serialize, Deserialize)]
342pub struct ValidatorRegisteredV2Legacy {
343    #[allow(missing_docs)]
344    pub account: alloy::sol_types::private::Address,
345    #[allow(missing_docs)]
346    pub blsVK: G2PointLegacy,
347    #[allow(missing_docs)]
348    pub schnorrVK: EdOnBN254PointLegacy,
349    #[allow(missing_docs)]
350    pub commission: u16,
351    #[allow(missing_docs)]
352    pub blsSig: G1PointLegacy,
353    #[allow(missing_docs)]
354    pub schnorrSig: alloy::sol_types::private::Bytes,
355}
356
357#[derive(Default, Debug, PartialEq, Eq, Hash)]
358/**```solidity
359struct EdOnBN254Point { uint256 x; uint256 y; }
360```*/
361#[allow(non_camel_case_types, non_snake_case, clippy::pub_underscore_fields)]
362#[derive(Clone, Serialize, Deserialize)]
363pub struct EdOnBN254PointLegacy {
364    #[allow(missing_docs)]
365    pub x: alloy::sol_types::private::primitives::aliases::U256,
366    #[allow(missing_docs)]
367    pub y: alloy::sol_types::private::primitives::aliases::U256,
368}
369
370#[derive(Default, Debug, PartialEq, Eq, Hash)]
371/**```solidity
372struct G2Point { BaseField x0; BaseField x1; BaseField y0; BaseField y1; }
373```*/
374#[allow(non_camel_case_types, non_snake_case, clippy::pub_underscore_fields)]
375#[derive(Clone, Serialize, Deserialize)]
376pub struct G2PointLegacy {
377    #[allow(missing_docs)]
378    pub x0: <BaseField as alloy::sol_types::SolType>::RustType,
379    #[allow(missing_docs)]
380    pub x1: <BaseField as alloy::sol_types::SolType>::RustType,
381    #[allow(missing_docs)]
382    pub y0: <BaseField as alloy::sol_types::SolType>::RustType,
383    #[allow(missing_docs)]
384    pub y1: <BaseField as alloy::sol_types::SolType>::RustType,
385}
386
387#[allow(non_camel_case_types, non_snake_case, clippy::pub_underscore_fields)]
388#[derive(Clone, Serialize, Deserialize)]
389pub struct G1PointLegacy {
390    #[allow(missing_docs)]
391    pub x: <BaseField as alloy::sol_types::SolType>::RustType,
392    #[allow(missing_docs)]
393    pub y: <BaseField as alloy::sol_types::SolType>::RustType,
394}
395
396#[allow(
397    non_camel_case_types,
398    non_snake_case,
399    clippy::pub_underscore_fields,
400    clippy::style
401)]
402#[derive(Clone, Serialize, Deserialize)]
403pub struct ValidatorExitLegacy {
404    #[allow(missing_docs)]
405    pub validator: alloy::sol_types::private::Address,
406}
407
408#[allow(
409    non_camel_case_types,
410    non_snake_case,
411    clippy::pub_underscore_fields,
412    clippy::style
413)]
414#[derive(Clone, Serialize, Deserialize)]
415pub struct DelegatedLegacy {
416    #[allow(missing_docs)]
417    pub delegator: alloy::sol_types::private::Address,
418    #[allow(missing_docs)]
419    pub validator: alloy::sol_types::private::Address,
420    #[allow(missing_docs)]
421    pub amount: alloy::sol_types::private::primitives::aliases::U256,
422}
423
424#[allow(
425    non_camel_case_types,
426    non_snake_case,
427    clippy::pub_underscore_fields,
428    clippy::style
429)]
430#[derive(Clone, Serialize, Deserialize)]
431pub struct UndelegatedLegacy {
432    #[allow(missing_docs)]
433    pub delegator: alloy::sol_types::private::Address,
434    #[allow(missing_docs)]
435    pub validator: alloy::sol_types::private::Address,
436    #[allow(missing_docs)]
437    pub amount: alloy::sol_types::private::primitives::aliases::U256,
438}
439
440#[allow(
441    non_camel_case_types,
442    non_snake_case,
443    clippy::pub_underscore_fields,
444    clippy::style
445)]
446#[derive(Clone, Serialize, Deserialize)]
447pub struct ConsensusKeysUpdatedLegacy {
448    #[allow(missing_docs)]
449    pub account: alloy::sol_types::private::Address,
450    #[allow(missing_docs)]
451    pub blsVK: G2PointLegacy,
452    #[allow(missing_docs)]
453    pub schnorrVK: EdOnBN254PointLegacy,
454}
455
456#[allow(
457    non_camel_case_types,
458    non_snake_case,
459    clippy::pub_underscore_fields,
460    clippy::style
461)]
462#[derive(Clone, Serialize, Deserialize)]
463pub struct ConsensusKeysUpdatedV2Legacy {
464    #[allow(missing_docs)]
465    pub account: alloy::sol_types::private::Address,
466    #[allow(missing_docs)]
467    pub blsVK: G2PointLegacy,
468    #[allow(missing_docs)]
469    pub schnorrVK: EdOnBN254PointLegacy,
470    #[allow(missing_docs)]
471    pub blsSig: G1PointLegacy,
472    #[allow(missing_docs)]
473    pub schnorrSig: alloy::sol_types::private::Bytes,
474}
475
476impl From<ValidatorRegisteredLegacy> for ValidatorRegistered {
477    fn from(v: ValidatorRegisteredLegacy) -> Self {
478        Self {
479            account: v.account,
480            blsVk: v.blsVk.into(),
481            schnorrVk: v.schnorrVk.into(),
482            commission: v.commission,
483        }
484    }
485}
486
487impl From<ValidatorRegisteredV2Legacy> for ValidatorRegisteredV2 {
488    fn from(v: ValidatorRegisteredV2Legacy) -> Self {
489        Self {
490            account: v.account,
491            blsVK: v.blsVK.into(),
492            schnorrVK: v.schnorrVK.into(),
493            commission: v.commission,
494            blsSig: v.blsSig.into(),
495            schnorrSig: v.schnorrSig,
496        }
497    }
498}
499
500impl From<ValidatorExitLegacy> for ValidatorExit {
501    fn from(v: ValidatorExitLegacy) -> Self {
502        Self {
503            validator: v.validator,
504        }
505    }
506}
507
508impl From<DelegatedLegacy> for Delegated {
509    fn from(v: DelegatedLegacy) -> Self {
510        Self {
511            delegator: v.delegator,
512            validator: v.validator,
513            amount: v.amount,
514        }
515    }
516}
517
518impl From<UndelegatedLegacy> for Undelegated {
519    fn from(v: UndelegatedLegacy) -> Self {
520        Self {
521            delegator: v.delegator,
522            validator: v.validator,
523            amount: v.amount,
524        }
525    }
526}
527
528impl From<ConsensusKeysUpdatedLegacy> for ConsensusKeysUpdated {
529    fn from(v: ConsensusKeysUpdatedLegacy) -> Self {
530        Self {
531            account: v.account,
532            blsVK: v.blsVK.into(),
533            schnorrVK: v.schnorrVK.into(),
534        }
535    }
536}
537
538impl From<ConsensusKeysUpdatedV2Legacy> for ConsensusKeysUpdatedV2 {
539    fn from(v: ConsensusKeysUpdatedV2Legacy) -> Self {
540        Self {
541            account: v.account,
542            blsVK: v.blsVK.into(),
543            schnorrVK: v.schnorrVK.into(),
544            blsSig: v.blsSig.into(),
545            schnorrSig: v.schnorrSig,
546        }
547    }
548}
549
550impl From<G2PointLegacy> for BN254::G2Point {
551    fn from(v: G2PointLegacy) -> Self {
552        Self {
553            x0: v.x0,
554            x1: v.x1,
555            y0: v.y0,
556            y1: v.y1,
557        }
558    }
559}
560
561impl From<G1PointLegacy> for BN254::G1Point {
562    fn from(v: G1PointLegacy) -> Self {
563        Self { x: v.x, y: v.y }
564    }
565}
566
567impl From<EdOnBN254PointLegacy> for EdOnBN254::EdOnBN254Point {
568    fn from(v: EdOnBN254PointLegacy) -> Self {
569        Self { x: v.x, y: v.y }
570    }
571}
572
573impl From<ValidatorRegistered> for ValidatorRegisteredLegacy {
574    fn from(v: ValidatorRegistered) -> Self {
575        Self {
576            account: v.account,
577            blsVk: v.blsVk.into(),
578            schnorrVk: v.schnorrVk.into(),
579            commission: v.commission,
580        }
581    }
582}
583
584impl From<ValidatorRegisteredV2> for ValidatorRegisteredV2Legacy {
585    fn from(v: ValidatorRegisteredV2) -> Self {
586        Self {
587            account: v.account,
588            blsVK: v.blsVK.into(),
589            schnorrVK: v.schnorrVK.into(),
590            commission: v.commission,
591            blsSig: v.blsSig.into(),
592            schnorrSig: v.schnorrSig,
593        }
594    }
595}
596
597impl From<ValidatorExit> for ValidatorExitLegacy {
598    fn from(v: ValidatorExit) -> Self {
599        Self {
600            validator: v.validator,
601        }
602    }
603}
604
605impl From<Delegated> for DelegatedLegacy {
606    fn from(v: Delegated) -> Self {
607        Self {
608            delegator: v.delegator,
609            validator: v.validator,
610            amount: v.amount,
611        }
612    }
613}
614
615impl From<Undelegated> for UndelegatedLegacy {
616    fn from(v: Undelegated) -> Self {
617        Self {
618            delegator: v.delegator,
619            validator: v.validator,
620            amount: v.amount,
621        }
622    }
623}
624
625impl From<ConsensusKeysUpdated> for ConsensusKeysUpdatedLegacy {
626    fn from(v: ConsensusKeysUpdated) -> Self {
627        Self {
628            account: v.account,
629            blsVK: v.blsVK.into(),
630            schnorrVK: v.schnorrVK.into(),
631        }
632    }
633}
634
635impl From<ConsensusKeysUpdatedV2> for ConsensusKeysUpdatedV2Legacy {
636    fn from(v: ConsensusKeysUpdatedV2) -> Self {
637        Self {
638            account: v.account,
639            blsVK: v.blsVK.into(),
640            schnorrVK: v.schnorrVK.into(),
641            blsSig: v.blsSig.into(),
642            schnorrSig: v.schnorrSig,
643        }
644    }
645}
646
647impl Clone for StakeTableV2::StakeTableV2Events {
648    fn clone(&self) -> Self {
649        match self {
650            Self::ValidatorRegistered(v) => Self::ValidatorRegistered(*v),
651            Self::ValidatorRegisteredV2(v) => Self::ValidatorRegisteredV2(v.clone()),
652            Self::ValidatorExit(v) => Self::ValidatorExit(*v),
653            Self::Delegated(v) => Self::Delegated(*v),
654            Self::Undelegated(v) => Self::Undelegated(*v),
655            Self::ConsensusKeysUpdated(v) => Self::ConsensusKeysUpdated(*v),
656            Self::ConsensusKeysUpdatedV2(v) => Self::ConsensusKeysUpdatedV2(v.clone()),
657            Self::CommissionUpdated(v) => Self::CommissionUpdated(v.clone()),
658            Self::ExitEscrowPeriodUpdated(v) => Self::ExitEscrowPeriodUpdated(v.clone()),
659            Self::MaxCommissionIncreaseUpdated(v) => Self::MaxCommissionIncreaseUpdated(v.clone()),
660            Self::MinCommissionUpdateIntervalUpdated(v) => {
661                Self::MinCommissionUpdateIntervalUpdated(v.clone())
662            },
663            Self::OwnershipTransferred(v) => Self::OwnershipTransferred(v.clone()),
664            Self::Paused(v) => Self::Paused(v.clone()),
665            Self::Unpaused(v) => Self::Unpaused(v.clone()),
666            Self::Initialized(v) => Self::Initialized(v.clone()),
667            Self::RoleAdminChanged(v) => Self::RoleAdminChanged(v.clone()),
668            Self::RoleGranted(v) => Self::RoleGranted(v.clone()),
669            Self::RoleRevoked(v) => Self::RoleRevoked(v.clone()),
670            Self::Upgraded(v) => Self::Upgraded(v.clone()),
671            Self::Withdrawal(v) => Self::Withdrawal(v.clone()),
672        }
673    }
674}
675
676impl std::fmt::Debug for StakeTableV2::StakeTableV2Events {
677    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
678        match self {
679            Self::ValidatorRegistered(_) => write!(f, "ValidatorRegistered(_)"),
680            Self::ValidatorRegisteredV2(_) => write!(f, "ValidatorRegisteredV2(_)"),
681            Self::ValidatorExit(v) => write!(f, "ValidatorExit({v:?})"),
682            Self::Delegated(v) => write!(f, "Delegated({v:?})"),
683            Self::Undelegated(v) => write!(f, "Undelegated({v:?})"),
684            Self::ConsensusKeysUpdated(_) => write!(f, "ConsensusKeysUpdated(_)"),
685            Self::ConsensusKeysUpdatedV2(_) => write!(f, "ConsensusKeysUpdatedV2(_)"),
686            Self::CommissionUpdated(v) => write!(f, "CommissionUpdated({v:?})"),
687            Self::ExitEscrowPeriodUpdated(v) => write!(f, "ExitEscrowPeriodUpdated({v:?})"),
688            Self::MaxCommissionIncreaseUpdated(v) => {
689                write!(f, "MaxCommissionIncreaseUpdated({v:?})")
690            },
691            Self::MinCommissionUpdateIntervalUpdated(v) => {
692                write!(f, "MinCommissionUpdateIntervalUpdated({v:?})")
693            },
694            Self::OwnershipTransferred(v) => write!(f, "OwnershipTransferred({v:?})"),
695            Self::Paused(v) => write!(f, "Paused({v:?})"),
696            Self::Unpaused(v) => write!(f, "Unpaused({v:?})"),
697            Self::Initialized(v) => write!(f, "Initialized({v:?})"),
698            Self::RoleAdminChanged(v) => write!(f, "RoleAdminChanged({v:?})"),
699            Self::RoleGranted(v) => write!(f, "RoleGranted({v:?})"),
700            Self::RoleRevoked(v) => write!(f, "RoleRevoked({v:?})"),
701            Self::Upgraded(v) => write!(f, "Upgraded({v:?})"),
702            Self::Withdrawal(v) => write!(f, "Withdrawal({v:?})"),
703        }
704    }
705}
706
707impl From<BN254::G2Point> for G2PointLegacy {
708    fn from(v: BN254::G2Point) -> Self {
709        Self {
710            x0: v.x0,
711            x1: v.x1,
712            y0: v.y0,
713            y1: v.y1,
714        }
715    }
716}
717
718impl From<G1PointSol> for G1PointLegacy {
719    fn from(v: G1PointSol) -> Self {
720        Self { x: v.x, y: v.y }
721    }
722}
723
724impl From<BN254::G1Point> for G1PointLegacy {
725    fn from(v: BN254::G1Point) -> Self {
726        Self { x: v.x, y: v.y }
727    }
728}
729
730impl From<EdOnBN254::EdOnBN254Point> for EdOnBN254PointLegacy {
731    fn from(v: EdOnBN254::EdOnBN254Point) -> Self {
732        Self { x: v.x, y: v.y }
733    }
734}
735
736#[cfg(test)]
737mod tests {
738    use alloy::{primitives::U256, sol_types::private::Address};
739
740    use crate::sol_types::StakeTableV2::CommissionUpdated;
741
742    #[test]
743    fn test_commission_updated_serde_roundtrip() {
744        let original = CommissionUpdated {
745            validator: Address::random(),
746            timestamp: U256::from(999),
747            oldCommission: 123,
748            newCommission: 456,
749        };
750
751        let serialized = bincode::serialize(&original).expect("Failed to serialize");
752        let deserialized: CommissionUpdated =
753            bincode::deserialize(&serialized).expect("Failed to deserialize");
754
755        assert_eq!(original.validator, deserialized.validator);
756        assert_eq!(original.timestamp, deserialized.timestamp);
757        assert_eq!(original.oldCommission, deserialized.oldCommission);
758        assert_eq!(original.newCommission, deserialized.newCommission);
759    }
760}