Skip to content

feat: add dynamic gas price support for transaction functions#12

Open
alexx855 wants to merge 1 commit into
mainfrom
dynamic-gas
Open

feat: add dynamic gas price support for transaction functions#12
alexx855 wants to merge 1 commit into
mainfrom
dynamic-gas

Conversation

@alexx855
Copy link
Copy Markdown
Owner

@alexx855 alexx855 commented Jan 3, 2026

No description provided.

Copilot AI review requested due to automatic review settings January 3, 2026 17:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces dynamic gas price support for blockchain transaction functions, replacing hardcoded gas prices with a flexible system that fetches current network prices while allowing manual overrides.

Key changes:

  • Added a new getGasPrice utility function that fetches current gas prices from the network with fallback support
  • Updated all blockchain transaction functions to accept an optional GasPriceOptions parameter
  • Replaced hardcoded gas prices (26 gwei and 50 gwei) with dynamic pricing across the codebase

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/utils.ts Adds getGasPrice function and GasPriceOptions interface for dynamic gas price fetching with fallback to 26 gwei
lib/transfers.ts Updates transferAxie and batchTransferAxies to accept GasPriceOptions and use dynamic gas pricing
lib/marketplace/settle-order.ts Updates buyMarketplaceOrder to support BuyMarketplaceOrderOptions interface extending GasPriceOptions
lib/marketplace/settle-material-order.ts Updates buyMaterialOrder to accept GasPriceOptions parameter
lib/marketplace/cancel-order.ts Updates cancelMarketplaceOrder to support CancelMarketplaceOrderOptions interface extending GasPriceOptions
lib/marketplace/cancel-material-order.ts Updates cancelMaterialOrder to accept GasPriceOptions parameter
lib/marketplace/approve.ts Updates all approval functions (approveMarketplaceContract, approveWETH, approveBatchTransfer, approveMaterialMarketplace) to accept GasPriceOptions
index.ts Exports the new getGasPrice function and related types (GasPriceOptions, BuyMarketplaceOrderOptions, CancelMarketplaceOrderOptions)
README.md Documents the new gas price options feature with usage examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// Call the contract with higher gas price for faster confirmation
const gasPrice = await getGasPrice(signer, options);

// Call the contract with dynamic gas price for faster confirmation
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

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

The comment states "for faster confirmation" but this is misleading. The previous hardcoded value was 50 gwei, while the new dynamic gas price may be lower or higher depending on network conditions. The comment should be updated to reflect that this uses a dynamic gas price rather than implying it's specifically optimized for speed.

Suggested change
// Call the contract with dynamic gas price for faster confirmation
// Call the contract with a dynamically determined gas price

Copilot uses AI. Check for mistakes.
Comment thread lib/utils.ts
Comment on lines +26 to +55
export async function getGasPrice(
signerOrProvider: Signer | JsonRpcProvider,
options?: GasPriceOptions,
): Promise<bigint> {
// If custom gas price is provided, use it
if (options?.gasPrice !== undefined) {
return options.gasPrice;
}

// Otherwise fetch from provider
let provider: JsonRpcProvider;
if ("provider" in signerOrProvider && signerOrProvider.provider) {
provider = signerOrProvider.provider as JsonRpcProvider;
} else {
provider = signerOrProvider as JsonRpcProvider;
}

try {
const feeData = await provider.getFeeData();
// Use gasPrice from feeData, fallback to a reasonable default if null
if (feeData.gasPrice) {
return feeData.gasPrice;
}
} catch (error) {
console.warn("Could not fetch gas price from network, using fallback.", error);
}

// Fallback default
return parseUnits("26", "gwei");
}
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

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

The new getGasPrice function lacks test coverage. Since the repository has comprehensive test coverage for other utility functions and marketplace operations, this new utility function should also have test coverage to verify the fallback behavior, custom gas price handling, and provider extraction logic.

Copilot uses AI. Check for mistakes.
Comment thread README.md

### Gas Price Options

All transaction functions support an optional `GasPriceOptions` parameter to customize gas pricing:
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

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

The statement "All transaction functions support an optional GasPriceOptions parameter" is misleading. Functions like createMarketplaceOrder and createMaterialMarketplaceOrder don't support gas price options because they only make API calls to create orders without executing on-chain transactions. Consider clarifying this to say "All blockchain transaction functions" or list which functions specifically support this parameter.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants