-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: LogNormalSolver * wip: save constant sum * feat: constant sum * Add `PairSolver` abstract contract to avoid custom allo/deallo delta computations * chore: natspec * chore: bindings * feat: constant sum pool type * feat: geometric mean pool type * feat: log normal pool type * feat: n token geometric mean * feat: n token geometric mean * fmt * return abi encoded allo/deallo data * feat: n-token bindings + pool types + tests * feat: n-token pooltype * feat: deploy n token geometric mean * feat: generic allocate and deallocate and update * feat: token admin * feat: mint request * feat: add wip ISolver * chore: amount is now called delta in allocate and deallocate * feat: G3MSolver is now using the ISolver interface * test: update G3M deallocate tests * test: update G3M allocate tests * test: update G3M swap tests * test: fix prepare allocation and deallocation params order for G3M tests * feat: add InvalidTokenIndex error to ISolver * feat: implement ISolver in ConstantSumSolver * chore: remove unused Reserves struct in ConstantSumSolver * test: update tests using ConstantSumSolver * feat: implement ISolver in LogNormalSolver * test: update LogNormal tests * feat: implement ISolver in NTokenG3MSolver * test: update NTokenG3M tests * feat: update ISolver getPrice function * feat: update getPrice in ConstantSumSolver * feat: update G3M getPrice function * feat: update ISolver interface * feat: update GeometricMeanSolver * chore: add NatSpec to ISolver * chore: add prepareInit and getPoolParams mentions in ISolver * feat: update LogNormalSolver with new ISolver * feat: update ConstantSumSolver with new ISolver changes * feat: update G3MSolver with new ISolver changes * feat: use IStrategy interface for startegy getter in ISolver * test: update LogNormal getPrice tests * feat: import errors from ISolver * feat: add InvalidDeltasLength error to ISolver * feat: import errors from ISolver in LogNormalSolver * feat: rework NTokenG3MSolver to fit with new ISolver * test: update ConstantSum setup * test: use prepareInit for ConstantSumSolver * test: use prepareInit for ConstantSumSolver * test: import NotEnoughLiquidity from ConstantSumSolver file * test: cast G3M strategy as IStrategy in G3M test setup * test: update G3M allocate tests with new solver * test: update G3M deallocate tests with new solver * test: use IStrategy type to init G3MSolver * test: use prepareInit for LogNormal tests * test: use getEstimatedPrice in LogNormal allocate tests * test: use IStrategy type to init LogNormal solver * test: update NTokenG3M tests to new solver updates * feat: use ISolver errors in G3MSolver * chore: add NatSpec to ConstantSumSolver * chore: update NatSpec, remove unused imports in ConstantSumSolver * chore: move G3M and NTokenG3M READMEs around * chore: add NatSpec, remove unused imports in G3MSolver * feat: add token index check in G3M prepareSwap * feat: add NatSpec, remove unused functions, add token index checks * chore: add NatSpec to NTokenG3MSolver * test: update tests with solver changes * test: fix G3M transfer tokens test * feat: change rounding direction in NTokenG3MSolver --------- Co-authored-by: Waylon Jepsen <waylonjepsen1@gmail.com> Co-authored-by: kinrezc <matt.czernik@gmail.com> Co-authored-by: Waylon Jepsen <57912727+0xJepsen@users.noreply.github.com>
- Loading branch information
1 parent
3582603
commit 0edfaa9
Showing
95 changed files
with
26,637 additions
and
5,079 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#[allow(unused_imports)] | ||
use arbiter_engine::machine::ControlFlow; | ||
|
||
use super::*; | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct Allocate {} | ||
#[allow(unused_variables)] | ||
#[async_trait::async_trait] | ||
impl Behavior<()> for Allocate { | ||
async fn startup( | ||
&mut self, | ||
client: Arc<ArbiterMiddleware>, | ||
messager: Messager, | ||
) -> Result<Option<EventStream<()>>> { | ||
Ok(None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
use std::sync::Arc; | ||
|
||
use arbiter_bindings::bindings::arbiter_token::ArbiterToken; | ||
use arbiter_engine::{ | ||
machine::{Behavior, CreateStateMachine, Engine, EventStream, StateMachine}, | ||
messager::Messager, | ||
machine::{Behavior, ControlFlow, CreateStateMachine, Engine, EventStream, StateMachine}, | ||
messager::{Message, Messager, To}, | ||
}; | ||
use arbiter_macros::Behaviors; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use self::deployer::Deployer; | ||
use self::{allocate::Allocate, deployer::Deployer, token_admin::TokenAdmin}; | ||
use super::*; | ||
|
||
pub mod allocate; | ||
pub mod deployer; | ||
pub mod token_admin; | ||
|
||
#[derive(Behaviors, Debug, Deserialize, Serialize)] | ||
pub enum Behaviors { | ||
Allocate(Allocate), | ||
Deployer(Deployer), | ||
TokenAdmin(TokenAdmin), | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct TokenData { | ||
pub name: String, | ||
pub symbol: String, | ||
pub decimals: u8, | ||
pub address: Option<eAddress>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
use std::collections::HashMap; | ||
|
||
use super::*; | ||
|
||
#[derive(Deserialize, Serialize, Clone, Debug)] | ||
pub struct TokenAdmin { | ||
/// The identifier of the token admin. | ||
pub token_data: HashMap<String, TokenData>, | ||
#[serde(skip)] | ||
pub tokens: Option<HashMap<String, ArbiterToken<ArbiterMiddleware>>>, | ||
#[serde(skip)] | ||
pub client: Option<Arc<ArbiterMiddleware>>, | ||
#[serde(skip)] | ||
pub messager: Option<Messager>, | ||
#[serde(default)] | ||
pub count: u64, | ||
#[serde(default = "default_max_count")] | ||
pub max_count: Option<u64>, | ||
} | ||
|
||
pub fn default_max_count() -> Option<u64> { | ||
Some(3) | ||
} | ||
|
||
/// Used as an action to ask what tokens are available. | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub enum TokenAdminQuery { | ||
/// Get the address of the token. | ||
AddressOf(String), | ||
|
||
/// Mint tokens. | ||
MintRequest(MintRequest), | ||
} | ||
|
||
/// Used as an action to mint tokens. | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct MintRequest { | ||
/// The token to mint. | ||
pub token: String, | ||
|
||
/// The address to mint to. | ||
pub mint_to: eAddress, | ||
|
||
/// The amount to mint. | ||
pub mint_amount: u64, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Behavior<Message> for TokenAdmin { | ||
#[tracing::instrument(skip(self), fields(id = messager.id.as_deref()))] | ||
async fn startup( | ||
&mut self, | ||
client: Arc<ArbiterMiddleware>, | ||
messager: Messager, | ||
) -> Result<Option<EventStream<Message>>> { | ||
self.messager = Some(messager.clone()); | ||
self.client = Some(client.clone()); | ||
for token_data in self.token_data.values_mut() { | ||
let token = ArbiterToken::deploy( | ||
client.clone(), | ||
( | ||
token_data.name.clone(), | ||
token_data.symbol.clone(), | ||
token_data.decimals, | ||
), | ||
) | ||
.unwrap() | ||
.send() | ||
.await | ||
.unwrap(); | ||
|
||
token_data.address = Some(token.address()); | ||
self.tokens | ||
.get_or_insert_with(HashMap::new) | ||
.insert(token_data.name.clone(), token.clone()); | ||
} | ||
Ok(None) | ||
} | ||
|
||
#[tracing::instrument(skip(self), fields(id = | ||
self.messager.as_ref().unwrap().id.as_deref()))] | ||
async fn process(&mut self, event: Message) -> Result<ControlFlow> { | ||
if self.tokens.is_none() { | ||
error!( | ||
"There were no tokens to deploy! You must add tokens to | ||
the token admin before running the simulation." | ||
); | ||
} | ||
|
||
let query: TokenAdminQuery = serde_json::from_str(&event.data).unwrap(); | ||
trace!("Got query: {:?}", query); | ||
let messager = self.messager.as_ref().unwrap(); | ||
match query { | ||
TokenAdminQuery::AddressOf(token_name) => { | ||
trace!( | ||
"Getting address of token with name: {:?}", | ||
token_name.clone() | ||
); | ||
let token_data = self.token_data.get(&token_name).unwrap(); | ||
messager | ||
.send(To::Agent(event.from.clone()), token_data.address) | ||
.await?; | ||
} | ||
TokenAdminQuery::MintRequest(mint_request) => { | ||
trace!("Minting tokens: {:?}", mint_request); | ||
let token = self | ||
.tokens | ||
.as_ref() | ||
.unwrap() | ||
.get(&mint_request.token) | ||
.unwrap(); | ||
token | ||
.mint(mint_request.mint_to, eU256::from(mint_request.mint_amount)) | ||
.send() | ||
.await | ||
.unwrap() | ||
.await | ||
.unwrap(); | ||
self.count += 1; | ||
if self.count == self.max_count.unwrap_or(u64::MAX) { | ||
warn!("Reached max count. Halting behavior."); | ||
return Ok(ControlFlow::Halt); | ||
} | ||
} | ||
} | ||
Ok(ControlFlow::Continue) | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.