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-11-23 16:07:01 +01:00
|
|
|
contract Storage is 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;
|
2022-09-13 17:18:55 +10:00
|
|
|
uint256 public minCollateralThreshold;
|
2021-11-02 11:19:52 +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,
|
2022-09-13 17:14:57 +10:00
|
|
|
uint256 _slashPercentage,
|
2022-09-13 17:18:55 +10:00
|
|
|
uint256 _minCollateralThreshold
|
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;
|
2022-09-21 19:29:40 +10:00
|
|
|
minCollateralThreshold = _minCollateralThreshold;
|
2021-11-02 12:45:09 +01:00
|
|
|
}
|
2021-10-20 12:07:35 +02:00
|
|
|
|
2022-09-29 20:18:02 +10:00
|
|
|
function submitProof(SlotId slotId, bytes calldata proof) public {
|
2023-01-09 14:20:59 +01:00
|
|
|
_submitProof(slotId, proof);
|
2021-10-19 09:37:03 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-29 20:18:02 +10:00
|
|
|
function markProofAsMissing(SlotId slotId, uint256 period)
|
2022-09-08 17:56:01 +10:00
|
|
|
public
|
2022-09-22 12:21:49 +10:00
|
|
|
slotMustAcceptProofs(slotId)
|
2022-09-08 17:56:01 +10:00
|
|
|
{
|
2023-01-09 14:20:59 +01:00
|
|
|
_markProofAsMissing(slotId, period);
|
2022-09-13 17:18:55 +10:00
|
|
|
address host = _host(slotId);
|
2023-01-09 14:41:28 +01:00
|
|
|
if (missingProofs(slotId) % slashMisses == 0) {
|
2022-11-23 15:11:24 +01:00
|
|
|
_slash(host, slashPercentage);
|
2022-09-13 17:18:55 +10:00
|
|
|
|
2022-09-16 14:58:51 +10:00
|
|
|
if (balanceOf(host) < minCollateralThreshold) {
|
2022-09-21 19:13:12 +10:00
|
|
|
// When the collateral drops below the minimum threshold, the slot
|
2022-08-25 12:00:01 +10: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-11-23 15:10:58 +01:00
|
|
|
_forciblyFreeSlot(slotId);
|
2022-09-13 17:18:55 +10:00
|
|
|
}
|
2022-09-13 17:14:57 +10:00
|
|
|
}
|
2021-10-19 09:37:03 +02:00
|
|
|
}
|
2021-10-12 16:59:34 +02:00
|
|
|
}
|