Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Autoparallel committed Oct 25, 2023
1 parent 39aa45e commit 470d5dd
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 34 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ mdbook-katex = "0.5.8"
[arbiter]
bindings_workspace = "simulation" # must be a valid workspace member
submodules = false # change to true if you want the submodule bindings to be generated

3 changes: 1 addition & 2 deletions simulation/src/agents/arbitrageur.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::*;
use crate::agents::Agent;
use crate::strategy::ArbitrageStrategy;
use crate::{agents::Agent, strategy::ArbitrageStrategy};

#[derive(Clone)]
pub struct Arbitrageur<S: ArbitrageStrategy> {
Expand Down
6 changes: 3 additions & 3 deletions simulation/src/agents/liquidity_provider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::strategy::LiquidityStrategy;

use super::{strategy::Strategy, token_admin::TokenAdmin, *};
use crate::strategy::LiquidityStrategy;

#[derive(Clone)]
pub struct LiquidityProvider<S: LiquidityStrategy> {
Expand Down Expand Up @@ -42,7 +41,8 @@ impl<S: LiquidityStrategy> LiquidityProvider<S> {
#[async_trait::async_trait]
impl<S: LiquidityStrategy + std::marker::Sync + std::marker::Send> Agent for LiquidityProvider<S> {
async fn startup(&mut self) -> Result<()> {
// Initializes the liquidity of a pool with a target price given an initial amount of x tokens.
// Initializes the liquidity of a pool with a target price given an initial
// amount of x tokens.
let tx = self
.strategy
.instantiate(self.initial_x, self.initial_price)
Expand Down
7 changes: 5 additions & 2 deletions simulation/src/agents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ pub mod price_changer;
pub mod token_admin;
pub mod weight_changer;

use crate::settings::parameters::Direct;
use std::marker::{Send, Sync};

/// Universal agent methods for interacting with the simulation environment or loop.
use crate::settings::parameters::Direct;

/// Universal agent methods for interacting with the simulation environment or
/// loop.
#[async_trait::async_trait]
pub trait Agent: Sync + Send {
/// Executed outside the main simulation loop.
Expand Down Expand Up @@ -39,6 +41,7 @@ impl Agents {
}

impl Agents {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self(vec![])
}
Expand Down
6 changes: 4 additions & 2 deletions simulation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// TODO: Is it possible to just give every agent a reference to the client from the get go and use only that to construct them?
// TODO: Is it possible to just give every agent a reference to the client from
// the get go and use only that to construct them?

use std::{collections::BTreeMap, sync::Arc};
use std::sync::Arc;

use anyhow::Result;
use arbiter_core::{
Expand Down Expand Up @@ -28,6 +29,7 @@ use tracing::{info, trace};

#[allow(unused)]
mod agents;
#[allow(non_snake_case)]
pub mod bindings;
#[allow(unused)]
mod math;
Expand Down
6 changes: 3 additions & 3 deletions simulation/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use std::{env, path::Path};

use parameters::*;

use crate::simulations::SimulationType;

use super::*;
use crate::simulations::SimulationType;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SimulationConfig<P: Parameterized<f64>> {
Expand Down Expand Up @@ -105,9 +104,10 @@ impl Parameterized<SimulationConfig<Direct>> for SimulationConfig<Meta> {

#[cfg(test)]
mod tests {
use super::*;
use parameters::Parameterized;

use super::*;

#[test]
fn read_in_static() {
let config = SimulationConfig::new("configs/test/static.toml").unwrap();
Expand Down
10 changes: 5 additions & 5 deletions simulation/src/simulations/dynamic_weights.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use super::errors::SimulationError;
use super::*;
use crate::agents::{Agent, Agents};
use arbiter_core::environment::builder::BlockSettings;

use super::{errors::SimulationError, *};
use crate::{
agents::{
arbitrageur::Arbitrageur, block_admin::BlockAdmin, liquidity_provider::LiquidityProvider,
price_changer::PriceChanger, token_admin::TokenAdmin, weight_changer::WeightChanger,
price_changer::PriceChanger, token_admin::TokenAdmin, weight_changer::WeightChanger, Agent,
Agents,
},
bindings::i_strategy::IStrategy,
settings::SimulationConfig,
};
use arbiter_core::environment::builder::BlockSettings;

pub async fn setup(config: SimulationConfig<Direct>) -> Result<Simulation, SimulationError> {
let environment = EnvironmentBuilder::new()
Expand Down
4 changes: 2 additions & 2 deletions simulation/src/simulations/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

use thiserror::Error;

use super::*;

#[derive(Error, Debug)]
pub enum SimulationError {
#[error("Agent error: {0}")]
Expand Down
5 changes: 2 additions & 3 deletions simulation/src/simulations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use tokio::runtime::Runtime;
use tracing::{debug, warn};

use self::errors::SimulationError;

use super::*;

use crate::{
agents::{Agent, Agents},
settings::parameters::Direct,
Expand Down Expand Up @@ -85,9 +83,10 @@ pub async fn looper(mut agents: Agents, steps: usize) -> Result<()> {

#[cfg(test)]
mod tests {
use super::*;
use std::{env, io::Read, path::Path};

use super::*;

#[test]
fn static_output() {
batch("configs/test/static.toml").unwrap();
Expand Down
9 changes: 5 additions & 4 deletions simulation/src/strategy/g3m.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use ethers::types::TransactionReceipt;

use crate::bindings::i_strategy::IStrategy;

use super::*;
use crate::bindings::i_strategy::IStrategy;

/// Type of data that is specific to the G3M strategy.
/// Each G3M pool has weights for each side of the pool.
Expand Down Expand Up @@ -39,7 +38,8 @@ impl Strategy for IStrategy<RevmMiddleware> {
}
}

/// G3M pools must be initialized with a starting amount of x tokens and an initial price.
/// G3M pools must be initialized with a starting amount of x tokens and an
/// initial price.
#[async_trait::async_trait]
impl LiquidityStrategy for IStrategy<RevmMiddleware> {
async fn instantiate(
Expand All @@ -55,7 +55,8 @@ impl LiquidityStrategy for IStrategy<RevmMiddleware> {
}
}

/// Uses algebraic methods based on the G3M invariant math to compute the amount of tokens to swap.
/// Uses algebraic methods based on the G3M invariant math to compute the amount
/// of tokens to swap.
#[async_trait::async_trait]
impl ArbitrageStrategy for IStrategy<RevmMiddleware> {
async fn get_x_input(
Expand Down
21 changes: 14 additions & 7 deletions simulation/src/strategy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use super::*;
pub mod g3m;
pub mod rmm;

/// Strategies are a layer between an agent and the smart contracts responsible for managing a strategy's parameters and assets.
/// Sub-traits extend this core Strategy trait to provide additional functionality that is specific to different agents.
/// Strategies are a layer between an agent and the smart contracts responsible
/// for managing a strategy's parameters and assets. Sub-traits extend this core
/// Strategy trait to provide additional functionality that is specific to
/// different agents.
#[async_trait::async_trait]
pub trait Strategy: Sized {
/// Strategy stored is fetched from the strategy smart contract as bytes.
Expand All @@ -20,23 +22,28 @@ pub trait Strategy: Sized {
/// Returns the fee charged to the arbitrageur on rebalances.
async fn get_swap_fee(&self) -> Result<U256>;

/// Responsible for decoding the strategy data into the strategy data type defined above.
/// Responsible for decoding the strategy data into the strategy data type
/// defined above.
async fn decode_strategy_data(&self) -> Result<Self::StrategyData>;
}

/// A sub-trait for liquidity providers to implement their specific logic for providing/setting up a pool.
/// A sub-trait for liquidity providers to implement their specific logic for
/// providing/setting up a pool.
#[async_trait::async_trait]
pub trait LiquidityStrategy: Strategy {
/// Provides the pool with an initial amount of reserves and liquidity, at a price.
/// Provides the pool with an initial amount of reserves and liquidity, at a
/// price.
async fn instantiate(
&self,
initial_x_wad: U256,
initial_price_wad: U256,
) -> Result<Option<TransactionReceipt>>;
}

/// A sub-trait for arbitrageurs to implement their logic for computing how many tokens to swap.
/// For example, a generalized arbitrageur can use a root-finding method, while a specialized arbitrageur (arb G3M pools) can use algebra.
/// A sub-trait for arbitrageurs to implement their logic for computing how many
/// tokens to swap. For example, a generalized arbitrageur can use a
/// root-finding method, while a specialized arbitrageur (arb G3M pools) can use
/// algebra.
#[async_trait::async_trait]
pub trait ArbitrageStrategy: Strategy {
// For arbitrage
Expand Down

0 comments on commit 470d5dd

Please sign in to comment.