Query 07 - Network Compliance USDM Output Classes
Result
USDM quantities are decimal USDM.
| producerKind | txs | outputs | usdm |
|---|---|---|---|
| treasury-continuity | 5 | 5 | 1133086.284353 |
| swap-receipt | 51 | 54 | 425131.618692 |
| beneficiary-payment-change | 2 | 2 | 3013.697480 |
What
This query classifies USDM outputs produced at network_compliance by the shape of the producing transaction.
swap-receipt means the producer consumes a SundaeSwap V3 order output
and returns USDM to the treasury. beneficiary-payment-change means the
producer also pays USDM to the CAG bridge and returns USDM change to the
treasury. treasury-continuity means the producer spends a previous
treasury UTxO and rolls treasury state forward.
Why
This prevents the common mistake of treating every USDM output at the treasury address as new income.
The only new incoming USDM in the May accounting is the swap-receipt
class: 425,131.618692 USDM. The treasury-continuity row is internal
turnover of treasury state, and the beneficiary-payment-change row is
the residual USDM returned by payment transactions.
Diagram
flowchart LR
swaps[Swap consumers]
payments[Beneficiary payment txs]
rolls[Treasury continuity txs]
nc[network_compliance USDM outputs]
classes[Producer classes]
swaps --> nc
payments --> nc
rolls --> nc
nc --> classes
How
The query first builds one row per USDM output at the network_compliance address.
It then applies three graph-shape tests to the producing transaction: does it consume a SundaeSwap order output, does it emit USDM to the CAG payee bridge, and does it spend a previous network_compliance output?
Those tests produce the producerKind classification.
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/treasury-usdm-movement/07-network-compliance-usdm-output-classes.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#>
# Classify every USDM output produced at network_compliance by the producing
# transaction's graph shape.
SELECT ?producerKind
(COUNT(DISTINCT ?txId) AS ?txs)
(COUNT(DISTINCT ?outputRef) AS ?outputs)
((xsd:decimal(SUM(?outputUsdmRaw)) / 1000000) AS ?usdm)
WHERE {
{
SELECT ?tx ?txId ?outputRef (SUM(?qty) AS ?outputUsdmRaw)
WHERE {
VALUES ?usdmAssetId {
"c48cbb3d5e57ed56e276bc45f99ab39abe94e6cd7ac39fb402da47ad0014df105553444d"
}
?networkCompliance rdfs:label "amaru-treasury.network_compliance" ;
cardano:bech32 ?networkComplianceBech32 .
?tx cardano:hasTxId/cardano:bytesHex ?txId ;
cardano:hasOutput ?out .
?out cardano:hasIndex ?ix ;
cardano:atAddress/cardano:bech32 ?networkComplianceBech32 ;
cardano:hasAssetValue/rdf:rest*/rdf:first ?asset .
?asset cardano:hasIdentifier/cardano:bytesHex ?usdmAssetId ;
cardano:quantity ?qty .
BIND(CONCAT(?txId, "#", STR(?ix)) AS ?outputRef)
}
GROUP BY ?tx ?txId ?outputRef
}
BIND(EXISTS {
?orderScript rdfs:label "sundae.swap.v3.order" ;
cardano:hasIdentifier/cardano:bytesHex ?orderScriptHash .
?tx 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 .
} AS ?isSwapReceipt)
BIND(EXISTS {
VALUES ?usdmAssetId {
"c48cbb3d5e57ed56e276bc45f99ab39abe94e6cd7ac39fb402da47ad0014df105553444d"
}
?payee rdfs:label "amaru.cag-payee" ;
cardano:bech32 ?payeeBech32 .
?tx cardano:hasOutput ?payeeOut .
?payeeOut cardano:atAddress/cardano:bech32 ?payeeBech32 ;
cardano:hasAssetValue/rdf:rest*/rdf:first ?payeeAsset .
?payeeAsset cardano:hasIdentifier/cardano:bytesHex ?usdmAssetId .
} AS ?isBeneficiaryPaymentChange)
BIND(EXISTS {
?networkCompliance rdfs:label "amaru-treasury.network_compliance" ;
cardano:bech32 ?networkComplianceBech32 .
?tx cardano:hasInput ?input .
?input cardano:fromTxOutRef ?ref .
?ref cardano:hasTxId/cardano:bytesHex ?sourceTxId ;
cardano:hasIndex ?sourceIx .
?sourceTx cardano:hasTxId/cardano:bytesHex ?sourceTxId ;
cardano:hasOutput ?sourceOut .
?sourceOut cardano:hasIndex ?sourceIx ;
cardano:atAddress/cardano:bech32 ?networkComplianceBech32 .
} AS ?spendsTreasury)
BIND(
IF(
?isSwapReceipt,
"swap-receipt",
IF(?isBeneficiaryPaymentChange, "beneficiary-payment-change", IF(?spendsTreasury, "treasury-continuity", "other"))
) AS ?producerKind
)
}
GROUP BY ?producerKind
ORDER BY DESC(?usdm)