Skip to content

Commit 1adee31

Browse files
authored
Merge pull request #827 from LIT-Protocol/feat/eip-1559
feat: add EIP1559 tx type support
2 parents 4748281 + da15c2a commit 1adee31

File tree

4 files changed

+1612
-4
lines changed

4 files changed

+1612
-4
lines changed

packages/pkp-ethers/src/lib/pkp-ethers.ts

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ import {
6262

6363
const logger = new Logger(version);
6464

65+
const EIP1559_TX_TYPE = 2;
66+
6567
export 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,30 @@ 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+
transaction.type = EIP1559_TX_TYPE;
279+
this.pkpBase.log(
280+
'signTransaction => maxFeePerGas:',
281+
transaction.maxFeePerGas
282+
);
283+
this.pkpBase.log(
284+
'signTransaction => maxPriorityFeePerGas:',
285+
transaction.maxPriorityFeePerGas
286+
);
287+
} else {
288+
transaction.gasPrice = feeData.gasPrice || (await this.getGasPrice());
289+
this.pkpBase.log(
290+
'signTransaction => fallback gasPrice:',
291+
transaction.gasPrice
292+
);
293+
}
245294
}
246295
} catch (err) {
247296
this.pkpBase.log(

packages/wasm/rust/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/target
22
**/*.rs.bk
3-
Cargo.lock
43
bin/
54
pkg/
65
wasm-pack.log

0 commit comments

Comments
 (0)