@across-protocol/sdk 4.2.15 → 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 (202) 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 +6 -2
  5. package/dist/cjs/arch/svm/SpokeUtils.js +66 -67
  6. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -1
  7. package/dist/cjs/arch/svm/utils.d.ts +3 -1
  8. package/dist/cjs/arch/svm/utils.js +20 -14
  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/MockSvmSpokePoolClient.d.ts +2 -2
  43. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +2 -2
  44. package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  45. package/dist/cjs/interfaces/HubPool.d.ts +19 -14
  46. package/dist/cjs/interfaces/SpokePool.d.ts +13 -13
  47. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
  48. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +10 -10
  49. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  50. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +5 -5
  51. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +41 -48
  52. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  53. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
  54. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +7 -7
  55. package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  56. package/dist/cjs/utils/AddressUtils.d.ts +12 -13
  57. package/dist/cjs/utils/AddressUtils.js +44 -46
  58. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  59. package/dist/cjs/utils/EventUtils.js +1 -1
  60. package/dist/cjs/utils/EventUtils.js.map +1 -1
  61. package/dist/cjs/utils/SpokeUtils.d.ts +3 -3
  62. package/dist/cjs/utils/SpokeUtils.js +4 -22
  63. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  64. package/dist/cjs/utils/TokenUtils.d.ts +4 -4
  65. package/dist/cjs/utils/TokenUtils.js +4 -6
  66. package/dist/cjs/utils/TokenUtils.js.map +1 -1
  67. package/dist/esm/arch/evm/SpokeUtils.d.ts +6 -2
  68. package/dist/esm/arch/evm/SpokeUtils.js +22 -7
  69. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  70. package/dist/esm/arch/svm/SpokeUtils.d.ts +6 -2
  71. package/dist/esm/arch/svm/SpokeUtils.js +70 -71
  72. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -1
  73. package/dist/esm/arch/svm/utils.d.ts +6 -1
  74. package/dist/esm/arch/svm/utils.js +21 -13
  75. package/dist/esm/arch/svm/utils.js.map +1 -1
  76. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  77. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +4 -2
  78. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  79. package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  80. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +61 -57
  81. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  82. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +14 -14
  83. package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
  84. package/dist/esm/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  85. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +5 -3
  86. package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
  87. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js +5 -1
  88. package/dist/esm/clients/BundleDataClient/utils/MerkleTreeUtils.js.map +1 -1
  89. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +4 -4
  90. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  91. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
  92. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js +12 -9
  93. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.js.map +1 -1
  94. package/dist/esm/clients/HubPoolClient.d.ts +23 -22
  95. package/dist/esm/clients/HubPoolClient.js +97 -63
  96. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  97. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +2 -2
  98. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  99. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  100. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +67 -47
  101. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  102. package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +9 -9
  103. package/dist/esm/clients/mocks/MockHubPoolClient.js +16 -10
  104. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  105. package/dist/esm/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  106. package/dist/esm/clients/mocks/MockSpokePoolClient.js +42 -38
  107. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  108. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
  109. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +3 -3
  110. package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -1
  111. package/dist/esm/interfaces/HubPool.d.ts +19 -14
  112. package/dist/esm/interfaces/SpokePool.d.ts +13 -13
  113. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
  114. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +11 -11
  115. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  116. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +6 -6
  117. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +43 -50
  118. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -1
  119. package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
  120. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +8 -8
  121. package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
  122. package/dist/esm/utils/AddressUtils.d.ts +13 -14
  123. package/dist/esm/utils/AddressUtils.js +50 -56
  124. package/dist/esm/utils/AddressUtils.js.map +1 -1
  125. package/dist/esm/utils/EventUtils.js +2 -2
  126. package/dist/esm/utils/EventUtils.js.map +1 -1
  127. package/dist/esm/utils/SpokeUtils.d.ts +3 -8
  128. package/dist/esm/utils/SpokeUtils.js +4 -26
  129. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  130. package/dist/esm/utils/TokenUtils.d.ts +4 -16
  131. package/dist/esm/utils/TokenUtils.js +5 -7
  132. package/dist/esm/utils/TokenUtils.js.map +1 -1
  133. package/dist/types/arch/evm/SpokeUtils.d.ts +6 -2
  134. package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
  135. package/dist/types/arch/svm/SpokeUtils.d.ts +6 -2
  136. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -1
  137. package/dist/types/arch/svm/utils.d.ts +6 -1
  138. package/dist/types/arch/svm/utils.d.ts.map +1 -1
  139. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +3 -3
  140. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
  141. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +4 -4
  142. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  143. package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
  144. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts +2 -1
  145. package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
  146. package/dist/types/clients/BundleDataClient/utils/MerkleTreeUtils.d.ts.map +1 -1
  147. package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
  148. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +63 -63
  149. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts.map +1 -1
  150. package/dist/types/clients/HubPoolClient.d.ts +23 -22
  151. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  152. package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
  153. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +2 -2
  154. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  155. package/dist/types/clients/mocks/MockHubPoolClient.d.ts +9 -9
  156. package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
  157. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts +5 -3
  158. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
  159. package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts +2 -2
  160. package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts.map +1 -1
  161. package/dist/types/interfaces/HubPool.d.ts +19 -14
  162. package/dist/types/interfaces/HubPool.d.ts.map +1 -1
  163. package/dist/types/interfaces/SpokePool.d.ts +13 -13
  164. package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
  165. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +6 -6
  166. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  167. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +6 -6
  168. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -1
  169. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +5 -5
  170. package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
  171. package/dist/types/utils/AddressUtils.d.ts +13 -14
  172. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  173. package/dist/types/utils/SpokeUtils.d.ts +3 -8
  174. package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
  175. package/dist/types/utils/TokenUtils.d.ts +4 -16
  176. package/dist/types/utils/TokenUtils.d.ts.map +1 -1
  177. package/package.json +1 -2
  178. package/src/arch/evm/SpokeUtils.ts +52 -12
  179. package/src/arch/svm/SpokeUtils.ts +102 -51
  180. package/src/arch/svm/utils.ts +11 -4
  181. package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +7 -4
  182. package/src/clients/BundleDataClient/BundleDataClient.ts +57 -53
  183. package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +28 -13
  184. package/src/clients/BundleDataClient/utils/FillUtils.ts +10 -4
  185. package/src/clients/BundleDataClient/utils/MerkleTreeUtils.ts +7 -1
  186. package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +4 -4
  187. package/src/clients/BundleDataClient/utils/SuperstructUtils.ts +13 -9
  188. package/src/clients/HubPoolClient.ts +126 -82
  189. package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +6 -0
  190. package/src/clients/SpokePoolClient/SpokePoolClient.ts +118 -35
  191. package/src/clients/mocks/MockHubPoolClient.ts +24 -19
  192. package/src/clients/mocks/MockSpokePoolClient.ts +39 -27
  193. package/src/clients/mocks/MockSvmSpokePoolClient.ts +12 -3
  194. package/src/interfaces/HubPool.ts +23 -14
  195. package/src/interfaces/SpokePool.ts +13 -13
  196. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +14 -12
  197. package/src/relayFeeCalculator/chain-queries/svmQuery.ts +41 -44
  198. package/src/relayFeeCalculator/relayFeeCalculator.ts +20 -12
  199. package/src/utils/AddressUtils.ts +58 -60
  200. package/src/utils/EventUtils.ts +2 -2
  201. package/src/utils/SpokeUtils.ts +11 -33
  202. package/src/utils/TokenUtils.ts +10 -11
