Skip to content

Commit

Permalink
chore: onto great things (contract reverts)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJepsen committed Apr 18, 2024
1 parent 30af3d7 commit 074af3b
Show file tree
Hide file tree
Showing 21 changed files with 78 additions and 89 deletions.
26 changes: 13 additions & 13 deletions kit/src/behaviors/update.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use bindings::idfmm::IDFMM;
use tracing::warn;

use super::*;
use crate::bindings::erc20::ERC20;

Expand Down Expand Up @@ -50,16 +53,16 @@ where
) -> Result<Option<(Self::Processor, EventStream<Message>)>> {
// Configuration from deployed contracts

debug!("starting the updator");
debug!("Startup: starting the updator");
let deployment_data = messager.clone().get_next::<DeploymentData>().await?.data;
debug!("got message {:?}", deployment_data);
debug!("Startup: got message {:?}", deployment_data);
let (strategy_contract, solver_contract) =
P::get_contracts(&deployment_data, client.clone());
let dfmm = DFMM::new(deployment_data.dfmm, client.clone());
let mut init_event_stream = stream_event(dfmm.init_filter());

let init_event = init_event_stream.next().await.unwrap();
debug!("got init event {:?}", init_event);
debug!("Startup: got init event {:?}", init_event);

let instance = loop {
// TODO: This is where we use the weird tuple struct to bypass compile issues
Expand All @@ -76,11 +79,8 @@ where
let lp_token = ERC20::new(init_event.lp_token, client.clone());
// Get the intended tokens for the pool and do approvals.
let mut tokens: Vec<ArbiterToken<ArbiterMiddleware>> = Vec::new();
for _ in self.data.token_list.drain(..) {
let token = ArbiterToken::new(
messager.get_next::<eAddress>().await.unwrap().data,
client.clone(),
);
for token in init_event.tokens {
let token = ArbiterToken::new(token, client.clone());
tokens.push(token);
}

Expand All @@ -101,6 +101,7 @@ where
pool_params: self.data.params.clone(),
},
};
warn!("got to the end up the updator startup");
let stream = process.data.messager.clone().stream()?;
Ok(Some((process, stream)))
}
Expand All @@ -112,17 +113,16 @@ where
P: PoolType + Send + Sync,
{
async fn process(&mut self, event: Message) -> Result<ControlFlow> {
warn!("Process: Got event: {:?}", event);
let msg: UpdatoorQuerry = serde_json::from_str(&event.data).unwrap_or(UpdatoorQuerry::NoOp);

warn!("Process: deserialized update querry: {:?}", msg);

match msg {
UpdatoorQuerry::UpdateMeDaddy => {
let params = self.data.pool_params.pop().unwrap();
self.data.pool.update(params.clone()).await?;
let _ = self
.data
.messager
.send(To::Agent(event.from), params)
.await?;
let _ = self.data.messager.send(To::All, params).await?;
}

UpdatoorQuerry::NoOp => {
Expand Down
4 changes: 2 additions & 2 deletions kit/src/bindings/constant_sum.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions kit/src/bindings/constant_sum_solver.rs

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions kit/src/bindings/dfmm.rs

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions kit/src/bindings/dfmm_init.rs

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions kit/src/bindings/dfmm_internal.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions kit/src/bindings/g3m_set_up.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions kit/src/bindings/geometric_mean.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions kit/src/bindings/geometric_mean_solver.rs

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions kit/src/bindings/idfmm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ pub mod idfmm {
::ethers::core::abi::ethabi::ParamType::Address,
),
),
indexed: true,
indexed: false,
},
::ethers::core::abi::ethabi::EventParam {
name: ::std::borrow::ToOwned::to_owned("reserves"),
Expand Down Expand Up @@ -1205,8 +1205,7 @@ pub mod idfmm {
pub strategy: ::ethers::core::types::Address,
pub lp_token: ::ethers::core::types::Address,
pub pool_id: ::ethers::core::types::U256,
#[ethevent(indexed)]
pub tokens: ::ethers::core::types::H256,
pub tokens: ::std::vec::Vec<::ethers::core::types::Address>,
pub reserves: ::std::vec::Vec<::ethers::core::types::U256>,
pub total_liquidity: ::ethers::core::types::U256,
}
Expand Down
4 changes: 2 additions & 2 deletions kit/src/bindings/log_normal.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions kit/src/bindings/log_normal_arbitrage.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions kit/src/bindings/log_normal_solver.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions kit/src/bindings/n_token_geometric_mean.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions kit/src/bindings/n_token_geometric_mean_solver.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions kit/src/bindings/set_up.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions kit/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use serde::{Deserialize, Serialize};

use self::{
behaviors::deploy::DeploymentData,
bindings::{erc20::ERC20, i_strategy::IStrategy, shared_types},
bindings::{erc20::ERC20, i_strategy::IStrategy, shared_types, arbiter_token::ArbiterToken, dfmm::DFMM, shared_types::InitParams},
};
use super::*;
use crate::bindings::{arbiter_token::ArbiterToken, dfmm::DFMM, shared_types::InitParams};

pub mod constant_sum;
// pub mod geometric_mean;
Expand Down Expand Up @@ -241,6 +240,7 @@ impl<P: PoolType> Pool<P> {
/// error.
pub async fn update(&self, new_data: P::Parameters) -> Result<()> {
let data = self.instance.update_data(new_data).await?;
info!("Got update data");
self.dfmm.update(self.id, data).send().await?.await?;
Ok(())
}
Expand Down
15 changes: 0 additions & 15 deletions kit/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,3 @@ pub fn constant_sum_parameters() -> Vec<ConstantSumParams> {
}
params
}
// pub fn spawn_geometric_mean_creator(world: &mut World) {
// world.add_agent(Agent::builder(CREATOR).with_behavior(Creator::<
// creator::Config<GeometricMeanPool>,
// > { token_admin: TOKEN_ADMIN.to_owned(), data: creator::Config { params:
// > GeometricMeanParams { target_weight_y:
// > ethers::utils::parse_ether(0.5).unwrap(), target_weight_x:
// > ethers::utils::parse_ether(0.5).unwrap(), w_x: todo!(), w_y: todo!(),
// > swap_fee: todo!(), controller: todo!(), }, base_config: BaseConfig {
// > name: "Test Pool".to_string(), symbol: "TP".to_string(), swap_fee:
// > ethers::utils::parse_ether(0.003).unwrap(), controller_fee: 0.into(),
// > }, allocation_data: GeometricMeanAllocationData { amount_x: RESERVE_X,
// > price: WAD, }, token_list: vec![TOKEN_X_NAME.to_owned(),
// > TOKEN_Y_NAME.to_owned()], },
// }));
// }
2 changes: 1 addition & 1 deletion kit/tests/creator_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ async fn run_creator_constant_sum() {
panic!("Test timed out");
}
}
}
}
42 changes: 25 additions & 17 deletions kit/tests/update_integration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,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;
Expand All @@ -23,26 +24,33 @@ 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;
messager
.send(
To::Agent(CREATOR.to_owned()),
update::UpdatoorQuerry::UpdateMeDaddy,
)
.await
.unwrap();
for _ in 0..2 {
messager
.send(
To::Agent(UPDATER.to_owned()),
update::UpdatoorQuerry::UpdateMeDaddy,
)
.await
.unwrap();
}
let mut count = 0;
let mut stream = messager.stream().unwrap();
// let mut count = 0;
while let Some(message) = stream.next().await {
info!("Saw message: {:#?}", message);

// BUG IS HERE: for some reason we are never entering this loop
match serde_json::from_str::<ConstantSumParams>(&message.data) {
match serde_json::from_str::<MessageTypes<ConstantSumPool>>(&message.data) {
Ok(data) => {
info!("Saw data: {:#?}", data);
let mock_data = constant_sum_parameters();
assert_eq!(data, mock_data[0]);
info!("Asserts passed!");
break;
info!("deserialized data: {:#?}", data);
match data {
MessageTypes::Deploy(_) => continue,
MessageTypes::Create(_) => continue,
MessageTypes::TokenAdmin(_) => continue,
MessageTypes::Update(params) => {
let mock_data = constant_sum_parameters();
// assert_eq!(data, mock_data[0]);
warn!("deseriazlied into update respondse {:?}", params);
break;
}
}
}
Err(_) => {
warn!(
Expand All @@ -57,7 +65,7 @@ async fn run_updater_constant_sum() {
});

// Setup a timeout for the test to ensure it does not run indefinitely.
let timeout_duration = Duration::from_secs(5); // Adjust the timeout as needed.
let timeout_duration = Duration::from_secs(10); // Adjust the timeout as needed.

tokio::select! {
_ = world.run() => {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IDFMM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ interface IDFMM {
address strategy,
address lpToken,
uint256 poolId,
address[] indexed tokens,
address[] tokens,
uint256[] reserves,
uint256 totalLiquidity
);
Expand Down

0 comments on commit 074af3b

Please sign in to comment.