TORQUEDocs

Query Builder

Generate and preview SQL queries for incentive data sources

The query builder tools generate SQL queries that define what user activity an incentive tracks and how it's measured, and preview the results before an incentive is created.

generate_incentive_query

Generate the SQL for an incentive query. Set the source parameter to select the data source, then provide source-specific parameters. The tool returns a validated SQL string ready to pass as sqlQuery to create_recurring_incentive.

Requires: authentication, active project

Common parameters

ParameterTypeRequiredDescription
source"swap" | "bonding_curve" | "hold" | "custom_event" | "idl_instruction" | "dune_query"YesData source for the query
confirmedbooleanNoSet to true to confirm (custom_event, idl_instruction, dune_query). Omit to preview the generated SQL.

Threshold semantics are inclusive by default. minUsdAmount, minAmountIn, minBalance, and any numeric filters use >= (inclusive). When a user says "over 100" or "100+", use 100. Only use > when the user says "more than" or "above" without inclusion.

Swap parameters

ParameterTypeDescription
tokenMintstringSPL token mint address (required)
direction"buy" | "sell" | "both"Trade direction (default: "buy")
measure"volume" | "count"Required. volume uses USD; count is transaction count.
minUsdAmountnumberMinimum USD value per swap (inclusive)
protocolstringDEX protocol filter (e.g. Jupiter, Raydium)

Bonding curve parameters

ParameterTypeDescription
launchpad"raydium_launchlab" | "metaplex_genesis"Required
direction"buy" | "sell" | "both"Default: "buy"
measure"volume" | "count"Required
poolStatestringPool state address (required for raydium_launchlab)
genesisAccountstringGenesis account (required for metaplex_genesis)
minAmountInnumberMinimum purchase size, raw amount (inclusive)

Hold parameters

ParameterTypeDescription
tokenMintstringSPL token mint address (required)
measure"balance" | "duration" | "count"Required. balance = latest qualifying balance per wallet; duration = distinct days with qualifying balance; count = number of qualifying balance records.
minBalancenumberMinimum token balance, must be > 0 (required; inclusive)

Custom event parameters

ParameterTypeDescription
customEventIdstringCustom event ID (required). Use list_custom_events.
valueExpressionstringE.g. "SUM(amount)", "COUNT(*)", "1" (flat reward). Mutually exclusive with rawQuery.
filtersstring[]WHERE conditions using field names (inclusive semantics apply).
groupByPubkeybooleanDefault: true
orderBy"DESC" | "ASC"Sort order
limitnumberMax rows
rawQuerystringFull SELECT with {{startDate}} / {{endDate}} placeholders. Mutually exclusive with valueExpression.

IDL instruction parameters

ParameterTypeDescription
instructionIdstringInstruction ID (required). Use list_idls.
valueExpressionstringE.g. "SUM(amount_in)", "COUNT(*)". Mutually exclusive with rawQuery.
filtersstring[]WHERE conditions
groupByFeePayerbooleanDefault: true
orderBy"DESC" | "ASC"Sort order
rawQuerystringFull SELECT with {{startDate}} / {{endDate}} placeholders. Mutually exclusive with valueExpression.

Dune query parameters

ParameterTypeDescription
duneEventQueryIdstringTorque-side UUID returned by register_dune_event_source — NOT the numeric duneQueryId. Required.
valueExpressionstringE.g. "SUM(volume_usd)", "COUNT(*)", "1". Mutually exclusive with rawQuery.
filtersstring[]WHERE conditions using columns from the Dune result set
groupByPubkeybooleanDefault: true
orderBy"DESC" | "ASC"Sort order
limitnumberMax rows
rawQuerystringFull SELECT with {{startDate}} / {{endDate}} placeholders. Mutually exclusive with valueExpression.

Dune event sources must complete at least one daily ingestion run before they can be queried. generate_incentive_query rejects sources without a populated column mapping. See Dune Event Sources.

preview_incentive_query

Execute a SQL query against real indexed data and preview the results before creating an incentive. The query runs asynchronously with up to 60 seconds of polling. By default, previews the last 3 complete days of data (midnight today is excluded to avoid partial-day data).

Requires: authentication, active project

ParameterTypeRequiredDescription
sqlQuerystringYesThe SQL query to preview
startDatestringNoISO 8601 start (default: midnight 3 days ago)
endDatestringNoISO 8601 end (default: midnight today)

Up to 20 rows are rendered in the output as a markdown table; the full result count is reported alongside. If the query times out (60s), the tool returns the queryId so results can be retrieved later from the platform.

Always preview your query before creating an incentive. This validates that the query produces the expected shape and data against the live indexed database.

Creation-time only. This tool tests queries during incentive setup. To check results or status of a live incentive, use get_epoch_leaderboard instead.

Query Builder - Torque Docs