diff --git a/.gitignore b/.gitignore index 85198aa..4250648 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,8 @@ # Compiler files +broadcast/ cache/ out/ - -# Ignores development broadcast logs -!/broadcast -/broadcast/*/31337/ -/broadcast/**/dry-run/ +zkout/ # Docs docs/ diff --git a/.gitmodules b/.gitmodules index 888d42d..690924b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "lib/forge-std"] path = lib/forge-std url = https://github.com/foundry-rs/forge-std +[submodule "lib/openzeppelin-contracts"] + path = lib/openzeppelin-contracts + url = https://github.com/OpenZeppelin/openzeppelin-contracts diff --git a/foundry.toml b/foundry.toml index 25b918f..6529fb8 100644 --- a/foundry.toml +++ b/foundry.toml @@ -3,4 +3,5 @@ src = "src" out = "out" libs = ["lib"] -# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options +[profile.default.zksync] +zksolc = "1.5.6" diff --git a/lib/openzeppelin-contracts b/lib/openzeppelin-contracts new file mode 160000 index 0000000..69c8def --- /dev/null +++ b/lib/openzeppelin-contracts @@ -0,0 +1 @@ +Subproject commit 69c8def5f222ff96f2b5beff05dfba996368aa79 diff --git a/remappings.txt b/remappings.txt new file mode 100644 index 0000000..6fdbafd --- /dev/null +++ b/remappings.txt @@ -0,0 +1 @@ +@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ diff --git a/script/ERC20.s.sol b/script/ERC20.s.sol new file mode 100644 index 0000000..3d6d68e --- /dev/null +++ b/script/ERC20.s.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import {Script, console} from "forge-std/Script.sol"; +import {TestnetERC20Token} from "../src/TestnetERC20Token.sol"; + +contract ERC20Script is Script { + TestnetERC20Token public dai; + TestnetERC20Token public wbtc; + + function setUp() public {} + + function run() public { + vm.startBroadcast(); + + dai = new TestnetERC20Token("DAI", "DAI", 18); + dai.mint(msg.sender, 10_000_000 * 10**18); + console.log("DAI address", address(dai)); + console.log("DAI minted", dai.balanceOf(msg.sender)); + + wbtc = new TestnetERC20Token("WBTC", "WBTC", 18); + wbtc.mint(msg.sender, 10_000_000 * 10**18); + console.log("WBTC address", address(wbtc)); + console.log("WBTC minted", wbtc.balanceOf(msg.sender)); + + vm.stopBroadcast(); + } +} diff --git a/src/Counter.sol b/src/Counter.sol index aded799..582041c 100644 --- a/src/Counter.sol +++ b/src/Counter.sol @@ -1,14 +1,24 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; -contract Counter { - uint256 public number; +import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; - function setNumber(uint256 newNumber) public { +contract Counter is Ownable { + uint256 private number; + + constructor() Ownable(msg.sender) {} + + function getNumber() public view returns (uint256) { + return number; + } + + function setNumber(uint256 newNumber) public onlyOwner { number = newNumber; } - function increment() public { + function increment() public onlyOwner { number++; } + + receive() external payable {} } diff --git a/src/TestnetERC20Token.sol b/src/TestnetERC20Token.sol new file mode 100644 index 0000000..4eaddf9 --- /dev/null +++ b/src/TestnetERC20Token.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.24; + +import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; + +contract TestnetERC20Token is ERC20 { + // add this to be excluded from coverage report + function test() internal virtual {} + + uint8 private _decimals; + + constructor(string memory name_, string memory symbol_, uint8 decimals_) ERC20(name_, symbol_) { + _decimals = decimals_; + } + + function mint(address _to, uint256 _amount) public returns (bool) { + _mint(_to, _amount); + return true; + } + + function decimals() public view override returns (uint8) { + return _decimals; + } +} diff --git a/test/Counter.t.sol b/test/Counter.t.sol deleted file mode 100644 index 54b724f..0000000 --- a/test/Counter.t.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Test, console} from "forge-std/Test.sol"; -import {Counter} from "../src/Counter.sol"; - -contract CounterTest is Test { - Counter public counter; - - function setUp() public { - counter = new Counter(); - counter.setNumber(0); - } - - function test_Increment() public { - counter.increment(); - assertEq(counter.number(), 1); - } - - function testFuzz_SetNumber(uint256 x) public { - counter.setNumber(x); - assertEq(counter.number(), x); - } -}