diff --git a/journal/alex-oct-19-notes.md b/journal/alex-oct-19-notes.md index 20a08b57f..234044add 100644 --- a/journal/alex-oct-19-notes.md +++ b/journal/alex-oct-19-notes.md @@ -1,6 +1,6 @@ # General Strategy Interfacing -Arbitrageurs are agents that need to get specific pricing info from the arbitrage target. While the mechanics of the arbitrage might be different from eachother, and require different variables, there is a universal set of actions and information they require. +Arbitrageurs are agents that need to get specific pricing info from the arbitrage target. While the mechanics of the arbitrage might be different from each other, and require different variables, there is a universal set of actions and information they require. Arbitrageur needs: - To get the current price of a pool that is the arbitrage target diff --git a/simulation/src/agents/arbitrageur.rs b/simulation/src/agents/arbitrageur.rs index 90a098ed9..8b5085f4d 100644 --- a/simulation/src/agents/arbitrageur.rs +++ b/simulation/src/agents/arbitrageur.rs @@ -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 { diff --git a/simulation/src/agents/liquidity_provider.rs b/simulation/src/agents/liquidity_provider.rs index 0d624eadf..27fa34563 100644 --- a/simulation/src/agents/liquidity_provider.rs +++ b/simulation/src/agents/liquidity_provider.rs @@ -1,6 +1,5 @@ -use crate::strategy::LiquidityStrategy; - use super::{strategy::Strategy, token_admin::TokenAdmin, *}; +use crate::strategy::LiquidityStrategy; #[derive(Clone)] pub struct LiquidityProvider { @@ -42,7 +41,8 @@ impl LiquidityProvider { #[async_trait::async_trait] impl Agent for LiquidityProvider { 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) diff --git a/simulation/src/agents/mod.rs b/simulation/src/agents/mod.rs index f22c6438d..2577275a0 100644 --- a/simulation/src/agents/mod.rs +++ b/simulation/src/agents/mod.rs @@ -9,7 +9,8 @@ pub mod weight_changer; use std::marker::{Send, Sync}; -/// Universal agent methods for interacting with the simulation environment or loop. +/// 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. diff --git a/simulation/src/agents/weight_changer.rs b/simulation/src/agents/weight_changer.rs index 4d8242c61..7349efd8c 100644 --- a/simulation/src/agents/weight_changer.rs +++ b/simulation/src/agents/weight_changer.rs @@ -68,7 +68,7 @@ impl WeightChanger { } fn calculate_rv(&mut self) -> Result<()> { - // if self.asset_prices.len() > 15 then only calcualte for the last 15 elements + // if self.asset_prices.len() > 15 then only calculate for the last 15 elements if self.asset_prices.len() > 15 { let asset_rv = compute_realized_volatility( self.asset_prices diff --git a/simulation/src/lib.rs b/simulation/src/lib.rs index 58433e2d5..ddfd300dc 100644 --- a/simulation/src/lib.rs +++ b/simulation/src/lib.rs @@ -1,4 +1,5 @@ -// 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::{ops::Div, sync::Arc}; diff --git a/simulation/src/simulations/dynamic_weights.rs b/simulation/src/simulations/dynamic_weights.rs index 4c1c7ed3d..a7f232349 100644 --- a/simulation/src/simulations/dynamic_weights.rs +++ b/simulation/src/simulations/dynamic_weights.rs @@ -1,14 +1,14 @@ +use arbiter_core::environment::builder::BlockSettings; + use super::*; -use crate::agents::Agent; 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, }, bindings::i_strategy::IStrategy, settings::SimulationConfig, }; -use arbiter_core::environment::builder::BlockSettings; pub async fn run(config_path: &str) -> Result<()> { let config = SimulationConfig::new(config_path)?; diff --git a/simulation/src/simulations/stable_portfolio.rs b/simulation/src/simulations/stable_portfolio.rs index 4c4a1b3f5..54b5299f5 100644 --- a/simulation/src/simulations/stable_portfolio.rs +++ b/simulation/src/simulations/stable_portfolio.rs @@ -26,7 +26,7 @@ pub async fn run(config_path: &str) -> Result<()> { lp.add_liquidity(&config).await?; - // have the loop iterate blcoks and block timestamps + // have the loop iterate blocks and block timestamps // draw random # from poisson distribution which determines how long we wait for // price to change loop that causes price change -> arbitrageur -> check if // weightchanger needs to run diff --git a/simulation/src/strategy/g3m.rs b/simulation/src/strategy/g3m.rs index 80c1e39f0..dc131c5bd 100644 --- a/simulation/src/strategy/g3m.rs +++ b/simulation/src/strategy/g3m.rs @@ -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. @@ -39,7 +38,8 @@ impl Strategy for IStrategy { } } -/// 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 { async fn instantiate( @@ -55,7 +55,8 @@ impl LiquidityStrategy for IStrategy { } } -/// 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 { async fn get_x_input( diff --git a/simulation/src/strategy/mod.rs b/simulation/src/strategy/mod.rs index 06b5287a9..c4344f0c8 100644 --- a/simulation/src/strategy/mod.rs +++ b/simulation/src/strategy/mod.rs @@ -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. @@ -20,14 +22,17 @@ pub trait Strategy: Sized { /// Returns the fee charged to the arbitrageur on rebalances. async fn get_swap_fee(&self) -> Result; - /// 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; } -/// 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, @@ -35,8 +40,10 @@ pub trait LiquidityStrategy: Strategy { ) -> Result>; } -/// 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