Open jjranalli opened 3 days ago
As you probably noticed, in Ponder the factory concept happens the config/sync layer, which makes this context idea a bit more difficult.
Could you share specific details about your use case for this feature (e.g. what does the factory event look like, what context are you trying to include, do you currently have a workaround, etc. )? That often sparks an idea on our end.
@0xOlias in our case each child contract is also linked to a tokenId
which we use as the id everywhere instead of the address. not just on the indexer but pretty much in all of our code, so would prefer not changing it.
my current workaround is retrieving said ID from the address at the beginning in each handler, and then use it as needed
const getSlicerId = async (slicerAddress: `0x${string}`) => {
const { items: slicers } = await db.Slicer.findMany({
where: {
address: slicerAddress
},
limit: 1
})
return slicers[0]!.id
}
I figured it would be tricky to implement in ponder given how it's setup in the config. On the top of my head I can think of two possible solutions:
export default createConfig({
// ...
contracts: {
Slicer: {
abi: SlicerAbi,
network: "base",
factory: {
address: "0x...",
event: TokenSlicedEvent,
// The name of the parameter that contains the address of the new child contract.
parameter: "slicerAddress",
// additional context object
context: {
// The name of the parameter that contains the id of the new child contract.
id: "slicerId"
}
}
}
}
former is likely easier and more efficient, but requires the additional context to be present in the same event containing the address. this works in my case, but may not work in others. latter would be more customisable
hope this helps!
currently when a factory creates a contract it's not possible to enrich its context arbitrarily.
this is often useful when events on the child contract require some data different than its address, like an id, which could be initialised in its context upon creation.
on the graph, this happens via
createWithContext
.would it be possible to add the feature to ponder?