        isAave[keyId] = _isAave;
        uint256 keyId = _getNextReserveKey();

        reservedKeys[_userAddress] = keyId;
        farmingKeys[keyId] = _wiseLendingNFT;
        uint256 borrowShares = isAave[_nftId]
            ? _getPositionBorrowSharesAave(
                _nftId
            )
            : _getPositionBorrowShares(
                _nftId
        );
        if (isAave[_nftId] == true) {
            poolAddress = AAVE_WETH_ADDRESS;
        }
       uint256 borrowShares = isAave[_nftId]
            ? _getPositionBorrowSharesAave(
                _nftId
            )
            : _getPositionBorrowShares(
                _nftId
        );
       address paybackToken = isAave[_nftId] == true
            ? AAVE_WETH_ADDRESS
            : WETH_ADDRESS;

        paybackAmount = WISE_LENDING.paybackAmount(
            paybackToken,
            _shareAmountToPay
        );

       uint256 cutoffShares = isAave[_nftId] == true
            ? _getPositionBorrowSharesAave(_nftId)
                * FIVTY_PERCENT
                / PRECISION_FACTOR_E18
            : _getPositionBorrowShares(_nftId)
                * FIVTY_PERCENT
                / PRECISION_FACTOR_E18;
        if (_checkDebtRatio(_nftId) == true) {
            revert DebtRatioTooLow();
        }
    function testAaveGetLiveDebtRatio() public cheatSetup(true){
        _prepareAave();
        uint256 keyID = powerFarmManagerInstance.enterFarm(
            true,
            1 ether,
            15 ether,
            entrySpread
        );

        uint nftId = powerFarmManagerInstance.farmingKeys(keyID);
        // gets borrow shares of weth instead of aeth
        uint ratio = powerFarmManagerInstance.getLiveDebtRatio(nftId);
        assertEq(ratio, 0);
    }

    function testAaveManuallyPayback() public cheatSetup(true){
        _prepareAave();
        uint256 keyID = powerFarmManagerInstance.enterFarm(
            true,
            1 ether,
            15 ether,
            entrySpread
        );

        uint nftId = powerFarmManagerInstance.farmingKeys(keyID);
        uint borrowShares = wiseLendingInstance.getPositionBorrowShares(nftId, AWETH);
        // tries to payback weth instead of aweth and reverts with an arithmetic underflow
        // since the position has 0 weth borrow shares
        vm.expectRevert();
        powerFarmManagerInstance.manuallyPaybackShares(keyID, borrowShares);
    }
    
    error DebtRatioTooLow();
    function testCannotLiquidate() public cheatSetup(true){
        _prepareAave();
        uint256 keyID = powerFarmManagerInstance.enterFarm(
            true,
            1 ether,
            15 ether,
            entrySpread
        );

        // increase collateral factors to make position eligible for liquidation
        wiseLendingInstance.setPoolParameters(AWETH, 99e16, type(uint256).max); // increasw Wiselending coll factor
        vm.store(address(powerFarmManagerInstance), bytes32(uint(2)), bytes32(uint(99e16))); //increasw PowerFarm coll factor
        assertEq(powerFarmManagerInstance.collateralFactor(), 99e16);

        uint nftId = powerFarmManagerInstance.farmingKeys(keyID);
        uint borrowShares = wiseLendingInstance.getPositionBorrowShares(nftId, AWETH);
        // will revert if it can't be liquidated
        wiseSecurityInstance.checksLiquidation(nftId, AWETH, borrowShares);

        uint nftIdLiquidator = positionNftsInstance.mintPosition();

        vm.expectRevert(DebtRatioTooLow.selector);
        powerFarmManagerInstance.liquidatePartiallyFromToken(nftId, nftIdLiquidator, borrowShares );
    }
-       uint256 borrowShares = isAave[_nftId]
+       uint256 borrowShares = isAave[keyId]
            ? _getPositionBorrowSharesAave(
                _nftId
            )
            : _getPositionBorrowShares(
                _nftId
        );
-       if (isAave[_nftId] == true) {
+       if (isAave[keyId] == true) {
            poolAddress = AAVE_WETH_ADDRESS;
        }
-        uint256 borrowShares = isAave[_nftId]
+        uint256 borrowShares = isAave[keyId]
            ? _getPositionBorrowSharesAave(
                _nftId
            )
            : _getPositionBorrowShares(
                _nftId
        );
-        address paybackToken = isAave[_nftId] == true
+        address paybackToken = isAave[keyId] == true
            ? AAVE_WETH_ADDRESS
            : WETH_ADDRESS;

        paybackAmount = WISE_LENDING.paybackAmount(
            paybackToken,
            _shareAmountToPay
        );

-       uint256 cutoffShares = isAave[_nftId] == true
+       uint256 cutoffShares = isAave[keyId] == true
            ? _getPositionBorrowSharesAave(_nftId)
                * FIVTY_PERCENT
                / PRECISION_FACTOR_E18
            : _getPositionBorrowShares(_nftId)
                * FIVTY_PERCENT
                / PRECISION_FACTOR_E18;
