diff --git a/SmartContractAakash/.gitignore b/SmartContractAakash/.gitignore new file mode 100644 index 00000000..00dad773 --- /dev/null +++ b/SmartContractAakash/.gitignore @@ -0,0 +1,11 @@ +node_modules +.env +coverage +coverage.json +typechain +typechain-types + +# Hardhat files +cache +artifacts + diff --git a/SmartContractAakash/README.md b/SmartContractAakash/README.md new file mode 100644 index 00000000..e9dd5f34 --- /dev/null +++ b/SmartContractAakash/README.md @@ -0,0 +1,13 @@ +# Sample Hardhat Project + +This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract. + +Try running some of the following tasks: + +```shell +npx hardhat help +npx hardhat test +REPORT_GAS=true npx hardhat test +npx hardhat node +npx hardhat run scripts/deploy.js +``` diff --git a/SmartContractAakash/contracts/ipl.sol b/SmartContractAakash/contracts/ipl.sol new file mode 100644 index 00000000..197ec8d2 --- /dev/null +++ b/SmartContractAakash/contracts/ipl.sol @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.9; + +// Uncomment this line to use console.log +// import "hardhat/console.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +contract IPLBetting { + struct Bet { + address bettor; + uint amount; + uint team; + bool paidOut; + } + + Bet[] public bets; + uint public winningTeam; + bool public gameSettled; + address public owner; + constructor() { + owner = msg.sender; + } + + function placeBet(uint _team) public payable { + require(msg.value > 0, "Bet amount must be greater than 0."); + require(gameSettled == false, "Betting is closed."); + require(_team <= 2, "Invalid team selection."); + + bets.push(Bet(msg.sender, msg.value, _team, false)); + } + + function settleBet(uint _winningTeam) public { + require(msg.sender == owner, "Only the owner can settle the bet."); + require(gameSettled == false, "The game has already been settled."); + require(_winningTeam <= 2, "Invalid team selection."); + + winningTeam = _winningTeam; + gameSettled = true; + + uint totalWinningAmount = 0; + uint totalLosingAmount = 0; + + for (uint i = 0; i < bets.length; i++) { + if (bets[i].team == winningTeam) { + totalWinningAmount += bets[i].amount; + bets[i].paidOut = true; + } else { + totalLosingAmount += bets[i].amount; + } + } + + for (uint i = 0; i < bets.length; i++) { + if (bets[i].paidOut == false) { + uint payout = (bets[i].amount * totalWinningAmount) / (totalWinningAmount + totalLosingAmount); + payable(bets[i].bettor).transfer(payout); + bets[i].paidOut = true; + } + } + } + + function getNumBets() public view returns (uint) { + return bets.length; + } + + function getBet(uint _index) public view returns (address, uint, uint, bool) { + require(_index < bets.length, "Invalid index."); + return (bets[_index].bettor, bets[_index].amount, bets[_index].team, bets[_index].paidOut); + } + + function getWinningTeam() public view returns (uint) { + require(gameSettled == true, "The game has not been settled yet."); + return winningTeam; + } +} + diff --git a/SmartContractAakash/hardhat.config.js b/SmartContractAakash/hardhat.config.js new file mode 100644 index 00000000..49c2de11 --- /dev/null +++ b/SmartContractAakash/hardhat.config.js @@ -0,0 +1,101 @@ +require('@nomiclabs/hardhat-ethers'); +require('@nomiclabs/hardhat-etherscan'); + +// Change private keys accordingly - ONLY FOR DEMOSTRATION PURPOSES - PLEASE STORE PRIVATE KEYS IN A SAFE PLACE +// Export your private key as +// export PRIVKEY=0x..... + + +module.exports = { + defaultNetwork: 'buildbear', + + networks: { + hardhat: {}, + buildbear: { + url: "https://rpc.buildbear.io/Curious_Jocasta_Nu_7265a8d5", + }, + + }, + solidity: { + compilers: [ + { + version: '0.8.16', + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + { + version: '0.8.4', + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + { + version: '0.8.9', + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + { + version: '0.5.0', + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + { + version: '0.8.13', + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + { + version: '0.5.5', + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + ], + }, + + etherscan: { + apiKey: { + buildbear: "test1", + }, + customChains: [ + { + network: "buildbear", + chainId: 8646, + urls: { + apiURL: "https://rpc.buildbear.io/verify/etherscan/Curious_Jocasta_Nu_7265a8d5", + browserURL: "https://explorer.buildbear.io/Curious_Jocasta_Nu_7265a8d5", + }, + }, + ], + }, + paths: { + sources: './contracts', + cache: './cache', + artifacts: './artifacts', + }, + mocha: { + timeout: 20000000000, + }, +}; diff --git a/SmartContractAakash/package.json b/SmartContractAakash/package.json new file mode 100644 index 00000000..74873d2e --- /dev/null +++ b/SmartContractAakash/package.json @@ -0,0 +1,24 @@ +{ + "name": "smartcontractaakash", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "@openzeppelin/contracts": "^4.8.2", + "npx": "^10.2.2" + }, + "devDependencies": { + "@nomicfoundation/hardhat-chai-matchers": "^1.0.6", + "@nomicfoundation/hardhat-network-helpers": "^1.0.8", + "@nomiclabs/hardhat-ethers": "^2.2.2", + "@nomiclabs/hardhat-etherscan": "^3.1.7", + "chai": "^4.3.7", + "chai-as-promised": "^7.1.1", + "hardhat": "^2.13.0" + } +} diff --git a/SmartContractAakash/scripts/deploy.js b/SmartContractAakash/scripts/deploy.js new file mode 100644 index 00000000..745b18d4 --- /dev/null +++ b/SmartContractAakash/scripts/deploy.js @@ -0,0 +1,32 @@ +// We require the Hardhat Runtime Environment explicitly here. This is optional +// but useful for running the script in a standalone fashion through `node