当前位置:网站首页>Uniswapv2 peripheral contract learning (VII) -- exampleslidingwindoworacle sol

Uniswapv2 peripheral contract learning (VII) -- exampleslidingwindoworacle sol

2022-06-09 14:01:00 MateZero

I remember a sentence from my circle of friends , If Defi It is the crown of Ethereum , that Uniswap It is the Pearl in this crown .Uniswap So far V2 edition , relative V1, Its functions are more comprehensive and optimized , However, the contract source code is not complicated . This article is for personal learning UniswapV2 Source code of a series of record articles .

One 、ExampleSlidingWindowOracle Contract introduction

The contract is the same as that learned in the previous article ExampleOracleSimple The contract is the same , Is to use UniswapV2 As a price prediction machine . But the application scenarios of the two are different :

  • ExampleOracleSimple The contract is used for fixed window mode , In this mode, historical data is not important , The current price has the same weight as the historical price . therefore , Records per cycle ( to update ) Just average the price once .
  • ExampleSlidingWindowOracle For sliding window mode , You can record price related information multiple times in a cycle . Sliding window mode is also divided into two categories , One is simple moving average , In other words, each price calculation is equal weight . The other is the exponential moving average , The most recent price calculation has a greater weight value .

This contract is an example of a simple moving average . About using UniswapV2 For more information about the price prediction machine, please read its documentation Buiding an Oracle. This document also elaborates on the overflow problem in price calculation .

Two 、 Contract source code

pragma solid
原网站

版权声明
本文为[MateZero]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091245531532.html