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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/dist/cjs/arch/evm/SpokeUtils.d.ts +6 -2
  2. package/dist/cjs/arch/evm/SpokeUtils.js +21 -6
  3. package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
  4. package/dist/cjs/arch/svm/SpokeUtils.d.ts +9 -5
  5. package/dist/cjs/arch/svm/SpokeUtils.js +70 -71
  6. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  7. package/dist/cjs/arch/svm/utils.d.ts +3 -5
  8. package/dist/cjs/arch/svm/utils.js +20 -28
  9. package/dist/cjs/arch/svm/utils.js.map +1 -1
  10. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  11. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
  12. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  13. package/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  14. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +60 -56
  15. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  16. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +13 -13
  17. package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  18. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  19. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +3 -2
  20. package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  21. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
  22. package/dist/cjs/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  23. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +3 -3
  24. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  25. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
  26. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js +11 -8
  27. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  28. package/dist/cjs/clients/HubPoolClient.d.ts +21 -21
  29. package/dist/cjs/clients/HubPoolClient.js +83 -58
  30. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  31. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +1 -1
  32. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  33. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  34. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +64 -45
  35. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  36. package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +9 -9
  37. package/dist/cjs/clients/mocks/MockHubPoolClient.js +15 -9
  38. package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
  39. package/dist/cjs/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  40. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +40 -36
  41. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  42. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  43. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +3 -4
  44. package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  45. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.d.ts +3 -3
  46. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +2 -2
  47. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  48. package/dist/cjs/interfaces/HubPool.d.ts +19 -14
  49. package/dist/cjs/interfaces/SpokePool.d.ts +13 -13
  50. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
  51. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +10 -10
  52. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  53. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +5 -5
  54. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +42 -49
  55. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  56. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
  57. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +7 -7
  58. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  59. package/dist/cjs/utils/AddressUtils.d.ts +12 -13
  60. package/dist/cjs/utils/AddressUtils.js +44 -46
  61. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  62. package/dist/cjs/utils/EventUtils.js +1 -1
  63. package/dist/cjs/utils/EventUtils.js.map +1 -1
  64. package/dist/cjs/utils/SpokeUtils.d.ts +3 -3
  65. package/dist/cjs/utils/SpokeUtils.js +4 -22
  66. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  67. package/dist/cjs/utils/TokenUtils.d.ts +4 -4
  68. package/dist/cjs/utils/TokenUtils.js +4 -6
  69. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  70. package/dist/esm/arch/evm/SpokeUtils.d.ts +6 -2
  71. package/dist/esm/arch/evm/SpokeUtils.js +22 -7
  72. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  73. package/dist/esm/arch/svm/SpokeUtils.d.ts +9 -5
  74. package/dist/esm/arch/svm/SpokeUtils.js +74 -75
  75. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  76. package/dist/esm/arch/svm/utils.d.ts +6 -8
  77. package/dist/esm/arch/svm/utils.js +21 -27
  78. package/dist/esm/arch/svm/utils.js.map +1 -1
  79. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  80. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
  81. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  82. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  83. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +61 -57
  84. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  85. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +14 -14
  86. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  87. package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  88. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +5 -3
  89. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  90. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
  91. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  92. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +4 -4
  93. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  94. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
  95. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +12 -9
  96. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  97. package/dist/esm/clients/HubPoolClient.d.ts +23 -22
  98. package/dist/esm/clients/HubPoolClient.js +97 -63
  99. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  100. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +2 -2
  101. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  102. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  103. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +67 -47
  104. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  105. package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +9 -9
  106. package/dist/esm/clients/mocks/MockHubPoolClient.js +16 -10
  107. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  108. package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  109. package/dist/esm/clients/mocks/MockSpokePoolClient.js +42 -38
  110. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  111. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  112. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +4 -5
  113. package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -1
  114. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.d.ts +3 -3
  115. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +3 -3
  116. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  117. package/dist/esm/interfaces/HubPool.d.ts +19 -14
  118. package/dist/esm/interfaces/SpokePool.d.ts +13 -13
  119. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
  120. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +11 -11
  121. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  122. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +6 -6
  123. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +44 -51
  124. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  125. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
  126. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +8 -8
  127. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  128. package/dist/esm/utils/AddressUtils.d.ts +13 -14
  129. package/dist/esm/utils/AddressUtils.js +50 -56
  130. package/dist/esm/utils/AddressUtils.js.map +1 -1
  131. package/dist/esm/utils/EventUtils.js +2 -2
  132. package/dist/esm/utils/EventUtils.js.map +1 -1
  133. package/dist/esm/utils/SpokeUtils.d.ts +3 -8
  134. package/dist/esm/utils/SpokeUtils.js +4 -26
  135. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  136. package/dist/esm/utils/TokenUtils.d.ts +4 -16
  137. package/dist/esm/utils/TokenUtils.js +5 -7
  138. package/dist/esm/utils/TokenUtils.js.map +1 -1
  139. package/dist/types/arch/evm/SpokeUtils.d.ts +6 -2
  140. package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
  141. package/dist/types/arch/svm/SpokeUtils.d.ts +9 -5
  142. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
  143. package/dist/types/arch/svm/utils.d.ts +6 -8
  144. package/dist/types/arch/svm/utils.d.ts.map +1 -1
  145. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  146. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
  147. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  148. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  149. package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
  150. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  151. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
  152. package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts.map +1 -1
  153. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
  154. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
  155. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
  156. package/dist/types/clients/HubPoolClient.d.ts +23 -22
  157. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  158. package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
  159. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  160. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  161. package/dist/types/clients/mocks/MockHubPoolClient.d.ts +9 -9
  162. package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
  163. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  164. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
  165. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts +1 -1
  166. package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts.map +1 -1
  167. package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts +3 -3
  168. package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts.map +1 -1
  169. package/dist/types/interfaces/HubPool.d.ts +19 -14
  170. package/dist/types/interfaces/HubPool.d.ts.map +1 -1
  171. package/dist/types/interfaces/SpokePool.d.ts +13 -13
  172. package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
  173. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
  174. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  175. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +6 -6
  176. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
  177. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
  178. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  179. package/dist/types/utils/AddressUtils.d.ts +13 -14
  180. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  181. package/dist/types/utils/SpokeUtils.d.ts +3 -8
  182. package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
  183. package/dist/types/utils/TokenUtils.d.ts +4 -16
  184. package/dist/types/utils/TokenUtils.d.ts.map +1 -1
  185. package/package.json +2 -3
  186. package/src/arch/evm/SpokeUtils.ts +52 -12
  187. package/src/arch/svm/SpokeUtils.ts +108 -59
  188. package/src/arch/svm/utils.ts +11 -20
  189. package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +7 -4
  190. package/src/clients/BundleDataClient/BundleDataClient.ts +57 -53
  191. package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +28 -13
  192. package/src/clients/BundleDataClient/utils/FillUtils.ts +10 -4
  193. package/src/clients/BundleDataClient/utils/MerkleTreeUtils.ts +7 -1
  194. package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +4 -4
  195. package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +13 -9
  196. package/src/clients/HubPoolClient.ts +126 -82
  197. package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +6 -0
  198. package/src/clients/SpokePoolClient/SpokePoolClient.ts +118 -35
  199. package/src/clients/mocks/MockHubPoolClient.ts +24 -19
  200. package/src/clients/mocks/MockSpokePoolClient.ts +39 -27
  201. package/src/clients/mocks/MockSvmCpiEventsClient.ts +3 -5
  202. package/src/clients/mocks/MockSvmSpokePoolClient.ts +12 -3
  203. package/src/interfaces/HubPool.ts +23 -14
  204. package/src/interfaces/SpokePool.ts +13 -13
  205. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +14 -12
  206. package/src/relayFeeCalculator/chain-queries/svmQuery.ts +42 -46
  207. package/src/relayFeeCalculator/relayFeeCalculator.ts +20 -12
  208. package/src/utils/AddressUtils.ts +58 -60
  209. package/src/utils/EventUtils.ts +2 -2
  210. package/src/utils/SpokeUtils.ts +11 -33
  211. package/src/utils/TokenUtils.ts +10 -11
