File tree Expand file tree Collapse file tree 1 file changed +22
-8
lines changed
Expand file tree Collapse file tree 1 file changed +22
-8
lines changed Original file line number Diff line number Diff line change 11import { nextTick } from "node:process" ;
22
3- import { chains , PERCENTAGE_FACTOR } from "@gearbox-protocol/sdk" ;
3+ import { chains , formatBN , PERCENTAGE_FACTOR } from "@gearbox-protocol/sdk" ;
44import type {
55 AnvilClient ,
66 AnvilNodeInfo ,
@@ -134,17 +134,31 @@ export default class Client {
134134 if ( maxPriorityFeePerGas && maxFeePerGas ) {
135135 req . maxPriorityFeePerGas = 10n * maxPriorityFeePerGas ;
136136 req . maxFeePerGas = 2n * maxFeePerGas + req . maxPriorityFeePerGas ;
137- this . logger . debug (
138- {
139- maxFeePerGas : req . maxFeePerGas ,
140- maxPriorityFeePerGas : req . maxPriorityFeePerGas ,
141- } ,
142- `increase gas fees` ,
143- ) ;
144137 }
145138 if ( gas ) {
146139 req . gas = ( gas * ( GAS_X + PERCENTAGE_FACTOR ) ) / PERCENTAGE_FACTOR ;
147140 }
141+ const txCost = req . gas * req . maxFeePerGas + ( req . value ?? 0n ) ;
142+ this . logger . debug (
143+ {
144+ maxFeePerGas : req . maxFeePerGas ,
145+ maxPriorityFeePerGas : req . maxPriorityFeePerGas ,
146+ gas : req . gas ,
147+ txCost,
148+ } ,
149+ `increase gas fees` ,
150+ ) ;
151+
152+ if ( this . #balance && txCost > this . #balance. value ) {
153+ this . logger . warn (
154+ {
155+ txCost,
156+ balance : this . #balance. value ,
157+ } ,
158+ `transaction cost ${ formatBN ( txCost , 18 ) } exceeds balance (${ formatBN ( this . #balance. value , 18 ) } ETH)` ,
159+ ) ;
160+ }
161+
148162 const serializedTransaction = await this . wallet . signTransaction ( req ) ;
149163 const hash = await this . wallet . sendRawTransaction ( {
150164 serializedTransaction,
You can’t perform that action at this time.
0 commit comments