Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.

Commit

Permalink
Fix escrow and calc (#18)
Browse files Browse the repository at this point in the history
* Change version to 1

* Fix transferring of escrow to depositer

* Add param for calc winnings

* Explain more about calc winnings return

* Fix typo with transferring escrow

* Change comment
  • Loading branch information
dwalintukan committed May 24, 2019
1 parent 5b6a1fe commit 63e7f72
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
6 changes: 4 additions & 2 deletions contracts/event/EventFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract EventFactory is NRC223Receiver {
uint amount;
}

uint16 private constant VERSION = 0;
uint16 private constant VERSION = 1;

address private _configManager;
address private _bodhiTokenAddress;
Expand Down Expand Up @@ -81,7 +81,9 @@ contract EventFactory is NRC223Receiver {

_escrows[msg.sender].didWithdraw = true;
uint amount = _escrows[msg.sender].amount;
INRC223(_bodhiTokenAddress).transfer(msg.sender, amount);

// Transfer to escrow depositer
INRC223(_bodhiTokenAddress).transfer(_escrows[msg.sender].depositer, amount);

return amount;
}
Expand Down
16 changes: 12 additions & 4 deletions contracts/event/MultipleResultsEvent.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract MultipleResultsEvent is NRC223Receiver, Ownable {
ResultBalance[11] balances;
}

uint16 private constant VERSION = 0;
uint16 private constant VERSION = 1;
uint8 private constant INVALID_RESULT_INDEX = 255;

uint8 private _numOfResults;
Expand Down Expand Up @@ -214,7 +214,7 @@ contract MultipleResultsEvent is NRC223Receiver, Ownable {

// Calculate and transfer winnings
_didWithdraw[msg.sender] = true;
uint winningAmount = calculateWinnings();
uint winningAmount = calculateWinnings(msg.sender);
if (winningAmount > 0) {
INRC223(_bodhiTokenAddress).transfer(msg.sender, winningAmount);
}
Expand All @@ -232,12 +232,20 @@ contract MultipleResultsEvent is NRC223Receiver, Ownable {
}

/// @notice Calculates the tokens returned based on the sender's participation.
/// @param better Address to calculate winnings for.
/// @return Amount of bet and vote tokens won.
function calculateWinnings()
function calculateWinnings(
address better)
public
view
returns (uint)
{
// Return 0 if there currentResultIndex is invalid since we cannot
// iterate through the balances by that index.
if (_currentResultIndex == INVALID_RESULT_INDEX) {
return 0;
}

// Calculate bet round losers' total
uint betRoundLosersTotal;
for (uint8 i = 0; i < _numOfResults; i++) {
Expand Down Expand Up @@ -274,7 +282,7 @@ contract MultipleResultsEvent is NRC223Receiver, Ownable {
uint allRoundsUserBets;
uint voteRoundsUserBets;
for (uint8 i = 0; i <= _currentRound; i++) {
uint bets = _eventRounds[i].balances[_currentResultIndex].bets[msg.sender];
uint bets = _eventRounds[i].balances[_currentResultIndex].bets[better];
allRoundsUserBets = allRoundsUserBets.add(bets);
if (i > 0) {
voteRoundsUserBets = voteRoundsUserBets.add(bets);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "bodhi-ethereum",
"version": "1.0.0",
"description": "Bodhi Ethereum Contracts",
"name": "prediction-market-contracts-naka",
"version": "0.0.1",
"description": "Bodhi Prediction Market Contracts for Nakachain",
"private": true,
"main": "truffle-config.js",
"directories": {
"test": "test"
Expand All @@ -19,20 +20,19 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/bodhiproject/bodhi-ethereum.git"
"url": "git+https://github.com/bodhiproject/prediction-market-contracts-naka.git"
},
"keywords": [
"bodhi",
"ethereum",
"erc223",
"prediction",
"market",
"dapp"
"ethereum",
"smart contracts"
],
"author": "Deric Walintukan",
"license": "ISC",
"bugs": {
"url": "https://github.com/bodhiproject/bodhi-ethereum/issues"
"url": "https://github.com/bodhiproject/prediction-market-contracts-naka/issues"
},
"homepage": "https://github.com/bodhiproject/bodhi-ethereum#readme"
"homepage": "https://github.com/bodhiproject/prediction-market-contracts-naka#readme"
}

0 comments on commit 63e7f72

Please sign in to comment.