@across-protocol/sdk 4.2.16-alpha.0 → 4.2.16-alpha.2

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 (211) hide show
  1. package/dist/cjs/arch/evm/SpokeUtils.d.ts +6 -2
  2. package/dist/cjs/arch/evm/SpokeUtils.js +21 -6
  3. package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
  4. package/dist/cjs/arch/svm/SpokeUtils.d.ts +9 -5
  5. package/dist/cjs/arch/svm/SpokeUtils.js +70 -71
  6. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  7. package/dist/cjs/arch/svm/utils.d.ts +3 -5
  8. package/dist/cjs/arch/svm/utils.js +20 -28
  9. package/dist/cjs/arch/svm/utils.js.map +1 -1
  10. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  11. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
  12. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  13. package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  14. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +60 -56
  15. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  16. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +13 -13
  17. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  18. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  19. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +3 -2
  20. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  21. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
  22. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  23. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +3 -3
  24. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  25. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
  26. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +11 -8
  27. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  28. package/dist/cjs/clients/HubPoolClient.d.ts +21 -21
  29. package/dist/cjs/clients/HubPoolClient.js +83 -58
  30. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  31. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
  32. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  33. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  34. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +64 -45
  35. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  36. package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +9 -9
  37. package/dist/cjs/clients/mocks/MockHubPoolClient.js +15 -9
  38. package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
  39. package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  40. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +40 -36
  41. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  42. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  43. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +3 -4
  44. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  45. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.d.ts +3 -3
  46. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +2 -2
  47. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  48. package/dist/cjs/interfaces/HubPool.d.ts +19 -14
  49. package/dist/cjs/interfaces/SpokePool.d.ts +13 -13
  50. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
  51. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +10 -10
  52. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  53. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +5 -5
  54. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +42 -49
  55. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  56. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
  57. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +7 -7
  58. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  59. package/dist/cjs/utils/AddressUtils.d.ts +12 -13
  60. package/dist/cjs/utils/AddressUtils.js +44 -46
  61. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  62. package/dist/cjs/utils/EventUtils.js +1 -1
  63. package/dist/cjs/utils/EventUtils.js.map +1 -1
  64. package/dist/cjs/utils/SpokeUtils.d.ts +3 -3
  65. package/dist/cjs/utils/SpokeUtils.js +4 -22
  66. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  67. package/dist/cjs/utils/TokenUtils.d.ts +4 -4
  68. package/dist/cjs/utils/TokenUtils.js +4 -6
  69. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  70. package/dist/esm/arch/evm/SpokeUtils.d.ts +6 -2
  71. package/dist/esm/arch/evm/SpokeUtils.js +22 -7
  72. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  73. package/dist/esm/arch/svm/SpokeUtils.d.ts +9 -5
  74. package/dist/esm/arch/svm/SpokeUtils.js +74 -75
  75. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  76. package/dist/esm/arch/svm/utils.d.ts +6 -8
  77. package/dist/esm/arch/svm/utils.js +21 -27
  78. package/dist/esm/arch/svm/utils.js.map +1 -1
  79. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  80. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
  81. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  82. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  83. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +61 -57
  84. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  85. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +14 -14
  86. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  87. package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  88. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +5 -3
  89. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  90. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
  91. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  92. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +4 -4
  93. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  94. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
  95. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +12 -9
  96. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  97. package/dist/esm/clients/HubPoolClient.d.ts +23 -22
  98. package/dist/esm/clients/HubPoolClient.js +97 -63
  99. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  100. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +2 -2
  101. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  102. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  103. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +67 -47
  104. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  105. package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +9 -9
  106. package/dist/esm/clients/mocks/MockHubPoolClient.js +16 -10
  107. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  108. package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  109. package/dist/esm/clients/mocks/MockSpokePoolClient.js +42 -38
  110. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  111. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  112. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +4 -5
  113. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  114. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.d.ts +3 -3
  115. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +3 -3
  116. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  117. package/dist/esm/interfaces/HubPool.d.ts +19 -14
  118. package/dist/esm/interfaces/SpokePool.d.ts +13 -13
  119. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
  120. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +11 -11
  121. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  122. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +6 -6
  123. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +44 -51
  124. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  125. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
  126. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +8 -8
  127. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  128. package/dist/esm/utils/AddressUtils.d.ts +13 -14
  129. package/dist/esm/utils/AddressUtils.js +50 -56
  130. package/dist/esm/utils/AddressUtils.js.map +1 -1
  131. package/dist/esm/utils/EventUtils.js +2 -2
  132. package/dist/esm/utils/EventUtils.js.map +1 -1
  133. package/dist/esm/utils/SpokeUtils.d.ts +3 -8
  134. package/dist/esm/utils/SpokeUtils.js +4 -26
  135. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  136. package/dist/esm/utils/TokenUtils.d.ts +4 -16
  137. package/dist/esm/utils/TokenUtils.js +5 -7
  138. package/dist/esm/utils/TokenUtils.js.map +1 -1
  139. package/dist/types/arch/evm/SpokeUtils.d.ts +6 -2
  140. package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
  141. package/dist/types/arch/svm/SpokeUtils.d.ts +9 -5
  142. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
  143. package/dist/types/arch/svm/utils.d.ts +6 -8
  144. package/dist/types/arch/svm/utils.d.ts.map +1 -1
  145. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  146. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
  147. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  148. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  149. package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
  150. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  151. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
  152. package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts.map +1 -1
  153. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
  154. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
  155. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
  156. package/dist/types/clients/HubPoolClient.d.ts +23 -22
  157. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  158. package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
  159. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  160. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  161. package/dist/types/clients/mocks/MockHubPoolClient.d.ts +9 -9
  162. package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
  163. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  164. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
  165. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  166. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts.map +1 -1
  167. package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts +3 -3
  168. package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts.map +1 -1
  169. package/dist/types/interfaces/HubPool.d.ts +19 -14
  170. package/dist/types/interfaces/HubPool.d.ts.map +1 -1
  171. package/dist/types/interfaces/SpokePool.d.ts +13 -13
  172. package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
  173. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
  174. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  175. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +6 -6
  176. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
  177. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
  178. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  179. package/dist/types/utils/AddressUtils.d.ts +13 -14
  180. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  181. package/dist/types/utils/SpokeUtils.d.ts +3 -8
  182. package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
  183. package/dist/types/utils/TokenUtils.d.ts +4 -16
  184. package/dist/types/utils/TokenUtils.d.ts.map +1 -1
  185. package/package.json +2 -3
  186. package/src/arch/evm/SpokeUtils.ts +52 -12
  187. package/src/arch/svm/SpokeUtils.ts +108 -59
  188. package/src/arch/svm/utils.ts +11 -20
  189. package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +7 -4
  190. package/src/clients/BundleDataClient/BundleDataClient.ts +57 -53
  191. package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +28 -13
  192. package/src/clients/BundleDataClient/utils/FillUtils.ts +10 -4
  193. package/src/clients/BundleDataClient/utils/MerkleTreeUtils.ts +7 -1
  194. package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +4 -4
  195. package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +13 -9
  196. package/src/clients/HubPoolClient.ts +126 -82
  197. package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +6 -0
  198. package/src/clients/SpokePoolClient/SpokePoolClient.ts +118 -35
  199. package/src/clients/mocks/MockHubPoolClient.ts +24 -19
  200. package/src/clients/mocks/MockSpokePoolClient.ts +39 -27
  201. package/src/clients/mocks/MockSvmCpiEventsClient.ts +3 -5
  202. package/src/clients/mocks/MockSvmSpokePoolClient.ts +12 -3
  203. package/src/interfaces/HubPool.ts +23 -14
  204. package/src/interfaces/SpokePool.ts +13 -13
  205. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +14 -12
  206. package/src/relayFeeCalculator/chain-queries/svmQuery.ts +42 -46
  207. package/src/relayFeeCalculator/relayFeeCalculator.ts +20 -12
  208. package/src/utils/AddressUtils.ts +58 -60
  209. package/src/utils/EventUtils.ts +2 -2
  210. package/src/utils/SpokeUtils.ts +11 -33
  211. package/src/utils/TokenUtils.ts +10 -11
