diff --git a/ponder.config.ts b/ponder.config.ts index 8ee7655..a7ad479 100644 --- a/ponder.config.ts +++ b/ponder.config.ts @@ -11,7 +11,7 @@ const factoryNewPoolEvent = parseAbiItem( ); const factoryPoolAddress = "0x669c864169Cf8ba8e7E1cf9a4D4A2C979E456Dc8"; -const factoryStartBlock = 22131714; +const factoryStartBlock = 22131713; export default createConfig({ networks: { diff --git a/ponder.schema.ts b/ponder.schema.ts index 499e457..cf4a92f 100644 --- a/ponder.schema.ts +++ b/ponder.schema.ts @@ -9,6 +9,7 @@ export const factory = onchainTable("factory", (t) => ({ mintFee: t.bigint().notNull(), redeemFee: t.bigint().notNull(), offPegFeeMultiplier: t.bigint().notNull(), + owner: t.hex().notNull(), A: t.bigint().notNull(), creationTransactionId: t.text().notNull(), })); @@ -16,6 +17,7 @@ export const factory = onchainTable("factory", (t) => ({ export const pool = onchainTable("pool", (t) => ({ id: t.text().primaryKey(), chainId: t.integer().notNull(), + address: t.hex().notNull(), factoryId: t.text().notNull(), lpTokenId: t.text().notNull(), wlpTokenId: t.text().notNull(), diff --git a/src/factory.ts b/src/factory.ts index 1099676..59bc390 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -5,22 +5,68 @@ import { handleFactoryUpdateParameters, } from "./utils/databaseWriteUtils"; import { readPoolInfo } from "./utils/multicalls"; -import { pool } from "ponder:schema"; +import { factory, pool } from "ponder:schema"; import { getAddressId, getTransactionId } from "./utils/ids"; import { Address } from "viem"; -ponder.on("Factory:AModified", handleFactoryUpdateParameters); -ponder.on("Factory:GovernorModified", handleFactoryUpdateParameters); -ponder.on("Factory:SwapFeeModified", handleFactoryUpdateParameters); -ponder.on("Factory:MintFeeModified", handleFactoryUpdateParameters); -ponder.on("Factory:OffPegFeeMultiplierModified", handleFactoryUpdateParameters); -ponder.on("Factory:RedeemFeeModified", handleFactoryUpdateParameters); +ponder.on("Factory:AModified", async ({ context, event }) => { + await handleFactoryUpdateParameters({ + context, + event, + data: event.args, + }); +}); +ponder.on("Factory:GovernorModified", async ({ context, event }) => { + await handleFactoryUpdateParameters({ + context, + event, + data: event.args, + }); +}); +ponder.on("Factory:SwapFeeModified", async ({ context, event }) => { + await handleFactoryUpdateParameters({ + context, + event, + data: event.args, + }); +}); +ponder.on("Factory:MintFeeModified", async ({ context, event }) => { + await handleFactoryUpdateParameters({ + context, + event, + data: event.args, + }); +}); +ponder.on("Factory:OffPegFeeMultiplierModified", async ({ context, event }) => { + await handleFactoryUpdateParameters({ + context, + event, + data: event.args, + }); +}); +ponder.on("Factory:RedeemFeeModified", async ({ context, event }) => { + await handleFactoryUpdateParameters({ + context, + event, + data: event.args, + }); +}); +ponder.on("Factory:OwnershipTransferred", async ({ context, event }) => { + await handleFactoryUpdateParameters({ + context, + event, + data: { owner: event.args.newOwner }, + }); +}); ponder.on("Factory:PoolCreated", async ({ context, event }) => { + const chainId = context.network.chainId; + const factoryId = getAddressId(chainId, event.log.address); + const [poolInfo, factoryData] = await Promise.all([ readPoolInfo(context, event.args.selfPeggingAsset), - context.db.find(pool, { - id: getAddressId(context.network.chainId, event.log.address), + context.db.find(factory, { + id: factoryId, }), ]); @@ -32,7 +78,6 @@ ponder.on("Factory:PoolCreated", async ({ context, event }) => { context.network.chainId, event.args.selfPeggingAsset ); - const chainId = context.network.chainId; const tokenAId = getAddressId(chainId, poolInfo.tokens[0] as Address); @@ -44,10 +89,11 @@ ponder.on("Factory:PoolCreated", async ({ context, event }) => { createIfNotExistsToken(event.args.poolToken, context), createIfNotExistsToken(event.args.wrappedPoolToken, context), context.db.insert(pool).values({ - id: getAddressId(chainId, event.args.selfPeggingAsset), + id: poolId, chainId: chainId, + address: event.args.selfPeggingAsset, creationTransactionId: getTransactionId(event, context), - factoryId: getAddressId(chainId, event.log.address), + factoryId: factoryId, lpTokenId: getAddressId(chainId, event.args.poolToken), wlpTokenId: getAddressId(chainId, event.args.wrappedPoolToken), mintFee: factoryData.mintFee, diff --git a/src/utils/databaseWriteUtils.ts b/src/utils/databaseWriteUtils.ts index e0fcd6f..d8f2d59 100644 --- a/src/utils/databaseWriteUtils.ts +++ b/src/utils/databaseWriteUtils.ts @@ -7,6 +7,7 @@ import { readErc20Information, readFactoryInfo } from "./multicalls"; export async function handleFactoryUpdateParameters({ context, event, + data, }: { context: Context; event: Event< @@ -16,14 +17,16 @@ export async function handleFactoryUpdateParameters({ | "Factory:OffPegFeeMultiplierModified" | "Factory:RedeemFeeModified" | "Factory:GovernorModified" + | "Factory:OwnershipTransferred" >; + data: Partial; }) { const factoryId = getAddressId(context.network.chainId, event.log.address); const factoryDb = await context.db.find(factory, { id: factoryId }); if (factoryDb) { - await context.db.update(factory, { id: factoryId }).set(event.args); + await context.db.update(factory, { id: factoryId }).set(data); return; } @@ -43,7 +46,7 @@ export async function handleFactoryUpdateParameters({ address: event.log.address, creationTransactionId, }) - .onConflictDoUpdate(event.args), + .onConflictDoUpdate(data), createIfNotExistsTransaction(event, context), ]); } diff --git a/src/utils/multicalls.ts b/src/utils/multicalls.ts index ef31495..5ddf37a 100644 --- a/src/utils/multicalls.ts +++ b/src/utils/multicalls.ts @@ -35,6 +35,10 @@ export async function readFactoryInfo(context: Context, factory: Address) { ...factoryContract, functionName: "A", }, + { + ...factoryContract, + functionName: "owner", + }, ], }); @@ -49,6 +53,7 @@ export async function readFactoryInfo(context: Context, factory: Address) { redeemFee: res[3].result as bigint, offPegFeeMultiplier: res[4].result as bigint, A: res[5].result as bigint, + owner: res[6].result as Address, }; }