-
Notifications
You must be signed in to change notification settings - Fork 2
/
RewardSystem.sol
130 lines (115 loc) · 4.83 KB
/
RewardSystem.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
// SPDX-License-Identifier: Immuni Software PTE Ltd General Source License
// https://github.com/immunefi-team/vaults/blob/main/LICENSE.md
pragma solidity 0.8.18;
import { Enum } from "@gnosis.pm/safe-contracts/contracts/common/Enum.sol";
import { GnosisSafe } from "@gnosis.pm/safe-contracts/contracts/GnosisSafe.sol";
import { Rewards } from "./common/Rewards.sol";
import { RewardSystemBase } from "./base/RewardSystemBase.sol";
/**
* @title RewardSystem
* @author Immunefi
* @notice A component to enable sending rewards
*/
contract RewardSystem is RewardSystemBase {
constructor() {
_disableInitializers();
}
/**
* @notice Initializes the contract.
* @param _owner Default admin role recipient
* @param _module Address of the ImmunefiModule
* @param _vaultDelegate Address of the VaultDelegate
* @param _arbitration Address of the Arbitration
* @param _vaultFreezer Address of the VaultFreezer
*/
function setUp(
address _owner,
address _module,
address _vaultDelegate,
address _arbitration,
address _vaultFreezer
) public initializer {
__AccessControl_init();
require(_owner != address(0), "RewardSystem: owner cannot be 0x00");
_setModule(_module);
_setVaultDelegate(_vaultDelegate);
_setArbitration(_arbitration);
_setVaultFreezer(_vaultFreezer);
_grantRole(DEFAULT_ADMIN_ROLE, _owner);
emit RewardSystemSetup(msg.sender, _owner);
}
/**
* @notice Enforces sendReward on a vault.
* @param referenceId The reference id of the report.
* @param to The address of the recipient.
* @param tokenAmounts The amounts of tokens to send.
* @param nativeTokenAmount The amount of native tokens to send.
* @param vault The address of the vault.
* @param gasToTarget The gas limit getting forwarded to the `to` address.
*/
function enforceSendReward(
uint96 referenceId,
address to,
Rewards.ERC20Reward[] calldata tokenAmounts,
uint256 nativeTokenAmount,
address vault,
uint256 gasToTarget
) external onlyRole(ENFORCER_ROLE) {
require(to != address(0), "RewardSystem: to cannot be 0x00");
require(arbitration.vaultIsInArbitration(vault), "RewardSystem: vault is not in arbitration");
bytes memory data = abi.encodeCall(
vaultDelegate.sendReward,
(referenceId, to, tokenAmounts, nativeTokenAmount, gasToTarget)
);
immunefiModule.execute(vault, address(vaultDelegate), 0, data, Enum.Operation.DelegateCall);
}
/**
* @notice Enforces sendRewardNoFees on a vault.
* @param referenceId The reference id of the report.
* @param to The address of the recipient.
* @param tokenAmounts The amounts of tokens to send.
* @param nativeTokenAmount The amount of native tokens to send.
* @param vault The address of the vault.
* @param gasToTarget The gas limit getting forwarded to the `to` address.
*/
function enforceSendRewardNoFees(
uint96 referenceId,
address to,
Rewards.ERC20Reward[] calldata tokenAmounts,
uint256 nativeTokenAmount,
address vault,
uint256 gasToTarget
) external onlyRole(ENFORCER_ROLE) {
require(to != address(0), "RewardSystem: to cannot be 0x00");
require(arbitration.vaultIsInArbitration(vault), "RewardSystem: vault is not in arbitration");
bytes memory data = abi.encodeCall(
vaultDelegate.sendRewardNoFees,
(referenceId, to, tokenAmounts, nativeTokenAmount, gasToTarget)
);
immunefiModule.execute(vault, address(vaultDelegate), 0, data, Enum.Operation.DelegateCall);
}
/**
* @notice Sends reward. Callable by the vault itself.
* @param referenceId The reference id of the report.
* @param to The address of the recipient.
* @param tokenAmounts The amounts of tokens to send.
* @param nativeTokenAmount The amount of native tokens to send.
* @param gasToTarget The gas limit getting forwarded to the `to` address.
*/
function sendRewardByVault(
uint96 referenceId,
address to,
Rewards.ERC20Reward[] calldata tokenAmounts,
uint256 nativeTokenAmount,
uint256 gasToTarget
) external {
require(to != address(0), "RewardSystem: to cannot be 0x00");
require(!vaultFreezer.isFrozen(msg.sender), "RewardSystem: vault is frozen");
require(!arbitration.vaultIsInArbitration(msg.sender), "RewardSystem: vault is in arbitration");
bytes memory data = abi.encodeCall(
vaultDelegate.sendReward,
(referenceId, to, tokenAmounts, nativeTokenAmount, gasToTarget)
);
immunefiModule.execute(msg.sender, address(vaultDelegate), 0, data, Enum.Operation.DelegateCall);
}
}