Skip to content

Commit 4db5d6f

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 4db5d6f

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

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,11 @@ export function useSmartAccountFee(
5151

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

54+
const modularChainInfo = chainStore.getModularChain(chainId);
55+
const hasOpStackFee = modularChainInfo.hasFeature(
56+
"op-stack-l1-data-fee"
57+
);
58+
5459
ethereumAccount
5560
.simulateGas(hexAddress, {
5661
to: hexAddress,
@@ -61,9 +66,25 @@ export function useSmartAccountFee(
6166
evmChainId
6267
),
6368
})
64-
.then((result) => {
69+
.then(async (result) => {
70+
if (cancelled) return;
71+
72+
let l1DataFee: Dec | undefined;
73+
if (hasOpStackFee) {
74+
const l1Fee = await ethereumAccount.simulateOpStackL1Fee({
75+
to: hexAddress,
76+
value: "0x0",
77+
data: "0x",
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)