-
Notifications
You must be signed in to change notification settings - Fork 7
/
CFABasePCOFacet.sol
192 lines (173 loc) · 5.95 KB
/
CFABasePCOFacet.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
import "../libraries/LibCFABasePCO.sol";
import "../interfaces/ICFABasePCO.sol";
import {CFAv1Library} from "@superfluid-finance/ethereum-contracts/contracts/apps/CFAv1Library.sol";
import {ISuperToken} from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperToken.sol";
import {IERC721} from "@solidstate/contracts/interfaces/IERC721.sol";
import "../../registry/interfaces/IPCOLicenseParamsStore.sol";
import "../../beneficiary/interfaces/ICFABeneficiary.sol";
import {OwnableStorage} from "@solidstate/contracts/access/ownable/OwnableStorage.sol";
contract CFABasePCOFacetModifiers {
using OwnableStorage for OwnableStorage.Layout;
modifier onlyOwner() {
require(
msg.sender == OwnableStorage.layout().owner,
"Ownable: sender must be owner"
);
_;
}
modifier onlyPayer() {
LibCFABasePCO.Bid storage _currentBid = LibCFABasePCO._currentBid();
require(
msg.sender == _currentBid.bidder,
"CFABasePCOFacet: Only payer is allowed to perform this action"
);
_;
}
modifier onlyIfPayerBidActive() {
require(
LibCFABasePCO._isPayerBidActive(),
"CFABasePCOFacet: Can only perform action when payer bid is active"
);
_;
}
modifier onlyNotPayer() {
LibCFABasePCO.Bid storage _currentBid = LibCFABasePCO._currentBid();
require(
msg.sender != _currentBid.bidder,
"CFABasePCOFacet: Payer is not allowed to perform this action"
);
_;
}
}
/// @notice Handles basic PCO functionality using Constant Flow Agreement (CFA)
contract CFABasePCOFacet is ICFABasePCO, CFABasePCOFacetModifiers {
using CFAv1Library for CFAv1Library.InitData;
/**
* @notice Initialize bid.
* - Must be the contract owner
* - Must have payment token buffer deposited
* - Must have permissions to create flow for bidder
* @param paramsStore Global store for parameters
* @param initLicense Underlying ERC721 license
* @param initLicenseId Token ID of license
* @param bidder Initial bidder
* @param newContributionRate New contribution rate for bid
* @param newForSalePrice Intended new for sale price. Must be within rounding bounds of newContributionRate
*/
function initializeBid(
ICFABeneficiary beneficiary,
IPCOLicenseParamsStore paramsStore,
IERC721 initLicense,
uint256 initLicenseId,
address bidder,
int96 newContributionRate,
uint256 newForSalePrice
) external onlyOwner {
LibCFABasePCO._initializeBid(
beneficiary,
paramsStore,
initLicense,
initLicenseId,
bidder,
newContributionRate,
newForSalePrice,
new bytes(0)
);
}
/**
* @notice Initialize bid with content hash
* - Must be the contract owner
* - Must have payment token buffer deposited
* - Must have permissions to create flow for bidder
* @param paramsStore Global store for parameters
* @param initLicense Underlying ERC721 license
* @param initLicenseId Token ID of license
* @param bidder Initial bidder
* @param newContributionRate New contribution rate for bid
* @param newForSalePrice Intented new for sale price. Must be within rounding bounds of newContributionRate
* @param _contentHash Content hash for parcel content
*/
function initializeBid(
ICFABeneficiary beneficiary,
IPCOLicenseParamsStore paramsStore,
IERC721 initLicense,
uint256 initLicenseId,
address bidder,
int96 newContributionRate,
uint256 newForSalePrice,
bytes calldata _contentHash
) external onlyOwner {
LibCFABasePCO._initializeBid(
beneficiary,
paramsStore,
initLicense,
initLicenseId,
bidder,
newContributionRate,
newForSalePrice,
_contentHash
);
}
/**
* @notice Current payer of license
*/
function payer() external view returns (address) {
LibCFABasePCO.Bid storage _currentBid = LibCFABasePCO._currentBid();
return _currentBid.bidder;
}
/**
* @notice Current contribution rate of payer
*/
function contributionRate() external view returns (int96) {
return LibCFABasePCO._contributionRate();
}
/**
* @notice Current price needed to purchase license
*/
function forSalePrice() external view returns (uint256) {
if (LibCFABasePCO._isPayerBidActive()) {
LibCFABasePCO.Bid storage _currentBid = LibCFABasePCO._currentBid();
return _currentBid.forSalePrice;
} else {
return 0;
}
}
/**
* @notice License Id
*/
function licenseId() external view returns (uint256) {
LibCFABasePCO.DiamondStorage storage ds = LibCFABasePCO
.diamondStorage();
return ds.licenseId;
}
/**
* @notice License
*/
function license() external view returns (IERC721) {
LibCFABasePCO.DiamondStorage storage ds = LibCFABasePCO
.diamondStorage();
return ds.license;
}
/**
* @notice Is current bid actively being paid
*/
function isPayerBidActive() external view returns (bool) {
return LibCFABasePCO._isPayerBidActive();
}
/**
* @notice Get current bid
*/
function currentBid() external pure returns (LibCFABasePCO.Bid memory) {
LibCFABasePCO.Bid storage bid = LibCFABasePCO._currentBid();
return bid;
}
/**
* @notice Get content hash
*/
function contentHash() external view returns (bytes memory) {
LibCFABasePCO.Bid storage bid = LibCFABasePCO._currentBid();
return bid.contentHash;
}
}