dagger-contracts/contracts/Storage.sol

90 lines
2.4 KiB
Solidity
Raw Normal View History

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./Marketplace.sol";
import "./Proofs.sol";
import "./Collateral.sol";
contract Storage is Marketplace {
uint256 public collateralAmount;
2022-02-09 13:17:23 +00:00
uint256 public slashMisses;
uint256 public slashPercentage;
uint256 public minCollateralThreshold;
constructor(
IERC20 token,
uint256 _proofPeriod,
uint256 _proofTimeout,
2022-03-10 09:19:21 +00:00
uint8 _proofDowntime,
uint256 _collateralAmount,
2022-02-09 13:17:23 +00:00
uint256 _slashMisses,
uint256 _slashPercentage,
uint256 _minCollateralThreshold
2022-03-10 09:19:21 +00:00
)
Marketplace(
token,
_collateralAmount,
_proofPeriod,
_proofTimeout,
_proofDowntime
)
2022-03-10 09:19:21 +00:00
{
collateralAmount = _collateralAmount;
slashMisses = _slashMisses;
slashPercentage = _slashPercentage;
minCollateralThreshold = _minCollateralThreshold;
2021-11-02 11:45:09 +00:00
}
function missingProofs(SlotId slotId) public view returns (uint256) {
return _missed(_toProofId(slotId));
}
function isProofRequired(SlotId slotId) public view returns (bool) {
2022-11-23 14:11:24 +00:00
if (!_slotAcceptsProofs(slotId)) {
return false;
}
return _isProofRequired(_toProofId(slotId));
}
2021-10-18 12:55:59 +00:00
function willProofBeRequired(SlotId slotId) public view returns (bool) {
2022-11-23 14:11:24 +00:00
if (!_slotAcceptsProofs(slotId)) {
return false;
}
return _willProofBeRequired(_toProofId(slotId));
}
function getChallenge(SlotId slotId) public view returns (bytes32) {
2022-11-23 14:11:24 +00:00
if (!_slotAcceptsProofs(slotId)) {
return bytes32(0);
}
return _getChallenge(_toProofId(slotId));
2022-03-10 12:04:46 +00:00
}
function getPointer(SlotId slotId) public view returns (uint8) {
return _getPointer(_toProofId(slotId));
}
function submitProof(SlotId slotId, bytes calldata proof) public {
_submitProof(_toProofId(slotId), proof);
2021-10-19 07:37:03 +00:00
}
function markProofAsMissing(SlotId slotId, uint256 period)
public
slotMustAcceptProofs(slotId)
{
ProofId proofId = _toProofId(slotId);
_markProofAsMissing(proofId, period);
address host = _host(slotId);
if (_missed(_toProofId(slotId)) % slashMisses == 0) {
2022-11-23 14:11:24 +00:00
_slash(host, slashPercentage);
if (balanceOf(host) < minCollateralThreshold) {
// 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).
_forciblyFreeSlot(slotId);
}
}
2021-10-19 07:37:03 +00:00
}
}