feat: fill up challenge
Some checks failed
Lint / ci (lts/*, ubuntu-latest) (push) Has been cancelled
Some checks failed
Lint / ci (lts/*, ubuntu-latest) (push) Has been cancelled
This commit is contained in:
@@ -10,18 +10,27 @@ contract CrowdFund {
|
||||
/////////////////
|
||||
|
||||
// Errors go here...
|
||||
error NotOpenToWithdraw();
|
||||
error WithdrawTransferFailed(address to, uint256 amount);
|
||||
error TooEarly(uint256 deadline, uint256 currentTimestamp);
|
||||
error AlreadyCompleted();
|
||||
|
||||
//////////////////////
|
||||
/// State Variables //
|
||||
//////////////////////
|
||||
|
||||
FundingRecipient public fundingRecipient;
|
||||
mapping(address => uint256) public balances;
|
||||
bool public openToWithdraw;
|
||||
uint256 public deadline = block.timestamp + 2 hours;
|
||||
uint256 public constant threshold = 1 ether;
|
||||
|
||||
////////////////
|
||||
/// Events /////
|
||||
////////////////
|
||||
|
||||
// Events go here...
|
||||
event Contribution(address, uint256);
|
||||
|
||||
///////////////////
|
||||
/// Modifiers /////
|
||||
@@ -29,6 +38,7 @@ contract CrowdFund {
|
||||
|
||||
modifier notCompleted() {
|
||||
_;
|
||||
if (block.timestamp >= deadline) revert AlreadyCompleted();
|
||||
}
|
||||
|
||||
///////////////////
|
||||
@@ -43,19 +53,42 @@ contract CrowdFund {
|
||||
/// Functions /////
|
||||
///////////////////
|
||||
|
||||
function contribute() public payable {}
|
||||
function contribute() public payable {
|
||||
balances[msg.sender] += msg.value;
|
||||
emit Contribution(msg.sender, msg.value);
|
||||
}
|
||||
|
||||
function withdraw() public {}
|
||||
function withdraw() public {
|
||||
if (!openToWithdraw) revert NotOpenToWithdraw();
|
||||
|
||||
function execute() public {}
|
||||
uint256 amount = balances[msg.sender];
|
||||
balances[msg.sender] = 0;
|
||||
|
||||
receive() external payable {}
|
||||
(bool success,) = msg.sender.call{value: amount}("");
|
||||
if (!success) revert WithdrawTransferFailed(msg.sender, amount);
|
||||
}
|
||||
|
||||
function execute() public {
|
||||
if (block.timestamp < deadline) revert TooEarly(deadline, block.timestamp);
|
||||
|
||||
uint256 balance = address(this).balance;
|
||||
if (balance >= threshold) {
|
||||
fundingRecipient.complete{value: balance}();
|
||||
} else {
|
||||
openToWithdraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
receive() external payable {
|
||||
contribute();
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
/// View Functions /////
|
||||
////////////////////////
|
||||
|
||||
function timeLeft() public view returns (uint256) {
|
||||
return 0;
|
||||
if (block.timestamp >= deadline) return 0;
|
||||
return deadline - block.timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
1
packages/hardhat/deployments/sepolia/.chainId
Normal file
1
packages/hardhat/deployments/sepolia/.chainId
Normal file
@@ -0,0 +1 @@
|
||||
11155111
|
||||
310
packages/hardhat/deployments/sepolia/CrowdFund.json
Normal file
310
packages/hardhat/deployments/sepolia/CrowdFund.json
Normal file
File diff suppressed because one or more lines are too long
76
packages/hardhat/deployments/sepolia/FundingRecipient.json
Normal file
76
packages/hardhat/deployments/sepolia/FundingRecipient.json
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"address": "0xeA89D4E3dA2eb001631dD1c0CFa0D922869D1836",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "complete",
|
||||
"outputs": [],
|
||||
"stateMutability": "payable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "completed",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
}
|
||||
],
|
||||
"transactionHash": "0x7ad9d25092aed9d8f2ee38614dee5e9b457442ad32bf820384c0bc9aaf36c54c",
|
||||
"receipt": {
|
||||
"to": null,
|
||||
"from": "0x2C24aE4fDc0d94FF458F9a12A4c2fF5E5E0a6ca6",
|
||||
"contractAddress": "0xeA89D4E3dA2eb001631dD1c0CFa0D922869D1836",
|
||||
"transactionIndex": 106,
|
||||
"gasUsed": "87989",
|
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockHash": "0xe9fa6a5e45cd6851195ebf9ba728928f4e5d2982f2d8606c64450ea2ae23b4b5",
|
||||
"transactionHash": "0x7ad9d25092aed9d8f2ee38614dee5e9b457442ad32bf820384c0bc9aaf36c54c",
|
||||
"logs": [],
|
||||
"blockNumber": 10021914,
|
||||
"cumulativeGasUsed": "20601449",
|
||||
"status": 1,
|
||||
"byzantium": true
|
||||
},
|
||||
"args": [],
|
||||
"numDeployments": 1,
|
||||
"solcInputHash": "458d1396e5cbe5b8f0626cefc89ad3a7",
|
||||
"metadata": "{\"compiler\":{\"version\":\"0.8.20+commit.a1b79de6\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"complete\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"completed\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"contracts/FundingRecipient.sol\":\"FundingRecipient\"},\"evmVersion\":\"paris\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"contracts/FundingRecipient.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity 0.8.20; // Do not change the solidity version as it negatively impacts submission grading\\n\\ncontract FundingRecipient {\\n bool public completed;\\n\\n function complete() public payable {\\n completed = true;\\n }\\n}\\n\",\"keccak256\":\"0x093e9f4390e6f225b75cb2775607526dbf062751fca91949ee80de147707f219\",\"license\":\"MIT\"}},\"version\":1}",
|
||||
"bytecode": "0x6080604052348015600f57600080fd5b5060a08061001e6000396000f3fe60806040526004361060265760003560e01c8063522e117714602b5780639d9a7fe914603e575b600080fd5b603c6000805460ff19166001179055565b005b348015604957600080fd5b5060005460569060ff1681565b604051901515815260200160405180910390f3fea2646970667358221220db8e4d450c3ce702917ec87bbf961a466fe7b3581202297048bd7b39e9b649e064736f6c63430008140033",
|
||||
"deployedBytecode": "0x60806040526004361060265760003560e01c8063522e117714602b5780639d9a7fe914603e575b600080fd5b603c6000805460ff19166001179055565b005b348015604957600080fd5b5060005460569060ff1681565b604051901515815260200160405180910390f3fea2646970667358221220db8e4d450c3ce702917ec87bbf961a466fe7b3581202297048bd7b39e9b649e064736f6c63430008140033",
|
||||
"devdoc": {
|
||||
"kind": "dev",
|
||||
"methods": {},
|
||||
"version": 1
|
||||
},
|
||||
"userdoc": {
|
||||
"kind": "user",
|
||||
"methods": {},
|
||||
"version": 1
|
||||
},
|
||||
"storageLayout": {
|
||||
"storage": [
|
||||
{
|
||||
"astId": 56,
|
||||
"contract": "contracts/FundingRecipient.sol:FundingRecipient",
|
||||
"label": "completed",
|
||||
"offset": 0,
|
||||
"slot": "0",
|
||||
"type": "t_bool"
|
||||
}
|
||||
],
|
||||
"types": {
|
||||
"t_bool": {
|
||||
"encoding": "inplace",
|
||||
"label": "bool",
|
||||
"numberOfBytes": "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -37,7 +37,7 @@ const config: HardhatUserConfig = {
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultNetwork: "localhost",
|
||||
defaultNetwork: "sepolia", //"localhost",
|
||||
namedAccounts: {
|
||||
deployer: {
|
||||
// By default, it will take the first Hardhat account as the deployer
|
||||
|
||||
Reference in New Issue
Block a user