wp-evm-algebra-interfaces 0.1.10

sol!-generated bindings for Algebra V1.9 protocol interfaces
Documentation
//! Algebra Eternal Farming bindings (FarmingCenter + EternalFarming + IncentiveKey).
//! Generic across Algebra eternal-farming forks; Blackhole config lives in the facade.

use alloy_sol_types::sol;

sol! {
    #[derive(Debug)]
    struct IncentiveKey {
        address rewardToken;
        address bonusRewardToken;
        address pool;
        uint256 nonce;
    }

    #[allow(missing_docs)]
    interface IFarmingCenter {
        function eternalFarming() external view returns (address);
        function algebraPoolDeployer() external view returns (address);
        function collectRewards(IncentiveKey key, uint256 tokenId) external returns (uint256 reward, uint256 bonusReward);
        function claimReward(address rewardToken, address to, uint256 amountRequested) external returns (uint256 rewardBalanceBefore);
    }

    #[allow(missing_docs)]
    interface IAlgebraEternalFarming {
        function incentiveKeys(address poolAddress) external view returns (address rewardToken, address bonusRewardToken, address pool, uint256 nonce);
        function getRewardInfo(IncentiveKey key, uint256 tokenId) external returns (uint256 reward, uint256 bonusReward);
    }

    #[allow(missing_docs)]
    interface IMulticall {
        function multicall(bytes[] calldata data) external returns (bytes[] memory results);
    }
}

// IncentiveKey doubles as a HashMap key — manual Eq/Hash (sol! derives neither).
impl PartialEq for IncentiveKey {
    fn eq(&self, other: &Self) -> bool {
        self.rewardToken == other.rewardToken
            && self.bonusRewardToken == other.bonusRewardToken
            && self.pool == other.pool
            && self.nonce == other.nonce
    }
}
impl Eq for IncentiveKey {}
impl std::hash::Hash for IncentiveKey {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.rewardToken.hash(state);
        self.bonusRewardToken.hash(state);
        self.pool.hash(state);
        self.nonce.hash(state);
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use alloy_primitives::{Address, U256};
    use alloy_sol_types::SolCall;

    #[test]
    fn selectors_match_blackhole_contracts() {
        assert_eq!(IFarmingCenter::collectRewardsCall::SELECTOR, [0x6a, 0xf0, 0x0a, 0xee]);
        assert_eq!(IFarmingCenter::claimRewardCall::SELECTOR, [0x2f, 0x2d, 0x78, 0x3d]);
        assert_eq!(IFarmingCenter::eternalFarmingCall::SELECTOR, [0xde, 0x23, 0x56, 0xd1]);
        assert_eq!(IFarmingCenter::algebraPoolDeployerCall::SELECTOR, [0x14, 0x25, 0x82, 0x56]);
        assert_eq!(IAlgebraEternalFarming::incentiveKeysCall::SELECTOR, [0x57, 0x65, 0x58, 0x46]);
        assert_eq!(IAlgebraEternalFarming::getRewardInfoCall::SELECTOR, [0x96, 0xda, 0x9b, 0xd5]);
        assert_eq!(IMulticall::multicallCall::SELECTOR, [0xac, 0x96, 0x50, 0xd8]);
    }

    #[test]
    fn incentive_key_hash_eq() {
        use std::collections::HashSet;
        let a = Address::repeat_byte(1);
        let k1 =
            IncentiveKey { rewardToken: a, bonusRewardToken: a, pool: a, nonce: U256::from(1) };
        let k2 =
            IncentiveKey { rewardToken: a, bonusRewardToken: a, pool: a, nonce: U256::from(1) };
        let k3 = IncentiveKey { nonce: U256::from(2), ..k1.clone() };
        assert_eq!(k1, k2);
        assert_ne!(k1, k3);
        let mut s = HashSet::new();
        s.insert(k1.clone());
        s.insert(k2);
        s.insert(k3);
        assert_eq!(s.len(), 2);
    }
}