-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrustedForwarder.sol
More file actions
46 lines (38 loc) · 1.66 KB
/
TrustedForwarder.sol
File metadata and controls
46 lines (38 loc) · 1.66 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
cat > ~/tips-ecosystem/contracts/TrustedForwarder.sol << 'EOF'
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/access/Ownable.sol";
/**
* @title TrustedForwarder
* @dev Forwarder contract for gasless meta-transactions
*/
contract TrustedForwarder is Ownable {
mapping(address => bool) public trustedConsumers;
mapping(address => uint256) public lastTransactionTime;
uint256 public constant COOLDOWN_PERIOD = 1 hours;
event ConsumerAdded(address indexed consumer);
event ConsumerRemoved(address indexed consumer);
event MetaTransactionExecuted(address indexed user, address indexed target, bool success);
constructor() Ownable() {}
function addTrustedConsumer(address consumer) external onlyOwner {
trustedConsumers[consumer] = true;
emit ConsumerAdded(consumer);
}
function removeTrustedConsumer(address consumer) external onlyOwner {
trustedConsumers[consumer] = false;
emit ConsumerRemoved(consumer);
}
function executeMetaTransaction(
address userAddress,
bytes calldata functionSignature,
address targetContract
) external payable returns (bytes memory) {
require(trustedConsumers[targetContract], "Target contract not trusted");
require(block.timestamp > lastTransactionTime[userAddress] + COOLDOWN_PERIOD, "Too frequent");
lastTransactionTime[userAddress] = block.timestamp;
(bool success, bytes memory ret) = targetContract.call(functionSignature);
emit MetaTransactionExecuted(userAddress, targetContract, success);
return ret;
}
}
EOF