feat: add ABI validation helpers for Ponder (#29)

resolves https://codeberg.org/johba/harb/issues/23

Co-authored-by: openhands <openhands@all-hands.dev>
Reviewed-on: https://codeberg.org/johba/harb/pulls/29
This commit is contained in:
johba 2025-09-30 20:02:43 +02:00
parent 0eaf91be13
commit 76d84341de
17 changed files with 2105 additions and 49 deletions

1
services/ponder/CLAUDE.md Symbolic link
View file

@ -0,0 +1 @@
AGENTS.md

File diff suppressed because it is too large Load diff

View file

@ -7,17 +7,19 @@
"dev": "ponder dev",
"start": "ponder start",
"codegen": "ponder codegen",
"build": "tsc"
"build": "ponder codegen"
},
"dependencies": {
"@ponder/core": "^0.7.17",
"hono": "^4.5.0",
"ponder": "^0.13.1",
"kraiken-lib": "file:../../kraiken-lib",
"ponder": "^0.13.6",
"viem": "^2.21.0"
},
"devDependencies": {
"@types/node": "^20.11.30",
"esbuild": "^0.25.10",
"typescript": "^5.4.3"
"typescript": "^5.9.2"
},
"overrides": {
"esbuild": "^0.25.10",

View file

@ -9,6 +9,12 @@ declare module "ponder:schema" {
export * from "./ponder.schema.ts";
}
declare module "*.json" {
import type { Abi } from 'viem'
const value: { abi: Abi }
export default value
}
// This file enables type checking and editor autocomplete for this Ponder project.
// After upgrading, you may find that changes have been made to this file.
// If this happens, please commit the changes. Do not manually edit this file.

View file

@ -1,10 +1,20 @@
import { createConfig } from "ponder";
import type { Abi } from "viem";
import KraikenAbi from "./abis/Kraiken.json";
import StakeAbi from "./abis/Stake.json";
import { KraikenAbi, StakeAbi } from "kraiken-lib";
// Network configurations keyed by canonical environment name
const networks = {
type NetworkConfig = {
chainId: number;
rpc: string;
disableCache?: boolean;
contracts: {
kraiken: string;
stake: string;
startBlock: number;
};
};
const networks: Record<string, NetworkConfig> = {
BASE_SEPOLIA_LOCAL_FORK: {
chainId: 31337,
rpc: process.env.PONDER_RPC_URL_BASE_SEPOLIA_LOCAL_FORK || "http://127.0.0.1:8545",
@ -33,7 +43,7 @@ const networks = {
startBlock: 26038614,
},
},
} as const;
};
// Select network based on environment variable
const NETWORK = (process.env.PONDER_NETWORK as keyof typeof networks) || "BASE_SEPOLIA_LOCAL_FORK";
@ -57,18 +67,18 @@ export default createConfig({
[NETWORK]: {
id: selectedNetwork.chainId,
rpc: selectedNetwork.rpc,
disableCache: selectedNetwork.disableCache,
disableCache: selectedNetwork.disableCache ?? false,
},
},
contracts: {
Kraiken: {
abi: KraikenAbi.abi as Abi,
abi: KraikenAbi satisfies Abi,
chain: NETWORK,
address: selectedNetwork.contracts.kraiken as `0x${string}`,
startBlock: selectedNetwork.contracts.startBlock,
},
Stake: {
abi: StakeAbi.abi as Abi,
abi: StakeAbi satisfies Abi,
chain: NETWORK,
address: selectedNetwork.contracts.stake as `0x${string}`,
startBlock: selectedNetwork.contracts.startBlock,

View file

@ -0,0 +1,19 @@
import type { Abi } from 'viem'
/**
* Helper function to ensure an imported ABI matches the viem Abi type at compile time
* @param abi The ABI to validate
* @returns The validated ABI
*/
export function validateAbi<T extends Abi>(abi: T): T {
return abi
}
/**
* Helper function to ensure an imported contract ABI matches the viem Abi type at compile time
* @param contract The contract with an abi property to validate
* @returns The validated contract ABI
*/
export function validateContractAbi<T extends { abi: Abi }>(contract: T): T['abi'] {
return contract.abi
}