-
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.
- Loading branch information
1 parent
2bbfdf9
commit d8d4d3d
Showing
7 changed files
with
85 additions
and
2 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 |
---|---|---|
|
@@ -5,4 +5,7 @@ optimized-out | |
|
||
# Rust | ||
kit/target | ||
target | ||
target | ||
|
||
# VSCode | ||
.vscode |
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,2 +1,6 @@ | ||
pub mod behaviors; | ||
pub mod bindings; | ||
pub mod pool; | ||
|
||
use anyhow::Result; | ||
use ethers::types::U256 as eU256; |
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,30 @@ | ||
use bindings::{constant_sum::ConstantSum, constant_sum_solver::ConstantSumSolver}; | ||
use ethers::abi::Tokenize; | ||
|
||
use super::*; | ||
|
||
pub struct ConstantSumPool { | ||
pub strategy_contract: ConstantSum<ArbiterMiddleware>, | ||
pub solver_contract: ConstantSumSolver<ArbiterMiddleware>, | ||
pub parameters: ConstantSumParameters, | ||
} | ||
|
||
pub struct ConstantSumParameters { | ||
pub price: eU256, | ||
pub swap_fee: eU256, | ||
} | ||
|
||
impl PoolType for ConstantSumPool { | ||
type Parameters = ConstantSumParameters; | ||
type StrategyContract = ConstantSum<ArbiterMiddleware>; | ||
type SolverContract = ConstantSumSolver<ArbiterMiddleware>; | ||
|
||
async fn swap_data(&self, pool_id: eU256, swap_x_in: bool, amount_in: eU256) -> Result<Bytes> { | ||
let data = self | ||
.solver_contract | ||
.simulate_swap(pool_id, swap_x_in, amount_in) | ||
.call() | ||
.await?; | ||
Ok(Bytes::from(ethers::abi::encode(&data.into_tokens()))) | ||
} | ||
} |
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 @@ | ||
|
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 @@ | ||
|
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,44 @@ | ||
use arbiter_core::middleware::ArbiterMiddleware; | ||
|
||
use ethers::types::Bytes; | ||
|
||
use self::bindings::dfmm::DFMM; | ||
use super::*; | ||
use crate::bindings::arbiter_token::ArbiterToken; | ||
|
||
pub mod constant_sum; | ||
pub mod geometric_mean; | ||
pub mod log_normal; | ||
|
||
pub trait PoolType { | ||
type Parameters; | ||
type StrategyContract; | ||
type SolverContract; | ||
|
||
#[allow(async_fn_in_trait)] | ||
async fn swap_data(&self, pool_id: eU256, swap_x_in: bool, amount_in: eU256) -> Result<Bytes>; | ||
} | ||
|
||
pub struct Pool<P: PoolType> { | ||
pub id: eU256, | ||
pub dfmm: DFMM<ArbiterMiddleware>, | ||
pub instance: P, | ||
pub token_x: ArbiterToken<ArbiterMiddleware>, | ||
pub token_y: ArbiterToken<ArbiterMiddleware>, | ||
} | ||
|
||
impl<P: PoolType> Pool<P> { | ||
pub async fn swap( | ||
&self, | ||
amount_in: eU256, | ||
token_in: &ArbiterToken<ArbiterMiddleware>, | ||
) -> Result<()> { | ||
let swap_x_in = token_in.address() == self.token_x.address(); | ||
let data = self | ||
.instance | ||
.swap_data(self.id, swap_x_in, amount_in) | ||
.await?; | ||
self.dfmm.swap(self.id, data).send().await?.await?; | ||
Ok(()) | ||
} | ||
} |