Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for specifying a custom start block when indexing child contracts created by a factory pattern. Previously, child contracts were always indexed starting from the block where the factory event was emitted. This change allows backfilling events from child contracts that occurred before the factory event.
Motivation
In some use cases, a factory contract may emit events about child contracts that were created earlier, or you may want to index child contract events from a specific historical block regardless of when the factory event occurred. This was previously not possible with Ponder's factory pattern.
New Features
1.
childStartBlock- Static Start BlockSpecify a fixed block number to start indexing all child contract events from:
export default createConfig({
contracts: {
ChildContract: {
abi: childAbi,
address: factory({
address: "0xFactoryAddress",
event: parseAbiEvent("event ChildCreated(address indexed child)"),
parameter: "child",
childStartBlock: 14645816, // All children indexed from this block
}),
network: "mainnet",
},
},
});### 2.
startBlockParameter- Dynamic Start Block from EventExtract the start block dynamically from a parameter in the factory event:
export default createConfig({
contracts: {
ChildContract: {
abi: childAbi,
address: factory({
address: "0xFactoryAddress",
event: parseAbiEvent("event ChildCreated(address indexed child, uint256 indexed startBlock)"),
parameter: "child",
startBlockParameter: "startBlock", // Start block extracted from event
}),
network: "mainnet",
},
},
});## Implementation Details
Files Changed
packages/core/src/config/address.ts- AddedchildStartBlockandstartBlockParameterto the publicFactorytypepackages/core/src/internal/types.ts- AddedchildStartBlockandchildStartBlockLocationto internalLogFactorytypepackages/core/src/build/factory.ts- UpdatedbuildLogFactoryto process the new options and compute parameter locationspackages/core/src/build/config.ts- Pass new options through config buildingpackages/core/src/runtime/filter.ts- AddedgetChildStartBlock()helper function for extracting start blockspackages/core/src/sync-historical/index.ts- Updated historical sync to use custom start blocks for backfillingpackages/core/src/sync-realtime/index.ts- Updated realtime sync to track start blocks per child addressTests Added
buildLogFactory with childStartBlock static valuebuildLogFactory with startBlockParameter from indexed topicbuildLogFactory with startBlockParameter from data offsetbuildLogFactory with startBlockParameter extracts from chainIdbuildLogFactory throws if startBlockParameter not foundgetChildStartBlock() returns undefined when no configgetChildStartBlock() returns static childStartBlockgetChildStartBlock() extracts from topicgetChildStartBlock() extracts from data offsetgetChildStartBlock() static childStartBlock takes precedence over locationBreaking Changes
None. The new options are fully optional and existing factory configurations continue to work unchanged.
Testing