> ## Documentation Index
> Fetch the complete documentation index at: https://docs.initia.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Executor

The OPinit Bot Executor is a critical component in maintaining the communication
and operational integrity between the Initia L1 and rollup blockchains. It
handles and automates key tasks related to the OPinit Bridge, which facilitates
cross-chain interactions and ensures that both blockchains remain synchronized
and secure.

The primary responsibilities of the Executor include:

1. **Executing Token Transfers:** Executing token transfers between Initia L1
   and a rollup
2. **Submitting Output Proposals:** Submitting output proposals to the Initia L1
3. **Transaction Batch DA Submission:** Submitting rollup transaction batches to
   the DA layer
4. **Relaying Oracle Update (Optional):** Relaying oracle price feed updates to
   the rollup

## Detailed Architecture

### Transfer Token from L1 to L2 (Deposit)

The token deposit process begins when a user submits a deposit transaction on
the Initia L1 chain. Once the transaction is confirmed, the Bridge Executor
retrieves the latest block data (including the deposit) from the L1 node. It
then submits a message to the rollup node to finalize the deposit. After the L2
node confirms the finalized deposit, it mints the corresponding opINIT tokens on
the specified rollup.

```mermaid theme={null}
sequenceDiagram
    participant User
    participant IL1 as Initia L1
    participant OPH as OPhost Module
    participant OPB as OPinit Bot
    participant OPC as OPchild Module
    participant R as Rollup

    User->>IL1: Initiate token deposit
    IL1->>OPH: Process deposit
    OPH->>OPB: Emit deposit event
    OPB->>OPB: Process deposit event
    OPB->>OPC: Relay deposit transaction
    OPC->>R: Finalize deposit
    R->>R: Mint tokens to user on L2
```

### Transfer Token from L2 to L1 (Withdrawal)

The token withdrawal process begins when a user submits a withdrawal transaction
on the rollup. Once the transaction is confirmed, the Bridge Executor retrieves
the latest block data (including the withdrawal) from the L2 node. It then
submits a message to the Initia L1 node to finalize the withdrawal. After the L1
node confirms the finalized withdrawal, it burns the corresponding opINIT tokens
on the specified rollup.

The withdrawal then enters a withdrawal period during which the transaction can
be challenged and potentially canceled. If no challenge is submitted by the end
of this period, the user can claim the withdrawal on Initia L1.

```mermaid theme={null}
sequenceDiagram
    participant User
    participant R as Rollup
    participant OPC as OPchild Module
    participant OPB as OPinit Bot
    participant OPH as OPhost Module
    participant IL1 as Initia L1

    User->>R: Initiate token withdrawal
    R->>OPC: Process withdrawal request
    OPC->>OPC: Lock tokens and emit event
    OPC->>OPB: Notify of withdrawal event
    OPB->>OPB: Update Merkle tree
    OPB->>OPH: Submit updated L2 output root
    OPH->>IL1: Store L2 output root
    Note over OPB,IL1: Wait for finalization period
    User->>OPB: Request withdrawal proof
    OPB->>OPB: Generate Merkle proof
    OPB->>User: Provide withdrawal proof
    User->>IL1: Submit proof & finalize withdrawal
    IL1->>OPH: Verify proof
    OPH->>IL1: Approve token release
    IL1->>User: Transfer withdrawn tokens
```

The withdrawal period is designed to allow for a challenge period during which
any malicious activity can be detected and addressed. If a challenge is
submitted, the withdrawal is canceled. If no challenge is submitted, the
transaction is finalized and the tokens are released to the user on Initia L1.

### Oracle Updates

The executor process is, when enabled on the rollup, also responsible for
relaying the latest [Connect](https://github.com/skip-mev/connect) oracle data
to the rollup. When relayed, the bot submits a `MsgUpdateOracle` to the L2 node.

```mermaid theme={null}
sequenceDiagram
    participant SO as Connect Oracle
    participant ORM as Oracle Module (L1)
    participant IL1 as Initia L1
    participant OPB as OPinit Bot
    participant OPC as OPchild Module
    participant R as Rollup

    loop Continuous update cycle
        SO->>ORM: Update oracle data
        ORM->>IL1: Store updated data
        IL1->>OPB: Emit oracle update event
        OPB->>ORM: Read new oracle data
        OPB->>OPC: Relay oracle data
        OPC->>R: Update L2 oracle state
    end
```

### DA Batch Submission

Lastly, the Executor is responsible for batching and submitting transaction data
to Celestia.

```mermaid theme={null}
sequenceDiagram
    participant R as Rollup
    participant OPC as OPchild Module
    participant OPB as OPinit Bot
    participant DA as Data Availability Layer
    participant IL1 as Initia L1

    loop For each L2 block
        R->>OPC: Generate block
        OPC->>OPB: Provide block data
        OPB->>OPB: Compress and batch data
        OPB->>DA: Submit batched data
        DA->>DA: Store data and generate proof
        OPB->>IL1: Submit DA proof (if required)
    end
```
