openzeppelin-upgrades icon indicating copy to clipboard operation
openzeppelin-upgrades copied to clipboard

Override transaction options (from, gas, gasPrice) in create and upgrade proxy

Open spalladino opened this issue 6 years ago • 32 comments

Add from, gas, and gasPrice as optional values to the options parameter of createProxy and upgradeProxy, so the user can change the defaults for a specific transaction. For example:

await upgradeProxy(existing.address, BoxV2, { deployer, from: '0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0', gasPrice: 10e9, gas: 1e6 });

(found in truffle plugin, unsure if applies to builder as well)

spalladino avatar Jul 31 '20 20:07 spalladino

We potentially want these settings to be granular since each function can correspond to multiple transactions.

frangio avatar Aug 19 '20 14:08 frangio

We potentially want these settings to be granular since each function can correspond to multiple transactions.

@frangio Agree, but at least the from option would be great to support.

pedrobranco avatar Nov 03 '20 14:11 pedrobranco

Note that the plugin will use the signer that comes attached to the ImplFactory in the Hardhat plugin, and I believe it also uses the same from default that was set for the contract class passed in the Truffle plugin.

This means that you can customize from by setting it in the contract abstraction you give the plugin (e.g. a MyContractV2 class).

frangio avatar Dec 03 '21 21:12 frangio

I had a nightmare deploying to mainnet using deployProxy. I was unable to set maxPriorityFeePerGas which made me wait 36 hours to get the implementation deployed. After that I resumed the process, got the Admin contract deployed quickly, but then got stuck on Proxy deployment for another 2 days. Overriding maxPriorityFeePerGas and maxFeePerGas is a must. Ideally we should be able to resume the process and bump the fees.

blabno avatar Dec 28 '21 13:12 blabno

Its totally a bad idea to not allow configuring the max base fee when deploying.... Not sure if i've seen any workaround for now, is there any to achieve cheap deployment of many contracts?

ItsShadowl avatar Feb 02 '22 21:02 ItsShadowl

Here is a possible workaround for ethers.js:

const FEE_DATA = {
    maxFeePerGas:         ethers.utils.parseUnits('100', 'gwei'),
    maxPriorityFeePerGas: ethers.utils.parseUnits('5',   'gwei'),
};

// Wrap the provider so we can override fee data.
const provider = new ethers.providers.FallbackProvider([ethers.provider], 1);
provider.getFeeData = async () => FEE_DATA;

// Create the signer for the mnemonic, connected to the provider with hardcoded fee data
const signer = ethers.Wallet.fromMnemonic(/* mnemonic */).connect(provider);

// Get the contract factory connected to signer so it uses hardcoded fee data
const MyContract = await ethers.getContractFactory('MyContract', signer);

// Should now use hardcoded fee data for deployments
await upgrades.deployProxy(MyContract);

frangio avatar Feb 02 '22 22:02 frangio

I'm trying the above @frangio still the same result. everything works fine on the mainnet (even without the workaround above), but the same configuration fails on testnet (harmony)

gitbaq avatar Feb 09 '22 12:02 gitbaq

@gitbaq Please share more information about the error.

frangio avatar Feb 09 '22 15:02 frangio

When the gas price is set to >15 mins slow, it times out with : timed out waiting for transaction "txHash" error, any solution to that or should just revert to suggested ethers.js gas price? Not sure if the transaction can continue without manual intervention

ItsShadowl avatar Feb 14 '22 01:02 ItsShadowl

@noobshow Note that if it times out, you can just run the deployProxy function again and it will continue waiting for the transaction to be confirmed (you can also use the timeout and pollingInterval options to change how long it waits). Does that help, or are you more looking for a way to replace the transaction with a different gas price?

ericglau avatar Feb 14 '22 21:02 ericglau

There are lots of deployments set up to go after each other. I was hoping it was possible for the deployment of implementation and the proxy to happen without waiting for the other or maybe a replacement transaction with a higher gas fee, since the script I use updates according to some gas prices recommendations

ItsShadowl avatar Feb 15 '22 09:02 ItsShadowl

the deployment of implementation and the proxy to happen without waiting for the other

