{
    "Function": "destroy",
    "File": "contracts/NestedFactory.sol",
    "Parent Contracts": [
        "node_modules/@openzeppelin/contracts/utils/Multicall.sol",
        "contracts/MixinOperatorResolver.sol",
        "node_modules/@openzeppelin/contracts/access/Ownable.sol",
        "node_modules/@openzeppelin/contracts/utils/Context.sol",
        "node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol",
        "contracts/interfaces/INestedFactory.sol"
    ],
    "High-Level Calls": [
        "NestedRecords",
        "NestedRecords",
        "IERC20",
        "NestedRecords",
        "NestedRecords",
        "NestedRecords",
        "NestedAsset",
        "IERC20",
        "NestedReserve"
    ],
    "Internal Calls": [
        "_safeSubmitOrder",
        "require(bool,string)",
        "_msgSender",
        "_msgSender",
        "_transferFeeWithRoyalty",
        "require(bool,string)",
        "_safeTransferAndUnwrap",
        "_msgSender",
        "require(bool,string)",
        "nonReentrant",
        "isUnlocked",
        "onlyTokenOwner",
        "_calculateFees"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function destroy(\n        uint256 _nftId,\n        IERC20 _buyToken,\n        Order[] calldata _orders\n    ) external override nonReentrant onlyTokenOwner(_nftId) isUnlocked(_nftId) {\n        address[] memory tokens = nestedRecords.getAssetTokens(_nftId);\n        require(_orders.length > 0, \"NestedFactory::destroy: Missing orders\");\n        require(tokens.length == _orders.length, \"NestedFactory::destroy: Missing sell args\");\n        require(\n            nestedRecords.getAssetReserve(_nftId) == address(reserve),\n            \"NestedFactory::destroy: Assets in different reserve\"\n        );\n\n        uint256 buyTokenInitialBalance = _buyToken.balanceOf(address(this));\n\n        for (uint256 i = 0; i < tokens.length; i++) {\n            NestedRecords.Holding memory holding = nestedRecords.getAssetHolding(_nftId, tokens[i]);\n            reserve.withdraw(IERC20(holding.token), holding.amount);\n\n            _safeSubmitOrder(tokens[i], address(_buyToken), holding.amount, _nftId, _orders[i]);\n            nestedRecords.freeHolding(_nftId, tokens[i]);\n        }\n\n        // Amount calculation to send fees and tokens\n        uint256 amountBought = _buyToken.balanceOf(address(this)) - buyTokenInitialBalance;\n        uint256 amountFees = _calculateFees(_msgSender(), amountBought);\n        amountBought = amountBought - amountFees;\n\n        _transferFeeWithRoyalty(amountFees, _buyToken, _nftId);\n        _safeTransferAndUnwrap(_buyToken, amountBought, _msgSender());\n\n        // Burn NFT\n        nestedRecords.removeNFT(_nftId);\n        nestedAsset.burn(_msgSender(), _nftId);\n        emit NftBurned(_nftId);\n    }"
}