Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/attestations.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,35 @@ INSERT INTO retired_market_actions (action_name) VALUES
ON CONFLICT (action_name) DO NOTHING;
```

### Old and new market actions

A market asks one question about a stream at time T: is the value above a threshold, below it, inside a range, or did the index change by an amount inside a range. Each question has an old action and a new one.

| Question | Old action (id) | New action (id) |
|---|---|---|
| Above a threshold | `price_above_threshold` (6) | `price_above_threshold_v2` (14) |
| Below a threshold | `price_below_threshold` (7) | `price_below_threshold_v2` (15) |
| Inside a range | `value_in_range` (8) | `value_in_range_v2` (16) |
| Index change inside a range | `index_change_in_range` (12) | `index_change_in_range_v2` (13) |

How each one finds the record it answers on:

- **Old value actions (6, 7, 8)** read the newest record stamped in the day before T. With none there, they read the newest record before that, however old. With no record at or before T, every capture fails, so the market never settles and its collateral stays locked. They answer YES or NO only.
- **The old index change action (12)** needs the index at T, from a record no more than a day old, and at T minus the interval, from a record no more than one interval older than that. Without either one, every capture fails in the same way.
- **New value actions (14, 15, 16)** read only the newest record stamped within `[T - tolerance, T]`, with the tolerance set by the market.
- **The new index change action (13)** reads the first record stamped within `[T, T + tolerance]`, and the record nearest to one interval before it, at most the tolerance away.
- **All four new actions** retry the capture while a record they need is missing. A capture taken from block time `T + W` that still finds none answers INVALID, and the market is refunded: every share is paid $0.50 and open buy orders are returned. The new index change action (13) also answers INVALID from T, without waiting, when its prior record's value is 0.
- **Range bounds differ.** `value_in_range` (8) counts both bounds as inside, `[min, max]`, and needs both. `value_in_range_v2` (16) counts min but not max, `[min, max)`, and a NULL bound leaves that side open. With the same bounds and min below max, a value equal to max answers YES on 8 and NO on 16. Equal bounds are allowed on 8, and 16 refuses them.

So an old value market can settle on an older record when the one it waits for is late, and an old market never settles when the stream has no record it accepts. A new market settles only on records inside its tolerance, and is refunded when its first capture from `T + W` still finds none. On a new value action, a stream that stamps its records more than the tolerance before T reads as having no record, even where an old action finds the same record through its fallback. A market on such a stream needs a tolerance that reaches back to the stamp, up to 45 days.

Listing an old action in `retired_market_actions` changes only new markets:

- `create_market` refuses a new market on it, from any wallet.
- Markets already created on it keep trading and settle as before.
- `request_attestation` does not read the table, so attestations of the old actions outside a market still work.
- Deleting the row makes the action available for new markets again.

## Retrieving Attestations

Call the `get_signed_attestation` action with the `request_tx_id` from your attestation request.
Expand Down
Loading