-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
3 changed files
with
82 additions
and
4 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
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 |
---|---|---|
@@ -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); | ||
} | ||
} |