Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OZ 4.9.3 #18

Merged
merged 6 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Seed phrase used for mainnet deployments
MAINNET_MNEMONIC=
# Seed phrase used for testnet deployments
TESTNET_MNEMONIC=
# Mainnet Accounts (Mnemonic is checked first, then Private Key)
MAINNET_MNEMONIC=crouch maple syrup lunch syrup syrup syrup syrup syrup syrup syrup syrup syrup
MAINNET_PRIVATE_KEY=
# Testnet Account (Mnemonic is checked first, then Private Key)
TESTNET_MNEMONIC=crouch maple syrup lunch syrup syrup syrup syrup syrup syrup syrup syrup syrup
TESTNET_PRIVATE_KEY=

# EVM Explorer API Keys (For Verification)
ETHERSCAN_API_KEY=
Expand Down Expand Up @@ -33,4 +35,8 @@ TELOS_TESTNET_RPC_URL=
# Tenderly Simulation API
TENDERLY_USER=
TENDERLY_PROJECT=
TENDERLY_ACCESS_KEY=
TENDERLY_ACCESS_KEY=

## Development and Testing
DEVELOPMENT=true # Use this setting to console log outputs from the SDK
# DEVELOPMENT=false # Omit or set to false to disable console log outputs from the SDK
2 changes: 1 addition & 1 deletion contracts/Lock.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.23;
pragma solidity 0.8.19;

// Import this file to use console.log
// import "hardhat/console.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/LockUpgradeable.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.23;
pragma solidity 0.8.19;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

Expand Down
3 changes: 2 additions & 1 deletion contracts/external/OpenZeppelinImports.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
/// @dev Decided to adapt this contract with a constructor to set the initial owner. See contracts/proxy/ProxyAdmin.sol
// import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

/// @dev This contract enables hardhat to compile the builds for upgradeable deployments
Expand Down
87 changes: 87 additions & 0 deletions contracts/proxy/ProxyAdmin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.3) (proxy/transparent/ProxyAdmin.sol)

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

/**
* @dev This is an auxiliary contract meant to be assigned as the admin of a {TransparentUpgradeableProxy}. For an
* explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}.
* @notice Added constructor to set initial owner
*/
contract ProxyAdmin is Ownable {
/// @dev ADDED by DeFiFoFum to set initial owner
constructor(address _initialOwner) Ownable() {
_transferOwnership(_initialOwner);
}
Comment on lines +16 to +18

Check notice

Code scanning / Semgrep

Semgrep Finding: rules.solidity.performance.non-payable-constructor Note

Consider making costructor payable to save gas.

/**
* @dev Returns the current implementation of `proxy`.
*
* Requirements:
*
* - This contract must be the admin of `proxy`.
*/
function getProxyImplementation(ITransparentUpgradeableProxy proxy) public view virtual returns (address) {
// We need to manually run the static call since the getter cannot be flagged as view
// bytes4(keccak256("implementation()")) == 0x5c60da1b
(bool success, bytes memory returndata) = address(proxy).staticcall(hex"5c60da1b");
require(success);
return abi.decode(returndata, (address));
}

/**
* @dev Returns the current admin of `proxy`.
*
* Requirements:
*
* - This contract must be the admin of `proxy`.
*/
function getProxyAdmin(ITransparentUpgradeableProxy proxy) public view virtual returns (address) {
// We need to manually run the static call since the getter cannot be flagged as view
// bytes4(keccak256("admin()")) == 0xf851a440
(bool success, bytes memory returndata) = address(proxy).staticcall(hex"f851a440");
require(success);
return abi.decode(returndata, (address));
}

/**
* @dev Changes the admin of `proxy` to `newAdmin`.
*
* Requirements:
*
* - This contract must be the current admin of `proxy`.
*/
function changeProxyAdmin(ITransparentUpgradeableProxy proxy, address newAdmin) public virtual onlyOwner {
proxy.changeAdmin(newAdmin);
}

/**
* @dev Upgrades `proxy` to `implementation`. See {TransparentUpgradeableProxy-upgradeTo}.
*
* Requirements:
*
* - This contract must be the admin of `proxy`.
*/
function upgrade(ITransparentUpgradeableProxy proxy, address implementation) public virtual onlyOwner {
proxy.upgradeTo(implementation);
}

/**
* @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation. See
* {TransparentUpgradeableProxy-upgradeToAndCall}.
*
* Requirements:
*
* - This contract must be the admin of `proxy`.
*/
function upgradeAndCall(
ITransparentUpgradeableProxy proxy,
address implementation,
bytes memory data
) public payable virtual onlyOwner {
proxy.upgradeToAndCall{value: msg.value}(implementation, data);
}
}
60 changes: 29 additions & 31 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { HardhatUserConfig, task, types } from 'hardhat/config'
import { HardhatRuntimeEnvironment, HttpNetworkUserConfig, SolcUserConfig } from 'hardhat/types'
import {
HardhatRuntimeEnvironment,
HttpNetworkAccountsUserConfig,
HttpNetworkUserConfig,
SolcUserConfig,
} from 'hardhat/types'
import { TASK_TEST } from 'hardhat/builtin-tasks/task-names'
// Plugins
import '@nomicfoundation/hardhat-toolbox'
Expand Down Expand Up @@ -39,8 +44,15 @@ task(TASK_TEST, '🫶 Test Task')
.addOptionalParam('blockNumber', 'Optional block number to fork in case of running fork tests.', undefined, types.int)
.setAction(testRunner)

