Skip to content

Commit 1fcac4d

Browse files
committed
chore(stuff): added matic-mumbai, review comments
1 parent 936ab2e commit 1fcac4d

File tree

11 files changed

+3142
-760
lines changed

11 files changed

+3142
-760
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ Ganache
2727
2. Start Ganache on port 8545
2828
3. In second terminal```npx buidler run --network localhost scripts/deploy.ts ```
2929

30+
#### Deploying to Matic
31+
1. ```npm install truffle -g```
32+
2. ```npm install truffle-flattener -g```
33+
34+
Mumbai Testnet configured in ```./truffle-config.js```
35+
36+
Test deployment using Truffle against a runnning Ganache instance: ```truffle migrate```
37+
Deploy to Mumbai testnet: ```truffle migrate --network matic```
38+
39+
Verify deployment using contract address at the [Matic Explorer](https://explorer-mumbai.maticvigil.com/)
40+
41+
*Verifying & publishing the contract code*
42+
In the [Matic Explorer](https://explorer-mumbai.maticvigil.com/) find your contract based on the address reported by Truffle.
43+
Go to the tab ```Code```
44+
45+
Quite note on setting up Matic:
46+
* Configure Matic network in [MetaMask](https://docs.matic.network/docs/develop/metamask/config-matic/)
47+
* Request funds at [faucet](https://faucet.matic.network/)
48+
* Use this wallet's seed phrase in the .env file to pay the deployment
3049

3150
#### Interacting with the contract
3251
After deploying to a local node
@@ -37,7 +56,7 @@ After deploying to a local node
3756
Example for interacting:
3857
```await commitPool.withdraw(1000)```
3958
## Features
40-
59+
[Technical documentation](https://ipfs.io/ipfs/QmdJsGYi822G1azEMtGL39LRwXZtJRC58KT393TGPixP6z)
4160
#### Creation of Commitment
4261

4362
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.

contracts/Migrations.sol

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.6.10;
3+
4+
contract Migrations {
5+
address public owner;
6+
7+
// A function with the signature `last_completed_migration()`, returning a uint, is required.
8+
uint public last_completed_migration;
9+
10+
modifier restricted() {
11+
if (msg.sender == owner) _;
12+
}
13+
14+
constructor() public {
15+
owner = msg.sender;
16+
}
17+
18+
// A function with the signature `setCompleted(uint)` is required.
19+
function setCompleted(uint completed) public restricted {
20+
last_completed_migration = completed;
21+
}
22+
23+
function upgrade(address new_address) public restricted {
24+
Migrations upgraded = Migrations(new_address);
25+
upgraded.setCompleted(last_completed_migration);
26+
}
27+
}

contracts/SinglePlayerCommit.sol

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ contract SinglePlayerCommit is ChainlinkClient, Ownable {
148148
available = available.sub(commitment.stake);
149149
}
150150

151-
require(amount >= available, "SPC::withdraw - not enough (unstaked) balance available");
151+
require(amount <= available, "SPC::withdraw - not enough (unstaked) balance available");
152152

153153
_changeCommitterBalance(amount, false);
154154

@@ -250,12 +250,13 @@ contract SinglePlayerCommit is ChainlinkClient, Ownable {
250250
/// @dev Process commitment by lookup based on address, checking metrics, state and updating balances
251251
function processCommitment(address committer) public {
252252
console.log("Processing commitment");
253+
require(commitments[committer].exists, "SPC::processCommitment - commitment does not exist");
253254
Commitment storage commitment = commitments[committer];
254255

255256
require(commitment.endTime < block.timestamp, "SPC::processCommitment - commitment is still active");
256257
require(commitment.endTime < commitment.lastActivityUpdate, "SPC::processCommitment - update activity");
257258

258-
commitment.met = commitment.reportedValue > commitment.goalValue;
259+
commitment.met = commitment.reportedValue >= commitment.goalValue;
259260

260261
if (!commitment.met) {
261262
_slashFunds(commitment.stake, committer);
@@ -269,6 +270,7 @@ contract SinglePlayerCommit is ChainlinkClient, Ownable {
269270
/// @dev Process commitment by lookup msg.sender, checking metrics, state and updating balances
270271
function processCommitmentUser() public {
271272
console.log("Processing commitment");
273+
require(commitments[msg.sender].exists, "SPC::processCommitmentUser - commitment does not exist");
272274
Commitment storage commitment = commitments[msg.sender];
273275

274276
commitment.met = commitment.reportedValue > commitment.goalValue;
@@ -289,8 +291,9 @@ contract SinglePlayerCommit is ChainlinkClient, Ownable {
289291
console.log("Received call for owner withdrawal for amount %s", amount);
290292

291293
require(amount <= slashedBalance, "SPC::ownerWithdraw - not enough available balance");
294+
slashedBalance = slashedBalance.sub(amount);
295+
292296
require(token.transfer(msg.sender, amount), "SPC::ownerWithdraw - token transfer failed");
293-
slashedBalance -= amount;
294297

295298
return true;
296299
}
@@ -318,7 +321,7 @@ contract SinglePlayerCommit is ChainlinkClient, Ownable {
318321
function _slashFunds(uint256 amount, address committer) internal returns (bool success) {
319322
require(committerBalances[committer] >= amount, "SPC::_slashFunds - funds not available");
320323
_changeCommitterBalance(amount, false);
321-
slashedBalance += amount;
324+
slashedBalance = slashedBalance.add(amount);
322325
return true;
323326
}
324327

@@ -337,10 +340,10 @@ contract SinglePlayerCommit is ChainlinkClient, Ownable {
337340
console.log("All provided activities added");
338341
}
339342

340-
/// @notice Add activity to contract's activityList
343+
/// @notice Add activity to contract's activityKeyList
341344
/// @param _activityName String name of activity
342345
/// @param _oracleAddress Contract address of oracle
343-
/// @dev Create key from name, create activity, push to activityList, return key
346+
/// @dev Create key from name, create activity, push to activityKeyList, return key
344347
function _addActivity(string memory _activityName, address _oracleAddress)
345348
internal
346349
returns (bytes32 activityKey)

migrations/01_intial_migration.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var Migrations = artifacts.require("Migrations");
2+
3+
module.exports = function(deployer) {
4+
// Deploy the Migrations contract as our only task
5+
deployer.deploy(Migrations);
6+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const SinglePlayerCommit = artifacts.require("SinglePlayerCommit");
2+
3+
module.exports = function(deployer) {
4+
// Deploy the Migrations contract as our only task
5+
const activities = ["biking", "cycling"];
6+
const oracle = "0x70d1F773A9f81C852087B77F6Ae6d3032B02D2AB";
7+
const token = "0xcB1e72786A6eb3b44C2a2429e317c8a2462CFeb1";
8+
deployer.deploy(SinglePlayerCommit, activities, oracle, token);
9+
};

0 commit comments

Comments
 (0)