Skip to content

Instantly share code, notes, and snippets.

@joeb000
Last active June 5, 2023 19:16
Show Gist options
  • Save joeb000/411b41f41fa9a194312f0b1602dc0f56 to your computer and use it in GitHub Desktop.
Save joeb000/411b41f41fa9a194312f0b1602dc0f56 to your computer and use it in GitHub Desktop.
Bet Contract
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
contract TrumpBet {
mapping (address => uint) public bets;
mapping (address => bool) paid;
mapping (address => bool) oracles;
bytes32 public conditionsHash;
uint public endDate;
bool public oracleExecuted;
bool public conditionsMet;
bool public withdrawable;
uint public totalWinnableEth;
uint8 public payoutMultiplier;
uint public totalCommittedEth = 0;
constructor(bytes32 _conditionsHash, uint8 _payoutMulti, address[] memory _o, uint end) payable {
conditionsHash = _conditionsHash;
totalWinnableEth = msg.value;
payoutMultiplier = _payoutMulti;
endDate = end;
for (uint256 i = 0; i < _o.length; i++) {
oracles[_o[i]] = true;
}
}
modifier OnlyOracle {
if (oracles[msg.sender]) {
_;
}
}
function placeBet() public payable {
if (((msg.value * payoutMultiplier) + totalCommittedEth) <= totalWinnableEth) {
bets[msg.sender] = msg.value;
totalCommittedEth += msg.value * payoutMultiplier;
}
}
function checkConditionsHash(string memory _conditions) public view returns (bool) {
return keccak256(abi.encode(_conditions)) == conditionsHash;
}
function executeOracle(bool _conditionsMet) public OnlyOracle {
if (block.timestamp >= endDate) {
oracleExecuted = true;
conditionsMet = _conditionsMet;
}
}
function allowWithdraw(bool _withdrawable) public OnlyOracle {
withdrawable = _withdrawable;
}
function withdraw() public {
if (withdrawable && block.timestamp < endDate) {
payable(msg.sender).transfer(bets[msg.sender]);
}
}
function executePayout (address[] memory a) public {
if (block.timestamp >= endDate && conditionsMet) {
for (uint256 i = 0; i < a.length; i++) {
if (!paid[a[i]]) {
uint amount = bets[a[i]] * payoutMultiplier;
payable(a[i]).transfer(amount);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment