mirror of
https://github.com/getwax/bls-wallet.git
synced 2026-01-08 23:28:21 -05:00
Add the L1 fee for optimism when calculating profit
This commit is contained in:
@@ -22,6 +22,7 @@ import BundleTable, { BundleRow, makeHash } from "./BundleTable.ts";
|
||||
import plus from "./helpers/plus.ts";
|
||||
import AggregationStrategy from "./AggregationStrategy.ts";
|
||||
import nil from "../helpers/nil.ts";
|
||||
import getOptimismL1Fee from "../helpers/getOptimismL1Fee.ts";
|
||||
|
||||
export type AddBundleResponse = { hash: string } | {
|
||||
failures: TransactionFailure[];
|
||||
@@ -34,6 +35,7 @@ export default class BundleService {
|
||||
maxAggregationDelayMillis: env.MAX_AGGREGATION_DELAY_MILLIS,
|
||||
maxUnconfirmedAggregations: env.MAX_UNCONFIRMED_AGGREGATIONS,
|
||||
maxEligibilityDelay: env.MAX_ELIGIBILITY_DELAY,
|
||||
isOptimism: env.IS_OPTIMISM,
|
||||
};
|
||||
|
||||
unconfirmedBundles = new Set<Bundle>();
|
||||
@@ -344,7 +346,7 @@ export default class BundleService {
|
||||
try {
|
||||
const balanceBefore = await this.ethereumService.wallet.getBalance();
|
||||
|
||||
const receipt = await this.ethereumService.submitBundle(
|
||||
const { response, receipt } = await this.ethereumService.submitBundle(
|
||||
aggregateBundle,
|
||||
Infinity,
|
||||
300,
|
||||
@@ -363,7 +365,13 @@ export default class BundleService {
|
||||
const profit = balanceAfter.sub(balanceBefore);
|
||||
|
||||
/** What we paid to process the bundle */
|
||||
const cost = receipt.gasUsed.mul(receipt.effectiveGasPrice);
|
||||
let cost = receipt.gasUsed.mul(receipt.effectiveGasPrice);
|
||||
|
||||
if (this.config.isOptimism) {
|
||||
cost = cost.add(
|
||||
await getOptimismL1Fee(this.ethereumService.provider, response),
|
||||
);
|
||||
}
|
||||
|
||||
/** Fees collected from users */
|
||||
const actualFee = profit.add(cost);
|
||||
|
||||
@@ -318,7 +318,7 @@ export default class EthereumService {
|
||||
bundle: Bundle,
|
||||
maxAttempts = 1,
|
||||
retryDelay = 300,
|
||||
): Promise<ethers.providers.TransactionReceipt> {
|
||||
): Promise<ResponseAndReceipt> {
|
||||
assert(bundle.operations.length > 0, "Cannot process empty bundle");
|
||||
assert(maxAttempts > 0, "Must have at least one attempt");
|
||||
|
||||
@@ -345,10 +345,10 @@ export default class EthereumService {
|
||||
};
|
||||
|
||||
const attempt = async () => {
|
||||
let txResponse: ethers.providers.TransactionResponse;
|
||||
let response: ethers.providers.TransactionResponse;
|
||||
|
||||
try {
|
||||
txResponse = await this.wallet.sendTransaction(txRequest);
|
||||
response = await this.wallet.sendTransaction(txRequest);
|
||||
} catch (error) {
|
||||
if (/\binvalid transaction nonce\b/.test(error.message)) {
|
||||
// This can occur when the nonce is in the future, which can
|
||||
@@ -364,7 +364,10 @@ export default class EthereumService {
|
||||
}
|
||||
|
||||
try {
|
||||
return { type: "receipt" as const, value: await txResponse.wait() };
|
||||
return {
|
||||
type: "complete" as const,
|
||||
value: { response, receipt: await response.wait() },
|
||||
};
|
||||
} catch (error) {
|
||||
return { type: "waitError" as const, value: error };
|
||||
}
|
||||
@@ -380,7 +383,7 @@ export default class EthereumService {
|
||||
|
||||
const attemptResult = await attempt();
|
||||
|
||||
if (attemptResult.type === "receipt") {
|
||||
if (attemptResult.type === "complete") {
|
||||
return attemptResult.value;
|
||||
}
|
||||
|
||||
@@ -554,3 +557,8 @@ export default class EthereumService {
|
||||
return wallet;
|
||||
}
|
||||
}
|
||||
|
||||
type ResponseAndReceipt = {
|
||||
response: ethers.providers.TransactionResponse;
|
||||
receipt: ethers.providers.TransactionReceipt;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user