Skip to content

Commit 3aeaf32

Browse files
committed
Add maxPriority in createAccount
1 parent b5edafa commit 3aeaf32

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

packages/pq-account/js/createAccount.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ethers } from 'ethers';
22
import { nttCompact, redirectConsole, explorerTxUrl } from './utils.js';
33
import { to_expanded_encoded_bytes } from './utils_mldsa.js';
4-
import * as softEcdsaKeygen from './software-signer/ecdsaKeygen.js';
5-
import * as softMldsaKeygen from './software-signer/mldsaKeygen.js';
4+
import * as softEcdsaKeygen from './software-signer/ecdsaKeygen.js';
5+
import * as softMldsaKeygen from './software-signer/mldsaKeygen.js';
66
import * as softFalconKeygen from './software-signer/falconKeygen.js';
77
import {
88
openTransport,
@@ -95,7 +95,7 @@ async function main(mode) {
9595
sepolia: '0xaa36a7',
9696
arbitrumSepolia: '0x66eee', baseSepolia: '0x14a34',
9797
};
98-
const selectedNetwork = document.getElementById('targetNetwork')?.value;
98+
const selectedNetwork = document.getElementById('targetNetwork')?.value;
9999
const expectedChainHex = networkToChainId[selectedNetwork];
100100

101101
await window.ethereum.request({ method: 'eth_requestAccounts' });
@@ -114,7 +114,7 @@ async function main(mode) {
114114
}
115115

116116
provider = new ethers.BrowserProvider(window.ethereum);
117-
signer = await provider.getSigner();
117+
signer = await provider.getSigner();
118118

119119
const address = await signer.getAddress();
120120
const balance = await provider.getBalance(address);
@@ -130,7 +130,7 @@ async function main(mode) {
130130

131131
if (mode === 'ledger') {
132132
const ecdsaPubkey = await getEcdsaPublicKey(transport, "m/44'/60'/0'/0/0");
133-
const raw = ecdsaPubkey.subarray(2, 66);
133+
const raw = ecdsaPubkey.subarray(2, 66);
134134
const hash = ethers.keccak256(raw);
135135
preQuantumPubKey = ethers.getAddress('0x' + hash.slice(-40));
136136
console.log("✅ ECDSA address: " + preQuantumPubKey);
@@ -139,7 +139,7 @@ async function main(mode) {
139139
pqPublicKey = await getMldsaPublicKey(transport);
140140
console.log("✅ ML-DSA public key retrieved (" + pqPublicKey.length + " bytes)");
141141
} else {
142-
const preQuantumSeed = document.getElementById('prequantum').value.trim();
142+
const preQuantumSeed = document.getElementById('prequantum').value.trim();
143143
const postQuantumSeed = document.getElementById('postquantum').value.trim();
144144

145145
try {
@@ -175,25 +175,25 @@ async function main(mode) {
175175
console.log("🎉 DEPLOYMENT COMPLETE!");
176176
console.log("🔑 Account: " + result.address);
177177
if (result.transactionHash) console.log("🔍 Tx: " + result.transactionHash);
178-
if (result.alreadyExists) console.log("ℹ️ Account already existed at this address");
178+
if (result.alreadyExists) console.log("ℹ️ Account already existed at this address");
179179
console.log("============================================================");
180180
} else {
181181
console.error("Deployment failed" + (result.error ? ": " + result.error : ""));
182182
}
183183

184184
} finally {
185185
if (transport) {
186-
try { await transport.close(); } catch (_) {}
186+
try { await transport.close(); } catch (_) { }
187187
}
188188
}
189189
}
190190

191191
// ─── UI Setup ───────────────────────────────────────────────────────────
192192

193193
function setup() {
194-
const deployBtn = document.getElementById('deploy');
194+
const deployBtn = document.getElementById('deploy');
195195
const deployLedgerBtn = document.getElementById('deploy-ledger');
196-
const output = document.getElementById('output');
196+
const output = document.getElementById('output');
197197

198198
if (!output) { console.error('Missing UI elements'); return; }
199199

@@ -233,7 +233,7 @@ function setup() {
233233
}
234234
}
235235

236-
if (deployBtn) deployBtn.addEventListener('click', () => run('soft'));
236+
if (deployBtn) deployBtn.addEventListener('click', () => run('soft'));
237237
if (deployLedgerBtn) deployLedgerBtn.addEventListener('click', () => run('ledger'));
238238
}
239239

@@ -343,20 +343,32 @@ export async function deployERC4337Account(
343343
estimatedGas = 5000000n;
344344
console.log("- Using default gas limit: " + estimatedGas.toString());
345345
}
346-
347346
const feeData = await provider.getFeeData();
348-
const gasCostWei = estimatedGas * (feeData.gasPrice || feeData.maxFeePerGas || 0n);
349-
console.log("- Gas price: " + ethers.formatUnits(feeData.gasPrice || feeData.maxFeePerGas || 0n, "gwei") + " gwei");
350-
console.log("- Estimated cost: " + ethers.formatEther(gasCostWei) + " ETH");
351347

348+
// Ensure a minimum priority fee so OP-Stack sequencers don't drop the tx
349+
const minTip = 1_000_000n; // 0.001 gwei floor
350+
const maxPriority = (feeData.maxPriorityFeePerGas && feeData.maxPriorityFeePerGas > minTip)
351+
? feeData.maxPriorityFeePerGas
352+
: minTip;
353+
const maxFee = feeData.maxFeePerGas
354+
? (feeData.maxFeePerGas > maxPriority ? feeData.maxFeePerGas * 2n : maxPriority * 2n)
355+
: maxPriority * 2n;
356+
357+
const gasCostWei = estimatedGas * maxFee;
358+
console.log("- Max fee: " + ethers.formatUnits(maxFee, "gwei") + " gwei");
359+
console.log("- Max priority fee: " + ethers.formatUnits(maxPriority, "gwei") + " gwei");
360+
console.log("- Estimated cost (upper bound): " + ethers.formatEther(gasCostWei) + " ETH");
352361
console.log("🚀 Creating account — please confirm the transaction...");
353362

354363
const tx = await factory.createAccount(
355364
preQuantumPubKey,
356365
postQuantumPubKey,
357-
{ gasLimit: estimatedGas * 120n / 100n }
366+
{
367+
gasLimit: estimatedGas * 120n / 100n,
368+
maxFeePerGas: maxFee,
369+
maxPriorityFeePerGas: maxPriority,
370+
}
358371
);
359-
360372
const txHash = tx.hash;
361373
console.log("✅ Transaction signed: " + txHash);
362374

0 commit comments

Comments
 (0)