overlay-market / v1-core

Core smart contracts of Overlay V1
MIT License
41 stars 13 forks source link

Adds RISK_MANAGER role #181

Closed magnetto90 closed 7 months ago

magnetto90 commented 7 months ago

Solves #178

    /// @dev bound on notional cap to mitigate back-running attack
    /// @dev bound = macroWindowInBlocks * reserveInOv * 2 * delta
    function backRunBound(Oracle.Data memory data) public view returns (uint256) {
        uint256 averageBlockTime = params.get(Risk.Parameters.AverageBlockTime);
        uint256 window = (data.macroWindow * ONE * TO_MS) / averageBlockTime;
        uint256 delta = params.get(Risk.Parameters.Delta);
        return delta.mulDown(data.reserveOverMicroWindow).mulDown(window).mulDown(2 * ONE);
    }

Reference code

As @EperezOk mentions in this comment if the averageBlockTime decrease the window is increasead and also the cap(not visible in this segment of code).

Due the fact the current average block time of Arbitrum is 0.26s (source), we should set the averageBlockTime to this number and set an alarm to change it if necessary, for this purpose we add a new role named RISK_MANAGER that is able to change any Risk Parameter. This could be done automatically with a BOT or maybe using Defender.

Note: In the current version of Overlay Protocol this code is unreachable because we are using Chain Link Feed that sets the hasReserve property to false by default making any effort to solve this issue not necessary at the moment considering that adding a new feed also could lead to more modifications and a new audit.