Skip to content

Commit

Permalink
codespell, fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJepsen committed Oct 23, 2023
1 parent 42f48a0 commit d3b9c19
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 24 deletions.
2 changes: 1 addition & 1 deletion journal/alex-oct-19-notes.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
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
3 changes: 2 additions & 1 deletion simulation/src/agents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion simulation/src/agents/weight_changer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion simulation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
6 changes: 3 additions & 3 deletions simulation/src/simulations/dynamic_weights.rs
Original file line number Diff line number Diff line change
@@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion simulation/src/simulations/stable_portfolio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 d3b9c19

Please sign in to comment.