2024-12-20
*issue*
================================================================================

After closing synthetix position we don't update global data for liquidations

================================================================================

*issue-contents*

0 CONTENTS

*issue-metadata*

1 METADATA

Number 178
Severity High
Author valuevalk
Contest Autonomint
Platform Sherlock
*issue-summary*

2 SUMMARY

After admin closes synthetix position we don’t update any global variables, which means that dCDS depositors and the whole protocol cannot benefit from the liquidation and the potential gains from its shorted position.

*issue-root-cause*

3 ROOT CAUSE

closeThePositionInSynthetix() function in borrowLiquidation.sol only closes the position and does not update any global variables like in the liquidation type 1

    function closeThePositionInSynthetix() external onlyBorrowingContract {
        (, uint128 ethPrice) = borrowing.getUSDValue(borrowing.assetAddress(IBorrowing.AssetName.ETH));
        // Submit an order to close all positions in synthetix
        synthetixPerpsV2.submitOffchainDelayedOrder(-synthetixPerpsV2.positions(address(this)).size, ethPrice * 1e16);
    }

For reference in liquidation type 1 we update many values to make the protocol aware of the fact that we have a position liquidated and its collateral is ready to be taken from dCDS depositors opted-in for that. ( other values related to yield for ABOND also shall be updated, just like in liquidation type 1 )

      // Update the CDS data
        cds.updateLiquidationInfo(omniChainData.noOfLiquidations, liquidationInfo);
        cds.updateTotalCdsDepositedAmount(cdsAmountToGetFromThisChain);
        cds.updateTotalCdsDepositedAmountWithOptionFees(cdsAmountToGetFromThisChain);
        cds.updateTotalAvailableLiquidationAmount(cdsAmountToGetFromThisChain);
        omniChainData.collateralProfitsOfLiquidators += depositDetail.depositedAmountInETH;

        // Update the global data
        omniChainData.totalCdsDepositedAmount -= liquidationAmountNeeded - cdsProfits; //! need to revisit this
        omniChainData.totalCdsDepositedAmountWithOptionFees -= liquidationAmountNeeded - cdsProfits;
        omniChainData.totalAvailableLiquidationAmount -= liquidationAmountNeeded - cdsProfits;
        omniChainData.totalInterestFromLiquidation += uint256(borrowerDebt - depositDetail.borrowedAmount);
        omniChainData.totalVolumeOfBorrowersAmountinWei -= depositDetail.depositedAmountInETH;
        omniChainData.totalVolumeOfBorrowersAmountinUSD -= depositDetail.depositedAmountUsdValue;
        omniChainData.totalVolumeOfBorrowersAmountLiquidatedInWei += depositDetail.depositedAmountInETH;

        // Update totalInterestFromLiquidation
        uint256 totalInterestFromLiquidation = uint256(borrowerDebt - depositDetail.borrowedAmount);

        // Update individual collateral data
        --collateralData.noOfIndices;
        collateralData.totalDepositedAmount -= depositDetail.depositedAmount;
        collateralData.totalDepositedAmountInETH -= depositDetail.depositedAmountInETH;
        collateralData.totalLiquidatedAmount += depositDetail.depositedAmount;
        // Calculate the yields
        uint256 yields = depositDetail.depositedAmount - ((depositDetail.depositedAmountInETH * 1 ether) / exchangeRate);

        // Update treasury data
        treasury.updateTotalVolumeOfBorrowersAmountinWei(depositDetail.depositedAmountInETH);
        treasury.updateTotalVolumeOfBorrowersAmountinUSD(depositDetail.depositedAmountUsdValue);
        treasury.updateDepositedCollateralAmountInWei(depositDetail.assetName, depositDetail.depositedAmountInETH);
        treasury.updateDepositedCollateralAmountInUsd(depositDetail.assetName, depositDetail.depositedAmountUsdValue);
        treasury.updateTotalInterestFromLiquidation(totalInterestFromLiquidation);
        treasury.updateYieldsFromLiquidatedLrts(yields);
        treasury.updateDepositDetails(user, index, depositDetail);

        globalVariables.updateCollateralData(depositDetail.assetName, collateralData);
        globalVariables.setOmniChainData(omniChainData);
*issue-internal-pre-conditions*

4 INTERNAL PRE-CONDITIONS

No response

*issue-external-pre-conditions*

5 EXTERNAL PRE-CONDITIONS

No response

*issue-attack-path*

6 ATTACK PATH

*issue-impact*

7 IMPACT

*issue-poc*

8 POC

No response

*issue-mitigation*

9 MITIGATION

After closing the short position update the global variables, so the protocol can work with the collateral thats now available to be withdrawn from dCDS depositors. Other factors such as yield for abond apply as well.

================================================================================

LINKS

*issue-links*