<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: amoweolubusayo</title>
    <description>The latest articles on DEV Community by amoweolubusayo (@amoweolubusayo).</description>
    <link>https://dev.to/amoweolubusayo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F807470%2F0071c600-932c-4af1-9b55-05250a5d6708.jpeg</url>
      <title>DEV Community: amoweolubusayo</title>
      <link>https://dev.to/amoweolubusayo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amoweolubusayo"/>
    <language>en</language>
    <item>
      <title>Navigating the Future of Tech: Should Software Engineers Focus on AI or Blockchain in 2023?</title>
      <dc:creator>amoweolubusayo</dc:creator>
      <pubDate>Thu, 26 Jan 2023 03:38:16 +0000</pubDate>
      <link>https://dev.to/amoweolubusayo/navigating-the-future-of-tech-should-software-engineers-focus-on-ai-or-blockchain-in-2023-591o</link>
      <guid>https://dev.to/amoweolubusayo/navigating-the-future-of-tech-should-software-engineers-focus-on-ai-or-blockchain-in-2023-591o</guid>
      <description>&lt;p&gt;As technology continues to evolve at a rapid pace, software engineers are faced with the decision of which emerging field to focus on in order to stay ahead of the curve. Two technologies that have gained significant traction in recent years are blockchain and AI. Both offer unique opportunities and challenges, and choosing which one to focus on in 2023 will depend on a variety of factors.&lt;/p&gt;

&lt;p&gt;Blockchain technology is best known for its use in the creation of digital currencies like Bitcoin, but it has the potential to be used in a wide range of applications beyond just finance. Blockchain technology is essentially a decentralized, digital ledger that can be used to record transactions across a network of computers. It is secure, transparent, and tamper-proof, making it well-suited for use in industries such as finance, supply chain management, and voting systems.&lt;/p&gt;

&lt;p&gt;AI, on the other hand, is a set of technologies that allow machines to learn and make decisions based on data. It encompasses a wide range of techniques, including machine learning, natural language processing, and computer vision. AI is being used in a wide range of applications such as self-driving cars, personal assistants, and medical diagnosis.&lt;/p&gt;

&lt;p&gt;So, which one should software engineers focus on in 2023? The answer is not clear cut, as it depends on the engineer's interest, expertise and the industry they are working in.&lt;/p&gt;

&lt;p&gt;If an engineer is interested in finance, supply chain management, or voting systems, then blockchain technology may be the best choice. Blockchain technology is still in its early stages and there is a lot of room for innovation and growth in this space. Companies such as ChainGuardian, ConsenSys, and BlockFi are building blockchain-based solutions in these areas and are worth keeping an eye on.&lt;/p&gt;

&lt;p&gt;On the other hand, if an engineer is interested in areas such as self-driving cars, personal assistants, or medical diagnosis, then AI may be the better choice. AI is being used in these areas to great effect and is expected to continue to be a major growth area in the coming years. Companies such as Google, Microsoft, and NVIDIA are investing heavily in AI and are worth keeping an eye on.&lt;/p&gt;

&lt;p&gt;Both blockchain and AI are promising technologies with a lot of potential. Software engineers should focus on the technology that aligns with their interests and expertise, as well as the industry they are working in. Keep an eye on the companies that are building solutions in these areas, as they are likely to be at the forefront of innovation and growth in the coming years.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>Building in the Bear Market: The Resilience of Decentralized Finance Projects</title>
      <dc:creator>amoweolubusayo</dc:creator>
      <pubDate>Thu, 26 Jan 2023 03:16:20 +0000</pubDate>
      <link>https://dev.to/amoweolubusayo/building-in-the-bear-market-the-resilience-of-decentralized-finance-projects-3pg4</link>
      <guid>https://dev.to/amoweolubusayo/building-in-the-bear-market-the-resilience-of-decentralized-finance-projects-3pg4</guid>
      <description>&lt;p&gt;Over the past few years, we've seen an explosion of DeFi projects and protocols, each with its own unique approach to creating a more open and accessible financial system. Some of the most popular DeFi projects include decentralized exchanges (DEXs) like Uniswap and SushiSwap, lending platforms like Aave and Compound, and yield farming protocols like Yearn Finance and Curve.&lt;/p&gt;

&lt;p&gt;Despite the bear market that has gripped the industry, many DeFi projects are still actively building and making progress on their platforms. In this article, we'll take a look at some of the most promising DeFi projects that are still making headway in the bear market, and explore what they're doing to continue building and growing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Aave&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fodkte0gwmw8mh2yvfivz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fodkte0gwmw8mh2yvfivz.png" alt="Aave" width="800" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the most promising DeFi projects still making progress in the bear market is Aave. Aave is a decentralized lending platform that allows users to borrow and lend cryptocurrencies in a trustless and decentralized manner. The platform is built on the Ethereum blockchain and uses smart contracts to facilitate lending and borrowing. Aave has a feature called "flash loans," which allows users to borrow funds for a very short period of time, typically just a few minutes. This feature has the potential to open up a whole new set of use cases for DeFi lending and borrowing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MakerDAO&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz8e4to3s22540zxur94z.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz8e4to3s22540zxur94z.jpeg" alt="MakerDAO" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
Another DeFi project that is still building in the bear market is MakerDAO. MakerDAO is a decentralized stablecoin platform that allows users to collateralize their assets and mint a stablecoin called DAI. The platform is also built on the Ethereum blockchain and uses smart contracts to facilitate the collateralization and minting process. MakerDAO has been making steady progress on its platform, and has a feature called "Multi-Collateral DAI (MCD)." This feature allows users to collateralize a wider range of assets, including real-world assets such as commodities and real estate.&lt;/p&gt;

&lt;p&gt;Uniswap&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbnka49txj8ua0xg2yjmx.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbnka49txj8ua0xg2yjmx.jpeg" alt="Uniswap" width="800" height="800"&gt;&lt;/a&gt;&lt;br&gt;
Uniswap is another DeFi project that is still building in the bear market. Uniswap is a decentralized exchange (DEX) that allows users to trade cryptocurrencies in a trustless and decentralized manner. The platform is also built on the Ethereum blockchain and uses smart contracts to facilitate trading. Uniswap has been making steady progress on its platform, and has a feature called "Uniswap v3" which has been designed to improve scalability and reduce the trading fees.&lt;/p&gt;

&lt;p&gt;In summary, the bear market has not stopped several DeFi projects from building and making progress. Aave, MakerDAO, and Uniswap are examples of projects that have been actively working on their platforms and launching new features. Despite the current market conditions, these projects have a strong community, great teams and a clear vision which make them promising projects to still look out for in the DeFi space.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>programming</category>
      <category>development</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Top 3 Optimistic Rollup L2 projects</title>
      <dc:creator>amoweolubusayo</dc:creator>
      <pubDate>Sun, 24 Jul 2022 05:06:00 +0000</pubDate>
      <link>https://dev.to/amoweolubusayo/top-3-optimistic-rollup-l2-projects-30g3</link>
      <guid>https://dev.to/amoweolubusayo/top-3-optimistic-rollup-l2-projects-30g3</guid>
      <description>&lt;p&gt;Before we go into discussing optimistic rollups, some base knowledge is needed. One of which is &lt;strong&gt;&lt;em&gt;blockchain scaling.&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Blockchain scaling
&lt;/h2&gt;

&lt;p&gt;Ethereum as a case study has grown to a level where the blockchain has hit some capacity limits. As a result, Ethereum network usage has become more expensive, necessitating scaling. The whole point of scaling actually is to increase transaction throughput (the number of transactions per second) and speed (faster finality) without compromising security or decentralization.&lt;/p&gt;

&lt;p&gt;Scaling a blockchain ecosystem can be done in one of two ways&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Increasing the capacity of transactions on the blockchain itself.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Modifying how you utilize the blockchain.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can read more about scaling &lt;a href="https://ethereum.org/en/developers/docs/scaling/"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second point highlighted involves users conducting the majority of their activity off-chain in an L2 ( &lt;a href="https://ethereum.org/en/layer-2/"&gt;Layer 2&lt;/a&gt; ) protocol rather than directly placing all activity on the blockchain. &lt;/p&gt;

