Skip to content

docs(intelligent-contracts): add best practices and common patterns guide#352

Open
luch91 wants to merge 1 commit intogenlayerlabs:mainfrom
luch91:add/best-practices-guide
Open

docs(intelligent-contracts): add best practices and common patterns guide#352
luch91 wants to merge 1 commit intogenlayerlabs:mainfrom
luch91:add/best-practices-guide

Conversation

@luch91
Copy link

@luch91 luch91 commented Mar 1, 2026

Description

Add a best-practices guide for GenLayer contract development under the Intelligent Contracts documentation.

This page is based on the community-maintained genlayer-utils patterns library and is intended to complement the existing primitive/API documentation with a more practical, workflow-oriented guide.

It adds guidance on:

  • non-deterministic execution patterns and equivalence principles
  • prompt design for validator consensus
  • storage patterns and helper recipes
  • access-control patterns
  • indexed event patterns
  • a minimal proxy/upgrade pattern
  • a gas-aware preview/write workflow pattern

This PR is documentation-only and does not attempt to introduce SDK or Studio features.

Closes #345

Summary by CodeRabbit

  • Documentation
    • Added comprehensive documentation on best practices and common patterns for intelligent contract development, covering non-deterministic patterns, equivalence principles, prompt engineering, access control, storage patterns, debugging, event indexing, upgrade patterns, and gas optimization strategies.

@vercel
Copy link
Contributor

vercel bot commented Mar 1, 2026

@luch91 is attempting to deploy a commit to the YeagerAI Team on Vercel.

A member of the Team first needs to authorize it.

@netlify
Copy link

netlify bot commented Mar 1, 2026

Deploy Preview for genlayer-docs ready!

Name Link
🔨 Latest commit 04d6d39
🔍 Latest deploy log https://app.netlify.com/projects/genlayer-docs/deploys/69a42aee588efe00086946e5
😎 Deploy Preview https://deploy-preview-352--genlayer-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 1, 2026

📝 Walkthrough

Walkthrough

A new documentation page on intelligent contract best practices and common patterns was added, covering non-deterministic blocks, prompt engineering, access control, storage patterns, event indexing, and upgrade patterns, registered in the site metadata.

Changes

Cohort / File(s) Summary
Documentation Setup
pages/developers/intelligent-contracts/security-and-best-practices/_meta.json
Added "best-practices" entry to site navigation metadata.
Best Practices Content
pages/developers/intelligent-contracts/security-and-best-practices/best-practices.mdx
New comprehensive documentation covering non-deterministic patterns, prompt engineering for consensus, access control, storage patterns, event indexing, upgrade patterns, helper functions, and gas-aware price-feed workflows with examples.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • cristiam86
  • kp2pml30

Poem

🐰 The docs now bloom with patterns true,
Best practices guide us through and through,
From storage maps to access gates,
GenLayer contracts reach new states! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly follows Conventional Commits format and accurately describes the main change: adding a best practices and common patterns guide for intelligent contracts documentation.
Description check ✅ Passed The description provides a detailed overview of the changes, references the community source, closes issue #345, and clarifies the documentation-only nature with no SDK/Studio feature changes.
Linked Issues check ✅ Passed The PR meets all requirements from issue #345: comprehensive guide covering non-deterministic patterns, equivalence principles, prompt engineering, access control, storage patterns, debugging tips, and event/upgrade patterns.
Out of Scope Changes check ✅ Passed All changes are scoped to documentation: a metadata file entry and a new best-practices guide file, both directly supporting the stated objective of adding a best practices guide.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pages/developers/intelligent-contracts/security-and-best-practices/best-practices.mdx (1)

3-8: Consider making helper/example references clickable and repo-scoped.

Many references are plain filenames/paths; converting them to explicit links (and naming the target repo where relevant) would improve navigation and reduce ambiguity for readers.

