Skip to content

Commit

Permalink
wip: save
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJepsen committed Apr 18, 2024
1 parent 074af3b commit eb8c24c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
21 changes: 19 additions & 2 deletions kit/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ use std::sync::Arc;

use arbiter_core::middleware::ArbiterMiddleware;
use ethers::{abi::AbiDecode, types::Bytes};
use futures_util::future::err;
use serde::{Deserialize, Serialize};
use tracing::warn;

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

pub mod constant_sum;
// pub mod geometric_mean;
Expand Down Expand Up @@ -241,7 +247,18 @@ impl<P: PoolType> Pool<P> {
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?;
let tx = self.dfmm.update(self.id, data);
let tx_result = tx.send().await;
match tx_result {
Ok(_) => {}
Err(er) => match er.as_middleware_error().unwrap() {
arbiter_core::errors::ArbiterCoreError::ExecutionRevert { gas_used, output } => {
let error = dfmm::DFMMErrors::decode(output);
warn!("Contract reverted with error: {:?}", error);
}
_ => todo!(),
},
}
Ok(())
}
}
48 changes: 25 additions & 23 deletions kit/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,7 @@ pub fn spawn_token_admin(world: &mut World) {
}

pub fn spawn_constant_sum_creator(world: &mut World) {
world.add_agent(Agent::builder(CREATOR).with_behavior(Create::<
creator::Config<ConstantSumPool>,
> {
token_admin: TOKEN_ADMIN.to_owned(),
data: creator::Config {
params: ConstantSumParams {
price: PRICE,
swap_fee: ethers::utils::parse_ether(0.003).unwrap(),
controller: eAddress::zero(),
},
token_list: vec![TOKEN_X_NAME.to_owned(), TOKEN_Y_NAME.to_owned()],
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: ConstantSumAllocationData {
reserve_x: RESERVE_X,
reserve_y: RESERVE_Y,
},
},
}));
world.add_agent(Agent::builder(CREATOR).with_behavior(creator()));
}

pub fn spawn_constant_sum_updater(world: &mut World) {
Expand Down Expand Up @@ -137,3 +115,27 @@ pub fn constant_sum_parameters() -> Vec<ConstantSumParams> {
}
params
}

fn creator() -> Create<creator::Config<ConstantSumPool>> {
Create::<creator::Config<ConstantSumPool>> {
token_admin: TOKEN_ADMIN.to_owned(),
data: creator::Config {
params: ConstantSumParams {
price: PRICE,
swap_fee: ethers::utils::parse_ether(0.003).unwrap(),
controller: eAddress::zero(),
},
token_list: vec![TOKEN_X_NAME.to_owned(), TOKEN_Y_NAME.to_owned()],
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: ConstantSumAllocationData {
reserve_x: RESERVE_X,
reserve_y: RESERVE_Y,
},
},
}
}
2 changes: 1 addition & 1 deletion kit/tests/update_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async fn run_updater_constant_sum() {

spawn_deployer(&mut world);
spawn_token_admin(&mut world);
spawn_constant_sum_creator(&mut world);
// spawn_constant_sum_creator(&mut world);
spawn_constant_sum_updater(&mut world);

let task: tokio::task::JoinHandle<()> = tokio::spawn(async move {
Expand Down

0 comments on commit eb8c24c

Please sign in to comment.