|
1 | 1 | import { |
| 2 | + Address, |
2 | 3 | Chain, |
3 | 4 | ContractFunctionExecutionError, |
4 | 5 | encodeFunctionData, |
@@ -45,13 +46,15 @@ import { |
45 | 46 | simulateTxOnTenderly, |
46 | 47 | TenderlySimulateTxParams, |
47 | 48 | assertValidIntegratorId, |
| 49 | + AcrossChain, |
48 | 50 | } from "./utils"; |
49 | 51 | import { |
50 | 52 | AcrossApiSimulationError, |
51 | 53 | ConfigError, |
52 | 54 | SimulationError, |
53 | 55 | } from "./errors"; |
54 | 56 | import { |
| 57 | + ChainInfoMap, |
55 | 58 | ConfiguredPublicClient, |
56 | 59 | ConfiguredPublicClientMap, |
57 | 60 | ConfiguredWalletClient, |
@@ -138,6 +141,7 @@ export class AcrossClient { |
138 | 141 |
|
139 | 142 | private integratorId: Hex; |
140 | 143 | private publicClients: ConfiguredPublicClientMap; |
| 144 | + private chainInfo?: ChainInfoMap; |
141 | 145 | private walletClient?: ConfiguredWalletClient; |
142 | 146 | private apiUrl: string; |
143 | 147 | private indexerUrl: string; |
@@ -228,6 +232,32 @@ export class AcrossClient { |
228 | 232 | return client; |
229 | 233 | } |
230 | 234 |
|
| 235 | + async getSpokePoolAddress(chainId: number): Promise<Address> { |
| 236 | + const chainInfo = await this.getChainInfo(chainId); |
| 237 | + return chainInfo.spokePool; |
| 238 | + } |
| 239 | + |
| 240 | + /** |
| 241 | + * @param chainId - number |
| 242 | + * @returns See {@link AcrossChain}. |
| 243 | + */ |
| 244 | + async getChainInfo(chainId: number): Promise<AcrossChain> { |
| 245 | + if (!this.chainInfo) { |
| 246 | + const acrossChains = await this.getSupportedChains({ |
| 247 | + chainId: Array.from(this.publicClients.keys()), |
| 248 | + }); |
| 249 | + // cache across chain info in memory |
| 250 | + this.chainInfo = new Map( |
| 251 | + acrossChains.map((acrossChain) => [acrossChain.chainId, acrossChain]), |
| 252 | + ); |
| 253 | + } |
| 254 | + if (this.chainInfo.has(chainId)) { |
| 255 | + throw new Error(`Could not find chainInfo for chain with id ${chainId}`); |
| 256 | + } |
| 257 | + |
| 258 | + return this.chainInfo.get(chainId)!; |
| 259 | + } |
| 260 | + |
231 | 261 | /** |
232 | 262 | * Execute a quote by: |
233 | 263 | * 1. Approving the SpokePool contract if necessary |
|
0 commit comments