feat: ApprovalsManager trait
Make Permit2 and TokenApprovalsManager implement it. This way in the RouternEncoder we can use either one (I'm not exactly sure what this would mean in the contract though) I'm not sure I like this generalisation. The TokenApprovalsManager was made with a different purpose: to approve token allowances for the pools (like balancer and curve) for our router
This commit is contained in:
38
src/encoding/approvals/permit2.rs
Normal file
38
src/encoding/approvals/permit2.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use crate::encoding::approvals::interface::{Approval, ApprovalsManager};
|
||||
use alloy_primitives::U256;
|
||||
use std::str::FromStr;
|
||||
use tycho_core::Bytes;
|
||||
|
||||
pub struct Permit2 {
|
||||
pub address: Bytes,
|
||||
}
|
||||
|
||||
impl Permit2 {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
address: Bytes::from_str("0x000000000022D473030F116dDEE9F6B43aC78BA3")
|
||||
.expect("Permit2 address not valid"),
|
||||
}
|
||||
}
|
||||
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 ApprovalsManager for Permit2 {
|
||||
fn encode_approvals(&self, approvals: Vec<Approval>) -> Vec<u8> {
|
||||
// calls get_allowance_data to get nonce
|
||||
// checks if we are not permitted already
|
||||
// puts data into a permitSingle struct if there is only 1 PermitDetails, if there are several, use PermitBatch
|
||||
// adds the nonce and the expiration (uniswap recommends 30 days for expiration)
|
||||
// signs data
|
||||
// returns encoded data
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user