@across-protocol/sdk 4.2.16 → 4.3.0

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 (220) hide show
  1. package/dist/cjs/arch/evm/SpokeUtils.d.ts +8 -3
  2. package/dist/cjs/arch/evm/SpokeUtils.js +26 -11
  3. package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
  4. package/dist/cjs/arch/svm/SpokeUtils.d.ts +8 -2
  5. package/dist/cjs/arch/svm/SpokeUtils.js +41 -50
  6. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  7. package/dist/cjs/arch/svm/eventsClient.js +4 -2
  8. package/dist/cjs/arch/svm/eventsClient.js.map +1 -1
  9. package/dist/cjs/arch/svm/utils.d.ts +3 -3
  10. package/dist/cjs/arch/svm/utils.js +16 -14
  11. package/dist/cjs/arch/svm/utils.js.map +1 -1
  12. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  13. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
  14. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  15. package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  16. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +60 -56
  17. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  18. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +13 -13
  19. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  20. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  21. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +3 -2
  22. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  23. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
  24. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  25. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +3 -3
  26. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  27. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +71 -71
  28. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +13 -8
  29. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  30. package/dist/cjs/clients/HubPoolClient.d.ts +21 -21
  31. package/dist/cjs/clients/HubPoolClient.js +85 -58
  32. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  33. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
  34. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  35. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  36. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +65 -45
  37. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  38. package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +9 -9
  39. package/dist/cjs/clients/mocks/MockHubPoolClient.js +15 -9
  40. package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
  41. package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  42. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +40 -36
  43. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  44. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  45. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +6 -4
  46. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  47. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
  48. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +2 -2
  49. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  50. package/dist/cjs/interfaces/HubPool.d.ts +19 -14
  51. package/dist/cjs/interfaces/SpokePool.d.ts +18 -19
  52. package/dist/cjs/interfaces/SpokePool.js.map +1 -1
  53. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +15 -7
  54. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +24 -15
  55. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  56. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +1 -1
  57. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  58. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +12 -4
  59. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +46 -44
  60. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  61. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +6 -6
  62. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +10 -10
  63. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  64. package/dist/cjs/utils/AddressUtils.d.ts +12 -8
  65. package/dist/cjs/utils/AddressUtils.js +33 -36
  66. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  67. package/dist/cjs/utils/SpokeUtils.d.ts +3 -3
  68. package/dist/cjs/utils/SpokeUtils.js +4 -22
  69. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  70. package/dist/cjs/utils/TokenUtils.d.ts +4 -4
  71. package/dist/cjs/utils/TokenUtils.js +5 -3
  72. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  73. package/dist/esm/arch/evm/SpokeUtils.d.ts +9 -4
  74. package/dist/esm/arch/evm/SpokeUtils.js +29 -14
  75. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  76. package/dist/esm/arch/svm/SpokeUtils.d.ts +9 -3
  77. package/dist/esm/arch/svm/SpokeUtils.js +42 -55
  78. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  79. package/dist/esm/arch/svm/eventsClient.js +5 -3
  80. package/dist/esm/arch/svm/eventsClient.js.map +1 -1
  81. package/dist/esm/arch/svm/utils.d.ts +3 -3
  82. package/dist/esm/arch/svm/utils.js +17 -15
  83. package/dist/esm/arch/svm/utils.js.map +1 -1
  84. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  85. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
  86. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  87. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  88. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +61 -57
  89. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  90. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +14 -14
  91. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  92. package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  93. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +7 -7
  94. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  95. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
  96. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  97. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +4 -4
  98. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  99. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +71 -71
  100. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +20 -10
  101. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  102. package/dist/esm/clients/HubPoolClient.d.ts +22 -22
  103. package/dist/esm/clients/HubPoolClient.js +91 -62
  104. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  105. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +2 -2
  106. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  107. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  108. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +68 -47
  109. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  110. package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +9 -9
  111. package/dist/esm/clients/mocks/MockHubPoolClient.js +16 -10
  112. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  113. package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  114. package/dist/esm/clients/mocks/MockSpokePoolClient.js +42 -38
  115. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  116. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  117. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +7 -5
  118. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  119. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
  120. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +3 -3
  121. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  122. package/dist/esm/interfaces/HubPool.d.ts +19 -14
  123. package/dist/esm/interfaces/SpokePool.d.ts +18 -19
  124. package/dist/esm/interfaces/SpokePool.js.map +1 -1
  125. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +18 -10
  126. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +29 -20
  127. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  128. package/dist/esm/relayFeeCalculator/chain-queries/factory.js +2 -2
  129. package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  130. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +14 -6
  131. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +51 -48
  132. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  133. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +6 -6
  134. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +9 -9
  135. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  136. package/dist/esm/utils/AddressUtils.d.ts +12 -8
  137. package/dist/esm/utils/AddressUtils.js +36 -38
  138. package/dist/esm/utils/AddressUtils.js.map +1 -1
  139. package/dist/esm/utils/SpokeUtils.d.ts +3 -8
  140. package/dist/esm/utils/SpokeUtils.js +4 -26
  141. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  142. package/dist/esm/utils/TokenUtils.d.ts +22 -18
  143. package/dist/esm/utils/TokenUtils.js +6 -4
  144. package/dist/esm/utils/TokenUtils.js.map +1 -1
  145. package/dist/types/arch/evm/SpokeUtils.d.ts +9 -4
  146. package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
  147. package/dist/types/arch/svm/SpokeUtils.d.ts +9 -3
  148. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
  149. package/dist/types/arch/svm/eventsClient.d.ts.map +1 -1
  150. package/dist/types/arch/svm/utils.d.ts +3 -3
  151. package/dist/types/arch/svm/utils.d.ts.map +1 -1
  152. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  153. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
  154. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  155. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  156. package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
  157. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  158. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
  159. package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts.map +1 -1
  160. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
  161. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +71 -71
  162. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
  163. package/dist/types/clients/HubPoolClient.d.ts +22 -22
  164. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  165. package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
  166. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  167. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  168. package/dist/types/clients/mocks/MockHubPoolClient.d.ts +9 -9
  169. package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
  170. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  171. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
  172. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  173. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts.map +1 -1
  174. package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
  175. package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts.map +1 -1
  176. package/dist/types/interfaces/HubPool.d.ts +19 -14
  177. package/dist/types/interfaces/HubPool.d.ts.map +1 -1
  178. package/dist/types/interfaces/SpokePool.d.ts +18 -19
  179. package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
  180. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +18 -10
  181. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  182. package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
  183. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +14 -6
  184. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
  185. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +6 -6
  186. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  187. package/dist/types/utils/AddressUtils.d.ts +12 -8
  188. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  189. package/dist/types/utils/SpokeUtils.d.ts +3 -8
  190. package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
  191. package/dist/types/utils/TokenUtils.d.ts +22 -18
  192. package/dist/types/utils/TokenUtils.d.ts.map +1 -1
  193. package/package.json +1 -2
  194. package/src/arch/evm/SpokeUtils.ts +72 -22
  195. package/src/arch/svm/SpokeUtils.ts +67 -53
  196. package/src/arch/svm/eventsClient.ts +40 -8
  197. package/src/arch/svm/utils.ts +6 -6
  198. package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +7 -4
  199. package/src/clients/BundleDataClient/BundleDataClient.ts +57 -53
  200. package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +28 -13
  201. package/src/clients/BundleDataClient/utils/FillUtils.ts +12 -8
  202. package/src/clients/BundleDataClient/utils/MerkleTreeUtils.ts +7 -1
  203. package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +4 -4
  204. package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +22 -10
  205. package/src/clients/HubPoolClient.ts +123 -82
  206. package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +6 -0
  207. package/src/clients/SpokePoolClient/SpokePoolClient.ts +121 -35
  208. package/src/clients/mocks/MockHubPoolClient.ts +24 -19
  209. package/src/clients/mocks/MockSpokePoolClient.ts +39 -27
  210. package/src/clients/mocks/MockSvmCpiEventsClient.ts +8 -5
  211. package/src/clients/mocks/MockSvmSpokePoolClient.ts +12 -3
  212. package/src/interfaces/HubPool.ts +20 -14
  213. package/src/interfaces/SpokePool.ts +19 -19
  214. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +39 -20
  215. package/src/relayFeeCalculator/chain-queries/factory.ts +2 -2
  216. package/src/relayFeeCalculator/chain-queries/svmQuery.ts +57 -56
  217. package/src/relayFeeCalculator/relayFeeCalculator.ts +15 -13
  218. package/src/utils/AddressUtils.ts +39 -51
  219. package/src/utils/SpokeUtils.ts +11 -33
  220. package/src/utils/TokenUtils.ts +10 -8
