<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Fetch liquidated position on</title><link>https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/4-vault-protocol/7-borrow-second-time/2-fetch-liquidated-position/</link><description>Recent content in Fetch liquidated position on</description><generator>Hugo -- 0.152.2</generator><language>en-us</language><atom:link href="https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/4-vault-protocol/7-borrow-second-time/2-fetch-liquidated-position/index.xml" rel="self" type="application/rss+xml"/><item><title>Liquidations &amp; Factors</title><link>https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/4-vault-protocol/7-borrow-second-time/2-fetch-liquidated-position/1-liquidations-and-factors/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/4-vault-protocol/7-borrow-second-time/2-fetch-liquidated-position/1-liquidations-and-factors/</guid><description>&lt;p&gt;Let&amp;rsquo;s say we have 4 users opening debt positions on 4 different ticks on the &lt;code&gt;ETH / USDC&lt;/code&gt; vault, and let&amp;rsquo;s assume &lt;code&gt;1 ETH = 2500 USDC&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Alice: 15k debt&lt;br&gt;
Bob: 10k debt&lt;br&gt;
Charlie: 25k debt&lt;br&gt;
Eve: 12k debt&lt;/p&gt;
&lt;p&gt;Important to note is that these examples will have one user per tick for simplicity in visuals, although every tick can have multiple positions in it. Fluid never works with individual positions during liquidations, but rather with tick data, which we will also do.&lt;/p&gt;</description></item><item><title>fn: fetchLatestPosition</title><link>https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/4-vault-protocol/7-borrow-second-time/2-fetch-liquidated-position/2-fetch-latest-position/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/4-vault-protocol/7-borrow-second-time/2-fetch-liquidated-position/2-fetch-latest-position/</guid><description>&lt;p&gt;We have background now, so let&amp;rsquo;s revisit the main function for fetching user positions after liquidations:&lt;/p&gt;
&lt;figure&gt;
&lt;img loading="lazy" src="https://rajkoz.com/fluid-vault/vault/fetch-latest-position-2.png"
alt="Vault protocol" width="100%"/&gt;
&lt;/figure&gt;
&lt;h2 id="1-fetch-tick-generation-data"&gt;1. Fetch tick generation data&lt;/h2&gt;
&lt;p&gt;We know that the user got liquidated, partially or fully. Liquidation happened on some branch, that might be, or might not be, merged into another branch (which can also be merged with its base, etc.).&lt;/p&gt;
&lt;p&gt;We also know that the user is part of some epoch, which we call tick ID, which can be the latest current epoch living in the &lt;code&gt;tickData&lt;/code&gt; mapping, or an older epoch that lives in history, in the &lt;code&gt;tickId&lt;/code&gt; mapping.&lt;/p&gt;</description></item><item><title>Update debt and branch data</title><link>https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/4-vault-protocol/7-borrow-second-time/2-fetch-liquidated-position/3-update-debt-and-branch-data/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/4-vault-protocol/7-borrow-second-time/2-fetch-liquidated-position/3-update-debt-and-branch-data/</guid><description>&lt;p&gt;There is one small piece of code left to cover to finish this section of fetching a liquidated position.&lt;/p&gt;
&lt;p&gt;We called the &lt;code&gt;fetchLatestPosition&lt;/code&gt; function, and now the only part left is to update final debt and branch data:&lt;/p&gt;
&lt;figure&gt;
&lt;img loading="lazy" src="https://rajkoz.com/fluid-vault/vault/liquidated-position.png"
alt="Vault protocol" width="100%"/&gt;
&lt;/figure&gt;
&lt;p&gt;First, we check if new raw debt is bigger than previously stored &lt;code&gt;dustDebtRaw&lt;/code&gt;. This simply ensures that net debt is bigger than zero, because we will subtract dust from new raw debt. If that&amp;rsquo;s not the case, we accumulate the difference and mark the user as fully liquidated:&lt;/p&gt;</description></item></channel></rss>