Exercise 1 · Safe Swap
Build a peer-to-peer swap contract that lets one user exchange Token A for Token B safely.Requirements
- Safety — it must be impossible for one party to receive the other’s tokens while their own tokens are not transferred.
- Cancelable — before finalization, either party can cancel the swap without compromising safety.
- GEN standards:
- Roles implemented through components
- Asynchronous calls handled correctly
Deliverables
- Design — diagram of the architecture you plan to implement, with short text explanations.
- Implementation — the contract plus a test scenario that demonstrates the swap works inside the GEN framework.
Reference solution. Whether you finished or threw in the towel, ask your
Gen Labs contact for access to the worked example at
github.com/gen-bc/safe-swap-example.
The repo is private; your contact will add you.
Exercise 2 · CLOB (Central Limit Order Book)
Extend Exercise 1 by building a CLOB on top of your Safe Swap mechanism.Requirements
- Maintain a single order book for one token pair.
- Orders matched first-come, first-served.
- Match purely on token amounts, not price per token.
- No partial matching — unmatched orders stay in the book.
- Same safety, cancelability, and GEN-standards requirements as Exercise 1.
Deliverables
- Design — diagram + short explanations.
- Implementation — contract + test scenario demonstrating correct CLOB behavior.
Going the extra mile
Three appendix tracks that go beyond the two main exercises. Each is self-contained and can be tackled in any order.Going Meta with Metadata
Setting and enforcing rules for component installation — using root
metadata to cap installs, gate roles, and enforce contract-wide invariants.
The Client is Always Right
Using bare
GvmComponentId addresses instead of typed self_refs /
contract refs — the generic path for advanced use cases.Composable Errors
A deeper take on error handling across activations — conditioning a
follow-up call on the success of a prior one, with both
.await and
.spawn() patterns.
