<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jonnyhimalaya on Medium]]></title>
        <description><![CDATA[Stories by Jonnyhimalaya on Medium]]></description>
        <link>https://medium.com/@jonnyhimalaya?source=rss-f2bbd9fd8a10------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NfW98yPujf7N0Fyxg3PSew.jpeg</url>
            <title>Stories by Jonnyhimalaya on Medium</title>
            <link>https://medium.com/@jonnyhimalaya?source=rss-f2bbd9fd8a10------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 15:13:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jonnyhimalaya/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building DeFi on Bitcoin — An Overview of the Current Landscape.]]></title>
            <link>https://medium.com/@jonnyhimalaya/building-defi-on-bitcoin-an-overview-of-the-current-landscape-1faa74cd2676?source=rss-f2bbd9fd8a10------2</link>
            <guid isPermaLink="false">https://medium.com/p/1faa74cd2676</guid>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[ordinal]]></category>
            <category><![CDATA[defi]]></category>
            <dc:creator><![CDATA[Jonnyhimalaya]]></dc:creator>
            <pubDate>Tue, 03 Sep 2024 15:22:44 GMT</pubDate>
            <atom:updated>2024-09-03T15:22:44.910Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building DeFi on Bitcoin — An Overview of the Current Landscape.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*nHJN0U-0gzPI3SyjWdbyJQ.png" /></figure><p>The rapid growth of the Ordinals protocol, and subsequently the BRC20 and Runes ecosystems, highlighted the market’s acceptance of off-chain indexing. This is an important concept to understand. For example with Ordinals; by ordering sats, data “inscribed” onto those sats could be catalogued using an off-chain indexer, ORD. The ORD indexer is a program that follows certain rules outlined by the Ordinals protocol to catalogue and present certain information that has been inscribed into the “Witness” section of a Bitcoin Transaction. So the data is on the Bitcoin block-chain, but an indexer is needed to scan the blockchain to search for, organise and present that data.</p><p><a href="https://x.com/domodata">Domo</a> took this idea further when he developed the BRC20 protocol. By inscribing certain instructions onto the blockchain using the Ordinals protocol, tokens could be deployed, minted and transferred. BRC20 mints, transfers and balances could be tracked by a new indexer, the BRC20 indexer. The BRC20 indexer would then calculate the address balances associated with each token. Therefore the BRC20 indexer relies on the ORD indexer.</p><p>Runes, the token protocol developed by the creator of Ordinals, <a href="https://x.com/rodarmor">Casey Rodarmor</a>, works quite differently to BRC20s. It is UTXO based, rather than account based, and it does not rely on the Ordinals protocol. Therefore, it can be said that Runes is perhaps more native to Bitcoin than BRC20s. However, the Runes protocol still relies on an indexer, the Runes Indexer, to track mints, transfers, balances and store the state.</p><p>Bitcoin currently does not have functional on-chain smart contracts or sufficient virtual machine capabilities. This is why we have not seen a DeFi ecosystem develop on Bitcoin to the extent that we have seen on other blockchains. However, this is beginning to change with the use and acceptance of off-chain indexers that can mimic this smart contract functionality, even beyond simply just the deploy, mint and transfer of tokens. Technically all sorts of functions and computations are possible, as long as the market accepts these off-chain computations.</p><p>There are a variety of teams trying to build protocols and products to help foster a token DeFi ecosystem native to Bitcoin. This article will provide an overview of some of those products, with an aim to help the reader understand the technology and the subtle differences between these approaches. It is also important to note that the following protocols/projects are not necessarily competing with each other. In fact, some of them complement each other very well.</p><h3><strong>TAP Protocol</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IGr3uJ6-ZcvkZMwW" /></figure><p>Website: <a href="https://trac.network/">https://trac.network/</a></p><p>Twitter: <a href="https://x.com/tap_protocol">https://x.com/tap_protocol</a></p><p>Tap protocol is a multi-asset protocol that enables DeFi features directly on Bitcoin L1, built on top of ORD, by the TRAC team. The TRAC project aims to provide decentralised indexing and oracles for Bitcoin and other blockchains. They were the first team to recognise the limitations of the BRC20 protocol and begin to build a solution, the Tap Protocol.</p><p>Tap, similar to BRC20s, is built on top of the Ordinals protocol. Instructions are inscribed as an Ordinal, and the Tap indexer scans for these instructions, performs the appropriate computations and updates balances etc. What sets Tap apart from BRC20 is the increased level of functionality coded into the indexer, beyond simply the deploy, mint and transfer of tokens. The TAP Protocol is capable of being embedded into other blockchains, expanding its utility even further and also letting other chains tap into Bitcoin.</p><p>Additional features(operations) of the Tap indexer:</p><ul><li>Token Authorities — This operation allows third parties to authorise token transfers based on certain rules or conditions. This is an important feature of any defi ecosystem; the ability to program token actions based on certain criteria. This feature facilitates staking rewards, distribution of in-game rewards, cross chain token bridges, tokenized membership applications.</li><li>Privilege Authorities — This feature essentially supports on-chain whitelisting and non-snipable mints. Anyone who was front-ran during an ordinals or BRC20 mint will understand the importance of this feature.</li><li>Token Send — This feature allows the sending of tokens to multiple wallets with one transaction. This allows very cheap airdrops and batch sending of tokens. Airdrops now only cost a few dollars to deploy, a saving of thousands when compared to BRC20 or Runes.</li><li>Token Trade — Allows for peer to peer trading of tokens without any middleman or smart contracts. Optional fees can be applied to marketplaces and wallets implementing this feature.</li><li><a href="https://digital-matter-theory.gitbook.io/digital-matter-theory">DMT — Digital Matter Theory</a>; the creation of assets based on data from the Bitcoin blockchain. This concept has excited builders in the ecosystem, particularly in relation to the creation of Metaverse assets. Item/spaces can be created based on <a href="https://x.com/tap_protocol/status/1829517562792874217">data engrained in Bitcoin</a>, rather than random decisions made by humans. This can introduce scarcity and structure to the metaverse that is beyond human decisions, an important step towards a decentralised metaverse economy. Perhaps the most famous use of DMT so far has been the <a href="https://magiceden.io/ordinals/marketplace/dmtnatcats">NatCats collection</a>, where the features and the rarity of each image is derived from certain patterns in the block data.</li></ul><p>The operations mentioned above add a certain amount of flexibility to what can be achieved directly on Bitcoin by using indexers . These features are intended to attract developers who are interested in building Bitcoin native applications to build on the Tap protocol. These features are coded into the indexer. The ability to modify these features or add new features will be governed by the TRAC token.</p><p>Whilst the features described above facilitate a wide range of use cases for a successful decentralised token ecosystem, they don’t cover all possible use cases provided by a Turing complete smart contract blockchain. To further extend the smart contract functionality of the protocol, Tap are leveraging the Chain Fusion technology from ICP.</p><h3>ICP and Chain Fusion.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LTcCTJqM079j3d8X_P6vog.png" /></figure><p>Website: <a href="https://internetcomputer.org/chainfusion">https://internetcomputer.org/chainfusion</a></p><p>Twitter: <a href="https://x.com/dfinity">https://x.com/dfinity</a></p><p>Internet Computer (ICP) aim to provide decentralised serverless compute for developers of apps and products, with a focus on the use of smart contracts. It also enables smart contracts which are hosted on ICP to create transactions on other blockchains. With ICP’s Chain Fusion technology it is possible to have smart contracts interact with Bitcoin L1.</p><p>Currently Bitcoin does not have native Turing Complete smart contract functionality. Metaprotocols, such as BRC20 and TAP use off-chain indexers to mimic smart contract computations and state updates. However, the operations must be coded into the indexer in order for the functionality to exist. True smart contract capability should allow for the creation of any arbitrary operation, permissionlessly, without having a central entity or DAO in control of what can and cannot be built into the indexer. This is a drawback of many meta-protocols that use off-chain indexing to emulate the smart contract functionality.</p><p>This is where ICP’s Chain Fusion offers a solution. ICP has the ability to read from, write to, and sign transactions on the Bitcoin blockchain. Developers can create smart contracts that interact directly with the Bitcoin chain. ICP uses Threshold Schnorr signing based on MPC to enable trust minimised integrations with the Bitcoin Network. ICP enables applications on layer one Bitcoin to have smart contract functionality without having to wrap tokens or bridge to another blockchain or layer 2.</p><p>For example; an important application in a DeFi ecosystem is a Decentralised AMM. How can one set up fully decentralised and permissionless liquidity pools on Bitcoin, since Bitcoin has no native smart contracts to which a liquidity provider can send funds? By creating a smart contract (cannister) hosted on ICP. This cannister is capable of creating a Bitcoin address, which can serve as a liquidity pool. The private keys for this address are protected by the Threshold signing network. So a user could add/remove liquidity from their own Bitcoin wallet by initiating a Bitcoin transaction which can be read by the ICP cannister. This cannister can then complete any necessary “smart contract” computations and state updates, and subsequently create and sign a transaction on the Bitcoin chain, using the Threshold Schnorr scheme. This creates a much more permissionless and decentralised way of adding/removing liquidity to/from a liquidity pool on Bitcoin than the current available approach, which mainly use a multisig custodial solution. The end user would only ever interact with Bitcoin, and can be completely unaware that ICP technology has been used in the background to facilitate the transaction.</p><p>The ability to create smart contracts that can seamlessly interact with the Bitcoin blockchain and sign Bitcoin transactions, without necessarily having to bridge, makes ICPs Chain Fusion technology an exciting product for developers interested in building applications on Bitcoin. This is why Tap Protocol is leveraging this technology to help complete their offering as a go to ecosystem for DeFi on Bitcoin. Fully permissionless and more decentralised AMM exchanges can be developed for Tap assets.</p><p>Tap protocol has been in development for over a year. Many features are already live on Bitcoin main-net, with more advanced features, such as the ICP integration, coming soon. Tap have a head start on their competitors. There are numerous projects building their applications on the Tap protocol; <a href="https://x.com/FoxxiOfficial">Foxxi</a>, <a href="https://x.com/traverse_io">Traverse</a> and <a href="https://x.com/GhostyCash">Ghosty.cash</a> to name a few.</p><h3>Op_Net</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0YgAPPA9xbXFgJLI" /></figure><p>Website: <a href="https://opnet.org/">https://opnet.org/</a></p><p>Twitter: <a href="https://x.com/opnetbtc">https://x.com/opnetbtc</a></p><p>Op_Net is a bitcoin aligned metaprotocol, which operates outside of the Ordinals envelope, i.e. it does not rely on the Ordinals indexer. It was designed to facilitate fully open, permissionless and decentralised applications on Bitcoin Layer 1. To achieve this, they have effectively built their own version of ORD, where the functionality is geared towards tracking addresses and smart contract executions, rather than tracking sats and digital artifacts. Smart contracts can be executed by off-chain indexers (Op_Net Nodes) via their WASM based virtual machine. The use of WASM means that a variety of different programming languages can be used to create the smart contracts.</p><p>Flexibility, openness and permissionless app design has been the main mantra from the Op_Net team, which boast almost 20 members. Op_Net uses an account based model, similar to EVMs, such that any app which can be built on Ethereum, can be forked and built on Op_Net. Op_Net can also be deployed on any other Taproot enabled Bitcoin fork or sidechain, such as Fractal or Bellscoin.</p><p>Since Op_Net is a meta-protocol, a smart contract version of ORD, there is no native Op_Net token. All transaction fees and execution fees are paid in Bitcoin. When a developer creates and uploads a smart contract, a new, unspendable, Bitcoin public key (address) is created which hosts the contract. To interact with this contract, users essentially send a Bitcoin transaction to that address, and this transaction contains extra data that instructs the indexer on what functions to invoke from the smart contract. All transaction and execution fees sent to this address are effectively burned.</p><p>Op_Net will have its own ecosystem of DeFi applications, and its own token standard, OP20. Op_Net offers users multiple ways to onboard into their ecosystem. Users can mint tokens, or purchase OP20 tokens directly with their BTC, using PSBTs, or alternatively, they can ‘wrap’ their BTC into the ecosystem. For example, users who wish to interact with the OP20 standard in an Op_Net native application or smart contract, can first bridge Bitcoin to receive WBTC, the OP20 version of pegged Bitcoin. This is analogous to how users must wrap their Eth to wEth to interact with swaps and smart contracts on Ethereum. Users wishing to swap BTC for and OP20 token on <a href="https://x.com/MotoswapBTC">Motoswap</a> (native Dex) can wrap and swap all in the same block, an important feature for a smoother user experience. There will be a few options for bridging and wrapping, all secured by Op_Net’s “Proof of Authority” nodes, a subset of the Op_Net nodes, run by trusted parties.</p><p>Perhaps the most impressive feature of Op_Net is the amount of resources already built in preparation for the launch on mainnet. There is an abundance of documentation to help developers get started, a wallet application and even a block explorer, <a href="https://opscan.org/">Op_Scan</a>. Using Op_Scan users can upload and verify smart contracts, browse balances, transactions and states, interact with smart contracts etc. They are also building their version of the OpenZeppelin library for building secure smart contracts. With all of these resources and open permissionless nature, it is no surprise that many developers have begun building their applications on Op_Net. A selection of projects can be found on their <a href="https://opnet.org/">homepage.</a></p><h3>Arch</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uzGT1bbL3qqSZvUwUioSXQ.png" /></figure><p>Website: <a href="https://www.arch.network/">https://www.arch.network/</a></p><p>Twitter: <a href="https://x.com/ArchNtwrk">https://x.com/ArchNtwrk</a></p><p>Arch network is a Bitcoin native application platform that enables smart contract like functionality on Bitcoin. The core innovations are their Arch VM and their Decentralised Verifier Network. The Arch VM, which is based on the Solana VM, produces the computation for the smart contract execution. This is an off-chain VM in relation to Bitcoin Layer 1. The Decentralised Verifier Network control the multisig wallets, (each node has a key share) and can sign and broadcast transaction back to main Bitcoin Layer 1 blockchain.</p><p>What are the differences between Arch and Op_Net? Op_Net is a meta-protocol, where the smart contracts are posted on chain and all transactions occur on-chain. These transactions trigger smart contract executions in an off-chain indexer Virtual Machine(Op_Net nodes). The Op-Net VM is a “read only” state machine. This means it can read transactions from the Bitcoin blockchain, and update the “State” of the ecosystem through it’s VM. It cannot “write” back to the blockchain to trigger subsequent Bitcoin Layer 1 transactions. Using WBTC in the Op_Net ecosystem can emulate these capabilities, which of course introduces a level of trust in the Op_Net Proof of Authority nodes.</p><p>Arch on the other hand is a “read” and “write” application platform. Arch has state transition functions (like Op_Net) but also asset transfer capabilities on Bitcoin Layer 1. From this point of view, Arch is quite similar to the Chain Fusion protocol from ICP in terms of read and write functionality related to Bitcoin. The smart contract logic is held off-chain, in the Arch VM. The output of this VM computation is passed on to the Decentralised Verifier Network (DVN) to be “confirmed”. This DVN can then sign and broadcast any subsequent transactions on Bitcoin Layer 1, to initiate any asset transfers that were an output of the smart contract execution. Once again, there are some trust assumptions related to the Verifier Network.</p><p>Arch essentially enables the creation of smart contract controlled wallets, that can programmatically send Bitcoin native assets, such as Ordinals, BRC20s and Runes. This feature enables the creation of more interesting apps, especially for those who want to have functionality on Bitcoin Layer 1, without having to wrap or bridge to another chain or L2. When an app end user initiates a “smart contract” call, a Bitcoin transaction will pop up on their screen, which the user can sign. The Arch VM handles the logic and the Decentralised Verifier Network can sign and broadcast the subsequent transaction on Bitcoin. The user can be completely unaware of the use of Arch in the background and simply have a native Bitcoin experience.</p><p>Arch has a couple of different offerings, various levels of trust, functionality and decentralisation a project can take on when building an app on their architecture. For example, in the case of an AMM; Liquidity providers can lock funds in the Decentralised Verifier Network to create a liquidity pool. This liquidity pool is custodied by the Arch Verifier Network. Traders can trade and swap trustlessly with this liquidity pool. In this model, the makers (LPs) take on the trust assumptions of Arch Network, but the takers (swappers) can trade in a completely trustless way. This is similar to how Dotswap currently works, and exactly the same as what TAP is doing with ICP. Arch’s combined FROST/ROAST signing system is quite novel and more secure than most other options being used in the market right now to sign multisig transactions.</p><p>The above AMM example abstracts some of the computation and handling of private keys away from Bitcoin Layer 1 and in to Arch network, but all transactions still take place on Bitcoin L1. Another option, for increased functionality, transaction speeds, but also increased trust assumptions, would be to use Arch network as a de-facto Bitcoin Layer 2. Users can bridge their funds to the Verifier Network and interact with apps that are completely hosted on Arch, taking advantage of the power of the VM and the 2 second transaction times.</p><p>What Arch are building is quite similar to ICPs Chain Fusion integration with Bitcoin, from a use case perspective at least. One key difference is how they store state. ICP stores state locally in their cannisters, whereas Arch stores state in a more decentralised manner, in the Verifier Network, and state transitions are posted back on to the Bitcoin Network. Arch’s goal to unify all of the fragmented liquidity across all Bitcoin metaprotocols, by enabling cross metaprotocol swaps, is much needed in the ecosystem. Therefore Arch has the potential to become the inter-operability layer between the many different meta-protocols on Bitcoin, such as BRC20, TAP, OpNet etc.</p><h3>Fractal</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SkbRj7sqmELRGr0eFDvXJg.png" /></figure><p>Website: <a href="https://www.fractalbitcoin.io/">https://www.fractalbitcoin.io/</a></p><p>Twitter: <a href="https://x.com/fractal_bitcoin">https://x.com/fractal_bitcoin</a></p><p>Fractal is a new Bitcoin side-chain being developed by the Unisat team, who are responsible for most of the development in the BRC20 ecosystem. Their main goal was to build a blockchain as similar as possible to Bitcoin, but with a focus on faster blocks and cheaper fees. Fractal want their blockchain to be seen as an extension of Bitcoin, rather than a separate chain. Fractal is the first ‘Taproot enabled’ Bitcoin fork. The codebase of the Fractal blockchain is almost identical to Bitcoin L1, but with a few small changes to introduce these “scaling solutions”. Users who trade their assets on Bitcoin can easily move to Fractal when Bitcoin fees or congestion rises. There are many Bitcoin Layer 2s and sidechains, but Fractal has the most potential to be <strong>THE</strong> Bitcoin sidechain, for a number of reasons.</p><p>Fractal is a Proof of Work blockchain, which is mined using a “Cadence Mining” process. One third of the blocks are merge mined with Bitcoin, and two thirds of the blocks are mined by Fractal nodes. Since Fractal uses the same SHA256 hashing algorithm as Bitcoin, existing Bitcoin hashpower can be directed to also mine Fractal, without the need for miners to upgrade their equipment. Agreements have been made with many large Bitcoin mining pools and Fractal regarding this “Cadence Mining” process. This is a great way to bootstrap the hashrate for the new POW blockchain.</p><p>Since Fractal has Taproot enabled, Fractal users will have the same wallet address as on Bitcoin Layer 1. This will contribute to a smooth user experience, as users can simply switch in-app between Fractal and Bitcoin mainchain. This also allows airdrops of assets on Fractal based on what assets a user has in their Bitcoin L1 wallet, which will be a great way to onboard users from various Bitcoin Ordinals, BRC20 and Runes communities. This seems obvious now, but no other sidechain or layer 2 has this capability.</p><p>Regarding the transfer of assets between Bitcoin L1 and Fractal; the Fractal team have stated that there will be a few bridging options available, and users can decide on their bridging method of choice. It is important to understand that all of these bridging methods will come with trust assumptions, as a trustless bridge has yet to be developed.</p><p>Fractal was born from a demand for a better user experience when trading Bitcoin tokens. The Fractal team are launching <a href="https://fractal-testnet.unisat.io/swap">“Pizza Swap”</a>, which will be a BRC20 focused swap, which, once again, will use off-chain indexing to handle the swap logic. The hope is that this will re-invigorate the BRC20 community. The Fractal ecosystem is already starting to grow with many projects in the pipeline.</p><p>Fractal is like Bitcoin, but with cheaper fees and faster blocks. Perhaps the most exciting feature of Fractal is their decision to include OP_CAT upon their launch on September 9th.</p><h3>OP_CAT</h3><p>OP_CAT is an old <a href="https://x.com/hbeckeri/status/1828632146019525104/photo/1">Bitcoin OpCode</a> that was originally included in the early versions of Bitcoin but was since disabled, along with about ten other OpCodes. An OpCode is a piece of code that gives Bitcoin the ability to perform a certain function. For example OP_MUL, another disabled OpCode, gives Bitcoin the ability to multiply two integers. Yes, currently Bitcoin doesn’t even have the ability to multiply two integers.</p><p>OP_CAT is a code that essentialy allows you to concatenate (merge) two strings. What makes OP_CAT very interesting is how it can be used to mimic the functionality of many of the other disabled OpCodes. By activating OP_CAT, Fractal has basically activated the ingredients to create a ‘<a href="https://youtu.be/3Rr16uye_tE?si=uQ4hbGcDN22Ij0cl">Turing Complete’ Virtual Machine</a>, directly on Fractal, without the need for an external off-chain indexer. OP_CAT enables Covenants. Covenants are programmable spending conditions enforced on a UTXO. Using OP_CAT to create Recursive Covenants can allow one to store state directly in Bitcoin transactions, thus facilitating the creation of a Virtual Machine on Bitcoin. This is very exciting. All of the “smart contract” solutions mentioned above (TAP/ICP, Arch, OpNet), require some element of off-chain indexing to handle the computation and store the state. By enabling OP_CAT, Fractal is enabling the possibility of having all of this be achieved directly on chain. It will also be interesting to see how current products, such as BRC20 marketplaces, leverage OP_CAT to improve their functionality and user experience.</p><p>There have been tremendous efforts lately to get OP_CAT re-activated on Bitcoin Layer 1. <a href="https://x.com/TaprootWizards">The Taproot Wizards</a> have been the main driver of this initiative. OP_CAT had originally been disabled over fears that badly programmed scripts could cause memory problems or infinite loops on the Bitcoin blockchain. Ever since the Taproot upgrade, which placed a limit on script size, this fear has been somewhat mitigated. The increased interest in an ecosystem built directly on Bitcoin Layer 1, ignited by Ordinals, has led to this renewed effort to get OP_CAT re-activated on Bitcoin mainnet. Until this happens, Fractal can be seen as a live testnet for builders interested in building native smart contract applications directly on Bitcoin. Builders from other similar UTXO blockchains where OP_CAT has been enabled, such as BSV, are flocking to Fractal to showcase their skills. The following <a href="https://www.bedlamresear.ch/posts/script/">research report by Bedlam Research</a> is highly recommended for those who wish to deepen their understanding of OP_CAT and Bitcoin Script.</p><h3>sCrypt</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JZWu1RNUWRTIVWYzWZ8ybA.png" /></figure><p>Website: <a href="https://scrypt.io/">https://scrypt.io/</a></p><p>Twitter: <a href="https://x.com/scryptplatform">https://x.com/scryptplatform</a></p><p>sCrypt have built a compiler to help developers create applications on Bitcoin using Bitcoin Script. Bitcoin Script is a low level language, it runs at the bytecode level. There a only a small number of developers in the world proficient in writing Bitcoin Script. sCrypt is a compiler that can take the Typescript language and compile it into Bitcoin Script, which can then be interpreted by the Bitcoin blockchain.</p><p>sCrpyt is therefore quite similar to Solidity on Ethereum. Ethereum has a low level OpCode scripting language too, which is also quite challenging to use. Most Ethereum developers use Solidity, which is a higher level language, much easier for developers to use. The Solidity compiler then compiles this code into the bytecode to be read by the Ethereum blockchain. There are an estimated 30,000 Solidity developers in the world.</p><p>What makes sCrypt possibly more interesting than Solidity is that it uses Typescript as the input. There are an estimated 20 million Javascript developers in the world, who could essentially learn Typescript in a few days, as the two languages are almost identical. Once a developer is proficient in Typescript, they can use the abundance of <a href="https://docs.scrypt.io/">sCrypt resources</a> and interesting <a href="https://by-example.scrypt.io/">examples</a> to begin writing apps for Bitcoin. Fully on-chain apps that do not rely on external indexers.</p><p>sCrypt had initially been developed for writing applications on Bitcoin SV, since all of the OpCodes and functionality are available on BSV. With the addition of OP_CAT to Fractal and the hope of re-enabling of OP_CAT on Bitcoin mainnet, sCrypt is suddenly a very interesting product. There are many teams gearing up to use Fractal to develop their Bitcoin apps, in preparation for the day that OP_CAT is hopefully enabled on Bitcoin mainnet. sCrypt provides the tools and libraries for these developers to turn their ideas into a reality.</p><p>It is clear that the landscape of Defi and applications on Bitcoin is heating up, and it will be worthwhile to keep a close eye on the developments of the aforementioned projects. Other projects that may be worth taking note of include <a href="https://catvm.org/catvm.pdf">CatVM</a>, <a href="https://x.com/atomicalsxyz">Atomicals</a>, <a href="https://x.com/glittrfi">Glittr</a>, <a href="https://github.com/kungfuflex/protorune/wiki">ProtoRunes</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1faa74cd2676" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Overview of the emerging Bitcoin Layer 1 DEX landscape.]]></title>
            <link>https://medium.com/@jonnyhimalaya/overview-of-the-emerging-bitcoin-layer-1-dex-landscape-5d425a51b14a?source=rss-f2bbd9fd8a10------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d425a51b14a</guid>
            <category><![CDATA[decentralized-exchange]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[decentralized-finance]]></category>
            <category><![CDATA[ordinals-protocol]]></category>
            <category><![CDATA[runes]]></category>
            <dc:creator><![CDATA[Jonnyhimalaya]]></dc:creator>
            <pubDate>Mon, 17 Jun 2024 09:49:54 GMT</pubDate>
            <atom:updated>2024-06-17T12:22:33.643Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>The following article examines a selection of the most promising Layer 1 Bitcoin Dexs and AMMs. Most of these marketplaces are still in development, some still only on testnet. These marketplaces can generally be divided into 2 different categories: OrderBook exchanges and AMMs. Research interviews were conducted with most of the teams covered in this report.</em></strong></p><p>Defi on Bitcoin is coming. We have had little tastes of what defi on Bitcoin could look like, with the emergence of Ordinals, Runes, and metaprotocols such as BRC20 and TAP. The community wants to trade “Shitcoins on Bitcoin”, but the infrastructure just isn’t there yet. But it is coming!</p><p>Currently the trading experience for tokens on BTC is subpar and full of friction. On marketplaces such as Unisat and Magic Eden, sellers of a token (BRC20 or Runes) must list a specific amount of a token at a specific price and wait for a willing buyer to come along for that exact number of tokens at that exact price. This causes friction in the trading experience.</p><p>There are many teams who are trying to solve this problem and bring AMM and Dex style trading to Bitcoin; that familiar trading experience that we are used to from EVMs. Because Bitcoin uses the UTXO model, rather than the account-based model used by EVMs, certain functionalities have to be reimagined. In-fact, UTXOs have some technical features which are unavailable to EVMs in terms of the various ways a PSBT (Partially Signed Bitcoin Transaction) can be designed to create atomic swaps.</p><p>I analysed each marketplace with specific criteria in mind; User experience when swapping, level of decentralization, permissioned versus permissionless and other trade-offs.</p><p>Most teams are innovating with <a href="https://learn.saylor.org/mod/book/view.php?id=36341&amp;chapterid=18919">PSBTs and Sighashes.</a> A Sighash is a mechanism for signing the inputs and outputs of a Bitcoin transaction. There are 6 different types of Sighash, ranging from “Sighash All”, which is the most secure but least flexible, to “Sighash None — Anyone Can Pay”, which is the least secure but most flexible. Current popular marketplaces such as Unisat and Magic Eden use “Sighash-Single” to create their PSBTs. This means that not all outputs have been signed, leaving the transaction open to MEV sniping. Using “Sighash-All” means all inputs and outputs are fully signed, so any transaction signed in this way is protected from MEV sniping.</p><p>There are many other factors to consider when analysing a Dex or Swap, such as liquidity &amp; slippage, maker and taker fees, LP incentives, trade volume etc. However, since most of the marketplaces analysed below are still in testing or early release, it will take time before these other metrics are pertinent.</p><p><strong>Fluid BTC</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*ZrsW9Ojcl313874z0SgFNw.png" /></figure><p>Website: <a href="https://btc.fluidtokens.com/swap">https://btc.fluidtokens.com/swap</a></p><p>Twitter: <a href="https://x.com/FluidtokensXBT">https://x.com/FluidtokensXBT</a></p><p>Fluid Tokens is an orderbook based DEX. Users can currently trade Runes-BTC, and Runes-Runes functionality is coming shortly. Fluid is essentially a marketplace for peer to peer trading. When a trader wants to create an order (maker), they make an offchain “commitment” (eg. I want to sell 1,000 $DOG and receive 0.001 BTC in return). These commitments are posted as limit orders in the order book. When a taker comes along to take the order, ie to market buy or sell, they initiate the PSBT, which details all the inputs and outputs as previously defined by the commitment of the maker. The original maker is then be notified (by email or in-app) that their limit order has been matched, and they then sign the PSBT to broadcast the transaction to facilitate the trade.</p><p>This trading design is completely permissionless and peer to peer. The marketplace is essentially a facilitator of these trades. The trade-off in this case is the back-and-forth user experience. Maker makes commitment, posts limit order — Taker matches order and initiates PSBT — Maker then signs and finalises the PSBT. This friction essentially slows down the trading process, and generally does not allow for that quick sell that traders often need. Another possible issue could be manipulation or spoofing of orders, where a maker creates an order that they have no intention of fulfilling, to try manipulate the price for example. To mitigate this, the Fluid platform only currently allows one maker commitment order per pair per address. Therefore laddering of orders, to scale into a position is not possible yet, but that functionality is on the roadmap.</p><p>All the trades on Fluid are fully permissionless, and also MEV protected and sniper resistant since “Sighash All” can be used in the PSBTs, meaning the transaction is only verified if both the maker and taker addresses are part of the trade. A third party cannot “snipe” the transaction, an issue that often occurs with trades on current popular marketplaces such as Magic-Eden and Unisat. Fluid have prioritised fully permissionless and secure trading, with the drawback of a less smooth trading experience. Fluid are launching their marketplace in the coming weeks.</p><p><strong>Saturn BTC</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*PC514VB0o0aig-sWQoeyFw.png" /></figure><p>Website: <a href="https://www.saturnbtc.io/">https://www.saturnbtc.io/</a></p><p>Twitter: <a href="https://x.com/Saturn_btc">https://x.com/Saturn_btc</a></p><p>Saturn BTC is an orderbook based on-chain exchange, originally launched for rare sats in Summer 2023. They have just launched their marketplace for Runes trading. They have focused on creating a trading experience which is very similar to the smooth experience on centralised exchanges. They have a “peer to peer” orderbook where users can place on-chain limit orders to fill the order book, and users can also market buy, ‘taking’ the existing limit orders in the book. This user experience is quite slick, particularly since the user does not have to worry about splitting up UTXOs or matching the exact requirements of the order placed by the maker. This is a huge improvement on the traditional, more cumbersome Runes trading experience on Unisat and Magic Eden, described above. Saturn also have a “Swap” function, but this is not a swap in terms of AMM style functionality with liquidity pools. By swapping, the user simply market buys the appropriate amount of sell orders that are in the order book, and vice versa.</p><p>To achieve this improvement in trading experience and functionality, particularly in relation to their limit orders and matching engine, Saturn currently requires users to “deposit” their funds onto a “trading account” which is a multisig, signed by the user and co-signed by Saturn. This “trading wallet” will be replaced by single use multi-sigs in their next iteration. When a user creates a limit order, they sign a “Sighash None” PSBT, which technically hands control of the tokens/btc involved in that specific order to the Saturn platform and matching engine, in a 2/2 multisig. The transaction is finalised with “Sighash All” before being broadcast to the mempool, ensuring sniper protection. This trading process means the trader must trust Saturn with the specific funds involved in the transaction, as long as the order remains open. Therefore, the trading experience is not fully permissionless and has some centralised aspects to it.</p><p>Saturn have taken an interesting and innovative approach, by taking the smooth trading experience on centralised exchanges and replicating it directly on chain on BTC Layer 1. They even have full charting functionality in their platform, courtesy of Trading View. There is no need to split orders, the platform takes care of this and there is an ability to have partial fills and multiple wallets in the same transaction. Saturn is a very user friendly, intuitive Dex, with many product improvements and additions in their roadmap.</p><p><strong>UniTap</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*yjyBbdqlMysPzW72SjKwgw.png" /></figure><p>Website: <a href="https://unitap.io/">https://unitap.io/</a></p><p>Twitter: <a href="https://x.com/Uni_Tap">https://x.com/Uni_Tap</a></p><p>Unitap is a Dex being built for the TAP ecosystem. The TAP metaprotocol, enables various aspects of Defi functionality and operations to be carried out directly on Bitcoin Layer 1, using a system of decentralised indexers to aid in computation and account balancing.</p><p>Unitap are building a marketplace to trade not only Tap based assets, but also Tap to Runes. They have a Runes to Tap bridge in development.</p><p>Unitap have designed a completely non-custodial swapping system. Users who wish to sell a token (-tap for example) create a PSBT using “Sighash Single” to specify the exact amount of tokens they wish to sell and what exactly (token and amount) they want to receive in return. This may be BTC or another Tap or Rune token. This creates a very specific sell order, that may take some time to find a match, especially in a less liquid market. To help overcome this friction, Unitap places this sell order into a marketplace among all other orders that match the buy side of that specific sell order. For example, if I would like to sell some $-tap, I can select that token and click on the “Give” tab. This will open a marketplace that contains every buy order of $-tap, where sellers of other assets are looking for $-tap in return for the sale of their asset (see the screenshot above). This adds some flexibility to the marketplace and can help facilitate that quick sell that traders like. Currently Tap-Tap assets are tradeable, with Tap-Runes and Runes-Tap swaps arriving in the coming months.</p><p>Unitap are also launching their own wallet in the coming weeks which will support all TAP operations and support cross-protocol swaps such as Tap-Runes or Tap-BRC20.</p><p><strong>Dotswap</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*EM1lSQ2XijVySKQsaabrMw.png" /></figure><p>Website: <a href="https://www.dotswap.app/">https://www.dotswap.app/</a></p><p>Twitter: <a href="https://x.com/dot_swap">https://x.com/dot_swap</a></p><p>Dotswap is a BTC Layer 1 native AMM style swap for BRC20s, ARC20s and Runes. The trading experience is very similar to how Uniswap works. Users can already swap between BRC20/Bitcoin and Runes/Bitcoin, with Runes/Runes swaps coming soon.</p><p>The Atomic swaps are completely permissionless and non-custodial, using “Sighash All” PSBTs. Users select how much BTC/tokens they want to swap and receive the appropriate amount of the other token in the swap, <strong>all in the same transaction.</strong> The use of Sighash-All means all transactions are sniper resistant.</p><p>The “trade-off” here is that the Liquidity Pools are custodial. When a liquidity provider sends funds into the liquidity pool, these funds are stored in a multisig system, as BTC has no smart contracts to which you can send funds. Dotswap’s unique <a href="https://dotswap.gitbook.io/dotswap/about-dotswap/dotswap-v3">MMM (Multilayered Multisig Matrix)</a> custody scheme was developed in house and operates in collaboration with custodians <a href="https://www.safeheron.com/">Safeheron</a> and <a href="https://www.bitgo.com/">BitGo</a>. The process of adding and removing liquidity is as simple as one would expect, similar to the experience on EVM AMMs. Dotswap were the first team on BTC to implement a centralised sequencer to protect transaction ordering, and therefore pricing, between block confirmations.</p><p>Dotswap have also developed a launchpad for new Runes tokens, which works in a similar way to pump.fun on Solana. Upon launch, participants purchase the specific Runes token with BTC, and the majority of this BTC is used to seed the liquidity pool for that token. Therefore, any Rune that launches on this platform has an immediate liquidity pool where users can swap and trade in a fully permissionless way. Launchpad contributors therefore also own their proportion of the liquidity pool and can earn trading fees.</p><p>Dotswap have developed an AMM which is completely permissionless and non-custodial for the trader/swapper. The liquidity providers are the ones who take on trust assumptions. To this date Dotswap has done over $40M in trading volume. If Dotswap are successful in attracting more liquidity to their pools (favourable trading fees, liquidity mining etc), increased trading volume should follow.</p><p><strong>Ordiswap</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*tKrGWKm5Hz7z_9kPpWytJw.png" /></figure><p>Website: <a href="https://app.ordiswap.fi/stake">https://app.ordiswap.fi</a>/</p><p>Twitter: <a href="https://x.com/OrdiswapLabs">https://x.com/OrdiswapLabs</a></p><p>Ordiswap is an onchain AMM for swapping BRC20 or Runes tokens. Users can swap, provide liquidity, remove liquidity, create a new pool — all on BTC L1. Ordiswap were the first AMM to appear in the BRC20 space last year.</p><p>When a user initiates a swap on Ordiswap (eg. swap BTC for ORDI), they create a transaction which sends their BTC to the Ordiswap LP. This transaction also includes a script, which contains the details of the swap. The Ordiswap back end indexer reads this script and sends the user the appropriate amount of ORDI in a subsequent transaction. This means the user must trust the Ordiswap API when they sign a transaction to initiate a swap.</p><p>Ordiswap uses a combination of off-chain servers, oracles, indexers and BTC nodes to create the AMM functionality. Ordiswap’s server updates the off-chain balances of the users involved in the trade and periodic settlements are performed on-chain. All swaps are currently handled by the <a href="https://ordiswap.gitbook.io/ordiswap/protocol-concepts/osapi">Ordiswap API</a>. This is a slightly less elegant solution than using PSBTs for atomic swaps, which can complete the entire swap in the same transaction. However, atomic swaps on the roadmap.</p><p>The Liquidity Pools are once again custodial, and discussions with custodial partners are currently underway to upgrade security. Their V2 BRC20 swap was live for 2 months and did about $500k total trading volume.</p><p>Ordiswap also has potential to be a leading AMM on Bitcoin, if they can achieve everything they have set out. It’s an ambitious, modular swap implementation on Bitcoin. They are currently in their V3 main-net closed beta stage. Reports are that testing is progressing nicely and they are perfecting the final aspects of their swapping mechanism.</p><p><strong>RunesDex</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b4HwYwyn_Fv9LY0B-Sm7kA.png" /></figure><p>Website: <a href="https://www.runesdex.com/">https://www.runesdex.com/</a></p><p>Twitter: <a href="https://x.com/RUNES_DEX">https://x.com/RUNES_DEX</a></p><p>Runes Dex is another recently launched AMM on Bitcoin Layer 1, for Runes-BTC trading. They are well funded with a big team and are developing fast. They are currently in their <a href="https://x.com/RUNES_DEX/status/1798652506333159844?t=ZqZvzJQa0UzLo1ZR3yrwOQ&amp;s=19">Alpha testing phase on Mainnet</a>. Users can test swapping their native Rune IS•THIS•WORKING. Like the aforementioned AMMs, trading on RunesDex is completely non-custodial and permissionless, but the liquidity pools are custodial. Currently RunesDex is in full control of the private keys, they are stored in a vault using AWS. Custodial partnerships are in the pipeline.</p><p>They are also building a pump.fun style lauchpad, a Runes-tracker which can take into account pending transactions in the mempool, and a Runes bridge which will bridge memecoins from other chains such as Solana onto Runes. They use “Sighash All” for their Dex swap PSBTs, which means that every swap will be sniper resistant. They plan for their LP providers to earn fees in BTC. They have also created an automatic UTXO splitter on the LP side to ensure smooth experience when swapping. RunesDex AMM will be fully live within the coming weeks. Another AMM with potential.</p><p><strong>Runeswap — Swapsats</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MKxIiGc-CezWOBPJo1FtcA.png" /></figure><p>Website: <a href="https://rune-testnet.swapsats.io/">https://rune-testnet.swapsats.io/</a></p><p>Twitter: <a href="https://x.com/Swapsats_io">https://x.com/Swapsats_io</a></p><p>The Runeswap by Swapsats is a Runes-BTC AMM style swap being developed by the team behind the OG sub 10k Ordinals collection <a href="https://x.com/ordinaleggs">Ordinal Eggs</a>. The swap will operate in a similar manner to the swaps mentioned above; a permissionless swapping experience but with a custodial Liquidity Pool.</p><p>Their philosophy, as a group of collectors, is to build a Dex with their community in mind. Holders of their collections will receive benefits on the Dex, such as reduced trading fees and revenue share from Dex income. They are prioritising a slick UI and user experience, to help further cultivate their community. The swap is currently in the alpha testnet phase, with main-net due to go live in the coming weeks.</p><p><strong>RunesFi</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HDuC7yfe0s5O-WCojc__Hw.png" /></figure><p>Website: <a href="https://runesfi.io/">https://runesfi.io/</a></p><p>Twitter: <a href="https://x.com/Runes_Fi">https://x.com/Runes_Fi</a></p><p>RunesFi are aiming to be a one stop infra hub for BTC assets. They intend to build a Runes Block Explorer, Launchpad and Incubator, Runes Engraver and most importantly, a Runes and BRC20 Dex. They are currently in testnet phase of their Dex, with their mainnet product expected to go live before the end of 2024.</p><p>There are some other dexes in development that promise some more decentralisation than those listed above, such as <a href="https://x.com/Omnisats">Omnisats</a> and <a href="https://x.com/MotoswapBTC">Motoswap</a> (OPNet?). I can analyse these when they are closer to launch and more information is available. Unisat have also recently announced their new BRC20 swap module, which will include liquidity pools etc. This is currently in development and should be functional within 6 months. Magic Eden too are teasing about upcoming swap functionality, although the timeline is unclear.</p><p><strong>Concluding Remarks.</strong></p><p>Building on Bitcoin is challenging, especially if trying to directly replicate the functionality of EVMs. Bitcoin’s UTXO model differs from the account based model of EVMs, and those teams that embrace the uniqueness of Bitcoins Mechanics (PSBTs, Sighashes, etc) are more likely to be successful in the long run, versus those who solely try to recreate the EVM stack.</p><p>Teams currently creating innovative solutions are balancing different trade-offs. For example, regarding Orderbook Dexes, <a href="https://www.saturnbtc.io/"><strong>Saturn</strong></a> have prioritised a super-slick user experience and functionality, at the expense of fully permissionless trading. <a href="https://btc.fluidtokens.com/swap"><strong>Fluid</strong></a><strong> </strong>have taken a different approach, prioritising fully decentralised and non-custodial trading, albeit with a little friction in the trading experience. It will be interesting to see which philosophy the market values more.</p><p>In the AMM space, most teams are creating a system where traders can trade in a fully permissionless way, but the liquidity pools are held in some version of a vault, multi-sig or semi-custodial solution. This may be an acceptable trade-off, since most traders will not care how the liquidity pool is set up, as long as they can swap quickly and permissionlessly. Also, considering how many bridges and contracts have been exploited on Ethereum, LP provision to a well known custodian might even be a more attractive solution. At the current moment, <a href="https://www.dotswap.app/"><strong>Dotswap</strong></a> has the advantage here, as they are furthest along in terms of development, product offerings and their LP custody solutions. However, other teams such as <a href="https://www.runesdex.com/"><strong>RunesDex</strong></a> and <a href="https://app.ordiswap.fi/"><strong>Ordiswap</strong></a> are hot on their heels, with their products launching very soon.</p><p>I’m sure there are other teams building that I am unaware of at the time of writing. If you would like your project to be included in this analysis, please contact me:</p><p>Email: jonnyhimalaya@gmail.com</p><p>Twitter: <a href="https://x.com/Enter_the_krypt">https://x.com/Enter_the_krypt</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d425a51b14a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Uniswap V2 Eth-Dai Pool Analysis Building a Complete Dataframe]]></title>
            <link>https://medium.com/@jonnyhimalaya/uniswap-v2-eth-dai-pool-analysis-building-a-complete-dataframe-720f6822a496?source=rss-f2bbd9fd8a10------2</link>
            <guid isPermaLink="false">https://medium.com/p/720f6822a496</guid>
            <category><![CDATA[uniswap]]></category>
            <category><![CDATA[eth]]></category>
            <category><![CDATA[defi]]></category>
            <dc:creator><![CDATA[Jonnyhimalaya]]></dc:creator>
            <pubDate>Tue, 04 Jun 2024 20:28:40 GMT</pubDate>
            <atom:updated>2024-06-04T20:28:40.375Z</atom:updated>
            <content:encoded><![CDATA[<p>The following article was written in early 2021, before many of the modern Defi scanners were available. Impermanent Loss was a fairly new concept at the time.</p><p>Automated Money Markets (AMMs) such as Uniswap are one of the cornerstones of decentralised finance (De-Fi). However, the historical data available on the liquidity pools that make up these AMMs is still quite limited. Websites exist that have some informative liquidity pool related metrics on display for their users (eg. Zapper, Sommelier, APY.vision ), but we are more interested in the raw datasets that can be used to create such metrics, which can also be used for backtesting strategies. This type of blockchain data can be quite difficult to find. Certain projects have raised millions of dollars to provide such blockchain data query tools. Anyone who has tried to use these tools to build a complete dataset on a Uniswap pool will know how challenging this can be, particularly in cases when one can only query data which has previously been arranged into some subset. We wanted the ability to query the smart contract historical data directly, as one can then find the exact information they are looking for when building their dataset. We decided to use the Curvegrid MultiBaas system to build our dataset, along with Python Pandas and our own mathematical models and algorithms.</p><p>Curvegrid’s MultiBaas blockchain middleware provides real time and historical access to the output of smart contract functions, and enriched and aggregated smart contract time series event data. Applications can query MultiBaas’ REST API and users can integrate MultiBaas into their spread-sheets via a plugin.</p><p>Pandas is a powerful, open source data analysis and manipulation tool built on top of the Python programming language. It is widely used in financial analytics, and many Quantitative Analysts will be familiar with it.</p><p>Our goal was to build the most complete view of a Uniswap trading pair (we started with Eth-Dai), in the most efficient way possible, by examining both smart contract function output, and time series event data. The only events we tracked were Mints and Burns of the Uni-V2 Eth-Dai LP token, ie. where liquidity is added to or removed from the pool. We did not track the individual swaps. This is because the number of swaps that occur on the higher volume pools would be so huge, that many millions of API calls would have been needed to import the data. We felt that there might be a more efficient way of doing this analysis.</p><p>How can we analyse the profitability of a liquidity pool, the fees generated, the volume traded, the impermanent loss encountered, without looking at a single swap? This was our challenge. We used various simple mathematical models (based on our study of the Uniswap smart contracts), to infer what the fees earned and impermanent loss encountered must have been, all based on the information and balances every time liquidity was added to or removed from the pool.</p><p>Our latest solution utilises over 1000 lines of Python code and over 200,000 API calls to the MultiBaas system. We queried both event data, along with historical Ethereum archive node data, to construct the following data frame. Some of the columns are populated purely from the result of certain API calls. Other columns are a result of certain mathematical models and calculations involving preceding columns.</p><p>We saved the dataframe as a .csv , .xlsx and .pkl file, each of which can be accessed via the <a href="https://www.curvegrid.com/defi-data">following link.</a> We encourage the reader to download the data and run analysis on it. The dataframe has 59912 rows, each row representing a Mint or Burn event. The dataframe has 27 columns, each column representing either a parameter associated with the specific event, or a snapshot of the state of the liquidity pool at the time of the event. The following article will explain what each column represents, so the reader can understand how to interact with the data.</p><p><strong>Index:</strong> In order to accurately index blockchain events, we constructed a primary key from the following components: </p><p><strong>BlockNum</strong> — The block number in which the event (mint/burn) occurred.</p><p><strong>txIndexInBlock </strong>— The transaction index within a block.</p><p><strong>eventIndexInLog</strong> — The event index within a log (block) There are many cases where multiple mints and burns happen in the same block, so we needed a more accurate index than simply block number or timestamp. Out of 59912 events examined, the distribution of mints and burns per block can be seen in Table 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*mW7BfJl0PSZ4uri8TtWb-g.png" /></figure><p><strong>Timestamp:</strong> The timestamp of the block in which the event was confirmed. Every block has a recorded timestamp. This represents the number of seconds since the Unix Epoch on January 1st, 1970 at UTC. This can be converted into regular date and time. The earliest timestamp in the data set is 1589413386, which points to May 13th 2020, when the pool went live. We can see that the very first event here is a Mint where 200 Dai and 1 Eth were initially added to the pool in block 10060850. <a href="https://etherscan.io/tx/0xe8d096e8662fc1d5bccff6743f99888aed1536dd41055d4fdbe4dd7cd46755a7">[ tx here]</a></p><p><strong>LPChange:</strong> The amount of Uni-V2 Eth-Dai LP tokens being created or destroyed. When one decides to provide liquidity to a Uni-V2 pool, they receive a token which acts as a claim on their proportion of the pool. This figure is sometimes given as an output of the smart contract event and therefore can be requested as part of an API call to MultiBaas. In other instances we had to calculate it by comparing the number of LP tokens in existence before and after the event. For a Mint the amount of LP tokens created is calculated by the following equation, which we found on line 422 of the source code for Uniswap V2 Eth-Dai Liquidity Pool:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*EzqNG4c15rvhFPuGDc7FjQ.png" /></figure><p>where;</p><p>a_0 is amount, a_1 is amount1, R_0 is Reserve0, R_1 is Reserve1, LPS is the supply of Uni-V2 Eth-Dai LP tokens at the time of the Mint.</p><p>These terms are explained in more detail below.</p><p>Uni-V3 will make this metric slightly more difficult to track considering the conditional liquidity provision ranges that are being introduced.</p><p><strong>amount0:</strong> This refers to the amount of Dai being added to or removed from the liquidity pool.</p><p><strong>amount1:</strong> This refers to the amount of Eth being added to or removed from the liquidity pool.</p><p><strong>Reserve0:</strong> This originally was the total amount of Dai in the liquidity pool at the end of the block in which the event has occurred. This consists of Dai that has been added by LP providers, Dai that was swapped in for Eth and also Dai that has been earned in fees. We picked this apart in later columns. Anytime there was more than one mint/burn in the block we did some extra calculations involving amount0, so the Reserve0 column then accurately represents the amount of Dai directly after the mint/burn, as opposed to the end of the block. Even though all mints/burns are not confirmed until the end of the block, doing the calculations this way makes subsequent calculations for fees and impermanent loss a little easier.</p><p><strong>Reserve1:</strong> This was the total amount of Eth in the liquidity pool at the end of the block in which the event has occurred. Eth from LP Providers, swaps, and fees earned. The same logic was used as Reserve0 in terms of using amount1 to calculate a more accurate version of this column, to represent the state after the event as opposed to the end of the block.</p><p><strong>LpSupply:</strong> The number of Uni-V2 Eth-Dai LP tokens that are in existence, at the end of the block in which the event has occurred. These LP tokens are generally held in the wallets of the user who provided the liquidity, but sometimes they are actually held by a 3rd party contract, if the user has provided liquidity to Uniswap through another platform.</p><p><strong>contractName:</strong> The name of the contract calling the mint/burn function. This is generally the Uni-V2 Router, but there are many other contracts interacting with the Uniswap Eth-Dai pool. In fact, we found over 100 different contracts adding and removing liquidity, some of which include 1-Inch, Zapper, Zerion and even Sushiswap migration contracts. Interestingly, we also found 1180 interactions from unkown contracts. Some more sophisticated market participants code their own smart contracts to interact with Uniswap, rather than using the Uniswap UI. While we cannot see the specific functions of these custom made contracts, we can still see their effects on the pool. We are currently separately doing a more detailed study of these various interacting contracts, with this dataframe being our starting point.</p><p><strong>contractAddress:</strong> The address of the contract described in the previous column.</p><p><strong>txName:</strong> The name of the transaction within the contract that is calling the mint/burn. Common examples are addLiquidityEth, removeLiquidityEthWithPermit, startExecution (Zerion), ZapOut (ZapperFi) and many more.</p><p><strong>txHash:</strong> The transaction hash of the mint/burn.</p><p><strong>Wallet:</strong> The public key (Eth address) of the user who is adding/removing liquidity. One simple application of this column is to sort the Data Frame by largest transactions, and create a subset of “Whale” wallets.</p><p>All of the columns described above were populated primarily from API requests to the Curvegrid MultiBaas system. The remainder of the columns described below are created from calculations on pre-existing columns. Some of these calculations were quite simple, others were a lot more intricate. We took particular care to consider that some blocks had multiple mints or burns, and how this would affect some of the rolling calculations.</p><p><strong>Eth Price: </strong>The Eth price on Uniswap at the time of the event. This is created by simply calculating the ratio of the reserves;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/249/1*3l6ZYAXIqQQbuwtJVGvIQA.png" /></figure><p>This represents the Eth price on Uniswap, and this can fall out of line with the Eth price on centralised exchanges. This is seen as the opportunity for arbitrageurs to step in and profit, therefore helping close the arbitrage gap and bring Uniswap prices (ratios) back in line with the rest of the market.</p><p><strong>Total Liquidity:</strong> This is the USD value of the combined amount of Eth and Dai in the liquidity pool, at the end of the block in which the Mint/Burn has occurred. The graph below shows how the liquidity changed over time (red). We can also see how the Eth price has changed (blue) over the same time period.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*EDfCTIkqxp6lFqFatGFDbQ.png" /></figure><p>We can see that there was a huge drop in liquidity provided in November 2020. This is just before the price of Eth really started to move upwards. Did LP providers remove their liquidity in anticipation of the swift appreciation of the Eth price, to avoid whatever impermanent loss they might encounter as a result of the price divergence? What’s important to understand here is that the liquidity never recovered. The small recovery in January 2021 is actually false. Since the Liquidity is measured in USD, the “recovery” we see here is merely just an appreciation of the value of the pool due to the increase in the price of the Eth that is in the pool, not an influx of liquidity. We can actually factor this Eth price out of the Liquidity analysis, and the situation looks more like the graph below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*M0E5uH1AhjxlGOBw--30kw.png" /></figure><p>It is clear from the above image that the liquidity never really recovered when you analyse it from the point of view of the number of tokens in the pool.</p><p>Another strong possibility for the liquidity drop off in the Uni Eth-Dai pool during November 2020 is users migrating their liquidity to Sushiswap. The liquidity in the Eth-Dai pool on Sushiswap increased from $34m to $120m during the same time period as the drop in liquidity on Uniswap. We can also see in our dataframe the increased usage of the SushiSwap migration contract. This contract was designed to migrate liquidity from Uniswap pools to Sushiswap pools, in what’s known as a “Vampire Attack”. If we filter our dataframe to only look at Sushi migration events during November 2020, we can see that $4.8 million were transferred directly from the Uni Eth-Dai liquidity pool to the Sushi pool using the Sushi migration contract alone. Millions more were withdrawn from Uni and deposited to Sushi manually. We are looking at this in more detail in our study on the various contracts interacting with Uniswap.</p><p><strong>Lp Token Value:</strong> The value in USD of the combined amount of Dai and Eth that is the equivalent of 1 Uni-V2 Eth-Dai LP token at the time. This was calculated by simply dividing the Total Liquidity (USD Value) by the total LP token supply at that time. Tracking the performance of the value of 1 LP token over time is a simple way to understand the return from providing liquidity to the pool. The fees earned and impermanent loss encountered are incorporated into this value.</p><p><strong>Lp Token TVH (Total Value if Held):</strong> This column tracks the value of the ‘Holding Portfolio’ equivalent to the ratio and amounts of Eth-Dai necessary for 1 LP token at the beginning. However, in this case the Eth-Dai has not been put into the liquidity pool, therefore the initial ratio is unchanged throughout the time series, so this value is only changing due to the change in the price of Eth. This can be viewed as the opportunity cost of depositing your Eth and Dai into the LP (earning fees and encountering impermanent loss), rather than simply holding the Eth and Dai in a wallet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*WNln0XIq7gKlE8Xbp4ARVg.png" /></figure><p>In the graph above we can see that providing liquidity was more profitable than holding until near the end of 2020. Then once the price of Eth really started to appreciate, the level of impermanent loss encountered by the pool became greater than the fees being earned, thus meaning liquidity providers were now worse off for providing liquidity.</p><p>The graph below tracks this profitability comparison as a percentage of the value of 1 LP token. When this graph turns negative, it is not suggesting that LP provision is yielding negative returns. Rather, it is suggesting that providing liquidity had become less profitable than simply holding the assets. It is also important to note that this analysis is based on comparing strategies from the inception of the pool until the time of this analysis. Selecting different starting points can give quite a different result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*RmbGiZGK6oKsYdsbY1nwmA.png" /></figure><p><strong>Dai Earned:</strong> This column represents the amount of Dai earned in fees by the pool since the last mint/burn.</p><p><strong>Eth Earned: </strong>This column represents the amount of Eth earned in fees by the pool since the last mint/burn.</p><p>To calculate both Dai Earned and Eth Earned figures, we considered the difference in the amount of Dai and Eth in the pool now versus after the previous mint/burn. We also had to consider how much was minted or burned in the event, so as not to count those into the fees earned. The challenging part was accounting for how the ratios of Eth-Dai had changed from swapping and we had to filter this ratio change out of our calculations. Taking all of this into account we came up with the following sets of equations which described the “problem”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*4P2SX9GAnQ4jHliOBZ5DEw.png" /></figure><p>where x and y represent the amounts of Dai and Eth that would exist after the previous event, should no fees have been earned. x and y are such that they satisfy the following ratio related equations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/175/1*59GGE-NXrDuFyMaHYc0Uxw.png" /></figure><p>k is calculated as R0 × R1 , so k_{−1} represents this value taken from the block of the previous mint/burn event. Solving the above for x and y and substituting into equations (3) and (4) gives us the following equations to calculate the Dai earned and the Eth earned by the liquidity pool since the last event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*RfuFdBUjV5VfwDnHPHo-nA.png" /></figure><p><strong>Value of Eth Earned:</strong> This is simply the previous column (Eth Earned) multiplied by the price of Eth at that time.</p><p><strong>Fees Earned:</strong> Dai Earned + Value of Eth Earned.</p><p><strong>Fees Earned per LP:</strong> Fees Earned divided by LP supply.</p><p><strong>Volume:</strong> The fees earned by the pool is 0.3% of the trading volume. Therefore the trading volume should be the Fees Earned divided by 0.003. This column displays the implied trading volume since the last mint/burn event. It is important to understand that the time between such events is arbitrary, so care must be taken if trying to use this data to interpret/calculate the average volume over a certain time period (daily/weekly etc).</p><p><strong>IL Nominal:</strong> The value in USD of the impermanent loss encountered by the pool since the previous event.</p><p><strong>IL %:</strong> The Impermanent Loss (I.L.) of the period since the previous event expressed as a percentage of the Holding Portfolio. The Holding Portfolio refers to where the LP provider has maintained the same Eth-Dai ratio as that of the previous event, rather than having the ratio change by being a part of the liquidity pool. We can calculate this a few different ways. One way is to manually compare the ratios in the pool at the time of the event versus the Holding Portfolio. We also created the following equation to model percentage I.L., from time n to time n+1, based purely on price information:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*nIGVWQX9kFY9qS2F7CdJQg.png" /></figure><p>where, p_0 represents the price of asset 0 at time n, p_1 represents the price of asset 1 at time n, pˆ_0 represents the price of asset 0 at time n + 1, pˆ_1 represents the price of asset 1 at time n + 1.</p><p>The above equation calculates impermanent loss only for liquidity pools which are weighted 50/50 and have simlilar trading mechanics to Uniswap. There are similar formulas to be found, discussed in various other reviews of impermanent loss, for example the following article by <a href="https://dedotfi-guides.medium.com/why-impermanent-loss-calculators-are-wrong-and-how-to-avoid-incorrect-assessment-of-the-money-waste-d349607706fc">DefiYield.info.</a></p><p>We are currently separately doing a more detailed study on impermanent loss using our datasets, from various points of view. For example, we can look at the I.L. from the point of view of each individual wallet (user), and calculate the I.L. that was actually encountered by each liquidity provider during the time in which they provided liquidity. We can then study whether there is a certain level of I.L. users are willing to put up with, before they pull their liquidity and make their impermanent loss become permanent. This statistic may have more importance than simply analysing the hypothetical I.L. between two arbitrary times or price points.</p><p>Currently there is no consensus across the sector on exactly how to quantify and price the risk of I.L., other than these hypothetical calculations. This is something we are examining further. For example, the payoff for providing liquidity depends on the fees earned (a function of volume and the fee itself), the share of the liquidity pool owned, and the price divergence of the two assets in question. An LP provider wants high volume and thus high fees earned, and very little price divergence in order to maximise profits. This payoff is not dissimilar to writing options, more specifically, being the writer of a straddle option strategy. The option writer earns fees as the option premium, but can lose quite a lot if the price moves significantly in either direction. We can use our dataframe to calculate historical fees, price divergences and volatilities and incorporate these into well tested options pricing strategies to gain further understanding in how to accurately price the risk versus reward of providing liquidity. Uni-V3 adds another layer of complexity considering the concentrated liquidity strategy. However, the general ‘shape’ of AMM’s are so far conserved across networks with Cosmos Gravity Dex being a prime example.</p><p>Our dataframes and models are a continuous work in progress, and are constantly being edited and updated as we learn. With our models and algorithms, and utilisation of Curvegrid’s MultiBaas system, we can do this type of analysis (historical and live) on any token pair, on any AMM, on any blockchain. We highly encourage blockchain data explorers to contact us so we can expand our analysis and understanding for AMM’s in a systemic sense. We are currently still exploring what is possible and anticipate using additional tools as they are made available.</p><p>Consideration of the movements in mints and burns are examples of metrics that are not so obvious but have indications on pool and trading pair health. Future work on these dataframes will include additional parameters like gas prices, Bitcoin variance, and altcoin correlations to find relationships and create meaningful clarity into the forces that drive AMM markets. We encourage the reader to download and interact with the dataset, perhaps run some of your own analysis and share it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=720f6822a496" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>