Skip to content

Commit 518a2ec

Browse files
committed
chore(contract): refactor to remove measures and ranges
1 parent 99f6c11 commit 518a2ec

File tree

5 files changed

+2261
-91
lines changed

5 files changed

+2261
-91
lines changed

README.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,13 @@ Currently Ganache and Node 14 are not playing well together. To get started:
1616

1717
## Features
1818

19-
Single Player mode features:
20-
21-
- [x] Creation of Commitment
22-
- [ ] Management of Activities
23-
- [ ] Management of Measures
24-
- [x] Execution of commitment settlement
25-
2619
#### Creation of Commitment
2720

28-
A commitment consists of an ```activity```, a ```measure``` for given activity, a ```start time```, and ```stake```. We will set the ```end date``` 7 days after the startdate.
21+
A commitment consists of an ```activity```, a ```goalValue``` for given activity, a ```startTime```, and ```stake```. We will automagically set the ```endTime``` 7 days after the startdate.
2922

3023
#### Management of Activities
3124

32-
An activity consists of a ```name```, a ```measure``` to express activity metrics, an array of accepted ```ranges```, and the ```oracle``` address. Activities can be enabled by setting it to ```allowed```.
33-
34-
For the Single Player mode ```biking``` is the only available activity, as declared in ```scripts/deploy.ts```
35-
36-
#### Management of Measures
37-
38-
A measure has a ```name``` and can be enabled by setting it to ```allowed```.
39-
40-
For the Single Player mode ```km``` is the only available measure, as declared in ```scripts/deploy.ts```
25+
An activity consists of a ```name``` and the ```oracle``` address. Activities can be enabled by setting it to ```allowed```.
4126

4227
#### Execution of commitment settlement
4328

contracts/SinglePlayerCommit.sol

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ contract SinglePlayerCommit is Ownable {
2828
struct Commitment {
2929
address committer; // user
3030
bytes32 activityKey;
31-
uint256 goal;
31+
uint256 goalValue;
3232
uint256 startTime;
3333
uint256 endTime;
3434
uint256 stake; // amount of token staked, scaled by token decimals
3535
bool exists; // flag to help check if commitment exists
3636
uint256 reportedValue; // as reported by oracle
37-
bool timed; //if true, take time from API. if false, use default (distance)
3837
bool met; // whether the commitment has been met
3938
}
4039

@@ -44,8 +43,7 @@ contract SinglePlayerCommit is Ownable {
4443
event NewCommitment(
4544
address committer,
4645
string activityName,
47-
uint256 goal,
48-
bool timed,
46+
uint256 goalValue,
4947
uint256 startTime,
5048
uint256 endTime,
5149
uint256 stake
@@ -93,14 +91,13 @@ contract SinglePlayerCommit is Ownable {
9391
// other public functions
9492
function depositAndCommit(
9593
bytes32 _activityKey,
96-
uint256 _goal,
97-
bool _timed,
94+
uint256 _goalValue,
9895
uint256 _startTime,
9996
uint256 _stake,
10097
uint256 _depositAmount
10198
) public returns (bool) {
10299
require(deposit(_depositAmount), "SPC::depositAndCommit - deposit failed");
103-
require(makeCommitment(_activityKey, _goal, _timed, _startTime, _stake), "SPC::depositAndCommit - commitment failed");
100+
require(makeCommitment(_activityKey, _goalValue, _startTime, _stake), "SPC::depositAndCommit - commitment failed");
104101

105102
return true;
106103
}
@@ -120,9 +117,7 @@ contract SinglePlayerCommit is Ownable {
120117

121118
function makeCommitment(
122119
bytes32 _activityKey,
123-
// uint256 _measureIndex, // index of the Activity.measures array
124-
uint256 _goal,
125-
bool _timed,
120+
uint256 _goalValue,
126121
uint256 _startTime,
127122
uint256 _stake
128123
) public returns (bool) {
@@ -134,7 +129,7 @@ contract SinglePlayerCommit is Ownable {
134129
"SPC::makeCommitment - activity doesn't exist or isn't allowed"
135130
);
136131
require(_startTime > block.timestamp, "SPC::makeCommitment - commitment cannot start in the past");
137-
require(_goal >= 1, "SPC::makeCommitment - goal is too low");
132+
require(_goalValue > 1, "SPC::makeCommitment - goal is too low");
138133
require(balances[msg.sender] >= _stake, "SPC::makeCommitment - insufficient token balance");
139134

140135
uint256 endTime = _startTime.add(7 days);
@@ -143,8 +138,7 @@ contract SinglePlayerCommit is Ownable {
143138
Commitment memory commitment = Commitment({
144139
committer: msg.sender,
145140
activityKey: _activityKey,
146-
goal: _goal,
147-
timed: _timed,
141+
goalValue: _goalValue,
148142
startTime: _startTime,
149143
endTime: endTime,
150144
stake: _stake,
@@ -156,7 +150,7 @@ contract SinglePlayerCommit is Ownable {
156150
// ...and add it to storage
157151
commitments[msg.sender] = commitment;
158152

159-
emit NewCommitment(msg.sender, allowedActivities[_activityKey].name, _goal, _timed, _startTime, endTime, _stake);
153+
emit NewCommitment(msg.sender, allowedActivities[_activityKey].name, _goalValue, _startTime, endTime, _stake);
160154

161155
return true;
162156
}

0 commit comments

Comments
 (0)