-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Angry Coding <mailidanielifechukwu@gmail.com> Co-authored-by: tokodev <pablo@asdloop.com> Co-authored-by: Shiv Bhonde <shivbhonde04@gmail.com>
- Loading branch information
1 parent
adb8c81
commit 95c01fb
Showing
39 changed files
with
867 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
pragma solidity >=0.8.0 <0.9.0; //Do not change the solidity version as it negativly impacts submission grading | ||
//SPDX-License-Identifier: MIT | ||
|
||
import "hardhat/console.sol"; | ||
|
||
contract DiceGame { | ||
uint256 public nonce = 0; | ||
uint256 public prize = 0; | ||
|
||
error NotEnoughEther(); | ||
|
||
event Roll(address indexed player, uint256 amount, uint256 roll); | ||
event Winner(address winner, uint256 amount); | ||
|
||
constructor() payable { | ||
resetPrize(); | ||
} | ||
|
||
function resetPrize() private { | ||
prize = ((address(this).balance * 10) / 100); | ||
} | ||
|
||
function rollTheDice() public payable { | ||
if (msg.value < 0.002 ether) { | ||
revert NotEnoughEther(); | ||
} | ||
|
||
bytes32 prevHash = blockhash(block.number - 1); | ||
bytes32 hash = keccak256(abi.encodePacked(prevHash, address(this), nonce)); | ||
uint256 roll = uint256(hash) % 16; | ||
|
||
console.log("\t", " Dice Game Roll:", roll); | ||
|
||
nonce++; | ||
prize += ((msg.value * 40) / 100); | ||
|
||
emit Roll(msg.sender, msg.value, roll); | ||
|
||
if (roll > 2) { | ||
return; | ||
} | ||
|
||
uint256 amount = prize; | ||
(bool sent, ) = msg.sender.call{value: amount}(""); | ||
require(sent, "Failed to send Ether"); | ||
|
||
resetPrize(); | ||
emit Winner(msg.sender, amount); | ||
} | ||
|
||
receive() external payable {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pragma solidity >=0.8.0 <0.9.0; //Do not change the solidity version as it negativly impacts submission grading | ||
//SPDX-License-Identifier: MIT | ||
|
||
import "hardhat/console.sol"; | ||
import "./DiceGame.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
contract RiggedRoll is Ownable { | ||
|
||
DiceGame public diceGame; | ||
|
||
constructor(address payable diceGameAddress) { | ||
diceGame = DiceGame(diceGameAddress); | ||
} | ||
|
||
|
||
// Implement the `withdraw` function to transfer Ether from the rigged contract to a specified address. | ||
|
||
// Create the `riggedRoll()` function to predict the randomness in the DiceGame contract and only initiate a roll when it guarantees a win. | ||
|
||
// Include the `receive()` function to enable the contract to receive incoming Ether. | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { DeployFunction } from "hardhat-deploy/types"; | ||
import { ethers } from "hardhat/"; | ||
import { DiceGame } from "../typechain-types/"; | ||
|
||
const deployDiceGame: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
const { deployer } = await hre.getNamedAccounts(); | ||
const { deploy } = hre.deployments; | ||
|
||
await deploy("DiceGame", { | ||
from: deployer, | ||
value: ethers.utils.parseEther("0.05"), | ||
log: true, | ||
}); | ||
|
||
// Simple example on how get the deployed dice game contract | ||
const diceGame: DiceGame = await ethers.getContract("DiceGame"); | ||
|
||
console.log("Deployed Dice Game Contract Address", diceGame.address); | ||
|
||
const balance = await ethers.provider.getBalance(diceGame.address); | ||
console.log("Deployed Dice Game Contract Balance", ethers.utils.formatEther(balance.toString())); | ||
}; | ||
|
||
export default deployDiceGame; | ||
|
||
deployDiceGame.tags = ["DiceGame"]; |
Oops, something went wrong.