Skip to content

Commit

Permalink
#23 - Adds D-day based claim method (#27)
Browse files Browse the repository at this point in the history
* modifies few API response types

* adds D day based claiming method

* incorporates review comment change requests

* updates param docs
  • Loading branch information
devpavan04 authored Nov 8, 2021
1 parent 3d8c0c6 commit 6da3c88
Show file tree
Hide file tree
Showing 11 changed files with 454 additions and 29 deletions.
45 changes: 38 additions & 7 deletions contracts/SafientMain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
* @param _beneficiary Address of the safe beneficiary
* @param _safeId Id of the safe
* @param _claimType Type of the claim
* @param _signalingPeriod Signaling time window
* @param _signalingPeriod The time window in seconds within which the creator wants to signal the safe in response to a claim on the safe
* @param _DDay The timestamp in unix epoch milliseconds after which the beneficiary can directly claim the safe
* @param _metaEvidence URL of the metaevidence
*/
function createSafe(
address _beneficiary,
string memory _safeId,
Types.ClaimType _claimType,
uint256 _signalingPeriod,
uint256 _DDay,
string calldata _metaEvidence
) external payable returns (bool) {
return
Expand All @@ -56,6 +58,7 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
_safeId,
_claimType,
_signalingPeriod,
_DDay,
_metaEvidence
);
}
Expand All @@ -65,14 +68,16 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
* @param _creator Address of the safe creator
* @param _safeId Id of the safe
* @param _claimType Type of the claim
* @param _signalingPeriod Signaling time window
* @param _signalingPeriod TThe time window in seconds within which the creator wants to signal the safe in response to a claim on the safe
* @param _DDay The timestamp in unix epoch milliseconds after which the beneficiary can directly claim the safe
* @param _metaEvidence URL of the metaevidence
*/
function syncSafe(
address _creator,
string memory _safeId,
Types.ClaimType _claimType,
uint256 _signalingPeriod,
uint256 _DDay,
string calldata _metaEvidence
) external payable returns (bool) {
return
Expand All @@ -81,6 +86,7 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
_safeId,
_claimType,
_signalingPeriod,
_DDay,
_metaEvidence
);
}
Expand Down Expand Up @@ -130,8 +136,18 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {

safe.claimsCount += 1;
safes[_safeId] = safe;
}
} else if (safe.claimType == Types.ClaimType.DDayBased) {
Types.DDayBasedClaimData memory data = Types.DDayBasedClaimData(
safe.currentOwner,
safe.beneficiary,
safe.dDay
);

_createDDayBasedClaim(_safeId, data);

safe.claimsCount += 1;
safes[_safeId] = safe;
}
return true;
}

