Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions packages/pkp-ethers/src/lib/pkp-ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ import {

const logger = new Logger(version);

const EIP1559_TX_TYPE = 2;

export class PKPEthersWallet
implements
PKPWallet,
Expand All @@ -81,6 +83,8 @@ export class PKPEthersWallet
// -- manual tx settings --
manualGasPrice?: string;
manualGasLimit?: string;
manualMaxFeePerGas?: string;
manualMaxPriorityFeePerGas?: string;
nonce?: string;
chainId?: number;

Expand Down Expand Up @@ -155,6 +159,14 @@ export class PKPEthersWallet
this.manualGasLimit = gasLimit;
};

setMaxFeePerGas = (maxFeePerGas: string): void => {
this.manualMaxFeePerGas = maxFeePerGas;
};

setMaxPriorityFeePerGas = (maxPriorityFeePerGas: string): void => {
this.manualMaxPriorityFeePerGas = maxPriorityFeePerGas;
};

setNonce = (nonce: string): void => {
this.nonce = nonce;
};
Expand All @@ -166,6 +178,8 @@ export class PKPEthersWallet
resetManualSettings = (): void => {
this.manualGasPrice = undefined;
this.manualGasLimit = undefined;
this.manualMaxFeePerGas = undefined;
this.manualMaxPriorityFeePerGas = undefined;
this.nonce = undefined;
this.chainId = undefined;
};
Expand Down Expand Up @@ -215,6 +229,20 @@ export class PKPEthersWallet
transaction.gasLimit = this.manualGasLimit;
}

if (this.manualMaxFeePerGas && this.manualMaxPriorityFeePerGas) {
transaction.maxFeePerGas = this.manualMaxFeePerGas;
transaction.maxPriorityFeePerGas = this.manualMaxPriorityFeePerGas;
transaction.type = EIP1559_TX_TYPE;
this.pkpBase.log(
'signTransaction => EIP-1559 maxFeePerGas:',
transaction.maxFeePerGas
);
this.pkpBase.log(
'signTransaction => EIP-1559 maxPriorityFeePerGas:',
transaction.maxPriorityFeePerGas
);
}

if (this.nonce) {
transaction.nonce = this.nonce;
}
Expand All @@ -239,9 +267,30 @@ export class PKPEthersWallet
this.pkpBase.log('signTransaction => chainId:', transaction.chainId);
}

if (!transaction['gasPrice']) {
transaction.gasPrice = await this.getGasPrice();
this.pkpBase.log('signTransaction => gasPrice:', transaction.gasPrice);
if (
!transaction.gasPrice &&
(!transaction.maxFeePerGas || !transaction.maxPriorityFeePerGas)
) {
const feeData = await this.getFeeData();
if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) {
transaction.maxFeePerGas = feeData.maxFeePerGas;
transaction.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
transaction.type = EIP1559_TX_TYPE;
this.pkpBase.log(
'signTransaction => maxFeePerGas:',
transaction.maxFeePerGas
);
this.pkpBase.log(
'signTransaction => maxPriorityFeePerGas:',
transaction.maxPriorityFeePerGas
);
} else {
transaction.gasPrice = feeData.gasPrice || (await this.getGasPrice());
this.pkpBase.log(
'signTransaction => fallback gasPrice:',
transaction.gasPrice
);
}
}
} catch (err) {
this.pkpBase.log(
Expand Down
1 change: 0 additions & 1 deletion packages/wasm/rust/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/target
**/*.rs.bk
Cargo.lock
bin/
pkg/
wasm-pack.log
Loading
Loading