export const mainnetMnemonic = getEnv('MAINNET_MNEMONIC')
export const testnetMnemonic = getEnv('TESTNET_MNEMONIC')
const mainnetMnemonic = getEnv('MAINNET_MNEMONIC')
const mainnetAccounts: HttpNetworkAccountsUserConfig = mainnetMnemonic
? { mnemonic: mainnetMnemonic }
: [getEnv('MAINNET_PRIVATE_KEY')] // Fallback to private key

const testnetMnemonic = getEnv('TESTNET_MNEMONIC')
const testnetAccounts: HttpNetworkAccountsUserConfig = testnetMnemonic
? { mnemonic: testnetMnemonic }
: [getEnv('TESTNET_PRIVATE_KEY')] // Fallback to private key

type ExtendedNetworkOptions = {
getExplorerUrl: (address: string) => string
Expand All @@ -58,65 +70,49 @@ const networkConfig: ExtendedHardhatNetworkConfig = {
url: getEnv('MAINNET_RPC_URL') || 'https://eth.llamarpc.com',
getExplorerUrl: (address: string) => `https://etherscan.io/address/${address}`,
chainId: 1,
accounts: {
mnemonic: mainnetMnemonic,
},
accounts: mainnetAccounts,
},
goerli: {
url: getEnv('GOERLI_RPC_URL') || '',
getExplorerUrl: (address: string) => `https://goerli.etherscan.io/address/${address}`,
chainId: 5,
accounts: {
mnemonic: testnetMnemonic,
},
accounts: testnetAccounts,
},
arbitrum: {
url: getEnv('ARBITRUM_RPC_URL') || 'https://endpoints.omniatech.io/v1/arbitrum/one/public ',
getExplorerUrl: (address: string) => `https://arbiscan.io/address/${address}`,
chainId: 42161,
accounts: {
mnemonic: mainnetMnemonic,
},
accounts: mainnetAccounts,
},
arbitrumGoerli: {
url: getEnv('ARBITRUM_GOERLI_RPC_URL') || '',
getExplorerUrl: (address: string) => `https://testnet.arbiscan.io/address/${address}`,
chainId: 421613,
accounts: {
mnemonic: testnetMnemonic,
},
accounts: testnetAccounts,
},
bsc: {
url: getEnv('BSC_RPC_URL') || 'https://bsc-dataseed1.binance.org',
getExplorerUrl: (address: string) => `https://bscscan.com/address/${address}`,
chainId: 56,
accounts: {
mnemonic: mainnetMnemonic,
},
accounts: mainnetAccounts,
},
bscTestnet: {
url: getEnv('BSC_TESTNET_RPC_URL') || 'https://data-seed-prebsc-1-s1.binance.org:8545',
getExplorerUrl: (address: string) => `https://testnet.bscscan.com/address/${address}`,
chainId: 97,
accounts: {
mnemonic: testnetMnemonic,
},
accounts: testnetAccounts,
},
polygon: {
url: getEnv('POLYGON_RPC_URL') || 'https://matic-mainnet.chainstacklabs.com',
url: getEnv('POLYGON_RPC_URL') || 'https://polygon.llamarpc.com',
getExplorerUrl: (address: string) => `https://polygonscan.com/address/${address}`,
chainId: 137,
accounts: {
mnemonic: mainnetMnemonic,
},
accounts: mainnetAccounts,
},
polygonTestnet: {
url: getEnv('POLYGON_TESTNET_RPC_URL') || 'https://rpc-mumbai.maticvigil.com/',
getExplorerUrl: (address: string) => `https://mumbai.polygonscan.com/address/${address}`,
chainId: 80001,
accounts: {
mnemonic: testnetMnemonic,
},
accounts: testnetAccounts,
},
// Placeholder for the configuration below.
hardhat: {
Expand All @@ -128,6 +124,10 @@ export function getExplorerUrlForNetwork(networkName: Networks) {
return networkConfig[networkName]?.getExplorerUrl
}

export function convertToExplorerUrlForNetwork(networkName: Networks, address: string) {
return getExplorerUrlForNetwork(networkName)(address)
}

/**
* Configure compiler versions in ./solhint.config.js
*
Expand Down Expand Up @@ -174,9 +174,7 @@ const config: HardhatUserConfig = {
typechain: {
// outDir: 'src/types', // defaults to './typechain-types/'
target: 'ethers-v5',
externalArtifacts: [
// './artifacts-custom/**/*.json'
], // optional array of glob patterns with external artifacts to process (for example external libs from node_modules)
externalArtifacts: ['./artifacts-external/**/*.json'], // optional array of glob patterns with external artifacts to process (for example external libs from node_modules)
alwaysGenerateOverloads: false, // should overloads with full signatures like deposit(uint256) be generated always, even if there are no overloads?
dontOverrideCompile: false, // defaults to false
},
Expand Down
31 changes: 25 additions & 6 deletions hardhat/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,37 @@ const DEFAULTS = {
silent: false,
}

