Skip to content

Commit

Permalink
OP Fault Proofs support
Browse files Browse the repository at this point in the history
  • Loading branch information
isstuev committed May 28, 2024
1 parent 86e33ca commit 3422862
Show file tree
Hide file tree
Showing 27 changed files with 495 additions and 19 deletions.
22 changes: 22 additions & 0 deletions configs/app/features/faultProofSystem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Feature } from './types';

import { getEnvValue } from '../utils';
import rollup from './rollup';

const title = 'Fault proof system';

const config: Feature<{ isEnabled: true }> = (() => {
if (rollup.isEnabled && rollup.type === 'optimistic' && getEnvValue('NEXT_PUBLIC_FAULT_PROOF_ENABLED') === 'true') {
return Object.freeze({
title,
isEnabled: true,
});
}

return Object.freeze({
title,
isEnabled: false,
});
})();

export default config;
1 change: 1 addition & 0 deletions configs/app/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export { default as bridgedTokens } from './bridgedTokens';
export { default as blockchainInteraction } from './blockchainInteraction';
export { default as csvExport } from './csvExport';
export { default as dataAvailability } from './dataAvailability';
export { default as faultProofSystem } from './faultProofSystem';
export { default as gasTracker } from './gasTracker';
export { default as googleAnalytics } from './googleAnalytics';
export { default as graphqlApiDocs } from './graphqlApiDocs';
Expand Down
1 change: 1 addition & 0 deletions configs/envs/.env.optimism_sepolia
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ NEXT_PUBLIC_VIEWS_CONTRACT_SOLIDITYSCAN_ENABLED=true
NEXT_PUBLIC_ROLLUP_TYPE=optimistic
NEXT_PUBLIC_ROLLUP_L2_WITHDRAWAL_URL=https://app.optimism.io/bridge/withdraw
NEXT_PUBLIC_ROLLUP_L1_BASE_URL=https://eth-sepolia.blockscout.com/
NEXT_PUBLIC_FAULT_PROOF_ENABLED=true
10 changes: 10 additions & 0 deletions deploy/tools/envs-validator/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,16 @@ const schema = yup
NEXT_PUBLIC_GAS_TRACKER_ENABLED: yup.boolean(),
NEXT_PUBLIC_GAS_TRACKER_UNITS: yup.array().transform(replaceQuotes).json().of(yup.string<GasUnit>().oneOf(GAS_UNITS)),
NEXT_PUBLIC_DATA_AVAILABILITY_ENABLED: yup.boolean(),
NEXT_PUBLIC_FAULT_PROOF_ENABLED: yup.boolean()
.when('NEXT_PUBLIC_ROLLUP_TYPE', {
is: 'optimistic',
then: (schema) => schema,
otherwise: (schema) => schema.test(
'not-exist',
'NEXT_PUBLIC_FAULT_PROOF_ENABLED can only be used with NEXT_PUBLIC_ROLLUP_TYPE=optimistic',
value => value === undefined,
),
}),

