<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DeFi Archives - Be on the Right Side of Change</title>
	<atom:link href="https://blog.finxter.com/category/defi/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.finxter.com/category/defi/</link>
	<description></description>
	<lastBuildDate>Fri, 30 Sep 2022 12:47:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://blog.finxter.com/wp-content/uploads/2020/08/cropped-cropped-finxter_nobackground-32x32.png</url>
	<title>DeFi Archives - Be on the Right Side of Change</title>
	<link>https://blog.finxter.com/category/defi/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Aave for DeFi Developers &#8211; A Simple Guide with Video</title>
		<link>https://blog.finxter.com/aave-for-defi-developers/</link>
		
		<dc:creator><![CDATA[Yogesh Kulkarni]]></dc:creator>
		<pubDate>Fri, 30 Sep 2022 12:39:41 +0000</pubDate>
				<category><![CDATA[Crypto]]></category>
		<category><![CDATA[DeFi]]></category>
		<category><![CDATA[Ethereum]]></category>
		<category><![CDATA[Finance]]></category>
		<category><![CDATA[Investment]]></category>
		<category><![CDATA[Solidity]]></category>
		<guid isPermaLink="false">https://blog.finxter.com/?p=738415</guid>

					<description><![CDATA[<p>This is in continuation of our DeFi series. In this post, we look at yet another decentralized lending and borrowing platform Aave. 🪙 Full DeFi Course: Click the link to access our free full DeFi course that’ll show you the ins and outs of decentralized finance (DeFi). Aave Aave launched in 2017 is a DeFi ... <a title="Aave for DeFi Developers &#8211; A Simple Guide with Video" class="read-more" href="https://blog.finxter.com/aave-for-defi-developers/" aria-label="Read more about Aave for DeFi Developers &#8211; A Simple Guide with Video">Read more</a></p>
<p>The post <a href="https://blog.finxter.com/aave-for-defi-developers/">Aave for DeFi Developers &#8211; A Simple Guide with Video</a> appeared first on <a href="https://blog.finxter.com">Be on the Right Side of Change</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Aave for DeFi Developers - A Simple Guide" width="937" height="527" src="https://www.youtube.com/embed/t9N4StMf-tI?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p>This is in continuation of our <a href="https://blog.finxter.com/getting-started-with-defi/" target="_blank" rel="noreferrer noopener">DeFi series</a>. In this post, we look at yet another decentralized lending and borrowing platform <strong><a href="https://app.aave.com/" data-type="URL" data-id="https://app.aave.com/" target="_blank" rel="noreferrer noopener">Aave</a>.</strong></p>



<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1fa99.png" alt="🪙" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong><a rel="noreferrer noopener" href="https://blog.finxter.com/decentralized-finance-for-coders-free-video-course/" target="_blank">Full DeFi Course</a></strong>: Click the link to access our free full DeFi course that’ll show you the ins and outs of decentralized finance (DeFi).</p>



<h2 class="wp-block-heading"><a id="_d82p7mz43y4r"></a>Aave</h2>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><a href="https://docs.aave.com/hub/" target="_blank" rel="noreferrer noopener"><img fetchpriority="high" decoding="async" src="https://blog.finxter.com/wp-content/uploads/2022/09/image-158.png" alt="" class="wp-image-738448" width="701" height="620" srcset="https://blog.finxter.com/wp-content/uploads/2022/09/image-158.png 900w, https://blog.finxter.com/wp-content/uploads/2022/09/image-158-300x265.png 300w, https://blog.finxter.com/wp-content/uploads/2022/09/image-158-768x679.png 768w" sizes="(max-width: 701px) 100vw, 701px" /></a></figure>
</div>


<p>Aave launched in 2017 is a DeFi protocol similar to <a rel="noreferrer noopener" href="https://blog.finxter.com/yield-farming-borrowing-and-lending-with-compound-a-simple-guide-for-devs/" target="_blank">Compound</a> with a lot of upgrades. </p>



<p>Beyond what Compound provides, Aave gives several extra tokens for supply and borrowing. As of now, Compound offered nine different tokens (various <a href="https://blog.finxter.com/how-does-the-erc-20-token-work/" target="_blank" rel="noreferrer noopener">ERC- 20</a> Ethereum- based assets). </p>



<p>Aave provides these nine besides an additional 13 that Compound does not. </p>



<p>Depositors give the market liquidity to generate a passive income, while borrowers can borrow if they have an over-collateralized token or can avail flash loans for under-collateralized (one-block liquidity).</p>



<p>Currently, we can see two major markets on Aave. </p>



<ul class="wp-block-list"><li>The first is for ERC-20 tokens that are more frequently used, like those of Compound, and their underlying assets, such as <a href="https://blog.finxter.com/introduction-to-ethereums-gas-in-solidity-development/" data-type="post" data-id="37644" target="_blank" rel="noreferrer noopener">ETH</a>, DAI and USDC. </li><li>The latter is only available with <a href="https://academy.finxter.com/university/uniswap-development-for-blockcain-engineers/" target="_blank" rel="noreferrer noopener">Uniswap</a> LP tokens. </li></ul>



<p>For instance, a user receives an LP token signifying market ownership when they deposit collateral into a liquidity pool on the Uniswap platform. To provide additional benefits, the LP tokens can be sold on the Uniswap market of Aave.</p>



<p>As per DeFi pulse, Aave has a TVL (Total Value Locked) of $4.09B as of today.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" width="624" height="264" src="https://blog.finxter.com/wp-content/uploads/2022/09/image-159.png" alt="" class="wp-image-738474" srcset="https://blog.finxter.com/wp-content/uploads/2022/09/image-159.png 624w, https://blog.finxter.com/wp-content/uploads/2022/09/image-159-300x127.png 300w" sizes="(max-width: 624px) 100vw, 624px" /><figcaption><strong><em>Fig</em></strong><em>: Defi Pulse for Aave</em></figcaption></figure>
</div>


<p></p>



<h2 class="wp-block-heading"><a id="_ze3jgd37zegl"></a>Aave Versions</h2>



<p>Aave has released three versions (v1, v2 and v3) as of now and the Governance token of Aave is <strong>‘AAVE’</strong>. Version 1 or v1 is the base version launched in 2017 and then there have been upgrades with multiple new features added. Below is a short comparison of when to use v2 or v3.</p>



<p>You should use Aave V2 when:</p>



<ul class="wp-block-list"><li>You won&#8217;t need to borrow many tokens.</li><li>Little profit</li><li>You borrow important tokens like WETH, USDC, etc.</li></ul>



<p>You should use Aave V3 when:</p>



<ul class="wp-block-list"><li>Many tokens must be borrowed</li><li>High profit margin</li><li>You borrow mid-cap tokens like <a href="https://blog.finxter.com/earn-passive-and-active-income-200-h-as-a-chainlink-validator-and-freelance-consultant/" data-type="post" data-id="36581" target="_blank" rel="noreferrer noopener">LINK</a>, etc.</li></ul>



<h2 class="wp-block-heading"><a id="_mtj40sir8iyr"></a>Borrow and Lending in Aave</h2>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><a href="https://docs.aave.com/hub/" target="_blank" rel="noreferrer noopener"><img fetchpriority="high" decoding="async" src="https://blog.finxter.com/wp-content/uploads/2022/09/image-158.png" alt="" class="wp-image-738448" width="701" height="620" srcset="https://blog.finxter.com/wp-content/uploads/2022/09/image-158.png 900w, https://blog.finxter.com/wp-content/uploads/2022/09/image-158-300x265.png 300w, https://blog.finxter.com/wp-content/uploads/2022/09/image-158-768x679.png 768w" sizes="(max-width: 701px) 100vw, 701px" /></a><figcaption><strong>Fig</strong>: Aave borrow and lend (pic credit: https://docs.aave.com)</figcaption></figure>
</div>


<h3 class="wp-block-heading"><a id="_2vml0ze9194i"></a>Borrow</h3>



<p>You must deposit any asset to be used as collateral before borrowing.</p>



<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4a1.png" alt="💡" class="wp-smiley" style="height: 1em; max-height: 1em;" /> The amount you can borrow up to depends on the value you have deposited and the readily available liquidity. </p>



<p>For instance, if there isn&#8217;t enough liquidity or if your health factor (minimum threshold of the collateral = 1, below this value, liquidation of your collateral is triggered) prevents it, you can&#8217;t borrow an asset.</p>



<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4a1.png" alt="💡" class="wp-smiley" style="height: 1em; max-height: 1em;" /> The loan is repaid with the same asset that you borrowed. </p>



<p>For instance, if you borrow 1 ETH, you&#8217;ll need to pay back 1 ETH plus interest. </p>



<p>In the updated Version 2 of the Aave Protocol, you can also use your collateral to make payments. You can borrow any of the stable coins like USDC, DAI, USDT, etc. if you want to repay the loan based on the price of the USD.</p>



<h4 class="wp-block-heading"><a id="_3ug43e3edtap"></a>Stable vs Variable Interest Rate</h4>



<p>In the short-term, <strong>stable</strong> rates function as a fixed rate, but they can be rebalanced in the long run in reaction to alterations in the market environment. Depending on supply and demand in Aave, the <strong>variable</strong> rate can change.</p>



<p>The stable rate is the better choice for forecasting how much interest you will have to pay because, as its name suggests, it will remain fairly stable. The variable rate changes over time and, depending on market conditions, could be the optimal rate.</p>



<p>Through your dashboard, you can switch between the stable and variable rate at any time.</p>



<h3 class="wp-block-heading"><a id="_fvo1t16f6n00"></a>Deposit/Lending</h3>



<p>Lenders share the interest payments made by borrowers based on the utilization rate multiplied by the average borrowing rate. The yield for depositors increases as reserve utilization increases.</p>



<p>Lenders are also entitled to a portion of the Flash Loan fees, equal to .09% of the Flash Loan volume.</p>



<p>There is no minimum or maximum deposit amount; you may deposit any amount you choose.</p>



<h2 class="wp-block-heading"><a id="_q3wxg92kl62s"></a>Flash Loans in Aave</h2>



<p>Flash Loans are unique business agreements that let you borrow an asset as long as you repay the borrowed money (plus a fee) before the deal expires (also called One Block Borrows). Users are not required to provide collateral for these transactions in order to proceed. </p>



<p>Flash Loans have no counterpart in the real world, so understanding how state is controlled within blocks in blockchains is a prerequisite.</p>



<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4a1.png" alt="💡" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Flash-loan enables users to access pool liquidity <strong>for a single transaction</strong> as long as the amount borrowed plus fees are returned or (if permitted) a debt position is opened by the end of the transaction.</p>



<p>For flash loans, Aave V3 provides two choices:</p>



<p>(1) “<strong>flashLoan</strong>”: enables borrowers to access the liquidity of several reserves in a single flash loan transaction. In this situation, the borrower also has the choice to open a fixed or variable-rate loan position secured by provided collateral.</p>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> The fee for flashloan is waived for approved flash borrowers.</p>



<p>(2) <strong>“flashLoanSimple”</strong>: enables the borrower to access a single reserve&#8217;s liquidity for the transaction. For individuals looking to take advantage of a straightforward flash loan with a single reserve asset, this approach is gas-efficient.</p>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> The fee for flashloanSimple is not waived for the flash borrowers. The Flashloan fee on Aave V3 is 0.05%.</p>



<h2 class="wp-block-heading"><a id="_6q15nvst9n5n"></a>Let&#8217;s Code a Simple Flash Loan</h2>



<p>Let&#8217;s code a simple flash loan in Aave, where we buy and repay the asset in the same transaction without having to provide any collateral. First, we set up the environment for writing the code.</p>



<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/25b6.png" alt="▶" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Note:</strong> It is recommended to follow the video along for a better understanding.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$npm install -g truffle  # in case truffle not installed
$mkdir aave_flashloan 
$cd aave_flashloan
$truffle init
$npm install @aave/core-v3
$npm install @openzeppelin/contracts
$npm install @openzeppelin/test-helpers 
</pre>



<p class="has-global-color-8-background-color has-background"><strong>Note:</strong> Aave3 is currently available on <a rel="noreferrer noopener" href="https://blog.finxter.com/polygon-quickstart-for-developers/" target="_blank">Polygon</a>, Arbitrum, Avalanche, and other L2 chains. As of now, it is not available on the <a href="https://blog.finxter.com/category/ethereum/" target="_blank" rel="noreferrer noopener">Ethereum</a> mainnet. Thus, we will fork the Polygon mainnet for our tests.</p>



<p>Set up a new app in <a href="https://dashboard.alchemy.com/" target="_blank" rel="noreferrer noopener">Alchemy</a> with the chain as Polygon mainnet and note down the API key.</p>



<p>Create a new file <code>.env</code> and enter the below info.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$WEB3_ALCHEMY_POLYGON_ID=&lt;API key noted above>
$USDC_WHALE=0x075e72a5eDf65F0A5f44699c7654C1a76941Ddc8</pre>



<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Recommended Tutorial</strong>: <a rel="noreferrer noopener" href="https://blog.finxter.com/solidity/" data-type="post" data-id="37379" target="_blank">Solidity Crash Course &#8212; Your First Smart Contract</a></p>



<h3 class="wp-block-heading"><a id="_g3lcn7rqxnvs"></a>Simple Flash Loan Contract</h3>



<p>The contract code (<code>FlashLoanPolygon.sol</code>) in the <code>contracts</code> folder.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@aave/core-v3/contracts/interfaces/IPool.sol";
import "@aave/core-v3/contracts/flashloan/base/FlashLoanSimpleReceiverBase.sol";

contract AaveFlashloan is FlashLoanSimpleReceiverBase {
    using SafeMath for uint256;
    using SafeERC20 for IERC20;
    event Log(string message, uint256 val);
    constructor(IPoolAddressesProvider provider)
        FlashLoanSimpleReceiverBase(provider)
    {}

    function aaveFlashloan(address loanToken, uint256 loanAmount) external {
        IPool(address(POOL)).flashLoanSimple(
            address(this),
            loanToken,
            loanAmount,
            "0x",
            0
        );
    }

    function executeOperation(
        address asset,
        uint256 amount,
        uint256 premium,
        address initiator,
        bytes memory
    ) public override returns (bool) {
        require(
            amount &lt;= IERC20(asset).balanceOf(address(this)),
            "Invalid balance for the contract"
        );
        // pay back the loan amount and the premium (flashloan fee)
        uint256 amountToReturn = amount.add(premium);
        require(
            IERC20(asset).balanceOf(address(this)) >= amountToReturn,
            "Not enough amount to return loan"
        );

        approveToken(asset, address(POOL), amountToReturn);
        emit Log("borrowed amount", amount);
        emit Log("flashloan fee", premium);
        emit Log("amountToReturn", amountToReturn);

        return true;
    }
}</pre>



<p>The contract code contains two important functions.</p>



<ul class="wp-block-list"><li><strong><code>aaveFlashloan()</code></strong> which calls the pools function <code>flashLoanSimple()</code>. Our test code must call this function to initiate a flash loan.</li><li><strong><code>executeOperation()</code></strong> is a callback function of the pool which pays the loan + interest back to the pool.</li></ul>



<h3 class="wp-block-heading"><a id="_v0asinpmqfkt"></a>Testing Contract</h3>



<p>In the test folder, create a <a rel="noreferrer noopener" href="https://blog.finxter.com/javascript-developer-income-and-opportunity/" data-type="post" data-id="191233" target="_blank">JavaScript</a> file <strong><code>config.js</code></strong> with the following content:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">const USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";

const aavePoolAddressesProvider =
  "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb";

const USDC_WHALE = process.env.USDC_WHALE;

module.exports = {
    USDC,
    USDC_WHALE,
    aavePoolAddressesProvider,
}</pre>



<p>In the test folder, create another file <strong><code>testAaveFlashLoanSimple.js</code></strong>:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">const BN = require("bn.js");
const IERC20 = artifacts.require("IERC20");
const AaveFlashLoan = artifacts.require("AaveFlashloan");
const {USDC,aavePoolAddressesProvider,USDC_WHALE} = require("./config");


function sendEther(web3, from, to, amount) {
  return web3.eth.sendTransaction({
    from,
    to,
    value: web3.utils.toWei(amount.toString(), "ether"),
  });
}

contract("AaveFlashLoan", (accounts) => {
  const WHALE = USDC_WHALE
  const TOKEN_BORROW = USDC
  const DECIMALS = 6  // USDC uses 6 decimal places and not 18 like other ERC20
  // We fund more because we need to pay back along with the fees during Flash loan.
  // So let us fund extra (2 million round figure to the calculations simple)
  const FUND_AMOUNT = new BN(10).pow(new BN(DECIMALS)).mul(new BN(500)); 500 USDC
  const BORROW_AMOUNT = new BN(10).pow(new BN(DECIMALS)).mul(new BN(1000000)); // 1 million USDC

  let aaveFlashLoanInstance
  let token

  beforeEach(async () => {
    token = await IERC20.at(TOKEN_BORROW) // USDC token
    aaveFlashLoanInstance = await AaveFlashLoan.new(aavePoolAddressesProvider)

    // send ether to USDC WHALE contract to cover tx fees
    await sendEther(web3, accounts[0], WHALE, 1)

    // send enough token to cover fee
    const bal = await token.balanceOf(WHALE)
    assert(bal.gte(FUND_AMOUNT), "balance &lt; FUND")
    // Send USDC tokens to AaveFlashLoan contract
    await token.transfer(aaveFlashLoanInstance.address, FUND_AMOUNT, {
      from: WHALE,
    })
    console.log("balance of USDC in AAveFlashLoan contract:", bal2.toString())

  })
    it("aave simple flash loan", async () => {
        const tx = await aaveFlashLoanInstance.aaveFlashloan(token.address, BORROW_AMOUNT)
        console.log("token address:",token.address)
        for (const log of tx.logs) {
        console.log(log.args.message, log.args.val.toString())
        }
    })

});</pre>



<p>Again, feel free to watch the video at the beginning of this tutorial to understand the testing process.</p>



<p>Open two terminals. </p>



<p><strong>In terminal 1:</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$source .env
$npx ganache-cli i --fork https://polygon-mainnet.g.alchemy.com/v2/$WEB3_ALCHEMY_POLYGON_ID \
--unlock $USDC_WHALE \
--networkId 999</pre>



<p>This should start a local fork of the Polygon mainnet.</p>



<p><strong>In terminal 2:</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ source .env
$ env $(cat .env) npx truffle test --network polygon_main_fork test/testAaveFlashLoanSimple.js</pre>



<p>This should run the flash loan test case, and it must pass.</p>



<h2 class="wp-block-heading"><a id="_jcn33wkhhowf"></a>Conclusion</h2>



<p>This tutorial discussed Aave, a leading <a href="https://blog.finxter.com/top-defi-articles/" data-type="post" data-id="395129" target="_blank" rel="noreferrer noopener">Dapp</a> lending and borrowing provider. </p>



<p>It covered some basic functionalities supported in Aave, such as lending, borrowing, and flash loans. </p>



<p>There are many other features Aave supports and it is not possible to cover it in one post, such as governance, liquidation, and advanced features such as Siloed Borrowing, Credit Delegation, and many more. </p>



<p>The post also examined a simple flash loan contract using Aave API.</p>



<p>You can explore more about borrowing and lending with Aave in this <a rel="noreferrer noopener" href="https://github.com/MatricksDeCoder/AaveDeFi" target="_blank">link</a>. It has a full stack Defi Aave dapp with frontend to perform borrowing and lending.</p>



<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Recommended Tutorial</strong>: <a href="https://blog.finxter.com/crypto-trading-bot-developer-income-and-opportunity/" data-type="URL" data-id="https://blog.finxter.com/crypto-trading-bot-developer-income-and-opportunity/" target="_blank" rel="noreferrer noopener">Crypto Trading Bot Developer &#8212; Income and Opportunity</a></p>
<p>The post <a href="https://blog.finxter.com/aave-for-defi-developers/">Aave for DeFi Developers &#8211; A Simple Guide with Video</a> appeared first on <a href="https://blog.finxter.com">Be on the Right Side of Change</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Decentralized Finance for Coders [Free Video Course]</title>
		<link>https://blog.finxter.com/decentralized-finance-for-coders-free-video-course/</link>
		
		<dc:creator><![CDATA[Yogesh Kulkarni]]></dc:creator>
		<pubDate>Wed, 27 Jul 2022 13:53:40 +0000</pubDate>
				<category><![CDATA[Crypto]]></category>
		<category><![CDATA[DeFi]]></category>
		<category><![CDATA[Ethereum]]></category>
		<category><![CDATA[Finance]]></category>
		<category><![CDATA[Solidity]]></category>
		<guid isPermaLink="false">https://blog.finxter.com/?p=516148</guid>

					<description><![CDATA[<p>This course will show you the ins and outs of decentralized finance (DeFi). Each step links to a more detailed article/tutorial, so you can dive deeper into the rabbit hole. Let&#8217;s get started! Step 1: Getting Started with DeFi What is DeFi? Decentralized Finance, also referred to as “DeFi,” enables customers to access financial services ... <a title="Decentralized Finance for Coders [Free Video Course]" class="read-more" href="https://blog.finxter.com/decentralized-finance-for-coders-free-video-course/" aria-label="Read more about Decentralized Finance for Coders [Free Video Course]">Read more</a></p>
<p>The post <a href="https://blog.finxter.com/decentralized-finance-for-coders-free-video-course/">Decentralized Finance for Coders [Free Video Course]</a> appeared first on <a href="https://blog.finxter.com">Be on the Right Side of Change</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This course will show you the ins and outs of decentralized finance (DeFi). Each step links to a more detailed article/tutorial, so you can dive deeper into the rabbit hole. </p>



<p>Let&#8217;s get started!</p>



<h2 class="wp-block-heading">Step 1: Getting Started with DeFi</h2>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="460" height="345" src="https://blog.finxter.com/wp-content/uploads/2022/07/image-41.png" alt="" class="wp-image-459270" srcset="https://blog.finxter.com/wp-content/uploads/2022/07/image-41.png 460w, https://blog.finxter.com/wp-content/uploads/2022/07/image-41-300x225.png 300w" sizes="auto, (max-width: 460px) 100vw, 460px" /></figure>



<p>What is DeFi?</p>



<p>Decentralized Finance, also referred to as “DeFi,” enables customers to access financial services that include lending, borrowing, and trading.</p>



<p>These financial services use Decentralized applications (Dapps) in implementing their functionality and they do not rely on centralized finances to execute their operations. The vast majority of these services are being created on the <a href="https://blog.finxter.com/smart-contracts-and-evm/" target="_blank" rel="noreferrer noopener">Ethereum</a> blockchain.</p>



<p>To use the DeFi tools, you don’t need to be an Ethereum expert, although it helps to be familiar with how Ethereum or <a href="https://blog.finxter.com/polygon-quickstart-for-developers/" target="_blank" rel="noreferrer noopener">layer-2</a> blockchains like <a href="https://blog.finxter.com/polygon-quickstart-for-developers/" target="_blank" rel="noreferrer noopener">Polygon</a> operate.</p>



<p>Defi is not a single service or a product, but an assortment of several goods and services that can replace traditional institutions like banking, bonds, insurance, and trading.</p>



<p>It is possible to integrate these services, each having its own functionality, to build one protocol with multiple functions. Thus grouping services like borrowing, lending, staking and many others together to create one multi-functional financial application. As it is workable to assemble these services, DeFi apps are also called <strong><em>“money LEGOS”</em></strong>.</p>



<p class="has-base-background-color has-background"> <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1fa99.png" alt="🪙" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Learn More</strong>: You can read the <a href="https://blog.finxter.com/getting-started-with-defi/" data-type="URL" data-id="https://blog.finxter.com/getting-started-with-defi/" target="_blank" rel="noreferrer noopener">full tutorial on the Finxter blog</a>.</p>



<h2 class="wp-block-heading">Step 2: MakerDAO 101 for Coders – How DeFi Lending and Borrowing Works</h2>



<p>DeFi breakthroughs have been happening on <a rel="noreferrer noopener" href="https://blog.finxter.com/smart-contracts-and-evm/" data-type="post" data-id="92507" target="_blank">Ethe</a>reum because of its prominence, but it is also emerging on other blockchains like Solana, Polkadot, Algorand, and many more. </p>



<p>We will look at three popular DeFi dApps: MakerDAO, Compound, and Aave. I will explain MakerDAO in this article and the other two &#8211; Compound and Aave in the next.</p>



<p class="has-global-color-8-background-color has-background"><a rel="noreferrer noopener" href="https://makerdao.com/en/" target="_blank">MakerDAO</a> is a good example of understanding the DeFi ecosystem, where <a rel="noreferrer noopener" href="https://academy.finxter.com/university/creating-a-dao-from-scratch-with-solidity-and-javascript/" target="_blank">DAO</a> stands for <strong><em>decentralized autonomous organization</em></strong>. It employs two tokens. A stablecoin called DAI and a governance token called MKR. We will discuss each of them ‌and their use cases.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="624" height="316" src="https://blog.finxter.com/wp-content/uploads/2022/07/image-105.png" alt="" class="wp-image-515969" srcset="https://blog.finxter.com/wp-content/uploads/2022/07/image-105.png 624w, https://blog.finxter.com/wp-content/uploads/2022/07/image-105-300x152.png 300w" sizes="auto, (max-width: 624px) 100vw, 624px" /><figcaption><strong>Fig</strong>: MakerDAO (<em><a rel="noreferrer noopener" href="https://docs.makerdao.com/" data-type="URL" data-id="https://docs.makerdao.com/" target="_blank">pic credit</a></em>)</figcaption></figure>
</div>


<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1fa99.png" alt="🪙" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>DAI</strong> is a crypto-collateralized stable coin with a 1:1 parity with US dollar ($), and value backed by ETH (<a rel="noreferrer noopener" href="https://blog.finxter.com/introduction-to-ethereums-gas-in-solidity-development/" data-type="post" data-id="37644" target="_blank">Ether</a>) as collateral in the <a href="https://blog.finxter.com/introduction-to-smart-contracts-and-solidity/" data-type="post" data-id="445145">smart </a><a rel="noreferrer noopener" href="https://blog.finxter.com/introduction-to-smart-contracts-and-solidity/" data-type="post" data-id="445145" target="_blank">c</a><a href="https://blog.finxter.com/introduction-to-smart-contracts-and-solidity/" data-type="post" data-id="445145">ontract</a> called the <em>Maker collateral vault. DAI token has the money function and acts as currency.</em></p>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1fa99.png" alt="🪙" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>MKR</strong> token is the governance token issued by the Maker protocol to the lenders or stakeholders that grants voting rights and decision-making in the improvements of the Maker protocol. The MKR token holders also govern the stability of DAI. Thus MKR token has a utility function.</p>



<p>Users can mint new $DAI tokens when they take their digital assets ($ETH, $BAT, $USDC, $YFI, $LINK) with MakerDAO’s smart contract. Thus, by staking digital assets, you can create $DAI.</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="MakerDAO 101 for Coders - How DeFi Lending and Borrowing Works" width="937" height="527" src="https://www.youtube.com/embed/32c0Aw0-eZ4?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="has-base-background-color has-background"> <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1fa99.png" alt="🪙" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Learn More</strong>: You can read the <a rel="noreferrer noopener" href="https://blog.finxter.com/makerdao-101-for-coders-how-defi-lending-and-borrowing-works/" data-type="URL" data-id="https://blog.finxter.com/makerdao-101-for-coders-how-defi-lending-and-borrowing-works/" target="_blank">full tutorial on the Finxter blog</a>.</p>



<h2 class="wp-block-heading">Step 3: Compound for Developers: Yield Farming, Borrowing, Lending</h2>



<p><a rel="noreferrer noopener" href="https://compound.finance/" target="_blank">Compound</a> is a popular lending and borrowing platform for various ERC-20 tokens. </p>



<p>As per DeFi pulse, Compound has a Total Value Locked (TVL) of $2.56 billion USD.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="624" height="237" src="https://blog.finxter.com/wp-content/uploads/2022/09/image-25.png" alt="" class="wp-image-675843" srcset="https://blog.finxter.com/wp-content/uploads/2022/09/image-25.png 624w, https://blog.finxter.com/wp-content/uploads/2022/09/image-25-300x114.png 300w" sizes="auto, (max-width: 624px) 100vw, 624px" /><figcaption><em><strong>Figure 1</strong>: Defi Pulse for Compound</em></figcaption></figure>
</div>


<p>You can deposit items that can be pledged as collateral for loans through Compound. </p>



<p>Based on your collateral, you are only permitted to borrow up to a particular percentage (about 60–70%). Credit ratings are meaningless, and since <a href="https://blog.finxter.com/smart-contracts-and-evm/" data-type="post" data-id="92507" target="_blank" rel="noreferrer noopener">Ethereum</a> accounts are anonymous, it is nearly impossible to get payment in the event of a loan default. </p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Compound for Developers: Yield Farming, Borrowing, Lending" width="937" height="527" src="https://www.youtube.com/embed/NWUQaIb5nQ4?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="has-base-background-color has-background"> <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1fa99.png" alt="🪙" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Learn More</strong>: You can read the <a href="https://blog.finxter.com/yield-farming-borrowing-and-lending-with-compound-a-simple-guide-for-devs/" data-type="post" data-id="675817" target="_blank" rel="noreferrer noopener">full tutorial on the Finxter blog</a>.</p>



<h2 class="wp-block-heading">Step 4: Aave for Defi Developers</h2>



<p>Aave launched in 2017 is a DeFi protocol similar to <a rel="noreferrer noopener" href="https://blog.finxter.com/yield-farming-borrowing-and-lending-with-compound-a-simple-guide-for-devs/" target="_blank">Compound</a> with a lot of upgrades.</p>



<figure class="wp-block-image"><a href="https://docs.aave.com/hub/" target="_blank" rel="noreferrer noopener"><img loading="lazy" decoding="async" width="900" height="796" src="https://blog.finxter.com/wp-content/uploads/2022/09/image-158.png" alt="" class="wp-image-738448" srcset="https://blog.finxter.com/wp-content/uploads/2022/09/image-158.png 900w, https://blog.finxter.com/wp-content/uploads/2022/09/image-158-300x265.png 300w, https://blog.finxter.com/wp-content/uploads/2022/09/image-158-768x679.png 768w" sizes="auto, (max-width: 900px) 100vw, 900px" /></a></figure>



<p>Beyond what Compound provides, Aave gives several extra tokens for supply and borrowing. As of now, Compound offered nine different tokens (various <a href="https://blog.finxter.com/how-does-the-erc-20-token-work/" target="_blank" rel="noreferrer noopener">ERC- 20</a> Ethereum- based assets).</p>



<p>Aave provides these nine besides an additional 13 that Compound does not.</p>



<p>Depositors give the market liquidity to generate a passive income, while borrowers can borrow if they have an over-collateralized token or can avail flash loans for under-collateralized (one-block liquidity).</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="Aave for DeFi Developers - A Simple Guide" width="937" height="527" src="https://www.youtube.com/embed/t9N4StMf-tI?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="has-base-background-color has-background"> <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1fa99.png" alt="🪙" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Learn More</strong>: You can read the <a href="https://blog.finxter.com/aave-for-defi-developers/" data-type="post" data-id="738415" target="_blank" rel="noreferrer noopener">full tutorial on the Finxter blog</a>.</p>
<p>The post <a href="https://blog.finxter.com/decentralized-finance-for-coders-free-video-course/">Decentralized Finance for Coders [Free Video Course]</a> appeared first on <a href="https://blog.finxter.com">Be on the Right Side of Change</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>MakerDAO 101 for Coders &#8211; How DeFi Lending and Borrowing Works</title>
		<link>https://blog.finxter.com/makerdao-101-for-coders-how-defi-lending-and-borrowing-works/</link>
		
		<dc:creator><![CDATA[Yogesh Kulkarni]]></dc:creator>
		<pubDate>Wed, 27 Jul 2022 13:40:34 +0000</pubDate>
				<category><![CDATA[Crypto]]></category>
		<category><![CDATA[DeFi]]></category>
		<category><![CDATA[Ethereum]]></category>
		<category><![CDATA[Finance]]></category>
		<guid isPermaLink="false">https://blog.finxter.com/?p=515912</guid>

					<description><![CDATA[<p>This is in continuation of the first part of our DeFi series. 💡 Abstract: In this article, we will see how decentralized lending and borrowing work. It starts with comparing centralized finance (CeFi) with decentralized finance (DeFi) lending and borrowing. You&#8217;ll then learn about the most important Ethereum based DeFi decentralized apps (dapps) for lending ... <a title="MakerDAO 101 for Coders &#8211; How DeFi Lending and Borrowing Works" class="read-more" href="https://blog.finxter.com/makerdao-101-for-coders-how-defi-lending-and-borrowing-works/" aria-label="Read more about MakerDAO 101 for Coders &#8211; How DeFi Lending and Borrowing Works">Read more</a></p>
<p>The post <a href="https://blog.finxter.com/makerdao-101-for-coders-how-defi-lending-and-borrowing-works/">MakerDAO 101 for Coders &#8211; How DeFi Lending and Borrowing Works</a> appeared first on <a href="https://blog.finxter.com">Be on the Right Side of Change</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This is in continuation of the first part of our <a rel="noreferrer noopener" href="https://blog.finxter.com/getting-started-with-defi/" target="_blank">DeFi series</a>. </p>



<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4a1.png" alt="💡" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Abstract</strong>: In this article, we will see how decentralized lending and borrowing work. It starts with comparing centralized finance (CeFi) with decentralized finance (DeFi) lending and borrowing. You&#8217;ll then learn about the most important <a rel="noreferrer noopener" href="https://blog.finxter.com/category/ethereum/" target="_blank">Ethereum</a> based DeFi decentralized apps (dapps) for lending and borrowing. I explain MakerDAO here and address Compound and Aave in the next article.</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="MakerDAO 101 for Coders - How DeFi Lending and Borrowing Works" width="937" height="527" src="https://www.youtube.com/embed/32c0Aw0-eZ4?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1fa99.png" alt="🪙" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong><a rel="noreferrer noopener" href="https://blog.finxter.com/decentralized-finance-for-coders-free-video-course/" data-type="post" data-id="516148" target="_blank">Full DeFi Course</a></strong>: Click the link to access our free full DeFi course that&#8217;ll show you the ins and outs of decentralized finance (DeFi).</p>



<h2 class="wp-block-heading">CeFi vs. DeFi Lending and Borrowing</h2>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="521" height="927" src="https://blog.finxter.com/wp-content/uploads/2022/07/image-104.png" alt="" class="wp-image-515941" srcset="https://blog.finxter.com/wp-content/uploads/2022/07/image-104.png 521w, https://blog.finxter.com/wp-content/uploads/2022/07/image-104-169x300.png 169w" sizes="auto, (max-width: 521px) 100vw, 521px" /></figure>
</div>


<p>Lending and borrowing cash are two of the most popular services provided by the financial sector. </p>



<p>Thanks to the idea of credit and collateralization, which makes this workable. The beginning of the period of modernity in European history (also called the <strong><em>Renaissance</em></strong> period) was because of commercial scale lending and borrowing, which led to the furor in economic activity. </p>



<p>Because of this powerful mechanism, the economy rose at an unparalleled speed.</p>



<p>An entrepreneur can borrow the initial money needed for a startup from the lender by providing the business as collateral, or a family can mortgage a house as collateral for loans.</p>



<p>This technique helps in reducing the borrower&#8217;s absconding with all the loaned money. </p>



<p>Thus, the CeFi borrowing or lending needs some kind of middleman, such as banks. Before you get the borrowed amount from the bank, you need to show your ability to repay loans and also stick to the restrictions imposed by them. </p>



<p>Besides this, there is a complex system of credit scores that determines an individual&#8217;s ability to repay the loan and also considering other factors such as geographical legal restrictions of the banks, multiple applicants etc. add to high barriers in getting the loans approved. Basically, to be even considered for loans, you have to be affluent enough when using CeFi.</p>



<p>With the DeFi system, this barrier and impediments do not exist. </p>



<p>Anybody can access the funds from the pool if you have enough collateral (other <a rel="noreferrer noopener" href="https://blog.finxter.com/category/crypto/" target="_blank">crypto</a> currencies or tokens.). All the masses can contribute to the liquidity pool, which the borrowers can withdraw from and repay at the interest rate set by the algorithms of the DeFi system. Using the DeFi ecosystem, asset lending is no longer the privilege of the rich.</p>



<p>Another notable difference between CeFi and DeFi is the bank regulations like Anti Money Laundering (AML) and Know-Your-Customer (KYC) in place, whereas in the DeFi ecosystem you just need to only submit the crypto collateral. It&#8217;s very simple and has no hassles.</p>



<h2 class="wp-block-heading">MakerDAO &#8211; A Lending and Borrowing dApp</h2>



<p>DeFi breakthroughs have been happening on <a rel="noreferrer noopener" href="https://blog.finxter.com/smart-contracts-and-evm/" data-type="post" data-id="92507" target="_blank">Ethe</a>reum because of its prominence, but it is also emerging on other blockchains like Solana, Polkadot, Algorand, and many more. </p>



<p>We will look at three popular DeFi dApps: MakerDAO, Compound, and Aave. I will explain MakerDAO in this article and the other two &#8211; Compound and Aave in the next.</p>



<p class="has-global-color-8-background-color has-background"><a rel="noreferrer noopener" href="https://makerdao.com/en/" target="_blank">MakerDAO</a> is a good example of understanding the DeFi ecosystem, where <a rel="noreferrer noopener" href="https://academy.finxter.com/university/creating-a-dao-from-scratch-with-solidity-and-javascript/" target="_blank">DAO</a> stands for <strong><em>decentralized autonomous organization</em></strong>. It employs two tokens. A stablecoin called DAI and a governance token called MKR. We will discuss each of them ‌and their use cases.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="624" height="316" src="https://blog.finxter.com/wp-content/uploads/2022/07/image-105.png" alt="" class="wp-image-515969" srcset="https://blog.finxter.com/wp-content/uploads/2022/07/image-105.png 624w, https://blog.finxter.com/wp-content/uploads/2022/07/image-105-300x152.png 300w" sizes="auto, (max-width: 624px) 100vw, 624px" /><figcaption><strong>Fig</strong>: MakerDAO (<em><a rel="noreferrer noopener" href="https://docs.makerdao.com/" data-type="URL" data-id="https://docs.makerdao.com/" target="_blank">pic credit</a></em>)</figcaption></figure>
</div>


<p>                                               </p>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1fa99.png" alt="🪙" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>DAI</strong> is a crypto-collateralized stable coin with a 1:1 parity with US dollar ($), and value backed by ETH (<a rel="noreferrer noopener" href="https://blog.finxter.com/introduction-to-ethereums-gas-in-solidity-development/" data-type="post" data-id="37644" target="_blank">Ether</a>) as collateral in the <a href="https://blog.finxter.com/introduction-to-smart-contracts-and-solidity/" data-type="post" data-id="445145">smart </a><a rel="noreferrer noopener" href="https://blog.finxter.com/introduction-to-smart-contracts-and-solidity/" data-type="post" data-id="445145" target="_blank">c</a><a href="https://blog.finxter.com/introduction-to-smart-contracts-and-solidity/" data-type="post" data-id="445145">ontract</a> called the <em>Maker collateral vault. DAI token has the money function and acts as currency.</em></p>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1fa99.png" alt="🪙" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>MKR</strong> token is the governance token issued by the Maker protocol to the lenders or stakeholders that grants voting rights and decision-making in the improvements of the Maker protocol. The MKR token holders also govern the stability of DAI. Thus MKR token has a utility function.</p>



<p>Users can mint new $DAI tokens when they take their digital assets ($ETH, $BAT, $USDC, $YFI, $LINK) with MakerDAO’s smart contract. Thus, by staking digital assets, you can create $DAI.</p>



<h3 class="wp-block-heading"><a id="_pgzn1joz4ge0"></a>Operation model of MakerDAO</h3>



<p>The best way to know how MakerDAO operates is by looking at an example. Before we look into an example, let us understand two important terminologies in MakerDAO &#8211; debt and CDP (collateralized debt positions). </p>



<p>Users can deposit crypto assets (ETH or other <a href="https://blog.finxter.com/how-does-the-erc-20-token-work/" data-type="post" data-id="87294" target="_blank" rel="noreferrer noopener">ERC20</a> tokens) into the smart contract to generate or mint the $DAI tokens up to a particular collateralization ratio (at least 150%). </p>



<p>This generates a position called CDP and ‘<em>debt’</em> in DAI. </p>



<p>MakerDAO is always over collateralized (as mentioned >=150%) so that the value of the collateral is always greater than the debt. MakerDAO needs this because the price of ETH is highly volatile.</p>



<p>Now let&#8217;s take an example to see how MakerDAO algorithms work.</p>



<p>Let&#8217;s consider you are the ETH owner who wants to have liquidity but does not intend to sell ETH, as it may rise in value in the future (this is like the owner who wants to mortgage the house or apartment because they want the liquidity but do not want to sell the house). </p>



<p>Let&#8217;s consider you have 5 ETH and the ETH price is = $1000, totaling to $5000.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="441" height="152" src="https://blog.finxter.com/wp-content/uploads/2022/07/image-106.png" alt="" class="wp-image-515984" srcset="https://blog.finxter.com/wp-content/uploads/2022/07/image-106.png 441w, https://blog.finxter.com/wp-content/uploads/2022/07/image-106-300x103.png 300w" sizes="auto, (max-width: 441px) 100vw, 441px" /></figure>
</div>


<ol class="wp-block-list" type="1"><li>Deposit 5 ETH to open a CDP (collateralized debt position).</li><li>If the collateralization requirement is at least 150% for MakerDAO, then you can mint up to 5000/1.5 ~= 3334 DAI. If the ETH plummets below $1000, then in such a case, the contract would be under-collateralized, and the system must also maintain the $1 = 1 DAI ratio. Thus, ‌you cannot mint all the 3334 DAI, as there is no notice from the exchange or broker to deposit more ETH or liquidate the position to maintain this ratio. As liquidation will happen instantly, you always mint less than 3334 DAI to provide a safety net.</li></ol>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="451" height="152" src="https://blog.finxter.com/wp-content/uploads/2022/07/image-107.png" alt="" class="wp-image-515987" srcset="https://blog.finxter.com/wp-content/uploads/2022/07/image-107.png 451w, https://blog.finxter.com/wp-content/uploads/2022/07/image-107-300x101.png 300w" sizes="auto, (max-width: 451px) 100vw, 451px" /></figure>
</div>


<p>Let&#8217;s take a case if you only mint 2500 DAI, with a collateralization ratio of 2.0 ($5000/2 = 2500). Now consider the two scenarios:</p>



<ol class="wp-block-list" type="a"><li>If collateral price increases, i.e., ETH price increases by 50%, meaning the collateral is now worth $7500 ($5000 + $2500). As collateralization was 200%, you can mint up to 3750 DAI, which is an additional 1250 DAI.</li><li>If collateral price decreases, i.e.  ETH price decreases by 25%, it becomes an intriguing issue. The collateral is now worth $3750 ($5000 &#8211; $1250). With a maximum mint of 2500 DAI, the collateralization ratio gets reduced to 1.5 (3750/2500). You have three options to solve the problem.</li></ol>



<p>1.) You can increase the amount of collateral in the contract by adding $1250 worth of ETH (or 1.6 ETH).</p>



<p>2.) As you have 2500 DAI, you can pay off the debt and get back 5 ETH, however the total worth of ETH is now reduced to $3750.</p>



<p>3.) Last, if you use neither option, then a third party called <em>keepers</em> will look for liquidation in order to liquidate the debt. The keeper will sell ETH at auction to get back enough DAI to pay off the debt. In our case, 1.6 ETH($1250) gets sold and you get back 3.2 ETH and the keeper gets 0.2 ETH as a percentage fee. So in total you have 3.2 ETH ($2400) and 2500 DAI.</p>



<h3 class="wp-block-heading"><a id="_a0uqkrf7uuv"></a>Where is MakerDAO used?</h3>



<ul class="wp-block-list"><li>Decentralized exchanges like Uniswap, Sushiswap, Curve, Balancer. They use DAI because it makes trade easy and is always in demand.</li><li>Lending protocols like Aave, Compound, Celsius. They use DAI because it is less volatile and hence provides stability for lending and borrowing.</li></ul>



<h3 class="wp-block-heading"><a id="_3snr2nap25ja"></a>DAI in Smart contracts</h3>



<p>Let us get ‌practical and try using DAI in our smart contract. Below is the <a href="https://blog.finxter.com/introduction-to-smart-contracts-and-solidity/">smart contract</a>, which can accept/<code>deposit()</code> and <code>withdraw()</code> DAI token. We will make use of the Kovan network, where DAI (ERC20) contract deployed at &#8211;  <a href="https://kovan.etherscan.io/address/0x4f96fe3b7a6cf9725f59d353f723c1bdb64ca6aa" target="_blank" rel="noreferrer noopener">0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa</a></p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">//SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import "@openzeppelin/contracts/access/Ownable.sol";

// Adding only the ERC-20 function we need
interface DaiToken {
    function transfer(address dst, uint wad) external returns (bool);
    function balanceOf(address guy) external view returns (uint);
}

contract DaiFaucet is Ownable  {
    
    event Withdrawal(address indexed to, uint amount);
    event Deposit(address indexed from, uint amount);
   

    DaiToken daitoken;

    
    constructor() public{
        // kovan network
        daitoken = DaiToken(0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa);
    }

    // Give out Dai to anyone who asks
    function withdraw(uint withdraw_amount) public {
        // Limit withdrawal amount
        require(withdraw_amount &lt;= 0.1 ether);
        require(daitoken.balanceOf(address(this)) >= withdraw_amount,
            "Insufficient balance in faucet for withdrawal request");
        // Send the amount to the address that requested it
        daitoken.transfer(msg.sender, withdraw_amount);
        emit Withdrawal(msg.sender, withdraw_amount);
    }

    // Accept any incoming amount
    fallback () external payable {
        emit Deposit(msg.sender, msg.value);
    }

        // Only owner can shutdown this contract.
    function destroy() public onlyOwner {
        daitoken.transfer(owner(), daitoken.balanceOf(address(this)));
        selfdestruct(payable(msg.sender));
    }
}
</pre>



<p>An interface <strong><em>DaiToken </em></strong>interacts with the DAI contract for <code>transfer()</code> and <code>balanceOf()</code>.</p>



<p>The contract <code>DaiFucet</code> defines:</p>



<ol class="wp-block-list" type="1"><li><code>constructor()</code> to get an instance of the DAI token contract on Kovan network.</li><li><code>withdraw()</code> function to withdraw DAI. It transfers DAI from this contract to the <code>msg.sender</code> only on the condition that the requested amount is &lt;= 0.1 DAI (you have to use it as &lt;= 0.1 ETH).</li><li>A <code>fallback</code> function to accept DAI for the contract.</li><li><code><strong><em>destroy</em></strong>()</code> to destroy the contract when you no longer need it.</li></ol>



<p>Compile and deploy the contract to the Kovan network using Remix Ide and <a href="https://blog.finxter.com/metamask-simple-tutorial/" data-type="post" data-id="38157" target="_blank" rel="noreferrer noopener">Metamask</a>. I have already deployed the contract at <a href="https://kovan.etherscan.io/address/0xabc10a81b5d50f4455f4f7cc1f418ff70259dd8a" target="_blank" rel="noreferrer noopener">0xABC10a81b5d50f4455f4F7cC1f418ff70259dd8A</a>. Your contract will be at a unique address than mine.</p>



<h3 class="wp-block-heading"><a id="_piac54u5qk2c"></a>How to send DAI to the contract and withdraw?</h3>



<p>Use <a rel="noreferrer noopener" href="https://app.uniswap.org/#/swap?chain=kovan" target="_blank">Uniswap</a> to swap some ether to DAI on the Kovan network through your Metamask account. Now you have DAI in your Metamask account. On Metamask, you can see it in the assets section. See the figure below.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img loading="lazy" decoding="async" src="https://blog.finxter.com/wp-content/uploads/2022/07/image-108.png" alt="" class="wp-image-516072" width="307" height="352" srcset="https://blog.finxter.com/wp-content/uploads/2022/07/image-108.png 292w, https://blog.finxter.com/wp-content/uploads/2022/07/image-108-261x300.png 261w" sizes="auto, (max-width: 307px) 100vw, 307px" /><figcaption><strong>Fig</strong>: Metamask with DAI</figcaption></figure>
</div>


<p>You can now click on DAI and select send, type the address of the above deployed contract and click on send, by signing the transaction, your contract will now receive DAI.</p>



<p>Now you can interact with the contract to withdraw DAI from Remix (You can only withdraw a maximum of 0.1 DAI per transaction as per the rule set in the contract).</p>



<p>After you are done enough with the contract, you can as well destroy it by calling <code>destroy()</code> function.</p>



<h2 class="wp-block-heading"><a id="_4p5sn5ydas3p"></a>Conclusion</h2>



<p>The article started with discussing lending and borrowing in CeFi and DeFi. </p>



<p>We saw how DeFi is easy to use and you have complete control over your assets with no interference from a central finance institute like banks, etc. </p>



<p>The architecture of the most widely used and popular dapps like MakerDAO was explained, and finally saw an example of sending and receiving DAI in a <a href="https://blog.finxter.com/introduction-to-smart-contracts-and-solidity/">smart contract</a>.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p>Feel free to check out our related course on the <a href="https://academy.finxter.com" data-type="URL" data-id="https://academy.finxter.com" target="_blank" rel="noreferrer noopener">Finxter Academy</a>:</p>



<div class="wp-block-image"><figure class="aligncenter size-full"><a href="https://academy.finxter.com/university/creating-a-dao-from-scratch-with-solidity-and-javascript/" target="_blank" rel="noopener"><img loading="lazy" decoding="async" width="363" height="650" src="https://blog.finxter.com/wp-content/uploads/2022/05/image-282.png" alt="" class="wp-image-387280" srcset="https://blog.finxter.com/wp-content/uploads/2022/05/image-282.png 363w, https://blog.finxter.com/wp-content/uploads/2022/05/image-282-168x300.png 168w" sizes="auto, (max-width: 363px) 100vw, 363px" /></a></figure></div>
<p>The post <a href="https://blog.finxter.com/makerdao-101-for-coders-how-defi-lending-and-borrowing-works/">MakerDAO 101 for Coders &#8211; How DeFi Lending and Borrowing Works</a> appeared first on <a href="https://blog.finxter.com">Be on the Right Side of Change</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: blog.finxter.com @ 2026-06-27 16:00:07 by W3 Total Cache
-->