&lt;h2&gt;
  
  
  Rollups
&lt;/h2&gt;

&lt;p&gt;Rollups is one of the types of layer-2 scaling. It can be refered to as a layer 2 hybrid scheme. The concept of Rollup is that Rollups keep some data per transaction on-chain while moving computation and state storage off-chain.&lt;/p&gt;

&lt;p&gt;Here is a diagram that shows how rollups work&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2QhD3LrY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1kk8bov9elq4crs353m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2QhD3LrY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1kk8bov9elq4crs353m.png" alt="Rollup" width="880" height="274"&gt;&lt;/a&gt;&lt;br&gt;
Source: &lt;a href="https://vitalik.ca/general/2021/01/05/rollup.html"&gt;vitalik.ca&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Rollup Types
&lt;/h2&gt;

&lt;p&gt;The two types of rollups are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Optimistic rollups: also called fraud proofs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ZK rollups: also called validity proofs&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Optimistic rollups
&lt;/h2&gt;

&lt;p&gt;In optimistic rollups, the rollup contract records each batch's hash and the history of each state's roots. Optimistic rollups by default don't perform any computation. Instead, they suggest the new state to Mainnet after a transaction. &lt;/p&gt;

&lt;h2&gt;
  
  
  Optimistic Rollup L2 projects
&lt;/h2&gt;

&lt;p&gt;Here are three projects that use the Optimistic Rollup Technology&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arbitrum&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Gx4DmI3a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hy9xbysshy2jv6nls67n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Gx4DmI3a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hy9xbysshy2jv6nls67n.png" alt="Arbitrum" width="256" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Arbitrum is a suite of Ethereum scaling solutions that enables high-throughput, low cost smart contracts while maintaining trustlessly security. Arbitrum supports all EVM language and natively supports all Ethereum tooling. Arbitrum Rollup differs from Ethereum in terms of price: transactions on Arbitrum only cost a small portion. It is quick and easy to port contracts from Ethereum to Arbitrum; no new software or code changes are required.&lt;/p&gt;

&lt;p&gt;Website: &lt;a href="https://arbitrum.io"&gt;https://arbitrum.io&lt;/a&gt;&lt;br&gt;
Documentation: &lt;a href="https://developer.offchainlabs.com"&gt;https://developer.offchainlabs.com&lt;/a&gt;&lt;br&gt;
Explorer: &lt;a href="https://explorer.arbitrum.io"&gt;https://explorer.arbitrum.io&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optimism&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iz0JrLVo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rux54lisr4zfcocxa6ma.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iz0JrLVo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rux54lisr4zfcocxa6ma.png" alt="Optimism" width="256" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Optimism is a Layer 2 scaling protocol for Ethereum applications thus it makes transactions cheap. Optimism is intended to be an expansion of Ethereum. The &lt;code&gt;CanonicalTransactionChain&lt;/code&gt; is a unique Ethereum smart contract that houses all Optimism blocks. Code in the &lt;code&gt;CanonicalTransactionChain&lt;/code&gt; ensures that new Ethereum transactions cannot change the list of existing blocks. Users can send any messages between smart contracts on Optimism and Ethereum. &lt;/p&gt;

&lt;p&gt;Website: &lt;a href="https://www.optimism.io"&gt;https://www.optimism.io&lt;/a&gt;&lt;br&gt;
Documentation: &lt;a href="https://community.optimism.io/docs"&gt;https://community.optimism.io/docs&lt;/a&gt;&lt;br&gt;
Explorer: &lt;a href="https://optimistic.etherscan.io"&gt;https://optimistic.etherscan.io&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Boba Network&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QcALLDIA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q8mpfdylfsz742mvmdgm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QcALLDIA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q8mpfdylfsz742mvmdgm.png" alt="Boba" width="256" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The foundation of Boba is actually the optimistic rollup created by Optimism. In addition to its emphasis on enhancing computing, Boba has it's own unique features such as: providing a swap-based system for quick exits from L2 to L1 (the standard exit period of rollups is 7 days) and an additional cross-chain messaging such as a message-relayer-fast.&lt;/p&gt;

&lt;p&gt;Website: &lt;a href="https://boba.network"&gt;https://boba.network&lt;/a&gt;&lt;br&gt;
Documentation: &lt;a href="https://docs.boba.network"&gt;https://docs.boba.network&lt;/a&gt;&lt;br&gt;
Explorer: &lt;a href="https://blockexplorer.boba.network"&gt;https://blockexplorer.boba.network&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A lot of developers are building on all 3 that I reviewed in this article. To get started with them, you can try out by deploying a contract. The following resources will help: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.offchainlabs.com/docs/contract_deployment"&gt;Contract Deployment using Arbritrum&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://community.optimism.io/docs/developers/build/basic-contract"&gt;Contract Deployment using Optimism&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.boba.network/for-developers/contract-deployment"&gt;Contract Deployment using Boba&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this article, we have discussed blockchain scaling, the need for it, the various ways of scaling, rollups, optimistic rollups and finally projects whose technology are based on optimistic rollups. &lt;/p&gt;

&lt;p&gt;I hope this article helped to keep things in perspective for someone out there. &lt;/p&gt;

&lt;p&gt;References&lt;/p&gt;

&lt;p&gt;&lt;a href="https://vitalik.ca/general/2021/01/05/rollup.html"&gt;https://vitalik.ca/general/2021/01/05/rollup.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://ethereum.org/en/developers/docs/scaling"&gt;https://ethereum.org/en/developers/docs/scaling&lt;/a&gt;&lt;br&gt;
&lt;a href="https://l2beat.com"&gt;https://l2beat.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>layer2</category>
      <category>optimisticrollup</category>
    </item>
    <item>
      <title>Staking. What happens behind the scenes. Brief code walkthrough and mathematical calculation</title>
      <dc:creator>amoweolubusayo</dc:creator>
      <pubDate>Sat, 11 Jun 2022 11:07:29 +0000</pubDate>
      <link>https://dev.to/amoweolubusayo/staking-what-happens-behind-the-scenes-brief-code-walkthrough-and-mathematical-calculation-1cd5</link>
      <guid>https://dev.to/amoweolubusayo/staking-what-happens-behind-the-scenes-brief-code-walkthrough-and-mathematical-calculation-1cd5</guid>
      <description>&lt;p&gt;Hello again. I'm here to talk DeFi. Have you ever had to stake? Wonder what happens behind the scenes? I have staked on platforms like Binance and I have always wondered how the calculations were done. Haven't staked before? No worries. I will give a brief description of what staking means. &lt;/p&gt;

&lt;p&gt;Think of staking as mining but using lesser resources. So like you know people mine bitcoin for example and are rewarded for it, for humor purposes only, some people also mine the famous PI in hope for rewards. Staking works similarly but instead of mining, you lock your crypto in order to receive rewards. Your locked crypto helps to secure and assist in operations of a blockchain network. &lt;/p&gt;

&lt;p&gt;After doing some research, I got to know about what I would call The MasterChef Algorithm. &lt;/p&gt;

&lt;p&gt;In this article, I will be taking you through &lt;a href="https://github.com/pancakeswap/pancake-farm/blob/master/contracts/MasterChef.sol"&gt;Pancakeswap's MasterChef contract&lt;/a&gt; briefly as well as the basic Mathematical calculation involved in staking. &lt;/p&gt;

&lt;p&gt;As it turns out, most staking contracts implement the MasterChef contract. Now, let's proceed to understanding basic variable meanings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;contract&lt;/span&gt; &lt;span class="nx"&gt;MasterChef&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;Ownable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;using&lt;/span&gt; &lt;span class="nx"&gt;SafeMath&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;uint256&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;using&lt;/span&gt; &lt;span class="nx"&gt;SafeBEP20&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;IBEP20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;struct&lt;/span&gt; &lt;span class="nx"&gt;UserInfo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;rewardDebt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;

 &lt;span class="nx"&gt;struct&lt;/span&gt; &lt;span class="nx"&gt;PoolInfo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;IBEP20&lt;/span&gt; &lt;span class="nx"&gt;lpToken&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;           
        &lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;allocPoint&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    
        &lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;lastRewardBlock&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;accCakePerShare&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this code above, there is a struct called&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;UserInfo&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;. This represents a user who has come in to stake.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;unit256&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;
