better backend comms
This commit is contained in:
parent
d0e8623cf9
commit
02a057622c
17 changed files with 1054 additions and 134 deletions
|
|
@ -1,8 +0,0 @@
|
|||
# Auto-generated by local_env.sh
|
||||
PONDER_NETWORK=BASE_SEPOLIA_LOCAL_FORK
|
||||
KRAIKEN_ADDRESS=0x56186c1e64ca8043def78d06aff222212ea5df71
|
||||
STAKE_ADDRESS=0x056e4a859558a3975761abd7385506bc4d8a8e60
|
||||
START_BLOCK=31443298
|
||||
# Use PostgreSQL connection
|
||||
DATABASE_URL=postgresql://ponder:ponder_local@localhost/ponder_local
|
||||
DATABASE_SCHEMA=ponder_local_31443298
|
||||
|
|
@ -1,10 +1,19 @@
|
|||
import { Hono } from "hono";
|
||||
import { cors } from "hono/cors";
|
||||
import { client, graphql } from "ponder";
|
||||
import { db } from "ponder:api";
|
||||
import schema from "ponder:schema";
|
||||
import { Hono } from "hono";
|
||||
import { client, graphql } from "ponder";
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
const allowedOrigins = process.env.PONDER_CORS_ORIGINS?.split(",").map((origin) => origin.trim()).filter(Boolean);
|
||||
|
||||
app.use("/*", cors({
|
||||
origin: allowedOrigins?.length ? allowedOrigins : "*",
|
||||
allowMethods: ["GET", "POST", "OPTIONS"],
|
||||
allowHeaders: ["Content-Type", "Apollo-Require-Preflight"],
|
||||
}));
|
||||
|
||||
// SQL endpoint
|
||||
app.use("/sql/*", client({ db, schema }));
|
||||
|
||||
|
|
@ -12,4 +21,4 @@ app.use("/sql/*", client({ db, schema }));
|
|||
app.use("/graphql", graphql({ db, schema }));
|
||||
app.use("/", graphql({ db, schema }));
|
||||
|
||||
export default app;
|
||||
export default app;
|
||||
|
|
|
|||
|
|
@ -99,22 +99,46 @@ export async function ensureStatsExists(context: any, timestamp?: bigint) {
|
|||
let statsData = await context.db.find(stats, { id: STATS_ID });
|
||||
if (!statsData) {
|
||||
const { client, contracts } = context;
|
||||
const readWithFallback = async <T>(fn: () => Promise<T>, fallback: T, label: string): Promise<T> => {
|
||||
try {
|
||||
return await fn();
|
||||
} catch (error) {
|
||||
console.warn(`[stats.ensureStatsExists] Falling back for ${label}`, error);
|
||||
return fallback;
|
||||
}
|
||||
};
|
||||
|
||||
const [kraikenTotalSupply, stakeTotalSupply, outstandingStake] = await Promise.all([
|
||||
client.readContract({
|
||||
abi: contracts.Kraiken.abi,
|
||||
address: contracts.Kraiken.address,
|
||||
functionName: "totalSupply",
|
||||
}),
|
||||
client.readContract({
|
||||
abi: contracts.Stake.abi,
|
||||
address: contracts.Stake.address,
|
||||
functionName: "totalSupply",
|
||||
}),
|
||||
client.readContract({
|
||||
abi: contracts.Stake.abi,
|
||||
address: contracts.Stake.address,
|
||||
functionName: "outstandingStake",
|
||||
}),
|
||||
readWithFallback(
|
||||
() =>
|
||||
client.readContract({
|
||||
abi: contracts.Kraiken.abi,
|
||||
address: contracts.Kraiken.address,
|
||||
functionName: "totalSupply",
|
||||
}),
|
||||
0n,
|
||||
"Kraiken.totalSupply",
|
||||
),
|
||||
readWithFallback(
|
||||
() =>
|
||||
client.readContract({
|
||||
abi: contracts.Stake.abi,
|
||||
address: contracts.Stake.address,
|
||||
functionName: "totalSupply",
|
||||
}),
|
||||
0n,
|
||||
"Stake.totalSupply",
|
||||
),
|
||||
readWithFallback(
|
||||
() =>
|
||||
client.readContract({
|
||||
abi: contracts.Stake.abi,
|
||||
address: contracts.Stake.address,
|
||||
functionName: "outstandingStake",
|
||||
}),
|
||||
0n,
|
||||
"Stake.outstandingStake",
|
||||
),
|
||||
]);
|
||||
|
||||
cachedStakeTotalSupply = stakeTotalSupply;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue