Skip to content

Commit

Permalink
Merge pull request #10 from initia-labs/feat/sdk
Browse files Browse the repository at this point in the history
feat: OPinit bot
  • Loading branch information
JSHan94 authored Jan 23, 2024
2 parents 148246e + 417b5b1 commit 8b6137e
Show file tree
Hide file tree
Showing 103 changed files with 9,162 additions and 7,757 deletions.
5 changes: 0 additions & 5 deletions bots/.env

This file was deleted.

37 changes: 37 additions & 0 deletions bots/.env_sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# common setting
TYPEORM_CONNECTION=postgres
TYPEORM_HOST=localhost
TYPEORM_USERNAME=username
TYPEORM_PASSWORD=password
TYPEORM_DATABASE=rollup
TYPEORM_PORT=5432
TYPEORM_SYNCHRONIZE=true
TYPEORM_LOGGING=false
TYPEORM_ENTITIES=src/orm/*Entity.ts
USE_LOG_FILE=false

L1_CHAIN_ID=local-initia
L2_CHAIN_ID=local-minitia
L1_LCD_URI=http://localhost:1317
L1_RPC_URI=http://localhost:26657
L2_LCD_URI=http://localhost:1318
L2_RPC_URI=http://localhost:26667
BRIDGE_ID=1

# setting for slack (optional)
SLACK_WEB_HOOK=''

# setting for executor
EXECUTOR_MNEMONIC=''
EXECUTOR_PORT=5000

# setting for batch
BATCH_SUBMITTER_MNEMONIC=''
BATCH_PORT=5001

# setting for output
OUTPUT_SUBMITTER_MNEMONIC=''

# setting for challenger
CHALLENGER_MNEMONIC=''

33 changes: 0 additions & 33 deletions bots/.envrc_sample

This file was deleted.

6 changes: 5 additions & 1 deletion bots/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ apidoc/
static/

.envrc
.env
.env.*

build
logs/
testing/

temp*
temp*
test/
3 changes: 0 additions & 3 deletions bots/.gitmodules

This file was deleted.

22 changes: 0 additions & 22 deletions bots/Dockerfile

This file was deleted.

185 changes: 96 additions & 89 deletions bots/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Initia Rollup JS
# OPinit Bots

Initia Optimistic Rollup Bots.

Expand All @@ -9,116 +9,123 @@ Initia Optimistic Rollup Bots.

## How to use

## Setup L2
## Create Bridge

Initializes the L2 id and op-bridge/output contracts.
You should set `submissionInterval`, `finalizedTime` and `l2StartBlockHeight` before initializing.
Before running rollup bots, you should create bridge between L1 and L2. If you use `initia.js`, you can create bridge using `MsgCreateBridge` message as follows.

```bash
export SUB_INTV=10
export FIN_TIME=10
export L2_HEIGHT=1
npm run l2setup
```typescript
import { MsgCreateBridge, BridgeConfig, Duration } from '@initia/initia.js';

const bridgeConfig = new BridgeConfig(
challenger.key.accAddress,
outputSubmitter.key.accAddress,
Duration.fromString(submissionInterval.toString()),
Duration.fromString(finalizedTime.toString()),
new Date(),
this.metadata
);
const msg = new MsgCreateBridge(executor.key.accAddress, bridgeConfig);
```

## Bridge Executor
## Configuration

Bridge executor is a bot that monitor L1, L2 node and execute bridge transaction. It will execute following steps.
- `.env.executor`
| Name | Description | Default |
| ------------------------- | ------------------------------------------------------ | -------------------------------- |
| L1_LCD_URI | L1 node LCD URI | <http://127.0.0.1:1317> |
| L1_RPC_URI | L1 node RPC URI | <http://127.0.0.1:26657> |
| L2_LCD_URI | L2 node LCD URI | <http://127.0.0.1:1317> |
| L2_RPC_URI | L2 node RPC URI | <http://127.0.0.1:26657> |
| BRIDGE_ID | Bridge ID | '' |
| EXECUTOR_PORT | Executor port | 5000 |
| EXECUTOR_MNEMONIC | Mnemonic seed for executor | '' |
| SLACK_WEB_HOOK | Slack web hook for notification (optional) | '' |

1. Publish L2 ID to L1
- L2 ID should be published under executor account
2. Initialize bridge contract on L1 with L2 ID
- Execute `initialize<L2ID>` entry function in `bridge.move`
3. Run executor bot
- Execute L1, L2 monitor in bridge executor
- `.env.output`
| Name | Description | Default |
| ------------------------- | ------------------------------------------------------ | -------------------------------- |
| L1_LCD_URI | L1 node LCD URI | <http://127.0.0.1:1317> |
| L1_RPC_URI | L1 node RPC URI | <http://127.0.0.1:26657> |
| BRIDGE_ID | Bridge ID | '' |
| OUTPUT_SUBMITTER_MNEMONIC | Mnemonic seed for output submitter | '' |
| SLACK_WEB_HOOK | Slack web hook for notification (optional) | '' |

```bash
npm run executor
```
- `.env.batch`
| Name | Description | Default |
| ------------------------- | ------------------------------------------------------ | -------------------------------- |
| L1_LCD_URI | L1 node LCD URI | <http://127.0.0.1:1317> |
| L1_RPC_URI | L1 node RPC URI | <http://127.0.0.1:26657> |
| L2_LCD_URI | L2 node LCD URI | <http://127.0.0.1:1317> |
| L2_RPC_URI | L2 node RPC URI | <http://127.0.0.1:26657> |
| BRIDGE_ID | Bridge ID | '' |
| BATCH_PORT | Batch submitter port | 5001 |
| BATCH_SUBMITTER_MNEMONIC | Mnemonic seed for submitter | '' |
| SLACK_WEB_HOOK | Slack web hook for notification (optional) | '' |

- If you use pm2, you can run executor with following command.
- `.env.challenger`
| Name | Description | Default |
| ------------------------- | ------------------------------------------------------ | -------------------------------- |
| L1_LCD_URI | L1 node LCD URI | <http://127.0.0.1:1317> |
| L1_RPC_URI | L1 node RPC URI | <http://127.0.0.1:26657> |
| L2_LCD_URI | L2 node LCD URI | <http://127.0.0.1:1317> |
| L2_RPC_URI | L2 node RPC URI | <http://127.0.0.1:26657> |
| BRIDGE_ID | Bridge ID | '' |
| CHALLENGER_MNEMONIC | Mnemonic seed for challenger | '' |
| DELETE_OUTPUT_PROPOSAL | Enable delete output proposal instantly | '' |
| SLACK_WEB_HOOK | Slack web hook for notification (optional) | '' |

```bash
pm2 start executor.json
```
> In OPinit bots, we use [.dotenv](https://www.npmjs.com/package/dotenv) for managing environment variable for development. If you want to set `.env` by worker, you should name it as `.env.{WORKER_NAME}` and set `WORKER_NAME` in [`executor`, `output`, `batch`, `challenger`].
For example, if you want to set `.env` for `executor`, you should name it as `.env.executor` and set `WORKER_NAME=executor` in local environment.

4. Register coin to bridge store and prepare deposit store
- Execute `register_token<L2ID, CoinType>`
5. Now you can deposit after registering coin is done
## Bridge Executor

## Batch Submitter
Bridge executor is a bot that monitor L1, L2 node and execute bridge transaction. It will execute following steps.

Batch submitter is a background process that submits transaction batches to the BatchInbox module of L1.
You can run with following command.
1. Set bridge executor mnemonic on `.env`.
```bash
export EXECUTOR_MNEMONIC="..."
```
2. Run executor bot
```bash
npm run executor
```

```bash
npm run batch
```
## Batch Submitter

If you use pm2,
Batch submitter is a background process that submits transaction batches to the BatchInbox module of L1.

```bash
pm2 start batch.json
```
1. Set batch submitter mnemonic on `.env`.
```bash
export BATCH_SUBMITTER_MNEMONIC="..."
```
2. Run batch submitter bot
```bash
npm run batch
```

## Output Submitter

Output submitter is the component to store the L2 output root for block finalization.
Output submitter will get the L2 output results from executor and submit it to L1 using `propose_l2_output<L2ID>` in `output.move`.
Output submitter will get the L2 output results from executor and submit it to L1.

```bash
npm run output
```

If you use pm2,

```bash
pm2 start output.json
```
1. Set output submitter mnemonic on `.env`.
```bash
export OUTPUT_SUBMITTER_MNEMONIC="..."
```
2. Run output submitter bot
```bash
npm run output
```

## Challenger

Challenger is an entity capable of deleting invalid output proposals from the output oracle.

```bash
npm run challenger
```

If you use pm2,

```bash
pm2 start challenger.json
```

## Configuration

| Name | Description | Default |
| ------------------------- | ------------------------------------------------------ | -------------------------------- |
| L1_LCD_URI | L1 node LCD URI | <https://stone-rest.initia.tech>' |
| L1_RPC_URI | L1 node RPC URI | <https://stone-rpc.initia.tech>' |
| L2_LCD_URI | L2 node LCD URI | <http://localhost:1317> |
| L2_RPC_URI | L2 node RPC URI | <http://localhost:26657> |
| L2ID | L2ID | '' |
| BATCH_PORT | Batch submitter port | 3000 |
| EXECUTOR_PORT | Executor port | 3001 |
| EXECUTOR_URI | Executor URI (for output submitter) | <http://localhost:3000> |
| EXECUTOR_MNEMONIC | Mnemonic seed for executor | '' |
| BATCH_SUBMITTER_MNEMONIC | Mnemonic seed for submitter | '' |
| OUTPUT_SUBMITTER_MNEMONIC | Mnemonic seed for output submitter | '' |
| CHALLENGER_MNEMONIC | Mnemonic seed for challenger | '' |

> In Batch Submitter, we use [direnv](https://direnv.net) for managing environment variable for development. See [sample of .envrc](.envrc_sample)

## Test

Docker and docker-compose are required to run integration test.

```bash
npm run test:integration
```

If you want to reset docker container, run following command.

```bash
./docker-compose-reset
```
1. Set challenger mnemonic on `.env`.
```bash
export CHALLENGER_MNEMONIC="..."
```
2. Run challenger bot
```bash
npm run challenger
```
11 changes: 0 additions & 11 deletions bots/batch.json

This file was deleted.

11 changes: 0 additions & 11 deletions bots/challenger.json

This file was deleted.

7 changes: 0 additions & 7 deletions bots/docker-compose-reset

This file was deleted.

Loading

0 comments on commit 8b6137e

Please sign in to comment.