@@ -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
  getNetworkName,
47
46
  } from "../../utils";
48
47
  import winston from "winston";
@@ -69,22 +68,21 @@ type DataCache = Record<string, Promise<LoadDataReturnValue>>;
69
68
  // V3 dictionary helper functions
70
69
  function updateExpiredDepositsV3(dict: ExpiredDepositsToRefundV3, deposit: V3DepositWithBlock): void {
71
70
  // A deposit refund for a deposit is invalid if the depositor has a bytes32 address input for an EVM chain. It is valid otherwise.
72
- if (chainIsEvm(deposit.originChainId) && !isValidEvmAddress(deposit.depositor)) {
71
+ if (!deposit.depositor.isValidOn(deposit.originChainId)) {
73
72
  return;
74
73
  }
74
+
75
75
  const { originChainId, inputToken } = deposit;
76
- if (!dict?.[originChainId]?.[inputToken]) {
77
- assign(dict, [originChainId, inputToken], []);
78
- }
79
- dict[originChainId][inputToken].push(deposit);
76
+ dict[originChainId] ??= {};
77
+ dict[originChainId][inputToken.toBytes32()] ??= [];
78
+ dict[originChainId][inputToken.toBytes32()].push(deposit);
80
79
  }
81
80
 
82
81
  function updateBundleDepositsV3(dict: BundleDepositsV3, deposit: V3DepositWithBlock): void {
83
82
  const { originChainId, inputToken } = deposit;
84
- if (!dict?.[originChainId]?.[inputToken]) {
85
- assign(dict, [originChainId, inputToken], []);
86
- }
87
- dict[originChainId][inputToken].push(deposit);
83
+ dict[originChainId] ??= {};
84
+ dict[originChainId][inputToken.toBytes32()] ??= [];
85
+ dict[originChainId][inputToken.toBytes32()].push(deposit);
88
86
  }
89
87
 
90
88
  function updateBundleFillsV3(
@@ -92,29 +90,29 @@ function updateBundleFillsV3(
92
90
  fill: V3FillWithBlock,
93
91
  lpFeePct: BigNumber,
94
92
  repaymentChainId: number,
95
- repaymentToken: string,
96
- repaymentAddress: string
93
+ repaymentToken: Address,
94
+ repaymentAddress: Address
97
95
  ): void {
98
96
  // We shouldn't pass any unrepayable fills into this function, so we perform an extra safety check.
99
- if (chainIsEvm(repaymentChainId) && !isValidEvmAddress(fill.relayer)) {
97
+ if (!fill.relayer.isValidOn(repaymentChainId)) {
100
98
  return;
101
99
  }
102
- if (!dict?.[repaymentChainId]?.[repaymentToken]) {
103
- assign(dict, [repaymentChainId, repaymentToken], {
104
- fills: [],
105
- totalRefundAmount: bnZero,
106
- realizedLpFees: bnZero,
107
- refunds: {},
108
- });
109
- }
100
+
101
+ dict[repaymentChainId] ??= {};
102
+ dict[repaymentChainId][repaymentToken.toBytes32()] ??= {
103
+ fills: [],
104
+ totalRefundAmount: bnZero,
105
+ realizedLpFees: bnZero,
106
+ refunds: {},
107
+ };
110
108
 
111
109
  const bundleFill: BundleFillV3 = { ...fill, lpFeePct, relayer: repaymentAddress };
112
110
 
113
111
  // Add all fills, slow and fast, to dictionary.
114
- assign(dict, [repaymentChainId, repaymentToken, "fills"], [bundleFill]);
112
+ assign(dict, [repaymentChainId, repaymentToken.toBytes32(), "fills"], [bundleFill]);
115
113
 
116
114
  // All fills update the bundle LP fees.
117
- const refundObj = dict[repaymentChainId][repaymentToken];
115
+ const refundObj = dict[repaymentChainId][repaymentToken.toBytes32()];
118
116
  const realizedLpFee = bundleFill.inputAmount.mul(bundleFill.lpFeePct).div(fixedPointAdjustment);
119
117
  refundObj.realizedLpFees = refundObj.realizedLpFees ? refundObj.realizedLpFees.add(realizedLpFee) : realizedLpFee;
120
118
 
@@ -128,10 +126,11 @@ function updateBundleFillsV3(
128
126
  // Instantiate dictionary if it doesn't exist.
129
127
  refundObj.refunds ??= {};
130
128
 
131
- if (refundObj.refunds[bundleFill.relayer]) {
132
- refundObj.refunds[bundleFill.relayer] = refundObj.refunds[bundleFill.relayer].add(refundAmount);
129
+ if (refundObj.refunds[bundleFill.relayer.toBytes32()]) {
130
+ refundObj.refunds[bundleFill.relayer.toBytes32()] =
131
+ refundObj.refunds[bundleFill.relayer.toBytes32()].add(refundAmount);
133
132
  } else {
134
- refundObj.refunds[bundleFill.relayer] = refundAmount;
133
+ refundObj.refunds[bundleFill.relayer.toBytes32()] = refundAmount;
135
134
  }
136
135
  }
137
136
  }
@@ -141,21 +140,20 @@ function updateBundleExcessSlowFills(
141
140
  deposit: V3DepositWithBlock & { lpFeePct: BigNumber }
142
141
  ): void {
143
142
  const { destinationChainId, outputToken } = deposit;
144
- if (!dict?.[destinationChainId]?.[outputToken]) {
145
- assign(dict, [destinationChainId, outputToken], []);
146
- }
147
- dict[destinationChainId][outputToken].push(deposit);
143
+ dict[destinationChainId] ??= {};
144
+ dict[destinationChainId][outputToken.toBytes32()] ??= [];
145
+ dict[destinationChainId][outputToken.toBytes32()].push(deposit);
148
146
  }
149
147
 
150
148
  function updateBundleSlowFills(dict: BundleSlowFills, deposit: V3DepositWithBlock & { lpFeePct: BigNumber }): void {
151
- if (chainIsEvm(deposit.destinationChainId) && !isValidEvmAddress(deposit.recipient)) {
149
+ if (!deposit.recipient.isValidOn(deposit.destinationChainId)) {
152
150
  return;
153
151
  }
152
+
154
153
  const { destinationChainId, outputToken } = deposit;
155
- if (!dict?.[destinationChainId]?.[outputToken]) {
156
- assign(dict, [destinationChainId, outputToken], []);
157
- }
158
- dict[destinationChainId][outputToken].push(deposit);
154
+ dict[destinationChainId] ??= {};
155
+ dict[destinationChainId][outputToken.toBytes32()] ??= [];
156
+ dict[destinationChainId][outputToken.toBytes32()].push(deposit);
159
157
  }
160
158
 
161
159
  // @notice Shared client for computing data needed to construct or validate a bundle.
@@ -507,22 +505,24 @@ export class BundleDataClient {
507
505
  // worst from the relayer's perspective.
508
506
  const { relayer, inputAmount: refundAmount } = fill;
509
507
  refundsForChain[chainToSendRefundTo] ??= {};
510
- refundsForChain[chainToSendRefundTo][repaymentToken] ??= {};
511
- const existingRefundAmount = refundsForChain[chainToSendRefundTo][repaymentToken][relayer] ?? bnZero;
512
- refundsForChain[chainToSendRefundTo][repaymentToken][relayer] = existingRefundAmount.add(refundAmount);
508
+ refundsForChain[chainToSendRefundTo][repaymentToken.toBytes32()] ??= {};
509
+ const existingRefundAmount =
510
+ refundsForChain[chainToSendRefundTo][repaymentToken.toBytes32()][relayer.toBytes32()] ?? bnZero;
511
+ refundsForChain[chainToSendRefundTo][repaymentToken.toBytes32()][relayer.toBytes32()] =
512
+ existingRefundAmount.add(refundAmount);
513
513
  });
514
514
  }
515
515
  return refundsForChain;
516
516
  }
517
517
 
518
- getUpcomingDepositAmount(chainId: number, l2Token: string, latestBlockToSearch: number): BigNumber {
518
+ getUpcomingDepositAmount(chainId: number, l2Token: Address, latestBlockToSearch: number): BigNumber {
519
519
  const spokePoolClient = this.spokePoolClientManager.getClient(chainId);
520
520
  if (!isDefined(spokePoolClient)) {
521
521
  return toBN(0);
522
522
  }
523
523
  return spokePoolClient
524
524
  .getDeposits()
525
- .filter((deposit) => deposit.blockNumber > latestBlockToSearch && deposit.inputToken === l2Token)
525
+ .filter((deposit) => deposit.blockNumber > latestBlockToSearch && deposit.inputToken.eq(l2Token))
526
526
  .reduce((acc, deposit) => {
527
527
  return acc.add(deposit.inputAmount);
528
528
  }, toBN(0));
@@ -645,18 +645,18 @@ export class BundleDataClient {
645
645
  const executedRefunds: { [tokenAddress: string]: { [relayer: string]: BigNumber } } = {};
646
646
  for (const refundLeaf of executedRefundLeaves) {
647
647
  const tokenAddress = refundLeaf.l2TokenAddress;
648
- if (executedRefunds[tokenAddress] === undefined) {
649
- executedRefunds[tokenAddress] = {};
648
+ if (executedRefunds[tokenAddress.toBytes32()] === undefined) {
649
+ executedRefunds[tokenAddress.toBytes32()] = {};
650
650
  }
651
- const executedTokenRefunds = executedRefunds[tokenAddress];
651
+ const executedTokenRefunds = executedRefunds[tokenAddress.toBytes32()];
652
652
 
653
653
  for (let i = 0; i < refundLeaf.refundAddresses.length; i++) {
654
654
  const relayer = refundLeaf.refundAddresses[i];
655
655
  const refundAmount = refundLeaf.refundAmounts[i];
656
- if (executedTokenRefunds[relayer] === undefined) {
657
- executedTokenRefunds[relayer] = bnZero;
656
+ if (executedTokenRefunds[relayer.toBytes32()] === undefined) {
657
+ executedTokenRefunds[relayer.toBytes32()] = bnZero;
658
658
  }
659
- executedTokenRefunds[relayer] = executedTokenRefunds[relayer].add(refundAmount);
659
+ executedTokenRefunds[relayer.toBytes32()] = executedTokenRefunds[relayer.toBytes32()].add(refundAmount);
660
660
  }
661
661
  }
662
662
  return executedRefunds;
@@ -695,15 +695,15 @@ export class BundleDataClient {
695
695
  return allRefunds;
696
696
  }
697
697
 
698
- getRefundsFor(bundleRefunds: CombinedRefunds, relayer: string, chainId: number, token: string): BigNumber {
699
- if (!bundleRefunds[chainId] || !bundleRefunds[chainId][token]) {
698
+ getRefundsFor(bundleRefunds: CombinedRefunds, relayer: Address, chainId: number, token: Address): BigNumber {
699
+ if (!bundleRefunds[chainId] || !bundleRefunds[chainId][token.toBytes32()]) {
700
700
  return BigNumber.from(0);
701
701
  }
702
- const allRefunds = bundleRefunds[chainId][token];
703
- return allRefunds && allRefunds[relayer] ? allRefunds[relayer] : BigNumber.from(0);
702
+ const allRefunds = bundleRefunds[chainId][token.toBytes32()];
703
+ return allRefunds && allRefunds[relayer.toBytes32()] ? allRefunds[relayer.toBytes32()] : BigNumber.from(0);
704
704
  }
705
705
 
706
- getTotalRefund(refunds: CombinedRefunds[], relayer: string, chainId: number, refundToken: string): BigNumber {
706
+ getTotalRefund(refunds: CombinedRefunds[], relayer: Address, chainId: number, refundToken: Address): BigNumber {
707
707
  return refunds.reduce((totalRefund, refunds) => {
708
708
  return totalRefund.add(this.getRefundsFor(refunds, relayer, chainId, refundToken));
709
709
  }, bnZero);
@@ -916,7 +916,11 @@ export class BundleDataClient {
916
916
  "Not using correct bundle deposit hash key"
917
917
  );
918
918
  if (deposit.blockNumber >= originChainBlockRange[0]) {
919
- if (bundleDepositsV3?.[originChainId]?.[deposit.inputToken]?.find((d) => duplicateEvent(deposit, d))) {
919
+ if (
920
+ bundleDepositsV3?.[originChainId]?.[deposit.inputToken.toBytes32()]?.find((d) =>
921
+ duplicateEvent(deposit, d)
922
+ )
923
+ ) {
920
924
  this.logger.debug({
921
925
  at: "BundleDataClient#loadData",
922
926
  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
  }
@@ -196,9 +201,8 @@ function _repaymentAddressNeedsToBeOverwritten(fill: Fill): boolean {
196
201
  return false;
197
202
  }
198
203
 
199
- // @todo add Solana logic here:
200
- // - i.e. If chainIsSvm && !isValidSvmAddress(fill.relayer) then return false
201
- // If chainIsEvm && !isValidEvmAddress(fill.relayer) then return false
202
- // If chainIsEvm && isValidEvmAddress(fill.relayer) then return true
203
- return !isValidEvmAddress(fill.relayer);
204
+ // @dev If the repayment chain is EVM, the repayment address is valid if the address is 20 bytes.
205
+ // If the repayment chain is SVM, the repayment address is valid if the address is strictly greater than
206
+ // 20 bytes.
207
+ return !fill.relayer.isValidOn(fill.repaymentChainId);
204
208
  }
@@ -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
  });
@@ -14,8 +14,8 @@ import {
14
14
  union,
15
15
  type,
16
16
  } from "superstruct";
17
- import { UNDEFINED_MESSAGE_HASH } from "../../../constants";
18
- import { BigNumber } from "../../../utils";
17
+ import { CHAIN_IDs, UNDEFINED_MESSAGE_HASH } from "../../../constants";
18
+ import { BigNumber, EvmAddress, RawAddress, SvmAddress, toAddressType } 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,31 @@ const BigNumberType = coerce(instance(BigNumber), union([string(), number()]), (
31
31
  }
32
32
  });
33
33
 
34
+ // Accept any concrete implementation of `Address` (Evm, Svm, or Raw) but avoid using the
35
+ // abstract `Address` class directly to keep TypeScript happy.
36
+ const AddressInstanceSS = union([instance(EvmAddress), instance(SvmAddress), instance(RawAddress)]);
37
+
38
+ const AddressType = coerce(AddressInstanceSS, string(), (value) => {
39
+ // Addresses are posted to arweave in their native format (base16 for EVM, base58 for SVM). The chainId for
40
+ // for the event data is not directly available, so infer it based on the shape of the address. RawAddress
41
+ // will be instantiated if the address format does not match the expected family.
42
+ const chainId = value.startsWith("0x") ? CHAIN_IDs.MAINNET : CHAIN_IDs.SOLANA;
43
+ return toAddressType(value, chainId);
44
+ });
45
+
34
46
  const FillTypeSS = number();
35
47
 
36
48
  const V3RelayDataSS = {
37
- inputToken: string(),
49
+ inputToken: AddressType,
38
50
  inputAmount: BigNumberType,
39
- outputToken: string(),
51
+ outputToken: AddressType,
40
52
  outputAmount: BigNumberType,
41
53
  fillDeadline: number(),
42
- exclusiveRelayer: string(),
54
+ exclusiveRelayer: AddressType,
43
55
  exclusivityDeadline: number(),
44
56
  originChainId: number(),
45
- depositor: string(),
46
- recipient: string(),
57
+ depositor: AddressType,
58
+ recipient: AddressType,
47
59
  depositId: BigNumberType,
48
60
  message: string(),
49
61
  };
@@ -67,7 +79,7 @@ const V3DepositSS = {
67
79
  quoteTimestamp: number(),
68
80
  relayerFeePct: optional(BigNumberType),
69
81
  speedUpSignature: optional(string()),
70
- updatedRecipient: optional(string()),
82
+ updatedRecipient: optional(AddressType),
71
83
  updatedOutputAmount: optional(BigNumberType),
72
84
  updatedMessage: optional(string()),
73
85
  };
@@ -88,7 +100,7 @@ const V3DepositWithBlockLpFeeSS = object({
88
100
  const V3RelayExecutionEventInfoSS = object({
89
101
  updatedOutputAmount: BigNumberType,
90
102
  fillType: FillTypeSS,
91
- updatedRecipient: string(),
103
+ updatedRecipient: AddressType,
92
104
  updatedMessage: optional(string()),
93
105
  updatedMessageHash: defaulted(string(), UNDEFINED_MESSAGE_HASH),
94
106
  });
@@ -98,7 +110,7 @@ const V3FillSS = {
98
110
  message: optional(string()),
99
111
  messageHash: defaulted(string(), UNDEFINED_MESSAGE_HASH),
100
112
  destinationChainId: number(),
101
- relayer: string(),
113
+ relayer: AddressType,
102
114
  repaymentChainId: number(),
103
115
  relayExecutionInfo: V3RelayExecutionEventInfoSS,
104
116
  quoteTimestamp: number(),