@@ -15,6 +15,7 @@ use ethers::{
1515} ;
1616use foundry_common:: { abi:: get_indexed_event, SELECTOR_LEN } ;
1717use hashbrown:: HashSet ;
18+ use once_cell:: sync:: OnceCell ;
1819use std:: collections:: { BTreeMap , HashMap } ;
1920
2021/// Build a new [CallTraceDecoder].
@@ -25,7 +26,7 @@ pub struct CallTraceDecoderBuilder {
2526
2627impl CallTraceDecoderBuilder {
2728 pub fn new ( ) -> Self {
28- Self { decoder : CallTraceDecoder :: new ( ) }
29+ Self { decoder : CallTraceDecoder :: new ( ) . clone ( ) }
2930 }
3031
3132 /// Add known labels to the decoder.
@@ -65,7 +66,7 @@ impl CallTraceDecoderBuilder {
6566///
6667/// Note that a call trace decoder is required for each new set of traces, since addresses in
6768/// different sets might overlap.
68- #[ derive( Default , Debug ) ]
69+ #[ derive( Clone , Default , Debug ) ]
6970pub struct CallTraceDecoder {
7071 /// Information for decoding precompile calls.
7172 pub precompiles : HashMap < Address , Function > ,
@@ -115,7 +116,14 @@ impl CallTraceDecoder {
115116 ///
116117 /// The call trace decoder always knows how to decode calls to the cheatcode address, as well
117118 /// as DSTest-style logs.
118- pub fn new ( ) -> Self {
119+ pub fn new ( ) -> & ' static Self {
120+ // If you want to take arguments in this function, assign them to the fields of the cloned
121+ // lazy instead of removing it
122+ static INIT : OnceCell < CallTraceDecoder > = OnceCell :: new ( ) ;
123+ INIT . get_or_init ( Self :: init)
124+ }
125+
126+ fn init ( ) -> Self {
119127 Self {
120128 // TODO: These are the Ethereum precompiles. We should add a way to support precompiles
121129 // for other networks, too.
0 commit comments