Skip to content
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

Allow contract config to suggest relative's template #3837

Merged
merged 35 commits into from
May 28, 2024

Conversation

adamiak
Copy link
Member

@adamiak adamiak commented May 23, 2024

Resolves L2B-5660

This PR includes a simple use of a suggested templates in zora, as an example.

Implementation deals with situations where:

  • discovery for contract A already took place (with or without template)
  • further in discovery, some contract B requests for A to be discovered using a template (via field.target.template).
  • if no template was used in first discovery, discovery for contract A is removed with all orphaned discoveries and rediscovered. If a template was already used, it's either marked as error (when both contracts are "suggested") or not re-discovered (if contract was explicitly set via "extends" in main config.jsonc, or it's the same one that was used).
  • any contracts awaiting discovery are pruned for no longer reachable contracts

Copy link

vercel bot commented May 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
l2beat-frontend2-production ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 28, 2024 2:03pm
l2beat-mock ✅ Ready (Inspect) Visit Preview May 28, 2024 2:03pm
l2beat-production ✅ Ready (Inspect) Visit Preview May 28, 2024 2:03pm
l2beat-staging ✅ Ready (Inspect) Visit Preview May 28, 2024 2:03pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
l2beat-frontend2-staging ⬜️ Ignored (Inspect) Visit Preview May 28, 2024 2:03pm

Copy link

linear bot commented May 28, 2024

@adamiak adamiak marked this pull request as ready for review May 28, 2024 13:54
@adamiak adamiak changed the title Allow templates to suggest target's template Allow templates to suggest their relative's template May 28, 2024
@adamiak adamiak changed the title Allow templates to suggest their relative's template Allow contract config to suggest its relative's template May 28, 2024
@adamiak adamiak changed the title Allow contract config to suggest its relative's template Allow contract config to suggest relative's template May 28, 2024
Copy link
Contributor

@mateuszradomski mateuszradomski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little convoluted but it looks good

Comment on lines +40 to +56
function getAddresses(
value: ContractValue | undefined,
template?: string,
): EthereumAddress[] {
if (Array.isArray(value)) {
return value.flatMap((v) => getAddresses(v, template))
} else if (typeof value === 'object') {
return Object.values(value).flatMap((v) => getAddresses(v, template))
} else if (typeof value === 'string') {
try {
return [EthereumAddress(value)]
} catch {
return []
}
}
return []
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is template here really used anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot, will be removed.

@adamiak adamiak added this pull request to the merge queue May 28, 2024
Merged via the queue into main with commit 12f850f May 28, 2024
14 checks passed
@adamiak adamiak deleted the config-specifying-target-template branch May 28, 2024 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants