-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathAutomationLib.sol
More file actions
93 lines (83 loc) · 2.77 KB
/
AutomationLib.sol
File metadata and controls
93 lines (83 loc) · 2.77 KB
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
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright 2017 Loopring Technology Limited.
pragma solidity ^0.8.17;
import "./InheritanceLib.sol";
import "./WalletData.sol";
import "../../account-abstraction/interfaces/UserOperation.sol";
import "../../iface/IConnectorRegistry.sol";
library AutomationLib {
using InheritanceLib for Wallet;
event AutomationApproveExecutor(
address wallet,
address executor,
uint validUntils
);
function _spell(
address _target,
bytes memory _data
) private returns (bytes memory response) {
require(_target != address(0), "target-invalid");
// solhint-disable-next-line no-inline-assembly
assembly {
let succeeded := delegatecall(
gas(),
_target,
add(_data, 0x20),
mload(_data),
0,
0
)
let size := returndatasize()
response := mload(0x40)
mstore(
0x40,
add(response, and(add(add(size, 0x20), 0x1f), not(0x1f)))
)
mstore(response, size)
returndatacopy(add(response, 0x20), 0, size)
switch iszero(succeeded)
case 1 {
// throw if delegatecall failed
returndatacopy(0x00, 0x00, size)
revert(0x00, size)
}
}
}
function isExecutorOrOwner(
Wallet storage wallet,
address executor
) internal view returns (bool) {
bool isOwner = executor == wallet.owner;
bool isExecutor = wallet.executorsPermission[executor] >
// solhint-disable-next-line not-rely-on-time
block.timestamp;
return isExecutor || isOwner;
}
function cast(
address connectorRegistry,
address[] calldata targets,
bytes[] calldata datas
) internal {
require(connectorRegistry != address(0), "disabled connector registry");
uint256 _length = targets.length;
require(_length == datas.length, "different length");
// check all targets is valid
require(
IConnectorRegistry(connectorRegistry).isConnectors(targets),
"valid connector"
);
for (uint i = 0; i < _length; i++) {
_spell(targets[i], datas[i]);
}
}
function approveExecutor(
Wallet storage wallet,
address executor,
uint256 validUntil
) internal {
uint256 curValidUntil = wallet.executorsPermission[executor];
require(curValidUntil == 0 || validUntil == 0, "approve failed");
wallet.executorsPermission[executor] = validUntil;
emit AutomationApproveExecutor(address(this), executor, validUntil);
}
}