@across-protocol/sdk 4.2.16 → 4.3.1

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 (256) 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 +59 -59
  17. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  18. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +16 -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 +2 -2
  34. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  35. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js +1 -3
  36. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
  37. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  38. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +66 -46
  39. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  40. package/dist/cjs/clients/SpokePoolClient/index.d.ts +1 -0
  41. package/dist/cjs/clients/SpokePoolClient/index.js +3 -1
  42. package/dist/cjs/clients/SpokePoolClient/index.js.map +1 -1
  43. package/dist/cjs/clients/index.d.ts +1 -1
  44. package/dist/cjs/clients/index.js +2 -1
  45. package/dist/cjs/clients/index.js.map +1 -1
  46. package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +9 -9
  47. package/dist/cjs/clients/mocks/MockHubPoolClient.js +15 -9
  48. package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
  49. package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  50. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +40 -36
  51. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  52. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  53. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +6 -4
  54. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  55. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
  56. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +2 -2
  57. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  58. package/dist/cjs/interfaces/HubPool.d.ts +19 -14
  59. package/dist/cjs/interfaces/SpokePool.d.ts +18 -19
  60. package/dist/cjs/interfaces/SpokePool.js.map +1 -1
  61. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +17 -9
  62. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +24 -15
  63. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  64. package/dist/cjs/relayFeeCalculator/chain-queries/factory.d.ts +1 -1
  65. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +8 -5
  66. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  67. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +13 -5
  68. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +61 -58
  69. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  70. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +15 -7
  71. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +13 -13
  72. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  73. package/dist/cjs/utils/AddressUtils.d.ts +12 -8
  74. package/dist/cjs/utils/AddressUtils.js +33 -36
  75. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  76. package/dist/cjs/utils/DepositUtils.d.ts +2 -2
  77. package/dist/cjs/utils/DepositUtils.js +1 -1
  78. package/dist/cjs/utils/DepositUtils.js.map +1 -1
  79. package/dist/cjs/utils/SpokeUtils.d.ts +1 -3
  80. package/dist/cjs/utils/SpokeUtils.js +3 -25
  81. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  82. package/dist/cjs/utils/TokenUtils.d.ts +4 -4
  83. package/dist/cjs/utils/TokenUtils.js +5 -3
  84. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  85. package/dist/esm/arch/evm/SpokeUtils.d.ts +9 -4
  86. package/dist/esm/arch/evm/SpokeUtils.js +29 -14
  87. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  88. package/dist/esm/arch/svm/SpokeUtils.d.ts +9 -3
  89. package/dist/esm/arch/svm/SpokeUtils.js +42 -55
  90. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  91. package/dist/esm/arch/svm/eventsClient.js +5 -3
  92. package/dist/esm/arch/svm/eventsClient.js.map +1 -1
  93. package/dist/esm/arch/svm/utils.d.ts +3 -3
  94. package/dist/esm/arch/svm/utils.js +17 -15
  95. package/dist/esm/arch/svm/utils.js.map +1 -1
  96. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  97. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
  98. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  99. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  100. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +60 -60
  101. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  102. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +18 -15
  103. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  104. package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  105. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +7 -7
  106. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  107. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
  108. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  109. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +4 -4
  110. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  111. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +71 -71
  112. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +20 -10
  113. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  114. package/dist/esm/clients/HubPoolClient.d.ts +22 -22
  115. package/dist/esm/clients/HubPoolClient.js +93 -66
  116. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  117. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +3 -3
  118. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  119. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js +2 -4
  120. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -1
  121. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  122. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +69 -48
  123. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  124. package/dist/esm/clients/SpokePoolClient/index.d.ts +1 -0
  125. package/dist/esm/clients/SpokePoolClient/index.js +1 -0
  126. package/dist/esm/clients/SpokePoolClient/index.js.map +1 -1
  127. package/dist/esm/clients/index.d.ts +1 -1
  128. package/dist/esm/clients/index.js +1 -1
  129. package/dist/esm/clients/index.js.map +1 -1
  130. package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +9 -9
  131. package/dist/esm/clients/mocks/MockHubPoolClient.js +16 -10
  132. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  133. package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  134. package/dist/esm/clients/mocks/MockSpokePoolClient.js +42 -38
  135. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  136. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  137. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +7 -5
  138. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  139. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
  140. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +3 -3
  141. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  142. package/dist/esm/interfaces/HubPool.d.ts +19 -14
  143. package/dist/esm/interfaces/SpokePool.d.ts +18 -19
  144. package/dist/esm/interfaces/SpokePool.js.map +1 -1
  145. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +20 -12
  146. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +28 -19
  147. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  148. package/dist/esm/relayFeeCalculator/chain-queries/factory.d.ts +1 -1
  149. package/dist/esm/relayFeeCalculator/chain-queries/factory.js +9 -6
  150. package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  151. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +15 -7
  152. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +67 -63
  153. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  154. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +25 -8
  155. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +12 -12
  156. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  157. package/dist/esm/utils/AddressUtils.d.ts +12 -8
  158. package/dist/esm/utils/AddressUtils.js +36 -38
  159. package/dist/esm/utils/AddressUtils.js.map +1 -1
  160. package/dist/esm/utils/DepositUtils.d.ts +2 -2
  161. package/dist/esm/utils/DepositUtils.js +2 -2
  162. package/dist/esm/utils/DepositUtils.js.map +1 -1
  163. package/dist/esm/utils/SpokeUtils.d.ts +1 -8
  164. package/dist/esm/utils/SpokeUtils.js +3 -29
  165. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  166. package/dist/esm/utils/TokenUtils.d.ts +6 -18
  167. package/dist/esm/utils/TokenUtils.js +6 -4
  168. package/dist/esm/utils/TokenUtils.js.map +1 -1
  169. package/dist/types/arch/evm/SpokeUtils.d.ts +9 -4
  170. package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
  171. package/dist/types/arch/svm/SpokeUtils.d.ts +9 -3
  172. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
  173. package/dist/types/arch/svm/eventsClient.d.ts.map +1 -1
  174. package/dist/types/arch/svm/utils.d.ts +3 -3
  175. package/dist/types/arch/svm/utils.d.ts.map +1 -1
  176. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  177. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
  178. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  179. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  180. package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
  181. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  182. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
  183. package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts.map +1 -1
  184. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
  185. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +71 -71
  186. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
  187. package/dist/types/clients/HubPoolClient.d.ts +22 -22
  188. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  189. package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
  190. package/dist/types/clients/SpokePoolClient/SVMSpokePoolClient.d.ts.map +1 -1
  191. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  192. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  193. package/dist/types/clients/SpokePoolClient/index.d.ts +1 -0
  194. package/dist/types/clients/SpokePoolClient/index.d.ts.map +1 -1
  195. package/dist/types/clients/index.d.ts +1 -1
  196. package/dist/types/clients/index.d.ts.map +1 -1
  197. package/dist/types/clients/mocks/MockHubPoolClient.d.ts +9 -9
  198. package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
  199. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  200. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
  201. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  202. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts.map +1 -1
  203. package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
  204. package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts.map +1 -1
  205. package/dist/types/interfaces/HubPool.d.ts +19 -14
  206. package/dist/types/interfaces/HubPool.d.ts.map +1 -1
  207. package/dist/types/interfaces/SpokePool.d.ts +18 -19
  208. package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
  209. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +20 -12
  210. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  211. package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts +1 -1
  212. package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
  213. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +15 -7
  214. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
  215. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +25 -8
  216. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  217. package/dist/types/utils/AddressUtils.d.ts +12 -8
  218. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  219. package/dist/types/utils/DepositUtils.d.ts +2 -2
  220. package/dist/types/utils/DepositUtils.d.ts.map +1 -1
  221. package/dist/types/utils/SpokeUtils.d.ts +1 -8
  222. package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
  223. package/dist/types/utils/TokenUtils.d.ts +6 -18
  224. package/dist/types/utils/TokenUtils.d.ts.map +1 -1
  225. package/package.json +1 -2
  226. package/src/arch/evm/SpokeUtils.ts +72 -22
  227. package/src/arch/svm/SpokeUtils.ts +67 -53
  228. package/src/arch/svm/eventsClient.ts +40 -8
  229. package/src/arch/svm/utils.ts +6 -6
  230. package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +7 -4
  231. package/src/clients/BundleDataClient/BundleDataClient.ts +56 -56
  232. package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +32 -15
  233. package/src/clients/BundleDataClient/utils/FillUtils.ts +12 -8
  234. package/src/clients/BundleDataClient/utils/MerkleTreeUtils.ts +7 -1
  235. package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +4 -4
  236. package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +22 -10
  237. package/src/clients/HubPoolClient.ts +125 -86
  238. package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +7 -2
  239. package/src/clients/SpokePoolClient/SVMSpokePoolClient.ts +1 -4
  240. package/src/clients/SpokePoolClient/SpokePoolClient.ts +122 -37
  241. package/src/clients/SpokePoolClient/index.ts +1 -0
  242. package/src/clients/index.ts +1 -0
  243. package/src/clients/mocks/MockHubPoolClient.ts +24 -19
  244. package/src/clients/mocks/MockSpokePoolClient.ts +39 -27
  245. package/src/clients/mocks/MockSvmCpiEventsClient.ts +8 -5
  246. package/src/clients/mocks/MockSvmSpokePoolClient.ts +12 -3
  247. package/src/interfaces/HubPool.ts +20 -14
  248. package/src/interfaces/SpokePool.ts +19 -19
  249. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +39 -21
  250. package/src/relayFeeCalculator/chain-queries/factory.ts +8 -5
  251. package/src/relayFeeCalculator/chain-queries/svmQuery.ts +73 -58
  252. package/src/relayFeeCalculator/relayFeeCalculator.ts +23 -21
  253. package/src/utils/AddressUtils.ts +39 -51
  254. package/src/utils/DepositUtils.ts +4 -4
  255. package/src/utils/SpokeUtils.ts +8 -36
  256. package/src/utils/TokenUtils.ts +10 -8