// 6. External services envs
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID: yup.string(),
Expand Down
3 changes: 2 additions & 1 deletion deploy/tools/envs-validator/test/.env.rollup
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
NEXT_PUBLIC_ROLLUP_TYPE=optimistic
NEXT_PUBLIC_ROLLUP_L1_BASE_URL=https://example.com
NEXT_PUBLIC_ROLLUP_L2_WITHDRAWAL_URL=https://example.com
NEXT_PUBLIC_ROLLUP_L2_WITHDRAWAL_URL=https://example.com
NEXT_PUBLIC_FAULT_PROOF_ENABLED=true
9 changes: 9 additions & 0 deletions docs/ENVS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Please be aware that all environment variables prefixed with `NEXT_PUBLIC_` will
- [Beacon chain](ENVS.md#beacon-chain)
- [User operations](ENVS.md#user-operations-feature-erc-4337)
- [Rollup chain](ENVS.md#rollup-chain)
- [Fault proof system](ENVS.md#fault-proof-system)
- [Export data to CSV file](ENVS.md#export-data-to-csv-file)
- [Google analytics](ENVS.md#google-analytics)
- [Mixpanel analytics](ENVS.md#mixpanel-analytics)
Expand Down Expand Up @@ -401,6 +402,14 @@ This feature is **enabled by default** with the `coinzilla` ads provider. To swi

&nbsp;

### Fault proof system

| Variable | Type| Description | Compulsoriness | Default value | Example value |
| --- | --- | --- | --- | --- | --- |
| NEXT_PUBLIC_FAULT_PROOF_ENABLED | `boolean` | Set to `true` for chains with fault proof system enabled (OP stack only) | - | - | `true` |

&nbsp;

### Export data to CSV file

| Variable | Type| Description | Compulsoriness | Default value | Example value |
Expand Down
8 changes: 8 additions & 0 deletions icons/games.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 16 additions & 3 deletions lib/api/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import type {
OptimisticL2OutputRootsResponse,
OptimisticL2TxnBatchesResponse,
OptimisticL2WithdrawalsResponse,
OptimisticL2DisputeGamesResponse,
} from 'types/api/optimisticL2';
import type { RawTracesResponse } from 'types/api/rawTrace';
import type { SearchRedirectResult, SearchResult, SearchResultFilters, SearchResultItem } from 'types/api/search';
Expand Down Expand Up @@ -650,6 +651,15 @@ export const RESOURCES = {
path: '/api/v2/optimism/txn-batches/count',
},

optimistic_l2_dispute_games: {
path: '/api/v2/optimism/games',
filterFields: [],
},

optimistic_l2_dispute_games_count: {
path: '/api/v2/optimism/games/count',
},

// zkEvm L2
zkevm_l2_deposits: {
path: '/api/v2/zkevm/deposits',
Expand Down Expand Up @@ -853,6 +863,7 @@ export type PaginatedResources = 'blocks' | 'block_txs' |
'token_instance_transfers' | 'token_instance_holders' |
'verified_contracts' |
'optimistic_l2_output_roots' | 'optimistic_l2_withdrawals' | 'optimistic_l2_txn_batches' | 'optimistic_l2_deposits' |
'optimistic_l2_dispute_games' |
'shibarium_deposits' | 'shibarium_withdrawals' |
'zkevm_l2_deposits' | 'zkevm_l2_withdrawals' | 'zkevm_l2_txn_batches' | 'zkevm_l2_txn_batch_txs' |
'zksync_l2_txn_batches' | 'zksync_l2_txn_batch_txs' |
Expand Down Expand Up @@ -955,20 +966,22 @@ Q extends 'optimistic_l2_output_roots' ? OptimisticL2OutputRootsResponse :
Q extends 'optimistic_l2_withdrawals' ? OptimisticL2WithdrawalsResponse :
Q extends 'optimistic_l2_deposits' ? OptimisticL2DepositsResponse :
Q extends 'optimistic_l2_txn_batches' ? OptimisticL2TxnBatchesResponse :
Q extends 'optimistic_l2_dispute_games' ? OptimisticL2DisputeGamesResponse :
Q extends 'optimistic_l2_output_roots_count' ? number :
Q extends 'optimistic_l2_withdrawals_count' ? number :
Q extends 'optimistic_l2_deposits_count' ? number :
Q extends 'optimistic_l2_txn_batches_count' ? number :
Q extends 'config_backend_version' ? BackendVersionConfig :
Q extends 'address_metadata_info' ? AddressMetadataInfo :
Q extends 'address_metadata_tag_types' ? PublicTagTypesResponse :
Q extends 'optimistic_l2_dispute_games_count' ? number :
never;
// !!! IMPORTANT !!!
// See comment above
/* eslint-enable @typescript-eslint/indent */

/* eslint-disable @typescript-eslint/indent */
export type ResourcePayloadB<Q extends ResourceName> =
Q extends 'config_backend_version' ? BackendVersionConfig :
Q extends 'address_metadata_info' ? AddressMetadataInfo :
Q extends 'address_metadata_tag_types' ? PublicTagTypesResponse :
Q extends 'blob' ? Blob :
Q extends 'marketplace_dapps' ? Array<MarketplaceAppOverview> :
Q extends 'marketplace_dapp' ? MarketplaceAppOverview :
Expand Down
7 changes: 7 additions & 0 deletions lib/hooks/useNavItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export default function useNavItems(): ReturnType {
icon: 'output_roots',
isActive: pathname === '/output-roots',
};
const rollupDisputeGames = config.features.faultProofSystem.isEnabled ? {
text: 'Dispute games',
nextRoute: { pathname: '/dispute-games' as const },
icon: 'games',
isActive: pathname === '/dispute-games',
} : null;

const rollupFeature = config.features.rollup;

Expand All @@ -109,6 +115,7 @@ export default function useNavItems(): ReturnType {
[
blocks,
rollupTxnBatches,
rollupDisputeGames,
rollupFeature.type === 'optimistic' ? rollupOutputRoots : undefined,
].filter(Boolean),
[
Expand Down
1 change: 1 addition & 0 deletions lib/metadata/getPageOgType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const OG_TYPE_DICT: Record<Route['pathname'], OGPageType> = {
'/csv-export': 'Regular page',
'/deposits': 'Root page',
'/output-roots': 'Root page',
'/dispute-games': 'Root page',
'/batches': 'Root page',
'/batches/[number]': 'Regular page',
'/blobs/[hash]': 'Regular page',
Expand Down
1 change: 1 addition & 0 deletions lib/metadata/templates/description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const TEMPLATE_MAP: Record<Route['pathname'], string> = {
'/csv-export': DEFAULT_TEMPLATE,
'/deposits': DEFAULT_TEMPLATE,
'/output-roots': DEFAULT_TEMPLATE,
'/dispute-games': DEFAULT_TEMPLATE,
'/batches': DEFAULT_TEMPLATE,
'/batches/[number]': DEFAULT_TEMPLATE,
'/blobs/[hash]': DEFAULT_TEMPLATE,
Expand Down
1 change: 1 addition & 0 deletions lib/metadata/templates/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const TEMPLATE_MAP: Record<Route['pathname'], string> = {
'/csv-export': 'export data to CSV',
'/deposits': 'deposits (L1 > L2)',
'/output-roots': 'output roots',
'/dispute-games': 'dispute games',
'/batches': 'tx batches (L2 blocks)',
'/batches/[number]': 'L2 tx batch %number%',
'/blobs/[hash]': 'blob %hash% details',
Expand Down
1 change: 1 addition & 0 deletions lib/mixpanel/getPageType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const PAGE_TYPE_DICT: Record<Route['pathname'], string> = {
'/csv-export': 'Export data to CSV file',
'/deposits': 'Deposits (L1 > L2)',
'/output-roots': 'Output roots',
'/dispute-games': 'Dispute games',
'/batches': 'Tx batches (L2 blocks)',
'/batches/[number]': 'L2 tx batch details',
'/blobs/[hash]': 'Blob details',
Expand Down
27 changes: 27 additions & 0 deletions mocks/l2disputeGames/disputeGames.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export const data = {
items: [
{
contract_address: '0x5cbe1b88b6357e6a8f0821bea72cc0b88c231f1c',
created_at: '2022-05-27T01:13:48.000000Z',
game_type: 0,
index: 6662,
l2_block_number: 12542890,
resolved_at: null,
status: 'In progress',
},
{
contract_address: '0x5cbe1b88b6357e6a8f0821bea72cc0b88c231f1c',
created_at: '2022-05-27T01:13:48.000000Z',
game_type: 0,
index: 6662,
l2_block_number: 12542890,
resolved_at: '2022-05-27T01:13:48.000000Z',
status: 'Defender wins',
},
],
next_page_params: {
items_count: 50,
l1_block_number: 8382363,
tx_hash: '0x2012f0ce966ce6573e7826e9235f227edf5a2f8382b8d646c979f85a77e15c05',
},
};
10 changes: 10 additions & 0 deletions nextjs/getServerSideProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,13 @@ export const publicTagsSubmit: GetServerSideProps<Props> = async(context) => {

return base(context);
};

export const disputeGames: GetServerSideProps<Props> = async(context) => {
if (!config.features.faultProofSystem.isEnabled) {
return {
notFound: true,
};
}

return base(context);
};
1 change: 1 addition & 0 deletions nextjs/nextjs-routes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ declare module "nextjs-routes" {
| StaticRoute<"/contract-verification">
| StaticRoute<"/csv-export">
| StaticRoute<"/deposits">
| StaticRoute<"/dispute-games">
| StaticRoute<"/gas-tracker">
| StaticRoute<"/graphiql">
| StaticRoute<"/">
Expand Down
19 changes: 19 additions & 0 deletions pages/dispute-games/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { NextPage } from 'next';
import dynamic from 'next/dynamic';
import React from 'react';

import PageNextJs from 'nextjs/PageNextJs';

const DisputeGames = dynamic(() => import('ui/pages/OptimisticL2DisputeGames'), { ssr: false });

const Page: NextPage = () => {
return (
<PageNextJs pathname="/dispute-games">
<DisputeGames/>
</PageNextJs>
);
};

export default Page;

export { disputeGames as getServerSideProps } from 'nextjs/getServerSideProps';
1 change: 1 addition & 0 deletions playwright/fixtures/mockEnvs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const ENVS_MAP: Record<string, Array<[string, string]>> = {
[ 'NEXT_PUBLIC_ROLLUP_TYPE', 'optimistic' ],
[ 'NEXT_PUBLIC_ROLLUP_L1_BASE_URL', 'https://localhost:3101' ],
[ 'NEXT_PUBLIC_ROLLUP_L2_WITHDRAWAL_URL', 'https://localhost:3102' ],
[ 'NEXT_PUBLIC_FAULT_PROOF_ENABLED', 'true' ],
],
shibariumRollup: [
[ 'NEXT_PUBLIC_ROLLUP_TYPE', 'shibarium' ],
Expand Down
1 change: 1 addition & 0 deletions public/icons/name.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
| "filter"
| "finalized"
| "flame"
| "games"
| "gas_xl"
| "gas"
| "gear_slim"
Expand Down
11 changes: 11 additions & 0 deletions stubs/L2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {
OptimisticL2DepositsItem,
OptimisticL2DisputeGamesItem,
OptimisticL2OutputRootsItem,
OptimisticL2TxnBatchesItem,
OptimisticL2WithdrawalsItem,
Expand Down Expand Up @@ -45,3 +46,13 @@ export const L2_OUTPUT_ROOTS_ITEM: OptimisticL2OutputRootsItem = {
l2_output_index: 50655,
output_root: TX_HASH,
};

export const L2_DISPUTE_GAMES_ITEM: OptimisticL2DisputeGamesItem = {
contract_address: ADDRESS_HASH,
created_at: '2023-06-01T15:26:12.000000Z',
game_type: 0,
index: 6594,
l2_block_number: 50655,
resolved_at: null,
status: 'In progress',
};
36 changes: 27 additions & 9 deletions types/api/optimisticL2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ export type OptimisticL2WithdrawalsItem = {
'status': string;
}

export const WITHDRAWAL_STATUSES = [
'Waiting for state root',
'Ready to prove',
'In challenge period',
'Ready for relay',
'Relayed',
] as const;

export type OptimisticL2WithdrawalStatus = typeof WITHDRAWAL_STATUSES[number];
export type OptimisticL2WithdrawalStatus =
'Waiting for state root' |
'Ready to prove' |
'In challenge period' |
'Waiting a game to resolve' |
'Ready to prove' |
'Proven' |
'Ready for relay' |
'Relayed';

export type OptimisticL2WithdrawalsResponse = {
items: Array<OptimisticL2WithdrawalsItem>;
Expand All @@ -78,3 +78,21 @@ export type OptimisticL2WithdrawalsResponse = {
'nonce': string;
};
}

export type OptimisticL2DisputeGamesResponse = {
items: Array<OptimisticL2DisputeGamesItem>;
'next_page_params': {
'items_count': number;
'index': number;
};
}

export type OptimisticL2DisputeGamesItem = {
contract_address: string;
created_at: string;
game_type: number;
index: number;
l2_block_number: number;
resolved_at: string | null;
status: string;
}
Loading

0 comments on commit 3422862

Please sign in to comment.