arena_core/engine/
mod.rs

1use alloy::{
2    primitives::{Address, Signed, I256},
3    providers::{Provider, WalletProvider},
4};
5
6use super::*;
7use crate::{error::ArenaError, types::controller::ArenaController};
8/// Defines a trait for custom arbitrage strategies.
9pub mod arbitrageur;
10
11/// Defines a trait that allows custom strategy logging and telemetry.
12pub mod inspector;
13
14/// Abstraction to allow strategies to call state changing functions on the PoolManager without having to worry about callbacks.
15#[derive(Debug, Clone)]
16pub struct Engine {
17    pub(crate) controller: Address,
18}
19
20#[allow(clippy::redundant_closure)]
21impl Engine {
22    /// Modify pool liquidity.
23    pub async fn modify_liquidity(
24        &self,
25        liquidity_delta: I256,
26        tick_lower: Signed<24, 1>,
27        tick_upper: Signed<24, 1>,
28        hook_data: Bytes,
29        provider: AnvilProvider,
30    ) -> Result<(), ArenaError> {
31        let controller = ArenaController::new(self.controller, provider.clone());
32
33        controller
34            .addLiquidity(liquidity_delta, tick_lower, tick_upper, hook_data)
35            .nonce(
36                provider
37                    .get_transaction_count(provider.default_signer_address())
38                    .await
39                    .unwrap(),
40            )
41            .send()
42            .await
43            .map_err(ArenaError::ContractError)?
44            .watch()
45            .await
46            .map_err(|e| ArenaError::PendingTransactionError(e))?;
47
48        Ok(())
49    }
50}