Skip to content

Commit

Permalink
add mock contract
Browse files Browse the repository at this point in the history
  • Loading branch information
lorbke committed Nov 15, 2024
1 parent be06029 commit d3be16c
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 93 deletions.
146 changes: 146 additions & 0 deletions packages/foundry/contracts/HumanOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

// Useful for debugging. Remove when deploying to a live network.
// import "forge-std/console.sol";

contract HumanOracle {
// ====================
// ====== Structs =====
// ====================

struct User {
uint256 nullifierHash;
uint256 createdAtBlock;
}

struct Option {
uint256 totalStake;
mapping (address => uint256) userStakes;
}

struct Stake {
Option[] options;
uint256 totalStake;
}

struct Vote {
uint256 id;
string question;
string[] answers;
uint256 startBlock;
uint256 durationInBlocks;
Stake stake;
}

// ====================
// ==== Variables =====
// ====================

mapping (address => User) users;
Vote[] votes;

// ====================
// ====== Events ======
// ====================

event UserRegistered(address indexed user, uint256 nullifierHash, uint256 createdAtBlock);

event VoteCreated(uint256 indexed voteId, string question, uint256 startBlock, uint256 durationInBlocks);

event VoteSubmitted(address indexed user, uint256 indexed voteId, uint256 answerIndex, uint256 stakeAmount);

event RewardClaimed(address indexed user, uint256 indexed voteId, uint256 rewardAmount);

// ====================
// ==== Modifiers =====
// ====================

// ====================
// === Constructor ====
// ====================

// ====================
// ==== Functions =====
// ====================

// external

function signUpWithWorldId(uint256 nullifierHash, uint256[8] calldata proof) external {
}

function submitVotingDecisionWithStake(uint256 voteId, uint256 answerIndex, uint256 stake) external {

}

function claimRewardForVote(uint256 voteId) external {

}

function isUserRegistered() external pure returns (bool) {
return true;
}

function createVote(string calldata question, string[] calldata answers, uint256 startingBlock, uint256 durationInBlocks) external {

}

function getVotingPage(uint256 voteId) external pure returns (
string memory question,
string[] memory answers,
uint256 totalStake,
uint256[] memory stakePerAnswer
) {
// Mock Data based on voteId
if (voteId == 1) {
question = "What is your favorite blockchain?";
answers = new string[](3);
answers[0] = "Ethereum";
answers[1] = "Binance Smart Chain";
answers[2] = "Polkadot";
totalStake = 1000;
stakePerAnswer = new uint256[](3);
stakePerAnswer[0] = 600; // Ethereum
stakePerAnswer[1] = 300; // Binance Smart Chain
stakePerAnswer[2] = 100; // Polkadot
}
else if (voteId == 2) {
question = "Which DeFi project do you trust the most?";
answers = new string[](2);
answers[0] = "Uniswap";
answers[1] = "Aave";
totalStake = 500;
stakePerAnswer = new uint256[](2);
stakePerAnswer[0] = 350;
stakePerAnswer[1] = 150;
}
else {
question = new string(0);
answers = new string[](0);
totalStake = 0;
stakePerAnswer = new uint256[](0);
}
return (question, answers, totalStake, stakePerAnswer);
}

function getVotingList() external pure returns (
uint256[] memory ids,
string[] memory questions,
uint256[] memory totalStakes
) {
uint256 numberOfVotes = 2;
ids = new uint256[](numberOfVotes);
questions = new string[](numberOfVotes);
totalStakes = new uint256[](numberOfVotes);

ids[0] = 1;
questions[0] = "What is your favorite blockchain?";
totalStakes[0] = 1000;

ids[1] = 2;
questions[1] = "Which DeFi project do you trust the most?";
totalStakes[1] = 500;

return (ids, questions, totalStakes);
}
}
88 changes: 0 additions & 88 deletions packages/foundry/contracts/YourContract.sol

This file was deleted.

4 changes: 2 additions & 2 deletions packages/foundry/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ libs = ['lib']
fs_permissions = [{ access = "read-write", path = "./"}]

[rpc_endpoints]
default_network = "http://127.0.0.1:8545"
localhost = "http://127.0.0.1:8545"
default_network = "http://127.0.0.1:3000"
localhost = "http://127.0.0.1:3000"

mainnet = "https://cloudflare-eth.com"
sepolia = "https://rpc2.sepolia.org"
Expand Down
6 changes: 3 additions & 3 deletions packages/foundry/script/DeployYourContract.s.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "../contracts/YourContract.sol";
import "../contracts/HumanOracle.sol";
import "./DeployHelpers.s.sol";

contract DeployYourContract is ScaffoldETHDeploy {
// use `deployer` from `ScaffoldETHDeploy`
function run() external ScaffoldEthDeployerRunner {
YourContract yourContract = new YourContract(deployer);
HumanOracle humanOracle = new HumanOracle();
console.logString(
string.concat(
"YourContract deployed at: ", vm.toString(address(yourContract))
"HumanOracle deployed at: ", vm.toString(address(humanOracle))
)
);
}
Expand Down

0 comments on commit d3be16c

Please sign in to comment.