<?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 KOBA on Medium]]></title>
        <description><![CDATA[Stories by KOBA on Medium]]></description>
        <link>https://medium.com/@KOBA-PERP?source=rss-8cabb6f223d6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*2xjo94AVga8vMisw</url>
            <title>Stories by KOBA on Medium</title>
            <link>https://medium.com/@KOBA-PERP?source=rss-8cabb6f223d6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 01:19:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@KOBA-PERP/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[Fully On-chain Orderbook working with AMM]]></title>
            <link>https://medium.com/@KOBA-PERP/fully-on-chain-orderbook-working-with-amm-2a22a550d19?source=rss-8cabb6f223d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a22a550d19</guid>
            <category><![CDATA[defi]]></category>
            <category><![CDATA[dex]]></category>
            <dc:creator><![CDATA[KOBA]]></dc:creator>
            <pubDate>Tue, 13 Sep 2022 10:09:52 GMT</pubDate>
            <atom:updated>2022-09-13T10:09:52.164Z</atom:updated>
            <content:encoded><![CDATA[<h3>More liquidity means better trading environment</h3><ul><li>AMM is a famous liquidity providing method on DEX, but AMM LP-ing is not always profitable. There are conditions on the volatility and trading fees that AMM makes money.</li><li>In order to stabilize the liquidity in exchange, it is necessary to have a mechanism in which liquidity providers can always make money.</li><li>Thus, to encourage participation of various liquidity providers, we have introduced <strong>fully on-chain</strong> <strong>Orderbook</strong>, which enables traditional profitable market-making.</li></ul><h3>Features of PerpDEX Orderbook</h3><p>PerpDEX’s Orderbook is <strong>fully on-chain</strong>, <strong>low gas price</strong>, <strong>working with AMM</strong>, and of course <strong>0% fee</strong>.</p><h4><strong>(1) Fully on-chain and open-sourced</strong></h4><ul><li>Anyone can read the implementation. see: <a href="https://github.com/perpdex/perpdex-contract/tree/develop/contracts">[code]</a></li><li>Therefore, dishonest implementation is difficult and thus it is expected to be fair to everyone.</li></ul><h4><strong>(2) 10000+ orders can be processed within 1 transaction, but the gas price is cheap.</strong></h4><p>why cheap?</p><p><strong>(a) PerpDEX uses a data structure that requires less computation for orderbook</strong></p><ul><li>It uses <strong>red black tree</strong> for data structure.</li><li>Operations such as search, update and aggregation are <strong>O(logN)</strong>.</li></ul><p>(*N: total number of orders in ask or bid)</p><p><a href="https://medium.com/perpdex/red-black-tree-in-solidity-edcad36452b4">Red black tree in solidity</a></p><p><strong>(b) The lazy-evaluation in execution process of LimitOrder</strong></p><ul><li>When executed, set only flag that “LimitOrder has contracted”</li><li>It is done in the red black tree aggregation process, so computation-cost is <strong>O(logN)</strong>. It’s very cheap.</li><li>The execution process for LimitOrder with that flag will be executed at the time of the next state update operation by its LimitOrder’s owner.</li></ul><h4>(3) Working with AMM</h4><ul><li>Liquidity in Orderbook is used first, followed by AMM’s.</li><li>for more details, see: <a href="https://github.com/perpdex/perpdex-contract/blob/audit-20220828/contracts/lib/OrderBookLibrary.sol#L191-L261">core code</a></li></ul><h4>(4) trading fee is 0%</h4><ul><li>Like many CEXs, maker fee is more favorable than taker’s.</li><li>This is to attract market makers to providing liquidity.</li></ul><h3>Comparison with Serum’s Orderbook</h3><p><a href="https://www.projectserum.com/">Home | Serum</a></p><p>Serum is a famous example of on-chain orderbook implementation in Solana. I will show a brief comparison of computational complexity with it.</p><p>When we define</p><ul><li>N: number of orders in ask or bid</li><li>M: number of filled orders</li></ul><p>Computational complexity in Serum:</p><ul><li>limit order: O(logN)</li><li>take order : O(M)</li></ul><p>Computational complexity in PerpDEX:</p><ul><li>limit order: O(logN)</li><li>take order: O(logN)</li></ul><p>In the Serum implementation, the computational complexity at take order is linear with the number of orders filled.</p><p>Therefore, if the number of orders to be executed at once is large, it is not realistic for chains other than Solana. (Solana is basically very cheap)</p><p>On the other hand, our implementation is O(logN) regardless of the number of matches, thus it keeps gas price low.</p><h3>Is Market-Making in PerpDEX Profitable?</h3><ul><li>At this moment, we think YES<strong>.</strong> We will implement a sample market making bot and publish it soon.</li><li>If you find a reason that no profitable strategy is possible under this current implementation, please let us know. We’d like to improve it.</li></ul><h3>PerpDEX information</h3><ul><li><strong>Twitter</strong>: <a href="https://twitter.com/perpdex">https://twitter.com/perpdex</a></li><li><strong>Discord</strong>: <a href="https://discord.gg/6gXs4qq9hy">https://discord.gg/6gXs4qq9hy</a></li><li><strong>Website</strong>: <a href="https://perpdex.exchange/">https://perpdex.exchange</a></li></ul><h3>Conclusion</h3><ul><li>Introduced PerpDEX’s Orderbook</li><li>Compared PerpDEX Orderbook with serum and detailing features</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a22a550d19" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PerpDEX Arbitrager bot]]></title>
            <link>https://medium.com/@KOBA-PERP/perpdex-arbitrager-bot-bb93713a715d?source=rss-8cabb6f223d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb93713a715d</guid>
            <category><![CDATA[defi]]></category>
            <category><![CDATA[arbitrage]]></category>
            <dc:creator><![CDATA[KOBA]]></dc:creator>
            <pubDate>Tue, 13 Sep 2022 10:09:10 GMT</pubDate>
            <atom:updated>2022-09-13T10:09:10.625Z</atom:updated>
            <content:encoded><![CDATA[<p>I will introduce an arbitrager bot runnable in PerpDEX.</p><h3>Code(Github)</h3><p><a href="https://github.com/perpdex/perpdex-arbitrager">GitHub - perpdex/perpdex-arbitrager</a></p><h3>How it works</h3><ul><li>This bot arbitrages between CEX and PerpDEX.</li><li>When the price difference between CEX and PerpDEX opens, it starts building a position, and when the price difference closes, it closes the position.</li><li>It uses take order in both exchanges.</li></ul><h3>Notable point</h3><ul><li>At the same time, this bot is providing liquidity and rebalancing it regularly.</li><li>This will act like self-traded according to the PerpDEX implementation.</li><li>Therefore, loss due to slippage is expected to be mitigated</li></ul><h3>Is it profitable?</h3><ul><li>YES (at this moment)</li><li>You can earn below profit per one position closed</li></ul><pre>(spread between CEX and PerpDEX) - ((trade cost) + (gas price)) * 2</pre><ul><li>Of course, if someone starts to run a bot, which is more sophisticated than this bot, this bot may not be profitable.</li></ul><h3>Why publish?</h3><ul><li>As trade price is independent of Oracle, PerpDEX requires an Arbitrager to keep trade prices reasonable.</li><li>The above bot is currently run by core dev, but it would be nice to have someone run it instead.</li><li>We would be happy if someone saw this article and tried to make money with Arbitrager.</li></ul><h3>Points for improvement</h3><p>This bot is a minimal implementation and there is a lot of room for improvement. For examples:</p><ul><li>Since take order has a high trade cost, make order will improve profit</li><li>Also, the limit price of make order can be devised in various ways. (For example, adjust to volatility, etc.)</li><li>It can be more profitable by trading only when the spread is wider than trade cost</li></ul><h3>Trading Competition</h3><p>We are planning to hold a trading competition. I’m thinking of running the above Arbitrager bot during the competition.</p><p><a href="https://medium.com/perpdex/perpdex-trading-competition-round-1-eccfa4ebcfd1">PerpDEX Trading Competition — Round 1</a></p><p>You can also check Liquidator bot in PerpDEX, which is another profitable bot in PerpDEX.</p><p><a href="https://medium.com/perpdex/liquidator-bot-in-perpdex-50286455ad9d">Liquidator bot in PerpDEX</a></p><h3>Summary</h3><ul><li>Introduced an arbitrager bot</li></ul><h3>For any kind of question or clarifications, feel free to reach us</h3><ul><li><strong>Twitter</strong>: <a href="https://twitter.com/perpdex">https://twitter.com/perpdex</a></li><li><strong>Discord</strong>: <a href="https://discord.gg/6gXs4qq9hy">https://discord.gg/6gXs4qq9hy</a></li><li><strong>Website</strong>: <a href="https://perpdex.exchange/">https://perpdex.exchange</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb93713a715d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Liquidator bot in PerpDEX]]></title>
            <link>https://medium.com/perpdex/liquidator-bot-in-perpdex-50286455ad9d?source=rss-8cabb6f223d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/50286455ad9d</guid>
            <category><![CDATA[defi]]></category>
            <category><![CDATA[dex]]></category>
            <category><![CDATA[crypto]]></category>
            <dc:creator><![CDATA[KOBA]]></dc:creator>
            <pubDate>Mon, 29 Aug 2022 08:18:17 GMT</pubDate>
            <atom:updated>2022-08-29T08:18:17.923Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5X_iKxUvRe_FdATryvx_NQ.png" /></figure><p>This article explains how Liquidation works on PerpDEX and provides sample code of a Liquidator bot in PerpDEX.</p><h3>What is Liquidator bot ?</h3><p>In the case of Perpetual trading, the position will be liquidated when the maintenance margin rate falls below a certain level. In PerpDEX, like many other DEXs, anyone can execute liquidation, and those who execute liquidation will receive a reward, a percentage of the collateral that they liquidate. Liquidator bot is a trading bot that aims to earn those rewards.</p><h3>How Liquidation works on PerpDEX ?</h3><p>PerpDEX maintenance margin settings are as follows:</p><ul><li>Initial margin ratio (imRatio): 10%</li><li>Minimum margin ratio (mmRatio): 5%</li><li>see: <a href="https://github.com/perpdex/perpdex-contract/blob/audit-20220828/contracts/PerpdexExchange.sol#L40-L41">https://github.com/perpdex/perpdex-contract/blob/audit-20220828/contracts/PerpdexExchange.sol#L40-L41</a></li></ul><p>Therefore, you can open a position up to 10 times the margin(account value*), and if the position becomes 20 times the account value, that position will be subject to liquidation.<br>* account value = collateral + open position pnl + margin for LimitOrder</p><p>For example:</p><ul><li>If the account value is 1 ETH, you can open new positions until the total value of all positions is 10 ETH. (for simplicity, fee and slippage are ignored)</li><li>If you have 10 ETH long position and your account value falls below 10 ETH * 5% = 0.5 ETH (e.g. ETH falls 9.5% from the average price of the position), your position are subject to liquidation.</li></ul><p>Liquidation can be executed by <a href="https://github.com/perpdex/perpdex-contract/blob/audit-20220828/contracts/PerpdexExchange.sol#L123-L131">trade function</a></p><p>When a trader’s position meets the conditions for liquidation, anyone can execute the liquidation of that position. <a href="https://github.com/perpdex/perpdex-contract/blob/audit-20220828/contracts/lib/TakerLibrary.sol#L434-L436">[code]</a></p><p>If the trader to be liquidated has LimitOrders or Liquidity, they must be deleted before the liquidation. <a href="https://github.com/perpdex/perpdex-contract/blob/audit-20220828/contracts/lib/TakerLibrary.sol">[code]</a></p><p>The trader who succeeds the liquidation will receive a portion of the margin used for the liquidated position. [<a href="https://github.com/perpdex/perpdex-contract/blob/audit-20220828/contracts/lib/TakerLibrary.sol#L302-L303">code</a>]</p><p>In PerpDEX, rewards are smoothed with EMA (Exponential Moving Average) so that even small positions can be liquidated as much as possible. <a href="https://github.com/perpdex/perpdex-contract/blob/audit-20220828/contracts/lib/TakerLibrary.sol#L317-L325">[code]</a></p><h3>Liquidator bot logic</h3><p>So if you implement the following logic, you will have a Liquidator bot</p><p>(1) Get trader’s address list (monitor events or use subgraphs)</p><p>(2) Judge liquidation condition for each trader address</p><p>(3) If the trader is not subject to liquidation, skip below steps</p><p>(4) Remove LimitOrders and Liquidity before liquidation</p><p>(5) Execute liquidation</p><h3>Sample code</h3><p>Here is a simple sample code that implements the above logic.</p><p><a href="https://github.com/perpdex/perpdex-liquidator">GitHub - perpdex/perpdex-liquidator</a></p><p>We are planning to hold a trading competition. I’m thinking of running the above Liquidator bot during the trade competition.</p><p><a href="https://medium.com/perpdex/perpdex-trading-competition-round-1-eccfa4ebcfd1">PerpDEX Trading Competition — Round 1</a></p><h3>Conclusion</h3><p>In this article, I explained the Liquidator bot and also showed the sample code in PerpDEX. Liquidator bot is a trading bot that is easy to implement on DEX. If you are interested in trading with DEX, I would be happy if you could refer to it.</p><h3>For any kind of question or clarifications, feel free to reach us.</h3><ul><li><strong>Twitter</strong>: <a href="https://twitter.com/perpdex">https://twitter.com/perpdex</a></li><li><strong>Discord</strong>: <a href="https://discord.gg/6gXs4qq9hy">https://discord.gg/6gXs4qq9hy</a></li><li><strong>Website</strong>: <a href="https://perpdex.exchange/">https://perpdex.exchange</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50286455ad9d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/perpdex/liquidator-bot-in-perpdex-50286455ad9d">Liquidator bot in PerpDEX</a> was originally published in <a href="https://medium.com/perpdex">perpdex</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>