@across-protocol/sdk 4.2.16-alpha.6 → 4.2.16

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 (234) hide show
  1. package/dist/cjs/arch/evm/SpokeUtils.d.ts +3 -8
  2. package/dist/cjs/arch/evm/SpokeUtils.js +11 -26
  3. package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
  4. package/dist/cjs/arch/svm/SpokeUtils.d.ts +2 -8
  5. package/dist/cjs/arch/svm/SpokeUtils.js +50 -41
  6. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  7. package/dist/cjs/arch/svm/eventsClient.js +2 -4
  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 +14 -16
  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 +2 -4
  14. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  15. package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +6 -7
  16. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +83 -78
  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 +1 -2
  21. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +2 -3
  22. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  23. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +1 -5
  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 +8 -13
  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 +58 -84
  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 +45 -65
  37. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  38. package/dist/cjs/clients/SpokePoolClient/SpokePoolClientManager.d.ts +13 -0
  39. package/dist/cjs/clients/SpokePoolClient/SpokePoolClientManager.js +18 -0
  40. package/dist/cjs/clients/SpokePoolClient/SpokePoolClientManager.js.map +1 -0
  41. package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +9 -9
  42. package/dist/cjs/clients/mocks/MockHubPoolClient.js +9 -15
  43. package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
  44. package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +3 -5
  45. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +36 -40
  46. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  47. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  48. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +4 -6
  49. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  50. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
  51. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +2 -2
  52. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  53. package/dist/cjs/interfaces/HubPool.d.ts +14 -19
  54. package/dist/cjs/interfaces/SpokePool.d.ts +19 -18
  55. package/dist/cjs/interfaces/SpokePool.js.map +1 -1
  56. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +7 -15
  57. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +15 -24
  58. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  59. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +1 -1
  60. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  61. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +4 -12
  62. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +44 -46
  63. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  64. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +6 -6
  65. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +10 -10
  66. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  67. package/dist/cjs/utils/AddressUtils.d.ts +8 -12
  68. package/dist/cjs/utils/AddressUtils.js +36 -33
  69. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  70. package/dist/cjs/utils/NetworkUtils.js +1 -1
  71. package/dist/cjs/utils/NetworkUtils.js.map +1 -1
  72. package/dist/cjs/utils/SpokeUtils.d.ts +3 -3
  73. package/dist/cjs/utils/SpokeUtils.js +22 -4
  74. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  75. package/dist/cjs/utils/TokenUtils.d.ts +4 -4
  76. package/dist/cjs/utils/TokenUtils.js +3 -5
  77. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  78. package/dist/esm/arch/evm/SpokeUtils.d.ts +4 -9
  79. package/dist/esm/arch/evm/SpokeUtils.js +14 -29
  80. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  81. package/dist/esm/arch/svm/SpokeUtils.d.ts +3 -9
  82. package/dist/esm/arch/svm/SpokeUtils.js +55 -42
  83. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  84. package/dist/esm/arch/svm/eventsClient.js +3 -5
  85. package/dist/esm/arch/svm/eventsClient.js.map +1 -1
  86. package/dist/esm/arch/svm/utils.d.ts +3 -3
  87. package/dist/esm/arch/svm/utils.js +15 -17
  88. package/dist/esm/arch/svm/utils.js.map +1 -1
  89. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  90. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +2 -4
  91. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  92. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +6 -7
  93. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +84 -79
  94. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  95. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +14 -14
  96. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  97. package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +1 -2
  98. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +3 -5
  99. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  100. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +1 -5
  101. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  102. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +4 -4
  103. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  104. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +71 -71
  105. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +10 -20
  106. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  107. package/dist/esm/clients/HubPoolClient.d.ts +22 -23
  108. package/dist/esm/clients/HubPoolClient.js +63 -98
  109. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  110. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +2 -2
  111. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  112. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  113. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +47 -68
  114. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  115. package/dist/esm/clients/SpokePoolClient/SpokePoolClientManager.d.ts +28 -0
  116. package/dist/esm/clients/SpokePoolClient/SpokePoolClientManager.js +30 -0
  117. package/dist/esm/clients/SpokePoolClient/SpokePoolClientManager.js.map +1 -0
  118. package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +9 -9
  119. package/dist/esm/clients/mocks/MockHubPoolClient.js +10 -16
  120. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  121. package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +3 -5
  122. package/dist/esm/clients/mocks/MockSpokePoolClient.js +38 -42
  123. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  124. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  125. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +5 -7
  126. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  127. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
  128. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +3 -3
  129. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  130. package/dist/esm/interfaces/HubPool.d.ts +14 -19
  131. package/dist/esm/interfaces/SpokePool.d.ts +19 -18
  132. package/dist/esm/interfaces/SpokePool.js.map +1 -1
  133. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +10 -18
  134. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +20 -29
  135. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  136. package/dist/esm/relayFeeCalculator/chain-queries/factory.js +2 -2
  137. package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  138. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +6 -14
  139. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +48 -51
  140. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  141. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +6 -6
  142. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +9 -9
  143. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  144. package/dist/esm/utils/AddressUtils.d.ts +8 -12
  145. package/dist/esm/utils/AddressUtils.js +38 -36
  146. package/dist/esm/utils/AddressUtils.js.map +1 -1
  147. package/dist/esm/utils/NetworkUtils.js +1 -1
  148. package/dist/esm/utils/NetworkUtils.js.map +1 -1
  149. package/dist/esm/utils/SpokeUtils.d.ts +8 -3
  150. package/dist/esm/utils/SpokeUtils.js +26 -4
  151. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  152. package/dist/esm/utils/TokenUtils.d.ts +18 -22
  153. package/dist/esm/utils/TokenUtils.js +4 -6
  154. package/dist/esm/utils/TokenUtils.js.map +1 -1
  155. package/dist/types/arch/evm/SpokeUtils.d.ts +4 -9
  156. package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
  157. package/dist/types/arch/svm/SpokeUtils.d.ts +3 -9
  158. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
  159. package/dist/types/arch/svm/eventsClient.d.ts.map +1 -1
  160. package/dist/types/arch/svm/utils.d.ts +3 -3
  161. package/dist/types/arch/svm/utils.d.ts.map +1 -1
  162. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  163. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
  164. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +6 -7
  165. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  166. package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
  167. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +1 -2
  168. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
  169. package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts.map +1 -1
  170. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
  171. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +71 -71
  172. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
  173. package/dist/types/clients/HubPoolClient.d.ts +22 -23
  174. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  175. package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
  176. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  177. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  178. package/dist/types/clients/SpokePoolClient/SpokePoolClientManager.d.ts +29 -0
  179. package/dist/types/clients/SpokePoolClient/SpokePoolClientManager.d.ts.map +1 -0
  180. package/dist/types/clients/mocks/MockHubPoolClient.d.ts +9 -9
  181. package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
  182. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +3 -5
  183. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
  184. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  185. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts.map +1 -1
  186. package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
  187. package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts.map +1 -1
  188. package/dist/types/interfaces/HubPool.d.ts +14 -19
  189. package/dist/types/interfaces/HubPool.d.ts.map +1 -1
  190. package/dist/types/interfaces/SpokePool.d.ts +19 -18
  191. package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
  192. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +10 -18
  193. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  194. package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
  195. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +6 -14
  196. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
  197. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +6 -6
  198. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  199. package/dist/types/utils/AddressUtils.d.ts +8 -12
  200. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  201. package/dist/types/utils/SpokeUtils.d.ts +8 -3
  202. package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
  203. package/dist/types/utils/TokenUtils.d.ts +18 -22
  204. package/dist/types/utils/TokenUtils.d.ts.map +1 -1
  205. package/package.json +2 -1
  206. package/src/arch/evm/SpokeUtils.ts +22 -72
  207. package/src/arch/svm/SpokeUtils.ts +53 -67
  208. package/src/arch/svm/eventsClient.ts +8 -40
  209. package/src/arch/svm/utils.ts +6 -6
  210. package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +4 -7
  211. package/src/clients/BundleDataClient/BundleDataClient.ts +90 -77
  212. package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +13 -28
  213. package/src/clients/BundleDataClient/utils/FillUtils.ts +4 -10
  214. package/src/clients/BundleDataClient/utils/MerkleTreeUtils.ts +1 -7
  215. package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +4 -4
  216. package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +10 -22
  217. package/src/clients/HubPoolClient.ts +82 -127
  218. package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +0 -6
  219. package/src/clients/SpokePoolClient/SpokePoolClient.ts +35 -121
  220. package/src/clients/SpokePoolClient/SpokePoolClientManager.ts +36 -0
  221. package/src/clients/mocks/MockHubPoolClient.ts +19 -24
  222. package/src/clients/mocks/MockSpokePoolClient.ts +27 -39
  223. package/src/clients/mocks/MockSvmCpiEventsClient.ts +5 -8
  224. package/src/clients/mocks/MockSvmSpokePoolClient.ts +3 -12
  225. package/src/interfaces/HubPool.ts +14 -23
  226. package/src/interfaces/SpokePool.ts +19 -19
  227. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +20 -39
  228. package/src/relayFeeCalculator/chain-queries/factory.ts +2 -2
  229. package/src/relayFeeCalculator/chain-queries/svmQuery.ts +56 -57
  230. package/src/relayFeeCalculator/relayFeeCalculator.ts +13 -15
  231. package/src/utils/AddressUtils.ts +51 -39
  232. package/src/utils/NetworkUtils.ts +1 -1
  233. package/src/utils/SpokeUtils.ts +33 -11
  234. package/src/utils/TokenUtils.ts +8 -10
