-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCircuitBreaker.sol
49 lines (40 loc) · 1.38 KB
/
CircuitBreaker.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
49
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@chainlink/contracts/src/v0.8/AutomationCompatible.sol";
import {AutomationCompatibleInterface} from "@chainlink/contracts/src/v0.8/AutomationCompatible.sol";
import {IPerformExecutor} from './interfaces/IPerformExecutor.sol';
contract CircuitBreaker is AutomationCompatibleInterface {
/**
* @dev run off-chain, checks if balance is greater than expected and decides whether to run emergency action on-chain
* @param checkData address of the Executor contract
*/
function checkUpkeep(bytes calldata checkData)
external
view
override
returns (bool, bytes memory)
{
address executorAddress = abi.decode(checkData, (address));
IPerformExecutor performExecutor = IPerformExecutor(
executorAddress
);
if (
performExecutor.isFeedParamMet() &&
performExecutor.isEmergencyActionPossible()
) {
return (true, checkData);
}
return (false, checkData);
}
/**
* @dev if feed params are not met - executes emergency action
* @param performData address of the PerformExecutor contract
*/
function performUpkeep(bytes calldata performData) external override {
address executorAddress = abi.decode(performData, (address));
IPerformExecutor performExecutor = IPerformExecutor(
executorAddress
);
performExecutor.executeEmergencyAction();
}
}