@across-protocol/sdk 3.1.31 → 3.1.33
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/clients/BundleDataClient/BundleDataClient.js +10 -12
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient.d.ts +3 -1
- package/dist/cjs/clients/SpokePoolClient.js +16 -0
- package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
- package/dist/cjs/providers/constants.d.ts +0 -1
- package/dist/cjs/providers/constants.js +1 -2
- package/dist/cjs/providers/constants.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/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/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/clients/BundleDataClient/BundleDataClient.js +11 -13
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient.d.ts +9 -1
- package/dist/esm/clients/SpokePoolClient.js +23 -1
- package/dist/esm/clients/SpokePoolClient.js.map +1 -1
- package/dist/esm/providers/constants.d.ts +0 -4
- package/dist/esm/providers/constants.js +0 -4
- package/dist/esm/providers/constants.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/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/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/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient.d.ts +9 -1
- package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/providers/constants.d.ts +0 -4
- package/dist/types/providers/constants.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/speedProvider.d.ts +14 -0
- package/dist/types/providers/speedProvider.d.ts.map +1 -0
- 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/clients/BundleDataClient/BundleDataClient.ts +3 -5
- package/src/clients/SpokePoolClient.ts +21 -1
- package/src/providers/constants.ts +0 -5
- package/src/providers/index.ts +1 -0
- package/src/providers/speedProvider.ts +63 -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/package.json
CHANGED
|
@@ -175,13 +175,21 @@ export class ArweaveClient {
|
|
|
175
175
|
});
|
|
176
176
|
const results = await Promise.all(
|
|
177
177
|
entries.map(async (edge) => {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
178
|
+
try {
|
|
179
|
+
const data = await this.get<T>(edge.node.id, validator);
|
|
180
|
+
return isDefined(data)
|
|
181
|
+
? {
|
|
182
|
+
data,
|
|
183
|
+
hash: edge.node.id,
|
|
184
|
+
}
|
|
185
|
+
: null;
|
|
186
|
+
} catch (e) {
|
|
187
|
+
this.logger.warn({
|
|
188
|
+
at: "ArweaveClient:getByTopic",
|
|
189
|
+
message: `Bad request for Arweave topic ${edge.node.id}: ${e}`,
|
|
190
|
+
});
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
185
193
|
})
|
|
186
194
|
);
|
|
187
195
|
return results.filter(isDefined);
|
|
@@ -29,7 +29,6 @@ import {
|
|
|
29
29
|
getImpliedBundleBlockRanges,
|
|
30
30
|
isSlowFill,
|
|
31
31
|
mapAsync,
|
|
32
|
-
relayFillStatus,
|
|
33
32
|
bnUint32Max,
|
|
34
33
|
} from "../../utils";
|
|
35
34
|
import { BigNumber } from "ethers";
|
|
@@ -1125,8 +1124,7 @@ export class BundleDataClient {
|
|
|
1125
1124
|
) {
|
|
1126
1125
|
// If we haven't seen a fill matching this deposit, then we need to rule out that it was filled a long time ago
|
|
1127
1126
|
// by checkings its on-chain fill status.
|
|
1128
|
-
const fillStatus = await relayFillStatus(
|
|
1129
|
-
spokePoolClients[destinationChainId].spokePool,
|
|
1127
|
+
const fillStatus = await spokePoolClients[destinationChainId].relayFillStatus(
|
|
1130
1128
|
deposit,
|
|
1131
1129
|
// We can assume that in production
|
|
1132
1130
|
// the block ranges passed into this function would never contain blocks where the spoke pool client
|
|
@@ -1313,8 +1311,8 @@ export class BundleDataClient {
|
|
|
1313
1311
|
const startBlockForChain = Math.min(_startBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1314
1312
|
const endBlockForChain = Math.min(_endBlockForChain, spokePoolClient.latestBlockSearched);
|
|
1315
1313
|
const [startTime, endTime] = [
|
|
1316
|
-
|
|
1317
|
-
|
|
1314
|
+
await spokePoolClient.getTimestampForBlock(startBlockForChain),
|
|
1315
|
+
await spokePoolClient.getTimestampForBlock(endBlockForChain),
|
|
1318
1316
|
];
|
|
1319
1317
|
// Sanity checks:
|
|
1320
1318
|
assert(endTime >= startTime, "End time should be greater than start time.");
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
Deposit,
|
|
26
26
|
DepositWithBlock,
|
|
27
27
|
Fill,
|
|
28
|
+
FillStatus,
|
|
28
29
|
FillWithBlock,
|
|
29
30
|
FilledV3RelayEvent,
|
|
30
31
|
RealizedLpFee,
|
|
@@ -38,7 +39,7 @@ import {
|
|
|
38
39
|
} from "../interfaces";
|
|
39
40
|
import { SpokePool } from "../typechain";
|
|
40
41
|
import { getNetworkName } from "../utils/NetworkUtils";
|
|
41
|
-
import { getBlockRangeForDepositId, getDepositIdAtBlock } from "../utils/SpokeUtils";
|
|
42
|
+
import { getBlockRangeForDepositId, getDepositIdAtBlock, relayFillStatus } from "../utils/SpokeUtils";
|
|
42
43
|
import { BaseAbstractClient, isUpdateFailureReason, UpdateFailureReason } from "./BaseAbstractClient";
|
|
43
44
|
import { HubPoolClient } from "./HubPoolClient";
|
|
44
45
|
import { AcrossConfigStoreClient } from "./AcrossConfigStoreClient";
|
|
@@ -883,4 +884,23 @@ export class SpokePoolClient extends BaseAbstractClient {
|
|
|
883
884
|
this.configStoreClient?.isChainLiteChainAtTimestamp(deposit.destinationChainId, deposit.quoteTimestamp) ?? false
|
|
884
885
|
);
|
|
885
886
|
}
|
|
887
|
+
|
|
888
|
+
public async getTimestampForBlock(blockTag: number): Promise<number> {
|
|
889
|
+
const block = await this.spokePool.provider.getBlock(blockTag);
|
|
890
|
+
return Number(block.timestamp);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Find the amount filled for a deposit at a particular block.
|
|
895
|
+
* @param relayData Deposit information that is used to complete a fill.
|
|
896
|
+
* @param blockTag Block tag (numeric or "latest") to query at.
|
|
897
|
+
* @returns The amount filled for the specified deposit at the requested block (or latest).
|
|
898
|
+
*/
|
|
899
|
+
public relayFillStatus(
|
|
900
|
+
relayData: RelayData,
|
|
901
|
+
blockTag?: number | "latest",
|
|
902
|
+
destinationChainId?: number
|
|
903
|
+
): Promise<FillStatus> {
|
|
904
|
+
return relayFillStatus(this.spokePool, relayData, blockTag, destinationChainId);
|
|
905
|
+
}
|
|
886
906
|
}
|
|
@@ -4,8 +4,3 @@ export const BLOCK_NUMBER_TTL = 60;
|
|
|
4
4
|
// This is the TTL for the provider cache.
|
|
5
5
|
export const PROVIDER_CACHE_TTL = 3600;
|
|
6
6
|
export const PROVIDER_CACHE_TTL_MODIFIER = 0.15;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A default timeout for requests of 60 seconds.
|
|
10
|
-
*/
|
|
11
|
-
export const defaultTimeout = 60 * 1000;
|
package/src/providers/index.ts
CHANGED
|
@@ -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
|
+
}
|
|
@@ -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.
|