{
    "Function": "validate",
    "File": "contracts/types/TokenId.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "TokenId",
        "TokenId",
        "TokenId",
        "TokenId",
        "TokenId",
        "TokenId",
        "TokenId",
        "TokenId",
        "TokenId",
        "TokenId",
        "TokenId",
        "TokenId",
        "TokenId",
        "TokenId",
        "TokenId",
        "TokenId"
    ],
    "Internal Calls": [
        "revert InvalidTokenIdParameter(uint256)",
        "revert InvalidTokenIdParameter(uint256)",
        "revert InvalidTokenIdParameter(uint256)",
        "revert InvalidTokenIdParameter(uint256)",
        "revert InvalidTokenIdParameter(uint256)",
        "revert InvalidTokenIdParameter(uint256)",
        "revert InvalidTokenIdParameter(uint256)",
        "revert InvalidTokenIdParameter(uint256)"
    ],
    "Library Calls": [
        "riskPartner",
        "isLong",
        "isLong",
        "width",
        "tokenType",
        "asset",
        "tokenType",
        "univ3pool",
        "optionRatio",
        "riskPartner",
        "optionRatio",
        "optionRatio",
        "asset",
        "optionRatio",
        "strike",
        "strike"
    ],
    "Low-Level Calls": [],
    "Code": "function validate(uint256 self) internal pure returns (uint64) {\n        if (self.optionRatio(0) == 0) revert Errors.InvalidTokenIdParameter(1);\n\n        // loop through the 4 (possible) legs in the tokenId `self`\n        unchecked {\n            for (uint256 i = 0; i < 4; ++i) {\n                if (self.optionRatio(i) == 0) {\n                    // final leg in this position identified;\n                    // make sure any leg above this are zero as well\n                    // (we don't allow gaps eg having legs 1 and 4 active without 2 and 3 is not allowed)\n                    if ((self >> (64 + 48 * i)) != 0) revert Errors.InvalidTokenIdParameter(1);\n\n                    break; // we are done iterating over potential legs\n                }\n                // now validate this ith leg in the position:\n\n                // The width cannot be 0; the minimum is 1\n                if ((self.width(i) == 0)) revert Errors.InvalidTokenIdParameter(5);\n                // Strike cannot be MIN_TICK or MAX_TICK\n                if (\n                    (self.strike(i) == Constants.MIN_V3POOL_TICK) ||\n                    (self.strike(i) == Constants.MAX_V3POOL_TICK)\n                ) revert Errors.InvalidTokenIdParameter(4);\n\n                // In the following, we check whether the risk partner of this leg is itself\n                // or another leg in this position.\n                // Handles case where riskPartner(i) != i ==> leg i has a risk partner that is another leg\n                uint256 riskPartnerIndex = self.riskPartner(i);\n                if (riskPartnerIndex != i) {\n                    // Ensures that risk partners are mutual\n                    if (self.riskPartner(riskPartnerIndex) != i)\n                        revert Errors.InvalidTokenIdParameter(3);\n\n                    // Ensures that risk partners have 1) the same asset, and 2) the same ratio\n                    if (\n                        (self.asset(riskPartnerIndex) != self.asset(i)) ||\n                        (self.optionRatio(riskPartnerIndex) != self.optionRatio(i))\n                    ) revert Errors.InvalidTokenIdParameter(3);\n\n                    // long/short status of associated legs\n                    uint256 isLong = self.isLong(i);\n                    uint256 isLongP = self.isLong(riskPartnerIndex);\n\n                    // token type status of associated legs (call/put)\n                    uint256 tokenType = self.tokenType(i);\n                    uint256 tokenTypeP = self.tokenType(riskPartnerIndex);\n\n                    // if the position is the same i.e both long calls, short put's etc.\n                    // then this is a regular position, not a defined risk position\n                    if ((isLong == isLongP) && (tokenType == tokenTypeP))\n                        revert Errors.InvalidTokenIdParameter(4);\n\n                    // if the two token long-types and the tokenTypes are both different (one is a short call, the other a long put, e.g.), this is a synthetic position\n                    // A synthetic long or short is more capital efficient than each leg separated because the long+short premia accumulate proportionally\n                    if ((isLong != isLongP) && (tokenType != tokenTypeP))\n                        revert Errors.InvalidTokenIdParameter(5);\n                }\n            } // end for loop over legs\n        }\n\n        return self.univ3pool();\n    }"
}