Diff
checker
テキスト
テキスト
画像
ドキュメント
Excel
フォルダ
Legal
Enterprise
デスクトップ
料金
ログイン
Diffchecker デスクトップのダウンロード
テキスト比較
2 つのテキスト ファイルの違いを見つける
ツール
履歴
ライブエディター
空白の変更を非表示
未変更行を折りたたむ
折り返しなし
レイアウト
分割
統合
比較精度
スマート
単語
文字
テキストスタイル
外観を変更
シンタックスハイライト
構文を選択
無視
テキスト変換
最初の差分へ移動
入力を編集
Diffchecker Desktop
Diffcheckerを実行する最も安全な方法。Diffchecker Desktopアプリを入手:あなたの差分はコンピューターから出ることはありません!
Desktopを入手
ORACLE
作成日
昨年
差分は期限切れになりません
クリア
エクスポート
共有
説明
74 削除
行
合計
削除
文字
合計
削除
この機能を引き続き使用するには、アップグレードしてください
Diff
checker
Pro
価格を見る
82 行
すべてコピー
48 追加
行
合計
追加
文字
合計
追加
この機能を引き続き使用するには、アップグレードしてください
Diff
checker
Pro
価格を見る
61 行
すべてコピー
コピー
コピー済み
コピー
コピー済み
contract Oracle is
Epoch {
contract Oracle is
Operator {
using FixedPoint for *;
using SafeMath for uint256;
using SafeMath for uint256;
コピー
コピー済み
コピー
コピー済み
/* ========== STATE VARIABLES ========== */
// uniswap
address public token0;
address public token0;
address public token1;
address public token1;
コピー
コピー済み
コピー
コピー済み
IUniswapV2Pair
public pair;
IPool
public pair;
// oracle
uint32 public blockTimestampLast;
uint256 public price0CumulativeLast;
uint256 public price1CumulativeLast;
FixedPoint.uq112x112 public price0Average;
FixedPoint.uq112x112 public price1Average;
/* ========== CONSTRUCTOR ========== */
コピー
コピー済み
コピー
コピー済み
constructor(
constructor(
IPool
_pair
) public
{
IUniswapV2Pair
_pair
,
uint256 _period,
uint256 _startTime
) public
Epoch(_period, _startTime, 0)
{
pair = _pair;
pair = _pair;
token0 = pair.token0();
token0 = pair.token0();
token1 = pair.token1();
token1 = pair.token1();
コピー
コピー済み
コピー
コピー済み
price0CumulativeLast = pair.price0CumulativeLast(); // fetch the current accumulated price value (1 / 0)
uint
256
reserve0;
price1CumulativeLast = pair.price1CumulativeLast(); // fetch the current accumulated price value (0 / 1)
uint
256
reserve1;
uint
112
reserve0;
(reserve0, reserve1,
) = pair.getReserves();
uint
112
reserve1;
require(reserve0 != 0 && reserve1 != 0, "Oracle:
No reserves");
(reserve0, reserve1,
blockTimestampLast
) = pair.getReserves();
require(reserve0 != 0 && reserve1 != 0, "Oracle:
NO_RESERVES"); // ensure that there's liquidity in the pair
}
}
コピー
コピー済み
コピー
コピー済み
/* ========== MUTABLE FUNCTIONS ========== */
function update() external
{
pair.sync();
/** @dev Updates 1-day EMA price from Uniswap. */
function update() external
checkEpoch
{
(uint256 price0Cumulative, uint256 price1Cumulative, uint32 blockTimestamp) = UniswapV2OracleLibrary.currentCumulativePrices(address(pair));
uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired
if (timeElapsed == 0) {
// prevent divided by zero
return;
}
// overflow is desired, casting never truncates
// cumulative price is in (uq112x112 price * seconds) units so we simply wrap it after division by time elapsed
price0Average = FixedPoint.uq112x112(uint224((price0Cumulative - price0CumulativeLast) / timeElapsed));
price1Average = FixedPoint.uq112x112(uint224((price1Cumulative - price1CumulativeLast) / timeElapsed));
price0CumulativeLast = price0Cumulative;
price1CumulativeLast = price1Cumulative;
blockTimestampLast = blockTimestamp;
emit Updated(price0Cumulative, price1Cumulative);
}
}
コピー
コピー済み
コピー
コピー済み
// note this will always return 0 before update has been called successfully for the first time.
function consult(
function consult(
address _token,
uint256 _amountIn
) external view returns (
uint144
amountOut) {
address _token,
uint256 _amountIn
) external view returns (
uint256
amountOut) {
if (_token == token0) {
if (_token == token0) {
コピー
コピー済み
コピー
コピー済み
amountOut =
price0Average.mul(
_amountIn
).decode144(
);
amountOut =
_quote(_token,
_amountIn
, 12
);
} else {
} else {
コピー
コピー済み
コピー
コピー済み
require(_token == token1, "Oracle:
INVALID_TOKEN
");
require(_token == token1, "Oracle:
Invalid token
");
amountOut =
price1Average.mul(
_amountIn
).decode144(
);
amountOut =
_quote(_token,
_amountIn
, 12
);
}
}
}
}
コピー
コピー済み
コピー
コピー済み
function twap(
address _token,
uint256 _amountIn
) external view returns (
uint144 _
amountOut) {
function twap(
(uint256 price0Cumulative, uint256 price1Cumulative, uint32 blockTimestamp) = UniswapV2OracleLibrary.currentCumulativePrices(address(pair));
address _token,
uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired
uint256 _amountIn
) external view returns (
uint256
amountOut) {
if (_token == token0) {
if (_token == token0) {
コピー
コピー済み
コピー
コピー済み
_
amountOut =
FixedPoint.uq112x112(uint224((price0Cumulative - price0CumulativeLast) / timeElapsed)).mul(
_amountIn
).decode144(
);
amountOut =
_quote(_token,
_amountIn
, 2
);
} else
if
(_token == token1
) {
} else
{
_
amountOut =
FixedPoint.uq112x112(uint224((price1Cumulative - price1CumulativeLast) / timeElapsed)).mul(
_amountIn
).decode144(
);
require
(_token == token1
, "Oracle: Invalid token");
amountOut =
_quote(_token,
_amountIn
, 2
);
}
}
}
}
コピー
コピー済み
コピー
コピー済み
event Updated(uint256 price0CumulativeLast, uint256 price1CumulativeLast);
// Note the window parameter is removed as its always 1 (30min), granularity at 12 for example is (12 * 30min) = 6 hours
function _quote(
address tokenIn,
uint256 amountIn,
uint256 granularity // number of observations to query
) internal view returns (uint256 amountOut) {
uint256 observationLength = IPool(pair).observationLength();
require(
granularity <= observationLength,
"Oracle: Not enough observations"
);
uint256 price = IPool(pair).quote(tokenIn, amountIn, granularity);
amountOut = price;
}
}
}
保存された差分
原文
ファイルを開く
contract Oracle is Epoch { using FixedPoint for *; using SafeMath for uint256; /* ========== STATE VARIABLES ========== */ // uniswap address public token0; address public token1; IUniswapV2Pair public pair; // oracle uint32 public blockTimestampLast; uint256 public price0CumulativeLast; uint256 public price1CumulativeLast; FixedPoint.uq112x112 public price0Average; FixedPoint.uq112x112 public price1Average; /* ========== CONSTRUCTOR ========== */ constructor( IUniswapV2Pair _pair, uint256 _period, uint256 _startTime ) public Epoch(_period, _startTime, 0) { pair = _pair; token0 = pair.token0(); token1 = pair.token1(); price0CumulativeLast = pair.price0CumulativeLast(); // fetch the current accumulated price value (1 / 0) price1CumulativeLast = pair.price1CumulativeLast(); // fetch the current accumulated price value (0 / 1) uint112 reserve0; uint112 reserve1; (reserve0, reserve1, blockTimestampLast) = pair.getReserves(); require(reserve0 != 0 && reserve1 != 0, "Oracle: NO_RESERVES"); // ensure that there's liquidity in the pair } /* ========== MUTABLE FUNCTIONS ========== */ /** @dev Updates 1-day EMA price from Uniswap. */ function update() external checkEpoch { (uint256 price0Cumulative, uint256 price1Cumulative, uint32 blockTimestamp) = UniswapV2OracleLibrary.currentCumulativePrices(address(pair)); uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired if (timeElapsed == 0) { // prevent divided by zero return; } // overflow is desired, casting never truncates // cumulative price is in (uq112x112 price * seconds) units so we simply wrap it after division by time elapsed price0Average = FixedPoint.uq112x112(uint224((price0Cumulative - price0CumulativeLast) / timeElapsed)); price1Average = FixedPoint.uq112x112(uint224((price1Cumulative - price1CumulativeLast) / timeElapsed)); price0CumulativeLast = price0Cumulative; price1CumulativeLast = price1Cumulative; blockTimestampLast = blockTimestamp; emit Updated(price0Cumulative, price1Cumulative); } // note this will always return 0 before update has been called successfully for the first time. function consult(address _token, uint256 _amountIn) external view returns (uint144 amountOut) { if (_token == token0) { amountOut = price0Average.mul(_amountIn).decode144(); } else { require(_token == token1, "Oracle: INVALID_TOKEN"); amountOut = price1Average.mul(_amountIn).decode144(); } } function twap(address _token, uint256 _amountIn) external view returns (uint144 _amountOut) { (uint256 price0Cumulative, uint256 price1Cumulative, uint32 blockTimestamp) = UniswapV2OracleLibrary.currentCumulativePrices(address(pair)); uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired if (_token == token0) { _amountOut = FixedPoint.uq112x112(uint224((price0Cumulative - price0CumulativeLast) / timeElapsed)).mul(_amountIn).decode144(); } else if (_token == token1) { _amountOut = FixedPoint.uq112x112(uint224((price1Cumulative - price1CumulativeLast) / timeElapsed)).mul(_amountIn).decode144(); } } event Updated(uint256 price0CumulativeLast, uint256 price1CumulativeLast); }
変更されたテキスト
ファイルを開く
contract Oracle is Operator { using SafeMath for uint256; address public token0; address public token1; IPool public pair; constructor(IPool _pair) public { pair = _pair; token0 = pair.token0(); token1 = pair.token1(); uint256 reserve0; uint256 reserve1; (reserve0, reserve1, ) = pair.getReserves(); require(reserve0 != 0 && reserve1 != 0, "Oracle: No reserves"); } function update() external { pair.sync(); } function consult( address _token, uint256 _amountIn ) external view returns (uint256 amountOut) { if (_token == token0) { amountOut = _quote(_token, _amountIn, 12); } else { require(_token == token1, "Oracle: Invalid token"); amountOut = _quote(_token, _amountIn, 12); } } function twap( address _token, uint256 _amountIn ) external view returns (uint256 amountOut) { if (_token == token0) { amountOut = _quote(_token, _amountIn, 2); } else { require(_token == token1, "Oracle: Invalid token"); amountOut = _quote(_token, _amountIn, 2); } } // Note the window parameter is removed as its always 1 (30min), granularity at 12 for example is (12 * 30min) = 6 hours function _quote( address tokenIn, uint256 amountIn, uint256 granularity // number of observations to query ) internal view returns (uint256 amountOut) { uint256 observationLength = IPool(pair).observationLength(); require( granularity <= observationLength, "Oracle: Not enough observations" ); uint256 price = IPool(pair).quote(tokenIn, amountIn, granularity); amountOut = price; } }
違いを見つける