Merge pull request #234 from ArtemKolodko/proxy_erc20_tracking

Proxy erc20 tracking
pull/237/head
Artem 2 years ago committed by GitHub
commit 69b381e0dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/Routes.tsx
  2. 8
      src/api/client.ts
  3. 3
      src/components/ERC20_Pool.tsx
  4. 4
      src/hooks/ERC20_Pool.ts
  5. 3
      src/pages/AddressPage/ContractDetails/AbiMethodView.tsx
  6. 85
      src/pages/AddressPage/ContractDetails/index.tsx
  7. 2
      src/pages/AddressPage/tabs/transactions/Transactions.tsx
  8. 4
      src/pages/AddressPage/tabs/transactions/columns/erc20.tsx
  9. 31
      src/pages/ExportData/export-utils.ts
  10. 118
      src/pages/ExportData/index.tsx
  11. 196
      src/pages/VerifyProxyContract/VerifyProxyContract.tsx
  12. 1
      src/types/blockchain.ts

@ -15,7 +15,6 @@ import { ExportData } from "./pages/ExportData";
import { InventoryDetailsPage } from "./pages/InventoryDetailsPage/InventoryDetailsPage"; import { InventoryDetailsPage } from "./pages/InventoryDetailsPage/InventoryDetailsPage";
import { ApprovalPage } from "./pages/ApprovalPage"; import { ApprovalPage } from "./pages/ApprovalPage";
import { CheckHRC } from "./pages/tools/CheckHRC"; import { CheckHRC } from "./pages/tools/CheckHRC";
import {VerifyProxyContract} from "./pages/VerifyProxyContract/VerifyProxyContract";
import { ChartsPage } from "./pages/ChartsPage"; import { ChartsPage } from "./pages/ChartsPage";
import { TopStatsPage } from "./pages/TopStatsPage"; import { TopStatsPage } from "./pages/TopStatsPage";
@ -97,10 +96,6 @@ export function Routes() {
<VerifyContract /> <VerifyContract />
</Route> </Route>
<Route path="/proxyContractChecker">
<VerifyProxyContract />
</Route>
<Route path="/exportData"> <Route path="/exportData">
<ExportData /> <ExportData />
</Route> </Route>

@ -220,11 +220,3 @@ export async function getTokenERC1155AssetDetails(address: string, tokenID: stri
// todo fix on backend // todo fix on backend
return res && res[0] return res && res[0]
} }
export function getProxyImplementation(params: [ShardID, string]) {
return transport("getProxyImplementation", params) as Promise<any>;
}
export function assignProxyImplementation(params: [ShardID, string, string]) {
return transport("assignProxyImplementation", params) as Promise<any>;
}

