{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/grainfinance-co/main/json-schema/grainfinance-co-drawdown-proposal-response-schema.json",
  "title": "DrawdownProposalResponse",
  "description": "A drawdown proposal returned by the drawdown-quote call.",
  "x-generated": "2026-10-25",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/grainfinance-co-openapi.yaml#/components/schemas/DrawdownProposalResponse",
  "properties": {
    "id": {
      "$ref": "#/$defs/UUID",
      "description": "The id of this drawdown proposal, to be passed to the drawdown-accept call."
    },
    "fromCurrency": {
      "type": "string",
      "description": "The currency in which the transaction should be paid at by your customer."
    },
    "toCurrency": {
      "type": "string",
      "description": "The currency in which the inventory item is listed at on your platform."
    },
    "fromCurrencyAmount": {
      "type": "number",
      "format": "double",
      "description": "The amount to draw down in the fromCurrency.\nIf toCurrencyAmount is provided, then fromCurrencyAmount calculated as:\n`fromCurrencyAmount = toCurrencyAmount * quote`"
    },
    "toCurrencyAmount": {
      "type": "number",
      "format": "double",
      "description": "The amount to draw down in the toCurrency.\nIf fromCurrencyAmount is provided, then toCurrencyAmount calculated as:\n`toCurrencyAmount = fromCurrencyAmount / quote`"
    },
    "collateralAmountReleased": {
      "type": "number",
      "format": "double",
      "description": "The collateral amount released back to the customer as a result of this drawdown, in the fromCurrency."
    },
    "quote": {
      "type": "number",
      "format": "double",
      "description": "The rate at which this drawdown settles - the rate locked by the hedge."
    },
    "endAt": {
      "$ref": "#/$defs/GrainDateFormat",
      "description": "The date in which this drawdown executes, denoted in `YYYY-MM-DD` format."
    },
    "settlementAt": {
      "$ref": "#/$defs/GrainDateFormat",
      "description": "The date in which this drawdown settles (next business day after endAt), denoted in `YYYY-MM-DD` format."
    },
    "validUntilTs": {
      "type": "number",
      "format": "double",
      "description": "The unix timestamp until which this drawdown proposal is valid."
    },
    "beforeHedgeState": {
      "$ref": "#/$defs/HedgeStateSnapshot",
      "description": "The hedge's state immediately before this drawdown."
    },
    "afterHedgeState": {
      "$ref": "#/$defs/HedgeStateSnapshot",
      "description": "The hedge's remaining state immediately after this drawdown."
    }
  },
  "required": [
    "id",
    "fromCurrency",
    "toCurrency",
    "fromCurrencyAmount",
    "toCurrencyAmount",
    "collateralAmountReleased",
    "quote",
    "endAt",
    "settlementAt",
    "validUntilTs",
    "beforeHedgeState",
    "afterHedgeState"
  ],
  "type": "object",
  "additionalProperties": false,
  "$defs": {
    "GrainDateFormat": {
      "type": "string",
      "format": "YYYY-MM-DD",
      "description": "The date format accepted by Grain's API. We accept dash separated ISO-8601 date-only strings.",
      "pattern": "\\d{4}-\\d{2}-\\d{2}"
    },
    "HedgeStateSnapshot": {
      "description": "A lighter point-in-time view of a hedge's position, used inside drawdown responses\nto show the hedge state before and after the action.",
      "properties": {
        "fromCurrencyAmount": {
          "type": "number",
          "format": "double",
          "description": "The remaining hedge amount in the fromCurrency at this state."
        },
        "toCurrencyAmount": {
          "type": "number",
          "format": "double",
          "description": "The remaining hedge amount in the toCurrency at this state."
        },
        "quote": {
          "type": "number",
          "format": "double",
          "description": "The hedge rate at this state."
        },
        "endAt": {
          "$ref": "#/$defs/GrainDateFormat",
          "description": "The hedge end date at this state, denoted in `YYYY-MM-DD` format."
        },
        "settlementAt": {
          "$ref": "#/$defs/GrainDateFormat",
          "description": "The hedge settlement date at this state, denoted in `YYYY-MM-DD` format."
        },
        "collateralAmount": {
          "type": "number",
          "format": "double",
          "description": "The collateral amount held for the hedge at this state, in the fromCurrency."
        }
      },
      "required": [
        "fromCurrencyAmount",
        "toCurrencyAmount",
        "quote",
        "endAt",
        "settlementAt",
        "collateralAmount"
      ],
      "type": "object",
      "additionalProperties": false
    },
    "UUID": {
      "type": "string",
      "format": "uuid",
      "pattern": "[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}"
    }
  }
}