From 07181989247437e944678566eb873c51d80bc97e Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 18 Feb 2026 10:12:03 -0800 Subject: [PATCH] chore(smoke): preflight sepolia balance before membership tx --- scripts/e2e-membership-flow.cjs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/scripts/e2e-membership-flow.cjs b/scripts/e2e-membership-flow.cjs index ad8f18a..2b98669 100644 --- a/scripts/e2e-membership-flow.cjs +++ b/scripts/e2e-membership-flow.cjs @@ -116,10 +116,34 @@ async function main() { data: quote.calldata, value: quote.value, }; + + const value = ethers.BigNumber.from(txReq.value || "0x0"); + const feeData = await provider.getFeeData(); + const configuredGasPrice = GAS_PRICE_WEI ? ethers.BigNumber.from(GAS_PRICE_WEI) : null; + const effectiveGasPrice = + configuredGasPrice || feeData.gasPrice || feeData.maxFeePerGas || ethers.BigNumber.from("0"); + const gasUnitsReserve = ethers.BigNumber.from("250000"); + const estimatedGasCost = effectiveGasPrice.mul(gasUnitsReserve); + const totalNeeded = value.add(estimatedGasCost); + const balance = await provider.getBalance(address); + if (balance.lt(totalNeeded)) { + const deficit = totalNeeded.sub(balance); + throw new Error( + [ + "insufficient funded balance for membership mint preflight", + `balance_wei=${balance.toString()}`, + `required_min_wei=${totalNeeded.toString()}`, + `deficit_wei=${deficit.toString()}`, + `mint_value_wei=${value.toString()}`, + `gas_reserve_wei=${estimatedGasCost.toString()}`, + ].join(" ") + ); + } + const txRequest = { to: txReq.to, data: txReq.data, - value: txReq.value, + value: value, }; if (GAS_PRICE_WEI) { txRequest.gasPrice = ethers.BigNumber.from(GAS_PRICE_WEI);