**Weekly Update (Week 7) - BlockFuse Lab** Hey everyone, It's already Week 7 at BlockFuse Lab, and it's been an intense yet rewarding journey. This experience has demanded so much discipline, sacrifice, and continuous learning. As the saying goes, "Nothing good comes easy," and this week was a testament to that. ### **Exploring Uniswap & AMMs** We started the week diving into **Uniswap** and **Automated Market Makers (AMMs)**. We explored how liquidity pools function and how token swaps maintain the balance using the fundamental AMM formula: k = x * y where: - \( x \) and \( y \) represent the token reserves in the pool. - \( k \) remains constant during trades. Understanding liquidity provision was insightful, especially how liquidity providers contribute token pairs to earn fees from trades. ### **Mainnet Forking & Smart Contract Interactions** On Day 2, we explored **mainnet forking**, which allows us to simulate real blockchain environments. Using **impersonated accounts** with **USDC** and **DAI**, we executed transactions seamlessly. We interacted with Uniswap functions like: - `addLiquidity` - `removeLiquidity` - `swapExactTokensForTokens` Forking the mainnet enabled us to test transactions efficiently and understand how liquidity flows in real-world blockchain interactions. ## **Uniswap Liquidity Management** We also worked on smart contract interactions with **Uniswap**, handling liquidity provision and token swaps. ### **Core Functions:** 1. **Adding Liquidity** - Depositing token pairs into the Uniswap pool. 2. **Removing Liquidity** - Withdrawing funds from the pool. 3. **Swapping Tokens** - Exchanging one token for another at market rates. ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol"; contract UniswapLiquidity { IUniswapV2Router02 public uniswapRouter; constructor(address _router) { uniswapRouter = IUniswapV2Router02(_router); } function addLiquidity( address tokenA, address tokenB, uint256 amountA, uint256 amountB ) external { // Implementation for adding liquidity } function removeLiquidity(address tokenA, address tokenB) external { // Implementation for removing liquidity } function swapTokens(address tokenIn, address tokenOut, uint256 amountIn) external { // Implementation for token swaps } } ``` ### **Understanding Diamond Contracts** Day 3 was all about **staking contracts** in Solidity. We built a contract where users could stake tokens and earn rewards over time. We were introduced to **Diamond Contracts** and **delegate calls**, which make smart contracts modular and upgradeable. The key advantage of **delegate calls** in Diamond Contracts is that they allow a contract to execute logic stored in other contracts while maintaining the original contract’s storage, making upgrades and expansions seamless. --- ## **Gas Optimization Strategies in Smart Contracts** Optimizing gas usage is critical in Solidity development, especially when deploying contracts on Ethereum. This week, we explored several **gas optimization techniques** to reduce transaction costs and improve contract efficiency. From learning **Uniswap’s AMM model** to **mainnet forking** and **staking contracts**. The introduction to **Diamond Contracts**, **delegate calls**, and **gas optimization strategies** was fascinating, showing how we can build scalable and efficient smart contracts. Excited to see what next week holds! Stay tuned for more updates!