<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>nowonder</title>
        <link>https://paragraph.com/@justn</link>
        <description>Buidler @buidlguidl, devved Vitaliks Book app, just learning and doing stuff.</description>
        <lastBuildDate>Sun, 03 May 2026 12:29:28 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <image>
            <title>nowonder</title>
            <url>https://storage.googleapis.com/papyrus_images/05b36d6ae2de1adabc2b978b6164c9b0dd3b2122c8a593800c786a30ac3ca12b.jpg</url>
            <link>https://paragraph.com/@justn</link>
        </image>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[Maybe α: AAVE V2 Liquidations]]></title>
            <link>https://paragraph.com/@justn/maybe-aave-v2-liquidations</link>
            <guid>cptTTVd6ZfzyjH54cqum</guid>
            <pubDate>Tue, 24 Jan 2023 18:15:41 GMT</pubDate>
            <description><![CDATA[Here’s what I wish I knew about this weird creditorIf you have an understanding already, just skip to the bottom. Otherwise, there is info here that may help you make or improve your own bot. Note: The open-sourcing of this research is funded by BuidlGuidl & in a general sense, Public Goods Funding. I’ll be open-sourcing my work on this topic soon on my Github, it will be accompanied by a post here, so..SubscribeSimply put, an AAVE V2 Liquidation is:A user has previously supplied Collateral a...]]></description>
            <content:encoded><![CDATA[<h2 id="h-heres-what-i-wish-i-knew-about-this-weird-creditor" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Here’s what I wish I knew about this weird creditor</h2><p>If you have an understanding already, just skip to the bottom. Otherwise, there is info here that may help you make or improve your own bot.</p><p><em>Note: The open-sourcing of this research is funded by </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://buidlguidl.com/"><em>BuidlGuidl</em></a><em> &amp; in a general sense, </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://protocol.ai/blog/transcription-vitalik-buterin-funding-the-commons/"><em>Public Goods Funding</em></a><em>. I’ll be open-sourcing my work on this topic soon on my </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/simplemachine92"><em>Github</em></a><em>, it will be accompanied by a post here, so..</em></p><div data-type="subscribeButton" class="center-contents"><a class="email-subscribe-button" href="null">Subscribe</a></div><h2 id="h-simply-put-an-aave-v2-liquidation-is" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Simply put, an AAVE V2 Liquidation is:</h2><ul><li><p>A user has previously supplied <strong>Collateral</strong> and <strong>Borrowed</strong> an asset. The borrowed asset could be the same as the supplied asset.</p></li><li><p>The health value of their position has moved below 1.</p></li><li><p>A liquidator sends a tx that repays a <strong>Borrowed (debt)</strong> asset and chooses which <strong>Collateral</strong> to receive.</p></li></ul><p>The liquidator receives the <strong>Collateral</strong> plus the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://docs.aave.com/risk/v/aave-v2/asset-risk/risk-parameters">liquidation bonus</a>, a percentage determined per asset by the AAVE protocol, <strong>that varies per asset</strong>.</p><p>To help collect the necessary data, AAVE offers a <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/aave/aave-js">js package</a> that queries its Subgraph. I personally opted to listen for events emitted from <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://etherscan.io/address/0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9">v2 Lending Pool</a>.</p><h3 id="h-tips-for-reducing-down-to-profitability" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Tips for reducing down to profitability:</h3><ul><li><p>We need to clear a Collateral &gt; the debtToCover, and <strong>select whichever has the highest liquidation bonus</strong> in order to maximize profit.</p></li><li><p><strong>Lodash</strong> (uniqBy, maxBy, filter) will be your bff for combing through this data.</p></li><li><p>We need to know <em>exactly</em> how much collateral we are receiving, and it is helpful to know exactly the debt to be covered.</p></li></ul><pre data-type="codeBlock" text="const largestDebt: Debt = _.maxBy(
      liqParams[0],
      function (o: { debtPriceEth: number }) {
        return o.debtPriceEth;
      }
    );

    // Filter by amounts greater than debtToCover
    var collatGreaterThan: Collat[] = _.filter(
      liqParams[1],
      function (o: { collatPriceEth: number }) {
        if (o.collatPriceEth &gt;= largestDebt.debtPriceEth / 2) {
          return o.collatPriceEth;
        }
      }
    );

    // Finds the most profitable collateral to liquidate
    const largestCollat: Collat = _.maxBy(
      collatGreaterThan,
      function (o: { liquidationBonusMultiplier: number }) {
        return o.liquidationBonusMultiplier;
      }
    );
"><code>const largestDebt: Debt <span class="hljs-operator">=</span> <span class="hljs-keyword">_</span>.maxBy(
      liqParams[<span class="hljs-number">0</span>],
      <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">o: { debtPriceEth: number }</span>) </span>{
        <span class="hljs-keyword">return</span> o.debtPriceEth;
      }
    );

    <span class="hljs-comment">// Filter by amounts greater than debtToCover</span>
    <span class="hljs-keyword">var</span> collatGreaterThan: Collat[] <span class="hljs-operator">=</span> <span class="hljs-keyword">_</span>.filter(
      liqParams[<span class="hljs-number">1</span>],
      <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">o: { collatPriceEth: number }</span>) </span>{
        <span class="hljs-keyword">if</span> (o.collatPriceEth <span class="hljs-operator">></span><span class="hljs-operator">=</span> largestDebt.debtPriceEth <span class="hljs-operator">/</span> <span class="hljs-number">2</span>) {
          <span class="hljs-keyword">return</span> o.collatPriceEth;
        }
      }
    );

    <span class="hljs-comment">// Finds the most profitable collateral to liquidate</span>
    const largestCollat: Collat <span class="hljs-operator">=</span> <span class="hljs-keyword">_</span>.maxBy(
      collatGreaterThan,
      <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">o: { liquidationBonusMultiplier: number }</span>) </span>{
        <span class="hljs-keyword">return</span> o.liquidationBonusMultiplier;
      }
    );
