fragment NewMarketFields on NewMarket {
  instrument {
    name
    code
    futureProduct {
      settlementAsset {
        id
        name
        symbol
        decimals
        quantum
      }
      quoteName
      dataSourceSpecForSettlementData {
        sourceType {
          ... on DataSourceDefinitionExternal {
            sourceType {
              ... on DataSourceSpecConfiguration {
                signers {
                  signer {
                    ... on PubKey {
                      key
                    }
                    ... on ETHAddress {
                      address
                    }
                  }
                }
                filters {
                  key {
                    name
                    type
                  }
                  conditions {
                    operator
                    value
                  }
                }
              }
            }
          }
        }
      }
      dataSourceSpecForTradingTermination {
        sourceType {
          ... 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
  # }
  # linearSlippageFactor
  # quadraticSlippageFactor
  successorConfiguration {
    parentMarketId
  }
}

fragment UpdateMarketFields on UpdateMarket {
  marketId
  updateMarketConfiguration {
    instrument {
      code
      product {
        ... on UpdateFutureProduct {
          quoteName
          dataSourceSpecForSettlementData {
            sourceType {
              ... on DataSourceDefinitionExternal {
                sourceType {
                  ... on DataSourceSpecConfiguration {
                    signers {
                      signer {
                        ... on PubKey {
                          key
                        }
                        ... on ETHAddress {
                          address
                        }
                      }
                    }
                    filters {
                      key {
                        name
                        type
                      }
                      conditions {
                        operator
                        value
                      }
                    }
                  }
                }
              }
            }
          }
          dataSourceSpecForTradingTermination {
            sourceType {
              ... on DataSourceDefinitionExternal {
                sourceType {
                  ... on DataSourceSpecConfiguration {
                    signers {
                      signer {
                        ... on PubKey {
                          key
                        }
                        ... on ETHAddress {
                          address
                        }
                      }
                    }
                    filters {
                      key {
                        name
                        type
                      }
                      conditions {
                        operator
                        value
                      }
                    }
                  }
                }
              }
            }
          }
          dataSourceSpecBinding {
            settlementDataProperty
            tradingTerminationProperty
          }
        }
        ... on UpdatePerpetualProduct {
          quoteName
          dataSourceSpecForSettlementData {
            sourceType {
              ... on DataSourceDefinitionExternal {
                sourceType {
                  ... on DataSourceSpecConfiguration {
                    signers {
                      signer {
                        ... on PubKey {
                          key
                        }
                        ... on ETHAddress {
                          address
                        }
                      }
                    }
                    filters {
                      key {
                        name
                        type
                      }
                      conditions {
                        operator
                        value
                      }
                    }
                  }
                }
              }
            }
          }
          dataSourceSpecForSettlementSchedule {
            sourceType {
              ... on DataSourceDefinitionExternal {
                sourceType {
                  ... on DataSourceSpecConfiguration {
                    signers {
                      signer {
                        ... on PubKey {
                          key
                        }
                        ... on ETHAddress {
                          address
                        }
                      }
                    }
                    filters {
                      key {
                        name
                        type
                      }
                      conditions {
                        operator
                        value
                      }
                    }
                  }
                }
              }
            }
          }
          dataSourceSpecBinding {
            settlementDataProperty
            settlementScheduleProperty
          }
        }
      }
    }
    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 UpdateNetworkParameterFields 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 {
        ...UpdateNetworkParameterFields
      }
    }
  }
}

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

fragment NewMarketSuccessorFields on NewMarket {
  instrument {
    name
  }
  successorConfiguration {
    parentMarketId
  }
}

fragment SuccessorProposalListFields on Proposal {
  id
  terms {
    change {
      ... on NewMarket {
        ...NewMarketSuccessorFields
      }
    }
  }
}

query SuccessorProposalsList {
  proposalsConnection(proposalType: TYPE_NEW_MARKET, inState: STATE_OPEN) {
    edges {
      node {
        ...SuccessorProposalListFields
      }
    }
  }
}