&lt;span class="nx"&gt;unit256&lt;/span&gt; &lt;span class="nx"&gt;rewardDebt&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;amount&lt;/code&gt; here stands for how many Liquidity Pool(LP) tokens the user has provided. &lt;/p&gt;

&lt;p&gt;Notice we also have &lt;code&gt;rewardDebt&lt;/code&gt;. Reward debt is basically the reward that a user isn't entitled to. &lt;/p&gt;

&lt;p&gt;The next struct is the&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;PoolInfo&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This stands for the information of each pool. This pool is where tokens are locked in a smart contract&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;IBEP20&lt;/span&gt; &lt;span class="nx"&gt;lpToken&lt;/span&gt;
&lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;allocPoint&lt;/span&gt;
&lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;lastRewardBlock&lt;/span&gt;
&lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;accCakePerShare&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;lpToken&lt;/code&gt; here stands for the contract address of LP token.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;allocPoint&lt;/code&gt;here means that: How many tokens (which in this case is CAKE) is to be distributed to this pool? How many allocation points is assigned to this pool?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;lastRewardBlock&lt;/code&gt; here means that: What block number was the token (CAKE) distributed to last?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;accCakePerShare&lt;/code&gt; here means the Accumulated token (CAKEs) per share&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;enterStaking&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;PoolInfo&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt; &lt;span class="nx"&gt;pool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;poolInfo&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;UserInfo&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;userInfo&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;updatePool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;pending&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mul&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;accCakePerShare&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;e12&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rewardDebt&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pending&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
               &lt;span class="nx"&gt;safeCakeTransfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pending&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_amount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lpToken&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;safeTransferFrom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rewardDebt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mul&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;accCakePerShare&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;e12&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function above is a call to stake CAKE tokens to MasterChef and this function below is a call to Withdraw CAKE tokens from STAKING.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;leaveStaking&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;PoolInfo&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt; &lt;span class="nx"&gt;pool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;poolInfo&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;UserInfo&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;userInfo&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;withdraw: not good&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;updatePool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;pending&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mul&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;accCakePerShare&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;e12&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rewardDebt&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pending&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;safeCakeTransfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pending&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_amount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lpToken&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;safeTransfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rewardDebt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mul&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;accCakePerShare&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;e12&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nx"&gt;syrup&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;burn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;emit&lt;/span&gt; &lt;span class="nx"&gt;Withdraw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this code, let's do a little simulation.&lt;/p&gt;

&lt;p&gt;Assuming that on every block, the reward a user can get is $1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;RewardsPerBlock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="nx"&gt;A&lt;/span&gt; &lt;span class="nx"&gt;deposits&lt;/span&gt; &lt;span class="nx"&gt;$100&lt;/span&gt; &lt;span class="nx"&gt;on&lt;/span&gt; &lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="nx"&gt;B&lt;/span&gt; &lt;span class="nx"&gt;deposits&lt;/span&gt; &lt;span class="nx"&gt;$400&lt;/span&gt; &lt;span class="nx"&gt;on&lt;/span&gt; &lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We need to note these variables&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;RewardsPerBlock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Reward&lt;/span&gt; &lt;span class="nx"&gt;you&lt;/span&gt; &lt;span class="nx"&gt;can&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nx"&gt;per&lt;/span&gt; &lt;span class="nx"&gt;block&lt;/span&gt;
&lt;span class="nx"&gt;NumberOfBlocks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;blocks&lt;/span&gt;
&lt;span class="nx"&gt;TotalTokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Total&lt;/span&gt; &lt;span class="nx"&gt;Tokens&lt;/span&gt; &lt;span class="nx"&gt;present&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;block&lt;/span&gt; 
&lt;span class="nx"&gt;DepositUserA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;How&lt;/span&gt; &lt;span class="nx"&gt;much&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="nx"&gt;A&lt;/span&gt; &lt;span class="nx"&gt;deposited&lt;/span&gt;
&lt;span class="nx"&gt;ShareUserA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Share&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="nx"&gt;A&lt;/span&gt;
&lt;span class="nx"&gt;AccumulatedRewardUserA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Accumulated&lt;/span&gt; &lt;span class="nx"&gt;Reward&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="nx"&gt;A&lt;/span&gt;

&lt;span class="nx"&gt;ShareUserA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;DepositUserA&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;TotalTokens&lt;/span&gt;
&lt;span class="nx"&gt;AccumulatedRewardUserA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;RewardsPerBlock&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;NumberOfBlocks&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;ShareUserA&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;AccumulatedRewardUserA&lt;/span&gt; &lt;span class="nx"&gt;previously&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From block 0 to block 10, User A gets 100% of their rewards, which is calculated like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Block&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;Block&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; 

&lt;span class="nx"&gt;RewardsPerBlock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$1&lt;/span&gt;
&lt;span class="nx"&gt;NumberOfBlocks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="nx"&gt;TotalTokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$100&lt;/span&gt;
&lt;span class="nx"&gt;DepositUserA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$100&lt;/span&gt;
&lt;span class="nx"&gt;ShareUserA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="nx"&gt;AccumulatedRewardUserA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$10&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now on block 10, a new User B who is just joining the pool deposits $400. It might interest you to know that User B will also get 100% of rewards from block 0 to 10. However, it becomes a debt. Some other contract use timestamp instead of a debt. If User B decides to harvest at block 15, User B's reward will be calculated as&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Reward(Block 10 to Block 15) - Reward(Block 0 to Block 10)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The Reward(Block 0 to Block 10) in this case is the &lt;code&gt;rewardDebt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's move to block 15. At block 15, User A wants to harvest their reward. &lt;/p&gt;

&lt;p&gt;From block 10 to block 15, can you guess how much reward User A will get?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Block&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;Block&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt; 
&lt;span class="nx"&gt;Remember&lt;/span&gt; &lt;span class="nx"&gt;there&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="nx"&gt;B&lt;/span&gt; 

&lt;span class="nx"&gt;RewardsPerBlock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$1&lt;/span&gt;
&lt;span class="nx"&gt;NumberOfBlocks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="nx"&gt;TotalTokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$100&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;$400&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$500&lt;/span&gt;
&lt;span class="nx"&gt;DepositUserA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$100&lt;/span&gt;
&lt;span class="nx"&gt;ShareUserA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; 
&lt;span class="nx"&gt;AccumulatedRewardUserA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;$10&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$11&lt;/span&gt;


&lt;span class="nx"&gt;DepositUserB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$400&lt;/span&gt;
&lt;span class="nx"&gt;ShareUserB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="nx"&gt;AccumulatedRewardUserB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$4&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;UserA will now 'harvest' the &lt;code&gt;AccumulatedRewardUserA&lt;/code&gt; thus getting $11. &lt;/p&gt;

&lt;p&gt;After harvest, the pool needs to balance so AccumulatedRewardUserA = $0&lt;/p&gt;

&lt;p&gt;Let's move to block 20. At block 20, User B wants to harvest their reward.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Block&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;Block&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; 

&lt;span class="nx"&gt;RewardsPerBlock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$1&lt;/span&gt;
&lt;span class="nx"&gt;NumberOfBlocks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="nx"&gt;TotalTokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$100&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;$400&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$500&lt;/span&gt;
&lt;span class="nx"&gt;DepositUserB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$400&lt;/span&gt;
&lt;span class="nx"&gt;ShareUserB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; 
&lt;span class="nx"&gt;AccumulatedRewardUserB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$4&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;$4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$8&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;UserB will now 'harvest' the &lt;code&gt;AccumulatedRewardUserB&lt;/code&gt; thus getting $8. &lt;/p&gt;

&lt;p&gt;After harvest, the pool needs to balance so AccumulatedRewardUserB = $0&lt;/p&gt;

&lt;p&gt;Let's move to block 30. At block 30, Both User A and User B wants to harvest their reward.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Block&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;Block&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt; 

&lt;span class="nx"&gt;RewardsPerBlock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$1&lt;/span&gt;
&lt;span class="nx"&gt;NumberOfBlocks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="nx"&gt;TotalTokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$100&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;$400&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$500&lt;/span&gt;

