File size: 1,641 Bytes
cc183a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC4907} from "./interfaces/IERC4907.sol";

contract RenterReward13 {
    address public immutable collection;
    address public immutable feeToken;
    uint256 public immutable feeAmount;
    address public immutable rewardToken;
    uint256 public immutable rewardAmount;

    mapping(uint256 => uint256) public lastClaimDay;

    event RewardClaimed(uint256 indexed passId, address indexed renter, address indexed boundAccount, uint256 rewardAmount);

    constructor(
        address collection_,
        address feeToken_,
        uint256 feeAmount_,
        address rewardToken_,
        uint256 rewardAmount_
    ) {
        collection = collection_;
        feeToken = feeToken_;
        feeAmount = feeAmount_;
        rewardToken = rewardToken_;
        rewardAmount = rewardAmount_;
    }

    function claimReward(uint256 passId, address boundAccount) external {
        require(IERC4907(collection).userOf(passId) == msg.sender, "caller is not active user");
        uint256 today = (block.timestamp / 86400) + 1;
        require(lastClaimDay[passId] < today, "already claimed today");

        require(
            IERC20(feeToken).transferFrom(boundAccount, address(this), feeAmount),
            "fee transfer failed"
        );

        lastClaimDay[passId] = today;
        require(
            IERC20(rewardToken).transfer(msg.sender, rewardAmount),
            "reward transfer failed"
        );

        emit RewardClaimed(passId, msg.sender, boundAccount, rewardAmount);
    }
}