Files
tycho-execution/src/encoding/evm/approvals/permit2.rs
Diana Carvalho 979cdf7437 chore: Do not use expect
--- don't change below this line ---
ENG-4063 Took 57 minutes


Took 17 seconds

Took 45 seconds
2025-01-21 18:48:49 +00:00

47 lines
1.2 KiB
Rust

use std::str::FromStr;
use alloy_primitives::U256;
use tycho_core::Bytes;
use crate::encoding::{
errors::EncodingError,
user_approvals_manager::{Approval, UserApprovalsManager},
};
#[allow(dead_code)]
pub struct Permit2 {
pub address: Bytes,
}
#[allow(dead_code)]
impl Permit2 {
pub fn new() -> Result<Self, EncodingError> {
Ok(Self {
address: Bytes::from_str("0x000000000022D473030F116dDEE9F6B43aC78BA3")
.map_err(|_| EncodingError::FatalError("Permit2 address not valid".to_string()))?,
})
}
fn get_allowance_data(
&self,
_user: Bytes,
_router_address: Bytes,
_token: Bytes,
) -> (U256, u64, U256) {
// get allowance data (if it exists) and the nonce
// returns permitAmount, expiration, nonce
todo!()
}
}
impl UserApprovalsManager for Permit2 {
fn encode_approvals(&self, _approvals: Vec<Approval>) -> Vec<Vec<u8>> {
// calls get_allowance_data to get nonce
// checks if we are not permitted already
// puts data into a list of PermitSingles
// adds the nonce and the expiration (uniswap recommends
// 30 days for expiration) signs data
// returns encoded data
todo!()
}
}