&lt;span class="nx"&gt;DepositUserA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$100&lt;/span&gt;
&lt;span class="nx"&gt;ShareUserA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; 
&lt;span class="nx"&gt;AccumulatedRewardUserA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$2&lt;/span&gt; 

&lt;span class="nx"&gt;DepositUserB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$400&lt;/span&gt;
&lt;span class="nx"&gt;ShareUserB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; 
&lt;span class="nx"&gt;AccumulatedRewardUserB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$8&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;The&lt;/span&gt; &lt;span class="nx"&gt;Total&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;harvested&lt;/span&gt; &lt;span class="nx"&gt;reward&lt;/span&gt;
&lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="nx"&gt;A&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;AccumulatedRewardUserA&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Block&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;AccumulatedRewardUserA&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Block&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="nx"&gt;A&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$11&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;$2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$13&lt;/span&gt;

&lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="nx"&gt;B&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;AccumulatedRewardUserB&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Block&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;AccumulatedRewardUserB&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Block&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="nx"&gt;B&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$8&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;$8&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$16&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;User A harvested $13 as reward in total&lt;br&gt;
User B harvested $16 as reward in total&lt;/p&gt;

&lt;p&gt;With this base knowledge, you can chose to add your own customizable feature to your DeFi app. &lt;/p&gt;

&lt;p&gt;This article is just gives the basic overview of the Algorithm. You will get more insight by implementing a contract of your own. I encourage you to do that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Words
&lt;/h2&gt;

&lt;p&gt;I hope this makes sense and you now understand staking better. Feel free to drop a comment or question. I'm willing to interact. &lt;/p&gt;

&lt;p&gt;References&lt;br&gt;
&lt;a href="https://dev.to/heymarkkop/understanding-sushiswaps-masterchef-staking-rewards-1m6f"&gt;https://dev.to/heymarkkop/understanding-sushiswaps-masterchef-staking-rewards-1m6f&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/pancakeswap/pancake-farm/blob/master/contracts/MasterChef.sol"&gt;https://github.com/pancakeswap/pancake-farm/blob/master/contracts/MasterChef.sol&lt;/a&gt;&lt;/p&gt;

</description>
      <category>web3</category>
      <category>defi</category>
      <category>blockchain</category>
      <category>staking</category>
    </item>
    <item>
      <title>Front running in DeFi and protective measures</title>
      <dc:creator>amoweolubusayo</dc:creator>
      <pubDate>Sat, 04 Jun 2022 12:29:58 +0000</pubDate>
      <link>https://dev.to/amoweolubusayo/front-running-in-defi-and-protective-measures-36o1</link>
      <guid>https://dev.to/amoweolubusayo/front-running-in-defi-and-protective-measures-36o1</guid>
      <description>&lt;p&gt;So, I started looking at the DeFi space. I have found it interesting so far understanding the technicalities involved in trading especially on Dexs.&lt;/p&gt;

&lt;p&gt;This article however will be a less technical which is a little drift from my recent articles as I will be concentrating on one of the common problems traders face using exchanges. &lt;/p&gt;

&lt;p&gt;I hope you find this insightful!&lt;/p&gt;

&lt;h2&gt;
  
  
  Preamble
&lt;/h2&gt;

&lt;p&gt;Have you ever experienced a scenario where you received less than you expected after a trade? Yes? You might just have been front runned. &lt;/p&gt;

&lt;p&gt;In this article, I would talk about front running, how to be protected from front running as well as what protocols can do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Front running in DeFi
&lt;/h2&gt;

&lt;p&gt;Front running is the act of taking advantage of advanced information or prior knowledge of transactions to buy or sell assets. A front runner capitalizes on the way transactions are ordered within a block to take out profit from another trader thereby leading to losses for this trader involved. &lt;/p&gt;

&lt;p&gt;On the Ethereum blockchain, there is the problem of front-running where anyone who runs a full-node Ethereum client can see unconfirmed transactions and send transactions with a higher gas price. Actually, front-runners do not even need to run a full node to see transactions. They can have a bot that monitors pending transactions in the mempool or use any infrastructure such as the ones I wrote in this article here &lt;a href="https://dev.to/amoweolubusayo/top-5-web3-infrastructure-providers-you-should-know-48je"&gt;Top 5 Web3 infrastructure&lt;/a&gt;. Bots are also able to quote a higher gas price. Bots operate in milliseconds so imagine the speed in reading a transaction from the memory pool, calculating the optimal transaction size, configuring transactions and then executing them.&lt;/p&gt;

&lt;p&gt;Sadly, front running is such a common practice on Ethereum-based DEXs.&lt;/p&gt;

&lt;h2&gt;
  
  
  How can we be protected from Front running?
&lt;/h2&gt;

&lt;p&gt;Players involved: DEXs, users, protocols.&lt;/p&gt;

&lt;h2&gt;
  
  
  What can DEXs do?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Fast Matching orders:&lt;/em&gt; Orders can be matched in every block with very fast block times so that there is very little room for front-running to happen&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Provide off-chain privacy:&lt;/em&gt; Privacy should be taken seriously in markets such as DeFi.&lt;/p&gt;

&lt;h2&gt;
  
  
  What can users do?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Overpay on Gas:&lt;/em&gt; As a user, try to go for the ‘fast’ gas option on your wallet of choice, this way there would be no time for front runners to formulate an order. If you wish to place a large value order, this approach is recommended.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Place value smaller orders:&lt;/em&gt; You can also place smaller value orders. Front runners take into consideration gas fees on both entering and exiting the market, so you are most likely safe by trading low cash volume.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I think protocols can do on the long run
&lt;/h2&gt;

&lt;p&gt;Protocols should consider building untraceable blockchain node infrastructure such that node requests are somewhat hidden from people who wish to manipulate the market.&lt;/p&gt;

&lt;p&gt;They can do this by building tools that guarantees no monitoring of blockchain requests. In traditional blockchain, the requests to node providers can be tracked and monitored thus compromising privacy and giving front runners an unfair advantage from your metadata. Protocols can look into building tools with 0 monitoring of blockchain requests. &lt;/p&gt;

&lt;p&gt;Any other thoughts are welcome too! Kindly comment below. &lt;/p&gt;

&lt;p&gt;I would be posting more DeFi- related articles in the coming weeks/months. Stay tuned…&lt;/p&gt;

</description>
      <category>web3</category>
      <category>blockchain</category>
      <category>defi</category>
      <category>dex</category>
    </item>
    <item>
      <title>Upgrading Smart Contracts using OpenZeppelin Upgrade Plugin</title>
      <dc:creator>amoweolubusayo</dc:creator>
      <pubDate>Sat, 21 May 2022 16:41:43 +0000</pubDate>
      <link>https://dev.to/amoweolubusayo/upgrading-smart-contracts-using-openzeppelin-upgrades-plugins-5el4</link>
      <guid>https://dev.to/amoweolubusayo/upgrading-smart-contracts-using-openzeppelin-upgrades-plugins-5el4</guid>
      <description>&lt;h2&gt;
  
  
  A bit of intro
&lt;/h2&gt;

&lt;p&gt;When I came across upgradeable contracts, I was taken aback a bit. &lt;em&gt;Upgrade&lt;/em&gt;? Why is upgrade a topic when smart contracts are designed to be immutable by default? &lt;em&gt;Once a contract is created on the blockchain, there is no way to change it&lt;/em&gt;. You might have the same questions/thoughts as I had or even more. While researching how to write an upgradeable contract, I had a bit of a challenge understanding and finding a well-explanatory guide which is why I will be discussing some fundamentals in this article alongside showing you how to write a simple upgradeable smart contract using the openzepplin plugin.  &lt;/p&gt;

&lt;h2&gt;
  
  
  The Why
&lt;/h2&gt;

&lt;p&gt;Some scenarios call for modification of contracts. Relating it to regular daily lives, two parties who have signed a contract can decide to change agreements, perhaps they have to remove some terms or add some more or fix mistakes. As long as they both consent to it, it can be changed. On a blockchain such as Ethereum, it's possible that a bug was found in a smart contract that has already been deployed to production or more functionalities are just required. It could be anything really. It definitely calls for an upgrade. &lt;/p&gt;

