@@ -2,7 +2,6 @@ import * as ox__Hex from "ox/Hex";
2
2
import { formatTransactionRequest } from "viem" ;
3
3
import { roundUpGas } from "../../gas/op-gas-fee-reducer.js" ;
4
4
import { getAddress } from "../../utils/address.js" ;
5
- import { hexToBytes } from "../../utils/encoding/to-bytes.js" ;
6
5
import { resolvePromisedValue } from "../../utils/promise/resolve-promised-value.js" ;
7
6
import type { Prettify } from "../../utils/type-utils.js" ;
8
7
import type { Account } from "../../wallets/interfaces/wallet.js" ;
@@ -117,31 +116,20 @@ export async function estimateGas(
117
116
118
117
const rpcRequest = getRpcClient ( options . transaction ) ;
119
118
try {
120
- let gas = await eth_estimateGas (
121
- rpcRequest ,
122
- formatTransactionRequest ( {
123
- authorizationList : authorizationList ?. map ( ( auth ) => ( {
124
- ...auth ,
125
- contractAddress : getAddress ( auth . address ) ,
126
- nonce : Number ( auth . nonce ) ,
127
- r : ox__Hex . fromNumber ( auth . r ) ,
128
- s : ox__Hex . fromNumber ( auth . s ) ,
129
- } ) ) ,
130
- data : encodedData ,
131
- from : fromAddress ? getAddress ( fromAddress ) : undefined ,
132
- to : toAddress ? getAddress ( toAddress ) : undefined ,
133
- value,
134
- ...( authorizationList && authorizationList ?. length > 0
135
- ? {
136
- gas :
137
- minGas (
138
- hexToBytes ( encodedData ) ,
139
- BigInt ( authorizationList ?. length ?? 0 ) ,
140
- ) + 100_000n ,
141
- }
142
- : { } ) ,
143
- } ) ,
144
- ) ;
119
+ const formattedTx = formatTransactionRequest ( {
120
+ authorizationList : authorizationList ?. map ( ( auth ) => ( {
121
+ ...auth ,
122
+ contractAddress : getAddress ( auth . address ) ,
123
+ nonce : Number ( auth . nonce ) ,
124
+ r : ox__Hex . fromNumber ( auth . r ) ,
125
+ s : ox__Hex . fromNumber ( auth . s ) ,
126
+ } ) ) ,
127
+ data : encodedData ,
128
+ from : fromAddress ? getAddress ( fromAddress ) : undefined ,
129
+ to : toAddress ? getAddress ( toAddress ) : undefined ,
130
+ value,
131
+ } ) ;
132
+ let gas = await eth_estimateGas ( rpcRequest , formattedTx ) ;
145
133
146
134
if ( options . transaction . chain . experimental ?. increaseZeroByteCount ) {
147
135
gas = roundUpGas ( gas ) ;
@@ -158,19 +146,3 @@ export async function estimateGas(
158
146
cache . set ( txWithFrom , promise ) ;
159
147
return promise ;
160
148
}
161
-
162
- // EIP-7623 + EIP-7702 floor calculation
163
- const TxGas = 21_000n ;
164
- const TxCostFloorPerToken = 10n ; // params.TxCostFloorPerToken
165
- const TxTokenPerNonZero = 4n ; // params.TxTokenPerNonZeroByte
166
- const TxAuthTupleGas = 12_500n ;
167
-
168
- function minGas ( data : Uint8Array , authCount = 0n ) {
169
- let nz = 0n ;
170
- for ( const b of data ) if ( b !== 0 ) nz ++ ;
171
- const z = BigInt ( data . length ) - nz ;
172
- const tokens = nz * TxTokenPerNonZero + z ;
173
- const floor = TxGas + tokens * TxCostFloorPerToken ;
174
- const intrinsic = TxGas + authCount * TxAuthTupleGas ;
175
- return floor > intrinsic ? floor : intrinsic ;
176
- }
0 commit comments