|
| 1 | +## Architecture Diagram |
| 2 | +The TTC architecture consists of 2 hosted services (`Monitor` and `Prover`) and a shared Postgres database: |
| 3 | + |
| 4 | +<p align="center"> |
| 5 | + <img src="./architecture.drawio.png" width="500" title="hover text"> |
| 6 | +</p> |
| 7 | + |
| 8 | +The `Monitor` exposes a public facing JSON-RPC api with a [few methods](./monitor/api/src/rpc.rs). The `Monitor` has |
| 9 | +access to the `Prover` service, but the `Prover` service exposes no public api. |
| 10 | + |
| 11 | +The `Monitor` runs on an extremely basic VM, the `Prover` runs on a GPU enabled VM |
| 12 | +(currently using an [L4](https://www.nvidia.com/en-us/data-center/l4/) instance on GCP) |
| 13 | + |
| 14 | + |
| 15 | +## Deployment Flow. |
| 16 | + |
| 17 | +The `Operator` deploys the contracts and submits the address to the `Monitor` service. This spawns an event monitor loop looking for |
| 18 | +contract updates in the `TTC` contract. The loop will run until the termination criteria is realized, either |
| 19 | + - The contract is ready for proof generation |
| 20 | + - The proof request has timed out (after 250 blocks) |
| 21 | + |
| 22 | +<p align="center"> |
| 23 | + <img src="./flow1.drawio.png" width="500" title="hover text"> |
| 24 | +</p> |
| 25 | + |
| 26 | +## User Input Flow |
| 27 | + |
| 28 | +The contract is initialized in the `Deposit` phase. The duration of the phase is configurable at contract deployment. During this time |
| 29 | +`User`s may deposit ERC-721 tokens into the contract. |
| 30 | + |
| 31 | +After the `Deposit` phase is completed, the `Operator` (or any other actor) can transition the contract to the `Rank` Phase. |
| 32 | +At this time the deposits are locked and the users can submit their trading preferences. The duration of this phase is configured |
| 33 | +at deployment. |
| 34 | + |
| 35 | +After the `Rank` phase is completed, the contract is transitioned into the `Trade` phase. The preferences are locked and the contract |
| 36 | +emits an event for the `Monitor` service to act on. |
| 37 | + |
| 38 | +<p align="center"> |
| 39 | + <img src="./flow2.drawio.png" width="500" title="hover text"> |
| 40 | +</p> |
| 41 | + |
| 42 | +## Prove and Trade Flow |
| 43 | + |
| 44 | +The `Monitor` will write a job to the database indicating that there is proof work to do. It then sends a request to the prover to |
| 45 | +wake up and do the proving work. |
| 46 | + |
| 47 | +When the prover completes, it updates the job status and writes the proof to the database. This modification triggers a Postrges |
| 48 | +listen/notify channel, which alerts the monitor and anyone else listening for this status update (i.e. e.g. `Operator`). |
| 49 | + |
| 50 | +The `Operator` can then post the trades with proof to the chain, which will enact the trades within the contract and progress the phase |
| 51 | +to `Withdraw`. If no proof is posted within a 250 block window, anyone can manually update the phase to `Withdraw`. |
| 52 | + |
| 53 | +<p align="center"> |
| 54 | + <img src="./flow3.drawio.png" width="500" title="hover text"> |
| 55 | +</p> |
| 56 | + |
| 57 | +## Withdraw and Exit Flow |
| 58 | + |
| 59 | +The `User`s can now withdraw their tokens, which are reflected by the trade results. |
| 60 | + |
| 61 | +After all the tokens are withdrawn, the contract enters a `Cleanup` phase. At this point the `Operator` can collect |
| 62 | +any fees earnd by the contract. |
| 63 | + |
| 64 | +<p align="center"> |
| 65 | + <img src="./flow4.drawio.png" width="500" title="hover text"> |
| 66 | +</p> |
0 commit comments