{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.justlend.org/developers/contracts.schema.json",
  "title": "JustLend DAO contracts.json",
  "description": "Machine-readable contract directory for the JustLend DAO protocol on TRON. Records every JustLend contract on TRON Mainnet and Nile testnet in three equivalent address formats (Base58, EVM 0x-hex, TRON 41-hex) so consumers can use whichever their tooling expects without round-tripping through encoders.",
  "type": "object",
  "required": ["_meta", "networks"],
  "additionalProperties": false,
  "properties": {
    "$schema": { "type": "string", "format": "uri" },
    "_meta": { "$ref": "#/$defs/meta" },
    "networks": {
      "type": "object",
      "description": "Map of TRON network → category → contract records. `mainnet` is required; `nile` is optional but recommended for testnet integrations.",
      "required": ["mainnet"],
      "properties": {
        "mainnet": { "$ref": "#/$defs/network" },
        "nile":    { "$ref": "#/$defs/network" }
      },
      "additionalProperties": { "$ref": "#/$defs/network" }
    }
  },
  "$defs": {
    "meta": {
      "type": "object",
      "required": ["source_of_truth", "last_generated", "schema_version", "address_formats"],
      "properties": {
        "generated_by":     { "type": "string" },
        "source_of_truth":  { "type": "string", "format": "uri" },
        "last_generated":   { "type": "string", "format": "date" },
        "schema_version":   { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$", "description": "Semantic version of this document's shape. Pin a MAJOR." },
        "schema_version_policy": { "type": "string" },
        "address_formats": {
          "type": "object",
          "required": ["base58", "hex_evm", "hex_tron"],
          "additionalProperties": false,
          "properties": {
            "base58":   { "type": "string", "description": "Human description of when to use the Base58 form." },
            "hex_evm":  { "type": "string", "description": "Human description of when to use the EVM 0x form." },
            "hex_tron": { "type": "string", "description": "Human description of when to use the TRON 41 form." }
          }
        },
        "status_values": {
          "type": "object",
          "description": "Optional documentation for the `jtokens[*].status` enum.",
          "additionalProperties": { "type": "string" }
        },
        "comment": { "type": "string" }
      }
    },
    "address": {
      "type": "object",
      "description": "A TRON address in all three equivalent encodings.",
      "required": ["base58", "hex_evm", "hex_tron"],
      "additionalProperties": false,
      "properties": {
        "base58":   { "type": "string", "pattern": "^T[1-9A-HJ-NP-Za-km-z]{33}$", "description": "Base58Check, T-prefixed, 34 chars. Used by wallets, Tronscan, TronWeb display, end-user prompts." },
        "hex_evm":  { "type": "string", "pattern": "^0x[a-fA-F0-9]{40}$", "description": "EVM-style 0x-prefixed hex of the 20-byte address body. For cross-chain bridges, EVM-side tooling, Etherscan-like indexers." },
        "hex_tron": { "type": "string", "pattern": "^0x41[a-fA-F0-9]{40}$", "description": "TRON-internal 41-prefixed hex (21 bytes = 0x41 + EVM addr). For TronGrid / TronWeb low-level APIs." }
      }
    },
    "contract_record": {
      "type": "object",
      "description": "A single deployed contract on a TRON network.",
      "required": ["address"],
      "properties": {
        "label":    { "type": "string" },
        "address":  { "$ref": "#/$defs/address" },
        "network":  { "type": "string", "enum": ["mainnet", "nile"] },
        "tronscan": { "type": "string", "format": "uri", "pattern": "^https://(nile\\.)?tronscan\\.org/" },
        "role":     { "type": "string", "examples": ["entrypoint", "implementation", "executor", "token", "voting_wrapper", "model"] }
      },
      "additionalProperties": false
    },
    "underlying_record": {
      "type": "object",
      "description": "The underlying asset of a jToken market. Either a TRC20 (`address` present) or the native TRX (`address` absent, `note` present).",
      "required": ["label"],
      "properties": {
        "label":    { "type": "string" },
        "address":  { "$ref": "#/$defs/address" },
        "tronscan": { "type": "string", "format": "uri", "pattern": "^https://(nile\\.)?tronscan\\.org/" },
        "network":  { "type": "string", "enum": ["mainnet", "nile"] },
        "role":     { "type": "string", "examples": ["underlying"] },
        "note":     { "type": "string", "description": "Free text explaining oddities — e.g. native TRX having no TRC20 contract." }
      },
      "additionalProperties": false
    },
    "jtoken_record": {
      "type": "object",
      "description": "One JustLend jToken market: the delegator entrypoint (CErc20Delegator), its underlying TRC20 (or native TRX), and the optional delegate implementation.",
      "required": ["symbol", "status", "underlying_symbol", "decimals", "underlying_decimals", "delegator"],
      "properties": {
        "symbol":              { "type": "string", "pattern": "^j[A-Za-z0-9]+$", "description": "The jToken symbol — e.g. `jUSDT`, `jUSDCOLD`." },
        "status":              { "enum": ["active", "legacy"], "description": "`active` = open for new supply/borrow. `legacy` = closed to new supply/borrow but still queryable for existing positions to unwind." },
        "underlying_symbol":   { "type": "string", "description": "The underlying asset symbol — e.g. `USDT`, `USDC`." },
        "decimals":            { "const": 8, "description": "jToken decimals. **Always 8** for every Compound V2 jToken regardless of the underlying." },
        "underlying_decimals": { "type": "integer", "minimum": 0, "maximum": 18, "description": "Underlying token's decimals. TRX = 6, USDT/USDC/TUSD = 6, BTC/WBTC = 8, ETH/USDD = 18." },
        "delegator":           { "$ref": "#/$defs/contract_record" },
        "delegate":            { "$ref": "#/$defs/contract_record", "description": "The CErc20Delegate implementation behind the delegator. Optional; some delegators point at a shared/inline implementation." },
        "delegate_implementation": { "$ref": "#/$defs/contract_record", "description": "Legacy alias for `delegate`. Either key may appear in older generations of this file." },
        "underlying":          { "$ref": "#/$defs/underlying_record" }
      },
      "additionalProperties": false
    },
    "network": {
      "type": "object",
      "description": "A single TRON network's contract catalog. All `*` keys are optional — Nile testnet for example does not yet expose `price_oracle` or `interest_rate_models`.",
      "properties": {
        "comptroller": {
          "type": "object",
          "description": "Comptroller proxy + implementation. Key names: `unitroller_proxy`, `comptroller_impl`.",
          "additionalProperties": { "$ref": "#/$defs/contract_record" }
        },
        "price_oracle": {
          "type": "object",
          "description": "PriceOracle proxy + implementation.",
          "additionalProperties": { "$ref": "#/$defs/contract_record" }
        },
        "governance": {
          "type": "object",
          "description": "GovernorBravo delegator + delegate, Timelock, JST token, WJST voting wrapper.",
          "additionalProperties": { "$ref": "#/$defs/contract_record" }
        },
        "strx": {
          "type": "object",
          "description": "Liquid-staking sTRX contract (and proxy on Nile).",
          "additionalProperties": { "$ref": "#/$defs/contract_record" }
        },
        "jtokens": {
          "type": "object",
          "description": "Per-market jToken records, keyed by jToken symbol. Mainnet exposes 17 active + 6 legacy = 23 markets.",
          "additionalProperties": { "$ref": "#/$defs/jtoken_record" }
        },
        "interest_rate_models": {
          "type": "object",
          "description": "Per-deployment immutable interest-rate model contracts. Keyed by model name (e.g. `WhitePaperModelTRX`, `jumpRateUSDT`).",
          "additionalProperties": { "$ref": "#/$defs/contract_record" }
        },
        "energy_rental": {
          "type": "object",
          "description": "Energy Rental marketplace contract.",
          "additionalProperties": { "$ref": "#/$defs/contract_record" }
        },
        "note": {
          "type": "string",
          "description": "Free-text caveat about this network — e.g. testnet status, parity vs Mainnet."
        }
      },
      "additionalProperties": false
    }
  }
}
