{
  "openapi": "3.1.1",
  "info": {
    "title": "Smart Contract Relationship Graph API",
    "version": "1.0.0",
    "summary": "Map a contract's proxy, implementation, admin, owner, deployer/factory and token links as a graph.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://smartcontractrelationshipgraph.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Map a contract's proxy, implementation, admin, owner, deployer/factory and token links as a graph.",
        "description": "Draws the relationships around one address: proxy → implementation (and beacon), who can upgrade it (ProxyAdmin, Safe, timelock, EOA), owner() and admin(), who deployed it and whether that deployer is itself a contract (a factory), which token standards it implements (ERC-20 / ERC-721 / ERC-1155), plus any related addresses you add. Paste runtime bytecode and a relationship list for an offline graph.\n\nMethodology:\n- Proxy, implementation, beacon and upgrade controller come from the Smart Contract Upgrade Explorer tool (EIP-1967 / EIP-1822 / EIP-1167 / Safe / ZeppelinOS / EIP-7702 detection from storage slots and bytecode).\n- owner() and admin() are read with eth_call (a revert means the function does not exist or is restricted).\n- Deployer and creation transaction come from Sourcify (v2 API, fields=deployment) — only available for contracts verified on Sourcify. A deployer that has code is reported as a factory.\n- Token standards: ERC-165 supportsInterface for ERC-721 (0x80ac58cd) and ERC-1155 (0xd9b67a26); ERC-20 when totalSupply() and decimals() answer; name/symbol/decimals/totalSupply are read on-chain.\n- Offline: runtime bytecode is scanned for dispatcher selectors (PUSH4 … EQ) to infer ERC-20 / ERC-721 / ERC-1155 / Ownable / AccessControl, EIP-1167 clone targets and EIP-7702 delegation; your relationship lines are added verbatim.",
        "tags": [
          "web3"
        ],
        "x-mcp-tool": "smart_contract_relationship_graph",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SmartContractRelationshipGraphInput"
              },
              "examples": {
                "example1": {
                  "summary": "Token behind a minimal proxy, with known relationships (offline)",
                  "value": {
                    "mode": "bytecode",
                    "chain": "ethereum",
                    "bytecode": "0x608060405234801561001057600080fd5b5063a9059cbb146323b872dd1463095ea7b3146370a08231146318160ddd1463dd62ed3e14638da5cb5b1463f2fde38b1400",
                    "relationships": "this -> 0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed : owned by\n0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359 -> this : deployed\nthis -> 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 : holds USDC\n0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed -> Treasury Safe : member of"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SmartContractRelationshipGraphResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "SmartContractRelationshipGraphInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "mode": {
            "title": "What do you have?",
            "type": "string",
            "enum": [
              "lookup",
              "bytecode"
            ],
            "default": "lookup"
          },
          "chain": {
            "title": "Chain",
            "type": "string",
            "enum": [
              "ethereum",
              "base",
              "arbitrum",
              "optimism",
              "polygon",
              "avalanche",
              "bsc"
            ],
            "default": "ethereum"
          },
          "address": {
            "title": "Contract address",
            "type": "string",
            "maxLength": 42
          },
          "related": {
            "title": "Related addresses (optional)",
            "description": "One per line: \"0x… label\", e.g. a token it holds, a contract it calls or a known multisig.",
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 12
          },
          "bytecode": {
            "title": "Runtime bytecode (offline)",
            "type": "string",
            "maxLength": 200000
          },
          "relationships": {
            "title": "Relationship list (offline)",
            "description": "One per line: \"A -> B : label\" — A/B are addresses or names; use \"this\" for the analysed contract.",
            "type": "string",
            "maxLength": 20000
          }
        },
        "required": []
      },
      "SmartContractRelationshipGraphResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "mode",
              "chain",
              "address",
              "kind",
              "name",
              "proxy",
              "owner",
              "admin",
              "deployment",
              "interfaces",
              "token",
              "bytecode",
              "related",
              "graph"
            ],
            "properties": {
              "mode": {
                "type": "string",
                "enum": [
                  "lookup",
                  "bytecode"
                ]
              },
              "chain": {
                "type": "string"
              },
              "address": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "kind": {
                "type": "string",
                "enum": [
                  "contract",
                  "eoa",
                  "eip7702-account",
                  "bytecode"
                ]
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "proxy": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "required": [
                  "type",
                  "upgradeable",
                  "implementation",
                  "implementationName",
                  "beacon",
                  "admin",
                  "adminKind"
                ],
                "properties": {
                  "type": {
                    "type": "string"
                  },
                  "upgradeable": {
                    "type": "string"
                  },
                  "implementation": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "implementationName": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "beacon": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "admin": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "adminKind": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              },
              "owner": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "admin": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "deployment": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "required": [
                  "deployer",
                  "deployerType",
                  "txHash",
                  "block",
                  "viaFactory"
                ],
                "properties": {
                  "deployer": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "deployerType": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "txHash": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "block": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "viaFactory": {
                    "type": [
                      "boolean",
                      "null"
                    ]
                  }
                }
              },
              "interfaces": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "erc20",
                  "erc721",
                  "erc1155",
                  "ownable",
                  "accessControl"
                ],
                "properties": {
                  "erc20": {
                    "type": "boolean"
                  },
                  "erc721": {
                    "type": "boolean"
                  },
                  "erc1155": {
                    "type": "boolean"
                  },
                  "ownable": {
                    "type": "boolean"
                  },
                  "accessControl": {
                    "type": "boolean"
                  }
                }
              },
              "token": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "required": [
                  "name",
                  "symbol",
                  "decimals",
                  "totalSupply"
                ],
                "properties": {
                  "name": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "symbol": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "decimals": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "totalSupply": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              },
              "bytecode": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "size",
                  "selectors",
                  "upgradeFunctions",
                  "minimalProxyTarget",
                  "eip7702Delegate",
                  "hasDelegatecall"
                ],
                "properties": {
                  "size": {
                    "type": "integer"
                  },
                  "selectors": {
                    "type": "integer"
                  },
                  "upgradeFunctions": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "minimalProxyTarget": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "eip7702Delegate": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "hasDelegatecall": {
                    "type": "boolean"
                  }
                }
              },
              "related": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "id",
                    "label",
                    "type",
                    "name"
                  ],
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "label": {
                      "type": "string"
                    },
                    "type": {
                      "type": "string"
                    },
                    "name": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              },
              "graph": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "nodes",
                  "edges"
                ],
                "properties": {
                  "nodes": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "id",
                        "label",
                        "kind"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "label": {
                          "type": "string"
                        },
                        "kind": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "edges": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "from",
                        "to",
                        "label"
                      ],
                      "properties": {
                        "from": {
                          "type": "string"
                        },
                        "to": {
                          "type": "string"
                        },
                        "label": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}