Skip to content

Commit

Permalink
Merge pull request #113 from gnosisguild/cowswap-arb1
Browse files Browse the repository at this point in the history
Update networks and support cow order signer also on arb1
  • Loading branch information
jfschwarz authored Jun 6, 2024
2 parents e43dff6 + ceb6ca1 commit 413125d
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 220 deletions.
2 changes: 2 additions & 0 deletions extension/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"alchemix",
"ankr",
"apikey",
"arbitrum",
"barnbridge",
"bitshift",
"Blockhash",
Expand Down Expand Up @@ -45,6 +46,7 @@
"reflexer",
"refork",
"Samczun",
"sepolia",
"shazow",
"sighash",
"Sindre",
Expand Down
26 changes: 4 additions & 22 deletions extension/src/browser/Drawer/ContractAddress/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import React, { useEffect, useMemo, useState } from 'react'
import { RiExternalLinkLine, RiFileCopyLine } from 'react-icons/ri'

import { BlockLink, Box, Flex, IconButton } from '../../../components'
import {
EXPLORER_API_KEY,
EXPLORER_API_URL,
EXPLORER_URL,
} from '../../../chains'
import { EXPLORER_URL } from '../../../chains'
import { useConnection } from '../../../connections'

import classes from './style.module.css'
import { fetchContractInfo } from '../../fetchContractInfo'

