Skip to content

Commit

Permalink
shibarium deposits and withdrawals
Browse files Browse the repository at this point in the history
  • Loading branch information
ArminaAiren committed Feb 15, 2024
1 parent d4d4859 commit 10ac7f6
Show file tree
Hide file tree
Showing 31 changed files with 896 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/ENVS.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ This feature is **enabled by default** with the `coinzilla` ads provider. To swi

| Variable | Type| Description | Compulsoriness | Default value | Example value |
| --- | --- | --- | --- | --- | --- |
| NEXT_PUBLIC_ROLLUP_TYPE | `'optimistic' \| 'zkEvm' ` | Rollup chain type | Required | - | `'optimistic'` |
| NEXT_PUBLIC_ROLLUP_TYPE | `'optimistic' \| 'shibarium' \| 'zkEvm' ` | Rollup chain type | Required | - | `'optimistic'` |
| NEXT_PUBLIC_ROLLUP_L1_BASE_URL | `string` | Blockscout base URL for L1 network | Required | - | `'http://eth-goerli.blockscout.com'` |
| NEXT_PUBLIC_ROLLUP_L2_WITHDRAWAL_URL | `string` | URL for L2 -> L1 withdrawals | - | - | `https://app.optimism.io/bridge/withdraw` |

Expand Down
32 changes: 28 additions & 4 deletions lib/api/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import type {
} from 'types/api/optimisticL2';
import type { RawTracesResponse } from 'types/api/rawTrace';
import type { SearchRedirectResult, SearchResult, SearchResultFilters, SearchResultItem } from 'types/api/search';
import type { ShibariumWithdrawalsResponse, ShibariumDepositsResponse } from 'types/api/shibarium';
import type { Counters, StatsCharts, StatsChart, HomeStats } from 'types/api/stats';
import type {
TokenCounters,
Expand Down Expand Up @@ -601,6 +602,25 @@ export const RESOURCES = {
filterFields: [],
},

// SHIBARIUM L2
shibarium_deposits: {
path: '/api/v2/shibarium/deposits',
filterFields: [],
},

shibarium_deposits_count: {
path: '/api/v2/shibarium/deposits/count',
},

shibarium_withdrawals: {
path: '/api/v2/shibarium/withdrawals',
filterFields: [],
},

shibarium_withdrawals_count: {
path: '/api/v2/shibarium/withdrawals/count',
},

// USER OPS
user_ops: {
path: '/api/v2/proxy/account-abstraction/operations',
Expand Down Expand Up @@ -684,6 +704,7 @@ export type PaginatedResources = 'blocks' | 'block_txs' |
'token_instance_transfers' | 'token_instance_holders' |
'verified_contracts' |
'l2_output_roots' | 'l2_withdrawals' | 'l2_txn_batches' | 'l2_deposits' |
'shibarium_deposits' | 'shibarium_withdrawals' |
'zkevm_l2_txn_batches' | 'zkevm_l2_txn_batch_txs' |
'withdrawals' | 'address_withdrawals' | 'block_withdrawals' |
'watchlist' | 'private_tags_address' | 'private_tags_tx' |
Expand Down Expand Up @@ -805,15 +826,18 @@ never;
export type ResourcePayloadB<Q extends ResourceName> =
Q extends 'marketplace_dapps' ? Array<MarketplaceAppOverview> :
Q extends 'marketplace_dapp' ? MarketplaceAppOverview :
Q extends 'shibarium_withdrawals' ? ShibariumWithdrawalsResponse :
Q extends 'shibarium_deposits' ? ShibariumDepositsResponse :
Q extends 'shibarium_withdrawals_count' ? number :
Q extends 'shibarium_deposits_count' ? number :
never;
/* eslint-enable @typescript-eslint/indent */

export type ResourcePayload<Q extends ResourceName> = ResourcePayloadA<Q> | ResourcePayloadB<Q>;

// Right now there is no paginated resources in B-part
// Add "| ResourcePayloadB<Q>[...]" if it is not true anymore
export type PaginatedResponseItems<Q extends ResourceName> = Q extends PaginatedResources ? ResourcePayloadA<Q>['items'] : never;
export type PaginatedResponseNextPageParams<Q extends ResourceName> = Q extends PaginatedResources ? ResourcePayloadA<Q>['next_page_params'] : never;
export type PaginatedResponseItems<Q extends ResourceName> = Q extends PaginatedResources ? ResourcePayloadA<Q>['items'] | ResourcePayloadB<Q>['items'] : never;
export type PaginatedResponseNextPageParams<Q extends ResourceName> =
Q extends PaginatedResources ? ResourcePayloadA<Q>['next_page_params'] | ResourcePayloadB<Q>['next_page_params'] : never;

/* eslint-disable @typescript-eslint/indent */
export type PaginationFilters<Q extends PaginatedResources> =
Expand Down
17 changes: 17 additions & 0 deletions lib/hooks/useNavItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ export default function useNavItems(): ReturnType {
ensLookup,
].filter(Boolean),
];
} else if (rollupFeature.isEnabled && rollupFeature.type === 'shibarium') {
blockchainNavItems = [
[
txs,
// eslint-disable-next-line max-len
{ text: `Deposits (L1${ rightLineArrow }L2)`, nextRoute: { pathname: '/deposits' as const }, icon: 'arrows/south-east', isActive: pathname === '/deposits' },
// eslint-disable-next-line max-len
{ text: `Withdrawals (L2${ rightLineArrow }L1)`, nextRoute: { pathname: '/withdrawals' as const }, icon: 'arrows/north-east', isActive: pathname === '/withdrawals' },
],
[
blocks,
userOps,
topAccounts,
verifiedContracts,
ensLookup,
].filter(Boolean),
];
} else {
blockchainNavItems = [
txs,
Expand Down
61 changes: 61 additions & 0 deletions mocks/shibarium/deposits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { ShibariumDepositsResponse } from 'types/api/shibarium';

export const data: ShibariumDepositsResponse = {
items: [
{
l1_block_number: 8382841,
timestamp: '2022-05-27T01:13:48.000000Z',
l1_transaction_hash: '0xaf3e5f4ef03eac22a622b3434c5dc9f4465aa291900a86bcf0ad9fb14429f05e',
user: {
hash: '0x6197d1eef304eb5284a0f6720f79403b4e9bf3a5',
implementation_name: null,
is_contract: false,
is_verified: false,
name: null,
private_tags: [],
public_tags: [],
watchlist_names: [],
ens_domain_name: null,
},
l2_transaction_hash: '0xb9212c76069b926917816767e4c5a0ef80e519b1ac1c3d3fb5818078f4984667',
},
{
l1_block_number: 8382841,
timestamp: '2022-05-27T01:13:48.000000Z',
l1_transaction_hash: '0xaf3e5f4ef03eac22a622b3434c5dc9f4465aa291900a86bcf0ad9fb14429f05e',
user: {
hash: '0x6197d1eef304eb5284a0f6720f79403b4e9bf3a5',
implementation_name: null,
is_contract: false,
is_verified: false,
name: null,
private_tags: [],
public_tags: [],
watchlist_names: [],
ens_domain_name: null,
},
l2_transaction_hash: '0xb9212c76069b926917816767e4c5a0ef80e519b1ac1c3d3fb5818078f4984667',
},
{
l1_block_number: 8382841,
timestamp: '2022-05-27T01:13:48.000000Z',
l1_transaction_hash: '0xaf3e5f4ef03eac22a622b3434c5dc9f4465aa291900a86bcf0ad9fb14429f05e',
user: {
hash: '0x6197d1eef304eb5284a0f6720f79403b4e9bf3a5',
implementation_name: null,
is_contract: false,
is_verified: false,
name: null,
private_tags: [],
public_tags: [],
watchlist_names: [],
ens_domain_name: null,
},
l2_transaction_hash: '0xb9212c76069b926917816767e4c5a0ef80e519b1ac1c3d3fb5818078f4984667',
},
],
next_page_params: {
items_count: 50,
block_number: 8382363,
},
};
61 changes: 61 additions & 0 deletions mocks/shibarium/withdrawals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { ShibariumWithdrawalsResponse } from 'types/api/shibarium';

export const data: ShibariumWithdrawalsResponse = {
items: [
{
l2_block_number: 8382841,
timestamp: '2022-05-27T01:13:48.000000Z',
l1_transaction_hash: '0xaf3e5f4ef03eac22a622b3434c5dc9f4465aa291900a86bcf0ad9fb14429f05e',
user: {
hash: '0x6197d1eef304eb5284a0f6720f79403b4e9bf3a5',
implementation_name: null,
is_contract: false,
is_verified: false,
name: null,
private_tags: [],
public_tags: [],
watchlist_names: [],
ens_domain_name: null,
},
l2_transaction_hash: '0xb9212c76069b926917816767e4c5a0ef80e519b1ac1c3d3fb5818078f4984667',
},
{
l2_block_number: 8382841,
timestamp: '2022-05-27T01:13:48.000000Z',
l1_transaction_hash: '0xaf3e5f4ef03eac22a622b3434c5dc9f4465aa291900a86bcf0ad9fb14429f05e',
user: {
hash: '0x6197d1eef304eb5284a0f6720f79403b4e9bf3a5',
implementation_name: null,
is_contract: false,
is_verified: false,
name: null,
private_tags: [],
public_tags: [],
watchlist_names: [],
ens_domain_name: null,
},
l2_transaction_hash: '0xb9212c76069b926917816767e4c5a0ef80e519b1ac1c3d3fb5818078f4984667',
},
{
l2_block_number: 8382841,
timestamp: '2022-05-27T01:13:48.000000Z',
l1_transaction_hash: '0xaf3e5f4ef03eac22a622b3434c5dc9f4465aa291900a86bcf0ad9fb14429f05e',
user: {
hash: '0x6197d1eef304eb5284a0f6720f79403b4e9bf3a5',
implementation_name: null,
is_contract: false,
is_verified: false,
name: null,
private_tags: [],
public_tags: [],
watchlist_names: [],
ens_domain_name: null,
},
l2_transaction_hash: '0xb9212c76069b926917816767e4c5a0ef80e519b1ac1c3d3fb5818078f4984667',
},
],
next_page_params: {
items_count: 50,
block_number: 8382363,
},
};
12 changes: 11 additions & 1 deletion nextjs/getServerSideProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,20 @@ export const verifiedAddresses: GetServerSideProps<Props> = async(context) => {
return account(context);
};

export const deposits: GetServerSideProps<Props> = async(context) => {
if (!(rollupFeature.isEnabled && (rollupFeature.type === 'optimistic' || rollupFeature.type === 'shibarium'))) {
return {
notFound: true,
};
}

return base(context);
};

export const withdrawals: GetServerSideProps<Props> = async(context) => {
if (
!config.features.beaconChain.isEnabled &&
!(rollupFeature.isEnabled && rollupFeature.type === 'optimistic')
!(rollupFeature.isEnabled && (rollupFeature.type === 'optimistic' || rollupFeature.type === 'shibarium'))
) {
return {
notFound: true,
Expand Down
1 change: 1 addition & 0 deletions pages/batches/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Batches = dynamic(() => {
case 'optimistic':
return import('ui/pages/OptimisticL2TxnBatches');
}
throw new Error('Deposits feature is not enabled.');
}, { ssr: false });

const Page: NextPage = () => {
Expand Down
17 changes: 15 additions & 2 deletions pages/deposits/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@ import React from 'react';

import PageNextJs from 'nextjs/PageNextJs';

const Deposits = dynamic(() => import('ui/pages/OptimisticL2Deposits'), { ssr: false });
import config from 'configs/app';
const rollupFeature = config.features.rollup;

const Deposits = dynamic(() => {
if (rollupFeature.isEnabled && rollupFeature.type === 'optimistic') {
return import('ui/pages/OptimisticL2Deposits');
}

if (rollupFeature.isEnabled && rollupFeature.type === 'shibarium') {
return import('ui/pages/ShibariumDeposits');
}

throw new Error('Withdrawals feature is not enabled.');
}, { ssr: false });

const Page: NextPage = () => {
return (
Expand All @@ -16,4 +29,4 @@ const Page: NextPage = () => {

export default Page;

export { optimisticRollup as getServerSideProps } from 'nextjs/getServerSideProps';
export { deposits as getServerSideProps } from 'nextjs/getServerSideProps';
5 changes: 5 additions & 0 deletions pages/withdrawals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const Withdrawals = dynamic(() => {
if (rollupFeature.isEnabled && rollupFeature.type === 'optimistic') {
return import('ui/pages/OptimisticL2Withdrawals');
}

if (rollupFeature.isEnabled && rollupFeature.type === 'shibarium') {
return import('ui/pages/ShibariumWithdrawals');
}

if (beaconChainFeature.isEnabled) {
return import('ui/pages/BeaconChainWithdrawals');
}
Expand Down
4 changes: 4 additions & 0 deletions playwright/utils/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export const featureEnvs = {
{ name: 'NEXT_PUBLIC_ROLLUP_L1_BASE_URL', value: 'https://localhost:3101' },
{ name: 'NEXT_PUBLIC_ROLLUP_L2_WITHDRAWAL_URL', value: 'https://localhost:3102' },
],
shibariumRollup: [
{ name: 'NEXT_PUBLIC_ROLLUP_TYPE', value: 'shibarium' },
{ name: 'NEXT_PUBLIC_ROLLUP_L1_BASE_URL', value: 'https://localhost:3101' },
],
bridgedTokens: [
{
name: 'NEXT_PUBLIC_BRIDGED_TOKENS_CHAINS',
Expand Down
20 changes: 20 additions & 0 deletions stubs/shibarium.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { ShibariumDepositsItem, ShibariumWithdrawalsItem } from 'types/api/shibarium';

import { ADDRESS_PARAMS } from './addressParams';
import { TX_HASH } from './tx';

export const SHIBARIUM_DEPOSIT_ITEM: ShibariumDepositsItem = {
l1_block_number: 9045233,
l1_transaction_hash: TX_HASH,
l2_transaction_hash: TX_HASH,
timestamp: '2023-05-22T18:00:36.000000Z',
user: ADDRESS_PARAMS,
};

export const SHIBARIUM_WITHDRAWAL_ITEM: ShibariumWithdrawalsItem = {
l2_block_number: 9045233,
l1_transaction_hash: TX_HASH,
l2_transaction_hash: TX_HASH,
timestamp: '2023-05-22T18:00:36.000000Z',
user: ADDRESS_PARAMS,
};
33 changes: 33 additions & 0 deletions types/api/shibarium.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { AddressParam } from './addressParams';

export type ShibariumDepositsItem = {
l1_block_number: number;
l1_transaction_hash: string;
l2_transaction_hash: string;
timestamp: string;
user: AddressParam | string;
}

export type ShibariumDepositsResponse = {
items: Array<ShibariumDepositsItem>;
next_page_params: {
items_count: number;
block_number: number;
};
}

export type ShibariumWithdrawalsItem = {
l1_transaction_hash: string;
l2_block_number: number;
l2_transaction_hash: string;
timestamp: string;
user: AddressParam | string;
}

export type ShibariumWithdrawalsResponse = {
items: Array<ShibariumWithdrawalsItem>;
next_page_params: {
items_count: number;
block_number: number;
};
}
1 change: 1 addition & 0 deletions types/client/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ArrayElement } from 'types/utils';

export const ROLLUP_TYPES = [
'optimistic',
'shibarium',
'zkEvm',
] as const;

Expand Down
Loading

0 comments on commit 10ac7f6

Please sign in to comment.