This repository has been archived by the owner on Oct 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WRentable.sol
102 lines (86 loc) · 3.13 KB
/
WRentable.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
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.7;
// Inheritance
import {IERC721ExistExtension} from "../interfaces/IERC721ExistExtension.sol";
import {BaseTokenInitializable} from "./BaseTokenInitializable.sol";
// References
import {IERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";
import {IRentable} from "../interfaces/IRentable.sol";
import {IWRentableHooks} from "../interfaces/IWRentableHooks.sol";
import {ERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
/// @title WToken
/// @author Rentable Team <[email protected]>
/// @custom:security Rentable Security Team <[email protected]>
/// @notice Represents a transferrable tokenized rental and mimics the wrapped token
contract WRentable is IERC721ExistExtension, BaseTokenInitializable {
/* ========== CONSTRUCTOR ========== */
/// @notice Instantiate a token
/// @param wrapped wrapped token address
/// @param owner admin for the contract
/// @param rentable rentable address
constructor(
address wrapped,
address owner,
address rentable
) BaseTokenInitializable(wrapped, owner, rentable) {}
/* ========== VIEWS ========== */
/* ---------- Internal ---------- */
/// @inheritdoc BaseTokenInitializable
function _getPrefix() internal virtual override returns (string memory) {
return "w";
}
/// @dev Check ownership eventually skipping expire check
/// @param tokenId token id
/// @param skipExpirationCheck when true, return current owner skipping expire check
/// @return owner address
function _ownerOf(uint256 tokenId, bool skipExpirationCheck)
internal
view
returns (address)
{
// Eventually check rental expiration
if (
skipExpirationCheck ||
!IRentable(getRentable()).isExpired(getWrapped(), tokenId)
) {
return super.ownerOf(tokenId);
} else {
return address(0);
}
}
/* ---------- Public ---------- */
/// @inheritdoc IERC721Upgradeable
function ownerOf(uint256 tokenId) public view override returns (address) {
return _ownerOf(tokenId, false);
}
/// @inheritdoc IERC721ExistExtension
function ownerOf(uint256 tokenId, bool skipExpirationCheck)
external
view
override
returns (address)
{
return _ownerOf(tokenId, skipExpirationCheck);
}
/// @inheritdoc IERC721ExistExtension
function exists(uint256 tokenId) external view override returns (bool) {
return super._exists(tokenId);
}
/* ========== MUTATIVE FUNCTIONS ========== */
/* ---------- Internal ---------- */
/// @inheritdoc ERC721Upgradeable
function _transfer(
address from,
address to,
uint256 tokenId
) internal override {
// Notify Rentable after successful transfer
super._transfer(from, to, tokenId);
IWRentableHooks(getRentable()).afterWTokenTransfer(
getWrapped(),
from,
to,
tokenId
);
}
}