@@ -62,6 +62,8 @@ import {
6262
6363const logger = new Logger ( version ) ;
6464
65+ const EIP1559_TX_TYPE = 2 ;
66+
6567export class PKPEthersWallet
6668 implements
6769 PKPWallet ,
@@ -81,6 +83,8 @@ export class PKPEthersWallet
8183 // -- manual tx settings --
8284 manualGasPrice ?: string ;
8385 manualGasLimit ?: string ;
86+ manualMaxFeePerGas ?: string ;
87+ manualMaxPriorityFeePerGas ?: string ;
8488 nonce ?: string ;
8589 chainId ?: number ;
8690
@@ -155,6 +159,14 @@ export class PKPEthersWallet
155159 this . manualGasLimit = gasLimit ;
156160 } ;
157161
162+ setMaxFeePerGas = ( maxFeePerGas : string ) : void => {
163+ this . manualMaxFeePerGas = maxFeePerGas ;
164+ } ;
165+
166+ setMaxPriorityFeePerGas = ( maxPriorityFeePerGas : string ) : void => {
167+ this . manualMaxPriorityFeePerGas = maxPriorityFeePerGas ;
168+ } ;
169+
158170 setNonce = ( nonce : string ) : void => {
159171 this . nonce = nonce ;
160172 } ;
@@ -166,6 +178,8 @@ export class PKPEthersWallet
166178 resetManualSettings = ( ) : void => {
167179 this . manualGasPrice = undefined ;
168180 this . manualGasLimit = undefined ;
181+ this . manualMaxFeePerGas = undefined ;
182+ this . manualMaxPriorityFeePerGas = undefined ;
169183 this . nonce = undefined ;
170184 this . chainId = undefined ;
171185 } ;
@@ -215,6 +229,20 @@ export class PKPEthersWallet
215229 transaction . gasLimit = this . manualGasLimit ;
216230 }
217231
232+ if ( this . manualMaxFeePerGas && this . manualMaxPriorityFeePerGas ) {
233+ transaction . maxFeePerGas = this . manualMaxFeePerGas ;
234+ transaction . maxPriorityFeePerGas = this . manualMaxPriorityFeePerGas ;
235+ transaction . type = EIP1559_TX_TYPE ;
236+ this . pkpBase . log (
237+ 'signTransaction => EIP-1559 maxFeePerGas:' ,
238+ transaction . maxFeePerGas
239+ ) ;
240+ this . pkpBase . log (
241+ 'signTransaction => EIP-1559 maxPriorityFeePerGas:' ,
242+ transaction . maxPriorityFeePerGas
243+ ) ;
244+ }
245+
218246 if ( this . nonce ) {
219247 transaction . nonce = this . nonce ;
220248 }
@@ -239,9 +267,29 @@ export class PKPEthersWallet
239267 this . pkpBase . log ( 'signTransaction => chainId:' , transaction . chainId ) ;
240268 }
241269
242- if ( ! transaction [ 'gasPrice' ] ) {
243- transaction . gasPrice = await this . getGasPrice ( ) ;
244- this . pkpBase . log ( 'signTransaction => gasPrice:' , transaction . gasPrice ) ;
270+ if (
271+ ! transaction . gasPrice &&
272+ ( ! transaction . maxFeePerGas || ! transaction . maxPriorityFeePerGas )
273+ ) {
274+ const feeData = await this . getFeeData ( ) ;
275+ if ( feeData . maxFeePerGas && feeData . maxPriorityFeePerGas ) {
276+ transaction . maxFeePerGas = feeData . maxFeePerGas ;
277+ transaction . maxPriorityFeePerGas = feeData . maxPriorityFeePerGas ;
278+ this . pkpBase . log (
279+ 'signTransaction => maxFeePerGas:' ,
280+ transaction . maxFeePerGas
281+ ) ;
282+ this . pkpBase . log (
283+ 'signTransaction => maxPriorityFeePerGas:' ,
284+ transaction . maxPriorityFeePerGas
285+ ) ;
286+ } else {
287+ transaction . gasPrice = feeData . gasPrice || ( await this . getGasPrice ( ) ) ;
288+ this . pkpBase . log (
289+ 'signTransaction => fallback gasPrice:' ,
290+ transaction . gasPrice
291+ ) ;
292+ }
245293 }
246294 } catch ( err ) {
247295 this . pkpBase . log (
0 commit comments