chore(smoke): preflight sepolia balance before membership tx
This commit is contained in:
parent
cfb4770e7e
commit
0718198924
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user