-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from gnosisguild/cowswap-arb1
Update networks and support cow order signer also on arb1
- Loading branch information
Showing
11 changed files
with
80 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.