{
  "name": "Mesh Limit Order (Chipnet migration)",
  "description": "Open the original BCH-funded Mesh limit order and return the principal to the maker after expiry.",
  "$schema": "https://libauth.org/schemas/wallet-template-v0.schema.json",
  "version": "1.1.1",
  "supported": [
    "BCH_2025_05",
    "BCH_2026_05"
  ],
  "roles": {
    "maker": {
      "name": "Maker",
      "description": "Funds the order and retains early cancellation rights."
    },
    "refunder": {
      "name": "Refund sponsor",
      "description": "Pays the network fee and returns all locked BCH to the original maker after expiry."
    }
  },
  "start": [
    {
      "role": "maker",
      "action": "openOrder"
    }
  ],
  "actions": {
    "openOrder": {
      "name": "Open order",
      "description": "Fund a P2SH32 limit-order output with BCH.",
      "roles": {
        "maker": {}
      },
      "requirements": {
        "variables": [
          "makerPkh",
          "buyTokenCategory",
          "sellAmount",
          "buyAmount",
          "expiryTime"
        ],
        "participants": [
          {
            "role": "maker",
            "slots": {
              "min": 1,
              "max": 1
            }
          }
        ]
      },
      "transaction": "fundOrder"
    },
    "refundExpired": {
      "name": "Refund expired order",
      "description": "Return all locked BCH to the maker after expiry.",
      "roles": {
        "refunder": {}
      },
      "requirements": {
        "variables": [
          "makerPkh",
          "sellAmount",
          "expiryTime"
        ],
        "participants": [
          {
            "role": "refunder",
            "slots": {
              "min": 1,
              "max": 1
            }
          }
        ]
      },
      "transaction": "recoverOrder"
    }
  },
  "transactions": {
    "fundOrder": {
      "name": "Fund order",
      "description": "Create the Mesh covenant output.",
      "version": 2,
      "locktime": 0,
      "inputs": [],
      "outputs": [
        {
          "output": "orderOutput"
        }
      ],
      "composable": true
    },
    "recoverOrder": {
      "name": "Recover order",
      "description": "Return all locked principal to the maker.",
      "version": 2,
      "locktime": "$(<expiryTime>)",
      "inputs": [
        {
          "input": "orderInput",
          "inputIndex": 0
        }
      ],
      "outputs": [
        {
          "output": "makerRefund",
          "outputIndex": 0
        }
      ],
      "composable": true
    }
  },
  "inputs": {
    "orderInput": {
      "name": "Order input",
      "description": "Spend the funded order.",
      "token": null,
      "sequenceNumber": 4294967294,
      "unlockingScript": "refundWitness"
    }
  },
  "outputs": {
    "orderOutput": {
      "name": "Order output",
      "description": "Committed Mesh limit order.",
      "lockingScript": "orderCovenant",
      "valueSatoshis": "$(<sellAmount>)",
      "token": null
    },
    "makerRefund": {
      "name": "Maker refund",
      "description": "Returns the original BCH to the committed maker.",
      "lockingScript": "makerOutput",
      "valueSatoshis": "$(<sellAmount>)",
      "token": null
    }
  },
  "lockingScripts": {
    "orderCovenant": {
      "name": "Mesh order covenant",
      "description": "Existing LimitOrderSwap compiled redeem script.",
      "lockingType": "p2sh",
      "lockingBytecode": "orderRedeem",
      "state": {
        "variables": [
          "makerPkh",
          "buyTokenCategory",
          "sellAmount",
          "buyAmount",
          "expiryTime"
        ]
      },
      "roles": {
        "refunder": {
          "actions": [
            {
              "role": "refunder",
              "action": "refundExpired"
            }
          ],
          "selectable": true
        }
      }
    },
    "makerOutput": {
      "name": "Maker P2PKH",
      "description": "Payout script for the committed maker.",
      "lockingType": "p2pkh",
      "lockingBytecode": "makerPayout"
    }
  },
  "scripts": {
    "orderRedeem": "<expiryTime> <buyAmount> <sellAmount> <buyTokenCategory> OP_0 <makerPkh> 0x5679009c63587a5879adc3529dc576040065cd1da269567a9f690376a9147c7e0288ac7e00cd887800876300cc5479a2696700d152798800d35479a26900cc02e803a26968557aa90376a9147c7e0288ac7e51cd887600876351cc5379a2696751d1788851d35379a269686d6d7551675679519c63557ab1750376a9147c7e0288ac7e00cd887600876300cc5379a2696700d1788800d35379a269686d6d755167567a529d5679a97888577a577aad0376a9147c7e0288ac7e00cd887600876300cc5379a2696700d1788800d35379a269686d6d75516868",
    "makerPayout": "OP_DUP OP_HASH160 <makerPkh> OP_EQUALVERIFY OP_CHECKSIG",
    "refundWitness": "OP_1"
  },
  "variables": {
    "makerPkh": {
      "name": "Maker public key hash",
      "description": "Maker public key hash",
      "type": "bytes"
    },
    "buyTokenCategory": {
      "name": "Requested token category in covenant byte order",
      "description": "Requested token category in covenant byte order",
      "type": "bytes"
    },
    "sellAmount": {
      "name": "BCH locked in satoshis",
      "description": "BCH locked in satoshis",
      "type": "satoshis"
    },
    "buyAmount": {
      "name": "Requested token amount",
      "description": "Requested token amount",
      "type": "token_amount"
    },
    "expiryTime": {
      "name": "Expiry in Unix seconds",
      "description": "Expiry in Unix seconds",
      "type": "integer"
    }
  }
}