{
    "Function": "_beforeTokenTransfer",
    "File": "contracts/Pool/Pool.sol",
    "Parent Contracts": [
        "node_modules/@openzeppelin/contracts/utils/ReentrancyGuard.sol",
        "contracts/interfaces/IPool.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/token/ERC20/ERC20PausableUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/proxy/Initializable.sol"
    ],
    "High-Level Calls": [
        "IExtension",
        "IPoolFactory",
        "SafeMathUpgradeable",
        "IPoolFactory",
        "IPoolFactory",
        "IRepayment",
        "SafeMathUpgradeable",
        "SafeMathUpgradeable",
        "SafeMathUpgradeable",
        "IVerification",
        "SafeMathUpgradeable",
        "SafeMathUpgradeable",
        "SafeMathUpgradeable",
        "SafeMathUpgradeable",
        "SafeMathUpgradeable",
        "SafeMathUpgradeable"
    ],
    "Internal Calls": [
        "require(bool,string)",
        "require(bool,string)",
        "_withdrawRepayment",
        "getMarginCallEndTime",
        "require(bool,string)",
        "balanceOf",
        "balanceOf",
        "require(bool,string)",
        "_withdrawRepayment",
        "require(bool,string)",
        "getMarginCallEndTime",
        "totalSupply",
        "paused"
    ],
    "Library Calls": [
        "div",
        "add",
        "div",
        "sub",
        "add",
        "mul",
        "mul",
        "div",
        "sub",
        "mul"
    ],
    "Low-Level Calls": [],
    "Code": "function _beforeTokenTransfer(\n        address _from,\n        address _to,\n        uint256 _amount\n    ) internal override {\n        if (_to != address(0)) {\n            require(!paused(), 'TT1');\n        }\n        require(_to != poolConstants.borrower, 'TT2');\n\n        if (_from == address(0) || _to == address(0)) {\n            return;\n        }\n        IPoolFactory _poolFactory = IPoolFactory(poolFactory);\n        address _lenderVerifier = poolConstants.lenderVerifier;\n        if (_lenderVerifier != address(0)) {\n            require(IVerification(_poolFactory.userRegistry()).isUser(_to, _lenderVerifier), 'TT5');\n        }\n        require(getMarginCallEndTime(_from) == 0, 'TT3');\n        require(getMarginCallEndTime(_to) == 0, 'TT4');\n\n        //Withdraw repayments for user\n\n        //We enforce pending interest withdrawals before the transfers\n        \n        //effectiveInterestWithdrawn stores the interest we assume addresses have withdrawn to simplify future interest withdrawals.\n        // For eg, if _from has 100 pool tokens, _to has 50 pool tokens, and _amount is 50, the effectiveInterestWithdrawn for \n        // _from is done using 50 pool tokens, since future interest repayment withdrawals are done with respect to 50 tokens for _from\n        // Similarly, we use 100 for _to's effectiveInterestWithdrawn calculation since their future interest withdrawals are calculated\n        // based on 100 pool tokens. Refer calculateRepaymentWithdrawable()\n        _withdrawRepayment(_from);\n        _withdrawRepayment(_to);\n        uint256 _totalRepaidAmount = IRepayment(IPoolFactory(poolFactory).repaymentImpl()).getTotalRepaidAmount(address(this));\n        uint256 _totalSupply = totalSupply();\n        uint256 _fromBalance = balanceOf(_from);\n        uint256 _toBalance = balanceOf(_to);\n        lenders[_from].effectiveInterestWithdrawn = (_fromBalance.sub(_amount)).mul(_totalRepaidAmount).div(_totalSupply);\n        lenders[_to].effectiveInterestWithdrawn = (_toBalance.add(_amount)).mul(_totalRepaidAmount).div(_totalSupply);\n\n        IExtension(_poolFactory.extension()).removeVotes(_from, _to, _amount);\n\n        //transfer extra liquidity shares\n        uint256 _liquidityShare = lenders[_from].extraLiquidityShares;\n        if (_liquidityShare == 0) return;\n\n        uint256 toTransfer = _liquidityShare;\n        if (_amount != _fromBalance) {\n            toTransfer = (_amount.mul(_liquidityShare)).div(_fromBalance);\n        }\n\n        lenders[_from].extraLiquidityShares = lenders[_from].extraLiquidityShares.sub(toTransfer);\n        lenders[_to].extraLiquidityShares = lenders[_to].extraLiquidityShares.add(toTransfer);\n    }"
}