Skip to content

Commit

Permalink
display zk contract info
Browse files Browse the repository at this point in the history
  • Loading branch information
tom2drum committed Aug 15, 2024
1 parent 7478614 commit 98758f3
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 3 deletions.
7 changes: 7 additions & 0 deletions mocks/contract/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ export const withChangedByteCode: SmartContract = {
is_blueprint: true,
};

export const zkSync: SmartContract = {
...verified,
zk_compiler_version: 'v1.2.5',
optimization_enabled: true,
optimization_runs: 's',
};

export const nonVerified: SmartContract = {
is_verified: false,
is_blueprint: false,
Expand Down
3 changes: 2 additions & 1 deletion types/api/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface SmartContract {
compiler_version: string | null;
evm_version: string | null;
optimization_enabled: boolean | null;
optimization_runs: number | null;
optimization_runs: number | string | null;
name: string | null;
verified_at: string | null;
is_blueprint: boolean | null;
Expand Down Expand Up @@ -57,6 +57,7 @@ export interface SmartContract {
language: string | null;
license_type: SmartContractLicenseType | null;
certified?: boolean;
zk_compiler_version?: string;
}

export type SmartContractDecodedConstructorArg = [
Expand Down
1 change: 1 addition & 0 deletions types/api/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface VerifiedContract {
verified_at: string;
market_cap: string | null;
license_type: SmartContractLicenseType | null;
zk_compiler_version?: string;
}

export interface VerifiedContractsResponse {
Expand Down
8 changes: 8 additions & 0 deletions ui/address/contract/ContractCode.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ test('non verified', async({ render, mockApiResponse }) => {
await expect(component).toHaveScreenshot();
});

test('zkSync contract', async({ render, mockApiResponse, page, mockEnvs }) => {
await mockEnvs(ENVS_MAP.zkSyncRollup);
await mockApiResponse('contract', contractMock.zkSync, { pathParams: { hash: addressMock.contract.hash } });
await render(<ContractCode/>, { hooksConfig }, { withSocket: true });

await expect(page).toHaveScreenshot({ clip: { x: 0, y: 0, width: 1200, height: 300 } });
});

test.describe('with audits feature', () => {

test.beforeEach(async({ mockEnvs }) => {
Expand Down
12 changes: 10 additions & 2 deletions ui/address/contract/ContractCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const InfoItem = chakra(({ label, content, hint, className, isLoading }: InfoIte
</GridItem>
));

const rollupFeature = config.features.rollup;

const ContractCode = ({ addressHash, contractQuery, channel }: Props) => {
const [ isChangedBytecodeSocket, setIsChangedBytecodeSocket ] = React.useState<boolean>();

Expand Down Expand Up @@ -266,6 +268,7 @@ const ContractCode = ({ addressHash, contractQuery, channel }: Props) => {
<Grid templateColumns={{ base: '1fr', lg: '1fr 1fr' }} rowGap={ 4 } columnGap={ 6 } mb={ 8 }>
{ data.name && <InfoItem label="Contract name" content={ contractNameWithCertifiedIcon } isLoading={ isPlaceholderData }/> }
{ data.compiler_version && <InfoItem label="Compiler version" content={ data.compiler_version } isLoading={ isPlaceholderData }/> }
{ data.zk_compiler_version && <InfoItem label="ZK compiler version" content={ data.zk_compiler_version } isLoading={ isPlaceholderData }/> }
{ data.evm_version && <InfoItem label="EVM version" content={ data.evm_version } textTransform="capitalize" isLoading={ isPlaceholderData }/> }
{ licenseLink && (
<InfoItem
Expand All @@ -277,8 +280,13 @@ const ContractCode = ({ addressHash, contractQuery, channel }: Props) => {
) }
{ typeof data.optimization_enabled === 'boolean' &&
<InfoItem label="Optimization enabled" content={ data.optimization_enabled ? 'true' : 'false' } isLoading={ isPlaceholderData }/> }
{ data.optimization_runs !== null &&
<InfoItem label="Optimization runs" content={ String(data.optimization_runs) } isLoading={ isPlaceholderData }/> }
{ data.optimization_runs !== null && (
<InfoItem
label={ rollupFeature.isEnabled && rollupFeature.type === 'zkSync' ? 'Optimization mode' : 'Optimization runs' }
content={ String(data.optimization_runs) }
isLoading={ isPlaceholderData }
/>
) }
{ data.verified_at &&
<InfoItem label="Verified at" content={ dayjs(data.verified_at).format('llll') } wordBreak="break-word" isLoading={ isPlaceholderData }/> }
{ data.file_path && <InfoItem label="Contract file path" content={ data.file_path } wordBreak="break-word" isLoading={ isPlaceholderData }/> }
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions ui/verifiedContracts/VerifiedContractsListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ const VerifiedContractsListItem = ({ data, isLoading }: Props) => {
<Box color="text_secondary" wordBreak="break-all" whiteSpace="pre-wrap"> ({ data.compiler_version })</Box>
</Skeleton>
</Flex>
{ data.zk_compiler_version && (
<Flex columnGap={ 3 }>
<Skeleton isLoaded={ !isLoading } fontWeight={ 500 } flexShrink="0">ZK compiler</Skeleton>
<Skeleton isLoaded={ !isLoading } color="text_secondary" wordBreak="break-all" whiteSpace="pre-wrap">
{ data.zk_compiler_version }
</Skeleton>
</Flex>
) }
<Flex columnGap={ 3 }>
<Skeleton isLoaded={ !isLoading } fontWeight={ 500 }>Optimization</Skeleton>
{ data.optimization_enabled ?
Expand Down
8 changes: 8 additions & 0 deletions ui/verifiedContracts/VerifiedContractsTableItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ const VerifiedContractsTableItem = ({ data, isLoading }: Props) => {
</Tooltip>
</Skeleton>
</Flex>
{ data.zk_compiler_version && (
<Flex flexWrap="wrap" columnGap={ 2 } my={ 1 }>
<Skeleton isLoaded={ !isLoading } >ZK compiler</Skeleton>
<Skeleton isLoaded={ !isLoading } color="text_secondary" wordBreak="break-all">
<span>{ data.zk_compiler_version }</span>
</Skeleton>
</Flex>
) }
</Td>
<Td>
<Tooltip label={ isLoading ? undefined : 'Optimization' }>
Expand Down

0 comments on commit 98758f3

Please sign in to comment.