The ALX Protocol settlement layer is a set of deterministic, pure functions that any implementation must execute identically for identical inputs. These functions translate on-chain query payments into curator payouts by applying reputation multipliers and freshness decay, then record each payout in a tamper-evident ledger. All functions are exported fromDocumentation Index
Fetch the complete documentation index at: https://docs.xandrlabs.ai/llms.txt
Use this file to discover all available pages before exploring further.
@alx/protocol/economics.
Settlement formula
WhensettleQuery is called on-chain, the reference AlexandrianRegistryV2 contract splits msg.value across three buckets:
protocolFee + sum(parentRoyalties) + curatorAmount = msg.value. Earnings accumulate in pendingWithdrawals[address] and are claimed through pull-based withdrawal.
Constants
| Constant | Value | Description |
|---|---|---|
RS_MIN | 0.01 | Reputation score floor — ensures brand-new KBs with no query history still earn a minimal payout |
RS_MAX | 3 | Reputation score ceiling — the highest-reputation KB earns 3× the base payout |
HALF_LIFE_DAYS | 30 | Freshness decay half-life in days (per PROTOCOL-SPEC §8.3) |
Functions
computePayout
Computes the final payout for a Knowledge Block given its base query fee, reputation score, and freshness multiplier. This is the primary economics function you call after normalizing an on-chain score and computing freshness.
payout = base × clamp(rs) × freshness
The result is rounded to 6 decimal places and floored at 0.
Base query fee in the unit of account (e.g. ETH or token smallest unit). Sourced from
msg.value after protocol fee deduction.Raw reputation score. Automatically clamped to
[RS_MIN, RS_MAX] = [0.01, 3] before multiplication. Pass the output of normalizeOnChainScore directly.Freshness multiplier in the range
(0, 1]. Pass the output of freshnessMultiplier(isoDate) directly. A value of 1.0 means the KB was just published.Payout rounded to 6 decimal places, minimum
0.clampRS
Clamps a raw reputation score to the valid protocol range [RS_MIN, RS_MAX]. You rarely need to call this directly — computePayout clamps internally — but it is useful when you want to display or log a bounded score before computing a payout.
Raw reputation score. Values below
0.01 are raised to 0.01; values above 3 are lowered to 3.Clamped reputation score in
[0.01, 3].ledgerLeafHash
Produces a deterministic SHA-256 leaf hash for a ledger entry. Use this to verify settlement integrity after distributing payouts — recompute the hash and compare it to the stored value.
"${contentHash}:${amount}". The output is a 0x-prefixed 64-character lowercase hex string (32 bytes).
SHA-256 is required by the protocol, not a weaker hash. These hashes form a cryptographic integrity check on payout records.
The
kbHash (or equivalent contentHash) of the Knowledge Block being settled. Must be the canonical protocol-visible identifier.Payout amount for this KB. Use the value returned by
computePayout before any further rounding."0x" followed by 64 lowercase hex characters — a 32-byte SHA-256 digest.