@@ -26,13 +26,9 @@ import {
2626} from '@aave/types-next' ;
2727import {
2828 type Account ,
29- BaseError ,
3029 type Chain ,
31- createPublicClient ,
3230 defineChain ,
33- http ,
3431 type ProviderRpcError ,
35- type PublicClient ,
3632 type RpcError ,
3733 SwitchChainError ,
3834 TransactionExecutionError ,
@@ -44,7 +40,6 @@ import {
4440} from 'viem' ;
4541import {
4642 estimateGas as estimateGasWithViem ,
47- getBlock ,
4843 sendTransaction as sendTransactionWithViem ,
4944 signTypedData ,
5045 waitForTransactionReceipt ,
@@ -146,45 +141,19 @@ function ensureChain(
146141 } ) ;
147142}
148143
149- function getBlockGasLimit (
150- publicClient : PublicClient ,
151- ) : ResultAsync < bigint , SigningError > {
152- return ResultAsync . fromPromise (
153- getBlock ( publicClient , {
154- blockTag : 'latest' ,
155- } ) ,
156- ( err ) => SigningError . from ( err ) ,
157- ) . map ( ( block ) => block . gasLimit ) ;
158- }
159-
160144function estimateGas (
161145 walletClient : WalletClient ,
162146 request : TransactionRequest ,
163147) : ResultAsync < bigint , SigningError > {
164- const publicClient = createPublicClient ( {
165- chain : walletClient . chain ,
166- transport : http ( ) ,
167- } ) ;
168-
169148 return ResultAsync . fromPromise (
170- estimateGasWithViem ( publicClient , {
149+ estimateGasWithViem ( walletClient , {
171150 account : walletClient . account ,
172151 data : request . data ,
173152 to : request . to ,
174153 value : BigInt ( request . value ) ,
175154 } ) ,
176155 ( err ) => SigningError . from ( err ) ,
177- )
178- . map ( ( gas ) => ( gas * 115n ) / 100n ) // 15% buffer
179- . orElse ( ( err ) => {
180- if (
181- err instanceof BaseError &&
182- err . shortMessage . includes ( 'exceeds allowance' )
183- ) {
184- return getBlockGasLimit ( publicClient ) ;
185- }
186- return err . asResultAsync ( ) ;
187- } ) ;
156+ ) . map ( ( gas ) => ( gas * 115n ) / 100n ) ; // 15% buffer
188157}
189158
190159function sendEip1559Transaction (
0 commit comments