Contracts overview
The contracts repository contains eight contracts: two account components and six note scripts.
| Contract | Kind | Purpose |
|---|---|---|
port0 | account component | Pool: reserves accounting, LP supply, fee rates, protocol pot, price oracle |
pool-registry | account component | Accepted pool code commitments, pool set, asset pair index, protocol fee policy |
mint-note | note script | Add liquidity |
burn-note | note script | Remove liquidity |
swap-note | note script | Trade |
collect-note | note script | Move a pool’s accrued protocol fees to the protocol account |
register-note | note script | Register a pool in the registry |
registry-collect-note | note script | Move the registry’s accumulated register fees to the protocol account |
The repository layout:
contracts/
port0/ pool account component
pool-registry/ registry account component
mint-note/ add-liquidity note script
burn-note/ remove-liquidity note script
swap-note/ swap note script
collect-note/ pool protocol-fee collection note script
register-note/ pool registration note script
registry-collect-note/ registry fee collection note script
integration/ MockChain integration tests and deployment binaries
Pool lifecycle
- Build the pool account. Its initial storage holds the token0 and token1 asset keys, the two fee parameters, the P2ID root, and the registry pointer. The LP token key is derived from the pool’s account id and is not stored.
- Fund the pool with a note and consume that note as the pool’s first transaction. A network account requires every transaction to have an effect, so an empty scriptless deploy is rejected. The funding note commits the account and pays its first transaction fee from the received funds.
- Emit the register note. The registry verifies the pool’s code commitment and identity by foreign procedure invocation, then records the pool and its asset pair.
- Liquidity providers emit mint notes and burn notes. Traders emit swap notes.
- The fee recipient emits collect notes against a pool, or registry-collect notes against the registry. Both are permissionless.
Execution model
Notes invoke pool procedures through the component interface. Pool procedures run in account context and may create output notes and move assets. Note scripts run in note context and may not perform those actions directly.
A pool’s fee parameters, P2ID root, registry pointer, and token keys are initial storage and hold for the pool’s lifetime. No pool parameter is settable after creation.
Asset model
The LP token is a fungible asset issued by the pool account. No separate faucet
account exists. The asset key is derived from the pool’s account id as
[0, 0, suffix | 0x11, prefix], because the key embeds the account id and the
account id is derived from the initial storage commitment, so seeding it would
be circular.
Build and test
Each contract is a standalone crate built with cargo-miden:
cargo miden build --manifest-path contracts/port0/Cargo.toml --release
The integration tests run against MockChain, an in-process chain that compiles the contracts and executes the note flows without a network:
cargo test -p integration --release
The SDK’s artifact exporter builds the packages itself. A manual build is needed only to seed a fresh checkout.