chore: Refactor models:

- Delete min_checked_amount and use check_amount instead
- Use Bytes and not Address in interfaces
- Move router_address from Solution to Order
This commit is contained in:
Diana Carvalho
2025-01-14 10:37:06 +00:00
parent 5d79da44f3
commit 647f697ea2
6 changed files with 69 additions and 86 deletions

View File

@@ -1,44 +1,24 @@
use crate::encoding::models::{Order, Solution};
use crate::encoding::models::{Order, Solution, PROPELLER_ROUTER_ADDRESS};
use crate::encoding::permit2::{Permit2, PermitRequest};
use crate::encoding::strategy_encoder::{
SequentialExactInStrategyEncoder, SingleSwapStrategyEncoder, SlipSwapStrategyEncoder,
StrategyEncoder,
};
use crate::encoding::utils::{encode_input, ple_encode};
use alloy_primitives::Address;
use alloy_sol_types::SolValue;
use anyhow::Error;
use std::env;
use std::str::FromStr;
struct RouterEncoder {
router_address: Address,
}
struct RouterEncoder {}
impl RouterEncoder {
pub fn new() -> Self {
let router_address = Address::from_str(
&env::var("ROUTER_ADDRESS").expect("Missing ROUTER_ADDRESS in environment"),
)
.expect("Invalid ROUTER_ADDRESS");
Self { router_address }
}
pub fn encode_router_calldata(&self, solution: Solution) -> Result<Vec<u8>, Error> {
let permit_calldata = self.handle_approvals(&solution)?; // TODO: where should we append this?
let mut calldata_list: Vec<Vec<u8>> = Vec::new();
let encode_for_batch_execute = solution.orders.len() > 1;
for order in solution.orders {
let strategy = self.get_strategy(&order);
let contract_interaction = strategy.encode_strategy(
order,
if solution.router_address.is_some() {
solution.router_address.unwrap()
} else {
self.router_address
},
encode_for_batch_execute,
)?;
let contract_interaction = strategy.encode_strategy(order, encode_for_batch_execute)?;
calldata_list.push(contract_interaction);
}
if encode_for_batch_execute {
@@ -56,7 +36,10 @@ impl RouterEncoder {
token: order.given_token.clone(),
spender: order.sender.clone(),
amount: order.given_amount.clone(),
router_address: solution.router_address.unwrap_or(self.router_address),
router_address: order
.router_address
.clone()
.unwrap_or(PROPELLER_ROUTER_ADDRESS.clone()),
});
}
Ok(Permit2::new().encode_permit(permits))