Skip to content

Commit 395bbcb

Browse files
jungcome7claude
andcommitted
fix: add OP Stack L1 data fee calculation for smart account
Simulate L1 data fee via simulateOpStackL1Fee for chains with "op-stack-l1-data-fee" feature and include it in the total estimated fee. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1f26614 commit 395bbcb

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

apps/extension/src/pages/wallet/smart-account/confirm/hooks/use-smart-account-fee.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { formatFee } from "../../utils";
1010

1111
type FeeState =
1212
| { status: "loading" }
13-
| { status: "success"; gasUsed: number }
13+
| { status: "success"; gasUsed: number; l1DataFee?: Dec }
1414
| { status: "error" };
1515

1616
export function useSmartAccountFee(
@@ -51,6 +51,9 @@ export function useSmartAccountFee(
5151

5252
const ethereumAccount = ethereumAccountStore.getAccount(chainId);
5353

54+
const modularChainInfo = chainStore.getModularChain(chainId);
55+
const hasOpStackFee = modularChainInfo.hasFeature("op-stack-l1-data-fee");
56+
5457
ethereumAccount
5558
.simulateGas(hexAddress, {
5659
to: hexAddress,
@@ -61,9 +64,27 @@ export function useSmartAccountFee(
6164
evmChainId
6265
),
6366
})
64-
.then((result) => {
67+
.then(async (result) => {
68+
if (cancelled) return;
69+
70+
let l1DataFee: Dec | undefined;
71+
if (hasOpStackFee) {
72+
const gasLimit = Math.ceil(result.gasUsed * 1.3);
73+
const l1Fee = await ethereumAccount.simulateOpStackL1Fee({
74+
to: hexAddress,
75+
value: "0x0",
76+
data: "0x",
77+
gasLimit,
78+
});
79+
l1DataFee = new Dec(BigInt(l1Fee));
80+
}
81+
6582
if (!cancelled) {
66-
setFeeState({ status: "success", gasUsed: result.gasUsed });
83+
setFeeState({
84+
status: "success",
85+
gasUsed: result.gasUsed,
86+
l1DataFee,
87+
});
6788
}
6889
})
6990
.catch(() => {
@@ -75,6 +96,7 @@ export function useSmartAccountFee(
7596
};
7697
}, [
7798
chainId,
99+
chainStore,
78100
hexAddress,
79101
evmChainId,
80102
isValid,
@@ -93,7 +115,10 @@ export function useSmartAccountFee(
93115
const feePerGas = txFees?.maxFeePerGas ?? txFees?.gasPrice;
94116
if (!feePerGas || feePerGas.isZero()) return null;
95117
const gasLimit = Math.ceil(feeState.gasUsed * 1.3);
96-
const fee = feePerGas.mul(new Dec(gasLimit)).truncate();
118+
let fee = feePerGas.mul(new Dec(gasLimit)).truncate();
119+
if (feeState.l1DataFee) {
120+
fee = fee.add(feeState.l1DataFee.truncate());
121+
}
97122
return "0x" + BigInt(fee.toString()).toString(16);
98123
}, [feeState, txFees]);
99124

0 commit comments

Comments
 (0)