From 444095b131748eaaf38234ea28cf192563ee7e03 Mon Sep 17 00:00:00 2001 From: ts0yu <120932697+ts0yu@users.noreply.github.com> Date: Sun, 8 Sep 2024 08:37:43 +0000 Subject: [PATCH] feat: passing test suite, failing in anvil --- contracts/utils/foundry.toml | 2 +- src/arena.rs | 101 ++++++++++++++++++++++++++++++----- src/engine/mod.rs | 13 ++--- src/lib.rs | 15 +++--- 4 files changed, 104 insertions(+), 27 deletions(-) diff --git a/contracts/utils/foundry.toml b/contracts/utils/foundry.toml index 25b918f..e2ec3c9 100644 --- a/contracts/utils/foundry.toml +++ b/contracts/utils/foundry.toml @@ -2,5 +2,5 @@ src = "src" out = "out" libs = ["lib"] - +evm-version = "cancun" # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/src/arena.rs b/src/arena.rs index edd3aca..322cd9b 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -64,7 +64,6 @@ impl Arena { let engine = Engine { pool: self.pool.clone().into(), - provider: admin_provider.clone(), liquidity_manager: *lp_manager.address(), }; @@ -144,12 +143,86 @@ impl Arena { slot.sqrtPriceX96, ); - strategy.init( - self.providers[&(idx + 1)].clone(), - signal.clone(), - &mut self.inspector, - engine.clone(), - ); + let strategy_provider = self.providers[&(idx + 1)].clone(); + + currency_0 + .mint(strategy_provider.default_signer_address(), U256::MAX) + .nonce( + admin_provider + .get_transaction_count(admin_provider.default_signer_address()) + .await + .unwrap(), + ) + .send() + .await + .map_err(ArenaError::ContractError)? + .watch() + .await + .map_err(|e| ArenaError::PendingTransactionError(e))?; + + println!("this 1"); + + currency_1 + .mint(strategy_provider.default_signer_address(), U256::MAX) + .nonce( + admin_provider + .get_transaction_count(admin_provider.default_signer_address()) + .await + .unwrap(), + ) + .send() + .await + .map_err(ArenaError::ContractError)? + .watch() + .await + .map_err(|e| ArenaError::PendingTransactionError(e))?; + + println!("this 2"); + + currency_0 + .approve(*lp_manager.address(), U256::MAX) + .nonce( + admin_provider + .get_transaction_count(admin_provider.default_signer_address()) + .await + .unwrap(), + ) + .send() + .await + .map_err(ArenaError::ContractError)? + .watch() + .await + .map_err(|e| ArenaError::PendingTransactionError(e))?; + + println!("this 3"); + + currency_1 + .approve(*lp_manager.address(), U256::MAX) + .nonce( + admin_provider + .get_transaction_count(admin_provider.default_signer_address()) + .await + .unwrap(), + ) + .send() + .await + .map_err(ArenaError::ContractError)? + .watch() + .await + .map_err(|e| ArenaError::PendingTransactionError(e))?; + + println!("this 4"); + + strategy + .init( + self.providers[&(idx + 1)].clone(), + signal.clone(), + &mut self.inspector, + engine.clone(), + ) + .await; + + println!("this 5"); } self.arbitrageur.init(&signal, admin_provider.clone()).await; @@ -200,12 +273,14 @@ impl Arena { .await; for (idx, strategy) in self.strategies.iter_mut().enumerate() { - strategy.process( - self.providers[&(idx + 1)].clone(), - signal.clone(), - &mut self.inspector, - engine.clone(), - ); + strategy + .process( + self.providers[&(idx + 1)].clone(), + signal.clone(), + &mut self.inspector, + engine.clone(), + ) + .await; } self.feed.step(); diff --git a/src/engine/mod.rs b/src/engine/mod.rs index 83824de..55a27dc 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -56,7 +56,6 @@ impl PoolParameters { #[derive(Debug, Clone)] pub struct Engine { pub pool: PoolParameters, - pub(crate) provider: AnvilProvider, pub(crate) liquidity_manager: Address, } @@ -66,24 +65,26 @@ impl Engine { key: PoolKey, params: ModifyLiquidityParams, hook_data: Bytes, + provider: AnvilProvider, ) -> Result<(), ArenaError> { - let lp_manager = - PoolModifyLiquidityTest::new(self.liquidity_manager, self.provider.clone()); + let lp_manager = PoolModifyLiquidityTest::new(self.liquidity_manager, provider.clone()); lp_manager - .modifyLiquidity_0(key.into(), params, hook_data, false, false) + .modifyLiquidity_0(key.into(), params, hook_data, true, false) .nonce( - self.provider - .get_transaction_count(self.provider.default_signer_address()) + provider + .get_transaction_count(provider.default_signer_address()) .await .unwrap(), ) + .value(U256::from(0)) .send() .await .map_err(ArenaError::ContractError)? .watch() .await .map_err(|e| ArenaError::PendingTransactionError(e))?; + Ok(()) } } diff --git a/src/lib.rs b/src/lib.rs index f3e9ff4..189d62c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -241,7 +241,7 @@ impl Signal { #[cfg(test)] mod tests { - use alloy::primitives::{Signed, Uint}; + use alloy::primitives::{FixedBytes, Signed, Uint}; use async_trait::async_trait; use super::*; @@ -256,7 +256,6 @@ mod tests { strategy::Strategy, types::modify_liquidity::IPoolManager::ModifyLiquidityParams, }; - use alloy::primitives::FixedBytes; struct StrategyMock; @@ -264,20 +263,22 @@ mod tests { impl Strategy for StrategyMock { async fn init( &self, - _provider: AnvilProvider, + provider: AnvilProvider, signal: Signal, _inspector: &mut Box>, engine: Engine, ) { let params = ModifyLiquidityParams { - tickLower: Signed::try_from(-2).unwrap(), - tickUpper: Signed::try_from(2).unwrap(), - liquidityDelta: Signed::try_from(1000).unwrap(), + tickLower: Signed::try_from(-20).unwrap(), + tickUpper: Signed::try_from(20).unwrap(), + liquidityDelta: Signed::try_from(100000000000_u128).unwrap(), salt: FixedBytes::ZERO, }; + println!("{:#?}", signal); + engine - .modify_liquidity(signal.pool, params, Bytes::new()) + .modify_liquidity(signal.pool, params, Bytes::new(), provider.clone()) .await .unwrap(); }