Skip to content

Commit

Permalink
Use Bundler Gas Feed (#24)
Browse files Browse the repository at this point in the history
This replaces ethers.getFeeData with bundler gas fee data. Note sure if we want to add the other fee data as a fallback... any thoughts?

Note that this makes us more reliant on a specific 3rd party service.
  • Loading branch information
bh2smith authored Jul 2, 2024
1 parent 4e68981 commit 80b8c8e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/lib/bundler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ethers } from "ethers";
import {
GasPrices,
PaymasterData,
UnsignedUserOperation,
UserOperation,
Expand Down Expand Up @@ -46,6 +47,10 @@ export class Erc4337Bundler {
}
}

async getGasPrice(): Promise<GasPrices> {
return this.provider.send("pimlico_getUserOperationGasPrice", []);
}

async _getUserOpReceiptInner(
userOpHash: string
): Promise<UserOperationReceipt | null> {
Expand Down
10 changes: 3 additions & 7 deletions src/lib/safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "@safe-global/safe-modules-deployments";
import { PLACEHOLDER_SIG, packGas, packPaymasterData } from "../util.js";
import {
GasPrice,
PaymasterData,
UnsignedUserOperation,
UserOperation,
Expand Down Expand Up @@ -163,15 +164,11 @@ export class ContractSuite {
async buildUserOp(
txData: MetaTransaction,
safeAddress: ethers.AddressLike,
feeData: ethers.FeeData,
feeData: GasPrice,
setup: string,
safeNotDeployed: boolean,
safeSaltNonce: string
): Promise<UnsignedUserOperation> {
const { maxPriorityFeePerGas, maxFeePerGas } = feeData;
if (!maxPriorityFeePerGas || !maxFeePerGas) {
throw new Error("no gas fee data");
}
const rawUserOp = {
sender: safeAddress,
nonce: ethers.toBeHex(await this.entryPoint.getNonce(safeAddress, 0)),
Expand All @@ -183,8 +180,7 @@ export class ContractSuite {
txData.data,
txData.operation || 0,
]),
maxPriorityFeePerGas: ethers.toBeHex((maxPriorityFeePerGas * 12n) / 10n),
maxFeePerGas: ethers.toBeHex(maxFeePerGas),
...feeData,
};
return rawUserOp;
}
Expand Down
3 changes: 2 additions & 1 deletion src/tx-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export class TransactionManager {
options: UserOptions;
}): Promise<{ safeOpHash: string; unsignedUserOp: UserOperation }> {
const { transactions, options } = args;
const gasFees = await this.provider.getFeeData();
const gasFees = (await this.bundler.getGasPrice()).fast;
// const gasFees = await this.provider.getFeeData();
// Build Singular MetaTransaction for Multisend from transaction list.
const tx =
transactions.length > 1 ? encodeMulti(transactions) : transactions[0];
Expand Down
11 changes: 11 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,14 @@ export type UserOperationReceipt = {
receipt: Receipt;
logs: Log[];
};

export interface GasPrices {
slow: GasPrice;
standard: GasPrice;
fast: GasPrice;
}

export interface GasPrice {
maxFeePerGas: Hex;
maxPriorityFeePerGas: Hex;
}

0 comments on commit 80b8c8e

Please sign in to comment.