{
    "Function": "_updateValidator",
    "File": "contracts/DelegatedStaking.sol",
    "Parent Contracts": [
        "node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [
        "_sharesToTokens"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function _updateValidator(Validator storage v) internal {\n        // if validator is disabled, we do not update it since it was updated during disabling transaction\n        if(v.disabledEpoch == 0){\n            if (v.totalShares == 0){\n                // when validator stakes the first time, the exchange rate must be equal to the current global exchange rate\n                v.exchangeRate = globalExchangeRate;\n            }\n            else {\n                // the growth of global exchange rate since the validator was updated the last time\n                uint128 rateDifference;\n                unchecked { rateDifference = globalExchangeRate - v.lastUpdateGlobalRate; }\n                // tokens given to the validator and its delegators since last update\n                uint128 tokensGivenToValidator = _sharesToTokens(v.globalShares, rateDifference);\n                // commission paid out of the tokens\n                uint128 commissionPaid = uint128(uint256(tokensGivenToValidator) * uint256(v.commissionRate) /  divider);\n                // increase validator exchange rate by distributing the leftover tokens through the validator shares\n                v.exchangeRate += uint128(uint256(tokensGivenToValidator - commissionPaid) * divider / v.totalShares);\n                // give commission tokens to the validator\n                unchecked { v.commissionAvailableToRedeem += commissionPaid; }\n            }\n            // set the last update global rate to the current one\n            v.lastUpdateGlobalRate = globalExchangeRate;\n        }\n    }"
}