@across-protocol/sdk 4.1.22 → 4.1.24
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/SpokePoolClient.js +18 -12
- package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/factory.d.ts +20 -0
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +20 -0
- package/dist/cjs/utils/AddressUtils.d.ts +33 -0
- package/dist/cjs/utils/AddressUtils.js +132 -4
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/Multicall.d.ts +4 -0
- package/dist/cjs/utils/Multicall.js +33 -4
- package/dist/cjs/utils/Multicall.js.map +1 -1
- package/dist/cjs/utils/NetworkUtils.d.ts +2 -0
- package/dist/cjs/utils/NetworkUtils.js +11 -5
- package/dist/cjs/utils/NetworkUtils.js.map +1 -1
- package/dist/cjs/utils/SpokeUtils.d.ts +1 -0
- package/dist/cjs/utils/SpokeUtils.js +52 -1
- package/dist/cjs/utils/SpokeUtils.js.map +1 -1
- package/dist/cjs/utils/TokenUtils.d.ts +40 -0
- package/dist/esm/clients/SpokePoolClient.js +19 -13
- package/dist/esm/clients/SpokePoolClient.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/factory.d.ts +20 -0
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +20 -0
- package/dist/esm/utils/AddressUtils.d.ts +40 -0
- package/dist/esm/utils/AddressUtils.js +174 -2
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/Multicall.d.ts +4 -0
- package/dist/esm/utils/Multicall.js +33 -5
- package/dist/esm/utils/Multicall.js.map +1 -1
- package/dist/esm/utils/NetworkUtils.d.ts +7 -0
- package/dist/esm/utils/NetworkUtils.js +14 -4
- package/dist/esm/utils/NetworkUtils.js.map +1 -1
- package/dist/esm/utils/SpokeUtils.d.ts +1 -0
- package/dist/esm/utils/SpokeUtils.js +51 -0
- package/dist/esm/utils/SpokeUtils.js.map +1 -1
- package/dist/esm/utils/TokenUtils.d.ts +40 -0
- package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts +20 -0
- package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +20 -0
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
- package/dist/types/utils/AddressUtils.d.ts +40 -0
- package/dist/types/utils/AddressUtils.d.ts.map +1 -1
- package/dist/types/utils/Multicall.d.ts +4 -0
- package/dist/types/utils/Multicall.d.ts.map +1 -1
- package/dist/types/utils/NetworkUtils.d.ts +7 -0
- package/dist/types/utils/NetworkUtils.d.ts.map +1 -1
- package/dist/types/utils/SpokeUtils.d.ts +1 -0
- package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
- package/dist/types/utils/TokenUtils.d.ts +40 -0
- package/dist/types/utils/TokenUtils.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/clients/SpokePoolClient.ts +11 -18
- package/src/utils/AddressUtils.ts +179 -1
- package/src/utils/Multicall.ts +29 -1
- package/src/utils/NetworkUtils.ts +13 -4
- package/src/utils/SpokeUtils.ts +48 -1
package/src/utils/SpokeUtils.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { chunk } from "./ArrayUtils";
|
|
|
7
7
|
import { BigNumber, toBN, bnOne, bnZero } from "./BigNumberUtils";
|
|
8
8
|
import { keccak256 } from "./common";
|
|
9
9
|
import { isMessageEmpty } from "./DepositUtils";
|
|
10
|
+
import { blockAndAggregate, getMulticall3 } from "./Multicall";
|
|
10
11
|
import { isDefined } from "./TypeGuards";
|
|
11
12
|
import { getNetworkName } from "./NetworkUtils";
|
|
12
13
|
import { paginatedEventQuery, spreadEventWithBlockNumber } from "./EventUtils";
|
|
@@ -333,6 +334,52 @@ export function getRelayHashFromEvent(e: RelayData & { destinationChainId: numbe
|
|
|
333
334
|
return getRelayDataHash(e, e.destinationChainId);
|
|
334
335
|
}
|
|
335
336
|
|
|
337
|
+
export async function findDepositBlock(
|
|
338
|
+
spokePool: Contract,
|
|
339
|
+
depositId: BigNumber,
|
|
340
|
+
lowBlock: number,
|
|
341
|
+
highBlock?: number
|
|
342
|
+
): Promise<number | undefined> {
|
|
343
|
+
// We can only perform this search when we have a safe deposit ID.
|
|
344
|
+
if (isUnsafeDepositId(depositId)) {
|
|
345
|
+
throw new Error(`Cannot binary search for depositId ${depositId}`);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// @todo this call can be optimised away by using multicall3.blockAndAggregate(..., { blockTag: highBlockNumber }).
|
|
349
|
+
// This is left for future because the change is a bit complex, and multicall3 isn't supported in test.
|
|
350
|
+
const { chainId } = await spokePool.provider.getNetwork();
|
|
351
|
+
const multicall3 = getMulticall3(chainId, spokePool.provider);
|
|
352
|
+
assert(multicall3, `No multicall3 defined for chain ${chainId}`);
|
|
353
|
+
|
|
354
|
+
// Make sure the deposit occurred within the block range supplied by the caller.
|
|
355
|
+
const [_nDepositsLow, { blockNumber: _highBlock, returnData }] = await Promise.all([
|
|
356
|
+
spokePool.numberOfDeposits({ blockTag: lowBlock }),
|
|
357
|
+
blockAndAggregate(multicall3, [{ contract: spokePool, method: "numberOfDeposits" }], highBlock),
|
|
358
|
+
]);
|
|
359
|
+
highBlock = _highBlock;
|
|
360
|
+
assert(highBlock > lowBlock, `Block numbers out of range (${lowBlock} >= ${highBlock})`);
|
|
361
|
+
|
|
362
|
+
const nDepositsLow = toBN(_nDepositsLow);
|
|
363
|
+
const nDepositsHigh = toBN(returnData.at(0)!);
|
|
364
|
+
if (nDepositsLow.gt(depositId) || nDepositsHigh.lte(depositId)) {
|
|
365
|
+
return undefined; // Deposit did not occur within the specified block range.
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Find the lowest block number where numberOfDeposits is greater than the requested depositId.
|
|
369
|
+
do {
|
|
370
|
+
const midBlock = Math.floor((highBlock + lowBlock) / 2);
|
|
371
|
+
const nDeposits = toBN(await spokePool.numberOfDeposits({ blockTag: midBlock }));
|
|
372
|
+
|
|
373
|
+
if (nDeposits.gt(depositId)) {
|
|
374
|
+
highBlock = midBlock; // depositId occurred at or earlier than midBlock.
|
|
375
|
+
} else {
|
|
376
|
+
lowBlock = midBlock + 1; // depositId occurred later than midBlock.
|
|
377
|
+
}
|
|
378
|
+
} while (lowBlock < highBlock);
|
|
379
|
+
|
|
380
|
+
return lowBlock;
|
|
381
|
+
}
|
|
382
|
+
|
|
336
383
|
export function isUnsafeDepositId(depositId: BigNumber): boolean {
|
|
337
384
|
// SpokePool.unsafeDepositV3() produces a uint256 depositId by hashing the msg.sender, depositor and input
|
|
338
385
|
// uint256 depositNonce. There is a possibility that this resultant uint256 is less than the maxSafeDepositId (i.e.
|
|
@@ -439,7 +486,7 @@ export async function findFillBlock(
|
|
|
439
486
|
`Origin & destination chain IDs must not be equal (${destinationChainId})`
|
|
440
487
|
);
|
|
441
488
|
|
|
442
|
-
// Make sure the relay
|
|
489
|
+
// Make sure the relay was completed within the block range supplied by the caller.
|
|
443
490
|
const [initialFillStatus, finalFillStatus] = (
|
|
444
491
|
await Promise.all([
|
|
445
492
|
relayFillStatus(spokePool, relayData, lowBlockNumber, destinationChainId),
|