Skip to content

Commit

Permalink
feat: index OP Sepolia
Browse files Browse the repository at this point in the history
  • Loading branch information
tnrdd committed May 9, 2024
1 parent 0835d49 commit 3dab3b3
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DATABASE_URI=postgres://postgres:postgres@sqf-indexer-db-1:5432/sqf-indexer
RPC_URL_SEPOLIA=
RPC_URL_OPSEPOLIA=
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
compose-file: "./docker-compose.yaml"
env:
DATABASE_URI: ${{ secrets.DATABASE_URI }}
RPC_URL_SEPOLIA: ${{ secrets.RPC_URL_SEPOLIA }}
RPC_URL_OPSEPOLIA: ${{ secrets.RPC_URL_OPSEPOLIA }}
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
compose-file: "./docker-compose.yaml"
env:
DATABASE_URI: ${{ secrets.DATABASE_URI }}
RPC_URL_SEPOLIA: ${{ secrets.RPC_URL_SEPOLIA }}
RPC_URL_OPSEPOLIA: ${{ secrets.RPC_URL_OPSEPOLIA }}

deploy:
needs: build
Expand All @@ -38,6 +38,6 @@ jobs:
cd ${{ secrets.APP_PATH }}
git pull origin main
export DATABASE_URI=${{ secrets.DATABASE_URI }}
export RPC_URL_SEPOLIA=${{ secrets.RPC_URL_SEPOLIA }}
export RPC_URL_OPSEPOLIA=${{ secrets.RPC_URL_OPSEPOLIA }}
docker compose -f docker-compose.yaml up -d --build
ENDSSH
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
environment:
- NODE_ENV=production
- DATABASE_URI=${DATABASE_URI}
- RPC_URL_SEPOLIA=${RPC_URL_SEPOLIA}
- RPC_URL_OPSEPOLIA=${RPC_URL_OPSEPOLIA}
volumes:
- sqlite_data:/sqlite_cache
db:
Expand Down
1 change: 1 addition & 0 deletions src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export type RecipientsTable = {
anchorAddress: string | null;
status: "PENDING" | "REJECTED" | "APPROVED";
metadataCid: string | null;
metadata: unknown;
createdAtBlock: bigint;
updatedAtBlock: bigint;
tags: string[];
Expand Down
1 change: 1 addition & 0 deletions src/db/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ async function migrate<T>(db: Kysely<T>) {
.addColumn("anchorAddress", "text")
.addColumn("status", ref("status"))
.addColumn("metadataCid", "text")
.addColumn("metadata", "jsonb")
.addColumn("createdAtBlock", "bigint")
.addColumn("updatedAtBlock", "bigint")
.addColumn("tags", sql`text[]`)
Expand Down
4 changes: 2 additions & 2 deletions src/indexer/events/handleProfileMetadataUpdated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export async function handleProfileMetadataUpdated(
try {
db.updateTable("profiles")
.set({
metadataCid: metadataCid,
metadata: metadata,
metadataCid,
metadata,
})
.where("chainId", "=", chainId)
.where("id", "=", params.profileId)
Expand Down
6 changes: 5 additions & 1 deletion src/indexer/events/handleRegistered.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EventHandlerArgs, Indexer } from "chainsauce";
import { IndexerContext } from "../handleEvent.js";
import { getPool } from "../../db/index.js";
import { fetchIpfs } from "../ipfs.js";
import { decodeRegistrationDataAlloStrategy } from "../decode.js";
import { abis } from "../../lib/abi/index.js";

Expand Down Expand Up @@ -37,11 +38,13 @@ export async function handleRegistered(
metadata: { pointer: metadataCid },
} = decodeRegistrationDataAlloStrategy(encodedData);

const metadata = await fetchIpfs(metadataCid);

try {
await db
.insertInto("recipients")
.values({
id: recipientId,
id: recipientId.toLowerCase(),
chainId,
poolId: pool.id,
strategyAddress,
Expand All @@ -50,6 +53,7 @@ export async function handleRegistered(
recipientId !== recipientAddress ? recipientId.toLowerCase() : null,
status: "PENDING",
metadataCid,
metadata,
createdAtBlock: event.blockNumber,
updatedAtBlock: event.blockNumber,
tags: ["allo"],
Expand Down
2 changes: 1 addition & 1 deletion src/indexer/events/handleRoleGranted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export async function handleRoleGranted(
.insertInto("pendingPoolRoles")
.values({
chainId,
role: "manager",
role,
address,
createdAtBlock: event.blockNumber,
})
Expand Down
3 changes: 3 additions & 0 deletions src/indexer/events/handleUpdatedRegistration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EventHandlerArgs, Indexer } from "chainsauce";
import { IndexerContext } from "../handleEvent.js";
import { fetchIpfs } from "../ipfs.js";
import { decodeRegistrationDataAlloStrategy } from "../decode.js";
import { abis } from "../../lib/abi/index.js";

Expand Down Expand Up @@ -28,13 +29,15 @@ export async function handleUpdatedRegistration(
} = decodeRegistrationDataAlloStrategy(encodedData);

const strategyAddress = address.toLowerCase();
const metadata = await fetchIpfs(metadataCid);

try {
await db
.updateTable("recipients")
.set({
recipientAddress: recipientAddress.toLowerCase(),
metadataCid,
metadata,
updatedAtBlock: event.blockNumber,
})
.where("chainId", "=", chainId)
Expand Down
2 changes: 2 additions & 0 deletions src/indexer/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { createVerifiedFetch } from "@helia/verified-fetch";
import { IPFS_GATEWAYS } from "../lib/constants.js";

async function fetchIpfs(cid: string) {
await new Promise((resolve) => setTimeout(resolve, 1000));

const cidRegex = /^(Qm[1-9A-HJ-NP-Za-km-z]{44}|baf[0-9A-Za-z]{50,})$/;

if (!cidRegex.test(cid)) {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ export const ALLO_OWNER_ROLE =
export const IPFS_GATEWAYS = [
"https://gateway.pinata.cloud",
"https://storry.tv",
"https://cf-ipfs.com",
"https://4everland.io",
"https://cf-ipfs.com",
"https://ipfs.runfission.com",
"https://w3s.link",
"https://dweb.link",
"https://trustless-gateway.link",
];
11 changes: 6 additions & 5 deletions src/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ type Contract = {

const networks: Network[] = [
{
id: 11155111,
name: "sepolia",
rpc: process.env.RPC_URL_SEPOLIA ?? "https://sepolia.infura.io/v3",
id: 11155420,
name: "optimism-sepolia",
rpc:
process.env.RPC_URL_OPSEPOLIA ?? "https://optimism-sepolia.infura.io/v3",
contracts: [
{
name: "Allo",
address: "0x1133eA7Af70876e64665ecD07C0A0476d09465a1",
fromBlock: 5802180n,
fromBlock: 11724487n,
},
{
name: "AlloRegistry",
address: "0x4AAcca72145e1dF2aeC137E1f3C5E3D75DB8b5f3",
fromBlock: 5800180n,
fromBlock: 11724487n,
},
],
},
Expand Down

0 comments on commit 3dab3b3

Please sign in to comment.