defutures-contract

所属分类:collect
开发工具:Solidity
文件大小:0KB
下载次数:0
上传日期:2023-04-24 01:26:01
上 传 者sh-1993
说明:  ETH东京2023-去中心化期货,
(ETH Tokyo 2023 - Decentralized Futures,)

文件列表:
.prettierrc (41, 2023-04-23)
abi/ (0, 2023-04-23)
abi/ERC20.json (3384, 2023-04-23)
abi/ERC721.json (5396, 2023-04-23)
abi/Multicall2.json (6437, 2023-04-23)
abi/UniswapV2Defuture.json (17614, 2023-04-23)
abi/UniswapV2DefutureRouter.json (3881, 2023-04-23)
abi/UniswapV2Pair.json (12103, 2023-04-23)
contracts/ (0, 2023-04-23)
contracts/core/ (0, 2023-04-23)
contracts/core/BaseDefuture.sol (4023, 2023-04-23)
contracts/core/uniswap-v2/ (0, 2023-04-23)
contracts/core/uniswap-v2/UniswapV2Defuture.sol (7906, 2023-04-23)
contracts/core/uniswap-v2/UniswapV2DefutureFactory.sol (2124, 2023-04-23)
contracts/core/uniswap-v2/UniswapV2DefutureLibrary.sol (1280, 2023-04-23)
contracts/core/uniswap-v2/UniswapV2DefutureRouter.sol (6398, 2023-04-23)
contracts/core/uniswap-v3/ (0, 2023-04-23)
contracts/core/uniswap-v3/UniswapV3Defuture.sol (10483, 2023-04-23)
contracts/core/uniswap-v3/UniswapV3DefutureFactory.sol (2084, 2023-04-23)
contracts/core/uniswap-v3/UniswapV3DefutureRouter.sol (7302, 2023-04-23)
contracts/interfaces/ (0, 2023-04-23)
contracts/interfaces/core/ (0, 2023-04-23)
contracts/interfaces/core/IBaseDefuture.sol (631, 2023-04-23)
contracts/interfaces/core/uniswap-v2/ (0, 2023-04-23)
contracts/interfaces/core/uniswap-v2/IUniswapV2Defuture.sol (600, 2023-04-23)
contracts/interfaces/core/uniswap-v2/IUniswapV2DefutureFactory.sol (442, 2023-04-23)
contracts/interfaces/core/uniswap-v2/IUniswapV2DefutureRouter.sol (775, 2023-04-23)
contracts/interfaces/core/uniswap-v3/ (0, 2023-04-23)
contracts/interfaces/core/uniswap-v3/IUniswapV3Defuture.sol (491, 2023-04-23)
contracts/interfaces/core/uniswap-v3/IUniswapV3DefutureFactory.sol (266, 2023-04-23)
contracts/interfaces/core/uniswap-v3/IUniswapV3DefutureRouter.sol (1279, 2023-04-23)
contracts/interfaces/utils/ (0, 2023-04-23)
contracts/interfaces/utils/IERC165.sol (852, 2023-04-23)
contracts/interfaces/utils/IERC20.sol (2736, 2023-04-23)
contracts/interfaces/utils/IERC20Metadata.sol (681, 2023-04-23)
contracts/interfaces/utils/IERC20Minimal.sol (3044, 2023-04-23)
contracts/interfaces/utils/IERC721.sol (4852, 2023-04-23)
... ...

