1pub mod blockchain;
2pub mod chain_config;
3pub mod contract;
4pub mod error;
5pub mod protocol;
6pub mod token;
7
8use std::{collections::HashMap, fmt::Display, str::FromStr};
9
10pub use blockchain::{BlockChanges, TxWithContractChanges};
11use chain_config::{
12 chain_registry, ChainConfigError, ChainConfigRegistry, CustomChainConfig, CustomChainId,
13 TvlThresholdTier,
14};
15use deepsize::DeepSizeOf;
16use serde::{Deserialize, Serialize};
17use thiserror::Error;
18use token::Token;
19
20use crate::{dto, Bytes};
21
22pub type Address = Bytes;
25
26pub type BlockHash = Bytes;
29
30pub type TxHash = Bytes;
33
34pub type Code = Bytes;
36
37pub type CodeHash = Bytes;
39
40pub type Balance = Bytes;
42
43pub type StoreKey = Bytes;
45
46pub type AttrStoreKey = String;
48
49pub type StoreVal = Bytes;
51
52pub type ContractStore = HashMap<StoreKey, StoreVal>;
54pub type ContractStoreDeltas = HashMap<StoreKey, Option<StoreVal>>;
55pub type AccountToContractStoreDeltas = HashMap<Address, ContractStoreDeltas>;
56
57pub type ComponentId = String;
59
60pub type ProtocolSystem = String;
62
63pub type EntryPointId = String;
65
66#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
84#[serde(rename_all = "lowercase")]
85#[non_exhaustive]
86pub enum Chain {
87 #[default]
88 Ethereum,
89 Starknet,
90 ZkSync,
91 Arbitrum,
92 Base,
93 Bsc,
94 Unichain,
95 Polygon,
96 Plasma,
97 Robinhood,
98 Custom(CustomChainId),
100}
101
102impl DeepSizeOf for Chain {
103 fn deep_size_of_children(&self, _context: &mut deepsize::Context) -> usize {
104 0
105 }
106}
107
108impl Chain {
109 pub fn builtin_from_str(s: &str) -> Option<Self> {
111 match s {
112 "ethereum" => Some(Chain::Ethereum),
113 "starknet" => Some(Chain::Starknet),
114 "zksync" => Some(Chain::ZkSync),
115 "arbitrum" => Some(Chain::Arbitrum),
116 "base" => Some(Chain::Base),
117 "bsc" => Some(Chain::Bsc),
118 "unichain" => Some(Chain::Unichain),
119 "polygon" => Some(Chain::Polygon),
120 "plasma" => Some(Chain::Plasma),
121 "robinhood" => Some(Chain::Robinhood),
122 _ => None,
123 }
124 }
125
126 pub fn custom(name: &str) -> Result<Self, ChainConfigError> {
130 CustomChainId::checked(name, chain_registry()).map(Chain::Custom)
131 }
132}
133
134impl FromStr for Chain {
135 type Err = ChainConfigError;
136
137 fn from_str(s: &str) -> Result<Self, Self::Err> {
141 if let Some(chain) = Self::builtin_from_str(s) {
142 return Ok(chain);
143 }
144 Self::custom(s)
145 }
146}
147
148impl Display for Chain {
149 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
150 match self {
151 Chain::Ethereum => f.write_str("ethereum"),
152 Chain::Starknet => f.write_str("starknet"),
153 Chain::ZkSync => f.write_str("zksync"),
154 Chain::Arbitrum => f.write_str("arbitrum"),
155 Chain::Base => f.write_str("base"),
156 Chain::Bsc => f.write_str("bsc"),
157 Chain::Unichain => f.write_str("unichain"),
158 Chain::Polygon => f.write_str("polygon"),
159 Chain::Plasma => f.write_str("plasma"),
160 Chain::Robinhood => f.write_str("robinhood"),
161 Chain::Custom(name) => f.write_str(name.as_str()),
162 }
163 }
164}
165
166impl From<dto::Chain> for Chain {
167 fn from(value: dto::Chain) -> Self {
168 match value {
169 dto::Chain::Ethereum => Chain::Ethereum,
170 dto::Chain::Starknet => Chain::Starknet,
171 dto::Chain::ZkSync => Chain::ZkSync,
172 dto::Chain::Arbitrum => Chain::Arbitrum,
173 dto::Chain::Base => Chain::Base,
174 dto::Chain::Bsc => Chain::Bsc,
175 dto::Chain::Unichain => Chain::Unichain,
176 dto::Chain::Polygon => Chain::Polygon,
177 dto::Chain::Plasma => Chain::Plasma,
178 dto::Chain::Robinhood => Chain::Robinhood,
179 dto::Chain::Custom(name) => Chain::custom(name.as_str()).unwrap_or_else(|e| {
180 panic!(
181 "received custom chain '{name}' with no registered config: {e}; install it via \
182 the chain config file (TYCHO_CHAINS_CONFIG, default ./chains.yaml) or \
183 init_chain_registry before decoding wire data"
184 )
185 }),
186 }
187 }
188}
189
190impl From<dto::ChangeType> for ChangeType {
191 fn from(value: dto::ChangeType) -> Self {
192 match value {
193 dto::ChangeType::Update => ChangeType::Update,
194 dto::ChangeType::Creation => ChangeType::Creation,
195 dto::ChangeType::Deletion => ChangeType::Deletion,
196 dto::ChangeType::Unspecified => ChangeType::Update,
197 }
198 }
199}
200
201fn native_eth(chain: Chain) -> Token {
202 Token::new(
203 &Bytes::from_str("0x0000000000000000000000000000000000000000").unwrap(),
204 "ETH",
205 18,
206 0,
207 &[Some(2300)],
208 chain,
209 100,
210 )
211}
212
213fn native_bsc(chain: Chain) -> Token {
214 Token::new(
215 &Bytes::from_str("0x0000000000000000000000000000000000000000").unwrap(),
216 "BNB",
217 18,
218 0,
219 &[Some(2300)],
220 chain,
221 100,
222 )
223}
224
225fn wrapped_native_eth(chain: Chain, address: &str) -> Token {
226 Token::new(&Bytes::from_str(address).unwrap(), "WETH", 18, 0, &[Some(2300)], chain, 100)
227}
228
229fn native_pol(chain: Chain) -> Token {
230 Token::new(
231 &Bytes::from_str("0x0000000000000000000000000000000000000000").unwrap(),
232 "POL",
233 18,
234 0,
235 &[Some(2300)],
236 chain,
237 100,
238 )
239}
240
241fn native_xpl(chain: Chain) -> Token {
242 Token::new(
243 &Bytes::from_str("0x0000000000000000000000000000000000000000").unwrap(),
244 "XPL",
245 18,
246 0,
247 &[Some(2300)],
248 chain,
249 100,
250 )
251}
252
253fn try_resolve_custom<'a>(
256 id: &CustomChainId,
257 registry: &'a ChainConfigRegistry,
258) -> Result<&'a CustomChainConfig, ChainConfigError> {
259 registry
260 .get(id.as_str())
261 .ok_or_else(|| ChainConfigError::UnknownChain(id.as_str().to_owned()))
262}
263
264fn expect_registered<T>(result: Result<T, ChainConfigError>) -> T {
268 result.unwrap_or_else(|e| {
269 panic!(
270 "internal invariant violation resolving custom chain config: {e}; Chain::Custom is \
271 validated against the set-once chain registry at construction"
272 )
273 })
274}
275
276fn native_custom(chain: Chain, cfg: &CustomChainConfig) -> Token {
277 let addr = Bytes::from(cfg.native.address.as_bytes().to_vec());
278 Token::new(
279 &addr,
280 cfg.native.symbol.as_str(),
281 cfg.native.decimals as u32,
282 0,
283 &[Some(2300)],
284 chain,
285 100,
286 )
287}
288
289fn wrapped_native_bsc(chain: Chain, address: &str) -> Token {
290 Token::new(&Bytes::from_str(address).unwrap(), "WBNB", 18, 0, &[Some(2300)], chain, 100)
291}
292
293fn wrapped_native_pol(chain: Chain, address: &str) -> Token {
294 Token::new(&Bytes::from_str(address).unwrap(), "WMATIC", 18, 0, &[Some(2300)], chain, 100)
295}
296
297fn wrapped_native_xpl(chain: Chain, address: &str) -> Token {
298 Token::new(&Bytes::from_str(address).unwrap(), "WXPL", 18, 0, &[Some(2300)], chain, 100)
299}
300
301fn wrapped_native_custom(chain: Chain, cfg: &CustomChainConfig) -> Token {
302 let addr = Bytes::from(
303 cfg.wrapped_native
304 .address
305 .as_bytes()
306 .to_vec(),
307 );
308 Token::new(
309 &addr,
310 cfg.wrapped_native.symbol.as_str(),
311 cfg.wrapped_native.decimals as u32,
312 0,
313 &[Some(2300)],
314 chain,
315 100,
316 )
317}
318
319impl Chain {
320 pub fn id(&self) -> u64 {
324 expect_registered(self.try_id())
325 }
326
327 pub fn try_id(&self) -> Result<u64, ChainConfigError> {
330 Ok(match self {
331 Chain::Ethereum => 1,
332 Chain::ZkSync => 324,
333 Chain::Arbitrum => 42161,
334 Chain::Starknet => 0,
335 Chain::Base => 8453,
336 Chain::Bsc => 56,
337 Chain::Unichain => 130,
338 Chain::Polygon => 137,
339 Chain::Plasma => 9745,
340 Chain::Robinhood => 4663,
341 Chain::Custom(id) => try_resolve_custom(id, chain_registry())?.chain_id,
342 })
343 }
344
345 pub fn default_tvl_threshold(&self, tier: TvlThresholdTier) -> f64 {
355 expect_registered(self.try_default_tvl_threshold(tier))
356 }
357
358 pub fn try_default_tvl_threshold(
361 &self,
362 tier: TvlThresholdTier,
363 ) -> Result<f64, ChainConfigError> {
364 Ok(match (self, tier) {
365 (
368 Chain::Ethereum |
369 Chain::Starknet |
370 Chain::ZkSync |
371 Chain::Arbitrum |
372 Chain::Base |
373 Chain::Unichain |
374 Chain::Robinhood,
375 TvlThresholdTier::Low,
376 ) => 10.0,
377 (
378 Chain::Ethereum |
379 Chain::Starknet |
380 Chain::ZkSync |
381 Chain::Arbitrum |
382 Chain::Base |
383 Chain::Unichain |
384 Chain::Robinhood,
385 TvlThresholdTier::Medium,
386 ) => 100.0,
387
388 (Chain::Polygon, TvlThresholdTier::Low) => 200_000.0,
390 (Chain::Polygon, TvlThresholdTier::Medium) => 2_000_000.0,
391
392 (Chain::Plasma, TvlThresholdTier::Low) => 200_000.0,
394 (Chain::Plasma, TvlThresholdTier::Medium) => 2_000_000.0,
395
396 (Chain::Bsc, TvlThresholdTier::Low) => 32.0,
398 (Chain::Bsc, TvlThresholdTier::Medium) => 320.0,
399
400 (Chain::Custom(id), TvlThresholdTier::Low) => {
401 try_resolve_custom(id, chain_registry())?
402 .default_tvl_thresholds
403 .low
404 }
405 (Chain::Custom(id), TvlThresholdTier::Medium) => {
406 try_resolve_custom(id, chain_registry())?
407 .default_tvl_thresholds
408 .medium
409 }
410 })
411 }
412
413 pub fn native_token(&self) -> Token {
416 expect_registered(self.try_native_token())
417 }
418
419 pub fn try_native_token(&self) -> Result<Token, ChainConfigError> {
422 Ok(match self {
423 Chain::Ethereum => native_eth(Chain::Ethereum),
424 Chain::Starknet => native_eth(Chain::Starknet),
427 Chain::ZkSync => native_eth(Chain::ZkSync),
428 Chain::Arbitrum => native_eth(Chain::Arbitrum),
429 Chain::Base => native_eth(Chain::Base),
430 Chain::Bsc => native_bsc(Chain::Bsc),
431 Chain::Unichain => native_eth(Chain::Unichain),
432 Chain::Polygon => native_pol(Chain::Polygon),
433 Chain::Plasma => native_xpl(Chain::Plasma),
434 Chain::Robinhood => native_eth(Chain::Robinhood),
435 Chain::Custom(id) => native_custom(*self, try_resolve_custom(id, chain_registry())?),
436 })
437 }
438
439 pub fn wrapped_native_token(&self) -> Token {
442 expect_registered(self.try_wrapped_native_token())
443 }
444
445 pub fn try_wrapped_native_token(&self) -> Result<Token, ChainConfigError> {
448 Ok(match self {
449 Chain::Ethereum => {
450 wrapped_native_eth(Chain::Ethereum, "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
451 }
452 Chain::Starknet => {
454 wrapped_native_eth(Chain::Starknet, "0x0000000000000000000000000000000000000000")
455 }
456 Chain::ZkSync => {
457 wrapped_native_eth(Chain::ZkSync, "0x5AEa5775959fBC2557Cc8789bC1bf90A239D9a91")
458 }
459 Chain::Arbitrum => {
460 wrapped_native_eth(Chain::Arbitrum, "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1")
461 }
462 Chain::Base => {
463 wrapped_native_eth(Chain::Base, "0x4200000000000000000000000000000000000006")
464 }
465 Chain::Bsc => {
466 wrapped_native_bsc(Chain::Bsc, "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c")
467 }
468 Chain::Unichain => {
469 wrapped_native_eth(Chain::Unichain, "0x4200000000000000000000000000000000000006")
470 }
471 Chain::Polygon => {
472 wrapped_native_pol(Chain::Polygon, "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270")
473 }
474 Chain::Plasma => {
475 wrapped_native_xpl(Chain::Plasma, "0x6100E367285b01F48D07953803A2d8dCA5D19873")
476 }
477 Chain::Robinhood => {
479 wrapped_native_eth(Chain::Robinhood, "0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73")
480 }
481 Chain::Custom(id) => {
482 wrapped_native_custom(*self, try_resolve_custom(id, chain_registry())?)
483 }
484 })
485 }
486
487 pub fn block_time_secs(&self) -> u64 {
490 expect_registered(self.try_block_time_secs())
491 }
492
493 pub fn try_block_time_secs(&self) -> Result<u64, ChainConfigError> {
496 Ok(match self {
497 Chain::Ethereum => 12,
498 Chain::Starknet => 2,
499 Chain::ZkSync => 3,
500 Chain::Arbitrum => 1,
501 Chain::Base => 2,
502 Chain::Bsc => 1,
503 Chain::Unichain => 1,
504 Chain::Polygon => 2,
505 Chain::Plasma => 1,
506 Chain::Robinhood => 1,
507 Chain::Custom(id) => try_resolve_custom(id, chain_registry())?.block_time_secs,
508 })
509 }
510}
511
512#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash, Default)]
513pub struct ExtractorIdentity {
514 pub chain: Chain,
515 pub name: String,
516}
517
518impl ExtractorIdentity {
519 pub fn new(chain: Chain, name: &str) -> Self {
520 Self { chain, name: name.to_owned() }
521 }
522}
523
524impl std::fmt::Display for ExtractorIdentity {
525 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
526 write!(f, "{}:{}", self.chain, self.name)
527 }
528}
529
530impl From<ExtractorIdentity> for dto::ExtractorIdentity {
531 fn from(value: ExtractorIdentity) -> Self {
532 dto::ExtractorIdentity { chain: value.chain.into(), name: value.name }
533 }
534}
535
536impl From<dto::ExtractorIdentity> for ExtractorIdentity {
537 fn from(value: dto::ExtractorIdentity) -> Self {
538 Self { chain: value.chain.into(), name: value.name }
539 }
540}
541
542#[derive(Debug, PartialEq, Clone)]
543pub struct ExtractionState {
544 pub name: String,
545 pub chain: Chain,
546 pub attributes: serde_json::Value,
547 pub cursor: Vec<u8>,
548 pub block_hash: Bytes,
549}
550
551impl ExtractionState {
552 pub fn new(
553 name: String,
554 chain: Chain,
555 attributes: Option<serde_json::Value>,
556 cursor: &[u8],
557 block_hash: Bytes,
558 ) -> Self {
559 ExtractionState {
560 name,
561 chain,
562 attributes: attributes.unwrap_or_default(),
563 cursor: cursor.to_vec(),
564 block_hash,
565 }
566 }
567}
568
569#[derive(PartialEq, Debug, Clone, Default, Deserialize, Serialize)]
570pub enum ImplementationType {
571 #[default]
572 Vm,
573 Custom,
574}
575
576#[derive(PartialEq, Debug, Clone, Default, Deserialize, Serialize)]
577pub enum FinancialType {
578 #[default]
579 Swap,
580 Psm,
581 Debt,
582 Leverage,
583}
584
585#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
586pub struct ProtocolType {
587 pub name: String,
588 pub financial_type: FinancialType,
589 pub attribute_schema: Option<serde_json::Value>,
590 pub implementation: ImplementationType,
591}
592
593impl ProtocolType {
594 pub fn new(
595 name: String,
596 financial_type: FinancialType,
597 attribute_schema: Option<serde_json::Value>,
598 implementation: ImplementationType,
599 ) -> Self {
600 ProtocolType { name, financial_type, attribute_schema, implementation }
601 }
602}
603
604#[derive(Debug, PartialEq, Eq, Default, Copy, Clone, Deserialize, Serialize, DeepSizeOf)]
605pub enum ChangeType {
606 #[default]
607 Update,
608 Deletion,
609 Creation,
610}
611
612#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
613pub struct ContractId {
614 pub address: Address,
615 pub chain: Chain,
616}
617
618impl ContractId {
620 pub fn new(chain: Chain, address: Address) -> Self {
621 Self { address, chain }
622 }
623
624 pub fn address(&self) -> &Address {
625 &self.address
626 }
627}
628
629impl Display for ContractId {
630 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
631 write!(f, "{:?}: 0x{}", self.chain, hex::encode(&self.address))
632 }
633}
634
635#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
636pub struct PaginationParams {
637 pub page: i64,
638 pub page_size: i64,
639}
640
641impl PaginationParams {
642 pub fn new(page: i64, page_size: i64) -> Self {
643 Self { page, page_size }
644 }
645
646 pub fn offset(&self) -> i64 {
647 self.page * self.page_size
648 }
649}
650
651impl From<&dto::PaginationParams> for PaginationParams {
652 fn from(value: &dto::PaginationParams) -> Self {
653 PaginationParams { page: value.page, page_size: value.page_size }
654 }
655}
656
657#[derive(Error, Debug, PartialEq)]
658pub enum MergeError {
659 #[error("Can't merge {0} from differring idendities: Expected {1}, got {2}")]
660 IdMismatch(String, String, String),
661 #[error("Can't merge {0} from different blocks: 0x{1:x} != 0x{2:x}")]
662 BlockMismatch(String, Bytes, Bytes),
663 #[error("Can't merge {0} from the same transaction: 0x{1:x}")]
664 SameTransaction(String, Bytes),
665 #[error("Can't merge {0} with lower transaction index: {1} > {2}")]
666 TransactionOrderError(String, u64, u64),
667 #[error("Cannot merge: {0}")]
668 InvalidState(String),
669}
670
671#[cfg(test)]
675mod tests {
676 use arrayvec::ArrayString;
677
678 use super::{
679 chain_config::{
680 init_chain_registry, ChainAddress, ChainConfigError, ChainTokenConfig, TvlThresholds,
681 },
682 *,
683 };
684
685 fn test_config() -> CustomChainConfig {
686 CustomChainConfig::try_new(
687 "testchain",
688 9999,
689 5,
690 ChainTokenConfig::try_new("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "TST", 18)
691 .unwrap(),
692 ChainTokenConfig::try_new("0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "WTST", 18)
693 .unwrap(),
694 TvlThresholds::new(50.0, 500.0),
695 )
696 .unwrap()
697 }
698
699 fn init_test_registry() {
700 init_chain_registry(ChainConfigRegistry::from_configs([test_config()]).unwrap())
701 .expect("chain registry already initialised; run tests under nextest");
702 }
703
704 #[test]
705 fn test_custom_chain_display() {
706 init_test_registry();
707 assert_eq!(
708 Chain::custom("testchain")
709 .unwrap()
710 .to_string(),
711 "testchain"
712 );
713 }
714
715 #[test]
716 fn test_from_str_custom_returns_err() {
717 assert!("custom".parse::<Chain>().is_err());
718 assert!("unknown".parse::<Chain>().is_err());
719 }
720
721 #[test]
722 fn test_custom_unregistered_returns_err() {
723 init_test_registry();
724 assert_eq!(Chain::custom("nope"), Err(ChainConfigError::UnknownChain("nope".to_owned())));
725 }
726
727 #[test]
728 fn test_from_dto_registered_custom_roundtrips() {
729 init_test_registry();
730 let dto_chain: dto::Chain = Chain::custom("testchain")
731 .unwrap()
732 .into();
733 let chain: Chain = dto_chain.into();
734 assert_eq!(chain.id(), 9999);
735 }
736
737 #[test]
738 #[should_panic(expected = "no registered config")]
739 fn test_from_dto_unregistered_custom_panics() {
740 let dto_chain = dto::Chain::Custom(ArrayString::from("nope").unwrap());
741 let _: Chain = dto_chain.into();
742 }
743
744 #[test]
745 fn test_try_accessors_ok_for_registered_custom() {
746 init_test_registry();
747 let chain = Chain::custom("testchain").unwrap();
748 assert_eq!(chain.try_id().unwrap(), 9999);
749 assert_eq!(chain.try_block_time_secs().unwrap(), 5);
750 assert_eq!(
751 chain
752 .try_default_tvl_threshold(TvlThresholdTier::Low)
753 .unwrap(),
754 50.0
755 );
756 assert_eq!(chain.try_native_token().unwrap().symbol, "TST");
757 assert_eq!(
758 chain
759 .try_wrapped_native_token()
760 .unwrap()
761 .symbol,
762 "WTST"
763 );
764 }
765
766 #[test]
767 fn test_try_accessors_err_for_unregistered_custom() {
768 let ghost: Chain = serde_json::from_str(r#"{"custom":"ghostchain"}"#).unwrap();
771 assert_eq!(ghost.try_id(), Err(ChainConfigError::UnknownChain("ghostchain".to_owned())));
772 assert!(ghost.try_native_token().is_err());
773 }
774
775 #[test]
776 fn test_chain_stays_small() {
777 assert!(
780 std::mem::size_of::<Chain>() <= 40,
781 "Chain is {} bytes",
782 std::mem::size_of::<Chain>()
783 );
784 }
785
786 #[test]
787 fn test_custom_chain_id() {
788 init_test_registry();
789 let chain = Chain::custom("testchain").unwrap();
790 assert_eq!(chain.id(), 9999);
791 }
792
793 #[test]
794 fn test_custom_chain_tvl_thresholds() {
795 init_test_registry();
796 let chain = Chain::custom("testchain").unwrap();
797 assert_eq!(chain.default_tvl_threshold(TvlThresholdTier::Low), 50.0);
798 assert_eq!(chain.default_tvl_threshold(TvlThresholdTier::Medium), 500.0);
799 }
800
801 #[test]
802 fn test_custom_chain_native_token() {
803 init_test_registry();
804 let chain = Chain::custom("testchain").unwrap();
805 let token = chain.native_token();
806 assert_eq!(token.symbol, "TST");
807 assert_eq!(token.decimals, 18);
808 assert_eq!(token.chain, chain);
809 assert_eq!(token.address, Bytes::from(vec![0xAA; 20]));
810 }
811
812 #[test]
813 fn test_custom_chain_wrapped_native_token() {
814 init_test_registry();
815 let chain = Chain::custom("testchain").unwrap();
816 let token = chain.wrapped_native_token();
817 assert_eq!(token.symbol, "WTST");
818 assert_eq!(token.chain, chain);
819 assert_eq!(token.address, Bytes::from(vec![0xBB; 20]));
820 }
821
822 #[test]
823 fn test_chain_address_new_rejects_oversized_input() {
824 assert_eq!(ChainAddress::new(&[0u8; 33]), Err(ChainConfigError::AddressTooLong(33)));
825 }
826
827 #[test]
828 fn test_robinhood_chain_id() {
829 assert_eq!(Chain::Robinhood.id(), 4663);
830 }
831
832 #[test]
833 fn test_robinhood_chain_display() {
834 assert_eq!(Chain::Robinhood.to_string(), "robinhood");
835 }
836
837 #[test]
838 fn test_robinhood_chain_from_str() {
839 assert_eq!("robinhood".parse::<Chain>().unwrap(), Chain::Robinhood);
840 }
841
842 #[test]
843 fn test_robinhood_native_token() {
844 let token = Chain::Robinhood.native_token();
845 assert_eq!(token.symbol, "ETH");
846 assert_eq!(token.chain, Chain::Robinhood);
847 assert_eq!(
848 token.address,
849 Bytes::from_str("0x0000000000000000000000000000000000000000").unwrap()
850 );
851 }
852
853 #[test]
854 fn test_robinhood_wrapped_native_token() {
855 let token = Chain::Robinhood.wrapped_native_token();
856 assert_eq!(token.symbol, "WETH");
857 assert_eq!(token.chain, Chain::Robinhood);
858 assert_eq!(
859 token.address,
860 Bytes::from_str("0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73").unwrap()
861 );
862 }
863
864 #[test]
865 fn test_robinhood_default_tvl_threshold() {
866 assert_eq!(Chain::Robinhood.default_tvl_threshold(TvlThresholdTier::Low), 10.0);
867 assert_eq!(Chain::Robinhood.default_tvl_threshold(TvlThresholdTier::Medium), 100.0);
868 }
869
870 #[test]
871 fn test_robinhood_block_time_secs() {
872 assert_eq!(Chain::Robinhood.block_time_secs(), 1);
873 }
874
875 #[test]
876 fn test_chain_address_as_bytes_returns_active_slice() {
877 let addr = ChainAddress::new(&[0xAA; 20]).unwrap();
878 assert_eq!(addr.as_bytes(), &[0xAA; 20]);
879 assert_eq!(addr.as_bytes().len(), 20);
880 }
881}