-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUpdateOracle.s.sol
48 lines (35 loc) · 1.48 KB
/
UpdateOracle.s.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "forge-std/Script.sol";
import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
import {OracleUpdateHelper, IUniswapV3Pool} from "src/OracleUpdateHelper.sol";
import "./Keeper.s.sol";
contract UpdateOracleScript is KeeperScript {
OracleUpdateHelper constant oracleUpdateHelper = OracleUpdateHelper(0x63cd7973D2416ae5cA46231dfd358C75fbC39670);
uint256 constant updateThreshold = 0.0001e12;
function setUp() public {}
function run() external {
VolatilityOracle oracle = _oracle[block.chainid];
IUniswapV3Pool[] storage pools = _getPoolsFor(block.chainid);
IUniswapV3Pool[] memory poolsToUpdate = new IUniswapV3Pool[](pools.length);
uint256 j;
for (uint256 i; i < pools.length; i++) {
(, uint40 time,,) = oracle.lastWrites(pools[i]);
if (block.timestamp - time < 4 hours) continue;
oracle.update(pools[i], 1 << 32);
(, time,,) = oracle.lastWrites(pools[i]);
if (time != block.timestamp) continue;
poolsToUpdate[j] = pools[i];
j++;
console2.log(address(pools[i]));
}
assembly ("memory-safe") {
mstore(poolsToUpdate, j)
}
if (poolsToUpdate.length > 0) {
vm.startBroadcast(vm.envUint("PRIVATE_KEY_UPDATE_ORACLE"));
oracleUpdateHelper.update(oracle, poolsToUpdate);
vm.stopBroadcast();
}
}
}