@across-protocol/sdk 4.3.18 → 4.3.19

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 (37) hide show
  1. package/dist/cjs/arch/svm/BlockUtils.js +4 -31
  2. package/dist/cjs/arch/svm/BlockUtils.js.map +1 -1
  3. package/dist/cjs/arch/svm/SpokeUtils.d.ts +8 -8
  4. package/dist/cjs/arch/svm/SpokeUtils.js +39 -42
  5. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  6. package/dist/cjs/arch/svm/utils.d.ts +10 -2
  7. package/dist/cjs/arch/svm/utils.js +37 -3
  8. package/dist/cjs/arch/svm/utils.js.map +1 -1
  9. package/dist/cjs/clients/BaseAbstractClient.js +10 -10
  10. package/dist/cjs/clients/BaseAbstractClient.js.map +1 -1
  11. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +120 -120
  12. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +1 -1
  13. package/dist/esm/arch/svm/BlockUtils.js +4 -31
  14. package/dist/esm/arch/svm/BlockUtils.js.map +1 -1
  15. package/dist/esm/arch/svm/SpokeUtils.d.ts +8 -8
  16. package/dist/esm/arch/svm/SpokeUtils.js +41 -42
  17. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  18. package/dist/esm/arch/svm/utils.d.ts +16 -2
  19. package/dist/esm/arch/svm/utils.js +41 -2
  20. package/dist/esm/arch/svm/utils.js.map +1 -1
  21. package/dist/esm/clients/BaseAbstractClient.js +10 -10
  22. package/dist/esm/clients/BaseAbstractClient.js.map +1 -1
  23. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +120 -120
  24. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +1 -1
  25. package/dist/types/arch/svm/BlockUtils.d.ts.map +1 -1
  26. package/dist/types/arch/svm/SpokeUtils.d.ts +8 -8
  27. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
  28. package/dist/types/arch/svm/utils.d.ts +16 -2
  29. package/dist/types/arch/svm/utils.d.ts.map +1 -1
  30. package/dist/types/clients/BaseAbstractClient.d.ts.map +1 -1
  31. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +120 -120
  32. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +1 -1
  33. package/package.json +1 -1
  34. package/src/arch/svm/BlockUtils.ts +4 -12
  35. package/src/arch/svm/SpokeUtils.ts +27 -23
  36. package/src/arch/svm/utils.ts +25 -1
  37. package/src/clients/BaseAbstractClient.ts +3 -2
@@ -1,7 +1,9 @@
1
+ import assert from "assert";
1
2
  import { MessageTransmitterClient, SvmSpokeClient } from "@across-protocol/contracts";
2
3
  import { BN, BorshEventCoder, Idl } from "@coral-xyz/anchor";
3
4
  import {
4
5
  Address,
6
+ type Commitment,
5
7
  IInstruction,
6
8
  KeyPairSigner,
7
9
  address,
@@ -24,6 +26,7 @@ import { ethers } from "ethers";
24
26
  import { FillType, RelayData } from "../../interfaces";
25
27
  import { BigNumber, Address as SdkAddress, getRelayDataHash, isDefined, isUint8Array } from "../../utils";
26
28
  import { AttestedCCTPMessage, EventName, SVMEventNames, SVMProvider } from "./types";
29
+ import { getTimestampForSlot } from "./SpokeUtils";
27
30
 
28
31
  export { isSolanaError } from "@solana/kit";
29
32
 
@@ -56,6 +59,27 @@ export function toAddress(address: SdkAddress): Address<string> {
56
59
  return address.toBase58() as Address<string>;
57
60
  }
58
61
 
62
+ /**
63
+ * For a given slot (or implicit head of chain), find the immediate preceding slot that contained a block.
64
+ * @param provider SVM Provider instance.
65
+ * @param opts An object containing a specific slot number, or a Solana commitment, defaulting to "confirmed".
66
+ * @returns An object containing the slot number and the relevant timestamp for the block.
67
+ */
68
+ export async function getNearestSlotTime(
69
+ provider: SVMProvider,
70
+ opts: { slot: bigint } | { commitment: Commitment } = { commitment: "confirmed" }
71
+ ): Promise<{ slot: bigint; timestamp: number }> {
72
+ let timestamp: number | undefined;
73
+ let slot = "slot" in opts ? opts.slot : await provider.getSlot(opts).send();
74
+
75
+ do {
76
+ timestamp = await getTimestampForSlot(provider, slot);
77
+ } while (!isDefined(timestamp) && --slot);
78
+ assert(isDefined(timestamp), `Unable to resolve block time for SVM slot ${slot}`);
79
+
80
+ return { slot, timestamp };
81
+ }
82
+
59
83
  /**
60
84
  * Resolve the latest finalized slot, and then work backwards to find the nearest slot containing a block.
61
85
  * In most cases the first-resolved slot should also have a block. Avoid making arbitrary decisions about
@@ -66,7 +90,7 @@ export async function getLatestFinalizedSlotWithBlock(
66
90
  maxSlot: bigint,
67
91
  maxLookback = 1000
68
92
  ): Promise<number> {
69
- const finalizedSlot = await provider.getSlot({ commitment: "finalized" }).send();
93
+ const { slot: finalizedSlot } = await getNearestSlotTime(provider, { commitment: "finalized" });
70
94
  const endSlot = Math.min(Number(maxSlot), Number(finalizedSlot));
71
95
  const opts = { maxSupportedTransactionVersion: 0, transactionDetails: "none", rewards: false } as const;
72
96
 
@@ -1,7 +1,7 @@
1
1
  import { providers } from "ethers";
2
2
  import { CachingMechanismInterface } from "../interfaces";
3
3
  import { EventSearchConfig, isDefined, MakeOptional } from "../utils";
4
- import { SVMProvider } from "../arch/svm";
4
+ import { getNearestSlotTime, SVMProvider } from "../arch/svm";
5
5
 
6
6
  export enum UpdateFailureReason {
7
7
  NotReady,
@@ -72,7 +72,8 @@ export abstract class BaseAbstractClient {
72
72
  if (provider instanceof providers.Provider) {
73
73
  to = await provider.getBlockNumber();
74
74
  } else {
75
- to = Number(await provider.getSlot({ commitment: "confirmed" }).send());
75
+ const { slot } = await getNearestSlotTime(provider);
76
+ to = Number(slot);
76
77
  }
77
78
  if (to < from) {
78
79
  return UpdateFailureReason.AlreadyUpdated;