{
    "Function": "processSwapFee",
    "File": "contracts/UpsideProtocol.sol",
    "Parent Contracts": [
        "node_modules/@openzeppelin/contracts/access/Ownable.sol",
        "node_modules/@openzeppelin/contracts/utils/Context.sol"
    ],
    "High-Level Calls": [
        "IERC20Metadata",
        "IUpsideStaking"
    ],
    "Internal Calls": [
        "computeTimeFee"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function processSwapFee(\n        address _metaCoinAddress,\n        bool _isBuy,\n        uint256 _tokenAmount,\n        address _deployer\n    ) internal returns (uint256 tokenAmountAfterFee) {\n        (uint256 secondsPassed, uint256 swapFeeBp, uint256 swapDeployerFeeBp) = computeTimeFee(_metaCoinAddress);\n\n        uint256 fee;\n        uint256 feeToProtocol;\n        uint256 feeToDeployer;\n        uint256 feeToStakers;\n\n        if (_isBuy) {\n            // @dev On buy, the dynamic time fee is used\n            fee = (_tokenAmount * swapFeeBp) / 10000;\n            tokenAmountAfterFee = _tokenAmount - fee;\n\n            claimableProtocolFees += fee;\n            feeToProtocol = fee;\n        } else {\n            // @dev On sell, a static percentage bp is used (impl could be significantly improved to save gas)\n            fee = (_tokenAmount * feeInfo.swapFeeSellBp) / 10000;\n            tokenAmountAfterFee = _tokenAmount - fee;\n\n            feeToDeployer = (fee * swapDeployerFeeBp) / 10000;\n            claimableDeployerFees[_metaCoinAddress][_deployer] += feeToDeployer;\n            feeToStakers = fee - feeToDeployer;\n\n            IERC20Metadata(_metaCoinAddress).approve(stakingContractAddress, feeToStakers);\n            IUpsideStaking(stakingContractAddress).distributeRewards(_metaCoinAddress, feeToStakers);\n        }\n\n        emit SwapFeeProcessed(\n            _metaCoinAddress,\n            _isBuy,\n            secondsPassed,\n            _isBuy ? swapFeeBp : feeInfo.swapFeeSellBp,\n            fee,\n            feeToProtocol,\n            feeToDeployer,\n            feeToStakers\n        );\n    }"
}