fragment NewMarketFields on NewMarket {
  instrument {
    name
    code
    futureProduct {
      settlementAsset {
        id
        name
        symbol
        decimals
        quantum
      }
      quoteName
      dataSourceSpecForSettlementData {
        sourceType {
          ... on DataSourceDefinitionInternal {
            sourceType {
              ... on DataSourceSpecConfigurationTime {
                conditions {
                  operator
                  value
                }
              }
            }
          }
          ... on DataSourceDefinitionExternal {
            sourceType {
              ... on DataSourceSpecConfiguration {
                signers {
                  signer {
                    ... on PubKey {
                      key
                    }
                    ... on ETHAddress {
                      address
                    }
                  }
                }
                filters {
                  key {
                    name
                    type
                  }
                  conditions {
                    operator
                    value
                  }
                }
              }
            }
          }
        }
      }
      dataSourceSpecForTradingTermination {
        sourceType {
          ... on DataSourceDefinitionInternal {
            sourceType {
              ... on DataSourceSpecConfigurationTime {
                conditions {
                  operator
                  value
                }
              }
            }
          }
          ... on DataSourceDefinitionExternal {
            sourceType {
              ... on DataSourceSpecConfiguration {
                signers {
                  signer {
                    ... on PubKey {
                      key
                    }
                    ... on ETHAddress {
                      address
                    }
                  }
                }
                filters {
                  key {
                    name
                    type
                  }
                  conditions {
                    operator
                    value
                  }
                }
              }
            }
          }
        }
      }
      dataSourceSpecBinding {
        settlementDataProperty
        tradingTerminationProperty
      }
    }
  }
  decimalPlaces
  riskParameters {
    ... on LogNormalRiskModel {
      riskAversionParameter
      tau
      params {
        mu
        r
        sigma
      }
    }
    ... on SimpleRiskModel {
      params {
        factorLong
        factorShort
      }
    }
  }
  metadata
  # priceMonitoringParameters {
  #   triggers {
  #     horizonSecs
  #     probability
  #     auctionExtensionSecs
  #   }
  # }
  # liquidityMonitoringParameters {
  #   targetStakeParameters {
  #     timeWindow
  #     scalingFactor
  #   }
  #   triggeringRatio
  #   auctionExtensionSecs
  # }
  lpPriceRange
  # linearSlippageFactor
  # quadraticSlippageFactor
}

fragment UpdateMarketFields on UpdateMarket {
  marketId
  updateMarketConfiguration {
    instrument {
      code
      product {
        quoteName
        dataSourceSpecForSettlementData {
          sourceType {
            ... on DataSourceDefinitionInternal {
              sourceType {
                ... on DataSourceSpecConfigurationTime {
                  conditions {
                    operator
                    value
                  }
                }
              }
            }
            ... on DataSourceDefinitionExternal {
              sourceType {
                ... on DataSourceSpecConfiguration {
                  signers {
                    signer {
                      ... on PubKey {
                        key
                      }
                      ... on ETHAddress {
                        address
                      }
                    }
                  }
                  filters {
                    key {
                      name
                      type
                    }
                    conditions {
                      operator
                      value
                    }
                  }
                }
              }
            }
          }
        }
        dataSourceSpecForTradingTermination {
          sourceType {
            ... on DataSourceDefinitionInternal {
              sourceType {
                ... on DataSourceSpecConfigurationTime {
                  conditions {
                    operator
                    value
                  }
                }
              }
            }
            ... on DataSourceDefinitionExternal {
              sourceType {
                ... on DataSourceSpecConfiguration {
                  signers {
                    signer {
                      ... on PubKey {
                        key
                      }
                      ... on ETHAddress {
                        address
                      }
                    }
                  }
                  filters {
                    key {
                      name
                      type
                    }
                    conditions {
                      operator
                      value
                    }
                  }
                }
              }
            }
          }
        }
        dataSourceSpecBinding {
          settlementDataProperty
          tradingTerminationProperty
        }
      }
    }
    metadata
    priceMonitoringParameters {
      triggers {
        horizonSecs
        probability
        auctionExtensionSecs
      }
    }
    liquidityMonitoringParameters {
      targetStakeParameters {
        timeWindow
        scalingFactor
      }
      triggeringRatio
      # auctionExtensionSecs
    }
    riskParameters {
      __typename
      ... on UpdateMarketSimpleRiskModel {
        simple {
          factorLong
          factorShort
        }
      }
      ... on UpdateMarketLogNormalRiskModel {
        logNormal {
          riskAversionParameter
          tau
          params {
            mu
            r
            sigma
          }
        }
      }
    }
  }
}

fragment NewAssetFields on NewAsset {
  name
  symbol
  decimals
  quantum
  source {
    ... on BuiltinAsset {
      maxFaucetAmountMint
    }
    ... on ERC20 {
      contractAddress
      lifetimeLimit
      withdrawThreshold
    }
  }
}

fragment UpdateAssetFields on UpdateAsset {
  assetId
  quantum
  source {
    ... on UpdateERC20 {
      lifetimeLimit
      withdrawThreshold
    }
  }
}

fragment UpdateNetworkParameterFiels on UpdateNetworkParameter {
  networkParameter {
    key
    value
  }
}

fragment ProposalListFields on Proposal {
  id
  rationale {
    title
    description
  }
  reference
  state
  datetime
  rejectionReason
  party {
    id
  }
  votes {
    yes {
      totalTokens
      totalNumber
      totalWeight
    }
    no {
      totalTokens
      totalNumber
      totalWeight
    }
  }
  errorDetails
  rejectionReason
  requiredMajority
  requiredParticipation
  requiredLpMajority
  requiredLpParticipation
  terms {
    closingDatetime
    enactmentDatetime
    change {
      __typename
      ... on NewMarket {
        ...NewMarketFields
      }
      ... on UpdateMarket {
        ...UpdateMarketFields
      }
      ... on NewAsset {
        ...NewAssetFields
      }
      ... on UpdateAsset {
        ...UpdateAssetFields
      }
      ... on UpdateNetworkParameter {
        ...UpdateNetworkParameterFiels
      }
    }
  }
}

query ProposalsList($proposalType: ProposalType, $inState: ProposalState) {
  proposalsConnection(proposalType: $proposalType, inState: $inState) {
    edges {
      node {
        ...ProposalListFields
      }
    }
  }
}