interface LoggerOptions {
actor?: string
color?: string
verbose?: boolean
silent?: boolean
}

export class Logger {
actor: string
color: string
verbose: boolean
silent: boolean

static setDefaults(silent: boolean, verbose: boolean): void {
DEFAULTS.silent = silent
DEFAULTS.verbose = verbose
}

constructor(actor = '', color = 'white') {
constructor({
actor = '',
color = 'white',
verbose = DEFAULTS.verbose,
silent = DEFAULTS.silent,
}: LoggerOptions = {}) {
this.actor = actor
this.color = color
this.verbose = verbose
this.silent = silent
}

setVerbose(verbose: boolean): void {
this.verbose = verbose
}

setSilent(silent: boolean): void {
this.silent = silent
}

info(msg: string): void {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@defifofum/hardhat-template",
"version": "3.3.1",
"version": "3.3.2",
"description": "Solidity Smart Contract development template using modern Web3 frameworks/tools including Hardhat, Typechain, Foundry and more.",
"main": "./dist/index.js",
"files": [
Expand Down Expand Up @@ -98,8 +98,8 @@
"typescript": ">=4.5.0"
},
"dependencies": {
"@openzeppelin/contracts": "^5.0.0",
"@openzeppelin/contracts-upgradeable": "^5.0.0",
"@openzeppelin/contracts": "4.9.3",
"@openzeppelin/contracts-upgradeable": "4.9.3",
"@openzeppelin/hardhat-upgrades": "^1.22.1"
}
}
Loading
Loading