Skip to content

Commit e8b860a

Browse files
authored
fix: fix gas estimator on polygon (#3322)
1 parent 4f15a5d commit e8b860a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

packages/financial-templates-lib/src/helpers/GasEstimator.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,28 @@ class GasEstimator {
9292
try {
9393
const response = await fetch(url);
9494
const json = await response.json();
95+
// Depending on the network ID, the structure back from the API might change. If ethereum then expected structure is:
96+
// {
97+
// safeLow: 1, // slow maxPriorityFeePerGas
98+
// standard: 1.5, // standard maxPriorityFeePerGas
99+
// fast: 4, // fast maxPriorityFeePerGas
100+
// fastest: 6.2, // fastest maxPriorityFeePerGas
101+
// currentBaseFee: 33.1, // previous blocks base fee
102+
// recommendedBaseFee: 67.1 // maxFeePerGas
103+
// }
104+
// In this case, we want to use recommendedBaseFee & send legacy transactions. If Polygon then the expected structure is:
95105
// Primary URL expected response structure:
96106
// {
97107
// "safeLow": "25.0",
98108
// "standard": "30.0",
99109
// "fast": "35.0",
100110
// "fastest": "39.6"
101111
// }
102-
if (json.fastest) {
103-
let price = json.recommendedBaseFee;
104-
return price;
112+
// In this case, we want to use fastest and send legacy transactions.
113+
if (json.recommendedBaseFee) {
114+
return json.recommendedBaseFee;
115+
} else if (json.fastest) {
116+
return json.fastest;
105117
} else {
106118
throw new Error(`Main gas station API @ ${url}: bad json response`);
107119
}

0 commit comments

Comments
 (0)