feat: add dynamic gas price support for transaction functions#12
feat: add dynamic gas price support for transaction functions#12alexx855 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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
getGasPriceutility function that fetches current gas prices from the network with fallback support - Updated all blockchain transaction functions to accept an optional
GasPriceOptionsparameter - 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 |
There was a problem hiding this comment.
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.
| // Call the contract with dynamic gas price for faster confirmation | |
| // Call the contract with a dynamically determined gas price |
| 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"); | ||
| } |
There was a problem hiding this comment.
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.
|
|
||
| ### Gas Price Options | ||
|
|
||
| All transaction functions support an optional `GasPriceOptions` parameter to customize gas pricing: |
There was a problem hiding this comment.
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.
No description provided.