@@ -1,20 +1,20 @@
1
1
  import { SortableEvent } from "./Common";
2
2
  import { SpokePoolClient } from "../clients";
3
- import { BigNumber } from "../utils";
3
+ import { BigNumber, Address, EvmAddress } from "../utils";
4
4
  import { RelayerRefundLeaf } from "./HubPool";
5
5
 
6
6
  export interface RelayData {
7
7
  originChainId: number;
8
- depositor: string;
9
- recipient: string;
8
+ depositor: Address;
9
+ recipient: Address;
10
10
  depositId: BigNumber;
11
- inputToken: string;
11
+ inputToken: Address;
12
12
  inputAmount: BigNumber;
13
- outputToken: string;
13
+ outputToken: Address;
14
14
  outputAmount: BigNumber;
15
15
  message: string;
16
16
  fillDeadline: number;
17
- exclusiveRelayer: string;
17
+ exclusiveRelayer: Address;
18
18
  exclusivityDeadline: number;
19
19
  }
20
20
 
@@ -23,7 +23,7 @@ export interface Deposit extends RelayData {
23
23
  destinationChainId: number;
24
24
  quoteTimestamp: number;
25
25
  speedUpSignature?: string;
26
- updatedRecipient?: string;
26
+ updatedRecipient?: Address;
27
27
  updatedOutputAmount?: BigNumber;
28
28
  updatedMessage?: string;
29
29
  fromLiteChain: boolean;
@@ -51,7 +51,7 @@ export enum FillType {
51
51
  }
52
52
 
53
53
  export interface RelayExecutionEventInfo {
54
- updatedRecipient: string;
54
+ updatedRecipient: Address;
55
55
  updatedOutputAmount: BigNumber;
56
56
  updatedMessage?: string;
57
57
  updatedMessageHash: string;
@@ -61,7 +61,7 @@ export interface RelayExecutionEventInfo {
61
61
  export interface Fill extends Omit<RelayData, "message"> {
62
62
  messageHash: string;
63
63
  destinationChainId: number;
64
- relayer: string;
64
+ relayer: Address;
65
65
  repaymentChainId: number;
66
66
  relayExecutionInfo: RelayExecutionEventInfo;
67
67
  }
@@ -72,18 +72,18 @@ export interface FillWithTime extends Fill, SortableEvent {
72
72
  }
73
73
 
74
74
  export interface EnabledDepositRoute {
75
- originToken: string;
75
+ originToken: Address;
76
76
  destinationChainId: number;
77
77
  enabled: boolean;
78
78
  }
79
79
 
80
80
  export interface EnabledDepositRouteWithBlock extends EnabledDepositRoute, SortableEvent {}
81
81
  export interface SpeedUp {
82
- depositor: string;
82
+ depositor: EvmAddress;
83
83
  depositorSignature: string;
84
84
  depositId: BigNumber;
85
85
  originChainId: number;
86
- updatedRecipient: string;
86
+ updatedRecipient: Address;
87
87
  updatedOutputAmount: BigNumber;
88
88
  updatedMessage: string;
89
89
  }
@@ -130,7 +130,7 @@ export interface TokensBridged extends SortableEvent {
130
130
  amountToReturn: BigNumber;
131
131
  chainId: number;
132
132
  leafId: number;
133
- l2TokenAddress: string;
133
+ l2TokenAddress: Address;
134
134
  }
135
135
 
136
136
  export interface ClaimedRelayerRefundWithBlock extends SortableEvent {
@@ -15,11 +15,13 @@ import {
15
15
  bnZero,
16
16
  chainIsOPStack,
17
17
  fixedPointAdjustment,
18
+ toAddressType,
19
+ Address,
18
20
  } from "../../utils";
19
21
  import assert from "assert";
20
22
  import { Logger, QueryInterface, getDefaultSimulatedRelayerAddress } from "../relayFeeCalculator";
21
23
  import { Transport } from "viem";
22
- import { getGasPriceEstimate, EvmGasPriceEstimate } from "../../gasPriceOracle";
24
+ import { getGasPriceEstimate } from "../../gasPriceOracle";
23
25
  import { EvmProvider } from "../../arch/evm/types";
24
26
 
25
27
  export type SymbolMappingType = Record<
@@ -72,7 +74,7 @@ export class QueryBase implements QueryInterface {
72
74
  */
73
75
  async getGasCosts(
74
76
  deposit: Omit<Deposit, "messageHash">,
75
- relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
77
+ relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId),
76
78
  options: Partial<{
77
79
  gasPrice: BigNumberish;
78
80
  gasUnits: BigNumberish;
@@ -122,7 +124,7 @@ export class QueryBase implements QueryInterface {
122
124
  */
123
125
  getUnsignedTxFromDeposit(
124
126
  deposit: Omit<Deposit, "messageHash">,
125
- relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
127
+ relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId)
126
128
  ): Promise<PopulatedTransaction> {
127
129
  return populateV3Relay(this.spokePool, deposit, relayer);
128
130
  }
@@ -135,10 +137,10 @@ export class QueryBase implements QueryInterface {
135
137
  */
136
138
  async getNativeGasCost(
137
139
  deposit: Omit<Deposit, "messageHash">,
138
- relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
140
+ relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId)
139
141
  ): Promise<BigNumber> {
140
142
  const unsignedTx = await this.getUnsignedTxFromDeposit(deposit, relayer);
141
- const voidSigner = new VoidSigner(relayer, this.provider);
143
+ const voidSigner = new VoidSigner(relayer.toEvmAddress(), this.provider);
142
144
  return voidSigner.estimateGas(unsignedTx);
143
145
  }
144
146
 
@@ -152,7 +154,7 @@ export class QueryBase implements QueryInterface {
152
154
  */
153
155
  async getOpStackL1DataFee(
154
156
  unsignedTx: PopulatedTransaction,
155
- relayer = getDefaultSimulatedRelayerAddress(unsignedTx.chainId),
157
+ relayer = toAddressType(getDefaultSimulatedRelayerAddress(unsignedTx.chainId), CHAIN_IDs.MAINNET),
156
158
  options: Partial<{
157
159
  opStackL2GasUnits: BigNumberish;
158
160
  opStackL1DataFeeMultiplier: BigNumber;
@@ -161,7 +163,7 @@ export class QueryBase implements QueryInterface {
161
163
  const { opStackL2GasUnits, opStackL1DataFeeMultiplier = toBNWei("1") } = options || {};
162
164
  const { chainId } = await this.provider.getNetwork();
163
165
  assert(isOptimismL2Provider(this.provider), `Unexpected provider for chain ID ${chainId}.`);
164
- const voidSigner = new VoidSigner(relayer, this.provider);
166
+ const voidSigner = new VoidSigner(relayer.toEvmAddress(), this.provider);
165
167
  const populatedTransaction = await voidSigner.populateTransaction({
166
168
  ...unsignedTx,
167
169
  gasLimit: opStackL2GasUnits, // prevents additional gas estimation call
@@ -183,7 +185,7 @@ export class QueryBase implements QueryInterface {
183
185
  */
184
186
  async estimateGas(
185
187
  unsignedTx: PopulatedTransaction,
186
- senderAddress: string,
188
+ senderAddress: Address,
187
189
  provider: providers.Provider | L2Provider<providers.Provider>,
188
190
  options: Partial<{
189
191
  gasPrice: BigNumberish;
@@ -204,7 +206,7 @@ export class QueryBase implements QueryInterface {
204
206
  } = options || {};
205
207
 
206
208
  const { chainId } = await provider.getNetwork();
207
- const voidSigner = new VoidSigner(senderAddress, provider);
209
+ const voidSigner = new VoidSigner(senderAddress.toEvmAddress(), provider);
208
210
 
209
211
  // Estimate the Gas units required to submit this transaction.
210
212
  const queries = [
@@ -213,9 +215,9 @@ export class QueryBase implements QueryInterface {
213
215
  ? Promise.resolve({ maxFeePerGas: _gasPrice })
214
216
  : getGasPriceEstimate(provider, { chainId, baseFeeMultiplier, priorityFeeMultiplier, transport, unsignedTx }),
215
217
  ] as const;
216
- const [nativeGasCost, _gasPriceEstimate] = await Promise.all(queries);
217
- // It should be safe to cast to an EvmGasPriceEstimate here since QueryBase is only used for EVM chains.
218
- const gasPrice = (_gasPriceEstimate as EvmGasPriceEstimate).maxFeePerGas;
218
+ const [nativeGasCost, gasPriceEstimate] = await Promise.all(queries);
219
+
220
+ const gasPrice = gasPriceEstimate.maxFeePerGas;
219
221
  assert(nativeGasCost.gt(bnZero), "Gas cost should not be 0");
220
222
  let tokenGasCost: BigNumber;
221
223
 
@@ -12,10 +12,11 @@ import {
12
12
  getFillRelayDelegatePda,
13
13
  getFillStatusPda,
14
14
  getStatePda,
15
+ toAddress,
15
16
  } from "../../arch/svm";
16
17
  import { Coingecko } from "../../coingecko";
17
18
  import { CHAIN_IDs } from "../../constants";
18
- import { SvmGasPriceEstimate, getGasPriceEstimate } from "../../gasPriceOracle";
19
+ import { getGasPriceEstimate } from "../../gasPriceOracle";
19
20
  import { Deposit } from "../../interfaces";
20
21
  import {
21
22
  BigNumber,
@@ -40,7 +41,7 @@ export class SvmQuery implements QueryInterface {
40
41
  * Instantiates a SvmQuery instance
41
42
  * @param provider A valid solana/kit rpc client.
42
43
  * @param symbolMapping A mapping to valid ERC20 tokens and their respective characteristics
43
- * @param spokePoolAddress The valid address of the Spoke Pool deployment
44
+ * @param spokePool The valid address of the Spoke Pool deployment
44
45
  * @param simulatedRelayerAddress The address that these queries will reference as the sender. Note: This address must be approved for USDC
45
46
  * @param logger A logging utility to report logs
46
47
  * @param coingeckoProApiKey An optional CoinGecko API key that links to a PRO account
@@ -50,7 +51,7 @@ export class SvmQuery implements QueryInterface {
50
51
  constructor(
51
52
  readonly provider: SVMProvider,
52
53
  readonly symbolMapping: SymbolMappingType,
53
- readonly spokePoolAddress: SvmAddress,
54
+ readonly spokePool: SvmAddress,
54
55
  readonly simulatedRelayerAddress: SvmAddress,
55
56
  readonly logger: Logger,
56
57
  readonly coingeckoProApiKey?: string,
@@ -74,7 +75,7 @@ export class SvmQuery implements QueryInterface {
74
75
  */
75
76
  async getGasCosts(
76
77
  deposit: Omit<Deposit, "messageHash">,
77
- _relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
78
+ relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId),
78
79
  options: Partial<{
79
80
  gasPrice: BigNumberish;
80
81
  gasUnits: BigNumberish;
@@ -82,10 +83,9 @@ export class SvmQuery implements QueryInterface {
82
83
  priorityFeeMultiplier: BigNumber;
83
84
  }> = {}
84
85
  ): Promise<TransactionCostEstimate> {
85
- const relayer = _relayer ? toAddressType(_relayer).forceSvmAddress() : this.simulatedRelayerAddress;
86
- const fillRelayTx = await this.getFillRelayTx(deposit, relayer.toBase58());
86
+ const fillRelayTx = await this.getFillRelayTx(deposit, relayer);
87
87
 
88
- const [computeUnitsConsumed, _gasPriceEstimate] = await Promise.all([
88
+ const [computeUnitsConsumed, gasPriceEstimate] = await Promise.all([
89
89
  toBN(await this.computeUnitEstimator(fillRelayTx)),
90
90
  getGasPriceEstimate(this.provider, {
91
91
  unsignedTx: fillRelayTx,
@@ -96,7 +96,6 @@ export class SvmQuery implements QueryInterface {
96
96
 
97
97
  // We can cast the gas price estimate to an SvmGasPriceEstimate here since the oracle should always
98
98
  // query the Solana adapter.
99
- const gasPriceEstimate = _gasPriceEstimate as SvmGasPriceEstimate;
100
99
  const gasPrice = gasPriceEstimate.baseFee.add(
101
100
  gasPriceEstimate.microLamportsPerComputeUnit.mul(computeUnitsConsumed).div(toBN(1_000_000)) // 1_000_000 microLamports/lamport.
102
101
  );
@@ -116,7 +115,7 @@ export class SvmQuery implements QueryInterface {
116
115
  */
117
116
  async getNativeGasCost(
118
117
  deposit: Omit<Deposit, "messageHash">,
119
- _relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
118
+ _relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId)
120
119
  ): Promise<BigNumber> {
121
120
  const fillRelayTx = await this.getFillRelayTx(deposit, _relayer);
122
121
  return toBN(await this.computeUnitEstimator(fillRelayTx));
@@ -130,42 +129,40 @@ export class SvmQuery implements QueryInterface {
130
129
  */
131
130
  async getFillRelayTx(
132
131
  deposit: Omit<Deposit, "messageHash">,
133
- _relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
132
+ relayer = toAddressType(getDefaultSimulatedRelayerAddress(deposit.destinationChainId), deposit.destinationChainId),
134
133
  repaymentChainId = deposit.destinationChainId,
135
- repaymentAddress = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
134
+ repaymentAddress = toAddressType(
135
+ getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
136
+ deposit.destinationChainId
137
+ )
136
138
  ) {
137
- const toSvmAddress = (address: string) => toAddressType(address).forceSvmAddress().toV2Address();
138
- const relayer = _relayer ? toAddressType(_relayer).forceSvmAddress() : this.simulatedRelayerAddress;
139
- const state = await getStatePda(this.spokePoolAddress.toV2Address());
140
- const _relayDataHash = getRelayDataHash(deposit, deposit.destinationChainId);
139
+ const { depositor, recipient, inputToken, outputToken, exclusiveRelayer, destinationChainId } = deposit;
140
+
141
+ const program = toAddress(this.spokePool);
142
+ const _relayDataHash = getRelayDataHash(deposit, destinationChainId);
141
143
  const relayDataHash = new Uint8Array(Buffer.from(_relayDataHash.slice(2), "hex"));
142
- const delegate = await getFillRelayDelegatePda(
143
- relayDataHash,
144
- BigInt(repaymentChainId),
145
- toSvmAddress(repaymentAddress),
146
- this.spokePoolAddress.toV2Address()
147
- );
148
- const mint = toAddressType(deposit.outputToken).forceSvmAddress();
149
- const mintInfo = await fetchMint(this.provider, mint.toV2Address());
150
- const recipientAta = await getAssociatedTokenAddress(
151
- toAddressType(deposit.recipient).forceSvmAddress(),
152
- mint,
153
- mintInfo.programAddress
154
- );
155
- const relayerAta = await getAssociatedTokenAddress(
156
- SvmAddress.from(relayer.toBase58()),
157
- mint,
158
- mintInfo.programAddress
159
- );
160
- const fillStatus = await getFillStatusPda(this.spokePoolAddress.toV2Address(), deposit, deposit.destinationChainId);
161
- const eventAuthority = await getEventAuthority();
144
+
145
+ const [state, delegate] = await Promise.all([
146
+ getStatePda(program),
147
+ getFillRelayDelegatePda(relayDataHash, BigInt(repaymentChainId), toAddress(repaymentAddress), program),
148
+ ]);
149
+
150
+ const mint = toAddress(outputToken);
151
+ const mintInfo = await fetchMint(this.provider, mint);
152
+
153
+ const [recipientAta, relayerAta, fillStatus, eventAuthority] = await Promise.all([
154
+ getAssociatedTokenAddress(deposit.recipient, outputToken, mintInfo.programAddress),
155
+ getAssociatedTokenAddress(SvmAddress.from(relayer.toBase58()), outputToken, mintInfo.programAddress),
156
+ getFillStatusPda(program, deposit, destinationChainId),
157
+ getEventAuthority(program),
158
+ ]);
162
159
 
163
160
  const relayData: SvmSpokeClient.FillRelayInput["relayData"] = {
164
- depositor: toSvmAddress(deposit.depositor),
165
- recipient: toSvmAddress(deposit.recipient),
166
- exclusiveRelayer: toSvmAddress(deposit.exclusiveRelayer),
167
- inputToken: toSvmAddress(deposit.inputToken),
168
- outputToken: mint.toV2Address(),
161
+ depositor: toAddress(depositor),
162
+ recipient: toAddress(recipient),
163
+ exclusiveRelayer: toAddress(exclusiveRelayer),
164
+ inputToken: toAddress(inputToken),
165
+ outputToken: mint,
169
166
  inputAmount: deposit.inputAmount.toBigInt(),
170
167
  outputAmount: deposit.outputAmount.toBigInt(),
171
168
  originChainId: deposit.originChainId,
@@ -180,19 +177,19 @@ export class SvmQuery implements QueryInterface {
180
177
  signer: simulatedSigner,
181
178
  state,
182
179
  delegate,
183
- mint: mint.toV2Address(),
180
+ mint,
184
181
  relayerTokenAccount: relayerAta,
185
182
  recipientTokenAccount: recipientAta,
186
183
  fillStatus,
187
184
  tokenProgram: mintInfo.programAddress,
188
185
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
189
186
  systemProgram: SYSTEM_PROGRAM_ADDRESS,
190
- eventAuthority: eventAuthority,
191
- program: this.spokePoolAddress.toV2Address(),
187
+ eventAuthority,
188
+ program,
192
189
  relayHash: relayDataHash,
193
190
  relayData,
194
191
  repaymentChainId: BigInt(repaymentChainId),
195
- repaymentAddress: toSvmAddress(repaymentAddress),
192
+ repaymentAddress: toAddress(repaymentAddress),
196
193
  };
197
194
  // Pass createRecipientAtaIfNeeded =true to the createFillInstruction function to create the recipient token account
198
195
  // if it doesn't exist.
@@ -9,12 +9,9 @@ import { Deposit } from "../interfaces";
9
9
  import {
10
10
  BigNumber,
11
11
  BigNumberish,
12
- ConvertDecimals,
13
12
  MAX_BIG_INT,
14
13
  TransactionCostEstimate,
15
14
  bnZero,
16
- chainIsSvm,
17
- compareAddressesSimple,
18
15
  fixedPointAdjustment,
19
16
  getTokenInfo,
20
17
  isDefined,
@@ -25,13 +22,18 @@ import {
25
22
  percent,
26
23
  toBN,
27
24
  toBNWei,
25
+ compareAddressesSimple,
26
+ ConvertDecimals,
27
+ chainIsSvm,
28
+ toAddressType,
29
+ Address,
28
30
  } from "../utils";
29
31
 
30
32
  // This needs to be implemented for every chain and passed into RelayFeeCalculator
31
33
  export interface QueryInterface {
32
34
  getGasCosts: (
33
35
  deposit: Omit<Deposit, "messageHash">,
34
- relayer: string,
36
+ relayer: Address,
35
37
  options?: Partial<{
36
38
  gasPrice: BigNumberish;
37
39
  gasUnits: BigNumberish;
@@ -42,7 +44,7 @@ export interface QueryInterface {
42
44
  }>
43
45
  ) => Promise<TransactionCostEstimate>;
44
46
  getTokenPrice: (tokenSymbol: string) => Promise<number>;
45
- getNativeGasCost: (deposit: Omit<Deposit, "messageHash">, relayer: string) => Promise<BigNumber>;
47
+ getNativeGasCost: (deposit: Omit<Deposit, "messageHash">, relayer: Address) => Promise<BigNumber>;
46
48
  }
47
49
 
48
50
  export const expectedCapitalCostsKeys = ["lowerBound", "upperBound", "cutoff", "decimals"];
@@ -254,7 +256,10 @@ export class RelayFeeCalculator {
254
256
  deposit: Deposit,
255
257
  outputAmount: BigNumberish,
256
258
  simulateZeroFill = false,
257
- relayerAddress = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
259
+ relayerAddress = toAddressType(
260
+ getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
261
+ deposit.destinationChainId
262
+ ),
258
263
  _tokenPrice?: number,
259
264
  tokenMapping = TOKEN_SYMBOLS_MAP,
260
265
  gasPrice?: BigNumberish,
@@ -271,14 +276,14 @@ export class RelayFeeCalculator {
271
276
  // undefined address on destination.
272
277
  const destinationChainTokenDetails = Object.values(tokenMapping).find(
273
278
  (details) =>
274
- compareAddressesSimple(details.addresses[originChainId], inputToken) &&
279
+ compareAddressesSimple(details.addresses[originChainId], inputToken.toNative()) &&
275
280
  isDefined(details.addresses[destinationChainId])
276
281
  );
277
282
  const outputToken = isZeroAddress(deposit.outputToken)
278
283
  ? destinationChainTokenDetails!.addresses[destinationChainId]
279
- : deposit.outputToken;
284
+ : deposit.outputToken.toNative();
280
285
  const outputTokenInfo = getTokenInfo(outputToken, destinationChainId, tokenMapping);
281
- const inputTokenInfo = getTokenInfo(inputToken, originChainId, tokenMapping);
286
+ const inputTokenInfo = getTokenInfo(inputToken.toNative(), originChainId, tokenMapping);
282
287
  if (!isDefined(outputTokenInfo) || !isDefined(inputTokenInfo)) {
283
288
  throw new Error(`Could not find token information for ${inputToken} or ${outputToken}`);
284
289
  }
@@ -493,7 +498,10 @@ export class RelayFeeCalculator {
493
498
  deposit: Deposit,
494
499
  outputAmount?: BigNumberish,
495
500
  simulateZeroFill = false,
496
- relayerAddress = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
501
+ relayerAddress = toAddressType(
502
+ getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
503
+ deposit.destinationChainId
504
+ ),
497
505
  _tokenPrice?: number,
498
506
  gasPrice?: BigNumberish,
499
507
  gasUnits?: BigNumberish,
@@ -505,8 +513,8 @@ export class RelayFeeCalculator {
505
513
  const { inputToken, originChainId, outputToken, destinationChainId } = deposit;
506
514
  // We can perform a simple lookup with `getTokenInfo` here without resolving the exact token to resolve since we only need to
507
515
  // resolve the L1 token symbol and not the L2 token decimals.
508
- const inputTokenInfo = getTokenInfo(inputToken, originChainId);
509
- const outputTokenInfo = getTokenInfo(outputToken, destinationChainId);
516
+ const inputTokenInfo = getTokenInfo(inputToken.toNative(), originChainId);
517
+ const outputTokenInfo = getTokenInfo(outputToken.toNative(), destinationChainId);
510
518
  if (!isDefined(inputTokenInfo) || !isDefined(outputTokenInfo)) {
511
519
  throw new Error(`Could not find token information for ${inputToken} or ${outputToken}`);
512
520
  }
@@ -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;