-
Notifications
You must be signed in to change notification settings - Fork 9
/
OpenQV1.sol
executable file
·433 lines (372 loc) · 14.9 KB
/
OpenQV1.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import '../Storage/OpenQStorage.sol';
import '../../Library/ASCIIUtils.sol';
/// @title OpenQV1
/// @author FlacoJones
/// @notice Main administrative contract for all bounty operations
/// @dev Do not add any new storage variables here. Put them in a OpenQStorageV# and release new implementation
contract OpenQV1 is OpenQStorageV1 {
using ASCIIUtils for string;
constructor() {
_disableInitializers();
}
/// @notice Initializes the OpenQ implementation with necessary storage variables like owner
function initialize(
address _initialOracle,
address _bountyFactory,
address _depositManager,
address _claimManager
) external initializer onlyProxy {
__Ownable_init();
__Oraclize_init(_initialOracle);
__UUPSUpgradeable_init();
__ReentrancyGuard_init();
bountyFactory = _bountyFactory;
depositManager = _depositManager;
claimManager = _claimManager;
}
function batchMintBounty(
string[] calldata _bountyIds,
string[] calldata _organizations,
OpenQDefinitions.InitOperation[] memory _initOperations
) external nonReentrant onlyProxy {
for (uint i = 0; i < _bountyIds.length; i++) {
this.mintBounty(
_bountyIds[i],
_organizations[i],
_initOperations[i]
);
}
}
/// @notice Mints a new bounty BeaconProxy using BountyFactory
/// @param _bountyId A unique string to identify a bounty
/// @param _organization The ID of the organization which owns the bounty
/// @param _initOperation The ABI encoded data determining the type of bounty being initialized and associated data
/// @dev see IBountyCore.initialize.(_operation) for _operation ABI encoding schema
/// @return bountyAddress The address of the newly minted bounty
function mintBounty(
string calldata _bountyId,
string calldata _organization,
OpenQDefinitions.InitOperation memory _initOperation
) external nonReentrant onlyProxy returns (address) {
require(
bountyIdToAddress[_bountyId] == address(0),
Errors.BOUNTY_ALREADY_EXISTS
);
require(_bountyId.isAscii(), Errors.INVALID_STRING);
require(_organization.isAscii(), Errors.INVALID_STRING);
address bountyAddress = BountyFactory(bountyFactory).mintBounty(
_bountyId,
msg.sender,
_organization,
claimManager,
depositManager,
_initOperation
);
bountyIdToAddress[_bountyId] = bountyAddress;
emit BountyCreated(
_bountyId,
_organization,
msg.sender,
bountyAddress,
block.timestamp,
bountyType(_bountyId),
_initOperation.data,
VERSION_1
);
return bountyAddress;
}
/// @notice Sets the BountyFactory
/// @param _bountyFactory The BountyFactory address
function setBountyFactory(
address _bountyFactory
) external onlyProxy onlyOwner {
bountyFactory = _bountyFactory;
}
/// @notice Sets ClaimManager proxy address
/// @param _claimManager The ClaimManager address
function setClaimManager(
address _claimManager
) external onlyProxy onlyOwner {
claimManager = _claimManager;
}
/// @notice Sets DepositManager proxy address
/// @param _depositManager The DepositManager address
function setDepositManager(
address _depositManager
) external onlyProxy onlyOwner {
depositManager = _depositManager;
}
function batchSetTierWinner(
string[] calldata _bountyIds,
uint256[] calldata _tiers,
string[] calldata _winners
) external nonReentrant onlyProxy {
for (uint i = 0; i < _bountyIds.length; i++) {
this.setTierWinner(_bountyIds[i], _tiers[i], _winners[i]);
}
}
/// @notice Sets a winner for a particular tier
/// @param _bountyId The bounty id
/// @param _tier The tier they won
/// @param _winner The external UUID (e.g. an OpenQ User UUID) that won this tier
/// @dev Only callable by the bounty admin (AKA the minter of the bounty)
function setTierWinner(
string calldata _bountyId,
uint256 _tier,
string calldata _winner
) external {
IBounty bounty = getBounty(_bountyId);
require(msg.sender == bounty.issuer(), Errors.CALLER_NOT_ISSUER);
bounty.setTierWinner(_winner, _tier);
emit TierWinnerSelected(
address(bounty),
bounty.getTierWinners(),
new bytes(0),
VERSION_1
);
}
/// @notice Sets fundingGoal for bounty with id _bountyId
/// @param _bountyId The id to update
/// @param _fundingGoalToken The token address to be used for the funding goal
/// @param _fundingGoalVolume The volume of token to be used for the funding goal
function setFundingGoal(
string calldata _bountyId,
address _fundingGoalToken,
uint256 _fundingGoalVolume
) external onlyProxy {
IBounty bounty = getBounty(_bountyId);
require(msg.sender == bounty.issuer(), Errors.CALLER_NOT_ISSUER);
bounty.setFundingGoal(_fundingGoalToken, _fundingGoalVolume);
emit FundingGoalSet(
address(bounty),
_fundingGoalToken,
_fundingGoalVolume,
bounty.bountyType(),
new bytes(0),
VERSION_1
);
}
/// @notice Sets kycRequired on bounty with id _bountyId
/// @param _bountyId The id to update
/// @param _kycRequired Whether or not KYC is required for a bounty
function setKycRequired(
string calldata _bountyId,
bool _kycRequired
) external onlyProxy {
IBounty bounty = getBounty(_bountyId);
require(msg.sender == bounty.issuer(), Errors.CALLER_NOT_ISSUER);
bounty.setKycRequired(_kycRequired);
emit KYCRequiredSet(
address(bounty),
_kycRequired,
bounty.bountyType(),
new bytes(0),
VERSION_1
);
}
/// @notice Sets invoiceRequired on bounty with id _bountyId
/// @param _bountyId The id to update
/// @param _invoiceRequired Whether or not the bounty should be set as invoiceRequired
function setInvoiceRequired(
string calldata _bountyId,
bool _invoiceRequired
) external onlyProxy {
IBounty bounty = getBounty(_bountyId);
require(msg.sender == bounty.issuer(), Errors.CALLER_NOT_ISSUER);
bounty.setInvoiceRequired(_invoiceRequired);
emit InvoiceRequiredSet(
address(bounty),
_invoiceRequired,
bounty.bountyType(),
new bytes(0),
VERSION_1
);
}
/// @notice Sets whether or not supporting documents will be required to claim a bounty
/// @param _bountyId The id to update
/// @param _supportingDocumentsRequired Whether or not supporting documents are required to claim this bounty
function setSupportingDocumentsRequired(
string calldata _bountyId,
bool _supportingDocumentsRequired
) external onlyProxy {
IBounty bounty = getBounty(_bountyId);
require(msg.sender == bounty.issuer(), Errors.CALLER_NOT_ISSUER);
bounty.setSupportingDocumentsRequired(_supportingDocumentsRequired);
emit SupportingDocumentsRequiredSet(
address(bounty),
_supportingDocumentsRequired,
bounty.bountyType(),
new bytes(0),
VERSION_1
);
}
function batchSetInvoiceComplete(
string[] calldata _bountyIds,
bytes[] calldata _data
) external nonReentrant onlyProxy {
for (uint i = 0; i < _bountyIds.length; i++) {
this.setInvoiceComplete(_bountyIds[i], _data[i]);
}
}
/// @notice Sets invoiceComplete on bounty with id _bountyId
/// @param _bountyId The id to update
/// @param _data ABI encoded data (A simple bool for AtomicContract, a (string, bool) of claimId for Ongoing, and a (uint256, bool) for TieredBounty to specify the tier it was completed for)
function setInvoiceComplete(
string calldata _bountyId,
bytes calldata _data
) external onlyProxy {
IBounty bounty = getBounty(_bountyId);
require(
msg.sender == bounty.issuer() || msg.sender == _oracle,
Errors.CALLER_NOT_ISSUER_OR_ORACLE
);
bounty.setInvoiceComplete(_data);
emit InvoiceCompleteSet(
address(bounty),
bounty.bountyType(),
bounty.getInvoiceComplete(),
VERSION_1
);
}
function batchSetSupportingDocumentsComplete(
string[] calldata _bountyIds,
bytes[] calldata _data
) external nonReentrant onlyProxy {
for (uint i = 0; i < _bountyIds.length; i++) {
this.setSupportingDocumentsComplete(_bountyIds[i], _data[i]);
}
}
/// @notice Sets supportingDocumentsComplete on bounty with id _bountyId
/// @param _bountyId The id to update
/// @param _data ABI encoded data (A simple bool for AtomicContract, a (string, bool) of claimId for Ongoing, and a (uint256, bool) for TieredBounty to specify the tier it was completed for)
function setSupportingDocumentsComplete(
string calldata _bountyId,
bytes calldata _data
) external onlyProxy {
IBounty bounty = getBounty(_bountyId);
require(
msg.sender == bounty.issuer() || msg.sender == _oracle,
Errors.CALLER_NOT_ISSUER_OR_ORACLE
);
bounty.setSupportingDocumentsComplete(_data);
emit SupportingDocumentsCompleteSet(
address(bounty),
bounty.bountyType(),
bounty.getSupportingDocumentsComplete(),
VERSION_1
);
}
/// @notice Sets payout volume array on fixed tiered bounty with id _bountyId
/// @param _bountyId The bounty to update
/// @param _payoutSchedule An array of payout volumes for each tier
/// @param _payoutTokenAddress The address of the token to be used for the payout
function setPayoutScheduleFixed(
string calldata _bountyId,
uint256[] calldata _payoutSchedule,
address _payoutTokenAddress
) external onlyProxy {
IBounty bounty = getBounty(_bountyId);
require(msg.sender == bounty.issuer(), Errors.CALLER_NOT_ISSUER);
bounty.setPayoutScheduleFixed(_payoutSchedule, _payoutTokenAddress);
emit PayoutScheduleSet(
address(bounty),
_payoutTokenAddress,
_payoutSchedule,
bounty.bountyType(),
new bytes(0),
VERSION_1
);
}
/// @notice Checks if bounty associated with _bountyId is open
/// @param _bountyId The bounty id
/// @return True if _bountyId is associated with an open bounty, false otherwise
function bountyIsOpen(
string calldata _bountyId
) public view returns (bool) {
IBounty bounty = getBounty(_bountyId);
bool isOpen = bounty.status() == OpenQDefinitions.OPEN;
return isOpen;
}
/// @notice Returns the bountyType of the bounty (Single(0), Ongoing(1), Tiered(2), or Tiered Fixed(3))
/// @param _bountyId The bounty id
/// @return bountyType - See OpenQDefinitions.sol for values
function bountyType(
string calldata _bountyId
) public view returns (uint256) {
IBounty bounty = getBounty(_bountyId);
uint256 _bountyType = bounty.bountyType();
return _bountyType;
}
/// @notice Retrieves bountyId from a bounty's address
/// @param _bountyAddress The bounty address
/// @return string The bounty id associated with _bountyAddress
function bountyAddressToBountyId(
address _bountyAddress
) external view returns (string memory) {
IBounty bounty = IBounty(payable(_bountyAddress));
return bounty.bountyId();
}
/// @notice Determines whether or not a tier is claimed on a percentage tiered or fixed tiered bounty
/// @param _bountyId The bounty id
/// @param _tier The tier to check
/// @return True if claimed, false otherwise
function tierClaimed(
string calldata _bountyId,
uint256 _tier
) external view returns (bool) {
IBounty bounty = getBounty(_bountyId);
bool _tierClaimed = bounty.tierClaimed(_tier);
return _tierClaimed;
}
/// @notice Returns an IBounty ABI wrapped arround given bounty address
/// @param _bountyId The bounty id
/// @return An IBounty upon which any methods in IBounty can be called
function getBounty(
string calldata _bountyId
) internal view returns (IBounty) {
address bountyAddress = bountyIdToAddress[_bountyId];
IBounty bounty = IBounty(bountyAddress);
return bounty;
}
/// @notice Override for UUPSUpgradeable._authorizeUpgrade(address newImplementation) to enforce onlyOwner upgrades
function _authorizeUpgrade(address) internal override onlyOwner {}
/// @notice Override for ERC1967Upgrade._getImplementation() to expose implementation
/// @return address Implementation address associated with OpenQProxy
function getImplementation() external view returns (address) {
return _getImplementation();
}
/// @notice Exposes internal method Oraclize._transferOracle(address) restricted to onlyOwner called via proxy
/// @param _newOracle The new oracle address
function transferOracle(address _newOracle) external onlyProxy onlyOwner {
require(_newOracle != address(0), Errors.NO_ZERO_ADDRESS);
_transferOracle(_newOracle);
}
/// @notice Establishes a one-to-one mapping between an external user id and an address
/// @param _externalUserId The external user id (e.g. Github user id) to associate
/// @param _associatedAddress The address to associate to _externalUserId
/// @dev It is important that this nulls out the previous addres<=>uuid association
function associateExternalIdToAddress(
string calldata _externalUserId,
address _associatedAddress
) external onlyOracle {
// Clear previous addres<=>off-chain identity associations
string memory formerExternalUserId = addressToExternalUserId[
_associatedAddress
];
address formerAddress = externalUserIdToAddress[_externalUserId];
externalUserIdToAddress[formerExternalUserId] = address(0);
addressToExternalUserId[formerAddress] = '';
externalUserIdToAddress[_externalUserId] = _associatedAddress;
addressToExternalUserId[_associatedAddress] = _externalUserId;
emit ExternalUserIdAssociatedWithAddress(
_externalUserId,
_associatedAddress,
formerExternalUserId,
formerAddress,
new bytes(0),
VERSION_1
);
}
}