@@ -1,7 +1,6 @@
1
1
  import { providers, utils } from "ethers";
2
2
  import bs58 from "bs58";
3
- import { Address as V2Address } from "@solana/kit";
4
- import { BigNumber, chainIsEvm } from "./";
3
+ import { BigNumber, chainIsEvm, chainIsSvm } from "./";
5
4
 
6
5
  /**
7
6
  * Checks if a contract is deployed at the given address
@@ -48,8 +47,9 @@ export function toBytes32(address: string): string {
48
47
  return utils.hexZeroPad(address, 32).toLowerCase();
49
48
  }
50
49
 
51
- // Checks if the input string can be coerced into a bytes20 evm address. Returns true if it is possible, and false otherwise.
52
- export function toAddress(hexString: string): string {
50
+ // Constructs a 20-byte checksummed EVM address from a hex string input.
51
+ // Throws an error if the underlying address length is longer than 20 bytes or incorrectly checksummed.
52
+ export function toEvmAddress(hexString: string): string {
53
53
  // rawAddress is the address which is not properly checksummed.
54
54
  const rawAddress = utils.hexZeroPad(utils.hexStripZeros(hexString), 20);
55
55
  return utils.getAddress(rawAddress);
@@ -74,21 +74,17 @@ export function isValidEvmAddress(address: string): boolean {
74
74
  /**
75
75
  * Creates the proper address type given the input chain ID corresponding to the address's origin network.
76
76
  * @param address Stringified address type to convert. Can be either hex encoded or base58 encoded.
77
- * @param chainId Network ID corresponding to the input address, used to determine which address type to output.
77
+ * @param chainId Chain ID for the intended use of the address.
78
78
  * @returns a child `Address` type most fitting for the chain ID.
79
79
  * @todo: Change this to `toAddress` once we remove the other `toAddress` function.
80
80
  */
