wp-evm-v4-core 0.1.14

Pure data + quote + plan for v4-family DEXes — no async dependencies
Documentation
//! Permit2 calldata helpers for Uniswap V4 write flows.
//!
//! V4 PositionManager pulls ERC-20 funds through Permit2. The user must grant:
//! 1. ERC20 allowance from token -> Permit2, and
//! 2. Permit2 allowance from token -> PositionManager.
//!
//! This module covers the second step: encoding
//! `IAllowanceTransfer.approve(token, spender, amount, expiration)`.

use alloy_primitives::{aliases::U160, aliases::U48, Address, Bytes};
use alloy_sol_types::SolCall;
use wp_evm_v4_interfaces::periphery::position_manager::IAllowanceTransfer;

/// Encode Permit2 `approve(token, spender, amount, expiration)` calldata.
///
/// `spender` is normally the V4 PositionManager. `amount` is a uint160
/// because that is Permit2's allowance width; callers commonly pass
/// `U160::MAX`. `expiration` is a uint48 unix timestamp; R17's CLI default
/// is `u32::MAX` (year 2106), represented as `U48::from(u32::MAX)`.
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"
            )[..]
        );
    }
}