2021-10-12 16:59:34 +02:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
2022-02-22 09:25:42 +01:00
|
|
|
import "./Marketplace.sol";
|
2021-11-01 12:30:35 +01:00
|
|
|
import "./Proofs.sol";
|
2022-02-15 17:54:19 +01:00
|
|
|
import "./Collateral.sol";
|
2021-10-12 16:59:34 +02:00
|
|
|
|
2022-06-13 10:40:18 +02:00
|
|
|
contract Storage is Collateral, Marketplace {
|
2022-02-15 17:54:19 +01:00
|
|
|
uint256 public collateralAmount;
|
2022-02-09 14:17:23 +01:00
|
|
|
uint256 public slashMisses;
|
|
|
|
uint256 public slashPercentage;
|
2021-11-02 11:19:52 +01:00
|
|
|
|
2022-06-13 12:17:37 +02:00
|
|
|
mapping(bytes32 => bool) private contractFinished;
|
2021-11-04 11:18:05 +01:00
|
|
|
|
2021-11-04 14:19:58 +01:00
|
|
|
constructor(
|
|
|
|
IERC20 token,
|
2022-03-02 15:44:58 +01:00
|
|
|
uint256 _proofPeriod,
|
|
|
|
uint256 _proofTimeout,
|
2022-03-10 10:19:21 +01:00
|
|
|
uint8 _proofDowntime,
|
2022-02-15 17:54:19 +01:00
|
|
|
uint256 _collateralAmount,
|
2022-02-09 14:17:23 +01:00
|
|
|
uint256 _slashMisses,
|
|
|
|
uint256 _slashPercentage
|
2022-03-10 10:19:21 +01:00
|
|
|
)
|
2022-06-13 10:40:18 +02:00
|
|
|
Marketplace(
|
|
|
|
token,
|
|
|
|
_collateralAmount,
|
|
|
|
_proofPeriod,
|
|
|
|
_proofTimeout,
|
|
|
|
_proofDowntime
|
|
|
|
)
|
2022-03-10 10:19:21 +01:00
|
|
|
{
|
2022-02-15 17:54:19 +01:00
|
|
|
collateralAmount = _collateralAmount;
|
2021-11-04 14:19:58 +01:00
|
|
|
slashMisses = _slashMisses;
|
|
|
|
slashPercentage = _slashPercentage;
|
2021-11-02 12:45:09 +01:00
|
|
|
}
|
2021-10-20 12:07:35 +02:00
|
|
|
|
2022-04-06 14:52:02 +02:00
|
|
|
function getRequest(bytes32 id) public view returns (Request memory) {
|
|
|
|
return _request(id);
|
|
|
|
}
|
|
|
|
|
2021-11-04 10:19:23 +01:00
|
|
|
function finishContract(bytes32 id) public {
|
2022-06-13 12:17:37 +02:00
|
|
|
require(_host(id) != address(0), "Contract not started");
|
|
|
|
require(!contractFinished[id], "Contract already finished");
|
2022-03-08 15:58:08 +01:00
|
|
|
require(block.timestamp > proofEnd(id), "Contract has not ended yet");
|
2022-06-13 12:17:37 +02:00
|
|
|
contractFinished[id] = true;
|
|
|
|
require(
|
|
|
|
token.transfer(_host(id), _request(id).ask.maxPrice),
|
|
|
|
"Payment failed"
|
|
|
|
);
|
2021-11-04 09:49:07 +01:00
|
|
|
}
|
|
|
|
|
2022-02-09 14:17:23 +01:00
|
|
|
function missingProofs(bytes32 contractId) public view returns (uint256) {
|
2021-11-01 16:17:42 +01:00
|
|
|
return _missed(contractId);
|
2021-10-20 12:07:35 +02:00
|
|
|
}
|
|
|
|
|
2022-03-08 15:58:08 +01:00
|
|
|
function isProofRequired(bytes32 contractId) public view returns (bool) {
|
|
|
|
return _isProofRequired(contractId);
|
2021-10-14 12:37:14 +02:00
|
|
|
}
|
2021-10-18 14:55:59 +02:00
|
|
|
|
2022-04-05 11:27:02 +02:00
|
|
|
function willProofBeRequired(bytes32 contractId) public view returns (bool) {
|
|
|
|
return _willProofBeRequired(contractId);
|
|
|
|
}
|
|
|
|
|
2022-03-10 13:04:46 +01:00
|
|
|
function getChallenge(bytes32 contractId) public view returns (bytes32) {
|
|
|
|
return _getChallenge(contractId);
|
|
|
|
}
|
|
|
|
|
2022-03-10 13:35:41 +01:00
|
|
|
function getPointer(bytes32 id) public view returns (uint8) {
|
|
|
|
return _getPointer(id);
|
|
|
|
}
|
|
|
|
|
2022-04-12 08:43:47 +02:00
|
|
|
function submitProof(bytes32 contractId, bytes calldata proof) public {
|
2022-03-08 15:58:08 +01:00
|
|
|
_submitProof(contractId, proof);
|
2021-10-19 09:37:03 +02:00
|
|
|
}
|
|
|
|
|
2022-03-08 15:58:08 +01:00
|
|
|
function markProofAsMissing(bytes32 contractId, uint256 period) public {
|
|
|
|
_markProofAsMissing(contractId, period);
|
2021-11-04 14:19:58 +01:00
|
|
|
if (_missed(contractId) % slashMisses == 0) {
|
2022-06-13 12:17:37 +02:00
|
|
|
_slash(_host(contractId), slashPercentage);
|
2021-11-04 14:19:58 +01:00
|
|
|
}
|
2021-10-19 09:37:03 +02:00
|
|
|
}
|
2021-10-12 16:59:34 +02:00
|
|
|
}
|