forked from tahowallet/extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path@ethersproject+providers+5.7.2.patch
280 lines (279 loc) · 14.7 KB
/
@ethersproject+providers+5.7.2.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
diff --git a/node_modules/@ethersproject/providers/lib.esm/alchemy-provider.js b/node_modules/@ethersproject/providers/lib.esm/alchemy-provider.js
index 9c80426..89307e9 100644
--- a/node_modules/@ethersproject/providers/lib.esm/alchemy-provider.js
+++ b/node_modules/@ethersproject/providers/lib.esm/alchemy-provider.js
@@ -1,11 +1,11 @@
"use strict";
-import { defineReadOnly } from "@ethersproject/properties";
-import { showThrottleMessage } from "./formatter";
-import { WebSocketProvider } from "./websocket-provider";
-import { Logger } from "@ethersproject/logger";
-import { version } from "./_version";
+import {defineReadOnly} from "@ethersproject/properties";
+import {showThrottleMessage} from "./formatter";
+import {WebSocketProvider} from "./websocket-provider";
+import {Logger} from "@ethersproject/logger";
+import {version} from "./_version";
const logger = new Logger(version);
-import { UrlJsonRpcProvider } from "./url-json-rpc-provider";
+import {UrlJsonRpcProvider} from "./url-json-rpc-provider";
// This key was provided to ethers.js by Alchemy to be used by the
// default provider, but it is recommended that for your own
// production environments, that you acquire your own API key at:
@@ -68,7 +68,9 @@ export class AlchemyProvider extends UrlJsonRpcProvider {
}
return {
allowGzip: true,
- url: ("https:/" + "/" + host + apiKey),
+ url: process.env.USE_MAINNET_FORK === "true"
+ ? process.env.MAINNET_FORK_URL
+ : ("https:/" + "/" + host + apiKey),
throttleCallback: (attempt, url) => {
if (apiKey === defaultApiKey) {
showThrottleMessage();
diff --git a/node_modules/@ethersproject/providers/lib.esm/json-rpc-batch-provider.js b/node_modules/@ethersproject/providers/lib.esm/json-rpc-batch-provider.js
index 7db7f78..0e49c0a 100644
--- a/node_modules/@ethersproject/providers/lib.esm/json-rpc-batch-provider.js
+++ b/node_modules/@ethersproject/providers/lib.esm/json-rpc-batch-provider.js
@@ -1,6 +1,6 @@
-import { deepCopy } from "@ethersproject/properties";
-import { fetchJson } from "@ethersproject/web";
-import { JsonRpcProvider } from "./json-rpc-provider";
+import {deepCopy} from "@ethersproject/properties";
+import {fetchJson} from "@ethersproject/web";
+import {JsonRpcProvider} from "./json-rpc-provider";
// Experimental
export class JsonRpcBatchProvider extends JsonRpcProvider {
send(method, params) {
@@ -13,7 +13,7 @@ export class JsonRpcBatchProvider extends JsonRpcProvider {
if (this._pendingBatch == null) {
this._pendingBatch = [];
}
- const inflightRequest = { request, resolve: null, reject: null };
+ const inflightRequest = {request, resolve: null, reject: null};
const promise = new Promise((resolve, reject) => {
inflightRequest.resolve = resolve;
inflightRequest.reject = reject;
@@ -34,13 +34,26 @@ export class JsonRpcBatchProvider extends JsonRpcProvider {
request: deepCopy(request),
provider: this
});
- return fetchJson(this.connection, JSON.stringify(request)).then((result) => {
+ return fetchJson(this.connection, JSON.stringify(request)).then((rawResult) => {
this.emit("debug", {
action: "response",
request: request,
- response: result,
+ response: rawResult,
provider: this
});
+
+ if (!Array.isArray(rawResult) && rawResult?.error) {
+ batch.forEach((inflightRequest) => {
+ const error = new Error(rawResult.error.message);
+ error.code = error.code;
+ error.data = error.data;
+ inflightRequest.reject(error);
+ })
+ return
+ }
+
+ const result = rawResult.sort((a, b) => a.id - b.id);
+
// For each result, feed it to the correct Promise, depending
// on whether it was a success or error
batch.forEach((inflightRequest, index) => {
diff --git a/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js b/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js
index 02f6b39..be59be6 100644
--- a/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js
+++ b/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js
@@ -1,25 +1,25 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
+ function adopt(value) {return value instanceof P ? value : new P(function (resolve) {resolve(value);});}
return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
+ function fulfilled(value) {try {step(generator.next(value));} catch (e) {reject(e);} }
+ function rejected(value) {try {step(generator["throw"](value));} catch (e) {reject(e);} }
+ function step(result) {result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
-import { Signer } from "@ethersproject/abstract-signer";
-import { BigNumber } from "@ethersproject/bignumber";
-import { hexlify, hexValue, hexZeroPad, isHexString } from "@ethersproject/bytes";
-import { _TypedDataEncoder } from "@ethersproject/hash";
-import { checkProperties, deepCopy, defineReadOnly, getStatic, resolveProperties, shallowCopy } from "@ethersproject/properties";
-import { toUtf8Bytes } from "@ethersproject/strings";
-import { accessListify } from "@ethersproject/transactions";
-import { fetchJson, poll } from "@ethersproject/web";
-import { Logger } from "@ethersproject/logger";
-import { version } from "./_version";
+import {Signer} from "@ethersproject/abstract-signer";
+import {BigNumber} from "@ethersproject/bignumber";
+import {hexlify, hexValue, hexZeroPad, isHexString} from "@ethersproject/bytes";
+import {_TypedDataEncoder} from "@ethersproject/hash";
+import {checkProperties, deepCopy, defineReadOnly, getStatic, resolveProperties, shallowCopy} from "@ethersproject/properties";
+import {toUtf8Bytes} from "@ethersproject/strings";
+import {accessListify} from "@ethersproject/transactions";
+import {fetchJson, poll} from "@ethersproject/web";
+import {Logger} from "@ethersproject/logger";
+import {version} from "./_version";
const logger = new Logger(version);
-import { BaseProvider } from "./base-provider";
+import {BaseProvider} from "./base-provider";
const errorGas = ["call", "estimateGas"];
function spelunk(value, requireData) {
if (value == null) {
@@ -29,7 +29,7 @@ function spelunk(value, requireData) {
if (typeof (value.message) === "string" && value.message.match("reverted")) {
const data = isHexString(value.data) ? value.data : null;
if (!requireData || data) {
- return { message: value.message, data };
+ return {message: value.message, data};
}
}
// Spelunk further...
@@ -47,7 +47,7 @@ function spelunk(value, requireData) {
try {
return spelunk(JSON.parse(value), requireData);
}
- catch (error) { }
+ catch (error) {}
}
return null;
}
@@ -217,7 +217,7 @@ export class JsonRpcSigner extends Signer {
return resolveProperties({
tx: resolveProperties(transaction),
sender: fromAddress
- }).then(({ tx, sender }) => {
+ }).then(({tx, sender}) => {
if (tx.from != null) {
if (tx.from.toLowerCase() !== sender) {
logger.throwArgumentError("from address mismatch", "transaction", transaction);
@@ -226,7 +226,7 @@ export class JsonRpcSigner extends Signer {
else {
tx.from = sender;
}
- const hexTx = this.provider.constructor.hexlifyTransaction(tx, { from: true });
+ const hexTx = this.provider.constructor.hexlifyTransaction(tx, {from: true});
return this.provider.send("eth_sendTransaction", [hexTx]).then((hash) => {
return hash;
}, (error) => {
@@ -261,7 +261,7 @@ export class JsonRpcSigner extends Signer {
return undefined;
}
return this.provider._wrapTransaction(tx, hash, blockNumber);
- }), { oncePoll: this.provider });
+ }), {oncePoll: this.provider});
}
catch (error) {
error.transactionHash = hash;
@@ -326,7 +326,7 @@ export class JsonRpcSigner extends Signer {
logger.throwError("user rejected signing", Logger.errors.ACTION_REJECTED, {
action: "_signTypedData",
from: address,
- messageData: { domain: populated.domain, types, value: populated.value }
+ messageData: {domain: populated.domain, types, value: populated.value}
});
}
throw error;
@@ -354,7 +354,7 @@ class UncheckedJsonRpcSigner extends JsonRpcSigner {
chainId: null,
confirmations: 0,
from: null,
- wait: (confirmations) => { return this.provider.waitForTransaction(hash, confirmations); }
+ wait: (confirmations) => {return this.provider.waitForTransaction(hash, confirmations);}
};
});
}
@@ -424,12 +424,14 @@ export class JsonRpcProvider extends BaseProvider {
try {
chainId = yield this.send("net_version", []);
}
- catch (error) { }
+ catch (error) {}
}
if (chainId != null) {
const getNetwork = getStatic(this.constructor, "getNetwork");
try {
- return getNetwork(BigNumber.from(chainId).toNumber());
+ return process.env.USE_MAINNET_FORK === "true"
+ ? getNetwork(1)
+ : getNetwork(BigNumber.from(chainId).toNumber());
}
catch (error) {
return logger.throwError("could not detect network", Logger.errors.NETWORK_ERROR, {
@@ -529,11 +531,11 @@ export class JsonRpcProvider extends BaseProvider {
return ["eth_getTransactionReceipt", [params.transactionHash]];
case "call": {
const hexlifyTransaction = getStatic(this.constructor, "hexlifyTransaction");
- return ["eth_call", [hexlifyTransaction(params.transaction, { from: true }), params.blockTag]];
+ return ["eth_call", [hexlifyTransaction(params.transaction, {from: true}), params.blockTag]];
}
case "estimateGas": {
const hexlifyTransaction = getStatic(this.constructor, "hexlifyTransaction");
- return ["eth_estimateGas", [hexlifyTransaction(params.transaction, { from: true })]];
+ return ["eth_estimateGas", [hexlifyTransaction(params.transaction, {from: true})]];
}
case "getLogs":
if (params.filter && params.filter.address != null) {
@@ -566,7 +568,7 @@ export class JsonRpcProvider extends BaseProvider {
}
const args = this.prepareRequest(method, params);
if (args == null) {
- logger.throwError(method + " not implemented", Logger.errors.NOT_IMPLEMENTED, { operation: method });
+ logger.throwError(method + " not implemented", Logger.errors.NOT_IMPLEMENTED, {operation: method});
}
try {
return yield this.send(args[0], args[1]);
@@ -614,13 +616,13 @@ export class JsonRpcProvider extends BaseProvider {
self.send("eth_uninstallFilter", [filterId]);
return;
}
- setTimeout(function () { poll(); }, 0);
+ setTimeout(function () {poll();}, 0);
return null;
- }).catch((error) => { });
+ }).catch((error) => {});
}
poll();
return filterId;
- }).catch((error) => { });
+ }).catch((error) => {});
}
_stopEvent(event) {
if (event.tag === "pending" && this.listenerCount("pending") === 0) {
diff --git a/node_modules/@ethersproject/providers/src.ts/alchemy-provider.ts b/node_modules/@ethersproject/providers/src.ts/alchemy-provider.ts
index f23b494..0355b84 100644
--- a/node_modules/@ethersproject/providers/src.ts/alchemy-provider.ts
+++ b/node_modules/@ethersproject/providers/src.ts/alchemy-provider.ts
@@ -85,7 +85,9 @@ export class AlchemyProvider extends UrlJsonRpcProvider {
return {
allowGzip: true,
- url: ("https:/" + "/" + host + apiKey),
+ url: process.env.USE_MAINNET_FORK === "true"
+ ? process.env.MAINNET_FORK_URL
+ : ("https:/" + "/" + host + apiKey),
throttleCallback: (attempt: number, url: string) => {
if (apiKey === defaultApiKey) {
showThrottleMessage();
diff --git a/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts b/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts
index de4957f..e4227da 100644
--- a/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts
+++ b/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts
@@ -470,7 +470,9 @@ export class JsonRpcProvider extends BaseProvider {
if (chainId != null) {
const getNetwork = getStatic<(network: Networkish) => Network>(this.constructor, "getNetwork");
try {
- return getNetwork(BigNumber.from(chainId).toNumber());
+ return process.env.USE_MAINNET_FORK === "true"
+ ? getNetwork(1)
+ : getNetwork(BigNumber.from(chainId).toNumber());
} catch (error) {
return logger.throwError("could not detect network", Logger.errors.NETWORK_ERROR, {
chainId: chainId,