forked from DODOEX/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path165077f2.c3c89729.js
1 lines (1 loc) · 13.3 KB
/
165077f2.c3c89729.js
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[8],{105:function(e,t,a){"use strict";a.r(t),a.d(t,"frontMatter",(function(){return o})),a.d(t,"metadata",(function(){return l})),a.d(t,"rightToc",(function(){return s})),a.d(t,"default",(function(){return b}));var n=a(2),r=a(6),i=(a(0),a(146)),o={id:"flashSwap",title:"Flash Swap",sidebar_label:"Flash Swap"},l={id:"flashSwap",isDocsHomePage:!1,title:"Flash Swap",description:"What is Flash Swap",source:"@site/docs/flashSwap.md",permalink:"/docs/docs/flashSwap",editUrl:"https://github.com/DODOEX/docs/edit/master/docs/flashSwap.md",sidebar_label:"Flash Swap",sidebar:"someSidebar",previous:{title:"User Guide",permalink:"/docs/docs/contractUseGuide"},next:{title:"Deployment Information",permalink:"/docs/docs/deployedInfo"}},s=[{value:"What is Flash Swap",id:"what-is-flash-swap",children:[]},{value:"How Does Flash Swap Work",id:"how-does-flash-swap-work",children:[]},{value:"What Can Flash Swap Do",id:"what-can-flash-swap-do",children:[]},{value:"Some Thoughts on Flash Swap",id:"some-thoughts-on-flash-swap",children:[]}],c={rightToc:s};function b(e){var t=e.components,a=Object(r.a)(e,["components"]);return Object(i.b)("wrapper",Object(n.a)({},c,a,{components:t,mdxType:"MDXLayout"}),Object(i.b)("h2",{id:"what-is-flash-swap"},"What is Flash Swap"),Object(i.b)("p",null,"Simply put, you are allowed to pay on credit on DODO! When you buy tokens DODO, you can first get the tokens you want to buy, do anything you want with the tokens, and pay for them later."),Object(i.b)("h2",{id:"how-does-flash-swap-work"},"How Does Flash Swap Work"),Object(i.b)("p",null,Object(i.b)("img",Object(n.a)({parentName:"p"},{src:"https://dodoex.github.io/docs/img/dodo_flash_swap.jpeg",alt:null}))),Object(i.b)("p",null,"The figure above illustrates the four steps in a flash swap happening under the hood"),Object(i.b)("ol",null,Object(i.b)("li",{parentName:"ol"},"Call the ",Object(i.b)("inlineCode",{parentName:"li"},"buyBaseToken")," function from the ",Object(i.b)("inlineCode",{parentName:"li"},"DODO Pair")," smart contract"),Object(i.b)("li",{parentName:"ol"},Object(i.b)("inlineCode",{parentName:"li"},"DODO Pair")," transfers the base tokens to the message sender"),Object(i.b)("li",{parentName:"ol"},"If the parameter ",Object(i.b)("inlineCode",{parentName:"li"},"data")," of the ",Object(i.b)("inlineCode",{parentName:"li"},"buyBaseToken")," function call is not null, the ",Object(i.b)("inlineCode",{parentName:"li"},"DODO Pair")," smart contract will call the ",Object(i.b)("inlineCode",{parentName:"li"},"dodoCall")," method of the message sender"),Object(i.b)("li",{parentName:"ol"},"After the ",Object(i.b)("inlineCode",{parentName:"li"},"dodoCall")," is executed, the ",Object(i.b)("inlineCode",{parentName:"li"},"DODO Pair")," smart contract will retrieve the quote tokens required for this transaction from the message sender")),Object(i.b)("div",{className:"admonition admonition-note alert alert--secondary"},Object(i.b)("div",Object(n.a)({parentName:"div"},{className:"admonition-heading"}),Object(i.b)("h5",{parentName:"div"},Object(i.b)("span",Object(n.a)({parentName:"h5"},{className:"admonition-icon"}),Object(i.b)("svg",Object(n.a)({parentName:"span"},{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"16",viewBox:"0 0 14 16"}),Object(i.b)("path",Object(n.a)({parentName:"svg"},{fillRule:"evenodd",d:"M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"})))),"note")),Object(i.b)("div",Object(n.a)({parentName:"div"},{className:"admonition-content"}),Object(i.b)("p",{parentName:"div"},"The ",Object(i.b)("inlineCode",{parentName:"p"},"sellBaseToken")," function can also perform flash swap in the same way."))),Object(i.b)("p",null,"Flash swap requires the message sender to be a contract that implements the ",Object(i.b)("inlineCode",{parentName:"p"},"IDODOCallee")," interface."),Object(i.b)("pre",null,Object(i.b)("code",Object(n.a)({parentName:"pre"},{className:"language-javascript"}),"interface IDODOCallee {\n function dodoCall(\n bool isBuyBaseToken,\n uint256 baseAmount,\n uint256 quoteAmount,\n bytes calldata data\n ) external;\n}\n")),Object(i.b)("h2",{id:"what-can-flash-swap-do"},"What Can Flash Swap Do"),Object(i.b)("p",null,"Flash swap can significantly improve market efficiency. Market parity is maintained by arbitrageurs, and flash swap completely removes capital requirements for them, essentially eliminating the barrier of entry to arbitrage trading. "),Object(i.b)("p",null,"We will demonstrate a completely trustless and risk-free arbitrage trading contract as a use case of flash swap. Please refer to the ",Object(i.b)("inlineCode",{parentName:"p"},"UniswapArbitrageur.sol")," ",Object(i.b)("a",Object(n.a)({parentName:"p"},{href:"https://github.com/DODOEX/dodo-smart-contract/blob/master/contracts/helper/UniswapArbitrageur.sol"}),"source code")," for a concrete example. It has already been deployed and you can check out its Etherscan link ",Object(i.b)("a",Object(n.a)({parentName:"p"},{href:"https://etherscan.io/address/0xbf90b54cc00ceeaa93db1f6a54a01e3fe9ed4422"}),"here")),Object(i.b)("p",null,"The following figure illustrates how an arbitrageur might take advantage of the price discrepancies between DODO and Uniswap."),Object(i.b)("p",null,Object(i.b)("img",Object(n.a)({parentName:"p"},{src:"https://dodoex.github.io/docs/img/dodo_one_click_arbitrage.jpeg",alt:null}))),Object(i.b)("p",null,"A complete arbitrage trading maneuver consists of the following 9 steps:"),Object(i.b)("ol",null,Object(i.b)("li",{parentName:"ol"},"The user calls ",Object(i.b)("inlineCode",{parentName:"li"},"executeBuyArbitrage")," on ",Object(i.b)("inlineCode",{parentName:"li"},"UniswapArbitrageur")),Object(i.b)("li",{parentName:"ol"},Object(i.b)("inlineCode",{parentName:"li"},"UniswapArbitrageur")," calls ",Object(i.b)("inlineCode",{parentName:"li"},"buyBaseToken")," on ",Object(i.b)("inlineCode",{parentName:"li"},"DODO Pair")," and triggers flash swap"),Object(i.b)("li",{parentName:"ol"},Object(i.b)("inlineCode",{parentName:"li"},"DODO Pair")," transfers 1 WETH to ",Object(i.b)("inlineCode",{parentName:"li"},"UniswapArbitrageur")),Object(i.b)("li",{parentName:"ol"},Object(i.b)("inlineCode",{parentName:"li"},"DODO Pair")," calls ",Object(i.b)("inlineCode",{parentName:"li"},"dodoCall")," on ",Object(i.b)("inlineCode",{parentName:"li"},"UniswapArbitrageur")),Object(i.b)("li",{parentName:"ol"},Object(i.b)("inlineCode",{parentName:"li"},"UniswapArbitrageur")," transfers 1 WETH received from ",Object(i.b)("inlineCode",{parentName:"li"},"DODO Pair")," to ",Object(i.b)("inlineCode",{parentName:"li"},"UniswapV2")),Object(i.b)("li",{parentName:"ol"},Object(i.b)("inlineCode",{parentName:"li"},"UniswapArbitrageur")," calls ",Object(i.b)("inlineCode",{parentName:"li"},"swap")," on ",Object(i.b)("inlineCode",{parentName:"li"},"UniswapV2")),Object(i.b)("li",{parentName:"ol"},Object(i.b)("inlineCode",{parentName:"li"},"UniswapV2")," transfers 200 USDC to ",Object(i.b)("inlineCode",{parentName:"li"},"UniswapArbitrageur")),Object(i.b)("li",{parentName:"ol"},Object(i.b)("inlineCode",{parentName:"li"},"DODO Pair")," calls ",Object(i.b)("inlineCode",{parentName:"li"},"transferFrom")," and retrieves 150 USDC from ",Object(i.b)("inlineCode",{parentName:"li"},"UniswapArbitrageur")),Object(i.b)("li",{parentName:"ol"},Object(i.b)("inlineCode",{parentName:"li"},"UniswapArbitrageur")," transfers the remaining 50 USDC to the user")),Object(i.b)("p",null,"In summary,"),Object(i.b)("ul",null,Object(i.b)("li",{parentName:"ul"},"Steps 2, 3, 4, and 8 take care of the DODO front"),Object(i.b)("li",{parentName:"ul"},"Steps 5, 6, and 7 take care of the Uniswap front"),Object(i.b)("li",{parentName:"ul"},"The user is only exposed to the process of sending transactions and making profits, with everything else abstracted away!")),Object(i.b)("p",null,"The best part about the ",Object(i.b)("inlineCode",{parentName:"p"},"UniswapArbitrageur")," contract is that users do not need any capital, nor do they need to know how DODO and Uniswap work. They would simply call a function and, if the execution succeeds, make a profit. If the execution fails, the users would only lose some gas."),Object(i.b)("p",null,"In order to avoid unnecessary gas consumption, we recommend that users use ",Object(i.b)("inlineCode",{parentName:"p"},"eth_call")," to execute ",Object(i.b)("inlineCode",{parentName:"p"},"executeBuyArbitrage")," or ",Object(i.b)("inlineCode",{parentName:"p"},"executeSellArbitrage")," in advance to estimate arbitrage returns. If there is an arbitrage opportunity, these two functions will return profit of quote tokens and base tokens after successful execution."),Object(i.b)("h2",{id:"some-thoughts-on-flash-swap"},"Some Thoughts on Flash Swap"),Object(i.b)("p",null,"Once you have a deep understanding of flash swap, you will realize the superiority of the DeFi world over the centralized world. The composability of smart contracts has elevated the fund utilization of DeFi to an unprecedented level. Thanks to trustlessness, the cost of credit in DeFi is incredibly low. Once this financial system is integrated into the real world, its potential for improving our society and productivity will be truly boundless. The DODO team hopes that flash swap serves as a primer for DeFi builders and beginners alike to gain an appreciation for the power of DeFi."),Object(i.b)("div",{className:"admonition admonition-note alert alert--secondary"},Object(i.b)("div",Object(n.a)({parentName:"div"},{className:"admonition-heading"}),Object(i.b)("h5",{parentName:"div"},Object(i.b)("span",Object(n.a)({parentName:"h5"},{className:"admonition-icon"}),Object(i.b)("svg",Object(n.a)({parentName:"span"},{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"16",viewBox:"0 0 14 16"}),Object(i.b)("path",Object(n.a)({parentName:"svg"},{fillRule:"evenodd",d:"M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"})))),"note")),Object(i.b)("div",Object(n.a)({parentName:"div"},{className:"admonition-content"}),Object(i.b)("p",{parentName:"div"},"Flash swap was inspired by ",Object(i.b)("a",Object(n.a)({parentName:"p"},{href:"https://dydx.exchange/"}),"dYdX")," and ",Object(i.b)("a",Object(n.a)({parentName:"p"},{href:"https://uniswap.org/docs/v2/core-concepts/flash-swaps"}),"Uniswap"),". The DODO team genuinely appriciates and admires what these DeFi pioneers have done before us \ud83d\udc4d"))))}b.isMDXComponent=!0},146:function(e,t,a){"use strict";a.d(t,"a",(function(){return p})),a.d(t,"b",(function(){return u}));var n=a(0),r=a.n(n);function i(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function o(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function l(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?o(Object(a),!0).forEach((function(t){i(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):o(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function s(e,t){if(null==e)return{};var a,n,r=function(e,t){if(null==e)return{};var a,n,r={},i=Object.keys(e);for(n=0;n<i.length;n++)a=i[n],t.indexOf(a)>=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)a=i[n],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var c=r.a.createContext({}),b=function(e){var t=r.a.useContext(c),a=t;return e&&(a="function"==typeof e?e(t):l(l({},t),e)),a},p=function(e){var t=b(e.components);return r.a.createElement(c.Provider,{value:t},e.children)},d={inlineCode:"code",wrapper:function(e){var t=e.children;return r.a.createElement(r.a.Fragment,{},t)}},m=r.a.forwardRef((function(e,t){var a=e.components,n=e.mdxType,i=e.originalType,o=e.parentName,c=s(e,["components","mdxType","originalType","parentName"]),p=b(a),m=n,u=p["".concat(o,".").concat(m)]||p[m]||d[m]||i;return a?r.a.createElement(u,l(l({ref:t},c),{},{components:a})):r.a.createElement(u,l({ref:t},c))}));function u(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var i=a.length,o=new Array(i);o[0]=m;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l.mdxType="string"==typeof e?e:n,o[1]=l;for(var c=2;c<i;c++)o[c]=a[c];return r.a.createElement.apply(null,o)}return r.a.createElement.apply(null,a)}m.displayName="MDXCreateElement"}}]);