@across-protocol/sdk 4.3.4 → 4.3.5

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.
Files changed (24) hide show
  1. package/dist/cjs/arch/svm/utils.d.ts +2 -0
  2. package/dist/cjs/arch/svm/utils.js +53 -1
  3. package/dist/cjs/arch/svm/utils.js.map +1 -1
  4. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +13 -11
  5. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  6. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +2 -2
  7. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +45 -19
  8. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  9. package/dist/esm/arch/svm/utils.d.ts +13 -0
  10. package/dist/esm/arch/svm/utils.js +62 -1
  11. package/dist/esm/arch/svm/utils.js.map +1 -1
  12. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +14 -12
  13. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  14. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +2 -2
  15. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +55 -32
  16. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  17. package/dist/types/arch/svm/utils.d.ts +13 -0
  18. package/dist/types/arch/svm/utils.d.ts.map +1 -1
  19. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +2 -2
  20. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
  21. package/package.json +1 -1
  22. package/src/arch/svm/utils.ts +45 -1
  23. package/src/clients/BundleDataClient/BundleDataClient.ts +1 -1
  24. package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +52 -29
@@ -551,7 +551,7 @@ export class BundleDataClient {
551
551
 
552
552
  // @dev: If spoke pool client is undefined for a chain, then the end block will be null or undefined, which
553
553
  // should be handled gracefully and effectively cause this function to ignore refunds for the chain.
554
- let widestBundleBlockRanges = getWidestPossibleExpectedBlockRange(
554
+ let widestBundleBlockRanges = await getWidestPossibleExpectedBlockRange(
555
555
  chainIds,
556
556
  this.spokePoolClientManager.getSpokePoolClients(),
557
557
  getEndBlockBuffers(chainIds, this.blockRangeEndBlockBuffer),
@@ -1,7 +1,8 @@
1
1
  import { MerkleTree } from "@across-protocol/contracts/dist/utils/MerkleTree";
2
2
  import { RunningBalances, PoolRebalanceLeaf, Clients, SpokePoolTargetBalance } from "../../../interfaces";
3
- import { SpokePoolClient } from "../../SpokePoolClient";
4
- import { BigNumber, bnZero, compareAddresses, EvmAddress } from "../../../utils";
3
+ import { isSVMSpokePoolClient, SpokePoolClient } from "../../SpokePoolClient";
4
+ import { BigNumber, bnZero, chainIsEvm, chainIsSvm, compareAddresses, EvmAddress } from "../../../utils";
5
+ import { getLatestFinalizedSlotWithBlock } from "../../../arch/svm";
5
6
  import { HubPoolClient } from "../../HubPoolClient";
6
7
  import { V3DepositWithBlock } from "./shims";
7
8
  import { AcrossConfigStoreClient } from "../../AcrossConfigStoreClient";
@@ -18,25 +19,51 @@ export type PoolRebalanceRoot = {
18
19
  // when evaluating pending root bundle. The block end numbers must be less than the latest blocks for each chain ID
19
20
  // (because we can't evaluate events in the future), and greater than the expected start blocks, which are the
20
21
  // greater of 0 and the latest bundle end block for an executed root bundle proposal + 1.
21
- export function getWidestPossibleExpectedBlockRange(
22
- chainIdListForBundleEvaluationBlockNumbers: number[],
22
+ export async function getWidestPossibleExpectedBlockRange(
23
+ chainIds: number[],
23
24
  spokeClients: { [chainId: number]: SpokePoolClient },
24
25
  endBlockBuffers: number[],
25
26
  clients: Clients,
26
27
  latestMainnetBlock: number,
27
28
  enabledChains: number[]
28
- ): number[][] {
29
+ ): Promise<number[][]> {
29
30
  // We impose a buffer on the head of the chain to increase the probability that the received blocks are final.
30
31
  // Reducing the latest block that we query also gives partially filled deposits slightly more buffer for relayers
31
32
  // to fully fill the deposit and reduces the chance that the data worker includes a slow fill payment that gets
32
33
  // filled during the challenge period.
33
- const latestPossibleBundleEndBlockNumbers = chainIdListForBundleEvaluationBlockNumbers.map(
34
- (chainId: number, index) =>
35
- spokeClients[chainId] && Math.max(spokeClients[chainId].latestHeightSearched - endBlockBuffers[index], 0)
34
+ const resolveEndBlock = (chainId: number, idx: number): number =>
35
+ Math.max(spokeClients[chainId].latestHeightSearched - endBlockBuffers[idx], 0);
36
+
37
+ // Across bundles are bounded by slots on Solana. The UMIP requires that the bundle end slot is backed by a block.
38
+ const resolveSVMEndBlock = (chainId: number, idx: number): Promise<number> => {
39
+ const spokePoolClient = spokeClients[chainId];
40
+ assert(isSVMSpokePoolClient(spokePoolClient));
41
+
42
+ const maxSlot = resolveEndBlock(chainId, idx); // Respect any configured buffer for Solana.
43
+ return getLatestFinalizedSlotWithBlock(spokePoolClient.svmEventsClient.getRpc(), BigInt(maxSlot));
44
+ };
45
+
46
+ const latestPossibleBundleEndBlockNumbers = await Promise.all(
47
+ chainIds.map((chainId, idx) => {
48
+ if (!enabledChains.includes(chainId)) {
49
+ return -1; // Chain is disabled; end block is redundant and will be overridden later.
50
+ }
51
+
52
+ if (chainIsEvm(chainId)) {
53
+ return Promise.resolve(resolveEndBlock(chainId, idx));
54
+ }
55
+
56
+ if (chainIsSvm(chainId)) {
57
+ return resolveSVMEndBlock(chainId, idx);
58
+ }
59
+
60
+ assert(false, `Unsupported chainId: ${chainId}`);
61
+ })
36
62
  );
37
- return chainIdListForBundleEvaluationBlockNumbers.map((chainId: number, index) => {
63
+
64
+ return chainIds.map((chainId: number, index) => {
38
65
  const lastEndBlockForChain = clients.hubPoolClient.getLatestBundleEndBlockForChain(
39
- chainIdListForBundleEvaluationBlockNumbers,
66
+ chainIds,
40
67
  latestMainnetBlock,
41
68
  chainId
42
69
  );
@@ -45,26 +72,22 @@ export function getWidestPossibleExpectedBlockRange(
45
72
  // and end block.
46
73
  if (!enabledChains.includes(chainId)) {
47
74
  return [lastEndBlockForChain, lastEndBlockForChain];
48
- } else {
49
- // If the latest block hasn't advanced enough from the previous proposed end block, then re-use it. It will
50
- // be regarded as disabled by the Dataworker clients. Otherwise, add 1 to the previous proposed end block.
51
- if (lastEndBlockForChain >= latestPossibleBundleEndBlockNumbers[index]) {
52
- // @dev: Without this check, then `getNextBundleStartBlockNumber` could return `latestBlock+1` even when the
53
- // latest block for the chain hasn't advanced, resulting in an invalid range being produced.
54
- return [lastEndBlockForChain, lastEndBlockForChain];
55
- } else {
56
- // Chain has advanced far enough including the buffer, return range from previous proposed end block + 1 to
57
- // latest block for chain minus buffer.
58
- return [
59
- clients.hubPoolClient.getNextBundleStartBlockNumber(
60
- chainIdListForBundleEvaluationBlockNumbers,
61
- latestMainnetBlock,
62
- chainId
63
- ),
64
- latestPossibleBundleEndBlockNumbers[index],
65
- ];
66
- }
67
75
  }
76
+
77
+ // If the latest block hasn't advanced enough from the previous proposed end block, then re-use it. It will
78
+ // be regarded as disabled by the Dataworker clients. Otherwise, add 1 to the previous proposed end block.
79
+ if (lastEndBlockForChain >= latestPossibleBundleEndBlockNumbers[index]) {
80
+ // @dev: Without this check, then `getNextBundleStartBlockNumber` could return `latestBlock+1` even when the
81
+ // latest block for the chain hasn't advanced, resulting in an invalid range being produced.
82
+ return [lastEndBlockForChain, lastEndBlockForChain];
83
+ }
84
+
85
+ // Chain has advanced far enough including the buffer, return range from previous proposed end block + 1 to
86
+ // latest block for chain minus buffer.
87
+ return [
88
+ clients.hubPoolClient.getNextBundleStartBlockNumber(chainIds, latestMainnetBlock, chainId),
89
+ latestPossibleBundleEndBlockNumbers[index],
90
+ ];
68
91
  });
69
92
  }
70
93