A complete on-chain limit order implementation for decentralized exchanges on Cardano.
- ✅ Self-custodied limit orders with price+quantity guards
- ✅ Partial and full order fills
- ✅ Multiple time-in-force options (GTC, GTD, IOC, FOK)
- ✅ Fee mechanism with rebates
- ✅ Order cancellation and updates
- ✅ Price validation and execution bounds
- ✅ Expiration handling
- GTC: Good Till Cancelled
- GTD: Good Till Date
- IOC: Immediate or Cancel
- FOK: Fill or Kill
src/ ├── LimitOrder/ │ ├── Types.hs -- Data types and definitions │ ├── Validator.hs -- On-chain validator logic │ ├── Helpers.hs -- Helper functions │ └── OffChain.hs -- Off-chain code └── LimitOrder.hs -- Main module export
- Nix package manager
- Cabal
- GHC 8.10.7 or later
- Enter development environment:
nix develop
Build the project: cabal build
Run tests: cabal test
Start REPL: cabal repl
Usage Example
import LimitOrder
-- Create order parameters params = OrderParams { opFeeRecipient = "fee_pkh" , opMinOrderValue = 2000000 , opMaxFeeBps = 100 }
-- Create a buy order createLimitOrder params baseAsset quoteAsset Buy 100 1 10000000 GTC Nothing True 10
Order Flow Post Order: Maker creates and funds a limit order
Fill Order: Taker fills order at or better than limit price
Cancel Order: Maker cancels unfilled portion
Update Order: Maker updates order parameters
Security Features Price validation prevents bad executions
Only order owner can cancel/update
Proper asset transfer validation
Expiration handling for GTD orders
License Apache 2.0
src/LimitOrder/Types.hs - Data types
src/LimitOrder/Validator.hs - On-chain logic
src/LimitOrder/Helpers.hs - Helper functions
src/LimitOrder/OffChain.hs - Off-chain code
src/LimitOrder.hs - Main module
test/LimitOrderSpec.hs - Test specifications
test/Main.hs - Test runner
app/Main.hs - Example application
limit-order-contract.cabal - Cabal configuration
flake.nix - Nix flake configuration
default.nix - Nix development environment
README.md - Documentation