Loading video player...
In Part 1 of this tutorial, community contributor Aditii walks you through building the core smart contracts for a decentralized exchange (DEX) on Rootstock — Bitcoin's EVM-compatible smart contract layer. By the end of Part 1, you'll have written two Solidity contracts: ✅ RSKDex.sol — the core DEX contract with AMM logic, liquidity pools, token swaps, slippage protection, and a built-in price oracle ✅ MockERC20.sol — a test token contract for local development and testing ______ 🔧 WHAT YOU'LL LEARN - What a DEX is and how AMMs (Automated Market Makers) work - How the constant product formula (x * y = k) determines swap prices - DEX vs. CEX: key differences, trade-offs, and real examples (Uniswap) - AMM vs. Order Book models: on-chain vs. off-chain - Setting up a Foundry project with OpenZeppelin contracts - Building liquidity pool management: create, add, and remove liquidity - Implementing token swaps with fee handling and reentrancy protection - Building a TWAP price oracle for on-chain price tracking ______ Useful links - Foundry — https://getfoundry.sh - OpenZeppelin Contracts — https://docs.openzeppelin.com/contracts - Node.js — https://nodejs.org - MetaMask — https://metamask.io - Rootstock Testnet via Chainlist — https://chainlist.org (search "Rootstock Testnet") - Rootstock Testnet Faucet (free tRBTC) — https://faucet.rootstock.io - Rootstock Developer Docs — https://dev.rootstock.io - Rootstock RPC (Testnet) — https://public-node.testnet.rsk.co - Rootstock RPC (Mainnet) — https://public-node.rsk.co ______ This video is part of the From Devs to Devs series — technical tutorials created by community contributors through the Rootstock Hacktivator program. 👉 Want to create your own tutorial and earn rewards? Learn more at https://rootstock.io/hacktivator/ ______ Timestamps 00:00 Introduction to Rootstock and Decentralized Exchanges 06:26 Understanding Decentralized Exchanges (DEX) and Their Features 12:12 Types of DEX: AMM vs Order Book 14:04 Building a Decentralized Exchange on Rootstock 20:09 Smart Contract Development for DEX 29:26 Liquidity Management in DEX 37:55 Swapping Mechanism in DEX 40:00 Calculating Output Amounts and Token Transfers 41:19 Updating Reserves and Token Transfers 43:03 Implementing AMM Formulas and Calculating Amounts 44:22 Liquidity Checks and Calculating Amounts 46:06 Getting User Liquidity and Pool Information 47:30 Creating Functions for Adding Liquidity 49:03 Minting Liquidity Tokens and Updating Balances 51:01 Burning Liquidity Tokens and Updating Reserves 52:30 Updating Pool Information and Cumulative Prices 54:13 Finalizing the Smart Contract Implementation 55:42 Creating Mock ERC20 Token for Testing 01:00:30 Conclusion and Next Steps _______ #Rootstock #DEX #DeFi #Solidity #Foundry #Bitcoin #AMM #ERC20 #Web3 #SmartContracts #Uniswap #LiquidityPool #BlockchainDev