Skip to content

Commit 97d1d86

Browse files
committed
initial setup
0 parents  commit 97d1d86

24 files changed

+5920
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
dist
3+
node_modules
4+
_lib
5+
tsconfig.tsbuildinfo
6+
tsconfig.*.tsbuildinfo
7+
vocs.config.ts.timestamp-*
8+
.vercel
9+
.vocs

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a [Vocs](https://vocs.dev) project bootstrapped with the Vocs CLI.

docs/pages/config/configurations.mdx

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Stackr Testnet [Information regarding Stackr testnet tools]
2+
3+
## Vulcan
4+
5+
The vulcan committee is the verification layer that sits in between apps and the chain.
6+
Micro-rollups can connect to the vulcan layer with this endpoint
7+
8+
- RPC URL: `http://vulcan.stf.xyz`
9+
10+
(open it in a browser, you are in for a treat)
11+
12+
## Ethereum Base Chain
13+
14+
The Stackr testnet is based on a private EVM node. This means that you can use any Ethereum tools to deploy on the testnet. The configuration is as follows:
15+
16+
- RPC URL: `http://rpc.stf.xyz`
17+
- Chain ID: `42069`
18+
- Explorer: `http://rpc.stf.xyz:3000`
19+
- token: ETH
20+
- Faucet: `http://rpc.stf.xyz:4000`
21+
22+
(yeah the explorer URL is funny .\_. please bear with us)
23+
24+
## Faucet
25+
26+
Request the Stackr team to provide you with testnet tokens on the hackerhouse channel on Discord.
+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
---
2+
title: "Almost Micro-Rollup"
3+
description: "Packaging state machines inside the rollup and other things"
4+
---
5+
6+
### State Machines
7+
8+
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,
9+
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.
10+
11+
Stackr-JS provides a simple state machine implementation that takes in the Rollup state and STF
12+
13+
<Warning>All of this should go outside the `state.ts` file</Warning>
14+
15+
**example**
16+
17+
```ts
18+
import { StateMachine } from "@stackr/stackr-js/execution";
19+
import * as genesisState from "../genesis-state.json";
20+
21+
const counterFsm = new StateMachine({
22+
state: new CounterRollup(genesisState.state),
23+
stf: counterSTF,
24+
});
25+
```
26+
27+
### Genesis State
28+
29+
The genesis state is the initial state of the state machine.
30+
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.
31+
32+
You need to set the genesis state inside `genesis-state.json` file.
33+
34+
The format is
35+
36+
`{ "state" : WHATEVER_YOU_WANT_AS_JSON }`
37+
38+
example
39+
40+
<CodeGroup>
41+
```json counter
42+
{ "state": 0 }
43+
```
44+
45+
```json amm
46+
{
47+
"state": [
48+
{
49+
"owner": "Alice",
50+
"quantityA": 10,
51+
"quantityB": 0
52+
},
53+
{
54+
"owner": "Bob",
55+
"quantityA": 20,
56+
"quantityB": 10
57+
},
58+
{
59+
"owner": "Charlie",
60+
"quantityA": 200,
61+
"quantityB": 0
62+
}
63+
]
64+
}
65+
```
66+
67+
```json chess
68+
{ "state": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" }
69+
```
70+
71+
</CodeGroup>
72+
73+
### Input type schema
74+
75+
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.
76+
77+
<Info>
78+
This is what the user/ another entity send to the **app** or **rollup**. This
79+
is NOT what is applied to the State transition function.
80+
</Info>
81+
82+
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
83+
84+
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
85+
86+
Example, for a chess game you can define something like
87+
88+
```ts
89+
const actionSchemaType = {
90+
move: "String",
91+
};
92+
```
93+
94+
Or for a counter you can define something like
95+
96+
```ts
97+
const actionSchemaType = {
98+
type: "String",
99+
};
100+
```
101+
102+
or for a AMM you can define something like
103+
104+
```ts
105+
const actionSchemaType = {
106+
type: "String",
107+
owner: "String",
108+
quantityA: "Number",
109+
quantityB: "Number",
110+
};
111+
```
112+
113+
#### Notice the types
114+
115+
<Warning>
116+
These are not TypeScript interfaces, these are actual Objects hence the way
117+
the type is passed on is inside quotes.
118+
</Warning>
119+
120+
#### Supported user input types
121+
122+
These are same as solidity types
123+
124+
```ts internal stackr-js
125+
export type PrimitiveType = "String" | "Uint" | "Bool" | "Address" | "Bytes";
126+
export type SchemaType =
127+
| PrimitiveType
128+
| { [key: string]: SchemaType }
129+
| SchemaType[];
130+
```
131+
132+
So you can define both simple and complex input schema
133+
134+
<CodeGroup>
135+
```ts simple
136+
const actionSchemaType = {
137+
type: "String",
138+
owner: "String",
139+
quantityA: "Number",
140+
quantityB: "Number",
141+
};
142+
```
143+
144+
```ts nested
145+
const actionSchemaType = {
146+
type: "String",
147+
owner: "String",
148+
quantityA: "Number",
149+
quantityB: "Number",
150+
nested: {
151+
type: "String",
152+
owner: "String",
153+
quantityA: "Number",
154+
quantityB: "Number",
155+
},
156+
array: [
157+
{
158+
type: "String",
159+
owner: "String",
160+
quantityA: "Number",
161+
quantityB: "Number",
162+
},
163+
],
164+
};
165+
```
166+
167+
</CodeGroup>
168+
169+
<Info>
170+
Stackr Converts these to EIP-712 typed data fields and expects user signatures
171+
on it
172+
</Info>
173+
174+
You can now generate an `ActionSchema` from this
175+
176+
```ts
177+
import { ActionSchema } from "@stackr/stackr-js";
178+
179+
const userInputSchema = new ActionSchema("update-move", actionSchemaType);
180+
```
181+
182+
This `userInputSchema` can be used to create instances of user Actions
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: "Before You Begin"
3+
description: "some VERY important things to keep in mind"
4+
---
5+
6+
### `state.ts` file is important
7+
8+
Stackr-CLI has a basic parser that looks for `state.ts` file in the root directory to extract the STF logic.
9+
If you don't have this file, you will get an error.
10+
11+
However, you are free to add remove any other files in the root directory.
12+
13+
### `genesis-state.json` file is important
14+
15+
Stackr-CLI looks for `genesis-state.ts` file in the root directory to extract the genesis state and register with the Vulcan Layer.
16+
17+
### `deployment.json` file is important
18+
19+
This file is used to get the appId and rollup's inbox address. This is automatically generated after you register the rollup using CLI.
20+
21+
### Please use top level imports
22+
23+
For libraries like `ethers-js` there are some default ways of importing functions.
24+
However you should use it from the top level and call it from there
25+
26+
example
27+
28+
Do this 👇
29+
30+
```ts
31+
import { AbiCoder } from "ethers";
32+
33+
const encoder = AbiCoder.defaultAbiCoder();
34+
encoder.encode(stuff);
35+
```
36+
37+
Do not do this ❌
38+
39+
```ts
40+
import { ethers } from "ethers";
41+
42+
const encoder = ethers.AbiCoder.defaultAbiCoder();
43+
encoder.encode(stuff);
44+
```
45+
46+
Ideally the Stackr-CLI parses the file and makes this conversion, but it's not that smart yet for complicated setups.
47+
48+
### Do NOT do network calls in the STF
49+
50+
The STF is meant to be a pure function that takes in some input and returns some output.
51+
It should not do any network calls or any other side effects.
52+
53+
In case you want to do network calls, you can do it before creating an action, and pass the result to the STF in the `submitAction` step.
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: "Sequencer"
3+
description: "Ordering is important"
4+
---
5+
6+
Stackr allows applications to perform their own ordering of the actions inside the block
7+
It comes with a basic sequencer which can be extended to perform more complex ordering.
8+
9+
### Strategies
10+
11+
The basic sequencing strategy bundled with the SDK is the FIFO strategy. It does nothing tbh.
12+
13+
```ts
14+
import { FIFOStrategy } from "@stackr/stackr-js";
15+
16+
const buildStrategy = new FIFOStrategy();
17+
```
18+
19+
### Custom strategies
20+
21+
You can create your own strategy by extending the `BaseStrategy` and overriding the `orderTxLogic` class and pass it on to the rollup.
22+
23+
Example:
24+
25+
```ts
26+
import { BaseStrategy } from "@stackr/stackr-js";
27+
28+
export class Randomize extends BaseStrategy {
29+
constructor() {
30+
super("RandomOrder");
31+
}
32+
33+
async orderTxLogic(
34+
actions: Action<AllowedInputTypes>[]
35+
): Promise<Action<AllowedInputTypes>[]> {
36+
console.log("Random");
37+
38+
return Promise.resolve(
39+
actions.sort(() => {
40+
return 0.5 - Math.random();
41+
})
42+
);
43+
}
44+
}
45+
```
46+
47+
Not sure why but you can randomize the order of the actions inside the block like this 🤷🏻‍♂️

0 commit comments

Comments
 (0)