Almost Micro-Rollup
Packaging state machines inside the rollup and other things
State Machines
State machines are simple units that can be used to model the state of a system. They are composed of states, events, and transitions. A state machine can be in one state at a time, and can transition to another state when an event is triggered. The state machine can also have actions that are executed when a transition occurs.
Stackr-JS provides a simple state machine implementation that takes in the Rollup state and STF
state.ts
fileexample
Genesis State
The genesis state is the initial state of the state machine. It is the state that is used to initialize the state machine. It is also the state that is used to initialize the state of the rollup.
You need to set the genesis state inside genesis-state.json
file.
The format is
{ "state" : WHATEVER_YOU_WANT_AS_JSON }
example
Input type schema
The user-input type schema is the schema that is used to validate the user input. It is used to validate the user input before it is applied to the state machine.
This is what the user/ another entity send to the app or rollup. This is NOT what is applied to the State transition function.
You can define to get a custom input from the user using this schema -> optionally process it or add more items -> create an object for ActionInput for the state machine
To define a user input type schema, there are some special things to take care of since Stackr creates EIP-712 typed data field for the same
Example, for a chess game you can define something like
Or for a counter you can define something like
or for a AMM you can define something like
Notice the types
These are not TypeScript interfaces, these are actual Objects hence the way the type is passed on is inside quotes.
Supported user input types
These are same as solidity types
So you can define both simple and complex input schema
Stackr Converts these to EIP-712 typed data fields and expects user signatures on it
You can now generate an ActionSchema
from this
This userInputSchema
can be used to create instances of user Actions