diff --git a/src/contract_core/contract_def.h b/src/contract_core/contract_def.h index c28cf012..51ac2625 100644 --- a/src/contract_core/contract_def.h +++ b/src/contract_core/contract_def.h @@ -15,10 +15,13 @@ #include "contracts/qpi.h" #include "qpi_proposal_voting.h" -// make interfaces to oracles available for all contracts -#include "oracle_core/oracle_interfaces_def.h" - -#define QX_CONTRACT_INDEX 1 +// make interfaces to oracles available for all contracts +#include "oracle_core/oracle_interfaces_def.h" + +// make inert Qassandra prediction-market scaffold types available for contracts +#include "contracts/Qassandra.h" + +#define QX_CONTRACT_INDEX 1 #define CONTRACT_INDEX QX_CONTRACT_INDEX #define CONTRACT_STATE_TYPE QX #define CONTRACT_STATE2_TYPE QX2 diff --git a/src/contracts/Qassandra.h b/src/contracts/Qassandra.h new file mode 100644 index 00000000..b27c2d9c --- /dev/null +++ b/src/contracts/Qassandra.h @@ -0,0 +1,165 @@ +#pragma once + +using namespace QPI; + +// Inert scaffold for future Qassandra oracle-settled prediction markets. +// This header defines contract-safe identifiers, status/outcome values, and +// deterministic settlement comparison helpers without adding storage or runtime hooks. + +constexpr uint64 QASSANDRA_QUBIC_USD_PRICE_SCALE = 100000000ULL; + +enum QassandraMarketStatus : uint8 +{ + QASSANDRA_MARKET_STATUS_DRAFT = 0, + QASSANDRA_MARKET_STATUS_OPEN = 1, + QASSANDRA_MARKET_STATUS_LOCKED = 2, + QASSANDRA_MARKET_STATUS_SETTLED = 3, + QASSANDRA_MARKET_STATUS_CANCELLED = 4, +}; + +enum QassandraMarketType : uint8 +{ + QASSANDRA_MARKET_TYPE_UNKNOWN = 0, + QASSANDRA_MARKET_TYPE_BINARY_PRICE = 1, +}; + +enum QassandraOutcome : uint8 +{ + QASSANDRA_OUTCOME_UNKNOWN = 0, + QASSANDRA_OUTCOME_NO = 1, + QASSANDRA_OUTCOME_YES = 2, +}; + +enum QassandraComparisonDirection : uint8 +{ + QASSANDRA_COMPARE_GT = 0, + QASSANDRA_COMPARE_GTE = 1, + QASSANDRA_COMPARE_LT = 2, + QASSANDRA_COMPARE_LTE = 3, +}; + +enum QassandraOracleSettlementStatus : uint8 +{ + QASSANDRA_ORACLE_SETTLEMENT_STATUS_UNKNOWN = 0, + QASSANDRA_ORACLE_SETTLEMENT_STATUS_PENDING = 1, + QASSANDRA_ORACLE_SETTLEMENT_STATUS_READY = 2, + QASSANDRA_ORACLE_SETTLEMENT_STATUS_FINAL = 3, +}; + +struct QassandraMarketId +{ + id eventId; + uint64 nonce; +}; + +struct QassandraOracleSettlement +{ + uint64 thresholdValue; + uint8 comparisonDirection; +}; + +// Agent-readable market metadata and deterministic settlement surfaces are planned +// for later Qassandra layers; no wallet, API, or off-chain orchestration is added here. +struct QassandraMarketDescriptor +{ + QassandraMarketId marketId; + uint8 marketType; + id baseAsset; + id quoteAsset; + QassandraOracleSettlement settlement; + uint64 settlementTick; + uint64 settlementTime; + id oracleQueryId; + uint8 settlementStatus; + uint8 canAgentRead; +}; + +inline static bool qassandraIsValidPriceReply(const OI::Price::OracleReply& reply) +{ + return reply.numerator > 0 && reply.denominator > 0; +} + +inline static bool qassandraCompareScaledPrice(const OI::Price::OracleReply& reply, uint64 thresholdValue, uint8 comparisonDirection) +{ + if (!qassandraIsValidPriceReply(reply)) + { + return false; + } + + const uint128 left = uint128(reply.numerator) * uint128(QASSANDRA_QUBIC_USD_PRICE_SCALE); + const uint128 right = uint128(thresholdValue) * uint128(reply.denominator); + + if (comparisonDirection == QASSANDRA_COMPARE_GT) + { + return left > right; + } + if (comparisonDirection == QASSANDRA_COMPARE_GTE) + { + return left >= right; + } + if (comparisonDirection == QASSANDRA_COMPARE_LT) + { + return left < right; + } + if (comparisonDirection == QASSANDRA_COMPARE_LTE) + { + return left <= right; + } + // Unknown comparison directions fail closed. + return false; +} + +struct Qassandra : public ContractBase +{ + struct StateData + { + }; + + REGISTER_USER_FUNCTIONS_AND_PROCEDURES() + { + } + + INITIALIZE() + { + } + + BEGIN_EPOCH() + { + } + + END_EPOCH() + { + } + + BEGIN_TICK() + { + } + + END_TICK() + { + } + + PRE_ACQUIRE_SHARES() + { + } + + POST_ACQUIRE_SHARES() + { + } + + PRE_RELEASE_SHARES() + { + } + + POST_RELEASE_SHARES() + { + } + + POST_INCOMING_TRANSFER() + { + } + + EXPAND() + { + } +};