<?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[perpdex - Medium]]></title>
        <description><![CDATA[PerpDEX works with poor oracles. - Medium]]></description>
        <link>https://medium.com/perpdex?source=rss----551e8dc2fb63---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>perpdex - Medium</title>
            <link>https://medium.com/perpdex?source=rss----551e8dc2fb63---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 01:32:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/perpdex" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Liquidator bot in PerpDEX]]></title>
            <link>https://medium.com/perpdex/liquidator-bot-in-perpdex-50286455ad9d?source=rss----551e8dc2fb63---4</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:19:05 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>
        <item>
            <title><![CDATA[PerpDEX Trading Competition — Round 1]]></title>
            <link>https://medium.com/perpdex/perpdex-trading-competition-round-1-eccfa4ebcfd1?source=rss----551e8dc2fb63---4</link>
            <guid isPermaLink="false">https://medium.com/p/eccfa4ebcfd1</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[futures-trading]]></category>
            <category><![CDATA[blockchain-development]]></category>
            <category><![CDATA[trading-competition]]></category>
            <dc:creator><![CDATA[Nemo]]></dc:creator>
            <pubDate>Thu, 25 Aug 2022 23:22:58 GMT</pubDate>
            <atom:updated>2022-09-14T08:21:02.489Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CeCeDKfA0div9-87f5qCHg.png" /></figure><h3><strong>PerpDEX Trading Competition — Round 1 — (DEPRECATED)</strong></h3><p><strong>Update(14 Sep): This article is deprecated and the details of the competition have been updated in </strong><a href="https://medium.com/@bilalch93/perpdex-trading-competition-arbitrum-testnet-round-1-59195cd83009"><strong>this</strong></a><strong> new article.</strong></p><p>We are happy to announce that our alpha version of a perpetual futures exchange, known as PerpDEX, which operates on a hybrid model (AMM + Order-book) has been released on zkSync Testnet. This initial version is a proof of concept of our model for perpetual futures exchange and it’s time to test it out in public. For this, we are arranging this trading competition to give you chance to test out your trading skills in the ever-growing perpetual futures market.</p><p><strong>When will the competition happen?</strong></p><p>̶S̶t̶a̶r̶t̶ ̶D̶a̶t̶e̶:̶ ̶1̶ ̶S̶e̶p̶ ̶2̶0̶2̶2̶ ̶a̶t̶ ̶1̶4̶:̶0̶0̶ ̶U̶T̶C̶<br>̶E̶n̶d̶ ̶D̶a̶t̶e̶:̶ ̶8̶ ̶S̶e̶p̶ ̶2̶0̶2̶2̶ ̶a̶t̶ ̶1̶4̶:̶0̶0̶ ̶U̶T̶C̶</p><p><strong>Update(31 Aug): </strong>Due to delays in the development of the trade competition, We are really sorry to announce that the event will be postponed until the development is fully completed. A new date for the competition will be announced soon.</p><p>Blockchain: <strong>zkSync Testnet</strong></p><p><strong>How to register?</strong></p><p>All you need to participate in this competition is some trading skills, and a small amount of ETH to pay for the gas fee on zkSync Testnet for each trade. There’s no other requirement. Also, in order to have collateral deposited in your account, you can use debug function setCollateralBalance at the PerpDEX homepage to fund yourself with collateral as shown in the picture below. You can also deposit ETH directly from your wallet into your PerpDEX account.</p><p><strong>Note: </strong>setCollateralBalance is capped at 10000ETH.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dTlDKDkam0HKDCiOul-N-g.png" /><figcaption>PerpDEX Homepage — setCollateralBalance</figcaption></figure><p><strong>How to set up trading on PerpDEX?</strong></p><p>Firstly, you need to configure the Metamask wallet to work with zkSync using <a href="https://v2-docs.zksync.io/dev/testnet/important-links.html"><strong>this</strong></a> link.</p><p>Secondly, you need to get some test ETH into your wallet for gas fees using <a href="https://portal.zksync.io/faucet"><strong>this</strong></a> link.</p><p>If for some reason, the given link doesn’t work, you need to get test ETH on goerli using <a href="https://goerlifaucet.com/"><strong>this</strong></a> link and then bridge test ETH to zkSync using <a href="https://portal.zksync.io/bridge"><strong>this</strong></a>. You can use <a href="https://medium.com/@CalendarDefi/testnet-guide-zksync-2-0-6fabedf44f21"><strong>this</strong></a> guide to do this whole process.</p><p><strong>What are the winning criteria?</strong></p><p>There’s only one way to rock this competition and that is to maximize your <strong>percentage PnL</strong>.</p><p>Percentage PnL is your total realized profit and loss till the competition ends.</p><p>Percentage PnL is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*O60cpxIE8cLACykRtJpMHQ.png" /></figure><p>Where deposits are accumulated deposits, including transfers through wallet, and using setCollateralBalance.</p><p><strong>What are the rules?</strong></p><ul><li>You must agree to our Terms of service when using PerpDEX.</li><li>The trade must be opened and closed on PerpDEX (zkSync) within the competition date range.</li><li>Please refer to the list of restricted countries in our Terms of service — if you live or are a citizen of a restricted country, do not attempt to trade through PerDEX’s web interface.</li><li>PerpDEX reserves the right to amend/modify the competition rules and period if deemed necessary for any technical reason.</li></ul><p><strong>Note:</strong> Rules are subject to change without notice if deemed necessary.</p><p><strong>How to trade?</strong></p><p>Follow this guide to learn about how to trade on PerpDEX.</p><p><a href="https://perpdex.gitbook.io/docs/how-tos/open-position">Open Position</a></p><p><strong>Rankings and Rewards</strong></p><p>Listing of the participants according to rank will be displayed on the leaderboard section at PerpDEX.</p><p><strong>Gold Prize</strong>: Top 10 traders ranked by percentage PnL will receive NFT.</p><p><strong>Consolation Prize</strong>: The trader with the worst percentage PnL will receive NFT.</p><p><strong>Note</strong>: NFT prizes will have no economic value but acts as souvenirs.</p><p>For any kind of question or clarifications, feel free to reach us.</p><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=eccfa4ebcfd1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/perpdex/perpdex-trading-competition-round-1-eccfa4ebcfd1">PerpDEX Trading Competition — Round 1</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>
        <item>
            <title><![CDATA[PerpDEX updates (August, 2022)]]></title>
            <link>https://medium.com/perpdex/perpdex-updates-august-2022-a01161f3a2f0?source=rss----551e8dc2fb63---4</link>
            <guid isPermaLink="false">https://medium.com/p/a01161f3a2f0</guid>
            <category><![CDATA[defi]]></category>
            <category><![CDATA[arbitrum]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[zksync]]></category>
            <category><![CDATA[perpetual-contracts]]></category>
            <dc:creator><![CDATA[richmanbtc]]></dc:creator>
            <pubDate>Mon, 22 Aug 2022 18:35:14 GMT</pubDate>
            <atom:updated>2022-08-23T02:58:39.690Z</atom:updated>
            <content:encoded><![CDATA[<p>PerpDEX updates on recent developments.</p><p>past updates:</p><ul><li><a href="https://medium.com/perpdex/perpdex-updates-july-2022-7edf30aebdfa">https://medium.com/perpdex/perpdex-updates-july-2022-7edf30aebdfa</a></li></ul><h3>Order book is implemented</h3><p>We have implemented an order book on EVM</p><ul><li>Real order book that does not depend on arbitrager or keeper</li><li>Market orders are processed with optimal routing of AMM and limit orders like the DEX aggregator</li><li>+10000 orders can be matched in one transaction</li></ul><p>Details:</p><ul><li>gas comparison: <a href="https://medium.com/perpdex/on-chain-order-book-gas-comparison-90a2b3dd4fed">https://medium.com/perpdex/on-chain-order-book-gas-comparison-90a2b3dd4fed</a></li><li>tree used for reducing gas: <a href="https://medium.com/perpdex/red-black-tree-in-solidity-edcad36452b4">https://medium.com/perpdex/red-black-tree-in-solidity-edcad36452b4</a></li><li>implementation: <a href="https://github.com/perpdex/perpdex-contract/blob/develop/contracts/lib/OrderBookLibrary.sol">https://github.com/perpdex/perpdex-contract/blob/develop/contracts/lib/OrderBookLibrary.sol</a></li></ul><h3>zkSync2 testnet</h3><p><a href="https://perpdex.exchange/">https://perpdex.exchange/</a></p><p>supported networks: zkSync2 testnet, Arbitrum rinkeby</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*65V2jQjXXiUvYDUbs5-HEg.png" /></figure><h3>Roadmap</h3><ul><li>Currently under active development</li><li>Considering a trade competition</li><li>Future launches are planned for several chains, including zksync 2.</li></ul><p>* Future plans are subject to change without notice.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a01161f3a2f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/perpdex/perpdex-updates-august-2022-a01161f3a2f0">PerpDEX updates (August, 2022)</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>
        <item>
            <title><![CDATA[On-chain order book gas comparison]]></title>
            <link>https://medium.com/perpdex/on-chain-order-book-gas-comparison-90a2b3dd4fed?source=rss----551e8dc2fb63---4</link>
            <guid isPermaLink="false">https://medium.com/p/90a2b3dd4fed</guid>
            <category><![CDATA[dex]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[order-book]]></category>
            <dc:creator><![CDATA[richmanbtc]]></dc:creator>
            <pubDate>Sun, 14 Aug 2022 04:05:55 GMT</pubDate>
            <atom:updated>2022-08-14T04:05:35.316Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*749KDpgF1AKxWV5k" /><figcaption>Photo by <a href="https://unsplash.com/@veeterzy?utm_source=medium&amp;utm_medium=referral">veeterzy</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Gas comparison</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d5d38779e2fc35c111497ab44376d2a/href">https://medium.com/media/4d5d38779e2fc35c111497ab44376d2a/href</a></iframe><ul><li>N: total order count on order book</li><li>M: matched order count</li><li>pips: moved pips</li><li>L: pending lazy executing order count</li><li>K: lazy executed order count</li></ul><h3>Serum’s implementation</h3><p><a href="https://medium.com/perpdex/serum-order-book-implementation-2fca9301f76e">Serum order book implementation</a></p><h3>Position Protocol’s implementation</h3><ul><li>Order book is stored as a bitmap like Uniswap V3</li><li>The gas required to process a single pip is constant, no matter how many orders there are in a single pip, because execution decisions are made based on delayed evaluation.</li><li>Pips are handled linearly, so gas is needed in proportion to the number of pips.</li></ul><h3>Ours</h3><ul><li>Order books is stored in the red black tree</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90a2b3dd4fed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/perpdex/on-chain-order-book-gas-comparison-90a2b3dd4fed">On-chain order book gas comparison</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>
        <item>
            <title><![CDATA[Serum order book implementation]]></title>
            <link>https://medium.com/perpdex/serum-order-book-implementation-2fca9301f76e?source=rss----551e8dc2fb63---4</link>
            <guid isPermaLink="false">https://medium.com/p/2fca9301f76e</guid>
            <category><![CDATA[serum]]></category>
            <category><![CDATA[order-book]]></category>
            <category><![CDATA[dex]]></category>
            <category><![CDATA[solana-network]]></category>
            <category><![CDATA[solidity]]></category>
            <dc:creator><![CDATA[richmanbtc]]></dc:creator>
            <pubDate>Fri, 05 Aug 2022 20:51:36 GMT</pubDate>
            <atom:updated>2022-08-05T20:53:38.680Z</atom:updated>
            <content:encoded><![CDATA[<p>I investigated how serum’s order book is implemented.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MrSIof5BrD6pSdt1" /><figcaption>Photo by <a href="https://unsplash.com/@alfonsmc10?utm_source=medium&amp;utm_medium=referral">Alfons Morales</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Source code</h3><p>matching logic</p><p><a href="https://github.com/project-serum/serum-dex/blob/master/dex/src/matching.rs">https://github.com/project-serum/serum-dex/blob/master/dex/src/matching.rs</a></p><p>critbit</p><p><a href="https://github.com/project-serum/serum-dex/blob/master/dex/src/critbit.rs">https://github.com/project-serum/serum-dex/blob/master/dex/src/critbit.rs</a></p><h3>Matching logic</h3><ul><li>Limit prices are managed by critbit.</li><li>Matching process is performed in a loop one by one from the best order. <a href="https://github.com/project-serum/serum-dex/blob/0c23a513403d20cc21e47f8ddde3eb90fbb302bb/dex/src/matching.rs#L252">https://github.com/project-serum/serum-dex/blob/0c23a513403d20cc21e47f8ddde3eb90fbb302bb/dex/src/matching.rs#L252</a></li><li>Matching with one’s own limit price is handled exceptionally. <a href="https://github.com/project-serum/serum-dex/blob/0c23a513403d20cc21e47f8ddde3eb90fbb302bb/dex/src/matching.rs#L388">https://github.com/project-serum/serum-dex/blob/0c23a513403d20cc21e47f8ddde3eb90fbb302bb/dex/src/matching.rs#L388</a></li><li>Users can specify a maximum number of matches <a href="https://github.com/project-serum/serum-dex/blob/0c23a513403d20cc21e47f8ddde3eb90fbb302bb/dex/src/matching.rs#L253">https://github.com/project-serum/serum-dex/blob/0c23a513403d20cc21e47f8ddde3eb90fbb302bb/dex/src/matching.rs#L253</a></li></ul><h3>Gas efficiency summary</h3><ul><li>order matching: O(M * k)</li><li>create order: O(k)</li><li>cancel order: O(k)</li><li>k: bit count</li><li>M: matched order count</li></ul><p>I haven’t analyzed it properly, but I guess k is the worst case and actually log(N), where N is the number of orders.</p><h3>How many orders match per taker?</h3><ul><li>Not a proper investigation, but my binance transaction history shows that a not very large taker matched 10–100 orders.</li><li>Considering that a larger order would be 100 times this amount, M could be considered to be from 10 to 10,000.</li><li>Since the gas of matching orders is linear with respect to the number of matches, this method may not be available for non-solana chains such as ethereum.</li><li>In the case of ethereum, if there were 10000 matches, it would cost 5000 gas to write one slot, so 50M gas in total. In fact, it is considered to be larger than this, since more than 1 slot is rewritten in a single match (order change + 2 account change).</li></ul><h3>Conclusion</h3><ul><li>Serum implementation is simple</li><li>Order matching gas could be larger.</li><li>This may not be an available implementation method for some chains</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fca9301f76e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/perpdex/serum-order-book-implementation-2fca9301f76e">Serum order book implementation</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>
        <item>
            <title><![CDATA[Order dependency of trade execution]]></title>
            <link>https://medium.com/perpdex/order-dependency-of-trade-execution-ce6d2907eb4f?source=rss----551e8dc2fb63---4</link>
            <guid isPermaLink="false">https://medium.com/p/ce6d2907eb4f</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[trading]]></category>
            <category><![CDATA[exchange]]></category>
            <dc:creator><![CDATA[richmanbtc]]></dc:creator>
            <pubDate>Thu, 04 Aug 2022 23:40:21 GMT</pubDate>
            <atom:updated>2022-08-04T23:51:08.911Z</atom:updated>
            <content:encoded><![CDATA[<p>Summary</p><ul><li>Results of multiple trade executions (positions, avg entry price, margin) depend on the order of execution.</li><li>This makes it more difficult to handle programmatically</li><li>We have tried to come up with an alternative method that does not depend on the order of execution.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MRZKypyhu_eRCQ-Z" /><figcaption>Photo by <a href="https://unsplash.com/@lili_popper?utm_source=medium&amp;utm_medium=referral">Lili Popper</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Problem settings</h3><p>Question</p><p>Is there a reasonable alternative trade rule that the final states do not depend on the order of execution?</p><p>Settings</p><ul><li>Assume an account where all positions are combined and calculated (major CEX is in this rule)</li><li>States are position, entry price, and margin balance.</li><li>These states change depending on the execution of the trade</li><li>Traders can use this rule to execute multiple pending trades at once at any given point in time. If executed frequently, the rules will be the same as the normal rules. In other words, traders can choose between alternative rules and normal rules.</li></ul><h3>Freedom of the final states</h3><ul><li>No matter which order they are executed in, the position will have the same result.</li><li>No matter which order they are executed, the margin balance minus entry price * position will be the same</li><li>So, there is only one degree of freedom, for example, if the entry price is determined, the other states are determined.</li><li>The entry price falls between the minimum and maximum entry price for each execution</li></ul><h3>What is reasonable trade rule?</h3><p>There are several perspectives</p><ul><li>For exchanges, the smaller the unrealized loss, the lower the risk.</li><li>Traders can reduce unrealized PnL by trading, but not vice versa. Therefore, the smaller the absolute value of unrealized PnL, the narrower the trader’s options and the fewer the options for attack</li><li>It is natural if the result is continuous for all input variables. It is not good if the result changes abruptly depending on the sign.</li><li>The less execution and profit-taking processes, the smaller the computational cost.</li><li>Simple rules are good.</li></ul><h3>Method 1</h3><p>Method</p><ul><li>Consider all executions as one execution averaged together and execute against the initial state.</li></ul><p>Analysis</p><ul><li>Mixing the buy and sell and taking an average is not in the best nature because the entry price may be out of range. (It is easy to understand when considering the two-dimensional plane of position and notional value)</li><li>This means that this could result in impossible states in exact executions.</li></ul><h3>Method 2</h3><p>Method</p><ul><li>Separate the buy and sell and take an average of each.</li><li>First, execute a trade in the same direction as the current position, then execute the opposite trade</li></ul><p>Analysis</p><ul><li>One profit-taking process</li><li>The final entry price is either the average of the initial state and the entry price of the first execution, or the entry price of the second execution</li><li>The only branch that can cause a discontinuity is the sign of the initial position</li><li>When the initial position is negligibly small, changing the order of execution between the first and second executions does not change the result. So, it is continuous.</li><li>This execution result can be reproduced by adjusting the order with accurate execution</li></ul><h3>Conclusion</h3><p>Method 2 looks good.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce6d2907eb4f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/perpdex/order-dependency-of-trade-execution-ce6d2907eb4f">Order dependency of trade execution</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>
        <item>
            <title><![CDATA[Red black tree in solidity]]></title>
            <link>https://medium.com/perpdex/red-black-tree-in-solidity-edcad36452b4?source=rss----551e8dc2fb63---4</link>
            <guid isPermaLink="false">https://medium.com/p/edcad36452b4</guid>
            <category><![CDATA[red-black-tree]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[binary-search-tree]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[richmanbtc]]></dc:creator>
            <pubDate>Thu, 04 Aug 2022 15:31:40 GMT</pubDate>
            <atom:updated>2022-08-04T15:47:31.082Z</atom:updated>
            <content:encoded><![CDATA[<p>We introduce a solidity implementation of red black tree.</p><p>Features</p><ul><li>forked from <a href="https://github.com/bokkypoobah/BokkyPooBahsRedBlackTreeLibrary">https://github.com/bokkypoobah/BokkyPooBahsRedBlackTreeLibrary</a></li><li>added range remove (gas: O(logN))</li><li>added aggregation (gas: O(logN))</li><li>optimized gas</li><li>fixed minor bugs existed in original repository</li><li>added modern development tools (e.g. hardhat, gas reporter, lint)</li></ul><p>N: node count</p><h3>Repository</h3><p>Our implementation can be found in the following repositories</p><p><a href="https://github.com/perpdex/BokkyPooBahsRedBlackTreeLibrary">https://github.com/perpdex/BokkyPooBahsRedBlackTreeLibrary</a></p><h3>Range remove</h3><p>Efficient bulk remove operation can be implemented using join and split.</p><ul><li>Basically implemented according to “Set operations and bulk operations” in <a href="https://en.wikipedia.org/wiki/Red%E2%80%93black_tree">https://en.wikipedia.org/wiki/Red%E2%80%93black_tree</a></li><li>However, wikipedia’s implementation of split is incorrect. The original paper has the correct implementation. <a href="https://arxiv.org/abs/1602.02120">https://arxiv.org/abs/1602.02120</a></li></ul><p>Code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*0yxtv3RCFrP819JSbHY_Iw.png" /></figure><p><a href="https://github.com/perpdex/BokkyPooBahsRedBlackTreeLibrary/blob/b57d977de82b33420498e2c8571d8e02f8f8e7f6/contracts/BokkyPooBahsRedBlackTreeLibrary.sol#L454">https://github.com/perpdex/BokkyPooBahsRedBlackTreeLibrary/blob/b57d977de82b33420498e2c8571d8e02f8f8e7f6/contracts/BokkyPooBahsRedBlackTreeLibrary.sol#L454</a></p><h3>Aggregation</h3><p>The ability to calculate various aggregations expands the use cases.</p><ul><li>OrderStatisticsTree, a fork of BokkyPooBahsRedBlackTreeLibrary, can calculate the number of nodes <a href="https://github.com/rob-Hitchens/OrderStatisticsTree">https://github.com/rob-Hitchens/OrderStatisticsTree</a></li><li>But other aggregations such as sum are not supported</li><li>Implemented to support arbitrary aggregation independent of processing order (e.g. sum, max, min, count)</li><li>The minimum that needs to be implemented as a library feature has been implemented. Search was omitted because it can be implemented externally.</li></ul><p>Code</p><p><a href="https://github.com/perpdex/BokkyPooBahsRedBlackTreeLibrary/blob/b57d977de82b33420498e2c8571d8e02f8f8e7f6/contracts/BokkyPooBahsRedBlackTreeLibrary.sol#L123">https://github.com/perpdex/BokkyPooBahsRedBlackTreeLibrary/blob/b57d977de82b33420498e2c8571d8e02f8f8e7f6/contracts/BokkyPooBahsRedBlackTreeLibrary.sol#L123</a></p><h3>Gas optimization</h3><p>done</p><ul><li>Adjusted field size so that node fits in one slot.</li><li>I tried converting the recursion to a loop, but the gas increased, so I adopted recursion.</li></ul><p>considerations</p><ul><li>2-3 tree or 2-3-4 tree could be used to fit multiple nodes in one slot</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*91hvh3744TQbw06DDjfYww.png" /></figure><p><a href="https://github.com/perpdex/BokkyPooBahsRedBlackTreeLibrary/blob/b57d977de82b33420498e2c8571d8e02f8f8e7f6/contracts/BokkyPooBahsRedBlackTreeLibrary.sol#L19">https://github.com/perpdex/BokkyPooBahsRedBlackTreeLibrary/blob/b57d977de82b33420498e2c8571d8e02f8f8e7f6/contracts/BokkyPooBahsRedBlackTreeLibrary.sol#L19</a></p><h3>Use cases</h3><p>This could be used to implement the fully on-chain order book in the DEX. Here is a sketch of the implementation.</p><ul><li>Node represents an order</li><li>The order of nodes is determined by price and time.</li><li>The sum of the order’s amount and the order’s notional value is retained by the aggregation.</li><li>Search for a node whose aggregated sum of order amount matches the amount of the taker order</li><li>Delete executed orders using range remove</li><li>Process execution by lazy evaluation using information on whether a node has been deleted or not (whether following the parent will lead to root or not)</li></ul><p>Advantages over other order book implementations</p><ul><li>Not dependent on off-chain (like dYdX, 1inch)</li><li>Gas consumption for each operation is O(logN), so it works even if the number of orders increases.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edcad36452b4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/perpdex/red-black-tree-in-solidity-edcad36452b4">Red black tree in solidity</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>
        <item>
            <title><![CDATA[GMX research]]></title>
            <link>https://medium.com/perpdex/gmx-research-9da560f1e447?source=rss----551e8dc2fb63---4</link>
            <guid isPermaLink="false">https://medium.com/p/9da560f1e447</guid>
            <category><![CDATA[dex]]></category>
            <category><![CDATA[gmx]]></category>
            <category><![CDATA[defi]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[richmanbtc]]></dc:creator>
            <pubDate>Fri, 29 Jul 2022 19:23:30 GMT</pubDate>
            <atom:updated>2022-07-30T04:37:43.402Z</atom:updated>
            <content:encoded><![CDATA[<p>I did some research on GMX perpetual DEX.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zMufCqpPbMZwJ6gk" /><figcaption>Photo by <a href="https://unsplash.com/@bash__profile?utm_source=medium&amp;utm_medium=referral">Nicholas Cappello</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Technical Overview</h3><p><a href="https://gmx-io.notion.site/gmx-io/GMX-Technical-Overview-47fc5ed832e243afb9e97e8a4a036353">https://gmx-io.notion.site/gmx-io/GMX-Technical-Overview-47fc5ed832e243afb9e97e8a4a036353</a></p><blockquote>The keeper then executes the position at the current index price</blockquote><blockquote>A user can execute the position on their own if three minutes have passed between the request transaction and the execution transaction.</blockquote><p>Implemented in _validateExecution</p><blockquote>For swaps, the base fee is 0.25%, while price feeds update within 0.12% price movements</blockquote><p>Fees are large compared to CEX, dYdX, Perpetual Protocol v2.</p><blockquote>The keepers and watchers are currently run by separate team members</blockquote><p>Confirmed by the etherscan.</p><h3>Code reading</h3><p>Target repository</p><p><a href="https://github.com/gmx-io/gmx-contracts">https://github.com/gmx-io/gmx-contracts</a></p><h4>max price, min price</h4><p>max price used for long</p><ul><li><a href="https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/OrderBook.sol#L738">https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/OrderBook.sol#L738</a></li></ul><p>max price is calculated in</p><ul><li><a href="https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/Vault.sol#L761">https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/Vault.sol#L761</a></li><li><a href="https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/VaultPriceFeed.sol#L148">https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/VaultPriceFeed.sol#L148</a></li></ul><p>Looks like they are using multiple price sources to calculate robust ask bids.</p><p>Questions</p><ul><li>If the oracle is updated infrequently, it will effectively be using AMM prices, which may make it vulnerable to manipulation? <a href="https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/VaultPriceFeed.sol#L332">https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/VaultPriceFeed.sol#L332</a></li></ul><h3>oracles</h3><p>Looks like they are implementing the oracle themselves.</p><ul><li><a href="https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/oracle/FastPriceFeed.sol">https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/oracle/FastPriceFeed.sol</a></li></ul><p>Check the price feeds actually used.</p><ul><li><a href="https://gmxio.gitbook.io/gmx/contracts">https://gmxio.gitbook.io/gmx/contracts</a></li><li>Vault <a href="https://arbiscan.io/address/0x489ee077994B6658eAfA855C308275EAd8097C4A">https://arbiscan.io/address/0x489ee077994B6658eAfA855C308275EAd8097C4A</a></li><li>Vault.priceFeed(VaultPriceFeed) <a href="https://arbiscan.io/address/0xa18bb1003686d0854ef989bb936211c59eb6e363">https://arbiscan.io/address/0xa18bb1003686d0854ef989bb936211c59eb6e363</a></li><li>Vault.priceFeed.priceFeeds(weth) (EACAggregatorProxy) <a href="https://arbiscan.io/address/0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612">https://arbiscan.io/address/0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612</a></li><li>Vault.priceFeed.secondaryPriceFeed(FastPriceFeed) <a href="https://arbiscan.io/address/0x1a0ad27350cccd6f7f168e052100b4960efdb774">https://arbiscan.io/address/0x1a0ad27350cccd6f7f168e052100b4960efdb774</a></li></ul><p>priceFeeds looks like chainlink.</p><p>secondaryPriceFeed reporters</p><ul><li><a href="https://arbiscan.io/address/0xef9092d35fda3e5b6e2dd3fac5b580aefc346faf">https://arbiscan.io/address/0xef9092d35fda3e5b6e2dd3fac5b580aefc346faf</a></li><li><a href="https://arbiscan.io/address/0x1e359eae31f5815ac3d5b337b26771bc8adbdfa3">https://arbiscan.io/address/0x1e359eae31f5815ac3d5b337b26771bc8adbdfa3</a></li></ul><p>secondaryPriceFeed (FastPriceFeed) does not seem to be trustless</p><p><a href="https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/oracle/FastPriceFeed.sol#L71">https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/oracle/FastPriceFeed.sol#L71</a></p><h4>PositionRouter</h4><p>positionKeeper also feels like a non-trustless element.</p><ul><li><a href="https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/PositionRouter.sol#L207">https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/PositionRouter.sol#L207</a></li></ul><p>However, executeIncreasePosition is permissionless, so it may not matter if positionKeeper is malicious. When I read executeIncreasePositions again, it was just a convenience function to execute an unexecuted order.</p><ul><li><a href="https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/PositionRouter.sol#L392">https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/PositionRouter.sol#L392</a></li></ul><p>However, in the following function, whether the sender is a positionKeeper or not affected the processing, so it seems that execute is not trustless. This seems to prevent it from immediately executing on its own.</p><ul><li><a href="https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/PositionRouter.sol#L563">https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/PositionRouter.sol#L563</a></li></ul><p>Check the contracts actually used.</p><ul><li>PositionRouter <a href="https://arbiscan.io/address/0x3D6bA331e3D9702C5e8A8d254e5d8a285F223aba">https://arbiscan.io/address/0x3D6bA331e3D9702C5e8A8d254e5d8a285F223aba</a></li><li>PositionRouter.positionKeeper: I can see it in the old transaction, but I couldn’t see it on etherscan, so I didn’t check.</li></ul><p>It looks like the taker order is executed by submitting the order and then having the keeper execute it.</p><ul><li><a href="https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/PositionRouter.sol#L603">https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/PositionRouter.sol#L603</a></li></ul><h4>path</h4><p>It seems that the number of elements in a path is ≤ 2.We have not yet investigated what role path plays.</p><ul><li><a href="https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/PositionRouter.sol#L405">https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/PositionRouter.sol#L405</a></li><li><a href="https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/BasePositionManager.sol#L239">https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/BasePositionManager.sol#L239</a></li><li><a href="https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/BasePositionManager.sol#L246">https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/BasePositionManager.sol#L246</a></li><li><a href="https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/Vault.sol#L520">https://github.com/gmx-io/gmx-contracts/blob/787d767e033c411f6d083f2725fb54b7fa956f7e/contracts/core/Vault.sol#L520</a></li></ul><h4>acceptablePrice</h4><p>acceptablePrice seems to be a slippage constraint</p><ul><li><a href="https://github.com/gmx-io/gmx-contracts/blob/master/contracts/core/PositionRouter.sol#L414">https://github.com/gmx-io/gmx-contracts/blob/master/contracts/core/PositionRouter.sol#L414</a></li><li><a href="https://github.com/gmx-io/gmx-contracts/blob/master/contracts/core/BasePositionManager.sol#L152">https://github.com/gmx-io/gmx-contracts/blob/master/contracts/core/BasePositionManager.sol#L152</a></li></ul><h3>Conclusion</h3><p>specs</p><ul><li>fee ≥ 0.25%</li><li>two step execution mitigates front running (arbs)</li><li>not trustless (keeper is team)</li><li>quote is calculated by oracles (chainlink, trustful oracles by team, amm)</li></ul><p>pros</p><ul><li>high capital efficiency</li><li>no IL</li><li>passive LP</li></ul><p>cons</p><ul><li>Spreads won’t get smaller unless Oracle update frequency increases (because of max price and min price)</li><li>Requires keepers, which complicates the system</li><li>If all oracles fail at the same time, the market will fail</li></ul><p>We are biased because we are making a perpetual dex called perpdex that works differently than GMX. Please tell me if I’m wrong</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9da560f1e447" width="1" height="1" alt=""><hr><p><a href="https://medium.com/perpdex/gmx-research-9da560f1e447">GMX research</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>
        <item>
            <title><![CDATA[“botter “— crypto bot traders in Japan]]></title>
            <link>https://medium.com/perpdex/botter-the-crypto-bot-trader-in-japan-2f5f2a65856f?source=rss----551e8dc2fb63---4</link>
            <guid isPermaLink="false">https://medium.com/p/2f5f2a65856f</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[trading]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[dex]]></category>
            <category><![CDATA[bots]]></category>
            <dc:creator><![CDATA[richmanbtc]]></dc:creator>
            <pubDate>Thu, 21 Jul 2022 05:44:12 GMT</pubDate>
            <atom:updated>2022-08-04T16:14:32.818Z</atom:updated>
            <content:encoded><![CDATA[<p>I will explain the word “botter” used in Japan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vOqs1IQEg4STHbXd" /><figcaption>Photo by <a href="https://unsplash.com/@helloimnik?utm_source=medium&amp;utm_medium=referral">Hello I&#39;m Nik</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>What is the “botter”?</h3><p>“botter” represents a crypto bot trader. The word “botter” was born in Japan and is used in Japan. The Japanese often create their own English words. The word “botter” was coined to mean someone who trades with a bot, like “player”.</p><h3>botter community</h3><p>There is a botter community in Japan. They are loosely connected on twitter, discord, and note (a Japanese “medium” like service). There is a culture in which senior botters lead junior botters. When I first became a botter, I studied by reading articles published by senior botters.</p><h3>How to find botters</h3><p>The botter’s tweets can provide useful information such as trade ideas. To become a strong botter, it is important to first follow strong botters. Please try to read tweets with automatic translation. You can find botters by searching as follows.</p><ul><li><a href="https://twitter.com/search?q=botter%20lang%3Aja&amp;src=typed_query&amp;f=top">https://twitter.com/search?q=botter%20lang%3Aja&amp;src=typed_query&amp;f=live</a></li><li><a href="https://twitter.com/search?q=S%E7%B4%9Abotter%20lang%3Aja&amp;src=typed_query&amp;f=top">https://twitter.com/search?q=S%E7%B4%9Abotter%20lang%3Aja&amp;src=typed_query&amp;f=top</a></li><li><a href="https://twitter.com/search?q=mmbot%20lang%3Aja&amp;src=typed_query&amp;f=top">https://twitter.com/search?q=mmbot%20lang%3Aja&amp;src=typed_query&amp;f=top</a></li><li><a href="https://twitter.com/search?q=mlbot%20lang%3Aja&amp;src=typed_query&amp;f=top">https://twitter.com/search?q=mlbot%20lang%3Aja&amp;src=typed_query&amp;f=top</a></li><li><a href="https://twitter.com/search?q=dex%20botter%20lang%3Aja&amp;src=typed_query&amp;f=top">https://twitter.com/search?q=dex%20botter%20lang%3Aja&amp;src=typed_query&amp;f=top</a></li></ul><h3>botter grade</h3><p>botters have the following grades</p><ul><li>SS grade botter: monthly revenue ≥ $1,000,000</li><li>S grade botter: monthly revenue ≥ $100,000</li><li>A grade botter: monthly revenue ≥ $10,000</li><li>B grade botter: monthly revenue ≥ $1,000</li><li>C grade botter: monthly revenue ≥ $100</li></ul><h3>Various types of botters</h3><p>mmbotter (mmbot, market making botter)</p><p>mlbotter (mlbot, machine learning botter)</p><p>dex botter</p><p>high frequency botter</p><p>swing botter</p><p>delta neutral botter (earn funding rate by spot + 1x short)</p><h3>botter community in the world</h3><p>I found a community that is not called “botter” but is equivalent to the Japanese botter community. You can join via the discord at the following link.</p><p><a href="https://docs.flashbots.net/">https://docs.flashbots.net/</a></p><h3>Conclusion</h3><p>It is fun to be a botter in the botter community. I want to communicate with botters from all over the world.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f5f2a65856f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/perpdex/botter-the-crypto-bot-trader-in-japan-2f5f2a65856f">“botter “— crypto bot traders in Japan</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>
        <item>
            <title><![CDATA[zkSync2 testnet integration]]></title>
            <link>https://medium.com/perpdex/how-to-make-an-existing-evm-contract-compatible-with-zksync-2-396749d7f916?source=rss----551e8dc2fb63---4</link>
            <guid isPermaLink="false">https://medium.com/p/396749d7f916</guid>
            <category><![CDATA[zksync]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <dc:creator><![CDATA[richmanbtc]]></dc:creator>
            <pubDate>Wed, 20 Jul 2022 19:32:19 GMT</pubDate>
            <atom:updated>2022-08-18T15:23:42.006Z</atom:updated>
            <content:encoded><![CDATA[<p>We will share our findings in the process of making PerpDEX compatible with zkSync 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SPtSF0fo0R17kSB5" /><figcaption>Photo by <a href="https://unsplash.com/@madhatterzone?utm_source=medium&amp;utm_medium=referral">Manja Vitolic</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Background</h3><p>PerpDEX is a perpetual futures DEX we are developing in solidity and will be deployed on multiple EVM compatible chains.</p><h4>Tech stacks</h4><ul><li>solidity</li><li>hardhat</li><li>hardhat-deploy</li></ul><p>We will share the necessary actions to make an existing project using these stacks zkSync 2 compliant.</p><h3>Enable zksolc</h3><p>Install @matterlabs/hardhat-zksync-solc and add the following import to hardhat.config.ts</p><pre>import &quot;@matterlabs/hardhat-zksync-solc&quot;</pre><p>It was also necessary to raise the hardhat version to 2.10.1.</p><h3>Upgrade hardhat-deploy to support zkSync</h3><p>Updated hardhat-deploy to 0.11.11 which supports zkSync. The @matterlabs/hardhat-zksync-deploy recommended in the official zkSync documentation was not needed. hardhat-deploy automatically uses the provider for zkSync if the zkSync flag described next is true.</p><p><a href="https://github.com/wighawag/hardhat-deploy/blob/master/CHANGELOG.md#01111">hardhat-deploy changelog</a></p><h3>Added network configuration for zkSync 2 testnet</h3><p>Add the following settings to hardhat.config.ts</p><pre><strong><em>config</em></strong>.networks.zksync2_testnet = {<br>    url: &quot;https://zksync2-testnet.zksync.dev&quot;,<br>    chainId: 280,<br>    accounts: [<strong><em>process</em></strong>.env.TESTNET_PRIVATE_KEY],<br>    verify: {<br>        etherscan: {<br>            apiUrl: &quot;https://zksync2-testnet.zkscan.io/&quot;,<br>        },<br>    },<br>    zksync: true,<br>}</pre><p>The important thing is the zksync flag. hardhat-zksync-solc and hardhat-deploy will do the work for zksync if this is true.</p><h3>Change solidity version to 0.8</h3><p>Since the latest zksolc solidity version is 0.8, we need to increase the solidity version to 0.8 in order to support multiple EVM compatible chains with the same code. To do so, the following actions are required.</p><h4>Replaces FullMath.mulDiv</h4><p>PerpDEX used <a href="https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol">FullMath.mulDiv</a> from Uniswap V3. This would not compile with solidity 0.8, so I replaced it with openzeppelin Math.mulDiv</p><h4>Upgrade openzeppelin</h4><p>I was using openzeppelin 3.x, which does not support solidity 0.8, so I changed the version to 4.x.</p><h3>How to compile with zksolc</h3><p>Compile for zkSync by specifying the network as follows.</p><pre>npx hardhat compile --network zksync2_testnet</pre><p>Tip: The contract size in hardhat-contract-sizer appears to be in excess, but I was able to deploy successfully to zkSync 2 testnet.</p><h3>How to deploy to zksync 2 testnet</h3><p>It can be deployed like any other network.</p><pre>npx hardhat deploy --network zksync2_testnet</pre><h3>etherscan verification</h3><p>We should be able to verify with the following command…</p><pre>npx hardhat etherscan-verify --network zksync2_testnet</pre><p>I got the following error and could not verify the contract.</p><pre>Contract UniswapV2PriceFeedETHUSD was deployed without saving metadata. Cannot submit to etherscan, skipping.</pre><h3>thegraph</h3><p>thegraph worked for zksync 2 testnet. Specify “zkSync2-testnet” in network as follows</p><p><a href="https://github.com/perpdex/perpdex-subgraph/blob/cef3b488d57a2df2bd63e733ad5e8158c79776f6/configs/zksync2-testnet.json#L10">https://github.com/perpdex/perpdex-subgraph/blob/cef3b488d57a2df2bd63e733ad5e8158c79776f6/configs/zksync2-testnet.json#L10</a></p><h3>Implementations</h3><p>Below is the actual implementation we have done to make our PerpDEX contract compatible with zkSync 2. It may be helpful.</p><p>contracts</p><ul><li><a href="https://github.com/perpdex/perpdex-contract/pull/49">https://github.com/perpdex/perpdex-contract/pull/49</a></li><li><a href="https://github.com/perpdex/perpdex-stablecoin/pull/14">https://github.com/perpdex/perpdex-stablecoin/pull/14</a></li><li><a href="https://github.com/perpdex/perpdex-oracle-contract/pull/11">https://github.com/perpdex/perpdex-oracle-contract/pull/11</a></li></ul><p>UI</p><ul><li><a href="https://github.com/perpdex/perpdex-lite/pull/84">https://github.com/perpdex/perpdex-lite/pull/84</a></li></ul><p>subgraph (thegraph)</p><ul><li><a href="https://github.com/perpdex/perpdex-subgraph">https://github.com/perpdex/perpdex-subgraph</a></li></ul><p>web3.py (arbitrager)</p><ul><li><a href="https://github.com/perpdex/perpdex-arbitrager">https://github.com/perpdex/perpdex-arbitrager</a></li></ul><h3>Conclusion</h3><p>This article explains how to make your smart contract project zkSync compliant. If you have any questions, please feel free to contact us!</p><p>Twitter: <a href="https://twitter.com/perpdex">https://twitter.com/perpdex</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=396749d7f916" width="1" height="1" alt=""><hr><p><a href="https://medium.com/perpdex/how-to-make-an-existing-evm-contract-compatible-with-zksync-2-396749d7f916">zkSync2 testnet integration</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>