Skip to content

Commit

Permalink
Merge branch 'ponder-0.7' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Nov 21, 2024
2 parents fe53994 + 2d876b2 commit 6f0c582
Show file tree
Hide file tree
Showing 41 changed files with 1,041 additions and 8,615 deletions.
46 changes: 15 additions & 31 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- uses: dorny/paths-filter@v3
id: changes
Expand All @@ -41,40 +41,25 @@ jobs:
- 'packages/erpc/Dockerfile'
ponder:
- 'packages/ponder/**'
dockerRelated:
dockerImage:
- 'packages/erpc/erpc.yaml'
- 'packages/erpc/Dockerfile'
- 'packages/ponder/**'
- name: "🔧 Set up environment variables"
run: |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "STAGE=production" >> $GITHUB_ENV
echo "PONDER_PROD_IMAGE_TAG=${{ github.sha }}" >> $GITHUB_ENV
echo "PONDER_DEV_IMAGE_TAG=${{ github.sha }}" >> $GITHUB_ENV
echo "PONDER_DEV_IMAGE_TAG=latest" >> $GITHUB_ENV
else
echo "STAGE=dev" >> $GITHUB_ENV
echo "PONDER_PROD_IMAGE_TAG=latest" >> $GITHUB_ENV
echo "PONDER_DEV_IMAGE_TAG=${{ github.sha }}" >> $GITHUB_ENV
fi
- uses: pnpm/action-setup@v4
with:
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: "🔨 Install dependencies"
run: pnpm install --frozen-lockfile
run: bun install --frozen-lockfile

- name: "👥 Configure AWS Credentials"
uses: aws-actions/configure-aws-credentials@v4
Expand All @@ -88,15 +73,15 @@ jobs:
uses: aws-actions/amazon-ecr-login@v2

- name: Set up QEMU
if: steps.changes.outputs.dockerRelated == 'true'
if: steps.changes.outputs.dockerImage == 'true'
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
if: steps.changes.outputs.dockerRelated == 'true'
if: steps.changes.outputs.dockerImage == 'true'
uses: docker/setup-buildx-action@v3

- name: "🔨 Build Ponder dev docker dependencies"
if: steps.changes.outputs.ponder == 'true'
if: steps.changes.outputs.ponder == 'true' && env.STAGE == 'dev'
uses: docker/build-push-action@v6
with:
context: ./packages/ponder
Expand All @@ -110,7 +95,7 @@ jobs:
cache-to: type=gha,mode=min

- name: "🔨 Build Ponder prod docker dependencies"
if: steps.changes.outputs.ponder == 'true' && env.PONDER_PROD_IMAGE_TAG != 'latest'
if: steps.changes.outputs.ponder == 'true' && env.STAGE == 'production'
uses: docker/build-push-action@v6
with:
context: ./packages/ponder
Expand All @@ -124,7 +109,7 @@ jobs:
cache-to: type=gha,mode=min

- name: "🔨 Build ERPC docker dependencies"
if: steps.changes.outputs.erpc == 'true'
if: steps.changes.outputs.erpc == 'true' && env.STAGE == 'production'
uses: docker/build-push-action@v6
with:
context: ./packages/erpc
Expand All @@ -141,11 +126,10 @@ jobs:
- name: "🚀 SST Deploy"
run: |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
pnpm run deploy:prod
bun run deploy:prod
else
pnpm run deploy:dev
bun run deploy:dev
fi
pnpm sst deploy --stage prod
env:
ERPC_IMAGE_TAG: ${{ steps.changes.outputs.erpc == 'true' && github.sha || 'latest' }}
PONDER_DEV_IMAGE_TAG: ${{ steps.changes.outputs.ponder == 'true' && env.PONDER_DEV_IMAGE_TAG || 'latest' }}
Expand Down
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Frak Indexer

Frak Indexer is an open-source project designed to index events from Frak smart contracts on the Arbitrum Sepolia network. It combines the power of Ponder for building robust crypto apps with eRPC for efficient RPC caching and load balancing, all deployed using SST (Serverless Stack) on AWS infrastructure.
Frak Indexer is an open-source project designed to index events from Frak smart contracts on the Arbitrum network. It combines the power of Ponder for building robust crypto apps with eRPC for efficient RPC caching and load balancing, all deployed using SST (Serverless Stack) on AWS infrastructure.

