From 2a50abb2430fac8a20a22dc650d15969841f24a2 Mon Sep 17 00:00:00 2001 From: Waylon Jepsen Date: Fri, 19 Apr 2024 14:17:28 -0700 Subject: [PATCH] chore: Updater tests passing --- kit/src/behaviors/creator.rs | 10 ++++++++++ kit/src/behaviors/update.rs | 16 ++++++++++++---- kit/src/pool/constant_sum.rs | 5 +++++ kit/src/pool/mod.rs | 18 ++++++++++++++++-- kit/tests/common.rs | 15 ++++++++++----- kit/tests/update_integration.rs | 15 +++++++++------ 6 files changed, 62 insertions(+), 17 deletions(-) diff --git a/kit/src/behaviors/creator.rs b/kit/src/behaviors/creator.rs index 575076fb..5b750464 100644 --- a/kit/src/behaviors/creator.rs +++ b/kit/src/behaviors/creator.rs @@ -83,6 +83,13 @@ where tokens.push(token); } + debug!( + "Setting Controller Address to self address: {:?}", + client.address() + ); + if self.data.base_config.controller == eAddress::zero() { + self.data.base_config.controller = client.address(); + } debug!("creating pool..."); // Create the pool. let pool = Pool::

::new( @@ -110,6 +117,9 @@ where pool.id, pool.tokens.iter().map(|t| t.address()).collect::>(), pool.liquidity_token.address(), + // TODO: This params will show the incorrect controller address + // Would be nice to have it be the correct one set on line 88 + // so that the debug msg's are more helpful self.data.params.clone(), self.data.allocation_data.clone(), ); diff --git a/kit/src/behaviors/update.rs b/kit/src/behaviors/update.rs index 91cb8158..a27da045 100644 --- a/kit/src/behaviors/update.rs +++ b/kit/src/behaviors/update.rs @@ -1,3 +1,5 @@ +use std::collections::VecDeque; + use bindings::idfmm::IDFMM; use tracing::warn; @@ -15,7 +17,7 @@ pub struct Config { pub base_config: BaseConfig, pub allocation_data: P::AllocationData, pub token_list: Vec, - pub params: Vec, + pub params: VecDeque, } #[derive(Debug, Clone)] @@ -23,7 +25,7 @@ pub struct Processing { pub messager: Messager, pub client: Arc, pub pool: Pool

, - pub pool_params: Vec, + pub pool_params: VecDeque, } impl State for Config