@@ -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
- 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);
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);
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 abstract class Address {
92
+ export 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,6 +109,10 @@ export abstract 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
+
112
116
  // 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
113
117
  // throw since address length validation was done at construction time.
114
118
  toBytes32(): string {
@@ -163,6 +167,11 @@ export abstract class Address {
163
167
  return false;
164
168
  }
165
169
 
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
+
166
175
  // Converts the input address to a 32-byte hex data string.
167
176
  toString(): string {
168
177
  return this.toNative();
@@ -184,7 +193,6 @@ export abstract class Address {
184
193
  }
185
194
 
186
195
  // Compares Addresses by first converting them to BigNumbers.
187
- // note: Intended for use when sorting like addresses.
188
196
  compare(otherAddress: Address): 1 | -1 | 0 {
189
197
  // Convert address strings to BigNumbers and then sort numerical value of the BigNumber, which sorts the addresses
190
198
  // effectively by their hex value.
@@ -199,18 +207,20 @@ export abstract class Address {
199
207
  }
200
208
  }
201
209
 
202
- isEVM(): this is EvmAddress {
203
- return false;
210
+ static isEvmAddress(address: Address): boolean {
211
+ return address instanceof EvmAddress;
204
212
  }
205
213
 
206
- isSVM(): this is SvmAddress {
207
- return false;
214
+ static isSvmAddress(address: Address): boolean {
215
+ return address instanceof SvmAddress;
208
216
  }
209
217
  }
210
218
 
211
219
  // Subclass of address which strictly deals with 20-byte addresses. These addresses are guaranteed to be valid EVM addresses, so `toAddress` will always succeed.
212
220
  export class EvmAddress extends Address {
213
- private readonly _type = "evm";
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;
214
224
 
215
225
  // On construction, validate that the address can indeed be coerced into an EVM address. Throw immediately if it cannot.
216
226
  constructor(rawAddress: Uint8Array) {
@@ -219,7 +229,8 @@ export class EvmAddress extends Address {
219
229
  }
220
230
 
221
231
  super(rawAddress);
222
- this._type; // tsc noUnusedLocals appeasement.
232
+ // @dev required for TS to compile with `noUnusedLocals` rule
233
+ this._brandEvmAddress;
223
234
  }
224
235
 
225
236
  static validate(rawAddress: Uint8Array): boolean {
@@ -228,24 +239,34 @@ export class EvmAddress extends Address {
228
239
  );
229
240
  }
230
241
 
231
- override isEVM(): this is EvmAddress {
232
- return true;
233
- }
234
-
235
242
  // Override `toAddress` to return the 20-byte representation address.
236
243
  override toNative(): string {
237
244
  return this.toEvmAddress();
238
245
  }
239
246
 
240
247
  // Constructs a new EvmAddress type.
241
- static from(address: string, encoding: "base58" | "base16" = "base16"): EvmAddress {
242
- return encoding === "base16" ? new this(utils.arrayify(address)) : new this(bs58.decode(address));
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);
243
262
  }
244
263
  }
245
264
 
246
265
  // 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.
247
266
  export class SvmAddress extends Address {
248
- private readonly _type = "svm";
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;
249
270
 
250
271
  // On construction, validate that the address is a point on Curve25519. Throw immediately if it is not.
251
272
  constructor(rawAddress: Uint8Array) {
@@ -254,21 +275,12 @@ export class SvmAddress extends Address {
254
275
  }
255
276
 
256
277
  super(rawAddress);
257
- this._type; // tsc noUnusedLocals appeasement.
278
+ // @dev required for TS to compile with `noUnusedLocals` rule
279
+ this._brandSvmAddress;
258
280
  }
259
281
 
260
282
  static validate(rawAddress: Uint8Array): boolean {
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;
283
+ return rawAddress.length === 32;
272
284
  }
273
285
 
274
286
  // 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
@@ -279,15 +291,15 @@ export class SvmAddress extends Address {
279
291
 
280
292
  // Constructs a new SvmAddress type.
281
293
  static from(address: string, encoding: "base58" | "base16" = "base58"): SvmAddress {
282
- return encoding === "base58" ? new this(bs58.decode(address)) : new this(utils.arrayify(address));
283
- }
284
- }
294
+ if (encoding === "base58") {
295
+ return new this(bs58.decode(address));
296
+ }
285
297
 
286
- export class RawAddress extends Address {
287
- private readonly _type = "raw";
298
+ const decodedAddress = utils.arrayify(address);
299
+ if (decodedAddress.length !== 32) {
300
+ throw new Error(`Not a valid base16-encoded SVM address: ${address}`);
301
+ }
288
302
 
289
- constructor(rawAddress: Uint8Array) {
290
- super(rawAddress);
291
- this._type; // tsc noUnusedLocals appeasement.
303
+ return new this(decodedAddress);
292
304
  }
293
305
  }
@@ -21,7 +21,7 @@ export const hreNetworks: Record<number, string> = {
21
21
  */
22
22
  export function getNetworkName(networkId: number | string): string {
23
23
  networkId = Number(networkId);
24
- return PUBLIC_NETWORKS[networkId]?.name ?? hreNetworks[networkId] ?? "unknown";
24
+ return PUBLIC_NETWORKS[networkId]?.name ?? hreNetworks[networkId] ?? `unknown (${networkId})`;
25
25
  }
26
26
 
27
27
  /**
@@ -1,9 +1,9 @@
1
1
  import { encodeAbiParameters, Hex, keccak256 } from "viem";
2
2
  import { fixedPointAdjustment as fixedPoint } from "./common";
3
- import { MAX_SAFE_DEPOSIT_ID, ZERO_BYTES } from "../constants";
4
- import { Fill, FillType, RelayData, SlowFillLeaf } from "../interfaces";
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";
5
6
  import { BigNumber } from "./BigNumberUtils";
6
- import { Address } from "./AddressUtils";
7
7
  import { isMessageEmpty } from "./DepositUtils";
8
8
  import { chainIsSvm } from "./NetworkUtils";
9
9
  import { svm } from "../arch";
@@ -16,6 +16,28 @@ export function getSlowFillLeafLpFeePct(leaf: SlowFillLeaf): BigNumber {
16
16
  const { relayData, updatedOutputAmount } = leaf;
17
17
  return relayData.inputAmount.sub(updatedOutputAmount).mul(fixedPoint).div(relayData.inputAmount);
18
18
  }
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
+
19
41
  /**
20
42
  * Compute the RelayData hash for a fill. This can be used to determine the fill status.
21
43
  * @param relayData RelayData information that is used to complete a fill.
@@ -46,14 +68,14 @@ export function getRelayDataHash(relayData: RelayData, destinationChainId: numbe
46
68
 
47
69
  const _relayData = {
48
70
  ...relayData,
49
- depositor: relayData.depositor.toBytes32(),
50
- recipient: relayData.recipient.toBytes32(),
51
- inputToken: relayData.inputToken.toBytes32(),
52
- outputToken: relayData.outputToken.toBytes32(),
53
- exclusiveRelayer: relayData.exclusiveRelayer.toBytes32(),
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),
54
76
  };
55
77
  if (chainIsSvm(destinationChainId)) {
56
- return svm.getRelayDataHash(relayData, destinationChainId);
78
+ return svm.getRelayDataHash(_relayData, destinationChainId);
57
79
  }
58
80
  return keccak256(encodeAbiParameters(abi, [_relayData, destinationChainId]));
59
81
  }
@@ -73,8 +95,8 @@ export function isUnsafeDepositId(depositId: BigNumber): boolean {
73
95
  }
74
96
 
75
97
  // Determines if the input address (either a bytes32 or bytes20) is the zero address.
76
- export function isZeroAddress(address: Address): boolean {
77
- return address.toBytes32() === ZERO_BYTES;
98
+ export function isZeroAddress(address: string): boolean {
99
+ return address === ZERO_ADDRESS || address === ZERO_BYTES;
78
100
  }
79
101
 
80
102
  export function getMessageHash(message: string): string {
@@ -1,21 +1,20 @@
1
- import assert from "assert";
2
1
  import { BlockTag } from "@ethersproject/abstract-provider";
3
2
  import { Contract, providers, Signer } from "ethers";
4
3
  import * as constants from "../constants";
5
- import { TokenInfo } from "../interfaces";
4
+ import { L1Token } from "../interfaces";
6
5
  import { ERC20__factory } from "../typechain";
7
6
  import { BigNumber } from "./BigNumberUtils";
8
7
  import { getNetworkName, chainIsL1, chainIsProd } from "./NetworkUtils";
9
8
  import { isDefined } from "./TypeGuards";
10
- import { compareAddressesSimple, EvmAddress, toAddressType } from "./AddressUtils";
9
+ import { compareAddressesSimple, toAddressType } from "./AddressUtils";
11
10
  const { TOKEN_SYMBOLS_MAP, CHAIN_IDs, TOKEN_EQUIVALENCE_REMAPPING } = constants;
12
11
 
13
12
  type SignerOrProvider = providers.Provider | Signer;
14
13
 
15
- export async function fetchTokenInfo(address: string, signerOrProvider: SignerOrProvider): Promise<TokenInfo> {
14
+ export async function fetchTokenInfo(address: string, signerOrProvider: SignerOrProvider): Promise<L1Token> {
16
15
  const token = new Contract(address, ERC20__factory.abi, signerOrProvider);
17
16
  const [symbol, decimals] = await Promise.all([token.symbol(), token.decimals()]);
18
- return { address: EvmAddress.from(address), symbol, decimals };
17
+ return { address, symbol, decimals };
19
18
  }
20
19
 
21
20
  export const getL2TokenAddresses = (
@@ -34,7 +33,7 @@ export const getL2TokenAddresses = (
34
33
  * @param chainId Chain ID to query on.
35
34
  * @returns Symbol, decimals and contract address on the requested chain.
36
35
  */
37
- export function resolveSymbolOnChain(chainId: number, symbol: string): TokenInfo {
36
+ export function resolveSymbolOnChain(chainId: number, symbol: string): L1Token {
38
37
  // @dev Suppress tsc complaints by casting symbol to the expected type.
39
38
  const token = TOKEN_SYMBOLS_MAP[symbol as keyof typeof TOKEN_SYMBOLS_MAP];
40
39
  if (!isDefined(token) || !isDefined(token.addresses[chainId])) {
@@ -43,8 +42,7 @@ export function resolveSymbolOnChain(chainId: number, symbol: string): TokenInfo
43
42
  }
44
43
 
45
44
  const { decimals, addresses } = token;
46
- const address = toAddressType(addresses[chainId], chainId);
47
- assert(address.isEVM() || address.isSVM());
45
+ const address = addresses[chainId];
48
46
 
49
47
  return { symbol, decimals, address };
50
48
  }
@@ -113,7 +111,7 @@ export function isStablecoin(tokenSymbol: string): boolean {
113
111
  * @param tokenMapping
114
112
  * @returns
115
113
  */
116
- export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): TokenInfo {
114
+ export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): L1Token {
117
115
  const parsedAddress = toAddressType(l2TokenAddress, chainId).toNative();
118
116
 
119
117
  // @dev This might give false positives if tokens on different networks have the same address. I'm not sure how
@@ -129,7 +127,7 @@ export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMappi
129
127
  tokenObject = tokenMapping[l1TokenSymbol as keyof typeof tokenMapping];
130
128
  }
131
129
  return {
132
- address: toAddressType(l2TokenAddress, chainId),
130
+ address: l2TokenAddress,
133
131
  symbol: tokenObject.symbol,
134
132
  decimals: tokenObject.decimals,
135
133
  };