{"id":1550,"date":"2019-07-02T15:57:29","date_gmt":"2019-07-02T07:57:29","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=1550"},"modified":"2019-07-03T13:44:43","modified_gmt":"2019-07-03T05:44:43","slug":"ep-01-defi-connoisseur-uniswap","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/ep-01-defi-connoisseur-uniswap\/","title":{"rendered":"EP 01. Defi \u5408\u7ea6\u9274\u8d4f\u4e4b Uniswap\uff08WIP\uff09"},"content":{"rendered":"<p><a href=\"https:\/\/www.facebook.com\/gsetcrw\/posts\/2254226074631843\">\u524d\u4e9b\u65e5\u5b50\u548c Roger Wu \u8ba8\u8bba<\/a>\uff0c\u8981\u4e0d\u8981\u5199\u4e00\u672c Defi \u5408\u7ea6\u9274\u8d4f\u7684 Booklet\uff0c\u4f46\u662f\u6211\u4eec\u4f3c\u4e4e\u90fd\u8981\u9762\u4e34\u548c <a href=\"https:\/\/www-cs-faculty.stanford.edu\/~knuth\/taocp.html#vol4\">Donald E. Knuth. \u540c\u6837\u7684\u95ee\u9898<\/a>\uff0c\u5199\u7684\u901f\u5ea6\u8fd8\u6ca1\u6709\u884c\u4e1a\u7684\u53d1\u5c55\u5feb\u3002\u4e8e\u662f\u6211\u4eec\u51b3\u5b9a\u91c7\u53d6\u300c\u5206\u800c\u6cbb\u4e4b\u300d\u4e4b\u7b56\u7565\uff0c\u4e3a\u4e86\u4e0d\u8ba9\u8fdb\u5ea6\u843d\u540e\u66f4\u591a\uff0c\u4e0d\u59a8\u8ba9\u6211\u5148\u627e\u4e00\u4e2a\u8f6f\u67ff\u5b50\u4e0b\u624b\u3002\u663e\u7136\u6240\u6709 Defi \u9879\u76ee\u4e2d\u6700\u8f6f\u7684\uff0c\u5c31\u8981\u6570 Uniswap \u4e86\u3002<\/p>\n<p>\u521a\u597d Uniswap \u7684\u521b\u59cb\u4eba Hayden Adams \u53c2\u52a0\u4e86 <a href=\"https:\/\/epicenter.tv\/episode\/292\/\">\u6700\u8fd1\u7684\u4e00\u671f Epicenter<\/a>\uff0c\u5728\u8fd9\u96c6 Podcast \u4e2d Hayden Adams \u8ba8\u8bba\u4e86\u8bb8\u591a\u5e55\u540e\u7684\u6545\u4e8b\uff0c\u6709\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u53bb\u56de\u987e\u3002<\/p>\n<h4>\u53c2\u8003\u8d44\u6599<\/h4>\n<ul>\n<li><a href=\"https:\/\/uniswap.io\/\">Protocol Website<\/a><\/li>\n<li><a href=\"https:\/\/docs.uniswap.io\/\">Documentation<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Uniswap\">Code<\/a><\/li>\n<li><a href=\"https:\/\/hackmd.io\/C-DvwDSfSxuh-Gd4WKE_ig\">Whitepaper<\/a><\/li>\n<\/ul>\n<p><!--more--><\/p>\n<h3>\u505a\u5e02\u673a\u5236 Market Maker Mechanism<\/h3>\n<p>Uniswap \u6700\u4e3a\u7a81\u51fa\u7684\u7279\u6027\u5c31\u662f\u5979\u7684\u505a\u5e02\u673a\u5236\uff08Market Maker Mechanism\uff09\u8db3\u591f\u7684\u7b80\u5355\u3002\u4e0e Bancor \u548c P3D \u7c7b\u4f3c\uff0cUniswap \u4e2d\u4e5f\u6ca1\u6709\u4f20\u7edf\u4ea4\u6613\u6240\u4e2d\u7684 Order Book\uff0c\u76f4\u63a5\u5728\u5408\u7ea6\u4e2d\u7528\u5e02\u4ef7\u4ea4\u6613\uff0c\u901a\u8fc7\u5408\u7ea6\u4e2d\u7684\u50a8\u5907\u91d1\u6765\u63d0\u4f9b\u6d41\u52a8\u6027\u3002<\/p>\n<p>\u6240\u4e0d\u540c\u7684\u662f\uff0cUniswap \u7684\u505a\u5e02\u673a\u5236\u66f4\u52a0\u7075\u6d3b\u548c\u666e\u9002\uff0c\u4e0d\u9700\u8981\u50cf Bancor \u4e00\u6837\u8bbe\u8ba1\u6240\u8c13\u7684 SmartToken \u548c\u56fa\u5b9a\u50a8\u5907\u91d1\u7387\u8fd9\u6837 <a href=\"https:\/\/www.jinse.com\/bitcoin\/249008.html\">\u591a\u4f59\u7684\u8bbe\u8ba1<\/a>\u3002\u5e76\u4e14\u5728 Uniswap \u7684\u5408\u7ea6\u4e2d\u6709\u673a\u5236\u53bb\u9f13\u52b1\u7528\u6237\u589e\u52a0\u4e24\u4e2a\u65b9\u5411\u50a8\u5907\u91d1\u6765\u63d0\u4f9b\u66f4\u591a\u7684\u6d41\u52a8\u6027\uff0c\u56e0\u800c\u4e0d\u4f1a\u56e0\u4e3a\u5e02\u573a\u7684\u589e\u957f\uff0c\u800c\u8ba9\u5408\u7ea6\u8f7b\u6613\u7684\u906d\u9047 Landslide\uff0c\u4f7f\u5f97\u7a33\u5b9a\u6027\u6210\u4e3a Token \u8fdb\u4e00\u6b65\u53d1\u5c55\u7684\u74f6\u9888\u3002<\/p>\n<p>\u5728 Token \u7684\u7684\u4ea4\u6613\u8fc7\u7a0b\u4e2d\uff0c\u6240\u7ef4\u6301\u7684\u4e0d\u53d8\u5f0f\uff08Invariant\uff09\u4e5f\u4ec5\u4ec5\u662f <strong>x*y = k<\/strong>\u3002<\/p>\n<p>\u867d\u7136 Uniswap \u6700\u8fd1\u624d\u589e\u957f\u8d77\u6765\uff0c\u4f46\u5b9e\u9645\u4e0a <strong>x*y = k<\/strong> \u662f\u4e00\u4e2a\u76f8\u5bf9\u53e4\u8001\u7684 idea\uff0c\u65e9\u5728 <a href=\"https:\/\/www.reddit.com\/r\/ethereum\/comments\/55m04x\/lets_run_onchain_decentralized_exchanges_the_way\/\">16 \u5e74 10 \u6708<\/a>\uff0cVitalik \u5c31\u5728 Reddit \u91cc\u63d0\u51fa\u5efa\u8bae\uff0c\u63a2\u8ba8\u7528\u8fd9\u79cd\u65b9\u6cd5\u5efa\u7acb\u4e00\u4e2a\u53bb\u4e2d\u5fc3\u5316\u4ea4\u6613\u6240\u7684\u53ef\u80fd\u6027\u3002\u968f\u540e\u5728 <a href=\"https:\/\/ethresear.ch\/t\/improving-front-running-resistance-of-x-y-k-market-makers\/1281\">18 \u5e74\u7684 5 \u6708<\/a>\uff0cVitalik \u53c8\u56de\u5230\u8fd9\u4e2a\u95ee\u9898\uff0c\u5e76\u4e14\u4ecb\u7ecd\u4e86\u4e00\u79cd\u9632\u6b62 Front Running Attacks \u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u56e0\u4e3a\u4ee5\u592a\u574a\u7684\u4ea4\u6613\u4ece\u53d1\u51fa\u5230\u786e\u8ba4\u4e2d\u95f4\u4f1a\u6709\u5ef6\u8fdf\uff0c\u6240\u4ee5\u4e8b\u5b9e\u4e0a\u4f60\u53ef\u4ee5\u62a2\u5148\u53d1\u9001 Gas \u8d39\u7528\u66f4\u9ad8\u7684\u8f6c\u8d26\u6765\u5229\u7528\u8fd9\u4e9b\u534a\u7a7a\u4e2d\u7684\u4ea4\u6613\u4fe1\u606f\u622a\u80e1\uff0c\u4ece\u800c\u8fdb\u884c\u65e0\u98ce\u9669\u5957\u5229\uff0c\u5f53\u65f6\u5305\u62ec Bancor\u3001Cryptokitty \u751a\u81f3 Crypto Country \u90fd\u66fe\u7ecf\u906d\u53d7\u8fc7\u6b64\u7c7b\u653b\u51fb\u3002 \u6211\u5728 Google \u7684\u795e\u540c\u4e8b <a href=\"https:\/\/hackernoon.com\/@ivanbogatyy\">Ivan Bogatyy<\/a> \u5f53\u65f6\u66fe\u7ecf\u5728 Mountainview \u7684 Google Cryptocurrency Monthly Meetup \u505a\u8fc7\u4e00\u671f\u5206\u4eab\uff0c\u5177\u4f53\u53ef\u4ee5\u53c2\u9605 <a href=\"https:\/\/hackernoon.com\/front-running-bancor-in-150-lines-of-python-with-ethereum-api-d5e2bfd0d798\">\u8fd9\u7bc7\u6587\u7ae0<\/a>\u3002<\/p>\n<p>\u5176\u4e2d x \u4e0e y \u5206\u522b\u8868\u793a\u951a\u5b9a\u7684\u4e24\u79cd Token\uff0c\u5728 Uniswap \u91cc\u662f ETH \u548c\u53e6\u4e00\u79cd ERC20\uff0c\u800c k \u4e3a\u4e00\u4e2a\u5b9a\u503c\uff0ck \u5728\u4ea4\u6613\u7684\u8fc7\u7a0b\u4e2d\u4e0d\u53d1\u751f\u53d8\u5316\u3002<\/p>\n<p><a href=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/5cde80046c11a2d4c30622a8362527a2973c195c.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1553\" data-permalink=\"https:\/\/www.shuizilong.com\/house\/archives\/ep-01-defi-connoisseur-uniswap\/5cde80046c11a2d4c30622a8362527a2973c195c\/\" data-orig-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/5cde80046c11a2d4c30622a8362527a2973c195c.png\" data-orig-size=\"297,261\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"5cde80046c11a2d4c30622a8362527a2973c195c\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/5cde80046c11a2d4c30622a8362527a2973c195c.png\" data-large-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/5cde80046c11a2d4c30622a8362527a2973c195c.png\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/5cde80046c11a2d4c30622a8362527a2973c195c.png\" alt=\"\" width=\"297\" height=\"261\" class=\"aligncenter size-full wp-image-1553\" \/><\/a><\/p>\n<p>\u6211\u4eec\u6765\u770b\u4e00\u4e0b Uniswap \u7684 Interface\uff0c\u6211\u4eec\u770b\u5230 Buy\/Sell \u5728 Uniswap \u91cc\u8fd9\u4e24\u4e2a\u64cd\u4f5c\u90fd\u53eb\u505a Swap\uff08\u6240\u4ee5\u53eb Uniswap\uff09\u3002\u4e0d\u5931\u4e00\u822c\u6027\uff0c\u4e0d\u59a8\u6211\u4eec\u9009 ETH\/DAI \u4ea4\u6613\u5bf9\u4e3e\u4f8b\u3002<\/p>\n<p><a href=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/\u5c4f\u5e55\u5feb\u7167-2019-07-02-\u4e0b\u53483.54.08.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1551\" data-permalink=\"https:\/\/www.shuizilong.com\/house\/archives\/ep-01-defi-connoisseur-uniswap\/%e5%b1%8f%e5%b9%95%e5%bf%ab%e7%85%a7-2019-07-02-%e4%b8%8b%e5%8d%883-54-08\/\" data-orig-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/\u5c4f\u5e55\u5feb\u7167-2019-07-02-\u4e0b\u53483.54.08.png\" data-orig-size=\"1174,982\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"\u5c4f\u5e55\u5feb\u7167 2019-07-02 \u4e0b\u53483.54.08\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/\u5c4f\u5e55\u5feb\u7167-2019-07-02-\u4e0b\u53483.54.08-300x251.png\" data-large-file=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/\u5c4f\u5e55\u5feb\u7167-2019-07-02-\u4e0b\u53483.54.08-1024x857.png\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/\u5c4f\u5e55\u5feb\u7167-2019-07-02-\u4e0b\u53483.54.08.png\" alt=\"\" width=\"1174\" height=\"982\" class=\"aligncenter size-full wp-image-1551\" srcset=\"https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/\u5c4f\u5e55\u5feb\u7167-2019-07-02-\u4e0b\u53483.54.08.png 1174w, https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/\u5c4f\u5e55\u5feb\u7167-2019-07-02-\u4e0b\u53483.54.08-300x251.png 300w, https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/\u5c4f\u5e55\u5feb\u7167-2019-07-02-\u4e0b\u53483.54.08-768x642.png 768w, https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/\u5c4f\u5e55\u5feb\u7167-2019-07-02-\u4e0b\u53483.54.08-1024x857.png 1024w, https:\/\/www.shuizilong.com\/house\/wp-content\/uploads\/2019\/07\/\u5c4f\u5e55\u5feb\u7167-2019-07-02-\u4e0b\u53483.54.08-359x300.png 359w\" sizes=\"auto, (max-width: 1174px) 100vw, 1174px\" \/><\/a><\/p>\n<p>\u6211\u4eec\u628a\u4ee5\u592a\u574a\u533a\u5757\u94fe\u89c6\u4f5c\u4e00\u4e2a\u72b6\u6001\u673a\uff0c\u8bbe<br \/>\n&#8211; <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/ql-cache\/quicklatex.com-ede05c264bba0eda080918aaa09c4658_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;\" title=\"Rendered by QuickLaTeX.com\" height=\"8\" width=\"10\" style=\"vertical-align: 0px;\"\/>\u3001<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/ql-cache\/quicklatex.com-0af556714940c351c933bba8cf840796_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#121;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"9\" style=\"vertical-align: -4px;\"\/> \u5206\u522b\u662f transcation \u6267\u884c\u524d\u5408\u7ea6\u4e2d\u50a8\u5907\u7684 ETH \u548c DAI\u3002<br \/>\n&#8211; <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/ql-cache\/quicklatex.com-b5e2f0a82567597c38101d0774b3fa68_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;&#39;\" title=\"Rendered by QuickLaTeX.com\" height=\"14\" width=\"14\" style=\"vertical-align: 0px;\"\/>\u3001<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/ql-cache\/quicklatex.com-3442cf6a7b319e3456f27a2aac1c66ea_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#121;&#39;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"13\" style=\"vertical-align: -4px;\"\/> \u5206\u522b\u662f transcation \u6267\u884c\u7ed3\u675f\u4e4b\u540e\u5408\u7ea6\u4e2d\u65b0\u7684\u7684 ETH \u548c DAI\u3002<br \/>\n&#8211; <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/ql-cache\/quicklatex.com-b7398eb19d4a7b42e0948c84ca560c29_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"25\" style=\"vertical-align: 0px;\"\/> \u4e3a\u4e0b\u9762\u7684 swap() \u65b9\u6cd5\u4e2d\u4f20\u5165\u7684 ETH\u3002<br \/>\n&#8211; <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/ql-cache\/quicklatex.com-316218d36496d90790aa912e60e1a7ad_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#121;\" title=\"Rendered by QuickLaTeX.com\" height=\"17\" width=\"24\" style=\"vertical-align: -4px;\"\/> \u662f swap() \u65b9\u6cd5\u5151\u6362\u51fa\u7684 DAI\u3002<\/p>\n<p>\u5356 ETH \u7684\u8fc7\u7a0b\u5c31\u662f\u5df2\u77e5\u5176\u4ed6\u53c2\u6570\uff0c\u6c42 <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/ql-cache\/quicklatex.com-e32b117efe1a8b8eed116700c8d8e682_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#68;&#101;&#108;&#116;&#97;&#32;&#121;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"53\" style=\"vertical-align: -4px;\"\/>\uff0c\u90a3\u4e48\u663e\u7136\u672c\u6b21\u4ea4\u6613\u7684\u4ef7\u683c\u5c31\u662f <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/ql-cache\/quicklatex.com-128f6c81581be157f133baac126b107c_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#102;&#114;&#97;&#99;&#123;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#121;&#125;&#123;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"24\" width=\"20\" style=\"vertical-align: -6px;\"\/>\u3002<\/p>\n<p>\u800c <strong>x*y = k<\/strong> invariant \u6307\u7684\u5c31\u662f\uff1a<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 21px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/ql-cache\/quicklatex.com-f8b06eccb01243a98150bdbdd1e8122f_l3.png\" height=\"21\" width=\"332\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#120;&#32;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#121;&#32;&#61;&#32;&#107;&#32;&#61;&#32;&#120;&#39;&#32;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#121;&#39;&#32;&#61;&#32;&#40;&#120;&#32;&#43;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#41;&#32;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#40;&#121;&#32;&#43;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#121;&#41;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>\u65b9\u7a0b\u89e3\u5f97<\/p>\n<p class=\"ql-center-displayed-equation\" style=\"line-height: 41px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.shuizilong.com\/house\/wp-content\/ql-cache\/quicklatex.com-7dc01b3a3f8ad729398fb4bd5d6d3bd2_l3.png\" height=\"41\" width=\"183\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#68;&#101;&#108;&#116;&#97;&#32;&#121;&#32;&#61;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#107;&#125;&#123;&#40;&#120;&#32;&#43;&#32;&#92;&#68;&#101;&#108;&#116;&#97;&#32;&#120;&#41;&#125;&#32;&#45;&#32;&#121;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: python; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\neth_pool: uint256         \r\ntoken_pool: uint256       \r\ntoken: address(ERC20) \r\n\r\n@public\r\n@payable\r\ndef ethToTokenSwap():\r\n    fee: uint256 = msg.value \/ 500 \r\n    invariant: uint256 = self.eth_pool * self.token_pool\r\n    new_eth_pool: uint256 = self.eth_pool + msg.value\r\n    new_token_pool: uint256 = invariant \/ (new_eth_pool - fee)\r\n    tokens_out: uint256 = self.token_pool - new_token_pool\r\n    self.eth_pool = new_eth_pool\r\n    self.token_pool = new_token_pool\r\n    self.token.transfer(msg.sender, tokens_out\r\n<\/pre>\n<p>\u4e70 ETH \u7684\u8fc7\u7a0b\u7c7b\u4f3c\uff0c<br \/>\n\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: python; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n@public\r\ndef tokenToEthSwap(tokens_in: uint256):\r\n    fee: uint256 = tokens_in \/ 500\r\n    invariant: uint256 = self.eth_pool * self.token_pool\r\n    new_token_pool: uint256 = self.token_pool + tokens_in\r\n    new_eth_pool: uint256 = self.invariant \/ (new_token_pool - fee)\r\n    eth_out: uint256 = self.eth_pool - new_eth_pool\r\n    self.eth_pool = new_eth_pool\r\n    self.token_pool = new_token_pool\r\n    self.token.transferFrom(msg.sender, self, tokens_out)\r\n    send(msg.sender, eth_out)\r\n<\/pre>\n<h3>\u6d41\u52a8\u6027\u901a\u8bc1 Liquidity Token<\/h3>\n<p>\u6d41\u52a8\u6027\u662f\u4ea4\u6613\u6240\u7684\u7075\u9b42\u3002Bancor \u6700\u4e3a\u4eba\u8bdf\u75c5\u7684\u4e00\u70b9\u5c31\u662f\u4ed6\u7684\u6d41\u52a8\u6027\u4e0d\u591f\u7075\u6d3b\uff0c\u5728\u5408\u7ea6\u521b\u5efa\u4e4b\u540e\uff0c\u5c31\u6ca1\u6709\u4efb\u4f55\u673a\u5236\u53ef\u4ee5\u8c03\u8282\u4e86\u3002\u800c Uniswap \u9f13\u52b1\u7528\u6237\u81ea\u884c\u7ed9\u5408\u7ea6\u63d0\u4f9b\u6d41\u52a8\u6027\uff0c\u5e76\u4f7f\u7528 Liquidity Token \u8fdb\u884c\u6fc0\u52b1\uff0c\u9887\u6709\u4e00\u79cd\u300c\u5403\u767e\u5bb6\u996d\uff0c\u7a7f\u767e\u5bb6\u8863\u300d\u7684\u611f\u89c9\u3002\u4e8b\u5b9e\u4e0a Uniswap \u751a\u81f3\u90fd\u6ca1\u6709\u7ed9\u81ea\u5df1\u8bbe\u7f6e\u4efb\u4f55\u6536\u53d6\u624b\u7eed\u8d39\u7684\u540e\u95e8\uff08zero rent extraction\uff09\uff0cUniswap \u76c8\u5229\u7684\u552f\u4e00\u65b9\u5f0f\u5c31\u662f\u81ea\u5df1\u4e5f\u53bb\u63d0\u4f9b\u6d41\u52a8\u6027\u3002<\/p>\n<p>\u589e\u52a0\u6d41\u52a8\u6027\uff08addLiquidity\uff09\u7684\u65b9\u6cd5\u5341\u5206\u7b80\u5355\uff0c\u7528\u6237\u901a\u8fc7\u5411\u5408\u7ea6\u540c\u65f6\u62b5\u62bc\u4e00\u90e8\u5206 ETH \u548c DAI \u6765\u63d0\u4f9b\u6d41\u52a8\u6027\uff0c\u800c\u8fd9\u4e00\u6b21\u7ef4\u62a4\u7684\u4e0d\u53d8\u5f0f\u662f\uff0c\u6d41\u52a8\u6027\u6539\u53d8\u7684\u524d\u540e\uff0c\u4ef7\u683c\u4e0d\u53d8\u3002<\/p>\n<h3>\u5c3e\u58f0 Epilogue<\/h3>\n<p>\uff08TBD\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u4e9b\u65e5\u5b50\u548c Roger Wu \u8ba8\u8bba\uff0c\u8981\u4e0d\u8981\u5199\u4e00\u672c Defi \u5408\u7ea6\u9274\u8d4f\u7684 Booklet\uff0c\u4f46\u662f\u6211\u4eec\u4f3c\u4e4e\u90fd\u8981\u9762\u4e34\u548c Donald E. Knuth. \u540c\u6837\u7684\u95ee\u9898\uff0c\u5199\u7684\u901f\u5ea6\u8fd8\u6ca1\u6709\u884c\u4e1a\u7684\u53d1\u5c55\u5feb\u3002\u4e8e\u662f\u6211\u4eec\u51b3\u5b9a\u91c7\u53d6\u300c\u5206\u800c\u6cbb\u4e4b\u300d\u4e4b\u7b56\u7565\uff0c\u4e3a\u4e86\u4e0d\u8ba9\u8fdb\u5ea6\u843d\u540e\u66f4\u591a\uff0c\u4e0d\u59a8\u8ba9\u6211\u5148\u627e\u4e00\u4e2a\u8f6f\u67ff\u5b50\u4e0b\u624b\u3002\u663e\u7136\u6240\u6709 Defi \u9879\u76ee\u4e2d\u6700\u8f6f\u7684\uff0c\u5c31\u8981\u6570 Uniswap \u4e86\u3002 \u521a\u597d Uniswap \u7684\u521b\u59cb\u4eba Hayden Adams \u53c2\u52a0\u4e86 \u6700\u8fd1\u7684\u4e00\u671f Epicenter\uff0c\u5728\u8fd9\u96c6 Podcast \u4e2d Hayden Adams \u8ba8\u8bba\u4e86\u8bb8\u591a\u5e55\u540e\u7684\u6545\u4e8b\uff0c\u6709\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u53bb\u56de\u987e\u3002 \u53c2\u8003\u8d44\u6599 Protocol Website Documentation Code Whitepaper<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[34],"tags":[],"class_list":["post-1550","post","type-post","status-publish","format-standard","hentry","category-34"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-p0","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1550","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=1550"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1550\/revisions"}],"predecessor-version":[{"id":1552,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1550\/revisions\/1552"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=1550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=1550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=1550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}