Uniswapについて調べてみた

 Uniswapについて調べてみた

7e3f65953e7e49cd19443950fd1e6469?s=128

YutaSugimura

May 17, 2019
Tweet

Transcript

  1. Uniswapͷ͓࿩ @YutaSugimura ੀଜɹ༏ଠ

  2. Enbowl inc. DEXͱ͸ ෼ࢄܕऔҾॴʢDEXʣͱ͸ɺ தԝ؅ཧऀΛհͣ͞ ݸਓؒͰ ௚઀Ծ૝௨՟ͷަ׵͕Ͱ͖ΔऔҾॴͷ͜ͱ ex. Uniswap, KyberSwap,

    DDEX, … (Decentralized Exchange)
  3. Enbowl inc. Uniswap DeFiͰ͸4ҐͷϘϦϡʔϜ https://defipulse.com/

  4. Enbowl inc. ɾಛఆͷೋऀؒͷަ׵͢Δ൘τϨʔυͰ͸ͳ͘ɺ ɹݻఆϨʔτͰͷଈ࣌ަ׵Λఏڙ͢Δϓϩτίϧ ɾͦͷଞDEXʹൺ΂ͯऔҾʹ͔͔ΔΨε୅͕௿͍ ɾऔҾख਺ྉ͕0.3% ɾྲྀಈੑఏڙ͢Δ͜ͱͰऔҾख਺ྉͷҰ෦Λ֫ಘͰ͖Δ Uniswapͷಛ௃

  5. Enbowl inc. Ψείετ͕͍҆ whitePaper: https://hackmd.io/s/HJ9jLsfTz ग़య:

  6. Enbowl inc. Uniswap Contract ɾUniswap_exchange.vy ɾUniswap_factory.vy Uniswapʹަ׵ՄೳͳτʔΫϯΛ௥Ճ͢Δػೳ τʔΫϯͷަ׵΍ྲྀಈੑఏڙ͢Δػೳ https://etherscan.io/address/0xc0a47dfe034b400b47bdad5fecda2621de6c4d95 https://etherscan.io/address/0xc0a47dfe034b400b47bdad5fecda2621de6c4d95

    Exchange Factory ίϯτϥΫτͷߏ੒
  7. Enbowl inc. factory Contract createExchange() ௥Ճ͍ͨ͠ERC20τʔΫϯͷίϯτϥΫτΞυϨε ΛೖΕ࣮ͯߦ͢Δ͜ͱͰτʔΫϯΛ௥Ճ͞ΕΔ https://etherscan.io/accounts/label/uniswap ओʹ࢖ΘΕΔؔ਺

  8. Enbowl inc. Uniswap Contract ɾSwap ɾSend ɾPool ETH·ͨ͸τʔΫϯΛଞͷτʔΫϯʹަ׵ ETH·ͨτʔΫϯΛผͷΞυϨεʹૹۚ UniswapʹྲྀಈੑͷఏڙΛ͢Δػೳ

    Exchange contract ͷߏ੒
  9. Enbowl inc. Exchange Contract Swap ަ׵ՄೳͳίΠϯ 40छྨҎ্ ex. REP, DAI,

    MKR, TUSD, ZRX, … Alice Alice 5ETH DAIʹަ׵ 4ETH ɾETH => ERC20 ɾERC20 => ETH ɾERC20 => ERC20 3ͭͷަ׵ํ๏ʹରԠ 0DAI 250DAI 1ETHΛ
  10. Enbowl inc. Exchange Contract Swap ethToTokenSwapInput() ethToTokenSwapOutput() tokenToEthSwapInput() tokenToEthSwapOutput() tokenToTokenSwapInput()

    tokenToEthSwapOutput() ͦͷଞ ɾETH => ERC20 ɾERC20 => ETH ɾERC20 => ERC20 https://github.com/Uniswap/contracts-vyper/blob/master/contracts/uniswap_exchange.vy Uniswap contract ͜ΕΒͷؔ਺Λ࢖ͬͯަ׵͍ͯ͠Δ
  11. Enbowl inc. Exchange Contract Send ETH => ERC20 ERC20 =>

    ETH ERC20 => ERC20 ૹۚͷࡍʹτʔΫϯΛม׵ͯ͠ૹۚ͢Δ͜ͱ͕Ͱ͖Δ Alice Bob 5ETH DAIʹަ׵ͯ͠ૹۚ 250DAI swapಉ༷ʹ3ͭͷૹۚʹରԠ 0DAI 1ETHΛ ॴ͍࣋ͯ͠ͳ͍τʔΫϯͷૹ͕ۚεϜʔζ https://github.com/Uniswap/contracts-vyper/blob/master/contracts/uniswap_exchange.vy Uniswap contract
  12. Enbowl inc. Exchange Contract Transfer ETH => ERC20 ERC20 =>

    ETH ERC20 => ERC20 ethToTokenTransferInput() tokenToEthTransferInput() tokenToTokenTransferInput() ಺෦తͰ͸Swapͷؔ਺͕࣮ߦ͞Ε͓ͯΓɺडऔਓ͕ૹۚ૬खͷΞυϨεʹͳ͍ͬͯΔ ethToTokenTransferOutput() tokenToEthTransferOutput() tokenToEthTransferOutput() ͦͷଞ
  13. Enbowl inc. Exchange Contract ྲྀಈੑͷఏڙ ࠷ॳʹྲྀಈੑΛఏڙ͢Δਓ͕Ձ֨Λઃఆ 5PLFOͱ 5PLFOͱಉྔͷ&5)ΛϩοΫ͢Δ Alice 1ETH

    250DAI uniswapʹྲྀಈੑΛఏڙ 1ETH 250DAI uniswap ΑͬͯՁ͕֨ઃఆ͞ΕΔ ͦΕҎ߱ʹఏڙ͢Δਓ͸ͦͷՁ֨ͰϩοΫ͍ͯ͘͠ ఏڙ͢Δ͜ͱͰख਺ྉͷҰ෦Λ΋Β͑Δ (0.3%ͷख਺ྉ͔Βఏڙൺ཰෼)
  14. Enbowl inc. Exchange Contract ɾྲྀಈੑͷఏڙ ɾaddLiquidity() ɾremoveLiquidity() ྲྀಈੑͷఏڙ ఏڙͷఫୀ ྲྀಈੑఏڙͷઆ໌͸লུ

  15. Enbowl inc. Exchange Contract (Swap) (input_amount * 997) * output_reserve

    (input_reserve * 1000) + (input_amount * 997) Tokens_bought = output_reserve = self.token.balanceOf(self) input_reserve = self.balance -msg.value input_amount = msg.value (Pool͕͍࣋ͬͯΔτʔΫϯྔ) (͜ͷϓʔϧ͕͍࣋ͬͯΔETHྔ) (ߪೖʹ࢖༻͢ΔETHͷྔ) inputͷ৔߹ (outputͷ৔߹ҟͳΔ) ethToTokenSwapͷ৔߹
  16. Enbowl inc. whitePaper: https://hackmd.io/s/HJ9jLsfTz ग़య: Exchange Contract

  17. Enbowl inc. 45.35OMGʹަ׵ token_Pool: eth_Pool: 10 500 ϓʔϧྔ invariant 5000

    Exchange Contract Alice 1ETHͰ Bob 1ETHͰߪೖ ड͚औΓྔ 37.8 OMG ಉֹۚ͡Ͱ΋ങ͑Δྔ͕ݮΔ AliceߪೖޙBob͕1ETHͰOMGߪೖ͢Δ token_Pool: eth_Pool: 11 454.65 ϓʔϧྔ New invariant 5001.15
  18. Enbowl inc. Exchange Contract 1000ഒͷPoolͩͱ 1ETHͰ49.84OMG token_Pool: eth_Pool: 10000 500000

    ϓʔϧྔ Alice ड͚औΔ͜ͱ͕Ͱ͖ͨ ΑͬͯPool͞Ε͍ͯΔτʔΫϯͷྔ͕ଟ͍ͱՁ͕֨҆ఆ͢Δ
  19. Enbowl inc. ΈΜͳτϨʔυԼख͔ͩΒUniswapʹྲྀಈੑΛఏڙ͠Α͏

  20. Enbowl inc. Link https://uniswap.io https://hackmd.io/C-DvwDSfSxuh-Gd4WKE_ig White Paper Official IUUQTVOJTXBQFYDIBOHFTXBQ Exchange

    GitHub https://github.com/Uniswap