# Welcome to DeFutures We developed a smart contract using Hardhat and Solidity language. As the futures market differs from the spot market and can cause arbitrage when the price rises immediately after buying, it was challenging to implement an AMM for the futures market. Therefore, we created our own futures market AMM that is simple yet accurately sets the futures price by modifying Uniswap's CPMM. In addition, we completed the contract development using `UniswapV2Router` to create the product, and `SwapRouter` and `NonfungiblePositionManager` in `UniswapV3Router`. With the use of the Router, we were able to implement the addLiquidity and Hedge functions for the users. Furthermore, we created our own `UniswapV2DefutureRouter` and `UniswapV3DefutureRouter` by modifying the Router and implemented `addPosition`, `clearPosition`, and `hedge` functions with them. To prove that it can be executed on various networks, we deployed it on **`Mumbai`, `Scroll`, `Linea`, `Taiko`, `Celo`, and `Mantle`** networks. ## Inspiration ### Problem In the recent years, the popularity of futures trading exploded as it returned highest yields, especially in the world of DeFi where high fluctuations exists. Futures trading is proven to provide stability by its hedging mechanism and at the same time maintaining high profit when chosen the right volatility. However, the appearance of futures trading resulted DeFi users to lean more towards profitability in trading that exposes their positions to the heightened price volatility. High gas costs resulted for syncing off-chain data inevitable as well, resulting in a less decentralized dapp, counterfeiting blockchain’s main functions. ### Solution We have figured this problem by implementing a fully decentralized futures exchange through integration of on-chain AMM formulas. This easily decides the cost of the position from given amount to buy. This is essential as it solves high gas costs when trying to form a cost in other ways, for instance order book mechanism. Bringing in an existing AMM formula, also helps in deriving a simpler structural mechanism, leading into high scalability and compatibility interchain and layers. Variating futures options in an existing DeFi protocol is expected to induce immense number of user pool and overall TVL. ## What it does Defutures, a decentralized futures trading exchange, meets users expectations to invest in a way it provides back both stability and high yield returns. Users are open to choices of volatility and a pair of their own desire. ### Main Functions Hedged Liquidation: Liquidators choose one pair of an asset, the amount to invest, an asset of either to farm and margin ratio aka. volatility. A portion of the base tokens will be swapped to farm tokens, creating a stake consisting of both tokens with equivalent value. The other portion calculated by volatility will enter futures contract that commits to swapping the farm token back to a predetermined amount of base tokens in the future. One intriguing fact from the function is that it enables both transaction and hedging at one transaction. AMM Integration: Defutures is fully flexible as it welcomes multiple chains and layers, and to DeFi protocols with an existing AMM. It is structured to focus solely on providing low-risk investment products to the user, and at the same time guaranteeing constant profits. Therefore being designed in a simple, straightforward manner, scalability throughout the entire blockchain system is relatively easily drawn. Market stabilizer: Positions from both ends when placed together, this impacts the whole market to stabilize prize fluctuations as it will act as key axis throughout the duration. In other words, more positions the more impact it will strive the market, creating a firm market price dome reaching stability preventing price sudden peaks. This powerful feature is expected to reach high demands as users tend to look for stable, safe products to invest in. ## How we built it For each AMM defutures integrate with, it will duplicate the same AMM to create its own pricing mechanisms. Both spot trades and futures trades is highly expected to converge to one another as long as arbitrage will be available between the two pairs. Otherwise when arbitrage will not be available, the whole system of futures will break down as there will be no guarantee involved in the pricing system of the futures. Theoretically, syncing futures prices and spot prices every time a position order happens, and daily liquidation occurring based on spot margin will allow the two distinct pairs converge creating one healthy steady pricing system. Assuming the premise is proven true, the following scenario would be satisfied true. Bob deposits 100 USDT in pair USDC-DOGE, asserting 1 USDC = 10 DOGE. Given 10 USDT to be used as margin, `addLiquidateHedged` function will divide the other 90 USDT into both USDC and DOGE in both equivalent values, staking them to receive fees throughout the stake duration. For instance, 45 USDT will be swapped to 450 DOGE. The other half of 90 USDT, 45 USDT, will be staked together with 450 DOGE into a pool where fees will be collected. The problem appears as there is no guarantee that 450 DOGE will be swapped back at 45 USDT. If 450 USDT is swapped for a 40 USDT, user’s loss would be greater than the fee user had retrieved. This is where our stabilizer, defutures comes in place, as it uses the 10 USDT as margin to buy a position 450 DOGE → 45 USDT. Risks to a certain point still remains has been greatly reduced. The two following scenario could be drawn to envision our product. ## To provide an example, we will consider Uniswap’s AMM. ### 1. 1 USDC → 12 DOGE To maintain 1 USDC → 12 DOGE, the amount staked (45 USDT, 450 DOGE) could be rephrased to 41.08 USDC + 492.95 DOGE, and when expressed in USDC, it will result to 82.16 USDC. This implies 7.84 USDC loss during the stake duration, excluding fees collected. However, at the same time the futures price for 45 USDC is now 540(=45*12) DOGE, implying 90 DOGE as opportunity cost. Including margin of 17.5 USDC (10 USDC as margin, 7.5 USDC from 90 DOGE opportunity cost), despite the price loss of DOGE, Bob secured 99.66 USDC + fees to be collected. ### 2. 1 USDC → 8 DOGE Amount staked 45 USDT, 450 DOGE could be recalculated to 50.31 USDC + 402.49 DOGE. This will equivalent to 100.62 USDC. Despite the profit, the position for stabilizing this model, would turn into a loss of opportunity cost. 45 USDC is now 360(=8*12) DOGE, implying 7.5 USDC of loss. Bob however, still secured 103.12(100.62+margin-7.5 USDC) excluding fees to be collected. The big picture of this product it to allow users to buy stability, broadening choices of investments and getting closer to users’ needs and flavor in investments. ## Challenges we ran into Futures Price Formation : As mentioned earlier, a pair is instantiated using the AMM from the DeFi protocol defutures is added on. However, these two are distinct from another and one does not necessarily affect the other in certain cases. Several complex simulations involving compound numeric values had to be dealt with until we could prove the possibility of arbitrage between the two pairs, resulting to convergence from one another. Security level management: DeFi is finance. It heavily associates with money, where security is most demanded. We had to think of scenarios from scratch where security features should be added especially as futures involve complex mechanisms. Moreover, every functions were designed to be extremely explicit leaving no room for security issues. ## User Flow ## Before Maturaity & After Maturaity ## Defuture has a great potential for expansion

近期下载者

相关文件


收藏者