81
- export function toAddressType(address: string): Address | EvmAddress | SvmAddress {
82
- try {
83
- if (utils.isHexString(address)) {
84
- return EvmAddress.from(address);
85
- }
86
- return SvmAddress.from(address);
87
- } catch (e) {
88
- // If we hit this block, then the validation for one of the child address classes failed. We still may want to keep this address in our state, so
89
- // return an unchecked address type.
90
- return new Address(utils.arrayify(address));
91
- }
81
+ export function toAddressType(address: string, chainId: number): Address {
82
+ const rawAddress = address.startsWith("0x") ? utils.arrayify(address) : bs58.decode(address);
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);
92
88
  }
93
89
 
94
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,
@@ -113,12 +109,24 @@ export class Address {
113
109
  this.rawAddress = utils.zeroPad(_rawAddress, 32);
114
110
  }
115
111
 
112
+ static __unsafeConstruct(_rawAddress: Uint8Array): Address {
113
+ return new this(_rawAddress);
114
+ }
115
+
116
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
117
117
  // throw since address length validation was done at construction time.
118
118
  toBytes32(): string {
119
119
  return (this.bytes32Address ??= utils.hexZeroPad(utils.hexlify(this.rawAddress), 32).toLowerCase());
120
120
  }
121
121
 
122
+ // Returns last 20 bytes of Address as a hex string. Truncates if necessary. This function is useful for comparing some longer addresses(e.g. Solana) to Solidity events
123
+ // that contain truncated `address` type as one of the fields
124
+ truncateToBytes20(): string {
125
+ // Take the last 20 bytes
126
+ const bytes20 = this.rawAddress.slice(-20);
127
+ return toEvmAddress(utils.hexlify(bytes20));
128
+ }
129
+
122
130
  // Converts the address (can be bytes32 or bytes20) to its base58 counterpart. This conversion will always succeed, even if the input address is not valid on Solana,
