Skip to content

Commit

Permalink
redeploy with more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lorbke committed Nov 16, 2024
1 parent 01ab7bd commit cda9efa
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 38 deletions.
58 changes: 58 additions & 0 deletions packages/foundry/broadcast/Deploy.s.sol/480/run-1731777622.json

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions packages/foundry/broadcast/Deploy.s.sol/480/run-1731777900.json

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions packages/foundry/broadcast/Deploy.s.sol/480/run-latest.json

Large diffs are not rendered by default.

26 changes: 17 additions & 9 deletions packages/foundry/contracts/HumanOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ contract HumanOracle {
_;
}

modifier userOldEnough(uint256 voteId) {
if (users[address(msg.sender)].createdAtBlock > getVoteStartBlock(voteId)) {
revert("user was created after voting begun");
}
_;
}
// security measurement
// modifier userOldEnough(uint256 voteId) {
// if (users[address(msg.sender)].createdAtBlock > getVoteStartBlock(voteId)) {
// revert("user was created after voting begun");
// }
// _;
// }

// ====================
// === Constructor ====
Expand Down Expand Up @@ -151,7 +152,7 @@ contract HumanOracle {
emit UserRegistered(userAddr, users[userAddr].nullifierHash, users[userAddr].createdAtBlock);
}

