Mock Ready

This commit is contained in:
2024-08-05 18:07:29 +08:00
parent 3ab5ee37c6
commit 39c2dd760b
12 changed files with 6904 additions and 1052 deletions
@@ -0,0 +1,41 @@
{
"language": "Solidity",
"sources": {
"@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface AggregatorV3Interface {\n function decimals() external view returns (uint8);\n\n function description() external view returns (string memory);\n\n function version() external view returns (uint256);\n\n // getRoundData and latestRoundData should both raise \"No data present\"\n // if they do not have data to report, instead of returning unset values\n // which could be misinterpreted as actual reported values.\n function getRoundData(uint80 _roundId)\n external\n view\n returns (\n uint80 roundId,\n int256 answer,\n uint256 startedAt,\n uint256 updatedAt,\n uint80 answeredInRound\n );\n\n function latestRoundData()\n external\n view\n returns (\n uint80 roundId,\n int256 answer,\n uint256 startedAt,\n uint256 updatedAt,\n uint80 answeredInRound\n );\n}\n"
},
"contracts/FundMe.sol": {
"content": "// SPDX-License-Identifier: MIT\n/*\n Get funds from users\n Withdraw funds\n Set a minimum funding value in USD\n*/\npragma solidity ^0.8.0;\n\nimport \"./PriceConverter.sol\";\n// Save Gas by using constant, immutable for variables\n\nerror NotOwner();\n\n// 816914\ncontract FundMe {\n /*\n Transaction Fields\n Nonce\n Gas Price\n Gas Limit - Max Gas that this TX can use\n To - Address\n Value - Amount of wei to send\n Data - What to send to the Address (Can Empty)\n v, r, s - components of TX signature\n */\n\n using PriceConverter for uint256;\n uint256 public constant MINIMUM_USD = 50 * 1e18;\n\n address[] public funders;\n mapping(address => uint256) public addressToAmountFunded;\n\n // immutable only can declare 1 time at contructor\n address public immutable i_owner;\n\n AggregatorV3Interface public priceFeed;\n\n constructor(address priceFeedAddress) {\n i_owner = msg.sender;\n priceFeed = AggregatorV3Interface(priceFeedAddress);\n }\n\n function fund() public payable {\n /*\n Want to be able to set a minimum fund amount in USD\n 1. How do we send ETH to this contract\n */\n //require (msg.value >= 1e18, \"Didn't send enough\"); // 1e18 = 1 * 10 * 18 = 1000000000000000000\n require(\n msg.value.getConversionRate(priceFeed) >= MINIMUM_USD,\n \"Didn't send enough\"\n );\n funders.push(msg.sender);\n addressToAmountFunded[msg.sender] = msg.value;\n }\n\n // Owner of this contract only can withdraw\n function withdraw() public onlyOwner {\n // Can use modifier to replace\n // require(msg.sender == owner, \"Sender is not owner\");\n\n /* starting index, eding index, step amount */\n for (\n uint256 funderIndex = 0;\n funderIndex < funders.length;\n funderIndex++\n ) {\n address funder = funders[funderIndex];\n addressToAmountFunded[funder] = 0;\n }\n // reset the array\n funders = new address[](0);\n\n /*\n // transfer - over 2300 gas will cause exception\n payable(msg.sender).transfer(address(this).balance);\n // send - over 2300 gas will not cause exception, only will return true or false\n bool sendSuccess = payable(msg.sender).send(address(this).balance);\n require(sendSuccess, \"Send failed\");\n */\n\n // call - lower level\n (bool callSuccess, ) = payable(msg.sender).call{\n value: address(this).balance\n }(\"\");\n require(callSuccess, \"Call failed\");\n }\n\n modifier onlyOwner() {\n // require(msg.sender == i_owner, \"Sender is not owner!\");\n if (msg.sender != i_owner) {\n revert NotOwner();\n }\n\n _; // doing the rest of the code\n }\n\n // What happens if someone send this contract ETH without calling the fund fucntion\n /*\n receive - people send money / empty money into this contract\n fallback - cannot identify which function to run\n */\n receive() external payable {\n fund();\n }\n\n fallback() external payable {\n fund();\n }\n}\n"
},
"contracts/PriceConverter.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\n//import \"@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol\";\nimport \"@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol\";\n\n// Why is this a library and not abstract?\n// Why not an interface?\nlibrary PriceConverter {\n // We could make this public, but then we'd have to deploy it\n function getPrice(\n AggregatorV3Interface priceFeed\n ) internal view returns (uint256) {\n (, int256 answer, , , ) = priceFeed.latestRoundData();\n // ETH/USD rate in 18 digit\n return uint256(answer * 10000000000);\n // or (Both will do the same thing)\n // return uint256(answer * 1e10); // 1* 10 ** 10 == 10000000000\n }\n\n // 1000000000\n function getConversionRate(\n uint256 ethAmount,\n AggregatorV3Interface priceFeed\n ) internal view returns (uint256) {\n uint256 ethPrice = getPrice(priceFeed);\n uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;\n // or (Both will do the same thing)\n // uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1e18; // 1 * 10 ** 18 == 1000000000000000000\n // the actual ETH/USD conversion rate, after adjusting the extra 0s.\n return ethAmountInUsd;\n }\n}\n"
}
},
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata",
"devdoc",
"userdoc",
"storageLayout",
"evm.gasEstimates"
],
"": [
"ast"
]
}
},
"metadata": {
"useLiteralContent": true
}
}
}