Skip to content

Commit

Permalink
feat: add hardhat exposed plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
emretepedev committed Jan 1, 2025
1 parent 1628512 commit 88606fa
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 3 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ artifacts
bin
cache
contracts
contracts-exposed
docs
node_modules
soldata
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ docs
node_modules
soldata
blockscout
contracts-exposed

gasReporterOutput.json

Expand Down
1 change: 1 addition & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ node_modules
scripts
soldata
blockscout
contracts-exposed

coverage*
*.js
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"**/artifacts/*/**": true,
"**/cache/*/**": true,
"**/coverage/*/**": true,
"**/soldata/*/**": true
"**/soldata/*/**": true,
"**/blockscout/*/**": true
},
"files.exclude": {
"blockscout": true
},
"files.saveConflictResolution": "overwriteFileOnDisk",
"editor.bracketPairColorization.enabled": true,
Expand Down
34 changes: 34 additions & 0 deletions contracts-exposed/Counters.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity >=0.6.0;

import "../contracts/Counters.sol";

contract $Counters {
bytes32 public constant __hh_exposed_bytecode_marker = "hardhat-exposed";

constructor() payable {
}

function $current(Counters.Counter counter) external pure returns (uint256 ret0) {
(ret0) = Counters.current(counter);
}

function $increment(Counters.Counter counter) external pure returns (Counters.Counter ret0) {
(ret0) = Counters.increment(counter);
}

function $decrement(Counters.Counter counter) external pure returns (Counters.Counter ret0) {
(ret0) = Counters.decrement(counter);
}

function $toUint256(Counters.Counter counter) external pure returns (uint256 ret0) {
(ret0) = Counters.toUint256(counter);
}

function $toCounter(uint256 counter) external pure returns (Counters.Counter ret0) {
(ret0) = Counters.toCounter(counter);
}

receive() external payable {}
}
59 changes: 59 additions & 0 deletions contracts-exposed/FooToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity >=0.6.0;

import "../contracts/FooToken.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/Context.sol";

contract $FooToken is FooToken {
bytes32 public constant __hh_exposed_bytecode_marker = "hardhat-exposed";

constructor(uint256 initialSupply) FooToken(initialSupply) payable {
}

function $_transfer(address from,address to,uint256 value) external {
super._transfer(from,to,value);
}

function $_update(address from,address to,uint256 value) external {
super._update(from,to,value);
}

function $_mint(address account,uint256 value) external {
super._mint(account,value);
}

function $_burn(address account,uint256 value) external {
super._burn(account,value);
}

function $_approve(address owner,address spender,uint256 value) external {
super._approve(owner,spender,value);
}

function $_approve(address owner,address spender,uint256 value,bool emitEvent) external {
super._approve(owner,spender,value,emitEvent);
}

function $_spendAllowance(address owner,address spender,uint256 value) external {
super._spendAllowance(owner,spender,value);
}

function $_msgSender() external view returns (address ret0) {
(ret0) = super._msgSender();
}

function $_msgData() external view returns (bytes memory ret0) {
(ret0) = super._msgData();
}

function $_contextSuffixLength() external view returns (uint256 ret0) {
(ret0) = super._contextSuffixLength();
}

receive() external payable {}
}
44 changes: 44 additions & 0 deletions contracts-exposed/Timers.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity >=0.6.0;

import "../contracts/Timers.sol";

contract $Timers {
bytes32 public constant __hh_exposed_bytecode_marker = "hardhat-exposed";

mapping(uint256 => Timers.BlockNumber) internal $v_Timers_BlockNumber;

constructor() payable {
}

function $get(Timers.BlockNumber calldata timer) external pure returns (uint256 ret0) {
(ret0) = Timers.get(timer);
}

function $set(uint256 timer,uint256 timestamp) external payable {
Timers.set($v_Timers_BlockNumber[timer],timestamp);
}

function $reset(uint256 timer) external payable {
Timers.reset($v_Timers_BlockNumber[timer]);
}

function $isUnset(Timers.BlockNumber calldata timer) external pure returns (bool ret0) {
(ret0) = Timers.isUnset(timer);
}

function $isStarted(Timers.BlockNumber calldata timer) external pure returns (bool ret0) {
(ret0) = Timers.isStarted(timer);
}

function $isPending(Timers.BlockNumber calldata timer) external view returns (bool ret0) {
(ret0) = Timers.isPending(timer);
}

function $isExpired(Timers.BlockNumber calldata timer) external view returns (bool ret0) {
(ret0) = Timers.isExpired(timer);
}

receive() external payable {}
}
29 changes: 29 additions & 0 deletions contracts-exposed/Workshop.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity >=0.6.0;

