-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contracts): support hardhat and foundry for contracts package
- Loading branch information
Showing
22 changed files
with
264 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,11 @@ artifacts | |
cache | ||
typechain-types | ||
|
||
# foundry | ||
cache_forge | ||
out | ||
docs | ||
|
||
# production | ||
dist | ||
build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,11 @@ artifacts | |
cache | ||
typechain-types | ||
|
||
# foundry | ||
cache_forge | ||
out | ||
docs | ||
|
||
# production | ||
dist | ||
build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"semi": false, | ||
"arrowParens": "always", | ||
"trailingComma": "none" | ||
"trailingComma": "none", | ||
"plugins": ["prettier-plugin-solidity"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
contracts/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,8 @@ | |
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"packageManager": "[email protected]" | ||
"packageManager": "[email protected]", | ||
"dependencies": { | ||
"@openzeppelin/contracts": "^5.0.2" | ||
} | ||
} |
12 changes: 5 additions & 7 deletions
12
packages/contracts/contracts/Lock.sol → packages/contracts/contracts/src/Lock.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.27; | ||
|
||
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
// Uncomment this line to use console.log | ||
// import "hardhat/console.sol"; | ||
|
||
contract Lock { | ||
contract Lock is Ownable(msg.sender) { | ||
uint256 public unlockTime; | ||
address payable public owner; | ||
|
||
event Withdrawal(uint256 amount, uint256 when); | ||
|
||
constructor(uint256 _unlockTime) payable { | ||
require(block.timestamp < _unlockTime, "Unlock time should be in the future"); | ||
|
||
unlockTime = _unlockTime; | ||
owner = payable(msg.sender); | ||
} | ||
|
||
function withdraw() public { | ||
function withdraw() public onlyOwner { | ||
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal | ||
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp); | ||
|
||
require(block.timestamp >= unlockTime, "You can't withdraw yet"); | ||
require(msg.sender == owner, "You aren't the owner"); | ||
|
||
emit Withdrawal(address(this).balance, block.timestamp); | ||
|
||
owner.transfer(address(this).balance); | ||
payable(owner()).transfer(address(this).balance); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.25 <0.9.0; | ||
|
||
import {Test} from "forge-std/src/Test.sol"; | ||
import {console2} from "forge-std/src/console2.sol"; | ||
|
||
import {Lock} from "../src/Lock.sol"; | ||
|
||
contract LockTest is Test { | ||
Lock internal lock; | ||
|
||
function setUp() public virtual { | ||
// Set unlock time to 1 hour from now | ||
lock = new Lock{value: 1 ether}(block.timestamp + 1 hours); | ||
} | ||
|
||
function test_CannotWithdrawYet() external { | ||
// Attempt to withdraw before unlock time | ||
vm.expectRevert("You can't withdraw yet"); | ||
lock.withdraw(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[profile.default] | ||
src = 'contracts/src' | ||
out = 'out' | ||
libs = ['node_modules'] | ||
test = 'contracts/test' | ||
cache_path = 'cache_forge' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import { HardhatUserConfig } from "hardhat/config" | ||
import "@nomicfoundation/hardhat-toolbox" | ||
import "@nomicfoundation/hardhat-foundry" | ||
|
||
const config: HardhatUserConfig = { | ||
solidity: "0.8.27" | ||
solidity: "0.8.27", | ||
paths: { | ||
sources: "./contracts/src", | ||
tests: "./test", | ||
cache: "./cache", | ||
artifacts: "./artifacts" | ||
} | ||
} | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
{ | ||
"name": "excubiae-contracts", | ||
"packageManager": "[email protected]", | ||
"private": true, | ||
"installConfig": { | ||
"hoistingLimits": "dependencies" | ||
}, | ||
"scripts": { | ||
"start": "hardhat node", | ||
"compile": "hardhat compile", | ||
"start:hardhat": "hardhat node", | ||
"start:anvil": "anvil", | ||
"compile": "yarn compile:hardhat && yarn compile:forge", | ||
"compile:hardhat": "hardhat compile", | ||
"compile:forge": "forge compile", | ||
"deploy": "hardhat deploy", | ||
"test": "hardhat test", | ||
"test:report-gas": "REPORT_GAS=true hardhat test", | ||
"test:coverage": "hardhat coverage", | ||
"test": "yarn test:hardhat && yarn test:forge", | ||
"test:hardhat": "hardhat test", | ||
"test:forge": "forge test", | ||
"test:report-gas": "REPORT_GAS=true yarn test && forge test --gas-report", | ||
"test:coverage": "hardhat coverage && forge coverage", | ||
"typechain": "hardhat typechain", | ||
"format:forge": "forge fmt", | ||
"lint": "solhint 'contracts/**/*.sol'", | ||
"lint:fix": "solhint 'contracts/**/*.sol' --fix --noPrompt" | ||
}, | ||
"devDependencies": { | ||
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0", | ||
"@nomicfoundation/hardhat-ethers": "^3.0.0", | ||
"@nomicfoundation/hardhat-foundry": "^1.1.2", | ||
"@nomicfoundation/hardhat-ignition": "^0.15.5", | ||
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.0", | ||
"@nomicfoundation/hardhat-network-helpers": "^1.0.0", | ||
|
@@ -25,16 +35,19 @@ | |
"@typechain/hardhat": "^9.0.0", | ||
"@types/chai": "^4.2.0", | ||
"@types/mocha": ">=9.1.0", | ||
"@types/node": "^22.6.1", | ||
"chai": "^4.2.0", | ||
"ethers": "^6.4.0", | ||
"forge-std": "github:foundry-rs/forge-std#v1.9.2", | ||
"hardhat": "^2.22.11", | ||
"hardhat-gas-reporter": "^1.0.8", | ||
"prettier-plugin-solidity": "^1.4.1", | ||
"solhint": "^5.0.3", | ||
"solhint-plugin-prettier": "^0.1.0", | ||
"solidity-coverage": "^0.8.1", | ||
"ts-node": "^10.9.2", | ||
"typechain": "^8.3.0", | ||
"typescript": "^5.5.0" | ||
"typescript": "5.3" | ||
}, | ||
"dependencies": { | ||
"@openzeppelin/contracts": "^5.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@openzeppelin/=node_modules/@openzeppelin/ | ||
forge-std/=node_modules/forge-std/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.