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-06-13 08:40:18 +00:00
|
|
|
contract Storage is Collateral, Marketplace {
|
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;
|
2022-09-13 07:18:55 +00:00
|
|
|
uint256 public minCollateralThreshold;
|
2021-11-02 10:19:52 +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,
|
2022-09-13 07:14:57 +00:00
|
|
|
uint256 _slashPercentage,
|
2022-09-13 07:18:55 +00:00
|
|
|
uint256 _minCollateralThreshold
|
2022-03-10 09:19:21 +00:00
|
|
|
)
|
2022-06-13 08:40:18 +00:00
|
|
|
Marketplace(
|
|
|
|
token,
|
|
|
|
_collateralAmount,
|
|
|
|
_proofPeriod,
|
|
|
|
_proofTimeout,
|
|
|
|
_proofDowntime
|
|
|
|
)
|
2022-03-10 09:19:21 +00:00
|
|
|
{
|
2022-02-15 16:54:19 +00:00
|
|
|
collateralAmount = _collateralAmount;
|
2021-11-04 13:19:58 +00:00
|
|
|
slashMisses = _slashMisses;
|
|
|
|
slashPercentage = _slashPercentage;
|
2022-09-21 09:29:40 +00:00
|
|
|
minCollateralThreshold = _minCollateralThreshold;
|
2021-11-02 11:45:09 +00:00
|
|
|
}
|
2021-10-20 10:07:35 +00:00
|
|
|
|
2022-09-29 10:18:02 +00:00
|
|
|
function getRequest(RequestId requestId) public view returns (Request memory) {
|
2022-08-17 05:24:19 +00:00
|
|
|
return _request(requestId);
|
2022-04-06 12:52:02 +00:00
|
|
|
}
|
|
|
|
|
2022-09-29 10:18:02 +00:00
|
|
|
function getSlot(SlotId slotId) public view returns (Slot memory) {
|
2022-08-22 06:16:45 +00:00
|
|
|
return _slot(slotId);
|
|
|
|
}
|
|
|
|
|
2022-09-29 10:18:02 +00:00
|
|
|
function getHost(SlotId slotId) public view returns (address) {
|
2022-09-13 07:18:55 +00:00
|
|
|
return _host(slotId);
|
2022-07-04 09:16:55 +00:00
|
|
|
}
|
|
|
|
|
2022-09-29 10:18:02 +00:00
|
|
|
function missingProofs(SlotId slotId) public view returns (uint256) {
|
|
|
|
return _missed(_toProofId(slotId));
|
2021-10-20 10:07:35 +00:00
|
|
|
}
|
|
|
|
|
2022-09-29 10:18:02 +00:00
|
|
|
function isProofRequired(SlotId slotId) public view returns (bool) {
|
2022-09-08 07:56:01 +00:00
|
|
|
if(!_slotAcceptsProofs(slotId)) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-09-29 10:18:02 +00:00
|
|
|
return _isProofRequired(_toProofId(slotId));
|
2021-10-14 10:37:14 +00:00
|
|
|
}
|
2021-10-18 12:55:59 +00:00
|
|
|
|
2022-09-29 10:18:02 +00:00
|
|
|
function willProofBeRequired(SlotId slotId) public view returns (bool) {
|
2022-09-08 07:56:01 +00:00
|
|
|
if(!_slotAcceptsProofs(slotId)) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-09-29 10:18:02 +00:00
|
|
|
return _willProofBeRequired(_toProofId(slotId));
|
2022-04-05 09:27:02 +00:00
|
|
|
}
|
|
|
|
|
2022-09-29 10:18:02 +00:00
|
|
|
function getChallenge(SlotId slotId) public view returns (bytes32) {
|
2022-09-08 07:56:01 +00:00
|
|
|
if(!_slotAcceptsProofs(slotId)) {
|
|
|
|
return bytes32(0);
|
|
|
|
}
|
2022-09-29 10:18:02 +00:00
|
|
|
return _getChallenge(_toProofId(slotId));
|
2022-03-10 12:04:46 +00:00
|
|
|
}
|
|
|
|
|
2022-09-29 10:18:02 +00:00
|
|
|
function getPointer(SlotId slotId) public view returns (uint8) {
|
|
|
|
return _getPointer(_toProofId(slotId));
|
2022-03-10 12:35:41 +00:00
|
|
|
}
|
|
|
|
|
2022-09-29 10:18:02 +00:00
|
|
|
function submitProof(SlotId slotId, bytes calldata proof) public {
|
|
|
|
_submitProof(_toProofId(slotId), proof);
|
2021-10-19 07:37:03 +00:00
|
|
|
}
|
|
|
|
|
2022-09-29 10:18:02 +00:00
|
|
|
function markProofAsMissing(SlotId slotId, uint256 period)
|
2022-09-08 07:56:01 +00:00
|
|
|
public
|
2022-09-22 02:21:49 +00:00
|
|
|
slotMustAcceptProofs(slotId)
|
2022-09-08 07:56:01 +00:00
|
|
|
{
|
2022-09-29 10:18:02 +00:00
|
|
|
ProofId proofId = _toProofId(slotId);
|
|
|
|
_markProofAsMissing(proofId, period);
|
2022-09-13 07:18:55 +00:00
|
|
|
address host = _host(slotId);
|
2022-09-29 10:18:02 +00:00
|
|
|
if (_missed(_toProofId(slotId)) % slashMisses == 0) {
|
2022-09-16 04:58:51 +00:00
|
|
|
_slash(host, slashPercentage);
|
2022-09-13 07:18:55 +00:00
|
|
|
|
2022-09-16 04:58:51 +00:00
|
|
|
if (balanceOf(host) < minCollateralThreshold) {
|
2022-09-21 09:13:12 +00:00
|
|
|
// When the collateral drops below the minimum threshold, the slot
|
2022-08-25 02:00:01 +00:00
|
|
|
// needs to be freed so that there is enough remaining collateral to be
|
|
|
|
// distributed for repairs and rewards (with any leftover to be burnt).
|
2022-09-13 07:18:55 +00:00
|
|
|
_freeSlot(slotId);
|
|
|
|
}
|
2022-09-13 07:14:57 +00:00
|
|
|
}
|
2021-10-19 07:37:03 +00:00
|
|
|
}
|
2021-10-12 14:59:34 +00:00
|
|
|
}
|