import "../contracts/Workshop.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../contracts/Counters.sol";

contract $Workshop is Workshop {
bytes32 public constant __hh_exposed_bytecode_marker = "hardhat-exposed";

constructor(address tokenAddress) Workshop(tokenAddress) payable {
}

function $_msgSender() external view returns (address ret0) {
(ret0) = super._msgSender();
}

function $_msgData() external view returns (bytes memory ret0) {
(ret0) = super._msgData();
}

function $_contextSuffixLength() external view returns (uint256 ret0) {
(ret0) = super._contextSuffixLength();
}

receive() external payable {}
}
7 changes: 7 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'hardhat-finder';
import 'hardhat-storage-vault';
import 'hardhat-contract-sizer';
import 'hardhat-tracer';
import 'hardhat-exposed';
import 'hardhat-exposed/dist/type-extensions';
import './tasks';

dotenvConfig();
Expand Down Expand Up @@ -103,6 +105,11 @@ const config: HardhatUserConfig = {
token: 'ETH',
currency: 'USD',
},
exposed: {
include: ['**/*.sol'],
outDir: 'contracts-exposed',
prefix: '$',
},
networks: {
hardhat: {
allowUnlimitedContractSize:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"eslint-plugin-promise": "^6.6.0",
"hardhat": "2.22.17",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-exposed": "^0.3.15",
"hardhat-finder": "^3.1.2",
"hardhat-gas-reporter": "^2.2.2",
"hardhat-storage-vault": "^1.3.0",
Expand Down
12 changes: 11 additions & 1 deletion test/FooToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('FooToken', () => {
const [deployer, ...walletClients] = await viem.getWalletClients();
const publicClient = await viem.getPublicClient();

const fooToken = await viem.deployContract('FooToken', fooTokenArgs);
const fooToken = await viem.deployContract('$FooToken', fooTokenArgs);

return {
fooToken,
Expand Down Expand Up @@ -47,6 +47,16 @@ describe('FooToken', () => {
});
});

describe('Exposed Functions', () => {
it('Should return msg.sender', async function () {
const { fooToken, deployer } = await loadFixture(deployFixture);

expect(await fooToken.read.$_msgSender()).to.match(
new RegExp(deployer.account.address, 'i')
);
});
});

it('the token name should be correct', async () => {
const { fooToken } = await loadFixture(deployFixture);

Expand Down
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4308,6 +4308,14 @@ hardhat-contract-sizer@^2.10.0:
cli-table3 "^0.6.0"
strip-ansi "^6.0.0"

hardhat-exposed@^0.3.15:
version "0.3.15"
resolved "https://registry.yarnpkg.com/hardhat-exposed/-/hardhat-exposed-0.3.15.tgz#8096b5b65ac9059e126f2413f9415e2ec0eb458b"
integrity sha512-jqxErCnSWGYf4vAkLmh3H3u+IuLuCLw/EVeV13z1JKJMJAd/iO+G283n8T124S/Q2BF/BoA2zgzYAlqXgNyKew==
dependencies:
micromatch "^4.0.4"
solidity-ast "^0.4.52"

hardhat-finder@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/hardhat-finder/-/hardhat-finder-3.1.2.tgz#efc50e652aac2842f86dc916402a9e85158aa481"
Expand Down Expand Up @@ -6809,7 +6817,7 @@ solhint@^5.0.3:
optionalDependencies:
prettier "^2.8.3"

solidity-ast@^0.4.38, solidity-ast@^0.4.51:
solidity-ast@^0.4.38, solidity-ast@^0.4.51, solidity-ast@^0.4.52:
version "0.4.59"
resolved "https://registry.yarnpkg.com/solidity-ast/-/solidity-ast-0.4.59.tgz#290a2815aef70a61092591ab3e991da080ae5931"
integrity sha512-I+CX0wrYUN9jDfYtcgWSe+OAowaXy8/1YQy7NS4ni5IBDmIYBq7ZzaP/7QqouLjzZapmQtvGLqCaYgoUWqBo5g==
Expand Down

0 comments on commit 88606fa

Please sign in to comment.