A distributed order-book DEX using composable atomic swaps with full delegation control and endogenous liquidity.
Haskell
78
156 commits
updated Sep 11, 2026
The Getting Started instructions can be found here and the benchmarks can be found here.
Cardano-Swaps is the DeFi Kernel's fully peer-to-peer order book settlement protocol, designed to replace TradFi's permissioned and centralized DTCC. As a foundational settlement layer, businesses and Layer 2 solutions are meant to build on top of it. While end-users will likely interact with the protocol directly in its early stages, the ecosystem is designed to evolve. Over time, users will naturally migrate to specialized L2s for the majority of their trades. The settlement protocol, however, will remain the ecosystem's liquidity core, serving trades that demand maximum censorship-resistance. Since large entities like central banks and pension funds prioritize censorship-resistance over high throughput, deep liquidity will gravitate to this foundational layer. With this in mind, the protocol has features specifically designed to allow L2s and other DeFi applications to seamlessly tap into and share this liquidity.
There are three reasons why Cardano needs this order book settlement protocol:
The rationale for this layered approach is detailed in foundational documents like The DeFi Hypothesis and this technical seminar. The core idea is that while a single system faces a trilemma, a composite system of specialized layers does not:
The blockchain trilemma applies to individual entities. If two entities specialize—one for censorship-resistance and one for high-throughput—and then interoperate, the collective system completely sidesteps the trilemma. End-users are free to use the layer that best supports their needs.
This architectural choice has profound consequences for building a sustainable DeFi ecosystem:
The capital inefficiency of current DeFi stems directly from its reliance on the constant-product
AMM. This formula, while simple, is extremely inefficient because it ties an asset's price
directly to its ratio within a liquidity pool. To execute a trade of size x while keeping slippage
under 1%, a constant-product AMM requires 100x that amount in passive liquidity. Zero-slippage
trades are a mathematical impossibility, requiring infinite liquidity.
An order book, in contrast, is 100% capital efficient: a trade of size x requires only x in
active liquidity at the target price to execute with zero slippage.
This is not a minor flaw; it is a systemic barrier to adoption with critical consequences:
This doesn't mean AMMs have no future; it means their future is to evolve. The next generation of AMMs will move away from simple formulas and instead use a deep, on-chain order book as their primary source for price discovery.
By providing this foundational primitive, Cardano-Swaps enables a more mature and efficient DeFi ecosystem. It allows Cardano's capital to provide the same effective market depth as a vastly larger pool of capital locked in inefficient, constant-product AMMs. This is the key to unlocking true liquidity for Cardano, and competing with the liquidity Goliath that is Ethereum's DeFi.
There is a fundamental conflict between the design of prevailing DeFi protocols and the core principles of Cardano. The network's security (Ouroboros) and governance (on-chain democracy) are powered by the direct delegation choices of individual ADA holders. Yet, most DeFi protocols, built on a shared smart contract model, force users to surrender both custody of their assets and, critically, their delegation rights.
This model poses an existential threat to Cardano's decentralization and has created the single greatest barrier to DeFi adoption on the network. The proof is in the on-chain data: approximately 98.5% of Cardano's potential liquidity remains on the sidelines, held by users and institutions unwilling to make the unacceptable trade-off between participation and sovereignty.
Cardano-Swaps resolves this conflict by design. It abandons the shared contract model. Instead, leveraging CIP-89, each user interacts through their own individual, sovereign smart contract instance. This architecture guarantees that users always maintain full custody of their assets and complete, unabridged control over their ADA delegation rights.
This commitment to user sovereignty is what elevates Cardano-Swaps from a mere alternative to the DTCC into a categorical upgrade. While the DTCC provides settlement, it does so within a closed, custodial system. Cardano-Swaps provides settlement as a public good, offering three transformative advantages:
By aligning financial utility with the core principles of decentralization, Cardano-Swaps is designed to be the trustworthy foundation required to unlock the vast pool of dormant capital on Cardano and build a financial system that is not only more efficient but fundamentally more free.
The Cardano-Swaps protocol is built on a set of simple, composable primitives that combine to create a uniquely powerful and flexible settlement layer.
The protocol is comprised of two core swap types:
(The advanced strategies for using Liquidity Swaps to market make profitably, even in a low-frequency environment like Cardano, are explored in the Protocol Discussion section after the specification.)
The true power of the protocol emerges from the ability to compose these simple swaps into a single, atomic transaction. This has two transformative benefits:
(The free-market mechanism for managing the UTxO contention that arises from this powerful feature is also detailed in the Protocol Discussion section.)*
Through the use of CIP-89 beacon tokens, the protocol operates as a true peer-to-peer network without requiring centralized batchers. This architecture is the key to delivering on the promise of self-sovereignty:
(If you are only interested in the high-level aspects of the protocol, feel free to skip to the next section.)
The protocol's on-chain design is modular, built around a spending script / beacon script pair for
each type of swap. This approach allows for easy extension with new swap types in the future. The
following principles apply to all swap types.
[!WARNING] All swap datums contain beacon information that must be configured correctly upon creation. If incorrect beacon information is supplied, the resulting UTxO may be locked forever.
To guarantee uniqueness and fit within Cardano's 64-character limit for token names, all beacon names are derived by hashing concatenated asset information.
A one-way swap uses three distinct beacons:
sha2_256( "01" ++ offer_policy_id ++ offer_asset_name )sha2_256( "02" ++ ask_policy_id ++ ask_asset_name )sha2_256( offer_id ++ offer_name ++ ask_id ++ ask_name )To distinguish between ADA → TOKEN and TOKEN → ADA, ADA's policy ID is replaced with "00" when it is the ask asset. This ensures each direction has a unique pair beacon.
A two-way swap uses a non-directional pair beacon and two asset beacons. The assets in the pair are
first sorted lexicographically to determine asset1 and asset2. This ensures consistency for
off-chain queries.
sha2_256( asset1_policy_id ++ asset1_asset_name )sha2_256( asset2_policy_id ++ asset2_asset_name )sha2_256( asset1_id ++ asset1_name ++ asset2_id ++ asset2_name )[!IMPORTANT] Datums and redeemers for one-way and two-way swaps are distinct data types, even if they share field names.
data SwapDatum = SwapDatum
{ beaconId :: CurrencySymbol -- ^ Hash of the one-way swap beacon script.
, pairBeacon :: TokenName -- ^ Trading pair beacon asset name.
, offerId :: CurrencySymbol -- ^ Offer policy id.
, offerName :: TokenName -- ^ Offer asset name.
, offerBeacon :: TokenName -- ^ Offer beacon asset name.
, askId :: CurrencySymbol -- ^ Ask policy id.
, askName :: TokenName -- ^ Ask asset name.
, askBeacon :: TokenName -- ^ Ask beacon asset name.
, swapPrice :: Rational -- ^ Desired swap ratio: Ask/Offer.
, prevInput :: Maybe TxOutRef -- ^ Tracks the corresponding input for an execution.
, expiration :: Maybe POSIXTime -- ^ An optional expiration. Must fall on 1-min interval.
}
-- The beacon script still requires a redeemer, but no longer inspects it: the script
-- purpose (minting, staking, or publishing) determines the behavior. These constructors
-- are kept for backwards compatibility and convention:
data BeaconPolicyRedeemer
= RegisterBeaconScript -- ^ Conventionally used when registering the script's staking credential.
| CreateOrCloseSwaps -- ^ Conventionally used with minting executions.
| UpdateSwaps -- ^ Conventionally used with staking executions.
data SwapSpendingRedeemer
= SpendWithMint -- ^ Delegates checks to the beacon script's minting policy execution.
| SpendWithStake -- ^ Delegates checks to the beacon script's staking script execution.
| Swap
SpendWithStake, SpendWithMintSwapdata SwapDatum = SwapDatum
{ beaconId :: CurrencySymbol -- ^ Hash of the two-way swap beacon script.
, pairBeacon :: TokenName -- ^ Trading pair beacon asset name.
, asset1Id :: CurrencySymbol -- ^ Policy id for the first asset in the sorted pair.
, asset1Name :: TokenName -- ^ Asset name for the first asset.
, asset1Beacon :: TokenName -- ^ Beacon name for asset1.
, asset2Id :: CurrencySymbol -- ^ Policy id for the second asset.
, asset2Name :: TokenName -- ^ Asset name for the second asset.
, asset2Beacon :: TokenName -- ^ Beacon name for asset2.
, asset1Price :: Rational -- ^ Price to take asset1 (Asset2/Asset1).
, asset2Price :: Rational -- ^ Price to take asset2 (Asset1/Asset2).
, prevInput :: Maybe TxOutRef -- ^ Tracks the corresponding input for an execution.
, expiration :: Maybe POSIXTime -- ^ An optional expiration. Must fall on 1-min interval.
}
-- The beacon script still requires a redeemer, but no longer inspects it: the script
-- purpose (minting, staking, or publishing) determines the behavior. These constructors
-- are kept for backwards compatibility and convention:
data BeaconPolicyRedeemer
= RegisterBeaconScript -- ^ Conventionally used when registering the script's staking credential.
| CreateOrCloseSwaps -- ^ Conventionally used with minting executions.
| UpdateSwaps -- ^ Conventionally used with staking executions.
data SwapSpendingRedeemer
= SpendWithMint -- ^ Delegates checks to the beacon script's minting policy execution.
| SpendWithStake -- ^ Delegates checks to the beacon script's staking script execution.
| TakeAsset1 -- ^ Take asset 1 from the swap and give asset 2.
| TakeAsset2 -- ^ Take asset 2 from the swap and give asset 1.
SpendWithStake, SpendWithMintTakeAsset1, TakeAsset2Any user can execute an open swap as long as the conditions are met.
The spending script is executed for each swap input in a transaction. Its logic is to:
pairBeacon and
updating the prevInput field in the output datum.This design cleverly utilizes Cardano's per-UTxO script execution to enable cheap composition of swaps across different trading pairs within a single transaction.
[!NOTE] Since the spending script first checks for the trading pair beacon, each execution is dedicated to a specific trading pair. Any other outputs are ignored in this specific execution. This logic works because a script is executed once for every UTxO spent from the address. If input 1 is for beacon XYZ and input 2 is for beacon ABC, the first execution can be dedicated to beacon XYZ and the second execution can be dedicated to ABC. The net transaction will only succeed if all executions succeed. This behavior allows cheaply composing swaps of different trading pairs that are located at the same address. In other words, the design is taking advantage of the redundant executions.
prevInput is updated to the TxOutRef of the input.asked asset given / offered asset taken must be ≥ the price
specified in the datum.invalid-hereafter slot must be set and
must be less than or equal to the expiration time.The process for owners is consistent across all swap types and is primarily validated by the beacon script.
To create a swap, the owner must execute the beacon script as a minting policy (any beacon
redeemer works; CreateOrCloseSwaps by convention). This requires:
SwapDatum with swapPrice > 0.asset1 must be lexicographically less than asset2.invalid-hereafter field set
less than or equal to this time.This process requires a deposit of ~2 ADA per swap UTxO, which is reclaimable upon closing.
[!NOTE] On 1-Minute Expiration Intervals
The requirement for expirations to fall on a 1-minute interval is a deliberate design choice. As this protocol is a settlement layer and not a high-frequency trading (HFT) venue, sub-second precision is unnecessary. This interval strikes a crucial balance: it is slow enough for light wallets to reliably query and keep up with the state of the on-chain order book, yet granular enough to enable advanced, non-HFT trading strategies.
The owner's approval (via the staking credential) is required.
UpdateSwaps beacon redeemer (executed as a staking script)
and the SpendWithStake spending redeemer. This is the most efficient method when no beacons are
being minted or burned.CreateOrCloseSwaps beacon redeemer (executed as a
minting policy) and the SpendWithMint spending redeemer. This allows for burning old beacons and
minting new ones. To reclaim the ~2 ADA deposit, the beacons must be burned.[!IMPORTANT] When spending multiple swap UTxOs as the owner, use the same redeemer combination for all of them. If even one swap is being closed, use the
CreateOrCloseSwapscombination for all inputs to avoid redundant script executions and save on fees.
The protocol versions have undergone the following security audits:
[!WARNING] Although the changes are minor, this protocol version has not been audited yet.
| Date | Auditor | Report |
|---|---|---|
| October 2025 | Cypher Enterprises | View Full Report |
The protocol is capable of handling 25 swaps in a single transaction, regardless of the composition of one-way and two-way swaps in the transaction.
No CIPs or hard-forks are needed. This protocol works on the Cardano blockchain, as is.
Full benchmarking details can be found in the Benchmarks folder.
This section explores some of the deeper implications of the Cardano-Swaps design and provides insight into advanced strategies for interacting with the protocol.
Since users get their own DEX addresses which use their own staking credentials for spending authorization, users maintain full custody and delegation control of their assets at all times while using the DEX. Not your keys, not your crypto.
Upgrades can propagate through the ecosystem democratically. Users can choose to close their current swaps and recreate them with new, upgraded contracts at any time. Because of the protocol's universal composability, there is no risk of bifurcating liquidity between different versions.
Cardano's minUTxOValue requirement (~2 ADA deposit per swap) provides a natural defense against spam. Creating millions of fake swap UTxOs to disrupt queries would require millions of ADA in deposits. This, combined with trivial on-chain checks for asset authenticity (minting history) and the transaction fees required to cycle the UTxOs, makes large-scale DoS attacks economically impractical.
[!NOTE] The
minUTxOValuerequirement is a core feature of Cardano's security and is not at risk of being removed.
The protocol's peer-to-peer design completely eliminates centralized batchers as a required component. Any user can create/close/execute any open swap directly from the blockchain, ensuring they are never reliant on a third-party intermediary.
As will be explained in the next section, this architecture gives rise to a free market for execution: users who need guaranteed, direct execution can bypass UTxO contention by choosing an order with a slightly less favorable price. While the protocol is fundamentally batcherless, it still allows for batching to exist as an emergent service. Arbitrageurs are naturally incentivized to act as on-demand batchers, providing this functionality to users who desire it without building it in as a centralizing chokepoint.
The protocol's liquidity and efficiency emerge from the interplay of two key roles: Market Makers and Arbitragers.
A market maker's primary strategy is to use Two-Way Swaps to provide liquidity and earn a profit from the spread.
Strategy
To manage risk on a blockchain with slower block times, market makers should not compete on speed but instead price in the time-based risk. A sophisticated provider will calculate the expected price volatility over a transaction's confirmation window (e.g., 5-10 blocks) and set their spread wider than this value. The spread becomes the premium earned for accepting short-term volatility, enabling profitable market making without high-frequency updates.
This strategy transforms the risk of Cardano's slower block time into a manageable business parameter.
Arbitrage is the connective tissue of the protocol. Arbitrageurs perform three vital, profit-driven functions that benefit the entire ecosystem:
The ability to compose any swap into a transaction creates a free-market solution to UTxO contention. Rather than competing for the single best-priced swap, a user needing guaranteed execution can "pay up" by selecting a swap with a slightly worse price, where contention is exponentially lower. This allows users to pay a small premium for predictable, reliable execution.
This contention market is the key to secure interoperability. An L2 or dApp needing to atomically swap assets can "pay up" for a low-contention UTxO to ensure their transaction succeeds. This means L1 market makers can also profit directly from providing liquidity to the entire L2 and dApp ecosystem on Cardano.
Cardano-Swaps delivers a foundational settlement layer for the digital age, but it is more than just a decentralized alternative to TradFi's DTCC. While the DTCC provides settlement within a closed, custodial, and permissioned system, Cardano-Swaps offers settlement as a public good, presenting three transformative advantages: it is self-custodial, entirely permissionless, and cryptographically trustless.
Furthermore, it is protocol designed for the realities of a public blockchain, transforming core challenges like UTXO contention from intractable problems into predictable, free-market mechanisms for guaranteeing settlement.
By providing the trustworthy foundation required to unlock the vast pool of dormant capital on Cardano, it paves the way for a financial system that is not only more efficient and composable but fundamentally more free.
Haskell
82.2%
Shell
12.9%
Aiken
4.9%
A distributed order-book DEX using composable atomic swaps with full delegation control and endogenous liquidity.
Haskell
78
156 commits
updated Sep 11, 2026
The Getting Started instructions can be found here and the benchmarks can be found here.
Cardano-Swaps is the DeFi Kernel's fully peer-to-peer order book settlement protocol, designed to replace TradFi's permissioned and centralized DTCC. As a foundational settlement layer, businesses and Layer 2 solutions are meant to build on top of it. While end-users will likely interact with the protocol directly in its early stages, the ecosystem is designed to evolve. Over time, users will naturally migrate to specialized L2s for the majority of their trades. The settlement protocol, however, will remain the ecosystem's liquidity core, serving trades that demand maximum censorship-resistance. Since large entities like central banks and pension funds prioritize censorship-resistance over high throughput, deep liquidity will gravitate to this foundational layer. With this in mind, the protocol has features specifically designed to allow L2s and other DeFi applications to seamlessly tap into and share this liquidity.
There are three reasons why Cardano needs this order book settlement protocol:
The rationale for this layered approach is detailed in foundational documents like The DeFi Hypothesis and this technical seminar. The core idea is that while a single system faces a trilemma, a composite system of specialized layers does not:
The blockchain trilemma applies to individual entities. If two entities specialize—one for censorship-resistance and one for high-throughput—and then interoperate, the collective system completely sidesteps the trilemma. End-users are free to use the layer that best supports their needs.
This architectural choice has profound consequences for building a sustainable DeFi ecosystem:
The capital inefficiency of current DeFi stems directly from its reliance on the constant-product
AMM. This formula, while simple, is extremely inefficient because it ties an asset's price
directly to its ratio within a liquidity pool. To execute a trade of size x while keeping slippage
under 1%, a constant-product AMM requires 100x that amount in passive liquidity. Zero-slippage
trades are a mathematical impossibility, requiring infinite liquidity.
An order book, in contrast, is 100% capital efficient: a trade of size x requires only x in
active liquidity at the target price to execute with zero slippage.
This is not a minor flaw; it is a systemic barrier to adoption with critical consequences:
This doesn't mean AMMs have no future; it means their future is to evolve. The next generation of AMMs will move away from simple formulas and instead use a deep, on-chain order book as their primary source for price discovery.
By providing this foundational primitive, Cardano-Swaps enables a more mature and efficient DeFi ecosystem. It allows Cardano's capital to provide the same effective market depth as a vastly larger pool of capital locked in inefficient, constant-product AMMs. This is the key to unlocking true liquidity for Cardano, and competing with the liquidity Goliath that is Ethereum's DeFi.
There is a fundamental conflict between the design of prevailing DeFi protocols and the core principles of Cardano. The network's security (Ouroboros) and governance (on-chain democracy) are powered by the direct delegation choices of individual ADA holders. Yet, most DeFi protocols, built on a shared smart contract model, force users to surrender both custody of their assets and, critically, their delegation rights.
This model poses an existential threat to Cardano's decentralization and has created the single greatest barrier to DeFi adoption on the network. The proof is in the on-chain data: approximately 98.5% of Cardano's potential liquidity remains on the sidelines, held by users and institutions unwilling to make the unacceptable trade-off between participation and sovereignty.
Cardano-Swaps resolves this conflict by design. It abandons the shared contract model. Instead, leveraging CIP-89, each user interacts through their own individual, sovereign smart contract instance. This architecture guarantees that users always maintain full custody of their assets and complete, unabridged control over their ADA delegation rights.
This commitment to user sovereignty is what elevates Cardano-Swaps from a mere alternative to the DTCC into a categorical upgrade. While the DTCC provides settlement, it does so within a closed, custodial system. Cardano-Swaps provides settlement as a public good, offering three transformative advantages:
By aligning financial utility with the core principles of decentralization, Cardano-Swaps is designed to be the trustworthy foundation required to unlock the vast pool of dormant capital on Cardano and build a financial system that is not only more efficient but fundamentally more free.
The Cardano-Swaps protocol is built on a set of simple, composable primitives that combine to create a uniquely powerful and flexible settlement layer.
The protocol is comprised of two core swap types:
(The advanced strategies for using Liquidity Swaps to market make profitably, even in a low-frequency environment like Cardano, are explored in the Protocol Discussion section after the specification.)
The true power of the protocol emerges from the ability to compose these simple swaps into a single, atomic transaction. This has two transformative benefits:
(The free-market mechanism for managing the UTxO contention that arises from this powerful feature is also detailed in the Protocol Discussion section.)*
Through the use of CIP-89 beacon tokens, the protocol operates as a true peer-to-peer network without requiring centralized batchers. This architecture is the key to delivering on the promise of self-sovereignty:
(If you are only interested in the high-level aspects of the protocol, feel free to skip to the next section.)
The protocol's on-chain design is modular, built around a spending script / beacon script pair for
each type of swap. This approach allows for easy extension with new swap types in the future. The
following principles apply to all swap types.
[!WARNING] All swap datums contain beacon information that must be configured correctly upon creation. If incorrect beacon information is supplied, the resulting UTxO may be locked forever.
To guarantee uniqueness and fit within Cardano's 64-character limit for token names, all beacon names are derived by hashing concatenated asset information.
A one-way swap uses three distinct beacons:
sha2_256( "01" ++ offer_policy_id ++ offer_asset_name )sha2_256( "02" ++ ask_policy_id ++ ask_asset_name )sha2_256( offer_id ++ offer_name ++ ask_id ++ ask_name )To distinguish between ADA → TOKEN and TOKEN → ADA, ADA's policy ID is replaced with "00" when it is the ask asset. This ensures each direction has a unique pair beacon.
A two-way swap uses a non-directional pair beacon and two asset beacons. The assets in the pair are
first sorted lexicographically to determine asset1 and asset2. This ensures consistency for
off-chain queries.
sha2_256( asset1_policy_id ++ asset1_asset_name )sha2_256( asset2_policy_id ++ asset2_asset_name )sha2_256( asset1_id ++ asset1_name ++ asset2_id ++ asset2_name )[!IMPORTANT] Datums and redeemers for one-way and two-way swaps are distinct data types, even if they share field names.
data SwapDatum = SwapDatum
{ beaconId :: CurrencySymbol -- ^ Hash of the one-way swap beacon script.
, pairBeacon :: TokenName -- ^ Trading pair beacon asset name.
, offerId :: CurrencySymbol -- ^ Offer policy id.
, offerName :: TokenName -- ^ Offer asset name.
, offerBeacon :: TokenName -- ^ Offer beacon asset name.
, askId :: CurrencySymbol -- ^ Ask policy id.
, askName :: TokenName -- ^ Ask asset name.
, askBeacon :: TokenName -- ^ Ask beacon asset name.
, swapPrice :: Rational -- ^ Desired swap ratio: Ask/Offer.
, prevInput :: Maybe TxOutRef -- ^ Tracks the corresponding input for an execution.
, expiration :: Maybe POSIXTime -- ^ An optional expiration. Must fall on 1-min interval.
}
-- The beacon script still requires a redeemer, but no longer inspects it: the script
-- purpose (minting, staking, or publishing) determines the behavior. These constructors
-- are kept for backwards compatibility and convention:
data BeaconPolicyRedeemer
= RegisterBeaconScript -- ^ Conventionally used when registering the script's staking credential.
| CreateOrCloseSwaps -- ^ Conventionally used with minting executions.
| UpdateSwaps -- ^ Conventionally used with staking executions.
data SwapSpendingRedeemer
= SpendWithMint -- ^ Delegates checks to the beacon script's minting policy execution.
| SpendWithStake -- ^ Delegates checks to the beacon script's staking script execution.
| Swap
SpendWithStake, SpendWithMintSwapdata SwapDatum = SwapDatum
{ beaconId :: CurrencySymbol -- ^ Hash of the two-way swap beacon script.
, pairBeacon :: TokenName -- ^ Trading pair beacon asset name.
, asset1Id :: CurrencySymbol -- ^ Policy id for the first asset in the sorted pair.
, asset1Name :: TokenName -- ^ Asset name for the first asset.
, asset1Beacon :: TokenName -- ^ Beacon name for asset1.
, asset2Id :: CurrencySymbol -- ^ Policy id for the second asset.
, asset2Name :: TokenName -- ^ Asset name for the second asset.
, asset2Beacon :: TokenName -- ^ Beacon name for asset2.
, asset1Price :: Rational -- ^ Price to take asset1 (Asset2/Asset1).
, asset2Price :: Rational -- ^ Price to take asset2 (Asset1/Asset2).
, prevInput :: Maybe TxOutRef -- ^ Tracks the corresponding input for an execution.
, expiration :: Maybe POSIXTime -- ^ An optional expiration. Must fall on 1-min interval.
}
-- The beacon script still requires a redeemer, but no longer inspects it: the script
-- purpose (minting, staking, or publishing) determines the behavior. These constructors
-- are kept for backwards compatibility and convention:
data BeaconPolicyRedeemer
= RegisterBeaconScript -- ^ Conventionally used when registering the script's staking credential.
| CreateOrCloseSwaps -- ^ Conventionally used with minting executions.
| UpdateSwaps -- ^ Conventionally used with staking executions.
data SwapSpendingRedeemer
= SpendWithMint -- ^ Delegates checks to the beacon script's minting policy execution.
| SpendWithStake -- ^ Delegates checks to the beacon script's staking script execution.
| TakeAsset1 -- ^ Take asset 1 from the swap and give asset 2.
| TakeAsset2 -- ^ Take asset 2 from the swap and give asset 1.
SpendWithStake, SpendWithMintTakeAsset1, TakeAsset2Any user can execute an open swap as long as the conditions are met.
The spending script is executed for each swap input in a transaction. Its logic is to:
pairBeacon and
updating the prevInput field in the output datum.This design cleverly utilizes Cardano's per-UTxO script execution to enable cheap composition of swaps across different trading pairs within a single transaction.
[!NOTE] Since the spending script first checks for the trading pair beacon, each execution is dedicated to a specific trading pair. Any other outputs are ignored in this specific execution. This logic works because a script is executed once for every UTxO spent from the address. If input 1 is for beacon XYZ and input 2 is for beacon ABC, the first execution can be dedicated to beacon XYZ and the second execution can be dedicated to ABC. The net transaction will only succeed if all executions succeed. This behavior allows cheaply composing swaps of different trading pairs that are located at the same address. In other words, the design is taking advantage of the redundant executions.
prevInput is updated to the TxOutRef of the input.asked asset given / offered asset taken must be ≥ the price
specified in the datum.invalid-hereafter slot must be set and
must be less than or equal to the expiration time.The process for owners is consistent across all swap types and is primarily validated by the beacon script.
To create a swap, the owner must execute the beacon script as a minting policy (any beacon
redeemer works; CreateOrCloseSwaps by convention). This requires:
SwapDatum with swapPrice > 0.asset1 must be lexicographically less than asset2.invalid-hereafter field set
less than or equal to this time.This process requires a deposit of ~2 ADA per swap UTxO, which is reclaimable upon closing.
[!NOTE] On 1-Minute Expiration Intervals
The requirement for expirations to fall on a 1-minute interval is a deliberate design choice. As this protocol is a settlement layer and not a high-frequency trading (HFT) venue, sub-second precision is unnecessary. This interval strikes a crucial balance: it is slow enough for light wallets to reliably query and keep up with the state of the on-chain order book, yet granular enough to enable advanced, non-HFT trading strategies.
The owner's approval (via the staking credential) is required.
UpdateSwaps beacon redeemer (executed as a staking script)
and the SpendWithStake spending redeemer. This is the most efficient method when no beacons are
being minted or burned.CreateOrCloseSwaps beacon redeemer (executed as a
minting policy) and the SpendWithMint spending redeemer. This allows for burning old beacons and
minting new ones. To reclaim the ~2 ADA deposit, the beacons must be burned.[!IMPORTANT] When spending multiple swap UTxOs as the owner, use the same redeemer combination for all of them. If even one swap is being closed, use the
CreateOrCloseSwapscombination for all inputs to avoid redundant script executions and save on fees.
The protocol versions have undergone the following security audits:
[!WARNING] Although the changes are minor, this protocol version has not been audited yet.
| Date | Auditor | Report |
|---|---|---|
| October 2025 | Cypher Enterprises | View Full Report |
The protocol is capable of handling 25 swaps in a single transaction, regardless of the composition of one-way and two-way swaps in the transaction.
No CIPs or hard-forks are needed. This protocol works on the Cardano blockchain, as is.
Full benchmarking details can be found in the Benchmarks folder.
This section explores some of the deeper implications of the Cardano-Swaps design and provides insight into advanced strategies for interacting with the protocol.
Since users get their own DEX addresses which use their own staking credentials for spending authorization, users maintain full custody and delegation control of their assets at all times while using the DEX. Not your keys, not your crypto.
Upgrades can propagate through the ecosystem democratically. Users can choose to close their current swaps and recreate them with new, upgraded contracts at any time. Because of the protocol's universal composability, there is no risk of bifurcating liquidity between different versions.
Cardano's minUTxOValue requirement (~2 ADA deposit per swap) provides a natural defense against spam. Creating millions of fake swap UTxOs to disrupt queries would require millions of ADA in deposits. This, combined with trivial on-chain checks for asset authenticity (minting history) and the transaction fees required to cycle the UTxOs, makes large-scale DoS attacks economically impractical.
[!NOTE] The
minUTxOValuerequirement is a core feature of Cardano's security and is not at risk of being removed.
The protocol's peer-to-peer design completely eliminates centralized batchers as a required component. Any user can create/close/execute any open swap directly from the blockchain, ensuring they are never reliant on a third-party intermediary.
As will be explained in the next section, this architecture gives rise to a free market for execution: users who need guaranteed, direct execution can bypass UTxO contention by choosing an order with a slightly less favorable price. While the protocol is fundamentally batcherless, it still allows for batching to exist as an emergent service. Arbitrageurs are naturally incentivized to act as on-demand batchers, providing this functionality to users who desire it without building it in as a centralizing chokepoint.
The protocol's liquidity and efficiency emerge from the interplay of two key roles: Market Makers and Arbitragers.
A market maker's primary strategy is to use Two-Way Swaps to provide liquidity and earn a profit from the spread.
Strategy
To manage risk on a blockchain with slower block times, market makers should not compete on speed but instead price in the time-based risk. A sophisticated provider will calculate the expected price volatility over a transaction's confirmation window (e.g., 5-10 blocks) and set their spread wider than this value. The spread becomes the premium earned for accepting short-term volatility, enabling profitable market making without high-frequency updates.
This strategy transforms the risk of Cardano's slower block time into a manageable business parameter.
Arbitrage is the connective tissue of the protocol. Arbitrageurs perform three vital, profit-driven functions that benefit the entire ecosystem:
The ability to compose any swap into a transaction creates a free-market solution to UTxO contention. Rather than competing for the single best-priced swap, a user needing guaranteed execution can "pay up" by selecting a swap with a slightly worse price, where contention is exponentially lower. This allows users to pay a small premium for predictable, reliable execution.
This contention market is the key to secure interoperability. An L2 or dApp needing to atomically swap assets can "pay up" for a low-contention UTxO to ensure their transaction succeeds. This means L1 market makers can also profit directly from providing liquidity to the entire L2 and dApp ecosystem on Cardano.
Cardano-Swaps delivers a foundational settlement layer for the digital age, but it is more than just a decentralized alternative to TradFi's DTCC. While the DTCC provides settlement within a closed, custodial, and permissioned system, Cardano-Swaps offers settlement as a public good, presenting three transformative advantages: it is self-custodial, entirely permissionless, and cryptographically trustless.
Furthermore, it is protocol designed for the realities of a public blockchain, transforming core challenges like UTXO contention from intractable problems into predictable, free-market mechanisms for guaranteeing settlement.
By providing the trustworthy foundation required to unlock the vast pool of dormant capital on Cardano, it paves the way for a financial system that is not only more efficient and composable but fundamentally more free.
Haskell
82.2%
Shell
12.9%
Aiken
4.9%