We don't do this because if the implementation deployment fails, then the proxy deployment will fail as well and it will cost a lot of gas for no reason.

frangio avatar Feb 17 '22 22:02 frangio

@frangio I am trying to deploy the contract at https://github.com/superpowerlabs/synr-seed/blob/main/contracts/SeedFarm.sol All tests pass and I can deploy it without issues on localhost. I can also deploy the other upgradeable contracts without issues on all chains. Still, I cannot deploy SeedFarm because hardhat returns a gas estimation issue. The problem is that it seems that there is no way to set up a limit manually. Any suggestion for a work-around? I have a deadline coming soon and if I do not find a solution, I have to rewrite it and use a different approach to upgradeability. Thanks!

sullof avatar Apr 10 '22 18:04 sullof

BTW, I didn't try on main net, yet. It fails on Ropsten, Mumbai and BSC Testnet.

sullof avatar Apr 10 '22 18:04 sullof

There is a workaround above: https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/85#issuecomment-1028435049

frangio avatar Apr 11 '22 13:04 frangio

Still no solution ?

I am trying to simply do a npx hardhat test of my proxy - upgradable contract, but not working:

image

image

migbash avatar May 21 '22 13:05 migbash

Hello everyone, I am having problem with deployProxy function, the script worked as well for goerli and rinkeby (without using the workaround above) but on mumbai I am not able to deploy the contract.

These are the library used:

"@nomiclabs/hardhat-ethers": "^2.0.6"
 "@openzeppelin/hardhat-upgrades": "^1.18.1"

This is the script:

const FEE_DATA = {
   maxFeePerGas:         ethers.utils.parseUnits('100', 'gwei'),
   maxPriorityFeePerGas: ethers.utils.parseUnits('5',   'gwei'),
 };

 // Wrap the provider so we can override fee data.
 const provider = new ethers.providers.FallbackProvider([ethers.provider], 1);
 provider.getFeeData = async () => FEE_DATA;

 // Create the signer for the mnemonic, connected to the provider with hardcoded fee data
 const signer = new ethers.Wallet(config.privateKey).connect(provider)
 // const [signer] = await ethers.getSigners();

 console.log("Deploying contracts with the account:", signer.address);

 console.log("#################################")
 console.log("STARTING DEPLOY ACCESS TOKEN CONTRACTS")
 const AccessTokenManager = await ethers.getContractFactory("AccessTokenManager", signer)
 const accessTokenManager = await upgrades.deployProxy(AccessTokenManager,{ initializer: 'initialize', kind: 'uups'})

Can someone please tell me was is wrong here?

Thanks in advance.

SalvatoreCataniaVS avatar Jun 10 '22 10:06 SalvatoreCataniaVS

@SalvatoreCataniaVS Please post this question in the OpenZeppelin Forum and include the error message you are seeing.

frangio avatar Jun 15 '22 15:06 frangio

Is from supported yet for deployProxy() in hardhat-upgrades?

sebastiantf avatar Oct 20 '22 06:10 sebastiantf

Here is a possible workaround for ethers.js:

const FEE_DATA = {
    maxFeePerGas:         ethers.utils.parseUnits('100', 'gwei'),
    maxPriorityFeePerGas: ethers.utils.parseUnits('5',   'gwei'),
};

// Wrap the provider so we can override fee data.
const provider = new ethers.providers.FallbackProvider([ethers.provider], 1);
provider.getFeeData = async () => FEE_DATA;

// Create the signer for the mnemonic, connected to the provider with hardcoded fee data
const signer = ethers.Wallet.fromMnemonic(/* mnemonic */).connect(provider);

// Get the contract factory connected to signer so it uses hardcoded fee data
const MyContract = await ethers.getContractFactory('MyContract', signer);

// Should now use hardcoded fee data for deployments
await upgrades.deployProxy(MyContract);

Maybe extending the Hardhat HRE following this example of the docs with the modifications indicated by @frangio :

  • In hardhat.config.js:

extendEnvironment((hre) => { const Web3 = require("web3"); hre.Web3 = Web3;

// hre.network.provider is an EIP1193-compatible provider. hre.web3 = new Web3(hre.network.provider); });

albatros-github avatar Oct 27 '22 05:10 albatros-github