<?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 tony on Medium]]></title>
        <description><![CDATA[Stories by tony on Medium]]></description>
        <link>https://medium.com/@guotie?source=rss-d0c2e22334be------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*1501Z-ujM1BVZ9Dz.jpg</url>
            <title>Stories by tony on Medium</title>
            <link>https://medium.com/@guotie?source=rss-d0c2e22334be------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 09 Jun 2026 00:37:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@guotie/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[How to fetch all uniswap v3 pools?]]></title>
            <link>https://medium.com/@guotie/how-to-fetch-all-uniswap-v3-pools-e91b338cdafa?source=rss-d0c2e22334be------2</link>
            <guid isPermaLink="false">https://medium.com/p/e91b338cdafa</guid>
            <category><![CDATA[pool]]></category>
            <category><![CDATA[uniswap]]></category>
            <category><![CDATA[uniswap-v3]]></category>
            <dc:creator><![CDATA[tony]]></dc:creator>
            <pubDate>Thu, 01 Aug 2024 07:32:23 GMT</pubDate>
            <atom:updated>2024-08-01T07:32:23.725Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/631/0*GLR-VNAgjlYvlyiZ.png" /><figcaption>uniswap v3</figcaption></figure><p>Unlike Uniswap v2, the <strong><em>factory</em></strong> contract has no <strong>allPairs </strong>method, so we cannot call <strong>allPairs </strong>to iterate all pools.</p><p>In the uniswap v3 contract, only position can be traversed, so we can start with the position contract <strong><em>NonfungiblePositionManager</em></strong>.</p><p>We need to use three methods of the <strong><em>NonfungiblePositionManager</em></strong> contract:</p><pre>interface INonfungiblePositionManager {<br>    function positions(<br>        uint256 tokenId<br>    )<br>        external<br>        view<br>        returns (<br>            uint96 nonce,<br>            address operator,<br>            address token0,<br>            address token1,<br>            uint24 fee,<br>            int24 tickLower,<br>            int24 tickUpper,<br>            uint128 liquidity,<br>            uint256 feeGrowthInside0LastX128,<br>            uint256 feeGrowthInside1LastX128,<br>            uint128 tokensOwed0,<br>            uint128 tokensOwed1<br>        );<br><br>    function tokenByIndex(uint256 index) external view returns (uint256);<br><br>    function totalSupply() external view returns (uint256);<br>}<br><br><br>interface IUniswapV3Factory {<br>    function getPool(<br>        address tokenA,<br>        address tokenB,<br>        uint24 fee<br>    ) external view returns (address pool);<br>}</pre><p>First, we use <strong><em>totalSupply</em></strong> to get the current number of positions, total position — burned position;<br>Then, we use the last <strong><em>tokenByIndex</em></strong> to get the total positions, recorded as <em>total</em>;<br>Finally, we call the <strong><em>positions</em></strong> method, starting from 1 (Uniswap v3’s tokenId starts from 1) and traverse until <em>total</em>; for each successfully returned result, call the <strong><em>getPool</em></strong> method of the Uniswap v3 factory to get the pool address</p><p>The full code is as follows:</p><pre>pragma solidity 0.8.24;<br><br>    function getV3Pools(<br>        address factory,<br>        address positionManager,<br>        uint from,<br>        uint to<br>    ) public view returns (address[] memory pools) {<br>        {<br>            uint256 total = INonfungiblePositionManager(positionManager)<br>                .totalSupply();<br>            uint256 tokens = INonfungiblePositionManager(positionManager)<br>                .tokenByIndex(total - 1);<br>            if (from == 0) {<br>                from = 1;<br>            }<br>            if (to == 0 || to &gt; tokens) {<br>                to = tokens;<br>            }<br>        }<br><br>        uint poolCount = 0;<br>        for (uint i = from; i &lt;= to; ++i) {<br>            try<br>                INonfungiblePositionManager(positionManager).positions(i)<br>            returns (<br>                uint96,<br>                address,<br>                address,<br>                address,<br>                uint24,<br>                int24,<br>                int24,<br>                uint128,<br>                uint256,<br>                uint256,<br>                uint128,<br>                uint128<br>            ) {<br>                ++poolCount;<br>            } catch {}<br>        }<br><br>        pools = new address[](poolCount);<br>        if (poolCount == 0) {<br>            return pools;<br>        }<br><br>        for (uint i = from; i &lt;= to; ++i) {<br>            try<br>                INonfungiblePositionManager(positionManager).positions(i)<br>            returns (<br>                uint96,<br>                address,<br>                address token0,<br>                address token1,<br>                uint24 fee,<br>                int24,<br>                int24,<br>                uint128,<br>                uint256,<br>                uint256,<br>                uint128,<br>                uint128<br>            ) {<br>                pools[--poolCount] = IUniswapV3Factory(factory).getPool(<br>                    token0,<br>                    token1,<br>                    fee<br>                );<br>            } catch {}<br>        }<br>    }</pre><p>Due to the limitations of solidity, this code will report an error when compiled</p><pre>stack too deep</pre><p>We need to configure the <strong><em>viaIR</em></strong> option for the compiler to enable successful compilation:</p><pre>solidity: {<br>    compilers: [{<br>        version: &#39;0.8.24&#39;,<br>        settings: {  <br>          viaIR: true,<br>          optimizer: {<br>            enabled: true,<br>            runs: 20000,<br>          },<br>        },<br>      }<br>  ]<br>}</pre><p>When we call the method getV3Pools, the step should less than 20,000,</p><p>When we call the <strong><em>getV3Pools</em></strong> method, the parameter step should be less than 20,000, otherwise <strong><em>out of gas</em></strong> may occur.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e91b338cdafa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[uniswap LP 的天生缺陷 — — 盈亏不对等]]></title>
            <link>https://medium.com/@guotie/uniswap-lp-%E7%9A%84%E5%A4%A9%E7%94%9F%E7%BC%BA%E9%99%B7-%E7%9B%88%E4%BA%8F%E4%B8%8D%E5%AF%B9%E7%AD%89-2739ebcc882d?source=rss-d0c2e22334be------2</link>
            <guid isPermaLink="false">https://medium.com/p/2739ebcc882d</guid>
            <dc:creator><![CDATA[tony]]></dc:creator>
            <pubDate>Fri, 02 Feb 2024 04:57:55 GMT</pubDate>
            <atom:updated>2024-02-02T04:57:55.974Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>uniswap LP 的天生缺陷 — — 盈亏不对等</strong></h3><p>English version: <a href="https://medium.com/@guotie/the-inherent-flaw-of-uniswap-lp-asymmetry-in-profit-and-loss-fc7c2d173c2f">https://medium.com/@guotie/the-inherent-flaw-of-uniswap-lp-asymmetry-in-profit-and-loss-fc7c2d173c2f</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/0*bj-70pPaxsZAGx56.png" /><figcaption>uniswap v3 LP</figcaption></figure><p>当我们对uniswap LP进行深入分析之后，我们发现了LP的惊人事实：那就是LP很难盈利，无论是USD本位还是币本位。</p><p>TL;DR<br>uniswap LP最根本的缺陷在于，相同币价涨幅与跌幅时，LP在上涨时的盈利和下跌时的亏损不对等。</p><p>为简单证明，我们以ETH/USDC为例来说明。</p><p>假如如下：<br>1. 现在ETH/USDC的价格是2000<br>2. 我们的初始资金是2000USDC<br>3. 我们提供流动性ETH和USDC的比例为1:1<br>4. 我们使用uniswap v3，价格范围为上下10%，即[1800, 2222]</p><p>我们的初始资产为2000USDC，LP的初始资产为：0.5ETH + 1000USDC</p><p>那么，存在以下几种可能：<br>1. 币价上涨超过10%，我们LP资产全部变为USDC<br>2. 币价下跌超过10%，我们LP资产全部变为ETH<br>3. 币价在[1800, 2222]之间波动</p><p>我们先来分析前两种情况。</p><h3>币价超过2222</h3><p>当币价高于2222时，我们的资产全部兑换为USDC，数量为：2053</p><p>那么，以USDC计价，我们的收益为：<br>(2053–2000)/2000=2.65%</p><h3>币价低于1800</h3><p>当币价低于1800时，我们的资产全部兑换为ETH，数量为1.026584</p><p>那么，以USDC计价，我们的损失为：<br>(2000–1800 * 1.026584)/2000 = 7.6%</p><p>通过上面的计算，我们可以发现，当币价上涨11%时我们的收益为2.65%，当币价下跌10%时，我们的损失为7.6%</p><p>1. LP降低了收益，同时也减少了亏损<br>2. LP在币价上涨时的收益与币价下跌时的亏损不平衡，上涨11%时，收益2.65%；而币价下跌10%时，亏损7.6%</p><h3>无常损失</h3><p>虽然有人可能会说，上面的亏损只是暂时的，当价格回到区间后，亏损就会</p><h3>币本位</h3><p>事实上，以币本位来计算不会影响结论，只是币价上涨时亏损加大，而币价下跌时盈利小。</p><h3>非对等比例LP</h3><p>上述分析基于token x 和token y的比例为1:1情况下，LP的收益和损失。那么，如果我们提供流动性时，x和y的比例不对等时，对收益和损失有什么影响呢？</p><p>让我们把上面的特例通用化。</p><p>首先，假设我们提供流动性时，当前价格在我们的价格区间内。如果不在，我们提供的流动性不会赚取任何手续费收益，因此暂不讨论。</p><p>当前价格为price current，记为pc<br>价格区间为price low, price high， 记为[pl, ph]<br>交易对为tokenx/tokeny<br>初始资产全部是token y，总量记为T。</p><p>为了开始提供流动性，我们需要把我们R比例的token y兑换为token x，这里R&gt;0 &amp;&amp; R&lt;1。</p><p>事实上，当我们的价格区间和总资产确定后，R是确定的。</p><p>uniswap v3流动性变量五元组：<br>1. 当前价格， price current<br>2. 价格区间， price low，price high<br>3. token数量，amountX, amountY</p><p>上述5个变量，可以通过任意4个计算出第五个。</p><p>由于：<br>x = L * [sqrt(ph) — sqrt(pc)] / [sqrt(pc) * sqrt(ph)]<br>y = L * [sqrt(pc) — sqrt(pl)]</p><p>两式相除：<br>x/y = [sqrt(ph) — sqrt(pc)]/{[sqrt(pc) — sqrt(pl)] * [sqrt(pc) * sqrt(ph)]}</p><p>x = RT/pc<br>y = (1-R)T</p><p>代入，得到：<br>R/(1-R) = pc * [sqrt(ph) — sqrt(pc)]/{[sqrt(pc) — sqrt(pl)] * [sqrt(pc) * sqrt(ph)]}</p><p>上述公式中，pc，ph，pl均为已知，因此，可以求解R</p><p>当价格变化后，假设新的价格为price new，记为pn，假设price new仍然在价格区间内。此时，由于L不变，可以求解出token x的数量xn和token y的数量 yn</p><p>xn = L * [sqrt(ph) — sqrt(pn)] / [sqrt(pn) * sqrt(ph)]<br>yn = L * [sqrt(pn) — sqrt(pl)]</p><p>因此，可以根据以上公式计算在[pl, ph] 区间下的各种价格的盈利和亏损，然后与币价的涨跌幅对比。</p><h3>总结</h3><p>很多人没有意识到uniswap LP的天生缺陷，就是相同币价涨幅与跌幅时，币价上涨时的盈利与币价下跌时的亏损的不对等。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2739ebcc882d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The inherent flaw of Uniswap LP — Asymmetry in Profit and Loss]]></title>
            <link>https://medium.com/@guotie/the-inherent-flaw-of-uniswap-lp-asymmetry-in-profit-and-loss-fc7c2d173c2f?source=rss-d0c2e22334be------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc7c2d173c2f</guid>
            <dc:creator><![CDATA[tony]]></dc:creator>
            <pubDate>Thu, 01 Feb 2024 12:12:08 GMT</pubDate>
            <atom:updated>2024-02-02T04:58:26.655Z</atom:updated>
            <content:encoded><![CDATA[<h3>The inherent flaw of Uniswap LP — Asymmetry in Profit and Loss</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/0*217ki4YgRSQSH2mr.png" /><figcaption>uniswap v3 curve</figcaption></figure><p>Chinese version: <a href="https://medium.com/@guotie/uniswap-lp-%E7%9A%84%E5%A4%A9%E7%94%9F%E7%BC%BA%E9%99%B7-%E7%9B%88%E4%BA%8F%E4%B8%8D%E5%AF%B9%E7%AD%89-2739ebcc882d">https://medium.com/@guotie/uniswap-lp-%E7%9A%84%E5%A4%A9%E7%94%9F%E7%BC%BA%E9%99%B7-%E7%9B%88%E4%BA%8F%E4%B8%8D%E5%AF%B9%E7%AD%89-2739ebcc882d</a></p><p>After conducting a thorough analysis of Uniswap Liquidity Providers (LP), we have uncovered a remarkable fact: LP faces challenges in achieving profitability, whether it be in USD terms or token terms.</p><p>TL;DR The fundamental flaw of Uniswap LP lies in the asymmetry of profit during price increases and losses during price decreases when the price change is the same.</p><p>To illustrate this, let’s consider the example of ETH/USDC.</p><p>Assuming the following:</p><p>1. The current price of ETH/USDC is 2000.<br>2. Our initial capital is 2000 USDC.<br>3. We provide liquidity in a 1:1 ratio of ETH to USDC.<br>4. We use Uniswap v3 with a price range of ±10%, i.e., [1800, 2222].</p><p>Our initial assets are 2000 USDC, and the LP’s initial assets are 0.5 ETH + 1000 USDC.</p><p>There are several possible scenarios:</p><p>1. If the coin price rises by more than 10%, our LP assets will be entirely converted to USDC.<br>2. If the coin price falls by more than 10%, our LP assets will be entirely converted to ETH.<br>3. If the coin price fluctuates within [1800, 2222].</p><p>Let’s analyze the first two scenarios.</p><h3>Price Exceeds 2222</h3><p>When the coin price is higher than 2222, our assets are entirely converted to USDC, with a quantity of 2053.</p><p>So, in terms of USDC, our profit is: (2053–2000)/2000 = 2.65%.</p><h3>Price Falls Below 1800</h3><p>When the coin price is lower than 1800, our assets are entirely converted to ETH, with a quantity of 1.026584.</p><p>So, in terms of USDC, our loss is: (2000–1800 * 1.026584)/2000 = 7.6%.</p><p>Through the above calculations, we find that when the coin price rises by 11%, our profit is 2.65%, and when the coin price falls by 10%, our loss is 7.6%.</p><p>1. LP reduces profits but also mitigates losses.<br>2. LP’s profit during coin price increases and losses during coin price decreases are imbalanced: a rise of 11% results in a profit of 2.65%, while a fall of 10% leads to a loss of 7.6%.</p><h3>Impermanent Loss</h3><p>Some may argue that the losses mentioned above are temporary, and they will be recovered when the price returns to the range.</p><h3>Token-based Perspective</h3><p>In fact, calculating in token terms does not alter the conclusion. It merely accentuates the increased loss during coin price increases and diminished profit during coin price decreases.</p><h3>Non-equivalent LP Ratios</h3><p>The above analysis is based on a 1:1 ratio of token x and token y. So, what happens to profits and losses if the ratio of x and y is not equal when providing liquidity?</p><p>Let’s generalize the above example.</p><p>Firstly, assuming we provide liquidity with the current price within our price range. If not, the liquidity provided won’t earn any fee income, so we won’t discuss it for now.</p><p>The current price is denoted as price current, [pl, ph] represents the price range, and the trading pair is token x/token y. The initial assets are entirely in token y, with a total quantity of T.</p><p>To initiate liquidity provision, we need to exchange an R ratio of token y for token x, where R &gt; 0 and R &lt; 1.</p><p>In reality, once our price range and total assets are determined, R is fixed.</p><p>Uniswap v3 liquidity variables include:</p><p>1. Current price, price current.<br>2. Price range, [price low, price high].<br>3. Token quantities, amountX, amountY.</p><p>Any four of the above five variables can be used to calculate the fifth.</p><p>Considering: <br>x = L * [sqrt(ph) — sqrt(pc)] / [sqrt(pc) * sqrt(ph)]<br>y = L * [sqrt(pc) — sqrt(pl)]</p><p>Dividing the two equations:：<br>x/y = [sqrt(ph) — sqrt(pc)]/{[sqrt(pc) — sqrt(pl)] * [sqrt(pc) * sqrt(ph)]}</p><p>Substituting<br>x = RT/pc<br>y = (1-R)T</p><p>We get:：<br>R/(1-R) = pc * [sqrt(ph) — sqrt(pc)]/{[sqrt(pc) — sqrt(pl)] * [sqrt(pc) * sqrt(ph)]}</p><p>In this formula, pc, ph, and pl are known, so R can be solved.</p><p>After a price change, assuming a new price, price new (pn), remains within the price range, and L remains constant, we can solve for the quantities of token x (xn) and token y (yn).</p><p>xn = L * [sqrt(ph) — sqrt(pn)] / [sqrt(pn) * sqrt(ph)]<br>yn = L * [sqrt(pn) — sqrt(pl)]</p><p>Therefore, based on the above formulas, we can calculate the profit and loss at various prices within the [pl, ph] range and compare them with the percentage changes in coin prices.</p><h3>Conclusion</h3><p>Many people are not aware of the inherent flaw in Uniswap LP, which is the asymmetry of profits during coin price increases.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc7c2d173c2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make JWT more safe]]></title>
            <link>https://medium.com/@guotie/make-jwt-more-safe-f53289ab29bb?source=rss-d0c2e22334be------2</link>
            <guid isPermaLink="false">https://medium.com/p/f53289ab29bb</guid>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[jwt-token]]></category>
            <category><![CDATA[safety]]></category>
            <dc:creator><![CDATA[tony]]></dc:creator>
            <pubDate>Sun, 12 Nov 2023 10:37:55 GMT</pubDate>
            <atom:updated>2023-11-12T10:37:55.496Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is JWT</h3><p>JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA or ECDSA.</p><h3>Make JWT more safe</h3><h3>secret for every Account</h3><p>In some best practice of JWT, they just say we need an universe secret for every account signature, which mostly from an envirment varible. But the secret is so fundemental, is it enough safe that a global secret for all account? Nobody care it, nobody discuss it, nobody mention it.</p><p>We use different salt to hash account password for different account, why we use same secret for all account? The JWT is JUST as important as user’s password!</p><p>In my opinion, we should use different secret for every account, just like password salt.</p><p>If we use different secret for every account, we should save the secret in server side, DB or redis. Of course, this will slow down the JWT validate flow, but we could save the secret in server’s memory cache after server start up.</p><h3>save &amp; validate signature in server side</h3><p>JWT is mostly about how to verify the JWT token is valid, by the signature. In most scene, this is great. But in some case, for example, we want kick off a special user, JWT can do nothing.</p><p>So, we could save the JWT signature in the server, then we could verify the JWT twice:</p><ul><li>first, verify the signature;</li><li>second, check the signature in server DB or redis, if exists, the JWT is valid; or else invalid</li></ul><p>By this method, we can kick off user or force user re-login.</p><p>Also, there are some tricks, we don’t need to save all JWT payload in the server, for example, we can just save the userId and JWT signature in the server side.</p><h3>JWT for anonymous or visitors</h3><p>Sometime we want give better user expirence for the anonymous or visitors, we can use JWT to record visitor’s information. For example, the user’s information:</p><pre>name<br>IP address<br>first visit time<br>location(optional)</pre><p>use these information, we could track visitors and provide good expirence.</p><h3>Question</h3><p>If we use JWT this way, why we use JWT instead of session? One of the most benefit of JWT is the client can get many information from JWT, even they have not connect to the server.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f53289ab29bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A little thought about stablecoins (1)]]></title>
            <link>https://medium.com/coinmonks/a-little-thought-about-stablecoins-1-12f28638d9fc?source=rss-d0c2e22334be------2</link>
            <guid isPermaLink="false">https://medium.com/p/12f28638d9fc</guid>
            <category><![CDATA[stablecoin-cryptocurrency]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[btc]]></category>
            <category><![CDATA[politics]]></category>
            <category><![CDATA[crypto]]></category>
            <dc:creator><![CDATA[tony]]></dc:creator>
            <pubDate>Sun, 27 Mar 2022 04:13:23 GMT</pubDate>
            <atom:updated>2022-03-29T15:22:40.143Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WiPXEm8fPTxjXZu0NPSEqA.png" /></figure><p>Since the 2019 covid-19 epidemic, various deglobalization thoughts and regulations have emerged; after the Ukraine war, deglobalization reflections in the financial sector have begun to appear, can the dollar still be trusted? Can financial institutions in neutral countries still be trusted? Behind these trust crises, it shows that decentralized BTC and ETH will be the right direction for human development in the future.</p><p>We are at the crossroads of a great transformation.</p><h3>About power</h3><p>Before talking about stablecoins, we need to talk about power.</p><p>The current regulations on crypto are all illusions, and the essence is a power struggle. The characteristics of power determine that power is always self-reinforcing and self-expanding. Most of the current power is in the hands of politicians and the rich; therefore, we can see that the power of each government is constantly expanding, and at the same time, wealth is becoming more and more concentrated, and the proportion of wealth of the rich in each country is constantly increasing. rise.</p><p>With the penetration of the blockchain into finance and economy, part of the power will inevitably be transferred to the chain and to the code. This is unbearable for the current power owners, and they will do everything possible to prevent them as much as possible. This transfer of power.</p><p>Let’s take a look at this example of the Ukrainian war. Since the Ukraine war, various agencies have been asked by the US to sanction Russian entities, individuals. The major crypto exchanges are no exception, the most obvious being binance. Several U.S. politicians named cex and binance, asking them to be more proactive in imposing sanctions on Russian entities and individuals. Binance CEO cz said that compared with hundreds of banks in Europe, the assets of Russian users managed by Binance are less than 0.3% of the bank’s assets, but American politicians have been staring at Binance and asked Binance to sanction Russian users. Does binance have more influence than those hundreds of banks? Obviously not.</p><p>There are two reasons.<br>First, cex is a subversion of the financial field. For a long time, the financial field has been licensed to operate, thus ensuring the monopoly position and income of practitioners, and cex has broken this monopoly to some extent, which has always been a thorn in the eyes of regulators; as the largest cex, binance, Naturally bear the brunt.</p><p>Second, the assets of cex can be easily transferred to the chain, making it impossible to be sanctioned; while the assets of banks can only be transferred between banks, no matter which bank they are transferred to, they cannot avoid being sanctioned;</p><p>The blockchain challenges the country’s financial system and coinage rights. Therefore, neither China, nor the United States, nor other governments are willing to see the development and growth of the blockchain. After several rounds of crackdowns, China basically wiped out the domestic exchanges and mining industries; during the same period, although Facebook made a lot of explanations, made a lot of preparations, and attracted many traditional financial institutions, the United States did not hesitate to stop it. The idea of ​​facebook issuing a stablecoin; Russia has been restricting the use of BTC before the Ukraine war, only allowing BTC to be mined to earn foreign exchange.</p><p>If the governments of various countries are monolithic, it is estimated that the use of BTC and ETH has already been banned by law. However, every country in the world has conflicts of interest, and different countries have different demands, which gives the blockchain industry development opportunities.</p><p>The United States, as a global hegemon, can harvest the world through currency issuance; other big countries, the government can harvest their own countries by issuing legal currency; the worst is some small countries, which basically have no monetary autonomy and can only be harvested, so we see, Salgado first used BTC as the national reserve currency, and then South American countries followed suit to study this policy. Now that Russia has been sanctioned and kicked out of the swift system, its attitude towards BTC has changed 180 degrees, and it has even been willing to accept BTC as payment for crude oil and natural gas.</p><p>The chaotic world promotes the development of crypto. Ukraine has accepted crypto donations from the very beginning, and has also issued NFTs. Now Russia is discussing accepting BTC for the purchase of crude oil and natural gas. These government actions have greatly enhanced the consensus of crypto. This poses a challenge to the current global dollar-based monetary system. Since crypto does not require trust, it cannot be controlled by anyone, any organization, or any country, and it exceeds national sovereignty. Therefore, it will inevitably win the final victory.</p><p>In the process of issuing fiat currency, the government obtains a hidden benefit called seigniorage. Among the various challenges that blockchain poses to governments, the challenge of minting rights is the greatest. BTC and ETH are more of an asset attribute, while the influence of stablecoins will involve payment, circulation, liquidation, and penetrate into all aspects of the economy and finance. It has brought huge benefits to the government, and no government will easily give up this power, which is determined by the nature of power. Therefore, we can see that the United States has especially strengthened the supervision of stablecoins in the past two years.</p><p>The chart below is a graph of the U.S. government’s liabilities from 1990 to 2020. Among more than 200 countries in the world, the United States is a relatively restrained government, but despite this, the US government’s debt is still accelerating. It is conceivable how much wealth the people of other countries have been plundered by inflation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4zKEG8cqLSlhRDjXthWS5A.png" /></figure><p>Paypal is a great company. Since 1998, Paypal has defeated countless competitors from a team of several people to become the current giant, and profoundly changed the payment industry; however, Paypal has not fully realized its original vision — — — Save most of the world’s people from inflation. Today, even Americans have begun to suffer from inflation under the circumstance that the currency is constantly over-issued.</p><p>100 years ago, the food we ate and the houses we lived in were much cheaper than now, and of course our income was much lower than now. In the process of the government’s continuous issuance of fiat currency, due to the timeliness of currency flow, everyone gets different benefits, and the government obtains additional benefits from seigniorage; Most of the people are victims of inflation and become poorer and poorer in the process of over-issue of money.</p><p>This is not that Paypal is not good enough, not great enough; it is essentially that Paypal cannot do this; at the same time, no individual, any organization, or any government can do it. Seigniorage is the source of inflation. The corruption of power and the greed of human nature cannot be changed. In the face of the huge temptation of seigniorage, power cannot restrain itself forever, and the currency will continue to be issued. Therefore, the final outcome of any credit currency in the world is collapse. From ancient times to the present , without exception.</p><p>OK, we are about to get to the point of stablecoins. Decentralized algorithmic stablecoins must be used if inflation is to be prevented from exploiting the general public.</p><blockquote>Join Coinmonks<a href="https://t.me/coincodecap"> Telegram Channel</a> and<a href="https://www.youtube.com/c/coinmonks/videos"> Youtube Channel</a> learn about crypto trading and investing</blockquote><h3>Also, Read</h3><ul><li><a href="https://medium.com/coinmonks/blockfi-vs-celsius-vs-hodlnaut-8a1cc8c26630">BlockFi vs Celsius</a> |<a href="https://medium.com/coinmonks/hodlnaut-review-best-way-to-hodl-is-to-earn-interest-on-your-bitcoin-6658a8c19edf"> Hodlnaut Review</a> |<a href="https://coincodecap.com/kucoin-review"> KuCoin Review</a></li><li><a href="https://medium.com/coinmonks/bitsgap-review-a-crypto-trading-bot-that-makes-easy-money-a5d88a336df2">Bitsgap review</a> |<a href="https://medium.com/coinmonks/quadency-review-a-crypto-trading-automation-platform-3068eaa374e1"> Quadency Review</a> |<a href="https://medium.com/coinmonks/bitbns-review-38256a07e161"> Bitbns Review</a></li><li><a href="https://medium.com/coinmonks/top-10-crypto-copy-trading-platforms-for-beginners-d0c37c7d698c">Crypto Copy Trading Platforms</a> |<a href="https://medium.com/coinmonks/coinmama-review-ace5641bde6e"> Coinmama Review</a></li><li><a href="https://medium.com/coinmonks/bitcoin-exchange-in-india-7f1fe79715c9">Crypto exchanges in India</a> |<a href="https://medium.com/coinmonks/bitcoin-savings-account-e65b13f92451"> Bitcoin Savings Account</a></li><li><a href="https://coincodecap.com/okex-kucoin">OKEx vs KuCoin</a> |<a href="https://coincodecap.com/celsius-alternatives"> Celsius Alternatives</a> |<a href="https://coincodecap.com/buy-vechain"> How to Buy VeChain</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12f28638d9fc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/a-little-thought-about-stablecoins-1-12f28638d9fc">A little thought about stablecoins (1)</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[react-native is on the wrong way…..]]></title>
            <link>https://medium.com/@guotie/react-native-is-on-the-wrong-way-b6345f4198c3?source=rss-d0c2e22334be------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6345f4198c3</guid>
            <category><![CDATA[wasm]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[tony]]></dc:creator>
            <pubDate>Tue, 14 Dec 2021 12:44:01 GMT</pubDate>
            <atom:updated>2021-12-14T12:44:01.194Z</atom:updated>
            <content:encoded><![CDATA[<p>When react-native is out, it is the first choice of cross-platform, but things changed. At this time, most people will choice flutter.</p><p>Why this?</p><p>Because react-native is on the wrong way.</p><p>First, performance, react-native waste time to use JIT to raise performance. This is the most big mistake. It should focus on wasm, not JIT.</p><p>Second, typescript. I think it should use typescript totally.</p><p>React-native will great again, typescript has big ecosym than flutter/dart, but the time window is not so long.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6345f4198c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[loopback swap in uniswap]]></title>
            <link>https://medium.com/@guotie/loopback-swap-in-uniswap-ca6d1053b7ef?source=rss-d0c2e22334be------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca6d1053b7ef</guid>
            <category><![CDATA[arbitrage]]></category>
            <category><![CDATA[loopback]]></category>
            <category><![CDATA[uniswap]]></category>
            <dc:creator><![CDATA[tony]]></dc:creator>
            <pubDate>Fri, 15 Oct 2021 02:28:53 GMT</pubDate>
            <atom:updated>2021-10-15T02:28:53.575Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ecnW0BN-AdxVGMC9i2v2hQ.png" /></figure><p>The transaction fee of `uniswap` is derived from the identity of `x * y = K`. In a specific transaction scenario, such as a loopback transaction, our transaction cost can be far lower than the rated fee .</p><h3>What is a loopback transaction</h3><p>The loopback transaction is a transaction in a transaction pair `tokenA/tokenB`, first swap`tokenA` to get `tokenB`, and then immediately swap the obtained `tokenB` back to `tokenA`.</p><p>The standard rate of `uniswap v2` is 0.3%, then the cost of loopback transaction is 0.6%, this cost is quite high. If we are just to brush the transaction volume, we need an effective way to reduce Handling fees, loopback transactions are a very effective way.</p><h3>Theoretical Derivation</h3><p>The following is our detailed derivation process. Assumptions are as follows:</p><p>* dx: the number of tokenA entered<br>* r0: the reserve quantity of tokenA<br>* r1: The reserve quantity of tokenB<br>* dy: the amount of the first tokenA -&gt; tokenB swap<br>* ex: the second swap tokenB -&gt; the number of tokenA</p><p>According to the formula of uniswap, the calculation is as follows:</p><blockquote>dy = dx*997*r1/(1000*r0 + dx*997)</blockquote><blockquote>R1 = r1-dy<br>R0 = r0 + dx</blockquote><blockquote>ex = dy*997*R0/(1000*R1 + dy*997)</blockquote><p>Substituting dy, after simplification, we can get:</p><blockquote>ex = 997*997*dx*(r0+dx) / (1000*1000*r0 + 997*997*dx)</blockquote><p>Divide by dx at the same time:</p><blockquote>ex/dx = 997*997*(r0+dx) / (1000*1000*r0 + 997*997*dx)</blockquote><p>Since <strong><em>ex</em> </strong>is our tokenA quantity at the end of the final loopback transaction, <strong><em>dx</em></strong><em> </em>is our tokenA input quantity, and <strong><em>1-ex/dx</em></strong> is our handling fee ratio.</p><p>It can be seen from the above formula that the final loopback transaction <strong><em>ex</em></strong> is only related to the input <strong><em>dx</em></strong> and the `reserve` of `tokenA`, and the higher the ratio of the input number `dx` to `tokenA reserve`, the final result is ` The closer the ex/dx` is to 1, the less the fee is paid.</p><h3>Code calculation</h3><p>The test code is as follows:</p><p>Filename: loopbackSwap.js</p><blockquote>const BigNumber = require(‘ethers’).BigNumber</blockquote><blockquote>const e18 = BigNumber.from(‘1000000000000000000’)</blockquote><blockquote>const getAmountOut = (amountIn, r0, r1) =&gt; {<br> const amountInWithFee = amountIn.mul(997)<br> , numerator = amountInWithFee.mul(r1)<br> , denominator = r0.mul(1000).add(amountInWithFee);</blockquote><blockquote>return numerator.div(denominator)<br>}</blockquote><blockquote>const getAmountBack = (amtIn, r0, r1, printable = false) =&gt; {<br> const out = getAmountOut(amtIn, r0, r1)<br> <br> r0 = r0.add(amtIn)<br> r1 = r1.sub(out)</blockquote><blockquote>const dx = getAmountOut(out, r1, r0)<br> if (printable) {<br> console.info(‘swap x-&gt;y: out=%s r0=%s r1=%s backx=%s’,<br> out.toString(), r0.toString(), r1.toString(), dx.toString())<br> }<br> return {amtInter: out, amtOut: dx}<br>}</blockquote><blockquote>function loopbackSwap() {<br> const reserveA = BigNumber.from(1000000).mul(e18)<br> , reserveB = BigNumber.from(2000000).mul(e18)<br> , ratio = (multor) =&gt; reserveA.mul(multor).div(1000)</blockquote><blockquote>let amts = [<br> 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 3000, 5000, 10000]</blockquote><blockquote>for (let amt of amts) {<br> let amtIn = ratio(amt)<br> let {amtOut} = getAmountBack(amtIn, reserveA, reserveB)<br> console.info(‘dx/reserve=%s amtOut/amtIn=%s’, amt/1000, amtOut.mul(10000).div(amtIn).toNumber()/10000)<br> }<br>}</blockquote><blockquote>loopbackSwap()</blockquote><p>run the scripts:</p><blockquote>npx hardhat run loopbackSwap.js<br>dx/reserve=0.001 amtOut/amtIn=0.994<br>dx/reserve=0.002 amtOut/amtIn=0.994<br>dx/reserve=0.005 amtOut/amtIn=0.994<br>dx/reserve=0.01 amtOut/amtIn=0.994<br>dx/reserve=0.02 amtOut/amtIn=0.9941<br>dx/reserve=0.05 amtOut/amtIn=0.9942<br>dx/reserve=0.1 amtOut/amtIn=0.9945<br>dx/reserve=0.2 amtOut/amtIn=0.995<br>dx/reserve=0.5 amtOut/amtIn=0.9959<br>dx/reserve=1 amtOut/amtIn=0.9969<br>dx/reserve=2 amtOut/amtIn=0.9979<br>dx/reserve=3 amtOut/amtIn=0.9984<br>dx/reserve=5 amtOut/amtIn=0.9989<br>dx/reserve=10 amtOut/amtIn=0.9994</blockquote><p>It can be seen from the results that when <strong><em>dx/reserve</em></strong> exceeds 1, the handling fee rate drops rapidly, and when <strong><em>dx/reserve=10</em></strong>, the handling fee is only 6/10000, incredible!</p><p>As a result, lightning loans can be used to lend a large amount of funds from the borrowing pool at a lower interest rate, and then perform loopback transactions. In some exchanges where transactions are mining, mining can be reduced in this way Handling fee, arbitrage profit.</p><h3>Actual combat</h3><p>We can write a contract to execute our loopback transaction.</p><p>It should be noted that we cannot directly set the `<strong><em>path</em></strong>` parameter of `uniswap router` to `<strong><em>[tokenA, tokenB, tokenA]</em></strong>` for loopback transactions, but must be divided into two swaps, the first is `<strong><em>[tokenA, tokenB]</em></strong> `, then `<strong><em>[tokenB, tokenA]</em></strong>`.</p><p>The sample code is as follows:</p><blockquote>/// <a href="http://twitter.com/dev">@dev</a> swapLoopback swap tokenA to tokenB, then swap tokenB to tokenA<br> /// <a href="http://twitter.com/param">@param</a> _router uniswap-like router<br> /// <a href="http://twitter.com/param">@param</a> reward the reward token<br> /// <a href="http://twitter.com/param">@param</a> amountIn amount in<br> /// <a href="http://twitter.com/param">@param</a> amountOutMin just set to 0<br> /// <a href="http://twitter.com/param">@param</a> path [tokenA, tokenB]<br> function swapLoopback(<br> address _router, // router<br> address reward, // reward token<br> uint amountIn,<br> uint amountOutMin,<br> address[] memory path<br> )<br> public<br> onlyOwner {<br> address tokenIn = path[0];<br> uint tokenInitial = IERC20(tokenIn).balanceOf(address(this));</blockquote><blockquote>_approve(IERC20(tokenIn), address(_router));<br> // solhint-disable-next-line<br> uint256 ts = block.timestamp + 60;<br> uint[] memory amounts = IUniswapRouter(_router).swapExactTokensForTokens(amountIn, amountOutMin, path, address(this), ts);</blockquote><blockquote>path[0] = path[1];<br> path[1] = tokenIn;<br> // console.log(“amounts:”, amounts[1]);<br> _approve(IERC20(path[0]), address(_router));<br> amounts = IUniswapRouter(_router).swapExactTokensForTokens(amounts[1], amountOutMin, path, address(this), ts);</blockquote><blockquote>// other arbitrage code with reward..<br> reward;<br> }</blockquote><p>About me: I’m an solidity developer, dive deeply in AAVE, uniswap, Compound, 1inch, etc, I am looking for a solidity develop job, My blog: <a href="https://tiege.dev">https://tiege.dev</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca6d1053b7ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>