@across-protocol/sdk 3.1.35 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +4 -4
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +1 -2
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/HubPoolClient.d.ts +7 -4
- package/dist/cjs/clients/HubPoolClient.js +37 -25
- package/dist/cjs/clients/HubPoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient.d.ts +7 -5
- package/dist/cjs/clients/SpokePoolClient.js +53 -90
- package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockConfigStoreClient.d.ts +4 -3
- package/dist/cjs/clients/mocks/MockConfigStoreClient.js +27 -44
- package/dist/cjs/clients/mocks/MockConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockEvents.d.ts +5 -5
- package/dist/cjs/clients/mocks/MockEvents.js +7 -44
- package/dist/cjs/clients/mocks/MockEvents.js.map +1 -1
- package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +5 -5
- package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +9 -19
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +22 -96
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/contracts/utils.d.ts +1 -1
- package/dist/cjs/contracts/utils.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/polygon.js +30 -7
- package/dist/cjs/gasPriceOracle/adapters/polygon.js.map +1 -1
- package/dist/cjs/interfaces/Common.d.ts +7 -0
- package/dist/cjs/priceClient/adapters/baseAdapter.js +11 -9
- package/dist/cjs/priceClient/adapters/baseAdapter.js.map +1 -1
- package/dist/cjs/utils/EventUtils.d.ts +7 -4
- package/dist/cjs/utils/EventUtils.js +9 -5
- package/dist/cjs/utils/EventUtils.js.map +1 -1
- package/dist/cjs/utils/JSONUtils.js +1 -1
- package/dist/cjs/utils/JSONUtils.js.map +1 -1
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +4 -4
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +2 -3
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/HubPoolClient.d.ts +19 -4
- package/dist/esm/clients/HubPoolClient.js +51 -27
- package/dist/esm/clients/HubPoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient.d.ts +13 -12
- package/dist/esm/clients/SpokePoolClient.js +61 -104
- package/dist/esm/clients/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockConfigStoreClient.d.ts +4 -3
- package/dist/esm/clients/mocks/MockConfigStoreClient.js +33 -47
- package/dist/esm/clients/mocks/MockConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockEvents.d.ts +5 -5
- package/dist/esm/clients/mocks/MockEvents.js +9 -50
- package/dist/esm/clients/mocks/MockEvents.js.map +1 -1
- package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +5 -5
- package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +9 -19
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +30 -100
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/contracts/utils.d.ts +1 -1
- package/dist/esm/contracts/utils.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/polygon.js +31 -10
- package/dist/esm/gasPriceOracle/adapters/polygon.js.map +1 -1
- package/dist/esm/interfaces/Common.d.ts +7 -0
- package/dist/esm/priceClient/adapters/baseAdapter.js +11 -9
- package/dist/esm/priceClient/adapters/baseAdapter.js.map +1 -1
- package/dist/esm/utils/EventUtils.d.ts +7 -4
- package/dist/esm/utils/EventUtils.js +7 -4
- package/dist/esm/utils/EventUtils.js.map +1 -1
- package/dist/esm/utils/JSONUtils.js +1 -1
- package/dist/esm/utils/JSONUtils.js.map +1 -1
- package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +4 -4
- package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
- package/dist/types/clients/HubPoolClient.d.ts +19 -4
- package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient.d.ts +13 -12
- package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockConfigStoreClient.d.ts +4 -3
- package/dist/types/clients/mocks/MockConfigStoreClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockEvents.d.ts +5 -5
- package/dist/types/clients/mocks/MockEvents.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockHubPoolClient.d.ts +5 -5
- package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +9 -19
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
- package/dist/types/contracts/utils.d.ts +1 -1
- package/dist/types/contracts/utils.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/adapters/polygon.d.ts.map +1 -1
- package/dist/types/interfaces/Common.d.ts +7 -0
- package/dist/types/interfaces/Common.d.ts.map +1 -1
- package/dist/types/priceClient/adapters/baseAdapter.d.ts.map +1 -1
- package/dist/types/utils/EventUtils.d.ts +7 -4
- package/dist/types/utils/EventUtils.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +9 -10
- package/src/clients/HubPoolClient.ts +34 -24
- package/src/clients/SpokePoolClient.ts +55 -74
- package/src/clients/mocks/MockConfigStoreClient.ts +11 -11
- package/src/clients/mocks/MockEvents.ts +15 -65
- package/src/clients/mocks/MockHubPoolClient.ts +6 -6
- package/src/clients/mocks/MockSpokePoolClient.ts +26 -59
- package/src/contracts/utils.ts +2 -1
- package/src/gasPriceOracle/adapters/polygon.ts +19 -8
- package/src/interfaces/Common.ts +7 -0
- package/src/priceClient/adapters/baseAdapter.ts +1 -0
- package/src/utils/EventUtils.ts +12 -7
- package/src/utils/JSONUtils.ts +1 -1
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
|
-
import { Contract
|
|
2
|
+
import { Contract } from "ethers";
|
|
3
3
|
import { random } from "lodash";
|
|
4
4
|
import winston from "winston";
|
|
5
5
|
import { ZERO_ADDRESS } from "../../constants";
|
|
6
6
|
import {
|
|
7
|
+
Log,
|
|
7
8
|
DepositWithBlock,
|
|
8
9
|
FillType,
|
|
9
|
-
V3FundsDepositedEvent,
|
|
10
|
-
RealizedLpFee,
|
|
11
10
|
RelayerRefundExecutionWithBlock,
|
|
12
11
|
SlowFillRequestWithBlock,
|
|
13
12
|
Fill,
|
|
@@ -15,25 +14,20 @@ import {
|
|
|
15
14
|
SlowFillLeaf,
|
|
16
15
|
SpeedUp,
|
|
17
16
|
} from "../../interfaces";
|
|
18
|
-
import {
|
|
17
|
+
import { toBN, toBNWei, getCurrentTime, randomAddress } from "../../utils";
|
|
19
18
|
import { SpokePoolClient, SpokePoolUpdate } from "../SpokePoolClient";
|
|
20
19
|
import { HubPoolClient } from "../HubPoolClient";
|
|
21
20
|
import { EventManager, EventOverrides, getEventManager } from "./MockEvents";
|
|
22
21
|
import { AcrossConfigStoreClient } from "../AcrossConfigStoreClient";
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// This class replaces internal SpokePoolClient functionality, enabling the
|
|
27
|
-
// user to bypass on-chain queries and inject ethers Event objects directly.
|
|
23
|
+
// This class replaces internal SpokePoolClient functionality, enabling
|
|
24
|
+
// the user to bypass on-chain queries and inject Log objects directly.
|
|
28
25
|
export class MockSpokePoolClient extends SpokePoolClient {
|
|
29
26
|
public eventManager: EventManager;
|
|
30
|
-
private realizedLpFeePct: BigNumber = bnZero;
|
|
31
|
-
private realizedLpFeePctOverride = false;
|
|
32
27
|
private destinationTokenForChainOverride: Record<number, string> = {};
|
|
33
28
|
// Allow tester to set the numberOfDeposits() returned by SpokePool at a block height.
|
|
34
29
|
public depositIdAtBlock: number[] = [];
|
|
35
30
|
public numberOfDeposits = 0;
|
|
36
|
-
public blocks: Record<number, Block> = {};
|
|
37
31
|
|
|
38
32
|
constructor(
|
|
39
33
|
logger: winston.Logger,
|
|
@@ -47,36 +41,10 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
47
41
|
this.eventManager = getEventManager(chainId, this.eventSignatures, deploymentBlock);
|
|
48
42
|
}
|
|
49
43
|
|
|
50
|
-
setDefaultRealizedLpFeePct(fee: BigNumber): void {
|
|
51
|
-
this.realizedLpFeePct = fee;
|
|
52
|
-
this.realizedLpFeePctOverride = true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
44
|
setConfigStoreClient(configStore?: AcrossConfigStoreClient): void {
|
|
56
45
|
this.configStoreClient = configStore;
|
|
57
46
|
}
|
|
58
47
|
|
|
59
|
-
clearDefaultRealizedLpFeePct(): void {
|
|
60
|
-
this.realizedLpFeePctOverride = false;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async computeRealizedLpFeePct(depositEvent: V3FundsDepositedEvent) {
|
|
64
|
-
const { realizedLpFeePct, realizedLpFeePctOverride } = this;
|
|
65
|
-
const { blockNumber: quoteBlock } = depositEvent;
|
|
66
|
-
return realizedLpFeePctOverride
|
|
67
|
-
? { realizedLpFeePct, quoteBlock }
|
|
68
|
-
: await super.computeRealizedLpFeePct(depositEvent);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async batchComputeRealizedLpFeePct(depositEvents: V3FundsDepositedEvent[]): Promise<RealizedLpFee[]> {
|
|
72
|
-
const { realizedLpFeePct, realizedLpFeePctOverride } = this;
|
|
73
|
-
return realizedLpFeePctOverride
|
|
74
|
-
? depositEvents.map(({ blockNumber: quoteBlock }) => {
|
|
75
|
-
return { realizedLpFeePct, quoteBlock };
|
|
76
|
-
})
|
|
77
|
-
: await super.batchComputeRealizedLpFeePct(depositEvents);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
48
|
setDestinationTokenForChain(chainId: number, token: string): void {
|
|
81
49
|
this.destinationTokenForChainOverride[chainId] = token;
|
|
82
50
|
}
|
|
@@ -107,33 +75,32 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
107
75
|
return Promise.resolve(this.depositIdAtBlock[blockTag]);
|
|
108
76
|
}
|
|
109
77
|
|
|
110
|
-
|
|
78
|
+
_update(eventsToQuery: string[]): Promise<SpokePoolUpdate> {
|
|
111
79
|
// Generate new "on chain" responses.
|
|
112
80
|
const latestBlockSearched = this.eventManager.blockNumber;
|
|
113
81
|
const currentTime = getCurrentTime();
|
|
114
82
|
|
|
115
|
-
const blocks: { [blockNumber: number]: Block } = {};
|
|
116
|
-
|
|
117
83
|
// Ensure an array for every requested event exists, in the requested order.
|
|
118
84
|
// All requested event types must be populated in the array (even if empty).
|
|
119
|
-
const events:
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
85
|
+
const events: Log[][] = eventsToQuery.map(() => []);
|
|
86
|
+
this.eventManager
|
|
87
|
+
.getEvents()
|
|
88
|
+
.flat()
|
|
89
|
+
.forEach((event) => {
|
|
90
|
+
const idx = eventsToQuery.indexOf(event.event);
|
|
91
|
+
if (idx !== -1) {
|
|
92
|
+
events[idx].push(event);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
128
95
|
|
|
129
96
|
// Update latestDepositIdQueried.
|
|
130
97
|
const idx = eventsToQuery.indexOf("V3FundsDeposited");
|
|
131
98
|
const latestDepositId = (events[idx] ?? []).reduce(
|
|
132
|
-
(depositId, event) => Math.max(depositId, event.args
|
|
99
|
+
(depositId, event) => Math.max(depositId, (event.args["depositId"] ?? 0) as number),
|
|
133
100
|
this.latestDepositIdQueried
|
|
134
101
|
);
|
|
135
102
|
|
|
136
|
-
return {
|
|
103
|
+
return Promise.resolve({
|
|
137
104
|
success: true,
|
|
138
105
|
firstDepositId: 0,
|
|
139
106
|
latestDepositId,
|
|
@@ -141,7 +108,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
141
108
|
oldestTime: 0,
|
|
142
109
|
events,
|
|
143
110
|
searchEndBlock: this.eventSearchConfig.toBlock || latestBlockSearched,
|
|
144
|
-
};
|
|
111
|
+
});
|
|
145
112
|
}
|
|
146
113
|
|
|
147
114
|
// Event signatures. Not strictly required, but they make generated events more recognisable.
|
|
@@ -151,7 +118,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
151
118
|
FundsDeposited: "uint256,uint256,uint256,int64,uint32,uint32,address,address,address,bytes",
|
|
152
119
|
};
|
|
153
120
|
|
|
154
|
-
depositV3(deposit: DepositWithBlock):
|
|
121
|
+
depositV3(deposit: DepositWithBlock): Log {
|
|
155
122
|
const event = "V3FundsDeposited";
|
|
156
123
|
|
|
157
124
|
const { blockNumber, transactionIndex } = deposit;
|
|
@@ -197,7 +164,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
197
164
|
});
|
|
198
165
|
}
|
|
199
166
|
|
|
200
|
-
fillV3Relay(fill: FillWithBlock):
|
|
167
|
+
fillV3Relay(fill: FillWithBlock): Log {
|
|
201
168
|
const event = "FilledV3Relay";
|
|
202
169
|
|
|
203
170
|
const { blockNumber, transactionIndex } = fill;
|
|
@@ -247,7 +214,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
247
214
|
});
|
|
248
215
|
}
|
|
249
216
|
|
|
250
|
-
speedUpV3Deposit(speedUp: SpeedUp):
|
|
217
|
+
speedUpV3Deposit(speedUp: SpeedUp): Log {
|
|
251
218
|
const event = "RequestedSpeedUpV3Deposit";
|
|
252
219
|
const topics = [speedUp.depositId, speedUp.depositor];
|
|
253
220
|
const args = { ...speedUp };
|
|
@@ -260,7 +227,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
260
227
|
});
|
|
261
228
|
}
|
|
262
229
|
|
|
263
|
-
requestV3SlowFill(request: SlowFillRequestWithBlock):
|
|
230
|
+
requestV3SlowFill(request: SlowFillRequestWithBlock): Log {
|
|
264
231
|
const event = "RequestedV3SlowFill";
|
|
265
232
|
|
|
266
233
|
const { originChainId, depositId } = request;
|
|
@@ -279,7 +246,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
279
246
|
|
|
280
247
|
// This is a simple wrapper around fillV3Relay().
|
|
281
248
|
// rootBundleId and proof are discarded here - we have no interest in verifying that.
|
|
282
|
-
executeV3SlowRelayLeaf(leaf: SlowFillLeaf):
|
|
249
|
+
executeV3SlowRelayLeaf(leaf: SlowFillLeaf): Log {
|
|
283
250
|
const fill: Fill = {
|
|
284
251
|
...leaf.relayData,
|
|
285
252
|
destinationChainId: this.chainId,
|
|
@@ -296,7 +263,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
296
263
|
return this.fillV3Relay(fill as FillWithBlock);
|
|
297
264
|
}
|
|
298
265
|
|
|
299
|
-
executeRelayerRefundLeaf(refund: RelayerRefundExecutionWithBlock):
|
|
266
|
+
executeRelayerRefundLeaf(refund: RelayerRefundExecutionWithBlock): Log {
|
|
300
267
|
const event = "ExecutedRelayerRefundRoot";
|
|
301
268
|
|
|
302
269
|
const chainId = refund.chainId ?? this.chainId;
|
|
@@ -328,7 +295,7 @@ export class MockSpokePoolClient extends SpokePoolClient {
|
|
|
328
295
|
destinationChainId: number,
|
|
329
296
|
enabled: boolean,
|
|
330
297
|
overrides: EventOverrides = {}
|
|
331
|
-
):
|
|
298
|
+
): Log {
|
|
332
299
|
const event = "EnabledDepositRoute";
|
|
333
300
|
|
|
334
301
|
const topics = [originToken, destinationChainId];
|
package/src/contracts/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { providers } from "ethers";
|
|
2
2
|
import { BaseHTTPAdapter, BaseHTTPAdapterArgs } from "../../priceClient/adapters/baseAdapter";
|
|
3
|
-
import { bnZero, isDefined, parseUnits } from "../../utils";
|
|
3
|
+
import { BigNumber, bnZero, isDefined, parseUnits } from "../../utils";
|
|
4
4
|
import { CHAIN_IDs } from "../../constants";
|
|
5
5
|
import { GasPriceEstimate } from "../types";
|
|
6
6
|
import { gasPriceError } from "../util";
|
|
@@ -27,8 +27,6 @@ type GasStationArgs = BaseHTTPAdapterArgs & {
|
|
|
27
27
|
|
|
28
28
|
const { POLYGON } = CHAIN_IDs;
|
|
29
29
|
|
|
30
|
-
// @dev toBNWei() is not imported from ../utils because of a circular dependency loop.
|
|
31
|
-
// The fix is probably to relocate the function estimateTotalGasRequiredByUnsignedTransaction().
|
|
32
30
|
class PolygonGasStation extends BaseHTTPAdapter {
|
|
33
31
|
readonly chainId: number;
|
|
34
32
|
|
|
@@ -42,7 +40,7 @@ class PolygonGasStation extends BaseHTTPAdapter {
|
|
|
42
40
|
async getFeeData(strategy: "safeLow" | "standard" | "fast" = "fast"): Promise<GasPriceEstimate> {
|
|
43
41
|
const gas = await this.query("v2", {});
|
|
44
42
|
|
|
45
|
-
const gasPrice
|
|
43
|
+
const gasPrice = (gas as GasStationV2Response)?.[strategy];
|
|
46
44
|
if (!this.isPolygon1559GasPrice(gasPrice)) {
|
|
47
45
|
// @todo: generalise gasPriceError() to accept a reason/cause?
|
|
48
46
|
gasPriceError("getFeeData()", this.chainId, bnZero);
|
|
@@ -69,12 +67,25 @@ class PolygonGasStation extends BaseHTTPAdapter {
|
|
|
69
67
|
}
|
|
70
68
|
}
|
|
71
69
|
|
|
72
|
-
export function gasStation(provider: providers.Provider, chainId: number): Promise<GasPriceEstimate> {
|
|
73
|
-
const gasStation = new PolygonGasStation({ chainId: chainId });
|
|
70
|
+
export async function gasStation(provider: providers.Provider, chainId: number): Promise<GasPriceEstimate> {
|
|
71
|
+
const gasStation = new PolygonGasStation({ chainId: chainId, timeout: 2000, retries: 0 });
|
|
72
|
+
let maxPriorityFeePerGas: BigNumber;
|
|
73
|
+
let maxFeePerGas: BigNumber;
|
|
74
74
|
try {
|
|
75
|
-
|
|
75
|
+
({ maxPriorityFeePerGas, maxFeePerGas } = await gasStation.getFeeData());
|
|
76
76
|
} catch (err) {
|
|
77
77
|
// Fall back to the RPC provider. May be less accurate.
|
|
78
|
-
|
|
78
|
+
({ maxPriorityFeePerGas, maxFeePerGas } = await eip1559(provider, chainId));
|
|
79
|
+
|
|
80
|
+
// Per the GasStation docs, the minimum priority fee on Polygon is 30 Gwei.
|
|
81
|
+
// https://docs.polygon.technology/tools/gas/polygon-gas-station/#interpretation
|
|
82
|
+
const minPriorityFee = parseUnits("30", 9);
|
|
83
|
+
if (maxPriorityFeePerGas.lt(minPriorityFee)) {
|
|
84
|
+
const priorityDelta = minPriorityFee.sub(maxPriorityFeePerGas);
|
|
85
|
+
maxPriorityFeePerGas = minPriorityFee;
|
|
86
|
+
maxFeePerGas = maxFeePerGas.add(priorityDelta);
|
|
87
|
+
}
|
|
79
88
|
}
|
|
89
|
+
|
|
90
|
+
return { maxPriorityFeePerGas, maxFeePerGas };
|
|
80
91
|
}
|
package/src/interfaces/Common.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import { Log as _Log } from "@ethersproject/abstract-provider";
|
|
1
2
|
import { BigNumber } from "../utils";
|
|
2
3
|
|
|
4
|
+
export type Log = _Log & {
|
|
5
|
+
event: string;
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
args: { [key: string]: any };
|
|
8
|
+
};
|
|
9
|
+
|
|
3
10
|
export interface SortableEvent {
|
|
4
11
|
blockNumber: number;
|
|
5
12
|
transactionIndex: number;
|
|
@@ -40,6 +40,7 @@ export class BaseHTTPAdapter {
|
|
|
40
40
|
protected async query(path: string, urlArgs?: object): Promise<unknown> {
|
|
41
41
|
const url = `https://${this.host}/${path ?? ""}`;
|
|
42
42
|
const args = {
|
|
43
|
+
headers: { "User-Agent": process.env.ACROSS_USER_AGENT ?? "across-protocol" },
|
|
43
44
|
timeout: this.timeout,
|
|
44
45
|
params: urlArgs ?? {},
|
|
45
46
|
};
|
package/src/utils/EventUtils.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { Result } from "@ethersproject/abi";
|
|
2
|
-
|
|
3
|
-
import { SortableEvent } from "../interfaces";
|
|
2
|
+
// eslint-disable-next-line no-restricted-imports
|
|
4
3
|
import { Contract, Event, EventFilter } from "ethers";
|
|
4
|
+
import { Log, SortableEvent } from "../interfaces";
|
|
5
|
+
import { delay } from "./common";
|
|
5
6
|
|
|
6
7
|
const maxRetries = 3;
|
|
7
8
|
const retrySleepTime = 10;
|
|
8
9
|
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
export function spreadEvent(args: Result
|
|
11
|
+
export function spreadEvent(args: Result | Record<string, unknown>): { [key: string]: any } {
|
|
11
12
|
const keys = Object.keys(args).filter((key: string) => isNaN(+key)); // Extract non-numeric keys.
|
|
12
13
|
|
|
13
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
const returnedObject:
|
|
15
|
+
const returnedObject: { [key: string]: unknown } = {};
|
|
15
16
|
keys.forEach((key: string) => {
|
|
16
17
|
switch (typeof args[key]) {
|
|
17
18
|
case "boolean": // fallthrough
|
|
@@ -67,15 +68,18 @@ export interface EventSearchConfig {
|
|
|
67
68
|
maxBlockLookBack?: number;
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
export const eventToLog = (event: Event): Log => ({ ...event, event: event.event!, args: spreadEvent(event.args!) });
|
|
72
|
+
|
|
70
73
|
export async function paginatedEventQuery(
|
|
71
74
|
contract: Contract,
|
|
72
75
|
filter: EventFilter,
|
|
73
76
|
searchConfig: EventSearchConfig,
|
|
74
77
|
retryCount = 0
|
|
75
|
-
): Promise<
|
|
78
|
+
): Promise<Log[]> {
|
|
76
79
|
// If the max block look back is set to 0 then we dont need to do any pagination and can query over the whole range.
|
|
77
80
|
if (searchConfig.maxBlockLookBack === 0) {
|
|
78
|
-
|
|
81
|
+
const events = await contract.queryFilter(filter, searchConfig.fromBlock, searchConfig.toBlock);
|
|
82
|
+
return events.map(eventToLog);
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
// Compute the number of queries needed. If there is no maxBlockLookBack set then we can execute the whole query in
|
|
@@ -93,6 +97,7 @@ export async function paginatedEventQuery(
|
|
|
93
97
|
.flat()
|
|
94
98
|
// Filter events by block number because ranges can include blocks that are outside the range specified for caching reasons.
|
|
95
99
|
.filter((event) => event.blockNumber >= searchConfig.fromBlock && event.blockNumber <= searchConfig.toBlock)
|
|
100
|
+
.map(eventToLog)
|
|
96
101
|
);
|
|
97
102
|
} catch (error) {
|
|
98
103
|
if (retryCount < maxRetries) {
|
|
@@ -163,7 +168,7 @@ export function getPaginatedBlockRanges({
|
|
|
163
168
|
return ranges;
|
|
164
169
|
}
|
|
165
170
|
|
|
166
|
-
export function spreadEventWithBlockNumber(event:
|
|
171
|
+
export function spreadEventWithBlockNumber(event: Log): SortableEvent {
|
|
167
172
|
return {
|
|
168
173
|
...spreadEvent(event.args),
|
|
169
174
|
blockNumber: event.blockNumber,
|
package/src/utils/JSONUtils.ts
CHANGED
|
@@ -53,7 +53,7 @@ export function jsonReplacerWithBigNumbers(_key: string, value: unknown): unknow
|
|
|
53
53
|
// We need to check if this is a big number, because the JSON parser
|
|
54
54
|
// is not aware of BigNumbers and will convert them to the string representation
|
|
55
55
|
// of the object itself which is not what we want.
|
|
56
|
-
if (BigNumber.isBigNumber(value)) {
|
|
56
|
+
if (BigNumber.isBigNumber(value) || typeof value === "bigint") {
|
|
57
57
|
return value.toString();
|
|
58
58
|
}
|
|
59
59
|
// There's a legacy issues that returns BigNumbers as { type: "BigNumber", hex: "0x..." }
|