123
131
  // as this address may be needed to represent an EVM address on Solana.
124
132
  toBase58(): string {
@@ -126,7 +134,7 @@ export class Address {
126
134
  }
127
135
 
128
136
  // Converts the address to a BigNumber type.
129
- toBigNumber(): BigNumber {
137
+ private toBigNumber(): BigNumber {
130
138
  return (this.bnAddress ??= BigNumber.from(this.toBytes32()));
131
139
  }
132
140
 
@@ -143,37 +151,20 @@ export class Address {
143
151
 
144
152
  // Converts the address to a hex string. This method should be overriden by subclasses to obtain more meaningful
145
153
  // address representations for the target chain ID.
146
- toAddress(): string {
154
+ toNative(): string {
147
155
  return this.toBytes32();
148
156
  }
149
157
 
150
- // Converts the address to a Buffer type.
151
- toBuffer(): Buffer {
152
- return Buffer.from(this.rawAddress);
153
- }
154
-
155
158
  // Implements `Hexable` for `Address`. Needed for encoding purposes. This class is treated by default as a bytes32 primitive type, but can change for subclasses.
156
159
  toHexString(): string {
157
160
  return this.toBytes32();
158
161
  }
159
162
 
160
- // Checks if this address can be coerced into a bytes20 evm address. Returns true if it is possible and false otherwise.
161
- isValidEvmAddress(): boolean {
162
- try {
163
- this.toAddress();
164
- return true;
165
- } catch {
166
- return false;
167
- }
168
- }
169
-
170
163
  // Checks if the address is valid on the given chain ID.
171
164
  isValidOn(chainId: number): boolean {
172
- if (chainIsEvm(chainId)) {
173
- return this.isValidEvmAddress();
174
- }
175
- // Assume the address is always valid on Solana.
176
- return true;
165
+ if (chainIsEvm(chainId)) return EvmAddress.validate(this.rawAddress);
166
+ if (chainIsSvm(chainId)) return SvmAddress.validate(this.rawAddress);
167
+ return false;
177
168
  }
178
169
 
179
170
  // Checks if the object is an address by looking at whether it has an Address constructor.
@@ -183,7 +174,7 @@ export class Address {
183
174
 
184
175
  // Converts the input address to a 32-byte hex data string.
185
176
  toString(): string {
186
- return this.toHexString();
177
+ return this.toNative();
187
178
  }
188
179
 
189
180
  // Checks if the address is the zero address.
@@ -196,11 +187,6 @@ export class Address {
196
187
  return SvmAddress.from(this.toBase58());
197
188
  }
198
189
 
199
- // Forces `rawAddress` to become an EvmAddress type. This will throw if `rawAddress.length > 20`.
200
- forceEvmAddress(): EvmAddress {
201
- return EvmAddress.from(this.toEvmAddress());
202
- }
203
-
204
190
  // Checks if the other address is equivalent to this address.
205
191
  eq(other: Address): boolean {
206
192
  return this.toString() === other.toString();
@@ -220,21 +206,35 @@ export class Address {
220
206
  return 0;
221
207
  }
222
208
  }
209
+
210
+ static isEvmAddress(address: Address): boolean {
211
+ return address instanceof EvmAddress;
212
+ }
213
+
214
+ static isSvmAddress(address: Address): boolean {
215
+ return address instanceof SvmAddress;
216
+ }
223
217
  }
224
218
 
225
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.
226
220
  export class EvmAddress extends Address {
227
221
  // On construction, validate that the address can indeed be coerced into an EVM address. Throw immediately if it cannot.
228
222
  constructor(rawAddress: Uint8Array) {
229
- super(rawAddress);
230
- const hexString = utils.hexlify(rawAddress);
231
- if (!this.isValidEvmAddress()) {
232
- throw new Error(`${hexString} is not a valid EVM address`);
223
+ if (!EvmAddress.validate(rawAddress)) {
224
+ throw new Error(`${utils.hexlify(rawAddress)} is not a valid EVM address`);
233
225
  }
226
+
227
+ super(rawAddress);
228
+ }
229
+
230
+ static validate(rawAddress: Uint8Array): boolean {
231
+ return (
232
+ rawAddress.length == 20 || (rawAddress.length === 32 && rawAddress.slice(0, 12).every((field) => field === 0))
233
+ );
234
234
  }
235
235
 
236
236
  // Override `toAddress` to return the 20-byte representation address.
237
- override toAddress(): string {
237
+ override toNative(): string {
238
238
  return this.toEvmAddress();
239
239
  }
240
240
 
@@ -260,25 +260,23 @@ export class EvmAddress extends Address {
260
260
  export class SvmAddress extends Address {
261
261
  // On construction, validate that the address is a point on Curve25519. Throw immediately if it is not.
262
262
  constructor(rawAddress: Uint8Array) {
263
+ if (!SvmAddress.validate(rawAddress)) {
264
+ throw new Error(`${utils.hexlify(rawAddress)} is not a valid SVM address`); // @todo: Display as Base58?
265
+ }
266
+
263
267
  super(rawAddress);
264
268
  }
265
269
 
270
+ static validate(rawAddress: Uint8Array): boolean {
271
+ return rawAddress.length === 32;
272
+ }
273
+
266
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
267
275
  // used in TOKEN_SYMBOLS_MAP.
268
- override toAddress(): string {
276
+ override toNative(): string {
269
277
  return this.toBase58();
270
278
  }
271
279
 
272
- // Small utility to convert an SvmAddress to a Solana Kit branded type.
273
- toV2Address(): V2Address<string> {
274
- return this.toBase58() as V2Address<string>;
275
- }
276
-
277
- // Forces an SvmAddress to an EVM address string by truncating the leading 12 bytes.
278
- override toEvmAddress(): string {
279
- return toAddress(`0x${this.toBytes32().slice(-40)}`);
280
- }
281
-
282
280
  // Constructs a new SvmAddress type.
283
281
  static from(address: string, encoding: "base58" | "base16" = "base58"): SvmAddress {
284
282
  if (encoding === "base58") {
@@ -3,7 +3,7 @@ import { Result } from "@ethersproject/abi";
3
3
  import { Contract, Event, EventFilter } from "ethers";
4
4
  import { Log, SortableEvent } from "../interfaces";
5
5
  import { delay } from "./common";
6
- import { isDefined, toBN, BigNumberish, toAddress } from "./";
6
+ import { isDefined, toBN, BigNumberish, toEvmAddress } from "./";
7
7
 
8
8
  const maxRetries = 3;
9
9
  const retrySleepTime = 10;
@@ -88,7 +88,7 @@ export function spreadEvent(args: Result | Record<string, unknown>): { [key: str
88
88
  if (isDefined(returnedObject[field])) {
89
89
  let address = String(returnedObject[field]);
90
90
  try {
91
- address = toAddress(address);
91
+ address = toEvmAddress(address);
92
92
  // eslint-disable-next-line no-empty
93
93
  } catch (_) {}
94
94
  returnedObject[field] = address;
@@ -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,20 @@
1
1
  import { BlockTag } from "@ethersproject/abstract-provider";
2
2
  import { Contract, providers, Signer } from "ethers";
3
3
  import * as constants from "../constants";
4
- import { L1Token } from "../interfaces";
4
+ import { L1TokenInfo, TokenInfo } from "../interfaces";
5
5
  import { ERC20__factory } from "../typechain";
6
6
  import { BigNumber } from "./BigNumberUtils";
7
- import { getNetworkName, chainIsL1, chainIsProd, chainIsSvm } from "./NetworkUtils";
7
+ import { getNetworkName, chainIsL1, chainIsProd } from "./NetworkUtils";
8
8
  import { isDefined } from "./TypeGuards";
9
9
  import { compareAddressesSimple, toAddressType } from "./AddressUtils";
10
10
  const { TOKEN_SYMBOLS_MAP, CHAIN_IDs, TOKEN_EQUIVALENCE_REMAPPING } = constants;
11
11
 
12
12
  type SignerOrProvider = providers.Provider | Signer;
13
13
 
14
- export async function fetchTokenInfo(address: string, signerOrProvider: SignerOrProvider): Promise<L1Token> {
14
+ export async function fetchTokenInfo(address: string, signerOrProvider: SignerOrProvider): Promise<TokenInfo> {
15
15
  const token = new Contract(address, ERC20__factory.abi, signerOrProvider);
16
16
  const [symbol, decimals] = await Promise.all([token.symbol(), token.decimals()]);
17
- return { address, symbol, decimals };
17
+ return { address: toAddressType(address, CHAIN_IDs.MAINNET), symbol, decimals };
18
18
  }
19
19
 
20
20
  export const getL2TokenAddresses = (
@@ -33,7 +33,7 @@ export const getL2TokenAddresses = (
33
33
  * @param chainId Chain ID to query on.
34
34
  * @returns Symbol, decimals and contract address on the requested chain.
35
35
  */
36
- export function resolveSymbolOnChain(chainId: number, symbol: string): L1Token {
36
+ export function resolveSymbolOnChain(chainId: number, symbol: string): TokenInfo {
37
37
  // @dev Suppress tsc complaints by casting symbol to the expected type.
38
38
  const token = TOKEN_SYMBOLS_MAP[symbol as keyof typeof TOKEN_SYMBOLS_MAP];
39
39
  if (!isDefined(token) || !isDefined(token.addresses[chainId])) {
@@ -44,7 +44,7 @@ export function resolveSymbolOnChain(chainId: number, symbol: string): L1Token {
44
44
  const { decimals, addresses } = token;
45
45
  const address = addresses[chainId];
46
46
 
47
- return { symbol, decimals, address };
47
+ return { symbol, decimals, address: toAddressType(address, chainId) };
48
48
  }
49
49
 
50
50
  /**
@@ -111,10 +111,9 @@ export function isStablecoin(tokenSymbol: string): boolean {
111
111
  * @param tokenMapping
112
112
  * @returns
113
113
  */
114
- export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): L1Token {
115
- const parsedAddress = chainIsSvm(chainId)
116
- ? toAddressType(l2TokenAddress).toBase58()
117
- : toAddressType(l2TokenAddress).toEvmAddress();
114
+ export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMapping = TOKEN_SYMBOLS_MAP): L1TokenInfo {
115
+ const parsedAddress = toAddressType(l2TokenAddress, chainId).toNative();
116
+
118
117
  // @dev This might give false positives if tokens on different networks have the same address. I'm not sure how
119
118
  // to get around this...
120
119
  let tokenObject = Object.values(tokenMapping).find(({ addresses }) => addresses[chainId] === parsedAddress);
@@ -128,7 +127,7 @@ export function getTokenInfo(l2TokenAddress: string, chainId: number, tokenMappi
128
127
  tokenObject = tokenMapping[l1TokenSymbol as keyof typeof tokenMapping];
129
128
  }
130
129
  return {
131
- address: l2TokenAddress,
130
+ address: toAddressType(l2TokenAddress, chainId),
132
131
  symbol: tokenObject.symbol,
133
132
  decimals: tokenObject.decimals,
134
133
  };