2021-10-12 14:59:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
2022-02-22 08:25:42 +00:00
|
|
|
import "./Marketplace.sol";
|
2021-11-01 11:30:35 +00:00
|
|
|
import "./Proofs.sol";
|
2022-02-15 16:54:19 +00:00
|
|
|
import "./Collateral.sol";
|
2021-10-12 14:59:34 +00:00
|
|
|
|
2022-02-22 08:25:42 +00:00
|
|
|
contract Storage is Collateral, Marketplace, Proofs {
|
2022-02-15 16:54:19 +00:00
|
|
|
uint256 public collateralAmount;
|
2022-02-09 13:17:23 +00:00
|
|
|
uint256 public slashMisses;
|
|
|
|
uint256 public slashPercentage;
|
2021-11-02 10:19:52 +00:00
|
|
|
|
2022-02-09 13:17:23 +00:00
|
|
|
mapping(bytes32 => bool) private finished;
|
2021-11-04 10:18:05 +00:00
|
|
|
|
2021-11-04 13:19:58 +00:00
|
|
|
constructor(
|
|
|
|
IERC20 token,
|
2022-03-02 14:44:58 +00:00
|
|
|
uint256 _proofPeriod,
|
|
|
|
uint256 _proofTimeout,
|
2022-03-10 09:19:21 +00:00
|
|
|
uint8 _proofDowntime,
|
2022-02-15 16:54:19 +00:00
|
|
|
uint256 _collateralAmount,
|
2022-02-09 13:17:23 +00:00
|
|
|
uint256 _slashMisses,
|
|
|
|
uint256 _slashPercentage
|
2022-03-10 09:19:21 +00:00
|
|
|
)
|
|
|
|
Marketplace(token, _collateralAmount)
|
|
|
|
Proofs(_proofPeriod, _proofTimeout, _proofDowntime)
|
|
|
|
{
|
2022-02-15 16:54:19 +00:00
|
|
|
collateralAmount = _collateralAmount;
|
2021-11-04 13:19:58 +00:00
|
|
|
slashMisses = _slashMisses;
|
|
|
|
slashPercentage = _slashPercentage;
|
2021-11-02 11:45:09 +00:00
|
|
|
}
|
2021-10-20 10:07:35 +00:00
|
|
|
|
2022-02-22 08:25:42 +00:00
|
|
|
function startContract(bytes32 id) public {
|
|
|
|
Offer storage offer = _offer(id);
|
|
|
|
require(msg.sender == offer.host, "Only host can call this function");
|
|
|
|
Request storage request = _request(offer.requestId);
|
2022-03-08 14:58:08 +00:00
|
|
|
_expectProofs(id, request.proofProbability, request.duration);
|
2021-11-04 08:49:07 +00:00
|
|
|
}
|
|
|
|
|
2021-11-04 09:19:23 +00:00
|
|
|
function finishContract(bytes32 id) public {
|
2022-03-08 14:58:08 +00:00
|
|
|
require(block.timestamp > proofEnd(id), "Contract has not ended yet");
|
2021-11-04 10:18:05 +00:00
|
|
|
require(!finished[id], "Contract already finished");
|
|
|
|
finished[id] = true;
|
2022-02-22 08:25:42 +00:00
|
|
|
Offer storage offer = _offer(id);
|
|
|
|
require(token.transfer(offer.host, offer.price), "Payment failed");
|
2021-11-04 08:49:07 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 14:44:58 +00:00
|
|
|
function proofPeriod() public view returns (uint256) {
|
|
|
|
return _period();
|
|
|
|
}
|
|
|
|
|
|
|
|
function proofTimeout() public view returns (uint256) {
|
|
|
|
return _timeout();
|
|
|
|
}
|
|
|
|
|
2022-02-09 13:17:23 +00:00
|
|
|
function proofEnd(bytes32 contractId) public view returns (uint256) {
|
2021-11-04 08:49:07 +00:00
|
|
|
return _end(contractId);
|
2021-11-01 15:17:42 +00:00
|
|
|
}
|
|
|
|
|
2022-02-09 13:17:23 +00:00
|
|
|
function missingProofs(bytes32 contractId) public view returns (uint256) {
|
2021-11-01 15:17:42 +00:00
|
|
|
return _missed(contractId);
|
2021-10-20 10:07:35 +00:00
|
|
|
}
|
|
|
|
|
2022-03-08 14:58:08 +00:00
|
|
|
function isProofRequired(bytes32 contractId) public view returns (bool) {
|
|
|
|
return _isProofRequired(contractId);
|
2021-10-14 10:37:14 +00:00
|
|
|
}
|
2021-10-18 12:55:59 +00:00
|
|
|
|
2022-03-08 14:58:08 +00:00
|
|
|
function submitProof(bytes32 contractId, bool proof) public {
|
|
|
|
_submitProof(contractId, proof);
|
2021-10-19 07:37:03 +00:00
|
|
|
}
|
|
|
|
|
2022-03-08 14:58:08 +00:00
|
|
|
function markProofAsMissing(bytes32 contractId, uint256 period) public {
|
|
|
|
_markProofAsMissing(contractId, period);
|
2021-11-04 13:19:58 +00:00
|
|
|
if (_missed(contractId) % slashMisses == 0) {
|
2022-02-22 08:25:42 +00:00
|
|
|
Offer storage offer = _offer(contractId);
|
|
|
|
_slash(offer.host, slashPercentage);
|
2021-11-04 13:19:58 +00:00
|
|
|
}
|
2021-10-19 07:37:03 +00:00
|
|
|
}
|
2021-10-12 14:59:34 +00:00
|
|
|
}
|