Decentralizing Cardano with Honey Badgers

We are excited to release our article on Honey Badgers — and how it should make TeddySwap the most decentralized DEX on Cardano. TeddySwap is an open-source decentralized exchange protocol on Cardano focusing on stablecoins.
Introduction
There are many features to the TeddySwap stablecoin DEX, that combined, make it a unique protocol on Cardano.
This is highlighted by our open-source code, 85% community distribution, TEDY buyback from protocol revenue, and our decentralized batchers, or, as we like to call them — Honey Badgers.
The reality of Cardano is that each DEX on mainnet is closed-sourced, where the code is not available for public review. This means there is over hundreds of millions of ADA locked in smart contracts where the community is not able to independently verify the authenticity or security of the contracts.
Additionally, all DEXs currently batch their own transactions, which is akin to say, Solana Foundation, verifying all of the transactions on Solana.
At TeddySwap, we are committed to making the most decentralized DEX possible, and this starts with open source code, and secondly, decentralized batchers, where anyone from the Cardano community can openly and freely help batch transactions for TeddySwap and earn ADA for doing so.
In this article, we explore how batchers work technically and why we believe it to be a secure and scalable solution.
Honey Badgers
TeddySwap is a decentralized exchange (DEX) built on top of the Cardano blockchain network. In order to provide a more efficient and concurrent trading experience for users, TeddySwap has adopted and customized a transaction batcher called "Honey Badger," originally developed by Spectrum Finance.
The Unspent Transaction Output (UTXO) model is used on the Cardano network to represent transactions as inputs and outputs of UTXOs. In our DEX, liquidity is represented by a UTXO containing an identifier token to identify the pool and the assets locked in the pool (Token X, Token Y, and liquidity tokens).
When multiple users attempt to interact with the liquidity pool UTXO, there can be concurrency or contention problems, resulting in only one user succeeding in trading while others have to wait for the updated UTXO.

To solve this issue, TeddySwap has customized a transaction batcher called a "Honey Badger" to chain transactions together, allowing for concurrent trading without waiting for previous transactions to be confirmed. The "Honey Badger" batcher monitors three proxy contracts: Swap, Add Liquidity, and Remove Liquidity, for incoming transactions.
Whenever a new transaction is detected, the batcher will check if it can be chained to a previous transaction in the batch. If a previous transaction exists, the Honey Badger will chain the new transaction to the previous transaction by including the output UTXO of the previous transaction in the input UTXO of the new transaction. The batcher will then apply the new transaction to the liquidity pool UTXO using the Automated Market Maker (AMM) constant product formula, creating a pending state of the liquidity pool UTXO reflecting the result of the transaction.
Even though the state of the liquidity pool UTXO is pending and not yet confirmed, the Honey Badger will continue to chain additional transactions to the pending state. This allows for concurrent trading, where multiple transactions can be processed simultaneously without waiting for previous transactions to be confirmed.
As soon as a new chained transaction is constructed, the Honey Badger will submit the transaction to the mempool of the blockchain node for processing. Each chained transaction will update the liquidity pool UTXO with the new state reflecting the result of that particular transaction, using the AMM constant product formula.

By using transaction chaining and batching transactions together with the Honey Badger, TeddySwap provides an efficient and concurrent trading experience for users. This not only prevents contention but also ensures that multiple transactions can be processed simultaneously. Additionally, using the AMM constant product formula ensures that prices of assets in the liquidity pool remain balanced, providing efficient and accurate trading for users.
One of the unique features of the Honey Badger is the incentives for batchers to process as many transactions as possible, earning fees for each transaction they process. Users who create orders can also add tips, known as "Honey", which incentivizes badgers to prioritize their transactions and increase their chances of being included in the batch. In the future, users will not only be able to use ADA for the honey "tip," but they will also be able to add any Cardano Native Asset as a "tip," leaving it up to the batcher to decide if they see value in the assets being tipped.
In conclusion, the "Honey Badger" batcher contributes to decentralizing Cardano by allowing for efficient, secure, and concurrent trading on the TeddySwap DEX. It provides an alternative to traditional centralized exchanges, allowing users to trade cryptocurrencies in a trustless and permissionless environment. We thank Spectrum Finance for leading the way in developing this batcher technology.
Security Issues
Security is a top priority for TeddySwap, and we think measures are in-place to ensure a secure and trustless environment for our users to trade cryptocurrencies on the Cardano network. The batcher architecture we use is designed to operate in a decentralized fashion with potential attacks in mind, and we believe it is resistant to major attacks like the sandwich attack.
Other DEXs that have tried to run centralized batchers have faced the issue of attackers manipulating the order of transaction execution to front-run other transactions and profit from the price difference.
In TeddySwap's batcher architecture, pool UTXOs are highly contested by batchers due to the incentives for batching as many transactions as possible to gain profits from the fees. This means that even if an attacker executes their own transactions, they are not guaranteed to succeed because other batchers may have already moved the state of the UTXO before the attack. This decentralization and lack of control by any single person or entity make it similar to block processing in other blockchains like Bitcoin.
The open-source nature of the batcher allows for customizable transaction ordering mechanics, such as time-based sorting or fee marking priority sorting, enabling anyone to modify the batcher and prevent attackers from reverse engineering the predefined ordering system and manipulating it to their advantage.
Furthermore, the Honey Badger architecture has also been successfully run by the Spectrum Finance team on Ergo, with no reports of definitive sandwich attacks.
With the batcher open-sourced, potential security issues can be identified and addressed by the community, ensuring a more secure and trustless environment for trading cryptocurrencies on TeddySwap.
The code for our Honey Badger can be found here.
Final Remarks
Thank you for reading our article on running decentralized batchers.
We are currently gearing up for our mainnet launch. We are working on deploying our yield-farming contracts to our public testnet and auditing our contracts for mainnet.
Our Teddy Bears Club NFT collection is minting, and community members can earn TEDY tokens for each NFT they hold.
Currently, each NFT would earn approximately 52,000 TEDY for each NFT held.
Thank you to our community for your support. We are on a mission to create a secure and seamless stablecoin DEX on Cardano, built on the foundations of open-source code, community, and transparency.

For more information on TeddySwap:
Website | Twitter | Discord | Docs | Github | Linktree | Mint Teddy Bears
TeddySwap is an open-source decentralized exchange AMM protocol focusing on stablecoins in the Cardano ecosystem. Our protocol is developed by former Cardano Foundation developers and the creators of plu-ts, a smart contract framework built to efficiently deploy Cardano dApps.