This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
IGelatoCore.sol
186 lines (162 loc) · 7.47 KB
/
IGelatoCore.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// "SPDX-License-Identifier: UNLICENSED"
pragma solidity ^0.6.10;
pragma experimental ABIEncoderV2;
import {IGelatoProviderModule} from "../../gelato_provider_modules/IGelatoProviderModule.sol";
import {IGelatoCondition} from "../../gelato_conditions/IGelatoCondition.sol";
struct Provider {
address addr; // if msg.sender == provider => self-Provider
IGelatoProviderModule module; // can be IGelatoProviderModule(0) for self-Providers
}
struct Condition {
IGelatoCondition inst; // can be AddressZero for self-conditional Actions
bytes data; // can be bytes32(0) for self-conditional Actions
}
enum Operation { Call, Delegatecall }
enum DataFlow { None, In, Out, InAndOut }
struct Action {
address addr;
bytes data;
Operation operation;
DataFlow dataFlow;
uint256 value;
bool termsOkCheck;
}
struct Task {
Condition[] conditions; // optional
Action[] actions;
uint256 selfProviderGasLimit; // optional: 0 defaults to gelatoMaxGas
uint256 selfProviderGasPriceCeil; // optional: 0 defaults to NO_CEIL
}
struct TaskReceipt {
uint256 id;
address userProxy;
Provider provider;
uint256 index;
Task[] tasks;
uint256 expiryDate;
uint256 cycleId; // auto-filled by GelatoCore. 0 for non-cyclic/chained tasks
uint256 submissionsLeft;
}
interface IGelatoCore {
event LogTaskSubmitted(
uint256 indexed taskReceiptId,
bytes32 indexed taskReceiptHash,
TaskReceipt taskReceipt
);
event LogExecSuccess(
address indexed executor,
uint256 indexed taskReceiptId,
uint256 executorSuccessFee,
uint256 sysAdminSuccessFee
);
event LogCanExecFailed(
address indexed executor,
uint256 indexed taskReceiptId,
string reason
);
event LogExecReverted(
address indexed executor,
uint256 indexed taskReceiptId,
uint256 executorRefund,
string reason
);
event LogTaskCancelled(uint256 indexed taskReceiptId, address indexed cancellor);
/// @notice API to query whether Task can be submitted successfully.
/// @dev In submitTask the msg.sender must be the same as _userProxy here.
/// @param _provider Gelato Provider object: provider address and module.
/// @param _userProxy The userProxy from which the task will be submitted.
/// @param _task Selected provider, conditions, actions, expiry date of the task
function canSubmitTask(
address _userProxy,
Provider calldata _provider,
Task calldata _task,
uint256 _expiryDate
)
external
view
returns(string memory);
/// @notice API to submit a single Task.
/// @dev You can let users submit multiple tasks at once by batching calls to this.
/// @param _provider Gelato Provider object: provider address and module.
/// @param _task A Gelato Task object: provider, conditions, actions.
/// @param _expiryDate From then on the task cannot be executed. 0 for infinity.
function submitTask(
Provider calldata _provider,
Task calldata _task,
uint256 _expiryDate
)
external;
/// @notice A Gelato Task Cycle consists of 1 or more Tasks that automatically submit
/// the next one, after they have been executed.
/// @param _provider Gelato Provider object: provider address and module.
/// @param _tasks This can be a single task or a sequence of tasks.
/// @param _expiryDate After this no task of the sequence can be executed any more.
/// @param _cycles How many full cycles will be submitted
function submitTaskCycle(
Provider calldata _provider,
Task[] calldata _tasks,
uint256 _expiryDate,
uint256 _cycles
)
external;
/// @notice A Gelato Task Cycle consists of 1 or more Tasks that automatically submit
/// the next one, after they have been executed.
/// @dev CAUTION: _sumOfRequestedTaskSubmits does not mean the number of cycles.
/// @dev If _sumOfRequestedTaskSubmits = 1 && _tasks.length = 2, only the first task
/// would be submitted, but not the second
/// @param _provider Gelato Provider object: provider address and module.
/// @param _tasks This can be a single task or a sequence of tasks.
/// @param _expiryDate After this no task of the sequence can be executed any more.
/// @param _sumOfRequestedTaskSubmits The TOTAL number of Task auto-submits
/// that should have occured once the cycle is complete:
/// _sumOfRequestedTaskSubmits = 0 => One Task will resubmit the next Task infinitly
/// _sumOfRequestedTaskSubmits = 1 => One Task will resubmit no other task
/// _sumOfRequestedTaskSubmits = 2 => One Task will resubmit 1 other task
/// ...
function submitTaskChain(
Provider calldata _provider,
Task[] calldata _tasks,
uint256 _expiryDate,
uint256 _sumOfRequestedTaskSubmits
)
external;
// ================ Exec Suite =========================
/// @notice Off-chain API for executors to check, if a TaskReceipt is executable
/// @dev GelatoCore checks this during execution, in order to safeguard the Conditions
/// @param _TR TaskReceipt, consisting of user task, user proxy address and id
/// @param _gasLimit Task.selfProviderGasLimit is used for SelfProviders. All other
/// Providers must use gelatoMaxGas. If the _gasLimit is used by an Executor and the
/// tx reverts, a refund is paid by the Provider and the TaskReceipt is annulated.
/// @param _execTxGasPrice Must be used by Executors. Gas Price fed by gelatoCore's
/// Gas Price Oracle. Executors can query the current gelatoGasPrice from events.
function canExec(TaskReceipt calldata _TR, uint256 _gasLimit, uint256 _execTxGasPrice)
external
view
returns(string memory);
/// @notice Executors call this when Conditions allow it to execute submitted Tasks.
/// @dev Executors get rewarded for successful Execution. The Task remains open until
/// successfully executed, or when the execution failed, despite of gelatoMaxGas usage.
/// In the latter case Executors are refunded by the Task Provider.
/// @param _TR TaskReceipt: id, userProxy, Task.
function exec(TaskReceipt calldata _TR) external;
/// @notice Cancel task
/// @dev Callable only by userProxy or selected provider
/// @param _TR TaskReceipt: id, userProxy, Task.
function cancelTask(TaskReceipt calldata _TR) external;
/// @notice Cancel multiple tasks at once
/// @dev Callable only by userProxy or selected provider
/// @param _taskReceipts TaskReceipts: id, userProxy, Task.
function multiCancelTasks(TaskReceipt[] calldata _taskReceipts) external;
/// @notice Compute hash of task receipt
/// @param _TR TaskReceipt, consisting of user task, user proxy address and id
/// @return hash of taskReceipt
function hashTaskReceipt(TaskReceipt calldata _TR) external pure returns(bytes32);
// ================ Getters =========================
/// @notice Returns the taskReceiptId of the last TaskReceipt submitted
/// @return currentId currentId, last TaskReceiptId submitted
function currentTaskReceiptId() external view returns(uint256);
/// @notice Returns computed taskReceipt hash, used to check for taskReceipt validity
/// @param _taskReceiptId Id of taskReceipt emitted in submission event
/// @return hash of taskReceipt
function taskReceiptHash(uint256 _taskReceiptId) external view returns(bytes32);
}