From 674a348b4dd88aa41c0e7e9485af86c925183438 Mon Sep 17 00:00:00 2001 From: jaipaljadeja Date: Tue, 3 Dec 2024 15:48:15 +0530 Subject: [PATCH] example: add factory mode --- ...-5146fc27-9558-48ae-819b-7000820431b8.json | 7 +++ .../indexers/3-starknet-factory.indexer.ts | 52 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 change/apibara-5146fc27-9558-48ae-819b-7000820431b8.json create mode 100644 examples/cli/indexers/3-starknet-factory.indexer.ts diff --git a/change/apibara-5146fc27-9558-48ae-819b-7000820431b8.json b/change/apibara-5146fc27-9558-48ae-819b-7000820431b8.json new file mode 100644 index 0000000..c162d4a --- /dev/null +++ b/change/apibara-5146fc27-9558-48ae-819b-7000820431b8.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "cli: add @electric-sql/pglite as external dependency", + "packageName": "apibara", + "email": "jadejajaipal5@gmail.com", + "dependentChangeType": "patch" +} diff --git a/examples/cli/indexers/3-starknet-factory.indexer.ts b/examples/cli/indexers/3-starknet-factory.indexer.ts new file mode 100644 index 0000000..ddf7bf3 --- /dev/null +++ b/examples/cli/indexers/3-starknet-factory.indexer.ts @@ -0,0 +1,52 @@ +import { defineIndexer } from "@apibara/indexer"; +import { useLogger } from "@apibara/indexer/plugins/logger"; +import { StarknetStream } from "@apibara/starknet"; +import type { ApibaraRuntimeConfig } from "apibara/types"; +import { hash } from "starknet"; + +const PAIR_CREATED = hash.getSelectorFromName("PairCreated") as `0x${string}`; +const SWAP = hash.getSelectorFromName("Swap") as `0x${string}`; + +export default function (runtimeConfig: ApibaraRuntimeConfig) { + return defineIndexer(StarknetStream)({ + streamUrl: "https://starknet.preview.apibara.org", + finality: "accepted", + startingCursor: { + orderKey: 800_000n, + }, + filter: { + header: "always", + events: [ + { + address: + "0x00dad44c139a476c7a17fc8141e6db680e9abc9f56fe249a105094c44382c2fd", + keys: [PAIR_CREATED], + }, + ], + }, + async factory({ block: { events } }) { + const logger = useLogger(); + + const poolEvents = (events ?? []).flatMap((event) => { + const pairAddress = event.data?.[2]; + + logger.log(`Factory: PairAddress - ${pairAddress}`); + return { + address: pairAddress, + keys: [SWAP], + includeReceipt: false, + }; + }); + return { + filter: { + header: "always", + events: poolEvents, + }, + }; + }, + async transform({ block, endCursor }) { + const logger = useLogger(); + logger.log("Transforming ", endCursor?.orderKey); + }, + }); +}