-
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.
- Loading branch information
1 parent
4e45b11
commit 9fc3df2
Showing
13 changed files
with
8,046 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
node_modules | ||
.env | ||
|
||
# Hardhat files | ||
/cache | ||
/artifacts | ||
|
||
# TypeChain files | ||
/typechain | ||
/typechain-types | ||
|
||
# solidity-coverage files | ||
/coverage | ||
/coverage.json | ||
|
||
# Hardhat Ignition default folder for deployments against a local node | ||
ignition/deployments/chain-31337 |
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,29 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import { IDiamond } from "./interfaces/IDiamond.sol"; | ||
|
||
contract Diamond { | ||
// A mapping to store which facet handles which function selectors | ||
mapping(bytes4 => address) public facets; | ||
|
||
event FacetUpdated(address indexed facet, bytes4[] selectors); | ||
|
||
// Function to add or replace a facet and its function selectors | ||
function updateFacet(address _facet, bytes4[] calldata _selectors) external { | ||
for (uint256 i = 0; i < _selectors.length; i++) { | ||
facets[_selectors[i]] = _facet; | ||
} | ||
emit FacetUpdated(_facet, _selectors); | ||
} | ||
|
||
// Thisi fallback function is used to delegate calls to the appropriate facet | ||
fallback() external payable { | ||
address facet = facets[msg.sig]; | ||
require(facet != address(0), "Diamond: Function does not exist"); | ||
(bool success, ) = facet.delegatecall(msg.data); | ||
require(success, "Diamond: Delegatecall failed"); | ||
} | ||
|
||
receive() external payable {} | ||
} |
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,34 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.24; | ||
|
||
// Uncomment this line to use console.log | ||
// import "hardhat/console.sol"; | ||
|
||
contract Lock { | ||
uint public unlockTime; | ||
address payable public owner; | ||
|
||
event Withdrawal(uint amount, uint when); | ||
|
||
constructor(uint _unlockTime) payable { | ||
require( | ||
block.timestamp < _unlockTime, | ||
"Unlock time should be in the future" | ||
); | ||
|
||
unlockTime = _unlockTime; | ||
owner = payable(msg.sender); | ||
} | ||
|
||
function withdraw() public { | ||
// 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); | ||
} | ||
} |
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,26 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import { IOwnershipFacet } from "../interfaces/IOwnershipFacet.sol"; | ||
|
||
contract OwnershipFacet is IOwnershipFacet { | ||
address public owner; | ||
|
||
modifier onlyOwner() { | ||
require(msg.sender == owner, "Not the owner"); | ||
_; | ||
} | ||
|
||
constructor() { | ||
owner = msg.sender; | ||
} | ||
|
||
function transferOwnership(address _newOwner) external override onlyOwner { | ||
require(_newOwner != address(0), "Invalid new owner"); | ||
owner = _newOwner; | ||
} | ||
|
||
function getOwner() external view override returns (address) { | ||
return owner; | ||
} | ||
} |
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.0; | ||
|
||
import { ITokenFacet } from "../interfaces/ITokenFacet.sol"; | ||
|
||
contract TokenFacet is ITokenFacet { | ||
mapping(address => uint256) public balances; | ||
|
||
function mint(address _to, uint256 _amount) external override { | ||
balances[_to] += _amount; | ||
} | ||
|
||
function transfer(address _to, uint256 _amount) external override { | ||
require(balances[msg.sender] >= _amount, "Not enough balance"); | ||
balances[msg.sender] -= _amount; | ||
balances[_to] += _amount; | ||
} | ||
|
||
function balanceOf(address _account) external view override returns (uint256) { | ||
return balances[_account]; | ||
} | ||
} |
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 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
interface IDiamond { | ||
function updateFacet(address _facet, bytes4[] calldata _selectors) external; | ||
} |
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,7 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
interface IOwnershipFacet { | ||
function transferOwnership(address _newOwner) external; | ||
function getOwner() external view returns (address); | ||
} |
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,8 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
interface ITokenFacet { | ||
function mint(address _to, uint256 _amount) external; | ||
function transfer(address _to, uint256 _amount) external; | ||
function balanceOf(address _account) external view returns (uint256); | ||
} |
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 @@ | ||
require("@nomicfoundation/hardhat-toolbox"); | ||
|
||
/** @type import('hardhat/config').HardhatUserConfig */ | ||
module.exports = { | ||
solidity: "0.8.24", | ||
}; |
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,15 @@ | ||
const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules"); | ||
|
||
const JAN_1ST_2030 = 1893456000; | ||
const ONE_GWEI = 1_000_000_000n; | ||
|
||
module.exports = buildModule("LockModule", (m) => { | ||
const unlockTime = m.getParameter("unlockTime", JAN_1ST_2030); | ||
const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI); | ||
|
||
const lock = m.contract("Lock", [unlockTime], { | ||
value: lockedAmount, | ||
}); | ||
|
||
return { lock }; | ||
}); |
Oops, something went wrong.