-
Notifications
You must be signed in to change notification settings - Fork 5
/
DaycareManager.sol
46 lines (40 loc) · 1.64 KB
/
DaycareManager.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "../interfaces/IAdventureTime.sol";
contract DaycareManager {
IAdventureTime adventureTime =
IAdventureTime(0x0D4C98901563ca730332e841EDBCB801fe9F2551);
uint256 public constant DAILY_FEE = 0.1 * 1e18;
mapping(uint256 => uint256) public daysPaid;
event registeredDaycare(
address _registerer,
uint256 _summonerId,
uint256 _days
);
event executedDaycare(address _executor, uint256 _summonerId);
function registerDaycare(
uint256[] calldata _summonerIds,
uint256[] calldata _days
) external payable {
uint256 len = _summonerIds.length;
require(len == _days.length, "DCM: Invalid lengths");
uint256 totalFee = 0;
for (uint256 i = 0; i < len; i++) {
require(_days[i] > 0, "DCM: Cannot daycare for 0 days");
daysPaid[_summonerIds[i]] += _days[i];
totalFee += _days[i] * DAILY_FEE;
emit registeredDaycare(msg.sender, _summonerIds[i], _days[i]);
}
require(msg.value >= totalFee, "DCM: Insufficient fee");
// Don't send too much FTM, otherwise it will be stuck in the contract
}
function executeDaycare(uint256[] calldata _summonerIds) external {
for (uint256 i = 0; i < _summonerIds.length; i++) {
daysPaid[_summonerIds[i]] -= 1;
emit executedDaycare(msg.sender, _summonerIds[i]);
}
// Below line will revert if any summoners can't be adventured
adventureTime.adventureTime(_summonerIds);
payable(msg.sender).transfer(_summonerIds.length * DAILY_FEE);
}
}