{
  "name": "Taifoon Grid — hire measured resources",
  "nodes": [
    {
      "parameters": {},
      "id": "trigger",
      "name": "When clicking Test workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [0, 0]
    },
    {
      "parameters": {
        "url": "https://www.taifoon.io/api/grid/economics",
        "options": {}
      },
      "id": "economics",
      "name": "What sharing earns (per kind, live bonus)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [260, -120]
    },
    {
      "parameters": {
        "url": "https://www.taifoon.io/api/grid/hire",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            { "name": "kind", "value": "storage" },
            { "name": "units", "value": "1" },
            { "name": "hours", "value": "24" }
          ]
        },
        "options": {}
      },
      "id": "hire",
      "name": "Hire storage (usable providers + quote)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [260, 80]
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" },
          "conditions": [
            { "id": "fulfilled", "leftValue": "={{ $json.fulfilled }}", "rightValue": 1, "operator": { "type": "number", "operation": "gte" } }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "gate",
      "name": "Any provider fulfilled?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [520, 80]
    },
    {
      "parameters": {
        "jsCode": "// The first offered provider and the live quote. Nothing is reserved:\n// settlement is NOT_DEPLOYED, so treat the quote as a price, not a charge.\n// Pass kind/units/hours through so the next node can RECORD the intent.\nconst r = $input.first().json;\nreturn [{ json: { kind: r.kind, units: r.requested, hours: 24, endpoint: r.providers[0].endpoint, trust: r.providers[0].trust, capacity: r.providers[0].capacity, totalGrid: r.quote.totalGrid, totalUsdc: r.quote.totalUsdc, settlement: r.quote.settlement } }];"
      },
      "id": "pick",
      "name": "Pick the best provider",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [780, 20]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://www.taifoon.io/api/grid/hire",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ kind: $json.kind, units: $json.units, hours: $json.hours, hirer: 'n8n-workflow', note: 'recorded by the Taifoon n8n hire workflow' }) }}",
        "options": {}
      },
      "id": "record",
      "name": "Record the hire intent (ledger, not settlement)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1040, 20]
    },
    {
      "parameters": {
        "jsCode": "// Nobody usable right now — the Grid is short of this kind. The bonus in\n// economics says what filling it pays; /join is one command.\nreturn [{ json: { shortfall: $input.first().json.shortfall, bonus: $input.first().json.bonus, join: 'https://www.taifoon.io/join' } }];"
      },
      "id": "short",
      "name": "Short — share instead",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [780, 200]
    }
  ],
  "connections": {
    "When clicking Test workflow": { "main": [[{ "node": "What sharing earns (per kind, live bonus)", "type": "main", "index": 0 }, { "node": "Hire storage (usable providers + quote)", "type": "main", "index": 0 }]] },
    "Hire storage (usable providers + quote)": { "main": [[{ "node": "Any provider fulfilled?", "type": "main", "index": 0 }]] },
    "Any provider fulfilled?": { "main": [[{ "node": "Pick the best provider", "type": "main", "index": 0 }], [{ "node": "Short — share instead", "type": "main", "index": 0 }]] },
    "Pick the best provider": { "main": [[{ "node": "Record the hire intent (ledger, not settlement)", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" },
  "meta": { "templateCredsSetupCompleted": true }
}
