Skip to content

Commit

Permalink
rough pass at docs and some linting and fixes yarn
Browse files Browse the repository at this point in the history
  • Loading branch information
Defi-Moses committed Sep 17, 2024
1 parent 9f901d7 commit 6845d9e
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 12 deletions.
25 changes: 25 additions & 0 deletions packages/rfq-indexer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# RFQ Indexer

## Overview

The RFQ (Request for Quote) Indexer is a system designed to index and track bridge events across multiple blockchain networks. It consists of two main parts: the indexer and the API.

1. What does the rfq-indexer do?
The rfq-indexer captures and stores bridge events from various blockchain networks, including Ethereum, Optimism, Arbitrum, Base, Blast, Scroll, Linea, and BNB Chain. It indexes events such as bridge requests, relays, proofs, refunds, and claims.

2. Parts of the indexer and their users:
- Indexer: Used by developers and system administrators to collect and store blockchain data.
- API: Used by front-end applications, other services, or developers to query the indexed data.

## Directory Structure
rfq-indexer/
├── api/ # API service
│ ├── src/ # API source code
│ ├── package.json # API dependencies and scripts
│ └── README.md # API documentation
├── indexer/ # Indexer service
│ ├── src/ # Indexer source code
│ ├── abis/ # Contract ABIs
│ ├── package.json # Indexer dependencies and scripts
│ └── README.md # Indexer documentation
└── README.md # This file
40 changes: 40 additions & 0 deletions packages/rfq-indexer/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# RFQ Indexer API

This API provides access to the indexed bridge event data.

## API Calls

1. GET /api/hello
- Description: A simple hello world endpoint
- Example: `curl http://localhost:3001/api/hello`

2. GET /api/pending-transactions-missing-relay
- Description: Retrieves pending transactions that are missing relay events
- Example:
```
curl http://localhost:3001/api/pending-transactions-missing-relay
```
3. GET /api/pending-transactions-missing-proof
- Description: Retrieves pending transactions that are missing proof events
- Example:
```
curl http://localhost:3001/api/pending-transactions-missing-proof
```
4. GET /api/pending-transactions-missing-claim
- Description: Retrieves pending transactions that are missing claim events
- Example:
```
curl http://localhost:3001/api/pending-transactions-missing-claim
```
5. GraphQL endpoint: /graphql
- Description: Provides a GraphQL interface for querying indexed data, the user is surfaced an interface to query the data via GraphiQL
## Important Scripts
- `yarn dev:local`: Runs the API in development mode using local environment variables
- `yarn dev:prod`: Runs the API in development mode using production environment variables
- `yarn start`: Starts the API in production mode
3 changes: 2 additions & 1 deletion packages/rfq-indexer/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
"start": "tsx src/index.ts",
"start:local": "dotenv -e .env -- tsx src/index.ts",
"dev": "dotenv -e .env -- tsx watch src/index.ts",
"lint:check": " ",
"ci:lint": " ",
"build:go": " ",
"build": " ",
"build:slither": " ",
"ci:lint": " ",
"test:coverage": "echo 'No tests defined.'"
},
"keywords": [],
Expand Down
10 changes: 8 additions & 2 deletions packages/rfq-indexer/api/src/db/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Kysely, PostgresDialect } from 'kysely'
import { Pool } from 'pg'

import type { BridgeRequestEvents, BridgeRelayedEvents, BridgeProofProvidedEvents, BridgeDepositRefundedEvents, BridgeDepositClaimedEvents } from '../types'
import type {
BridgeRequestEvents,
BridgeRelayedEvents,
BridgeProofProvidedEvents,
BridgeDepositRefundedEvents,
BridgeDepositClaimedEvents,
} from '../types'

const { DATABASE_URL } = process.env

Expand All @@ -17,4 +23,4 @@ export interface Database {
BridgeDepositClaimedEvents: BridgeDepositClaimedEvents
}

export const db = new Kysely<Database>({ dialect })
export const db = new Kysely<Database>({ dialect })
8 changes: 6 additions & 2 deletions packages/rfq-indexer/api/src/graphql/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ const additionalTypes = `
}
`

