Skip to content

Commit 5254cbd

Browse files
author
mingming.tang
committed
init project
0 parents  commit 5254cbd

14 files changed

+7328
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Sample Hardhat Project
2+
3+
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.
4+
5+
Try running some of the following tasks:
6+
7+
```shell
8+
npx hardhat help
9+
npx hardhat test
10+
REPORT_GAS=true npx hardhat test
11+
npx hardhat node
12+
npx hardhat run scripts/deploy.js
13+
```

contracts/BulkSender.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
// SPDX-License-Identifier: SimPL-3.0
3+
pragma solidity ^0.8.17;
4+
contract BulkSender{
5+
6+
function batchTransfer(address payable[] memory toList) payable public returns(uint256) {
7+
uint256 singleAmount = msg.value / toList.length;
8+
for (uint8 i=0; i<toList.length; i++) {
9+
address payable to = toList[i];
10+
to.transfer(singleAmount);
11+
}
12+
return singleAmount;
13+
}
14+
}

contracts/FallbackFunction.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.17;
3+
4+
contract FallbackFunction {
5+
6+
uint private callCount;
7+
8+
constructor() {
9+
callCount = 0;
10+
}
11+
12+
function getCallCount() public view returns(uint) {
13+
return callCount;
14+
}
15+
16+
fallback() external {
17+
callCount += 1;
18+
}
19+
}

contracts/Lock.sol

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.9;
3+
4+
// Uncomment this line to use console.log
5+
// import "hardhat/console.sol";
6+
7+
contract Lock {
8+
uint public unlockTime;
9+
address payable public owner;
10+
11+
event Withdrawal(uint amount, uint when);
12+
13+
constructor(uint _unlockTime) payable {
14+
require(
15+
block.timestamp < _unlockTime,
16+
"Unlock time should be in the future"
17+
);
18+
19+
unlockTime = _unlockTime;
20+
owner = payable(msg.sender);
21+
}
22+
23+
function withdraw() public {
24+
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
25+
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);
26+
27+
require(block.timestamp >= unlockTime, "You can't withdraw yet");
28+
require(msg.sender == owner, "You aren't the owner");
29+
30+
emit Withdrawal(address(this).balance, block.timestamp);
31+
32+
owner.transfer(address(this).balance);
33+
}
34+
}

contracts/Test_1.sol

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pragma solidity ^0.8.9;
2+
3+
contract Person {
4+
string name;
5+
6+
function getName() public view returns (string memory) {
7+
return name;
8+
}
9+
10+
function setName(string memory name_) public {
11+
name = name_;
12+
}
13+
}

hardhat.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require("@nomicfoundation/hardhat-toolbox");
2+
3+
/** @type import('hardhat/config').HardhatUserConfig */
4+
module.exports = {
5+
solidity: "0.8.17",
6+
networks: {
7+
goerli: {
8+
chainId: 5,
9+
url: "https://goerli.infura.io/v3/19f952ce3ba04e09a4e844c2bc4a7dbf",
10+
accounts: ["c1afce82cb3c8ace7e980bd74cfedd49f01c603413db0598ecacde802e9a8737"],
11+
}
12+
}
13+
};

oracle_1.sol

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
pragma solidity ^0.8.7;
2+
3+
4+
contract OraclePrice {
5+
uint32 public price;
6+
mapping(address => uint32) private balances;
7+
mapping(address => uint32) private lastFeed;
8+
9+
uint public lastUpdateBlockNumber;
10+
11+
12+
function balanceOf(address account) public view returns (uint32) {
13+
return balances[account];
14+
}
15+
16+
function getPrice() public view returns (uint32) {
17+
return price;
18+
}
19+
20+
function feed(uint32 feedPrice) public {
21+
lastFeed[msg.sender] = feedPrice;
22+
}
23+
24+
function update() public returns (bool) {
25+
if (lastUpdateBlockNumber !=0 && lastUpdateBlockNumber+1 == block.number) {
26+
return false;
27+
}
28+
29+
30+
}
31+
32+
}

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"devDependencies": {
3+
"@ethersproject/abi": "^5.4.7",
4+
"@ethersproject/providers": "^5.4.7",
5+
"@nomicfoundation/hardhat-chai-matchers": "^1.0.0",
6+
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
7+
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
8+
"@nomiclabs/hardhat-ethers": "^2.0.0",
9+
"@nomiclabs/hardhat-etherscan": "^3.0.0",
10+
"@typechain/ethers-v5": "^10.1.0",
11+
"@typechain/hardhat": "^6.1.2",
12+
"chai": "^4.2.0",
13+
"ethers": "^5.4.7",
14+
"hardhat": "^2.12.4",
15+
"hardhat-gas-reporter": "^1.0.8",
16+
"solidity-coverage": "^0.8.0",
17+
"typechain": "^8.1.0"
18+
},
19+
"dependencies": {
20+
"@openzeppelin/contracts": "^4.8.1",
21+
"@zondax/filecoin-solidity": "^0.5.0-beta.1"
22+
}
23+
}

