<?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 Scott Bigelow on Medium]]></title>
        <description><![CDATA[Stories by Scott Bigelow on Medium]]></description>
        <link>https://medium.com/@epheph?source=rss-b2797ae151ba------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*W29oNtAEgViywqL5.jpg</url>
            <title>Stories by Scott Bigelow on Medium</title>
            <link>https://medium.com/@epheph?source=rss-b2797ae151ba------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 20:49:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@epheph/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[Using Uniswap V2 Oracle With Storage Proofs]]></title>
            <link>https://medium.com/@epheph/using-uniswap-v2-oracle-with-storage-proofs-3530e699e1d3?source=rss-b2797ae151ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/3530e699e1d3</guid>
            <category><![CDATA[uniswap]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[uniswap-v2]]></category>
            <dc:creator><![CDATA[Scott Bigelow]]></dc:creator>
            <pubDate>Wed, 24 Jun 2020 06:46:11 GMT</pubDate>
            <atom:updated>2020-06-24T18:53:54.383Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://uniswap.org/blog/launch-uniswap-v2/">Uniswap V2 released with many new features</a>, including:</p><ul><li>Token:Token liquidity pairs (instead of ETH/DAI and ETH/MKR, Uniswap V2 now supports MKR/DAI natively)</li><li>Built-in multi-hop routing (ETH-&gt;DAI-&gt;MKR-&gt;USDT, if that’s the price for ETH-&gt;USDT)</li><li>ERC777 compatibility</li><li><strong>Price Accumulation Oracle</strong></li></ul><p>In this article, we are going to discuss this “Price Accumulation Oracle”, how it works, how it can be used, and introduce a Solidity library that can be used to integrate this Oracle into your own Ethereum project. This article will assume a deep understanding of constant product markets, such as Uniswap. If the pricing mechanisms discussed below are unclear, start with <a href="https://uniswap.org/docs/v2/#how-it-all-works">the [excellent] Uniswap docs</a>.</p><p><em>If you already know exactly where this article is heading, code samples and a solidity library are available here: </em><a href="https://github.com/Keydonix/uniswap-oracle"><em>https://github.com/Keydonix/uniswap-oracle</em></a><em>. If you’d like to learn more, read on!</em></p><p>While we normally consider an oracle to be a system which feeds off-chain information into the blockchain via transactions from trusted/bonded parties (e.g. Maker Price Feed, ChainLink), the Uniswap V2 oracle does not require any specific interaction to provide this data. Instead, every swap transaction contributes information to this oracle.</p><p>To illustrate the problem Uniswap V2 has solved with this new Oracle functionality, let’s first explore the problem with Uniswap V1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PqV5vAP7oI8cpICptxePbQ.jpeg" /></figure><h3>Don’t Use Uniswap V1 as an Oracle.</h3><p>The Uniswap team has never promoted Uniswap V1 as a viable on-chain Oracle. It is only due to Uniswap’s simple, permissionless, on-chain, market-oriented functionality that creative minds are enticed into using it as one. The Siren’s song of the Uniswap V1 oracle is simply:</p><pre>uint256 tokenPrice = token.balanceOf(uniswapMarket) / address(uniswapMarket).balance</pre><p>As the current “price” of a Uniswap V1 market is simply the ratio of token and ether balances, calculating these items is incredibly gas efficient and straight-forward. The problem, however, is that it is incredibly insecure. There are numerous attacks related to projects using Uniswap V1 as an Oracle, but perhaps the highest profile attack is the <a href="https://cointelegraph.com/news/are-the-bzx-flash-loan-attacks-signaling-the-end-of-defi">bZx/Fulcrum/Compound attack which, over 24 hours, netted nearly $1M USD.</a></p><p>The problem with Uniswap V1 is that the price feed is instantaneous, and is <em>easily manipulated over small periods of time, including instantaneously</em>. Let’s look at the following psuedo-code example:</p><pre>// send 100 ether and receive some number of tokens<br>uniswapMarket.ethToTokenSwapInput.value(100 ether)(100 ether);</pre><pre>exploitTarget.doSomethingThatUsesUniswapV1AsOracle();</pre><pre>// send all the tokens we received above back<br>uniswapMarket.tokenToEthSwapInput(token.balanceOf(address(this));</pre><p>In the attack above, you will pay a very small fee in ether, about 0.6 ETH, to the liquidity providers (0.3% both ways). However, when calling the exploitTarget, it will perceive the token as significantly more valuable than it actually is. If the exploitTarget was using the Uniswap V1 oracle to ensure the collateral you deposited was worth enough to withdraw some other token, that system would let you withdraw significantly more loaned tokens than your deposit warrants.</p><h3>How Uniswap V2 Acts Like an Oracle</h3><p>In the above example, Uniswap V1 price reads were problematic because they were instantaneous. V2 was deployed with a clever system for keeping price-time data recorded on-chain in a way that is expensive to manipulate over small periods of time, and <em>impossible to manipulate within a single transaction</em>. Through the use of “cumulative” price-time values, how long a price is available is weighted into a special value, with every token swap spending a small amount of gas to keep these values in sync.</p><p>Here is a snippet from the Uniswap market code:</p><p><em>Note: Unlike V1, V2 is a market between two tokens. Internally, one of these tokens needs to be represented as </em><em>token0 and the other </em><em>token1. Their balances are tracked by the corresponding </em><em>reserve0 and </em><em>reserve1. </em><a href="https://uniswap.org/docs/v2/technical-considerations/pair-addresses/"><em>Uniswap Docs have more info about token-ordering</em></a><em>.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/927fbce61544093798a3c90c03005401/href">https://medium.com/media/927fbce61544093798a3c90c03005401/href</a></iframe><p>price(0|1)CumulativeLast are independent storage variables which accumulate “price-time”. The UQ112x112 makes the code a little hard to read, but is not important conceptually; it only acts as a wrapper for high-precision division. The only difference between the “0” and “1” version of these cumulativeLast values is the direction of the price.</p><ul><li>price0CumulativeLast is “the price of token0 denominated in token1”</li><li>price1CumulativeLast is “the price of token1 denominated in token0”</li></ul><p><em>Due to the way the math works out when performing this accumulation, </em><em>price0CumulativeLast is NOT the inverse of </em><em>price1CumulativeLast. For the rest of this document, we will refer only to </em><em>price0CumulativeLast, but applies similarly to both values. Additionally, </em><em>price0CumulativeLast will not necessarily be up-to-date on every block, so you either need to </em><a href="https://github.com/Uniswap/uniswap-v2-core/blob/4dd59067c76dea4a0e8e4bfdda41877a6b16dedc/contracts/UniswapV2Pair.sol#L198-L200"><em>run sync() on the market</em></a><em>, or </em><a href="https://github.com/Keydonix/uniswap-oracle/blob/1c739f0ea572b1c1a55f5a9558b4822b111acb0a/contracts/source/UniswapOracle.sol#L84-L92"><em>true-up the value yourself</em></a><em>.</em></p><p>price0CumulativeLast is a value that only updates with the FIRST transaction on a block, taking the last known reserve0 and reserve1 values (token balances for token0 and token1), calculates their ratio (price), and scales it by the number of seconds since price0CumulativeLast was last updated. price0CumulativeLast is a value that <em>increases every second by the ratio of the two reserves</em>. To turn this value back into a price, one needs two point-in-time values of price0CumulativeLast, using the formula:</p><pre>(price0CumulativeLATEST — price0CumulativeFIRST) / (timestampOfLATEST — timestampOfFIRST)</pre><p>By dividing the <em>difference</em> in price0CumulativeLast in two samples by the number of seconds between those two samples, the process is reversed and the result is the time-weighted price for that period of time. The window you choose is an important security consideration:</p><ul><li>The fewer seconds between the two samples, the more up-to-date, but easier to manipulate</li><li>The more seconds between the two samples, the less up-to-date but more difficult to manipulate</li></ul><p>Finding the right balance between tamper-resistant and up-to-date should be carefully considered for your project.</p><p>Now that we have the formula for calculating this price, one problem remains: how does one retrieve the historical price cumulative information on-chain?</p><h3>Retrieving historic cumulative values using a smart contract</h3><p>Leveraging V2 as an on-chain oracle requires “proving” a prior value of:<br>price0CumulativeLast and its corresponding block timestamp</p><p>Retrieving current values for each of these is trivial (block.timstamp &amp; uniswapMarket.price0CumulativeLast()) but how do you retrieve the old one? The most straightforward approach is to deploy a smart contract which records the current value of price0CumulativeLast and timestamp into its own storage, to be recalled later as the historical value. While this would work, it has some drawbacks:</p><ul><li>Must be called periodically to store snapshot values, if you want that price feed constantly available in the future</li><li>If not called periodically, you must plan your transaction ahead, first to store the current value, waiting some period of time, then firing the transaction that uses that historical value</li></ul><p>You are stuck between somehow incentivizing bots to continually update the stored value (with bot fees coming from profits elsewhere in the system), or requiring users to send two transactions, one to snapshot the cumulative value, delaying the transaction they want to execute by some non-trivial amount of time in order to reach the number of seconds desired for the price feed average.</p><p>If you are not interested in designing an economic system for bots and you doubt users will want to wait to send two transaction, there is a better way to leverage Uniswap V2 as a price feed: Merkle Patricia Proofs!</p><h3>Retrieving historic cumulative value using storage proofs</h3><p>Ethereum contract state storage is stored in a “Merkle Trie”, a special data structure which allows a single 32 byte hash value to represent every storage values in every Ethereum contract (with separate tries for receipts and transaction data). This 32-byte value, named stateRoot, is an attribute of every Ethereum block (alongside ones you might be more familiar with, like block number, block hash, and timestamp)</p><p>(Note: Ethereum uses a variant called a <a href="https://medium.com/codechain/modified-merkle-patricia-trie-how-ethereum-saves-a-state-e6d7555078dd">“Merkle Patricia Trie” which you can read about here</a>).</p><p>Using the JSON-RPC interface of an Ethereum node, you can call eth_getProof to retrieve a payload which, when combined with this stateRoot value, can prove that for address A at storage slot B, the value C.</p><p>Using on-chain logic, it is possible to combine a stateRoot and storage proof to verify a storage slot’s value. If we target a Uniswap V2 Market and the storage slot for price0CumulativeLast, we can achieve the proof-based historic lookups we need.</p><p>However, stateRoot lookup is NOT available as an EVM opcode; the only relevant opcode is BLOCKHASH, which takes a blockNumber and returns the 32-byte block hash. The blockhash of a block is a simple Keccak256 hash of all of its various attributes, <a href="https://eth.wiki/en/fundamentals/rlp">rlp-encoded</a>. By providing ALL attributes of a block, including stateRoot, we can verify that the raw block data is valid, by hashing and comparing to the on-chain blockHash lookup. Once verified, we can then use the required attributes of the block (timestamp &amp; stateRoot).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3320c133f523444a0dac0c2e8e0604a3/href">https://medium.com/media/3320c133f523444a0dac0c2e8e0604a3/href</a></iframe><ol><li>A function like the one above can verify a full-block’s details and confirm all fields are correct for that block</li><li>Using the stateRoot (verified above) parse the provided proof (from a JSON-RPC getProof call) to retrieve the historic storage values from that block</li><li>Fetch the current price0CumulativeLast value from Uniswap market</li><li>Calculate average price between the provided block (from verified timestamp) and right now by dividing the increase in price0CumulativeLast by the number of seconds since the verified timestamp.</li></ol><p>At this point, you have your price in memory, an average over some configurable period of time, from a fully decentralized system based purely on market dynamics. For this price feed to be manipulated, the attacker would not only need to push this price in one direction, they would need to keep it there for long periods of time, between blocks, giving any buyer the chance to buy under-priced assets, which would in turn correct the price feed.</p><p><em>Note: on-chain </em><em>BLOCKHASH lookups only work for the past 256 blocks, the oldest block you can use for your storage proof must be </em><strong><em>within the last 256 blocks at the time the transaction lands</em></strong><em> on chain.</em></p><h3>Introducing Uniswap-Oracle Library</h3><p>The above strategy consists of a small bit of client side code (for handling proofs) and a larger amount of fairly complex Solidity, including YUL/assembly and Merkle Trie verification. <a href="https://medium.com/u/9e15b5664ca">Micah Zoltu</a> and I, as part of the <a href="https://medium.com/u/f605e3324ca4">Keydonix</a> development team, have developed and published <a href="https://github.com/Keydonix/uniswap-oracle/">Uniswap-Oracle</a>, a Solidity library which enables other smart contracts to leverage this oracle functionality.</p><p>To integrate with your own contract, simple inherit from the base contract <a href="https://github.com/Keydonix/uniswap-oracle/blob/master/contracts/source/UniswapOracle.sol">UniswapOracle.sol</a> ( contract HelloWorld is UniswapOracle), your contract will inherit the getPrice function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f88a07f92789bec727e31208c72f4fa/href">https://medium.com/media/3f88a07f92789bec727e31208c72f4fa/href</a></iframe><p>Your own function which requires access to this Uniswap price will need to receive this proof data as an argument to be passed along to this internal getPrice function call. Please see the <a href="https://github.com/Keydonix/uniswap-oracle/blob/master/README.md">Uniswap-Oracle README.me</a> for integration documentation.</p><p>The Uniswap-Oracle library is <strong>unaudited</strong>. Any application that is responsible for value on mainnet should be fully audited; please ensure your application’s audit covers the Uniswap-Oracle code as well.</p><p>Stop by the <a href="https://discord.gg/VybAU4">Keydonix Discord</a> to ask questions and get help with integration and <a href="https://twitter.com/keydonix">follow us on Twitter</a> for updates and new projects!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3530e699e1d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Announcing the new Amberdata Uniswap API]]></title>
            <link>https://medium.com/amberdata/announcing-the-new-amberdata-uniswap-api-304a2fe910ec?source=rss-b2797ae151ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/304a2fe910ec</guid>
            <category><![CDATA[exchange]]></category>
            <category><![CDATA[uniswap]]></category>
            <category><![CDATA[decentralized-exchange]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Scott Bigelow]]></dc:creator>
            <pubDate>Fri, 26 Jul 2019 18:29:58 GMT</pubDate>
            <atom:updated>2019-07-27T05:54:25.608Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://uniswap.exchange/swap">Uniswap</a> is a new take on a fully decentralized exchange (DEX) on Ethereum, one which provides immediate, fully on-chain settlement without requiring liquidity providers to coordinate off-chain or operate any market-making bots. Allowing anyone to provide liquidity significantly opens up the pool of liquidity beyond advanced users, increasing total Uniswap liquidity, which has risen quickly, hosting about $10M in liquidity with daily volumes exceeding $1M.</p><p>Leveraging Ethereum on-chain balances which <a href="https://amberdata.io/">Amberdata</a> already collects for every block, Amberdata now provides <a href="https://docs.amberdata.io/reference#get-market-orders-uniswap">an API to access Uniswap liquidity details</a> and <a href="https://docs.amberdata.io/reference#get-market-orders">a “materialized” order book</a>. Uniswap does not host an order book in the conventional sense, but given these on-chain balances and the exchange formula, we can materialize an order book, showing offer depth at various prices.</p><h3>About Uniswap</h3><p>To understand this API, let’s first look under the hood at how Uniswap works.</p><p>Uniswap operates under the “Constant Product” model, where the exchange rate for tokens is based on an extremely simple formula that considers the current contract balance of Ether against the contract balance of tokens being exchanged. For instance, on the ETH-DAI market, if the contract had a balance of 1,000 ether and 100,000 DAI, the “price” at that moment would be 1 ETH = 100 DAI (100,000 DAI divided by 1,000 ether). However, as users either buy or sell DAI, that rate changes at the moment of sale; the more you buy, the more each costs. As an example, given our above balances: 1,000 ETHER * 100,000 DAI = 100,000,000 (constant product).</p><p>If you wanted to exchange 100 ether for DAI, you deposit the Ether, and see how much DAI you can withdraw without impacting the product:</p><pre>(1,000 + 100) * (100,000-x) = 100,000,000<br>1,100         * 90,909      = 100,000,000</pre><pre>100,000 - x = 90,909<br>x = 9091 DAI (how much you can draw)<br>Price: 1 Ether = 90.91 DAI</pre><p>Notice this exchange rate isn’t the 1 ether = 100 DAI mid-point we mentioned above; we are operating on a significant portion of the total liquidity and the purchase itself changed the price significantly. 1 ETH = 90.91 DAI becomes the new mid-point price available for the next purchase; buying and selling into this market is the only way price changes. Instead of relying on market makers to set the price and spread, you rely exclusively on trades.</p><p>If we instead decided to sell more Ether, say 200, we would get a significantly different price:</p><pre>(1,000 + 200) * (100,000-x) = 100,000,000<br>1,200         *  83,333     = 100,000,000</pre><pre>100,000 - x = 83,333<br>x = 16,667 DAI (how much you can draw)<br>Price: 1 Ether = 83.35 DAI</pre><p>A more liquid Uniswap market will cause prices to move slowly with the same volume. The below table maps Uniswap liquidity to volume/price. Both of these charts are assuming a mid-point price of 100 DAI:ETH. Top row is Ether balance of contract (with an implied `100 * Ether balance` of tokens), left column is volume of order in Ether, value is how much DAI you must provide to buy that volume of Ether.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/303c1bf438de112deceb14aaead6f0b6/href">https://medium.com/media/303c1bf438de112deceb14aaead6f0b6/href</a></iframe><p>Those same values as a line chart:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*nmaKO4ffyZW5W4VqN764rQ.png" /></figure><p>Users who provide this liquidity do so as a pair of Ether and tokens. For instance, the Uniswap ETH-DAI contract would require liquidity providers to supply both Ether AND DAI, keeping the ratio of those tokens the same while increasing the balance of both (changing the product). If the current balance of each was 1,000 ETH : 100,000 DAI, you could provide liquidity by depositing 1 ETH and 100 DAI. Providing liquidity mints Uniswap liquidity tokens to be claimed from the market for your stake in the liquidity pool.</p><p>Users who provide this liquidity do so as a pair of Ether and tokens. For instance, the Uniswap ETH-DAI contract would require liquidity providers to supply both Ether AND DAI, keeping the ratio of those tokens the same while increasing the balance of both (changing the product). If the current balance of each was 1,000 ETH : 100,000 DAI, you could provide liquidity by depositing 1 ETH and 100 DAI. Providing liquidity mints Uniswap liquidity tokens to be claimed from the market for your stake in the liquidity pool.</p><ul><li>Uniswap trades will cause the ETH-DAI balance ratio to change, but not the product of the balances</li><li>Adding or removing liquidity to Uniswap will cause the product to change, but leave the ratio unchanged</li></ul><h3>Fees</h3><p>We did not cover fees in the above formulas for simplicity, but there is a 0.3% fee on all trades that goes entirely to the liquidity providers. The fee is calculated on input, if you deposit 1 Ether, you are only given tokens proportional to a deposit of 0.997 Ether.</p><h3>Uniswap API Endpoints</h3><p>The above formulas relating both to the current price, and how much the price changes as volume increases requires knowing only 2 values at a point in time: Ether balance and token balance of the market contract. This would normally require an archive node and many off-chain calls for historical perspective. Having already collected and indexed this data for all accounts and contracts, Amberdata is releasing a new endpoint for retrieving these values over time. Calling this liquidity endpoint returns a time-ordered array of each time the etherBalance or tokenBalance on this market changed, indicating a new mid-point price and volume curve.</p><h3>Liquidity Endpoint</h3><pre>$ curl -s &#39;https://web3api.io/api/v1/market/orders/uniswap/eth_dai/liquidity&#39; -H &quot;x-api-key: $API_KEY&quot;  | jq . | head -n 23<br>{<br> &quot;status&quot;: 200,<br> &quot;title&quot;: &quot;OK&quot;,<br> &quot;description&quot;: &quot;Successful request&quot;,<br> &quot;payload&quot;: [<br>   {<br>     &quot;timestamp&quot;: 1559865532000,<br>     &quot;blockNumber&quot;: &quot;7908742&quot;,<br>     &quot;etherBalance&quot;: &quot;3324430283894099142288&quot;,<br>     &quot;tokenBalance&quot;: &quot;828792193254129030902677&quot;<br>   },<br>   {<br>     &quot;timestamp&quot;: 1559865517000,<br>     &quot;blockNumber&quot;: &quot;7908740&quot;,<br>     &quot;etherBalance&quot;: &quot;3322930303743208056464&quot;,<br>     &quot;tokenBalance&quot;: &quot;829165190040182952588747&quot;<br>   },<br>   {<br>     &quot;timestamp&quot;: 1559865500000,<br>     &quot;blockNumber&quot;: &quot;7908734&quot;,<br>     &quot;etherBalance&quot;: &quot;3322120127262793325731&quot;,<br>     &quot;tokenBalance&quot;: &quot;829366794677970374451162&quot;<br>   },</pre><p>With options:</p><pre>$ curl -s &#39;https://web3api.io/api/v1/market/orders/uniswap/eth_zrx/liquidity?timeFormat=iso&amp;startDate=1559815500000&amp;endDate=1559865532000&#39; -H &quot;x-api-key: $API_KEY&quot;  | jq . | head -n 23<br>{<br>  &quot;status&quot;: 200,<br>  &quot;title&quot;: &quot;OK&quot;,<br>  &quot;description&quot;: &quot;Successful request&quot;,<br>  &quot;payload&quot;: [<br>    {<br>      &quot;timestamp&quot;: &quot;2019-06-06T23:01:42.000Z&quot;,<br>      &quot;blockNumber&quot;: &quot;7908472&quot;,<br>      &quot;etherBalance&quot;: &quot;347660842874075342316&quot;,<br>      &quot;tokenBalance&quot;: &quot;267458136974184976315471&quot;<br>    },<br>    {<br>      &quot;timestamp&quot;: &quot;2019-06-06T22:32:48.000Z&quot;,<br>      &quot;blockNumber&quot;: &quot;7908344&quot;,<br>      &quot;etherBalance&quot;: &quot;337111576953296679754&quot;,<br>      &quot;tokenBalance&quot;: &quot;259342506274184979058454&quot;<br>    },<br>    {<br>      &quot;timestamp&quot;: &quot;2019-06-06T19:38:49.000Z&quot;,<br>      &quot;blockNumber&quot;: &quot;7907611&quot;,<br>      &quot;etherBalance&quot;: &quot;347660842834227753835&quot;,<br>      &quot;tokenBalance&quot;: &quot;267458136943529922701354&quot;<br>    },</pre><p>Using this data, one could get current and all prior Uniswap mid-point prices and volume curves. Using these values, and a knowledge of the on-chain formula, you could calculate what buying or selling on Uniswap would cost and yield at any point in time. For instance, in late June, the the mid-point price was about 300 DAI per ETH, but the liquidity was lower than it is today, in July, by ~25%. Depending on the volume you are looking to exchange, it could be better to exchange at a lower price, but with more liquidity, as your order would not move the market nearly as much.</p><p>Having access to these numbers help drive that decision</p><h3>Standard Order Book Endpoint</h3><p>Instead of simply serving up the raw ether/token balance information, Amberdata can also use these balances server-side to reconstruct an order book by iterating through various volumes and reporting which prices were being offered. Since <a href="https://docs.amberdata.io/reference#get-market-orders">Amberdata already provides order book data for many of the top crypto exchanges</a>, we simply added “uniswap” as an exchange option (along with “gdax”, “binance”, “bitfinex”, etc), ensuring its output matches our standard order book snapshot endpoint:</p><pre>$ curl -s &#39;https://web3api.io/api/v1/market/orders/eth_zrx?exchange=uniswap&#39; -H &quot;x-api-key: $API_KEY&quot; | jq .<br>{<br>  &quot;status&quot;: 200,<br>  &quot;title&quot;: &quot;OK&quot;,<br>  &quot;description&quot;: &quot;Successful request&quot;,<br>  &quot;payload&quot;: {<br>    &quot;metadata&quot;: {<br>      &quot;columns&quot;: [<br>        &quot;price&quot;,<br>        &quot;volume&quot;,<br>        &quot;numOrders&quot;<br>      ],<br>      &quot;requestedTimestamp&quot;: 1559942084862,<br>      &quot;returnedTimestamp&quot;: 1559931517000<br>    },<br>    &quot;data&quot;: {<br>      &quot;bid&quot;: [<br>        [ 661.3182737611725, 49, 1 ],<br>        [ 662.9167671038554, 48, 1 ],<br>...<br>        [ 743.8230930428307, 3, 1 ],<br>        [ 745.8459262955631, 2, 1 ],<br>        [ 747.8797917751368, 1, 1 ],<br>        [ 749.7197780376213, 0.1, 1 ]<br>      ],<br>      &quot;ask&quot;: [<br>        [ 754.6495528334601, 0.1, 1 ],<br>        [ 756.5174080836109, 1, 1 ],<br>        [ 758.6036772163081, 2, 1 ],<br>        [ 760.7014848941935, 3, 1 ],<br>...<br>        [ 863.3643269502593, 46, 1 ],<br>        [ 866.0825798918668, 47, 1 ],<br>...</pre><p>This standardized order book snapshot response is a convenient format for those already integrated into the standard order book API or already have logic for interpreting an order book as a list of orders. There is no more information in this endpoint than the liquidity one, it’s simply server-side processing of the balances. Due to the sampling, this response is slightly inaccurate, as there aren’t “steps” in price; the Uniswap order book price is perfectly continuous across any volume that it can fulfill.</p><h3>The Uniswap Depth UI</h3><p>To demonstration this new API, we created a simple UI based on jQuery and Amcharts to retrieve Uniswap balance pairs over a range of time, and view them as if they were a standard depth chart, continuously. This utilizes the above “liquidity” endpoint and implements the Uniswap volume/price curve logic locally, with each chart being powered only by 2 values: Ether balance and token balance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*ETOWL2gobcEt-z2r.png" /></figure><p>The color fade here happens at 2% of the price. Because the chart is continuous, it is difficult to visualize the volume/price curve, as the shape is nearly identical. That dark colored bar shows how much volume the market supports before crossing 2% off the mid-point price.</p><h3>Check it out</h3><p>To see this chart and API in action for yourself, <a href="https://amberdata.github.io/unidepth/">see the demo hosted on github</a>. If you want to see what’s running under the hood, check out the <a href="https://github.com/amberdata/unidepth/">demo repo</a> and open up index.html in your browser. All assets are self-contained and there is no build process.</p><h3>More Resources</h3><ul><li><a href="https://docs.amberdata.io/reference#get-market-orders">https://docs.amberdata.io/reference#get-market-orders</a></li><li><a href="https://docs.amberdata.io/reference#get-market-orders-uniswap">https://docs.amberdata.io/reference#get-market-orders-uniswap</a></li><li><a href="https://uniswap.exchange/">https://uniswap.exchange/</a></li><li><a href="https://docs.uniswap.io/">https://docs.uniswap.io/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=304a2fe910ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/amberdata/announcing-the-new-amberdata-uniswap-api-304a2fe910ec">Announcing the new Amberdata Uniswap API</a> was originally published in <a href="https://medium.com/amberdata">amberdata</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SUM Token Contract — Was it worth $140K USD in Gas?]]></title>
            <link>https://medium.com/@epheph/sum-token-contract-was-it-worth-140k-usd-in-gas-f027190eaae8?source=rss-b2797ae151ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/f027190eaae8</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Scott Bigelow]]></dc:creator>
            <pubDate>Sat, 23 Mar 2019 01:12:42 GMT</pubDate>
            <atom:updated>2019-03-23T02:43:58.466Z</atom:updated>
            <content:encoded><![CDATA[<h3>SUM Token Contract — Was it Worth $140K USD in Gas?</h3><p>In early March, as we were making improvements to our Ethereum Daily Stats service (available on <a href="https://twitter.com/Amberdataio">@amberdataio Twitter</a>), one contract’s behavior caught our eye: every day, for several weeks, our service reported one Ethereum token contract named “SUM Token” (SUT) as the most active contract in the entire network. After verifying the results, to make sure there wasn’t a problem with the service or source of data, we concluded that this contract was, indeed, the most active contract by transaction count for many weeks in a row, starting in mid-February 2019.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7H1-qmSdOCznKnrT37n9_A.png" /><figcaption>Example Amberdata Ethereum Daily Stats showing SUM Token activity</figcaption></figure><p>Our research yielded that not only was the transaction count and quantity of gas used by this contract extraordinary, at 53,000,000,000 gas (enough to fully consume over 6,600 blocks), the gas price used in these transactions was significantly higher than required, consistently 20 Gwei at a time when 4 Gwei was more than enough. Consuming so much gas at such a high gas price <strong>spent more than 1,000 ether on gas alone</strong>, about $140K USD at time of writing (March 2019).</p><p>On March 10, 2019, daily transitions to this contract fell drastically, from ~30,000+/day to less than 100/day. These behaviors are all inline with an overly eager airdrop that concluded, but some odd token transfer behaviors could not be ignored and indicate that something else was going on.</p><p>It seems likely this is the web site related to the SUM Token: <a href="http://www.sumtoken.biz/">http://www.sumtoken.biz/</a>. It doesn’t make clear what this token is for, but the “monthly profit is 8%-20%” (250%-900% APR 🙄) should instill the correct amount of skepticism. If that doesn’t do it, just watch this 40 second YouTube clip, filled with futuristic stock footage and badly superimposed branding:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FArvIsYhF0E0%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DArvIsYhF0E0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FArvIsYhF0E0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b415f51557098b785613192a7ae5e5f1/href">https://medium.com/media/b415f51557098b785613192a7ae5e5f1/href</a></iframe><p>So what was the underlying purpose of the SUM Token contract? What person or group of people felt that this contract was worth spending this much ether on? While it is difficult to know the underlying motives were here, in this article, I will share the result of our investigation into the SUM Token, its transfer behaviors, and the set of possibilities we concluded were the most likely.</p><h3>The SUM Token Contract</h3><p><a href="https://amberdata.io/addresses/0x0e50e6d6bb434938d8fe670a2d7a14cd128eb50f/management">SUM Token</a> is a fixed-supply ERC20 Token, deployed in October of 2018, with an initial supply of 800M going to the creator. The underlying Solidity code is a trivial modification to this standard ERC20 token: <a href="https://github.com/ethereum/ethereum-org/blob/3bde33b4361c0b7da6a8607701284e79b919cbea/solidity/token-erc20.sol">github.com/ethereum/ethereum-org/solidity/token-erc20.sol</a>. For a token that had $140K spent on executing, I would have expected a more useful contract than a simple “Hello World” balance-tracking token. Perhaps it was promoted as a balance tracking mechanism before migration to a new chain (similar to TRX or ICX)? Or used as part of some centralized system providing the actual functionality?</p><p>There is a slight bug in the contract, with the pragma selection:</p><pre>pragma solidity ^0.4.16;<br>…<br>contract TokenERC20 {<br>…<br> constructor(<br>   uint256 initialSupply,<br>   string tokenName,<br>   string tokenSymbol<br> ) public {</pre><p>This constructor syntax was not valid in 0.4.16, for some reason they downgraded the solidity selection from the version in the source code they copied (which did not have this bug). It is unclear why they decided to change this portion of original contract. They also stripped the code of all comments, perhaps to make tracking its original source more difficult.</p><h3>Initial Supply Disbursement to Airdroppers</h3><p>In the contract’s creation, 800M were granted to the creator (<a href="https://amberdata.io/addresses/0x042cbd9e461f17da44dd26030a4eb116cdf761a1">0x042cbd9e461f17da44dd26030a4eb116cdf761a1</a>), which fully changed hands to <a href="https://amberdata.io/addresses/0x20288b32ecca9259ac1fb0a29289d423305cb4c4">0x20288b32ecca9259ac1fb0a29289d423305cb4c4</a>, and again to <a href="https://amberdata.io/addresses/0x5c119bd3345a42ff6e528c3f622fdafe14de6e09">0x5c119bd3345a42ff6e528c3f622fdafe14de6e09</a>. For our purposes, <a href="https://amberdata.io/addresses/0x5c119bd3345a42ff6e528c3f622fdafe14de6e09">0x5c119bd3345a42ff6e528c3f622fdafe14de6e09</a> is the actual initial holder which begins to spray these 800M tokens to various second-tier addresses, which received a bulk of tokens (in the 1M to 20M range each) for eventual further distribution to seemingly random Ethereum addresses in much smaller chunks.</p><p>In all, only about 10% of the supply was sent to these addresses, with the vast majority, over 600M, still held at a single address, <a href="https://amberdata.io/addresses/0x6eeee9af0788c04971f5f91f0275b6c5b1c49840">0x6eeee9af0788c04971f5f91f0275b6c5b1c49840</a>. From here, we will refer to the collection of addresses which further disperse to many accounts as the “airdroppers”, although it is possible this was not an airdrop at all.</p><p>The charts below tracks the flow of tokens from the initial supply through to these airdroppers, which are at the bottom right of the top chart, and filtering to only these addresses in the bottom chart</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-b9RdeX843AgLXyDh_oikw.png" /><figcaption>Sankey Chart of Initial Supply from 800M Genesis (unit: 1,000 SUM tokens)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G5uUjIXRmhsRm_I-AOOOEg.png" /><figcaption>Sankey Chart filtered to Airdrop accounts (unit: 1,000 SUM tokens)</figcaption></figure><h3>The Airdrop Begins</h3><p>With the above set of addresses loaded up with about 80M SUM tokens total, the airdrop began. While there was a trickle of airdrop transactions in October [2018] and November, the process picked up significantly in early December, with another large increase in transaction count in mid-February 2019. At its peak, an average Ethereum block contained 6 SUM transfers... for weeks! The airdrop sender addresses are noted below, with the number of drops performed by each address:</p><pre>Token Address                              (Tx Count)<a href="https://amberdata.io/addresses/0x38e7f9f19f4c1d03929176e01ad75b6eb3ce22ff"><br>0x38e7f9f19f4c1d03929176e01ad75b6eb3ce22ff</a> (29321)<br><a href="https://amberdata.io/addresses/0x4949a4c4d69d9c992322a01329e60c08af7048ee">0x4949a4c4d69d9c992322a01329e60c08af7048ee</a> (29321)<br><a href="https://amberdata.io/addresses/0x60025d2e4dcf731cb70763582b99ddc3ecc51741">0x60025d2e4dcf731cb70763582b99ddc3ecc51741</a> (29323)<br><a href="https://amberdata.io/addresses/0x8fbcd252a8a6feae3889f8765327c3c12836f772">0x8fbcd252a8a6feae3889f8765327c3c12836f772</a> (29323)<br><a href="https://amberdata.io/addresses/0xfaf1d7751fc4a82309b955f9a94d2fcfe7ae30e4">0xfaf1d7751fc4a82309b955f9a94d2fcfe7ae30e4</a> (29323)<br><a href="https://amberdata.io/addresses/0x07e7e01292143c475458b401a5f105df4704cae6">0x07e7e01292143c475458b401a5f105df4704cae6</a> (29324)<br><a href="https://amberdata.io/addresses/0xc7d5dc177f822ff63f715c2bd72a53aac64792f9">0xc7d5dc177f822ff63f715c2bd72a53aac64792f9</a> (29327)<br><a href="https://amberdata.io/addresses/0x46ad23bb05bb85e7e9f257dd1f4abad0725b23f0">0x46ad23bb05bb85e7e9f257dd1f4abad0725b23f0</a> (29328)<br><a href="https://amberdata.io/addresses/0xc2ff276322ce52cea94fbb671050af03a9eb89dc">0xc2ff276322ce52cea94fbb671050af03a9eb89dc</a> (29328)<br><a href="https://amberdata.io/addresses/0xf770e6c3f6ad1b518699918d50cc5907732ef007">0xf770e6c3f6ad1b518699918d50cc5907732ef007</a> (29518)<br><a href="https://amberdata.io/addresses/0x0cd62a4e72e4d2f489773ffaebf687952fc65bc3">0x0cd62a4e72e4d2f489773ffaebf687952fc65bc3</a> (90250)<br><a href="https://amberdata.io/addresses/0x2cb3046ffaa323b8d0818c9f89c59e71b2cb7cc7">0x2cb3046ffaa323b8d0818c9f89c59e71b2cb7cc7</a> (91979)<br><a href="https://amberdata.io/addresses/0xf501bec63c695ec5a14163e0792d47db5c38f860">0xf501bec63c695ec5a14163e0792d47db5c38f860</a> (92055)<br><a href="https://amberdata.io/addresses/0x118ef37556c0772f4e7bc17c91c8a0b8bd95a08a">0x118ef37556c0772f4e7bc17c91c8a0b8bd95a08a</a> (92232)<br><a href="https://amberdata.io/addresses/0x442f2f96a79a4cf83fab19ae1f9c0edc3320cec0">0x442f2f96a79a4cf83fab19ae1f9c0edc3320cec0</a> (92319)<br><a href="https://amberdata.io/addresses/0x4e69ebb5dd1c75dff083de765d0d8e21e1312529">0x4e69ebb5dd1c75dff083de765d0d8e21e1312529</a> (92445)<br><a href="https://amberdata.io/addresses/0x526c56e1def033896d46cda96ab7b91cdc8ca626">0x526c56e1def033896d46cda96ab7b91cdc8ca626</a> (93346)<br><a href="https://amberdata.io/addresses/0x0b7d3ef887a6907554afff9d49b683de690c6f00">0x0b7d3ef887a6907554afff9d49b683de690c6f00</a> (94410)<br><a href="https://amberdata.io/addresses/0x014d98f02dd38e287c3d6a5bf9356c6502c58a49">0x014d98f02dd38e287c3d6a5bf9356c6502c58a49</a> (95723)<br><a href="https://amberdata.io/addresses/0xa272204a3b65018c3881ece9dc89a27a34d60362">0xa272204a3b65018c3881ece9dc89a27a34d60362</a> (102759)</pre><p>An example transaction from this timeframe:</p><p><a href="https://amberdata.io/transactions/0x233b7a7eccb11d8d9ec37750f0ad79be613e79efcdb2d880e216d6e60009bf8b">amberdata.io/transactions/0x233b7a7eccb11d8d9ec37750f0ad79be613e79efcdb2d880e216d6e60009bf8b</a></p><p>In this transaction, 1.92 SUM were transferred to “<a href="https://amberdata.io/addresses/0x3eb800265f0c806e175a22d1f3eff4dc447492e2">0x3eb800265f0c806e175a22d1f3eff4dc447492e2</a>”. However, this was not the only transaction which transferred this address SUM tokens. Many airdrops of similar (but not identical) amounts were sent to this address over the course of the few months the airdrop took place, on about a daily cadence. In all, 97 separate airdrops went to this SINGLE address, each within the range of 1 to 5 SUM tokens. These tokens did not stay on this address; they eventually were sent in bulk to <a href="https://amberdata.io/addresses/0x512ff69caf4624df6e01e19be1e2d5499739055b">0x512ff69caf4624df6e01e19be1e2d5499739055b</a>. This pattern of receiving many times while funneling tokens back to this address is present in the majority of SUM airdrops that took place. In the 1.3M SUM airdrop transactions, only 67K addresses have ever received any SUM Token at all. The vast majority of those tokens, after being sent to one of these 67K addresses, found their way back to this central address, <a href="https://amberdata.io/addresses/0x512ff69caf4624df6e01e19be1e2d5499739055b">0x512ff69caf4624df6e01e19be1e2d5499739055b</a>.</p><p>This is not normal token behavior for an airdrop. Normally you would send the entire amount destined for an address in a single transaction to save gas costs and time, with the tokens often sitting idle for a long time or sent to an Exchange to be sold if a market exists. The collection of these tokens into a single address is highly unusual and can only be explained through either central control of all of these addresses OR some off-chain mechanism/application which uses these balances for some other purpose.</p><p>The chart below illustrates the token flows from these airdrop address, through a population of addresses, with the final destination of <a href="https://amberdata.io/addresses/0x512ff69caf4624df6e01e19be1e2d5499739055b">0x512ff69caf4624df6e01e19be1e2d5499739055b</a>. Nodes are colored by number of outbound transfers, red highlighting addresses which sent more, blue highlighting addresses which received more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DCrVt9WAajts3EFzjdQBww.png" /></figure><h3>Transaction Timing</h3><p>There is a strange daily cadence to the airdrop, with most airdrops occurring consistently on a roughly 24-hour global cycle. During a 24-hour period, most transactions occurred during 12 hours before dropping drastically for 12 hours, then starting over again. The chart below shows the the amount of ether spent on gas for the SUM Token contract. Each bar is one hour:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3iHE7KmeKak7HcdpCEGTVA.png" /><figcaption>How the 1,000+ Ether was spent over time</figcaption></figure><p>It is not clear what this cadence represents. Perhaps this token is localized to another region and this was when the airdrop admin or token users were awake? Transactions generally seem to ramp up around 09:00 UTC and 12:00 UTC</p><h3>Conclusion</h3><p>The behavior of SUM Token is strange for a number of reasons:</p><ol><li>The gas price used for these transactions was excessively large (20 Gwei), when half that price or less would have had a similar mining rate</li><li>The number of transactions at this gas price ended up consuming more than 1,000 Ether in gas, for a USD cost of $140K in March 2019</li><li>The total amount of airdropped tokens, relative to the overall supply is incredibly small. Less than 10% of total supply was eligible to be airdropped, and even less than that was actually sent along to various Ethereum addresses</li><li>The airdrops went to a small number of unique addresses, with the average account receiving ~20 different airdrop transfers and the most active receiving ~1,000</li><li>Accounts that received these multiple airdrops eventually ended up sending almost all of their tokens BACK to <a href="http://0x512ff69caf4624df6e01e19be1e2d5499739055b">a single address which currently holds 3.2M SUM Tokens</a> (being the recipient of 62K transactions)</li><li>The token itself serves no on-chain purpose. A look at the token verified source shows it to be a standard ERC20 token with no additional functionality one might expect from a token released in late 2018 worth $140K to distribute</li></ol><p>It is difficult to state what the underlying motives were here, but a few possibilities:</p><ol><li>This was an attempt to appear like an airdrop, but actually allow the token creators to keep control of even the small portion allocated to the airdrop (by transferring back to a single address)</li><li>This was not an airdrop at all, but an attempt to inflate a vanity metric, such as unique holders or tokens transferred to make SUM Token appear to be a more widely used token than it actually was.</li><li>This was part of a centrally controlled system, where users received tokens on some schedule based on some centrally controlled mechanism. Transferring these tokens back to <a href="https://amberdata.io/addresses/0x512ff69caf4624df6e01e19be1e2d5499739055b">0x512ff69caf4624df6e01e19be1e2d5499739055b</a> caused some other centralized actions to take place or credit internal to this system. Given the aforementioned “8%–20% returns” perhaps some sort of a Ponzi or Pyramid scheme?</li></ol><p>While it’s difficult to know which of these options SUM Token was operating under, #3 is somehow the least bad of them all. If this were a fake airdrop or vanity metric, there would be far, far cheaper and more effective ways to accomplish those goals. Although it isn’t terribly reassuring that the best option, by far, is a centrally controlled Ponzi-like scheme.</p><p><a href="https://amberdata.io/">AmberData</a> has been busy collecting, processing, and creating an API to help understand this blockchain information. Check out <a href="https://docs.amberdata.io/">our API docs</a> to see the data sources used to generate these charts, add our <a href="https://amberdatapartners.slack.com/apps/AGBEYKZ6X-crypto">@Crypto Slack Bot</a> for real-time market-data integrated into your own Slack, and <a href="https://twitter.com/Amberdataio">follow us on Twitter</a> for more Ethereum research and new feature announcements we are excited to release in the near future!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f027190eaae8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>