&lt;h2&gt;
  
  
  OpenZeppelin
&lt;/h2&gt;

&lt;p&gt;OpenZeppelin is the leading company when it comes to securing products, automating, and operating decentralized applications. They protect leading organizations by performing security audits on their systems and products. They have a library of modular, reusable, secure smart contracts for the Ethereum network, written in Solidity. Thanks to the &lt;a href="https://docs.openzeppelin.com/upgrades-plugins/1.x/"&gt;OpenZeppelin Upgrades Plugin&lt;/a&gt;, it's quite easy to modify a contract while still preserving important things like address, state, and balance.&lt;/p&gt;

&lt;h2&gt;
  
  
  The How
&lt;/h2&gt;

&lt;p&gt;Smart contracts can be upgraded using a proxy. Basically, there are two contracts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Contract 1 (proxy/point of access): This contract is a proxy or a wrapper that will be interacted with directly. It is also in charge of sending transactions to and fro the second contract that I would be talking about next.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Contract 2 (logic contract): This contract contains the logic.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;One thing to note is that the proxy never changes, however, you can swap the logic contract for another contract meaning that the access point/proxy can point to a different logic contract (in other words, it gets upgraded). This is illustrated below&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vpo_LvrA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/69888law0eamvv13enjq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vpo_LvrA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/69888law0eamvv13enjq.png" alt="Proxy picture" width="880" height="230"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Source:&lt;/em&gt; &lt;em&gt;&lt;a href="https://docs.openzeppelin.com/upgrades-plugins/1.x/proxies#upgrading-via-the-proxy-pattern"&gt;https://docs.openzeppelin.com/upgrades-plugins/1.x/proxies#upgrading-via-the-proxy-pattern&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To learn more about the proxy concepts, visit the &lt;a href="https://docs.openzeppelin.com/upgrades-plugins/1.x/proxies"&gt;openzepplin proxy upgrade pattern docs page&lt;/a&gt; and &lt;a href="https://docs.openzeppelin.com/contracts/4.x/api/proxy"&gt;openzepplin proxy page&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Upgradeability Patterns
&lt;/h2&gt;

&lt;p&gt;We have several upgradeability patterns. Listed below are four patterns&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;UUPS proxy: EIP1822&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Transparent proxy: EIP1967 (We would be focusing on this in this article)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Diamond Storage: EIP2355&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Eternal Storage: ERC930&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Transparent Proxy (EIP1967)
&lt;/h2&gt;

&lt;p&gt;Transparent proxies include the upgrade and admin logic in the proxy itself. I would refer to the admin as the owner of the contract that initiates the first upgrade. &lt;/p&gt;

&lt;p&gt;Using the transparent proxy, any account other than the admin that calls the proxy will have their calls forwarded to the implementation. In the same vein, if the admin calls the proxy, it can access the admin functions, but the admin calls will never be forwarded to the implementation. &lt;/p&gt;

&lt;p&gt;In summary, it's best for the admin to be a dedicated account only used for its purpose which is obviously &lt;em&gt;to be an admin&lt;/em&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Practical Steps
&lt;/h2&gt;

&lt;p&gt;Prerequisite: knowledge of how to set up dev environment and how to write smart contracts. More info &lt;a href="https://docs.openzeppelin.com/learn/developing-smart-contracts"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's write an upgradeable contract! We will be openzepplin's hardhat-upgrades plugin. To install, simply run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev @openzeppelin/hardhat-upgrades @nomiclabs/hardhat-ethers ethers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your &lt;code&gt;hardhat.config&lt;/code&gt; file, you need to load it in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// js
require('@openzeppelin/hardhat-upgrades');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ts
import '@openzeppelin/hardhat-upgrades';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;I will be using js for this article&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Your &lt;code&gt;hardhat.config.js&lt;/code&gt; file should be similar to this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require("@nomiclabs/hardhat-ethers");
require("@openzeppelin/hardhat-upgrades");
require("@nomiclabs/hardhat-etherscan");

//Using alchemy because I intend to deploy on goerli testnet, an apikey is required
//The mnemonic is your account's mnemonic
//if you intend to verify your contracts, you need to open an account on etherscan and copy the apikey
//all important keys should not be exposed, it can be kept in a secret.json file and added to gitignore

const { alchemyApiKey, mnemonic } = require("./secrets.json");