interface Props {
address: string
Expand Down Expand Up @@ -45,14 +42,9 @@ const ContractAddress: React.FC<Props> = ({

useEffect(() => {
let canceled = false
const explorerApiUrl = EXPLORER_API_URL[chainId]
const apiKey = EXPLORER_API_KEY[chainId]

memoizedFetchJson(
`${explorerApiUrl}?module=contract&action=getsourcecode&address=${address}&apikey=${apiKey}`
).then((json) => {
fetchContractInfo(address as `0x${string}`, chainId).then((info) => {
if (!canceled) {
setContractName(json.result[0]?.ContractName || '')
setContractName(info.name || '')
}
})

Expand Down Expand Up @@ -107,13 +99,3 @@ const ContractAddress: React.FC<Props> = ({
}

export default ContractAddress

const fetchCache = new Map<string, any>()
const memoizedFetchJson = async (url: string) => {
if (fetchCache.has(url)) {
return fetchCache.get(url)
}
const json = await fetch(url).then((res) => res.json())
fetchCache.set(url, json)
return json
}
18 changes: 9 additions & 9 deletions extension/src/browser/ProvideProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { useConnection } from '../connections'
import { Eip1193Provider } from '../types'

import fetchAbi from './fetchAbi'
import { fetchContractInfo } from './fetchContractInfo'
import { useDispatch, useNewTransactions } from '../state'
import { encodeTransaction } from '../encodeTransaction'

Expand Down Expand Up @@ -72,13 +72,13 @@ const ProvideProvider: React.FC<Props> = ({ simulate, children }) => {
const input = await decodeSingle(
metaTx,
new Web3Provider(provider),
(address: string, data: string) =>
fetchAbi(
connection.chainId,
address,
data,
new Web3Provider(provider)
),
async (address: string) => {
const info = await fetchContractInfo(
address as `0x${string}`,
connection.chainId
)
return JSON.stringify(info.abi)
},
txId
)
dispatch({
Expand Down Expand Up @@ -126,7 +126,7 @@ const ProvideProvider: React.FC<Props> = ({ simulate, children }) => {
`multi-send batch has been submitted with transaction hash ${batchTransactionHash}`
)
return batchTransactionHash
}, [transactions, wrappingProvider, dispatch, connection.chainId])
}, [transactions, wrappingProvider, dispatch, connection.multisend])

return (
<ProviderContext.Provider
Expand Down
61 changes: 0 additions & 61 deletions extension/src/browser/fetchAbi.spec.ts

This file was deleted.

94 changes: 0 additions & 94 deletions extension/src/browser/fetchAbi.ts

This file was deleted.

56 changes: 56 additions & 0 deletions extension/src/browser/fetchContractInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { getAddress } from 'ethers/lib/utils'
import { ChainId } from '../chains'

type AbiFragment = object

export interface ContractInfo {
address: `0x${string}`
proxyTo?: `0x${string}`
verified: boolean
name?: string
abi?: AbiFragment[]
}

export const fetchContractInfo = async (
address: `0x${string}`,
chainId: ChainId
): Promise<ContractInfo> => {
const url = `https://api.abi.pub/v1/chains/${chainId}/accounts/${address.toLowerCase()}`
const result = (await memoizedFetchJson(url)) || {
address: getAddress(address),
verified: false,
}

return 'proxy' in result
? {
address: result.address,
proxyTo: result.proxy.target,
name: result.implementation.name,
verified: result.implementation.verified,
abi: result.implementation.abi,
}
: {
address: result.address,
name: result.name,
verified: result.verified,
abi: result.abi,
}
}

const fetchCache = new Map<string, any>()
const memoizedFetchJson = async (url: string) => {
if (fetchCache.has(url)) {
return fetchCache.get(url)
}
const res = await fetch(url)

if (!res.ok) {
console.error('Failed to fetch contract info', url, res.status)
fetchCache.set(url, null)
return null
}

const json = await res.json()
fetchCache.set(url, json)
return json
}
16 changes: 1 addition & 15 deletions extension/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

export const RPC = {
1: 'https://mainnet.infura.io/v3/b81b456501e34bed8a85a3c2ff8f4577',
4: 'https://rinkeby.infura.io/v3/b81b456501e34bed8a85a3c2ff8f4577',
5: 'https://goerli.infura.io/v3/b81b456501e34bed8a85a3c2ff8f4577',
10: 'https://mainnet.optimism.io',
56: 'https://bsc-dataseed.binance.org',
100: 'https://rpc.gnosischain.com',
Expand All @@ -21,8 +19,6 @@ export type ChainId = keyof typeof RPC

export const EXPLORER_URL: Record<ChainId, string> = {
1: 'https://etherscan.io',
4: 'https://rinkeby.etherscan.io',
5: 'https://goerli.etherscan.io',
10: 'https://optimistic.etherscan.io',
56: 'https://bscscan.com',
100: 'https://gnosisscan.io',
Expand All @@ -38,8 +34,6 @@ export const EXPLORER_URL: Record<ChainId, string> = {

export const EXPLORER_API_URL: Record<ChainId, string> = {
1: 'https://api.etherscan.io/api',
4: 'https://api-rinkeby.etherscan.io/api',
5: 'https://api-goerli.etherscan.io/api',
10: 'https://api-optimistic.etherscan.io/api',
56: 'https://api.bscscan.com/api',
100: 'https://api.gnosisscan.io/api',
Expand All @@ -55,15 +49,13 @@ export const EXPLORER_API_URL: Record<ChainId, string> = {

export const EXPLORER_API_KEY: Record<ChainId, string> = {
1: 'N53BKW6ABNX7CNUK8QIXGRAQS2NME92YAN',
4: 'N53BKW6ABNX7CNUK8QIXGRAQS2NME92YAN',
5: 'N53BKW6ABNX7CNUK8QIXGRAQS2NME92YAN',
10: '',
56: '',
100: 'W575K6DTMSTVB7UFUSNW7GWQ4UWUARTJ7Z',
137: '',
246: '',
8453: 'KCC7EQHE17IAQZA9TICUS6BQTJGZUDRNIY',
42161: '',
42161: 'SJ5BEYBBC3DNSKTH5BAEPFJXUZDAJ133UI',
42220: '',
73799: '',
80001: '',
Expand All @@ -72,8 +64,6 @@ export const EXPLORER_API_KEY: Record<ChainId, string> = {

export const CHAIN_PREFIX: Record<ChainId, string> = {
1: 'eth',
4: 'rin',
5: 'gor',
10: 'oeth',
56: 'bsc',
100: 'gno',
Expand All @@ -89,8 +79,6 @@ export const CHAIN_PREFIX: Record<ChainId, string> = {

export const CHAIN_CURRENCY: Record<ChainId, string> = {
1: 'ETH',
4: 'ETH',
5: 'ETH',
56: 'BNB',
10: 'ETH',
100: 'xDAI',
Expand All @@ -106,8 +94,6 @@ export const CHAIN_CURRENCY: Record<ChainId, string> = {

export const CHAIN_NAME: Record<ChainId, string> = {
1: 'Ethereum',
4: 'Rinkeby',
5: 'Görli',
56: 'Binance Smart Chain',
10: 'Optimism',
100: 'Gnosis Chain',
Expand Down
14 changes: 2 additions & 12 deletions extension/src/components/Address/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import cn from 'classnames'
import copy from 'copy-to-clipboard'
import React from 'react'
import { RiExternalLinkLine, RiFileCopyLine } from 'react-icons/ri'
import { EXPLORER_URL } from '../../chains'

import { useConnection } from '../../connections'
import { validateAddress } from '../../utils'
Expand All @@ -21,17 +22,6 @@ interface Props {
const VISIBLE_START = 4
const VISIBLE_END = 4

const EXPLORER_URLS: Record<string, string | undefined> = {
'1': 'https://etherscan.io',
'4': 'https://rinkeby.etherscan.io',
'100': 'https://gnosisscan.io',
'73799': 'https://volta-explorer.energyweb.org',
'246': 'https://explorer.energyweb.org',
'137': 'https://polygonscan.com',
'56': 'https://bscscan.com',
'42161': 'https://arbiscan.io',
}

export const shortenAddress = (address: string): string => {
const checksumAddress = validateAddress(address)
const start = checksumAddress.substring(0, VISIBLE_START + 2)
Expand All @@ -48,7 +38,7 @@ const Address: React.FC<Props> = ({
const {
connection: { chainId },
} = useConnection()
const explorerUrl = chainId && EXPLORER_URLS[chainId]
const explorerUrl = chainId && EXPLORER_URL[chainId]
const checksumAddress = validateAddress(address)
const displayAddress = shortenAddress(checksumAddress)

Expand Down
6 changes: 3 additions & 3 deletions extension/src/components/AppPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const APP_CONFIG = [
name: 'Uniswap',
url: 'https://app.uniswap.org',
logoUrl: uniswapLogo,
networks: [1, 5, 11155111],
networks: [1, 11155111],
},
{
name: 'Honeyswap',
Expand Down Expand Up @@ -98,7 +98,7 @@ const APP_CONFIG = [
name: 'Cowswap',
url: 'https://swap.cow.fi/',
logoUrl: cowswapLogo,
networks: [1, 5, 100, 11155111],
networks: [1, 100, 11155111],
},
{
name: 'Saddle',
Expand All @@ -122,7 +122,7 @@ const APP_CONFIG = [
name: 'Sushiswap',
url: 'https://app.sushi.com/',
logoUrl: sushiswapLogo,
networks: [1, 5, 100, 11155111],
networks: [1, 100, 11155111],
},
{ name: 'Unit', url: 'https://unit.xyz/', logoUrl: unitLogo, networks: [1] },
{
Expand Down
Loading

0 comments on commit 413125d

Please sign in to comment.