Skip to content

Commit

Permalink
chore: nit updates to use Promise all and helper methods for readabil…
Browse files Browse the repository at this point in the history
…ity (#212)
  • Loading branch information
denniswon authored Nov 5, 2023
1 parent a886853 commit 3d6ec25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions packages/core/src/provider/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export class SmartAccountProvider<
// this pretty prints the uo
throw new Error(
`Request is missing parameters. All properties on UserOperationStruct must be set. uo: ${JSON.stringify(
request,
uoStruct,
null,
2
)}`
Expand Down Expand Up @@ -459,20 +459,22 @@ export class SmartAccountProvider<
};

readonly feeDataGetter: AccountMiddlewareFn = async (struct) => {
const maxPriorityFeePerGas =
await this.rpcClient.estimateMaxPriorityFeePerGas();
const feeData = await this.rpcClient.estimateFeesPerGas();
const [maxPriorityFeePerGas, feeData] = await Promise.all([
this.rpcClient.estimateMaxPriorityFeePerGas(),
this.rpcClient.estimateFeesPerGas(),
]);
if (!feeData.maxFeePerGas || !feeData.maxPriorityFeePerGas) {
throw new Error(
"feeData is missing maxFeePerGas or maxPriorityFeePerGas"
);
}

// add 33% to the priorty fee to ensure the transaction is mined
let maxPriorityFeePerGasBid = (BigInt(maxPriorityFeePerGas) * 4n) / 3n;
if (maxPriorityFeePerGasBid < this.minPriorityFeePerBid) {
maxPriorityFeePerGasBid = this.minPriorityFeePerBid;
}
// set maxPriorityFeePerGasBid to the max between 33% added priority fee estimate and
// the min priority fee per gas set for the provider
let maxPriorityFeePerGasBid = bigIntMax(
bigIntPercent(maxPriorityFeePerGas, 133n),
this.minPriorityFeePerBid
);

const maxFeePerGasBid =
BigInt(feeData.maxFeePerGas) -
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { BigNumberish } from "../types";
*/
export const bigIntMax = (...args: bigint[]) => {
if (!args.length) {
return undefined;
throw new Error("bigIntMax requires at least one argument");
}

return args.reduce((m, c) => (m > c ? m : c));
Expand Down

0 comments on commit 3d6ec25

Please sign in to comment.