{
    "Function": "performUpkeep",
    "File": "contracts/ThecosomataETH.sol",
    "Parent Contracts": [
        "node_modules/@openzeppelin/contracts/access/Ownable.sol",
        "node_modules/@openzeppelin/contracts/utils/Context.sol"
    ],
    "High-Level Calls": [
        "IBTRFLY",
        "IRedactedTreasury",
        "IBTRFLY",
        "IERC20",
        "ICurveCryptoPool",
        "IERC20",
        "IBTRFLY",
        "IERC20"
    ],
    "Internal Calls": [
        "require(bool,string)",
        "calculateAmountRequiredForLP",
        "calculateAmountRequiredForLP",
        "checkUpkeep",
        "require(bool,string)",
        "addLiquidity",
        "onlyOwner"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function performUpkeep() external onlyOwner {\n        require(checkUpkeep(), \"Invalid upkeep state\");\n\n        uint256 btrfly = IBTRFLY(BTRFLY).balanceOf(address(this));\n        uint256 ethAmount = calculateAmountRequiredForLP(btrfly, true);\n        uint256 ethCap = IERC20(WETH).balanceOf(TREASURY);\n        uint256 ethLiquidity = ethCap > ethAmount ? ethAmount : ethCap;\n\n        // Use BTRFLY balance if remaining capacity is enough, otherwise, calculate BTRFLY amount\n        uint256 btrflyLiquidity = ethCap > ethAmount\n            ? btrfly\n            : calculateAmountRequiredForLP(ethLiquidity, false);\n\n        IRedactedTreasury(TREASURY).manage(WETH, ethLiquidity);\n\n        // Only complete upkeep only on sufficient amounts\n        require(ethLiquidity > 0 && btrflyLiquidity > 0, \"Insufficient amounts\");\n        addLiquidity(ethLiquidity, btrflyLiquidity);\n\n        // Transfer out the pool token to treasury\n        address token = ICurveCryptoPool(CURVEPOOL).token();\n        uint256 tokenBalance = IERC20(token).balanceOf(address(this));\n        IERC20(token).transfer(TREASURY, tokenBalance);\n\n        uint256 unusedBTRFLY = IBTRFLY(BTRFLY).balanceOf(address(this));\n\n        if (unusedBTRFLY > 0) {\n            IBTRFLY(BTRFLY).burn(unusedBTRFLY);\n        }\n\n        emit AddLiquidity(ethLiquidity, btrflyLiquidity, unusedBTRFLY);\n    }"
}