<?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 Fang Gong on Medium]]></title>
        <description><![CDATA[Stories by Fang Gong on Medium]]></description>
        <link>https://medium.com/@gongfang2008?source=rss-f1e17af9a3ea------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BAtKRDEkcCaCgjNKJdMirQ.png</url>
            <title>Stories by Fang Gong on Medium</title>
            <link>https://medium.com/@gongfang2008?source=rss-f1e17af9a3ea------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 19:43:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gongfang2008/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[The Developer’s Guide to Uniswap]]></title>
            <link>https://blog.oceanprotocol.com/the-developers-guide-to-uniswap-48fcf6e9ee1e?source=rss-f1e17af9a3ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/48fcf6e9ee1e</guid>
            <category><![CDATA[homepage]]></category>
            <category><![CDATA[product]]></category>
            <category><![CDATA[uniswap]]></category>
            <category><![CDATA[deeptech]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Fang Gong]]></dc:creator>
            <pubDate>Wed, 01 May 2019 01:03:54 GMT</pubDate>
            <atom:updated>2019-06-03T12:20:14.458Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://uniswap.io/">Uniswap</a> implements a decentralized token exchange for cryptocurrencies in the Ethereum network, which provides a simple interface for token holders to swap one kind of ERC20 token to the other with low gas cost.</p><p>There are strong demands from blockchain developers to add their ERC20 tokens to the Uniswap in order to boost the token liquidity. In this article, we present a step-by-step guide to adding an ERC20 token into Uniswap. All code can be found in Ocean’s research repo of Uniswap: <a href="https://github.com/oceanprotocol/Nautilus/tree/master/3-uniswap">https://github.com/oceanprotocol/Nautilus/tree/master/3-uniswap</a></p><h3>1. Architecture Overview</h3><p>First of all, we need to understand the architecture of Uniswap, which includes two components:</p><ul><li><a href="https://github.com/Uniswap/contracts-vyper/blob/master/contracts/uniswap_factory.vy"><strong>Factory Contract</strong></a>: it is the manager of exchange contracts, which creates new exchange contracts and maintains a mapping from token contract address to its exchange contract address;</li><li><a href="https://github.com/Uniswap/contracts-vyper/blob/master/contracts/uniswap_exchange.vy"><strong>Exchange Contract</strong></a>: each token contract has its own exchange contract, which executes the transaction to swap tokens;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*RIVNjpKtmK1RsqEEYgMF_Q.jpeg" /><figcaption>Architecture Overview of Uniswap</figcaption></figure><p>A typical developer’s workflow using Uniswap is:</p><ol><li>Deploy ERC20 token contract to Ethereum network;</li><li>Create an exchange contract through factory contract for ERC20 token;</li><li>Swap ERC20 token with other tokens using the exchange contract;</li></ol><p>Each token exchange contract can only swap ERC20 token with ETH by itself. To swap between different ERC20 tokens, Uniswap uses ETH as the “ bridge” or intermediary token (i.e., sell token A into ETH and buy token B using ETH).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*fNonY1nKwXHa9c5UKJ_RIw.jpeg" /><figcaption>Token Swap with Uniswap</figcaption></figure><p>It is worth mentioning that <strong>Uniswap is limited to Ethereum network and token swap in the “same” Ethereum network</strong>.</p><p>For the demonstration purpose, this guide uses Rinkeby testnet to show the workflow, but the same procedure can be applied to Ethereum mainnet. We use <em>Truffle v5.0.3</em>, <em>Node.js v8.11.1</em> and <em>Web3.js-1.0</em> for the experiment.</p><h3>2. Create and Deploy Token Contract</h3><p>First, create a simple <a href="https://github.com/oceanprotocol/Nautilus/blob/master/3-uniswap/contracts/OceanToken.sol">ERC20 token contract</a> for our internal testing at Ocean:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*fnNqj7BsDGxe2JwHItBZeg.jpeg" /><figcaption>Simple ERC20 token contract</figcaption></figure><p>Compile with Truffle as:</p><pre>$ npm install<br>$ truffle compile</pre><p>Setup the Rinkeby network settings in truffle-config.js as:</p><pre>rinkeby: {<br>     provider: function() {<br>     return new HDWalletProvider(process.env.NMEMORIC, &quot;https://rinkeby.infura.io/&quot;)<br>     },<br>     network_id: &#39;4&#39;,<br>     websockets: true,<br>     gas: 6000000,<br>     gasPrice: 10000000000<br> },</pre><p>Deploy contract to Rinkeby 0xCC4d8eCFa6a5c1a84853EC5c0c08Cc54Cb177a6A:</p><pre>$ truffle deploy --network rinkeby <br>...<br>2_token.js<br>=================</pre><pre>   Replacing &#39;Token&#39;<br>   ----------------------<br>   &gt; transaction hash:    0xd17a0dc69f54f78aa9a158682dc5bd24c281de959e3a7545ecb7d3c60cdadeab<br>   &gt; Blocks: 0            Seconds: 12<br>   &gt; contract address:    0xCC4d8eCFa6a5c1a84853EC5c0c08Cc54Cb177a6A<br>   &gt; account:             0x0E364EB0Ad6EB5a4fC30FC3D2C2aE8EBe75F245c<br>   &gt; balance:             2.57090605<br>   &gt; gas used:            1214459<br>   &gt; gas price:           10 gwei<br>   &gt; value sent:          0 ETH<br>   &gt; total cost:          0.01214459 ETH</pre><pre>   &gt; Saving artifacts<br>   -------------------------------------<br>   &gt; Total cost:          0.01214459 ETH</pre><h3>3. Create Token Exchange Contract in Uniswap</h3><p>Uniswap Factory contract has been deployed by Uniswap on Rinkeby at 0xf5d915570bc477f9b8d6c0e980aa81757a3aac36. Its ABI and code can be found in the “Code” section of <a href="https://rinkeby.etherscan.io/address/0xf5d915570bc477f9b8d6c0e980aa81757a3aac36">Etherscan page</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rv6CLRNIImD-cQFFXrwHYA.jpeg" /><figcaption>Uniswap factory contract in Rinkeby from Etherscan</figcaption></figure><p>To create a new exchange contract for the ERC20 token, we need to send a signed transaction createExchange to the deployed Uniswap Factory contract in the Rinkeby network. A developer can choose to either run a local Ethereum client (e.g., <a href="https://github.com/ethereum/go-ethereum">Geth</a> or <a href="https://www.parity.io/ethereum/">Parity</a>) or send through <a href="https://infura.io/">Infura</a> in order to sign the transaction with the private key. For simplicity, we use Infura to send signed raw transactions.</p><p>Here is the Javascript file script/1.create.exchange.js used to create an exchange contract. [<a href="https://github.com/oceanprotocol/Nautilus/blob/master/3-uniswap/script/1.create.exchange.js">Source file</a>]. Note the parameter that passed into the createExchange function is ERC20 token contract address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*JtiB36Dl1zxo7ccaTRzKVQ.jpeg" /><figcaption>Javascript file to create an exchange contract in Uniswap</figcaption></figure><p>Run the Javascript file with Node.js as</p><pre>$ node 1.create.exchange.js</pre><p>The output should look like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FBy8WwmtmCcKFTJi8kD_SQ.jpeg" /></figure><p><em>Note:</em> if an error happens Error: Node error:{&quot;code&quot;:-32601, &quot;message&quot;: &quot;The method eth_sendTransaction does not exist/is not available&quot;}, it means that the underlying JSON-RPC method is not supported by Infura.</p><p>Infura blocks methods that do not make sense for Infura, such as those that require Infura to store private keys. For example, “web3.eth.sendTransaction” invokes the eth_sendTransaction method, which requires the server to hold keys. More details can be found in<a href="https://gist.github.com/raineorshine/c8b30db96d7532e15f85fcfe72ac719c"> raineorshine’s github.</a></p><p>At this moment, the exchange contract for our ERC20 token has been created inside Uniswap. We can use script/2.get.exchange.address.js to query its address [<a href="https://github.com/oceanprotocol/Nautilus/blob/master/3-uniswap/script/2.get.exchange.address.js">Source file</a>]:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*oie5KUMlrIiIpyoJ3qD0vg.jpeg" /></figure><pre>$ node script/2.get.exchange.address.js<br>the exchange address for ERC20 token is: 0x416F1Ac032D1eEE743b18296aB958743B1E61E81</pre><p>It verifies that we have successfully created an exchange contract for our ERC20 token contract in Uniswap! :)</p><h3>4. Add Liquidity to Exchange Contract</h3><p>Now we are ready to interact with the exchange contract. Here are important contract addresses that will be used:</p><ul><li>Token contract address: 0xCC4d8eCFa6a5c1a84853EC5c0c08Cc54Cb177a6A</li><li>Exchange contract address: 0x416F1Ac032D1eEE743b18296aB958743B1E61E81</li></ul><p>The exchange contract requires some initial token deposits in order to provide certain liquidity as an exchange. To this end, we need to first approve the exchange contract to withdraw ERC20 tokens from our wallet and then invoke addLiquidity function in the exchange contract to deposit both ERC20 tokens and ETH as following:</p><pre>1. token.approve(exchange_address, TOKEN_RESERVE)<br>2. exchange.addLiquidity(0, TOKEN_RESERVE, DEADLINE, transact={&#39;value&#39;: ETH_RESERVE})</pre><p>First, we use $node cript/3.approve.exchange.js to approve the Exchange contract to withdraw ERC20 tokens from our wallet. [<a href="https://github.com/oceanprotocol/Nautilus/blob/master/3-uniswap/script/3.approve.exchange.js">Source file</a>]:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*PQbRJEs3qeh0irBTiFkB4g.jpeg" /><figcaption>Javascript to approve exchange to withdraw ERC20 tokens</figcaption></figure><p>Then, we add liquidity to the exchange contract by depositing 15 ERC20 tokens and 0.1 ETH using $node script/4.add.liquidity.js [<a href="https://github.com/oceanprotocol/Nautilus/blob/master/3-uniswap/script/4.add.liquidity.js">Source file</a>].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*TYkN3nagjlwUxzO8jR8EvQ.jpeg" /><figcaption>Javascript to add liquidity to exchange contract</figcaption></figure><p>We can check the contract balance in Etherscan to verify the deposits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uCwyRJZLmkOYzTcrU3Ii7Q.jpeg" /></figure><h3>5. Swap Tokens in Uniswap</h3><p>We are ready to swap tokens using Uniswap right now.</p><p>In our first testing, ETH is sent to the exchange contract, which will be automatically converted into ERC20 tokens. The Javascript source file is <a href="https://github.com/oceanprotocol/Nautilus/blob/master/3-uniswap/script/5.eth2erc20.swap.js">here</a>.</p><pre>$node script/5.eth2erc20.swap.js</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*WAJSygeH4QWwKSkYAAKPHw.jpeg" /><figcaption>ETH to ERC20 swap</figcaption></figure><p>Etherscan shows 0.05 ETH has been deposited into the exchange contract and converted into 5 ERC20 tokens, which are transferred to the buyer’s wallet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LDKIXIBEhYPZT6EbTHFmBw.jpeg" /><figcaption>Swap from ETH to ERC20</figcaption></figure><p>In the second testing, we can swap between two ERC20 tokens. Here, we use our deployed ERC20 token and LINK token as an example [<a href="https://github.com/oceanprotocol/Nautilus/blob/master/3-uniswap/script/6.convert.token2token.js">Source file</a>]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*s7YOAZK5svUdclNhTsuMCw.jpeg" /><figcaption>swap token A to token B</figcaption></figure><p>Uniswap withdraws 0.0015 our ERC20 token and deposits 10 LINK tokens in the wallet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2i-Q87nR-MSYdj9YJ6RBqg.jpeg" /><figcaption>Token swap between our deployed ERC20 token and LINK token</figcaption></figure><h3>Conclusion</h3><p>In this article, we present a step-by-step guide to blockchain developers elaborating on the procedure to add ERC20 token into Uniswap Exchange. It results from our internal research at Ocean Protocol. Hope our experience and findings can help blockchain developers in other projects.</p><p>Thanks for reading this article!</p><p>This article is an on-going work and many pieces can be further improved. Feel free to send me comments: fang@oceanprotocol.com.</p><p>If you would like to know more, please follow <a href="https://twitter.com/gongf05?lang=en"><em>Fang Gong</em></a><em>.</em></p><p>Ready to dive in? — Check out the <a href="https://docs.oceanprotocol.com/">Ocean Documentation</a> to get a sense of what we’ve been working on, and fire all your technical questions in <a href="https://gitter.im/oceanprotocol/Lobby">our Gitter chatroom</a>.</p><p>Follow <strong>Ocean Protocol</strong> on <a href="https://twitter.com/oceanprotocol">Twitter,</a> <a href="https://t.me/oceanprotocol_community">Telegram</a>, <a href="https://www.linkedin.com/company/ocean-protocol/">LinkedIn</a>, <a href="https://www.reddit.com/r/oceanprotocol/">Reddit</a>, <a href="https://github.com/oceanprotocol">GitHub</a> &amp; <a href="https://oceanprotocol.com/newsletter/">Newsletter</a> for project updates and announcements.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48fcf6e9ee1e" width="1" height="1" alt=""><hr><p><a href="https://blog.oceanprotocol.com/the-developers-guide-to-uniswap-48fcf6e9ee1e">The Developer’s Guide to Uniswap</a> was originally published in <a href="https://blog.oceanprotocol.com/">Ocean Protocol</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Uniswap and Chainlink into Ocean Protocol]]></title>
            <link>https://blog.oceanprotocol.com/integrating-uniswap-and-chainlink-into-ocean-protocol-8e07d654e188?source=rss-f1e17af9a3ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e07d654e188</guid>
            <category><![CDATA[uniswap]]></category>
            <category><![CDATA[homepage]]></category>
            <category><![CDATA[product]]></category>
            <category><![CDATA[deeptech]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Fang Gong]]></dc:creator>
            <pubDate>Tue, 30 Apr 2019 01:05:47 GMT</pubDate>
            <atom:updated>2019-06-03T12:19:22.142Z</atom:updated>
            <content:encoded><![CDATA[<p>Ocean Protocol needs to integrate with <a href="https://uniswap.io/">Uniswap</a> [1] for better liquidity of Ocean tokens and interact with <a href="https://chain.link/">Chainlink</a> [2] network to retrieve off-chain data fed from the real world.</p><p>Our previous research on Uniswap and Chainlink has been presented in the following articles:</p><ul><li><a href="https://medium.com/@gongfang2008/the-developers-guide-to-uniswap-346612c9c1b0">Developer’s Guide to Uniswap</a></li><li><a href="https://medium.com/p/afcf19cfbb73/">Bridging Blockchain to the Real-World using Chainlink</a></li></ul><p>In this article, we illustrate the approach to integrate Uniswap and Chainlink into Ocean Protocol and make them work together. This is a collaborative effort between Ocean Protocol and Chainlink teams.</p><p>For illustration purposes, we build an example case on the Rinkeby network to imports off-chain random numbers into the on-chain smart contract. All the code can be found in Ocean’s research <a href="https://github.com/oceanprotocol/Nautilus/tree/master/5-random-numbers">repository</a> [3] with two folders:</p><ul><li><a href="https://github.com/oceanprotocol/Nautilus/tree/master/5-random-numbers/uniswap-token"><strong>Uniswap-token</strong></a>: the code for Uniswap related functions;</li><li><a href="https://github.com/oceanprotocol/Nautilus/tree/master/5-random-numbers/chainlink"><strong>Chainlink</strong></a>: the code for interacting with Chainlink network.</li></ul><p>Note: <em>Truffle v5.0.3, Node.js v8.11.1, </em>and <em>Web3.js-1.0</em> are used in the demo.</p><h3>1. Architecture Overview</h3><p>The diagram below shows the overall design of the architecture, which includes several components:</p><ul><li><strong>Token contract</strong>: both Ocean token contract and LINK token contract (“LINK” token is the ERC20 token issued by Chainlink) must be deployed to the blockchain network.</li><li><strong>Token exchange contract</strong>: Uniswap creates a new exchange contract for each token contract, which swaps between different ERC20 tokens.</li><li><strong>Ocean requester contract</strong>: the contract creates a request that will be submitted to the Chainlink network and pay LINK tokens.</li><li><strong>Chainlink oracle contract</strong>: the oracle smart contract deployed by Chainlink, which accepts LINK token payment, processes the received requests and dispatches jobs to Chainlink nodes.</li><li><strong>Chainlink nodes</strong>: the off-chain network of Chainlink nodes that retrieves data from the real world and provides it to the smart contract.</li><li><strong>Off-chain data sources</strong>: the original data sources that generate or provide the data. It can be Web, database, cloud, etc.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*NmU65wlRoERyKePZAiFBOA.jpeg" /><figcaption>Architecture Overview</figcaption></figure><h3>2. Integrate Uniswap with Ocean token</h3><p>Ocean Protocol uses its own Ocean tokens to pay for external services such as <a href="https://chain.link/">Chainlink</a>, <a href="https://truebit.io/">Truebit</a>, <a href="https://fitchain.io/">Fitchain</a>, etc. However, each of these services demands the use of its own ERC20 token as payment. In particular, Chainlink network only accepts “LINK” tokens to pay for its oracle service.</p><p>To resolve this issue, Ocean Protocol needs to swap Ocean tokens to LINK tokens which are used to pay for the Chainlink service. Since both are ERC20 tokens in Ethereum, Uniswap is a great solution to this challenge.</p><ul><li><strong>Deploy Ocean Token Contract to Rinkeby Network</strong></li></ul><p>For the demonstration purpose, we deploy an <a href="https://github.com/oceanprotocol/Nautilus/blob/master/5-random-numbers/uniswap-token/contracts/OceanToken.sol">ERC20 token contract</a> as:</p><pre>$ truffle migrate --network rinkeby<br>...<br>10_ocean_token.js<br>=================<br><br>   Replacing &#39;OceanToken&#39;<br>   ----------------------<br>   &gt; transaction hash:    0x07beaeb6979a8beda0544af0dd499ea260a8f72b411a9f9d12ec40dda5c8225c<br>   &gt; Blocks: 1            Seconds: 24<br>   &gt; contract address:    0x56F598cF576d923d7723781cB90BfBF41d81089f<br>   &gt; account:             0x0E364EB0Ad6EB5a4fC30FC3D2C2aE8EBe75F245c<br>   &gt; balance:             2.20082358<br>   &gt; gas used:            1214459<br>   &gt; gas price:           10 gwei<br>   &gt; value sent:          0 ETH<br>   &gt; total cost:          0.01214459 ETH<br><br>   &gt; Saving artifacts<br>   -------------------------------------<br>   &gt; Total cost:          0.01214459 ETH</pre><p>The LINK token contract has been deployed by Chainlink team to Rinkeby at:</p><pre>0x01BE23585060835E02B77ef475b0Cc51aA1e0709</pre><ul><li><strong>Create Exchange Contract for Ocean Token</strong></li></ul><p>Similar to the procedure in <a href="https://medium.com/@gongfang2008/the-developers-guide-to-uniswap-346612c9c1b0">the Developer’s Guide to Uniswap</a>, a new exchange contract for Ocean token needs to be deployed. We developed several Javascript files for this purpose, which can be found in the “<a href="https://github.com/oceanprotocol/Nautilus/tree/master/5-random-numbers/uniswap-token/script">script” folder</a> under the uniswap-token directory:</p><pre>// Step 1: create an exchange contract for deployed token contract:<br><strong>$ node uniswap-token/script/1.create.ocean.exchange.js</strong></pre><pre>// Step 2: get exchange contract address for Ocean token:<br><strong>$ node uniswap-token/script/2.get.ocean.exchange.address.js<br></strong>the exchange address is:0xaFD52EF3Cb0eE6673cA5EbE0A25686313fF0C283</pre><pre>// Step 3: get exchange contract address for LINK token<br><strong>$ node uniswap-token/</strong><strong>script/3.get.link.exchange.address.js</strong><br>the exchange address is:0x094AeF967D361E2aE3Af472718e231DC9134724F</pre><pre>// Step 4: approve exchange contract to withdraw Ocean tokens as initial deposit to provide liquidity<br><strong>$ node uniswap-token/script/4.approve.ocean.deposit.js</strong></pre><pre>// Step 5: add both ETH and Ocean tokens into the exchange contract:<br><strong>$ node uniswap-token/script/5.add.ocean.exchange.liqudity.js</strong></pre><p>As an example, we deposit 0.1 ETH and 15 Ocean tokens into the exchange contract for Ocean token. It can be verified in Etherscan:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q6vA3x3FEQqjBpG4t6czGQ.jpeg" /><figcaption>Initial deposit of tokens into the exchange contract for Ocean token</figcaption></figure><ul><li><strong>Exchange Ocean Tokens for LINK tokens</strong></li></ul><p>The exchange contract is functional at this moment, so we can swap Ocean tokens to LINK tokens with it. To do so, we need to call the function tokenToTokenTransferOutput in the Uniswap exchange contract, which converts input tokens into the output tokens and transfers to receiver address.</p><pre><strong>$ node uniswap-token/script/6.convert.ocean2link.js</strong></pre><p>From the transaction info in Etherscan, it is clear that Uniswap exchange contract withdraws 0.0015 Ocean tokens from the sender’s wallet and transfers 10 LINK tokens into it at the same time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2i-Q87nR-MSYdj9YJ6RBqg.jpeg" /><figcaption>Swap 0.0015 Ocean tokens into 10 LINK tokens using Uniswap exchange contract</figcaption></figure><p>We can see these 10 LINK tokens in our MetaMask wallet. Note that it is required to add a LINK token address into the wallet and switch to Rinkeby network:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/1*bq8upOM9I_dcFKmW_HFywg.jpeg" /><figcaption>LINK token balance in the MetaMask wallet</figcaption></figure><h3>3. Integrate Chainlink with Ocean Contract</h3><p>Next, we can connect the Ocean contract with Chainlink to submit a request to get a random number from off-chain sources (i.e. <a href="https://www.random.org/">random.org</a>). To further simplify the work, we can leverage the existing adapter from Chainlink at <a href="https://docs.chain.link/docs/randomorg-chainlink-testnet">Random.org-Chainlink-testnet</a>.</p><p>The detailed steps are illustrated in the below:</p><ul><li><strong>Create Ocean Requester Contract</strong></li></ul><p>The requester contract in Ocean is created as below. The complete source file can be found in <a href="https://github.com/oceanprotocol/Nautilus/tree/master/5-random-numbers/chainlink">Ocean’s research repo</a>.</p><pre>contract OceanRequester is Chainlinked, Ownable {<br>  /*<br>   * global variables<br>   */<br>  bytes32 constant JOB_ID =    bytes32(&quot;75e0a756bbcc48678c498802a7c5929b&quot;);<br>  uint256 constant private ORACLE_PAYMENT = 1 * LINK;<br>  uint256 public data;</pre><pre>  ...</pre><pre>  /*<br>   * constructor function<br>   */<br>  constructor() public {<br>    // Set the address for the LINK token for the Rinkeby network.<br>    setLinkToken(0x01BE23585060835E02B77ef475b0Cc51aA1e0709);<br>    // Set the address of the oracle in Rinkeby network<br>    setOracle(0x7AFe1118Ea78C1eae84ca8feE5C65Bc76CcF879e);<br>  }</pre><pre>/*<br>   * Create a request and send it to default Oracle contract<br>   */<br>  function getRandom(<br>    uint256 _min,<br>    uint256 _max<br>  )<br>    public<br>    onlyOwner<br>    returns (bytes32 requestId)<br>  {<br>    // create request instance<br>    Chainlink.Request memory req = newRequest(JOB_ID, this, this.fulfill.selector);<br>    // fill in the pass-in parameters<br>    req.addUint(&quot;min&quot;, _min);<br>    req.addUint(&quot;max&quot;, _max);<br>    // send request &amp; payment to Chainlink oracle (Requester Contract sends the payment)<br>    requestId = chainlinkRequest(req, ORACLE_PAYMENT);<br>    // emit event message<br>    emit requestCreated(msg.sender, JOB_ID, requestId);<br>  }</pre><pre>/*<br>   * callback function to keep the returned value from Oracle contract<br>   */<br>  function fulfill(bytes32 _requestId, uint256 _data)<br>    public<br>    recordChainlinkFulfillment(_requestId)<br>  {<br>    data = _data;<br>    emit requestFulfilled(_requestId, _data);<br>  }</pre><p>Note that JobID “75e0a756bbcc48678c498802a7c5929b” specifies the Chainlink service on the Rinkeby network that retrieves a random number from random.org website.</p><ul><li><strong>Deploy Requester Contract</strong></li></ul><p>This requester contract needs to be deployed into the Rinkeby network as:</p><pre>$ truffle migrate --network rinkeby<br>...<br>2_oceanrequester_migration.js<br>=============================<br><br>   Replacing &#39;OceanRequester&#39;<br>   --------------------------<br>   &gt; transaction hash:    0x060c7208a85c7d4786577de3703ffad223a9675d562ab6126beda51ccc3fe1ed<br>   &gt; Blocks: 0            Seconds: 8<br>   &gt; contract address:    <strong>0x81C8A4BE1bf2491D3c90BdE4615EE4672F13E63b</strong><br>   &gt; account:             0x0E364EB0Ad6EB5a4fC30FC3D2C2aE8EBe75F245c<br>   &gt; balance:             1.89272674<br>   &gt; gas used:            1289807<br>   &gt; gas price:           10 gwei<br>   &gt; value sent:          0 ETH<br>   &gt; total cost:          0.01289807 ETH<br><br>   &gt; Saving artifacts<br>   -------------------------------------<br>   &gt; Total cost:          0.01289807 ETH</pre><ul><li><strong>Request Random Number from Chainlink</strong></li></ul><p>The deployed requester contract can create and submit a request to the Chainlink network, but it needs LINK token to pay for the request. We can use the LINK tokens from a token swap performed via Uniswap.</p><p>This <a href="https://github.com/oceanprotocol/Nautilus/blob/master/5-random-numbers/chainlink/test/OceanRequester.Test.js">script</a> is used to send LINK token and submit a request:</p><pre>contract(&quot;OceanRequester&quot;, (accounts) =&gt; {<br>  const LinkToken = artifacts.require(&quot;LinkToken.sol&quot;);<br>  const OceanRequester = artifacts.require(&quot;OceanRequester.sol&quot;);<br>  const defaultAccount =0x0e364eb0ad6eb5a4fc30fc3d2c2ae8ebe75f245c;<br>  const LINK_FEE = web3.utils.toHex(1*10**18)<br>  const LB = web3.utils.toHex(100)  // lower bound of random numebr<br>  const UB = web3.utils.toHex(1000) // upper bound of random number<br>  let link, ocean;<br><br>  beforeEach(async () =&gt; {<br>    link = await LinkToken.at(&quot;0x01BE23585060835E02B77ef475b0Cc51aA1e0709&quot;);<br>    ocean = await OceanRequester.at(&quot;0x81C8A4BE1bf2491D3c90BdE4615EE4672F13E63b&quot;);<br>  });<br><br>  describe(&quot;should request data and receive callback&quot;, () =&gt; {<br>    let request;<br><br>    it(&quot;transfer 1 LINK token to Ocean requester contract if there is no any&quot;, async () =&gt; {<br>      let balance = await link.balanceOf(ocean.address)<br>      if (balance == 0) {<br>        await link.transfer(ocean.address, LINK_FEE)<br>      }<br>    });<br><br>    it(&quot;create a request and send to Chainlink&quot;, async () =&gt; {<br>      <strong>let tx = await ocean.getRandom(LB, UB);</strong><br>      request = h.decodeRunRequest(tx.receipt.rawLogs[3]);<br>      console.log(&quot;request has been sent. request id :=&quot; + request.id)<br><br>      let data = 0<br>      let timer = 0<br>      while(data == 0){<br>        data = await ocean.getRequestResult()<br>        if(data != 0) {<br>          console.log(&quot;Request is fulfilled. data := &quot; + data)<br>        }<br>        wait(1000)<br>        timer = timer + 1<br>        console.log(&quot;waiting for &quot; + timer + &quot; second&quot;)<br>      }<br><br>    });<br>  });<br>});</pre><p>Run this <a href="https://github.com/oceanprotocol/Nautilus/blob/master/5-random-numbers/chainlink/test/OceanRequester.Test.js">script</a> and generate console output as follows:</p><p>$ truffle test chainlink/test/OceanRequester.Test.js --network rinkeby</p><p>The Chainlink network fulfills the request and returns a random number 983 from random.org. It proves the entire workflow is working properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7I79XIqdbptnNaltO6l16A.jpeg" /></figure><h3><strong>4. Conclusion</strong></h3><p>In this article, we demonstrate a typical workflow for blockchain developers to exchange one ERC20 token for a target ERC20 token as a service payment and interact with that service’s network (i.e. Chainlink) to access the off-chain data feed. The same pattern can be applied to many other blockchain services.</p><p>This piece of research work results from the collaboration between Ocean Protocol and Chainlink. Special Thanks to Daniel Kochis and Thomas Hodges from Chainlink for their great advice and support to us!</p><p>We would like to share our research with the community and hope this work helps more developers and projects. Thank you for reading this article!</p><h3>5. Reference</h3><p>[1] Uniswap: <a href="https://uniswap.io/">https://uniswap.io/</a></p><p>[2] Chainlink: <a href="https://chain.link/">https://chain.link/</a></p><p>[3] Ocean’s Research Repository: <a href="https://github.com/oceanprotocol/Nautilus/blob/master/5-random-numbers/chainlink/test/OceanRequester.Test.js">https://github.com/oceanprotocol/Nautilus/blob/master/5-random-numbers/</a></p><p>This article is an on-going work and many pieces can be further improved. Feel free to send me comments: fang@oceanprotocol.com.</p><p>If you would like to know more, please follow <a href="https://twitter.com/gongf05?lang=en"><em>Fang Gong</em></a><em>.</em></p><p>Ready to dive in? — Check out the <a href="https://docs.oceanprotocol.com/">Ocean Documentation</a> to get a sense of what we’ve been working on, and fire all your technical questions in <a href="https://gitter.im/oceanprotocol/Lobby">our Gitter chatroom</a>.</p><p>Follow <strong>Ocean Protocol</strong> on <a href="https://twitter.com/oceanprotocol">Twitter,</a> <a href="https://t.me/oceanprotocol_community">Telegram</a>, <a href="https://www.linkedin.com/company/ocean-protocol/">LinkedIn</a>, <a href="https://www.reddit.com/r/oceanprotocol/">Reddit</a>, <a href="https://github.com/oceanprotocol">GitHub</a> &amp; <a href="https://oceanprotocol.com/newsletter/">Newsletter</a> for project updates and announcements.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e07d654e188" width="1" height="1" alt=""><hr><p><a href="https://blog.oceanprotocol.com/integrating-uniswap-and-chainlink-into-ocean-protocol-8e07d654e188">Integrating Uniswap and Chainlink into Ocean Protocol</a> was originally published in <a href="https://blog.oceanprotocol.com/">Ocean Protocol</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bridging Blockchain to the Real World using Chainlink]]></title>
            <link>https://blog.oceanprotocol.com/bridging-blockchain-to-the-real-world-using-chainlink-afcf19cfbb73?source=rss-f1e17af9a3ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/afcf19cfbb73</guid>
            <category><![CDATA[homepage]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[product]]></category>
            <category><![CDATA[deeptech]]></category>
            <dc:creator><![CDATA[Fang Gong]]></dc:creator>
            <pubDate>Mon, 29 Apr 2019 07:49:15 GMT</pubDate>
            <atom:updated>2019-06-03T12:18:56.182Z</atom:updated>
            <content:encoded><![CDATA[<p>The smart contract is locked up inside the blockchain space and isolated from the external world. However, the operation of a smart contract depends on the information in the real world for many applications.</p><p>Take Ocean Protocol as an example: the token rewards shall be paid out to data providers only if their data is proved to be available for consumption. Therefore, an Oracle network bridging blockchain to the real world is urgently sought.</p><p><a href="https://chain.link/">Chainlink</a> [1] is a decentralized oracle network that enables smart contracts in blockchain networks to securely access real-world data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*BVkwWuuzsSwTwLrdNbL_tg.jpeg" /><figcaption>Chainlink is the bridge between blockchain and real world</figcaption></figure><p>In this research, we investigate the Chainlink network and show how it works with built-in &amp; external adapters. The target audience is <em>blockchain developers</em> with comprehensive knowledge of blockchain and smart contracts.</p><p>We built a proof-of-concept (POC) in Kovan for demonstration purposes and all the code can be found in Ocean’s research <a href="https://github.com/oceanprotocol/Nautilus/tree/master/4-chainlink">repository</a> [2]. We used <em>Truffle v5.0.3</em> and <em>Node.js v8.11.1</em> in the POC.</p><h3>1. Architecture Overview</h3><p>Below is the diagram showing the components of the Chainlink network:</p><ul><li><strong>Chainlink Oracle Contract</strong>: the Oracle smart contract is deployed to the blockchain network by the node operator, which accepts LINK token payment through requests from contracts and dispatches events to Chainlink nodes;</li><li><strong>Chainlink Node</strong>: the off-chain middleware operates between the blockchain and external data sources, which provides real-world data and fulfills the requests from requester contracts [3];</li><li><strong>Adapters</strong>: an application-specific software interacts with data sources and fulfills a specific task [4]. It can be deployed in a server-less platform such as <a href="https://aws.amazon.com/lambda/">Amazon Lambda</a> or <a href="https://cloud.google.com/functions/">Google Cloud Functions</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*9ZoD0YvIftbqjQIZqVdJRg.jpeg" /><figcaption>Chainlink network architecture overview</figcaption></figure><p>It’s worth mentioning that each request from the requester contract must include a “Job Id”, which is the unique identification for a specific work pipeline. The Chainlink nodes rely on “Job Id” to recognize the required adapter to interact with and the workflow to process the data.</p><h3>2. Chainlink with Built-in Adapters</h3><p>In this section, we use the built-in adapters from Chainlink team to demonstrate how to integrate Chainlink and submit a request to it.</p><ul><li><strong>Install Chainlink Package</strong></li></ul><p>In the project root directory, install the Chainlink package as:</p><pre>$ npm install github:smartcontractkit/chainlink --save</pre><p>Moreover, Chainlink team has recently added a new NPM package just for the Chainlink contracts, and it can be installed as:</p><pre>$ npm install chainlink.js — save</pre><ul><li><strong>Create Requester Contract in Kovan</strong></li></ul><p>To interact with the Chainlink Oracle contract, it is required to build a requester contract that sends LINK tokens and submits requests.</p><p>We create an example requester contract for illustration, which can be found in our research repository [<a href="https://github.com/oceanprotocol/Nautilus/blob/master/4-chainlink/contracts/OceanRequester.sol">source code</a>].</p><p>The critical function in the contract is createRequest that creates a request and sets proper parameters:</p><ol><li><em>Job Id</em>: the unique identification for a specific work pipeline. The complete list of built-in adapters can be found here: <a href="https://docs.chain.link/docs/addresses-and-job-specs">https://docs.chain.link/docs/addresses-and-job-specs</a></li></ol><p>2. <em>URL</em>: the endpoint of the website that provides API interface to return data in JSON format;</p><p>3. <em>path</em>: it determines which data field in JSON object to be provided into the smart contract.</p><p>4. <em>times</em>: the number to multiply the data by. This operation converts a float number into an integer because Solidity smart contract only accepts integers.</p><pre>constructor() public {<br>    // Set the address for the LINK token in Kovan network.<br>    setLinkToken(0xa36085F69e2889c224210F603D836748e7dC0088);<br>    // Set the address of the Oracle contract in Kovan network.<br>    setOracle(0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e); <br>}</pre><pre>...</pre><pre>/*<br>   * Create a request and send it to default Oracle contract<br>   */<br>  function createRequest(<br>    bytes32 _jobId,<br>    string _url,<br>    string _path,<br>    int256 _times<br>  )<br>    public<br>    onlyOwner<br>    returns (bytes32 requestId)<br>  {<br>    // create request instance<br>    Chainlink.Request memory req = newRequest(_jobId, this, this.fulfill.selector);<br>    // fill in the pass-in parameters<br>    req.add(&quot;url&quot;, _url);<br>    req.add(&quot;path&quot;, _path);<br>    req.addInt(&quot;times&quot;, _times);<br>    // send request &amp; payment to Chainlink oracle<br>    requestId = chainlinkRequestTo(getOracle(), req, ORACLE_PAYMENT);<br>    // emit event message<br>    emit requestCreated(msg.sender, _jobId, requestId);<br>  }</pre><ul><li><strong>Deploy the Contract to Kovan</strong></li></ul><pre>$ truffle migrate --network kovan<br>	...<br>   Deploying &#39;OceanRequester&#39;<br>   --------------------------<br>   &gt; transaction hash:    0x6e228163e73828c58c8287fec72c551289516a1d8e9300aab5dcc99d848f6146<br>   &gt; Blocks: 0            Seconds: 16<br>   &gt; contract address:    0x04E4b02EA2662F5BF0189912e6092d317d6388F3<br>   &gt; account:             0x0E364EB0Ad6EB5a4fC30FC3D2C2aE8EBe75F245c<br>   &gt; balance:             2.703082875853937168<br>   &gt; gas used:            1439461<br>   &gt; gas price:           10 gwei<br>   &gt; value sent:          0 ETH<br>   &gt; total cost:          0.01439461 ETH<br><br>   &gt; Saving artifacts<br>   -------------------------------------<br>   &gt; Total cost:          0.01439461 ETH</pre><ul><li><strong>Deposit LINK Token to the Contract</strong></li></ul><p>The Chainlink team provides token faucets in different blockchain networks. The faucet in Kovan is <a href="https://kovan.chain.link/">https://kovan.chain.link/</a> where the developer can request some LINK tokens for testing purpose.</p><p>Simply type the contract address or wallet address, which is supposed to hold LINK tokens and submit requests to the Chainlink network. As such, Chainlink will transfer 100 LINK tokens into it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zkYBdlgkTAuxHd25IpK2jA.jpeg" /><figcaption>Chainlink Kovan Faucet</figcaption></figure><ul><li><strong>Request Data from the Contract</strong></li></ul><p>We created a Javascript file to interact with the requester contract to create and submit a request to the Chainlink network. The <a href="https://github.com/oceanprotocol/Nautilus/blob/master/4-chainlink/test/OceanRequester.Test.js">source file </a>of this script can be found in the Ocean’s research repository 4-chainlink/test [2].</p><p>The critical parameters are highlighted below. The job Id “2c6578f488c843588954be403aba2deb” identifies the adapter that retrieves the JSON data from a URL, copies the data field, formats it into an integer and then converts it into Solidity’s uint256 format.</p><pre>contract(&quot;OceanRequester&quot;, (accounts) =&gt; {<br>  const LinkToken = artifacts.require(&quot;LinkToken.sol&quot;);<br>  const OceanRequester = artifacts.require(&quot;OceanRequester.sol&quot;);<br>  const jobId = web3.utils.toHex(&quot;<strong>2c6578f488c843588954be403aba2deb</strong>&quot;);<br>  const url = &quot;<strong>https://min-api.cryptocompare.com/data/price?fsym=ETH&amp;tsyms=USD,EUR,JPY</strong>&quot;;<br>  const path = &quot;<strong>USD</strong>&quot;;<br>  const times = 100;<br>  let link, ocean;<br><br>  beforeEach(async () =&gt; {<br>    link = await LinkToken.at(&quot;<strong>0xa36085F69e2889c224210F603D836748e7dC0088</strong>&quot;);<br>    ocean = await OceanRequester.at(&quot;<strong>0x04E4b02EA2662F5BF0189912e6092d317d6388F3</strong>&quot;);<br>  });<br><br>  describe(&quot;query the initial token balance&quot;, () =&gt; {<br>    it(&quot;create a request and send to Chainlink&quot;, async () =&gt; {<br>      <strong>let tx = await ocean.createRequest(jobId, url, path, times);</strong><br>      request = h.decodeRunRequest(tx.receipt.rawLogs[3]);<br>      ...<br>      data = await ocean.getRequestResult(request.id)<br>      console.log(&quot;Request is fulfilled. data := &quot; + data)<br>	   ...<br>     });<br>   });<br>});</pre><p>For example, the URL that returns data in JSON format should look like the following. The path parameter “USD” indicates the data field corresponding to “USD” needs to be provided to the requester contract.</p><pre>{&quot;USD&quot;:142.33,&quot;EUR&quot;:126.69,&quot;JPY&quot;:15765.39}</pre><p>We can run the script to submit the request to the Chainlink network and retrieve the data from the URL endpoint. It takes 2 seconds for Chainlink nodes to fulfill the request, which includes block confirmations on both the request and fulfillment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*vy4BFHnAEAPKoyYBq6rYdA.jpeg" /></figure><h3>3. Chainlink with External Adapters</h3><p>The previous procedure looks clean and neat. However, the built-in adapters provided by Chainlink are very limited, which cannot satisfy requirements from all blockchain applications. Therefore, <a href="https://docs.chain.link/docs/external-adapters"><strong>an external and customized adapter</strong> </a>must be built to fit each different scenario.</p><p>In this section, we explore the approach to set up an external adapter and show how to put all the moving pieces together. Some external adapters can be found in <a href="https://chainlinkadapters.com/">https://chainlinkadapters.com/</a> for reference and there are also great guides available at <a href="https://chainlinkadapters.com/guides">https://chainlinkadapters.com/guides</a>.</p><ul><li><strong>Architecture with External Adapter</strong></li></ul><p>This diagram shows the overview structure including an external adapter. The blockchain developer needs to do the following work:</p><ol><li>Deploy an Oracle contract to a blockchain network;</li><li>Develop an external adapter and deploy to AWS Lambda or GCP functions, which provides a URL endpoint to interact with;</li><li>Run a new Chainlink node and register the URL endpoint of the external adapter in the bridge of the Chainlink node configuration;</li><li>Create a <a href="https://docs.chain.link/docs/job-specifications">Job Specification</a> for this task in the Chainlink node so that it can listen to the Oracle contract and trigger the proper work pipeline;</li><li>Register the new Chainlink nodes with on-chain Oracle contract;</li><li>Create a new requester contract to submit the request.</li></ol><p>We will present a step-by-step guide to this procedure in below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pubqolGPe17txM9TIgqgBw.jpeg" /><figcaption>The architecture of the Chainlink network with an external adapter</figcaption></figure><ul><li><strong>Step 1: Deploy an Oracle Contract to Kovan</strong></li></ul><p>An Oracle contract is required to interact with the new Chainlink node in our POC. To this end, we deploy a new <a href="https://github.com/oceanprotocol/Nautilus/blob/master/4-chainlink/contracts/Oracle.sol">Oracle contract</a> to the blockchain network: <a href="https://github.com/oceanprotocol/Nautilus/blob/master/4-chainlink/contracts">https://github.com/oceanprotocol/Nautilus/blob/master/4-chainlink</a>.</p><pre>3_oracle_migration.js<br>=====================<br><br>   Deploying &#39;Oracle&#39;<br>   ------------------<br>   &gt; transaction hash:    0xd281b18c4be0be9b2bdbfed4bae090aab5c86027564f048785b1f971cf0b6f2c<br>   &gt; Blocks: 0            Seconds: 8<br>   &gt; contract address:    <strong>0x698EFB00F79E858724633e297d5188705512e506</strong><br>   &gt; account:             0x0E364EB0Ad6EB5a4fC30FC3D2C2aE8EBe75F245c<br>   &gt; balance:             2.262907885853937168<br>   &gt; gas used:            1311430<br>   &gt; gas price:           10 gwei<br>   &gt; value sent:          0 ETH<br>   &gt; total cost:          0.0131143 ETH<br><br>   &gt; Saving artifacts<br>   -------------------------------------<br>   &gt; Total cost:           0.0131143 ETH</pre><ul><li><strong>Step 2: Build a New External Adapter</strong></li></ul><p>In this POC, we use an external adapter <a href="https://github.com/OracleFinder/CryptoCompareExternalAdapter">CryptoCompareExternalAdapter</a> from <a href="https://oraclefinder.com/">OracleFinder</a>. For more general applications, Thomas Hodges created a template for the external adapter using NodeJS: <a href="https://github.com/thodges-gh/CL-EA-NodeJS-Template">https://github.com/thodges-gh/CL-EA-NodeJS-Template</a></p><pre>$ git clone https://github.com/OracleFinder/CryptoCompareExternalAdapter.git<br>$ cd CryptoCompareExternalAdapter/<br>$ npm install<br>$ zip -r chainlink-cloud-adapter.zip .</pre><p>The zip file chainlink-cloud-adapter.zip is created and ready to be deployed. The <a href="https://github.com/oceanprotocol/Nautilus/blob/master/4-chainlink/adapter/chainlink-cloud-adapter.zip">zip file</a> can be found in the4-chainlink/adapter folder in the repository [2].</p><p>As an example, we deploy the external adapter to Google Cloud Functions. After log-in, create a new function as follows and upload the zip file chainlink-cloud-adapter.zip.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*oKtULixoM2AzufvRtbyyag.jpeg" /><figcaption>Create function in Google Cloud Functions</figcaption></figure><p>The generated URL endpoint of this external adapter is needed for the Chainlink node to interact with it:</p><pre>https://us-central1-macro-mercury-234919.cloudfunctions.net/coinmarketcap-adapter</pre><p>Now, from the console of Google Cloud Functions, we can test the adapter to ensure it works properly on its own:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*n8j7fzgIvIG-nuE1jDsk3Q.jpeg" /><figcaption>Testing external adapter in Google Cloud Functions</figcaption></figure><p>At this time, the external adapter is up and running in Google Cloud Platform, which is ready to fulfill the request from the Chainlink nodes.</p><ul><li><strong>Step 3: Register Adapter URL in a New Chainlink Node</strong></li></ul><p>We need to run a new Chainlink node in order to interact with the external adapter. Here is the procedure to set up a new one:</p><ol><li>Install <strong>Parity</strong> client for the Kovan network</li></ol><pre>$ docker pull parity/parity:stable<br>$ mkdir ~/.parity-kovan<br>$ docker run -h eth --name eth -p 8546:8546 \<br>           -v ~/.parity-kovan:/home/parity/.local/share/io.parity.ethereum/ \<br>           -it parity/parity:stable --chain=kovan \<br>           --ws-interface=all --ws-origins=&quot;all&quot; --light \<br>           --base-path /home/parity/.local/share/io.parity.ethereum/</pre><p>2. Create credentials to manage the Chainlink node</p><pre>$ docker pull smartcontract/chainlink:latest<br>$ mkdir -p ~/.chainlink-kovan/tls<br>$ openssl req -x509 -out  ~/.chainlink-kovan/tls/server.crt  -keyout ~/.chainlink-kovan/tls/server.key \<br>  -newkey rsa:2048 -nodes -sha256 \<br>  -subj &#39;/CN=localhost&#39; -extensions EXT -config &lt;( \<br>   printf &quot;[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth&quot;)</pre><p>3. Create the settings for Chainlink node configuration</p><pre>echo &quot;ROOT=/chainlink<br>LOG_LEVEL=debug<br>ETH_URL=ws://eth:8546 <br>ETH_CHAIN_ID=42<br>MIN_OUTGOING_CONFIRMATIONS=2<br>MIN_INCOMING_CONFIRMATIONS=0<br>LINK_CONTRACT_ADDRESS=<strong>0xa36085F69e2889c224210F603D836748e7dC0088</strong><br>TLS_CERT_PATH=/chainlink/tls/server.crt<br>TLS_KEY_PATH=/chainlink/tls/server.key<br>ALLOW_ORIGINS=*&quot; &gt; .env</pre><p>4. Run the Chainlink node</p><pre>$ docker run --link eth -p 6689:6689 -v ~/.chainlink-kovan:/chainlink -it --env-file=.env smartcontract/chainlink n</pre><p>Note that the latest instruction for this operation can be found in the official docs: <a href="https://docs.chain.link/docs/running-a-chainlink-node">https://docs.chain.link/docs/running-a-chainlink-node</a></p><p>Open the GUI configuration interface of the Chainlink node from <a href="https://localhost:6689/">https://localhost:6689</a> and log in with the credentials. The dashboard should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*48LBX_TswAg3FOYaeIsEEQ.jpeg" /><figcaption>the dashboard of Chainlink node</figcaption></figure><p>5. Register the external adapter in Chainlink node</p><p>In the Tab “Bridges”, we need to create a new bridge and fill the “Bridge URL” with the URL endpoint of the external adapter in Google Cloud Functions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*Px1RH_i5HzEiZM8tPcGKaA.jpeg" /><figcaption>create a new bridge for the external adapter</figcaption></figure><p>The new bridge should be up and running like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*M-9sfN64IdjDKW05YTKGoA.jpeg" /><figcaption>Status of Bridge Info</figcaption></figure><ul><li><strong>Step 4: Create a Job Specification for the external adapter</strong></li></ul><p>In the Chainlink node, it is very important to create a new Job Specification according to the tutorial here: <a href="https://docs.chain.link/docs/job-specifications">https://docs.chain.link/docs/job-specifications</a></p><p>With the Job Specification, the Chainlink node can listen to the event messages from the Oracle contract and trigger the proper pipeline defined in the Job Specification. Our Job Specification is the following:</p><pre>{<br>  &quot;initiators&quot;: [<br>    {<br>      &quot;type&quot;: &quot;RunLog&quot;,<br>      &quot;params&quot;: { &quot;address&quot;: &quot;0x698efb00f79e858724633e297d5188705512e506&quot; }<br>    }<br>  ],<br>  &quot;tasks&quot;: [<br>    {<br>      &quot;type&quot;: &quot;coinmarketcap&quot;,<br>      &quot;confirmations&quot;: 0,<br>      &quot;params&quot;: {}<br>    },<br>    {<br>      &quot;type&quot;: &quot;Copy&quot;,<br>      &quot;params&quot;: {}<br>    },<br>    {<br>      &quot;type&quot;: &quot;Multiply&quot;,<br>      &quot;params&quot;: { &quot;times&quot;: 100 }<br>    },<br>    { &quot;type&quot;: &quot;EthUint256&quot; },<br>    { &quot;type&quot;: &quot;EthTx&quot; }<br>  ]<br>}</pre><p>The initiators set the contract address that triggers the Chainlink node to initiate a specific job, while tasks defines the work pipeline for this job.</p><p>Note that the parameter “address: 0x698efb00f79e858724633e297d5188705512e506” indicates that the node will only listen to that address for the job ID, which should be updated with the deployed Oracle contract address properly. However, the “address” parameter can be removed. In this way, the node will listen to all addresses for the job ID.</p><p>For example, the “tasks” define that the Chainlink node will first retrieve data from the external adapter “coinmarketcap” (i.e., the Bridge will interact with the URL endpoint of external adapter to access the data in JSON format), copy the data field, multiply it by 100, and convert it into uint256 type.</p><p>The new Job can be found in the Tab of “Jobs” as below. Note that 80c7e6908e714bf4a73170c287b9a18c is the new <strong>jobID</strong> for this external adapter, which should be used for submitting a request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*Fb7GbMPO2zmyO6dZv39dEg.jpeg" /><figcaption>Job Info in Chainlink node</figcaption></figure><ul><li><strong>Step 5: Register the Chainlink node in the Oracle contract</strong></li></ul><p>The new Chainlink node must be registered in the Oracle contract deployed in the first step so that it can be allowed to accept requests and fulfill them.</p><p>The account address of the new Chainlink node can be found in the configuration page of the Chainlink node (highlighted in the below):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nUqwcajmkhChHM5bi0CONA.jpeg" /><figcaption>Account address of Chainlink node</figcaption></figure><p>We use a Javascript file to register this Chainlink node in the Oracle contract. The <a href="https://github.com/oceanprotocol/Nautilus/blob/master/4-chainlink/test/Oracle.Test.js">source file</a> Oracle.Test.js can be found in the test folder.</p><pre>const Web3 = require(&#39;web3&#39;)<br><br>const web3 = new Web3(new Web3.providers.HttpProvider(&#39;https://kovan.infura.io/&#39;))<br><br><br>const h = require(&quot;chainlink-test-helpers&quot;);<br>const scale = 1e18;<br><br>contract(&quot;Oracle&quot;, (accounts) =&gt; {<br>  const Oracle = artifacts.require(&quot;Oracle.sol&quot;);<br>  <strong>const chainlinkNode =&#39;0x79B80f3b6B06FD5516146af22E10df26dfDc5455&#39;;</strong><br>  let oracle;<br><br>  beforeEach(async () =&gt; {<br>    oracle = await Oracle.at(&quot;0x698EFB00F79E858724633e297d5188705512e506&quot;);<br>  });<br><br>  describe(&quot;should register chainlink node&quot;, () =&gt; {<br><br>    it(&quot;register chainlink node&quot;, async () =&gt; {<br>      <strong>await oracle.setFulfillmentPermission(chainlinkNode, true)</strong><br>      let status = await oracle.getAuthorizationStatus(chainlinkNode)<br>      console.log(&quot;Chainlink node&#39;s status is := &quot; + status)<br>    });<br>  });<br>});</pre><p>Run this script with Truffle as:</p><pre>$ truffle test test/Oracle.Test.js --network kovan<br>Using network &#39;kovan&#39;</pre><pre>   Contract: Oracle<br>       should register chainlink node<br>Chainlink node&#39;s status is := true</pre><p>The status of true indicates the Chainlink node has registered and been granted with the permission to fulfill the jobs in the Oracle contract.</p><ul><li><strong>Step 6: Create a requester contract to submit a request</strong></li></ul><p>To create and submit a request to the external adapter, we create a requester contract contracts/requestGCP.so to test the entire workflow. [<a href="https://github.com/oceanprotocol/Nautilus/blob/master/4-chainlink/contracts/requestGCP.sol">source code</a>]</p><p>The key function to create a request:</p><pre>function createRequest(<br>    bytes32 _jobId,<br>    string _coin,<br>    string _market<br>  )<br>    public<br>    onlyOwner<br>    returns (bytes32 requestId)<br>  {<br>    // create request instance<br>    Chainlink.Request memory req = newRequest(_jobId, this, this.fulfill.selector);<br>    // fill in the pass-in parameters<br>    req.add(&quot;endpoint&quot;, &quot;price&quot;);<br>    req.add(&quot;fsym&quot;, _coin);<br>    req.add(&quot;tsyms&quot;, _market);<br>    req.add(&quot;copyPath&quot;, _market);<br>    // send request &amp; payment to Chainlink oracle (Requester Contract sends the payment)<br>    requestId = chainlinkRequestTo(getOracle(), req, ORACLE_PAYMENT);<br>    // emit event message<br>    emit requestCreated(msg.sender, _jobId, requestId);<br>  }</pre><p>It should be deployed to Kovan network as well:</p><pre>4_requestGCP_migration.js<br>=========================<br><br>   Replacing &#39;requestGCP&#39;<br>   ----------------------<br>   &gt; transaction hash:    0x978974b43d843606c42ce15c87fcc560a5c625497bf074f5ec0f337347438fdf<br>   &gt; Blocks: 0            Seconds: 16<br>   &gt; contract address:    <strong>0x6f73E784253aD72F0BA4164101860992dFC17Fe1</strong><br>   &gt; account:             0x0E364EB0Ad6EB5a4fC30FC3D2C2aE8EBe75F245c<br>   &gt; balance:             2.248942845853937168<br>   &gt; gas used:            1396504<br>   &gt; gas price:           10 gwei<br>   &gt; value sent:          0 ETH<br>   &gt; total cost:          0.01396504 ETH<br><br>   &gt; Saving artifacts<br>   -------------------------------------<br>   &gt; Total cost:          0.01396504 ETH</pre><p>Fund this request contract with LINK tokens from the faucet: <a href="https://kovan.chain.link/">https://kovan.chain.link/</a></p><p>Now, we can fire the request to the external adapter to access off-chain data. It can be done with a script [<a href="https://github.com/oceanprotocol/Nautilus/blob/master/4-chainlink/test/requestGCP.Test.js">source file</a>]:</p><pre>const Web3 = require(&#39;web3&#39;)<br><br>const web3 = new Web3(new Web3.providers.WebsocketProvider(&#39;ws://eth:8546&#39;))<br><br>const h = require(&quot;chainlink-test-helpers&quot;);<br>const scale = 1e18;<br><br>contract(&quot;requestGCP&quot;, (accounts) =&gt; {<br>  const LinkToken = artifacts.require(&quot;LinkToken.sol&quot;);<br>  const RequestGCP = artifacts.require(&quot;requestGCP.sol&quot;);<br>  <strong>const jobId = web3.utils.toHex(&quot;80c7e6908e714bf4a73170c287b9a18c&quot;);</strong><br>  const coin = &quot;ETH&quot;<br>  const market = &quot;USD&quot;;<br>  const defaultAccount =0x0e364eb0ad6eb5a4fc30fc3d2c2ae8ebe75f245c;<br>  let link, ocean;<br><br>  beforeEach(async () =&gt; {<br>    link = await LinkToken.at(&quot;0xa36085F69e2889c224210F603D836748e7dC0088&quot;);<br>    ocean = await RequestGCP.at(&quot;<strong>0x6f73E784253aD72F0BA4164101860992dFC17Fe1</strong>&quot;);<br>  });<br><br>  describe(&quot;should request data and receive callback&quot;, () =&gt; {<br>    let request;</pre><pre>    ...<br>    it(&quot;create a request and send to Chainlink&quot;, async () =&gt; {<br>      <strong>let tx = await ocean.createRequest(jobId, coin, market);</strong><br>      request = h.decodeRunRequest(tx.receipt.rawLogs[3]);<br>      console.log(&quot;request has been sent. request id :=&quot; + request.id)<br><br>      let data = 0<br>      let timer = 0<br>      while(data == 0){<br>        data = await ocean.getRequestResult(request.id)<br>        if(data != 0) {<br>          console.log(&quot;Request is fulfilled. data := &quot; + data)<br>        }<br>        wait(1000)<br>        timer = timer + 1<br>        console.log(&quot;waiting for &quot; + timer + &quot; second&quot;)<br>      }<br><br>    });<br>  });<br>});</pre><p>Run this script as:</p><pre>$ truffle test test/requestGCP.Test.js --network kovan</pre><p>It shows the request takes 10s to be fulfilled by the external adapter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5de60lZXYVciVvdF93kYJg.jpeg" /><figcaption>the request is fulfilled by the external adapter</figcaption></figure><p>The transaction can be found in the transaction history of Chainlink node:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*YeS9BtNb18Ke3usE0iQ9nw.jpeg" /><figcaption>The transaction can be found in Chainlink node’s tx history</figcaption></figure><p>The same transaction can be found in the dashboard of the external adapter in Google Cloud Functions as follows. It proves that the external adapter receives the request and fulfills the job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uwte1rOWhg-ArQvleqpnuA.jpeg" /><figcaption>Transaction history of the external adapter in Google Cloud Functions</figcaption></figure><h3>4. Conclusion</h3><p>Chainlink is an important Oracle network to bridge the blockchain to the real world in a decentralized way. Many blockchain applications including Ocean Protocol may require interaction with Chainlink network to fulfill their services using a data feed from the real world.</p><p>In this article, we explain the architecture of Chainlink network and introduce how to integrate with Chainlink using built-in and external adapters. Blockchain developers need to deal with many moving pieces to develop external adapters for their own applications. We hope this article helps blockchain developers and projects with similar requirements. Thank you for reading this article!</p><p>Special Thanks to Daniel Kochis and Thomas Hodges from Chainlink for their great advice and support to us! This is a collaborative effort between Ocean Procotol and Chainlink.</p><h3>Reference</h3><p>[1] Chainlink: <a href="https://chain.link/">https://chain.link/</a></p><p>[2] Ocean’s research repository of Chainlink: <a href="https://github.com/oceanprotocol/Nautilus/tree/master/4-chainlink">https://github.com/oceanprotocol/Nautilus/tree/master/4-chainlink</a></p><p>[3] Running a Chainlink Node: <a href="https://docs.chain.link/docs/running-a-chainlink-node">https://docs.chain.link/docs/running-a-chainlink-node</a></p><p>[4] Adapters in Chainlink: <a href="https://docs.chain.link/docs/adapters">https://docs.chain.link/docs/adapters</a></p><p>[5] Job IDs in Chainlink Node: <a href="https://docs.chain.link/docs/addresses-and-job-specs">https://docs.chain.link/docs/addresses-and-job-specs</a></p><p>[6] CL-Adapters.com: <a href="https://chainlinkadapters.com/">https://chainlinkadapters.com/</a></p><p>[7] Chainlink NodeJS Serverless External Adapter Template <a href="https://github.com/thodges-gh/CL-EA-NodeJS-Template">https://github.com/thodges-gh/CL-EA-NodeJS-Template</a></p><p>This article is an on-going work and many pieces can be further improved. Feel free to send me comments: fang@oceanprotocol.com.</p><p>If you would like to know more, please follow <a href="https://twitter.com/gongf05?lang=en"><em>Fang Gong</em></a><em>.</em></p><p>Ready to dive in? — Check out the <a href="https://docs.oceanprotocol.com/">Ocean Documentation</a> to get a sense of what we’ve been working on, and fire all your technical questions in <a href="https://gitter.im/oceanprotocol/Lobby">our Gitter chatroom</a>.</p><p>Follow <strong>Ocean Protocol</strong> on <a href="https://twitter.com/oceanprotocol">Twitter,</a> <a href="https://t.me/oceanprotocol_community">Telegram</a>, <a href="https://www.linkedin.com/company/ocean-protocol/">LinkedIn</a>, <a href="https://www.reddit.com/r/oceanprotocol/">Reddit</a>, <a href="https://github.com/oceanprotocol">GitHub</a> &amp; <a href="https://oceanprotocol.com/newsletter/">Newsletter</a> for project updates and announcements.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afcf19cfbb73" width="1" height="1" alt=""><hr><p><a href="https://blog.oceanprotocol.com/bridging-blockchain-to-the-real-world-using-chainlink-afcf19cfbb73">Bridging Blockchain to the Real World using Chainlink</a> was originally published in <a href="https://blog.oceanprotocol.com/">Ocean Protocol</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enabling Short Selling in Bonding Curves — Part 4]]></title>
            <link>https://blog.oceanprotocol.com/enabling-short-selling-in-bonding-curves-part-4-bf97772194a1?source=rss-f1e17af9a3ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf97772194a1</guid>
            <category><![CDATA[deeptech]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[homepage]]></category>
            <category><![CDATA[bonding-curves]]></category>
            <category><![CDATA[mechanism-design]]></category>
            <dc:creator><![CDATA[Fang Gong]]></dc:creator>
            <pubDate>Sun, 10 Mar 2019 09:11:00 GMT</pubDate>
            <atom:updated>2019-03-10T09:11:00.657Z</atom:updated>
            <content:encoded><![CDATA[<h3>Enabling Short Selling in Bonding Curves — Part 4</h3><p><em>This is Part 4 of a series. Other Parts can be found in the list:</em></p><p><a href="https://medium.com/p/af871ad75d40/">Part 1: Overview of Short Selling Design in Bonding Curves</a><br><a href="https://medium.com/p/4d9da68324fb">Part 2: Simple Scenario with Single Short Position</a><br><a href="https://medium.com/p/6c2dd4eae4d7">Part 3: Complex Scenario with Multiple Short Positions</a><br><strong>Part 4: Performance &amp; Privacy Improvement</strong></p><h3>Part 4: Performance and Privacy Improvement</h3><p>In this Part, we investigate some performance and security issues about short selling in Bonding Curves. In the end, we discuss some requirements of the proposed solution.</p><h3><strong>1. Improve Performance with Batched Bonding Curves</strong></h3><p>In our previous discussion, we need to evaluate which short positions need to be covered whenever a new “buy” transaction is submitted. However, it may make the short positions very sensitive to the token price fluctuation.</p><p>Imagine there are two transactions: one buy order follows by one sell order and both orders have the<em> same amount </em>of tokens. After both transactions are executed, the token price remains the same.</p><p>If we follow the solution in Part 2 and Part 3, it is possible that some short positions need to be covered before the “buy” transaction. However, it turns out those short positions can be intact since the token price remains the same after two transactions.</p><p>This observation brings us to consider how to avoid unnecessary closing of short positions under token price fluctuation. In fact, we found the “Batched Bonding Curve” proposed by Billy Rennekamp can help [<a href="https://github.com/okwme/BatchedBondingCurves">1</a>][<a href="https://beta.observablehq.com/@okwme/batched-bonding-curves">2</a>], which was originally proposed to prevent front-running attack in Bonding Curves.</p><p>As shown in the figures below, we can aggregate all “sell” orders within a certain period of time into a single batched “sell” order and execute it first. Similarly, we can aggregate all “buy” orders in the same time window into a single batched “buy” order and execute it. All buyers in the same batched order will share the same purchase or sold price.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AshH4YbvZqJGyHENdOON3w.jpeg" /><figcaption>Illustration of Batched Bonding Curves</figcaption></figure><p>With the idea of Batched Bonding Curves, we can modify our presented solution as follows:</p><ul><li>aggregate all “sell” orders into a batched “sell” order and execute it first;</li><li>aggregate partial “buy” orders into a batched “buy” order to execute, which tries to reinstate the token price to its original value before the execution of any “sell” order;</li><li>if all “buy” orders have been executed but the token price becomes lower, there is no short position need to be covered;</li><li>aggregate the remaining “buy” orders into single batched “buy” order;</li><li>find any short positions need to be covered as described in Part 3;</li><li>execute the batched “buy” order after affected short positions are covered.</li></ul><p>As such, we can reduce the number of total transactions and keep short positions to be intact as long as possible.</p><h3>2. Privacy-preserving Short Selling</h3><p>The broker contract maintains all the short selling records and is open to the public. It is possible some attackers manipulate transactions to force some short positions to be covered and make profits. Therefore, it demands to keep the broker contract private when security is a major concern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*s_clxs8JGiFiSTgsVZ0uWw.jpeg" /><figcaption>Keep broker contract to be private for security purpose</figcaption></figure><p>As shown in the figure, the broker contract can be private by running inside a secure enclave using Enigma[<a href="https://enigma.co/">3</a>] or Oasis [<a href="https://www.oasislabs.com/">4</a>]. All buy/sell order (no matter regular order or short selling order) will be forced to be submitted into the broker contract. In other words, only the broker contract can directly buy/sell bonded tokens in the Bonding Curve.</p><p>In this way, it becomes very difficult to distinguish the short selling order from other regular orders by observing transactions in the Bonding Curve. Moreover, the short selling information maintained inside the broker contract remains to be private inside the enclave. Furthermore, the transaction going to the broker contract can be encrypted on the users’ local and decrypted inside the enclave, therefore, making it impossible for attackers to reveal the transaction details.</p><h3>3. Requirements for Application</h3><p>I guess you cannot wait to enable short selling in your Bonding Curves, right? Wait a minute…. I would like to remind you of some requirements that worths mentioning before you push the trigger:</p><ul><li>Bonding Curves should be modeled by the<strong> analytical formulae</strong>. The reason is we need to evaluate the integral and solve an equation to calculate the threshold price. An analytical formula significantly facilitates this task.</li><li>Buyers may get a <strong>higher purchase price</strong> in the end. If short selling is enabled, any “buy” transaction can potentially cause the closing of short positions and push up the token price. Thus, the real purchase price for the “buy” transaction becomes higher than the original one when the buyer submits the transaction. It is advisable to confirm the new token price with buyers before the execution.</li></ul><h3>4. Conclusion</h3><p>Short Selling is a new research topic in Bonding Curves and there is no existing work available at this moment. In this series of articles, we present a short selling strategy in Bonding Curves:</p><ul><li>the overall design of short selling;</li><li>the data structure design for the broker contract;</li><li>the methodology to handle short squeeze using the threshold price;</li><li>the solution to complex scenarios with multiple short positions;</li><li>the approach to improve performance with batched Bonding Curves;</li><li>the design to protect the privacy of the broker contract from attackers.</li></ul><p>This work should be treated as on-going research and many pieces need to be improved or fine-tuned. However, we would like to share our research with the community and hope this work help other researchers or projects.</p><p>Thank you for reading this series of articles!</p><h3>5. Acknowledgment</h3><p>Special thanks to <a href="https://medium.com/@trentmc0">Trent McConaghy</a>, <a href="https://medium.com/@DimitriDeJonghe">Dimitri de Jonghe</a>, <a href="https://medium.com/@Paul.Haas">Paul Kohlhaas</a>, <br><a href="https://medium.com/@gomox">Gonzalo Sainz Trápaga</a> and<strong> </strong><a href="https://medium.com/@simondlr">Simon de la Rouviere</a> for insightful reviews and suggestions, which significantly improve the quality of these articles.</p><h3>6. Reference</h3><p>[1] Billy Rennekamp, “<em>Bonding Curve Tokens with batched buy &amp; sell orders</em>”, Jan 16, 2019. <a href="https://github.com/okwme/BatchedBondingCurves">https://github.com/okwme/BatchedBondingCurves</a></p><p>[2] Billy Rennekamp, “<em>Batched Bonding Curves</em>”, Jan 2, 2019. <a href="https://beta.observablehq.com/@okwme/batched-bonding-curves">https://beta.observablehq.com/@okwme/batched-bonding-curves</a></p><p>[3] Enigma, <a href="https://enigma.co/">https://enigma.co/</a></p><p>[4] Oasis Labs, <a href="https://www.oasislabs.com/">https://www.oasislabs.com/</a></p><p>This is an on-going work and many pieces can be further improved. Feel free to send me comments: fang@oceanprotocol.com.</p><p>If you would like to know more, please follow <a href="https://twitter.com/gongf05?lang=en"><em>Fang Gong</em></a><em> </em>and Ocean Protocol on <a href="https://twitter.com/oceanprotocol">Twitter,</a> <a href="https://t.me/joinchat/GUyxrE0Hi154D0NrlOqLFg">Telegram</a>, <a href="https://www.linkedin.com/company/ocean-protocol/">LinkedIn</a>, <a href="https://www.reddit.com/r/oceanprotocol/">Reddit</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf97772194a1" width="1" height="1" alt=""><hr><p><a href="https://blog.oceanprotocol.com/enabling-short-selling-in-bonding-curves-part-4-bf97772194a1">Enabling Short Selling in Bonding Curves — Part 4</a> was originally published in <a href="https://blog.oceanprotocol.com/">Ocean Protocol</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enabling Short Selling in Bonding Curves — Part 3]]></title>
            <link>https://blog.oceanprotocol.com/enabling-short-selling-in-bonding-curves-part-3-6c2dd4eae4d7?source=rss-f1e17af9a3ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c2dd4eae4d7</guid>
            <category><![CDATA[deeptech]]></category>
            <category><![CDATA[homepage]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[bonding-curves]]></category>
            <category><![CDATA[mechanism-design]]></category>
            <dc:creator><![CDATA[Fang Gong]]></dc:creator>
            <pubDate>Sat, 09 Mar 2019 11:11:00 GMT</pubDate>
            <atom:updated>2019-03-09T11:11:00.775Z</atom:updated>
            <content:encoded><![CDATA[<h3>Enabling Short Selling in Bonding Curves — Part 3</h3><p><em>This is Part 3 of a series. Other Parts can be found in the list:</em></p><p><a href="https://medium.com/p/af871ad75d40/">Part 1: Overview of Short Selling Design in Bonding Curves</a><br><a href="https://medium.com/p/4d9da68324fb">Part 2: Simple Scenario with Single Short Position</a><br><strong>Part 3: Complex Scenario with Multiple Short Positions</strong><br><a href="https://medium.com/p/bf97772194a1">Part 4: Performance &amp; Privacy Improvement</a></p><h3><strong>Part 3: Complex Scenario with Multiple Short Positions</strong></h3><p>In the simple scenario with a single short position (Part 2), we solve the problem of determining when a short position should be covered.</p><p>In this article, we start to investigate more complex scenario, which has many short sellers and multiple short positions. The key challenges are:</p><ul><li>which short positions should be covered at one moment?</li><li>what is the order to cover those short positions if needed?</li></ul><p>We will explore the challenges and propose our solution to them. Without loss of generality, let us consider the case with two short positions. The same approach can be applied to cases with more than two short positions.</p><h3><strong>1. Find Need-To-Cover Short Positions</strong></h3><p>When there exist many short positions, it is desired to find those that need to be covered before the token price will move upward.</p><p>Here, we make use of the “<em>threshold price</em>” for each short position defined in Part 2, which is evaluated when a short position is created.</p><p>Moreover, each short position has its own “<em>price range</em>” starting from the threshold price as shown in the below. The variable <strong><em>k</em></strong> indicates the number of bonded tokens that short seller borrowed from the broker contract. As such, each short position has its own price range on the Bonding Curve.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*F9yVzXQOhQ-NitCHCkz8rg.jpeg" /><figcaption>Illustration of the price range of a short position starting from threshold price</figcaption></figure><p>Now, let us consider two short positions <strong>without overlap</strong> <strong>in their price ranges</strong>, which can be sorted from low to high according to their threshold prices as shown in the figure below. We will study the case with overlap in the next section in more details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*DPyW4lwqCAEpDSfrvrOogA.jpeg" /><figcaption>Price ranges of Short Positions can be sorted from low to high.</figcaption></figure><p>When a new “buy” transaction is submitted, the token price will move up if executed. As shown in the following figure (Red shaded area), the “buy” transaction will push the token price up to the level denoted as “<em>price after “buy” tx</em>”. If this price is lower than any threshold price of existing short positions, there is no short position needs to be covered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cO1I6wPHEOaM0h6TZ7n_Eg.jpeg" /><figcaption>Two Scenarios: Left: first short position (yellow shaded) must be covered; Right: both short positions must be covered.</figcaption></figure><ul><li><strong>Left figure</strong>: the price after “buy” tx will be higher than threshold price 1 but lower than threshold price 2, therefore, the first short position (Yellow shaded area) needs to be covered. The same check can be performed on the second short position (Blue shaded area) as well.</li><li><strong>Right figure</strong>: the price after “buy” tx will be higher than both threshold prices, therefore, two short positions must be covered before this “buy” transaction can be executed.</li></ul><p>The strategy can be extended to more general cases with multiple short positions in the following steps:</p><ul><li>sort short positions according to their threshold prices from low to high;</li><li>evaluate the price after the new “buy” transaction;</li><li>traverse short positions and start with the <strong>lowest</strong> threshold price;</li><li>if the “<em>price after “buy” tx</em>” is higher than one threshold price, the corresponding short position must be covered yielding price-after-cover.</li><li>continue until the threshold price is higher than the “<em>price after “buy” tx</em>” or there is no short position available.</li></ul><p>Note that the traversal operation may consume a lot of gas and render out-of-gas if there are many items on the list. This issue may be mitigated by moving traversal computation into off-chain or running it on a POA network with low gas cost.</p><h3><strong>2. Short Position Overlapping</strong></h3><p>Now, let us consider the complex case with price range overlap, which creates a great challenge: if we cover the first short position (Yellow shaded area), the second short position (Blue shaded area) can never be covered.</p><p>The reason is quite obvious: the token price after covering the first short position will be higher than the threshold price for the second short position.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*Vfq9mYeB53rkfV27YOo60w.jpeg" /><figcaption>Overlapped price ranges for two short positions</figcaption></figure><p>To address this issue, we need to remove this overlap before trying to cover any short positions. The solution is to eliminate the overlap by <em>moving the price range of the first short position to be lower</em>, because the first short position can be covered at a lower price securely but the second short position cannot be covered at a higher price.</p><p>With this adjustment, the price ranges for these two short positions become below. After, the approach presented in the last section can be applied to identify those short positions need to be covered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*ixmc8POW1hp8x2HaAAx7Dg.jpeg" /><figcaption>Result after removing the overlap between two price ranges for short positions.</figcaption></figure><p>It is noteworthy that attackers may manipulate a new short position to move an existing short position and force it to be covered on purpose. This attack vector can be prevented with the following rule: if the threshold price of the first short position (Yellow shaded area) becomes lower than the current price after the adjustment so that it needs to be covered, the new short position cannot be opened.</p><p>On the other side, if an attacker tries to block any future short position to be opened, he/she needs to borrow and sell a large amount of bonded tokens, which pushes the token price to be very low. As such, the attacker has an extremely high risk of loss, which is not a rational move.</p><p>The same method can be applied to general cases with multiple short positions in the following steps:</p><ul><li>traverse the short positions and start with the <strong>highest</strong> threshold price;</li><li>if there is any price range overlap exist, move the short position with lower threshold price to be lower so that to remove the overlap;</li><li>continue until there is no overlap.</li></ul><p>This procedure needs to be performed whenever the threshold price is updated or a new short position is created. In this scenario, the traverse can start from the updated or newly-created short position to save traversal cost.</p><h3>4. Overall Solution</h3><p>The complete solution to the complex scenario with multiple short positions can be built by combining the previous two approaches as:</p><ul><li>each short position has its own threshold price;</li><li>sort all short position according to their threshold prices from low to high;</li><li>traverse from the short position with the highest threshold price and remove any price range overlap as described in Section 3.</li><li>when a new “buy” transaction is submitted, the price after “buy” transaction should be evaluated based on current price;</li><li>traverse from the short position with the lowest threshold price;</li><li>cover the short position if the “<em>price after “buy” tx</em>” is higher than its threshold price;</li><li>continue until the threshold price is higher than the “<em>price after “buy” tx</em>” or there is no short position available.</li><li>after the short positions are covered, the “buy” transaction can be executed as usual.</li></ul><p>This article is an on-going work and many pieces can be further improved. Feel free to send me comments: fang@oceanprotocol.com.</p><p>If you would like to know more, please follow <a href="https://twitter.com/gongf05?lang=en"><em>Fang Gong</em></a><em> </em>and Ocean Protocol on <a href="https://twitter.com/oceanprotocol">Twitter,</a> <a href="https://t.me/joinchat/GUyxrE0Hi154D0NrlOqLFg">Telegram</a>, <a href="https://www.linkedin.com/company/ocean-protocol/">LinkedIn</a>, <a href="https://www.reddit.com/r/oceanprotocol/">Reddit</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c2dd4eae4d7" width="1" height="1" alt=""><hr><p><a href="https://blog.oceanprotocol.com/enabling-short-selling-in-bonding-curves-part-3-6c2dd4eae4d7">Enabling Short Selling in Bonding Curves — Part 3</a> was originally published in <a href="https://blog.oceanprotocol.com/">Ocean Protocol</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enabling Short Selling in Bonding Curves — Part 2]]></title>
            <link>https://blog.oceanprotocol.com/enabling-short-selling-in-bonding-curves-part-2-4d9da68324fb?source=rss-f1e17af9a3ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d9da68324fb</guid>
            <category><![CDATA[deeptech]]></category>
            <category><![CDATA[homepage]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[mechanism-design]]></category>
            <dc:creator><![CDATA[Fang Gong]]></dc:creator>
            <pubDate>Fri, 08 Mar 2019 11:51:00 GMT</pubDate>
            <atom:updated>2019-03-26T15:20:04.830Z</atom:updated>
            <content:encoded><![CDATA[<h3>Enabling Short Selling in Bonding Curves — Part 2</h3><p><em>This is Part 2 of a series. Other Parts can be found in the list:</em></p><p><a href="https://medium.com/p/af871ad75d40/">Part 1: Overview of Short Selling Design in Bonding Curves</a><br><strong>Part 2: Simple Scenario with Single Short Position</strong><br><a href="https://blog.oceanprotocol.com/enabling-short-selling-in-bonding-curves-part-3-6c2dd4eae4d7">Part 3: Complex Scenario with Multiple Short Positions</a> <br><a href="https://blog.oceanprotocol.com/enabling-short-selling-in-bonding-curves-part-4-bf97772194a1">Part 4: Performance &amp; Privacy Improvement</a></p><h3>Part 2: Simple Scenario with Single Short Position</h3><p>In this part, we start with a simple scenario: <em>one short seller has one single short position</em>. We will explore the challenges and develop some solutions.</p><h3>1. What is the Challenge?</h3><p>The most critical challenge is “<strong>Short Squeeze</strong>”[<a href="https://en.wikipedia.org/wiki/Short_squeeze">1</a>][<a href="https://www.investopedia.com/terms/s/shortsqueeze.asp">2</a>], where the token price moves up and short sellers are forced to close their short positions. In particular, the broker contract should guarantee that short sellers can pay back the borrowed bonded tokens and interests to the lenders in any situation.</p><p>As shown in the diagram, the short sellers sold borrowed tokens at price A and pushed the token price to B. The shaded area represents the number of reserved tokens from this sale. If there are new buy transactions and the token price moves up to C, the short seller cannot buy back the same amount of bonded tokens using the received reserved tokens. As such, the short seller cannot cover his short position and the lender loses money.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*k_3ls8UdvlB97WyxucZ8Ig.jpeg" /><figcaption>Diagram showing “Short Squeeze” situation</figcaption></figure><h3>2. Deposit of Collaterals</h3><p>The risk of a short squeeze increases as the token price fluctuates. If there is no buffer layer available, short sellers cannot tolerate any price increase.</p><p>To this end, <em>short sellers are required to</em> <em>deposit a certain amount of reserved tokens as collaterals</em>, which will be used to purchase bonded tokens in case of a price increase. It has been illustrated in the below diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*HpkrQSBUbnnEsrAUw4haZA.jpeg" /><figcaption>Illustration of Collateral Deposit</figcaption></figure><p>The red shaded area represents the collateral deposit that is used to cover the short position <strong>at a higher price</strong>, where the sale of short selling is not enough. Clearly, more collateral deposit indicates short sellers can tolerate more fluctuation in token price; otherwise, they will be forced to cover short positions with a very small price increase.</p><h3>3. Threshold Price</h3><p>The short seller desires to delay the time point when the short position must be covered in case of the increasing token price. They will have more time to wait and cover the short position when the token price moves below his short selling price to make a profit.</p><p>I , the lender will take more risk of losing his bonded tokens at the same time, because the short position may never be able to be covered due to the high token price.</p><p>To resolve this conflict of interest, we introduce “threshold price” to figure out the latest moment that the short position must be covered:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*GKRztNuirW9EoljBZyrOCA.jpeg" /><figcaption>Illustration of Threshold Price in Bonding Curves</figcaption></figure><p>Let us define some variables for illustration purpose:</p><ul><li><strong><em>S</em></strong>: the number of reserved tokens from the sale of short selling;</li><li><strong><em>C</em></strong>: the number of reserved tokens as a collateral deposit;</li><li><strong><em>k</em></strong>: the number of bonded tokens that had been sold in short selling;</li><li><strong><em>f(x)</em></strong>: the analytic formula that defines the Bonding Curve, where <strong><em>x</em></strong> is the number of bonded token supply;</li><li><strong><em>Pt</em></strong>: the threshold price implies that the short position must be covered when the token price reaches this price;</li><li><strong><em>N</em></strong>: the token supply corresponding to the threshold price <strong><em>Pt</em></strong>;</li><li><strong><em>I</em></strong>: the <em>maximum value</em> of the accumulated interest that the short seller needs to pay the lender.</li></ul><p>We can define the equation to describe the constraint as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/0*xE_IMa9AQ8Y7mR5N.png" /></figure><p>This formula implies that the cost of reserved tokens used to cover the short position at the threshold price <strong><em>Pt</em></strong> should not exceed the <em>total available fund for purchase</em>, which is the sum of sale proceeds <strong><em>S</em></strong> and collateral deposit <strong><em>C</em></strong> excluding the maximum value of the accumulated interest <strong><em>I</em></strong>.</p><p>With this formula, we can solve for the variable <strong><em>N</em></strong> and further calculate the threshold price <strong><em>Pt</em></strong> = <strong><em>f(N)</em></strong>. Therefore, when the token price increases and reaches the threshold price <strong><em>Pt</em></strong>, the short seller must cover the short position to return the borrowed bonded token and pay the interests to the lender.</p><p>The threshold price represents the highest token price that the short seller can tolerate before he is forced to cover the short position.</p><p>Note that the threshold price will be updated when the <em>loan-shifting</em> happens. This is because the short seller needs to pay extra interest to the new lender and the variable <strong><em>I</em></strong> changes accordingly.</p><h3>4. Single Short Position Scenario</h3><p>Let us consider the scenario:</p><ul><li>one short seller has sold the borrowed bonded tokens and made the collateral deposit to the broker contract.</li><li>there is a new “buy” transaction from the users, which will move the token price upward.</li></ul><p>This is the exact moment the broker contract needs to determine whether the short position should be covered. Specifically, the broker contract will first calculate the token price after the new “buy” transaction is executed, and then <em>compare this calculated price with the threshold price of the short position</em>.</p><p>There are two different scenarios as shown in the figure below. The yellow shaded area shows the new “buy” transaction that pushes up the token price to be higher, while the blue shaded area indicates the covering of short position at the threshold price.</p><p>If these two shaded areas have overlap, the short position must be covered. Otherwise, the short position can remain to be open.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V-lnBeSGPZPNzbyXkq4yLw.jpeg" /><figcaption>Illustration of two different scenarios: Left: short position does not need to be covered; Right: short position must be covered before the buy transaction.</figcaption></figure><ul><li><strong>Left Scenario</strong>: the short position does not need to be covered because the price after the new “buy” transaction is lower than the threshold price. The short seller can tolerate more price increase and securely cover the short position in the future.</li><li><strong>Right Scenario</strong>: the short position must be covered first because the price after the new “buy” transaction is higher than the threshold price. The short seller has no way to securely cover the short position if the “buy” transaction is executed and moves the token price up.</li></ul><p>In the <strong>Right Scenario</strong>, the buyer of the new “buy” transaction may get a higher token price because the covering of short position moves up the token price. Therefore, the broker contract may need to confirm the new purchase token price with the buyer before executing the “buy” order. If the buyer disagrees with the new price, both transactions can be canceled.</p><h3>5. Reference</h3><p>[1] “<em>Short Squeeze</em>”, Wikipedia, <a href="https://en.wikipedia.org/wiki/Short_squeeze">https://en.wikipedia.org/wiki/Short_squeeze</a></p><p>[2] James Chen, “<em>Short Squeeze</em>”, Investopedia, Dec 8, 2017. <a href="https://www.investopedia.com/terms/s/shortsqueeze.asp">https://www.investopedia.com/terms/s/shortsqueeze.asp</a></p><p>This article is an on-going work and many pieces can be further improved. Feel free to send me comments: fang@oceanprotocol.com.</p><p>If you would like to know more, please follow <a href="https://twitter.com/gongf05?lang=en"><em>Fang Gong</em></a><em> </em>and Ocean Protocol on <a href="https://twitter.com/oceanprotocol">Twitter,</a> <a href="https://t.me/joinchat/GUyxrE0Hi154D0NrlOqLFg">Telegram</a>, <a href="https://www.linkedin.com/company/ocean-protocol/">LinkedIn</a>, <a href="https://www.reddit.com/r/oceanprotocol/">Reddit</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d9da68324fb" width="1" height="1" alt=""><hr><p><a href="https://blog.oceanprotocol.com/enabling-short-selling-in-bonding-curves-part-2-4d9da68324fb">Enabling Short Selling in Bonding Curves — Part 2</a> was originally published in <a href="https://blog.oceanprotocol.com/">Ocean Protocol</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enabling Short Selling in Bonding Curves — Part 1]]></title>
            <link>https://blog.oceanprotocol.com/enabling-short-selling-in-bonding-curves-part-1-af871ad75d40?source=rss-f1e17af9a3ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/af871ad75d40</guid>
            <category><![CDATA[bonding-curves]]></category>
            <category><![CDATA[homepage]]></category>
            <category><![CDATA[deeptech]]></category>
            <category><![CDATA[mechanism-design]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Fang Gong]]></dc:creator>
            <pubDate>Thu, 07 Mar 2019 11:44:14 GMT</pubDate>
            <atom:updated>2019-03-26T15:16:25.142Z</atom:updated>
            <content:encoded><![CDATA[<h3>Enabling Short Selling in Bonding Curves — Part 1</h3><p>In this series of articles, we investigate the short selling in Bonding Curves and introduce our design to show how it works. It is worth mentioning that this work is originally inspired by our discussion with <a href="https://medium.com/@Paul.Haas">Paul Kohlhaas</a> and <a href="https://medium.com/@gomox">Gonzalo Sainz Trápaga</a> from <a href="http://www.molecule.to/">Molecule</a>, but the solution represents our internal research at Ocean Protocol.</p><h4>There are four articles in this series:</h4><p><strong>Part 1: Overview of Short Selling Design in Bonding Curves</strong><br><a href="https://blog.oceanprotocol.com/enabling-short-selling-in-bonding-curves-part-2-4d9da68324fb">Part 2: Simple Scenario with Single Short Position </a><br><a href="https://blog.oceanprotocol.com/enabling-short-selling-in-bonding-curves-part-3-6c2dd4eae4d7">Part 3: Complex Scenario with Multiple Short Positions</a><br><a href="https://blog.oceanprotocol.com/enabling-short-selling-in-bonding-curves-part-4-bf97772194a1">Part 4: Performance &amp; Privacy Improvement</a></p><h3>Part 1: Overview of Short Selling Design in Bonding Curves</h3><h3>1. Introduction</h3><p>Bonding Curves [<a href="https://medium.com/@simondlr/introducing-curation-markets-trade-popularity-of-memes-information-with-code-70bf6fed9881">1</a>][<a href="https://medium.com/@simondlr/tokens-2-0-curved-token-bonding-in-curation-markets-1764a2e0bee5">2</a>] had been introduced to tokenize assets with mintable bonded tokens and serve as an automatic market maker [<a href="https://blog.oceanprotocol.com/introducing-the-equilibrium-bonding-market-e7db528e0eff">3</a>] for token exchange. The bonded token can be purchased with reserved tokens such as Ether and its price is deterministically determined by the Bonding Curve &amp; token supply. Usually, the token price increases as more bonded tokens are minted and sold through the Bonding Curves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*pgU7Ee6F20480FZUqICzWg.jpeg" /><figcaption>Illustration of Bonding Curves</figcaption></figure><p>Users can sell bonded tokens into the Bonding Curves to decrease the token supply and push down the token price, which is a negative signal for the market value of the associated asset. However, this approach requires users to purchase bonded tokens before they can place a sell order.</p><p>In this article, we investigate an alternative approach to generate a negative signal called “<strong>Short Selling</strong>”:</p><blockquote>Short selling is the sale of a security that the seller has borrowed…Short seller sells to open the position and expects to buy it back later at a lower price and will keep the difference as a gain…Since the risk of loss on a short sale is theoretically unlimited, short selling should only be done by experienced traders. [<a href="https://www.investopedia.com/terms/s/shortselling.asp">4</a>].</blockquote><p>When the interest in an asset becomes irrationally high, short sellers come in to prevent asset from rising on hype so that to rationalize the market.</p><p>We will explore the approach to develop a similar technique and potentially alleviate the pump and dump behavior, which is a major attack vector around the Bonding Curves.</p><h3>2. Background</h3><p>In the existing stock market, <strong>Short Selling</strong> involves the sale of stock shares that the seller does not own or the seller borrows from the broker. They believe that stock price will decline in the future so they can buy at a “lower” price to make a profit.</p><p>However, if the stock price moves up, the short seller will be forced to cover the short position by purchasing stock shares at a higher price, which is called “<strong>Short Squeeze</strong>”. In this case, the short seller loses money!</p><p>The short selling process can be illustrated with 4 steps as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hrrp-ltZHLAqGeNLH7wE1A.jpeg" /><figcaption>Illustration of Short Selling trading technique.</figcaption></figure><p>The essential components involved in short selling include:</p><ul><li><strong>Lender</strong>: purchases stock shares and keeps them in the broker.</li><li><strong>Broker</strong>: borrows stock shares to short sellers for interests.</li><li><strong>Short Seller</strong>: borrows &amp; sells stock from the broker and returns it later.</li><li><strong>Market</strong>: executes the trading orders of stock shares.</li></ul><h3>3. Short Selling Design in Bonding Curves</h3><p>First of all, we need to identify similar components in our short selling design:</p><ul><li><strong>Lender</strong>: buy bonded tokens and send to the broker contract for lending.</li><li><strong>Broker</strong>: the contract to lend tokens and cover the short position if needed.</li><li><strong>Short Seller</strong>: borrow &amp; sell bonded tokens; deposit Ethers as collaterals.</li><li><strong>Market</strong>: Bonding Curves as an automatic market maker.</li></ul><p>With these settings, the overall workflow can be illustrated as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*wJCVcJqnygkFCmYaz20nYA.jpeg" /><figcaption>Overview of Short Selling Design in Bonding Curves</figcaption></figure><ul><li><strong>Step 1</strong>: lenders purchase bonded tokens from Bonding Curves and send those tokens to broker contract for lending;</li><li><strong>Step 2</strong>: short sellers borrow bonded tokens from the broker contract and sell those tokens into Bonding Curves; in the meantime, short sellers deposit reserved tokens (i.e., Ether) as the collaterals to broker contract.</li><li><strong>Step 3</strong>: broker contract automatically covers the short position using both proceeds from the sale of short selling and collateral deposit if needed. Otherwise, short sellers can close the short position and make profits.</li><li><strong>Step 4</strong>: broker contract distributes interest to the lender and allows the short seller to withdraw the profit if there is any.</li></ul><p>There may be a question from the audience: a lender wants to lend tokens for short selling due to the interest income. However, the short seller will push down the token price, therefore, making the lender lose money. Why lenders will provide the tokens if they have the risk of loss?</p><p>It is true that rational lenders need to trade off between token value and the interest income. If the asset has great value, its token price will climb back to be high after the short selling due to the strong token demand. Therefore, the lender can earn both gains due to token price appreciation and interest income. It encourages lenders to investigate the value of assets and spend their money to buy bonded tokens of assets with great value only.</p><h3>4. Broker Contract Design</h3><p>The broker contract is very critical in the short selling design. It is noteworthy that we may leverage other DeFi protocols like <a href="https://compound.finance/">Compound</a>, <a href="https://0x.org/">0x</a>, or even <a href="https://cdp.makerdao.com/">Collateralized Debt Positions (CDPs) on Maker </a>to fulfill certain roles of the broker contract. This could potentially enable a lot of functionalities.</p><p>For illustration and simplicity purpose, we will present our proposed data structure to implement the broker contract in this section, which facilitates the broker contract to find available bonded tokens and lend those tokens to short sellers upon their request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*gKBaAi2UfXsaHQUruXjgmg.jpeg" /><figcaption>Data Structure for Broker Contract Design</figcaption></figure><ul><li>a global hashtable “<em>token2dll</em>” that maps a specific bonded token to its corresponding double linked list (DLL) data structure;</li><li>the DLL consists of all available bonded tokens for lending.</li></ul><p>With the help of this core data structure, we can cope with the key problems in the broker contract design now.</p><ul><li><em>how to match the lending &amp; borrowing orders to fulfill the borrowing request?</em></li></ul><p>When the broker contract receives the borrowing request from the short seller, it will access the DLL of the requested bonded token to lend the next available tokens to the short seller.</p><p>The broker contract may lend tokens from multiple lenders to fulfill the requested amount if one single lender cannot.</p><ul><li><em>what if lender requests to withdraw bonded tokens that had been lent and sold by the short seller?</em></li></ul><p>The broker contract will find the next available bonded tokens to fulfill the withdrawal request from the original lender. As such, the loan of bonded tokens will be shifted to new lenders (aka “<strong>loan-shifting</strong>”), who will receive the bonded tokens and interests from short sellers.</p><p>If there is no new lender available and the loan cannot be shifted, the broker contract will force to close the short position and return the bonded tokens to the lender.</p><ul><li><em>how to calculate the interest for lending?</em></li></ul><p>In the stock market, the interest of stock shares borrowed from the broker is calculated based on dynamic stock price and accumulated over time. However, the same approach demands very expensive on-chain computations in the case of Bonding Curves, therefore, making it infeasible for our design.</p><p>Instead, we calculate the interest based on the <em>token amount</em> and <em>lending period</em>, which accumulates over time. When short sellers cover their short positions or the broker contract shifts loan to new lenders, the interests will be calculated and paid out to the lenders.</p><p>The curve of interest accumulation can be illustrated as below diagram. It increases faster at the beginning and the growth rate slows down over time. It encourages more lenders to participate in lending.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*byjaw7LIHC5FSql-j24Oiw.jpeg" /><figcaption>Diagram of interest accumulation over time.</figcaption></figure><p>Also, there is a cap for the total interest that a short seller needs to pay for the bonded tokens borrowed from <em>the same lender</em>. Once the total interest amount hits the cap after a specified period (e.g., one month), the lender tends to withdraw his tokens, which will trigger the loan-shifting. As such, the interest is reset to be zero and starts to accumulate again for the new lender.</p><h3>5. Reference</h3><p>[1] Simon de la Rouviere, “<em>Introducing Curation Markets: Trade Popularity of Memes &amp; Information</em>”, Medium Blog Post, May 2017 [Online]. Available: <a href="https://medium.com/@simondlr/introducing-curation-markets-trade-popularity-of-memes-information-with-code-70bf6fed9881">https://medium.com/@simondlr/introducing-curation-markets-trade-popularity-of-memes-information-with-code-70bf6fed9881</a></p><p>[2] Simon de la Rouviere, “<em>Tokens 2.0: Curved Token Bonding in Curation Markets</em>”, Medium Blog Post, Nov. 2017. [Online]. Available: <a href="https://medium.com/@simondlr/tokens-2-0-curved-token-bonding-in-curation-markets-1764a2e0bee5">https://medium.com/@simondlr/tokens-2-0-curved-token-bonding-in-curation-markets-1764a2e0bee5</a></p><p>[3] Fang Gong, “<em>Introducing the Equilibrium Bonding Market</em>”, Sept. 2018. [Online]. Available: <a href="https://blog.oceanprotocol.com/introducing-the-equilibrium-bonding-market-e7db528e0eff">https://blog.oceanprotocol.com/introducing-the-equilibrium-bonding-market-e7db528e0eff</a></p><p>[4] James Chen, “<em>Short Selling</em>”, Dec. 7, 2018. [Online]. Available: <a href="https://www.investopedia.com/terms/s/shortselling.asp">https://www.investopedia.com/terms/s/shortselling.asp</a></p><p>This article is an on-going work and many pieces can be further improved. Feel free to send me comments: fang@oceanprotocol.com.</p><p>If you would like to know more, please follow <a href="https://twitter.com/gongf05?lang=en"><em>Fang Gong</em></a><em> </em>and Ocean Protocol on <a href="https://twitter.com/oceanprotocol">Twitter,</a> <a href="https://t.me/joinchat/GUyxrE0Hi154D0NrlOqLFg">Telegram</a>, <a href="https://www.linkedin.com/company/ocean-protocol/">LinkedIn</a>, <a href="https://www.reddit.com/r/oceanprotocol/">Reddit</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af871ad75d40" width="1" height="1" alt=""><hr><p><a href="https://blog.oceanprotocol.com/enabling-short-selling-in-bonding-curves-part-1-af871ad75d40">Enabling Short Selling in Bonding Curves — Part 1</a> was originally published in <a href="https://blog.oceanprotocol.com/">Ocean Protocol</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing the Equilibrium Bonding Market]]></title>
            <link>https://blog.oceanprotocol.com/introducing-the-equilibrium-bonding-market-e7db528e0eff?source=rss-f1e17af9a3ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7db528e0eff</guid>
            <category><![CDATA[automated-market-maker]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[homepage]]></category>
            <category><![CDATA[deeptech]]></category>
            <category><![CDATA[bonding-curves]]></category>
            <dc:creator><![CDATA[Fang Gong]]></dc:creator>
            <pubDate>Thu, 06 Sep 2018 14:16:36 GMT</pubDate>
            <atom:updated>2018-09-06T14:16:36.676Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This article presents a new automated market maker design that overcomes issues with bonding curves, for application to curation and staking. It is called “equilibrium bonding market” because it provides the equilibrium price of the bonded token.</blockquote><h3>1. Introduction</h3><p>The bonding curve serves as an <em>automatic market-maker</em> to a bonded token without relying on any exchange:</p><ul><li><strong>Buy Bonded Token</strong>: Users can send “reserved token” (i.e., Ether) into the bonding contract and receive “bonded token” at any time.</li><li><strong>Sell Bonded Token</strong>: Users can send “bonded token” back to the bonding contract and receive “reserved token” at any time.</li></ul><p>The bonded tokens are associated with certain assets (e.g., dataset, computing service, etc.) and implicitly represent the stakes on the asset. Users can stake by buying bonded tokens and un-stake by selling bonded tokens.</p><p>The exchange ratio is determined by the bonding curve, which calculates the price of bonded token according to its supply. Usually the price increases as the number of issued bonded tokens increases. In addition, the exchange ratios for buying and selling are dynamically changing, therefore, users can either make profits or lose their money.</p><p>For more details, here are the original references <a href="https://blog.relevant.community/how-to-make-bonding-curves-for-continuous-token-models-3784653f8b17">[1]</a> <a href="https://medium.com/@simondlr/tokens-2-0-curved-token-bonding-in-curation-markets-1764a2e0bee5">[2]</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YML-2ao-7rkyYwcVooJ6-Q.jpeg" /><figcaption>Bonding curve as an automatic market-maker</figcaption></figure><p>Bonding curves became popular recently due to its application in staking and curation. However, existing bonding curves are public and pre-defined (i.e., defined as an analytical formula) so bonding contract offers token prices based on curves that are not equilibrium prices. In addition, attackers can predict the price of bonded tokens according to curves and easily speculate for profits by deliberately buying low and selling high. For example, “pump and dump” and “front running attack” are typical attack vectors.</p><h3>2. Properties of Automated Market Maker</h3><p>The essential properties of <em>automated market maker</em> designs are <strong>conservation</strong>, <strong>liquidity</strong>, and <strong>equilibrium</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*8CzPW4TZX5PTy1zaJediHw.jpeg" /><figcaption>The essential properties of automated market maker</figcaption></figure><ul><li>“<em>Automated</em>” implies “<strong>liquidity</strong>”: the “automated” market should always offer to sell tokens to buyers and buy back tokens from sellers at any time.</li><li>“<em>Market maker</em>” requires “<strong>Equilibrium</strong>” and “<strong>Conservation</strong>”. <br>1. “<a href="https://en.wikipedia.org/wiki/Economic_equilibrium"><strong>Equilibrium</strong></a>” is a <em>balanced</em> state determined by demand and supply together in the market and will not change until demand or supply changes. In particular, the equilibrium price is established through the bidding competition between buyers and sellers in the market. <br>2. “<strong>Conservation</strong>” means the total value of bonded tokens should match the balance of reserved tokens at any time. Users can never sell all bonded tokens and get more reserved tokens than the amount they put in. The value in the market complies with the conservation law similar to the energy conservation law in Physics.</li></ul><p>I aim to create a design that achieves all three properties.</p><h3>3. Equilibrium Bonding Market</h3><p>Here is the proposed solution called “<strong>Equilibrium Bonding Market (EBM)</strong>”. I now elaborate.</p><h4>Proposed Solution</h4><ol><li><strong>Scarcity</strong>: there is a cap to the bonded token supply in EBM. This is different from existing bonding curves, which have no limit on the total supply. When all bonded tokens are sold out, new buyers can only purchase tokens from existing holders.</li><li><strong>Liquidity</strong>: EBM operates pretty much as an “<em>order book</em>” and requires buyers to place a new sell order immediately after they buy an order. As such, the entire volume of bonded tokens in EBM is always on the order book available for sell, therefore, providing increased liquidity under limited token supply.</li><li><strong>Two-Stage Operation:</strong></li></ol><ul><li><strong>Fixed-price stage</strong>: As shown in the below figure, the bonded tokens are available for buy and sell at the <em>fixed price</em> until all tokens are sold out. With the fixed price, speculators have no interests to buy as they make no profit at this time. Only true believers of the asset associated with the bonded tokens will buy, because they believe the asset will become more valuable in the future.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*41jeZ2_DeAG5F6y8zWHBLQ.jpeg" /><figcaption>Illustration of Fixed-Price Stage in EBM</figcaption></figure><ul><li><strong>Price-discovering stage</strong>: When all available bonded tokens are sold out, the market enters price-discovering stage, where the purchase price of bonded token is determined by demand and supply. As shown in the figure below, holders have different sold prices for their holdings.<br>(a) When buyers purchase the bonded tokens, they must set “<em>target sell price</em>” and smart contract automatically places a new sell order for their holdings. The target sell price can be changed later to be either higher or lower than the cost basis.<br>(b) New buyers pay the lowest target sell price to purchase bonded tokens from existing holders. <em>This transaction is executed automatically </em>by the smart contract, which increases the liquidity of the market.<br>(c) If there is no buyer available, the seller can sell the bonded tokens to the market at the <em>fixed price</em> at any time, which complies with the conservation law.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qB31JS3M5TdO5mc4Kfto7A.jpeg" /><figcaption>Illustration of Price-discovering Stage in EBM</figcaption></figure><ul><li>The market can switch between these two stages without restrictions. For example, it can switch from the price-discovering stage into the fixed-price stage when bonded tokens are sold back into the market and become available for purchase with fixed price again.</li></ul><h4><strong>Design Comparison</strong></h4><p>We compare <em>Bonding Curve</em> (BC) [<a href="https://blog.relevant.community/how-to-make-bonding-curves-for-continuous-token-models-3784653f8b17">1</a>][<a href="https://medium.com/@simondlr/tokens-2-0-curved-token-bonding-in-curation-markets-1764a2e0bee5">2</a>] and <em>Equilibrium Bonding Market</em> (EBM) as following:</p><ul><li><strong>Conservation &amp; Liquidity</strong>: both designs offer high liquidity (i.e. always offer to sell tokens to buyers and buy back tokens from sellers at any time) and comply with conservation law.</li><li><strong>Equilibrium</strong>: BC offers token prices with formulae/curves, which are different from the equilibrium prices in the actual market. On the contrary, EBM provides equilibrium prices through price discovery process which are solely determined by demand and supply in the market.</li></ul><p>Note that the <em>interactive coin offerings</em> proposed in [<a href="https://people.cs.uchicago.edu/~teutsch/papers/ico.pdf">3</a>] tries to reach “fair valuation equilibrium” in crowd sales, which allows buyers to submit bids with target valuation and voluntarily withdraw their bids. This design provides “equilibrium” as well but token holders can never sell tokens back into the contract at any time. In addition, it is mainly used for crowd sales, while EBM is designed for staking and curation.</p><h3>4. User Story</h3><p>We use a simplified example with Alice, Bob and Carlos to walk through the user story of EBM:</p><p><strong><em>Settings</em></strong>: there are <strong>total 100 bonded tokens available</strong> and the <strong>fixed price is 1 Ether per bonded token</strong>.</p><ul><li>Alice purchases 50 bonded tokens with price = 1 Ether/token, and sets target sell price to be 2 Ether/token. The market has reserved token balance of 50 Ether.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OB61TQIweLsikWk2Uune7A.jpeg" /></figure><ul><li>Bob purchases 50 bonded tokens with price = 1 Ether/token, and sets his target sell price to be 3 Ether/token. <strong>All bonded tokens are sold out at this time. </strong>The market has the reserved token balance of 100 Ether.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mo-oI7myq-UFvRsj43geQA.jpeg" /></figure><ul><li>Carlos comes to buy 50 bonded tokens, and he <strong>chooses the lowest target sell price</strong> at 2 Ether/token set by Alice. <br>Note: if Carlos wants to buy 80 bonded tokens, he must first buy 50 tokens from Alice at price=2 Ether/token and then buy the other 30 tokens from Bob at price = 3 Ether/token.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SQvwpu6q4kqr6fECdPaY-g.jpeg" /></figure><ul><li>Carlos desires to buy 50 bonded tokens right now and will to pay the price of 2 Ether/token. <br>He makes the payment of 100 Ether to Alice and <strong>the transaction is automatically executed by the smart contract!</strong> <br>Alice makes a profit of 50 Ether and Carlos gets 50 bonded tokens! The market has the same balance of 100 Ether.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pd6CtiVGaNfFqN4kLA0lFQ.jpeg" /></figure><ul><li>Carlos really needs to sell his bonded tokens but there is no buyer at this time. He can only sell tokens at the fixed price of 1 Ether/token. He sells all his bonded tokens and gets 50 Ether back. <strong>Carlos loses 50 Ether!</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gi1B1niccJq_5KZkGvnzdQ.jpeg" /></figure><p><strong>Observations</strong> <strong>about EBM:</strong></p><ul><li>EBM compels new buyers to make careful purchase decisions because they will lose money by selling at the fixed price. To make a wise purchase decision, new buyer must do more due diligence on the assets associated with the bonded tokens and truly believe in the high quality of those assets. In this process, new buyers become curators of the assets and payments of reserved tokens represent their stakes on the assets.</li><li>Speculators cannot make profits if they set target sell price extremely high and there is no buyer available. They must take great loss by selling at the fixed price in order to liquidate bonded tokens and get their reserved tokens back. It discourages speculators from flipping the bonded tokens and dramatically reduces the probability of attacks.</li><li>Comparing the market cap of various bonded tokens (i.e., average sold price × total number of sold bonded tokens) can measure the <em>staking</em> on corresponding assets and generate “signals” for high quality assets. It helps curation market to rank various assets and maintain a trustworthy registry consisting of high quality assets.</li></ul><h3>5. Conclusion</h3><p>In this article, I proposed the Equilibrium Bonding Market (EBM) to address the issues and prevent attacks of existing bonding curves. It provides all required properties of an <em>automated market maker</em>: conservation, liquidity and equilibrium. In practical application, EBM can be used for staking and curation.</p><h3>Acknowledgements</h3><p>Special thanks to <a href="https://medium.com/@trentmc0">Trent McConaghy</a>, <a href="https://medium.com/@DimitriDeJonghe">Dimitri de Jonghe</a> and <a href="https://medium.com/@don_gossen">Don Gossen</a> for insightful reviews and suggestions, which significantly improve the quality of this article.</p><p>This article is an on-going work and many pieces can be further improved. Feel free to send me comments: fang@oceanprotocol.com.</p><p>If you would like to know more, please follow <a href="https://twitter.com/gongf05?lang=en">Twitter</a>, <a href="https://www.linkedin.com/in/fang-gong-65413712/">LinkedIn</a> and Ocean Protocol on <a href="https://twitter.com/oceanprotocol">Twitter,</a> <a href="https://t.me/joinchat/GUyxrE0Hi154D0NrlOqLFg">Telegram</a>, <a href="https://www.linkedin.com/company/ocean-protocol/">LinkedIn</a>, <a href="https://www.reddit.com/r/oceanprotocol/">Reddit</a>.</p><h3>References</h3><p>[1] Slava Balasanov, “<em>How to Make Bonding Curves for Continuous Token Models</em>”, Medium Blog Post, Feb. 2018. [Online]. Available: <a href="https://blog.relevant.community/how-to-make-bonding-curves-for-continuous-token-models-3784653f8b17">https://blog.relevant.community/how-to-make-bonding-curves-for-continuous-token-models-3784653f8b17</a></p><p>[2] Simon de la Rouviere, “<em>Tokens 2.0: Curved Token Bonding in Curation Markets</em>”, Medium Blog Post, Nov. 2017. [Online]. Available: <a href="https://medium.com/@simondlr/tokens-2-0-curved-token-bonding-in-curation-markets-1764a2e0bee5">https://medium.com/@simondlr/tokens-2-0-curved-token-bonding-in-curation-markets-1764a2e0bee5</a></p><p>[3] Jason Teutsch, Vitalik Buterin, Christopher Brown, “<em>Interactive coin offerings</em>”, technical paper, Dec. 2017. [Online]. Available: <a href="https://people.cs.uchicago.edu/~teutsch/papers/ico.pdf">https://people.cs.uchicago.edu/~teutsch/papers/ico.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7db528e0eff" width="1" height="1" alt=""><hr><p><a href="https://blog.oceanprotocol.com/introducing-the-equilibrium-bonding-market-e7db528e0eff">Introducing the Equilibrium Bonding Market</a> was originally published in <a href="https://blog.oceanprotocol.com/">Ocean Protocol</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decentralized Web Summit 2018 — Highlights]]></title>
            <link>https://blog.oceanprotocol.com/decentralized-web-summit-2018-highlights-a6376edefb01?source=rss-f1e17af9a3ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6376edefb01</guid>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[token-engineering]]></category>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[community]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Fang Gong]]></dc:creator>
            <pubDate>Fri, 10 Aug 2018 09:39:17 GMT</pubDate>
            <atom:updated>2018-08-10T09:39:17.415Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Locking the Web Open for Good</strong></h4><blockquote>Written by <a href="https://twitter.com/gongf05?lang=en">Dr. Fang Gong</a> with contributions from <a href="https://twitter.com/DimitriDeJonghe?lang=en">Dr. Dimitri De Jonghe</a>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nTBWfl_wUzRryiaLm_aKLg.jpeg" /><figcaption>From left: Christopher Allen, Ted Nelson, Tim Berners-Lee, Vint Cerf, Brewster Kahle (photo Dimitri De Jonge)</figcaption></figure><h3>1. Introduction</h3><p>The <em>Decentralized Web Summit</em> (July 31 — August 2, 2018) in San Francisco is one of the top events of the year for those who share our vision towards decentralization and the dawn of Web 3.0. Our team was there on the ground (and on the stage) to be a part of the disruption. This article highlights the activities of our team and some great talks from experts in the summit.</p><h3>2. Builders Day + Science Fair</h3><h3>Dimitri De Jonghe on Twitter</h3><p>Geeking out on the science fair at #DWebSummit with @oceanprotocol and jellyfish</p><p>The Science Fair was a part of Builders day, which had 130 selected people with one common goal: to lock the web open for good. We explored everyone’s efforts in decentralizing the web, but there were also selected topics with rountables- we attended the Decentralized Access Control and the Governance ones. The main outcomes:</p><ul><li>Decentralized Access control — The future of private key management and how to reconcile web2.0 services with web3.0 smart contracts.</li><li>Governance — We can absolutely explore digital governance; we have the tools to measure opinion, impact and accountability.</li></ul><h3>3. The Journey to Web 3 Talks</h3><h4>3.1 Peter Czaban from Web3Foundation</h4><h3>Web3 Foundation on Twitter</h3><p>Peter Czaban presents the #web3 tech stack and lays out the journey to Web3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tDfl9mBNG5RmfsMF51CUzQ.jpeg" /></figure><p>Peter gave a high-level talk about the Web3 technology stack, in which the main point was this: In order to bring Web3 to life, we need to build decentralized applications with this technology stack, which conform to certain necessary constraints:</p><ul><li>No user is privileged over other users (all users have equal rights);</li><li>The roles of all users are clearly defined; and</li><li>No trust between peers is required</li></ul><p>Web3 needs all these technologies to work together and they can reuse different technologies. From bottom-up:</p><ul><li>P2P protocol is built to connect to other nodes;</li><li>Universal way of computation like Ethereum Virtual machine (EVM) and Web Assembly (WASM);</li><li>Some protocols like Polkadot are needed to bridge the gap between different blockchains and allow them to send messages to each other.</li><li>Second layer protocols enable super-fast transactions and high though-put. These technologies, such as state channel and plasma, can be built on top of lower-level protocols and offload heavy computations to off-chain.</li><li>To enable developers to easily access those protocols and build applications on top of them, we need new APIs and languages.</li><li>Finally, browsers and user interfaces (i.e., MetaMask) are needed to enable real applications and allow users to access those protocols.</li></ul><p>Various worldwide projects are working on different levels, and making great progress to improve their work. It is fantastic to see people alinging bringing the Web3 stack together!</p><h4>3.2 Dr. Dimitri De Jonghe from Ocean Protocol</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Y79bMU2t-zUTb1X2t70aA.png" /></figure><p>Our Head of Research Dimitri introduced Ocean Protocol to the rapt crowd. Big companies know data is the most important component to an intelligent ecosystem, and they therefore silo huge quantities of personal data about user behavior online. With so much personal data under their sole control, these companies can misguide people towards biased outcome, detrimental to the natural and lucid decision-making process. Furthermore, people’s personal data lies entirely outside of their own control.</p><p>At Ocean Protocol, we are working to democratize access to data &amp; AI and build a decentralized community by connecting several parties: enterprises who own lot of data, AI startups who have algorithms, and scientists who can use this data to improve their algorithms. Ocean brings data, algorithm and computing power together to provide analytics with intelligent outcome. In this process, we can build curations of data, which signal data sets that are believed to be more valuable (see our Ocean for Data Scientists <a href="https://blog.oceanprotocol.com/feeding-a-data-hungry-world-8d43ca22c62">blog</a>).</p><p>One use case for Ocean: AVDEX // Autonomous Vehicles Data Exchange via the <a href="https://www.dlt.mobi/">MOBI consortium</a> of leading automakers etc. Self-driving car companies need more than 1 trillion miles of driving data, therefore, it is of utmost importance to build a community with incentivized users to provide their driving data.</p><h3>4. Token Engineering Workshop</h3><p>We also led a lively workshop in <a href="http://tokenengineering.net/">the nascent field of #TokenEngineering</a>, with speakers <a href="https://www.linkedin.com/in/mczargham/">Michael Zargham</a> (founder of <a href="https://twitter.com/block_science">BlockScience</a>), <a href="https://twitter.com/Fennie_Wang">Fennie Wang</a> from <a href="https://twitter.com/ixo_impact">IXO Impact</a>, and of course Dimitri from Ocean.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y9d1ZP5-lbkYWJr0PDrp3g.png" /></figure><p>Main takeaway? <a href="https://twitter.com/Fennie_Wang">Fennie</a> discussed the practical difficulties in designing tokens that measure social impact and outcomes of user activities. One great challenge is that existing token design tends to attach economic value to easier-to-measure activities. However, it will incentivize users to focus on activities with short-term benefits while ignoring the long-term social impact.</p><p>Additionally, creators of tokenized ecosystems usually do not have a clear formulation of token design goals before they get started, leading to the eventuality that the design of the token ecosystem cannot solve the target problem in real world. Therefore, we need to pay attention to the formulation of the ultimate design goal, so we can better identify the potential challenges and mitigate them with engineering discipline. What we <em>should</em> design is every bit as vital as <em>what </em>we design.</p><p>Blockchain is a public utility network, and its objective is to reward useful and proven behavior, using minting new tokens in each block. Token engineering is cross-discipline (combining game theory + token incentives + social behavior + governance), and therefore it requires the fusion of in-depth knowledge from many disciplines. Current token design practice: start from scratch, find potential way that it can fail, and improve it. It is not an efficient approach and can be improved by Token Engineering Canvas:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*nPamQGdg_MUFZQSdEffoKQ.png" /><figcaption>Token engineering canvas (Created by <a href="https://twitter.com/nembal">Balasz Nemethi</a> at <a href="https://twitter.com/Taqanu">Taqanu</a>)</figcaption></figure><p>More efficient steps in Token Ecosystem Design:</p><ul><li>Formulate the problem (i.e., objectives, constraints, and design space),</li><li>Try an existing building block and evaluate on objectives &amp; constraints (i.e., try different formulations or solvers like curation, identity, reputation, governance, proofs of X, etc.),</li><li>Design new building block or design patterns. Then, evaluate them on objectives &amp; constraints. Select the best design that meets the objective and satisfies all the contraints.</li></ul><h3>5. Web Legends!</h3><p>And last but certainly not least of our Decentralized Web Summit highlights….</p><h3>Dimitri De Jonghe on Twitter</h3><p>SSL + Xanadu + WWW + tcp/ip + Internet archive! Hat tip for bringing the world closer together ❤️ #DWebSummit @ChristopherA @tednelson @timberners_lee @vgcerf @brewster_kahle</p><p>We managed to score this snap of five true living legends, who have changed everything for us. From left to right:</p><ul><li><a href="https://twitter.com/ChristopherA">Christopher Allen</a>: Internet Cryptography Pioneer — Co-author TLS Security Standard</li><li>Ted Nelson: founder of <a href="http://www.xanadu.net/">Xanadu</a> project founded in 1960, which was the first hypertext project.</li><li><a href="https://twitter.com/timberners_lee">Tim Berners-Lee</a>: best known as the inventor of the World Wide Web.</li><li><a href="https://en.wikipedia.org/wiki/Vint_Cerf">Vint Cerf</a>: an American Internet pioneer, who is recognized as one of “the fathers of the Internet”, sharing this title with TCP/IP co-inventor Bob Kahn.</li><li><a href="https://twitter.com/brewster_kahle?lang=en">Brewster Kahle</a>: an American computer engineer, Internet entrepreneur, internet activist, advocate of universal access to all knowledge, and digital librarian. Kahle founded the Internet Archive.</li></ul><p>It was a great honor to meet these pioneers of the Internet. Their extraordinary work brought people from all corners of the globe closer together, and forever changed the course of history. Thanks guys!</p><h3>6. Conclusion</h3><p>Our team came away from <em>Decentralized Web Summit </em>with new ideas to be incorporated into our practice, key lessons from peers in the community, and insights on the future directions. Ocean is honored to be a part of this Web 3.0 disruption and making our own contributions. Thanks to the organizers and speakers for such a great event! Reunion again in 2019?</p><p>Ready to dive in? Follow Ocean Protocol on <a href="https://twitter.com/oceanprotocol">Twitter,</a> <a href="https://t.me/joinchat/GUyxrE0Hi154D0NrlOqLFg">Telegram</a>, <a href="https://www.linkedin.com/company/ocean-protocol/">LinkedIn</a>, <a href="https://www.reddit.com/r/oceanprotocol/">Reddit</a>. Be with us for every step of our BUIDLing journey- subscribe to our <a href="https://oceanprotocol.com/newsletter/">Newsletter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6376edefb01" width="1" height="1" alt=""><hr><p><a href="https://blog.oceanprotocol.com/decentralized-web-summit-2018-highlights-a6376edefb01">Decentralized Web Summit 2018 — Highlights</a> was originally published in <a href="https://blog.oceanprotocol.com/">Ocean Protocol</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>