Initial implementation of hardcoded address resolver with Uniswap V1/2/3 main contracts as a bootstrap test
This commit is contained in:
parent
2dd4850eb0
commit
f2fbab36a6
|
@ -0,0 +1,22 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95": "Uniswap V1: Factory",
|
||||||
|
"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f": "Uniswap V2: Factory",
|
||||||
|
"0xf164fC0Ec4E93095b804a4795bBe1e041497b92a": "Uniswap V2: Router 1",
|
||||||
|
"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D": "Uniswap V2: Router 2",
|
||||||
|
"0x1F98431c8aD98523631AE4a59f267346ea31F984": "Uniswap V3: Router"
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
import { BaseProvider } from "@ethersproject/providers";
|
import { BaseProvider } from "@ethersproject/providers";
|
||||||
import { ensRenderer } from "../../components/ENSName";
|
import { ensRenderer } from "../../components/ENSName";
|
||||||
|
import { plainStringRenderer } from "../../components/PlainString";
|
||||||
import { tokenRenderer } from "../../components/TokenName";
|
import { tokenRenderer } from "../../components/TokenName";
|
||||||
import { IAddressResolver, ResolvedAddressRenderer } from "./address-resolver";
|
import { IAddressResolver, ResolvedAddressRenderer } from "./address-resolver";
|
||||||
import {
|
import {
|
||||||
|
@ -8,16 +9,19 @@ import {
|
||||||
} from "./CompositeAddressResolver";
|
} from "./CompositeAddressResolver";
|
||||||
import { ENSAddressResolver } from "./ENSAddressResolver";
|
import { ENSAddressResolver } from "./ENSAddressResolver";
|
||||||
import { ERCTokenResolver } from "./ERCTokenResolver";
|
import { ERCTokenResolver } from "./ERCTokenResolver";
|
||||||
|
import { HardcodedAddressResolver } from "./HardcodedAddressResolver";
|
||||||
|
|
||||||
export type ResolvedAddresses = Record<string, SelectedResolvedName<any>>;
|
export type ResolvedAddresses = Record<string, SelectedResolvedName<any>>;
|
||||||
|
|
||||||
// Create and configure the main resolver
|
// Create and configure the main resolver
|
||||||
export const ensResolver = new ENSAddressResolver();
|
export const ensResolver = new ENSAddressResolver();
|
||||||
export const ercTokenResolver = new ERCTokenResolver();
|
export const ercTokenResolver = new ERCTokenResolver();
|
||||||
|
export const hardcodedResolver = new HardcodedAddressResolver();
|
||||||
|
|
||||||
const _mainResolver = new CompositeAddressResolver();
|
const _mainResolver = new CompositeAddressResolver();
|
||||||
_mainResolver.addResolver(ensResolver);
|
_mainResolver.addResolver(ensResolver);
|
||||||
_mainResolver.addResolver(ercTokenResolver);
|
_mainResolver.addResolver(ercTokenResolver);
|
||||||
|
_mainResolver.addResolver(hardcodedResolver);
|
||||||
|
|
||||||
export const mainResolver: IAddressResolver<SelectedResolvedName<any>> =
|
export const mainResolver: IAddressResolver<SelectedResolvedName<any>> =
|
||||||
_mainResolver;
|
_mainResolver;
|
||||||
|
@ -28,6 +32,7 @@ export const resolverRendererRegistry = new Map<
|
||||||
>();
|
>();
|
||||||
resolverRendererRegistry.set(ensResolver, ensRenderer);
|
resolverRendererRegistry.set(ensResolver, ensRenderer);
|
||||||
resolverRendererRegistry.set(ercTokenResolver, tokenRenderer);
|
resolverRendererRegistry.set(ercTokenResolver, tokenRenderer);
|
||||||
|
resolverRendererRegistry.set(hardcodedResolver, plainStringRenderer);
|
||||||
|
|
||||||
// TODO: implement progressive resolving
|
// TODO: implement progressive resolving
|
||||||
export const batchPopulate = async (
|
export const batchPopulate = async (
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
import React from "react";
|
||||||
|
import { NavLink } from "react-router-dom";
|
||||||
|
import { ResolvedAddressRenderer } from "../api/address-resolver/address-resolver";
|
||||||
|
|
||||||
|
type PlainStringProps = {
|
||||||
|
address: string;
|
||||||
|
name: string;
|
||||||
|
linkable: boolean;
|
||||||
|
dontOverrideColors: boolean | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
const PlainString: React.FC<PlainStringProps> = ({
|
||||||
|
address,
|
||||||
|
name,
|
||||||
|
linkable,
|
||||||
|
dontOverrideColors,
|
||||||
|
}) => {
|
||||||
|
if (linkable) {
|
||||||
|
return (
|
||||||
|
<NavLink
|
||||||
|
className={`${
|
||||||
|
dontOverrideColors ? "" : "text-link-blue hover:text-link-blue-hover"
|
||||||
|
} truncate`}
|
||||||
|
to={`/address/${address}`}
|
||||||
|
title={name}
|
||||||
|
>
|
||||||
|
{name}
|
||||||
|
</NavLink>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span className="text-gray-400 truncate" title={name}>
|
||||||
|
{name}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const plainStringRenderer: ResolvedAddressRenderer<string> = (
|
||||||
|
address,
|
||||||
|
resolvedAddress,
|
||||||
|
linkable,
|
||||||
|
dontOverrideColors
|
||||||
|
) => (
|
||||||
|
<PlainString
|
||||||
|
address={address}
|
||||||
|
name={resolvedAddress}
|
||||||
|
linkable={linkable}
|
||||||
|
dontOverrideColors={dontOverrideColors}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default PlainString;
|
Loading…
Reference in New Issue