@ -20,7 +20,8 @@ export function ERC20_Pool() {
erc20 = erc20.map((item) => { erc20 = erc20.map((item) => {
erc20Map[item.address] = { erc20Map[item.address] = {
...item, ...item,
isBridged: isTokenBridged(item.address) isBridged: isTokenBridged(item.address),
name: item.implementationAddress ? `${item.name} (Proxy)` : item.name
}; };
return { return {
[IndexedDbKeyPath]: item.address, [IndexedDbKeyPath]: item.address,

@ -17,7 +17,8 @@ export const useERC20Pool = singletonHook(initValue, () => {
erc20.forEach(item => { erc20.forEach(item => {
erc20Map[item.address] = { erc20Map[item.address] = {
...item, ...item,
isBridged: isTokenBridged(item.address) isBridged: isTokenBridged(item.address),
name: item.implementationAddress ? `${item.name} (Proxy)` : item.name
}; };
}) })
setMode(erc20Map) setMode(erc20Map)
@ -55,6 +56,7 @@ export interface Erc20 {
image?: string; image?: string;
}; };
isBridged: boolean; isBridged: boolean;
implementationAddress: string
} }
export type ERC20_Pool = Record<string, Erc20>; export type ERC20_Pool = Record<string, Erc20>;

@ -184,7 +184,7 @@ export const AbiMethodsView = (props: {
const itemType = input.type.slice(0, input.type.indexOf('[]')); const itemType = input.type.slice(0, input.type.indexOf('[]'));
return ( return (
<Field gap='5px'> <Field gap='5px' key={idx}>
<Text size='small'> <Text size='small'>
{name} <span>({input.type})</span> {name} <span>({input.type})</span>
</Text> </Text>
@ -296,6 +296,7 @@ export const AbiMethodsView = (props: {
{abiMethod.outputs {abiMethod.outputs
? abiMethod.outputs.map((input, idx) => { ? abiMethod.outputs.map((input, idx) => {
return (<AbiParam return (<AbiParam
key={idx}
readonly={true} readonly={true}
type={input.type} type={input.type}
name={input.name} name={input.name}

@ -8,6 +8,7 @@ import { ISourceCode } from "src/api/explorerV1";
import { AbiMethodsView } from "./AbiMethodView"; import { AbiMethodsView } from "./AbiMethodView";
import { AbiItem } from "web3-utils"; import { AbiItem } from "web3-utils";
import { Wallet } from "./ConnectWallets"; import { Wallet } from "./ConnectWallets";
import {Address} from "../../../components/ui";
const StyledTextArea = styled(TextArea)` const StyledTextArea = styled(TextArea)`
padding: 0.75rem; padding: 0.75rem;
@ -27,13 +28,13 @@ const LabelSuccess = styled(Box)`
export const ContractDetails = (props: { export const ContractDetails = (props: {
address: string; address: string;
contracts?: AddressDetails | null; contracts?: AddressDetails | null;
sourceCode?: ISourceCode | null; sourceCode: ISourceCode | null;
implementation?: AddressDetails | null; implementation?: AddressDetails | null;
implementationSourceCode?: ISourceCode | null; implementationSourceCode?: ISourceCode | null;
shard?: ShardID; shard?: ShardID;
}) => { }) => {
if (!!props.sourceCode) { if (!!props.sourceCode || (props.implementation && props.implementationSourceCode)) {
return ( return (
<VerifiedContractDetails <VerifiedContractDetails
sourceCode={props.sourceCode} sourceCode={props.sourceCode}
@ -71,6 +72,7 @@ export const AbiMethods = (props: {
{props.abi.map((abiMethod, idx) => {props.abi.map((abiMethod, idx) =>
abiMethod.name ? ( abiMethod.name ? (
<AbiMethodsView <AbiMethodsView
key={idx}
abiMethod={abiMethod} abiMethod={abiMethod}
address={props.address} address={props.address}
index={idx} index={idx}
@ -201,9 +203,7 @@ export const NoVerifiedContractDetails = (props: {
<Item <Item
label="Bytecode" label="Bytecode"
value={ value={
<StyledTextArea readOnly={true} rows={15} cols={100}> <StyledTextArea readOnly={true} rows={15} cols={100} value={props.contracts.bytecode || ""} />
{props.contracts.bytecode || ""}
</StyledTextArea>
} }
/> />
</Box> </Box>
@ -248,7 +248,7 @@ const TabButton = (props: {
}; };
export const VerifiedContractDetails = (props: { export const VerifiedContractDetails = (props: {
sourceCode: ISourceCode; sourceCode: ISourceCode | null;
address: string; address: string;
contracts?: AddressDetails | null; contracts?: AddressDetails | null;
shard: number; shard: number;
@ -269,7 +269,7 @@ export const VerifiedContractDetails = (props: {
: (chainId === 1666700000 || chainId === 1666900000); : (chainId === 1666700000 || chainId === 1666900000);
try { try {
abiString = JSON.stringify(props.sourceCode.abi, null, 4); abiString = JSON.stringify(props.sourceCode?.abi, null, 4);
} catch { } } catch { }
return ( return (
@ -281,20 +281,18 @@ export const VerifiedContractDetails = (props: {
onClick={() => setTab(V_TABS.CODE)} onClick={() => setTab(V_TABS.CODE)}
selected={tab === V_TABS.CODE} selected={tab === V_TABS.CODE}
/> />
{props.sourceCode.abi ? ( <>
<> <TabButton
<TabButton
text={V_TABS.READ} text={V_TABS.READ}
onClick={() => setTab(V_TABS.READ)} onClick={() => setTab(V_TABS.READ)}
selected={tab === V_TABS.READ} selected={tab === V_TABS.READ}
/> />
<TabButton <TabButton
text={V_TABS.WRITE} text={V_TABS.WRITE}
onClick={() => setTab(V_TABS.WRITE)} onClick={() => setTab(V_TABS.WRITE)}
selected={tab === V_TABS.WRITE} selected={tab === V_TABS.WRITE}
/> />
</> </>
) : null}
{/*{props.sourceCode.proxyAddress && props.sourceCode.proxy ? (*/} {/*{props.sourceCode.proxyAddress && props.sourceCode.proxy ? (*/}
{/* <>*/} {/* <>*/}
{/* <TabButton*/} {/* <TabButton*/}
@ -331,7 +329,7 @@ export const VerifiedContractDetails = (props: {
) : null} ) : null}
</Box> </Box>
{tab === V_TABS.CODE ? ( {tab === V_TABS.CODE && props.sourceCode ? (
<Box style={{ padding: "10px" }} margin={{ top: "medium" }}> <Box style={{ padding: "10px" }} margin={{ top: "medium" }}>
<Box direction="column" gap="30px"> <Box direction="column" gap="30px">
<Box direction="column"> <Box direction="column">
@ -357,8 +355,7 @@ export const VerifiedContractDetails = (props: {
<Item <Item
label="Contract Source Code Verified" label="Contract Source Code Verified"
value={ value={
<StyledTextArea readOnly={true} rows={15} cols={100} value={props.sourceCode.sourceCode || ""}> <StyledTextArea readOnly={true} rows={15} cols={100} value={props.sourceCode.sourceCode || ""} />
</StyledTextArea>
} }
/>} />}
{props.sourceCode.supporting?.sources {props.sourceCode.supporting?.sources
@ -368,9 +365,7 @@ export const VerifiedContractDetails = (props: {
key={i} key={i}
label={`Verified ${source.substring(source.lastIndexOf('/') + 1)}`} label={`Verified ${source.substring(source.lastIndexOf('/') + 1)}`}
value={ value={
<StyledTextArea readOnly={true} rows={15} cols={100} value={props.sourceCode.supporting.sources[source].source || ""}> <StyledTextArea readOnly={true} rows={15} cols={100} value={props.sourceCode?.supporting.sources[source].source || ""} />
</StyledTextArea>
} }
/> />
})} })}
@ -382,9 +377,7 @@ export const VerifiedContractDetails = (props: {
key={i} key={i}
label={`Verified ${source.substring(source.lastIndexOf('/') + 1)}`} label={`Verified ${source.substring(source.lastIndexOf('/') + 1)}`}
value={ value={
<StyledTextArea readOnly={true} rows={15} cols={100} value={props.sourceCode.supporting[source].source || ""}> <StyledTextArea readOnly={true} rows={15} cols={100} value={props.sourceCode?.supporting[source].source || ""} />
</StyledTextArea>
} }
/> />
})} })}
@ -421,20 +414,24 @@ export const VerifiedContractDetails = (props: {
</Box> </Box>
) : null} ) : null}
{tab === V_TABS.READ && props.sourceCode.abi ? ( {tab === V_TABS.CODE && !props.sourceCode && props.contracts && <NoVerifiedContractDetails contracts={props.contracts} address={props.address} shard={props.shard} />}
<Box style={{ padding: "10px" }} margin={{ top: "medium" }}>
<AbiMethods {tab === V_TABS.READ ? (
abi={props.sourceCode?.abi?.filter( (props.sourceCode && props.sourceCode.abi) ? <Box style={{ padding: "10px" }} margin={{ top: "medium" }}>
(a) => a.stateMutability === "view" && a.type === "function" <AbiMethods
)} abi={props.sourceCode?.abi?.filter(
address={props.address} (a) => a.stateMutability === "view" && a.type === "function"
isRead={V_TABS.READ === tab} )}
/> address={props.address}
</Box> isRead={V_TABS.READ === tab}
/>
</Box> : <Box style={{ padding: "10px" }} margin={{ top: "medium" }}>
Sorry, there are no available Contract ABI methods to read. Unable to read contract info.
</Box>
) : null} ) : null}
{tab === V_TABS.WRITE && props.sourceCode.abi ? ( {tab === V_TABS.WRITE ? (
<Box style={{ padding: "10px" }} margin={{ top: "medium" }}> (props.sourceCode && props.sourceCode.abi) ? <Box style={{ padding: "10px" }} margin={{ top: "medium" }}>
<Wallet onSetMetamask={setMetamask} onSetChainId={setChainId} /> <Wallet onSetMetamask={setMetamask} onSetChainId={setChainId} />
<AbiMethods <AbiMethods
abi={props.sourceCode.abi.filter( abi={props.sourceCode.abi.filter(
@ -447,11 +444,17 @@ export const VerifiedContractDetails = (props: {
metamaskAddress={metamaskAddress} metamaskAddress={metamaskAddress}
validChainId={validChainId} validChainId={validChainId}
/> />
</Box> </Box> : <Box style={{ padding: "10px" }} margin={{ top: "medium" }}>
Sorry, there are no available Contract ABI methods to write. Unable to write contract info.
</Box>
) : null} ) : null}
{tab === V_TABS.READ_PROXY && props.implementation?.address && props.implementationSourceCode?.abi ? ( {tab === V_TABS.READ_PROXY && props.implementation?.address && props.implementationSourceCode?.abi ? (
<Box style={{ padding: "10px" }} margin={{ top: "medium" }}> <Box style={{ padding: "10px" }} margin={{ top: "xsmall" }} gap={'16px'}>
<Box direction={'row'} align={'center'} gap={'4px'}>
<Text size={'small'}>ABI for the implementation contract at</Text>
<Address address={props.implementation?.address} hideCopyBtn={true} />
</Box>
<AbiMethods <AbiMethods
abi={props.implementationSourceCode?.abi.filter( abi={props.implementationSourceCode?.abi.filter(
(a) => a.stateMutability === "view" && a.type === "function" (a) => a.stateMutability === "view" && a.type === "function"
@ -463,7 +466,11 @@ export const VerifiedContractDetails = (props: {
) : null} ) : null}
{tab === V_TABS.WRITE_PROXY && props.implementation?.address && props.implementationSourceCode?.abi ? ( {tab === V_TABS.WRITE_PROXY && props.implementation?.address && props.implementationSourceCode?.abi ? (
<Box style={{ padding: "10px" }} margin={{ top: "medium" }}> <Box style={{ padding: "10px" }} margin={{ top: "xsmall" }} gap={'16px'}>
<Box direction={'row'} align={'center'} gap={'4px'}>
<Text size={'small'}>ABI for the implementation contract at</Text>
<Address address={props.implementation?.address} hideCopyBtn={true} />
</Box>
<Wallet onSetMetamask={setMetamask} onSetChainId={setChainId} /> <Wallet onSetMetamask={setMetamask} onSetChainId={setChainId} />
<AbiMethods <AbiMethods
abi={props.implementationSourceCode?.abi.filter( abi={props.implementationSourceCode?.abi.filter(

@ -305,7 +305,7 @@ export function Transactions(props: {
rowDetails={props.rowDetails} rowDetails={props.rowDetails}
showPages={totalElements > 0} showPages={totalElements > 0}
/> />
{['transaction', 'erc20', 'erc721', 'erc1155'].includes(props.type) && {['transaction', 'erc20', 'erc721', 'erc1155', 'internal_transaction'].includes(props.type) &&
<Box style={{ alignItems: 'flex-end' }}> <Box style={{ alignItems: 'flex-end' }}>
<ExportToCsvButton address={id} type={props.type} /> <ExportToCsvButton address={id} type={props.type} />
</Box> </Box>

@ -72,7 +72,7 @@ export function getERC20Columns(id: string): ColumnConfig<any>[] {
<Text <Text
color="minorText" color="minorText"
size="small" size="small"
style={{ width: '320px' }} style={{ width: '260px' }}
> >
Value Value
</Text> </Text>
@ -103,7 +103,7 @@ export function getERC20Columns(id: string): ColumnConfig<any>[] {
<Text <Text
color="minorText" color="minorText"
size="small" size="small"
style={{ width: '120px' }} style={{ width: '150px' }}
> >
Token Token
</Text> </Text>

@ -1,4 +1,4 @@
import { RelatedTransaction } from "../../types"; import {InternalTransaction, RelatedTransaction} from "../../types";
import dayjs from "dayjs"; import dayjs from "dayjs";
import Big from "big.js"; import Big from "big.js";
import { calculateFee, calculateFeePriceUSD } from "../../utils/fee"; import { calculateFee, calculateFeePriceUSD } from "../../utils/fee";
@ -62,6 +62,24 @@ const mapHrc20TxToExport = (ownerAddress: string, tx: any, erc20Map: Record<stri
} }
} }
const mapInternalTxToExport = (ownerAddress: string, tx: InternalTransaction, onePrice: number) => {
const txDate = dayjs(tx.timestamp)
const isSender = ownerAddress === tx.from
return {
Txhash: tx.transactionHash,
Blockno: tx.blockNumber,
UnixTimestamp: txDate.unix(),
DateTime: txDate.format('YYYY-MM-DD HH:MM:ss'),
From: tx.from,
To: tx.to,
['Value_IN(ONE)']: convertValue(isSender ? '0': tx.value),
['Value_OUT(ONE)']: convertValue(isSender ? tx.value : '0'),
[`CurrentValue @ $${onePrice}/ONE`]: convertValue(onePrice * +tx.value),
Method: tx.input.slice(0, 10),
Type: tx.type
}
}
export interface IDownloadCsvParams { export interface IDownloadCsvParams {
type: TRelatedTransaction type: TRelatedTransaction
address: string address: string
@ -76,12 +94,15 @@ export const downloadCSV = (params: IDownloadCsvParams, filename: string) => {
const { type, address, txs, onePrice, erc20Map, erc721Map, erc1155Map } = params const { type, address, txs, onePrice, erc20Map, erc721Map, erc1155Map } = params
const mapTx = (tx: any) => { const mapTx = (tx: any) => {
return type === 'transaction' if(type === 'erc20') {
? mapRelatedTxToExport(address, tx, onePrice) return mapHrc20TxToExport(address, tx, erc20Map, erc721Map, erc1155Map)
: mapHrc20TxToExport(address, tx, erc20Map, erc721Map, erc1155Map) } else if (type === 'internal_transaction') {
return mapInternalTxToExport(address, tx, onePrice)
}
return mapRelatedTxToExport(address, tx, onePrice)
} }
const mappedTxs = txs.map((tx) => mapTx(tx)) const mappedTxs = txs.map(mapTx)
const header = mappedTxs.filter((_, index) => index === 0).map(item => Object.keys(item)) const header = mappedTxs.filter((_, index) => index === 0).map(item => Object.keys(item))
const body = mappedTxs const body = mappedTxs
.map((item) => Object.values(item)) .map((item) => Object.values(item))

@ -4,7 +4,7 @@ import { Address, BaseContainer, BasePage, Button, TipContent } from "src/compon
import { Heading, DateInput, Box, Spinner, Tip, Text } from "grommet"; import { Heading, DateInput, Box, Spinner, Tip, Text } from "grommet";
import styled from "styled-components"; import styled from "styled-components";
import useQuery from "../../hooks/useQuery"; import useQuery from "../../hooks/useQuery";
import { getRelatedTransactionsByType } from "../../api/client"; import {getBlocks, getRelatedTransactionsByType} from "../../api/client";
import { downloadCSV } from "./export-utils"; import { downloadCSV } from "./export-utils";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { toaster } from "../../App"; import { toaster } from "../../App";
@ -35,9 +35,11 @@ const DownloadButton = styled(Button)`
height: 42px; height: 42px;
` `
const DefaultLimit = 5000
export const ExportData = () => { export const ExportData = () => {
const query = useQuery(); const query = useQuery();
const address = query.get('address') || ''; const address = (query.get('address') || '').toLowerCase()
const type = (query.get('type') || 'transaction') as TRelatedTransaction; const type = (query.get('type') || 'transaction') as TRelatedTransaction;
const dateFormat = 'YYYY-MM-DD' const dateFormat = 'YYYY-MM-DD'
@ -63,22 +65,6 @@ export const ExportData = () => {
inputProps: { width: '170px' } inputProps: { width: '170px' }
} }
const filter = {
offset: 0,
limit: 5000,
orderBy: 'block_number',
orderDirection: 'desc',
filters: [{
type: 'gt',
property: 'timestamp',
value: `'${dateFrom}'`
}, {
type: 'lt',
property: 'timestamp',
value: `'${dayjs(dateTo).add(1, 'day').format(dateFormat)}'`
}]
}
const showErrorNotification = () => { const showErrorNotification = () => {
toaster.show({ toaster.show({
message: () => ( message: () => (
@ -93,11 +79,86 @@ export const ExportData = () => {
const onDownloadClicked = async () => { const onDownloadClicked = async () => {
try { try {
setIsDownloading(true) setIsDownloading(true)
const txsFilter: any = {
offset: 0,
limit: DefaultLimit,
orderBy: 'block_number',
orderDirection: 'desc',
filters: []
}
// if (type === 'transaction') {
// if (dateFrom) {
// txsFilter.filters.push({
// type: 'gt',
// property: 'timestamp',
// value: `'${dateFrom}'`
// })
// }
// if (dateTo) {
// txsFilter.filters.push({
// type: 'lt',
// property: 'timestamp',
// value: `'${dayjs(dateTo).add(1, 'day').format(dateFormat)}'`
// })
// }
// }
// Get block numbers first, then filter internal by block number (not timestamp)
if (dateFrom) {
const blockFromFilter = {
offset: 0,
limit: 1,
orderBy: 'number',
orderDirection: 'desc',
filters: [{
type: 'lte',
property: 'timestamp',
value: `'${dateFrom}'`
}]
}
const [blockFrom] = await getBlocks([0, blockFromFilter]);
if(blockFrom) {
txsFilter.filters.push({
type: 'gte',
property: 'block_number',
value: blockFrom.number
})
}
}
if (dateTo) {
const diff = dayjs().diff(dayjs(dateTo), 'days')
const isCurrentDateOrNext = diff <= 0
const blockToFilter = {
offset: 0,
limit: 1,
orderBy: 'number',
orderDirection: 'desc',
filters: [] as any
}
if(!isCurrentDateOrNext) {
blockToFilter.filters.push({
type: 'lte',
property: 'timestamp',
value: `'${dayjs(dateTo).add(1, 'day').format(dateFormat)}'`
})
}
const [blockTo] = await getBlocks([0, blockToFilter]);
if(blockTo) {
txsFilter.filters.push({
type: 'lte',
property: 'block_number',
value: blockTo.number
})
}
}
const txs = await getRelatedTransactionsByType([ const txs = await getRelatedTransactionsByType([
0, 0,
address, address,
type, type,
filter, txsFilter,
]); ]);
const downloadParams = { const downloadParams = {
type, type,
@ -126,20 +187,27 @@ export const ExportData = () => {
} }
const getTxTextType = (type: TRelatedTransaction) => { const getTxTextType = (type: TRelatedTransaction) => {
return type === 'transaction' ? 'transactions' : type + ' transactions' if(type === 'transaction') {
return 'transactions'
} else if (type === 'internal_transaction') {
return 'internal transactions'
}
return type + ' transactions'
} }
return <BaseContainer pad={{ horizontal: "0" }} style={{ maxWidth: '700px', alignSelf: 'center' }}> return <BaseContainer pad={{ horizontal: "0" }} style={{ maxWidth: '740px', alignSelf: 'center' }}>
<Heading size="xsmall" margin={{ bottom: "medium", top: "0" }}> <Heading size="xsmall" margin={{ bottom: "medium", top: "0" }}>
Export transactions <Box gap={'4px'} direction={'row'} align={'baseline'}>
Download Data
<Text size={'medium'} weight={'normal'} color={'minorText'}>({getTxTextType(type)})</Text>
</Box>
</Heading> </Heading>
<BasePage pad={"medium"} style={{ overflow: "inherit" }}> <BasePage pad={"medium"} style={{ overflow: "inherit" }}>
<Box pad={{ top: 'medium', bottom: 'medium' }} style={{ display: 'inline-block' }}> <Box pad={{ top: 'medium', bottom: 'medium' }} style={{ display: 'inline-block' }}>
Export the last {filter.limit} {getTxTextType(type)} for <Address address={address} /> Export the last {DefaultLimit} {getTxTextType(type)} for <Address address={address} />
{type === 'transaction' && 'starting from'} {type === 'transaction' && 'starting from'}
</Box> </Box>
{/* TODO: support timestamp filter on backend side */} {!['erc20', 'internal_transaction'].includes(type) &&
{type === 'transaction' &&
<FlexWrapper> <FlexWrapper>
<InputContainer> <InputContainer>
<Tip dropProps={{ align: { bottom: "top" }}} content={<TipContent showArrow={true} message={'Select start date'} />}> <Tip dropProps={{ align: { bottom: "top" }}} content={<TipContent showArrow={true} message={'Select start date'} />}>

@ -1,196 +0,0 @@
import React, { useEffect, useState } from "react";
import {Box, Heading, Select, Spinner, Text, TextArea, TextInput, Tip} from "grommet";
import { Alert, StatusGood } from "grommet-icons";
import { useHistory } from "react-router-dom";
import useQuery from "../../hooks/useQuery";
import {
assignProxyImplementation,
getProxyImplementation
} from "../../api/client";
import {Address, BaseContainer, BasePage, Button} from "../../components/ui";
import styled from "styled-components";
import {getAddress} from "../../utils";
import {ISourceCode, loadSourceCode} from "../../api/explorerV1";
export const ActionButton = styled(Button)`
font-size: 14px;
padding: 8px 8px 5px 8px;
font-weight: 500;
`;
export function VerifyProxyContract() {
const query = useQuery();
const history = useHistory();
const queryAddress = query.get('a') || '';
const [isLoading, setIsLoading] = useState(false)
const [contractAddress, setContractAddress] = useState(queryAddress)
const [implementationAddress, setImplementationAddress] = useState('')
const [implementationCode, setImplementationCode] = useState<ISourceCode>()
const [contractCode, setContractCode] = useState<ISourceCode>()
const [verificationError, setVerificationError] = useState('')
const [isVerified, setIsVerified] = useState(false)
const enrichAddress = (address: string) => {
let a = address.trim().toLowerCase()
if(address.startsWith('one1')) { // convert one1 to 0x before send request to backend
try {
a = getAddress(address).basicHex
} catch (e) {}
}
return a
}
const setDefaultState = () => {
setImplementationAddress('')
setVerificationError('')
setIsVerified(false)
}
const validateAddress = (address: string) => {
if(address.length === 0) {
return ''
} else {
if(!address.startsWith('0x') && !address.startsWith('one1')) {
return 'Address should start with 0x or one1'
}
if(address.length != 42) {
return 'Address must be 42 characters long'
}
}
return ''
}
const verifyContract = async () => {
setImplementationAddress('')
const err = validateAddress(contractAddress)
if(err) {
setVerificationError(err)
} else {
try {
setIsLoading(true)
setVerificationError('')
const formattedContractAddress = enrichAddress(contractAddress)
const implContract = await getProxyImplementation([0, formattedContractAddress]);
if(implContract) {
try {
const code = await loadSourceCode(formattedContractAddress, 0)
const implCode = await loadSourceCode(implContract.address, 0)
setContractCode(code)
setImplementationCode(implCode)
} catch (e) {
setVerificationError('Proxy or implementation contract source code is not verified. Please verify and publish the contract source before proceeding with this proxy verification.')
}
setImplementationAddress(implContract.address)
} else {
setImplementationAddress('')
setVerificationError('This contract does not look like it contains any delegatecall opcode sequence.')
}
} catch (e) {
console.error('Unable to verify contract', e)
setVerificationError('Cannot verify contract address, try again later')
} finally {
setIsLoading(false)
}
}
}
const applyImplementationAddress = async () => {
const contract = await assignProxyImplementation([0, enrichAddress(contractAddress), implementationAddress])
setDefaultState()
setIsVerified(true)
}
const onChangeInput = (value: string) => {
setContractAddress(value)
setDefaultState()
}
return (
<BaseContainer pad={{ horizontal: "0" }}>
<Heading size="small" margin={{ bottom: "medium", top: "0" }}>
Proxy Contract Verification
</Heading>
<BasePage pad={"small"} style={{ overflow: "inherit" }}>
<Box pad={'16px'} gap={'16px'} width={'600px'}>
<Box direction="row" justify={'start'} wrap>
<Box margin={'0'}>
<Text size={'small'}>Please enter the Proxy Contract Address you would like to verify</Text>
<Box direction="row">
<Box width={'600px'}>
<TextInput
placeholder={"Contract address"}
onChange={(evt: React.ChangeEvent<HTMLInputElement>) => onChangeInput(evt.currentTarget.value)}
value={contractAddress}
disabled={false}
/>
</Box>
</Box>
</Box>
</Box>
{!implementationAddress &&
<Box direction={'column'} gap={'16px'}>
{verificationError &&
<Box round={'8px'} background={'backgroundError'} pad={'16px'}>
<Text color={'text'} size={'small'}>
{verificationError}
</Text>
</Box>
}
{isVerified &&
<Box round={'8px'} background={'backgroundSuccess'} pad={'16px'}>
<Text color={'successText'} size={'small'}>
Successfully saved. Feel free to return to the address <Address address={contractAddress} hideCopyBtn={true} /> to view updates.
</Text>
</Box>
}
<Box direction={'row'} gap={'16px'}>
<Box width={'small'}>
<ActionButton
disabled={!contractAddress || isLoading}
onClick={verifyContract}>
Verify
</ActionButton>
</Box>
<Box width={'small'}>
<ActionButton
disabled={!contractAddress}
onClick={() => {
setDefaultState()
setContractAddress('')
}
}>Clear</ActionButton>
</Box>
</Box>
</Box>
}
{implementationAddress &&
<Box direction={'column'} gap={'16px'}>
<Box>
<Text size={'small'}>The proxy's implementation contract is found at:</Text>
<Text size={'small'} weight={'bold'} color={'successText'}>
<Address address={implementationAddress} />
</Text>
</Box>
{verificationError &&
<Box round={'8px'} background={'backgroundError'} pad={'16px'}>
<Text color={'text'} size={'small'}>
{verificationError}
</Text>
</Box>
}
<Box direction={'row'} gap={'16px'}>
<Box width={'small'}>
<ActionButton
disabled={isLoading || !implementationCode || !contractCode}
onClick={applyImplementationAddress}>Save</ActionButton>
</Box>
<Box width={'small'}><ActionButton onClick={setDefaultState}>Clear</ActionButton></Box>
</Box>
</Box>
}
</Box>
</BasePage>
</BaseContainer>
)
}

@ -231,6 +231,7 @@ export type InternalTransaction = {
blockNumber: BlockNumber; blockNumber: BlockNumber;
transactionHash: TransactionHash; transactionHash: TransactionHash;
signatures?: any[]; signatures?: any[];
timestamp?: string
}; };
export type Transaction = { export type Transaction = {

Loading…
Cancel
Save