@@ -5,33 +5,35 @@ import {
5
5
  DEFAULT_SIMULATED_RELAYER_ADDRESS_SVM,
6
6
  TOKEN_SYMBOLS_MAP,
7
7
  } from "../constants";
8
- import { Deposit } from "../interfaces";
8
+ import { RelayData } from "../interfaces";
9
9
  import {
10
10
  BigNumber,
11
11
  BigNumberish,
12
- ConvertDecimals,
13
12
  MAX_BIG_INT,
14
13
  TransactionCostEstimate,
15
14
  bnZero,
16
- chainIsSvm,
17
- compareAddressesSimple,
18
15
  fixedPointAdjustment,
19
16
  getTokenInfo,
20
17
  isDefined,
21
- isZeroAddress,
22
18
  max,
23
19
  min,
24
20
  nativeToToken,
25
21
  percent,
26
22
  toBN,
27
23
  toBNWei,
24
+ compareAddressesSimple,
25
+ ConvertDecimals,
26
+ chainIsSvm,
27
+ Address,
28
+ EvmAddress,
29
+ SvmAddress,
28
30
  } from "../utils";
29
31
 
30
32
  // This needs to be implemented for every chain and passed into RelayFeeCalculator
31
33
  export interface QueryInterface {
32
34
  getGasCosts: (
33
- deposit: Omit<Deposit, "messageHash">,
34
- relayer: string,
35
+ deposit: RelayData & { destinationChainId: number },
36
+ relayer: Address,
35
37
  options?: Partial<{
36
38
  gasPrice: BigNumberish;
37
39
  gasUnits: BigNumberish;
@@ -42,7 +44,7 @@ export interface QueryInterface {
42
44
  }>
43
45
  ) => Promise<TransactionCostEstimate>;
44
46
  getTokenPrice: (tokenSymbol: string) => Promise<number>;
45
- getNativeGasCost: (deposit: Omit<Deposit, "messageHash">, relayer: string) => Promise<BigNumber>;
47
+ getNativeGasCost: (deposit: RelayData & { destinationChainId: number }, relayer: Address) => Promise<BigNumber>;
46
48
  }
47
49
 
48
50
  export const expectedCapitalCostsKeys = ["lowerBound", "upperBound", "cutoff", "decimals"];
@@ -112,10 +114,10 @@ export const DEFAULT_LOGGER: Logger = {
112
114
  error: (...args) => console.error(args),
113
115
  };
114
116
 
115
- export function getDefaultSimulatedRelayerAddress(chainId?: number) {
117
+ export function getDefaultRelayer(chainId?: number): Address {
116
118
  return isDefined(chainId) && chainIsSvm(chainId)
117
- ? DEFAULT_SIMULATED_RELAYER_ADDRESS_SVM
118
- : DEFAULT_SIMULATED_RELAYER_ADDRESS;
119
+ ? SvmAddress.from(DEFAULT_SIMULATED_RELAYER_ADDRESS_SVM)
120
+ : EvmAddress.from(DEFAULT_SIMULATED_RELAYER_ADDRESS);
119
121
  }
120
122
 
121
123
  // Small amount to simulate filling with. Should be low enough to guarantee a successful fill.
@@ -251,10 +253,10 @@ export class RelayFeeCalculator {
251
253
  * the correct parameters to see a full fill.
252
254
  */
253
255
  async gasFeePercent(
254
- deposit: Deposit,
256
+ deposit: RelayData & { destinationChainId: number },
255
257
  outputAmount: BigNumberish,
256
258
  simulateZeroFill = false,
257
- relayerAddress = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
259
+ relayerAddress = getDefaultRelayer(deposit.destinationChainId),
258
260
  _tokenPrice?: number,
259
261
  tokenMapping = TOKEN_SYMBOLS_MAP,
260
262
  gasPrice?: BigNumberish,
@@ -271,14 +273,14 @@ export class RelayFeeCalculator {
271
273
  // undefined address on destination.
272
274
  const destinationChainTokenDetails = Object.values(tokenMapping).find(
273
275
  (details) =>
274
- compareAddressesSimple(details.addresses[originChainId], inputToken) &&
276
+ compareAddressesSimple(details.addresses[originChainId], inputToken.toNative()) &&
275
277
  isDefined(details.addresses[destinationChainId])
276
278
  );
277
- const outputToken = isZeroAddress(deposit.outputToken)
279
+ const outputToken = deposit.outputToken.isZeroAddress()
278
280
  ? destinationChainTokenDetails!.addresses[destinationChainId]
279
- : deposit.outputToken;
281
+ : deposit.outputToken.toNative();
280
282
  const outputTokenInfo = getTokenInfo(outputToken, destinationChainId, tokenMapping);
281
- const inputTokenInfo = getTokenInfo(inputToken, originChainId, tokenMapping);
283
+ const inputTokenInfo = getTokenInfo(inputToken.toNative(), originChainId, tokenMapping);
282
284
  if (!isDefined(outputTokenInfo) || !isDefined(inputTokenInfo)) {
283
285
  throw new Error(`Could not find token information for ${inputToken} or ${outputToken}`);
284
286
  }
@@ -490,10 +492,10 @@ export class RelayFeeCalculator {
490
492
  * @returns A resulting `RelayerFeeDetails` object
491
493
  */
492
494
  async relayerFeeDetails(
493
- deposit: Deposit,
495
+ deposit: RelayData & { destinationChainId: number },
494
496
  outputAmount?: BigNumberish,
495
497
  simulateZeroFill = false,
496
- relayerAddress = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
498
+ relayerAddress = getDefaultRelayer(deposit.destinationChainId),
497
499
  _tokenPrice?: number,
498
500
  gasPrice?: BigNumberish,
499
501
  gasUnits?: BigNumberish,
@@ -505,8 +507,8 @@ export class RelayFeeCalculator {
505
507
  const { inputToken, originChainId, outputToken, destinationChainId } = deposit;
506
508
  // We can perform a simple lookup with `getTokenInfo` here without resolving the exact token to resolve since we only need to
507
509
  // resolve the L1 token symbol and not the L2 token decimals.
508
- const inputTokenInfo = getTokenInfo(inputToken, originChainId);
509
- const outputTokenInfo = getTokenInfo(outputToken, destinationChainId);
510
+ const inputTokenInfo = getTokenInfo(inputToken.toNative(), originChainId);
511
+ const outputTokenInfo = getTokenInfo(outputToken.toNative(), destinationChainId);
510
512
  if (!isDefined(inputTokenInfo) || !isDefined(outputTokenInfo)) {
511
513
  throw new Error(`Could not find token information for ${inputToken} or ${outputToken}`);
512
514
  }
@@ -81,15 +81,15 @@ export function isValidEvmAddress(address: string): boolean {
81
81
  export function toAddressType(address: string, chainId: number): Address {
82
82
  const rawAddress = address.startsWith("0x") ? utils.arrayify(address) : bs58.decode(address);
83
83
 
84
- const isEvm = chainIsEvm(chainId);
85
- if (isEvm && EvmAddress.validate(rawAddress)) return new EvmAddress(rawAddress);
86
- if (!isEvm && SvmAddress.validate(rawAddress)) return new SvmAddress(rawAddress);
87
- return new Address(rawAddress);
84
+ if (chainIsEvm(chainId) && EvmAddress.validate(rawAddress)) return new EvmAddress(rawAddress);
85
+ else if (chainIsSvm(chainId) && SvmAddress.validate(rawAddress)) return new SvmAddress(rawAddress);
86
+
87
+ return new RawAddress(rawAddress);
88
88
  }
89
89
 
90
90
  // The Address class can contain any address type. It is up to the subclasses to determine how to format the address's internal representation,
91
91
  // which for this class, is a bytes32 hex string.
92
- export class Address {
92
+ export abstract class Address {
93
93
  readonly rawAddress: Uint8Array;
94
94
 
95
95
  // Keep all address types in cache so that we may lazily evaluate them when necessary.
@@ -109,10 +109,6 @@ export class Address {
109
109
  this.rawAddress = utils.zeroPad(_rawAddress, 32);
110
110
  }
111
111
 
112
- static __unsafeConstruct(_rawAddress: Uint8Array): Address {
113
- return new this(_rawAddress);
114
- }
115
-
116
112
  // Converts the address into a bytes32 string. Note that the output bytes will be lowercase so that it matches ethers event data. This function will never
117
113
  // throw since address length validation was done at construction time.
118
114
  toBytes32(): string {
@@ -167,11 +163,6 @@ export class Address {
167
163
  return false;
168
164
  }
169
165
 
170
- // Checks if the object is an address by looking at whether it has an Address constructor.
171
- static isAddress(obj: unknown): boolean {
172
- return obj instanceof this;
173
- }
174
-
175
166
  // Converts the input address to a 32-byte hex data string.
176
167
  toString(): string {
177
168
  return this.toNative();
@@ -193,6 +184,7 @@ export class Address {
193
184
  }
194
185
 
195
186
  // Compares Addresses by first converting them to BigNumbers.
187
+ // note: Intended for use when sorting like addresses.
196
188
  compare(otherAddress: Address): 1 | -1 | 0 {
197
189
  // Convert address strings to BigNumbers and then sort numerical value of the BigNumber, which sorts the addresses
198
190
  // effectively by their hex value.
@@ -207,20 +199,18 @@ export class Address {
207
199
  }
208
200
  }
209
201
 
210
- static isEvmAddress(address: Address): boolean {
211
- return address instanceof EvmAddress;
202
+ isEVM(): this is EvmAddress {
203
+ return false;
212
204
  }
213
205
 
214
- static isSvmAddress(address: Address): boolean {
215
- return address instanceof SvmAddress;
206
+ isSVM(): this is SvmAddress {
207
+ return false;
216
208
  }
217
209
  }
218
210
 
219
211
  // Subclass of address which strictly deals with 20-byte addresses. These addresses are guaranteed to be valid EVM addresses, so `toAddress` will always succeed.
220
212
  export class EvmAddress extends Address {
221
- // @dev This property is required for Typescript typechecker to know to distinguish between `Address`, `SvmAddress` and `EvmAddress`.
222
- // Otherwise it lets any of these to use in place where other is expected.
223
- private readonly _brandEvmAddress!: void;
213
+ private readonly _type = "evm";
224
214
 
225
215
  // On construction, validate that the address can indeed be coerced into an EVM address. Throw immediately if it cannot.
226
216
  constructor(rawAddress: Uint8Array) {
@@ -229,8 +219,7 @@ export class EvmAddress extends Address {
229
219
  }
230
220
 
231
221
  super(rawAddress);
232
- // @dev required for TS to compile with `noUnusedLocals` rule
233
- this._brandEvmAddress;
222
+ this._type; // tsc noUnusedLocals appeasement.
234
223
  }
235
224
 
236
225
  static validate(rawAddress: Uint8Array): boolean {
@@ -239,34 +228,24 @@ export class EvmAddress extends Address {
239
228
  );
240
229
  }
241
230
 
231
+ override isEVM(): this is EvmAddress {
232
+ return true;
233
+ }
234
+
242
235
  // Override `toAddress` to return the 20-byte representation address.
243
236
  override toNative(): string {
244
237
  return this.toEvmAddress();
245
238
  }
246
239
 
247
240
  // Constructs a new EvmAddress type.
248
- static from(address: string, encoding: "base16" | "base58" = "base16"): EvmAddress {
249
- if (encoding === "base16") {
250
- return new this(utils.arrayify(address));
251
- }
252
-
253
- const decodedAddress = bs58.decode(address);
254
- const padding = decodedAddress.subarray(0, 12);
255
- const evmAddress = decodedAddress.subarray(12);
256
-
257
- if (padding.length !== 12 || utils.stripZeros(padding).length !== 0 || evmAddress.length !== 20) {
258
- throw new Error(`Not a valid base58-encoded EVM address: ${address}`);
259
- }
260
-
261
- return new this(evmAddress);
241
+ static from(address: string, encoding: "base58" | "base16" = "base16"): EvmAddress {
242
+ return encoding === "base16" ? new this(utils.arrayify(address)) : new this(bs58.decode(address));
262
243
  }
263
244
  }
264
245
 
265
246
  // Subclass of address which strictly deals SVM addresses. These addresses are guaranteed to be valid SVM addresses, so `toBase58` will always produce a valid Solana address.
266
247
  export class SvmAddress extends Address {
267
- // @dev This property is required for Typescript typechecker to know to distinguish between `Address`, `SvmAddress` and `EvmAddress`.
268
- // Otherwise it lets any of these to use in place where other is expected.
269
- private readonly _brandSvmAddress!: void;
248
+ private readonly _type = "svm";
270
249
 
271
250
  // On construction, validate that the address is a point on Curve25519. Throw immediately if it is not.
272
251
  constructor(rawAddress: Uint8Array) {
@@ -275,12 +254,21 @@ export class SvmAddress extends Address {
275
254
  }
276
255
 
277
256
  super(rawAddress);
278
- // @dev required for TS to compile with `noUnusedLocals` rule
279
- this._brandSvmAddress;
257
+ this._type; // tsc noUnusedLocals appeasement.
280
258
  }
281
259
 
282
260
  static validate(rawAddress: Uint8Array): boolean {
283
- return rawAddress.length === 32;
261
+ // Deliberately invalidate SVM addresses w/ the upper 12 bytes zeroed. These addresses are technically valid
262
+ // but highly improbable and are much more likely to be a mistaken interpretation of an EVM address. Err on
263
+ // the side of caution for the time being. Exception: Permit the zero address (i.e. for exclusiverRelayer).
264
+ return (
265
+ rawAddress.length === 32 &&
266
+ (!rawAddress.slice(0, 12).every((field) => field === 0) || rawAddress.every((field) => field === 0))
267
+ );
268
+ }
269
+
270
+ override isSVM(): this is SvmAddress {
271
+ return true;
284
272
  }
285
273
 
286
274
  // Override the toAddress function for SVM addresses only since while they will never have a defined 20-byte representation. The base58 encoded addresses are also the encodings
@@ -291,15 +279,15 @@ export class SvmAddress extends Address {
291
279
 
292
280
  // Constructs a new SvmAddress type.
293
281
  static from(address: string, encoding: "base58" | "base16" = "base58"): SvmAddress {
294
- if (encoding === "base58") {
295
- return new this(bs58.decode(address));
296
- }
282
+ return encoding === "base58" ? new this(bs58.decode(address)) : new this(utils.arrayify(address));
283
+ }
284
+ }
297
285
 
298
- const decodedAddress = utils.arrayify(address);
299
- if (decodedAddress.length !== 32) {
300
- throw new Error(`Not a valid base16-encoded SVM address: ${address}`);
301
- }
286
+ export class RawAddress extends Address {
287
+ private readonly _type = "raw";
302
288
 
303
- return new this(decodedAddress);
289
+ constructor(rawAddress: Uint8Array) {
290
+ super(rawAddress);
291
+ this._type; // tsc noUnusedLocals appeasement.
304
292
  }
305
293
  }
@@ -2,7 +2,7 @@ import assert from "assert";
2
2
  import { SpokePoolClient } from "../clients";
3
3
  import { DEFAULT_CACHING_TTL, EMPTY_MESSAGE, UNDEFINED_MESSAGE_HASH, ZERO_BYTES } from "../constants";
4
4
  import { CachingMechanismInterface, Deposit, DepositWithBlock, Fill, RelayData, SlowFillRequest } from "../interfaces";
5
- import { getMessageHash, isUnsafeDepositId, isZeroAddress } from "./SpokeUtils";
5
+ import { getMessageHash, isUnsafeDepositId } from "./SpokeUtils";
6
6
  import { getNetworkName } from "./NetworkUtils";
7
7
  import { bnZero } from "./BigNumberUtils";
8
8
  import { getDepositInCache, getDepositKey, setDepositInCache } from "./CachingUtils";
@@ -204,13 +204,13 @@ export function validateFillForDeposit(
204
204
  * @param deposit Deposit to check.
205
205
  * @returns True if deposit's input amount is 0 and message is empty.
206
206
  */
207
- export function isZeroValueDeposit(deposit: Pick<Deposit, "inputAmount" | "message">): boolean {
207
+ export function isZeroValueDeposit(deposit: Pick<RelayData, "inputAmount" | "message">): boolean {
208
208
  return deposit.inputAmount.eq(0) && isMessageEmpty(deposit.message);
209
209
  }
210
210
 
211
- export function invalidOutputToken(deposit: Pick<DepositWithBlock, "outputToken">): boolean {
211
+ export function invalidOutputToken(deposit: Pick<RelayData, "outputToken">): boolean {
212
212
  // If the output token is zero address, then it is invalid.
213
- return isZeroAddress(deposit.outputToken);
213
+ return deposit.outputToken.isZeroAddress();
214
214
  }
215
215
 
216
216
  export function isZeroValueFillOrSlowFillRequest(
@@ -1,8 +1,7 @@
1
1
  import { encodeAbiParameters, Hex, keccak256 } from "viem";
2
2
  import { fixedPointAdjustment as fixedPoint } from "./common";
3
- import { MAX_SAFE_DEPOSIT_ID, ZERO_ADDRESS, ZERO_BYTES } from "../constants";
4
- import { Deposit, Fill, FillType, RelayData, SlowFillLeaf } from "../interfaces";
5
- import { toBytes32 } from "./AddressUtils";
3
+ import { MAX_SAFE_DEPOSIT_ID, ZERO_BYTES } from "../constants";
4
+ import { Fill, FillType, RelayData, SlowFillLeaf } from "../interfaces";
6
5
  import { BigNumber } from "./BigNumberUtils";
7
6
  import { isMessageEmpty } from "./DepositUtils";
8
7
  import { chainIsSvm } from "./NetworkUtils";
@@ -16,28 +15,6 @@ export function getSlowFillLeafLpFeePct(leaf: SlowFillLeaf): BigNumber {
16
15
  const { relayData, updatedOutputAmount } = leaf;
17
16
  return relayData.inputAmount.sub(updatedOutputAmount).mul(fixedPoint).div(relayData.inputAmount);
18
17
  }
19
- /**
20
- * Produce the RelayData for a Deposit.
21
- * @param deposit Deposit instance.
22
- * @returns The corresponding RelayData object.
23
- */
24
- export function getDepositRelayData(deposit: Omit<Deposit, "messageHash">): RelayData {
25
- return {
26
- depositor: toBytes32(deposit.depositor),
27
- recipient: toBytes32(deposit.recipient),
28
- exclusiveRelayer: toBytes32(deposit.exclusiveRelayer),
29
- inputToken: toBytes32(deposit.inputToken),
30
- outputToken: toBytes32(deposit.outputToken),
31
- inputAmount: deposit.inputAmount,
32
- outputAmount: deposit.outputAmount,
33
- originChainId: deposit.originChainId,
34
- depositId: deposit.depositId,
35
- fillDeadline: deposit.fillDeadline,
36
- exclusivityDeadline: deposit.exclusivityDeadline,
37
- message: deposit.message,
38
- };
39
- }
40
-
41
18
  /**
42
19
  * Compute the RelayData hash for a fill. This can be used to determine the fill status.
43
20
  * @param relayData RelayData information that is used to complete a fill.
@@ -68,14 +45,14 @@ export function getRelayDataHash(relayData: RelayData, destinationChainId: numbe
68
45
 
69
46
  const _relayData = {
70
47
  ...relayData,
71
- depositor: toBytes32(relayData.depositor),
72
- recipient: toBytes32(relayData.recipient),
73
- inputToken: toBytes32(relayData.inputToken),
74
- outputToken: toBytes32(relayData.outputToken),
75
- exclusiveRelayer: toBytes32(relayData.exclusiveRelayer),
48
+ depositor: relayData.depositor.toBytes32(),
49
+ recipient: relayData.recipient.toBytes32(),
50
+ inputToken: relayData.inputToken.toBytes32(),
51
+ outputToken: relayData.outputToken.toBytes32(),
52
+ exclusiveRelayer: relayData.exclusiveRelayer.toBytes32(),
76
53
  };
77
54
  if (chainIsSvm(destinationChainId)) {
78
- return svm.getRelayDataHash(_relayData, destinationChainId);
55
+ return svm.getRelayDataHash(relayData, destinationChainId);
79
56
  }
80
57
  return keccak256(encodeAbiParameters(abi, [_relayData, destinationChainId]));
81
58
  }
@@ -94,11 +71,6 @@ export function isUnsafeDepositId(depositId: BigNumber): boolean {
94
71
  return maxSafeDepositId.lt(depositId);
95
72
  }
96
73
 
97
- // Determines if the input address (either a bytes32 or bytes20) is the zero address.
98
- export function isZeroAddress(address: string): boolean {
99
- return address === ZERO_ADDRESS || address === ZERO_BYTES;
100
- }
101
-
102
74
  export function getMessageHash(message: string): string {
103
75
  return isMessageEmpty(message) ? ZERO_BYTES : keccak256(message as Hex);
104
76
  }
@@ -1,20 +1,21 @@
1
+ import assert from "assert";
1
2
  import { BlockTag } from "@ethersproject/abstract-provider";
2
3
  import { Contract, providers, Signer } from "ethers";
3
4
  import * as constants from "../constants";
4
- import { L1Token } from "../interfaces";
5
+ import { L1TokenInfo, TokenInfo } from "../interfaces";
5
6
  import { ERC20__factory } from "../typechain";
6
7
  import { BigNumber } from "./BigNumberUtils";
7
8
  import { getNetworkName, chainIsL1, chainIsProd } from "./NetworkUtils";
8
9
  import { isDefined } from "./TypeGuards";
9
- import { compareAddressesSimple, toAddressType } from "./AddressUtils";
10
+ import { compareAddressesSimple, EvmAddress, toAddressType } from "./AddressUtils";
10
11
  const { TOKEN_SYMBOLS_MAP, CHAIN_IDs, TOKEN_EQUIVALENCE_REMAPPING } = constants;
11
12
 
12
13
  type SignerOrProvider = providers.Provider | Signer;
13
14
 
14
- export async function fetchTokenInfo(address: string, signerOrProvider: SignerOrProvider): Promise<L1Token> {
15
+ export async function fetchTokenInfo(address: string, signerOrProvider: SignerOrProvider): Promise<L1TokenInfo> {
15
16
  const token = new Contract(address, ERC20__factory.abi, signerOrProvider);
16
17
  const [symbol, decimals] = await Promise.all([token.symbol(), token.decimals()]);
17
- return { address, symbol, decimals };
18
+ return { address: EvmAddress.from(address), symbol, decimals };
18
19
  }
19
20
 
20
21
  export const getL2TokenAddresses = (
@@ -33,7 +34,7 @@ export const getL2TokenAddresses = (
33
34
  * @param chainId Chain ID to query on.
34
35
  * @returns Symbol, decimals and contract address on the requested chain.
35
36
  */
36
- export function resolveSymbolOnChain(chainId: number, symbol: string): L1Token {
37
+ export function resolveSymbolOnChain(chainId: number, symbol: string): TokenInfo {
37
38
  // @dev Suppress tsc complaints by casting symbol to the expected type.
38
39
  const token = TOKEN_SYMBOLS_MAP[symbol as keyof typeof TOKEN_SYMBOLS_MAP];
39
40
  if (!isDefined(token) || !isDefined(token.addresses[chainId])) {
@@ -42,7 +43,8 @@ export function resolveSymbolOnChain(chainId: number, symbol: string): L1Token {
42
43
  }
43
44
 
44
45
  const { decimals, addresses } = token;
45
- const address = addresses[chainId];
46
+ const address = toAddressType(addresses[chainId], chainId);
47
+ assert(address.isEVM() || address.isSVM());
46
48
 
47
49
  return { symbol, decimals, address };
48
50
  }
@@ -111,7 +113,7 @@ export function isStablecoin(tokenSymbol: string): boolean {
111
113
  * @param tokenMapping
112
114
  * @returns
113
115
  */
114
- export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): L1Token {
116
+ export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): TokenInfo {
115
117
  const parsedAddress = toAddressType(l2TokenAddress, chainId).toNative();
116
118
 
117
119
  // @dev This might give false positives if tokens on different networks have the same address. I'm not sure how
@@ -127,7 +129,7 @@ export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMappi
127
129
  tokenObject = tokenMapping[l1TokenSymbol as keyof typeof tokenMapping];
128
130
  }
129
131
  return {
130
- address: l2TokenAddress,
132
+ address: toAddressType(l2TokenAddress, chainId),
131
133
  symbol: tokenObject.symbol,
132
134
  decimals: tokenObject.decimals,
133
135
  };