Datum structure
Field reference
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
1
Create empty beacon
28 bytes of zeros:
0000...00002
Serialize datum with empty beacon
Convert the datum (with empty beacon) to CBOR format.
3
Hash the datum
Apply blake2b-224 to the serialized datum CBOR bytes.
4
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
5
Calculate final beacon
Apply blake2b-224 to the preimage, take the first 19 bytes, and prefix with the order type byte (
0 or 1). Result: 20 bytes.Implementation
outputReference- one of the transaction inputs (UTxO reference)orderIndex- index of the order output in the transaction (BigInt)orderType-'limit'or'market'