From 69076fae83337ed2c092b0fc744a77d7560b5871 Mon Sep 17 00:00:00 2001 From: Lulox Date: Wed, 27 Dec 2023 21:40:19 -0300 Subject: [PATCH] Added first draft of contract, deploy script, and README --- README.md | 55 +++++++++++++++++++++++++- packages/foundry/contracts/EasyPay.sol | 48 ++++++++++++++++++++++ packages/foundry/script/Deploy.s.sol | 8 ++-- 3 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 packages/foundry/contracts/EasyPay.sol diff --git a/README.md b/README.md index 542c0f4..e6c2325 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,57 @@ -# ๐Ÿ— Scaffold-ETH 2 +# ๐Ÿ’ธ EasyPay ๐Ÿ’ธ + +๐Ÿ’ธ dApp for requesting payments in a currency (like USD, ETH and BTC), and accept different type of valid tokens that share a common value using [Chainlink Price Feeds](https://docs.chain.link/data-feeds/price-feeds). + +๐Ÿฃ Project being developed by [Newbie's Lounge](https://lulox.notion.site/Newbie-s-Lounge-68ea7c4c5f1a4ec29786be6a76516878) +๐Ÿ‘ทโ€โ™€๏ธ To view current development tasks, [join this Trello board](https://trello.com/invite/b/s0vot1BA/ATTI366c508087a404ccf9343def4d76d1ce6F7899AA/newbies-lounge). +๐Ÿงฐ To chat with other buidlers about this project, [join our Telegram group](https://t.me/+FwCZPG51UhwzOTZh) +๐Ÿ› ๏ธ To collaborate, [fork and pull](https://github.com/susam/gitpr) a request to this repo. + +## Quickstart + +To get started with EasyPay, follow the steps below: + +1. Clone this repo & install dependencies + +``` +git clone https://github.com/luloxi/EasyPay.git +cd EasyPay +yarn install +``` + +2. Run a local network in the first terminal: + +``` +yarn chain +``` + +This command starts a local Ethereum network using Hardhat. The network runs on your local machine and can be used for testing and development. You can customize the network configuration in `hardhat.config.ts`. + +3. On a second terminal, deploy the test contract: + +``` +yarn deploy +``` + +This command deploys a test smart contract to the local network. The contract is located in `packages/hardhat/contracts` and can be modified to suit your needs. The `yarn deploy` command uses the deploy script located in `packages/hardhat/deploy` to deploy the contract to the network. You can also customize the deploy script. + +4. On a third terminal, start your NextJS app: + +``` +yarn start +``` + +Visit your app on: `http://localhost:3000`. You can interact with your smart contract using the contract component or the example ui in the frontend. You can tweak the app config in `packages/nextjs/scaffold.config.ts`. + +Run smart contract test with `yarn hardhat:test` + +- Edit your smart contract `EasyPay.sol` in `packages/hardhat/contracts` +- Edit your frontend in `packages/nextjs/pages` +- Edit your deployment scripts in `packages/hardhat/deploy` + +๐Ÿ— Project created using [Scaffold-ETH 2](https://scaffoldeth.io/) + +## ๐Ÿ— About Scaffold-ETH 2 ๐Ÿงช An open-source, up-to-date toolkit for building decentralized applications (dapps) on the Ethereum blockchain. It's designed to make it easier for developers to create and deploy smart contracts and build user interfaces that interact with those contracts. diff --git a/packages/foundry/contracts/EasyPay.sol b/packages/foundry/contracts/EasyPay.sol new file mode 100644 index 0000000..58d0fd5 --- /dev/null +++ b/packages/foundry/contracts/EasyPay.sol @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.22; + +/** +@dev Struct to store payment requests +@variables amount: Amount of USD requested +@variables receiver: Address of payment receiver +@variables completed: Boolean to determine if payment was succesfully made +*/ +struct PayRequest { + uint256 amount; + address receiver; + bool completed; +} + +contract EasyPay { + uint256 requests; + /** + @dev Mapping to store PayRequest structs mapped to a unique requestId + */ + mapping(uint256 requestId => PayRequest) public payRequests; + + function requestPayment(uint256 _amount) public { + requests++; + payRequests[requests] = PayRequest(_amount, msg.sender, false); + } + + function pay(uint256 _requestId) public payable { + require(payRequests[_requestId].receiver != address(0), "Request doesn't exist or was made by a dumb human!" ); + require(payRequests[_requestId].amount <= msg.value, "Ether sent must be equal or greater than requested amount!"); + require(payRequests[_requestId].completed == false, "Request has already been paid!"); + payRequests[_requestId].completed = true; + // Call returns a boolean value indicating success or failure. + // This is the current recommended method to use to transfer ETH. + (bool sent, ) = payRequests[_requestId].receiver.call{value: msg.value}(""); + require(sent, "Failed to send Ether, try again next block!"); + } + + // Function in case a payment is received where msg.data must be empty + receive() external payable { + require(msg.sender == address(0), "Are you stupid or what? Take care of your ETH!"); + } + + // Fallback function is called when msg.data is not empty + fallback() external payable { + require(msg.sender == address(0), "Are you stupid or what? Take care of your ETH!"); + } +} \ No newline at end of file diff --git a/packages/foundry/script/Deploy.s.sol b/packages/foundry/script/Deploy.s.sol index 48a1565..00a73c9 100644 --- a/packages/foundry/script/Deploy.s.sol +++ b/packages/foundry/script/Deploy.s.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: MIT pragma solidity ^0.8.19; -import "../contracts/YourContract.sol"; +import "../contracts/EasyPay.sol"; import "./DeployHelpers.s.sol"; contract DeployScript is ScaffoldETHDeploy { @@ -15,12 +15,12 @@ contract DeployScript is ScaffoldETHDeploy { ); } vm.startBroadcast(deployerPrivateKey); - YourContract yourContract = new YourContract( - vm.addr(deployerPrivateKey) + EasyPay easyPay = new EasyPay( + // vm.addr(deployerPrivateKey) ); console.logString( string.concat( - "YourContract deployed at: ", + "EasyPay deployed at: ", vm.toString(address(yourContract)) ) );