@across-protocol/sdk 4.0.3-beta.0 → 4.0.4

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 (109) hide show
  1. package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +2 -1
  2. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +25 -9
  3. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  4. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +1 -1
  5. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +4 -4
  6. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  7. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +6 -3
  8. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +5 -4
  9. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  10. package/dist/cjs/clients/SpokePoolClient.d.ts +1 -1
  11. package/dist/cjs/clients/SpokePoolClient.js +130 -84
  12. package/dist/cjs/clients/SpokePoolClient.js.map +1 -1
  13. package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +16 -2
  14. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +77 -35
  15. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  16. package/dist/cjs/constants.d.ts +2 -1
  17. package/dist/cjs/constants.js +3 -2
  18. package/dist/cjs/constants.js.map +1 -1
  19. package/dist/cjs/interfaces/SpokePool.d.ts +4 -2
  20. package/dist/cjs/package.json +1 -0
  21. package/dist/cjs/utils/AddressUtils.d.ts +1 -0
  22. package/dist/cjs/utils/AddressUtils.js +5 -1
  23. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  24. package/dist/cjs/utils/CachingUtils.js +1 -1
  25. package/dist/cjs/utils/CachingUtils.js.map +1 -1
  26. package/dist/cjs/utils/DepositUtils.d.ts +1 -1
  27. package/dist/cjs/utils/DepositUtils.js +11 -8
  28. package/dist/cjs/utils/DepositUtils.js.map +1 -1
  29. package/dist/cjs/utils/FlowUtils.d.ts +4 -3
  30. package/dist/cjs/utils/FlowUtils.js +5 -1
  31. package/dist/cjs/utils/FlowUtils.js.map +1 -1
  32. package/dist/cjs/utils/SpokeUtils.d.ts +6 -3
  33. package/dist/cjs/utils/SpokeUtils.js +2 -2
  34. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  35. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +2 -1
  36. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +29 -13
  37. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  38. package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +1 -1
  39. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +2 -2
  40. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  41. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +6 -3
  42. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +3 -2
  43. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  44. package/dist/esm/clients/SpokePoolClient.d.ts +1 -6
  45. package/dist/esm/clients/SpokePoolClient.js +138 -94
  46. package/dist/esm/clients/SpokePoolClient.js.map +1 -1
  47. package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +16 -2
  48. package/dist/esm/clients/mocks/MockSpokePoolClient.js +79 -37
  49. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  50. package/dist/esm/constants.d.ts +2 -1
  51. package/dist/esm/constants.js +6 -1
  52. package/dist/esm/constants.js.map +1 -1
  53. package/dist/esm/interfaces/SpokePool.d.ts +4 -2
  54. package/dist/esm/package.json +1 -0
  55. package/dist/esm/utils/AddressUtils.d.ts +1 -0
  56. package/dist/esm/utils/AddressUtils.js +7 -4
  57. package/dist/esm/utils/AddressUtils.js.map +1 -1
  58. package/dist/esm/utils/CachingUtils.js +2 -2
  59. package/dist/esm/utils/CachingUtils.js.map +1 -1
  60. package/dist/esm/utils/DepositUtils.d.ts +1 -1
  61. package/dist/esm/utils/DepositUtils.js +12 -9
  62. package/dist/esm/utils/DepositUtils.js.map +1 -1
  63. package/dist/esm/utils/FlowUtils.d.ts +4 -3
  64. package/dist/esm/utils/FlowUtils.js +6 -1
  65. package/dist/esm/utils/FlowUtils.js.map +1 -1
  66. package/dist/esm/utils/SpokeUtils.d.ts +6 -3
  67. package/dist/esm/utils/SpokeUtils.js +2 -2
  68. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  69. package/dist/esm/utils/abi/typechain/Multicall3.d.ts +4 -1
  70. package/dist/esm/utils/abi/typechain/factories/Multicall3__factory.js.map +1 -1
  71. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +2 -1
  72. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  73. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +1 -1
  74. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
  75. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +6 -3
  76. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
  77. package/dist/types/clients/SpokePoolClient.d.ts +1 -6
  78. package/dist/types/clients/SpokePoolClient.d.ts.map +1 -1
  79. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +16 -2
  80. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
  81. package/dist/types/constants.d.ts +2 -1
  82. package/dist/types/constants.d.ts.map +1 -1
  83. package/dist/types/interfaces/SpokePool.d.ts +4 -2
  84. package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
  85. package/dist/types/utils/AddressUtils.d.ts +1 -0
  86. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  87. package/dist/types/utils/DepositUtils.d.ts +1 -1
  88. package/dist/types/utils/DepositUtils.d.ts.map +1 -1
  89. package/dist/types/utils/FlowUtils.d.ts +4 -3
  90. package/dist/types/utils/FlowUtils.d.ts.map +1 -1
  91. package/dist/types/utils/SpokeUtils.d.ts +6 -3
  92. package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
  93. package/dist/types/utils/abi/typechain/Multicall3.d.ts +4 -1
  94. package/dist/types/utils/abi/typechain/Multicall3.d.ts.map +1 -1
  95. package/dist/types/utils/abi/typechain/common.d.ts.map +1 -1
  96. package/dist/types/utils/abi/typechain/factories/Multicall3__factory.d.ts.map +1 -1
  97. package/package.json +1 -1
  98. package/src/clients/BundleDataClient/BundleDataClient.ts +30 -13
  99. package/src/clients/BundleDataClient/utils/FillUtils.ts +2 -2
  100. package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +6 -3
  101. package/src/clients/SpokePoolClient.ts +71 -34
  102. package/src/clients/mocks/MockSpokePoolClient.ts +125 -29
  103. package/src/constants.ts +6 -1
  104. package/src/interfaces/SpokePool.ts +4 -2
  105. package/src/utils/AddressUtils.ts +8 -4
  106. package/src/utils/CachingUtils.ts +2 -2
  107. package/src/utils/DepositUtils.ts +8 -3
  108. package/src/utils/FlowUtils.ts +10 -4
  109. package/src/utils/SpokeUtils.ts +7 -4
