otterscan/src/api/address-resolver/HardcodedAddressResolver.ts

23 lines
622 B
TypeScript

import { BaseProvider } from "@ethersproject/providers";
import { IAddressResolver } from "./address-resolver";
type HardcodedAddressMap = Record<string, string | undefined>;
export class HardcodedAddressResolver implements IAddressResolver<string> {
async resolveAddress(
provider: BaseProvider,
address: string
): Promise<string | undefined> {
try {
const addressMap: HardcodedAddressMap = await import(
`./hardcoded-addresses/${provider.network.chainId}.json`
);
return addressMap[address];
} catch (err) {
// Ignore on purpose
return undefined;
}
}
}