(
provider: ethers.providers.Provider,
overrides: ethers.Overrides = {}
)
| 44 | * @returns The parsed overrides object with values compatible with Ethers |
| 45 | */ |
| 46 | export const parseOverrides = async ( |
| 47 | provider: ethers.providers.Provider, |
| 48 | overrides: ethers.Overrides = {} |
| 49 | ): Promise<ethers.Overrides> => { |
| 50 | const { gasPrice, maxFeePerGas, maxPriorityFeePerGas } = overrides; |
| 51 | |
| 52 | const feeData = await provider.getFeeData(); |
| 53 | const supportsEip1559 = !!(feeData.maxFeePerGas && feeData.maxPriorityFeePerGas); |
| 54 | const hasEip1559Overrides = !!(maxFeePerGas || maxPriorityFeePerGas); |
| 55 | const hasLegacyOverrides = !!gasPrice; |
| 56 | |
| 57 | // Mixed overrides |
| 58 | if (hasLegacyOverrides && hasEip1559Overrides) { |
| 59 | throw new Error('Both legacy and EIP1559 override pricing options specified - ambiguous'); |
| 60 | } |
| 61 | // Chain does not support EIP1559 but EIP1559 overrides provided |
| 62 | if (!supportsEip1559 && hasEip1559Overrides) { |
| 63 | throw new Error('EIP1559 override pricing specified on legacy network'); |
| 64 | } |
| 65 | |
| 66 | // EIP1559 network and no EIP1559 overrides or legacy overrides |
| 67 | if (supportsEip1559 && !hasEip1559Overrides && !hasLegacyOverrides) { |
| 68 | const gasTarget = await fetchProviderRecommendedEip1559GasPrice( |
| 69 | provider, |
| 70 | { |
| 71 | gasPriceStrategy: 'providerRecommendedEip1559GasPrice', |
| 72 | baseFeeMultiplier: 2, |
| 73 | priorityFee: { |
| 74 | value: 3.12, |
| 75 | unit: 'gwei', |
| 76 | }, |
| 77 | }, |
| 78 | Date.now() |
| 79 | ); |
| 80 | |
| 81 | return { |
| 82 | ...overrides, |
| 83 | ...gasTarget, |
| 84 | }; |
| 85 | } |
| 86 | |
| 87 | // Legacy network and no legacy overrides |
| 88 | if (!supportsEip1559 && !hasLegacyOverrides) { |
| 89 | const gasTarget = await fetchProviderRecommendedGasPrice( |
| 90 | provider, |
| 91 | { |
| 92 | gasPriceStrategy: 'providerRecommendedGasPrice', |
| 93 | recommendedGasPriceMultiplier: 1, |
| 94 | }, |
| 95 | Date.now() |
| 96 | ); |
| 97 | |
| 98 | return { |
| 99 | ...overrides, |
| 100 | ...gasTarget, |
| 101 | }; |
| 102 | } |
| 103 |
no test coverage detected