Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for gasPrice in transaction overrides and schemas #784

Merged
merged 2 commits into from
Dec 2, 2024
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
2 changes: 1 addition & 1 deletion src/server/schemas/transaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export const toTransactionSchema = (
if (transaction.status === "sent") {
return transaction.gasPrice?.toString() ?? null;
}
return null;
return transaction.overrides?.gasPrice?.toString() ?? null;
};

const resolveMaxFeePerGas = (): string | null => {
Expand Down
7 changes: 5 additions & 2 deletions src/server/schemas/txOverrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ export const txOverridesSchema = Type.Object({
description: "Gas limit for the transaction",
}),

// Overriding `gasPrice` is currently not supported.

gasPrice: Type.Optional({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also allow for a boolean true value here, which if detected, engine calculates the right gas amount to send

...WeiAmountStringSchema,
description:
"Gas price for the transaction. Do not use this if maxFeePerGas is set or if you want to use EIP-1559 type transactions. Only use this if you want to use legacy transactions.",
}),
maxFeePerGas: Type.Optional({
...WeiAmountStringSchema,
description: "Maximum fee per gas",
Expand Down
1 change: 1 addition & 0 deletions src/server/utils/transactionOverrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const parseTransactionOverrides = (
return {
overrides: {
gas: maybeBigInt(overrides.gas),
gasPrice: maybeBigInt(overrides.gasPrice),
maxFeePerGas: maybeBigInt(overrides.maxFeePerGas),
maxPriorityFeePerGas: maybeBigInt(overrides.maxPriorityFeePerGas),
},
Expand Down
1 change: 1 addition & 0 deletions src/utils/transaction/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type InsertedTransaction = {
// User-provided overrides.
overrides?: {
gas?: bigint;
gasPrice?: bigint;
maxFeePerGas?: bigint;
maxPriorityFeePerGas?: bigint;
};
Expand Down
2 changes: 2 additions & 0 deletions src/worker/tasks/sendTransactionWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ const _sendTransaction = async (
// Apply gas setting overrides.
// Do not set `maxFeePerGas` to estimate the onchain value.
gas: overrides?.gas,
gasPrice: overrides?.gasPrice,
maxPriorityFeePerGas: overrides?.maxPriorityFeePerGas,
},
});
Expand Down Expand Up @@ -403,6 +404,7 @@ const _sendTransaction = async (
}

await addSentNonce(chainId, from, nonce);

return {
...queuedTransaction,
status: "sent",
Expand Down