Where you are. Eighteen lessons, from a pool priced by a formula to a rail nobody owns. This project runs the three mechanisms that matter as one seeded script, and ends the course where module 3 left a promise.
The idea in one paragraph
Three artefacts, each verified by a property rather than by a number looking plausible. The pool is checked against simply holding, because a return that is not measured against the alternative is not a return. The liquidation engine is driven through a gap, because an engine that only sees continuous prices is an engine that has not been tested. And the cross-ledger settlement is run five times with failure injected at a different protocol step each time, because a settlement guarantee is a claim about every failure path, not about the happy one. The third of those is a property test, and it is the only kind of evidence that would justify the word atomic.
The brief
Measure the pool. Walk two deterministic price paths, a round trip and a doubling, and report impermanent loss, fee income and the net against holding for each. Confirm the fees pay for the round trip and do not pay for the trend.
Run the engine. Drive eight leveraged positions through a decline that gaps from ninety to seventy-two, absorbing shortfalls from the insurance fund in order and auto-deleveraging when it empties. Confirm the fund is exhausted exactly once and never goes negative.
Settle across the ledgers. Run the hash-time-locked trade five times, stopping after each protocol step in turn, and let every party recover as best it can. Confirm every run ends both or neither.
What the grid proves
The five runs are the project’s real result.
Stop before anything is locked, or after one lock, or after both: nothing has been revealed, both escrows expire and return home, and the answer is neither. Stop after the bonds are claimed and the secret is public, so the seller can take the cash whether or not the buyer cooperates, and the answer is both. Stop after everything: both.
| stopped after | end state |
|---|---|
| nothing yet | neither |
| cash locked | neither |
| bonds locked | neither |
| bonds claimed | both |
| cash claimed | both |
n = 5 trials · the protocol stopped after each step, then every party recovers
The transition happens at exactly one place: the moment the secret becomes public. Before it, no trade can complete; after it, no trade can fail to. There is no step at which the outcome is undetermined, which is what the guarantee actually means.
What you built
Working backwards, the finished script contains the module. The pool is lesson 2’s arithmetic with lesson 3’s fee. The comparison against holding is lesson 3’s whole argument. The mark price of lesson 9 is what an engine like lesson 10’s would read, and lesson 10’s gap is why the insurance fund exists at all. The locks are lesson 13’s, whose asymmetric deadlines are why the grid has no half-done row.
And the two ledgers are lesson 1’s, put on the bench before any of it, precisely so that the last thing the course does is the thing the first lesson could not.
Check yourself
1. Why is the pool measured against holding rather than reported as a yield?
Because a return that is not compared with the alternative is not a return. The pool’s value rises on a rising path while still leaving its provider behind somebody who did nothing, and only the comparison shows that.
2. Why must the crash gap rather than decline smoothly?
Because an engine that only meets continuous prices always closes positions while their margin still covers the loss, so the insurance fund is never tested. The gap creates the case the fund exists for, which is the case worth testing.
3. Where does the grid transition from neither to both, and why there?
At the moment the secret becomes public, which happens when the bonds are claimed. Before that no party can complete either leg; after it, the seller can complete the other leg unilaterally. The guarantee is that no step leaves the outcome undetermined.
4. What does a green property test here establish, and what does it not?
That the five enumerated failure modes end both or neither. It does not establish safety in general: a party revealing and going offline, a ledger reordering transactions, or badly set relative deadlines are all real failures outside the grid. The evidence supports the smaller claim.
Do this
Run the module as one system.
python3 code/trade_and_settle.py
The starter provides all three artefacts and leaves you the recovery step in the settlement: once the secret is public the seller claims the cash regardless of the buyer, and anything still locked at its deadline refunds. The assertions check that fees pay for the round trip and not the trend, that the fund is exhausted exactly once, and that all five injection points end both or neither.
The completed version is in solutions/trade_and_settle.py.
What you can now do. You can run a pool, a liquidation engine and a cross-ledger settlement as one system, and prove with a property test that no failure point in the enumerated set leaves a half-done trade. That is the end of the course: you have built the legacy machine, the token machine, and the bridge between them that settles rather than copies, and you have measured honestly what each one changed.