Skip to content

Commit edd2be0

Browse files
#43 - Added expiration claim method (#44)
* 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 <koshik.raj@gmail.com>
1 parent 440f132 commit edd2be0

File tree

13 files changed

+390
-206
lines changed

13 files changed

+390
-206
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Create a .env file in the root directory with `INFURA_API_KEY` for mainnet or te
1717
#### Testing the contracts
1818

1919
```bash
20-
npm run test-contract
20+
npm run test:contract
2121
```
2222

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

3333
```bash
34-
npm run deploy-sdk
35-
npm run test-sdk
34+
npm run deploy:sdk
35+
npm run test:sdk
3636
```
3737

3838
#### Testing the contract & SDK
3939

4040
```bash
41-
npm run deploy-sdk
42-
npm run tests
41+
npm run deploy:sdk
42+
npm run test
4343
```
4444

4545
## Getting started

contracts/SafientMain.sol

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,22 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
4040
* @param _beneficiary Address of the safe beneficiary
4141
* @param _safeId Id of the safe
4242
* @param _claimType Type of the claim
43-
* @param _signalingPeriod The time window in seconds within which the creator wants to signal the safe in response to a claim on the safe
44-
* @param _DDay The timestamp in unix epoch milliseconds after which the beneficiary can directly claim the safe
43+
* @param _claimPeriod Value of claim is uint256 it can be signaling period or dday or eday
4544
* @param _metaEvidence URL of the metaevidence
4645
*/
4746
function createSafe(
4847
address _beneficiary,
4948
string memory _safeId,
5049
Types.ClaimType _claimType,
51-
uint256 _signalingPeriod,
52-
uint256 _DDay,
50+
uint256 _claimPeriod,
5351
string calldata _metaEvidence
5452
) external payable returns (bool) {
5553
return
5654
_createSafe(
5755
_beneficiary,
5856
_safeId,
5957
_claimType,
60-
_signalingPeriod,
61-
_DDay,
58+
_claimPeriod,
6259
_metaEvidence
6360
);
6461
}
@@ -68,25 +65,22 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
6865
* @param _creator Address of the safe creator
6966
* @param _safeId Id of the safe
7067
* @param _claimType Type of the claim
71-
* @param _signalingPeriod TThe time window in seconds within which the creator wants to signal the safe in response to a claim on the safe
72-
* @param _DDay The timestamp in unix epoch milliseconds after which the beneficiary can directly claim the safe
68+
* @param _claimPeriod Value of claim is uint256 it can be signaling period or dday or eday
7369
* @param _metaEvidence URL of the metaevidence
7470
*/
7571
function syncSafe(
7672
address _creator,
7773
string memory _safeId,
7874
Types.ClaimType _claimType,
79-
uint256 _signalingPeriod,
80-
uint256 _DDay,
75+
uint256 _claimPeriod,
8176
string calldata _metaEvidence
8277
) external payable returns (bool) {
8378
return
8479
_syncSafe(
8580
_creator,
8681
_safeId,
8782
_claimType,
88-
_signalingPeriod,
89-
_DDay,
83+
_claimPeriod,
9084
_metaEvidence
9185
);
9286
}
@@ -126,25 +120,29 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
126120
_safeId,
127121
safe.currentOwner,
128122
safe.beneficiary,
129-
safe.endSignalTime
123+
safe.claimTimeStamp
130124
);
131-
132-
safe.latestSignalTime = 0;
133-
safe.endSignalTime = block.timestamp + safe.signalingPeriod;
134-
125+
// safe.latestSignalTime = 0;
126+
safe.claimTimeStamp = block.timestamp + safe.claimPeriod;
135127
_createSignalBasedClaim(_safeId, data);
136-
137128
safe.claimsCount += 1;
138129
safes[_safeId] = safe;
139130
} else if (safe.claimType == Types.ClaimType.DDayBased) {
140131
Types.DDayBasedClaimData memory data = Types.DDayBasedClaimData(
141132
safe.currentOwner,
142133
safe.beneficiary,
143-
safe.dDay
134+
safe.claimPeriod
144135
);
145-
146136
_createDDayBasedClaim(_safeId, data);
147-
137+
safe.claimsCount += 1;
138+
safes[_safeId] = safe;
139+
} else if (safe.claimType == Types.ClaimType.Expirion) {
140+
Types.ExpirionClaimData memory data = Types.ExpirionClaimData(
141+
safe.currentOwner,
142+
safe.beneficiary,
143+
safe.claimPeriod
144+
);
145+
_createExpirionBasedClaim(_safeId, data);
148146
safe.claimsCount += 1;
149147
safes[_safeId] = safe;
150148
}
@@ -217,25 +215,23 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
217215

