2021-08-08 22:49:45 +00:00
|
|
|
import { BlockTag } from "@ethersproject/abstract-provider";
|
2021-11-10 07:46:43 +00:00
|
|
|
import { ChecksummedAddress } from "./types";
|
2021-07-23 22:46:21 +00:00
|
|
|
|
2021-07-09 16:54:59 +00:00
|
|
|
export const fourBytesURL = (
|
|
|
|
assetsURLPrefix: string,
|
|
|
|
fourBytes: string
|
|
|
|
): string => `${assetsURLPrefix}/signatures/${fourBytes}`;
|
|
|
|
|
2021-10-08 05:38:46 +00:00
|
|
|
export const topic0URL = (assetsURLPrefix: string, topic0: string): string =>
|
|
|
|
`${assetsURLPrefix}/topic0/${topic0}`;
|
|
|
|
|
2021-07-09 16:54:59 +00:00
|
|
|
export const tokenLogoURL = (
|
|
|
|
assetsURLPrefix: string,
|
|
|
|
address: string
|
|
|
|
): string => `${assetsURLPrefix}/assets/${address}/logo.png`;
|
2021-07-23 22:46:21 +00:00
|
|
|
|
2021-08-08 22:49:45 +00:00
|
|
|
export const blockURL = (blockNum: BlockTag) => `/block/${blockNum}`;
|
2021-07-23 22:46:21 +00:00
|
|
|
|
2021-08-08 22:49:45 +00:00
|
|
|
export const blockTxsURL = (blockNum: BlockTag) => `/block/${blockNum}/txs`;
|
2021-07-24 23:04:49 +00:00
|
|
|
|
2021-12-27 18:48:46 +00:00
|
|
|
export const transactionURL = (txHash: string) => `/tx/${txHash}`;
|
|
|
|
|
2021-09-10 21:27:42 +00:00
|
|
|
export enum SourcifySource {
|
|
|
|
// Resolve trusted IPNS for root IPFS
|
|
|
|
IPFS_IPNS,
|
|
|
|
|
|
|
|
// Centralized Sourcify servers
|
|
|
|
CENTRAL_SERVER,
|
|
|
|
}
|
|
|
|
|
|
|
|
const sourcifyIPNS =
|
2021-09-05 19:55:37 +00:00
|
|
|
"k51qzi5uqu5dll0ocge71eudqnrgnogmbr37gsgl12uubsinphjoknl6bbi41p";
|
2021-10-18 01:57:19 +00:00
|
|
|
const defaultIpfsGatewayPrefix = `https://ipfs.io/ipns/${sourcifyIPNS}`;
|
2021-09-06 21:32:11 +00:00
|
|
|
const sourcifyHttpRepoPrefix = `https://repo.sourcify.dev`;
|
2021-09-10 21:27:42 +00:00
|
|
|
|
|
|
|
const resolveSourcifySource = (source: SourcifySource) => {
|
|
|
|
if (source === SourcifySource.IPFS_IPNS) {
|
2021-10-18 01:57:19 +00:00
|
|
|
return defaultIpfsGatewayPrefix;
|
2021-09-10 21:27:42 +00:00
|
|
|
}
|
|
|
|
if (source === SourcifySource.CENTRAL_SERVER) {
|
|
|
|
return sourcifyHttpRepoPrefix;
|
|
|
|
}
|
2021-10-22 18:59:45 +00:00
|
|
|
|
2021-11-01 18:37:10 +00:00
|
|
|
throw new Error(`Unknown Sourcify integration source code: ${source}`);
|
2021-09-10 21:27:42 +00:00
|
|
|
};
|
2021-09-05 19:55:37 +00:00
|
|
|
|
2021-07-24 23:04:49 +00:00
|
|
|
export const sourcifyMetadata = (
|
2021-11-10 07:46:43 +00:00
|
|
|
address: ChecksummedAddress,
|
|
|
|
chainId: number,
|
2021-09-10 21:27:42 +00:00
|
|
|
source: SourcifySource
|
2021-07-24 23:04:49 +00:00
|
|
|
) =>
|
2021-09-10 21:27:42 +00:00
|
|
|
`${resolveSourcifySource(
|
|
|
|
source
|
2021-11-10 07:46:43 +00:00
|
|
|
)}/contracts/full_match/${chainId}/${address}/metadata.json`;
|
2021-07-24 23:33:45 +00:00
|
|
|
|
|
|
|
export const sourcifySourceFile = (
|
2021-11-10 07:46:43 +00:00
|
|
|
address: ChecksummedAddress,
|
|
|
|
chainId: number,
|
2021-09-06 21:32:11 +00:00
|
|
|
filepath: string,
|
2021-09-10 21:27:42 +00:00
|
|
|
source: SourcifySource
|
2021-07-24 23:33:45 +00:00
|
|
|
) =>
|
2021-09-10 21:27:42 +00:00
|
|
|
`${resolveSourcifySource(
|
|
|
|
source
|
2021-11-10 07:46:43 +00:00
|
|
|
)}/contracts/full_match/${chainId}/${address}/sources/${filepath}`;
|
2021-09-06 07:14:49 +00:00
|
|
|
|
|
|
|
export const openInRemixURL = (checksummedAddress: string, networkId: number) =>
|
|
|
|
`https://remix.ethereum.org/#call=source-verification//fetchAndSave//${checksummedAddress}//${networkId}`;
|