Query 08 - Sundae Order Consumer Summary
Result
ADA quantities are decimal ADA. USDM quantities are decimal USDM.
| orderInputs | txs | orderAda | receivedUsdm |
|---|---|---|---|
| 1 | 49 | 1616710.802883 | 415066.592562 |
| 2 | 1 | 85.783609 | 20.879498 |
| 3 | 1 | 38201.413508 | 10044.146632 |
What
This query summarizes the 51 SundaeSwap V3 order consumer transactions that return USDM to the network_compliance treasury, grouped by how many order UTxOs each consumer spends.
Why
Query 19 lists every swap receipt. This query compresses that detail so a reader can see whether the receipts are mostly one-order scoops or multi-order scoops.
The result also cross-checks the incoming USDM total from Query 17:
the grouped receivedUsdm sum is exactly 425,131.618692.
Diagram
flowchart LR
orders[Sundae V3 order UTxOs]
consumers[Consumer transactions]
receipts[USDM to network_compliance]
groups[Group by order-input count]
orders --> consumers
consumers --> receipts
consumers --> groups
receipts --> groups
How
The query has one subquery for consumed order inputs and one subquery for USDM receipts.
The order-input subquery de-duplicates the Sundae V3 order script hash from the repeated rules overlay, then counts consumed order references per consumer transaction and sums their ADA.
The receipt subquery sums USDM outputs from the same producer transaction back to network_compliance. Joining after those per-tx aggregations avoids multiplying USDM receipts by the number of order inputs.
Run
From the repository root, run this query through the tutorial setup script:
bash docs/may-2026-amaru-lattice/setup.sh \
docs/may-2026-amaru-lattice/swaps-and-exchange-rates/08-sundae-order-consumer-summary.rq
SPARQL
PREFIX cardano: <https://lambdasistemi.github.io/cardano-knowledge-maps/vocab/cardano#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
# Summary of SundaeSwap V3 order consumers that returned USDM to
# network_compliance, grouped by how many order inputs each consumer spent.
SELECT ?orderInputs
(COUNT(?swapTx) AS ?txs)
((xsd:decimal(SUM(?orderLovelace)) / 1000000) AS ?orderAda)
((xsd:decimal(SUM(?receivedUsdmRaw)) / 1000000) AS ?receivedUsdm)
WHERE {
{
SELECT ?swapTx (COUNT(?orderRef) AS ?orderInputs)
(SUM(?oneOrderLovelace) AS ?orderLovelace)
WHERE {
# The rules graph is repeated in every transaction file, so the script
# hash must be de-duplicated before matching consumed order outputs.
{
SELECT DISTINCT ?orderScriptHash
WHERE {
?orderScript rdfs:label "sundae.swap.v3.order" ;
cardano:hasIdentifier/cardano:bytesHex ?orderScriptHash .
}
}
?swapTx cardano:hasInput ?in .
?in cardano:fromTxOutRef ?ref .
?ref cardano:hasTxId/cardano:bytesHex ?orderTxId ;
cardano:hasIndex ?orderIx .
?orderTx cardano:hasTxId/cardano:bytesHex ?orderTxId ;
cardano:hasOutput ?orderOut .
?orderOut cardano:hasIndex ?orderIx ;
cardano:atAddress/cardano:hasPaymentCredential/cardano:hasIdentifier/cardano:bytesHex ?orderScriptHash ;
cardano:lovelace ?oneOrderLovelace .
BIND(CONCAT(?orderTxId, "#", STR(?orderIx)) AS ?orderRef)
}
GROUP BY ?swapTx
}
{
SELECT ?swapTx (SUM(?receivedQty) AS ?receivedUsdmRaw)
WHERE {
VALUES ?usdmAssetId {
"c48cbb3d5e57ed56e276bc45f99ab39abe94e6cd7ac39fb402da47ad0014df105553444d"
}
{
SELECT DISTINCT ?networkComplianceBech32
WHERE {
?networkCompliance rdfs:label "amaru-treasury.network_compliance" ;
cardano:bech32 ?networkComplianceBech32 .
}
}
?swapTx cardano:hasOutput ?receiptOut .
?receiptOut cardano:atAddress/cardano:bech32 ?networkComplianceBech32 ;
cardano:hasAssetValue/rdf:rest*/rdf:first ?asset .
?asset cardano:hasIdentifier/cardano:bytesHex ?usdmAssetId ;
cardano:quantity ?receivedQty .
}
GROUP BY ?swapTx
}
}
GROUP BY ?orderInputs
ORDER BY ?orderInputs