/
AutomateTaskCreator.sol
86 lines (73 loc) · 2.3 KB
/
AutomateTaskCreator.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.14;
import "./AutomateReady.sol";
/**
* @dev Inherit this contract to allow your smart contract
* to be a task creator and create tasks.
*/
abstract contract AutomateTaskCreator is AutomateReady {
using SafeERC20 for IERC20;
address public immutable fundsOwner;
ITaskTreasuryUpgradable public immutable taskTreasury;
constructor(address _automate, address _fundsOwner)
AutomateReady(_automate, address(this))
{
fundsOwner = _fundsOwner;
taskTreasury = automate.taskTreasury();
}
/**
* @dev
* Withdraw funds from this contract's Gelato balance to fundsOwner.
*/
function withdrawFunds(uint256 _amount, address _token) external {
require(
msg.sender == fundsOwner,
"Only funds owner can withdraw funds"
);
taskTreasury.withdrawFunds(payable(fundsOwner), _token, _amount);
}
function _depositFunds(uint256 _amount, address _token) internal {
uint256 ethValue = _token == ETH ? _amount : 0;
taskTreasury.depositFunds{value: ethValue}(
address(this),
_token,
_amount
);
}
function _createTask(
address _execAddress,
bytes memory _execDataOrSelector,
ModuleData memory _moduleData,
address _feeToken
) internal returns (bytes32) {
return
automate.createTask(
_execAddress,
_execDataOrSelector,
_moduleData,
_feeToken
);
}
function _cancelTask(bytes32 _taskId) internal {
automate.cancelTask(_taskId);
}
function _resolverModuleArg(
address _resolverAddress,
bytes memory _resolverData
) internal pure returns (bytes memory) {
return abi.encode(_resolverAddress, _resolverData);
}
function _timeModuleArg(uint256 _startTime, uint256 _interval)
internal
pure
returns (bytes memory)
{
return abi.encode(uint128(_startTime), uint128(_interval));
}
function _proxyModuleArg() internal pure returns (bytes memory) {
return bytes("");
}
function _singleExecModuleArg() internal pure returns (bytes memory) {
return bytes("");
}
}