</code></pre><blockquote><p>Lodash makes combing our data EZY.</p></blockquote><p>The last on this list was the most challenging to solve. AAVE didn’t seem to have any view functions to get the exact debtToCover or collatReceived, and the docs instead point you toward a set of formulas,.</p><p>Also, depending on which conversions you use via Ethers.js or otherwise, you could end up dropping some granularity along the way:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/e946d0196211c53e70ff3c0b1e12384e3ea61b702ea0651983383561ab0d1af5.png" alt="Surely, nothing could go wrong?" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Surely, nothing could go wrong?</figcaption></figure><p>After many botched calculations, I instead <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://etherscan.io/address/0xA67BdecB3FB056F314Dcc76F3ACd3B3F936C52ca">deployed</a> a provider contract <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/simplemachine92/Gavel-Data-Contracts">that grabs these params directly from AAVE</a>. If you’d like to use that to skip the headache of bigint calculations, <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://gist.github.com/simplemachine92/3e1f2568af148fa9c11ed619613c6267">here’s the ABI</a>. I forgot to verify the contract, sorry to the eth-sdk users, but it’s pretty easy to rig this up with Typechain, and then..</p><pre data-type="codeBlock" text="const liqInfo = await liqData.liquidationCallData(
      largestCollat.collatT,
      largestDebt.debtT,
      address,
      ethers.constants.MaxUint256,
      false
    );
"><code>const liqInfo <span class="hljs-operator">=</span> await liqData.liquidationCallData(
      largestCollat.collatT,
      largestDebt.debtT,
      <span class="hljs-keyword">address</span>,
      ethers.constants.MaxUint256,
      <span class="hljs-literal">false</span>
    );
</code></pre><blockquote><p>A call to “liquidationCallData()” returns debtToCover (at index [0]), collatToReceive (at index [1], and a string which alerts us if any errors occured at index [2].</p></blockquote><p>And just like that, you know exactly how much <strong>debtToCover</strong> and <strong>collatReceived</strong> for a particular liquidation call. I’ll cover estimation and execution in the next post.</p><p><em>These are just tools/discoveries along my path of building software. I am in no way a financial expert, or traditionally trained in anything, and I’m most certainly an inexperienced writer. If you have questions, ask me on </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/nowonderer"><em>twitter</em></a><em> or visit the </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://t.me/+PXu_P6pps5I5ZmUx"><em>BuidlGuidl telegram</em></a><em>.</em></p>]]></content:encoded>
            <author>justn@newsletter.paragraph.com (nowonder)</author>
        </item>
    </channel>
</rss>