module.exports = {
  networks: {
    goerli: {
      url: `https://eth-goerli.alchemyapi.io/v2/${alchemyApiKey}`,
      accounts: { mnemonic: mnemonic },
    },
  },
  etherscan: {
    apiKey: "YOUR_API_KEY",
  },
  solidity: "0.8.4",
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Contract 1 (&lt;code&gt;contracts/Atm.sol&lt;/code&gt;) (proxy contract)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your contracts folder, create a new &lt;code&gt;.sol&lt;/code&gt; file. In this article, I would be simulating an atm/bank. So, create &lt;code&gt;Atm.sol&lt;/code&gt;. The code should look similar to this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Atm {

    // Declare state variables of the contract
    uint256 bankBalances;

    // Allow the owner to deposit money into the account
    function deposit(uint256 amount) public {
        bankBalances += amount;
    }
    function getBalance() public view returns (uint256) {
        return bankBalances;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Test Contract&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Test your contract in &lt;code&gt;test/Atm-test-js&lt;/code&gt; as illustrated below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("Atm", function () {
  before(async function () {
    this.Atm = await ethers.getContractFactory("Atm");
  });

  beforeEach(async function () {
    this.atm = await this.Atm.deploy();
    await this.atm.deployed();

    it("", async function () {});
    await this.atm.deposit(1000);
    expect((await this.atm.getBalance()).toString()).to.equal("1000");
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To test, run this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx hardhat test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Deploy Contract&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;!Important:&lt;/em&gt; In order to be able to upgrade the Atm contract, we need to first deploy it as an upgradeable contract. It is different from the deployment procedure we are used to. We are initializing that the start balance be 0. The script uses the &lt;code&gt;deployProxy&lt;/code&gt; method which is from the plugin. &lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;deploy-atm.js&lt;/code&gt; script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { ethers, upgrades } = require("hardhat");

async function main() {
  const Atm = await ethers.getContractFactory("Atm");
  console.log("Deploying Atm...");
  const atm = await upgrades.deployProxy(Atm, [0], {
    initializer: "deposit",
  });

  console.log(atm.address, " atm(proxy) address");
}

main().catch((error) =&amp;gt; {
  console.error(error);
  process.exitCode = 1;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can decide to test this as well. If you wish to test, your test file should be similar to this&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Script&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { expect } = require("chai");
const { ethers, upgrades } = require("hardhat");
const { Contract, BigNumber } = "ethers";

describe("Atm (proxy)", function () {
  let box = Contract;

  beforeEach(async function () {
    const Atm = await ethers.getContractFactory("Atm");
    //initilize with 0
    atm = await upgrades.deployProxy(Atm, [0], { initializer: "deposit" });
  });

  it("should return available balance", async function () {

    expect((await atm.getBalance()).toString()).to.equal("0");

    await atm.deposit(1000);
    expect((await atm.getBalance()).toString()).to.equal("1000");
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After confirming tests,&lt;/p&gt;

&lt;p&gt;Let's deploy to local first, we use the run command and deploy the Atm contract to dev network.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npx hardhat run --network localhost scripts/deploy-atm.js
Deploying Atm...
0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9  atm(proxy) address
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, we have successfully deployed and have our proxy and admin address.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Contract 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We want to add a new feature to our contract, a simple feature which is to include an add function that adds 500 to our balance.&lt;/p&gt;

&lt;p&gt;Create &lt;code&gt;contracts/AtmV2.sol&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./Atm.sol";

contract AtmV2 is Atm{
    // adds to the balance by 500
    function add() public {
        deposit(getBalance()+500);
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Test Contract&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Refer to how we tested Contract 1 and basically follow same logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Upgrade Contract&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now is the time to use our proxy/access point address. We would be using the &lt;code&gt;upgradeProxy and 'getAdmin'&lt;/code&gt; methods from the plugin. Recall our proxy address from our deployment console above as we would be needing it here. &lt;/p&gt;

&lt;p&gt;Create &lt;code&gt;scripts/upgrade-atmV2.js&lt;/code&gt;. Your script should look similar to this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { ethers, upgrades } = require("hardhat");

const proxyAddress = "YOUR_PROXY_ADDRESS_FROM_DEPLOYMENT";

async function main() {
  console.log(proxyAddress, " original Atm(proxy) address");
  const AtmV2 = await ethers.getContractFactory("AtmV2");
  console.log("upgrade to AtmV2...");
  const atmV2 = await upgrades.upgradeProxy(proxyAddress, AtmV2);
  console.log(atmV2.address, " AtmV2 address(should be the same)");
  console.log(
    await upgrades.erc1967.getAdminAddress(atmV2.address),
    "Proxy Admin"
  );
console.log('Atm upgraded');
}

main().catch((error) =&amp;gt; {
  console.error(error);
  process.exitCode = 1;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Test script&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;scripts/AtmProxyV2-test.js&lt;/code&gt;. It should look similar to this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { expect } = require("chai");
const { ethers, upgrades } = require("hardhat");
const { Contract, BigNumber } = "ethers";

describe("Atm (proxy) V2", function () {
  let atm = Contract;
  let atmV2 = Contract;

  beforeEach(async function () {
    const Atm = await ethers.getContractFactory("Atm");
    const AtmV2 = await ethers.getContractFactory("AtmV2");

    //initilize with 0
    atm = await upgrades.deployProxy(Atm, [0], { initializer: "deposit" });

    atmV2 = await upgrades.upgradeProxy(atm.address, AtmV2);
  });

  it("should get balance and addition correctly", async function () {
    expect((await atmV2.getBalance()).toString()).to.equal("0");

    await atmV2.add();
    //result = 0 + 500 = 500
    expect((await atmV2.getBalance()).toString()).to.equal("500");
    //balance is now 500, so add 100;
    await atmV2.deposit(100);
    //result = 500 + 100 = 600
    expect((await atmV2.getBalance()).toString()).to.equal("600");
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After confirming tests,&lt;/p&gt;

&lt;p&gt;Let's deploy our newly added contract with additional feature, we use the run command and deploy the AtmV2 contract to dev network.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx hardhat run --network localhost scripts/upgrade-atmV2.js
Compilation finished successfully
upgrade to AtmV2...
0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9  AtmV2 address(should be the same)
0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512  Proxy Admin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To deploy on goerli, simply replace&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx hardhat run --network localhost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx hardhat run --network goerli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There you have it, check for your addresses on &lt;a href="https://goerli.etherscan.io/"&gt;Goerli Explorer&lt;/a&gt; and verify it. &lt;/p&gt;

&lt;p&gt;For a view of all contracts, you can check out my contracts at&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://goerli.etherscan.io/address/0xB8E702904efb9D0DCC3601135922e870F9a10fF4"&gt;Proxy(Contract 1)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://goerli.etherscan.io/address/0xdA10DF35A73984de06d0B70870A98650a4316982"&gt;Logic Implementation(Contract 2)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://goerli.etherscan.io/address/0x800F80196224E001C80e5BfD7d5EC7c65Bfb1f04"&gt;Proxy Admin&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;While it is a fast approach to use the openzepplin plugin and it varies across teams, a better way to understand and do upgrades is to copy the &lt;a href="https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts/proxy/transparent"&gt;transparency proxy sol&lt;/a&gt; files and related sol files from openzepplin's into your project. This protects you from upstream attacks. &lt;/p&gt;

&lt;p&gt;This comes to the end of this article. Hope you learnt a thing or two. I would appreciate feedbacks as well! Kindly leave a comment. Happy building!&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable"&gt;https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts/proxy"&gt;https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts/proxy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/yakult/tutorial-write-upgradeable-smart-contract-proxy-contract-with-openzeppelin-1916"&gt;https://dev.to/yakult/tutorial-write-upgradeable-smart-contract-proxy-contract-with-openzeppelin-1916&lt;/a&gt;&lt;/p&gt;

</description>
      <category>smartcontracts</category>
      <category>web3</category>
      <category>blockchain</category>
      <category>solidity</category>
    </item>
    <item>
      <title>Top 5 Web3 Infrastructure providers you should know</title>
      <dc:creator>amoweolubusayo</dc:creator>
      <pubDate>Sun, 08 May 2022 12:22:14 +0000</pubDate>
      <link>https://dev.to/amoweolubusayo/top-5-web3-infrastructure-providers-you-should-know-48je</link>
      <guid>https://dev.to/amoweolubusayo/top-5-web3-infrastructure-providers-you-should-know-48je</guid>
      <description>&lt;h2&gt;
  
  
  Infrastructure is essential
&lt;/h2&gt;

&lt;p&gt;Infrastructure is simply the building blocks or foundation of any system. Complex systems need a suitable infrastructure to function efficiently. Infrastructure is a very important topic in Web3. &lt;/p&gt;

&lt;p&gt;Building on blockchains such as Ethereum, Polygon, Avalanche, and Fantom requires a lot of resources if one intends to set up their own infrastructure from scratch. For example, you would need to set up a node which can be expensive and time-consuming. &lt;/p&gt;

&lt;p&gt;Today, we now have infrastructure providers that provide developer tools, APIs, node functionalities, and data access so that developers/builders are able to concentrate more on their products and are able to ship their dApps faster. On your preferred blockchain, you get to easily build and operate full nodes and validator nodes usually in pretty simple steps.&lt;/p&gt;

&lt;p&gt;This topic was inspired by my personal usage and interaction with some infrastructure providers. In no particular order, here is a review of some of the best Web3 infrastructure providers alongside their features, products, and pricing.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://infura.io/" rel="noopener noreferrer"&gt;Infura&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4hxib8eswpl5g6oun2l1.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4hxib8eswpl5g6oun2l1.jpeg" alt="Infura logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Infura simplifies blockchain development by bringing all of your tools together in one place: Ethereum Nodes, Eth2 Nodes, Transaction Relaying, Layer 2 Networks, IPFS, Filecoin, and more. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Infura Products&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Ethereum API&lt;/em&gt;&lt;/strong&gt;: The Infura API suite gives rapid access to the Ethereum network through HTTPS and WebSockets.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;IPFS API and Dedicated Gateway&lt;/em&gt;&lt;/strong&gt;: Infura's IPFS API and dedicated gateway, designed for speed and simplicity, links apps of all sizes to distributed secure storage, paving the path for more resilience online.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Infura Transactions (ITX)&lt;/em&gt;&lt;/strong&gt;: ITX is the simplest method to submit an Ethereum transaction; simply choose your budget, fill your tank, and let them discover the cheapest gas pricing for you.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Infura Pricing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Infura's pricing fits per app and app usage. There are also custom plans with bulk savings, service level agreements, and limitless projects. &lt;/p&gt;

&lt;p&gt;For the Ethereum API, there is a free plan that supports up to 3 projects and 100,000 Requests per Day as well as the developer plan which supports 10 Projects and 200,000 Requests per Day for $50/month. Other plans are also available such as the team and growth plan. &lt;/p&gt;

&lt;p&gt;For the IPFS API &amp;amp; Dedicated Gateway, there is a free plan with up to 5GB of storage and 5GB data transfer up as well as the Plus plan which is billed per usage with unlimited storage at $0.08/GB and unlimited data transfer at $0.12/GB.  &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.ankr.com/" rel="noopener noreferrer"&gt;Ankr&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyjb5ygvtdwpe1eldxtj3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyjb5ygvtdwpe1eldxtj3.png" alt="Ankr logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ankr offers a genuinely distributed and decentralized Web3 architecture for running node services. Ankr Build is a completely distributed, multi-chain infrastructure network and toolset that simplifies application development. Ankr currently supports the following chains: Arbitrum, Avalanche, Binance Smart Chain, Celo, Ethereum, Fantom, Gnosis, Harmony, IoTex, Moonbeam, Near, Nervos, Polygon and Solana&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ankr Products&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Public Community RPC APIs&lt;/em&gt;&lt;/strong&gt;: The Ankr Protocol network is topped by the Public RPC Layer. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Ankr Scan&lt;/em&gt;&lt;/strong&gt;: Ankr Scan is a Multi-Chain Explorer that allows you to see assets from several chains as well as those tied to a single wallet address. Think EtherScan but for multiple chains.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Node Services&lt;/em&gt;&lt;/strong&gt;: For 50+ chains, full, archive, and validator/staking nodes are accessible on Ankr.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ankr Pricing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ankr offers adjustable options and price plans to fit all budgets and needs.&lt;/p&gt;

&lt;p&gt;The Public RPCs are free to use with an offer of access to Full and Archive Data, a soft limit of 1M requests per day, and HTTPS connection. The Premium RPCs cost about 10000 ANKR(approximately $717.44) with unlimited rate limit, unlimited requests, HTTPS and WebSockets connection, and Global node coverage.&lt;/p&gt;

&lt;p&gt;There are several API pricing plans such as the free plan with a 20 rate-limit per second and 170,000 Requests per day. There is also the basic plan which costs about $49/month for access to 200 rate-limit per second, 1M Requests per day and the builder plan which costs about $224/month for access to 600 rate-limit per second and 5M requests per day.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.quicknode.com/" rel="noopener noreferrer"&gt;QuickNode&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4j54eeldvjwda9vhepdw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4j54eeldvjwda9vhepdw.jpeg" alt="QuickNode logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;QuickNode makes it simple to power blockchain apps and scale-up business by providing elastic APIs, sophisticated tools and analytical tools. QuickNode currently supports the following chains: Binance Smart Chain, Ethereum, Arbitrum, Optimism, Avalanche, Fantom, Luna, Solana, Algorand, Terra, Gnosis, Polygon and Celo.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;QuickNode Products&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;QuickNode APIs&lt;/em&gt;&lt;/strong&gt;: QuickNode provides either a dedicated endpoint that always serves traffic from the same location as specified when the endpoint was launched or access to their global network, which always routes traffic to the nearest available endpoint.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;NFT API&lt;/strong&gt;&lt;/em&gt;: Without having to filter through individual smart contracts, QuickNode's NFT API allows you to discover any NFT, verify ownership, and retrieve transaction history and key collection information.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;QuickNode Pricing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;QuickNode provides a 7-day free trial plan known as the Launch plan after which a fee of $9/month is required and it gives access to Domain Masking, Analytics, HTTP Endpoint and Rate Limits of 150k responses per day. There is also the Build plan which costs $49/month for rate limits of unlimited responses per day, support response within 12 hours together with Domain Masking, Analytics, HTTP Endpoint and URL Whitelisting.&lt;/p&gt;

&lt;p&gt;The Scale plan and Enterprise/Custom plans are also available. The Scale plan costs $299/month. If you also need a private blockchain cloud, QuickNode can provide it. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="//moralis.io"&gt;Moralis&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwcc8nyrnlgnzcnfz3itk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwcc8nyrnlgnzcnfz3itk.png" alt="Moralis logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Moralis offers a unified approach for developing high-performance dApps and compatibility with favorite web3 tools and services. Consider Moralis as Firebase but for Web3. Moralis offers managed backend services for blockchain applications. Moralis currently supports the following chains: Ethereum, Binance Smart Chain, Polygon, Arbitrum, and Avalanche.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Moralis Products&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Moralis Web3 SDK&lt;/em&gt;&lt;/strong&gt;: The Moralis JavaScript SDK is the means via which the builder's dApp will communicate with the Moralis Server. The SDK may be used to access and set user data in order to get balances, NFTs, events, or transactions. It supports crypto login and user management, IPFS integration and dApp hosting. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Moralis Web3 API&lt;/em&gt;&lt;/strong&gt;: Moralis Web3 API is a sophisticated blockchain API that allows you to query data from any chain.&lt;br&gt;
The Web3 API can be called using the Moralis SDK with just a few lines of code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Speedy Node API&lt;/em&gt;&lt;/strong&gt;: Speedy Nodes have the same functionality as regular Ethereum, Polygon, or BSC nodes, but they are faster, more reliable, and completely integrated with all Moralis services.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Moralis Pricing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The free plan is called the Starter Plan and is very suitable for people that are just starting off with blockchain development. It offers free access to unlimited plugins, IPFS Gateway, and community support with 10M requests per month using Speedy Nodes + Moralis API.&lt;/p&gt;

&lt;p&gt;For blockchain professionals, there is the Pro plan that costs $49 per month with access to everything in the free plan with more requests, a higher Rate Limit, and email support with 25M requests per month using Speedy Nodes + Moralis API.&lt;/p&gt;

&lt;p&gt;For larger teams, there is the Enterprise plan with custom requests per month, SLAs, and premium chat support (Phone, Chat, Email).&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.alchemy.com" rel="noopener noreferrer"&gt;Alchemy&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvun5m93muovf0sr6iexx.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvun5m93muovf0sr6iexx.jpeg" alt="Alchemy Logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alchemy powers some of the top Web3 applications that are existing today. Alchemy gives the capabilities of a node and a no-configuration in-house set of developer tools for quicker prototyping, debugging, and shipping of dApps. Alchemy currently supports the following chains: Ethereum, Polygon, Arbitrum, Optimism, Flow, StarkNet and Crypto.org.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Alchemy Products&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Alchemy Supernode&lt;/em&gt;&lt;/strong&gt;: Alchemy Supernode's revolutionary web3 design amplifies every piece of node capability with separate distributed systems and ensures real-time data accuracy using a proprietary coordinator service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Alchemy Notify&lt;/em&gt;&lt;/strong&gt;: Alchemy Notify provides the UX builders expect and need. Alchemy Notify allows users to deliver appropriate, timely alerts on the most significant Web3 events such as notifications for mined transactions, dropped transactions, and smart contract events which are integrated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Alchemy Build&lt;/em&gt;&lt;/strong&gt;: Alchemy Build is a no-configuration in-house developer tool package that allows you to prototype, debug, and release products more quickly. Alchemy Build allows you to quickly prototype and fix unsuccessful requests with instant UI feedback.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Alchemy Monitor&lt;/em&gt;&lt;/strong&gt;: Alchemy Monitor is an all-in-one dashboard and alarm system for app health, performance, and user behavior. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Enhanced and Chain APIS&lt;/em&gt;&lt;/strong&gt;: Alchemy provides access to improved API methods for returning block and transaction requests, smart contract event logs, and pending transactions in a virtual mempool. Furthermore, access to updated WebSockets that are continually listening for changes and manage reconnection and backfilling missing events automatically.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Alchemy Pricing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Alchemy provides the free tier plan which gives free access to Supernode, Build, Monitor, Notify, Enhanced APIs, No Daily Request Limits, Full Archive Data and supports up to 5 Apps.&lt;/p&gt;

&lt;p&gt;The Growth plan costs about $49/month with access to everything in the free plan together with Auto-Scaling Compute Units, Parity Trace and Geth Debug , 2x Higher Throughput and supports up to 15 Apps. &lt;/p&gt;

&lt;p&gt;The Enterprise plan includes access to everything in the Growth plan plus Committed Use Discounts, Custom SLAs, Custom Throughput and supports an unlimited number of Apps.&lt;/p&gt;

&lt;p&gt;With that, we have come to end of my review! I recommend that you try out any of them that suits your needs! Happy hacking and building😁! LFG🚀🚀🚀! WAGMI🚀🚀!&lt;/p&gt;

</description>
      <category>web3</category>
      <category>blockchain</category>
      <category>infrastructure</category>
      <category>dapps</category>
    </item>
    <item>
      <title>How to deploy your .NET core apps to Azure Kubernetes</title>
      <dc:creator>amoweolubusayo</dc:creator>
      <pubDate>Fri, 04 Feb 2022 11:35:53 +0000</pubDate>
      <link>https://dev.to/amoweolubusayo/how-to-deploy-your-net-core-apps-to-azure-kubernetes-5foh</link>
      <guid>https://dev.to/amoweolubusayo/how-to-deploy-your-net-core-apps-to-azure-kubernetes-5foh</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/22i9BftJdMw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>azurekubernetes</category>
      <category>docker</category>
      <category>kubernetes</category>
    </item>
    <item>
      <title>A simple web app to display  ETH to USD price feed using DIA Oracle  </title>
      <dc:creator>amoweolubusayo</dc:creator>
      <pubDate>Wed, 02 Feb 2022 08:27:59 +0000</pubDate>
      <link>https://dev.to/amoweolubusayo/a-simple-web-app-to-display-eth-to-usd-price-feed-using-dia-oracle-4fhe</link>
      <guid>https://dev.to/amoweolubusayo/a-simple-web-app-to-display-eth-to-usd-price-feed-using-dia-oracle-4fhe</guid>
      <description>&lt;p&gt;&lt;strong&gt;What are oracles?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Oracles are data feeds that connect blockchains to off-chain, real-world information so that you can query data in your smart contracts. Your smart contracts will be able to execute based upon inputs and outputs from the real world. They typically provide a way for web3 ecosystems to access existing data sources and advanced computations. They are very useful for data analysts, data providers and data users. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DIA Oracle&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of such existing oracle is the DIA oracle. DIA provides a reliable and verifiable bridge between off-chain data from various sources and on-chain smart contracts that can be used to build a variety of financial dApps. There are quite a number of things you can do with DIA. You can develop applications and sources on top of DIA. In this article, I would be creating a simple app that displays ETH/USD price. Presently, DIA allows you do several other pairs such as BTC, DIA, USDC, FTM, SDN, KSM, MOVR which are all USD based.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time to code&lt;/strong&gt;&lt;br&gt;
Let's get to code, shall we! I will be using javascript and html for this.&lt;/p&gt;

&lt;p&gt;Create/Navigate to your project folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir pricefeed
cd pricefeed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now create &lt;code&gt;index.html&lt;/code&gt; and &lt;code&gt;index.js&lt;/code&gt; files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch index.html
touch index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I will be using one of DIA's &lt;a href="https://docs.diadata.org/documentation/oracle-documentation/deployed-contracts"&gt;deployed contracts&lt;/a&gt;. For this writeup, I would be using the smart contract address deployed on &lt;a href="https://bscscan.com/address/0xbafee71d40babc12a3d0b2b8937ee62d3a070835"&gt;Binance mainnet&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Nagivate to the contract tab on bscscan &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kOLvUPZJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8lt2ft1hi5b9plkbksab.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kOLvUPZJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8lt2ft1hi5b9plkbksab.png" alt="Contract's screenshot" width="880" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the contract's source code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pragma solidity 0.7.4;                                                                                                                                                                                                                      

contract DIACoinmarketcapOracle {                                                  
    mapping (string =&amp;gt; uint256) public values;                                     
    address oracleUpdater;                                                         

    event OracleUpdate(string key, uint128 value, uint128 timestamp);              
    event UpdaterAddressChange(address newUpdater);                                

    constructor() {                                                                
        oracleUpdater = msg.sender;                                                
    }                                                                              

    function setValue(string memory key, uint128 value, uint128 timestamp) public {
        require(msg.sender == oracleUpdater);                                      
        uint256 cValue = (((uint256)(value)) &amp;lt;&amp;lt; 128) + timestamp;                  
        values[key] = cValue;                                                      
        emit OracleUpdate(key, value, timestamp);                                  
    }                                                                              

    function getValue(string memory key) public view returns (uint128, uint128) {
        uint256 cValue = values[key];                                              
        uint128 timestamp = (uint128)(cValue % 2**128);                            
        uint128 value = (uint128)(cValue &amp;gt;&amp;gt; 128);                                  
        return (value, timestamp);                                                 
    }                                                                              

    function updateOracleUpdaterAddress(address newOracleUpdaterAddress) public {
        require(msg.sender == oracleUpdater);                                      
        oracleUpdater = newOracleUpdaterAddress;                                   
        emit UpdaterAddressChange(newOracleUpdaterAddress);                        
    }                                                                              
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Scroll down to also find the contract's ABI as we would be using it shortly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--snHSZOEO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hc3tsqc83u2p1zrg20qf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--snHSZOEO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hc3tsqc83u2p1zrg20qf.png" alt="Contract's ABI screenshot" width="880" height="203"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now looking at the contract, there is a getValue method, in order to get the response from the method, make a call to the method as shown below. Remember also that we are using the key ‘ETH’&lt;/p&gt;

&lt;p&gt;Your code should look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const currentPriceResponse = await contract.methods.getValue('ETH').call()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy the ABI as we would also be using it in our code. In the end, your js file would look something close to this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function connect() {
    const priceElem = document.querySelector('#price')
    try {
        priceElem.textContent = 'Updating price...';

        const ABI = [ABI]

        const web3 = new Web3(new Web3.providers.HttpProvider("https://bsc-dataseed.binance.org/"))
        const contract = new web3.eth.Contract(ABI);
        contract.options.address = "0xbAFEe71d40baBC12a3D0B2b8937ee62D3A070835";
        const currentPriceResponse = await contract.methods.getValue('ETH').call()
        console.log(currentPriceResponse[0]);
        if (currentPriceResponse[0]) {
            const formatter = new Intl.NumberFormat('en-US', {
                style: 'currency',
                currency: 'USD',
                minimumFractionDigits: 2,
            });
            priceElem.textContent = formatter.format(currentPriceResponse[0] / 100000);
        }

    } catch (e) {
        priceElem.textContent = 'An error occurred while updating the price, please refresh your page.';
    }
}

window.onload = function() {
    connect();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's give some edits to the index.html file. You can write something as simple as a div or a header.&lt;/p&gt;

&lt;p&gt;​​&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h5&amp;gt;
    &amp;lt;span&amp;gt;Current Value: &amp;lt;i id="price"&amp;gt;&amp;lt;/i&amp;gt;&amp;lt;/span&amp;gt;
&amp;lt;/h5&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run your app and you would see that you are getting ETH/USD prices in real time. That’s pretty much it! A sample is deployed &lt;a href="https://objective-goldberg-1a9508.netlify.app/"&gt;here&lt;/a&gt;. Feel free to check out the &lt;a href="https://github.com/amoweolubusayo/pricefeed"&gt;Source Code&lt;/a&gt;.&lt;br&gt;
Thanks for reading! I hope you learnt a thing or two. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Glossary&lt;/strong&gt;&lt;br&gt;
Off-chain: Off-chain transactions refer to those transactions occurring on a cryptocurrency network that move the value outside of the blockchain. Due to their zero/low cost, off-chain transactions are gaining popularity, especially among large participants. &lt;a href="https://www.investopedia.com/terms/o/offchain-transactions-cryptocurrency.asp#:~:text=Off%2Dchain%20transactions%20refer%20to,contrasted%20with%20on%2Dchain%20transactions"&gt;Read more&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On-chain: On-chain transactions refer to cryptocurrency transactions that occur on the blockchain and remain dependent on the state of the blockchain for their validity. On-chain transactions are considered valid only when the blockchain has been updated to reflect the transactions on the public ledger. &lt;a href="https://www.investopedia.com/terms/c/chain-transactions-cryptocurrency.asp"&gt;Read more&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Smart contracts: A "smart contract" is simply a program that runs on a blockchain. It's a collection of code (its functions) and data (its state) that resides at a specific address on the blockchain. &lt;a href="https://ethereum.org/en/developers/docs/smart-contracts/"&gt;Read more&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ABI : The Contract Application Binary Interface (ABI) is the standard way to interact with contracts in the Ethereum ecosystem, both from outside the blockchain and for contract-to-contract interaction. Data is encoded according to its type, as described in this specification. The encoding is not self describing and thus requires a schema in order to decode. &lt;a href="https://docs.soliditylang.org/en/v0.8.11/abi-spec.html#:~:text=Contract%20ABI%20Specification-,Basic%20Design,contract%2Dto%2Dcontract%20interaction.&amp;amp;text=This%20specification%20does%20not%20address,known%20only%20at%20run%2Dtime"&gt;Read more&lt;/a&gt;&lt;/p&gt;

</description>
      <category>smartcontracts</category>
      <category>web3js</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