@@ -39,10 +39,9 @@ import {
39
39
  bnUint32Max,
40
40
  isZeroValueDeposit,
41
41
  isZeroValueFillOrSlowFillRequest,
42
- chainIsEvm,
43
- isValidEvmAddress,
44
42
  duplicateEvent,
45
43
  invalidOutputToken,
44
+ Address,
46
45
  } from "../../utils";
47
46
  import winston from "winston";
48
47
  import {
@@ -67,22 +66,21 @@ type DataCache = Record<string, Promise<LoadDataReturnValue>>;
67
66
  // V3 dictionary helper functions
68
67
  function updateExpiredDepositsV3(dict: ExpiredDepositsToRefundV3, deposit: V3DepositWithBlock): void {
69
68
  // A deposit refund for a deposit is invalid if the depositor has a bytes32 address input for an EVM chain. It is valid otherwise.
70
- if (chainIsEvm(deposit.originChainId) && !isValidEvmAddress(deposit.depositor)) {
69
+ if (!deposit.depositor.isValidOn(deposit.originChainId)) {
71
70
  return;
72
71
  }
72
+
73
73
  const { originChainId, inputToken } = deposit;
74
- if (!dict?.[originChainId]?.[inputToken]) {
75
- assign(dict, [originChainId, inputToken], []);
76
- }
77
- dict[originChainId][inputToken].push(deposit);
74
+ dict[originChainId] ??= {};
75
+ dict[originChainId][inputToken.toBytes32()] ??= [];
76
+ dict[originChainId][inputToken.toBytes32()].push(deposit);
78
77
  }
79
78
 
80
79
  function updateBundleDepositsV3(dict: BundleDepositsV3, deposit: V3DepositWithBlock): void {
81
80
  const { originChainId, inputToken } = deposit;
82
- if (!dict?.[originChainId]?.[inputToken]) {
83
- assign(dict, [originChainId, inputToken], []);
84
- }
85
- dict[originChainId][inputToken].push(deposit);
81
+ dict[originChainId] ??= {};
82
+ dict[originChainId][inputToken.toBytes32()] ??= [];
83
+ dict[originChainId][inputToken.toBytes32()].push(deposit);
86
84
  }
87
85
 
88
86
  function updateBundleFillsV3(
@@ -90,29 +88,29 @@ function updateBundleFillsV3(
90
88
  fill: V3FillWithBlock,
91
89
  lpFeePct: BigNumber,
92
90
  repaymentChainId: number,
93
- repaymentToken: string,
94
- repaymentAddress: string
91
+ repaymentToken: Address,
92
+ repaymentAddress: Address
95
93
  ): void {
96
94
  // We shouldn't pass any unrepayable fills into this function, so we perform an extra safety check.
97
- if (chainIsEvm(repaymentChainId) && !isValidEvmAddress(fill.relayer)) {
95
+ if (fill.relayer.isValidOn(repaymentChainId)) {
98
96
  return;
99
97
  }
100
- if (!dict?.[repaymentChainId]?.[repaymentToken]) {
101
- assign(dict, [repaymentChainId, repaymentToken], {
102
- fills: [],
103
- totalRefundAmount: bnZero,
104
- realizedLpFees: bnZero,
105
- refunds: {},
106
- });
107
- }
98
+
99
+ dict[repaymentChainId] ??= {};
100
+ dict[repaymentChainId][repaymentToken.toBytes32()] ??= {
101
+ fills: [],
102
+ totalRefundAmount: bnZero,
103
+ realizedLpFees: bnZero,
104
+ refunds: {},
105
+ };
108
106
 
109
107
  const bundleFill: BundleFillV3 = { ...fill, lpFeePct, relayer: repaymentAddress };
110
108
 
111
109
  // Add all fills, slow and fast, to dictionary.
112
- assign(dict, [repaymentChainId, repaymentToken, "fills"], [bundleFill]);
110
+ assign(dict, [repaymentChainId, repaymentToken.toBytes32(), "fills"], [bundleFill]);
113
111
 
114
112
  // All fills update the bundle LP fees.
115
- const refundObj = dict[repaymentChainId][repaymentToken];
113
+ const refundObj = dict[repaymentChainId][repaymentToken.toBytes32()];
116
114
  const realizedLpFee = bundleFill.inputAmount.mul(bundleFill.lpFeePct).div(fixedPointAdjustment);
117
115
  refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
118
116
 
@@ -126,10 +124,11 @@ function updateBundleFillsV3(
126
124
  // Instantiate dictionary if it doesn't exist.
127
125
  refundObj.refunds ??= {};
128
126
 
129
- if (refundObj.refunds[bundleFill.relayer]) {
130
- refundObj.refunds[bundleFill.relayer] = refundObj.refunds[bundleFill.relayer].add(refundAmount);
127
+ if (refundObj.refunds[bundleFill.relayer.toBytes32()]) {
128
+ refundObj.refunds[bundleFill.relayer.toBytes32()] =
129
+ refundObj.refunds[bundleFill.relayer.toBytes32()].add(refundAmount);
131
130
  } else {
132
- refundObj.refunds[bundleFill.relayer] = refundAmount;
131
+ refundObj.refunds[bundleFill.relayer.toBytes32()] = refundAmount;
133
132
  }
134
133
  }
135
134
  }
@@ -139,21 +138,20 @@ function updateBundleExcessSlowFills(
139
138
  deposit: V3DepositWithBlock & { lpFeePct: BigNumber }
140
139
  ): void {
141
140
  const { destinationChainId, outputToken } = deposit;
142
- if (!dict?.[destinationChainId]?.[outputToken]) {
143
- assign(dict, [destinationChainId, outputToken], []);
144
- }
145
- dict[destinationChainId][outputToken].push(deposit);
141
+ dict[destinationChainId] ??= {};
142
+ dict[destinationChainId][outputToken.toBytes32()] ??= [];
143
+ dict[destinationChainId][outputToken.toBytes32()].push(deposit);
146
144
  }
147
145
 
148
146
  function updateBundleSlowFills(dict: BundleSlowFills, deposit: V3DepositWithBlock & { lpFeePct: BigNumber }): void {
149
- if (chainIsEvm(deposit.destinationChainId) && !isValidEvmAddress(deposit.recipient)) {
147
+ if (!deposit.recipient.isValidOn(deposit.destinationChainId)) {
150
148
  return;
151
149
  }
150
+
152
151
  const { destinationChainId, outputToken } = deposit;
153
- if (!dict?.[destinationChainId]?.[outputToken]) {
154
- assign(dict, [destinationChainId, outputToken], []);
155
- }
156
- dict[destinationChainId][outputToken].push(deposit);
152
+ dict[destinationChainId] ??= {};
153
+ dict[destinationChainId][outputToken.toBytes32()] ??= [];
154
+ dict[destinationChainId][outputToken.toBytes32()].push(deposit);
157
155
  }
158
156
 
159
157
  // @notice Shared client for computing data needed to construct or validate a bundle.
@@ -489,21 +487,23 @@ export class BundleDataClient {
489
487
  // worst from the relayer's perspective.
490
488
  const { relayer, inputAmount: refundAmount } = fill;
491
489
  refundsForChain[chainToSendRefundTo] ??= {};
492
- refundsForChain[chainToSendRefundTo][repaymentToken] ??= {};
493
- const existingRefundAmount = refundsForChain[chainToSendRefundTo][repaymentToken][relayer] ?? bnZero;
494
- refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
490
+ refundsForChain[chainToSendRefundTo][repaymentToken.toBytes32()] ??= {};
491
+ const existingRefundAmount =
492
+ refundsForChain[chainToSendRefundTo][repaymentToken.toBytes32()][relayer.toBytes32()] ?? bnZero;
493
+ refundsForChain[chainToSendRefundTo][repaymentToken.toBytes32()][relayer.toBytes32()] =
494
+ existingRefundAmount.add(refundAmount);
495
495
  });
496
496
  }
497
497
  return refundsForChain;
498
498
  }
499
499
 
500
- getUpcomingDepositAmount(chainId: number, l2Token: string, latestBlockToSearch: number): BigNumber {
500
+ getUpcomingDepositAmount(chainId: number, l2Token: Address, latestBlockToSearch: number): BigNumber {
501
501
  if (this.spokePoolClients[chainId] === undefined) {
502
502
  return toBN(0);
503
503
  }
504
504
  return this.spokePoolClients[chainId]
505
505
  .getDeposits()
506
- .filter((deposit) => deposit.blockNumber > latestBlockToSearch && deposit.inputToken === l2Token)
506
+ .filter((deposit) => deposit.blockNumber > latestBlockToSearch && deposit.inputToken.eq(l2Token))
507
507
  .reduce((acc, deposit) => {
508
508
  return acc.add(deposit.inputAmount);
509
509
  }, toBN(0));
@@ -626,18 +626,18 @@ export class BundleDataClient {
626
626
  const executedRefunds: { [tokenAddress: string]: { [relayer: string]: BigNumber } } = {};
627
627
  for (const refundLeaf of executedRefundLeaves) {
628
628
  const tokenAddress = refundLeaf.l2TokenAddress;
629
- if (executedRefunds[tokenAddress] === undefined) {
630
- executedRefunds[tokenAddress] = {};
629
+ if (executedRefunds[tokenAddress.toBytes32()] === undefined) {
630
+ executedRefunds[tokenAddress.toBytes32()] = {};
631
631
  }
632
- const executedTokenRefunds = executedRefunds[tokenAddress];
632
+ const executedTokenRefunds = executedRefunds[tokenAddress.toBytes32()];
633
633
 
634
634
  for (let i = 0; i < refundLeaf.refundAddresses.length; i++) {
635
635
  const relayer = refundLeaf.refundAddresses[i];
636
636
  const refundAmount = refundLeaf.refundAmounts[i];
637
- if (executedTokenRefunds[relayer] === undefined) {
638
- executedTokenRefunds[relayer] = bnZero;
637
+ if (executedTokenRefunds[relayer.toBytes32()] === undefined) {
638
+ executedTokenRefunds[relayer.toBytes32()] = bnZero;
639
639
  }
640
- executedTokenRefunds[relayer] = executedTokenRefunds[relayer].add(refundAmount);
640
+ executedTokenRefunds[relayer.toBytes32()] = executedTokenRefunds[relayer.toBytes32()].add(refundAmount);
641
641
  }
642
642
  }
643
643
  return executedRefunds;
@@ -678,15 +678,15 @@ export class BundleDataClient {
678
678
  return allRefunds;
679
679
  }
680
680
 
681
- getRefundsFor(bundleRefunds: CombinedRefunds, relayer: string, chainId: number, token: string): BigNumber {
682
- if (!bundleRefunds[chainId] || !bundleRefunds[chainId][token]) {
681
+ getRefundsFor(bundleRefunds: CombinedRefunds, relayer: Address, chainId: number, token: Address): BigNumber {
682
+ if (!bundleRefunds[chainId] || !bundleRefunds[chainId][token.toBytes32()]) {
683
683
  return BigNumber.from(0);
684
684
  }
685
- const allRefunds = bundleRefunds[chainId][token];
686
- return allRefunds && allRefunds[relayer] ? allRefunds[relayer] : BigNumber.from(0);
685
+ const allRefunds = bundleRefunds[chainId][token.toBytes32()];
686
+ return allRefunds && allRefunds[relayer.toBytes32()] ? allRefunds[relayer.toBytes32()] : BigNumber.from(0);
687
687
  }
688
688
 
689
- getTotalRefund(refunds: CombinedRefunds[], relayer: string, chainId: number, refundToken: string): BigNumber {
689
+ getTotalRefund(refunds: CombinedRefunds[], relayer: Address, chainId: number, refundToken: Address): BigNumber {
690
690
  return refunds.reduce((totalRefund, refunds) => {
691
691
  return totalRefund.add(this.getRefundsFor(refunds, relayer, chainId, refundToken));
692
692
  }, bnZero);
@@ -899,7 +899,11 @@ export class BundleDataClient {
899
899
  "Not using correct bundle deposit hash key"
900
900
  );
901
901
  if (deposit.blockNumber >= originChainBlockRange[0]) {
902
- if (bundleDepositsV3?.[originChainId]?.[deposit.inputToken]?.find((d) => duplicateEvent(deposit, d))) {
902
+ if (
903
+ bundleDepositsV3?.[originChainId]?.[deposit.inputToken.toBytes32()]?.find((d) =>
904
+ duplicateEvent(deposit, d)
905
+ )
906
+ ) {
903
907
  this.logger.debug({
904
908
  at: "BundleDataClient#loadData",
905
909
  message: "Duplicate deposit detected",
@@ -17,6 +17,7 @@ import {
17
17
  fixedPointAdjustment,
18
18
  count2DDictionaryValues,
19
19
  count3DDictionaryValues,
20
+ toAddressType,
20
21
  } from "../../../utils";
21
22
  import {
22
23
  addLastRunningBalance,
@@ -65,10 +66,10 @@ export function getRefundsFromBundle(
65
66
  Object.entries(depositsForChain).forEach(([l2TokenAddress, deposits]) => {
66
67
  deposits.forEach((deposit) => {
67
68
  if (combinedRefunds[originChainId][l2TokenAddress] === undefined) {
68
- combinedRefunds[originChainId][l2TokenAddress] = { [deposit.depositor]: deposit.inputAmount };
69
+ combinedRefunds[originChainId][l2TokenAddress] = { [deposit.depositor.toBytes32()]: deposit.inputAmount };
69
70
  } else {
70
- const existingRefundAmount = combinedRefunds[originChainId][l2TokenAddress][deposit.depositor];
71
- combinedRefunds[originChainId][l2TokenAddress][deposit.depositor] = deposit.inputAmount.add(
71
+ const existingRefundAmount = combinedRefunds[originChainId][l2TokenAddress][deposit.depositor.toBytes32()];
72
+ combinedRefunds[originChainId][l2TokenAddress][deposit.depositor.toBytes32()] = deposit.inputAmount.add(
72
73
  existingRefundAmount ?? bnZero
73
74
  );
74
75
  }
@@ -153,19 +154,23 @@ export function _buildPoolRebalanceRoot(
153
154
  // If the repayment token and repayment chain ID do not map to a PoolRebalanceRoute graph, then
154
155
  // there are no relevant L1 running balances.
155
156
  if (
156
- !clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(l2TokenAddress, repaymentChainId, mainnetBundleEndBlock)
157
+ !clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(
158
+ toAddressType(l2TokenAddress, repaymentChainId),
159
+ repaymentChainId,
160
+ mainnetBundleEndBlock
161
+ )
157
162
  ) {
158
163
  chainWithRefundsOnly.add(repaymentChainId);
159
164
  return;
160
165
  }
161
166
  const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
162
- l2TokenAddress,
167
+ toAddressType(l2TokenAddress, repaymentChainId),
163
168
  repaymentChainId,
164
169
  mainnetBundleEndBlock
165
170
  );
166
171
 
167
- updateRunningBalance(runningBalances, repaymentChainId, l1TokenCounterpart, totalRefundAmount);
168
- updateRunningBalance(realizedLpFees, repaymentChainId, l1TokenCounterpart, totalRealizedLpFee);
172
+ updateRunningBalance(runningBalances, repaymentChainId, l1TokenCounterpart.toEvmAddress(), totalRefundAmount);
173
+ updateRunningBalance(realizedLpFees, repaymentChainId, l1TokenCounterpart.toEvmAddress(), totalRealizedLpFee);
169
174
  }
170
175
  );
171
176
  });
@@ -182,12 +187,17 @@ export function _buildPoolRebalanceRoot(
182
187
  Object.entries(depositsForChain).forEach(([outputToken, deposits]) => {
183
188
  deposits.forEach((deposit) => {
184
189
  const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
185
- outputToken,
190
+ toAddressType(outputToken, destinationChainId),
186
191
  destinationChainId,
187
192
  mainnetBundleEndBlock
188
193
  );
189
194
  const lpFee = deposit.lpFeePct.mul(deposit.inputAmount).div(fixedPointAdjustment);
190
- updateRunningBalance(runningBalances, destinationChainId, l1TokenCounterpart, deposit.inputAmount.sub(lpFee));
195
+ updateRunningBalance(
196
+ runningBalances,
197
+ destinationChainId,
198
+ l1TokenCounterpart.toEvmAddress(),
199
+ deposit.inputAmount.sub(lpFee)
200
+ );
191
201
  // Slow fill LP fees are accounted for when the slow fill executes and a V3FilledRelay is emitted. i.e. when
192
202
  // the slow fill execution is included in bundleFillsV3.
193
203
  });
@@ -206,12 +216,17 @@ export function _buildPoolRebalanceRoot(
206
216
  Object.entries(slowFilledDepositsForChain).forEach(([outputToken, slowFilledDeposits]) => {
207
217
  slowFilledDeposits.forEach((deposit) => {
208
218
  const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
209
- outputToken,
219
+ toAddressType(outputToken, destinationChainId),
210
220
  destinationChainId,
211
221
  mainnetBundleEndBlock
212
222
  );
213
223
  const lpFee = deposit.lpFeePct.mul(deposit.inputAmount).div(fixedPointAdjustment);
214
- updateRunningBalance(runningBalances, destinationChainId, l1TokenCounterpart, lpFee.sub(deposit.inputAmount));
224
+ updateRunningBalance(
225
+ runningBalances,
226
+ destinationChainId,
227
+ l1TokenCounterpart.toEvmAddress(),
228
+ lpFee.sub(deposit.inputAmount)
229
+ );
215
230
  // Slow fills don't add to lpFees, only when the slow fill is executed and a V3FilledRelay is emitted, so
216
231
  // we don't need to subtract it here. Moreover, the HubPoole expects bundleLpFees to be > 0.
217
232
  });
@@ -271,11 +286,11 @@ export function _buildPoolRebalanceRoot(
271
286
  return;
272
287
  }
273
288
  const l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(
274
- inputToken,
289
+ toAddressType(inputToken, originChainId),
275
290
  originChainId,
276
291
  mainnetBundleEndBlock
277
292
  );
278
- updateRunningBalance(runningBalances, originChainId, l1TokenCounterpart, deposit.inputAmount);
293
+ updateRunningBalance(runningBalances, originChainId, l1TokenCounterpart.toEvmAddress(), deposit.inputAmount);
279
294
  });
280
295
  });
281
296
  });
@@ -2,7 +2,7 @@ import _ from "lodash";
2
2
  import assert from "assert";
3
3
  import { providers } from "ethers";
4
4
  import { DepositWithBlock, Fill, FillWithBlock } from "../../../interfaces";
5
- import { isSlowFill, isValidEvmAddress, isDefined, chainIsEvm } from "../../../utils";
5
+ import { isSlowFill, isValidEvmAddress, isDefined, chainIsEvm, Address, toAddressType } from "../../../utils";
6
6
  import { HubPoolClient } from "../../HubPoolClient";
7
7
  import { SVMProvider } from "../../../arch/svm";
8
8
 
@@ -25,7 +25,7 @@ export function getRefundInformationFromFill(
25
25
  bundleEndBlockForMainnet: number
26
26
  ): {
27
27
  chainToSendRefundTo: number;
28
- repaymentToken: string;
28
+ repaymentToken: Address;
29
29
  } {
30
30
  const chainToSendRefundTo = _getRepaymentChainId(relayData, hubPoolClient, bundleEndBlockForMainnet);
31
31
  if (chainToSendRefundTo === relayData.originChainId) {
@@ -49,6 +49,7 @@ export function getRefundInformationFromFill(
49
49
  chainToSendRefundTo,
50
50
  bundleEndBlockForMainnet
51
51
  );
52
+
52
53
  return {
53
54
  chainToSendRefundTo,
54
55
  repaymentToken,
@@ -125,7 +126,11 @@ export async function verifyFillRepayment(
125
126
  return undefined;
126
127
  }
127
128
  }
128
- fill.relayer = destinationRelayer;
129
+ fill.relayer = toAddressType(destinationRelayer, fill.destinationChainId);
130
+ assert(
131
+ fill.relayer.isValidOn(fill.destinationChainId),
132
+ `Cannot re-assign fill to msg.sender: ${destinationRelayer}`
133
+ );
129
134
  } else {
130
135
  return undefined;
131
136
  }
@@ -200,5 +205,6 @@ function _repaymentAddressNeedsToBeOverwritten(fill: Fill): boolean {
200
205
  // - i.e. If chainIsSvm && !isValidSvmAddress(fill.relayer) then return false
201
206
  // If chainIsEvm && !isValidEvmAddress(fill.relayer) then return false
202
207
  // If chainIsEvm && isValidEvmAddress(fill.relayer) then return true
203
- return !isValidEvmAddress(fill.relayer);
208
+ // @todo: UMIP might require upper 12 bytes non-zero for SVM repayment
209
+ return !fill.relayer.isValidOn(fill.repaymentChainId);
204
210
  }
@@ -21,6 +21,12 @@ export function buildPoolRebalanceLeafTree(poolRebalanceLeaves: PoolRebalanceLea
21
21
  }
22
22
 
23
23
  const paramType = getParamType("MerkleLibTest", "verifyPoolRebalance", "rebalance");
24
- const hashFn = (input: PoolRebalanceLeaf) => utils.keccak256(utils.defaultAbiCoder.encode([paramType], [input]));
24
+ const hashFn = (input: PoolRebalanceLeaf) => {
25
+ const ethersLeaf = {
26
+ ...input,
27
+ l1Tokens: input.l1Tokens.map((l1Token) => l1Token.toEvmAddress()),
28
+ };
29
+ return utils.keccak256(utils.defaultAbiCoder.encode([paramType], [ethersLeaf]));
30
+ };
25
31
  return new MerkleTree<PoolRebalanceLeaf>(poolRebalanceLeaves, hashFn);
26
32
  }
@@ -1,7 +1,7 @@
1
1
  import { MerkleTree } from "@across-protocol/contracts/dist/utils/MerkleTree";
2
2
  import { RunningBalances, PoolRebalanceLeaf, Clients, SpokePoolTargetBalance } from "../../../interfaces";
3
3
  import { SpokePoolClient } from "../../SpokePoolClient";
4
- import { BigNumber, bnZero, compareAddresses } from "../../../utils";
4
+ import { BigNumber, bnZero, compareAddresses, EvmAddress } from "../../../utils";
5
5
  import { HubPoolClient } from "../../HubPoolClient";
6
6
  import { V3DepositWithBlock } from "./shims";
7
7
  import { AcrossConfigStoreClient } from "../../AcrossConfigStoreClient";
@@ -151,7 +151,7 @@ export function addLastRunningBalance(
151
151
  const { runningBalance } = hubPoolClient.getRunningBalanceBeforeBlockForChain(
152
152
  latestMainnetBlock,
153
153
  Number(repaymentChainId),
154
- l1TokenAddress
154
+ EvmAddress.from(l1TokenAddress)
155
155
  );
156
156
  if (!runningBalance.eq(bnZero)) {
157
157
  updateRunningBalance(runningBalances, Number(repaymentChainId), l1TokenAddress, runningBalance);
@@ -172,7 +172,7 @@ export function updateRunningBalanceForDeposit(
172
172
  deposit.originChainId,
173
173
  mainnetBundleEndBlock
174
174
  );
175
- updateRunningBalance(runningBalances, deposit.originChainId, l1TokenCounterpart, updateAmount);
175
+ updateRunningBalance(runningBalances, deposit.originChainId, l1TokenCounterpart.toEvmAddress(), updateAmount);
176
176
  }
177
177
 
178
178
  export function constructPoolRebalanceLeaves(
@@ -253,7 +253,7 @@ export function constructPoolRebalanceLeaves(
253
253
  runningBalances: leafRunningBalances,
254
254
  groupIndex: groupIndexForChainId++,
255
255
  leafId: leaves.length,
256
- l1Tokens: l1TokensToIncludeInThisLeaf,
256
+ l1Tokens: l1TokensToIncludeInThisLeaf.map((l1TokenAddr: string) => EvmAddress.from(l1TokenAddr)),
257
257
  });
258
258
  }
259
259
  });
@@ -15,7 +15,7 @@ import {
15
15
  type,
16
16
  } from "superstruct";
17
17
  import { UNDEFINED_MESSAGE_HASH } from "../../../constants";
18
- import { BigNumber } from "../../../utils";
18
+ import { BigNumber, toAddressType, Address } from "../../../utils";
19
19
 
20
20
  const PositiveIntegerStringSS = pattern(string(), /\d+/);
21
21
  const Web3AddressSS = pattern(string(), /^0x[a-fA-F0-9]{40}$/);
@@ -31,19 +31,23 @@ const BigNumberType = coerce(instance(BigNumber), union([string(), number()]), (
31
31
  }
32
32
  });
33
33
 
34
+ const AddressType = coerce(instance(Address), string(), (value) => {
35
+ return toAddressType(value, 1); // @todo Don't merge without fixing this!
36
+ });
37
+
34
38
  const FillTypeSS = number();
35
39
 
36
40
  const V3RelayDataSS = {
37
- inputToken: string(),
41
+ inputToken: AddressType,
38
42
  inputAmount: BigNumberType,
39
- outputToken: string(),
43
+ outputToken: AddressType,
40
44
  outputAmount: BigNumberType,
41
45
  fillDeadline: number(),
42
- exclusiveRelayer: string(),
46
+ exclusiveRelayer: AddressType,
43
47
  exclusivityDeadline: number(),
44
48
  originChainId: number(),
45
- depositor: string(),
46
- recipient: string(),
49
+ depositor: AddressType,
50
+ recipient: AddressType,
47
51
  depositId: BigNumberType,
48
52
  message: string(),
49
53
  };
@@ -67,7 +71,7 @@ const V3DepositSS = {
67
71
  quoteTimestamp: number(),
68
72
  relayerFeePct: optional(BigNumberType),
69
73
  speedUpSignature: optional(string()),
70
- updatedRecipient: optional(string()),
74
+ updatedRecipient: optional(AddressType),
71
75
  updatedOutputAmount: optional(BigNumberType),
72
76
  updatedMessage: optional(string()),
73
77
  };
@@ -88,7 +92,7 @@ const V3DepositWithBlockLpFeeSS = object({
88
92
  const V3RelayExecutionEventInfoSS = object({
89
93
  updatedOutputAmount: BigNumberType,
90
94
  fillType: FillTypeSS,
91
- updatedRecipient: string(),
95
+ updatedRecipient: AddressType,
92
96
  updatedMessage: optional(string()),
93
97
  updatedMessageHash: defaulted(string(), UNDEFINED_MESSAGE_HASH),
94
98
  });
@@ -98,7 +102,7 @@ const V3FillSS = {
98
102
  message: optional(string()),
99
103
  messageHash: defaulted(string(), UNDEFINED_MESSAGE_HASH),
100
104
  destinationChainId: number(),
101
- relayer: string(),
105
+ relayer: AddressType,
102
106
  repaymentChainId: number(),
103
107
  relayExecutionInfo: V3RelayExecutionEventInfoSS,
104
108
  quoteTimestamp: number(),