Datum structure
Field reference
| Field | Type | Description |
|---|---|---|
tag | bytes | "09" in hex format |
redeemerAddress | constr | User’s address for receiving funds after execution |
input | list | [policyId, tokenName] - what the user is selling. ADA = ["", ""] |
tradableInput | integer | Amount of input asset in base units |
feePerExStep | integer | 600000 (0.6 ADA) |
output | list | [policyId, tokenName] - what the user wants to receive |
basePrice | list | [numerator, denominator] - price ratio |
cancellationPkh | bytes | User’s payment key hash for order cancellation |
beacon | bytes | 20-byte order identifier |
Price calculation
Price is theoutput / input ratio, stored as [numerator, denominator].
- Buy order
- Sell order
- Market order
Buying token with ADA:
- Input: ADA
- Output: Token
- Price:
tokenAmount / adaAmount=[tokenAmount, adaAmount]
[100, 50] = 2 tokens per ADAInput amount
- Buy order:
tradableInput= ADA amount the user is willing to spend - Sell order:
tradableInput= token amount the user is selling
Beacon calculation
The order beacon is a 20-byte unique identifier that prevents beacon collisions. Its primary purpose is to prevent beacon collisions - ensuring that every order placed on-chain has a globally unique identifier. Structure:- Byte 0: order type (
0= limit,1= market) - Bytes 1-19: first 19 bytes of a blake2b-224 hash
Algorithm
Build beacon preimage
Concatenate in order:
- Transaction hash (32 bytes) of one of the transaction inputs
- Output index (8 bytes, big-endian uint64)
- Order index (8 bytes, big-endian uint64)
- Datum hash (28 bytes) from step 3
Implementation
outputReference- one of the transaction inputs (UTxO reference)orderIndex- index of the order output in the transaction (BigInt)orderType-'limit'or'market'