Skip to content

Commit

Permalink
add deployed contracts to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mds1 committed Apr 30, 2024
1 parent df8838d commit 2aa413e
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 110 deletions.
4 changes: 2 additions & 2 deletions script/checks/deployed-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const deployedContracts: { name: string; address: Address }[] = [
},
{ name: 'Create2Deployer', address: '0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2' },
// ERC-4337.
{ name: 'ERC-4337 EntryPoint v0.6', address: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789' },
{ name: 'ERC-4337 Entry Point v0.6', address: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789' },
{
name: 'ERC-4337 SimpleAccountFactory v0.6',
name: 'ERC-4337 Simple Account Factory v0.6',
address: '0x9406Cc6185a346906296840746125a0E44976454',
},
// Other
Expand Down
4 changes: 2 additions & 2 deletions script/data/chain/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@
"hasCode": true
},
{
"name": "ERC-4337 EntryPoint v0.6",
"name": "ERC-4337 Entry Point v0.6",
"address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
"codeHash": "0xc93c806e738300b5357ecdc2e971d6438d34d8e4e17b99b758b1f9cac91c8e70",
"hasCode": true
},
{
"name": "ERC-4337 SimpleAccountFactory v0.6",
"name": "ERC-4337 Simple Account Factory v0.6",
"address": "0x9406Cc6185a346906296840746125a0E44976454",
"codeHash": "0xe7ca0f7aa741031b27df24056c8000e7df56cf8a4ff434e28b1bbe1aa6eaa515",
"hasCode": true
Expand Down
4 changes: 2 additions & 2 deletions script/data/chain/10.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@
"hasCode": true
},
{
"name": "ERC-4337 EntryPoint v0.6",
"name": "ERC-4337 Entry Point v0.6",
"address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
"codeHash": "0xc93c806e738300b5357ecdc2e971d6438d34d8e4e17b99b758b1f9cac91c8e70",
"hasCode": true
},
{
"name": "ERC-4337 SimpleAccountFactory v0.6",
"name": "ERC-4337 Simple Account Factory v0.6",
"address": "0x9406Cc6185a346906296840746125a0E44976454",
"codeHash": "0xe7ca0f7aa741031b27df24056c8000e7df56cf8a4ff434e28b1bbe1aa6eaa515",
"hasCode": true
Expand Down
4 changes: 2 additions & 2 deletions script/data/chain/42161.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@
"hasCode": true
},
{
"name": "ERC-4337 EntryPoint v0.6",
"name": "ERC-4337 Entry Point v0.6",
"address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
"codeHash": "0xc93c806e738300b5357ecdc2e971d6438d34d8e4e17b99b758b1f9cac91c8e70",
"hasCode": true
},
{
"name": "ERC-4337 SimpleAccountFactory v0.6",
"name": "ERC-4337 Simple Account Factory v0.6",
"address": "0x9406Cc6185a346906296840746125a0E44976454",
"codeHash": "0xe7ca0f7aa741031b27df24056c8000e7df56cf8a4ff434e28b1bbe1aa6eaa515",
"hasCode": true
Expand Down
12 changes: 6 additions & 6 deletions script/data/feature/deployedContracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"hasCode": true
},
{
"name": "ERC-4337 EntryPoint v0.6",
"name": "ERC-4337 Entry Point v0.6",
"address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
"codeHash": "0xc93c806e738300b5357ecdc2e971d6438d34d8e4e17b99b758b1f9cac91c8e70",
"hasCode": true
},
{
"name": "ERC-4337 SimpleAccountFactory v0.6",
"name": "ERC-4337 Simple Account Factory v0.6",
"address": "0x9406Cc6185a346906296840746125a0E44976454",
"codeHash": "0xe7ca0f7aa741031b27df24056c8000e7df56cf8a4ff434e28b1bbe1aa6eaa515",
"hasCode": true
Expand Down Expand Up @@ -63,13 +63,13 @@
"hasCode": true
},
{
"name": "ERC-4337 EntryPoint v0.6",
"name": "ERC-4337 Entry Point v0.6",
"address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
"codeHash": "0xc93c806e738300b5357ecdc2e971d6438d34d8e4e17b99b758b1f9cac91c8e70",
"hasCode": true
},
{
"name": "ERC-4337 SimpleAccountFactory v0.6",
"name": "ERC-4337 Simple Account Factory v0.6",
"address": "0x9406Cc6185a346906296840746125a0E44976454",
"codeHash": "0xe7ca0f7aa741031b27df24056c8000e7df56cf8a4ff434e28b1bbe1aa6eaa515",
"hasCode": true
Expand Down Expand Up @@ -107,13 +107,13 @@
"hasCode": true
},
{
"name": "ERC-4337 EntryPoint v0.6",
"name": "ERC-4337 Entry Point v0.6",
"address": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
"codeHash": "0xc93c806e738300b5357ecdc2e971d6438d34d8e4e17b99b758b1f9cac91c8e70",
"hasCode": true
},
{
"name": "ERC-4337 SimpleAccountFactory v0.6",
"name": "ERC-4337 Simple Account Factory v0.6",
"address": "0x9406Cc6185a346906296840746125a0E44976454",
"codeHash": "0xe7ca0f7aa741031b27df24056c8000e7df56cf8a4ff434e28b1bbe1aa6eaa515",
"hasCode": true
Expand Down
24 changes: 14 additions & 10 deletions script/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
import { http, fallback, createPublicClient } from 'viem';
import { checkDeployedContracts } from './checks/deployed-contracts';
import { checkEvmStackAddresses, EVMStack, EVMStackResult } from './checks/evm-stack-addresses';
import {
checkEvmStackAddresses,
type EVMStack,
type EVMStackResult,
} from './checks/evm-stack-addresses';
import { checkOpcodes } from './checks/opcodes';
import { checkPrecompiles } from './checks/precompiles';
import type { Metadata } from './types';

export type Chain = {
metadata: Metadata;
opcodes: {
number: `0x${string}`;
name: string;
supported: string | boolean;
number: `0x${string}`;
name: string;
supported: string | boolean;
}[];
deployedContracts: {
name: string;
address: `0x${string}`;
codeHash: `0x${string}`;
hasCode: boolean;
address: `0x${string}`;
codeHash: `0x${string}`;
hasCode: boolean;
}[];
precompiles: {
name: string;
address: `0x${string}`;
implemented: boolean;
address: `0x${string}`;
implemented: boolean;
}[];
evmStackAddresses: Record<EVMStack, EVMStackResult[]>;
}
};

async function main() {
// Initialize chain data.
Expand Down
98 changes: 14 additions & 84 deletions src/components/diff/DiffDeployedContracts.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import { Address, getAddress } from 'viem';
import { Abi } from '@/components/diff/utils/Abi';
import { Collapsible } from '@/components/diff/utils/Collapsible';
import { Markdown } from '@/components/diff/utils/Markdown';
import { Chain } from '@/../script/index';
import { RenderDiff } from '@/components/diff/utils/RenderDiff';
import { Copyable } from '@/components/ui/Copyable';
import {
DeployedContract,
DeployedContractKind,
ProxiedDeployedContract,
StandardDeployedContract,
} from '@/types';

type DeployedContract = Chain['deployedContracts'][0];
type Props = {
base: DeployedContract[];
target: DeployedContract[];
Expand All @@ -19,86 +12,34 @@ type Props = {

const formatDeployedContract = (deployedContract: DeployedContract | undefined) => {
if (!deployedContract) return <p>Not present</p>;

const title =
deployedContract.kind === DeployedContractKind.WrappedNativeAsset ? (
<Markdown
codeSize='0.9rem'
content={`${deployedContract.tokenName!} (${deployedContract.tokenSymbol!})`}
/>
) : (
<Markdown codeSize='0.9rem' content={deployedContract.name} />
);

const addr = getAddress(deployedContract.address);
const deployInstructions = deployedContract.deploymentInstructions || 'N/A';

return (
<>
<div>{title}</div>
<div className='text-secondary text-sm'>
<Markdown content={deployedContract.description} />
</div>
<div className='text-secondary mt-3 grid grid-cols-4 space-y-1 text-sm'>
<div className='mt-3 grid grid-cols-8 space-y-1'>
<div className='col-span-2'>Address</div>
<div className='col-span-2'>
<div className='col-span-6'>
<Copyable content={formatAddress(addr)} textToCopy={getAddress(addr)} />
</div>

<div className='col-span-2'>Deploy Instructions</div>
<div className='col-span-2'>
<Markdown content={deployInstructions} />
</div>
</div>
<div className='mt-4'>
<Abi contract={deployedContract} />
<Collapsible kind='references' contents={deployedContract.references} />
<div className='col-span-2'>Deployed?</div>
<div className='col-span-6'>{deployedContract.hasCode ? 'Yes' : 'No'}</div>
</div>
</>
);
};

export const convertToComparableContract = (contract: DeployedContract | undefined) => {
if (typeof contract === 'undefined') return undefined;
const slimmedContract = contract as any;
delete slimmedContract.codeHash;
return slimmedContract;
};

const formatAddress = (addr: Address) => {
addr = getAddress(addr);
return <code className='text-sm'>{`${addr.slice(0, 6)}...${addr.slice(-4)}`}</code>;
};

type OmittedStandardDeployedContract = Omit<
StandardDeployedContract,
'description' | 'deploymentInstructions' | 'references'
>;
type OmittedProxiedDeployedContract = Omit<
ProxiedDeployedContract,
'description' | 'deploymentInstructions' | 'references'
>;

export const convertToComparableContract = (
contract: DeployedContract | undefined
): OmittedStandardDeployedContract | OmittedProxiedDeployedContract | undefined => {
if (typeof contract === 'undefined') return undefined;

const baseReturnData: OmittedStandardDeployedContract = {
name: contract.name,
kind: contract.kind,
tokenName: contract.tokenName,
tokenSymbol: contract.tokenSymbol,
address: contract.address,
notes: contract.notes,
logicAbi: contract.logicAbi.sort(),
};

if ('proxyAbi' in contract) {
const proxiedReturnData: OmittedProxiedDeployedContract = {
...baseReturnData,
proxyAbi: contract.proxyAbi.sort(),
logicAddress: contract.logicAddress,
};
return proxiedReturnData;
}

return baseReturnData;
};

export const DiffDeployedContracts = ({ base, target, onlyShowDiff }: Props) => {
const sortedNames = [...base.map((c) => c.name), ...target.map((c) => c.name)].sort((a, b) =>
a.localeCompare(b)
Expand All @@ -117,24 +58,13 @@ export const DiffDeployedContracts = ({ base, target, onlyShowDiff }: Props) =>

const showDeployedContract = !isEqual || !onlyShowDiff;

let formattedName: string | JSX.Element = name;
if (name.includes('Create2 Deployer')) {
const [first, _] = name.split('Create2 Deployer');
formattedName = (
<>
<div>{first}</div>
<div>Create2 Deployer</div>
</>
);
}

return (
showDeployedContract && (
<div
key={name}
className='grid grid-cols-12 items-center border-b border-zinc-500/10 py-6 dark:border-zinc-500/20'
>
<div className='col-span-2'>{formattedName}</div>
<div className='col-span-2'>{name}</div>
<div className='col-span-5 pr-4'>{formatDeployedContract(baseDeployedContract)}</div>
<div className='col-span-5'>{formatDeployedContract(targetDeployedContract)}</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/diff/DiffOpcodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const DiffOpcodes = ({ base, target, onlyShowDiff }: Props): JSX.Element
const baseOpcode = base.find((opcode) => Number(opcode.number) === number);
const targetOpcode = target.find((opcode) => Number(opcode.number) === number);
if (!baseOpcode || !targetOpcode) {
return false
return false;
}

const isEqual = JSON.stringify(baseOpcode) === JSON.stringify(targetOpcode);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/diff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ interface Section {
const SECTION_MAP: Record<string, Section> = {
metadata: { title: 'Metadata', component: DiffMetadata },
opcodes: { title: 'Opcodes', component: DiffOpcodes },
deployedContracts: { title: 'Deployed Contracts', component: DiffDeployedContracts },
// precompiles: { title: 'Precompiles', component: DiffPrecompiles },
// predeploys: { title: 'Predeploys', component: DiffPredeploys },
// signatureTypes: { title: 'Transaction and Signature Types', component: DiffSignatureTypes },
// accountTypes: { title: 'Account Types', component: DiffAccountTypes },
// mempools: { title: 'Mempools', component: DiffMempools },
// deployedContracts: { title: 'Deployed Contracts', component: DiffDeployedContracts },
// eips: { title: 'Execution EIPs', component: DiffEIPs },
// executionNodes: { title: 'Execution Nodes', component: DiffNodes },
// consensusNodes: { title: 'Consensus Nodes', component: DiffNodes, hide: true }, // Hidden to scope UI to execution data
Expand Down

0 comments on commit 2aa413e

Please sign in to comment.