Skip to main content

hylo_idl/
lib.rs

1#![allow(clippy::pub_underscore_fields, clippy::too_many_arguments)]
2
3extern crate anchor_lang;
4
5mod codegen {
6  #[cfg(not(feature = "shadow"))]
7  anchor_lang::declare_program!(hylo_earn_pool);
8  #[cfg(not(feature = "shadow"))]
9  anchor_lang::declare_program!(hylo_exchange);
10  #[cfg(not(feature = "shadow"))]
11  anchor_lang::declare_program!(hylo_router);
12  #[cfg(feature = "shadow")]
13  anchor_lang::declare_program!(hylo_earn_pool_shadow);
14  #[cfg(feature = "shadow")]
15  anchor_lang::declare_program!(hylo_exchange_shadow);
16  #[cfg(feature = "shadow")]
17  anchor_lang::declare_program!(hylo_router_shadow);
18}
19
20pub mod pda;
21pub mod tokens;
22pub mod type_bridge;
23
24mod account_builders;
25mod instruction_builders;
26
27pub mod exchange {
28  pub use super::account_builders::exchange as account_builders;
29  #[cfg(not(feature = "shadow"))]
30  pub use super::codegen::hylo_exchange::*;
31  #[cfg(feature = "shadow")]
32  pub use super::codegen::hylo_exchange_shadow::*;
33  pub use super::instruction_builders::exchange as instruction_builders;
34}
35
36pub mod earn_pool {
37  pub use super::account_builders::earn_pool as account_builders;
38  #[cfg(not(feature = "shadow"))]
39  pub use super::codegen::hylo_earn_pool::*;
40  #[cfg(feature = "shadow")]
41  pub use super::codegen::hylo_earn_pool_shadow::*;
42  pub use super::instruction_builders::earn_pool as instruction_builders;
43}
44
45pub mod router {
46  pub use super::account_builders::router as account_builders;
47  #[cfg(not(feature = "shadow"))]
48  pub use super::codegen::hylo_router::*;
49  #[cfg(feature = "shadow")]
50  pub use super::codegen::hylo_router_shadow::*;
51  pub use super::instruction_builders::router as instruction_builders;
52}
53
54#[cfg(test)]
55mod tests {
56  use anchor_lang::prelude::{pubkey, Pubkey};
57  use anchor_lang::{Discriminator, Id, ToAccountMetas};
58  use const_crypto::sha2::Sha256;
59
60  use crate::{earn_pool, exchange, pda, router};
61
62  #[cfg(not(feature = "shadow"))]
63  mod expected {
64    use super::*;
65    pub const EARN_POOL: Pubkey =
66      pubkey!("HysTabVUfmQBFcmzu1ctRd1Y1fxd66RBpboy1bmtDSQQ");
67    pub const EXCHANGE: Pubkey =
68      pubkey!("HYEXCHtHkBagdStcJCp3xbbb9B7sdMdWXFNj6mdsG4hn");
69    pub const ROUTER: Pubkey =
70      pubkey!("hyRouTRDAgn65xyyJ3L5c4k5SFmSdr3NxDV8Euzjy3f");
71  }
72
73  #[cfg(feature = "shadow")]
74  mod expected {
75    use super::*;
76    pub const EARN_POOL: Pubkey =
77      pubkey!("HYShEAST5PHe5EFxUPYUgzXsmSo88VVdDqJE21jXBQ7N");
78    pub const EXCHANGE: Pubkey =
79      pubkey!("hyshEX5sNEYhnYPMm8MwMThhBRPuLN3rjoYDbC9esPQ");
80    pub const ROUTER: Pubkey =
81      pubkey!("HyshRo2hkqXGcyCfKU22zhSBPMwokmAnEoxDGeVQz7d");
82  }
83
84  #[test]
85  fn module_ids_match_expected() {
86    assert_eq!(earn_pool::ID, expected::EARN_POOL);
87    assert_eq!(exchange::ID, expected::EXCHANGE);
88    assert_eq!(router::ID, expected::ROUTER);
89  }
90
91  #[test]
92  fn id_trait_impls_match_expected() {
93    assert_eq!(earn_pool::program::HyloEarnPool::id(), expected::EARN_POOL);
94    assert_eq!(exchange::program::HyloExchange::id(), expected::EXCHANGE);
95    assert_eq!(router::program::HyloRouter::id(), expected::ROUTER);
96  }
97
98  #[test]
99  fn router_registry_derivations_match_program_seeds() {
100    let expected_registry = Pubkey::find_program_address(
101      &[&router::constants::EXO_REGISTRY],
102      &router::ID,
103    )
104    .0;
105
106    assert_eq!(pda::EXO_REGISTRY, expected_registry);
107    assert_eq!(pda::ROUTER_EVENT_AUTHORITY, pda::event_auth(router::ID));
108  }
109
110  #[test]
111  fn router_exo_registry_builders_use_canonical_accounts() {
112    let admin = Pubkey::new_unique();
113    let collateral_mint = Pubkey::new_unique();
114
115    let initialize =
116      router::instruction_builders::initialize_exo_registry(admin);
117    assert_eq!(initialize.program_id, router::ID);
118    assert!(initialize.accounts.iter().any(|account| account.pubkey
119      == pda::EXO_REGISTRY
120      && account.is_writable));
121
122    let register =
123      router::instruction_builders::register_exo_entry(admin, collateral_mint);
124    assert_eq!(register.program_id, router::ID);
125    assert!(register.accounts.iter().any(|account| account.pubkey
126      == pda::EXO_REGISTRY
127      && account.is_writable));
128    assert!(register.accounts.iter().any(|account| {
129      account.pubkey == pda::exo_levercoin_mint(collateral_mint)
130    }));
131  }
132
133  /// Asserts `route` and `route_v2` keep the default Anchor discriminators
134  /// for their names and `route` has no fixed accounts.
135  #[test]
136  fn route_instructions_match_anchor_defaults() {
137    let route = Sha256::new().update(b"global:route").finalize();
138    let route_v2 = Sha256::new().update(b"global:route_v2").finalize();
139    assert_eq!(router::client::args::Route::DISCRIMINATOR, &route[..8]);
140    assert!(router::client::accounts::Route {}
141      .to_account_metas(None)
142      .is_empty());
143    assert_eq!(router::client::args::RouteV2::DISCRIMINATOR, &route_v2[..8]);
144  }
145}