Add Rootstock DeFi Developer Guide#480
Conversation
|
@Janhavi312003 is attempting to deploy a commit to the IOV Labs Team on Vercel. A member of the Team first needs to authorize it. |
|
This Rootstock DeFi Developer Guide gives developers a detailed overview for building on the Rootstock platform. The guide covers key DeFi primitives, security considerations, and token standards. It uses OpenZeppelin contracts and Hardhat for testing and deployment, following industry best practices. However, the documentation has several areas for improvement, especially regarding code execution accuracy, clarity of some explanations, and consistency in address placeholders. The JavaScript code snippets provided for testing failed to execute correctly, which is an important issue for a technical guide. Review: docs/04-resources/06-guides/defi-developer-guide/category.ymlThis file defines the category metadata for the Docusaurus-based documentation structure. Docs:
Recommendations:
Review: docs/04-resources/06-guides/defi-developer-guide/amm-basics.mdThis file introduces the basics of Automated Market Makers (AMMs) and guides the user through building a simple constant product AMM on Rootstock. Code:
Docs:
Tutorials:
Technical accuracy:
Code execution results:
Grammar and style:
Clarity and completeness:
Review: What is an AMM? (Subsection of amm-basics.md)This section defines an AMM and introduces the constant product formula. Docs:
Recommendations:
Review: Core Concepts (Subsection of amm-basics.md)This section lists and briefly explains key AMM terms. Docs:
Recommendations:
Review: Our SimpleAMM Contract (Subsection of amm-basics.md)This section outlines the features of the Code:
Docs:
Recommendations:
Review: 2. Adding Liquidity (Subsection of amm-basics.md)This section details the Code:
Docs:
Recommendations:
Review: 3. Removing Liquidity (Subsection of amm-basics.md)This section details the Code:
Docs:
Recommendations:
Review: 4. Swapping Tokens (Subsection of amm-basics.md)This section details the Code:
Docs:
Recommendations:
Review: 5. Computing Output Amount (Subsection of amm-basics.md)This section provides the formula and implementation for Code:
Docs:
Recommendations:
Review: 6. Utility Functions: sqrt and min (Subsection of amm-basics.md)This section includes implementations for Code:
Docs:
Recommendations:
Review: Integrating with a React Frontend (Subsection of amm-basics.md)This section provides a basic React component for interacting with the AMM. Code:
Docs:
Recommendations:
Review: Conclusion (Subsection of amm-basics.md)This section summarizes the learning outcomes of the AMM guide. Docs:
Recommendations:
Review: docs/04-resources/06-guides/defi-developer-guide/oracle-integration.mdThis file guides users on integrating oracles, focusing on Chainlink Price Feeds and VRF. Code:
Docs:
Tutorials:
Technical accuracy:
Code execution results:
Grammar and style:
Clarity and completeness:
Review: What You'll Learn (Subsection of oracle-integration.md)This section outlines the learning objectives for the oracle integration guide. Docs:
Recommendations:
Review: Supported Oracles on Rootstock (Subsection of oracle-integration.md)This section lists and briefly describes oracle solutions available on Rootstock. Docs:
Recommendations:
Review: Part 1: Getting Price Feeds with Chainlink (Subsection of oracle-integration.md)This section walks through integrating Chainlink Price Feeds. Docs:
Recommendations:
Review: How Chainlink VRF Works (Subsection of oracle-integration.md)This section explains the mechanism of Chainlink VRF. Docs:
Recommendations:
Review: Security Considerations for Oracles (Subsection of oracle-integration.md)This section points out important security practices for using oracles. Code:
Docs:
Recommendations:
Review: Conclusion (Subsection of oracle-integration.md)This section summarizes the key takeaways from the oracle integration guide. Docs:
Recommendations:
Review: Additional Resources (Subsection of oracle-integration.md)This section lists external links for further learning. Docs:
Recommendations:
Review: docs/04-resources/06-guides/defi-developer-guide/security-patterns.mdThis file is an important part of the guide, detailing key security practices for DeFi dApps. Code:
Docs:
Tutorials:
Technical accuracy:
Code execution results:
Grammar and style:
Clarity and completeness:
Review: 1. Reentrancy Protection (Subsection of security-patterns.md)This section focuses on reentrancy vulnerabilities and their mitigation. Code:
Docs:
Recommendations:
Review: Attack sequence: (Subsection of security-patterns.md under Reentrancy Protection)This details how a reentrancy attack unfolds. Docs:
Recommendations:
Review: Fixed version: (Subsection of security-patterns.md under Reentrancy Protection)This presents the secure Code:
Docs:
Recommendations:
Review: Reentrancy via Token Hooks (ERC-777) (Subsection of security-patterns.md under Reentrancy Protection)This section discusses reentrancy specific to ERC-777 token hooks. Docs:
Recommendations:
Review: Testing for Reentrancy (Subsection of security-patterns.md under Reentrancy Protection)This section provides a Solidity example of an Code:
Docs:
Recommendations:
Review: Then in your test: (Subsection of security-patterns.md under Reentrancy Protection)This provides a JavaScript test snippet for checking reentrancy. Code execution results:
Recommendations:
Review: 2. Access Control (Subsection of security-patterns.md)This section covers different access control mechanisms. Code:
Docs:
Recommendations:
Review: Key features: (Subsection of security-patterns.md under Access Control)This lists features of Docs:
Recommendations:
Review: Use a Multi-Sig for Admin Roles (Subsection of security-patterns.md under Access Control)This recommends using a multi-sig for important roles. Code:
Docs:
Recommendations:
Review: Emergency Pause (Subsection of security-patterns.md under Access Control)This suggests a dedicated pause role. Docs:
Recommendations:
Review: Revoking vs. Renouncing (Subsection of security-patterns.md under Access Control)This clarifies the difference between Docs:
Recommendations:
Review: Testing Access Control (Subsection of security-patterns.md under Access Control)This provides a JavaScript test snippet for access control. Code execution results:
Recommendations:
Review: Common Pitfalls (Subsection of security-patterns.md under Access Control)This lists common mistakes in implementing access control. Docs:
Recommendations:
Review: 3. Integer Overflow/Underflow (Subsection of security-patterns.md)This section explains integer overfl 💬 Comment posted via Revue - Documentation Review Tool |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| @@ -0,0 +1,8 @@ | |||
| label: 'Rootstock DeFi Developer Guide' | |||
There was a problem hiding this comment.
Hi @Janhavi312003,
This is a really detailed guide, however I would like that we make it more visible and move it to the new /use-cases section recently introduced, keep the security patterns, token standards, and defi overview etc in resources/guides/defi-101, and repurpose the other content like the AMM, oracles, etc as integration guides fit for the different sections within /use-cases: https://dev.rootstock.io/use-cases/
Here's the strategy:
Split the guide by deliverable, not by chapter. Reframe each file as: “By the end you will have X on Rootstock testnet (or mainnet where appropriate).” Deduplicate shared setup via links. Reserve the “DeFi 101” and multi-pattern security catalogs for a resources/guides/defi-101 single page, and use Use Cases for concrete integration walkthroughs that match the tone and structure of the existing Vaults SDK and LayerZero articles.
Full strategy here
| tags: [rsk, rootstock, defi, amm, uniswap, solidity] | ||
| --- | ||
|
|
||
| :::warning[Understanding AMMs] |
There was a problem hiding this comment.
Please move this warning before to header to before Why Rootstock for DeFi? section. Do same for the other pages.
| An Automated Market Maker (AMM) uses a mathematical formula to set asset prices. This guide builds a minimal constant product AMM (x*y=k). It is for educational purposes – always audit before mainnet. | ||
| ::: | ||
|
|
||
| # Building an AMM on Rootstock |
There was a problem hiding this comment.
| # Building an AMM on Rootstock |
| - **Slippage**: The difference between the expected price and the executed price due to pool size. Traders set a minimum amount out to protect against slippage. | ||
| - **Fee**: Usually 0.3% of the trade is added to the pool as a reward for liquidity providers. | ||
|
|
||
| ## Our SimpleAMM Contract |
There was a problem hiding this comment.
| ## Our SimpleAMM Contract | |
| ## SimpleAMM Contract |
| This guide assumes you have basic knowledge of Solidity, blockchain fundamentals, and the Rootstock ecosystem. You should have a development environment set up (Hardhat, Foundry, or Truffle) and a testnet wallet with tRBTC. | ||
| ::: | ||
|
|
||
| # Rootstock DeFi Developer Guide |
There was a problem hiding this comment.
| # Rootstock DeFi Developer Guide | |
| # Rootstock DeFi 101 |
|
|
||
| In this guide, we'll focus on **Chainlink** because it's the most widely adopted and easiest to get started with. | ||
|
|
||
| --- |
| | Rootstock Testnet | 31 | `0x76474B42B0c268a268fC6F0D9B0B6f6c3b3C8f` (BTC/USD) | | ||
|
|
||
| **Where to find the latest addresses:** | ||
| Visit the [Chainlink Rootstock Addresses](https://docs.chain.link/docs/rootstock-addresses/) page. It lists all available feeds for both mainnet and testnet. The addresses above are current examples, but always verify the latest addresses from official Chainlink documentation before deploying. |
There was a problem hiding this comment.
Link is broken: https://docs.chain.link/docs/rootstock-addresses/
| --- | ||
|
|
||
| :::tip[Why Oracles?] | ||
| DeFi protocols need real-world data like asset prices, exchange rates, or random numbers. But blockchains are isolated – they can't access external data directly. Oracles bridge this gap by bringing verified off-chain information onto the blockchain. Rootstock supports multiple decentralized oracle solutions, including **Chainlink** and **Tellor**. This guide focuses on Chainlink Price Feeds and VRF. |
There was a problem hiding this comment.
This is based off a mock implementation, kindly state that in the guide, currently Chainlink CCIP is only supported for Rootstock, not certain about price feeders and VRF
https://docs.chain.link/vrf/v2-5/supported-networks
https://docs.chain.link/data-feeds/price-feeds/addresses
| @@ -0,0 +1,903 @@ | |||
| --- | |||
| sidebar_position: 5 | |||
| sidebar_label: Security Patterns | |||
There was a problem hiding this comment.
Reframe the security patterns, and token standards article as a DeFi 101, what to look out for before deploying to production, and link to the other integration guides for the oracle, and AMM for specific integration examples to developers looking to build DeFi use cases.
There was a problem hiding this comment.
@owans – I have moved the AMM and oracle guides to /use-cases and created defi-101.md under resources/guides/. Should I delete the original defi-developer-guide folder to avoid duplication, or keep it with a deprecation notice?
| collapsed: false | ||
| link: | ||
| type: generated-index | ||
| title: 'Rootstock DeFi Developer Guide' |
There was a problem hiding this comment.
| title: 'Rootstock DeFi Developer Guide' | |
| title: 'Rootstock DeFi 101' |
|
@owans – I have pushed additional commits to this PR based on your review feedback. The changes include:
The original folder Question: Should I delete the old Thank you for your review. |
Title
Docs: Add Rootstock DeFi Developer Guide
Description
Purpose:
This PR adds a comprehensive Rootstock DeFi Developer Guide to help developers build and integrate DeFi applications on Rootstock. The ecosystem currently lacks a structured, beginner‑friendly resource covering the essential topics.
Context:
Rootstock’s DeFi space is expanding rapidly, but developers often have to piece together information from multiple sources. This guide consolidates practical workflows, example code, and best practices into one place.
Changes:
The following new files have been added under
docs/04-resources/06-guides/defi-developer-guide/:_category_.yml– defines the sidebar categoryindex.md– overview, prerequisites, and how to use the guide01-oracle-integration.md– Chainlink price feeds, VRF, and security02-amm-basics.md– building a simple constant‑product AMM03-token-standards.md– ERC‑20, ERC‑721, ERC‑4626, wRBTC, best practices04-security-patterns.md– reentrancy, access control, oracle manipulation, etc.All code examples have been tested on Rootstock testnet.
Screenshots/GIFs
N/A – this is a documentation change with no visual layout modifications.
Testing
Verification:
npm run buildlocally – no errors../01-oracle-integration.md) to ensure they work.Output: (if you want to paste the build log, include it here, otherwise you can keep this line generic)