简体   繁体   English

使用 deployProxy 迁移 open-zeppelin 代理时,松露配置中的优化器设置不起作用

[英]Optimiser settings in truffle config is not working while migrating open-zeppelin proxy using deployProxy

I have added the compiler options in truffle-config.js -我在 truffle-config.js 中添加了编译器选项 -

compilers: {
    solc: {
      version: "0.8.16",
      settings: {
        optimizer: {
          enabled: false,
          runs: 200
        }
      }
    }
  }

I am deploying an upgradable erc20 contract using truffle.我正在使用 truffle 部署可升级的 erc20 合约。 To do that I am using OpenZeppelin truffle suite.为此,我正在使用 OpenZeppelin 松露套件。

truffle console --network testnet
truffle(testnet)> compile --all
truffle(testnet)> migrate

for migrate, I have 1_deploy_contracts.js as below对于迁移,我有 1_deploy_contracts.js 如下

const { deployProxy } = require('@openzeppelin/truffle-upgrades');
const PolarizeV1 = artifacts.require('Erc20Token');

module.exports = async function (deployer) {
    const instance = await deployProxy(Erc20Token, [], { deployer, initializer: 'initialize' });
}

This deploys 3 contracts for me:这为我部署了 3 个合约:

Erc20Token
proxyAdmin
TransparentUpgradeableProxy

Now, The proxy (TransparentUpgradeableProxy) is verified automatically on the testnet with optimiser shows as "Yes with 200"现在,代理(TransparentUpgradeableProxy)在测试网上自动验证,优化器显示为“Yes with 200”

在此处输入图像描述

Now my aim is to deploy this proxy with NO optimisations since the life cycle of the contract is suppose to last indefinitely.现在我的目标是部署这个代理而不进行任何优化,因为合同的生命周期应该无限期地持续下去。

Then I checked the verified code on bsc scan testnet.然后我在 bsc scan testnet 上检查了经过验证的代码。 I found this:我找到了这个: 在此处输入图像描述 So I traced back the code where open-zeppelin library adds this settings which turned out to be in所以我追溯了 open-zeppelin 库添加这个设置的代码,结果是

node_modules/@openzeppelin/upgrades-core/artifacts/build-info.json

There I manually edited the build-info.json and set enabled: false .在那里我手动编辑了 build-info.json 并设置enabled: false

在此处输入图像描述

I could also see the same solc compiler version in build-info.json which matches with the verified proxy contract on testnet, you can see that in first image.我还可以在 build-info.json 中看到相同的 solc 编译器版本,它与 testnet 上经过验证的代理合约相匹配,您可以在第一张图片中看到。

"solcLongVersion": "0.8.2+commit.661d1103",

Still the problem persists.问题仍然存在。 Do let me know or point to any relevant resources请让我知道或指向任何相关资源

UPDATE:更新:

I tried with hardhat as well, and the result is same.我也尝试过使用安全帽,结果是一样的。 On both places I'm using deployProxy module of open-Zeppelin.在这两个地方我都在使用 open-Zeppelin 的 deployProxy 模块。

So either, the problem is with deployProxy.因此,问题出在 deployProxy 上。 Please help.请帮忙。

I was able to solve the issue by deploying each of the contract individually and verifying them individually by flattening the code using truffle-flattener.我能够通过单独部署每个合约并通过使用 truffle-flattener 扁平化代码来单独验证它们来解决这个问题。 Make sure after flattening, remove all but top one // SPDX-License-Identifier: MIT licenses from the flatten code.确保在展平后,从展平代码中删除除顶部一个以外的所有 // SPDX-License-Identifier: MIT 许可证。

And for TransparentUpgradeableProxy there are three input to constructor, while verifying make sure to find the abi code for arguments by using https://abi.hashex.org/ Also use this this link to find proper bytecode for your constructor arguments.对于TransparentUpgradeableProxy,构造函数有三个输入,在验证时,请确保使用https://abi.hashex.org/找到 arguments 的 abi 代码,还可以使用此链接为您的构造函数 ZDBC11CAA5BDA8E7F7D7E 找到正确的字节码。 Happy Coding.快乐编码。

deploy.js部署.js

const { ethers } = require("hardhat");
async function main() {
  const Erc20 = await ethers.getContractFactory("erc20");
  const Admin = await ethers.getContractFactory("ProxyAdmin");
  const Proxy = await ethers.getContractFactory("TransparentUpgradeableProxy");

  const erc20 = await Erc20.deploy();
  const admin = await Admin.deploy();
  const iface = new ethers.utils.Interface(["function initialize()"]);
  const encodedFunctionData = iface.encodeFunctionData(
        "initialize",
        []
    )
  const proxy = await Proxy.deploy(erc20.address, admin.address, encodedFunctionData, { gasLimit: 2000000 });
  console.log(`Address of proxy: ${proxy.address}`);

  }
  
  main()
    .then(() => process.exit(0))
    .catch(error => {
      console.error(error);
      process.exit(1);
    });

I'll keep the bounty if we can do it using the truffle or hardhat plugins deployProxy如果我们可以使用 truffle 或安全帽插件 deployProxy,我会保留赏金

not sure about truffle but are you the following setting with hardhat it will work.不确定松露,但您是否使用安全帽进行以下设置,它会起作用。 I was stuck once with same problem after 2 days got to know that you gotta put it inside the compiler indent.在 2 天后我被同样的问题困住了,我知道你必须把它放在编译器缩进中。 If it helps dun forget to accept the answer.如果有帮助,请不要忘记接受答案。

solidity: {
    compilers: [
      {
        version: "0.8.13",
        settings: {
          optimizer: {
            enabled: true,
            runs: 200,
          },
        },
      },
    ],
  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM