Skip to content

Celo: support L2 epochs #2784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions configs/app/features/celo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { getEnvValue } from '../utils';

const title = 'Celo chain';

const config: Feature<{ L2UpgradeBlock: number | undefined; BLOCKS_PER_EPOCH: number }> = (() => {
const config: Feature<{ }> = (() => {

if (getEnvValue('NEXT_PUBLIC_CELO_ENABLED') === 'true') {
return Object.freeze({
title,
isEnabled: true,
L2UpgradeBlock: getEnvValue('NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK') ? Number(getEnvValue('NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK')) : undefined,
BLOCKS_PER_EPOCH: 17_280,
});
}

Expand Down
2 changes: 1 addition & 1 deletion configs/envs/.env.celo_alfajores
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ NEXT_PUBLIC_API_BASE_PATH=/
NEXT_PUBLIC_API_HOST=celo-alfajores.blockscout.com
NEXT_PUBLIC_API_SPEC_URL=https://raw.githubusercontent.com/blockscout/blockscout-api-v2-swagger/main/swagger.yaml
NEXT_PUBLIC_CELO_ENABLED=true
NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK=26369280
NEXT_PUBLIC_CONTRACT_CODE_IDES=[{'title':'Remix IDE','url':'https://remix.ethereum.org/?address={hash}&blockscout={domain}','icon_url':'https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/ide-icons/remix.png'}]
NEXT_PUBLIC_CONTRACT_INFO_API_HOST=https://contracts-info.services.blockscout.com
NEXT_PUBLIC_FEATURED_NETWORKS=https://raw.githubusercontent.com/blockscout/frontend-configs/main/configs/featured-networks/celo.json
Expand All @@ -24,6 +23,7 @@ NEXT_PUBLIC_GAS_TRACKER_ENABLED=false
NEXT_PUBLIC_GRAPHIQL_TRANSACTION=0x9767ce30754afad2a3279b9df2d13257f467c3dad4e0e601271e66d16dfd1641
NEXT_PUBLIC_HAS_USER_OPS=true
NEXT_PUBLIC_HOMEPAGE_CHARTS=['daily_txs']
NEXT_PUBLIC_HOMEPAGE_STATS=['total_blocks','average_block_time','total_txs','wallet_addresses','current_epoch']
NEXT_PUBLIC_HOMEPAGE_HERO_BANNER_CONFIG={'background':['rgba(252, 255, 82, 1)'],'text_color':['rgba(0, 0, 0, 1)']}
NEXT_PUBLIC_IS_TESTNET=true
NEXT_PUBLIC_MARKETPLACE_ENABLED=false
Expand Down
10 changes: 0 additions & 10 deletions deploy/tools/envs-validator/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,6 @@ const celoSchema = yup
.object()
.shape({
NEXT_PUBLIC_CELO_ENABLED: yup.boolean(),
NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK: yup
.string()
.when('NEXT_PUBLIC_CELO_ENABLED', {
is: (value: boolean) => value,
then: (schema) => schema.min(0).optional(),
otherwise: (schema) => schema.max(
-1,
'NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK cannot not be used if NEXT_PUBLIC_CELO_ENABLED is not set to "true"',
),
}),
});

const adButlerConfigSchema = yup
Expand Down
3 changes: 1 addition & 2 deletions deploy/tools/envs-validator/test/.env.celo
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
NEXT_PUBLIC_CELO_ENABLED=true
NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK=420
NEXT_PUBLIC_CELO_ENABLED=true
1 change: 1 addition & 0 deletions docs/DEPRECATED_ENVS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
| NEXT_PUBLIC_NETWORK_GOVERNANCE_TOKEN_SYMBOL | `string` | Network governance token symbol | - | - | `GNO` | v1.12.0 | v1.29.0 | Replaced by NEXT_PUBLIC_NETWORK_SECONDARY_COIN_SYMBOL |
| NEXT_PUBLIC_SWAP_BUTTON_URL | `string` | Application ID in the marketplace or website URL | - | - | `uniswap` | v1.24.0 | v1.31.0 | Replaced by NEXT_PUBLIC_DEFI_DROPDOWN_ITEMS |
| NEXT_PUBLIC_HOMEPAGE_SHOW_AVG_BLOCK_TIME | `boolean` | Set to false if average block time is useless for the network | - | `true` | `false` | v1.0.x+ | v1.35.0 | Replaced by NEXT_PUBLIC_HOMEPAGE_STATS |
| NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK | `number` | Indicates the block number when the Celo-type chain transitioned to L2. This is used to display links to the Epoch block page from a regular block page. | - | - | `26369280` | v1.37.0+ | v2.2.0 | Removed; configuration done on the API side |
1 change: 0 additions & 1 deletion docs/ENVS.md
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,6 @@ For blockchains that use the Celo platform. _Note_, that once the Celo mainnet b
| Variable | Type| Description | Compulsoriness | Default value | Example value | Version |
| --- | --- | --- | --- | --- | --- | --- |
| NEXT_PUBLIC_CELO_ENABLED | `boolean` | Indicates that it is a Celo-based chain. | - | - | `true` | v1.37.0+ |
| NEXT_PUBLIC_CELO_L2_UPGRADE_BLOCK | `number` | Indicates the block number when the Celo-type chain transitioned to L2. This is used to display links to the Epoch block page from a regular block page. | - | - | `26369280` | v1.37.0+ |

&nbsp;

Expand Down
2 changes: 1 addition & 1 deletion icons/clock-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions icons/hourglass.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions icons/hourglass_slim.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/api/services/general/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const GENERAL_API_ADDRESS_RESOURCES = {
paginated: true,
},
address_epoch_rewards: {
path: '/api/v2/addresses/:hash/election-rewards',
path: '/api/v2/addresses/:hash/celo/election-rewards',
pathParams: [ 'hash' as const ],
filterFields: [],
paginated: true,
Expand Down
15 changes: 0 additions & 15 deletions lib/api/services/general/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import type {
BlockFilters,
BlockWithdrawalsResponse,
BlockCountdownResponse,
BlockEpoch,
BlockEpochElectionRewardDetailsResponse,
BlockInternalTransactionsResponse,
} from 'types/api/block';
import type { TTxsWithBlobsFilters } from 'types/api/txsFilters';
Expand Down Expand Up @@ -39,17 +37,6 @@ export const GENERAL_API_BLOCK_RESOURCES = {
filterFields: [],
paginated: true,
},
block_epoch: {
path: '/api/v2/blocks/:height_or_hash/epoch',
pathParams: [ 'height_or_hash' as const ],
filterFields: [],
},
block_election_rewards: {
path: '/api/v2/blocks/:height_or_hash/election-rewards/:reward_type',
pathParams: [ 'height_or_hash' as const, 'reward_type' as const ],
filterFields: [],
paginated: true,
},
} satisfies Record<string, ApiResource>;

export type GeneralApiBlockResourceName = `general:${ keyof typeof GENERAL_API_BLOCK_RESOURCES }`;
Expand All @@ -62,8 +49,6 @@ R extends 'general:block_countdown' ? BlockCountdownResponse :
R extends 'general:block_txs' ? BlockTransactionsResponse :
R extends 'general:block_internal_txs' ? BlockInternalTransactionsResponse :
R extends 'general:block_withdrawals' ? BlockWithdrawalsResponse :
R extends 'general:block_epoch' ? BlockEpoch :
R extends 'general:block_election_rewards' ? BlockEpochElectionRewardDetailsResponse :
never;
/* eslint-enable @stylistic/indent */

Expand Down
27 changes: 26 additions & 1 deletion lib/api/services/general/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import type {
import type { Blob } from 'types/api/blobs';
import type { Block } from 'types/api/block';
import type { ChartMarketResponse, ChartSecondaryCoinPriceResponse, ChartTransactionResponse } from 'types/api/charts';
import type { BackendVersionConfig, CsvExportConfig } from 'types/api/configs';
import type { BackendVersionConfig, CeloConfig, CsvExportConfig } from 'types/api/configs';
import type { CeloEpochDetails, CeloEpochElectionRewardDetailsResponse, CeloEpochListResponse } from 'types/api/epochs';
import type { IndexingStatus } from 'types/api/indexingStatus';
import type { NovesAccountHistoryResponse, NovesDescribeTxsResponse, NovesResponseData } from 'types/api/noves';
import type {
Expand Down Expand Up @@ -181,6 +182,23 @@ export const GENERAL_API_MISC_RESOURCES = {
pathParams: [ 'hash' as const ],
},

// EPOCHS
epochs_celo: {
path: '/api/v2/celo/epochs',
filterFields: [],
paginated: true,
},
epoch_celo: {
path: '/api/v2/celo/epochs/:number',
pathParams: [ 'number' as const ],
},
epoch_celo_election_rewards: {
path: '/api/v2/celo/epochs/:number/election-rewards/:reward_type',
pathParams: [ 'number' as const, 'reward_type' as const ],
filterFields: [],
paginated: true,
},

// ADVANCED FILTER
advanced_filter: {
path: '/api/v2/advanced-filters',
Expand Down Expand Up @@ -224,6 +242,9 @@ export const GENERAL_API_MISC_RESOURCES = {
config_csv_export: {
path: '/api/v2/config/csv-export',
},
config_celo: {
path: '/api/v2/config/celo',
},

// CSV EXPORT
csv_export_token_holders: {
Expand Down Expand Up @@ -261,13 +282,17 @@ R extends 'general:search' ? SearchResult :
R extends 'general:search_check_redirect' ? SearchRedirectResult :
R extends 'general:config_backend_version' ? BackendVersionConfig :
R extends 'general:config_csv_export' ? CsvExportConfig :
R extends 'general:config_celo' ? CeloConfig :
R extends 'general:blob' ? Blob :
R extends 'general:validators_stability' ? ValidatorsStabilityResponse :
R extends 'general:validators_stability_counters' ? ValidatorsStabilityCountersResponse :
R extends 'general:validators_blackfort' ? ValidatorsBlackfortResponse :
R extends 'general:validators_blackfort_counters' ? ValidatorsBlackfortCountersResponse :
R extends 'general:validators_zilliqa' ? ValidatorsZilliqaResponse :
R extends 'general:validator_zilliqa' ? ValidatorZilliqa :
R extends 'general:epochs_celo' ? CeloEpochListResponse :
R extends 'general:epoch_celo' ? CeloEpochDetails :
R extends 'general:epoch_celo_election_rewards' ? CeloEpochElectionRewardDetailsResponse :
R extends 'general:user_ops' ? UserOpsResponse :
R extends 'general:user_op' ? UserOp :
R extends 'general:user_ops_account' ? UserOpsAccount :
Expand Down
7 changes: 7 additions & 0 deletions lib/hooks/useNavItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ export default function useNavItems(): ReturnType {
icon: 'MUD_menu',
isActive: pathname === '/mud-worlds',
} : null;
const epochs = config.features.celo.isEnabled ? {
text: 'Epochs',
nextRoute: { pathname: '/epochs' as const },
icon: 'hourglass',
isActive: pathname.startsWith('/epochs'),
} : null;

const rollupFeature = config.features.rollup;

Expand Down Expand Up @@ -196,6 +202,7 @@ export default function useNavItems(): ReturnType {
internalTxs,
userOps,
blocks,
epochs,
topAccounts,
validators,
verifiedContracts,
Expand Down
2 changes: 2 additions & 0 deletions lib/metadata/getPageOgType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const OG_TYPE_DICT: Record<Route['pathname'], OGPageType> = {
'/name-domains/[name]': 'Regular page',
'/validators': 'Root page',
'/validators/[id]': 'Regular page',
'/epochs': 'Root page',
'/epochs/[number]': 'Regular page',
'/gas-tracker': 'Root page',
'/mud-worlds': 'Root page',
'/token-transfers': 'Root page',
Expand Down
2 changes: 2 additions & 0 deletions lib/metadata/templates/description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const TEMPLATE_MAP: Record<Route['pathname'], string> = {
'/name-domains/[name]': DEFAULT_TEMPLATE,
'/validators': DEFAULT_TEMPLATE,
'/validators/[id]': DEFAULT_TEMPLATE,
'/epochs': DEFAULT_TEMPLATE,
'/epochs/[number]': DEFAULT_TEMPLATE,
'/gas-tracker': 'Explore real-time %network_title% gas fees with Blockscout\'s advanced gas fee tracker. Get accurate %network_gwei% estimates and track transaction costs live.',
'/mud-worlds': DEFAULT_TEMPLATE,
'/token-transfers': DEFAULT_TEMPLATE,
Expand Down
2 changes: 2 additions & 0 deletions lib/metadata/templates/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const TEMPLATE_MAP: Record<Route['pathname'], string> = {
'/name-domains/[name]': '%network_name% %name% domain details',
'/validators': '%network_name% validators list',
'/validators/[id]': '%network_name% validator %id% details',
'/epochs': '%network_name% epochs',
'/epochs/[number]': '%network_name% epoch %number% details',
'/gas-tracker': 'Track %network_name% gas fees in %network_gwei%',
'/mud-worlds': '%network_name% MUD worlds list',
'/token-transfers': '%network_name% token transfers',
Expand Down
2 changes: 2 additions & 0 deletions lib/mixpanel/getPageType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export const PAGE_TYPE_DICT: Record<Route['pathname'], string> = {
'/name-domains/[name]': 'Domain details',
'/validators': 'Validators list',
'/validators/[id]': 'Validator details',
'/epochs': 'Epochs',
'/epochs/[number]': 'Epoch details',
'/gas-tracker': 'Gas tracker',
'/mud-worlds': 'MUD worlds',
'/token-transfers': 'Token transfers',
Expand Down
4 changes: 3 additions & 1 deletion lib/shortenString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ export default function shortenString(string: string | null, charNumber: number
return string;
}

return string.slice(0, charNumber - 4) + '...' + string.slice(-4);
const tailLength = charNumber < 8 ? 2 : 4;

return string.slice(0, charNumber - tailLength) + '...' + string.slice(-tailLength);
}
8 changes: 1 addition & 7 deletions mocks/address/epochRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export const epochRewards: AddressEpochRewardsResponse = {
amount: '136609473658452408568',
account: withName,
associated_account: withName,
block_hash: '0x',
block_number: 26369280,
block_timestamp: '2022-05-15T13:16:24Z',
epoch_number: 1526,
token: tokenInfo,
Expand All @@ -22,8 +20,6 @@ export const epochRewards: AddressEpochRewardsResponse = {
amount: '117205842355246195095',
account: withoutName,
associated_account: withoutName,
block_hash: '0x',
block_number: 26352000,
block_timestamp: '2022-05-15T13:16:24Z',
epoch_number: 1525,
token: tokenInfo,
Expand All @@ -33,8 +29,6 @@ export const epochRewards: AddressEpochRewardsResponse = {
amount: '125659647325556554060',
account: withEns,
associated_account: withEns,
block_hash: '0x',
block_number: 26300160,
block_timestamp: '2022-05-15T13:16:24Z',
epoch_number: 1524,
token: tokenInfo,
Expand All @@ -43,7 +37,7 @@ export const epochRewards: AddressEpochRewardsResponse = {
next_page_params: {
amount: '71952055594478242556',
associated_account_address_hash: '0x30d060f129817c4de5fbc1366d53e19f43c8c64f',
block_number: 25954560,
epoch_number: 25954560,
items_count: 50,
type: 'delegated_payment',
},
Expand Down
2 changes: 1 addition & 1 deletion mocks/blocks/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const celo: Block = {
recipient: addressMock.contract,
},
epoch_number: 1486,
is_epoch_block: true,
l1_era_finalized_epoch_number: 1485,
},
};

Expand Down
Loading
Loading