Skip to content

Commit d112e2d

Browse files
committed
gas price fix
1 parent de708de commit d112e2d

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

dkg/providers/blockchain/async_blockchain.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,38 @@ async def fetch_gas_price(oracle_url: str) -> Wei | None:
182182
async with session.get(oracle_url) as response:
183183
response.raise_for_status()
184184
data: dict = await response.json()
185+
186+
print(f"🔍 Gas price oracle response: {data}")
185187

186188
if "result" in data:
187189
gas_price = int(data["result"], 16)
188190
elif "fast" in data:
189191
gas_price = self.w3.to_wei(data["fast"], "gwei")
192+
elif "result" in data and "SafeGasPrice" in data["result"]:
193+
# Handle Basescan format
194+
gas_price = self.w3.to_wei(data["result"]["SafeGasPrice"], "gwei")
195+
elif "result" in data and "FastGasPrice" in data["result"]:
196+
# Handle Basescan format with FastGasPrice
197+
gas_price = self.w3.to_wei(data["result"]["FastGasPrice"], "gwei")
190198
else:
199+
print(f"⚠️ Unknown gas price oracle format: {data}")
191200
return None
192201

193-
# Ensure minimum gas price (1 gwei = 1,000,000,000 wei)
194-
min_gas_price = self.w3.to_wei(1, "gwei") # 1 gwei minimum
202+
print(f"💰 Parsed gas price: {gas_price} wei")
203+
204+
# Ensure minimum gas price (2 gwei = 2,000,000,000 wei)
205+
min_gas_price = self.w3.to_wei(2, "gwei") # 2 gwei minimum
195206
if gas_price < min_gas_price:
196207
print(f"⚠️ Gas price from oracle too low ({gas_price} wei), using minimum ({min_gas_price} wei)")
197-
return min_gas_price
208+
gas_price = min_gas_price
209+
210+
# Apply multiplier to ensure transaction goes through (1.5x)
211+
gas_price = int(gas_price * 1.5)
212+
print(f"🚀 Final gas price with multiplier: {gas_price} wei")
198213

199214
return gas_price
200-
except Exception:
215+
except Exception as e:
216+
print(f"❌ Error fetching gas price from {oracle_url}: {e}")
201217
return None
202218

203219
oracles = self.gas_price_oracle
@@ -213,14 +229,14 @@ async def fetch_gas_price(oracle_url: str) -> Wei | None:
213229
# Fallback: use network gas price with minimum
214230
try:
215231
network_gas_price = await self.w3.eth.gas_price
216-
min_gas_price = self.w3.to_wei(1, "gwei") # 1 gwei minimum
232+
min_gas_price = self.w3.to_wei(2, "gwei") # 2 gwei minimum
217233
if network_gas_price < min_gas_price:
218234
print(f"⚠️ Network gas price too low ({network_gas_price} wei), using minimum ({min_gas_price} wei)")
219235
return min_gas_price
220236
return network_gas_price
221237
except Exception:
222238
# Final fallback: return minimum gas price
223-
return self.w3.to_wei(1, "gwei")
239+
return self.w3.to_wei(2, "gwei")
224240

225241
async def _init_contracts(self):
226242
init_tasks = []

dkg/providers/blockchain/blockchain.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,22 +167,38 @@ def fetch_gas_price(oracle_url: str) -> Wei | None:
167167
response = requests.get(oracle_url)
168168
response.raise_for_status()
169169
data: dict = response.json()
170+
171+
print(f"🔍 Gas price oracle response: {data}")
170172

171173
if "result" in data:
172174
gas_price = int(data["result"], 16)
173175
elif "fast" in data:
174176
gas_price = self.w3.to_wei(data["fast"], "gwei")
177+
elif "result" in data and "SafeGasPrice" in data["result"]:
178+
# Handle Basescan format
179+
gas_price = self.w3.to_wei(data["result"]["SafeGasPrice"], "gwei")
180+
elif "result" in data and "FastGasPrice" in data["result"]:
181+
# Handle Basescan format with FastGasPrice
182+
gas_price = self.w3.to_wei(data["result"]["FastGasPrice"], "gwei")
175183
else:
184+
print(f"⚠️ Unknown gas price oracle format: {data}")
176185
return None
177186

178-
# Ensure minimum gas price (1 gwei = 1,000,000,000 wei)
179-
min_gas_price = self.w3.to_wei(1, "gwei") # 1 gwei minimum
187+
print(f"💰 Parsed gas price: {gas_price} wei")
188+
189+
# Ensure minimum gas price (2 gwei = 2,000,000,000 wei)
190+
min_gas_price = self.w3.to_wei(2, "gwei") # 2 gwei minimum
180191
if gas_price < min_gas_price:
181192
print(f"⚠️ Gas price from oracle too low ({gas_price} wei), using minimum ({min_gas_price} wei)")
182-
return min_gas_price
193+
gas_price = min_gas_price
194+
195+
# Apply multiplier to ensure transaction goes through (1.5x)
196+
gas_price = int(gas_price * 1.5)
197+
print(f"🚀 Final gas price with multiplier: {gas_price} wei")
183198

184199
return gas_price
185-
except Exception:
200+
except Exception as e:
201+
print(f"❌ Error fetching gas price from {oracle_url}: {e}")
186202
return None
187203

188204
oracles = self.gas_price_oracle
@@ -198,14 +214,14 @@ def fetch_gas_price(oracle_url: str) -> Wei | None:
198214
# Fallback: use network gas price with minimum
199215
try:
200216
network_gas_price = self.w3.eth.gas_price
201-
min_gas_price = self.w3.to_wei(1, "gwei") # 1 gwei minimum
217+
min_gas_price = self.w3.to_wei(2, "gwei") # 2 gwei minimum
202218
if network_gas_price < min_gas_price:
203219
print(f"⚠️ Network gas price too low ({network_gas_price} wei), using minimum ({min_gas_price} wei)")
204220
return min_gas_price
205221
return network_gas_price
206222
except Exception:
207223
# Final fallback: return minimum gas price
208-
return self.w3.to_wei(1, "gwei")
224+
return self.w3.to_wei(2, "gwei")
209225

210226
def _init_contracts(self):
211227
for contract in self.abi.keys():

0 commit comments

Comments
 (0)