218216
if (
219217
safe.claimType == Types.ClaimType.ArbitrationBased ||
220-
safe.claimType == Types.ClaimType.DDayBased
218+
safe.claimType == Types.ClaimType.DDayBased ||
219+
safe.claimType == Types.ClaimType.Expirion
221220
) {
222221
Types.Claim memory claim = claims[_claimId];
223-
224222
return claim.status;
225223
} else if (safe.claimType == Types.ClaimType.SignalBased) {
226224
if (
227-
safe.latestSignalTime == 0 &&
228-
safe.endSignalTime != 0 &&
229-
block.timestamp < safe.endSignalTime
225+
safe.claimTimeStamp != 0 &&
226+
block.timestamp < safe.claimTimeStamp
230227
) {
231228
return Types.ClaimStatus.Active;
232229
} else if (
233-
safe.latestSignalTime == 0 &&
234-
safe.endSignalTime != 0 &&
235-
block.timestamp > safe.endSignalTime
230+
safe.claimTimeStamp != 0 &&
231+
block.timestamp > safe.claimTimeStamp
236232
) {
237233
return Types.ClaimStatus.Passed;
238-
} else if (safe.latestSignalTime > 0 && safe.endSignalTime == 0) {
234+
} else if (safe.claimTimeStamp == 0) {
239235
return Types.ClaimStatus.Failed;
240236
}
241237
}
@@ -298,4 +294,11 @@ contract SafientMain is Safes, Claims, Guardians, IArbitrable {
298294
{
299295
return _updateDDay(_safeId, _DDay);
300296
}
297+
298+
function updateEDay(string memory _safeId, uint256 _DDay)
299+
external
300+
returns (bool)
301+
{
302+
return _updateEDay(_safeId, _DDay);
303+
}
301304
}

contracts/components/Claims.sol

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,29 @@ contract Claims {
9696
_;
9797
}
9898

99+
modifier ExpirionBasedClaim(
100+
string memory _safeId,
101+
Types.ExpirionClaimData memory data
102+
) {
103+
require(data.currentOwner != address(0), "Safe does not exist");
104+
105+
require(
106+
bytes(_safeId).length > 1,
107+
"Should provide ID of the safe on threadDB"
108+
);
109+
110+
require(
111+
msg.sender == data.beneficiary,
112+
"Only beneficiary of the safe can create the claim"
113+
);
114+
115+
require(
116+
data.expiryDay != 0,
117+
"Expiry date is not set by the safe's current owner"
118+
);
119+
_;
120+
}
121+
99122
modifier evidenceSubmission(uint256 _disputeID, string calldata _evidence) {
100123
Types.Claim memory claim = claims[_disputeID];
101124

@@ -177,23 +200,18 @@ contract Claims {
177200

178201
evidenceGroupID += 1;
179202

180-
emit Dispute(
181-
data.arbitrator,
182-
disputeID,
183-
data.metaEvidenceId
184-
);
203+
emit Dispute(data.arbitrator, disputeID, data.metaEvidenceId);
185204

186205
claims[disputeID] = Types.Claim({
187206
id: disputeID,
188207
claimedBy: msg.sender,
189-
claimType: Types.ClaimType.ArbitrationBased,
190208
metaEvidenceId: data.metaEvidenceId,
191209
evidenceGroupId: evidenceGroupID,
192210
status: Types.ClaimStatus.Active
193211
});
194212

195213
claimsCount += 1;
196-
emit CreateClaim(_safeId,disputeID, block.timestamp);
214+
emit CreateClaim(_safeId, disputeID, block.timestamp);
197215
if (bytes(_evidence).length != 0) {
198216
_submitEvidence(disputeID, _evidence, data.arbitrator);
199217
}
@@ -215,7 +233,6 @@ contract Claims {
215233
claims[claimsCount] = Types.Claim({
216234
id: claimsCount,
217235
claimedBy: msg.sender,
218-
claimType: Types.ClaimType.SignalBased,
219236
metaEvidenceId: 0,
220237
evidenceGroupId: 0,
221238
status: Types.ClaimStatus.Active
@@ -235,17 +252,41 @@ contract Claims {
235252
) internal dDayBasedClaim(_safeId, data) {
236253
claimsCount += 1;
237254

238-
require(block.timestamp >= data.dDay, "Cannot create claim before DDay");
239-
claims[claimsCount] = Types.Claim({
240-
id: claimsCount,
241-
claimedBy: msg.sender,
242-
claimType: Types.ClaimType.DDayBased,
243-
metaEvidenceId: 0,
244-
evidenceGroupId: 0,
245-
status: Types.ClaimStatus.Passed
246-
});
247-
248-
emit CreateClaim(_safeId,claimsCount, block.timestamp);
255+
require(
256+
block.timestamp >= data.dDay,
257+
"Cannot create claim before DDay"
258+
);
259+
claims[claimsCount] = Types.Claim({
260+
id: claimsCount,
261+
claimedBy: msg.sender,
262+
metaEvidenceId: 0,
263+
evidenceGroupId: 0,
264+
status: Types.ClaimStatus.Passed
265+
});
266+
267+
emit CreateClaim(_safeId, claimsCount, block.timestamp);
268+
}
269+
270+
/**
271+
* @notice Create a new Expiry-Day based claim
272+
* @param _safeId Id of the safe
273+
* @param data Includes safe data
274+
*/
275+
function _createExpirionBasedClaim(
276+
string memory _safeId,
277+
Types.ExpirionClaimData memory data
278+
) internal ExpirionBasedClaim(_safeId, data) {
279+
claimsCount += 1;
280+
require(block.timestamp < data.expiryDay, "Safe has been expired");
281+
claims[claimsCount] = Types.Claim({
282+
id: claimsCount,
283+
claimedBy: msg.sender,
284+
metaEvidenceId: 0,
285+
evidenceGroupId: 0,
286+
status: Types.ClaimStatus.Passed
287+
});
288+
289+
emit CreateClaim(_safeId, claimsCount, block.timestamp);
249290
}
250291

251292
/**

0 commit comments

Comments
 (0)