Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add safe deprecation and updation feature for the creator #47

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions contracts/SafientMain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
returns (bool)
{
Types.Safe memory safe = safes[_safeId];
require(!safe.deprecated, "Safe has been deprecated");

if (safe.claimType == Types.ClaimType.ArbitrationBased) {
uint256 arbitrationCost = arbitrator.arbitrationCost("");
Expand Down Expand Up @@ -192,15 +193,6 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
return _withdrawFunds(_safeId);
}

/**
* @notice Signal the safe in response to the claim made on
* the safe
* @param _safeId Id of the safe
*/
function sendSignal(string memory _safeId) external returns (bool) {
return _sendSignal(_safeId);
}

/**
* @notice Get the status of a claim
* @param _safeId Id of the safe
Expand Down Expand Up @@ -283,22 +275,20 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
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);
}

function updateEDay(string memory _safeId, uint256 _DDay)
external
returns (bool)
{
return _updateEDay(_safeId, _DDay);
function updateSafe(
string calldata _safeId,
Types.ClaimType _claimType,
uint256 _claimPeriod,
string calldata _metaEvidence,
bool _deprecated
) external returns (bool) {
return
_updateSafe(
_safeId,
_claimType,
_claimPeriod,
_metaEvidence,
_deprecated
);
}
}
187 changes: 98 additions & 89 deletions contracts/components/Safes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ contract Safes {
modifier depositSafeFunds(string memory _safeId) {
Types.Safe memory safe = safes[_safeId];

require(!safe.deprecated, "Safe has been deprecated");
require(safe.currentOwner != address(0), "Safe does not exist");
_;
}
Expand All @@ -81,56 +82,19 @@ contract Safes {
"Only safe owner can withdraw the deposit balance"
);

require(!safe.deprecated, "Safe has been deprecated");

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

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

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

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

require(
block.timestamp < safe.claimTimeStamp,
"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.claimPeriod, "DDay has already passed");
_;
}

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

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

require(block.timestamp < safe.claimPeriod, "EDay has expired");
require(!safe.deprecated, "Safe has been deprecated");
_;
}

Expand Down Expand Up @@ -170,10 +134,11 @@ contract Safes {
beneficiary: _beneficiary,
claimPeriod: _claimPeriod,
claimType: _claimType,
claimTimeStamp : 0,
claimTimeStamp: 0,
metaEvidenceId: metaEvidenceID,
claimsCount: 0,
funds: msg.value
funds: msg.value,
deprecated: false
});

safesCount += 1;
Expand Down Expand Up @@ -211,12 +176,13 @@ contract Safes {
createdBy: _creator,
currentOwner: _creator,
beneficiary: msg.sender,
claimPeriod : _claimPeriod,
claimPeriod: _claimPeriod,
claimType: _claimType,
claimTimeStamp : 0,
claimTimeStamp: 0,
metaEvidenceId: metaEvidenceID,
claimsCount: 0,
funds: msg.value
funds: msg.value,
deprecated: false
});

safesCount += 1;
Expand Down Expand Up @@ -272,54 +238,97 @@ contract Safes {
return sent;
}

/**
* @notice Signal the safe in response to the claim made on
* the safe
* @param _safeId Id of the safe
*/
function _sendSignal(string memory _safeId)
internal
signal(_safeId)
returns (bool)
{
Types.Safe memory safe = safes[_safeId];

// safe.latestSignalTime = block.timestamp;
safe.claimTimeStamp = 0;
safes[_safeId] = safe;

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)
{
function updateClaimType(
string calldata _safeId,
Types.ClaimType _claimType,
uint256 _claimPeriod,
string calldata _metaEvidence
) internal returns (bool) {
Types.Safe memory safe = safes[_safeId];

safe.claimPeriod = _DDay;
if (_claimType == Types.ClaimType.ArbitrationBased) {
metaEvidenceID += 1;
emit MetaEvidence(metaEvidenceID, _metaEvidence);
}
safe.claimType = _claimType;
safe.claimPeriod = _claimPeriod;
safe.metaEvidenceId = metaEvidenceID;
safes[_safeId] = safe;

return true;
}

function _updateEDay(string memory _safeId, uint256 _EDay)
internal
EDayUpdate(_safeId)
returns (bool)
{
function _updateSafe(
string calldata _safeId,
Types.ClaimType _claimType,
uint256 _claimPeriod,
string calldata _metaEvidence,
bool _deprecated
) internal SafeOwner(_safeId) returns (bool) {
Types.Safe memory safe = safes[_safeId];

safe.claimPeriod = _EDay;
safes[_safeId] = safe;

return true;
if (_deprecated) {
safe.deprecated = true;
safes[_safeId] = safe;
return true;
}
if (safe.claimType == Types.ClaimType.SignalBased) {
require(
safe.claimTimeStamp != 0,
"Safe is not claimed since safes endSignalTime is zero"
);
require(
block.timestamp < safe.claimTimeStamp,
"Signaling period is over"
);
if (safe.claimType != _claimType) {
// update claim type & claim period
return
updateClaimType(
_safeId,
_claimType,
_claimPeriod,
_metaEvidence
);
} else {
safe.claimTimeStamp = 0;
safes[_safeId] = safe;
return true;
}
} else if (safe.claimType == Types.ClaimType.ArbitrationBased) {
// need to discuss
} else if (safe.claimType == Types.ClaimType.DDayBased) {
require(
block.timestamp < safe.claimPeriod,
"DDay has already passed"
);
if (safe.claimType != _claimType) {
// update claim type & claim period
return
updateClaimType(
_safeId,
_claimType,
_claimPeriod,
_metaEvidence
);
} else {
safe.claimPeriod = _claimPeriod;
safes[_safeId] = safe;
return true;
}
} else if (safe.claimType == Types.ClaimType.Expirion) {
require(block.timestamp < safe.claimPeriod, "EDay has expired");
if (safe.claimType != _claimType) {
// update claim type & claim period
return
updateClaimType(
_safeId,
_claimType,
_claimPeriod,
_metaEvidence
);
} else {
safe.claimPeriod = _claimPeriod;
safes[_safeId] = safe;
return true;
}
}
}

}
1 change: 1 addition & 0 deletions contracts/libraries/Types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ library Types {
uint256 metaEvidenceId;
uint256 claimsCount;
uint256 funds;
bool deprecated;
}

struct Claim {
Expand Down
Loading