function submitVotingDecisionWithStake(uint256 voteId, uint256 answerIndex, uint256 amount) userOldEnough(voteId) userExists() hasNotVoted(voteId) voteActive(voteId) external {
function submitVotingDecisionWithStake(uint256 voteId, uint256 answerIndex, uint256 amount) userExists() hasNotVoted(voteId) voteActive(voteId) external {
require(amount <= 5, "max staking amount is 5");
address userAddr = address(msg.sender);
stakeForAnswer(userAddr, voteId, answerIndex, amount);
Expand All @@ -160,6 +161,7 @@ contract HumanOracle {

function claimRewardForVote(uint256 voteId) voteEnded(voteId) external returns (uint256) {
address userAddr = address(msg.sender);
require(!hasUserClaimedForVote(userAddr, voteId), "user already claimed");
setUserHasClaimedToTrueForVote(userAddr, voteId);
uint256 payout = getStakeResolvedUserAmount(userAddr, voteId);
emit RewardClaimed(userAddr, voteId, payout);
Expand Down Expand Up @@ -187,7 +189,7 @@ contract HumanOracle {

createNewStake(voteId, bounty);

emit VoteCreated(votes[voteId].id, votes[voteId].question, votes[voteId].startBlock, votes[voteId].durationInBlocks);
emit VoteCreated(voteId, getVoteQuestion(voteId), getVoteStartBlock(voteId), getVoteDurationInBlocks(voteId));
}

function getVotingPage(uint256 voteId) external view returns (
Expand Down Expand Up @@ -244,19 +246,25 @@ contract HumanOracle {
return false;
}

function hasUserClaimedForVote(address userAddr, uint256 voteId) external view returns (bool) {
function hasUserClaimedForVote(address userAddr, uint256 voteId) public view returns (bool) {
return stakesForVoteIds[voteId].hasUserClaimed[userAddr];
}

function getUserPayoutForVote(address userAddr, uint256 voteId) public view returns (uint256 payout) {
return getStakeResolvedUserAmount(userAddr, voteId);
}

// internal

// stake related
function createNewStake(uint256 voteId, uint256 initialStake) internal {
Stake storage newStake = stakesForVoteIds[voteId];
newStake.totalStake = initialStake;
uint256 answerCount = votes[voteId].answers.length;
uint256 initialStakePerAnswer = initialStake / answerCount;
for (uint i = 0; i < answerCount; i++) {
newStake.answers.push();
newStake.answers[i].totalStake = initialStakePerAnswer;
}
}

Expand Down
26 changes: 17 additions & 9 deletions packages/foundry/contractsToVerify/HumanOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ contract HumanOracle {
_;
}

modifier userOldEnough(uint256 voteId) {
if (users[address(msg.sender)].createdAtBlock > getVoteStartBlock(voteId)) {
revert("user was created after voting begun");
}
_;
}
// security measurement
// modifier userOldEnough(uint256 voteId) {
// if (users[address(msg.sender)].createdAtBlock > getVoteStartBlock(voteId)) {
// revert("user was created after voting begun");
// }
// _;
// }

// ====================
// === Constructor ====
Expand Down Expand Up @@ -151,7 +152,7 @@ contract HumanOracle {
emit UserRegistered(userAddr, users[userAddr].nullifierHash, users[userAddr].createdAtBlock);
}

function submitVotingDecisionWithStake(uint256 voteId, uint256 answerIndex, uint256 amount) userOldEnough(voteId) userExists() hasNotVoted(voteId) voteActive(voteId) external {
function submitVotingDecisionWithStake(uint256 voteId, uint256 answerIndex, uint256 amount) userExists() hasNotVoted(voteId) voteActive(voteId) external {
require(amount <= 5, "max staking amount is 5");
address userAddr = address(msg.sender);
stakeForAnswer(userAddr, voteId, answerIndex, amount);
Expand All @@ -160,6 +161,7 @@ contract HumanOracle {

function claimRewardForVote(uint256 voteId) voteEnded(voteId) external returns (uint256) {
address userAddr = address(msg.sender);
require(!hasUserClaimedForVote(userAddr, voteId), "user already claimed");
setUserHasClaimedToTrueForVote(userAddr, voteId);
uint256 payout = getStakeResolvedUserAmount(userAddr, voteId);
emit RewardClaimed(userAddr, voteId, payout);
Expand Down Expand Up @@ -187,7 +189,7 @@ contract HumanOracle {

createNewStake(voteId, bounty);

emit VoteCreated(votes[voteId].id, votes[voteId].question, votes[voteId].startBlock, votes[voteId].durationInBlocks);
emit VoteCreated(voteId, getVoteQuestion(voteId), getVoteStartBlock(voteId), getVoteDurationInBlocks(voteId));
}

function getVotingPage(uint256 voteId) external view returns (
Expand Down Expand Up @@ -244,19 +246,25 @@ contract HumanOracle {
return false;
}

function hasUserClaimedForVote(address userAddr, uint256 voteId) external view returns (bool) {
function hasUserClaimedForVote(address userAddr, uint256 voteId) public view returns (bool) {
return stakesForVoteIds[voteId].hasUserClaimed[userAddr];
}

function getUserPayoutForVote(address userAddr, uint256 voteId) public view returns (uint256 payout) {
return getStakeResolvedUserAmount(userAddr, voteId);
}

// internal

// stake related
function createNewStake(uint256 voteId, uint256 initialStake) internal {
Stake storage newStake = stakesForVoteIds[voteId];
newStake.totalStake = initialStake;
uint256 answerCount = votes[voteId].answers.length;
uint256 initialStakePerAnswer = initialStake / answerCount;
for (uint i = 0; i < answerCount; i++) {
newStake.answers.push();
newStake.answers[i].totalStake = initialStakePerAnswer;
}
}

Expand Down
26 changes: 25 additions & 1 deletion packages/nextjs-app/src/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ const deployedContracts = {
},
480: {
HumanOracle: {
address: "0x909ebe9c98afa1a685603584ed2eea91a20d5311",
address: "0xaacd5df051fe64da91422a0a2bf4f99a14732bda",
abi: [
{
type: "constructor",
Expand Down Expand Up @@ -369,6 +369,30 @@ const deployedContracts = {
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "getUserPayoutForVote",
inputs: [
{
name: "userAddr",
type: "address",
internalType: "address",
},
{
name: "voteId",
type: "uint256",
internalType: "uint256",
},
],
outputs: [
{
name: "payout",
type: "uint256",
internalType: "uint256",
},
],
stateMutability: "view",
},
{
type: "function",
name: "getVotingList",
Expand Down
26 changes: 25 additions & 1 deletion packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ const deployedContracts = {
},
480: {
HumanOracle: {
address: "0x909ebe9c98afa1a685603584ed2eea91a20d5311",
address: "0xaacd5df051fe64da91422a0a2bf4f99a14732bda",
abi: [
{
type: "constructor",
Expand Down Expand Up @@ -370,6 +370,30 @@ const deployedContracts = {
outputs: [],
stateMutability: "nonpayable",
},
{
type: "function",
name: "getUserPayoutForVote",
inputs: [
{
name: "userAddr",
type: "address",
internalType: "address",
},
{
name: "voteId",
type: "uint256",
internalType: "uint256",
},
],
outputs: [
{
name: "payout",
type: "uint256",
internalType: "uint256",
},
],
stateMutability: "view",
},
{
type: "function",
name: "getVotingList",
Expand Down

0 comments on commit cda9efa

Please sign in to comment.