Before using unsafeAllowLinkedLibraries hardhat-deploy my deploy script looked like this:
require("@nomiclabs/hardhat-web3");
const { HardhatRuntimeEnvironment } = require('hardhat/types');
async function main() {
const accounts = await ethers.getSigners()
const LibExchangeAuctionFactory = await ethers.getContractFactory("LibExchangeAuction");
const libExchangeAuction = await LibExchangeAuctionFactory.deploy();
const ExchangeV2 = await ethers.getContractFactory("ExchangeV2", {
libraries: {
LibExchangeAuction: libExchangeAuction.address
}
});
const TransferProxy = await ethers.getContractFactory('TransferProxy');
const ERC20TransferProxy = await ethers.getContractFactory('ERC20TransferProxy');
//deploy and initialize TransferProxy
transferProxyDeployed = await TransferProxy.deploy();
await transferProxyDeployed.__TransferProxy_init();
//deploy and initialize ERC20TransferProxy
erc20TransferProxyDeployed = await ERC20TransferProxy.deploy();
await erc20TransferProxyDeployed.__ERC20TransferProxy_init();
const transferProxy = transferProxyDeployed.address
const erc20TransferProxy = erc20TransferProxyDeployed.address
const exchangeFeeWallet = accounts[0].address
const adminRecoveryAddress = accounts[0].address
const feesBP = 200
const instance = await upgrades.deployProxy(
ExchangeV2,
[transferProxy, erc20TransferProxy, feesBP, exchangeFeeWallet, adminRecoveryAddress],
{ initializer: '__ExchangeV2_init', unsafeAllowLinkedLibraries: true }
);
//add ExchangeV2 address to the the allowed operators of transferProxy & erc20TransferProxy
await transferProxyDeployed.addOperator(instance.address)
await erc20TransferProxyDeployed.addOperator(instance.address)
console.log('ExchangeV2 Deployed', instance.address);
console.log('transferProxy: ', transferProxy)
console.log('erc20TransferProxy: ', erc20TransferProxy)
console.log('exchangeFeeWallet: ', exchangeFeeWallet)
console.log('adminRecoveryAddress: ', adminRecoveryAddress)
console.log('libExchangeAuction deployed: ', libExchangeAuction.address);
console.log('fees value: ', feesBP / 100 + '%')
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
and contracts were deploying fine.
Now using hardhat-deploy (for several reasons) and getting a cryptic error about my new deploy script:
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {DeployFunction} from 'hardhat-deploy/types';
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {deployments, getNamedAccounts} = hre;
const {deploy} = deployments;
const {deployer} = await getNamedAccounts();
const TransferProxy = await hre.deployments.get('TransferProxy');
const ERC20TransferProxy = await hre.deployments.get('ERC20TransferProxy');
const feesBP = 200
await deploy('ExchangeV2', {
from: deployer,
proxy: {
owner: deployer,
proxyContract: 'OpenZeppelinTransparentProxy',
execute: {
init: {
methodName: '__ExchangeV2_init',
args: [TransferProxy.address, ERC20TransferProxy.address, feesBP, deployer, deployer],
},
},
},
log: true,
});
console.log('transferProxy: ', TransferProxy.address)
console.log('erc20TransferProxy: ', ERC20TransferProxy.address)
console.log('exchangeFeeWallet: ', deployer)
console.log('adminRecoveryAddress: ', deployer)
console.log('fees value: ', feesBP / 100 + '%')
};
export default func;
func.tags = ['ExchangeV2'];
module.exports.dependencies = ['TransferProxy', 'ERC20TransferProxy']; // this ensure the Token script above is executed first, so `deployments.get('Token')` succeeds
Double Checked the arguments and try to remove parts of the proxy part:
proxy: {
owner: deployer,
proxyContract: 'OpenZeppelinTransparentProxy',
execute: {
init: {
methodName: '__ExchangeV2_init',
args: [TransferProxy.address, ERC20TransferProxy.address, feesBP, deployer, deployer],
},
},
still getting the same error.
Error
Nothing to compile
No need to generate any newer typings.
deploying "TransferProxy" (tx: 0x7742d91aea442e05ad5124fb7e2d022b99750870fb9e6f3851c07de2aecb7c10)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 580020 gas
executing TransferProxy.__TransferProxy_init (tx: 0xe4a4a0ab3f37a5a897b33ba6725b64dd7c69fff6d7d56fc27d84eb43c8a56477) ...: performed with 68699 gas
deploying "ERC20TransferProxy" (tx: 0x000e66d2fb67a6dd8e2f2b5de9dddddbaaa1fd7dba0f45396bc578556e489350)...: deployed at 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 with 508719 gas
executing ERC20TransferProxy.__ERC20TransferProxy_init (tx: 0x302340130838bd8e0ca5ad4d8c902a291322335f6fd5de5abef9553dea797c73) ...: performed with 68721 gas
deploying "DefaultProxyAdmin" (tx: 0x94827f0fbfd094ba4bafc34efda34a27de24c55ed897d2df0a54d90dbecd6157)...: deployed at 0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9 with 671461 gas
An unexpected error occurred:
Error: ERROR processing /Users/selimerunkut/dev_freelance/GhostMarketContractAvalancheExchange_wighawag/deploy/003_deploy_auction.ts:
Error: invalid bytecode (argument="bytecode", value="0x608060405234801561001057600080fd5b50615ea380620000216000396000f3fe608060405
...VERY_LONG_BYTE_CODE...
21220e386586237d2001616b2acb69feee8164e5579f4864e65d2229a760d0dfc38f464736f6c63430008040033", code=INVALID_ARGUMENT, version=contracts/5.4.1)
at Logger.makeError (/Users/selimerunkut/dev_freelance/GhostMarketContractAvalancheExchange_wighawag/node_modules/@ethersproject/logger/src.ts/index.ts:225:28)
at Logger.throwError (/Users/selimerunkut/dev_freelance/GhostMarketContractAvalancheExchange_wighawag/node_modules/@ethersproject/logger/src.ts/index.ts:237:20)
at Logger.throwArgumentError (/Users/selimerunkut/dev_freelance/GhostMarketContractAvalancheExchange_wighawag/node_modules/@ethersproject/logger/src.ts/index.ts:241:21)
at new ContractFactory (/Users/selimerunkut/dev_freelance/GhostMarketContractAvalancheExchange_wighawag/node_modules/@ethersproject/contracts/src.ts/index.ts:1136:20)
at _deploy (/Users/selimerunkut/dev_freelance/GhostMarketContractAvalancheExchange_wighawag/node_modules/hardhat-deploy/src/helpers.ts:530:21)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at runNextTicks (internal/process/task_queues.js:64:3)
at listOnTimeout (internal/timers.js:526:9)
at processTimers (internal/timers.js:500:7)
at async _deployOne (/Users/selimerunkut/dev_freelance/GhostMarketContractAvalancheExchange_wighawag/node_modules/hardhat-deploy/src/helpers.ts:895:16)
at DeploymentsManager.executeDeployScripts (/Users/selimerunkut/dev_freelance/GhostMarketContractAvalancheExchange_wighawag/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1108:19)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at runNextTicks (internal/process/task_queues.js:64:3)
at listOnTimeout (internal/timers.js:526:9)
at processTimers (internal/timers.js:500:7)
at async DeploymentsManager.runDeploy (/Users/selimerunkut/dev_freelance/GhostMarketContractAvalancheExchange_wighawag/node_modules/hardhat-deploy/src/DeploymentsManager.ts:938:5)
at async Environment._runTaskDefinition (/Users/selimerunkut/dev_freelance/GhostMarketContractAvalancheExchange_wighawag/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
at async Environment.run (/Users/selimerunkut/dev_freelance/GhostMarketContractAvalancheExchange_wighawag/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14)
at async SimpleTaskDefinition.action (/Users/selimerunkut/dev_freelance/GhostMarketContractAvalancheExchange_wighawag/node_modules/hardhat-deploy/src/index.ts:546:32)
at async Environment._runTaskDefinition (/Users/selimerunkut/dev_freelance/GhostMarketContractAvalancheExchange_wighawag/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
error Command failed with exit code 1.
Code to reproduce
Environment
see here: https://github.com/selimerunkut/find_bugs/blob/main/package.json