Also applies to: 33-34, 54-55, 71-73, 76-83, 115-116, 122-123, 142-143, 155-163

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@pages/developers/intelligent-contracts/security-and-best-practices/best-practices.mdx`
around lines 3 - 8, The document best-practices.mdx contains many plain
filenames/paths used as helper/example references; replace each plain
filename/path with an explicit clickable link pointing to the appropriate
repo/file (use full GitHub URLs or repo-scoped relative links) and include the
target repo name in the link text for clarity. Update the occurrences referenced
(around lines 33-34, 54-55, 71-73, 76-83, 115-116, 122-123, 142-143, 155-163) so
every helper/example mention becomes a descriptive link (e.g., "genlayer-utils:
path/to/file" linking to the file), and ensure links open in the same docs/site
convention used elsewhere in the project. Ensure link formatting is valid MDX
and preserves current surrounding wording and emphasis.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@pages/developers/intelligent-contracts/security-and-best-practices/best-practices.mdx`:
- Line 99: Update the table row wording to be precise: change "Calling
`gl.nondet` outside equivalent" to something like "Calling `gl.nondet` outside
an equivalence-principle wrapper (e.g., outside `gl.eq_principle.*`)" so it
clearly indicates the operator must be used within an equivalence-principle
wrapper; update the cell that currently suggests "Wrap in `gl.eq_principle.*`
function" to match the new phrasing for consistency.

---

Nitpick comments:
In
`@pages/developers/intelligent-contracts/security-and-best-practices/best-practices.mdx`:
- Around line 3-8: The document best-practices.mdx contains many plain
filenames/paths used as helper/example references; replace each plain
filename/path with an explicit clickable link pointing to the appropriate
repo/file (use full GitHub URLs or repo-scoped relative links) and include the
target repo name in the link text for clarity. Update the occurrences referenced
(around lines 33-34, 54-55, 71-73, 76-83, 115-116, 122-123, 142-143, 155-163) so
every helper/example mention becomes a descriptive link (e.g., "genlayer-utils:
path/to/file" linking to the file), and ensure links open in the same docs/site
convention used elsewhere in the project. Ensure link formatting is valid MDX
and preserves current surrounding wording and emphasis.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e7426e and 04d6d39.

📒 Files selected for processing (2)
  • pages/developers/intelligent-contracts/security-and-best-practices/_meta.json
  • pages/developers/intelligent-contracts/security-and-best-practices/best-practices.mdx

| Forgetting `sort_keys=True` | Always `json.dumps(result, sort_keys=True)` before `strict_eq` |
| Using `dict`/`list` for storage | Use `TreeMap` / `DynArray` instead |
| Missing `@allow_storage @dataclass` | Required on every stored custom class |
| Calling `gl.nondet` outside equivalent | Wrap in `gl.eq_principle.*` function |
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Clarify wording in the common-mistakes row.

Calling gl.nondet outside equivalent is unclear; use outside an equivalence-principle wrapper (or similar) for precision.

✏️ Proposed wording fix
-| Calling `gl.nondet` outside equivalent  | Wrap in `gl.eq_principle.*` function                               |
+| Calling `gl.nondet` outside an equivalence-principle wrapper | Wrap in a `gl.eq_principle.*` function |
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
| Calling `gl.nondet` outside equivalent | Wrap in `gl.eq_principle.*` function |
| Calling `gl.nondet` outside an equivalence-principle wrapper | Wrap in a `gl.eq_principle.*` function |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@pages/developers/intelligent-contracts/security-and-best-practices/best-practices.mdx`
at line 99, Update the table row wording to be precise: change "Calling
`gl.nondet` outside equivalent" to something like "Calling `gl.nondet` outside
an equivalence-principle wrapper (e.g., outside `gl.eq_principle.*`)" so it
clearly indicates the operator must be used within an equivalence-principle
wrapper; update the cell that currently suggests "Wrap in `gl.eq_principle.*`
function" to match the new phrasing for consistency.

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.

Docs suggestion: Best Practices & Common Patterns guide

1 participant