Skip to content

Commit

Permalink
#43 - Added expiration claim method (#44)
Browse files Browse the repository at this point in the history
* Added new Claim

Create a new expiration-based claim method
• The claim method will take an expiration time stamp
• Allow the beneficiary to claim before the expiration time stamp
• Write new tests for the method

* Incorporates minor changes

Removes Claim Type in Claims
modifies ClaimValue to ClaimPeriod

Co-authored-by: Koshik Raj <[email protected]>
  • Loading branch information
AnkithVijay and koshikraj authored Sep 14, 2022
1 parent 440f132 commit edd2be0
Show file tree
Hide file tree
Showing 13 changed files with 390 additions and 206 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Create a .env file in the root directory with `INFURA_API_KEY` for mainnet or te
#### Testing the contracts

```bash
npm run test-contract
npm run test:contract
```

#### Testing the JS SDK
Expand All @@ -31,15 +31,15 @@ Run a local blockchain
Deploy the contract, run the test on a different terminal

```bash
npm run deploy-sdk
npm run test-sdk
npm run deploy:sdk
npm run test:sdk
```

#### Testing the contract & SDK

```bash
npm run deploy-sdk
npm run tests
npm run deploy:sdk
npm run test
```

## Getting started
Expand Down
63 changes: 33 additions & 30 deletions contracts/SafientMain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,22 @@ 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 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 _claimPeriod Value of claim is uint256 it can be signaling period or dday or eday
* @param _metaEvidence URL of the metaevidence
*/
function createSafe(
address _beneficiary,
string memory _safeId,
Types.ClaimType _claimType,
uint256 _signalingPeriod,
uint256 _DDay,
uint256 _claimPeriod,
string calldata _metaEvidence
) external payable returns (bool) {
return
_createSafe(
_beneficiary,
_safeId,
_claimType,
_signalingPeriod,
_DDay,
_claimPeriod,
_metaEvidence
);
}
Expand All @@ -68,25 +65,22 @@ 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 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 _claimPeriod Value of claim is uint256 it can be signaling period or dday or eday
* @param _metaEvidence URL of the metaevidence
*/
function syncSafe(
address _creator,
string memory _safeId,
Types.ClaimType _claimType,
uint256 _signalingPeriod,
uint256 _DDay,
uint256 _claimPeriod,
string calldata _metaEvidence
) external payable returns (bool) {
return
_syncSafe(
_creator,
_safeId,
_claimType,
_signalingPeriod,
_DDay,
_claimPeriod,
_metaEvidence
);
}
Expand Down Expand Up @@ -126,25 +120,29 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
_safeId,
safe.currentOwner,
safe.beneficiary,
safe.endSignalTime
safe.claimTimeStamp
);

safe.latestSignalTime = 0;
safe.endSignalTime = block.timestamp + safe.signalingPeriod;

// safe.latestSignalTime = 0;
safe.claimTimeStamp = block.timestamp + safe.claimPeriod;
_createSignalBasedClaim(_safeId, data);

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
safe.claimPeriod
);

_createDDayBasedClaim(_safeId, data);

safe.claimsCount += 1;
safes[_safeId] = safe;
} else if (safe.claimType == Types.ClaimType.Expirion) {
Types.ExpirionClaimData memory data = Types.ExpirionClaimData(
safe.currentOwner,
safe.beneficiary,
safe.claimPeriod
);
_createExpirionBasedClaim(_safeId, data);
safe.claimsCount += 1;
safes[_safeId] = safe;
}
Expand Down Expand Up @@ -217,25 +215,23 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {

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

return claim.status;
} else if (safe.claimType == Types.ClaimType.SignalBased) {
if (
safe.latestSignalTime == 0 &&
safe.endSignalTime != 0 &&
block.timestamp < safe.endSignalTime
safe.claimTimeStamp != 0 &&
block.timestamp < safe.claimTimeStamp
) {
return Types.ClaimStatus.Active;
} else if (
safe.latestSignalTime == 0 &&
safe.endSignalTime != 0 &&
block.timestamp > safe.endSignalTime
safe.claimTimeStamp != 0 &&
block.timestamp > safe.claimTimeStamp
) {
return Types.ClaimStatus.Passed;
} else if (safe.latestSignalTime > 0 && safe.endSignalTime == 0) {
} else if (safe.claimTimeStamp == 0) {
return Types.ClaimStatus.Failed;
}
}
Expand Down Expand Up @@ -298,4 +294,11 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
{
return _updateDDay(_safeId, _DDay);
}