## Architecture Overview

Expand Down Expand Up @@ -33,15 +33,6 @@ Both services are deployed as containerized applications on AWS ECS (Elastic Con
- **Observable**: Includes CloudWatch logs and metrics for monitoring.
- **Maintainable**: Infrastructure as Code (IaC) using SST for easy updates and version control.

## Deployment

This project uses SST for infrastructure deployment. To deploy:

1. Ensure you have AWS credentials configured.
2. Setup the secrets required to run the project (check the `iac/Config.ts` file for the required secrets).
3. Install dependencies: `pnpm install`
4. Deploy the stack: `npx run deploy`

## Contributing

We welcome contributions to the Frak Indexer project!
Expand Down
Binary file added bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions infra/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getPonderEntrypoint(type: "indexer" | "reader") {
const command = type === "indexer" ? "start" : "serve";

return [
"pnpm",
"bun",
"ponder",
"--log-format",
"json",
Expand All @@ -34,7 +34,7 @@ const cloudmapErpcUrl = vpc.nodes.cloudmapNamespace.name.apply(
(namespaceName) =>
`http://Erpc.production.frak-indexer.${namespaceName}:8080/${erpcProject}/evm`
);
const externalErpcUrl = "https://rpc.frak-labs.com/ponder-dev-rpc/evm";
const externalErpcUrl = `https://rpc.frak-labs.com/${erpcProject}/evm`;

export const ponderEnv = {
environment: {
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
"type": "module",
"scripts": {
"deploy:prod": "sst deploy --stage production",
"deploy:dev": "sst deploy --stage dev",
"deploy:dev": "sst deploy --stage dev --print-logs",
"format": "biome check --write .",
"format:check": "biome check .",
"lint": "biome lint .",
"typecheck": "tsc"
"typecheck": "tsc",
"update:deps": "npm-check-updates -ui -ws -f \\!sst"
},
"devDependencies": {
"npm-check-updates": "^17.1.11",
"@biomejs/biome": "1.9.4",
"@pulumi/aws": "^6.59.1",
"@pulumi/pulumi": "^3.139.0",
Expand All @@ -22,8 +24,6 @@
"engines": {
"node": ">=18.14"
},
"packageManager": "[email protected]",
"dependencies": {
"sst": "3.3.22"
}
"packageManager": "[email protected]",
"workspaces": ["packages/*"]
}
2 changes: 1 addition & 1 deletion packages/erpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
"engines": {
"node": ">=18.14"
},
"packageManager": "pnpm@9.1.3"
"packageManager": "bun@1.1.36"
}
21 changes: 10 additions & 11 deletions packages/erpc/sst-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
/* tslint:disable */
/* eslint-disable */
/* deno-fmt-ignore-file */
import "sst"
export {}
import "sst";
declare module "sst" {
export interface Resource {
"MasterVpc": {
"bastion": string
"type": "sst.aws.Vpc"
export interface Resource {
MasterVpc: {
bastion: string;
type: "sst.aws.Vpc";
};
PonderDevIndexer: {
service: string;
type: "sst.aws.Service";
};
}
"PonderDevIndexer": {
"service": string
"type": "sst.aws.Service"
}
}
}
39 changes: 16 additions & 23 deletions packages/ponder/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
# Base image is node-22
FROM node:22-slim AS base

# Setup pnpm
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
RUN corepack install --global [email protected]

# Create app directory
# Base stage
FROM --platform=$BUILDPLATFORM oven/bun:1 AS base
WORKDIR /usr/src/app

# install dependencies into temp directory
# this will cache them and speed up future builds
# Bun package installation
FROM base AS install
# install python and all the stuff required to build sqlite3
RUN apt-get update && apt-get install -y python3 build-essential

# Install dependencies
ENV NODE_ENV=production

# Install prod dependencies
RUN mkdir -p /temp/prod
COPY package.json /temp/prod/
RUN --mount=type=cache,id=pnpm,target=/pnpm/store cd /temp/prod && pnpm install --prod
RUN cd /temp/prod && bun install --production

FROM base AS release

# Set env to production
ENV NODE_ENV=production
# Start a new stage for the final image
FROM base AS release

# copy production dependencies and source code into final image
COPY . .
# todo: Ideally ponder would expose a bundler command or something like that to have a lighter docker image,
# thus permitting to use more efficient runtime than vite (like a bun binary bundle)
# Copy the installed node_modules and the app
COPY --from=install /temp/prod/node_modules node_modules
COPY . .

# run the app
# Run the app
ENV NODE_ENV=production
EXPOSE 42069/tcp
ENTRYPOINT [ "pnpm", "ponder", "start"]
ENTRYPOINT ["bun", "ponder", "start"]
30 changes: 0 additions & 30 deletions packages/ponder/DockerfileBun

This file was deleted.

6 changes: 3 additions & 3 deletions packages/ponder/config/config-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { createEnvConfig } from "./configBuilder";
*/
export default createEnvConfig({
network: {
chainId: 42161,
deploymentBlock: 261367992,
chainId: 421614,
deploymentBlock: 86607902,
},
networkKey: "arbitrum",
networkKey: "arbitrumSepolia",
});
2 changes: 2 additions & 0 deletions packages/ponder/config/config-prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ export default createEnvConfig({
deploymentBlock: 261367992,
},
networkKey: "arbitrum",
// Reduce polling interval on prod to 60sec
pollingInterval: 30_000,
});
15 changes: 12 additions & 3 deletions packages/ponder/config/configBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ function safeClient(initialTransport: Transport): Transport {
* @returns
*/
function getTransport(chainId: number) {
// todo: Intercept getBlockByNumber and replace finalized with latest (plus small delay, like 0.5ms)
// todo: rpc url = internal or external, use both env variables
// Get our erpc instance transport
const erpcInternalUrl = process.env.INTERNAL_RPC_URL;
const erpcExternalUrl = process.env.EXTERNAL_RPC_URL;
Expand Down Expand Up @@ -153,7 +155,13 @@ export function createEnvConfig<NetworkKey extends string>({
pgDatabase,
network,
networkKey,
}: { pgDatabase?: string; network: EnvNetworkConfig; networkKey: NetworkKey }) {
pollingInterval,
}: {
pgDatabase?: string;
network: EnvNetworkConfig;
networkKey: NetworkKey;
pollingInterval?: number;
}) {
const contractNetworkConfig = {
[networkKey]: {
startBlock: network.deploymentBlock,
Expand All @@ -168,14 +176,15 @@ export function createEnvConfig<NetworkKey extends string>({
connectionString: `${process.env.PONDER_DATABASE_URL}/${pgDatabase}`,
}
: {
kind: "sqlite",
kind: "pglite",
},
// networks config
networks: {
[networkKey]: {
chainId: network.chainId,
transport: getTransport(network.chainId),
pollingInterval: 30_000,
// Polling interval to 60sec by default
pollingInterval: pollingInterval ?? 60_000,
},
},
// contracts config
Expand Down
18 changes: 8 additions & 10 deletions packages/ponder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,24 @@
"start": "ponder --config config/config-local.ts start",
"start:dev": "ponder --config config/config-dev.ts start",
"start:prod": "ponder --config config/config-prod.ts start",
"typecheck": "tsc"
"typecheck": "tsc",
"docker": "bun docker:build && bun docker:run",
"docker:build": "docker build --tag ponder-dev .",
"docker:run": "docker run -P ponder-dev"
},
"dependencies": {
"@ponder/core": "0.6.24",
"drizzle-orm": "^0.31.4",
"hono": "4.6.8",
"@ponder/core": "0.7.8",
"drizzle-orm": "0.34.1",
"hono": "4.6.10",
"viem": "^2.21.40"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@types/aws-lambda": "8.10.138",
"@types/node": "^22.4.0",
"sst": "3.3.22",
"typescript": "^5.6.3"
},
"trustedDependencies": [
"better_sqlite3"
],
"engines": {
"node": ">=18.14"
},
"packageManager": "pnpm@9.1.3"
"packageManager": "bun@1.1.36"
}
Loading

0 comments on commit 6f0c582

Please sign in to comment.