-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ChanX21/feature/stackrInit
Envio Stackr -> Main Merge
- Loading branch information
Showing
45 changed files
with
12,843 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# To create or update a token visit https://envio.dev/app/api-tokens | ||
ENVIO_API_TOKEN="<YOUR-API-TOKEN>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
*.exe | ||
*.obj | ||
*.out | ||
*.compile | ||
*.native | ||
*.byte | ||
*.cmo | ||
*.annot | ||
*.cmi | ||
*.cmx | ||
*.cmt | ||
*.cmti | ||
*.cma | ||
*.a | ||
*.cmxa | ||
*.obj | ||
*~ | ||
*.annot | ||
*.cmj | ||
*.bak | ||
lib/* | ||
*.mlast | ||
*.mliast | ||
.vscode | ||
.merlin | ||
.bsb.lock | ||
/node_modules/ | ||
benchmarks/ | ||
artifacts | ||
cache | ||
generated | ||
logs | ||
*.bs.js | ||
*.bs.mjs | ||
*.gen.ts | ||
build | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Needed for ts build folder to have | ||
# access to rescript node_modules | ||
shamefully-hoist=true | ||
# Needed so users can run `pnpm install` in the root of the repo without requiring the `-w` flag. | ||
ignore-workspace-root-check=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## Envio Blank Template | ||
|
||
*Please refer to the [documentation website](https://docs.envio.dev) for a thorough guide on all Envio indexer features* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# yaml-language-server: $schema=./node_modules/envio/evm.schema.json | ||
name: ninjai | ||
networks: | ||
- id: 11155111 | ||
start_block: 0 | ||
contracts: | ||
- name: Escrow | ||
address: | ||
- 0x6B0D6D6FdAe18cD3bDC6aE2EEa711350F54e0B48 | ||
handler: src/EventHandlers.ts | ||
events: | ||
- event: Deposited(address indexed user, uint256 amount, uint8 escrowType, uint256 escrowId) | ||
- event: MinEthRequiredUpdated(uint256 oldMinEthRequired, uint256 newMinEthRequired) | ||
- event: OwnershipTransferred(address indexed previousOwner, address indexed newOwner) | ||
- event: Released(address indexed winner, uint256 amount, uint256 escrowId) | ||
rollback_on_reorg: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "ninjai", | ||
"version": "0.1.0", | ||
"scripts": { | ||
"clean": "tsc --clean", | ||
"build": "tsc --build", | ||
"watch": "tsc --watch", | ||
"mocha": "ts-mocha test/**/*.ts", | ||
"codegen": "envio codegen", | ||
"dev": "envio dev", | ||
"test": "pnpm mocha", | ||
"start": "ts-node generated/src/Index.bs.js" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.3.11", | ||
"@types/mocha": "10.0.6", | ||
"@types/node": "20.8.8", | ||
"ts-mocha": "^10.0.0", | ||
"ts-node": "10.9.1", | ||
"typescript": "5.2.2", | ||
"chai": "4.3.10", | ||
"mocha": "10.2.0" | ||
}, | ||
"dependencies": { | ||
"envio": "2.2.0" | ||
}, | ||
"optionalDependencies": { | ||
"generated": "./generated" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
packages: | ||
- ./* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
type Escrow_Deposited { | ||
id: ID! | ||
user: String! | ||
amount: BigInt! | ||
escrowType: BigInt! | ||
escrowId: BigInt! | ||
} | ||
|
||
type Escrow_MinEthRequiredUpdated { | ||
id: ID! | ||
oldMinEthRequired: BigInt! | ||
newMinEthRequired: BigInt! | ||
} | ||
|
||
type Escrow_OwnershipTransferred { | ||
id: ID! | ||
previousOwner: String! | ||
newOwner: String! | ||
} | ||
|
||
type Escrow_Released { | ||
id: ID! | ||
winner: String! | ||
amount: BigInt! | ||
escrowId: BigInt! | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Please refer to https://docs.envio.dev for a thorough guide on all Envio indexer features | ||
*/ | ||
import { | ||
Escrow, | ||
Escrow_Deposited, | ||
Escrow_MinEthRequiredUpdated, | ||
Escrow_OwnershipTransferred, | ||
Escrow_Released, | ||
} from "generated"; | ||
|
||
Escrow.Deposited.handler(async ({ event, context }) => { | ||
const entity: Escrow_Deposited = { | ||
id: `${event.chainId}_${event.block.number}_${event.logIndex}`, | ||
user: event.params.user, | ||
amount: event.params.amount, | ||
escrowType: event.params.escrowType, | ||
escrowId: event.params.escrowId, | ||
}; | ||
|
||
context.Escrow_Deposited.set(entity); | ||
}); | ||
|
||
|
||
Escrow.MinEthRequiredUpdated.handler(async ({ event, context }) => { | ||
const entity: Escrow_MinEthRequiredUpdated = { | ||
id: `${event.chainId}_${event.block.number}_${event.logIndex}`, | ||
oldMinEthRequired: event.params.oldMinEthRequired, | ||
newMinEthRequired: event.params.newMinEthRequired, | ||
}; | ||
|
||
context.Escrow_MinEthRequiredUpdated.set(entity); | ||
}); | ||
|
||
|
||
Escrow.OwnershipTransferred.handler(async ({ event, context }) => { | ||
const entity: Escrow_OwnershipTransferred = { | ||
id: `${event.chainId}_${event.block.number}_${event.logIndex}`, | ||
previousOwner: event.params.previousOwner, | ||
newOwner: event.params.newOwner, | ||
}; | ||
|
||
context.Escrow_OwnershipTransferred.set(entity); | ||
}); | ||
|
||
|
||
Escrow.Released.handler(async ({ event, context }) => { | ||
const entity: Escrow_Released = { | ||
id: `${event.chainId}_${event.block.number}_${event.logIndex}`, | ||
winner: event.params.winner, | ||
amount: event.params.amount, | ||
escrowId: event.params.escrowId, | ||
}; | ||
|
||
context.Escrow_Released.set(entity); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import assert from "assert"; | ||
import { | ||
TestHelpers, | ||
Escrow_Deposited | ||
} from "generated"; | ||
const { MockDb, Escrow } = TestHelpers; | ||
|
||
describe("Escrow contract Deposited event tests", () => { | ||
// Create mock db | ||
const mockDb = MockDb.createMockDb(); | ||
|
||
// Creating mock for Escrow contract Deposited event | ||
const event = Escrow.Deposited.createMockEvent({/* It mocks event fields with default values. You can overwrite them if you need */}); | ||
|
||
it("Escrow_Deposited is created correctly", async () => { | ||
// Processing the event | ||
const mockDbUpdated = await Escrow.Deposited.processEvent({ | ||
event, | ||
mockDb, | ||
}); | ||
|
||
// Getting the actual entity from the mock database | ||
let actualEscrowDeposited = mockDbUpdated.entities.Escrow_Deposited.get( | ||
`${event.chainId}_${event.block.number}_${event.logIndex}` | ||
); | ||
|
||
// Creating the expected entity | ||
const expectedEscrowDeposited: Escrow_Deposited = { | ||
id: `${event.chainId}_${event.block.number}_${event.logIndex}`, | ||
user: event.params.user, | ||
amount: event.params.amount, | ||
escrowType: event.params.escrowType, | ||
escrowId: event.params.escrowId, | ||
}; | ||
// Asserting that the entity in the mock database is the same as the expected entity | ||
assert.deepEqual(actualEscrowDeposited, expectedEscrowDeposited, "Actual EscrowDeposited should be the same as the expectedEscrowDeposited"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2020", //required for use with BigInt types | ||
"lib": [ | ||
"es2020" | ||
], | ||
"allowJs": true, | ||
"checkJs": false, | ||
"outDir": "build", | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"esModuleInterop": true, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"module": "CommonJS" | ||
}, | ||
"include": [ | ||
"src", | ||
"test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
PRIVATE_KEY= | ||
VULCAN_RPC= | ||
L1_RPC= | ||
REGISTRY_CONTRACT= | ||
NODE_ENV=development | ||
DATABASE_URI=./db.sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.sqlite | ||
node_modules/ | ||
build/ | ||
bun.lockb | ||
stackr_build/ | ||
.env | ||
dist/ | ||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM node:lts-bookworm-slim | ||
|
||
RUN npm install -g npm@latest | ||
|
||
# Install bun globally | ||
RUN npm install -g bun | ||
|
||
WORKDIR /app | ||
|
||
# Copy package.json and tsconfig.json | ||
COPY package.json package.json | ||
COPY tsconfig.json tsconfig.json | ||
|
||
# Copy Stackr files | ||
COPY deployment.json deployment.json | ||
COPY genesis-state.json genesis-state.json | ||
COPY stackr.config.ts stackr.config.ts | ||
|
||
# Copy source code | ||
COPY src src | ||
|
||
# Install dependencies | ||
RUN npm install | ||
|
||
# Command to run the application | ||
CMD ["npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Ninja Strike | ||
|
||
Project initialized using [@stackr/sdk](https://www.stackrlabs.xyz/) | ||
|
||
## Project structure | ||
|
||
```bash | ||
. | ||
├── .env.example | ||
├── .gitignore | ||
├── Dockerfile | ||
├── genesis-state.json | ||
├── package-lock.json | ||
├── package.json | ||
├── src | ||
│ ├── index.ts ## -> starting point, everything gets imported here. | ||
│ ├── server.ts ## -> server setup if any in the example. | ||
│ ├── cli.ts ## -> CLI interaction setup if any in the example. | ||
│ ├── contract ## -> place to keep your utility Contracts like Hook and Bridge | ||
│ │ └──Contract.sol | ||
│ ├── stackr | ||
│ ├── machine.ts ## -> preferred place to keep your State Machine(s) and export from | ||
│ ├── mru.ts ## -> place to initialize your MicroRollup | ||
│ ├── schemas.ts ## -> one place to create and export all schemas from | ||
│ ├── state.ts ## -> file to define your State class, can be omitted if state is trivial. | ||
│ └── transitions.ts ## -> one place to store all your transitions & hooks _(hooks can have seaprate hooks.ts file too.)_ | ||
├── stackr.config.ts | ||
├── tests | ||
│ └── some.test.ts | ||
└── tsconfig.json | ||
``` | ||
|
||
Note: Some files are specific to certain examples, as mentioned in the tree above. | ||
|
||
## How to run? | ||
|
||
### Run using Node.js :rocket: | ||
|
||
```bash | ||
npm start | ||
``` | ||
|
||
### Run using Docker :whale: | ||
|
||
- Build the image using the following command: | ||
|
||
```bash | ||
# For Linux | ||
docker build -t count:latest . | ||
|
||
# For Mac with Apple Silicon chips | ||
docker buildx build --platform linux/amd64,linux/arm64 -t count:latest . | ||
``` | ||
|
||
- Run the Docker container using the following command: | ||
|
||
```bash | ||
# If using SQLite as the datastore | ||
docker run --env-file .env -v ./db.sqlite:/app/db.sqlite -p <HOST_PORT>:<CONTAINER_PORT> --name=count -it count:latest | ||
|
||
# If using other URI based datastores | ||
docker run --env-file .env -p <HOST_PORT>:<CONTAINER_PORT> --name=count -it count:latest | ||
``` | ||
|
||
## Playground Plugin | ||
|
||
To leverage examples and test the SDK, you can use Stackr's Playground hosted at: [https://playground.stackrlabs.xyz](https://playground.stackrlabs.xyz). | ||
|
||
In you application, add Playground by importing the following: | ||
|
||
```ts | ||
import { Playground } from "@stackr/sdk/plugins"; | ||
|
||
const rollup = ... | ||
await rollup.init(); | ||
|
||
Playground.init(rollup); | ||
// this will start a server at http://localhost:42069, which is taken as input by the Playground | ||
``` | ||
|
||
Full instructions can be found at [here](https://docs.stf.xyz/build/plugins/playground) | ||
|
||
## Vulcan Explorer | ||
|
||
To explore your submitted blocks and batches, you can use the Vulcan Explorer hosted at: [https://explorer.vulcan.stf.xyz/](https://explorer.vulcan.stf.xyz/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"appId": 94, | ||
"appInbox": "0x632090EC4E84fB4D367a51cEc6CFa885f1c265BC", | ||
"chainId": 11155111 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"state": { | ||
"games": [] | ||
} | ||
} | ||
|
Oops, something went wrong.