<?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>Fluid Vault Smart Contracts - Deep Dive on</title><link>https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/</link><description>Recent content in Fluid Vault Smart Contracts - Deep Dive on</description><generator>Hugo -- 0.152.2</generator><language>en-us</language><lastBuildDate>Mon, 01 Jan 0001 00:00:00 +0000</lastBuildDate><atom:link href="https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/index.xml" rel="self" type="application/rss+xml"/><item><title>Introduction</title><link>https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/1-introduction/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/1-introduction/</guid><description>&lt;h3 id="overall-architecture"&gt;Overall architecture&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s take a peek at overall Fluid architecture:&lt;/p&gt;
&lt;figure&gt;
&lt;img loading="lazy" src="https://rajkoz.com/fluid-vault/architecture.jpg"
alt="Fluid architecture" width="80%"/&gt;
&lt;/figure&gt;
&lt;p&gt;We can see &lt;strong&gt;liquidity&lt;/strong&gt; at the center, with a few other components branching from there. This is how Fluid can keep iterating faster, as they don’t have to bootstrap liquidity for new products (we can also call them consumers). Liquidity is aggregated in one contract which is handy if you have multiple versions of the protocol, as you don’t have to wait for years for users to migrate to newer versions, you just reuse the liquidity from before.&lt;/p&gt;</description></item><item><title>BigMath Library</title><link>https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/2-big-numbers/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/2-big-numbers/</guid><description>&lt;p&gt;Before we dive into main flows, it&amp;rsquo;s worth exploring how Fluid stores and works with numbers.&lt;br&gt;
In order to compress numbers, Fluid uses a custom-made BigMath library that stores numbers with a coefficient and exponent.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-sol" data-lang="sol"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;number &lt;span style="color:#f92672"&gt;=&lt;/span&gt; coefficient &lt;span style="color:#f92672"&gt;&amp;lt;&amp;lt;&lt;/span&gt; exponent
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;rsquo;s take an example from the Fluid codebase for the decimal number &lt;code&gt;5035703444687813576399599&lt;/code&gt;.
Storing that in binary we get:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-sol" data-lang="sol"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#ae81ff"&gt;10000101010010110100000011111011110010100110100000000011100101001101001101011101111&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now if we take a coefficient of &lt;code&gt;32&lt;/code&gt; bits and an exponent of &lt;code&gt;8&lt;/code&gt; bits, the same number gets represented like:&lt;/p&gt;</description></item><item><title>Finish</title><link>https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/5-finish/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://rajkoz.com/posts/fluid-vault-smart-contracts-deep-dive/5-finish/</guid><description>&lt;p&gt;Congratulations! 🎉🎉🎉 🌊🌊🌊&lt;/p&gt;
&lt;p&gt;We just finished this long deep dive on Fluid internals.&lt;/p&gt;
&lt;p&gt;I hope you learned something new. I certainly did while writing all of this, and I hope that different tricks and complex liquidation design will stick with you once you read future protocols and innovations out there.&lt;/p&gt;
&lt;p&gt;The good thing is that typical DeFi projects out there are not this complex to reason about, so if you really grasped how Fluid works and struggled through the code with me, you are really well prepared to just go out there and read and reason about any codebase.&lt;/p&gt;</description></item></channel></rss>