{
    "Function": "destroy",
    "File": "contracts/NestedFactory.sol",
    "Parent Contracts": [
        "contracts/abstracts/MixinOperatorResolver.sol",
        "contracts/abstracts/OwnableProxyDelegation.sol",
        "node_modules/@openzeppelin/contracts/utils/Context.sol",
        "node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol",
        "contracts/interfaces/INestedFactory.sol"
    ],
    "High-Level Calls": [
        "NestedRecords",
        "NestedAsset",
        "IERC20",
        "NestedRecords",
        "IERC20",
        "NestedReserve",
        "NestedRecords",
        "NestedRecords",
        "NestedRecords"
    ],
    "Internal Calls": [
        "_safeSubmitOrder",
        "require(bool,string)",
        "_msgSender",
        "nonReentrant",
        "require(bool,string)",
        "isUnlocked",
        "_msgSender",
        "_transferFeeWithRoyalty",
        "_safeTransferAndUnwrap",
        "onlyTokenOwner",
        "require(bool,string)"
    ],
    "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        uint256 tokensLength = tokens.length;\n        require(_orders.length != 0, \"NF: INVALID_ORDERS\");\n        require(tokensLength == _orders.length, \"NF: INPUTS_LENGTH_MUST_MATCH\");\n        require(nestedRecords.getAssetReserve(_nftId) == address(reserve), \"NF: RESERVE_MISMATCH\");\n\n        uint256 buyTokenInitialBalance = _buyToken.balanceOf(address(this));\n\n        for (uint256 i = 0; i < tokensLength; i++) {\n            uint256 amount = nestedRecords.getAssetHolding(_nftId, tokens[i]);\n            reserve.withdraw(IERC20(tokens[i]), amount);\n\n            _safeSubmitOrder(tokens[i], address(_buyToken), 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 = amountBought / 100; // 1% Fee\n        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    }"
}