@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
@@ -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
  }
@@ -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_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";
6
+ import { Address } from "./AddressUtils";
7
7
  import { isMessageEmpty } from "./DepositUtils";
8
8
  import { chainIsSvm } from "./NetworkUtils";
9
9
  import { svm } from "../arch";
@@ -16,28 +16,6 @@ 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
-
41
19
  /**
42
20
  * Compute the RelayData hash for a fill. This can be used to determine the fill status.
43
21
  * @param relayData RelayData information that is used to complete a fill.
@@ -68,14 +46,14 @@ export function getRelayDataHash(relayData: RelayData, destinationChainId: numbe
68
46
 
69
47
  const _relayData = {
70
48
  ...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),
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(),
76
54
  };
77
55
  if (chainIsSvm(destinationChainId)) {
78
- return svm.getRelayDataHash(_relayData, destinationChainId);
56
+ return svm.getRelayDataHash(relayData, destinationChainId);
79
57
  }
80
58
  return keccak256(encodeAbiParameters(abi, [_relayData, destinationChainId]));
81
59
  }
@@ -95,8 +73,8 @@ export function isUnsafeDepositId(depositId: BigNumber): boolean {
95
73
  }
96
74
 
97
75
  // 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;
76
+ export function isZeroAddress(address: Address): boolean {
77
+ return address.toBytes32() === ZERO_BYTES;
100
78
  }
101
79
 
102
80
  export function getMessageHash(message: string): string {
@@ -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 { 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<TokenInfo> {
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
  };