wp-evm-algebra-interfaces 0.1.12

sol!-generated bindings for Algebra V1.9 protocol interfaces
Documentation
//! Algebra V1.9 NonfungiblePositionManager read/collect ABI.

use alloy_sol_types::sol;

sol! {
    interface IAlgebraNonfungiblePositionManager {
        function positions(uint256 tokenId) external view returns (
            uint96 nonce,
            address operator,
            address token0,
            address token1,
            int24 tickLower,
            int24 tickUpper,
            uint128 liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        );
        function ownerOf(uint256 tokenId) external view returns (address);
        function balanceOf(address owner) external view returns (uint256);
        function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);

        struct CollectParams {
            uint256 tokenId;
            address recipient;
            uint128 amount0Max;
            uint128 amount1Max;
        }
        function collect(CollectParams params) external payable returns (uint256 amount0, uint256 amount1);
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use alloy_sol_types::SolCall;

    #[test]
    fn selectors_match_known_values() {
        assert_eq!(
            IAlgebraNonfungiblePositionManager::positionsCall::SELECTOR,
            [0x99, 0xfb, 0xab, 0x88]
        );
        assert_eq!(
            IAlgebraNonfungiblePositionManager::ownerOfCall::SELECTOR,
            [0x63, 0x52, 0x21, 0x1e]
        );
        assert_eq!(
            IAlgebraNonfungiblePositionManager::balanceOfCall::SELECTOR,
            [0x70, 0xa0, 0x82, 0x31]
        );
        assert_eq!(
            IAlgebraNonfungiblePositionManager::tokenOfOwnerByIndexCall::SELECTOR,
            [0x2f, 0x74, 0x5c, 0x59]
        );
        assert_eq!(
            IAlgebraNonfungiblePositionManager::collectCall::SELECTOR,
            [0xfc, 0x6f, 0x78, 0x65]
        );
    }

    /// Decode raw QuickSwap NFPM `positions(1962)` return bytes captured
    /// from Polygon block 86_077_558. Locks real 11-field ordering
    /// (notably: no V3 `fee` slot between token1 and tickLower).
    #[test]
    fn real_quickswap_positions_return_decodes_11_tuple() {
        use alloy_primitives::{address, aliases::I24, Address, U256};

        let raw = alloy_primitives::hex!(
            "0000000000000000000000000000000000000000000000000000000000000000"
            "0000000000000000000000000000000000000000000000000000000000000000"
            "0000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa84174"
            "000000000000000000000000c2132d05d31c914a87c6611c10748aeb04b58e8f"
            "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff4c"
            "00000000000000000000000000000000000000000000000000000000000000b4"
            "0000000000000000000000000000000000000000000000000000000001ed7486"
            "0000000000000000000000000000000000000be92b01de98ddaf95a6dfbb609e"
            "0000000000000000000000000000000000000bb4faa41b4f4e0e0e6b00793074"
            "0000000000000000000000000000000000000000000000000000000000000000"
            "0000000000000000000000000000000000000000000000000000000000000000"
        );
        let decoded =
            IAlgebraNonfungiblePositionManager::positionsCall::abi_decode_returns(&raw).unwrap();

        assert_eq!(decoded.nonce, alloy_primitives::aliases::U96::ZERO);
        assert_eq!(decoded.operator, Address::ZERO);
        assert_eq!(decoded.token0, address!("2791Bca1f2de4661ED88A30C99A7a9449Aa84174"));
        assert_eq!(decoded.token1, address!("c2132D05D31c914a87C6611C10748AEb04B58e8F"));
        assert_eq!(decoded.tickLower, I24::try_from(-180i32).unwrap());
        assert_eq!(decoded.tickUpper, I24::try_from(180i32).unwrap());
        assert_eq!(decoded.liquidity, 32_339_078u128);
        assert_eq!(
            decoded.feeGrowthInside0LastX128,
            U256::from_str_radix("241579977621525341222512191299742", 10).unwrap()
        );
        assert_eq!(
            decoded.feeGrowthInside1LastX128,
            U256::from_str_radix("237445144537992520764764362190964", 10).unwrap()
        );
        assert_eq!(decoded.tokensOwed0, 0);
        assert_eq!(decoded.tokensOwed1, 0);
    }

    /// Round-trip an Algebra NFPM `positions` return value through the
    /// codec to lock the 11-field tuple shape (notably: no V3 `fee`).
    #[test]
    fn positions_return_round_trips_11_tuple() {
        use alloy_primitives::{
            address,
            aliases::{I24, U96},
            Address, U256,
        };
        use IAlgebraNonfungiblePositionManager::positionsReturn;

        let original = positionsReturn {
            nonce: U96::from(7u64),
            operator: Address::ZERO,
            token0: address!("2791Bca1f2de4661ED88A30C99A7a9449Aa84174"),
            token1: address!("7ceB23fD6bC0adD59E62ac25578270cFf1b9f619"),
            tickLower: I24::try_from(-69_120i32).unwrap(),
            tickUpper: I24::try_from(276_320i32).unwrap(),
            liquidity: 1_234_567_890_123u128,
            feeGrowthInside0LastX128: U256::from(42u64),
            feeGrowthInside1LastX128: U256::from(99u64),
            tokensOwed0: 123u128,
            tokensOwed1: 456u128,
        };

        let encoded =
            IAlgebraNonfungiblePositionManager::positionsCall::abi_encode_returns(&original);
        let decoded =
            IAlgebraNonfungiblePositionManager::positionsCall::abi_decode_returns(&encoded)
                .unwrap();

        assert_eq!(decoded.nonce, original.nonce);
        assert_eq!(decoded.operator, original.operator);
        assert_eq!(decoded.token0, original.token0);
        assert_eq!(decoded.token1, original.token1);
        assert_eq!(decoded.tickLower, original.tickLower);
        assert_eq!(decoded.tickUpper, original.tickUpper);
        assert_eq!(decoded.liquidity, original.liquidity);
        assert_eq!(decoded.feeGrowthInside0LastX128, original.feeGrowthInside0LastX128);
        assert_eq!(decoded.feeGrowthInside1LastX128, original.feeGrowthInside1LastX128);
        assert_eq!(decoded.tokensOwed0, original.tokensOwed0);
        assert_eq!(decoded.tokensOwed1, original.tokensOwed1);
    }
}