From f2fbab36a6b1f5c72623d47201d7ef432baa36ea Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Tue, 2 Nov 2021 03:30:16 -0300 Subject: [PATCH 1/3] Initial implementation of hardcoded address resolver with Uniswap V1/2/3 main contracts as a bootstrap test --- .../HardcodedAddressResolver.ts | 22 ++++++++ .../hardcoded-addresses/1.json | 7 +++ src/api/address-resolver/index.ts | 5 ++ src/components/PlainString.tsx | 53 +++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 src/api/address-resolver/HardcodedAddressResolver.ts create mode 100644 src/api/address-resolver/hardcoded-addresses/1.json create mode 100644 src/components/PlainString.tsx diff --git a/src/api/address-resolver/HardcodedAddressResolver.ts b/src/api/address-resolver/HardcodedAddressResolver.ts new file mode 100644 index 0000000..42d1102 --- /dev/null +++ b/src/api/address-resolver/HardcodedAddressResolver.ts @@ -0,0 +1,22 @@ +import { BaseProvider } from "@ethersproject/providers"; +import { IAddressResolver } from "./address-resolver"; + +type HardcodedAddressMap = Record; + +export class HardcodedAddressResolver implements IAddressResolver { + async resolveAddress( + provider: BaseProvider, + address: string + ): Promise { + try { + const addressMap: HardcodedAddressMap = await import( + `./hardcoded-addresses/${provider.network.chainId}.json` + ); + + return addressMap[address]; + } catch (err) { + // Ignore on purpose + return undefined; + } + } +} diff --git a/src/api/address-resolver/hardcoded-addresses/1.json b/src/api/address-resolver/hardcoded-addresses/1.json new file mode 100644 index 0000000..73c949d --- /dev/null +++ b/src/api/address-resolver/hardcoded-addresses/1.json @@ -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" +} \ No newline at end of file diff --git a/src/api/address-resolver/index.ts b/src/api/address-resolver/index.ts index dc72a9f..f1514be 100644 --- a/src/api/address-resolver/index.ts +++ b/src/api/address-resolver/index.ts @@ -1,5 +1,6 @@ import { BaseProvider } from "@ethersproject/providers"; import { ensRenderer } from "../../components/ENSName"; +import { plainStringRenderer } from "../../components/PlainString"; import { tokenRenderer } from "../../components/TokenName"; import { IAddressResolver, ResolvedAddressRenderer } from "./address-resolver"; import { @@ -8,16 +9,19 @@ import { } from "./CompositeAddressResolver"; import { ENSAddressResolver } from "./ENSAddressResolver"; import { ERCTokenResolver } from "./ERCTokenResolver"; +import { HardcodedAddressResolver } from "./HardcodedAddressResolver"; export type ResolvedAddresses = Record>; // Create and configure the main resolver export const ensResolver = new ENSAddressResolver(); export const ercTokenResolver = new ERCTokenResolver(); +export const hardcodedResolver = new HardcodedAddressResolver(); const _mainResolver = new CompositeAddressResolver(); _mainResolver.addResolver(ensResolver); _mainResolver.addResolver(ercTokenResolver); +_mainResolver.addResolver(hardcodedResolver); export const mainResolver: IAddressResolver> = _mainResolver; @@ -28,6 +32,7 @@ export const resolverRendererRegistry = new Map< >(); resolverRendererRegistry.set(ensResolver, ensRenderer); resolverRendererRegistry.set(ercTokenResolver, tokenRenderer); +resolverRendererRegistry.set(hardcodedResolver, plainStringRenderer); // TODO: implement progressive resolving export const batchPopulate = async ( diff --git a/src/components/PlainString.tsx b/src/components/PlainString.tsx new file mode 100644 index 0000000..5b891bf --- /dev/null +++ b/src/components/PlainString.tsx @@ -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 = ({ + address, + name, + linkable, + dontOverrideColors, +}) => { + if (linkable) { + return ( + + {name} + + ); + } + + return ( + + {name} + + ); +}; + +export const plainStringRenderer: ResolvedAddressRenderer = ( + address, + resolvedAddress, + linkable, + dontOverrideColors +) => ( + +); + +export default PlainString; From 7daffbca263c2e30576cc64109c0bafbf0ecc11e Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Tue, 2 Nov 2021 03:36:30 -0300 Subject: [PATCH 2/3] Add tornado cash proxy --- src/api/address-resolver/hardcoded-addresses/1.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/address-resolver/hardcoded-addresses/1.json b/src/api/address-resolver/hardcoded-addresses/1.json index 73c949d..1eb4ec0 100644 --- a/src/api/address-resolver/hardcoded-addresses/1.json +++ b/src/api/address-resolver/hardcoded-addresses/1.json @@ -1,4 +1,5 @@ { + "0x722122dF12D4e14e13Ac3b6895a86e84145b6967": "Tornado Cash: Proxy", "0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95": "Uniswap V1: Factory", "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f": "Uniswap V2: Factory", "0xf164fC0Ec4E93095b804a4795bBe1e041497b92a": "Uniswap V2: Router 1", From 2dd055755efdf2d59b615246878ae406e4519828 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Tue, 2 Nov 2021 03:48:42 -0300 Subject: [PATCH 3/3] Add gitcoin donation checkout address --- src/api/address-resolver/hardcoded-addresses/1.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/address-resolver/hardcoded-addresses/1.json b/src/api/address-resolver/hardcoded-addresses/1.json index 1eb4ec0..7ae2f9b 100644 --- a/src/api/address-resolver/hardcoded-addresses/1.json +++ b/src/api/address-resolver/hardcoded-addresses/1.json @@ -1,4 +1,5 @@ { + "0x7d655c57f71464B6f83811C55D84009Cd9f5221C": "Gitcoin: Bulk Checkout", "0x722122dF12D4e14e13Ac3b6895a86e84145b6967": "Tornado Cash: Proxy", "0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95": "Uniswap V1: Factory", "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f": "Uniswap V2: Factory",