Skip to content

Commit 31013be

Browse files
committed
chore(review): pr comments and mumbai deployment
1 parent 1fcac4d commit 31013be

File tree

6 files changed

+1778
-1669
lines changed

6 files changed

+1778
-1669
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ Ganache
2929

3030
#### Deploying to Matic
3131
1. ```npm install truffle -g```
32-
2. ```npm install truffle-flattener -g```
3332

3433
Mumbai Testnet configured in ```./truffle-config.js```
3534

@@ -39,9 +38,12 @@ Deploy to Mumbai testnet: ```truffle migrate --network matic```
3938
Verify deployment using contract address at the [Matic Explorer](https://explorer-mumbai.maticvigil.com/)
4039

4140
*Verifying & publishing the contract code*
41+
4242
In the [Matic Explorer](https://explorer-mumbai.maticvigil.com/) find your contract based on the address reported by Truffle.
4343
Go to the tab ```Code```
4444

45+
Flattening contract: https://github.com/poanetwork/solidity-flattener and cleanup SPDX licenses and _Chainlink appended to classes like SafeMath, Buffer and ENSResolver
46+
4547
Quite note on setting up Matic:
4648
* Configure Matic network in [MetaMask](https://docs.matic.network/docs/develop/metamask/config-matic/)
4749
* Request funds at [faucet](https://faucet.matic.network/)

contracts/Migrations.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//SPDX-License-Identifier: UNLICENSED
2-
pragma solidity ^0.6.10;
2+
pragma solidity 0.6.10;
33

44
contract Migrations {
55
address public owner;

contracts/SinglePlayerCommit.sol

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* SPDX-License-Identifier: MIT */
2-
pragma solidity ^0.6.10;
2+
pragma solidity 0.6.10;
33
pragma experimental ABIEncoderV2;
44

55
import { console } from "@nomiclabs/buidler/console.sol";
@@ -129,7 +129,7 @@ contract SinglePlayerCommit is ChainlinkClient, Ownable {
129129
"SPC::deposit - token transfer failed"
130130
);
131131

132-
_changeCommitterBalance(amount, true);
132+
_changeCommitterBalance(msg.sender, amount, true);
133133

134134
emit Deposit(msg.sender, amount);
135135

@@ -150,7 +150,7 @@ contract SinglePlayerCommit is ChainlinkClient, Ownable {
150150

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

153-
_changeCommitterBalance(amount, false);
153+
_changeCommitterBalance(msg.sender, amount, false);
154154

155155
require(token.transfer(msg.sender, amount), "SPC::withdraw - token transfer failed");
156156

@@ -244,7 +244,6 @@ contract SinglePlayerCommit is ChainlinkClient, Ownable {
244244
return true;
245245
}
246246

247-
//TODO DRY in procesCommitment methods
248247
/// @notice Enables processing of open commitments after endDate that have not been processed by creator
249248
/// @param committer address of the creator of the committer to process
250249
/// @dev Process commitment by lookup based on address, checking metrics, state and updating balances
@@ -256,13 +255,8 @@ contract SinglePlayerCommit is ChainlinkClient, Ownable {
256255
require(commitment.endTime < block.timestamp, "SPC::processCommitment - commitment is still active");
257256
require(commitment.endTime < commitment.lastActivityUpdate, "SPC::processCommitment - update activity");
258257

259-
commitment.met = commitment.reportedValue >= commitment.goalValue;
258+
require(_commitmentSettlement(commitment), "SPC::processCommitmentUser - reconciliation failed");
260259

261-
if (!commitment.met) {
262-
_slashFunds(commitment.stake, committer);
263-
}
264-
265-
commitment.exists = false;
266260
emit CommitmentEnded(committer, commitment.met, commitment.stake);
267261
}
268262

@@ -273,17 +267,23 @@ contract SinglePlayerCommit is ChainlinkClient, Ownable {
273267
require(commitments[msg.sender].exists, "SPC::processCommitmentUser - commitment does not exist");
274268
Commitment storage commitment = commitments[msg.sender];
275269

270+
require(_commitmentSettlement(commitment), "SPC::processCommitmentUser - reconciliation failed");
271+
emit CommitmentEnded(msg.sender, commitment.met, commitment.stake);
272+
}
273+
274+
/// @notice Internal function for evaluating commitment and slashing funds if needed
275+
/// @dev Receive call with commitment object from storage
276+
function _commitmentSettlement(Commitment storage commitment) internal returns (bool success) {
276277
commitment.met = commitment.reportedValue > commitment.goalValue;
277278

278279
if (!commitment.met) {
279280
_slashFunds(commitment.stake, msg.sender);
280281
}
281282

282283
commitment.exists = false;
283-
emit CommitmentEnded(msg.sender, commitment.met, commitment.stake);
284+
return true;
284285
}
285286

286-
//TODO state change after transfer is not recommended
287287
/// @notice Contract owner can withdraw funds not owned by committers. E.g. slashed from failed commitments
288288
/// @param amount Amount of <token> to withdraw
289289
/// @dev Check amount against slashedBalance, transfer amount and update slashedBalance
@@ -302,12 +302,12 @@ contract SinglePlayerCommit is ChainlinkClient, Ownable {
302302
/// @param amount Amount of <token> to deposit/withdraw
303303
/// @param add Boolean toggle to deposit or withdraw
304304
/// @dev Based on add param add or substract amount from msg.sender balance and total committerBalance
305-
function _changeCommitterBalance(uint256 amount, bool add) internal returns (bool success) {
305+
function _changeCommitterBalance(address committer, uint256 amount, bool add) internal returns (bool success) {
306306
if (add) {
307-
committerBalances[msg.sender] = committerBalances[msg.sender].add(amount);
307+
committerBalances[committer] = committerBalances[committer].add(amount);
308308
totalCommitterBalance = totalCommitterBalance.add(amount);
309309
} else {
310-
committerBalances[msg.sender] = committerBalances[msg.sender].sub(amount);
310+
committerBalances[committer] = committerBalances[committer].sub(amount);
311311
totalCommitterBalance = totalCommitterBalance.sub(amount);
312312
}
313313

@@ -320,7 +320,7 @@ contract SinglePlayerCommit is ChainlinkClient, Ownable {
320320
/// @dev Substract amount from committer balance and add to slashedBalance
321321
function _slashFunds(uint256 amount, address committer) internal returns (bool success) {
322322
require(committerBalances[committer] >= amount, "SPC::_slashFunds - funds not available");
323-
_changeCommitterBalance(amount, false);
323+
_changeCommitterBalance(committer, amount, false);
324324
slashedBalance = slashedBalance.add(amount);
325325
return true;
326326
}

0 commit comments

Comments
 (0)