Midas state

This should definitely be in main by now. It includes a fully functional state machine as per documentation. Still has room for improvement, but it's now stable and meets initial specification.