@across-protocol/sdk 3.1.30 → 3.1.32
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/caching/Arweave/ArweaveClient.js +12 -2
- package/dist/cjs/caching/Arweave/ArweaveClient.js.map +1 -1
- package/dist/cjs/providers/index.d.ts +1 -0
- package/dist/cjs/providers/index.js +1 -0
- package/dist/cjs/providers/index.js.map +1 -1
- package/dist/cjs/providers/retryProvider.js +9 -0
- package/dist/cjs/providers/retryProvider.js.map +1 -1
- package/dist/cjs/providers/speedProvider.d.ts +10 -0
- package/dist/cjs/providers/speedProvider.js +59 -0
- package/dist/cjs/providers/speedProvider.js.map +1 -0
- package/dist/cjs/providers/utils.js +2 -0
- package/dist/cjs/providers/utils.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +2 -2
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +1 -1
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +2 -2
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/cjs/utils/common.d.ts +1 -1
- package/dist/cjs/utils/common.js +28 -22
- package/dist/cjs/utils/common.js.map +1 -1
- package/dist/esm/caching/Arweave/ArweaveClient.js +12 -2
- package/dist/esm/caching/Arweave/ArweaveClient.js.map +1 -1
- package/dist/esm/providers/index.d.ts +1 -0
- package/dist/esm/providers/index.js +1 -0
- package/dist/esm/providers/index.js.map +1 -1
- package/dist/esm/providers/retryProvider.js +10 -0
- package/dist/esm/providers/retryProvider.js.map +1 -1
- package/dist/esm/providers/speedProvider.d.ts +13 -0
- package/dist/esm/providers/speedProvider.js +63 -0
- package/dist/esm/providers/speedProvider.js.map +1 -0
- package/dist/esm/providers/utils.js +3 -1
- package/dist/esm/providers/utils.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +2 -2
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +3 -3
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +3 -1
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +4 -2
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/esm/utils/common.d.ts +2 -2
- package/dist/esm/utils/common.js +29 -23
- package/dist/esm/utils/common.js.map +1 -1
- package/dist/types/caching/Arweave/ArweaveClient.d.ts.map +1 -1
- package/dist/types/providers/index.d.ts +1 -0
- package/dist/types/providers/index.d.ts.map +1 -1
- package/dist/types/providers/retryProvider.d.ts.map +1 -1
- package/dist/types/providers/speedProvider.d.ts +14 -0
- package/dist/types/providers/speedProvider.d.ts.map +1 -0
- package/dist/types/providers/utils.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +2 -2
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +3 -1
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
- package/dist/types/utils/common.d.ts +2 -2
- package/dist/types/utils/common.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/caching/Arweave/ArweaveClient.ts +15 -7
- package/src/providers/index.ts +1 -0
- package/src/providers/retryProvider.ts +12 -0
- package/src/providers/speedProvider.ts +63 -0
- package/src/providers/utils.ts +2 -0
- package/src/relayFeeCalculator/chain-queries/baseQuery.ts +3 -3
- package/src/relayFeeCalculator/relayFeeCalculator.ts +4 -2
- package/src/utils/common.ts +8 -7
package/src/providers/index.ts
CHANGED
|
@@ -41,6 +41,18 @@ export class RetryProvider extends ethers.providers.StaticJsonRpcProvider {
|
|
|
41
41
|
...inputs
|
|
42
42
|
)
|
|
43
43
|
);
|
|
44
|
+
|
|
45
|
+
// This is added for interim testing to see whether relayer fill performance improves.
|
|
46
|
+
this.providers.forEach((provider) => {
|
|
47
|
+
const url = getOriginFromURL(provider.connection.url);
|
|
48
|
+
const { pollingInterval } = provider;
|
|
49
|
+
provider.pollingInterval = 1000;
|
|
50
|
+
logger?.debug({
|
|
51
|
+
at: "RetryProvider",
|
|
52
|
+
message: `Dropped ${url} pollingInterval ${pollingInterval} -> ${provider.pollingInterval}.`,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
44
56
|
if (this.nodeQuorumThreshold < 1 || !Number.isInteger(this.nodeQuorumThreshold)) {
|
|
45
57
|
throw new Error(
|
|
46
58
|
`nodeQuorum,Threshold cannot be < 1 and must be an integer. Currently set to ${this.nodeQuorumThreshold}`
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import { CachingMechanismInterface } from "../interfaces";
|
|
3
|
+
import { CacheProvider } from "./cachedProvider";
|
|
4
|
+
import { formatProviderError } from "./utils";
|
|
5
|
+
import { PROVIDER_CACHE_TTL } from "./constants";
|
|
6
|
+
import { Logger } from "winston";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* RPC provider that sends requests to multiple providers in parallel and returns the fastest response.
|
|
10
|
+
*/
|
|
11
|
+
export class SpeedProvider extends ethers.providers.StaticJsonRpcProvider {
|
|
12
|
+
readonly providers: ethers.providers.StaticJsonRpcProvider[];
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
params: ConstructorParameters<typeof ethers.providers.StaticJsonRpcProvider>[],
|
|
16
|
+
chainId: number,
|
|
17
|
+
readonly maxConcurrencySpeed: number,
|
|
18
|
+
readonly maxConcurrencyRateLimit: number,
|
|
19
|
+
providerCacheNamespace: string,
|
|
20
|
+
pctRpcCallsLogged: number,
|
|
21
|
+
redisClient?: CachingMechanismInterface,
|
|
22
|
+
standardTtlBlockDistance?: number,
|
|
23
|
+
noTtlBlockDistance?: number,
|
|
24
|
+
providerCacheTtl = PROVIDER_CACHE_TTL,
|
|
25
|
+
logger?: Logger
|
|
26
|
+
) {
|
|
27
|
+
// Initialize the super just with the chainId, which stops it from trying to immediately send out a .send before
|
|
28
|
+
// this derived class is initialized.
|
|
29
|
+
super(undefined, chainId);
|
|
30
|
+
this.providers = params.map(
|
|
31
|
+
(inputs) =>
|
|
32
|
+
new CacheProvider(
|
|
33
|
+
providerCacheNamespace,
|
|
34
|
+
redisClient,
|
|
35
|
+
standardTtlBlockDistance,
|
|
36
|
+
noTtlBlockDistance,
|
|
37
|
+
providerCacheTtl,
|
|
38
|
+
maxConcurrencyRateLimit,
|
|
39
|
+
pctRpcCallsLogged,
|
|
40
|
+
logger,
|
|
41
|
+
...inputs
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
override async send(method: string, params: Array<unknown>): Promise<unknown> {
|
|
47
|
+
try {
|
|
48
|
+
const providersToUse = this.providers.slice(0, this.maxConcurrencySpeed);
|
|
49
|
+
const result = await Promise.any(providersToUse.map((provider) => provider.send(method, params)));
|
|
50
|
+
return result;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
// Only thrown if all providers failed to respond
|
|
53
|
+
if (error instanceof AggregateError) {
|
|
54
|
+
const errors = error.errors.map((error, index) => {
|
|
55
|
+
const provider = this.providers[index];
|
|
56
|
+
return formatProviderError(provider, error.message);
|
|
57
|
+
});
|
|
58
|
+
throw new Error("All providers errored:\n" + errors.join("\n"));
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/providers/utils.ts
CHANGED
|
@@ -102,6 +102,8 @@ const IGNORED_FIELDS = {
|
|
|
102
102
|
"l1BatchTimestamp", // zkSync
|
|
103
103
|
"size", // Alchemy/Arbitrum (temporary)
|
|
104
104
|
"totalDifficulty", // Quicknode/Alchemy (sometimes)
|
|
105
|
+
"logsBloom", // zkSync (third-party providers return 0x0..0)
|
|
106
|
+
"transactions", // Polygon yParity field in transactions[]
|
|
105
107
|
],
|
|
106
108
|
eth_getLogs: ["blockTimestamp", "transactionLogIndex", "l1BatchNumber", "logType"],
|
|
107
109
|
};
|
|
@@ -59,14 +59,14 @@ export class QueryBase implements QueryInterface {
|
|
|
59
59
|
* @param deposit V3 deposit instance.
|
|
60
60
|
* @param relayerAddress Relayer address to simulate with.
|
|
61
61
|
* @param gasPrice Optional gas price to use for the simulation.
|
|
62
|
-
* @param
|
|
62
|
+
* @param gasUnits Optional gas units to use for the simulation.
|
|
63
63
|
* @returns The gas estimate for this function call (multiplied with the optional buffer).
|
|
64
64
|
*/
|
|
65
65
|
async getGasCosts(
|
|
66
66
|
deposit: Deposit,
|
|
67
67
|
relayer = DEFAULT_SIMULATED_RELAYER_ADDRESS,
|
|
68
68
|
gasPrice = this.fixedGasPrice,
|
|
69
|
-
|
|
69
|
+
gasUnits?: BigNumberish
|
|
70
70
|
): Promise<TransactionCostEstimate> {
|
|
71
71
|
const tx = await populateV3Relay(this.spokePool, deposit, relayer);
|
|
72
72
|
return estimateTotalGasRequiredByUnsignedTransaction(
|
|
@@ -75,7 +75,7 @@ export class QueryBase implements QueryInterface {
|
|
|
75
75
|
this.provider,
|
|
76
76
|
this.gasMarkup,
|
|
77
77
|
gasPrice,
|
|
78
|
-
|
|
78
|
+
gasUnits
|
|
79
79
|
);
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -342,6 +342,8 @@ export class RelayFeeCalculator {
|
|
|
342
342
|
* the relayer.
|
|
343
343
|
* @param relayerAddress The relayer that will be used for the gas cost simulation
|
|
344
344
|
* @param _tokenPrice The token price for normalizing fees
|
|
345
|
+
* @param gasPrice Optional gas price to use for the simulation
|
|
346
|
+
* @param gasUnits Optional gas units to use for the simulation
|
|
345
347
|
* @returns A resulting `RelayerFeeDetails` object
|
|
346
348
|
*/
|
|
347
349
|
async relayerFeeDetails(
|
|
@@ -351,7 +353,7 @@ export class RelayFeeCalculator {
|
|
|
351
353
|
relayerAddress = DEFAULT_SIMULATED_RELAYER_ADDRESS,
|
|
352
354
|
_tokenPrice?: number,
|
|
353
355
|
gasPrice?: BigNumberish,
|
|
354
|
-
|
|
356
|
+
gasUnits?: BigNumberish
|
|
355
357
|
): Promise<RelayerFeeDetails> {
|
|
356
358
|
// If the amount to relay is not provided, then we
|
|
357
359
|
// should use the full deposit amount.
|
|
@@ -370,7 +372,7 @@ export class RelayFeeCalculator {
|
|
|
370
372
|
_tokenPrice,
|
|
371
373
|
undefined,
|
|
372
374
|
gasPrice,
|
|
373
|
-
|
|
375
|
+
gasUnits
|
|
374
376
|
);
|
|
375
377
|
const gasFeeTotal = gasFeePercent.mul(amountToRelay).div(fixedPointAdjustment);
|
|
376
378
|
const capitalFeePercent = this.capitalFeePercent(
|
package/src/utils/common.ts
CHANGED
|
@@ -242,7 +242,7 @@ export type TransactionCostEstimate = {
|
|
|
242
242
|
* @param provider A valid ethers provider - will be used to reason the gas price.
|
|
243
243
|
* @param gasMarkup Markup on the estimated gas cost. For example, 0.2 will increase this resulting value 1.2x.
|
|
244
244
|
* @param gasPrice A manually provided gas price - if set, this function will not resolve the current gas price.
|
|
245
|
-
* @param
|
|
245
|
+
* @param gasUnits A manually provided gas units - if set, this function will not estimate the gas units.
|
|
246
246
|
* @returns Estimated cost in units of gas and the underlying gas token (gasPrice * estimatedGasUnits).
|
|
247
247
|
*/
|
|
248
248
|
export async function estimateTotalGasRequiredByUnsignedTransaction(
|
|
@@ -251,7 +251,7 @@ export async function estimateTotalGasRequiredByUnsignedTransaction(
|
|
|
251
251
|
provider: providers.Provider | L2Provider<providers.Provider>,
|
|
252
252
|
gasMarkup: number,
|
|
253
253
|
gasPrice?: BigNumberish,
|
|
254
|
-
|
|
254
|
+
gasUnits?: BigNumberish
|
|
255
255
|
): Promise<TransactionCostEstimate> {
|
|
256
256
|
assert(
|
|
257
257
|
gasMarkup > -1 && gasMarkup <= 4,
|
|
@@ -262,11 +262,12 @@ export async function estimateTotalGasRequiredByUnsignedTransaction(
|
|
|
262
262
|
const voidSigner = new VoidSigner(senderAddress, provider);
|
|
263
263
|
|
|
264
264
|
// Estimate the Gas units required to submit this transaction.
|
|
265
|
-
let nativeGasCost =
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
265
|
+
let nativeGasCost = gasUnits
|
|
266
|
+
? BigNumber.from(gasUnits)
|
|
267
|
+
: await voidSigner.estimateGas({
|
|
268
|
+
...unsignedTx,
|
|
269
|
+
gasPrice,
|
|
270
|
+
});
|
|
270
271
|
let tokenGasCost: BigNumber;
|
|
271
272
|
|
|
272
273
|
// OP stack is a special case; gas cost is computed by the SDK, without having to query price.
|