diff --git a/.changeset/afraid-hotels-bathe.md b/.changeset/afraid-hotels-bathe.md new file mode 100644 index 0000000000..15ef0d2c31 --- /dev/null +++ b/.changeset/afraid-hotels-bathe.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/cli": patch +--- + +Add support for legacy transactions in deploy script by falling back to `gasPrice` if `lastBaseFeePerGas` is not available diff --git a/packages/cli/src/utils/deploy.ts b/packages/cli/src/utils/deploy.ts index 765cdf42ac..4d724a7196 100644 --- a/packages/cli/src/utils/deploy.ts +++ b/packages/cli/src/utils/deploy.ts @@ -59,8 +59,10 @@ export async function deploy( console.log("Initial nonce", nonce); // Compute maxFeePerGas and maxPriorityFeePerGas like ethers, but allow for a multiplier to allow replacing pending transactions - let maxPriorityFeePerGas: number; - let maxFeePerGas: BigNumber; + let maxPriorityFeePerGas: number | undefined; + let maxFeePerGas: BigNumber | undefined; + let gasPrice: BigNumber | undefined; + await setInternalFeePerGas(priorityFeeMultiplier); // Catch all to await any promises before exiting the script @@ -402,6 +404,7 @@ export async function deploy( nonce: nonce++, maxPriorityFeePerGas, maxFeePerGas, + gasPrice, }) .then((c) => (disableTxWait ? c : c.deployed())); @@ -497,7 +500,7 @@ export async function deploy( const gasLimit = await contract.estimateGas[func].apply(null, args); console.log(chalk.gray(`executing transaction: ${functionName} with nonce ${nonce}`)); const txPromise = contract[func] - .apply(null, [...args, { gasLimit, nonce: nonce++, maxPriorityFeePerGas, maxFeePerGas }]) + .apply(null, [...args, { gasLimit, nonce: nonce++, maxPriorityFeePerGas, maxFeePerGas, gasPrice }]) .then((tx: any) => (confirmations === 0 ? tx : tx.wait(confirmations))); promises.push(txPromise); return txPromise; @@ -542,15 +545,28 @@ export async function deploy( async function setInternalFeePerGas(multiplier: number) { // Compute maxFeePerGas and maxPriorityFeePerGas like ethers, but allow for a multiplier to allow replacing pending transactions const feeData = await provider.getFeeData(); - if (!feeData.lastBaseFeePerGas) throw new MUDError("Can not fetch lastBaseFeePerGas from RPC"); - if (!feeData.lastBaseFeePerGas.eq(0) && (await signer.getBalance()).eq(0)) { - throw new MUDError(`Attempting to deploy to a chain with non-zero base fee with an account that has no balance. -If you're deploying to the Lattice testnet, you can fund your account by running 'pnpm mud faucet --address ${await signer.getAddress()}'`); - } - // Set the priority fee to 0 for development chains with no base fee, to allow transactions from unfunded wallets - maxPriorityFeePerGas = feeData.lastBaseFeePerGas.eq(0) ? 0 : Math.floor(1_500_000_000 * multiplier); - maxFeePerGas = feeData.lastBaseFeePerGas.mul(2).add(maxPriorityFeePerGas); + if (feeData.lastBaseFeePerGas) { + if (!feeData.lastBaseFeePerGas.eq(0) && (await signer.getBalance()).eq(0)) { + throw new MUDError(`Attempting to deploy to a chain with non-zero base fee with an account that has no balance. + If you're deploying to the Lattice testnet, you can fund your account by running 'pnpm mud faucet --address ${await signer.getAddress()}'`); + } + + // Set the priority fee to 0 for development chains with no base fee, to allow transactions from unfunded wallets + maxPriorityFeePerGas = feeData.lastBaseFeePerGas.eq(0) ? 0 : Math.floor(1_500_000_000 * multiplier); + maxFeePerGas = feeData.lastBaseFeePerGas.mul(2).add(maxPriorityFeePerGas); + } else if (feeData.gasPrice) { + // Legacy chains with gasPrice instead of maxFeePerGas + if (!feeData.gasPrice.eq(0) && (await signer.getBalance()).eq(0)) { + throw new MUDError( + `Attempting to deploy to a chain with non-zero gas price with an account that has no balance.` + ); + } + + gasPrice = feeData.gasPrice; + } else { + throw new MUDError("Can not fetch fee data from RPC"); + } } }