# Potential order book designs on Miden There are three models we have discussed during our call. The models differ by the degree of self-custody and speed for the user. ## Orders as notes - fully non-custodial ![image](https://hackmd.io/_uploads/H1SIbUIykg.png) Fully non-custodial, as both the maker and taker execute and prove transactions locally. Takes ~2s each due to blocktime. Order price updates or cancellation can be ms. | Action | Time | Comment | | -------- | -------- | -------- | | Create order | 2s | On-chain | | Take order | 2s | On-chain (next block) | | Order price update* | <10 ms | Revealing parts of the note script | | Order canceling** | <10 ms | Non-revealing pre-image | '* One note can contain many order each with its own price. These prices can be revealed one after another in real time. '** Note consumption can require a secret that market maker holds - market makers need to be constantly online then. Cancellation means not sending out the secret anymore. A potential design can be found [here](https://github.com/0xPolygonMiden/examples/discussions/138). ## Orders as notes using ephemeral notes - semi-custodial Semi-custodial, since state gets committed every 2 seconds. The "in-flight' state of the order book (i.e., the last ~2 seconds of activity) is controlled by the operator. Ephemeral notes don't need to be on-chain. Operator proves on behalf of user. He knows the future state and users can act on trusted off-chain state. First note of a chain must still be on-chain. ![image](https://hackmd.io/_uploads/H1UKChPJyg.png) | Action | Time | Comment | | -------- | -------- | -------- | | Create order | 2s | On-chain | | Take order* | 500 ms | Off-chain | | Order price update | <10 ms | Off-chain | | Order canceling | <10 ms | Off-chain | '* Taking requires a transaction to be executed against taker account. Operator executes. Time depends on the machine and final design. ## Orders as balances in a Miden account Semi-custodial. Each Miden account can act as its own Validium or zkRollup. Assets are locked as balances in the account. A single state change in the order book account can update multiple balances, allowing many users to be served simultaneously. ![image](https://hackmd.io/_uploads/SJhBF8UJke.png) | Action | Time | Comment | | -------- | -------- | -------- | | Initial deposit | 2s | Blocktime | | Create order | 100 ms | Signature check | | Take order | 100 ms | Signature check | | Order price update | 100 ms | Signature check | | Order canceling | 100 ms | Signature check |