const typeDefs = mergeTypeDefs([...typesArray, ...queriesArray, additionalTypes])
const typeDefs = mergeTypeDefs([
...typesArray,
...queriesArray,
additionalTypes,
])

export const schema = makeExecutableSchema({
typeDefs,
resolvers,
})
})
16 changes: 10 additions & 6 deletions packages/rfq-indexer/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express from 'express'
import { createYoga } from 'graphql-yoga'

import { schema } from './graphql/schema'
import { overrideJsonBigIntSerialization } from './utils/overrideJsonBigIntSerialization'
import { resolvers } from './graphql/resolvers'
Expand All @@ -13,12 +14,13 @@ const yoga = createYoga({ schema })
app.use(yoga.graphqlEndpoint, yoga)

app.get('/api/hello', (req, res) => {
res.json({ message: 'Hello World!' })
})
res.json({ message: 'Hello World!' })
})

app.get('/api/pending-transactions-missing-relay', async (req, res) => {
try {
const pendingTransactions = await resolvers.Query.pendingTransactionsMissingRelay();
const pendingTransactions =
await resolvers.Query.pendingTransactionsMissingRelay()
res.json(pendingTransactions);
} catch (error) {
console.error('Error fetching pending transactions:', error);
Expand All @@ -28,7 +30,8 @@ app.get('/api/pending-transactions-missing-relay', async (req, res) => {

app.get('/api/pending-transactions-missing-proof', async (req, res) => {
try {
const pendingTransactionsMissingProof = await resolvers.Query.pendingTransactionsMissingProof();
const pendingTransactionsMissingProof =
await resolvers.Query.pendingTransactionsMissingProof()
res.json(pendingTransactionsMissingProof);
} catch (error) {
console.error('Error fetching pending transactions missing proof:', error);
Expand All @@ -38,7 +41,8 @@ app.get('/api/pending-transactions-missing-proof', async (req, res) => {

app.get('/api/pending-transactions-missing-claim', async (req, res) => {
try {
const pendingTransactionsMissingClaim = await resolvers.Query.pendingTransactionsMissingClaim();
const pendingTransactionsMissingClaim =
await resolvers.Query.pendingTransactionsMissingClaim()
res.json(pendingTransactionsMissingClaim);
} catch (error) {
console.error('Error fetching pending transactions missing claim:', error);
Expand All @@ -51,4 +55,4 @@ app.listen(process.env.PORT, () => {
console.info('API server runs on http://localhost:3001')
console.info('REST requests go through http://localhost:3001/api')
console.info('GraphQL requests go through http://localhost:3001/graphql')
})
})
7 changes: 6 additions & 1 deletion packages/rfq-indexer/api/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ export interface BridgeDepositClaimedEvents {
}

// Add any other shared types used across the API
export type EventType = 'REQUEST' | 'RELAYED' | 'PROOF_PROVIDED' | 'DEPOSIT_REFUNDED' | 'DEPOSIT_CLAIMED'
export type EventType =
| 'REQUEST'
| 'RELAYED'
| 'PROOF_PROVIDED'
| 'DEPOSIT_REFUNDED'
| 'DEPOSIT_CLAIMED'

export interface EventFilter {
type?: EventType
Expand Down
25 changes: 25 additions & 0 deletions packages/rfq-indexer/indexer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# RFQ Indexer

This indexer captures and stores FastBridgeV2 events from various blockchain networks.

## Important Scripts

- `yarn dev:local`: Runs the indexer in development mode, clearing previous data
- `yarn dev`: Runs the indexer in development mode
- `yarn start`: Starts the indexer in production mode

To run these scripts, use `yarn <script-name>` in the terminal from the indexer directory.

## Main Files for Contributors

1. ponder.schema.ts
- Description: Defines the database schema for indexed events
2. ponder.config.ts
- Description: Configures the indexer, including network details and contract addresses
3. src/index.ts
- Description: Contains the main indexing logic for different event types

4. abis/FastBridgeV2.ts
- Description: Contains the ABI (Application Binary Interface) for the FastBridgeV2 contract

When contributing, focus on these files for making changes to the indexing logic, adding new event types, or modifying the database schema.

0 comments on commit 6845d9e

Please sign in to comment.