Skip to content

Commit

Permalink
feat: token approval for liq admin
Browse files Browse the repository at this point in the history
  • Loading branch information
ts0yu committed Jul 17, 2024
1 parent 3d25280 commit e87c1d5
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/bindings/poolmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,7 @@ pub mod PoolManager {
struct ModifyLiquidityParams { int24 tickLower; int24 tickUpper; int256 liquidityDelta; bytes32 salt; }
```*/
#[allow(non_camel_case_types, non_snake_case)]
#[derive(Clone)]
#[derive(Clone, Default, Debug)]
pub struct ModifyLiquidityParams {
pub tickLower: <alloy::sol_types::sol_data::Int<24> as alloy::sol_types::SolType>::RustType,
pub tickUpper: <alloy::sol_types::sol_data::Int<24> as alloy::sol_types::SolType>::RustType,
Expand Down
10 changes: 7 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use crate::{
bindings::{
arenatoken::ArenaToken,
liquidexchange::LiquidExchange,
poolmanager::{PoolManager, PoolManager::PoolKey},
poolmanager::{
PoolManager,
PoolManager::{ModifyLiquidityParams, PoolKey},
},
},
deployer::{DeploymentRequest, DeploymentResponse},
pool_admin::PoolParams,
Expand All @@ -25,6 +28,7 @@ use crate::{
pub mod arbitrageur;
pub mod bindings;
pub mod deployer;
pub mod liquidity_admin;
pub mod pool_admin;
pub mod price_changer;
pub mod types;
Expand Down Expand Up @@ -56,8 +60,8 @@ mod tests {
.send(
To::Agent("deployer".to_string()),
DeploymentRequest::Token {
name: String::from("TEST"),
symbol: String::from("TST"),
name: String::from("TEST0"),
symbol: String::from("TST0"),
decimals: 18,
},
)
Expand Down
74 changes: 74 additions & 0 deletions src/liquidity_admin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use alloy::sol_types::sol_data::Int;

use super::*;

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct LiquidityAdmin {
#[serde(skip)]
pub messager: Option<Messager>,

#[serde(skip)]
pub client: Option<Arc<AnvilProvider>>,

pub deployment: Option<Address>,
}

#[derive(Deserialize, Serialize, Clone)]
pub struct AllocationRequest {
#[serde(skip)]
pool: PoolKey,

#[serde(skip)]
modification: ModifyLiquidityParams,
}

#[async_trait::async_trait]
impl Behavior<Message> for LiquidityAdmin {
async fn startup(
&mut self,
client: Arc<AnvilProvider>,
messager: Messager,
) -> Result<Option<EventStream<Message>>> {
self.client = Some(client.clone());
self.messager = Some(messager.clone());

let mut stream = messager.clone().stream().unwrap();

while let Some(event) = stream.next().await {
let query: DeploymentResponse = match serde_json::from_str(&event.data) {
Ok(query) => query,
Err(_) => continue,
};

if let DeploymentResponse::PoolManager(address) = query {
self.deployment = Some(address);
break;
}
}

Ok(Some(messager.clone().stream().unwrap()))
}

async fn process(&mut self, event: Message) -> Result<ControlFlow> {
let query: AllocationRequest = match serde_json::from_str(&event.data) {
Ok(query) => query,
Err(_) => return Ok(ControlFlow::Continue),
};

ArenaToken::new(query.pool.currency0, self.client.clone().unwrap())
.approve(self.deployment.unwrap(), Uint::MAX)
.send()
.await?
.watch()
.await?;

ArenaToken::new(query.pool.currency1, self.client.clone().unwrap())
.approve(self.deployment.unwrap(), Uint::MAX)
.send()
.await?
.watch()
.await?;

return Ok(ControlFlow::Continue);
}
}

0 comments on commit e87c1d5

Please sign in to comment.