scripts/deploy.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// We require the Hardhat Runtime Environment explicitly here. This is optional
2+
// but useful for running the script in a standalone fashion through `node <script>`.
3+
//
4+
// You can also run a script with `npx hardhat run <script>`. If you do that, Hardhat
5+
// will compile your contracts, add the Hardhat Runtime Environment's members to the
6+
// global scope, and execute the script.
7+
const hre = require("hardhat");
8+
9+
async function main() {
10+
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
11+
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
12+
const unlockTime = currentTimestampInSeconds + ONE_YEAR_IN_SECS;
13+
14+
const lockedAmount = hre.ethers.utils.parseEther("1");
15+
16+
const Lock = await hre.ethers.getContractFactory("Lock");
17+
const lock = await Lock.deploy(unlockTime, { value: lockedAmount });
18+
19+
await lock.deployed();
20+
21+
console.log(
22+
`Lock with 1 ETH and unlock timestamp ${unlockTime} deployed to ${lock.address}`
23+
);
24+
}
25+
26+
// We recommend this pattern to be able to use async/await everywhere
27+
// and properly handle errors.
28+
main().catch((error) => {
29+
console.error(error);
30+
process.exitCode = 1;
31+
});

scripts/deploy_bulk_sneder.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// We require the Hardhat Runtime Environment explicitly here. This is optional
2+
// but useful for running the script in a standalone fashion through `node <script>`.
3+
//
4+
// You can also run a script with `npx hardhat run <script>`. If you do that, Hardhat
5+
// will compile your contracts, add the Hardhat Runtime Environment's members to the
6+
// global scope, and execute the script.
7+
const hre = require("hardhat");
8+
9+
async function main() {
10+
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
11+
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
12+
const unlockTime = currentTimestampInSeconds + ONE_YEAR_IN_SECS;
13+
14+
const lockedAmount = hre.ethers.utils.parseEther("1");
15+
16+
const Lock = await hre.ethers.getContractFactory("BulkSender");
17+
const lock = await Lock.deploy();
18+
19+
await lock.deployed();
20+
21+
console.log(
22+
`Lock with 1 ETH and unlock timestamp ${unlockTime} deployed to ${lock.address}`
23+
);
24+
}
25+
26+
// We recommend this pattern to be able to use async/await everywhere
27+
// and properly handle errors.
28+
main().catch((error) => {
29+
console.error(error);
30+
process.exitCode = 1;
31+
});

scripts/deploy_fallback_function.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// We require the Hardhat Runtime Environment explicitly here. This is optional
2+
// but useful for running the script in a standalone fashion through `node <script>`.
3+
//
4+
// You can also run a script with `npx hardhat run <script>`. If you do that, Hardhat
5+
// will compile your contracts, add the Hardhat Runtime Environment's members to the
6+
// global scope, and execute the script.
7+
const hre = require("hardhat");
8+
9+
async function main() {
10+
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
11+
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
12+
const unlockTime = currentTimestampInSeconds + ONE_YEAR_IN_SECS;
13+
14+
const lockedAmount = hre.ethers.utils.parseEther("1");
15+
16+
const Lock = await hre.ethers.getContractFactory("FallbackFunction");
17+
const lock = await Lock.deploy();
18+
19+
await lock.deployed();
20+
21+
console.log(
22+
`Lock with 1 ETH and unlock timestamp ${unlockTime} deployed to ${lock.address}`
23+
);
24+
}
25+
26+
// We recommend this pattern to be able to use async/await everywhere
27+
// and properly handle errors.
28+
main().catch((error) => {
29+
console.error(error);
30+
process.exitCode = 1;
31+
});

scripts/deploy_test_1.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// We require the Hardhat Runtime Environment explicitly here. This is optional
2+
// but useful for running the script in a standalone fashion through `node <script>`.
3+
//
4+
// You can also run a script with `npx hardhat run <script>`. If you do that, Hardhat
5+
// will compile your contracts, add the Hardhat Runtime Environment's members to the
6+
// global scope, and execute the script.
7+
const hre = require("hardhat");
8+
9+
async function main() {
10+
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
11+
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
12+
const unlockTime = currentTimestampInSeconds + ONE_YEAR_IN_SECS;
13+
14+
const lockedAmount = hre.ethers.utils.parseEther("1");
15+
16+
const Lock = await hre.ethers.getContractFactory("Person");
17+
const lock = await Lock.deploy();
18+
19+
await lock.deployed();
20+
21+
console.log(
22+
`Lock with 1 ETH and unlock timestamp ${unlockTime} deployed to ${lock.address}`
23+
);
24+
}
25+
26+
// We recommend this pattern to be able to use async/await everywhere
27+
// and properly handle errors.
28+
main().catch((error) => {
29+
console.error(error);
30+
process.exitCode = 1;
31+
});

0 commit comments

Comments
 (0)