function updateEDay(string memory _safeId, uint256 _DDay)
external
returns (bool)
{
return _updateEDay(_safeId, _DDay);
}
}
79 changes: 60 additions & 19 deletions contracts/components/Claims.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,29 @@ contract Claims {
_;
}

modifier ExpirionBasedClaim(
string memory _safeId,
Types.ExpirionClaimData 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.expiryDay != 0,
"Expiry date is not set by the safe's current owner"
);
_;
}

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

Expand Down Expand Up @@ -177,23 +200,18 @@ contract Claims {

evidenceGroupID += 1;

emit Dispute(
data.arbitrator,
disputeID,
data.metaEvidenceId
);
emit Dispute(data.arbitrator, disputeID, data.metaEvidenceId);

claims[disputeID] = Types.Claim({
id: disputeID,
claimedBy: msg.sender,
claimType: Types.ClaimType.ArbitrationBased,
metaEvidenceId: data.metaEvidenceId,
evidenceGroupId: evidenceGroupID,
status: Types.ClaimStatus.Active
});

claimsCount += 1;
emit CreateClaim(_safeId,disputeID, block.timestamp);
emit CreateClaim(_safeId, disputeID, block.timestamp);
if (bytes(_evidence).length != 0) {
_submitEvidence(disputeID, _evidence, data.arbitrator);
}
Expand All @@ -215,7 +233,6 @@ contract Claims {
claims[claimsCount] = Types.Claim({
id: claimsCount,
claimedBy: msg.sender,
claimType: Types.ClaimType.SignalBased,
metaEvidenceId: 0,
evidenceGroupId: 0,
status: Types.ClaimStatus.Active
Expand All @@ -235,17 +252,41 @@ contract Claims {
) internal dDayBasedClaim(_safeId, data) {
claimsCount += 1;

require(block.timestamp >= data.dDay, "Cannot create claim before DDay");
claims[claimsCount] = Types.Claim({
id: claimsCount,
claimedBy: msg.sender,
claimType: Types.ClaimType.DDayBased,
metaEvidenceId: 0,
evidenceGroupId: 0,
status: Types.ClaimStatus.Passed
});

emit CreateClaim(_safeId,claimsCount, block.timestamp);
require(
block.timestamp >= data.dDay,
"Cannot create claim before DDay"
);
claims[claimsCount] = Types.Claim({
id: claimsCount,
claimedBy: msg.sender,
metaEvidenceId: 0,
evidenceGroupId: 0,
status: Types.ClaimStatus.Passed
});

emit CreateClaim(_safeId, claimsCount, block.timestamp);
}

/**
* @notice Create a new Expiry-Day based claim
* @param _safeId Id of the safe
* @param data Includes safe data
*/
function _createExpirionBasedClaim(
string memory _safeId,
Types.ExpirionClaimData memory data
) internal ExpirionBasedClaim(_safeId, data) {
claimsCount += 1;
require(block.timestamp < data.expiryDay, "Safe has been expired");
claims[claimsCount] = Types.Claim({
id: claimsCount,
claimedBy: msg.sender,
metaEvidenceId: 0,
evidenceGroupId: 0,
status: Types.ClaimStatus.Passed
});

emit CreateClaim(_safeId, claimsCount, block.timestamp);
}

/**
Expand Down
Loading

0 comments on commit edd2be0

Please sign in to comment.