Skip to content

Commit

Permalink
debug: ruled out token aprovals and mints
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJepsen committed Apr 11, 2024
1 parent 62a3c5a commit 858c207
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 76 deletions.
6 changes: 6 additions & 0 deletions kit/configs/test.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
[[deployer]]
Deployer = {}

[[token_admin]]
TokenAdmin = { init_token_data = [
{ name = "US Dollar Coin", symbol = "USDC", decimals = 18 },
{ name = "Wrapped Ether", symbol = "WETH", decimals = 18 },
] }
99 changes: 67 additions & 32 deletions kit/src/behaviors/creator.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use arbiter_engine::machine::{Behavior, Configuration, Processing, Processor, State};
use arbiter_engine::{
machine::{Behavior, Configuration, Processing, Processor, State},
universe,
};
use bindings::dfmm::DFMM;
use futures_util::StreamExt;
use serde::de::DeserializeOwned;
use tracing::debug;

use super::*;
use crate::{
behaviors::deployer::DeploymentData,
behaviors::{deployer::DeploymentData, token_admin::TokenAdminQuery},
bindings::dfmm,
pool::{Pool, PoolType},
};

Expand Down Expand Up @@ -41,6 +45,8 @@ pub struct PoolProcessor<P: PoolType> {
impl<P> Behavior<()> for PoolCreator<Configuration<PoolConfig<P>>>
where
P: PoolType + Send + Sync + 'static,
P::StrategyContract: Send,
P::SolverContract: Send,
{
// type Processor = PoolCreator<Processing<PoolProcessor<P>>>;
type Processor = ();
Expand All @@ -49,7 +55,7 @@ where
client: Arc<ArbiterMiddleware>,
messager: Messager,
) -> Result<Option<(Self::Processor, EventStream<()>)>> {
let mut stream = messager.stream()?;
let mut stream = messager.clone().stream()?;
let res = stream.next().await.unwrap();
let data: String = serde_json::from_str(&res.data).expect(
"Failed to
Expand All @@ -60,10 +66,54 @@ deserialize message data",
token data",
);

let token_x = ArbiterToken::new(parsed_data.token_x, client.clone());
let token_y = ArbiterToken::new(parsed_data.token_y, client.clone());
let _ = messager
.send(
To::Agent("token_admin_agent".to_owned()),
TokenAdminQuery::GetAssetUniverse,
)
.await?;
let res = stream.next().await.unwrap();
let universe: Vec<(TokenData, eAddress)> =
serde_json::from_str(&res.data).expect("failed to serde");

let token_x = ArbiterToken::new(universe[0].clone().1, client.clone());
let token_y = ArbiterToken::new(universe[1].clone().1, client.clone());

let mint_x = MintRequest {
token: universe[0].clone().0.name,
mint_to: client.address(),
mint_amount: 100_000_000_000,
};

let mint_y = MintRequest {
token: universe[1].clone().0.name,
mint_to: client.address(),
mint_amount: 100_000_000_000,
};

let _ = messager
.send(To::Agent("token_admin_agent".to_owned()), mint_x)
.await?;
let _ = messager
.send(To::Agent("token_admin_agent".to_owned()), mint_y)
.await?;

let (strategy_contract, solver_contract) = P::get_contracts(&parsed_data, client.clone());
let dfmm = DFMM::new(parsed_data.dfmm, client);

let _ = token_x
.clone()
.approve(dfmm.address(), MAX)
.send()
.await?
.await?;
let _ = token_y
.clone()
.approve(dfmm.address(), MAX)
.send()
.await?
.await?;

let init_data = self.data.initial_allocation_data.clone();
debug!("Got to before pool deployment");
let pool = P::create_pool(
Expand Down Expand Up @@ -119,35 +169,20 @@ mod test {

let mut world = World::new("test");

let agent = Agent::builder("token_admin_agent");
let creator = Agent::builder("pool_creator_agent");
let pool_creator = PoolCreator::<Configuration<PoolConfig<ConstantSumPool>>> {
data: PoolConfig {
params: ConstantSumParams {
price: WAD,
swap_fee: 0.into(),
controller: eAddress::random(),
},
initial_allocation_data: ConstantSumInitData {
name: "Test Pool".to_string(),
symbol: "TP".to_string(),
reserve_x: WAD,
reserve_y: WAD,
token_x_name: "Token X".to_string(),
token_y_name: "Token Y".to_string(),
params: ConstantSumParams {
price: WAD,
swap_fee: 10000.into(),
controller: Address::zero(),
},
},
token_list: vec![Address::zero(), Address::zero()],
},
};
world.add_agent(creator.with_behavior(pool_creator));

// deployer
let agent = Agent::builder("deployer");
world.add_agent(agent.with_behavior(Deployer {}));

// Token Admin
let token_admin_config = default_admin_config();
let token_admin = Agent::builder("token_admin_agent");
world.add_agent(token_admin.with_behavior(token_admin_config));

// Pool Creator
let creator = Agent::builder("pool_creator_agent");
let pool_creator_config = default_creator_config();
world.add_agent(creator.with_behavior(pool_creator_config));

world.run().await.unwrap();
}
}
27 changes: 0 additions & 27 deletions kit/src/behaviors/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ pub struct DeploymentData {
pub log_normal: Address,
pub constant_sum: Address,
pub constant_sum_solver: Address,
pub token_x: Address,
pub token_y: Address,
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -52,25 +50,6 @@ impl Behavior<()> for Deployer {
.await?;
trace!("ConstantSum deployed at {:?}", constant_sum.address());

let token_x = ArbiterToken::deploy(
client.clone(),
("Token X".to_owned(), "ARBX".to_owned(), 18u8),
)?
.send()
.await?;
let token_y = ArbiterToken::deploy(
client.clone(),
("Token Y".to_owned(), "ARBY".to_owned(), 18u8),
)?
.send()
.await?;

trace!(
"Tokens deployed at {:?} and {:?}",
token_x.address(),
token_y.address()
);

let n_token_geometric_mean = GeometricMean::deploy(client.clone(), dfmm.address())?
.send()
.await?;
Expand All @@ -79,10 +58,6 @@ impl Behavior<()> for Deployer {
.send()
.await?;

// do aprovals to DFMM contract mint tokens to creator agent
token_y.approve(dfmm.address(), MAX).send().await?.await?;
token_x.approve(dfmm.address(), MAX).send().await?.await?;

let deployment_data = DeploymentData {
n_token_geometric_mean: n_token_geometric_mean.address(),
weth: weth.address(),
Expand All @@ -91,8 +66,6 @@ impl Behavior<()> for Deployer {
log_normal: log_normal.address(),
constant_sum: constant_sum.address(),
constant_sum_solver: cs_solver.address(),
token_x: token_x.address(),
token_y: token_y.address(),
};

messager
Expand Down
52 changes: 50 additions & 2 deletions kit/src/behaviors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;

use arbiter_engine::{
agent::Agent,
machine::{Behavior, Configuration, ControlFlow, EventStream},
messager::{Messager, To},
};
Expand All @@ -9,9 +10,13 @@ use bindings::arbiter_token::ArbiterToken;
use serde::{Deserialize, Serialize};

use self::{
bindings::constant_sum_solver::ConstantSumParams,
creator::{PoolConfig, PoolCreator},
deployer::Deployer,
pool::PoolType,
pool::{
constant_sum::{ConstantSumInitData, ConstantSumPool},
PoolType,
},
token_admin::{TokenAdmin, TokenAdminConfig}, /* token_admin::TokenAdmin,
* allocate::InitialAllocation, */
};
Expand All @@ -34,5 +39,48 @@ pub struct TokenData {
pub name: String,
pub symbol: String,
pub decimals: u8,
pub address: Option<eAddress>,
}

pub(crate) fn default_admin_config() -> TokenAdmin<Configuration<TokenAdminConfig>> {
let token1 = TokenData {
name: "US Dollar Coin".to_owned(),
symbol: "USDC".to_owned(),
decimals: 18,
};

let token2 = TokenData {
name: "ShibaInuObamaSonic Coin".to_owned(),
symbol: "SIOS".to_owned(),
decimals: 18,
};
let config = TokenAdminConfig {
token_data: vec![token1, token2],
};
TokenAdmin::<Configuration<TokenAdminConfig>> { data: config }
}

pub(crate) fn default_creator_config() -> PoolCreator<Configuration<PoolConfig<ConstantSumPool>>> {
PoolCreator::<Configuration<PoolConfig<ConstantSumPool>>> {
data: PoolConfig {
params: ConstantSumParams {
price: WAD,
swap_fee: 0.into(),
controller: eAddress::random(),
},
initial_allocation_data: ConstantSumInitData {
name: "Test Pool".to_string(),
symbol: "TP".to_string(),
reserve_x: WAD,
reserve_y: WAD,
token_x_name: "Token X".to_string(),
token_y_name: "Token Y".to_string(),
params: ConstantSumParams {
price: WAD,
swap_fee: 10000.into(),
controller: eAddress::zero(),
},
},
token_list: vec![eAddress::zero(), eAddress::zero()],
},
}
}
Loading

0 comments on commit 858c207

Please sign in to comment.