-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Enrich context to contracts created by factories #1203
Comments
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 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?
The text was updated successfully, but these errors were encountered: