use alloy_primitives::{aliases::U160, aliases::U48, Address, Bytes};
use alloy_sol_types::SolCall;
use wp_evm_v4_interfaces::periphery::position_manager::IAllowanceTransfer;
pub fn permit2_approve_calldata(
token: Address,
spender: Address,
amount: U160,
expiration: U48,
) -> Bytes {
IAllowanceTransfer::approveCall { token, spender, amount, expiration }.abi_encode().into()
}
#[cfg(test)]
mod tests {
use super::*;
use alloy_primitives::{address, hex};
#[test]
fn permit2_approve_calldata_matches_golden_hex() {
let token = address!("A0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48");
let spender = address!("bd216513d74c8cf14cf4747e6aaa6420ff64ee9e");
let calldata = permit2_approve_calldata(token, spender, U160::MAX, U48::from(u32::MAX));
assert_eq!(
calldata.as_ref(),
&hex!(
"87517c45"
"000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
"000000000000000000000000bd216513d74c8cf14cf4747e6aaa6420ff64ee9e"
"000000000000000000000000ffffffffffffffffffffffffffffffffffffffff"
"00000000000000000000000000000000000000000000000000000000ffffffff"
)[..]
);
}
}