@@ -39,10 +39,14 @@ export function compareAddressesSimple(addressA?: string, addressB?: string): bo
39
39
  return addressA.toLowerCase() === addressB.toLowerCase();
40
40
  }
41
41
 
42
- // Converts an input (assumed to be) bytes32 string into a bytes20 string.
43
- // If the input is not a bytes32 but is less than type(uint160).max, then this function
44
- // will still succeed.
45
- // Throws an error if the string as an unsigned integer is greater than type(uint160).max.
42
+ // Converts an input hex data string into a bytes32 string. Note that the output bytes will be lowercase
43
+ // so that it naturally matches with ethers event data.
44
+ // Throws an error if the input string is already greater than 32 bytes.
45
+ export function toBytes32(address: string): string {
46
+ return utils.hexZeroPad(address, 32).toLowerCase();
47
+ }
48
+
49
+ // Checks if the input string can be coerced into a bytes20 evm address. Returns true if it is possible, and false otherwise.
46
50
  export function toAddress(hexString: string): string {
47
51
  // rawAddress is the address which is not properly checksummed.
48
52
  const rawAddress = utils.hexZeroPad(utils.hexStripZeros(hexString), 20);
@@ -2,7 +2,7 @@ import { DEFAULT_CACHING_SAFE_LAG, DEFAULT_CACHING_TTL } from "../constants";
2
2
  import { CachingMechanismInterface, Deposit, Fill, SlowFillRequest } from "../interfaces";
3
3
  import { assert } from "./LogUtils";
4
4
  import { composeRevivers, objectWithBigNumberReviver } from "./ReviverUtils";
5
- import { getRelayHashFromEvent } from "./SpokeUtils";
5
+ import { getRelayEventKey } from "./SpokeUtils";
6
6
  import { getCurrentTime } from "./TimeUtils";
7
7
  import { isDefined } from "./TypeGuards";
8
8
 
@@ -51,6 +51,6 @@ export async function setDepositInCache(
51
51
  * @returns The key for caching the event.
52
52
  */
53
53
  export function getDepositKey(bridgeEvent: Deposit | Fill | SlowFillRequest): string {
54
- const relayHash = getRelayHashFromEvent(bridgeEvent);
54
+ const relayHash = getRelayEventKey(bridgeEvent);
55
55
  return `deposit_${bridgeEvent.originChainId}_${bridgeEvent.depositId.toString()}_${relayHash}`;
56
56
  }
@@ -3,9 +3,10 @@ import { SpokePoolClient } from "../clients";
3
3
  import { DEFAULT_CACHING_TTL, EMPTY_MESSAGE, ZERO_BYTES } from "../constants";
4
4
  import { CachingMechanismInterface, Deposit, DepositWithBlock, Fill, SlowFillRequest } from "../interfaces";
5
5
  import { getNetworkName } from "./NetworkUtils";
6
+ import { bnZero } from "./BigNumberUtils";
6
7
  import { getDepositInCache, getDepositKey, setDepositInCache } from "./CachingUtils";
7
8
  import { validateFillForDeposit } from "./FlowUtils";
8
- import { isUnsafeDepositId } from "./SpokeUtils";
9
+ import { getMessageHash, isUnsafeDepositId } from "./SpokeUtils";
9
10
  import { getCurrentTime } from "./TimeUtils";
10
11
  import { isDefined } from "./TypeGuards";
11
12
  import { isDepositFormedCorrectly } from "./ValidatorUtils";
@@ -122,6 +123,8 @@ export async function queryHistoricalDepositForFill(
122
123
  }
123
124
  }
124
125
 
126
+ deposit.messageHash ??= getMessageHash(deposit.message);
127
+
125
128
  const match = validateFillForDeposit(fill, deposit);
126
129
  if (match.valid) {
127
130
  return { found: true, deposit };
@@ -146,8 +149,10 @@ export function isZeroValueDeposit(deposit: Pick<Deposit, "inputAmount" | "messa
146
149
  return deposit.inputAmount.eq(0) && isMessageEmpty(deposit.message);
147
150
  }
148
151
 
149
- export function isZeroValueFillOrSlowFillRequest(e: Pick<Fill | SlowFillRequest, "inputAmount" | "message">): boolean {
150
- return e.inputAmount.eq(0) && isFillOrSlowFillRequestMessageEmpty(e.message);
152
+ export function isZeroValueFillOrSlowFillRequest(
153
+ e: Pick<Fill | SlowFillRequest, "inputAmount" | "messageHash">
154
+ ): boolean {
155
+ return e.inputAmount.eq(bnZero) && e.messageHash === ZERO_BYTES;
151
156
  }
152
157
 
153
158
  /**
@@ -1,5 +1,6 @@
1
1
  import { isDefined } from "../utils";
2
2
  import { Deposit, RelayData } from "../interfaces";
3
+ import { UNDEFINED_MESSAGE_HASH } from "../constants";
3
4
 
4
5
  export const RELAYDATA_KEYS = [
5
6
  "depositId",
@@ -14,14 +15,14 @@ export const RELAYDATA_KEYS = [
14
15
  "fillDeadline",
15
16
  "exclusivityDeadline",
16
17
  "exclusiveRelayer",
17
- "message",
18
+ "messageHash",
18
19
  ] as const;
19
20
 
20
21
  // Ensure that each deposit element is included with the same value in the fill. This includes all elements defined
21
22
  // by the depositor as well as destinationToken, which are pulled from other clients.
22
23
  export function validateFillForDeposit(
23
- relayData: RelayData & { destinationChainId: number },
24
- deposit?: Deposit
24
+ relayData: Omit<RelayData, "message"> & { messageHash: string; destinationChainId: number },
25
+ deposit?: Omit<Deposit, "quoteTimestamp" | "fromLiteChain" | "toLiteChain">
25
26
  ): { valid: true } | { valid: false; reason: string } {
26
27
  if (deposit === undefined) {
27
28
  return { valid: false, reason: "Deposit is undefined" };
@@ -30,7 +31,12 @@ export function validateFillForDeposit(
30
31
  // Note: this short circuits when a key is found where the comparison doesn't match.
31
32
  // TODO: if we turn on "strict" in the tsconfig, the elements of FILL_DEPOSIT_COMPARISON_KEYS will be automatically
32
33
  // validated against the fields in Fill and Deposit, generating an error if there is a discrepency.
33
- const invalidKey = RELAYDATA_KEYS.find((key) => relayData[key].toString() !== deposit[key].toString());
34
+ let invalidKey = RELAYDATA_KEYS.find((key) => relayData[key].toString() !== deposit[key].toString());
35
+
36
+ // There should be no paths for `messageHash` to be unset, but mask it off anyway.
37
+ if (!isDefined(invalidKey) && [relayData.messageHash, deposit.messageHash].includes(UNDEFINED_MESSAGE_HASH)) {
38
+ invalidKey = "messageHash";
39
+ }
34
40
 
35
41
  return isDefined(invalidKey)
36
42
  ? { valid: false, reason: `${invalidKey} mismatch (${relayData[invalidKey]} != ${deposit[invalidKey]})` }
@@ -1,7 +1,7 @@
1
1
  import assert from "assert";
2
2
  import { BytesLike, Contract, PopulatedTransaction, providers, utils as ethersUtils } from "ethers";
3
3
  import { CHAIN_IDs, MAX_SAFE_DEPOSIT_ID, ZERO_ADDRESS, ZERO_BYTES } from "../constants";
4
- import { Deposit, Fill, FillStatus, FillWithBlock, RelayData, SlowFillRequest } from "../interfaces";
4
+ import { Deposit, FillStatus, FillWithBlock, RelayData } from "../interfaces";
5
5
  import { SpokePoolClient } from "../clients";
6
6
  import { chunk } from "./ArrayUtils";
7
7
  import { BigNumber, toBN, bnOne, bnZero } from "./BigNumberUtils";
@@ -64,7 +64,9 @@ export function populateV3Relay(
64
64
  * is required to compute a complete RelayData hash.
65
65
  * note: This function should _not_ be used to query the SpokePool.fillStatuses mapping.
66
66
  */
67
- export function getRelayEventKey(data: RelayData & { destinationChainId: number }): string {
67
+ export function getRelayEventKey(
68
+ data: Omit<RelayData, "message"> & { messageHash: string; destinationChainId: number }
69
+ ): string {
68
70
  return [
69
71
  data.depositor,
70
72
  data.recipient,
@@ -78,7 +80,7 @@ export function getRelayEventKey(data: RelayData & { destinationChainId: number
78
80
  data.depositId,
79
81
  data.fillDeadline,
80
82
  data.exclusivityDeadline,
81
- data.message,
83
+ data.messageHash,
82
84
  ]
83
85
  .map(String)
84
86
  .join("-");
@@ -284,7 +286,7 @@ export function getRelayDataHash(relayData: RelayData, destinationChainId: numbe
284
286
  );
285
287
  }
286
288
 
287
- export function getRelayHashFromEvent(e: Deposit | Fill | SlowFillRequest): string {
289
+ export function getRelayHashFromEvent(e: RelayData & { destinationChainId: number }): string {
288
290
  return getRelayDataHash(e, e.destinationChainId);
289
291
  }
290
292
 
@@ -455,6 +457,7 @@ export async function findFillEvent(
455
457
  const fill = {
456
458
  ...spreadEventWithBlockNumber(event),
457
459
  destinationChainId,
460
+ messageHash: getMessageHash(event.args.message),
458
461
  } as FillWithBlock;
459
462
  return fill;
460
463
  }