Expand Down Expand Up @@ -190,17 +206,20 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
/**
* @notice Get the status of a claim
* @param _safeId Id of the safe
* @param _disputeID Id of the claim
* @param _claimId Id of the claim
*/
function getClaimStatus(string memory _safeId, uint256 _disputeID)
function getClaimStatus(string memory _safeId, uint256 _claimId)
external
view
returns (Types.ClaimStatus status)
{
Types.Safe memory safe = safes[_safeId];

if (safe.claimType == Types.ClaimType.ArbitrationBased) {
Types.Claim memory claim = claims[_disputeID];
if (
safe.claimType == Types.ClaimType.ArbitrationBased ||
safe.claimType == Types.ClaimType.DDayBased
) {
Types.Claim memory claim = claims[_claimId];

return claim.status;
} else if (safe.claimType == Types.ClaimType.SignalBased) {
Expand Down Expand Up @@ -267,4 +286,16 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
function claimRewards(uint256 _funds) external returns (bool) {
return _claimRewards(_funds);
}

/**
* @notice Update the D-Day
* @param _safeId Id of the safe
* @param _DDay The timestamp in unix epoch milliseconds after which the beneficiary can directly claim the safe
*/
function updateDDay(string memory _safeId, uint256 _DDay)
external
returns (bool)
{
return _updateDDay(_safeId, _DDay);
}
}
65 changes: 64 additions & 1 deletion contracts/components/Claims.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ contract Claims {
Types.ArbitrationBasedClaimData memory data
) {
require(data.currentOwner != address(0), "Safe does not exist");

require(
bytes(_safeId).length > 1,
"Should provide ID of the safe on threadDB"
);

require(
msg.sender == data.beneficiary,
"Only beneficiary of the safe can create the claim"
);

require(
data.funds >= data.arbitrationCost,
"Insufficient funds in the safe to pay the arbitration fee"
Expand All @@ -58,22 +61,48 @@ contract Claims {
Types.SignalBasedClaimData memory data
) {
require(data.currentOwner != address(0), "Safe does not exist");

require(
bytes(_safeId).length > 1,
"Should provide ID of the safe on threadDB"
);

require(
msg.sender == data.beneficiary,
"Only beneficiary of the safe can create the claim"
);

require(data.endSignalTime == 0, "Safe end signal time should be zero");
_;
}

modifier dDayBasedClaim(
string memory _safeId,
Types.DDayBasedClaimData memory data
) {
require(data.currentOwner != address(0), "Safe does not exist");

require(
bytes(_safeId).length > 1,
"Should provide ID of the safe on threadDB"
);

require(
msg.sender == data.beneficiary,
"Only beneficiary of the safe can create the claim"
);

require(data.dDay != 0, "D day is not set by the safe's current owner");
_;
}

modifier evidenceSubmission(uint256 _disputeID, string calldata _evidence) {
Types.Claim memory claim = claims[_disputeID];

require(_disputeID <= claimsCount, "Claim or Dispute does not exist");

require(bytes(_evidence).length > 1, "Should provide evidence URI");
Types.Claim memory claim = claims[_disputeID];

require(
msg.sender == claim.claimedBy,
"Only creator of the claim can submit the evidence"
Expand Down Expand Up @@ -199,6 +228,40 @@ contract Claims {
emit CreateClaim(msg.sender, _safeId, claimsCount);
}

/**
* @notice Create a new D-Day based claim
* @param _safeId Id of the safe
* @param data Includes safe data
*/
function _createDDayBasedClaim(
string memory _safeId,
Types.DDayBasedClaimData memory data
) internal dDayBasedClaim(_safeId, data) {
claimsCount += 1;

if (block.timestamp >= data.dDay) {
claims[claimsCount] = Types.Claim({
id: claimsCount,
claimedBy: msg.sender,
claimType: Types.ClaimType.DDayBased,
metaEvidenceId: 0,
evidenceGroupId: 0,
status: Types.ClaimStatus.Passed
});
} else if (block.timestamp < data.dDay) {
claims[claimsCount] = Types.Claim({
id: claimsCount,
claimedBy: msg.sender,
claimType: Types.ClaimType.DDayBased,
metaEvidenceId: 0,
evidenceGroupId: 0,
status: Types.ClaimStatus.Failed
});
}

emit CreateClaim(msg.sender, _safeId, claimsCount);
}

/**
* @notice Give a ruling on an arbitration based claim
* @param _disputeID Dispute id of the claim
Expand Down
1 change: 1 addition & 0 deletions contracts/components/Guardians.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ contract Guardians {

modifier withdrawRewards(uint256 _funds) {
require(guardianRewards[msg.sender] != 0, "No rewards remaining");

require(
guardianRewards[msg.sender] >= _funds,
"Funds requested exceeds the total remaining funds"
Expand Down
52 changes: 50 additions & 2 deletions contracts/components/Safes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ contract Safes {
bytes(_safeId).length > 1,
"Should provide ID of the safe on threadDB"
);

require(
_beneficiary != address(0),
"Should provide an beneficiary for the safe"
);

require(
msg.sender != _beneficiary,
"Safe creator should not be the beneficiary of the safe"
Expand All @@ -49,10 +51,12 @@ contract Safes {
bytes(_safeId).length > 1,
"Should provide ID of the safe on threadDB"
);

require(
_creator != address(0),
"Should provide an creator for the safe"
);

require(
msg.sender != _creator,
"Safe should be synced by the beneficiary of the safe"
Expand All @@ -62,42 +66,62 @@ contract Safes {

modifier depositSafeFunds(string memory _safeId) {
Types.Safe memory safe = safes[_safeId];

require(safe.currentOwner != address(0), "Safe does not exist");
_;
}

modifier withdrawSafeFunds(string memory _safeId) {
Types.Safe memory safe = safes[_safeId];

require(safe.currentOwner != address(0), "Safe does not exist");

require(
msg.sender == safe.currentOwner,
"Only safe owner can withdraw the deposit balance"
);

require(safe.funds != 0, "No funds remaining in the safe");
_;
}

modifier signal(string memory _safeId) {
Types.Safe memory safe = safes[_safeId];

require(
msg.sender == safe.currentOwner,
"Only safe current owner can send the signal"
);

require(
safe.endSignalTime != 0,
"Safe is not claimed since safe's endSignalTime is zero"
);

require(
block.timestamp < safe.endSignalTime,
"Signaling period is over"
);

require(
safe.latestSignalTime == 0,
"Safe is not claimed since safe's latestSignalTime is not zero"
);
_;
}

modifier DDayUpdate(string memory _safeId) {
Types.Safe memory safe = safes[_safeId];

require(
msg.sender == safe.currentOwner,
"Only safe current owner can updade the D Day"
);

require(block.timestamp < safe.dDay, "DDay has already passed");
_;
}

event MetaEvidence(uint256 indexed _metaEvidenceID, string _evidence);

event CreateSafe(
Expand All @@ -111,14 +135,16 @@ contract Safes {
* @param _beneficiary Address of the safe beneficiary
* @param _safeId Id of the safe
* @param _claimType Type of the claim
* @param _signalingPeriod Signaling time window
* @param _signalingPeriod The time window in seconds within which the creator wants to signal the safe in response to a claim on the safe
* @param _DDay The timestamp in unix epoch milliseconds after which the beneficiary can directly claim the safe
* @param _metaEvidence URL of the metaevidence
*/
function _createSafe(
address _beneficiary,
string memory _safeId,
Types.ClaimType _claimType,
uint256 _signalingPeriod,
uint256 _DDay,
string calldata _metaEvidence
) internal createSafeByCreator(_safeId, _beneficiary) returns (bool) {
if (_claimType == Types.ClaimType.ArbitrationBased) {
Expand All @@ -135,6 +161,7 @@ contract Safes {
signalingPeriod: _signalingPeriod,
endSignalTime: 0,
latestSignalTime: 0,
dDay: _DDay,
claimType: _claimType,
metaEvidenceId: metaEvidenceID,
claimsCount: 0,
Expand All @@ -156,14 +183,16 @@ contract Safes {
* @param _creator Address of the safe creator
* @param _safeId Id of the safe
* @param _claimType Type of the claim
* @param _signalingPeriod Signaling time window
* @param _signalingPeriod The time window in seconds within which the creator wants to signal the safe in response to a claim on the safe
* @param _DDay The timestamp in unix epoch milliseconds after which the beneficiary can directly claim the safe
* @param _metaEvidence URL of the metaevidence
*/
function _syncSafe(
address _creator,
string memory _safeId,
Types.ClaimType _claimType,
uint256 _signalingPeriod,
uint256 _DDay,
string calldata _metaEvidence
) internal syncSafeByBeneficiary(_safeId, _creator) returns (bool) {
if (_claimType == Types.ClaimType.ArbitrationBased) {
Expand All @@ -180,6 +209,7 @@ contract Safes {
signalingPeriod: _signalingPeriod,
endSignalTime: 0,
latestSignalTime: 0,
dDay: _DDay,
claimType: _claimType,
metaEvidenceId: metaEvidenceID,
claimsCount: 0,
Expand Down Expand Up @@ -257,4 +287,22 @@ contract Safes {

return true;
}

/**
* @notice Update the D-Day
* @param _safeId Id of the safe
* @param _DDay The timestamp in unix epoch milliseconds after which the beneficiary can directly claim the safe
*/
function _updateDDay(string memory _safeId, uint256 _DDay)
internal
DDayUpdate(_safeId)
returns (bool)
{
Types.Safe memory safe = safes[_safeId];

safe.dDay = _DDay;
safes[_safeId] = safe;

return true;
}
}
Loading

0 comments on commit 6da3c88

Please sign in to comment.