{ @@ -64,6 +66,7 @@ where mut messager: Messager, ) -> Result)>> { // Make a "TODO" list. + // This is the data I need to recieve to do my job let mut todo: Todo

= Todo { deployment_data: None, pool_creation: None, @@ -152,9 +155,14 @@ where match msg { UpdatoorQuerry::UpdateMeDaddy => { - let params = self.data.pool_params.pop().unwrap(); + let params = self.data.pool_params.pop_front().unwrap(); self.data.pool.update(params.clone()).await?; - let _ = self.data.messager.send(To::All, params).await?; + let _ = self + .data + .messager + .send(To::Agent(event.from), MessageTypes::Update::

(params)) + .await?; + info!("Successfully updated!"); } UpdatoorQuerry::NoOp => { diff --git a/kit/src/pool/constant_sum.rs b/kit/src/pool/constant_sum.rs index 0e17728b..529525df 100644 --- a/kit/src/pool/constant_sum.rs +++ b/kit/src/pool/constant_sum.rs @@ -45,6 +45,11 @@ impl PoolType for ConstantSumPool { Ok(init_bytes) } + fn set_controller(mut params: Self::Parameters, controller: eAddress) -> Self::Parameters { + params.controller = controller; + params + } + fn get_strategy_address(strategy_contract: &Self::StrategyContract) -> eAddress { strategy_contract.address() } diff --git a/kit/src/pool/mod.rs b/kit/src/pool/mod.rs index 29ee9e4d..db25c45f 100644 --- a/kit/src/pool/mod.rs +++ b/kit/src/pool/mod.rs @@ -29,6 +29,7 @@ pub struct BaseConfig { pub name: String, pub symbol: String, pub swap_fee: eU256, + pub controller: eAddress, pub controller_fee: eU256, } @@ -84,6 +85,8 @@ pub trait PoolType: Clone + Debug + 'static { solver_contract: &Self::SolverContract, ) -> Result; + fn set_controller(params: Self::Parameters, controller: eAddress) -> Self::Parameters; + fn create_instance( strategy_contract: Self::StrategyContract, solver_contract: Self::SolverContract, @@ -142,7 +145,17 @@ impl Pool

{ dfmm: DFMM, tokens: Vec>, ) -> Result { - let data = P::get_init_data(params.clone(), &allocation_data, &solver_contract).await?; + // This seems a little hacky but might be the way forward untill we get the + // contract changes settled in the future we should see if we can work + // with Matt and Clement to remove the controller from the init params + let params_with_controller = P::set_controller(params, base_config.controller); + + let data = P::get_init_data( + params_with_controller.clone(), + &allocation_data, + &solver_contract, + ) + .await?; debug!("Got init data {:?}", data); let init_params = InitParams { name: base_config.name, @@ -157,7 +170,8 @@ impl Pool

{ let (id, _reserves, _total_liquidity) = dfmm.init(init_params.clone()).call().await?; dfmm.init(init_params).send().await?.await?; let pool: shared_types::Pool = dfmm.pools(id).call().await?; - let instance = P::create_instance(strategy_contract, solver_contract, params); + let instance = + P::create_instance(strategy_contract, solver_contract, params_with_controller); let client = dfmm.client(); let pool = Self { diff --git a/kit/tests/common.rs b/kit/tests/common.rs index 14679721..d0db756e 100644 --- a/kit/tests/common.rs +++ b/kit/tests/common.rs @@ -1,3 +1,5 @@ +use std::collections::VecDeque; + use arbiter_engine::{agent::Agent, world::World}; use dfmm_kit::{ behaviors::{ @@ -87,6 +89,7 @@ pub fn spawn_constant_sum_updater(world: &mut World) { symbol: "TP".to_string(), swap_fee: ethers::utils::parse_ether(0.003).unwrap(), controller_fee: 0.into(), + controller: eAddress::zero(), }, allocation_data: ConstantSumAllocationData { reserve_x: RESERVE_X, @@ -100,20 +103,21 @@ pub fn spawn_constant_sum_updater(world: &mut World) { ) } -pub fn constant_sum_parameters() -> Vec { - let prices = vec![ +pub fn constant_sum_parameters() -> VecDeque { + let prices: VecDeque = vec![ PRICE, ethers::utils::parse_ether(2).unwrap(), ethers::utils::parse_ether(3).unwrap(), - ]; - let mut params = vec![]; + ] + .into(); + let mut params = VecDeque::new(); for price in prices { let parameter = ConstantSumParams { price, swap_fee: ethers::utils::parse_ether(0.003).unwrap(), controller: eAddress::zero(), }; - params.push(parameter); + params.push_back(parameter); } params } @@ -133,6 +137,7 @@ fn creator() -> Create> { symbol: "TP".to_string(), swap_fee: ethers::utils::parse_ether(0.003).unwrap(), controller_fee: 0.into(), + controller: eAddress::zero(), }, allocation_data: ConstantSumAllocationData { reserve_x: RESERVE_X, diff --git a/kit/tests/update_integration.rs b/kit/tests/update_integration.rs index 93ec2024..f9b698fe 100644 --- a/kit/tests/update_integration.rs +++ b/kit/tests/update_integration.rs @@ -3,8 +3,7 @@ use std::time::Duration; use arbiter_engine::messager::To; use dfmm_kit::behaviors::MessageTypes; use futures_util::StreamExt; -use tracing::{debug, info, warn}; -use tracing_subscriber::registry::Data; +use tracing::{info, warn}; include!("common.rs"); #[tokio::test(flavor = "multi_thread", worker_threads = 5)] @@ -24,7 +23,7 @@ async fn run_updater_constant_sum() { // receivers. TODO: This is a bit of a hack and we could honestly make // the `World::run` better to handle this, but this works for now. tokio::time::sleep(Duration::from_millis(2000)).await; - for _ in 0..2 { + for _ in 0..3 { messager .send( To::Agent(UPDATER.to_owned()), @@ -45,10 +44,14 @@ async fn run_updater_constant_sum() { MessageTypes::Create(_) => continue, MessageTypes::TokenAdmin(_) => continue, MessageTypes::Update(params) => { + info!("successfully updated the params to {:?}", params); let mock_data = constant_sum_parameters(); - // assert_eq!(data, mock_data[0]); - warn!("deseriazlied into update respondse {:?}", params); - break; + assert_eq!(params, mock_data[count]); + if count >= 2 { + break; + } else { + count += 1; + } } } }