-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCampaignGeneric.sol
More file actions
54 lines (44 loc) · 1.75 KB
/
Copy pathCampaignGeneric.sol
File metadata and controls
54 lines (44 loc) · 1.75 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "../rewards/same-chain/RewardsClaim.sol";
import "./RewardsUpdateGeneric.sol";
contract CampaignGeneric is RewardsUpdateGeneric, RewardsClaim {
using SafeERC20 for IERC20;
// called by proxy to properly set storage of proxy contract, owner is contract owner (hw or multisig)
function init(
ConfigGeneric calldata cfg,
IBrevisProof brv,
address owner,
bytes32[] calldata vks,
uint64 dataChainId,
address rewardUpdater,
address externalPayoutAddress
) external {
initOwner(owner);
_initConfig(cfg, brv, vks, dataChainId);
_grantRole(REWARD_UPDATER_ROLE, rewardUpdater);
_setExternalPayoutAddress(externalPayoutAddress);
}
// ----- external functions -----
// after grace period, refund all remaining balance to creator
function refund() external {
ConfigGeneric memory cfg = config;
require(block.timestamp > cfg.startTime + cfg.duration + gracePeriod, "too soon");
for (uint256 i = 0; i < cfg.rewards.length; i++) {
address erc20 = cfg.rewards[i].token;
IERC20(erc20).safeTransfer(cfg.creator, IERC20(erc20).balanceOf(address(this)));
}
}
function canRefund() external view returns (bool) {
return block.timestamp > config.startTime + config.duration + gracePeriod;
}
// ----- internal functions -----
function _useEnumerableMap() internal pure override returns (bool) {
return false;
}
function _updatable() internal pure override returns (bool) {
return true;
}
}